From 188b78cc26bc38b75d7afa6db9fd925db7e1228e Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 26 Oct 2011 22:06:44 +0200 Subject: [PATCH] Added key to skip to the next unread news in the feed. --- include/mainwindow.h | 2 ++ include/rssparser.h | 5 +++++ larss/mainwindow.cpp | 14 +++++++++++--- larss/rssparser.cpp | 15 +++++++++++++++ ui/mainwindow.ui | 15 +++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 5faff7f..283f191 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -34,6 +34,8 @@ private slots: void on_actionAdd_Category_triggered(); + void on_actionNext_unread_news_triggered(); + public slots: /** * @brief Callback for the start of an update of a feed. diff --git a/include/rssparser.h b/include/rssparser.h index a240e38..53cca45 100644 --- a/include/rssparser.h +++ b/include/rssparser.h @@ -73,6 +73,11 @@ namespace Larss { void selectActiveFeed (quint64 feed_id); /** + * @brief Get the next unread element. + */ + int getNextUnread (const QModelIndex& index); + + /** * @brief Database where all the news will be loaded and saved. */ QSqlDatabase db; diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp index 1766f1b..cbbfe59 100644 --- a/larss/mainwindow.cpp +++ b/larss/mainwindow.cpp @@ -113,9 +113,6 @@ void MainWindow::on_actionExit_activated() void Larss::MainWindow::on_feedTreeView_clicked(const QModelIndex &index) { - // Trigger refresh of selected item - poller->queueWork(index); - // Set the active filter quint64 feed_id; if ((feed_id = rssParser->getFeed (index))) @@ -193,3 +190,14 @@ void Larss::MainWindow::loadFeed(const QModelIndex& index) rssParser->setReadStatus(index, true); ui->newsTableView->selectRow(rowNumber); } + +void Larss::MainWindow::on_actionNext_unread_news_triggered() +{ + QModelIndex index = ui->newsTableView->selectionModel()->currentIndex(); + int nextUnread = rssParser->getNextUnread(index); + if (nextUnread > 0) + { + ui->newsTableView->selectRow(nextUnread); + loadFeed (ui->newsTableView->selectionModel()->currentIndex()); + } +} diff --git a/larss/rssparser.cpp b/larss/rssparser.cpp index 28313b1..be2e6b5 100644 --- a/larss/rssparser.cpp +++ b/larss/rssparser.cpp @@ -168,3 +168,18 @@ Larss::RssParser::selectActiveFeed(quint64 feed_id) // Show only the news from the given feed setFilter(QString("feed='%1'").arg(feed_id)); } + +int +Larss::RssParser::getNextUnread(const QModelIndex& starting) +{ + int row = starting.row(); + while (row < rowCount(starting.parent())) + { + QSqlRecord record = this->record(row); + if (record.value("read").toInt() == 0) + return row; + row++; + } + + return -1; +} diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index b75b12d..286a875 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -118,7 +118,14 @@ + + + Feed + + + + @@ -136,6 +143,14 @@ Add Category + + + Next unread news + + + N + + -- 2.1.4