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()));
59 connect(confirmButton, SIGNAL(clicked()),
60 this, SLOT(accept()));
65 void XdxfDialog::initializeUI() {
66 mainVerticalLayout = new QVBoxLayout;
68 widget->setLayout(mainVerticalLayout);
70 infoLabel = new QLabel;
71 infoLabel->setWordWrap(true);
74 setWindowTitle(tr("Add new XDXF dictionary"));
76 browseLayout = new QHBoxLayout;
77 browseButton = new QPushButton(tr("Browse"));
78 infoLabel->setText(tr("Dictionary file: not selected"));
80 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
81 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
83 mainVerticalLayout->addLayout(browseLayout);
86 setWindowTitle(tr("XDXF Settings"));
88 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
89 tr("From: ") + plugin->langFrom() + "\n" +
90 tr("To: ") + plugin->langTo() + "\n" +
91 tr("Description: ") + plugin->name() + "\n" +
93 mainVerticalLayout->addWidget(infoLabel);
96 accentsLayout = new QHBoxLayout;
97 accentsCheckBox = new QCheckBox(tr("Strip accents"));
98 accentsCheckBox->setToolTip(accentsToolTip);
99 accentsLayout->addWidget(accentsCheckBox);
101 accentsInfoToolButton = new QToolButton;
102 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
103 accentsLayout->addWidget(accentsInfoToolButton);
106 cacheLayout = new QHBoxLayout;
107 cacheCheckBox = new QCheckBox(tr("Optimize"));
108 cacheCheckBox->setToolTip(cacheToolTip);
109 cacheLayout->addWidget(cacheCheckBox);
111 cacheInfoToolButton = new QToolButton;
112 cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
113 cacheLayout->addWidget(cacheInfoToolButton);
116 mainVerticalLayout->addLayout(cacheLayout);
117 mainVerticalLayout->addLayout(accentsLayout);
120 //load old setting if exists
122 cacheCheckBox->setChecked(true);
123 accentsCheckBox->setChecked(true);
124 accentsCheckBox->setEnabled(false);
125 _generateCache = true;
127 _dictionaryFilePath = "";
129 else if(plugin && plugin->settings()->value("cached") == "true") {
130 cacheCheckBox->setChecked(true);
131 accentsCheckBox->setChecked(true);
132 accentsCheckBox->setEnabled(false);
133 _generateCache = true;
137 cacheCheckBox->setChecked(false);
138 _generateCache = false;
140 if(plugin->settings()->value("strip_accents") == "true") {
141 accentsCheckBox->setChecked(true);
145 accentsCheckBox->setChecked(false);
150 confirmButton = new QPushButton;
151 mainVerticalLayout->addWidget(confirmButton);
153 confirmButton->setText(tr("Add"));
156 confirmButton->setText(tr("Save settings"));
159 scrollArea = new QScrollArea;
160 scrollArea->setWidget(widget);
161 scrollArea->setWidgetResizable(true);
163 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
166 infoLabel->setMinimumWidth(200);
167 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
168 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
169 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
173 layout = new QHBoxLayout;
174 layout->addWidget(scrollArea);
178 setMinimumSize(400,200);
180 setMinimumHeight(350);
183 scrollArea->setLineWidth(0);
184 scrollArea->setMidLineWidth(0);
185 scrollArea->setFrameStyle(QFrame::NoFrame);
191 void XdxfDialog::setAccents(bool accents) {
195 void XdxfDialog::setGenerateCache(bool generate) {
196 _generateCache = generate;
199 _lastAccents = _accents;
200 accentsCheckBox->setChecked(true);
203 accentsCheckBox->setChecked(_lastAccents);
205 accentsCheckBox->setEnabled(!generate);
208 void XdxfDialog::selectFile() {
209 QString fileName = QFileDialog::getOpenFileName(this,
210 tr("Select dictionary file"),
212 tr("XDXF Files (*.xdxf)"),
216 if (!fileName.isEmpty()) {
217 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
218 _dictionaryFilePath = fileName;
223 void XdxfDialog::saveSettings() {
224 _settings = new Settings;
226 foreach(QString key, plugin->settings()->keys())
227 _settings->setValue(key, plugin->settings()->value(key));
230 _settings->setValue("path", _dictionaryFilePath);
234 _settings->setValue("generateCache", "true");
236 _settings->setValue("generateCache", "false");
239 _settings->setValue("strip_accents", "true");
241 _settings->setValue("strip_accents", "false");
244 void XdxfDialog::accept() {
245 if(type == New && _dictionaryFilePath.isEmpty()) {
246 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
255 Settings* XdxfDialog::getSettings() {
260 void XdxfDialog::showCacheInfo() {
261 Q_EMIT notify(Notify::Warning, cacheToolTip);
264 void XdxfDialog::showAccentsInfo() {
265 Q_EMIT notify(Notify::Warning, accentsToolTip);