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 *******************************************************************************/
23 \brief Implementation of xdxf plugin's dialogs.
25 \author Mateusz Półrola <mateusz.polrola@gmail.com>
28 #include "XdxfDialog.h"
31 XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
35 this->plugin = plugin;
38 cacheToolTip = tr("Optimize for quicker searches (may take some time)");
39 accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
43 connect(cacheCheckBox, SIGNAL(toggled(bool)),
44 this, SLOT(setGenerateCache(bool)));
45 connect(accentsCheckBox, SIGNAL(toggled(bool)),
46 this, SLOT(setAccents(bool)));
49 connect(accentsInfoToolButton, SIGNAL(clicked()),
50 this, SLOT(showAccentsInfo()));
51 connect(cacheInfoToolButton, SIGNAL(clicked()),
52 this, SLOT(showCacheInfo()));
56 connect(browseButton, SIGNAL(clicked()),
57 this, SLOT(selectFile()));
58 connect(downloadButton, SIGNAL(clicked()),
59 this, SLOT(downloadFile()));
60 connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
61 this, SLOT(fileDownloaded(QString)));
64 connect(confirmButton, SIGNAL(clicked()),
65 this, SLOT(accept()));
69 void XdxfDialog::fileDownloaded(QString) {
70 infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
71 _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
76 void XdxfDialog::initializeUI() {
77 mainVerticalLayout = new QVBoxLayout;
79 widget->setLayout(mainVerticalLayout);
81 infoLabel = new QLabel;
82 infoLabel->setWordWrap(true);
85 setWindowTitle(tr("Add new XDXF dictionary"));
87 browseLayout = new QHBoxLayout;
89 QVBoxLayout* buttonLayout = new QVBoxLayout;
90 browseButton = new QPushButton(tr("Browse"));
91 browseButton->setMaximumWidth(150);
93 downloadButton = new QPushButton(tr("Download"));
94 downloadButton->setMaximumWidth(150);
96 infoLayout = new QHBoxLayout;
97 infoLabel->setText(tr("Dictionary file: not selected"));
99 browseLayout->addWidget(infoLabel,0,Qt::AlignLeft);
100 browseLayout->addLayout(buttonLayout);
101 buttonLayout->addWidget(browseButton,0,Qt::AlignLeft);
102 buttonLayout->addWidget(downloadButton,0,Qt::AlignLeft);
104 mainVerticalLayout->addLayout(browseLayout);
107 setWindowTitle(tr("XDXF Settings"));
109 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
110 tr("From: ") + plugin->langFrom() + "\n" +
111 tr("To: ") + plugin->langTo() + "\n" +
112 tr("Description: ") + plugin->name() + "\n" +
114 mainVerticalLayout->addWidget(infoLabel);
117 accentsLayout = new QHBoxLayout;
118 accentsCheckBox = new QCheckBox(tr("Strip accents"));
119 accentsCheckBox->setToolTip(accentsToolTip);
120 accentsLayout->addWidget(accentsCheckBox);
122 accentsInfoToolButton = new QToolButton;
123 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
124 accentsLayout->addWidget(accentsInfoToolButton);
127 cacheLayout = new QHBoxLayout;
128 cacheCheckBox = new QCheckBox(tr("Optimize"));
129 cacheCheckBox->setToolTip(cacheToolTip);
130 cacheLayout->addWidget(cacheCheckBox);
133 cacheInfoToolButton = new QToolButton;
134 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
135 cacheLayout->addWidget(cacheInfoToolButton);
138 mainVerticalLayout->addLayout(cacheLayout);
139 mainVerticalLayout->addLayout(accentsLayout);
141 //load old setting if exists
143 cacheCheckBox->setChecked(true);
144 accentsCheckBox->setChecked(true);
145 accentsCheckBox->setEnabled(false);
146 _generateCache = true;
148 _dictionaryFilePath = "";
150 else if(plugin && plugin->settings()->value("cached") == "true") {
151 cacheCheckBox->setChecked(true);
152 accentsCheckBox->setChecked(true);
153 accentsCheckBox->setEnabled(false);
154 _generateCache = true;
158 cacheCheckBox->setChecked(false);
159 _generateCache = false;
161 if(plugin->settings()->value("strip_accents") == "true") {
162 accentsCheckBox->setChecked(true);
166 accentsCheckBox->setChecked(false);
171 confirmButton = new QPushButton;
172 mainVerticalLayout->addWidget(confirmButton);
174 confirmButton->setText(tr("Add"));
176 confirmButton->setText(tr("Save settings"));
178 scrollArea = new QScrollArea;
179 scrollArea->setWidget(widget);
180 scrollArea->setWidgetResizable(true);
183 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
186 infoLabel->setMinimumWidth(250);
187 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
191 layout = new QHBoxLayout;
192 layout->addWidget(scrollArea);
196 setMinimumSize(385,200);
198 setMinimumHeight(350);
201 scrollArea->setLineWidth(0);
202 scrollArea->setMidLineWidth(0);
203 scrollArea->setFrameStyle(QFrame::NoFrame);
207 void XdxfDialog::setAccents(bool accents) {
212 void XdxfDialog::setGenerateCache(bool generate) {
213 _generateCache = generate;
216 _lastAccents = _accents;
217 accentsCheckBox->setChecked(true);
220 accentsCheckBox->setChecked(_lastAccents);
221 accentsCheckBox->setEnabled(!generate);
225 void XdxfDialog::selectFile() {
226 QString fileName = QFileDialog::getOpenFileName(this,
227 tr("Select dictionary file"),
229 tr("XDXF Files (*.xdxf)"),
232 if (!fileName.isEmpty()) {
233 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
234 _dictionaryFilePath = fileName;
240 void XdxfDialog::downloadFile() {
241 XdxfPlugin::dictDownloader.download(this);
245 void XdxfDialog::saveSettings() {
246 _settings = new Settings;
248 foreach(QString key, plugin->settings()->keys())
249 _settings->setValue(key, plugin->settings()->value(key));
252 _settings->setValue("path", _dictionaryFilePath);
255 _settings->setValue("generateCache", "true");
257 _settings->setValue("generateCache", "false");
260 _settings->setValue("strip_accents", "true");
262 _settings->setValue("strip_accents", "false");
266 void XdxfDialog::accept() {
267 if(type == New && _dictionaryFilePath.isEmpty()) {
268 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
277 Settings* XdxfDialog::getSettings() {
283 void XdxfDialog::showCacheInfo() {
284 Q_EMIT notify(Notify::Warning, cacheToolTip);
288 void XdxfDialog::showAccentsInfo() {
289 Q_EMIT notify(Notify::Warning, accentsToolTip);