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
24 //Created by Mateusz Półrola
26 #include "XdxfSettingsDialog.h"
29 XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
32 this->plugin = plugin;
33 verticalLayout = new QVBoxLayout();
34 setLayout(verticalLayout);
36 setWindowTitle(tr("XDXF Settings"));
39 infoLabel = new QLabel(this);
41 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
42 tr("From: ") + plugin->langFrom() + "\n" +
43 tr("To: ") + plugin->langTo() + "\n" +
44 tr("Description: ") + plugin->name());
46 verticalLayout->addWidget(infoLabel);
48 browseLayout = new QHBoxLayout();
49 verticalLayout->addLayout(browseLayout);
51 browseButton = new QPushButton(tr("Browse"));
52 browseLabel = new QLabel(tr("Dictionary file: ") +
53 plugin->settings()->value("path"));
55 browseLayout->addWidget(browseLabel);
56 browseLayout->addWidget(browseButton,0, Qt::AlignRight);
59 cacheLayout = new QHBoxLayout();
60 verticalLayout->insertLayout(-1,cacheLayout,0);
61 accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more time, "
62 "but spelling don't have to be exact)"));
63 verticalLayout->addWidget(accentsCheckBox);
65 if(plugin->settings()->value("strip_accents") == "true")
66 accentsCheckBox->setChecked(true);
68 accentsCheckBox->setChecked(false);
70 cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
71 if(plugin->settings()->value("cached") == "true") {
72 cacheCheckBox->setChecked(true);
73 accentsCheckBox->setChecked(true);
74 accentsCheckBox->setEnabled(false);
75 _generateCache = true;
78 cacheCheckBox->setChecked(false);
79 _generateCache = false;
82 cacheLayout->addWidget(cacheCheckBox);
84 saveButton = new QPushButton(tr("Save settings"));
86 verticalLayout->addWidget(saveButton);
90 connect(browseButton, SIGNAL(clicked()),
91 this, SLOT(selectFile()));
93 connect(saveButton, SIGNAL(clicked()),
94 this, SLOT(accept()));
96 connect(cacheCheckBox, SIGNAL(toggled(bool)),
97 SLOT(setGenerateCache(bool)));
99 connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
102 _dicitonaryFilePath = plugin->settings()->value("path");
103 lastAccents = accentsCheckBox->isChecked();
107 void XdxfSettingsDialog::setAccents(bool state) {
112 void XdxfSettingsDialog::setGenerateCache(bool generate) {
113 _generateCache = generate;
116 accentsCheckBox->setChecked(true);
118 accentsCheckBox->setChecked(lastAccents);
120 accentsCheckBox->setEnabled(!generate);
123 bool XdxfSettingsDialog::generateCache() {
124 return _generateCache;
127 void XdxfSettingsDialog::selectFile() {
128 QString fileName = QFileDialog::getOpenFileName(this,
129 tr("Select dictionary file"),
131 tr("XDXF Files (*.xdxf)"),
134 if (!fileName.isEmpty()) {
135 browseLabel->setText(tr("Dictionary file: ") + fileName);
136 _dicitonaryFilePath = fileName;
140 QString XdxfSettingsDialog::dicitonaryFilePath() {
141 return _dicitonaryFilePath;
144 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
146 XdxfSettingsDialog settingsDialog(plugin, parent);
149 if(settingsDialog.exec()==QDialog::Accepted) {
150 Settings* settings = new Settings;
151 foreach(QString key, plugin->settings()->keys())
152 settings->setValue(key, plugin->settings()->value(key));
153 settings->setValue("path", settingsDialog.dicitonaryFilePath());
155 if(settingsDialog.generateCache()) {
156 settings->setValue("generateCache", "true");
159 settings->setValue("generateCache", "false");
162 if(settingsDialog.accentsCheckBox->isChecked())
163 settings->setValue("strip_accents", "true");
165 settings->setValue("strip_accents", "false");
167 plugin->setSettings(settings);