1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 /*! \file XdxfLoadDialog.cpp
24 //Created by Mateusz Półrola
26 #include "XdxfLoadDialog.h"
28 XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
30 verticalLayout = new QVBoxLayout;
31 setLayout(verticalLayout);
33 setWindowTitle(tr("Add new XDXF dictionary"));
37 browseLayout = new QHBoxLayout;
39 browseButton = new QPushButton(tr("Browse"));
40 browseLabel = new QLabel(tr("Dictionary file: not selected"));
41 //browseLabel->setMargin(5);
43 browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
44 browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
46 verticalLayout->addLayout(browseLayout);
48 cacheLayout = new QHBoxLayout;
49 verticalLayout->addLayout(cacheLayout);
50 accentsCheckBox = new QCheckBox(tr("Strip accents (searching takes more "
51 "time, but spelling don't have to be exact)"));
52 verticalLayout->addWidget(accentsCheckBox);
54 cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
55 cacheCheckBox->setChecked(true);
56 cacheLayout->addWidget(cacheCheckBox);
58 addButton = new QPushButton(tr("Add"));
60 verticalLayout->addWidget(addButton);
64 connect(browseButton, SIGNAL(clicked()),
65 this, SLOT(selectFile()));
67 connect(addButton, SIGNAL(clicked()),
68 this, SLOT(addDictionary()));
70 connect(cacheCheckBox, SIGNAL(toggled(bool)),
71 SLOT(setGenerateCache(bool)));
73 connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
74 lastAccents = accentsCheckBox->isChecked();
75 _dicitonaryFilePath = QString();
80 void XdxfLoadDialog::setAccents(bool state) {
86 void XdxfLoadDialog::selectFile() {
87 QString fileName = QFileDialog::getOpenFileName(this,
88 tr("Select dictionary file"),
90 tr("XDXF Files (*.xdxf)"),
94 if (!fileName.isEmpty()) {
95 browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
96 _dicitonaryFilePath = fileName;
101 void XdxfLoadDialog::addDictionary() {
102 _generateCache = cacheCheckBox->isChecked();
103 if(!_dicitonaryFilePath.isEmpty()) {
108 QString XdxfLoadDialog::dicitonaryFilePath() {
109 return _dicitonaryFilePath;
112 bool XdxfLoadDialog::generateCache() {
113 return _generateCache;
116 void XdxfLoadDialog::setGenerateCache(bool generate) {
117 _generateCache = generate;
120 accentsCheckBox->setChecked(true);
122 accentsCheckBox->setChecked(lastAccents);
124 accentsCheckBox->setEnabled(!generate);
127 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
128 XdxfLoadDialog loadDialog(parent);
129 Settings* settings = new Settings;
131 if(loadDialog.exec()==QDialog::Accepted) {
132 settings->setValue("path", loadDialog.dicitonaryFilePath());
133 if(loadDialog.generateCache()) {
134 settings->setValue("generateCache", "true");
137 settings->setValue("generateCache", "false");
139 if(loadDialog.accentsCheckBox->isChecked())
140 settings->setValue("strip_accents", "true");
142 settings->setValue("strip_accents", "false");