From: Marcin Kazmierczak Date: Tue, 5 Oct 2010 13:56:55 +0000 (+0200) Subject: Add check of existing stardict file, when user select .ifo file. Also set path to... X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=b7fac67b7aa565f757177939978ca7c8e1808005;p=mdictionary Add check of existing stardict file, when user select .ifo file. Also set path to this file in plugin's settings --- diff --git a/src/plugins/stardict/StarDialog.cpp b/src/plugins/stardict/StarDialog.cpp index 3874fba..8ca8b3a 100644 --- a/src/plugins/stardict/StarDialog.cpp +++ b/src/plugins/stardict/StarDialog.cpp @@ -23,6 +23,7 @@ #include "StarDialog.h" #include +#include 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; } diff --git a/src/plugins/stardict/StarDialog.h b/src/plugins/stardict/StarDialog.h index 85a08cc..95f4b0e 100644 --- a/src/plugins/stardict/StarDialog.h +++ b/src/plugins/stardict/StarDialog.h @@ -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;