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 /*! \file XdxfSettingsDialog.cpp
26 #include "XdxfSettingsDialog.h"
29 XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
32 this->plugin = plugin;
34 verticalLayout = new QVBoxLayout;
36 QWidget* w = new QWidget;
37 w->setLayout(verticalLayout);
39 setWindowTitle(tr("XDXF Settings"));
42 infoLabel = new QLabel(this);
44 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
45 tr("From: ") + plugin->langFrom() + "\n" +
46 tr("To: ") + plugin->langTo() + "\n" +
47 tr("Description: ") + plugin->name() + "\n" +
48 tr("License: ") + plugin->infoNote());
49 infoLabel->setWordWrap(true);
52 verticalLayout->addWidget(infoLabel);
55 accentsCheckBox = new QCheckBox(tr("Strip accents"));
56 /*(searching takes more time, "
57 "but spelling don't have to be exact)*/
58 if(plugin->settings()->value("strip_accents") == "true")
59 accentsCheckBox->setChecked(true);
61 accentsCheckBox->setChecked(false);
63 cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches"));
64 /*(may take some time)*/
65 if(plugin->settings()->value("cached") == "true") {
66 cacheCheckBox->setChecked(true);
67 accentsCheckBox->setChecked(true);
68 accentsCheckBox->setEnabled(false);
69 _generateCache = true;
72 cacheCheckBox->setChecked(false);
73 _generateCache = false;
76 accentsToolButton = new QToolButton;
77 cacheToolButton = new QToolButton;
79 accentsToolButton->setIcon(QIcon::fromTheme("general_information"));
80 cacheToolButton->setIcon(QIcon::fromTheme("general_information"));
82 cacheLayout = new QHBoxLayout;
83 accentsLayout = new QHBoxLayout;
85 accentsLayout->addWidget(accentsCheckBox);
86 accentsLayout->addWidget(accentsToolButton);
88 cacheLayout->addWidget(cacheCheckBox);
89 cacheLayout->addWidget(cacheToolButton);
91 verticalLayout->addLayout(cacheLayout);
92 verticalLayout->addLayout(accentsLayout);
96 saveButton = new QPushButton(tr("Save settings"));
98 verticalLayout->addWidget(saveButton);
100 scrollArea = new QScrollArea;
101 scrollArea->setWidget(w);
104 QHBoxLayout* layout = new QHBoxLayout();
106 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
107 scrollArea->setWidgetResizable(true);
108 layout->addWidget(scrollArea);
115 connect(saveButton, SIGNAL(clicked()),
116 this, SLOT(accept()));
118 connect(cacheCheckBox, SIGNAL(toggled(bool)),
119 SLOT(setGenerateCache(bool)));
121 connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
124 _dicitonaryFilePath = plugin->settings()->value("path");
125 lastAccents = accentsCheckBox->isChecked();
129 void XdxfSettingsDialog::setAccents(bool state) {
133 void XdxfSettingsDialog::setGenerateCache(bool generate) {
134 _generateCache = generate;
137 accentsCheckBox->setChecked(true);
139 accentsCheckBox->setChecked(lastAccents);
141 accentsCheckBox->setEnabled(!generate);
144 bool XdxfSettingsDialog::generateCache() {
145 return _generateCache;
148 QString XdxfSettingsDialog::dicitonaryFilePath() {
149 return _dicitonaryFilePath;
152 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
154 XdxfSettingsDialog settingsDialog(plugin, parent);
157 if(settingsDialog.exec()==QDialog::Accepted) {
158 Settings* settings = new Settings;
159 foreach(QString key, plugin->settings()->keys())
160 settings->setValue(key, plugin->settings()->value(key));
161 settings->setValue("path", settingsDialog.dicitonaryFilePath());
163 if(settingsDialog.generateCache()) {
164 settings->setValue("generateCache", "true");
167 settings->setValue("generateCache", "false");
170 if(settingsDialog.accentsCheckBox->isChecked())
171 settings->setValue("strip_accents", "true");
173 settings->setValue("strip_accents", "false");
175 plugin->setSettings(settings);