fix db worning in xdxf plugin
[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;
31     setLayout(verticalLayout);
32
33     setWindowTitle(tr("Add new XDXF dictionary"));
34
35     browseLayout = new QVBoxLayout;
36
37     browseButton =  new QPushButton(tr("Browse"));
38     browseLabel = new QLabel(tr("Dictionary file: not selected"));
39     //browseLabel->setWordWrap(true);
40     browseLabel->setMargin(5);
41
42     browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
43     browseLayout->addWidget(browseButton);
44
45     verticalLayout->addLayout(browseLayout);
46
47     cacheLayout = new QHBoxLayout;
48     verticalLayout->addLayout(cacheLayout);
49     accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more "
50                  "time, but spelling don't have to be exact)"));
51     verticalLayout->addWidget(accentsCheckBox);
52
53     cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
54     cacheCheckBox->setChecked(true);
55     cacheLayout->addWidget(cacheCheckBox);
56
57     addButton = new QPushButton(tr("Add"));
58
59     verticalLayout->addWidget(addButton);
60
61     setModal(true);
62
63     connect(browseButton, SIGNAL(clicked()),
64             this, SLOT(selectFile()));
65
66     connect(addButton, SIGNAL(clicked()),
67             this, SLOT(addDictionary()));
68
69     _dicitonaryFilePath = QString();
70 }
71
72 void XdxfLoadDialog::selectFile() {
73     QString fileName = QFileDialog::getOpenFileName(this,
74                                      tr("Select dictionary file"),
75                                      "",
76                                      tr("XDXF Files (*.xdxf)"),
77                                      NULL,
78                                      NULL);
79
80     if (!fileName.isEmpty()) {
81         browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
82         _dicitonaryFilePath = fileName;
83     }repaint(rect());
84     resize(size());
85 }
86
87 void XdxfLoadDialog::addDictionary() {
88     _generateCache = cacheCheckBox->isChecked();
89     if(!_dicitonaryFilePath.isEmpty()) {
90         accept();
91     }
92     else {
93         reject();
94     }
95 }
96
97 QString XdxfLoadDialog::dicitonaryFilePath() {
98     return _dicitonaryFilePath;
99 }
100
101 bool XdxfLoadDialog::generateCache() {
102     return _generateCache;
103 }
104
105 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
106     XdxfLoadDialog loadDialog(parent);
107     Settings* settings = new Settings;
108
109     if(loadDialog.exec()==QDialog::Accepted) {
110         settings->setValue("path", loadDialog.dicitonaryFilePath());
111         if(loadDialog.generateCache()) {
112             settings->setValue("generateCache", "true");
113         }
114         else {
115             settings->setValue("generateCache", "false");
116         }
117         if(loadDialog.accentsCheckBox->isChecked())
118             settings->setValue("strip_accents", "true");
119         else
120             settings->setValue("strip_accents", "false");
121
122
123         return settings;
124     }
125
126     return NULL;
127 }
128
129