Merge branch 'cache' of ssh://drop.maemo.org/git/mdictionary into cache
[mdictionary] / trunk / src / plugins / xdxf / src / XdxfLoadDialog.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
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.
9
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.
14
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/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 //Created by Mateusz Półrola
23
24 #include "XdxfLoadDialog.h"
25
26 XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
27     QDialog(parent) {
28     verticalLayout = new QVBoxLayout;
29     setLayout(verticalLayout);
30
31     setWindowTitle(tr("Add new XDXF dictionary"));
32
33     browseLayout = new QHBoxLayout;
34     verticalLayout->addLayout(browseLayout);
35
36     browseButton =  new QPushButton(tr("Browse"));
37     browseLabel = new QLabel(tr("Dictionary file: not selected"));
38
39     browseLayout->addWidget(browseLabel);
40     browseLayout->addWidget(browseButton,0, Qt::AlignRight);
41
42
43     cacheLayout = new QHBoxLayout;
44     verticalLayout->addLayout(cacheLayout);
45
46     cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"));
47     cacheCheckBox->setChecked(true);
48     cacheLayout->addWidget(cacheCheckBox);
49
50     addButton = new QPushButton(tr("Add"));
51
52     verticalLayout->addWidget(addButton);
53
54     setModal(true);
55
56     connect(browseButton, SIGNAL(clicked()),
57             this, SLOT(selectFile()));
58
59     connect(addButton, SIGNAL(clicked()),
60             this, SLOT(addDictionary()));
61
62     _dicitonaryFilePath = QString();
63 }
64
65 void XdxfLoadDialog::selectFile() {
66     QString fileName = QFileDialog::getOpenFileName(this,
67                                      tr("Select dictionary file"),
68                                      "",
69                                      tr("XDXF Files (*.xdxf)"),
70                                      NULL,
71                                      NULL);
72     if (!fileName.isEmpty()) {
73         browseLabel->setText(tr("Dictionary file: ") + fileName);
74         _dicitonaryFilePath = fileName;
75     }
76 }
77
78 void XdxfLoadDialog::addDictionary() {
79     _generateCache = cacheCheckBox->isChecked();
80     if(!_dicitonaryFilePath.isEmpty()) {
81         accept();
82     }
83     else {
84         reject();
85     }
86 }
87
88 QString XdxfLoadDialog::dicitonaryFilePath() {
89     return _dicitonaryFilePath;
90 }
91
92 bool XdxfLoadDialog::generateCache() {
93     return _generateCache;
94 }
95
96 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
97     XdxfLoadDialog loadDialog(parent);
98     Settings* settings = new Settings;
99
100     if(loadDialog.exec()==QDialog::Accepted) {
101         settings->setValue("path", loadDialog.dicitonaryFilePath());
102         if(loadDialog.generateCache()) {
103             settings->setValue("cached", "true");
104         }
105         else {
106             settings->setValue("cached", "false");
107         }
108
109         return settings;
110     }
111
112     return NULL;
113 }
114
115