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 GoogleSettingsDialog.cpp
23 \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
26 #include "GoogleDialog.h"
29 GoogleDialog::GoogleDialog(GooglePlugin *plugin,
30 GoogleDialogType type,
31 QWidget *parent) : QDialog(parent) {
32 this->plugin = plugin;
37 _langTo=GooglePlugin::languages.key(
38 plugin->settings()->value("lang_to"));
40 _langFrom=GooglePlugin::languages.key(
41 plugin->settings()->value("lang_from"));
44 _langTo=GooglePlugin::languages.key("pl");
45 _langFrom=GooglePlugin::languages.key("en");
50 connect(confirmButton, SIGNAL(clicked()),
51 this, SLOT(accept()));
53 connect(langFromComboBox, SIGNAL(currentIndexChanged(int)),
54 this, SLOT(langFromChanged(int)));
56 connect(langToComboBox, SIGNAL(currentIndexChanged(int)),
57 this, SLOT(langToChanged(int)));
59 connect(changeLangButton, SIGNAL(clicked()),
60 this, SLOT(changeLangButtonClicked()));
64 void GoogleDialog::initializeUI() {
69 setWindowTitle(tr("Google Plugin Settings"));
71 langFromLabel = new QLabel(tr("From:"));
72 langToLabel = new QLabel(tr("To: "));
74 verticalLayout = new QVBoxLayout;
75 setLayout(verticalLayout);
77 langLayout = new QVBoxLayout;
78 langsFormLayout = new QFormLayout;
79 changeLangLayout = new QHBoxLayout;
82 setMinimumHeight(370);
83 changeLangButton=new QPushButton(
84 QIcon::fromTheme("general_refresh"), "");
86 changeLangButton=new QPushButton(
87 QIcon::fromTheme("object-flip-vertical"),"");
90 infoLabel = new QLabel;
91 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
92 tr("From: ") + _langFrom + "\n" +
93 tr("To: ") + _langTo);
94 verticalLayout->addWidget(infoLabel);
97 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
98 "connection, so it may cost You."));
99 connectInfoLabel->setWordWrap(true);
100 verticalLayout->addWidget(connectInfoLabel);
103 langFromComboBox = new QComboBox;
104 langToComboBox = new QComboBox;
106 foreach(QString langs, GooglePlugin::languages.keys()){
111 if(langs!="Detect langlage"){
112 langToComboBox->addItem(langs);
115 langFromComboBox->addItem(langs);
119 langToComboBox->setCurrentIndex(actualLangTo);
120 langFromComboBox->setCurrentIndex(actualLangFrom);
122 langLayout->addLayout(langsFormLayout);
124 langsFormLayout->addRow(langFromLabel, langFromComboBox);
125 langsFormLayout->addRow(langToLabel, langToComboBox);
127 changeLangLayout->addLayout(langLayout);
128 changeLangLayout->addWidget(changeLangButton);
130 verticalLayout->addLayout(changeLangLayout);
132 confirmButton = new QPushButton;
134 confirmButton->setText(tr("Add"));
137 confirmButton->setText(tr("Save settings"));
140 verticalLayout->addWidget(confirmButton);
143 setMinimumSize(sizeHint());
144 setMaximumSize(sizeHint());
148 void GoogleDialog::langFromChanged(int index) {
149 _langFrom=langFromComboBox->itemText(index);
153 void GoogleDialog::langToChanged(int index) {
154 _langTo=langToComboBox->itemText(index);
158 void GoogleDialog::changeLangButtonClicked() {
159 int indexTo=langToComboBox->findText(langFromComboBox->currentText());
160 int indexFrom=langFromComboBox->findText(langToComboBox->currentText());
162 if(indexTo!= -1 && indexFrom!= -1) {
163 langToComboBox->setCurrentIndex(indexTo);
164 langFromComboBox->setCurrentIndex(indexFrom);
169 void GoogleDialog::accept() {
175 void GoogleDialog::saveSettings() {
176 _settings = new Settings;
178 foreach(QString key, plugin->settings()->keys())
179 _settings->setValue(key, plugin->settings()->value(key));
182 _settings->setValue("lang_to",
183 GooglePlugin::languages.value(_langTo));
184 _settings->setValue("lang_from",
185 GooglePlugin::languages.value(_langFrom));
189 Settings* GoogleDialog::getSettings() {