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);
47 browseLayout = new QHBoxLayout;
48 browseButton = new QPushButton(tr("Browse"));
50 setWindowTitle(tr("Add new StarDict dictionary"));
51 infoLabel->setText(tr("Dictionary file: not selected"));
52 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
53 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
54 mainVerticalLayout->addLayout(browseLayout);
57 setWindowTitle(tr("StarDict Settings"));
58 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
59 tr("Book name: ") + plugin->settings()->value("bookname")
61 tr("Version: ") + plugin->settings()->value("version") + "\n" +
62 tr("Word count: ") + plugin->settings()->value("wordcount")
64 tr("Author: ") + plugin->settings()->value("author") + "\n" +
65 tr("E-mail: ") + plugin->settings()->value("email") + "\n" +
66 tr("Website: ") + plugin->settings()->value("website") + "\n" +
67 tr("Description: ") + plugin->settings()->value("description")
69 tr("Date: ") + plugin->settings()->value("date"));
70 mainVerticalLayout->addWidget(infoLabel);
74 _dictionaryFilePath = "";
76 confirmButton = new QPushButton;
77 mainVerticalLayout->addWidget(confirmButton);
79 confirmButton->setText(tr("Add"));
81 confirmButton->setText(tr("Save settings"));
83 scrollArea = new QScrollArea;
84 scrollArea->setWidget(widget);
85 scrollArea->setWidgetResizable(true);
87 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
90 infoLabel->setMinimumWidth(200);
91 setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
92 setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
93 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
97 layout = new QHBoxLayout;
98 layout->addWidget(scrollArea);
102 setMinimumSize(400,200);
104 setMinimumHeight(350);
107 scrollArea->setLineWidth(0);
108 scrollArea->setMidLineWidth(0);
109 scrollArea->setFrameStyle(QFrame::NoFrame);
113 void StarDialog::selectFile() {
114 QString fileName = QFileDialog::getOpenFileName(this,
115 tr("Select dictionary file"),
117 tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
120 if (!fileName.isEmpty()) {
121 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
122 _dictionaryFilePath = fileName;
123 if (_dictionaryFilePath.endsWith(".tar.bz2"))
124 _isCompressed = true;
126 _isCompressed = false;
132 void StarDialog::saveSettings() {
133 _settings = new Settings;
136 foreach(QString key, plugin->settings()->keys())
137 _settings->setValue(key, plugin->settings()->value(key));
139 if(_settings->value("path")=="")
140 _settings->setValue("path", _dictionaryFilePath);
142 if(_settings->value("ifoFileName")=="")
143 _settings->setValue("ifoFileName", _dictName + ".ifo");
145 if(_settings->value("idxFileName")=="")
146 _settings->setValue("idxFileName", _dictName + ".idx");
148 if(_settings->value("dictFileName")==""){
149 if (QFile::exists(_dictName + ".dict.dz") == true)
150 _settings->setValue("dictFileName", _dictName + ".dict.dz");
152 _settings->setValue("dictFileName", _dictName + ".dict");
155 if(_settings->value("synFileName")=="")
156 if (QFile::exists(_dictName + ".syn") == true)
157 _settings->setValue("synFileName", _dictName + ".syn");
161 void StarDialog::accept() {
162 if(type == New && _dictionaryFilePath.isEmpty()) {
163 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
167 if(type == New && !_dictionaryFilePath.isEmpty() && !checkFiles()) {
168 Q_EMIT notify(Notify::Warning, tr("Dictionary files are not complete"));
177 bool StarDialog::checkFiles() {
178 if (!_isCompressed) {
179 if (_dictionaryFilePath.right(2) == "dz") {
180 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
181 _dictName = _dictName.left(_dictName.lastIndexOf("."));
184 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
188 if (QFile::exists(_dictName + ".idx") == false
189 && QFile::exists(_dictName + ".idx.gz") == false) {
192 if (QFile::exists(_dictName + ".dict") == false
193 && QFile::exists(_dictName + ".dict.dz") == false) {
203 Settings* StarDialog::getSettings() {