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 "GoogleSettingsDialog.h"
29 GoogleSettingsDialog::GoogleSettingsDialog(QWidget *parent,
30 Settings *pluginSettings,
31 QString acceptButtonLabel) :
34 QMap<QString, QString> languages;
35 languages=GooglePlugin::initLanguages();
40 if(pluginSettings==0) {
41 _langTo=languages.key("pl");
42 _langFrom=languages.key("en");
45 _langTo=languages.key(pluginSettings->value("lang_to"));
46 _langFrom=languages.key(pluginSettings->value("lang_from"));
51 setMinimumHeight(370);
52 changeLangButton=new QPushButton(
53 QIcon::fromTheme("general_refresh"), "");
55 changeLangButton=new QPushButton(
56 QIcon::fromTheme("object-flip-vertical"),tr(""));
59 langFromLabel = new QLabel(tr("From:"));
60 langToLabel = new QLabel(tr(" To: "));
62 setWindowTitle(tr("Google Settings"));
64 verticalLayout = new QVBoxLayout;
65 langLayout = new QVBoxLayout;
66 langFromLayout = new QHBoxLayout;
67 langToLayout = new QHBoxLayout;
68 changelangLayout = new QHBoxLayout;
70 setLayout(verticalLayout);
72 infoLabel = new QLabel;
73 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
74 tr("From: ") + _langFrom + "\n" +
75 tr("To: ") + _langTo);
76 verticalLayout->addWidget(infoLabel);
80 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
81 "connection, so it may cost You."));
82 connectInfoLabel->setWordWrap(true);
84 verticalLayout->addWidget(connectInfoLabel);
87 langFromComboBox = new QComboBox;
88 langToComboBox = new QComboBox;
91 foreach(QString langs,languages.keys()){
96 langToComboBox->addItem(langs);
97 langFromComboBox->addItem(langs);
100 langToComboBox->setCurrentIndex(actualLangTo);
101 langFromComboBox->setCurrentIndex(actualLangFrom);
104 langFromLayout->addWidget(langFromLabel);
105 langFromLayout->addWidget(langFromComboBox);
106 langToLayout->addWidget(langToLabel);
107 langToLayout->addWidget(langToComboBox);
110 langLayout->addLayout(langFromLayout);
111 langLayout->addLayout(langToLayout);
112 changelangLayout->addLayout(langLayout);
113 changelangLayout->addWidget(changeLangButton);
114 verticalLayout->addLayout(changelangLayout);
116 saveButton = new QPushButton(acceptButtonLabel);
117 verticalLayout->addWidget(saveButton);
121 connect(saveButton, SIGNAL(clicked()),
122 this, SLOT(accept()));
125 connect(langFromComboBox, SIGNAL(activated(int)),
126 this, SLOT(activatedFrom(int)));
127 connect(langToComboBox, SIGNAL(activated(int)),
128 this, SLOT(activatedTo(int)));
131 connect(changeLangButton, SIGNAL(clicked()),
132 this, SLOT(changeLangButtonClicked()));
136 void GoogleSettingsDialog::activatedFrom(int index) {
137 _langFrom=langFromComboBox->itemText(index);
140 void GoogleSettingsDialog::activatedTo(int index) {
141 _langTo=langToComboBox->itemText(index);
145 void GoogleSettingsDialog::changeLangButtonClicked() {
147 int tempIndexTo=langToComboBox->currentIndex();
148 QString tempLangTo=_langTo;
149 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
150 langFromComboBox->setCurrentIndex(tempIndexTo);
152 _langFrom=tempLangTo;
156 QString GoogleSettingsDialog::langFrom() {
160 QString GoogleSettingsDialog::langTo() {
164 Settings* GoogleSettingsDialog::getSettings(QWidget *parent,
165 Settings *pluginSettings,
166 QString acceptButtonLabel) {
167 GoogleSettingsDialog settingsDialog(parent,pluginSettings,acceptButtonLabel);
169 QMap<QString, QString> languages;
170 languages=GooglePlugin::initLanguages();
171 if(settingsDialog.exec()==QDialog::Accepted) {
172 Settings *settings = new Settings();
173 settings->setValue("lang_to",languages.value(settingsDialog.langTo()));
174 settings->setValue("lang_from",languages.value(settingsDialog.langFrom()));
175 settings->setValue("connection_accepted","true");
176 settings->setValue("type","google");
182 void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin,
184 Settings *settings = new Settings();
185 settings=getSettings(parent,plugin->settings(),tr("Save changes"));
186 plugin->setSettings(settings);