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,QString langTo,QString langFrom) :
32 QMap<QString, QString> languages;
33 languages=GooglePlugin::initLanguages();
43 _langTo=languages.key(langTo);
44 _langFrom=languages.key(langFrom);
48 changeLangButton=new QPushButton(QIcon::fromTheme("general_refresh"),tr(""));
50 changeLangButton=new QPushButton(QIcon::fromTheme("object-flip-vertical"),tr(""));
52 langFromLabel = new QLabel("From:");
53 langToLabel = new QLabel(" To: ");
54 connectInfoLabel = new QLabel(tr("Google plugin make use of internet "
55 "conection, so it may cost You."));
56 connectInfoLabel->setWordWrap(true);
59 setWindowTitle(tr("Google Settings"));
61 verticalLayout = new QVBoxLayout(this);
62 langLayout = new QVBoxLayout(this);
63 langFromLayout = new QHBoxLayout(this);
64 langToLayout = new QHBoxLayout(this);
65 changelangLayout = new QHBoxLayout(this);
67 setLayout(verticalLayout);
69 infoLabel = new QLabel(this);
70 infoLabel->setText(tr("Plugin:GoogleTranslator \n")+
71 tr("From: ") + languages.key(langFrom) + "\n" +
72 tr("To: ") + languages.key(langTo));
73 verticalLayout->addWidget(infoLabel);
75 langFromComboBox = new QComboBox(this);
76 langToComboBox = new QComboBox(this);
78 foreach(QString langs,languages.keys()){
79 if(langs==languages.key(langTo))
81 if(langs==languages.key(langFrom))
83 langToComboBox->addItem(langs);
84 langFromComboBox->addItem(langs);
88 verticalLayout->addWidget(connectInfoLabel);
89 langFromLayout->addWidget(langFromLabel);
90 langFromLayout->addWidget(langFromComboBox);
91 langToLayout->addWidget(langToLabel);
92 langToLayout->addWidget(langToComboBox);
93 langLayout->addLayout(langFromLayout);
94 langLayout->addLayout(langToLayout);
95 changelangLayout->addLayout(langLayout);
96 changelangLayout->addWidget(changeLangButton);
97 verticalLayout->addLayout(changelangLayout);
100 langToComboBox->setCurrentIndex(actualLangTo);
101 langFromComboBox->setCurrentIndex(actualLangFrom);
103 saveButton = new QPushButton(tr("Save settings"),this);
104 verticalLayout->addWidget(saveButton);
108 connect(saveButton, SIGNAL(clicked()),this, SLOT(accept()));
109 connect(langFromComboBox, SIGNAL(activated(int)),this, SLOT(activatedFrom(int)));
110 connect(langToComboBox, SIGNAL(activated(int)),this, SLOT(activatedTo(int)));
111 connect(changeLangButton, SIGNAL(clicked()),this, SLOT(changeLangButtonClicked()));
114 void GoogleSettingsDialog::activatedFrom(int index) {
115 _langFrom=langFromComboBox->itemText(index);
118 void GoogleSettingsDialog::activatedTo(int index) {
119 _langTo=langToComboBox->itemText(index);
122 void GoogleSettingsDialog::changeLangButtonClicked() {
123 int tempIndexTo=langToComboBox->currentIndex();
124 QString tempLangTo=_langTo;
126 langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
127 langFromComboBox->setCurrentIndex(tempIndexTo);
130 _langFrom=tempLangTo;
133 QString GoogleSettingsDialog::langFrom() {
137 QString GoogleSettingsDialog::langTo() {
141 Settings* GoogleSettingsDialog::getSettings(QWidget *parent,QString langTo,QString langFrom) {
142 GoogleSettingsDialog settingsDialog(parent,langTo,langFrom);
143 QMap<QString, QString> languages;
144 languages=GooglePlugin::initLanguages();
145 if(settingsDialog.exec()==QDialog::Accepted) {
146 Settings *settings = new Settings();
147 settings->setValue("langTo",languages.value(settingsDialog.langTo()));
148 settings->setValue("langFrom",languages.value(settingsDialog.langFrom()));
149 settings->setValue("connectionAccept","true");
155 void GoogleSettingsDialog::changeSettings(GooglePlugin* plugin, QWidget *parent) {
156 Settings *settings = new Settings();
157 settings=getSettings(parent,plugin->settings()->value("langTo"),plugin->settings()->value("langFrom"));
159 plugin->setSettings(settings);