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 \author Mateusz Półrola <mateusz.polrola@gmail.com>
26 #include "StarDialog.h"
30 StarDialog::StarDialog(StarDictPlugin *plugin, StarDialogType type,
31 QWidget *parent) : QDialog(parent) {
32 this->plugin = plugin;
36 connect(browseButton, SIGNAL(clicked()),this, SLOT(selectFile()));
37 connect(confirmButton, SIGNAL(clicked()),this, SLOT(accept()));
41 void StarDialog::initializeUI() {
42 mainVerticalLayout = new QVBoxLayout;
44 widget->setLayout(mainVerticalLayout);
45 infoLabel = new QLabel;
46 infoLabel->setWordWrap(true);
47 QVBoxLayout* buttonLayout = new QVBoxLayout;
50 browseLayout = new QHBoxLayout;
51 browseButton = new QPushButton(tr("Browse"));
52 browseButton->setMaximumWidth(150);
53 infoLabel->setText(tr("Dictionary file: not selected"));
54 setWindowTitle(tr("Add new StarDict dictionary"));
55 infoLabel->setText(tr("Dictionary file: not selected"));
56 browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
57 browseLayout->addLayout(buttonLayout);
58 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
59 mainVerticalLayout->addLayout(browseLayout);
62 setWindowTitle(tr("StarDict Settings"));
63 infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
64 tr("Book name: ") + plugin->settings()->value("bookname")
66 tr("Version: ") + plugin->settings()->value("version") + "\n" +
67 tr("Word count: ") + plugin->settings()->value("wordcount")
69 tr("Author: ") + plugin->settings()->value("author") + "\n" +
70 tr("E-mail: ") + plugin->settings()->value("email") + "\n" +
71 tr("Website: ") + plugin->settings()->value("website") + "\n" +
72 tr("Description: ") + plugin->settings()->value("description")
74 tr("Date: ") + plugin->settings()->value("date"));
75 mainVerticalLayout->addWidget(infoLabel);
79 _dictionaryFilePath = "";
81 confirmButton = new QPushButton;
82 mainVerticalLayout->addWidget(confirmButton);
84 confirmButton->setText(tr("Add"));
86 confirmButton->setText(tr("Save settings"));
88 scrollArea = new QScrollArea;
89 scrollArea->setWidget(widget);
90 scrollArea->setWidgetResizable(true);
92 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 infoLabel->setMinimumWidth(200);
96 // setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
97 // setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
98 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
102 layout = new QHBoxLayout;
103 layout->addWidget(scrollArea);
107 setMinimumSize(400,200);
109 setMinimumHeight(350);
112 scrollArea->setLineWidth(0);
113 scrollArea->setMidLineWidth(0);
114 scrollArea->setFrameStyle(QFrame::NoFrame);
118 void StarDialog::selectFile() {
119 QString fileName = QFileDialog::getOpenFileName(this,
120 tr("Select dictionary file"),
122 tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
125 if (!fileName.isEmpty()) {
126 infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
127 _dictionaryFilePath = fileName;
128 if (_dictionaryFilePath.endsWith(".tar.bz2"))
129 _isCompressed = true;
131 _isCompressed = false;
137 void StarDialog::saveSettings() {
138 _settings = new Settings;
141 foreach(QString key, plugin->settings()->keys())
142 _settings->setValue(key, plugin->settings()->value(key));
144 if(_settings->value("path")=="")
145 _settings->setValue("path", _dictionaryFilePath);
147 if(_settings->value("ifoFileName")=="")
148 _settings->setValue("ifoFileName", _dictName + ".ifo");
150 if(_settings->value("idxFileName")=="")
151 _settings->setValue("idxFileName", _dictName + ".idx");
153 if(_settings->value("dictFileName")==""){
154 if (QFile::exists(_dictName + ".dict.dz") == true)
155 _settings->setValue("dictFileName", _dictName + ".dict.dz");
157 _settings->setValue("dictFileName", _dictName + ".dict");
160 if(_settings->value("synFileName")=="")
161 if (QFile::exists(_dictName + ".syn") == true)
162 _settings->setValue("synFileName", _dictName + ".syn");
166 void StarDialog::accept() {
167 if(type == New && _dictionaryFilePath.isEmpty()) {
168 Q_EMIT notify(Notify::Warning, tr("File path is not set"));
172 if(type == New && !_dictionaryFilePath.isEmpty() && !checkFiles()) {
173 Q_EMIT notify(Notify::Warning, tr("Dictionary files are not complete"));
182 bool StarDialog::checkFiles() {
183 if (!_isCompressed) {
184 if (_dictionaryFilePath.right(2) == "dz") {
185 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
186 _dictName = _dictName.left(_dictName.lastIndexOf("."));
189 _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
192 if (QFile::exists(_dictName + ".idx") == false
193 && QFile::exists(_dictName + ".idx.gz") == false) {
196 if (QFile::exists(_dictName + ".dict") == false
197 && QFile::exists(_dictName + ".dict.dz") == false) {
207 Settings* StarDialog::getSettings() {