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 *******************************************************************************/
23 \brief Implementation of stardict plugin's dialogs.
25 \author Mateusz Półrola <mateusz.polrola@gmail.com>
28 #include "StarDialog.h"
32 StarDialog::StarDialog(StarDictPlugin *plugin, StarDialogType type,
33 QWidget *parent) : QDialog(parent) {
34 this->plugin = plugin;
38 connect(browseButton, SIGNAL(clicked()),this, SLOT(selectFile()));
39 connect(confirmButton, SIGNAL(clicked()),this, SLOT(accept()));
43 void StarDialog::initializeUI() {
44 mainVerticalLayout = new QVBoxLayout;
46 widget->setLayout(mainVerticalLayout);
47 infoLabel = new QLabel;
48 infoLabel->setWordWrap(true);
49 QVBoxLayout* buttonLayout = new QVBoxLayout;
52 browseLayout = new QHBoxLayout;
53 browseButton = new QPushButton(tr("Browse"));
54 browseButton->setMaximumWidth(150);
55 infoLabel->setText(tr("Dictionary file: not selected"));
56 setWindowTitle(tr("Add new StarDict dictionary"));
57 infoLabel->setText(tr("Dictionary file: not selected"));
58 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
59 browseLayout->addLayout(buttonLayout);
60 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
61 mainVerticalLayout->addLayout(browseLayout);
64 setWindowTitle(tr("StarDict Settings"));
65 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
66 tr("Book name: ") + plugin->settings()->value("bookname")
68 tr("Version: ") + plugin->settings()->value("version") + "\n" +
69 tr("Word count: ") + plugin->settings()->value("wordcount")
71 tr("Author: ") + plugin->settings()->value("author") + "\n" +
72 tr("E-mail: ") + plugin->settings()->value("email") + "\n" +
73 tr("Website: ") + plugin->settings()->value("website") + "\n" +
74 tr("Description: ") + plugin->settings()->value("description")
76 tr("Date: ") + plugin->settings()->value("date"));
77 mainVerticalLayout->addWidget(infoLabel);
81 _dictionaryFilePath = "";
83 confirmButton = new QPushButton;
84 mainVerticalLayout->addWidget(confirmButton);
86 confirmButton->setText(tr("Add"));
88 confirmButton->setText(tr("Save settings"));
90 scrollArea = new QScrollArea;
91 scrollArea->setWidget(widget);
92 scrollArea->setWidgetResizable(true);
94 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
97 infoLabel->setMinimumWidth(200);
98 // setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
99 // setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
100 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
104 layout = new QHBoxLayout;
105 layout->addWidget(scrollArea);
109 setMinimumSize(400,200);
111 setMinimumHeight(350);
114 scrollArea->setLineWidth(0);
115 scrollArea->setMidLineWidth(0);
116 scrollArea->setFrameStyle(QFrame::NoFrame);
120 void StarDialog::selectFile() {
121 QString fileName = QFileDialog::getOpenFileName(this,
122 tr("Select dictionary file"),
124 tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
127 if (!fileName.isEmpty()) {
128 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
129 _dictionaryFilePath = fileName;
130 if (_dictionaryFilePath.endsWith(".tar.bz2"))
131 _isCompressed = true;
133 _isCompressed = false;
139 void StarDialog::saveSettings() {
140 _settings = new Settings;
143 foreach(QString key, plugin->settings()->keys())
144 _settings->setValue(key, plugin->settings()->value(key));
146 if(_settings->value("path")=="")
147 _settings->setValue("path", _dictionaryFilePath);
149 if(_settings->value("ifoFileName")=="")
150 _settings->setValue("ifoFileName", _dictName + ".ifo");
152 if(_settings->value("idxFileName")=="")
153 _settings->setValue("idxFileName", _dictName + ".idx");
155 if(_settings->value("dictFileName")==""){
156 if (QFile::exists(_dictName + ".dict.dz") == true)
157 _settings->setValue("dictFileName", _dictName + ".dict.dz");
159 _settings->setValue("dictFileName", _dictName + ".dict");
162 if(_settings->value("synFileName")=="")
163 if (QFile::exists(_dictName + ".syn") == true)
164 _settings->setValue("synFileName", _dictName + ".syn");
168 void StarDialog::accept() {
169 if(type == New && _dictionaryFilePath.isEmpty()) {
170 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
174 if(type == New && !_dictionaryFilePath.isEmpty() && !checkFiles()) {
175 Q_EMIT notify(Notify::Warning, tr("Dictionary files are not complete"));
184 bool StarDialog::checkFiles() {
185 if (!_isCompressed) {
186 if (_dictionaryFilePath.right(2) == "dz") {
187 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
188 _dictName = _dictName.left(_dictName.lastIndexOf("."));
191 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
194 if (QFile::exists(_dictName + ".idx") == false
195 && QFile::exists(_dictName + ".idx.gz") == false) {
198 if (QFile::exists(_dictName + ".dict") == false
199 && QFile::exists(_dictName + ".dict.dz") == false) {
209 Settings* StarDialog::getSettings() {