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 "GoogleDialog.h"
29 GoogleDialog::GoogleDialog(GooglePlugin *plugin,
30 GoogleDialogType type,
31 QWidget *parent) : QDialog(parent) {
32 this->plugin = plugin;
37 _langTo=GooglePlugin::languages.key(
38 plugin->settings()->value("lang_to"));
40 _langFrom=GooglePlugin::languages.key(
41 plugin->settings()->value("lang_from"));
44 _langTo=GooglePlugin::languages.key("pl");
45 _langFrom=GooglePlugin::languages.key("en");
50 connect(confirmButton, SIGNAL(clicked()),
51 this, SLOT(accept()));
53 connect(langFromComboBox, SIGNAL(currentIndexChanged(int)),
54 this, SLOT(langFromChanged(int)));
56 connect(langToComboBox, SIGNAL(currentIndexChanged(int)),
57 this, SLOT(langToChanged(int)));
59 connect(changeLangButton, SIGNAL(clicked()),
60 this, SLOT(changeLangButtonClicked()));
64 void GoogleDialog::initializeUI() {
65 setWindowTitle(tr("Google Plugin Settings"));
67 langFromLabel = new QLabel(tr("From:"));
68 langToLabel = new QLabel(tr("To: "));
70 verticalLayout = new QVBoxLayout;
71 setLayout(verticalLayout);
74 langLayout = new QVBoxLayout;
75 langsFormLayout = new QFormLayout;
76 changeLangLayout = new QHBoxLayout;
80 setMinimumHeight(370);
81 changeLangButton=new QPushButton(
82 QIcon::fromTheme("general_refresh"), "");
84 changeLangButton=new QPushButton(
85 QIcon::fromTheme("object-flip-vertical"),"");
88 infoLabel = new QLabel;
89 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
90 tr("From: ") + _langFrom + "\n" +
91 tr("To: ") + _langTo);
92 verticalLayout->addWidget(infoLabel);
96 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
97 "connection, so it may cost You."));
98 connectInfoLabel->setWordWrap(true);
100 verticalLayout->addWidget(connectInfoLabel);
103 langFromComboBox = new QComboBox;
104 langToComboBox = new QComboBox;
109 int actualLangFrom=0;
111 foreach(QString langs, GooglePlugin::languages.keys()){
116 if(langs!="Detect langlage"){
117 langToComboBox->addItem(langs);
120 langFromComboBox->addItem(langs);
124 langToComboBox->setCurrentIndex(actualLangTo);
125 langFromComboBox->setCurrentIndex(actualLangFrom);
127 langLayout->addLayout(langsFormLayout);
129 langsFormLayout->addRow(langFromLabel, langFromComboBox);
131 langsFormLayout->addRow(langToLabel, langToComboBox);
133 changeLangLayout->addLayout(langLayout);
134 changeLangLayout->addWidget(changeLangButton);
136 verticalLayout->addLayout(changeLangLayout);
138 confirmButton = new QPushButton;
140 confirmButton->setText(tr("Add"));
143 confirmButton->setText(tr("Save settings"));
146 verticalLayout->addWidget(confirmButton);
150 setMinimumSize(sizeHint());
151 setMaximumSize(sizeHint());
154 void GoogleDialog::langFromChanged(int index) {
155 _langFrom=langFromComboBox->itemText(index);
158 void GoogleDialog::langToChanged(int index) {
159 _langTo=langToComboBox->itemText(index);
162 void GoogleDialog::changeLangButtonClicked() {
163 //int tempIndexTo=langToComboBox->currentIndex();
165 int indexTo=langToComboBox->findText(langFromComboBox->currentText());
166 int indexFrom=langFromComboBox->findText(langToComboBox->currentText());
168 if(indexTo!= -1 && indexFrom!= -1) {
169 langToComboBox->setCurrentIndex(indexTo);
170 langFromComboBox->setCurrentIndex(indexFrom);
173 // langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
174 //langFromComboBox->setCurrentIndex(tempIndexTo);
177 void GoogleDialog::accept() {
183 void GoogleDialog::saveSettings() {
184 _settings = new Settings;
186 foreach(QString key, plugin->settings()->keys())
187 _settings->setValue(key, plugin->settings()->value(key));
190 _settings->setValue("lang_to",
191 GooglePlugin::languages.value(_langTo));
192 _settings->setValue("lang_from",
193 GooglePlugin::languages.value(_langFrom));
196 Settings* GoogleDialog::getSettings() {