Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / plugins / google / GoogleDialog.cpp
index a8dd8ab..657640a 100644 (file)
     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>
 */
 
@@ -45,8 +47,6 @@ GoogleDialog::GoogleDialog(GooglePlugin *plugin,
         _langFrom=GooglePlugin::languages.key("en");
     }
 
-
-
     initializeUI();
 
     connect(confirmButton, SIGNAL(clicked()),
@@ -64,6 +64,10 @@ GoogleDialog::GoogleDialog(GooglePlugin *plugin,
 
 
 void GoogleDialog::initializeUI() {
+    int i=0,j=0;
+    int actualLangTo=0;
+    int actualLangFrom=0;
+
     setWindowTitle(tr("Google Plugin Settings"));
 
     langFromLabel = new QLabel(tr("From:"));
@@ -72,16 +76,14 @@ void GoogleDialog::initializeUI() {
     verticalLayout = new QVBoxLayout;
     setLayout(verticalLayout);
 
-
     langLayout = new QVBoxLayout;
     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"),"");
@@ -93,27 +95,25 @@ void GoogleDialog::initializeUI() {
                    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++;
     }
@@ -124,7 +124,6 @@ void GoogleDialog::initializeUI() {
     langLayout->addLayout(langsFormLayout);
 
     langsFormLayout->addRow(langFromLabel, langFromComboBox);
-
     langsFormLayout->addRow(langToLabel, langToComboBox);
 
     changeLangLayout->addLayout(langLayout);
@@ -143,33 +142,38 @@ void GoogleDialog::initializeUI() {
     verticalLayout->addWidget(confirmButton);
 
     setModal(true);
+    setMinimumSize(sizeHint());
+    setMaximumSize(sizeHint());
 }
 
+
 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);
+    }
 }
 
+
 void GoogleDialog::accept() {
     saveSettings();
-
     QDialog::accept();
 }
 
+
 void GoogleDialog::saveSettings() {
     _settings = new Settings;
     if(plugin) {
@@ -183,6 +187,7 @@ void GoogleDialog::saveSettings() {
                         GooglePlugin::languages.value(_langFrom));
 }
 
+
 Settings* GoogleDialog::getSettings() {
     return _settings;
 }