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,Settings *pluginSettings) :
32 QMap<QString, QString> languages;
33 languages=GooglePlugin::initLanguages();
38 if(pluginSettings==0) {
39 _langTo=languages.key("pl");
40 _langFrom=languages.key("en");
43 _langTo=languages.key(pluginSettings->value("lang_to"));
44 _langFrom=languages.key(pluginSettings->value("lang_from"));
48 changeLangButton=new QPushButton(QIcon::fromTheme("general_refresh"),tr(""));
50 changeLangButton=new QPushButton(QIcon::fromTheme("object-flip-vertical"),tr(""));
53 langFromLabel = new QLabel("From:");
54 langToLabel = new QLabel(" To: ");
55 connectInfoLabel = new QLabel(tr("Google plugin make use of internet "
56 "conection, so it may cost You."));
57 infoLabel = new QLabel(tr("Plugin:GoogleTranslator \n From: %1 \n To: %2").arg(
59 verticalLayout = new QVBoxLayout(this);
60 langLayout = new QVBoxLayout(this);
61 langFromLayout = new QHBoxLayout(this);
62 langToLayout = new QHBoxLayout(this);
63 changelangLayout = new QHBoxLayout(this);
64 langFromComboBox = new QComboBox(this);
65 langToComboBox = new QComboBox(this);
66 saveButton = new QPushButton(tr("Save settings"),this);
68 connectInfoLabel->setWordWrap(true);
71 foreach(QString langs,languages.keys()){
76 langToComboBox->addItem(langs);
77 langFromComboBox->addItem(langs);
80 langToComboBox->setCurrentIndex(actualLangTo);
81 langFromComboBox->setCurrentIndex(actualLangFrom);
83 setWindowTitle(tr("Google Settings"));
84 setLayout(verticalLayout);
85 verticalLayout->addWidget(infoLabel);
86 verticalLayout->addWidget(connectInfoLabel);
87 langFromLayout->addWidget(langFromLabel);
88 langFromLayout->addWidget(langFromComboBox);
89 langToLayout->addWidget(langToLabel);
90 langToLayout->addWidget(langToComboBox);
91 langLayout->addLayout(langFromLayout);
92 langLayout->addLayout(langToLayout);
93 changelangLayout->addLayout(langLayout);
94 changelangLayout->addWidget(changeLangButton);
95 verticalLayout->addLayout(changelangLayout);
96 verticalLayout->addWidget(saveButton);
100 connect(saveButton, SIGNAL(clicked()),this, SLOT(accept()));
101 connect(langFromComboBox, SIGNAL(activated(int)),this, SLOT(activatedFrom(int)));
102 connect(langToComboBox, SIGNAL(activated(int)),this, SLOT(activatedTo(int)));
103 connect(changeLangButton, SIGNAL(clicked()),this, SLOT(changeLangButtonClicked()));
106 void GoogleSettingsDialog::activatedFrom(int index) {
107 _langFrom=langFromComboBox->itemText(index);
110 void GoogleSettingsDialog::activatedTo(int index) {
111 _langTo=langToComboBox->itemText(index);
114 void GoogleSettingsDialog::changeLangButtonClicked() {
115 int tempIndexTo=langToComboBox->currentIndex();
116 QString tempLangTo=_langTo;
117 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
118 langFromComboBox->setCurrentIndex(tempIndexTo);
120 _langFrom=tempLangTo;
123 QString GoogleSettingsDialog::langFrom() {
127 QString GoogleSettingsDialog::langTo() {
131 Settings* GoogleSettingsDialog::getSettings(QWidget *parent,Settings *pluginSettings) {
132 GoogleSettingsDialog settingsDialog(parent,pluginSettings);
133 QMap<QString, QString> languages;
134 languages=GooglePlugin::initLanguages();
135 if(settingsDialog.exec()==QDialog::Accepted) {
136 Settings *settings = new Settings();
137 settings->setValue("lang_to",languages.value(settingsDialog.langTo()));
138 settings->setValue("lang_from",languages.value(settingsDialog.langFrom()));
139 settings->setValue("connection_accept","true");
140 settings->setValue("type","google");
146 void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin, QWidget *parent) {
147 Settings *settings = new Settings();
148 settings=getSettings(parent,plugin->settings());
150 plugin->setSettings(settings);