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 infoLayout = new QHBoxLayout;
98 infoLayout->addWidget(infoLabel,0,Qt::AlignLeft);
99 infoLabel->setText(tr("Dictionary file: not selected"));
101 browseLayout->addLayout(buttonLayout);
102 buttonLayout->addWidget(browseButton);
103 buttonLayout->addWidget(downloadButton);
105 mainVerticalLayout->addLayout(browseLayout);
106 mainVerticalLayout->addLayout(infoLayout);
109 setWindowTitle(tr("XDXF Settings"));
111 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
112 tr("From: ") + plugin->langFrom() + "\n" +
113 tr("To: ") + plugin->langTo() + "\n" +
114 tr("Description: ") + plugin->name() + "\n" +
116 mainVerticalLayout->addWidget(infoLabel);
119 accentsLayout = new QHBoxLayout;
120 accentsCheckBox = new QCheckBox(tr("Strip accents"));
121 accentsCheckBox->setToolTip(accentsToolTip);
122 accentsLayout->addWidget(accentsCheckBox);
124 accentsInfoToolButton = new QToolButton;
125 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
126 accentsLayout->addWidget(accentsInfoToolButton);
129 cacheLayout = new QHBoxLayout;
130 cacheCheckBox = new QCheckBox(tr("Optimize"));
131 cacheCheckBox->setToolTip(cacheToolTip);
132 cacheLayout->addWidget(cacheCheckBox);
135 cacheInfoToolButton = new QToolButton;
136 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
137 cacheLayout->addWidget(cacheInfoToolButton);
140 mainVerticalLayout->addLayout(cacheLayout);
141 mainVerticalLayout->addLayout(accentsLayout);
144 //load old setting if exists
146 cacheCheckBox->setChecked(true);
147 accentsCheckBox->setChecked(true);
148 accentsCheckBox->setEnabled(false);
149 _generateCache = true;
151 _dictionaryFilePath = "";
153 else if(plugin && plugin->settings()->value("cached") == "true") {
154 cacheCheckBox->setChecked(true);
155 accentsCheckBox->setChecked(true);
156 accentsCheckBox->setEnabled(false);
157 _generateCache = true;
161 cacheCheckBox->setChecked(false);
162 _generateCache = false;
164 if(plugin->settings()->value("strip_accents") == "true") {
165 accentsCheckBox->setChecked(true);
169 accentsCheckBox->setChecked(false);
174 confirmButton = new QPushButton;
175 mainVerticalLayout->addWidget(confirmButton);
177 confirmButton->setText(tr("Add"));
180 confirmButton->setText(tr("Save settings"));
183 scrollArea = new QScrollArea;
184 scrollArea->setWidget(widget);
185 scrollArea->setWidgetResizable(true);
187 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
190 infoLabel->setMinimumWidth(550);
191 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
192 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
193 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
197 layout = new QHBoxLayout;
198 layout->addWidget(scrollArea);
202 setMinimumSize(600,200);
204 setMinimumHeight(350);
207 scrollArea->setLineWidth(0);
208 scrollArea->setMidLineWidth(0);
209 scrollArea->setFrameStyle(QFrame::NoFrame);
215 void XdxfDialog::setAccents(bool accents) {
219 void XdxfDialog::setGenerateCache(bool generate) {
220 _generateCache = generate;
223 _lastAccents = _accents;
224 accentsCheckBox->setChecked(true);
227 accentsCheckBox->setChecked(_lastAccents);
229 accentsCheckBox->setEnabled(!generate);
232 void XdxfDialog::selectFile() {
233 QString fileName = QFileDialog::getOpenFileName(this,
234 tr("Select dictionary file"),
236 tr("XDXF Files (*.xdxf)"),
240 if (!fileName.isEmpty()) {
241 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
242 _dictionaryFilePath = fileName;
247 void XdxfDialog::downloadFile() {
248 XdxfPlugin::dictDownloader.download(this);
251 void XdxfDialog::saveSettings() {
252 _settings = new Settings;
254 foreach(QString key, plugin->settings()->keys())
255 _settings->setValue(key, plugin->settings()->value(key));
258 _settings->setValue("path", _dictionaryFilePath);
262 _settings->setValue("generateCache", "true");
264 _settings->setValue("generateCache", "false");
267 _settings->setValue("strip_accents", "true");
269 _settings->setValue("strip_accents", "false");
272 void XdxfDialog::accept() {
273 if(type == New && _dictionaryFilePath.isEmpty()) {
274 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
283 Settings* XdxfDialog::getSettings() {
288 void XdxfDialog::showCacheInfo() {
289 Q_EMIT notify(Notify::Warning, cacheToolTip);
292 void XdxfDialog::showAccentsInfo() {
293 Q_EMIT notify(Notify::Warning, accentsToolTip);