change comment's and fix bug (xslt transform)
[mdictionary] / src / plugins / xdxf / XdxfDialog.cpp
index 0927061..070a0bf 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
-//Created by Mateusz Półrola
+/*!
+    \file XdxfDialog.cpp
+    \author Mateusz Półrola <mateusz.polrola@gmail.com>
+*/
 
 #include "XdxfDialog.h"
 #include <QDebug>
 XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
                        XdxfDialogType type,
                        QWidget *parent) :
-    QDialog(parent) {
+                QDialog(parent) {
     this->plugin = plugin;
     this->type = type;
 
-
     cacheToolTip = tr("Optimize for quicker searches (may take some time)");
-    accentsToolTip = tr("Strip accents (searching takes more time, but spelling don't have to be exact)");
+    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)),
             this, SLOT(setAccents(bool)));
 
     #ifdef Q_WS_MAEMO_5
         connect(accentsInfoToolButton, SIGNAL(clicked()),
                  this, SLOT(showAccentsInfo()));
-
         connect(cacheInfoToolButton, SIGNAL(clicked()),
                  this, SLOT(showCacheInfo()));
     #endif
@@ -54,11 +53,21 @@ XdxfDialog::XdxfDialog(XdxfPlugin *plugin,
     if(type == New) {
         connect(browseButton, SIGNAL(clicked()),
                 this, SLOT(selectFile()));
+        connect(downloadButton, SIGNAL(clicked()),
+                this, SLOT(downloadFile()));
+        connect(&XdxfPlugin::dictDownloader, SIGNAL(fileDownloaded(QString)),
+                this, SLOT(fileDownloaded(QString)));
     }
 
     connect(confirmButton, SIGNAL(clicked()),
             this, SLOT(accept()));
+}
 
+
+void XdxfDialog::fileDownloaded(QString) {
+    infoLabel->setText(tr("Dictionary file: %1").arg(XdxfPlugin::dictDownloader.downloadedFile()));
+    _dictionaryFilePath = XdxfPlugin::dictDownloader.downloadedFile();
+    updateGeometry();
 }
 
 
@@ -74,11 +83,21 @@ void XdxfDialog::initializeUI() {
         setWindowTitle(tr("Add new XDXF dictionary"));
 
         browseLayout = new QHBoxLayout;
+
+        QVBoxLayout* buttonLayout = new QVBoxLayout;
         browseButton = new QPushButton(tr("Browse"));
+        browseButton->setMaximumWidth(150);
+
+        downloadButton = new QPushButton(tr("Download"));
+        downloadButton->setMaximumWidth(150);
+
+        infoLayout = new QHBoxLayout;
         infoLabel->setText(tr("Dictionary file: not selected"));
 
-        browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
-        browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
+        browseLayout->addWidget(infoLabel,0,Qt::AlignLeft);
+        browseLayout->addLayout(buttonLayout);
+        buttonLayout->addWidget(browseButton,0,Qt::AlignLeft);
+        buttonLayout->addWidget(downloadButton,0,Qt::AlignLeft);
 
         mainVerticalLayout->addLayout(browseLayout);
     }
@@ -89,7 +108,7 @@ void XdxfDialog::initializeUI() {
                        tr("From: ") + plugin->langFrom() + "\n" +
                        tr("To: ") + plugin->langTo() + "\n" +
                        tr("Description: ") + plugin->name() + "\n" +
-                       tr("License: ") + plugin->infoNote());
+                       plugin->infoNote());
         mainVerticalLayout->addWidget(infoLabel);
     }
 
@@ -104,9 +123,10 @@ void XdxfDialog::initializeUI() {
     #endif
 
     cacheLayout = new QHBoxLayout;
-    cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches"));
+    cacheCheckBox = new QCheckBox(tr("Optimize"));
     cacheCheckBox->setToolTip(cacheToolTip);
     cacheLayout->addWidget(cacheCheckBox);
+
     #ifdef Q_WS_MAEMO_5
         cacheInfoToolButton = new QToolButton;
         cacheInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
@@ -116,7 +136,6 @@ void XdxfDialog::initializeUI() {
     mainVerticalLayout->addLayout(cacheLayout);
     mainVerticalLayout->addLayout(accentsLayout);
 
-
     //load old setting if exists
     if(!plugin) {
         cacheCheckBox->setChecked(true);
@@ -149,18 +168,22 @@ void XdxfDialog::initializeUI() {
 
     confirmButton = new QPushButton;
     mainVerticalLayout->addWidget(confirmButton);
-    if(type == New) {
+    if(type == New)
         confirmButton->setText(tr("Add"));
-    }
-    else {
+    else
         confirmButton->setText(tr("Save settings"));
-    }
 
     scrollArea = new QScrollArea;
     scrollArea->setWidget(widget);
     scrollArea->setWidgetResizable(true);
+
     #ifdef Q_WS_MAEMO_5
         scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    #else
+        if(type==New) {
+            infoLabel->setMinimumWidth(250);
+            scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+        }
     #endif
 
     layout = new QHBoxLayout;
@@ -168,8 +191,14 @@ void XdxfDialog::initializeUI() {
     setLayout(layout);
 
     #ifndef Q_WS_MAEMO_5
-        setMinimumSize(400,200);
+        setMinimumSize(385,200);
+    #else
+        setMinimumHeight(350);
     #endif
+
+    scrollArea->setLineWidth(0);
+    scrollArea->setMidLineWidth(0);
+    scrollArea->setFrameStyle(QFrame::NoFrame);
 }
 
 
@@ -177,6 +206,7 @@ void XdxfDialog::setAccents(bool accents) {
     _accents = accents;
 }
 
+
 void XdxfDialog::setGenerateCache(bool generate) {
     _generateCache = generate;
 
@@ -186,10 +216,10 @@ void XdxfDialog::setGenerateCache(bool generate) {
     }
     else
         accentsCheckBox->setChecked(_lastAccents);
-
     accentsCheckBox->setEnabled(!generate);
 }
 
+
 void XdxfDialog::selectFile() {
     QString fileName = QFileDialog::getOpenFileName(this,
                                      tr("Select dictionary file"),
@@ -197,22 +227,27 @@ void XdxfDialog::selectFile() {
                                      tr("XDXF Files (*.xdxf)"),
                                      NULL,
                                      NULL);
-
     if (!fileName.isEmpty()) {
         infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
         _dictionaryFilePath = fileName;
+        updateGeometry();
     }
 }
 
+
+void XdxfDialog::downloadFile() {
+   XdxfPlugin::dictDownloader.download(this);
+}
+
+
 void XdxfDialog::saveSettings() {
     _settings = new Settings;
     if(plugin) {
         foreach(QString key, plugin->settings()->keys())
             _settings->setValue(key, plugin->settings()->value(key));
     }
-    else {
+    else
         _settings->setValue("path", _dictionaryFilePath);
-    }
 
     if(_generateCache)
         _settings->setValue("generateCache", "true");
@@ -225,10 +260,10 @@ void XdxfDialog::saveSettings() {
         _settings->setValue("strip_accents", "false");
 }
 
+
 void XdxfDialog::accept() {
     if(type == New && _dictionaryFilePath.isEmpty()) {
         Q_EMIT notify(Notify::Warning, tr("File path is not set"));
-
         return;
     }
 
@@ -236,15 +271,18 @@ void XdxfDialog::accept() {
     QDialog::accept();
 }
 
+
 Settings* XdxfDialog::getSettings() {
     return _settings;
 }
 
+
 #ifdef Q_WS_MAEMO_5
     void XdxfDialog::showCacheInfo() {
         Q_EMIT notify(Notify::Warning, cacheToolTip);
     }
 
+
     void XdxfDialog::showAccentsInfo() {
         Q_EMIT notify(Notify::Warning, accentsToolTip);
     }