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"));
49 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: "));
61 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
62 "connection, so it may cost You."));
64 connectInfoLabel->setWordWrap(true);
65 setWindowTitle(tr("Google Settings"));
67 verticalLayout = new QVBoxLayout;
68 langLayout = new QVBoxLayout;
69 langFromLayout = new QHBoxLayout;
70 langToLayout = new QHBoxLayout;
71 changelangLayout = new QHBoxLayout;
73 setLayout(verticalLayout);
75 infoLabel = new QLabel;
76 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
77 tr("From: ") + _langFrom + "\n" +
78 tr("To: ") + _langTo);
79 verticalLayout->addWidget(infoLabel);
82 langFromComboBox = new QComboBox;
83 langToComboBox = new QComboBox;
86 foreach(QString langs,languages.keys()){
91 langToComboBox->addItem(langs);
92 langFromComboBox->addItem(langs);
95 langToComboBox->setCurrentIndex(actualLangTo);
96 langFromComboBox->setCurrentIndex(actualLangFrom);
100 setWindowTitle(tr("Google Settings"));
101 verticalLayout->addWidget(connectInfoLabel);
103 langFromLayout->addWidget(langFromLabel);
104 langFromLayout->addWidget(langFromComboBox);
105 langToLayout->addWidget(langToLabel);
106 langToLayout->addWidget(langToComboBox);
109 langLayout->addLayout(langFromLayout);
110 langLayout->addLayout(langToLayout);
111 changelangLayout->addLayout(langLayout);
112 changelangLayout->addWidget(changeLangButton);
113 verticalLayout->addLayout(changelangLayout);
115 saveButton = new QPushButton(acceptButtonLabel);
116 verticalLayout->addWidget(saveButton);
120 connect(saveButton, SIGNAL(clicked()),
121 this, SLOT(accept()));
124 connect(langFromComboBox, SIGNAL(activated(int)),
125 this, SLOT(activatedFrom(int)));
126 connect(langToComboBox, SIGNAL(activated(int)),
127 this, SLOT(activatedTo(int)));
130 connect(changeLangButton, SIGNAL(clicked()),
131 this, SLOT(changeLangButtonClicked()));
135 void GoogleSettingsDialog::activatedFrom(int index) {
136 _langFrom=langFromComboBox->itemText(index);
139 void GoogleSettingsDialog::activatedTo(int index) {
140 _langTo=langToComboBox->itemText(index);
144 void GoogleSettingsDialog::changeLangButtonClicked() {
146 int tempIndexTo=langToComboBox->currentIndex();
147 QString tempLangTo=_langTo;
148 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
149 langFromComboBox->setCurrentIndex(tempIndexTo);
151 _langFrom=tempLangTo;
155 QString GoogleSettingsDialog::langFrom() {
159 QString GoogleSettingsDialog::langTo() {
163 Settings* GoogleSettingsDialog::getSettings(QWidget *parent,
164 Settings *pluginSettings,
165 QString acceptButtonLabel) {
166 GoogleSettingsDialog settingsDialog(parent,pluginSettings,acceptButtonLabel);
168 QMap<QString, QString> languages;
169 languages=GooglePlugin::initLanguages();
170 if(settingsDialog.exec()==QDialog::Accepted) {
171 Settings *settings = new Settings();
172 settings->setValue("lang_to",languages.value(settingsDialog.langTo()));
173 settings->setValue("lang_from",languages.value(settingsDialog.langFrom()));
174 settings->setValue("connection_accepted","true");
175 settings->setValue("type","google");
181 void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin,
183 Settings *settings = new Settings();
184 settings=getSettings(parent,plugin->settings(),tr("Save changes"));
185 plugin->setSettings(settings);