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