a63b258b52e38cab2e82d3368d17bfa6596d73b5
[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     accept();
81 }
82
83 QString XdxfLoadDialog::dicitonaryFilePath() {
84     return _dicitonaryFilePath;
85 }
86
87 bool XdxfLoadDialog::generateCache() {
88     return _generateCache;
89 }
90
91 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
92     XdxfLoadDialog loadDialog(parent);
93     Settings* settings = new Settings;
94
95     if(loadDialog.exec()==QDialog::Accepted) {
96         settings->setValue("path", loadDialog.dicitonaryFilePath());
97         if(loadDialog.generateCache()) {
98             settings->setValue("cache", "true");
99         }
100         else {
101             settings->setValue("cache", "false");
102         }
103
104         return settings;
105     }
106
107     return NULL;
108 }
109
110