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 GoogleDialog.cpp
23 \brief Implementation of google plugin's dialogs.
25 \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
28 #include "GoogleDialog.h"
31 GoogleDialog::GoogleDialog(GooglePlugin *plugin,
32 GoogleDialogType type,
33 QWidget *parent) : QDialog(parent) {
34 this->plugin = plugin;
41 _langTo=GooglePlugin::languages.key(
42 plugin->settings()->value("lang_to"));
44 _langFrom=GooglePlugin::languages.key(
45 plugin->settings()->value("lang_from"));
48 _langTo=GooglePlugin::languages.key("pl");
49 _langFrom=GooglePlugin::languages.key("en");
53 connect(confirmButton, SIGNAL(clicked()),
54 this, SLOT(accept()));
56 connect(langFromComboBox, SIGNAL(currentIndexChanged(int)),
57 this, SLOT(langFromChanged(int)));
59 connect(langToComboBox, SIGNAL(currentIndexChanged(int)),
60 this, SLOT(langToChanged(int)));
62 connect(changeLangButton, SIGNAL(clicked()),
63 this, SLOT(changeLangButtonClicked()));
70 QList<QString> langList;
71 foreach(QString langs, GooglePlugin::languages.keys()){
76 if(langs!="Detect langlage"){
77 langList.append(langs);
83 _actualLangFrom = actualLangFrom;
84 _actualLangTo = actualLangTo;
85 model = new ComboBoxModel(langList);
87 view= new QDeclarativeView();
88 ctxt = view->rootContext();
89 ctxt->setContextProperty("comboBoxModel", &(*model));
90 view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/GoogleDialog.qml"));
91 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
92 //view->setAlignment(Qt::AlignCenter);
95 mainLayout = new QVBoxLayout;
96 mainLayout->addWidget(view);
97 setLayout(mainLayout);
98 view->setWindowTitle(tr("Google Settings"));
100 QGraphicsObject *rootObject = view->rootObject();
102 connect(rootObject, SIGNAL(saveButtonClicked(QString, QString)),
103 this, SLOT(saveButtonClicked(QString,QString)));
105 connect(this, SIGNAL(setInfo(QVariant)),
106 rootObject, SLOT(setInfo(QVariant)));
107 connect(this,SIGNAL(setNew(QVariant)),
108 rootObject, SLOT(setNew(QVariant)));
109 connect(this,SIGNAL(setStartValues(QVariant,QVariant,QVariant,QVariant)),
110 rootObject, SLOT(setStartValues(QVariant, QVariant, QVariant, QVariant)));
118 void GoogleDialog::initializeUI() {
121 setWindowTitle(tr("Google Plugin Settings"));
124 QString info=tr("Plugin: ") + plugin->type().toUpper() +"\n" +
125 tr("From: ") + _langFrom + "\n" +
126 tr("To: ") + _langTo;
132 emit setStartValues(_langFrom, _langTo, _actualLangFrom, _actualLangTo);
134 // setMinimumSize(sizeHint());
141 int actualLangFrom=0;
143 setWindowTitle(tr("Google Plugin Settings"));
145 langFromLabel = new QLabel(tr("From:"));
146 langToLabel = new QLabel(tr("To: "));
148 verticalLayout = new QVBoxLayout;
149 setLayout(verticalLayout);
151 langLayout = new QVBoxLayout;
152 langsFormLayout = new QFormLayout;
153 changeLangLayout = new QHBoxLayout;
156 setMinimumHeight(370);
157 changeLangButton=new QPushButton(
158 QIcon::fromTheme("general_refresh"), "");
160 changeLangButton=new QPushButton(
161 QIcon::fromTheme("object-flip-vertical"),"");
164 infoLabel = new QLabel;
165 infoLabel->setText(tr("Plugin: GoogleTranslator \n")+
166 tr("From: ") + _langFrom + "\n" +
167 tr("To: ") + _langTo);
168 verticalLayout->addWidget(infoLabel);
171 connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
172 "connection, so it may cost You."));
173 connectInfoLabel->setWordWrap(true);
174 verticalLayout->addWidget(connectInfoLabel);
177 langFromComboBox = new QComboBox;
178 langToComboBox = new QComboBox;
180 foreach(QString langs, GooglePlugin::languages.keys()){
185 if(langs!="Detect langlage"){
186 langToComboBox->addItem(langs);
189 langFromComboBox->addItem(langs);
193 langToComboBox->setCurrentIndex(actualLangTo);
194 langFromComboBox->setCurrentIndex(actualLangFrom);
196 langLayout->addLayout(langsFormLayout);
198 langsFormLayout->addRow(langFromLabel, langFromComboBox);
199 langsFormLayout->addRow(langToLabel, langToComboBox);
201 changeLangLayout->addLayout(langLayout);
202 changeLangLayout->addWidget(changeLangButton);
204 verticalLayout->addLayout(changeLangLayout);
206 confirmButton = new QPushButton;
208 confirmButton->setText(tr("Add"));
211 confirmButton->setText(tr("Save settings"));
214 verticalLayout->addWidget(confirmButton);
217 setMinimumSize(sizeHint());
218 setMaximumSize(sizeHint());
223 void GoogleDialog::langFromChanged(int index) {
224 _langFrom=langFromComboBox->itemText(index);
228 void GoogleDialog::langToChanged(int index) {
229 _langTo=langToComboBox->itemText(index);
233 void GoogleDialog::changeLangButtonClicked() {
234 int indexTo=langToComboBox->findText(langFromComboBox->currentText());
235 int indexFrom=langFromComboBox->findText(langToComboBox->currentText());
237 if(indexTo!= -1 && indexFrom!= -1) {
238 langToComboBox->setCurrentIndex(indexTo);
239 langFromComboBox->setCurrentIndex(indexFrom);
244 void GoogleDialog::accept() {
250 void GoogleDialog::saveSettings() {
251 _settings = new Settings;
253 foreach(QString key, plugin->settings()->keys())
254 _settings->setValue(key, plugin->settings()->value(key));
257 _settings->setValue("lang_to",
258 GooglePlugin::languages.value(_langTo));
259 _settings->setValue("lang_from",
260 GooglePlugin::languages.value(_langFrom));
264 void GoogleDialog::saveButtonClicked(QString langFrom, QString langTo){
265 saveSettings(langFrom, langTo);
269 void GoogleDialog::saveSettings(QString langFrom, QString langTo){
270 _settings = new Settings;
271 _langFrom = langFrom;
274 foreach(QString key, plugin->settings()->keys())
275 _settings->setValue(key, plugin->settings()->value(key));
278 _settings->setValue("lang_to",
279 GooglePlugin::languages.value(langTo));
280 _settings->setValue("lang_from",
281 GooglePlugin::languages.value(langFrom));
285 Settings* GoogleDialog::getSettings() {