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 \author Mateusz Półrola <mateusz.polrola@gmail.com>
26 #include "XdxfDialog.h"
29 XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
33 this->plugin = plugin;
36 cacheToolTip = tr("Optimize for quicker searches (may take some time)");
37 accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
41 connect(cacheCheckBox, SIGNAL(toggled(bool)),
42 this, SLOT(setGenerateCache(bool)));
43 connect(accentsCheckBox, SIGNAL(toggled(bool)),
44 this, SLOT(setAccents(bool)));
47 connect(accentsInfoToolButton, SIGNAL(clicked()),
48 this, SLOT(showAccentsInfo()));
49 connect(cacheInfoToolButton, SIGNAL(clicked()),
50 this, SLOT(showCacheInfo()));
54 connect(browseButton, SIGNAL(clicked()),
55 this, SLOT(selectFile()));
56 connect(downloadButton, SIGNAL(clicked()),
57 this, SLOT(downloadFile()));
58 connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
59 this, SLOT(fileDownloaded(QString)));
62 connect(confirmButton, SIGNAL(clicked()),
63 this, SLOT(accept()));
67 void XdxfDialog::fileDownloaded(QString) {
68 infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
69 _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
74 void XdxfDialog::initializeUI() {
75 mainVerticalLayout = new QVBoxLayout;
77 widget->setLayout(mainVerticalLayout);
79 infoLabel = new QLabel;
80 infoLabel->setWordWrap(true);
83 setWindowTitle(tr("Add new XDXF dictionary"));
85 browseLayout = new QHBoxLayout;
87 QVBoxLayout* buttonLayout = new QVBoxLayout;
88 browseButton = new QPushButton(tr("Browse"));
89 browseButton->setMaximumWidth(150);
91 downloadButton = new QPushButton(tr("Download"));
92 downloadButton->setMaximumWidth(150);
94 infoLayout = new QHBoxLayout;
95 infoLabel->setText(tr("Dictionary file: not selected"));
97 browseLayout->addWidget(infoLabel,0,Qt::AlignLeft);
98 browseLayout->addLayout(buttonLayout);
99 buttonLayout->addWidget(browseButton,0,Qt::AlignLeft);
100 buttonLayout->addWidget(downloadButton,0,Qt::AlignLeft);
102 mainVerticalLayout->addLayout(browseLayout);
105 setWindowTitle(tr("XDXF Settings"));
107 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
108 tr("From: ") + plugin->langFrom() + "\n" +
109 tr("To: ") + plugin->langTo() + "\n" +
110 tr("Description: ") + plugin->name() + "\n" +
112 mainVerticalLayout->addWidget(infoLabel);
115 accentsLayout = new QHBoxLayout;
116 accentsCheckBox = new QCheckBox(tr("Strip accents"));
117 accentsCheckBox->setToolTip(accentsToolTip);
118 accentsLayout->addWidget(accentsCheckBox);
120 accentsInfoToolButton = new QToolButton;
121 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
122 accentsLayout->addWidget(accentsInfoToolButton);
125 cacheLayout = new QHBoxLayout;
126 cacheCheckBox = new QCheckBox(tr("Optimize"));
127 cacheCheckBox->setToolTip(cacheToolTip);
128 cacheLayout->addWidget(cacheCheckBox);
131 cacheInfoToolButton = new QToolButton;
132 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
133 cacheLayout->addWidget(cacheInfoToolButton);
136 mainVerticalLayout->addLayout(cacheLayout);
137 mainVerticalLayout->addLayout(accentsLayout);
139 //load old setting if exists
141 cacheCheckBox->setChecked(true);
142 accentsCheckBox->setChecked(true);
143 accentsCheckBox->setEnabled(false);
144 _generateCache = true;
146 _dictionaryFilePath = "";
148 else if(plugin && plugin->settings()->value("cached") == "true") {
149 cacheCheckBox->setChecked(true);
150 accentsCheckBox->setChecked(true);
151 accentsCheckBox->setEnabled(false);
152 _generateCache = true;
156 cacheCheckBox->setChecked(false);
157 _generateCache = false;
159 if(plugin->settings()->value("strip_accents") == "true") {
160 accentsCheckBox->setChecked(true);
164 accentsCheckBox->setChecked(false);
169 confirmButton = new QPushButton;
170 mainVerticalLayout->addWidget(confirmButton);
172 confirmButton->setText(tr("Add"));
174 confirmButton->setText(tr("Save settings"));
176 scrollArea = new QScrollArea;
177 scrollArea->setWidget(widget);
178 scrollArea->setWidgetResizable(true);
181 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
184 infoLabel->setMinimumWidth(250);
185 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
186 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
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);