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(this);
34 setLayout(verticalLayout);
36 setWindowTitle(tr("XDXF Settings"));
39 infoLabel = new QLabel(this);
41 infoLabel->setText(tr("Plugin type: ") + plugin->type() +"\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(this);
49 verticalLayout->addLayout(browseLayout);
51 browseButton = new QPushButton(tr("Browse"),this);
52 browseLabel = new QLabel(tr("Dictionary file: ") +
53 plugin->settings()->value("path"),this);
55 browseLayout->addWidget(browseLabel);
56 browseLayout->addWidget(browseButton,0, Qt::AlignRight);
59 cacheLayout = new QHBoxLayout(this);
60 verticalLayout->addLayout(cacheLayout);
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 _generateCache = true;
76 cacheCheckBox->setChecked(false);
77 _generateCache = false;
80 cacheLayout->addWidget(cacheCheckBox);
82 saveButton = new QPushButton(tr("Save settings"),this);
84 verticalLayout->addWidget(saveButton);
88 connect(browseButton, SIGNAL(clicked()),
89 this, SLOT(selectFile()));
91 connect(saveButton, SIGNAL(clicked()),
92 this, SLOT(accept()));
94 connect(cacheCheckBox, SIGNAL(toggled(bool)),
95 SLOT(setGenerateCache(bool)));
97 _dicitonaryFilePath = plugin->settings()->value("path");
100 void XdxfSettingsDialog::setGenerateCache(bool generate) {
101 _generateCache = generate;
104 bool XdxfSettingsDialog::generateCache() {
105 return _generateCache;
108 void XdxfSettingsDialog::selectFile() {
109 QString fileName = QFileDialog::getOpenFileName(this,
110 tr("Select dictionary file"),
112 tr("XDXF Files (*.xdxf)"),
115 if (!fileName.isEmpty()) {
116 browseLabel->setText(tr("Dictionary file: ") + fileName);
117 _dicitonaryFilePath = fileName;
121 QString XdxfSettingsDialog::dicitonaryFilePath() {
122 return _dicitonaryFilePath;
125 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
127 XdxfSettingsDialog settingsDialog(plugin, parent);
130 if(settingsDialog.exec()==QDialog::Accepted) {
131 Settings* settings = new Settings;
132 foreach(QString key, plugin->settings()->keys())
133 settings->setValue(key, plugin->settings()->value(key));
134 settings->setValue("path", settingsDialog.dicitonaryFilePath());
136 if(settingsDialog.generateCache()) {
137 settings->setValue("generateCache", "true");
140 settings->setValue("generateCache", "false");
143 if(settingsDialog.accentsCheckBox->isChecked())
144 settings->setValue("strip_accents", "true");
146 settings->setValue("strip_accents", "false");
148 plugin->setSettings(settings);