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"));
35 browseLayout = new QVBoxLayout;
37 browseButton = new QPushButton(tr("Browse"));
38 browseLabel = new QLabel(tr("Dictionary file: not selected"));
39 //browseLabel->setWordWrap(true);
40 browseLabel->setMargin(5);
42 browseLayout->addWidget(browseLabel, 0, Qt::AlignLeft);
43 browseLayout->addWidget(browseButton);
45 verticalLayout->addLayout(browseLayout);
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);
53 cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
54 cacheCheckBox->setChecked(true);
55 cacheLayout->addWidget(cacheCheckBox);
57 addButton = new QPushButton(tr("Add"));
59 verticalLayout->addWidget(addButton);
63 connect(browseButton, SIGNAL(clicked()),
64 this, SLOT(selectFile()));
66 connect(addButton, SIGNAL(clicked()),
67 this, SLOT(addDictionary()));
69 connect(cacheCheckBox, SIGNAL(toggled(bool)),
70 SLOT(setGenerateCache(bool)));
72 connect(accentsCheckBox, SIGNAL(clicked(bool)), SLOT(setAccents(bool)));
73 lastAccents = accentsCheckBox->isChecked();
74 _dicitonaryFilePath = QString();
79 void XdxfLoadDialog::setAccents(bool state) {
85 void XdxfLoadDialog::selectFile() {
86 QString fileName = QFileDialog::getOpenFileName(this,
87 tr("Select dictionary file"),
89 tr("XDXF Files (*.xdxf)"),
93 if (!fileName.isEmpty()) {
94 browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
95 _dicitonaryFilePath = fileName;
100 void XdxfLoadDialog::addDictionary() {
101 _generateCache = cacheCheckBox->isChecked();
102 if(!_dicitonaryFilePath.isEmpty()) {
110 QString XdxfLoadDialog::dicitonaryFilePath() {
111 return _dicitonaryFilePath;
114 bool XdxfLoadDialog::generateCache() {
115 return _generateCache;
118 void XdxfLoadDialog::setGenerateCache(bool generate) {
119 _generateCache = generate;
122 accentsCheckBox->setChecked(true);
124 accentsCheckBox->setChecked(lastAccents);
126 accentsCheckBox->setEnabled(!generate);
129 Settings* XdxfLoadDialog::getSettings(QWidget *parent) {
130 XdxfLoadDialog loadDialog(parent);
131 Settings* settings = new Settings;
133 if(loadDialog.exec()==QDialog::Accepted) {
134 settings->setValue("path", loadDialog.dicitonaryFilePath());
135 if(loadDialog.generateCache()) {
136 settings->setValue("generateCache", "true");
139 settings->setValue("generateCache", "false");
141 if(loadDialog.accentsCheckBox->isChecked())
142 settings->setValue("strip_accents", "true");
144 settings->setValue("strip_accents", "false");