From 8fef2b281c8badcaa51d4eac669975852b96dc9a Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Tue, 25 Oct 2011 17:57:24 +0200 Subject: [PATCH] Open link in the RSS news on user click on the title. --- include/mainwindow.h | 19 ++++++++++++++++++- larss/feedpoller.cpp | 6 ++++++ larss/mainwindow.cpp | 52 ++++++++++++++++++++++++++++++++++++++++------------ ui/mainwindow.ui | 3 +++ 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index b3430e2..b2ee79c 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -34,9 +34,20 @@ private slots: void on_actionAdd_Category_triggered(); - public slots: +public slots: + /** + * @brief Callback for the start of an update of a feed. + */ void loadingFeedStart (QString feedName); + /** + * @brief Load a feed in the webview. + */ + void loadFeed (const QModelIndex& index); + +protected: + bool eventFilter (QObject *object, QEvent *event); + private: Ui::MainWindow *ui; void do_exit(); @@ -45,6 +56,12 @@ private: FeedModel *feedModel; RssParser *rssParser; FeedPoller *poller; + + /** + * @brief A string containing the url to load + * for the loaded in the webview. + */ + QString loadedNews; }; } diff --git a/larss/feedpoller.cpp b/larss/feedpoller.cpp index 796fdf8..b8d6ce8 100644 --- a/larss/feedpoller.cpp +++ b/larss/feedpoller.cpp @@ -42,6 +42,12 @@ FeedPoller::run() queueAll(); + /* Connect timer to their terminations */ + QObject::connect(this, SIGNAL(finished()), + timer, SLOT(stop())); + QObject::connect(this, SIGNAL(finished()), + updaterTimer, SLOT(stop())); + QThread::exec(); } diff --git a/larss/mainwindow.cpp b/larss/mainwindow.cpp index a294759..38d3e0f 100644 --- a/larss/mainwindow.cpp +++ b/larss/mainwindow.cpp @@ -49,6 +49,10 @@ MainWindow::MainWindow(QWidget *parent) : poller->connect(poller, SIGNAL(startLoadingFeed(QString)), this, SLOT(loadingFeedStart(QString))); poller->start(); + + // Install event filter to handle particular events. + ui->webViewTitleLabel->installEventFilter(this); + loadedNews = ""; } MainWindow::~MainWindow() @@ -96,19 +100,8 @@ void Larss::MainWindow::on_feedTreeView_clicked(const QModelIndex &index) void Larss::MainWindow::on_newsTableView_clicked(const QModelIndex &index) { - // Get the number of the row, since index.row () is likely to change - // while we set the read status on the post. - quint32 row_number = index.row(); - // A row got activated, so open it in the webview. - ui->webView->setHtml(rssParser->getContent(index)); - - // Select the right title - ui->webViewTitleLabel->setText(QString("%1").arg(rssParser->getTitle (index))); - - // And then mark it as read - rssParser->setReadStatus(index, true); - ui->newsTableView->selectRow(row_number); + loadFeed(index); } void Larss::MainWindow::on_newsTableView_activated(const QModelIndex &index) @@ -134,3 +127,38 @@ void Larss::MainWindow::on_actionAdd_Category_triggered() feedModel->addCategory(dialog.getCategoryName()); } } + +bool Larss::MainWindow::eventFilter(QObject *object, QEvent *event) +{ + if (object == ui->webViewTitleLabel) + { + if (event->type() == QEvent::MouseButtonPress) + { + QMouseEvent *mouseEvent = static_cast(event); + if (loadedNews != "") + { + ui->webView->load(QUrl(loadedNews)); + } + return true; + } + else + return false; + } + else + return QMainWindow::eventFilter(object, event); + +} + +void Larss::MainWindow::loadFeed(const QModelIndex& index) +{ + quint64 rowNumber = index.row(); + loadedNews = rssParser->getLink(index); + ui->webView->setHtml(rssParser->getContent(index)); + + // Select the right title + ui->webViewTitleLabel->setText(QString("%1").arg(rssParser->getTitle (index))); + + // And then mark it as read + rssParser->setReadStatus(index, true); + ui->newsTableView->selectRow(rowNumber); +} diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index c1f3a62..1eab07f 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -52,6 +52,9 @@ + + PointingHandCursor + -- 2.1.4