1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "XdxfDialog.h"
27 XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
31 this->plugin = plugin;
36 connect(cacheCheckBox, SIGNAL(toggled(bool)),
37 this, SLOT(setGenerateCache(bool)));
39 connect(accentsCheckBox, SIGNAL(toggled(bool)),
40 this, SLOT(setAccents(bool)));
42 connect(accentsInfoToolButton, SIGNAL(clicked()),
43 this, SLOT(showAccentsInfo()));
45 connect(cacheInfoToolButton, SIGNAL(clicked()),
46 this, SLOT(showCacheInfo()));
49 connect(browseButton, SIGNAL(clicked()),
50 this, SLOT(selectFile()));
52 connect(addButton, SIGNAL(clicked()),
53 this, SLOT(accept()));
56 connect(saveButton, SIGNAL(clicked()),
57 this, SLOT(accept()));
62 void XdxfDialog::initializeUI() {
63 mainVerticalLayout = new QVBoxLayout;
65 widget->setLayout(mainVerticalLayout);
68 setWindowTitle(tr("Add new XDXF dictionary"));
71 browseLayout = new QHBoxLayout;
72 browseButton = new QPushButton(tr("Browse"));
73 browseLabel = new QLabel(tr("Dictionary file: not selected"));
75 browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
76 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
78 mainVerticalLayout->addLayout(browseLayout);
81 setWindowTitle(tr("XDXF Settings"));
84 infoLabel = new QLabel;
86 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
87 tr("From: ") + plugin->langFrom() + "\n" +
88 tr("To: ") + plugin->langTo() + "\n" +
89 tr("Description: ") + plugin->name() + "\n" +
90 tr("License: ") + plugin->infoNote());
91 infoLabel->setWordWrap(true);
92 mainVerticalLayout->addWidget(infoLabel);
95 accentsCheckBox = new QCheckBox(tr("Strip accents"));
96 accentsInfoToolButton = new QToolButton;
97 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
99 accentsLayout = new QHBoxLayout;
100 accentsLayout->addWidget(accentsCheckBox);
101 accentsLayout->addWidget(accentsInfoToolButton);
104 cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches"));
105 cacheInfoToolButton = new QToolButton;
106 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
108 cacheLayout = new QHBoxLayout;
109 cacheLayout->addWidget(cacheCheckBox);
110 cacheLayout->addWidget(cacheInfoToolButton);
112 mainVerticalLayout->addLayout(cacheLayout);
113 mainVerticalLayout->addLayout(accentsLayout);
116 //load old setting if exists
118 cacheCheckBox->setChecked(true);
119 accentsCheckBox->setChecked(true);
120 accentsCheckBox->setEnabled(false);
121 _generateCache = true;
123 _dictionaryFilePath = "";
125 else if(plugin && plugin->settings()->value("cached") == "true") {
126 cacheCheckBox->setChecked(true);
127 accentsCheckBox->setChecked(true);
128 accentsCheckBox->setEnabled(false);
129 _generateCache = true;
133 cacheCheckBox->setChecked(false);
134 _generateCache = false;
136 if(plugin->settings()->value("strip_accents") == "true") {
137 accentsCheckBox->setChecked(true);
141 accentsCheckBox->setChecked(false);
147 addButton = new QPushButton(tr("Add"));
148 mainVerticalLayout->addWidget(addButton);
151 saveButton = new QPushButton(tr("Save settings"));
152 mainVerticalLayout->addWidget(saveButton);
155 scrollArea = new QScrollArea;
156 scrollArea->setWidget(widget);
157 scrollArea->setWidgetResizable(true);
158 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
160 layout = new QHBoxLayout;
161 layout->addWidget(scrollArea);
166 void XdxfDialog::setAccents(bool accents) {
170 void XdxfDialog::setGenerateCache(bool generate) {
171 _generateCache = generate;
174 _lastAccents = _accents;
175 accentsCheckBox->setChecked(true);
178 accentsCheckBox->setChecked(_lastAccents);
180 accentsCheckBox->setEnabled(!generate);
183 void XdxfDialog::selectFile() {
184 QString fileName = QFileDialog::getOpenFileName(this,
185 tr("Select dictionary file"),
187 tr("XDXF Files (*.xdxf)"),
191 if (!fileName.isEmpty()) {
192 browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
193 _dictionaryFilePath = fileName;
197 void XdxfDialog::saveSettings() {
198 _settings = new Settings;
200 foreach(QString key, plugin->settings()->keys())
201 _settings->setValue(key, plugin->settings()->value(key));
204 _settings->setValue("path", _dictionaryFilePath);
208 _settings->setValue("generateCache", "true");
210 _settings->setValue("generateCache", "false");
213 _settings->setValue("strip_accents", "true");
215 _settings->setValue("strip_accents", "false");
218 void XdxfDialog::accept() {
219 if(type == New && _dictionaryFilePath.isEmpty()) {
220 Q_EMIT notify(Notify::Warning, tr("File path is not set"), this);
229 Settings* XdxfDialog::getSettings() {
233 void XdxfDialog::showCacheInfo() {
234 Q_EMIT notify(Notify::Info, tr("Optimize for quicker searches (may take some time)"), this);
237 void XdxfDialog::showAccentsInfo() {
238 Q_EMIT notify(Notify::Info, tr("Strip accents (searching takes more "
239 "time, but spelling don't have to be exact)"), this);