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 "StarDialog.h"
27 StarDialog::StarDialog(StarDictPlugin *plugin,
31 this->plugin = plugin;
34 accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
39 connect(accentsCheckBox, SIGNAL(toggled(bool)),
40 this, SLOT(setAccents(bool)));
43 connect(accentsInfoToolButton, SIGNAL(clicked()),
48 connect(browseButton, SIGNAL(clicked()),
49 this, SLOT(selectFile()));
52 connect(confirmButton, SIGNAL(clicked()),
53 this, SLOT(accept()));
58 void StarDialog::initializeUI() {
59 mainVerticalLayout = new QVBoxLayout;
61 widget->setLayout(mainVerticalLayout);
63 infoLabel = new QLabel;
64 infoLabel->setWordWrap(true);
67 setWindowTitle(tr("Add new StarDict dictionary"));
69 browseLayout = new QHBoxLayout;
70 browseButton = new QPushButton(tr("Browse"));
71 infoLabel->setText(tr("Dictionary file: not selected"));
73 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
74 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
76 mainVerticalLayout->addLayout(browseLayout);
79 setWindowTitle(tr("StarDict Settings"));
81 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
82 tr("From: ") + plugin->langFrom() + "\n" +
83 tr("To: ") + plugin->langTo() + "\n" +
84 tr("Description: ") + plugin->name() + "\n" +
86 mainVerticalLayout->addWidget(infoLabel);
89 accentsLayout = new QHBoxLayout;
90 accentsCheckBox = new QCheckBox(tr("Strip accents"));
91 accentsCheckBox->setToolTip(accentsToolTip);
92 accentsLayout->addWidget(accentsCheckBox);
94 accentsInfoToolButton = new QToolButton;
95 accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
96 accentsLayout->addWidget(accentsInfoToolButton);
100 mainVerticalLayout->addLayout(accentsLayout);
103 //load old setting if exists
105 accentsCheckBox->setChecked(true);
106 accentsCheckBox->setEnabled(false);
108 _dictionaryFilePath = "";
110 else if(plugin && plugin->settings()->value("cached") == "true") {
111 accentsCheckBox->setChecked(true);
112 accentsCheckBox->setEnabled(false);
116 if(plugin->settings()->value("strip_accents") == "true") {
117 accentsCheckBox->setChecked(true);
121 accentsCheckBox->setChecked(false);
126 confirmButton = new QPushButton;
127 mainVerticalLayout->addWidget(confirmButton);
129 confirmButton->setText(tr("Add"));
132 confirmButton->setText(tr("Save settings"));
135 scrollArea = new QScrollArea;
136 scrollArea->setWidget(widget);
137 scrollArea->setWidgetResizable(true);
139 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
142 infoLabel->setMinimumWidth(200);
143 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
144 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
145 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
149 layout = new QHBoxLayout;
150 layout->addWidget(scrollArea);
154 setMinimumSize(400,200);
156 setMinimumHeight(350);
159 scrollArea->setLineWidth(0);
160 scrollArea->setMidLineWidth(0);
161 scrollArea->setFrameStyle(QFrame::NoFrame);
167 void StarDialog::setAccents(bool accents) {
172 void StarDialog::selectFile() {
173 QString fileName = QFileDialog::getOpenFileName(this,
174 tr("Select dictionary file"),
176 tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
180 if (!fileName.isEmpty()) {
181 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
182 _dictionaryFilePath = fileName;
187 void StarDialog::saveSettings() {
188 _settings = new Settings;
190 foreach(QString key, plugin->settings()->keys())
191 _settings->setValue(key, plugin->settings()->value(key));
194 _settings->setValue("path", _dictionaryFilePath);
197 _settings->setValue("strip_accents", "true");
199 _settings->setValue("strip_accents", "false");
202 void StarDialog::accept() {
203 if(type == New && _dictionaryFilePath.isEmpty()) {
204 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
213 Settings* StarDialog::getSettings() {
218 void StarDialog::showAccentsInfo() {
219 Q_EMIT notify(Notify::Warning, accentsToolTip);