Copyright 2010 Comarch S.A.
*******************************************************************************/
+/*!
+ \file GoogleDialog.cpp
+ \brief Implementation of google plugin's dialogs.
-/*! \file GoogleSettingsDialog.cpp
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
this->plugin = plugin;
this->type = type;
_settings = 0;
+ _actualLangFrom = 0;
+ _actualLangTo = 0;
if(plugin) {
_langTo=GooglePlugin::languages.key(
_langFrom=GooglePlugin::languages.key("en");
}
-
-
- initializeUI();
-
+#ifdef Q_WS_MAEMO_5
connect(confirmButton, SIGNAL(clicked()),
this, SLOT(accept()));
connect(changeLangButton, SIGNAL(clicked()),
this, SLOT(changeLangButtonClicked()));
+#else
+
+ int i=0,j=0;
+ int actualLangTo=0;
+ int actualLangFrom=0;
+
+ QList<QString> langList;
+ foreach(QString langs, GooglePlugin::languages.keys()){
+ if(langs==_langTo)
+ actualLangTo=j;
+ if(langs==_langFrom)
+ actualLangFrom=i;
+ if(langs!="Detect langlage"){
+ langList.append(langs);
+ j++;
+ }
+ i++;
+ }
+
+ _actualLangFrom = actualLangFrom;
+ _actualLangTo = actualLangTo;
+ model = new ComboBoxModel(langList);
+
+ view= new QDeclarativeView();
+ ctxt = view->rootContext();
+ ctxt->setContextProperty("comboBoxModel", &(*model));
+ view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/GoogleDialog.qml"));
+ view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ //view->setAlignment(Qt::AlignCenter);
+ view->show();
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(view);
+ setLayout(mainLayout);
+ view->setWindowTitle(tr("Google Settings"));
+
+ QGraphicsObject *rootObject = view->rootObject();
+
+ connect(rootObject, SIGNAL(saveButtonClicked(QString, QString)),
+ this, SLOT(saveButtonClicked(QString,QString)));
+
+ connect(this, SIGNAL(setInfo(QVariant)),
+ rootObject, SLOT(setInfo(QVariant)));
+ connect(this,SIGNAL(setNew(QVariant)),
+ rootObject, SLOT(setNew(QVariant)));
+ connect(this,SIGNAL(setStartValues(QVariant,QVariant,QVariant,QVariant)),
+ rootObject, SLOT(setStartValues(QVariant, QVariant, QVariant, QVariant)));
+
+#endif
+
+ initializeUI();
}
void GoogleDialog::initializeUI() {
+#ifndef Q_WS_MAEMO_5
+
+ setWindowTitle(tr("Google Plugin Settings"));
+ if (type != New){
+ emit setNew(false);
+ QString info=tr("Plugin: ") + plugin->type().toUpper() +"\n" +
+ tr("From: ") + _langFrom + "\n" +
+ tr("To: ") + _langTo;
+ emit setInfo(info);
+ }
+ else{
+ emit setNew(true);
+ }
+ emit setStartValues(_langFrom, _langTo, _actualLangFrom, _actualLangTo);
+
+// setMinimumSize(sizeHint());
+
+
+#else
+
+ int i=0,j=0;
+ int actualLangTo=0;
+ int actualLangFrom=0;
+
setWindowTitle(tr("Google Plugin Settings"));
langFromLabel = new QLabel(tr("From:"));
verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
-
langLayout = new QVBoxLayout;
- langFromLayout = new QHBoxLayout;
- langToLayout = new QHBoxLayout;
+ langsFormLayout = new QFormLayout;
changeLangLayout = new QHBoxLayout;
-
#ifdef Q_WS_MAEMO_5
setMinimumHeight(370);
changeLangButton=new QPushButton(
- QIcon::fromTheme("general_refresh"), "");
+ QIcon::fromTheme("general_refresh"), "");
#else
changeLangButton=new QPushButton(
QIcon::fromTheme("object-flip-vertical"),"");
tr("To: ") + _langTo);
verticalLayout->addWidget(infoLabel);
-
#ifdef Q_WS_MAEMO_5
- connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet " "connection, so it may cost You."));
+ connectInfoLabel = new QLabel(tr("Google plugin makes use of Internet "
+ "connection, so it may cost You."));
connectInfoLabel->setWordWrap(true);
-
verticalLayout->addWidget(connectInfoLabel);
#endif
langFromComboBox = new QComboBox;
langToComboBox = new QComboBox;
- int i=0;
- int actualLangTo=0;
- int actualLangFrom=0;
-
foreach(QString langs, GooglePlugin::languages.keys()){
if(langs==_langTo)
- actualLangTo=i;
+ actualLangTo=j;
if(langs==_langFrom)
actualLangFrom=i;
- langToComboBox->addItem(langs);
+ if(langs!="Detect langlage"){
+ langToComboBox->addItem(langs);
+ j++;
+ }
langFromComboBox->addItem(langs);
i++;
}
langToComboBox->setCurrentIndex(actualLangTo);
langFromComboBox->setCurrentIndex(actualLangFrom);
- langFromLayout->addWidget(langFromLabel);
- langFromLayout->addWidget(langFromComboBox);
+ langLayout->addLayout(langsFormLayout);
- langToLayout->addWidget(langToLabel);
- langToLayout->addWidget(langToComboBox);
-
- langLayout->addLayout(langFromLayout);
- langLayout->addLayout(langToLayout);
+ langsFormLayout->addRow(langFromLabel, langFromComboBox);
+ langsFormLayout->addRow(langToLabel, langToComboBox);
changeLangLayout->addLayout(langLayout);
changeLangLayout->addWidget(changeLangButton);
verticalLayout->addWidget(confirmButton);
setModal(true);
+ setMinimumSize(sizeHint());
+ setMaximumSize(sizeHint());
+#endif
}
+
void GoogleDialog::langFromChanged(int index) {
_langFrom=langFromComboBox->itemText(index);
}
+
void GoogleDialog::langToChanged(int index) {
_langTo=langToComboBox->itemText(index);
}
-void GoogleDialog::changeLangButtonClicked() {
- int tempIndexTo=langToComboBox->currentIndex();
- QString tempLangTo=_langTo;
- langToComboBox->setCurrentIndex(langFromComboBox->currentIndex());
- langFromComboBox->setCurrentIndex(tempIndexTo);
+void GoogleDialog::changeLangButtonClicked() {
+ int indexTo=langToComboBox->findText(langFromComboBox->currentText());
+ int indexFrom=langFromComboBox->findText(langToComboBox->currentText());
- _langTo=_langFrom;
- _langFrom=tempLangTo;
+ if(indexTo!= -1 && indexFrom!= -1) {
+ langToComboBox->setCurrentIndex(indexTo);
+ langFromComboBox->setCurrentIndex(indexFrom);
+ }
}
+#ifdef Q_WS_MAEMO_5
void GoogleDialog::accept() {
saveSettings();
-
QDialog::accept();
}
+
void GoogleDialog::saveSettings() {
_settings = new Settings;
if(plugin) {
GooglePlugin::languages.value(_langFrom));
}
+#else
+void GoogleDialog::saveButtonClicked(QString langFrom, QString langTo){
+ saveSettings(langFrom, langTo);
+ QDialog::accept();
+}
+
+void GoogleDialog::saveSettings(QString langFrom, QString langTo){
+ _settings = new Settings;
+ _langFrom = langFrom;
+ _langTo = langTo;
+ if(plugin) {
+ foreach(QString key, plugin->settings()->keys())
+ _settings->setValue(key, plugin->settings()->value(key));
+ }
+
+ _settings->setValue("lang_to",
+ GooglePlugin::languages.value(langTo));
+ _settings->setValue("lang_from",
+ GooglePlugin::languages.value(langFrom));
+}
+#endif
+
Settings* GoogleDialog::getSettings() {
return _settings;
}