Google plugin shows errors only once, when no words are found words list shows text...
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 15 Sep 2010 12:57:13 +0000 (14:57 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 15 Sep 2010 12:57:13 +0000 (14:57 +0200)
src/mdictionary/gui/WordListWidget.cpp
src/plugins/google/GooglePlugin.cpp
src/plugins/google/GooglePlugin.h

index 2ac5d1e..5d278dd 100644 (file)
@@ -97,17 +97,28 @@ void WordListWidget::showSearchResults(
     clear();
     searchResult = result;
 
-    model->setColumnCount(2);
-    model->setRowCount(result.count());
+    if(searchResult.count()>0) {
+        setEnabled(true);
+        model->setColumnCount(2);
+        model->setRowCount(result.count());
+
+        int row=0;
+        QHash<QString, QList<Translation*> >::iterator i;
+        for(i = searchResult.begin(); i != searchResult.end(); i++) {
+               addWord(i.key(), row++);
+        }
 
-    int row=0;
-    QHash<QString, QList<Translation*> >::iterator i;
-    for(i = searchResult.begin(); i != searchResult.end(); i++) {
-           addWord(i.key(), row++);
+        model->sort(0);
+        resizeColumns();
     }
+    else {
+        QStandardItem* item = new QStandardItem(tr("Can't find any matching words"));
+        item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+        item->setTextAlignment(Qt::AlignCenter);
+        setEnabled(false);
 
-    model->sort(0);
-    resizeColumns();    
+        model->setItem(0,item);
+    }
 
     setFocus();
 }
index 95ae0e4..50df74e 100644 (file)
@@ -28,6 +28,8 @@
 #include "GoogleDictDialog.h"
 
 QMap<QString, QString> GooglePlugin::languages;
+bool GooglePlugin::noNetworkErrorShowed = false;
+
 
 GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
                     _name(""),_infoNote("") {
@@ -192,9 +194,11 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int ) {
             error=http->errorString();
 
         if(error!="" && error!="Unknown error") {
-            qDebug()<<error;
-            Q_EMIT notify(Notify::Warning,
-                    tr("GooglePlugin: %1").arg(error));
+            if(!noNetworkErrorShowed) {
+                noNetworkErrorShowed = true;
+                Q_EMIT notify(Notify::Warning,
+                        tr("GooglePlugin: %1").arg(error));
+            }
         }
 
         QString text = QString::fromUtf8(http->readAll());
index 01097bb..17c0154 100644 (file)
@@ -132,6 +132,8 @@ public slots:
 
     //! loads translations for each plugin only once
     void retranslate();
+protected:
+    static bool noNetworkErrorShowed;
 
 private:
     //! name of a dictionary