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 //Created by Mateusz Półrola
24 #include "XdxfDialog.h"
27 XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
31 this->plugin = plugin;
35 cacheToolTip = tr("Optimize for quicker searches (may take some time)");
36 accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
40 connect(cacheCheckBox, SIGNAL(toggled(bool)),
41 this, SLOT(setGenerateCache(bool)));
43 connect(accentsCheckBox, SIGNAL(toggled(bool)),
44 this, SLOT(setAccents(bool)));
47 connect(accentsInfoToolButton, SIGNAL(clicked()),
48 this, SLOT(showAccentsInfo()));
50 connect(cacheInfoToolButton, SIGNAL(clicked()),
51 this, SLOT(showCacheInfo()));
55 connect(browseButton, SIGNAL(clicked()),
56 this, SLOT(selectFile()));
58 connect(downloadButton, SIGNAL(clicked()),
59 this, SLOT(downloadFile()));
61 connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
62 this, SLOT(fileDownloaded(QString)));
65 connect(confirmButton, SIGNAL(clicked()),
66 this, SLOT(accept()));
70 void XdxfDialog::fileDownloaded(QString name) {
71 infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
72 _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
77 void XdxfDialog::initializeUI() {
78 mainVerticalLayout = new QVBoxLayout;
80 widget->setLayout(mainVerticalLayout);
82 infoLabel = new QLabel;
83 infoLabel->setWordWrap(true);
86 setWindowTitle(tr("Add new XDXF dictionary"));
88 browseLayout = new QHBoxLayout;
90 QHBoxLayout* buttonLayout = new QHBoxLayout;
91 browseButton = new QPushButton(tr("Browse"));
92 browseButton->setMaximumWidth(100);
94 downloadButton = new QPushButton(tr("Download"));
95 downloadButton->setMaximumWidth(150);
97 infoLabel->setText(tr("Dictionary file: not selected"));
99 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
101 browseLayout->addLayout(buttonLayout);
102 buttonLayout->addWidget(browseButton);
103 buttonLayout->addWidget(downloadButton);
105 mainVerticalLayout->addLayout(browseLayout);
108 setWindowTitle(tr("XDXF Settings"));
110 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
111 tr("From: ") + plugin->langFrom() + "\n" +
112 tr("To: ") + plugin->langTo() + "\n" +
113 tr("Description: ") + plugin->name() + "\n" +
115 mainVerticalLayout->addWidget(infoLabel);
118 accentsLayout = new QHBoxLayout;
119 accentsCheckBox = new QCheckBox(tr("Strip accents"));
120 accentsCheckBox->setToolTip(accentsToolTip);
121 accentsLayout->addWidget(accentsCheckBox);
123 accentsInfoToolButton = new QToolButton;
124 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
125 accentsLayout->addWidget(accentsInfoToolButton);
128 cacheLayout = new QHBoxLayout;
129 cacheCheckBox = new QCheckBox(tr("Optimize"));
130 cacheCheckBox->setToolTip(cacheToolTip);
131 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);
142 //load old setting if exists
144 cacheCheckBox->setChecked(true);
145 accentsCheckBox->setChecked(true);
146 accentsCheckBox->setEnabled(false);
147 _generateCache = true;
149 _dictionaryFilePath = "";
151 else if(plugin && plugin->settings()->value("cached") == "true") {
152 cacheCheckBox->setChecked(true);
153 accentsCheckBox->setChecked(true);
154 accentsCheckBox->setEnabled(false);
155 _generateCache = true;
159 cacheCheckBox->setChecked(false);
160 _generateCache = false;
162 if(plugin->settings()->value("strip_accents") == "true") {
163 accentsCheckBox->setChecked(true);
167 accentsCheckBox->setChecked(false);
172 confirmButton = new QPushButton;
173 mainVerticalLayout->addWidget(confirmButton);
175 confirmButton->setText(tr("Add"));
178 confirmButton->setText(tr("Save settings"));
181 scrollArea = new QScrollArea;
182 scrollArea->setWidget(widget);
183 scrollArea->setWidgetResizable(true);
185 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
188 infoLabel->setMinimumWidth(250);
189 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
190 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
191 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
195 layout = new QHBoxLayout;
196 layout->addWidget(scrollArea);
200 setMinimumSize(450,200);
202 setMinimumHeight(350);
205 scrollArea->setLineWidth(0);
206 scrollArea->setMidLineWidth(0);
207 scrollArea->setFrameStyle(QFrame::NoFrame);
213 void XdxfDialog::setAccents(bool accents) {
217 void XdxfDialog::setGenerateCache(bool generate) {
218 _generateCache = generate;
221 _lastAccents = _accents;
222 accentsCheckBox->setChecked(true);
225 accentsCheckBox->setChecked(_lastAccents);
227 accentsCheckBox->setEnabled(!generate);
230 void XdxfDialog::selectFile() {
231 QString fileName = QFileDialog::getOpenFileName(this,
232 tr("Select dictionary file"),
234 tr("XDXF Files (*.xdxf)"),
238 if (!fileName.isEmpty()) {
239 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
240 _dictionaryFilePath = fileName;
245 void XdxfDialog::downloadFile() {
247 XdxfPlugin::dictDownloader.download(this);
250 void XdxfDialog::saveSettings() {
251 _settings = new Settings;
253 foreach(QString key, plugin->settings()->keys())
254 _settings->setValue(key, plugin->settings()->value(key));
257 _settings->setValue("path", _dictionaryFilePath);
261 _settings->setValue("generateCache", "true");
263 _settings->setValue("generateCache", "false");
266 _settings->setValue("strip_accents", "true");
268 _settings->setValue("strip_accents", "false");
271 void XdxfDialog::accept() {
272 if(type == New && _dictionaryFilePath.isEmpty()) {
273 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
282 Settings* XdxfDialog::getSettings() {
287 void XdxfDialog::showCacheInfo() {
288 Q_EMIT notify(Notify::Warning, cacheToolTip);
291 void XdxfDialog::showAccentsInfo() {
292 Q_EMIT notify(Notify::Warning, accentsToolTip);