Merge branch 'stardict' of ssh://drop.maemo.org/git/mdictionary into stardict
authorMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 14:05:31 +0000 (16:05 +0200)
committerMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 14:05:31 +0000 (16:05 +0200)
Conflicts:
src/plugins/stardict/StarDialog.cpp

debian/mdictionary.install
src/plugins/stardict/StarDialog.cpp
src/plugins/stardict/StarDialog.h
src/plugins/xdxf/XdxfDictDownloader.cpp

index 80cb872..b67ebf1 100644 (file)
@@ -7,4 +7,4 @@ usr/lib/mdictionary/plugins/eng-us.xdxf
 usr/lib/mdictionary/plugins/eng-thai.xdxf
 usr/share/mdictionary/xdxf.png
 usr/share/mdictionary/css/
-usr/share/applications/mdictionary.desktop
+usr/share/applications/hildon/mdictionary.desktop
index c8deb1b..b6b4e78 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "StarDialog.h"
 #include <QDebug>
+#include <QFile>
 
 StarDialog::StarDialog(StarDictPlugin *plugin,
                        StarDialogType type,
@@ -180,6 +181,12 @@ void StarDialog::selectFile() {
     if (!fileName.isEmpty()) {
         infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
         _dictionaryFilePath = fileName;
+        if (_dictionaryFilePath.endsWith(".tar.bz2")){
+                _isCompressed = true;
+        }
+        else {
+                _isCompressed = false;
+        }
         updateGeometry();
     }
 }
@@ -192,6 +199,12 @@ void StarDialog::saveSettings() {
     }
     else {
         _settings->setValue("path", _dictionaryFilePath);
+        _settings->setValue("ifoFileName", _dictName + ".ifo");
+        _settings->setValue("idxFileName", _dictName + ".idx");
+        _settings->setValue("dictFileName", _dictName + ".dict");
+        if (QFile::exists(_dictName + ".syn") == true) {
+                _settings->setValue("synFileName", _dictName + ".syn");
+        }
     }
     if(_accents)
         _settings->setValue("strip_accents", "true");
@@ -206,10 +219,32 @@ void StarDialog::accept() {
         return;
     }
 
+    if(type == New && !_dictionaryFilePath.isEmpty() && !checkFiles()) {
+        Q_EMIT notify(Notify::Warning, tr("Dictionary files are not complete"));
+        return;
+    }
+
     saveSettings();
     QDialog::accept();
 }
 
+bool StarDialog::checkFiles() {
+        if (!_isCompressed){
+               _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
+               if (QFile::exists(_dictName + ".idx") == false && QFile::exists(_dictName + ".idx.gz") == false) {
+                       return false;
+               }
+               if (QFile::exists(_dictName + ".dict") == false && QFile::exists(_dictName + ".dict.dz") == false) {
+                       return false;
+               }
+               return true;
+        }
+        else {
+                //TODO: untar files (?)
+                return false;
+        }
+}
+
 Settings* StarDialog::getSettings() {
     return _settings;
 }
index 1a15ffa..b87cf0f 100644 (file)
@@ -104,6 +104,7 @@ private:
 
     //! saves new settings after acceptance of dialog
     void saveSettings();
+    bool checkFiles();
 
     QLabel* infoLabel;
     QPushButton* browseButton;
@@ -133,6 +134,9 @@ private:
     bool _accents;
     bool _lastAccents;
 
+    bool _isCompressed;
+    QString _dictName;
+
     Settings* _settings;
 
     StarDictPlugin* plugin;
index 908f1ef..6ae05a6 100644 (file)
@@ -27,6 +27,8 @@
 #include "XdxfDictDownloader.h"
 #include "XdxfDictDownloadProgressDialog.h"
 #include <QDebug>
+#include <QProcess>
+
 
 #include <bzlib.h>
 #include <libtar.h>
@@ -211,6 +213,7 @@ bool XdxfDictDownloader::extract(QString file) {
     fclose(archive);
 
     // Extracting tar
+    #ifndef Q_WS_MAEMO_5
     TAR *t;
     char * tarfname = new char[file.replace(QRegExp(".bz2%"), "").size()+1];
     strcpy(tarfname, file.replace(QRegExp(".bz2%"), "").toStdString().c_str());
@@ -224,6 +227,11 @@ bool XdxfDictDownloader::extract(QString file) {
         return false;
     }
     tar_close(t);
+    #else
+    QProcess tar;
+    tar.start("tar -xvf " + file.replace(QRegExp(".bz2%"), "") + " -C /tmp/mdict");
+    tar.waitForFinished(-1);
+    #endif
 
     return true;
 }