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"
28 StarDialog::StarDialog(StarDictPlugin *plugin, StarDialogType type,
29 QWidget *parent) : QDialog(parent) {
30 this->plugin = plugin;
34 connect(browseButton, SIGNAL(clicked()),this, SLOT(selectFile()));
35 connect(confirmButton, SIGNAL(clicked()),this, SLOT(accept()));
39 void StarDialog::initializeUI() {
40 mainVerticalLayout = new QVBoxLayout;
42 widget->setLayout(mainVerticalLayout);
43 infoLabel = new QLabel;
44 infoLabel->setWordWrap(true);
45 QVBoxLayout* buttonLayout = new QVBoxLayout;
48 browseLayout = new QHBoxLayout;
49 browseButton = new QPushButton(tr("Browse"));
50 browseButton->setMaximumWidth(150);
51 infoLabel->setText(tr("Dictionary file: not selected"));
52 setWindowTitle(tr("Add new StarDict dictionary"));
53 infoLabel->setText(tr("Dictionary file: not selected"));
54 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
55 browseLayout->addLayout(buttonLayout);
56 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
57 mainVerticalLayout->addLayout(browseLayout);
60 setWindowTitle(tr("StarDict Settings"));
61 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
62 tr("Book name: ") + plugin->settings()->value("bookname")
64 tr("Version: ") + plugin->settings()->value("version") + "\n" +
65 tr("Word count: ") + plugin->settings()->value("wordcount")
67 tr("Author: ") + plugin->settings()->value("author") + "\n" +
68 tr("E-mail: ") + plugin->settings()->value("email") + "\n" +
69 tr("Website: ") + plugin->settings()->value("website") + "\n" +
70 tr("Description: ") + plugin->settings()->value("description")
72 tr("Date: ") + plugin->settings()->value("date"));
73 mainVerticalLayout->addWidget(infoLabel);
77 _dictionaryFilePath = "";
79 confirmButton = new QPushButton;
80 mainVerticalLayout->addWidget(confirmButton);
82 confirmButton->setText(tr("Add"));
84 confirmButton->setText(tr("Save settings"));
86 scrollArea = new QScrollArea;
87 scrollArea->setWidget(widget);
88 scrollArea->setWidgetResizable(true);
90 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93 infoLabel->setMinimumWidth(200);
94 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
95 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
96 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
100 layout = new QHBoxLayout;
101 layout->addWidget(scrollArea);
105 setMinimumSize(400,200);
107 setMinimumHeight(350);
110 scrollArea->setLineWidth(0);
111 scrollArea->setMidLineWidth(0);
112 scrollArea->setFrameStyle(QFrame::NoFrame);
116 void StarDialog::selectFile() {
117 QString fileName = QFileDialog::getOpenFileName(this,
118 tr("Select dictionary file"),
120 tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
123 if (!fileName.isEmpty()) {
124 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
125 _dictionaryFilePath = fileName;
126 if (_dictionaryFilePath.endsWith(".tar.bz2"))
127 _isCompressed = true;
129 _isCompressed = false;
135 void StarDialog::saveSettings() {
136 _settings = new Settings;
139 foreach(QString key, plugin->settings()->keys())
140 _settings->setValue(key, plugin->settings()->value(key));
142 if(_settings->value("path")=="")
143 _settings->setValue("path", _dictionaryFilePath);
145 if(_settings->value("ifoFileName")=="")
146 _settings->setValue("ifoFileName", _dictName + ".ifo");
148 if(_settings->value("idxFileName")=="")
149 _settings->setValue("idxFileName", _dictName + ".idx");
151 if(_settings->value("dictFileName")==""){
152 if (QFile::exists(_dictName + ".dict.dz") == true)
153 _settings->setValue("dictFileName", _dictName + ".dict.dz");
155 _settings->setValue("dictFileName", _dictName + ".dict");
158 if(_settings->value("synFileName")=="")
159 if (QFile::exists(_dictName + ".syn") == true)
160 _settings->setValue("synFileName", _dictName + ".syn");
164 void StarDialog::accept() {
165 if(type == New && _dictionaryFilePath.isEmpty()) {
166 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
170 if(type == New && !_dictionaryFilePath.isEmpty() && !checkFiles()) {
171 Q_EMIT notify(Notify::Warning, tr("Dictionary files are not complete"));
180 bool StarDialog::checkFiles() {
181 if (!_isCompressed) {
182 if (_dictionaryFilePath.right(2) == "dz") {
183 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
184 _dictName = _dictName.left(_dictName.lastIndexOf("."));
187 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
191 if (QFile::exists(_dictName + ".idx") == false
192 && QFile::exists(_dictName + ".idx.gz") == false) {
195 if (QFile::exists(_dictName + ".dict") == false
196 && QFile::exists(_dictName + ".dict.dz") == false) {
206 Settings* StarDialog::getSettings() {