xdxfDialog in qml
[mdictionary] / src / plugins / xdxf / XdxfDialog.cpp
index c0d8bac..32abb55 100644 (file)
@@ -32,14 +32,63 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
                        XdxfDialogType type,
                        QWidget *parent) :
                 QDialog(parent) {
+
     this->plugin = plugin;
     this->type = type;
 
+#ifndef Q_WS_MAEMO_5
+
+    view= new QDeclarativeView();
+    view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/XdxfDialog.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    view->setAlignment(Qt::AlignCenter);
+    view->show();
+
+    mainLayout = new QVBoxLayout;
+    mainLayout->addWidget(view);
+    setLayout(mainLayout);
+    view->setWindowTitle(tr("Xdxf Settings"));
+
+    QGraphicsObject *rootObject = view->rootObject();
+
+    connect(this, SIGNAL(setPlugin(QVariant)),
+           rootObject, SLOT(setPlugin(QVariant)));
+    connect(this, SIGNAL(setFrom(QVariant)),
+           rootObject, SLOT(setFrom(QVariant)));
+    connect(this, SIGNAL(setTo(QVariant)),
+           rootObject, SLOT(setTo(QVariant)));
+    connect(this, SIGNAL(setDescription(QVariant)),
+           rootObject, SLOT(setDescription(QVariant)));
+    connect(this, SIGNAL(setInfo(QVariant)),
+           rootObject, SLOT(setInfo(QVariant)));
+    connect(this, SIGNAL(setCheckedOptimalize(QVariant)),
+           rootObject, SLOT(setCheckedOptimalize(QVariant)));
+    connect(this, SIGNAL(setCheckedStrip(QVariant)),
+           rootObject, SLOT(setCheckedStrip(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(downloadButtonClicked()),
+           this, SLOT(downloadFile()));
+    connect(rootObject, SIGNAL(browseButtonClicked()),
+           this, SLOT(selectFile()));
+
+    connect(rootObject, SIGNAL(optimalizeCheckboxChanged(bool)),
+           this, SLOT(setGenerateCache(bool)));
+    connect(rootObject, SIGNAL(stripCheckboxChanged(bool)),
+           this, SLOT(setAccents(bool)));
+
+#else
+
     cacheToolTip = tr("Optimize for quicker searches (may take some time)");
     accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
 
-    initializeUI();
-
     connect(cacheCheckBox, SIGNAL(toggled(bool)),
             this, SLOT(setGenerateCache(bool)));
     connect(accentsCheckBox, SIGNAL(toggled(bool)),
@@ -60,20 +109,64 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
         connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
                 this, SLOT(fileDownloaded(QString)));
     }
-
     connect(confirmButton, SIGNAL(clicked()),
             this, SLOT(accept()));
-}
-
+#endif
 
-void XdxfDialog::fileDownloaded(QString) {
-    infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
-    _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
-    updateGeometry();
+    initializeUI();
 }
 
 
 void XdxfDialog::initializeUI() {
+#ifndef Q_WS_MAEMO_5
+
+    if(type != New){
+        emit setNew(false);
+        emit setPlugin(plugin->type().toUpper());
+        emit setFrom(plugin->langFrom());
+        emit setTo(plugin->langTo());
+        emit setDescription(plugin->name());
+        emit setInfo(plugin->infoNote());
+    }
+    else{
+        emit setNew(true);
+        connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+                this, SLOT(fileDownloaded(QString)));
+    }
+
+    if(!plugin) {
+        emit setCheckedOptimalize(true);
+        emit setCheckedStrip(true);
+//        accentsCheckBox->setEnabled(false);
+        _generateCache = true;
+        _accents = true;
+        _dictionaryFilePath = "";
+    }
+    else if(plugin && plugin->settings()->value("cached") == "true") {
+        emit setCheckedOptimalize(true);
+        emit setCheckedStrip(true);
+//        accentsCheckBox->setEnabled(false);
+        _generateCache = true;
+        _accents = true;
+    }
+    else {
+        emit setCheckedOptimalize(false);
+        _generateCache = false;
+        if(plugin->settings()->value("strip_accents") == "true") {
+            emit setCheckedStrip(true);
+            _accents = true;
+        }
+        else {
+            emit setCheckedStrip(false);
+            _accents = false;
+        }
+    }
+    if(type == New)
+        emit setButtonText("Add");
+    else
+        emit setButtonText("Save settings");
+
+#else
     mainVerticalLayout = new QVBoxLayout;
     widget = new QWidget;
     widget->setLayout(mainVerticalLayout);
@@ -201,17 +294,29 @@ void XdxfDialog::initializeUI() {
     scrollArea->setLineWidth(0);
     scrollArea->setMidLineWidth(0);
     scrollArea->setFrameStyle(QFrame::NoFrame);
+#endif
 }
 
 
 void XdxfDialog::setAccents(bool accents) {
+    qDebug()<<"setAcents"<<accents;
     _accents = accents;
 }
 
 
 void XdxfDialog::setGenerateCache(bool generate) {
     _generateCache = generate;
-
+#ifndef Q_WS_MAEMO_5
+    if(generate) {
+        _lastAccents = _accents;
+        emit setCheckedOptimalize(true);
+        emit setCheckedStrip(true);
+    }
+    else{
+        emit setCheckedStrip(_lastAccents);
+    }
+//  accentsCheckBox->setEnabled(!generate);
+#else
     if(generate) {
         _lastAccents = _accents;
         accentsCheckBox->setChecked(true);
@@ -219,6 +324,7 @@ void XdxfDialog::setGenerateCache(bool generate) {
     else
         accentsCheckBox->setChecked(_lastAccents);
     accentsCheckBox->setEnabled(!generate);
+#endif
 }
 
 
@@ -230,15 +336,32 @@ void XdxfDialog::selectFile() {
                                      NULL,
                                      NULL);
     if (!fileName.isEmpty()) {
-        infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
         _dictionaryFilePath = fileName;
-        updateGeometry();
+        #ifndef Q_WS_MAEMO_5
+            emit setPath(tr("Dictionary file: %1").arg(fileName));
+        #else
+            infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
+            updateGeometry();
+        #endif
     }
 }
 
 
+void XdxfDialog::fileDownloaded(QString) {
+#ifndef Q_WS_MAEMO_5
+    qDebug()<<"fileDownloaded";
+    emit setPath(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+    _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+#else
+    infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+    _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+    updateGeometry();
+#endif
+}
+
+
 void XdxfDialog::downloadFile() {
-   XdxfPlugin::dictDownloader.download(this);
+    XdxfPlugin::dictDownloader.download(this);
 }
 
 
@@ -250,7 +373,6 @@ void XdxfDialog::saveSettings() {
     }
     else
         _settings->setValue("path", _dictionaryFilePath);
-
     if(_generateCache)
         _settings->setValue("generateCache", "true");
     else