Feed updating every 10 minutes.

Leonardo Robol [2011-10-25 10:56]
Feed updating every 10 minutes.
Filename
include/feedpoller.h
include/mainwindow.h
larss/feedpoller.cpp
larss/mainwindow.cpp
diff --git a/include/feedpoller.h b/include/feedpoller.h
index 1072dab..1e0340d 100644
--- a/include/feedpoller.h
+++ b/include/feedpoller.h
@@ -19,10 +19,13 @@ namespace Larss {
         void stopPolling ();

     signals:
+        void startLoadingFeed (QString name);
+        void finishedLoadingFeed (QString name);

     public slots:
         void networkManagerReplyFinished(QNetworkReply* reply);
         bool poll();
+        void queueAll ();

     private:
         /**
diff --git a/include/mainwindow.h b/include/mainwindow.h
index dc628ec..b3430e2 100644
--- a/include/mainwindow.h
+++ b/include/mainwindow.h
@@ -34,6 +34,9 @@ private slots:

     void on_actionAdd_Category_triggered();

+ public slots:
+    void loadingFeedStart (QString feedName);
+
 private:
     Ui::MainWindow *ui;
     void do_exit();
diff --git a/larss/feedpoller.cpp b/larss/feedpoller.cpp
index 011f576..796fdf8 100644
--- a/larss/feedpoller.cpp
+++ b/larss/feedpoller.cpp
@@ -35,6 +35,13 @@ FeedPoller::run()
                    this, SLOT(poll()));
     timer->start();

+    QTimer* updaterTimer = new QTimer();
+    updaterTimer->setInterval(10 * 60 * 1000);
+    updaterTimer->connect(updaterTimer, SIGNAL(timeout()),
+                   this, SLOT(queueAll()));
+
+    queueAll();
+
     QThread::exec();
 }

@@ -51,6 +58,7 @@ FeedPoller::poll()
             QModelIndex next_item = workQueue->takeFirst();
             FeedNode *node = model->itemFromIndex(next_item);
             nowLoading = node->id();
+            startLoadingFeed(node->name());
             manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
             return true;
         }
@@ -78,6 +86,24 @@ FeedPoller::queueWork(const QModelIndex &index)
 }

 void
+FeedPoller::queueAll()
+{
+    QStandardItem *rootItem = model->invisibleRootItem();
+    for(qint32 i = 0; i < rootItem->rowCount(); i++)
+    {
+        // Get the category
+        FeedNode *categoryNode = model->itemFromIndex(rootItem->child(i, 0)->index());
+
+        // Get all the feed in that category
+        for(qint32 j = 0; j < categoryNode->rowCount(); j++)
+        {
+            QModelIndex feedIndex = categoryNode->child(j, 0)->index ();
+            queueWork(feedIndex);
+        }
+    }
+}
+
+void
 FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
 {
     // Assume that the string is UTF-8 encoded. This is likely to be
@@ -135,7 +161,6 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
             }
             else
             {
-                qDebug() << "Rss 1.0";
                 guid = link;
                 pubDate = QDateTime::currentDateTime().toTime_t();
             }
@@ -170,6 +195,8 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
         qDebug () << "Error parsing the document";

     nowLoading = 0;
+    finishedLoadingFeed("");
+
     return;

     // Check if there is work in the queue
@@ -178,6 +205,7 @@ FeedPoller::networkManagerReplyFinished(QNetworkReply *reply)
         QModelIndex next_item = workQueue->takeFirst();
         FeedNode *node = (FeedNode*) next_item.internalPointer();
         nowLoading = node->id();
+        startLoadingFeed(node->name());
         manager->get(QNetworkRequest(QUrl(model->getUrl(next_item))));
     }
 }
diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp
index b09ce0d..a294759 100644
--- a/larss/mainwindow.cpp
+++ b/larss/mainwindow.cpp
@@ -46,6 +46,8 @@ MainWindow::MainWindow(QWidget *parent) :
     rssParser->setFilter("1 = 0");

     poller = new FeedPoller (this, rssParser, feedModel);
+    poller->connect(poller, SIGNAL(startLoadingFeed(QString)), this,
+                    SLOT(loadingFeedStart(QString)));
     poller->start();
 }

@@ -55,6 +57,12 @@ MainWindow::~MainWindow()
     delete ui;
 }

+void
+MainWindow::loadingFeedStart(QString feedName)
+{
+    ui->statusBar->showMessage(tr("Updating feed '%1'...").arg(feedName), 2000);
+}
+
 void MainWindow::do_exit()
 {
     poller->stopPolling();
ViewGit