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");
52 connect(confirmButton, SIGNAL(clicked()),
53 this, SLOT(accept()));
55 connect(langFromComboBox, SIGNAL(currentIndexChanged(int)),
56 this, SLOT(langFromChanged(int)));
58 connect(langToComboBox, SIGNAL(currentIndexChanged(int)),
59 this, SLOT(langToChanged(int)));
61 connect(changeLangButton, SIGNAL(clicked()),
62 this, SLOT(changeLangButtonClicked()));
66 void GoogleDialog::initializeUI() {
67 setWindowTitle(tr("Google Plugin Settings"));
69 langFromLabel = new QLabel(tr("From:"));
70 langToLabel = new QLabel(tr("To: "));
72 verticalLayout = new QVBoxLayout;
73 setLayout(verticalLayout);
76 langLayout = new QVBoxLayout;
77 langsFormLayout = new QFormLayout;
78 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);
98 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet " "connection, so it may cost You."));
99 connectInfoLabel->setWordWrap(true);
101 verticalLayout->addWidget(connectInfoLabel);
104 langFromComboBox = new QComboBox;
105 langToComboBox = new QComboBox;
109 int actualLangFrom=0;
111 foreach(QString langs, GooglePlugin::languages.keys()){
116 langToComboBox->addItem(langs);
117 langFromComboBox->addItem(langs);
121 langToComboBox->setCurrentIndex(actualLangTo);
122 langFromComboBox->setCurrentIndex(actualLangFrom);
124 langLayout->addLayout(langsFormLayout);
126 langsFormLayout->addRow(langFromLabel, langFromComboBox);
128 langsFormLayout->addRow(langToLabel, langToComboBox);
130 changeLangLayout->addLayout(langLayout);
131 changeLangLayout->addWidget(changeLangButton);
133 verticalLayout->addLayout(changeLangLayout);
135 confirmButton = new QPushButton;
137 confirmButton->setText(tr("Add"));
140 confirmButton->setText(tr("Save settings"));
143 verticalLayout->addWidget(confirmButton);
148 void GoogleDialog::langFromChanged(int index) {
149 _langFrom=langFromComboBox->itemText(index);
152 void GoogleDialog::langToChanged(int index) {
153 _langTo=langToComboBox->itemText(index);
156 void GoogleDialog::changeLangButtonClicked() {
157 int tempIndexTo=langToComboBox->currentIndex();
158 QString tempLangTo=_langTo;
160 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
161 langFromComboBox->setCurrentIndex(tempIndexTo);
164 _langFrom=tempLangTo;
167 void GoogleDialog::accept() {
173 void GoogleDialog::saveSettings() {
174 _settings = new Settings;
176 foreach(QString key, plugin->settings()->keys())
177 _settings->setValue(key, plugin->settings()->value(key));
180 _settings->setValue("lang_to",
181 GooglePlugin::languages.value(_langTo));
182 _settings->setValue("lang_from",
183 GooglePlugin::languages.value(_langFrom));
186 Settings* GoogleDialog::getSettings() {