Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[mdictionary] / trunk / src / plugins / xdxf / src / XdxfSettingsDialog.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 //Created by Mateusz Półrola
23
24 #include "XdxfSettingsDialog.h"
25
26 XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
27     QDialog(parent)
28 {
29     this->plugin = plugin;
30     verticalLayout = new QVBoxLayout;
31     setLayout(verticalLayout);
32
33     setWindowTitle(tr("XDXF Settings"));
34
35
36     infoLabel = new QLabel;
37
38     infoLabel->setText(tr("Plugin type: ") + plugin->type() +"\n" +
39                    tr("From: ") + plugin->langFrom() + "\n" +
40                    tr("To: ") + plugin->langTo() + "\n" +
41                    tr("Description: ") + plugin->name());
42
43     verticalLayout->addWidget(infoLabel);
44
45     browseLayout = new QHBoxLayout;
46     verticalLayout->addLayout(browseLayout);
47
48     browseButton =  new QPushButton(tr("Browse"));
49     browseLabel = new QLabel(tr("Dictionary file: ") +
50                              plugin->settings()->value("path"));
51
52     browseLayout->addWidget(browseLabel);
53     browseLayout->addWidget(browseButton,0, Qt::AlignRight);
54
55
56     cacheLayout = new QHBoxLayout;
57     verticalLayout->addLayout(cacheLayout);
58
59     cacheButton = new QPushButton(tr("Cache"));
60     if(plugin->settings()->value("Cached") == "true") {
61         cacheButton->setEnabled(false);
62     }
63
64     cacheLayout->addWidget(cacheButton);
65
66     saveButton = new QPushButton(tr("Save settings"));
67
68     verticalLayout->addWidget(saveButton);
69
70     setModal(true);
71
72     connect(browseButton, SIGNAL(clicked()),
73             this, SLOT(selectFile()));
74
75     connect(saveButton, SIGNAL(clicked()),
76             this, SLOT(accept()));
77
78     _dicitonaryFilePath = plugin->settings()->value("path");
79 }
80
81 void XdxfSettingsDialog::selectFile() {
82     QString fileName = QFileDialog::getOpenFileName(this,
83                                      tr("Select dictionary file"),
84                                      "",
85                                      tr("XDXF Files (*.xdxf)"),
86                                      NULL,
87                                      NULL);
88     if (!fileName.isEmpty()) {
89         browseLabel->setText(tr("Dictionary file: ") + fileName);
90         _dicitonaryFilePath = fileName;
91     }
92 }
93
94 QString XdxfSettingsDialog::dicitonaryFilePath() {
95     return _dicitonaryFilePath;
96 }
97
98 Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
99                                           QWidget *parent) {
100     XdxfSettingsDialog settingsDialog(plugin, parent);
101
102
103     if(settingsDialog.exec()==QDialog::Accepted) {
104         Settings* settings = new Settings;
105         foreach(QString key, plugin->settings()->keys())
106             settings->setValue(key, plugin->settings()->value(key));
107         settings->setValue("path", settingsDialog.dicitonaryFilePath());
108         plugin->setSettings(settings);
109         return NULL;
110     }
111
112     return NULL;
113 }
114
115