Added exception and event handling: gui & plugin
authorBartosz Szatkowski <bulislaw@linux.com>
Mon, 23 Aug 2010 07:56:40 +0000 (09:56 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Mon, 23 Aug 2010 07:56:40 +0000 (09:56 +0200)
trunk/src/base/backbone/Bookmarks.cpp
trunk/src/base/backbone/backbone.cpp
trunk/src/base/gui/MainWindow.cpp
trunk/src/base/gui/main.cpp
trunk/src/includes/Notify.h
trunk/src/plugins/xdxf/src/XdxfCachingDialog.cpp
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

index 2f20ea9..c39a2fa 100644 (file)
@@ -60,7 +60,6 @@ void Bookmarks::add(Translation* translation) {
 }
 
 
-
 void Bookmarks::remove(Translation* translation) {
     QSqlDatabase db = getDbCnx(dbName);
     if(!db.isOpen() && !db.open()) {
index c288a7d..e65582f 100644 (file)
@@ -30,7 +30,7 @@
 
 int Backbone::_searchLimit;
 
-// Sadly QtConcurent mapped dont let me use something like calling method of
+// Sadly QtConcurent::mapped dosent let me use something like calling method of
 // some class with supplied argument
 QString mappedSearch;
 QList<Translation*> mapSearch(CommonDictInterface *dict) {
index 24d699b..d92f839 100644 (file)
@@ -329,6 +329,7 @@ Settings* MainWindow::settings() {
 
 
 void MainWindow::showNotify(Notify::NotifyType type, QString text) {
+
     switch(type) {
     case Notify::Info:
         #ifdef Q_WS_MAEMO_5
@@ -341,9 +342,12 @@ void MainWindow::showNotify(Notify::NotifyType type, QString text) {
         break;
 
     case Notify::Warning:
+        qDebug() << text;
         #ifndef Q_WS_MAEMO_5
                 QMessageBox::warning(this, "Warning", text);
                 break;
+        #else
+            QMessageBox::information(this, "Warning", text);
         #endif
 
     case Notify::Error:
@@ -400,6 +404,9 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(searchCanceled()),
             this, SIGNAL(setIdle()));
 
+    connect(backbone, SIGNAL(notify(Notify::NotifyType,QString)),
+            this, SLOT(showNotify(Notify::NotifyType,QString)));
+
 
 
 
index c5879c5..f047889 100644 (file)
@@ -25,6 +25,7 @@
 #include "MainWindow.h"
 #include "../backbone/backbone.h"
 #include "../../includes/translation.h"
+#include "../../includes/Notify.h"
 #include <QDebug>
 
 
@@ -60,6 +61,8 @@ int main(int argc, char *argv[]) {
 
     qRegisterMetaType<Translation*>("Translation*");
     qRegisterMetaType<QList<Translation*> >("QList<Translation*>");
+    qRegisterMetaType<Notify>("Notify");
+    qRegisterMetaType<Notify::NotifyType>("Notify::NotifyType");
     Backbone backbone;
     MainWindow w(&backbone);
     w.show();
index 7fe2995..a5266e9 100644 (file)
@@ -29,6 +29,7 @@
 #define NOTIFY_H
 
 #include <QObject>
+#include <QMetaClassInfo>
 
 /*! Notify wraps NotifyType which is interpreted by GUI and may change way in
     which GUI handles given notification
@@ -36,6 +37,8 @@
 class Notify : QObject {
     Q_OBJECT
 public:
+    Notify() : QObject(0) {}
+    Notify(const Notify&) : QObject(0) {}
     enum notifytype {Error, Warning, Info};
     Q_DECLARE_FLAGS(NotifyType, notifytype);
 };
index 8cb8e45..2b6932f 100644 (file)
@@ -70,6 +70,9 @@ void XdxfCachingDialog::updateCachingProgress(int progress, int time) {
 
     cachingLabel->setText(tr("Estimated time left: ") +
                       QString::number(seconds) + tr(" seconds"));
+    if(progress >= 100)
+        this->hide();
+        
 
 }
 
index 26e0176..09db806 100644 (file)
@@ -125,7 +125,6 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
             settings->setValue(key, plugin->settings()->value(key));
         settings->setValue("path", settingsDialog.dicitonaryFilePath());
 
-        qDebug()<<settingsDialog.generateCache();
         if(settingsDialog.generateCache()) {
             settings->setValue("generateCache", "true");
         }
index 6a812ee..d2a81fd 100644 (file)
@@ -29,6 +29,7 @@
 #include <QtPlugin>
 #include "TranslationXdxf.h"
 #include "../../../includes/settings.h"
+#include "../../../includes/Notify.h"
 
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
@@ -90,6 +91,9 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
         db.setDatabaseName(cacheFilePath);
         if(!db.open()) {
             qDebug() << "Database error" << db.lastError().text() << endl;
+            Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                    "opened for %1 dictionary. Searching in xdxf file. "
+                    "You may want to recache.").arg(name()));
             return searchWordListFile(word, limit);
         }
 
@@ -137,6 +141,8 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     regWord.setPatternSyntax(QRegExp::Wildcard);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1").arg(name()));
         return translations.toList();
     }
 
@@ -188,6 +194,9 @@ QString XdxfPlugin::searchCache(QString key) {
 
     if(!db.open()) {
         qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                "opened for %1 dictionary. Searching in xdxf file. "
+                "You may want to recache.").arg(name()));
         return searchFile(key);
     }
 
@@ -207,6 +216,8 @@ QString XdxfPlugin::searchFile(QString key) {
     QFile dictionaryFile(path);
     QString resultString("");
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1").arg(name()));
         qDebug()<<"Error: could not open file";
         return "";
     }
@@ -341,6 +352,8 @@ void XdxfPlugin::setSettings(Settings *settings) {
 void XdxfPlugin::getDictionaryInfo() {
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+       Q_EMIT notify(Notify::Warning,
+               QString("Xdxf file cannot be read dictionary"));
         qDebug()<<"Error: could not open file";
         return;
     }
@@ -398,6 +411,9 @@ int XdxfPlugin::countWords() {
 
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1 dictionary")
+                .arg(name()));
         qDebug()<<"Error: could not open file";
         return -1;
     }
@@ -431,6 +447,10 @@ bool XdxfPlugin::makeCache(QString dir) {
 
 
     if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning,
+                QString("Xdxf file cannot be read for %1 dictionary")
+                .arg(name()));
         return 0;
     }
 
@@ -439,6 +459,10 @@ bool XdxfPlugin::makeCache(QString dir) {
     db.setDatabaseName(cachePathN);
     if(!db.open()) {
         qDebug() << "Database error" << db.lastError().text() << endl;
+        Q_EMIT updateCachingProgress(100, 0);
+        Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+                "opened for %1 dictionary. Searching in xdxf file. "
+                "You may want to recache.").arg(name()));
         return false;
     }
     QCoreApplication::processEvents();
@@ -513,6 +537,9 @@ bool XdxfPlugin::makeCache(QString dir) {
 
     if(!cur.next() || countWords() != cur.value(0).toInt())
     {
+        Q_EMIT updateCachingProgress(100, timer.restart());
+        Q_EMIT notify(Notify::Warning,
+                QString("Database caching error, please try againg."));
         db.close();
         return false;
     }