Add check of existing stardict file, when user select .ifo file. Also set path to...
authorMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 13:56:55 +0000 (15:56 +0200)
committerMarcin Kazmierczak <marcin.kazmierczak@comarch.pl>
Tue, 5 Oct 2010 13:56:55 +0000 (15:56 +0200)
src/plugins/stardict/StarDialog.cpp
src/plugins/stardict/StarDialog.h

index 3874fba..8ca8b3a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "StarDialog.h"
 #include <QDebug>
+#include <QFile>
 
 StarDialog::StarDialog(StarDictPlugin *plugin,
                        StarDialogType type,
@@ -197,13 +198,19 @@ void StarDialog::selectFile() {
     QString fileName = QFileDialog::getOpenFileName(this,
                                      tr("Select dictionary file"),
                                      _dictionaryFilePath,
-                                     tr("XDXF Files (*.xdxf)"),
+                                     tr(".ifo Files (*.ifo)"),
                                      NULL,
                                      NULL);
 
     if (!fileName.isEmpty()) {
         infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
         _dictionaryFilePath = fileName;
+        if (_dictionaryFilePath.endsWith(".tar.bz2")){
+                _isCompressed = true;
+        }
+        else {
+                _isCompressed = false;
+        }
         updateGeometry();
     }
 }
@@ -216,6 +223,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(_generateCache)
@@ -236,10 +249,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 85a08cc..95f4b0e 100644 (file)
@@ -104,6 +104,7 @@ private:
 
     //! saves new settings after acceptance of dialog
     void saveSettings();
+    bool checkFiles();
 
     QLabel* infoLabel;
     QPushButton* browseButton;
@@ -138,6 +139,9 @@ private:
     bool _accents;
     bool _lastAccents;
 
+    bool _isCompressed;
+    QString _dictName;
+
     Settings* _settings;
 
     StarDictPlugin* plugin;