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);
62 cacheCheckBox = new QCheckBox(tr("Cached"),this);
63 if(plugin->settings()->value("cached") == "true") {
64 cacheCheckBox->setChecked(true);
65 _generateCache = true;
68 cacheCheckBox->setChecked(false);
69 _generateCache = false;
72 cacheLayout->addWidget(cacheCheckBox);
74 saveButton = new QPushButton(tr("Save settings"),this);
76 verticalLayout->addWidget(saveButton);
80 connect(browseButton, SIGNAL(clicked()),
81 this, SLOT(selectFile()));
83 connect(saveButton, SIGNAL(clicked()),
84 this, SLOT(accept()));
86 connect(cacheCheckBox, SIGNAL(toggled(bool)),
87 SLOT(setGenerateCache(bool)));
89 _dicitonaryFilePath = plugin->settings()->value("path");
92 void XdxfSettingsDialog::setGenerateCache(bool generate) {
93 _generateCache = generate;
96 bool XdxfSettingsDialog::generateCache() {
97 return _generateCache;
100 void XdxfSettingsDialog::selectFile() {
101 QString fileName = QFileDialog::getOpenFileName(this,
102 tr("Select dictionary file"),
104 tr("XDXF Files (*.xdxf)"),
107 if (!fileName.isEmpty()) {
108 browseLabel->setText(tr("Dictionary file: ") + fileName);
109 _dicitonaryFilePath = fileName;
113 QString XdxfSettingsDialog::dicitonaryFilePath() {
114 return _dicitonaryFilePath;
117 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
119 XdxfSettingsDialog settingsDialog(plugin, parent);
122 if(settingsDialog.exec()==QDialog::Accepted) {
123 Settings* settings = new Settings;
124 foreach(QString key, plugin->settings()->keys())
125 settings->setValue(key, plugin->settings()->value(key));
126 settings->setValue("path", settingsDialog.dicitonaryFilePath());
128 if(settingsDialog.generateCache()) {
129 settings->setValue("generateCache", "true");
132 settings->setValue("generateCache", "false");
134 plugin->setSettings(settings);