code clean
[mdictionary] / src / plugins / stardict / StarDialog.cpp
index da50275..baf11d3 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
+/*!
+    \file StarDialog.cpp
+    \brief Implementation of stardict plugin's dialogs.
 
-//Created by Mateusz Półrola
+    \author Mateusz Półrola <mateusz.polrola@gmail.com>
+*/
 
 #include "StarDialog.h"
 #include <QDebug>
 #include <QFile>
 
 StarDialog::StarDialog(StarDictPlugin *plugin, StarDialogType type,
-                       QWidget *parent) : QDialog(parent) {
+                       QWidget *parent) : QDialog(parent) {                                        
    this->plugin = plugin;
    this->type = type;
-   initializeUI();
+
+#ifndef Q_WS_MAEMO_5
+    view= new QDeclarativeView();
+    view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/StarDictDialog.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    view->setAlignment(Qt::AlignCenter);
+    view->show();
+
+    mainLayout = new QVBoxLayout;
+    mainLayout->addWidget(view);
+    setLayout(mainLayout);
+    view->setWindowTitle(tr("StarDict Settings"));
+
+    QGraphicsObject *rootObject = view->rootObject();
+
+    connect(this, SIGNAL(setInfo(QVariant)),
+           rootObject, SLOT(setInfo(QVariant)));
+    connect(this,SIGNAL(setButtonText(QVariant)),
+            rootObject, SLOT(setButtonText(QVariant)));
+    connect(this,SIGNAL(setNew(QVariant)),
+            rootObject, SLOT(setNew(QVariant)));
+    connect(this,SIGNAL(setPath(QVariant)),
+            rootObject, SLOT(setPath(QVariant)));
+
+    connect(rootObject, SIGNAL(saveButtonClicked()),
+            this, SLOT(accept()));
+    connect(rootObject, SIGNAL(browseButtonClicked()),
+            this, SLOT(selectFile()));
+    connect(rootObject, SIGNAL(heightChange(int)),
+            this, SLOT(heightChange(int)));
+
+#else
    if(type == New)
        connect(browseButton, SIGNAL(clicked()),this, SLOT(selectFile()));
    connect(confirmButton, SIGNAL(clicked()),this, SLOT(accept()));
+#endif
+    initializeUI();
+}
+
+void StarDialog::heightChange(int height){
+    if(height>sizeHint().height())
+        resize(sizeHint().width(),height);
+    lastHeight=height;
 }
 
+void StarDialog::resizeEvent(QResizeEvent *e){
+    QDialog::resizeEvent(e);
+    if(lastHeight>sizeHint().height()){
+        resize(sizeHint().width(),lastHeight);
+    }
+}
 
 void StarDialog::initializeUI() {
+#ifndef Q_WS_MAEMO_5
+    if(type != New){
+        emit setNew(false);
+        QString info=tr("Plugin: ") + plugin->type().toUpper() +"\n" +
+            tr("Book name: ") + plugin->settings()->value("bookname") + "\n" +
+            tr("Version: ") + plugin->settings()->value("version") + "\n" +
+            tr("Word count: ") + plugin->settings()->value("wordcount") + "\n" +
+            tr("Author: ") + plugin->settings()->value("author") + "\n" +
+            tr("E-mail: ") + plugin->settings()->value("email") + "\n" +
+            tr("Website: ") + plugin->settings()->value("website") + "\n" +
+            tr("Description: ") + plugin->settings()->value("description")+"\n"+
+            tr("Date: ") + plugin->settings()->value("date");
+        emit setInfo(info);
+        emit setButtonText("Save settings");
+    }
+    else{
+        emit setNew(true);
+        emit setButtonText("Add");
+    }
+
+    if(!plugin)
+        _dictionaryFilePath = "";
+
+#else
     mainVerticalLayout = new QVBoxLayout;
     widget = new QWidget;
     widget->setLayout(mainVerticalLayout);
@@ -50,7 +123,6 @@ void StarDialog::initializeUI() {
         browseButton->setMaximumWidth(150);
         infoLabel->setText(tr("Dictionary file: not selected"));
         setWindowTitle(tr("Add new StarDict dictionary"));
-        infoLabel->setText(tr("Dictionary file: not selected"));
         browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
         browseLayout->addLayout(buttonLayout);
         browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
@@ -91,8 +163,8 @@ void StarDialog::initializeUI() {
     #else
         if(type==New) {
             infoLabel->setMinimumWidth(200);
-            setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
-            setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
+//            setMinimumSize(sizeHint().width()*1.5, sizeHint().height()*1.2);
+//            setMaximumSize(sizeHint().width()*1.7, sizeHint().height()*1.5);
             scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
         }
     #endif
@@ -110,6 +182,7 @@ void StarDialog::initializeUI() {
     scrollArea->setLineWidth(0);
     scrollArea->setMidLineWidth(0);
     scrollArea->setFrameStyle(QFrame::NoFrame);
+#endif
 }
 
 
@@ -121,20 +194,29 @@ void StarDialog::selectFile() {
                      NULL,
                      NULL);
     if (!fileName.isEmpty()) {
+#ifndef Q_WS_MAEMO_5
+        emit setPath(tr("Dictionary file: %1").arg(fileName));
+#else
         infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
+#endif
         _dictionaryFilePath = fileName;
         if (_dictionaryFilePath.endsWith(".tar.bz2"))
             _isCompressed = true;
         else
             _isCompressed = false;
+#ifndef Q_WS_MAEMO_5
+        resize(view->sizeHint());
+
+#else
         updateGeometry();
+#endif
     }
 }
 
 
 void StarDialog::saveSettings() {
-    _settings = new Settings;
 
+    _settings = new Settings;
     if(plugin)
         foreach(QString key, plugin->settings()->keys())
             _settings->setValue(key, plugin->settings()->value(key));
@@ -154,7 +236,6 @@ void StarDialog::saveSettings() {
         else
             _settings->setValue("dictFileName", _dictName + ".dict");
     }
-
     if(_settings->value("synFileName")=="")
         if (QFile::exists(_dictName + ".syn") == true)
             _settings->setValue("synFileName", _dictName + ".syn");
@@ -187,7 +268,6 @@ bool StarDialog::checkFiles() {
             _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
         }
 
-
         if (QFile::exists(_dictName + ".idx") == false
                 && QFile::exists(_dictName + ".idx.gz") == false) {
             return false;