fig delete settings
[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         qDebug()<<fileName;
82         browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
83         _dicitonaryFilePath = fileName;
84     }repaint(rect());
85     resize(size());
86 }
87
88 void XdxfLoadDialog::addDictionary() {
89     _generateCache = cacheCheckBox->isChecked();
90     if(!_dicitonaryFilePath.isEmpty()) {
91         accept();
92     }
93     else {
94         reject();
95     }
96 }
97
98 QString XdxfLoadDialog::dicitonaryFilePath() {
99     return _dicitonaryFilePath;
100 }
101
102 bool XdxfLoadDialog::generateCache() {
103     return _generateCache;
104 }
105
106 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
107     XdxfLoadDialog loadDialog(parent);
108     Settings* settings = new Settings;
109
110     if(loadDialog.exec()==QDialog::Accepted) {
111         settings->setValue("path", loadDialog.dicitonaryFilePath());
112         if(loadDialog.generateCache()) {
113             settings->setValue("generateCache", "true");
114         }
115         else {
116             settings->setValue("generateCache", "false");
117         }
118         if(loadDialog.accentsCheckBox->isChecked())
119             settings->setValue("strip_accents", "true");
120         else
121             settings->setValue("strip_accents", "false");
122
123
124         return settings;
125     }
126
127     return NULL;
128 }
129
130