Added key to skip to the next unread news in the feed.
Leonardo Robol [2011-10-26 20:06]
Added key to skip to the next unread news in the feed.
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 @@
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
+ <widget class="QMenu" name="menuFeed">
+ <property name="title">
+ <string>Feed</string>
+ </property>
+ <addaction name="actionNext_unread_news"/>
+ </widget>
<addaction name="menuFile"/>
+ <addaction name="menuFeed"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionExit">
@@ -136,6 +143,14 @@
<string>Add Category</string>
</property>
</action>
+ <action name="actionNext_unread_news">
+ <property name="text">
+ <string>Next unread news</string>
+ </property>
+ <property name="shortcut">
+ <string>N</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>