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 changeLangButton=new QPushButton(
52 QIcon::fromTheme("general_refresh"), "");
54 changeLangButton=new QPushButton(
55 QIcon::fromTheme("object-flip-vertical"),tr(""));
58 langFromLabel = new QLabel(tr("From:"));
59 langToLabel = new QLabel(tr(" To: "));
60 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
61 "connection, so it may cost You."));
63 connectInfoLabel->setWordWrap(true);
64 setWindowTitle(tr("Google Settings"));
66 verticalLayout = new QVBoxLayout;
67 langLayout = new QVBoxLayout;
68 langFromLayout = new QHBoxLayout;
69 langToLayout = new QHBoxLayout;
70 changelangLayout = new QHBoxLayout;
72 setLayout(verticalLayout);
74 infoLabel = new QLabel;
75 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
76 tr("From: ") + _langFrom + "\n" +
77 tr("To: ") + _langTo);
78 verticalLayout->addWidget(infoLabel);
80 langFromComboBox = new QComboBox;
81 langToComboBox = new QComboBox;
84 foreach(QString langs,languages.keys()){
89 langToComboBox->addItem(langs);
90 langFromComboBox->addItem(langs);
93 langToComboBox->setCurrentIndex(actualLangTo);
94 langFromComboBox->setCurrentIndex(actualLangFrom);
96 setWindowTitle(tr("Google Settings"));
97 verticalLayout->addWidget(connectInfoLabel);
98 langFromLayout->addWidget(langFromLabel);
99 langFromLayout->addWidget(langFromComboBox);
100 langToLayout->addWidget(langToLabel);
101 langToLayout->addWidget(langToComboBox);
102 langLayout->addLayout(langFromLayout);
103 langLayout->addLayout(langToLayout);
104 changelangLayout->addLayout(langLayout);
105 changelangLayout->addWidget(changeLangButton);
106 verticalLayout->addLayout(changelangLayout);
108 saveButton = new QPushButton(acceptButtonLabel);
109 verticalLayout->addWidget(saveButton);
113 connect(saveButton, SIGNAL(clicked()),
114 this, SLOT(accept()));
115 connect(langFromComboBox, SIGNAL(activated(int)),
116 this, SLOT(activatedFrom(int)));
117 connect(langToComboBox, SIGNAL(activated(int)),
118 this, SLOT(activatedTo(int)));
119 connect(changeLangButton, SIGNAL(clicked()),
120 this, SLOT(changeLangButtonClicked()));
123 void GoogleSettingsDialog::activatedFrom(int index) {
124 _langFrom=langFromComboBox->itemText(index);
127 void GoogleSettingsDialog::activatedTo(int index) {
128 _langTo=langToComboBox->itemText(index);
131 void GoogleSettingsDialog::changeLangButtonClicked() {
132 int tempIndexTo=langToComboBox->currentIndex();
133 QString tempLangTo=_langTo;
134 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
135 langFromComboBox->setCurrentIndex(tempIndexTo);
137 _langFrom=tempLangTo;
140 QString GoogleSettingsDialog::langFrom() {
144 QString GoogleSettingsDialog::langTo() {
148 Settings* GoogleSettingsDialog::getSettings(QWidget *parent,
149 Settings *pluginSettings,
150 QString acceptButtonLabel) {
151 GoogleSettingsDialog settingsDialog(parent,pluginSettings,acceptButtonLabel);
153 QMap<QString, QString> languages;
154 languages=GooglePlugin::initLanguages();
155 if(settingsDialog.exec()==QDialog::Accepted) {
156 Settings *settings = new Settings();
157 settings->setValue("lang_to",languages.value(settingsDialog.langTo()));
158 settings->setValue("lang_from",languages.value(settingsDialog.langFrom()));
159 settings->setValue("connection_accepted","true");
160 settings->setValue("type","google");
166 void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin,
168 Settings *settings = new Settings();
169 settings=getSettings(parent,plugin->settings(),tr("Save changes"));
171 plugin->setSettings(settings);