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()));
62 connect(confirmButton, SIGNAL(clicked()),
63 this, SLOT(accept()));
68 void XdxfDialog::initializeUI() {
69 mainVerticalLayout = new QVBoxLayout;
71 widget->setLayout(mainVerticalLayout);
73 infoLabel = new QLabel;
74 infoLabel->setWordWrap(true);
77 setWindowTitle(tr("Add new XDXF dictionary"));
79 browseLayout = new QHBoxLayout;
81 QHBoxLayout* buttonLayout = new QHBoxLayout;
82 browseButton = new QPushButton(tr("Browse"));
83 browseButton->setMaximumWidth(150);
85 downloadButton = new QPushButton(tr("Download"));
86 downloadButton->setMaximumWidth(150);
88 infoLabel->setText(tr("Dictionary file: not selected"));
90 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
92 browseLayout->addLayout(buttonLayout);
93 buttonLayout->addWidget(browseButton);
94 buttonLayout->addWidget(downloadButton);
96 mainVerticalLayout->addLayout(browseLayout);
99 setWindowTitle(tr("XDXF Settings"));
101 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
102 tr("From: ") + plugin->langFrom() + "\n" +
103 tr("To: ") + plugin->langTo() + "\n" +
104 tr("Description: ") + plugin->name() + "\n" +
106 mainVerticalLayout->addWidget(infoLabel);
109 accentsLayout = new QHBoxLayout;
110 accentsCheckBox = new QCheckBox(tr("Strip accents"));
111 accentsCheckBox->setToolTip(accentsToolTip);
112 accentsLayout->addWidget(accentsCheckBox);
114 accentsInfoToolButton = new QToolButton;
115 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
116 accentsLayout->addWidget(accentsInfoToolButton);
119 cacheLayout = new QHBoxLayout;
120 cacheCheckBox = new QCheckBox(tr("Optimize"));
121 cacheCheckBox->setToolTip(cacheToolTip);
122 cacheLayout->addWidget(cacheCheckBox);
124 cacheInfoToolButton = new QToolButton;
125 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
126 cacheLayout->addWidget(cacheInfoToolButton);
129 mainVerticalLayout->addLayout(cacheLayout);
130 mainVerticalLayout->addLayout(accentsLayout);
133 //load old setting if exists
135 cacheCheckBox->setChecked(true);
136 accentsCheckBox->setChecked(true);
137 accentsCheckBox->setEnabled(false);
138 _generateCache = true;
140 _dictionaryFilePath = "";
142 else if(plugin && plugin->settings()->value("cached") == "true") {
143 cacheCheckBox->setChecked(true);
144 accentsCheckBox->setChecked(true);
145 accentsCheckBox->setEnabled(false);
146 _generateCache = true;
150 cacheCheckBox->setChecked(false);
151 _generateCache = false;
153 if(plugin->settings()->value("strip_accents") == "true") {
154 accentsCheckBox->setChecked(true);
158 accentsCheckBox->setChecked(false);
163 confirmButton = new QPushButton;
164 mainVerticalLayout->addWidget(confirmButton);
166 confirmButton->setText(tr("Add"));
169 confirmButton->setText(tr("Save settings"));
172 scrollArea = new QScrollArea;
173 scrollArea->setWidget(widget);
174 scrollArea->setWidgetResizable(true);
176 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
179 infoLabel->setMinimumWidth(200);
180 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
181 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
182 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
186 layout = new QHBoxLayout;
187 layout->addWidget(scrollArea);
191 setMinimumSize(400,200);
193 setMinimumHeight(350);
196 scrollArea->setLineWidth(0);
197 scrollArea->setMidLineWidth(0);
198 scrollArea->setFrameStyle(QFrame::NoFrame);
204 void XdxfDialog::setAccents(bool accents) {
208 void XdxfDialog::setGenerateCache(bool generate) {
209 _generateCache = generate;
212 _lastAccents = _accents;
213 accentsCheckBox->setChecked(true);
216 accentsCheckBox->setChecked(_lastAccents);
218 accentsCheckBox->setEnabled(!generate);
221 void XdxfDialog::selectFile() {
222 QString fileName = QFileDialog::getOpenFileName(this,
223 tr("Select dictionary file"),
225 tr("XDXF Files (*.xdxf)"),
229 if (!fileName.isEmpty()) {
230 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
231 _dictionaryFilePath = fileName;
236 void XdxfDialog::downloadFile() {
237 XdxfPlugin::dictDownloader.download(this);
240 void XdxfDialog::saveSettings() {
241 _settings = new Settings;
243 foreach(QString key, plugin->settings()->keys())
244 _settings->setValue(key, plugin->settings()->value(key));
247 _settings->setValue("path", _dictionaryFilePath);
251 _settings->setValue("generateCache", "true");
253 _settings->setValue("generateCache", "false");
256 _settings->setValue("strip_accents", "true");
258 _settings->setValue("strip_accents", "false");
261 void XdxfDialog::accept() {
262 if(type == New && _dictionaryFilePath.isEmpty()) {
263 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
272 Settings* XdxfDialog::getSettings() {
277 void XdxfDialog::showCacheInfo() {
278 Q_EMIT notify(Notify::Warning, cacheToolTip);
281 void XdxfDialog::showAccentsInfo() {
282 Q_EMIT notify(Notify::Warning, accentsToolTip);