From bc2aa7f7770e5cbb7261f2a99eeef4cac6b0ead7 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 27 Oct 2014 18:11:30 +0100 Subject: [PATCH] Fixed #87. --- resources/text/CHANGELOG | 3 ++- src/core/feedsmodel.cpp | 10 ++++++++++ src/core/feedsmodel.h | 12 ++++++++---- src/core/feedsmodelfeed.cpp | 8 ++------ src/gui/feedmessageviewer.cpp | 6 +++--- src/gui/feedmessageviewer.h | 2 +- src/gui/feedsview.cpp | 3 ++- src/gui/feedsview.h | 6 ++++-- src/gui/systemtrayicon.cpp | 17 +++++++---------- src/gui/systemtrayicon.h | 2 +- 10 files changed, 40 insertions(+), 29 deletions(-) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 07066057a..a099e12ac 100644 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -4,11 +4,12 @@ Fixed: Added: diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index ce0a7242c..f188c4c76 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -549,6 +549,16 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { */ } +bool FeedsModel::hasAnyFeedNewMessages() { + foreach (const FeedsModelFeed *feed, allFeeds()) { + if (feed->status() == FeedsModelFeed::NewMessages) { + return true; + } + } + + return false; +} + bool FeedsModel::mergeModel(FeedsImportExportModel *model, QString &output_message) { if (model == NULL || model->rootItem() == NULL) { output_message = tr("Invalid tree data."); diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 9187ac912..9f71fbf3e 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -114,14 +114,16 @@ class FeedsModel : public QAbstractItemModel { // Returns ALL CHILD feeds contained within single index. QList feedsForIndex(const QModelIndex &index); - // Returns pointer to feed if it lies in given index - // or NULL if no feed lies in given index. + // Returns pointer to feed if it lies on given index + // or NULL if no feed lies on given index. FeedsModelFeed *feedForIndex(const QModelIndex &index); - // Returns pointer to category if it lies in given index - // or NULL if no category lies in given index. + // Returns pointer to category if it lies on given index + // or NULL if no category lies on given index. FeedsModelCategory *categoryForIndex(const QModelIndex &index) const; + // Returns pointer to recycle bin if lies on given index + // or NULL if no recycle bin lies on given index. FeedsModelRecycleBin *recycleBinForIndex(const QModelIndex &index) const; // Returns feed/category which lies at the specified index or @@ -131,6 +133,8 @@ class FeedsModel : public QAbstractItemModel { // Returns source QModelIndex on which lies given item. QModelIndex indexForItem(FeedsModelRootItem *item) const; + bool hasAnyFeedNewMessages(); + // Access to root item. inline FeedsModelRootItem *rootItem() const { return m_rootItem; diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index a0108a2f1..e64678dbb 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -120,17 +120,13 @@ void FeedsModelFeed::updateCounts(bool including_total_count, bool update_feed_s query_all.setForwardOnly(true); if (including_total_count) { - if (query_all.exec(QString("SELECT count(*) FROM Messages " - "WHERE feed = %1 AND is_deleted = 0;").arg(id())) && - query_all.next()) { + if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = %1 AND is_deleted = 0;").arg(id())) && query_all.next()) { m_totalCount = query_all.value(0).toInt(); } } // Obtain count of unread messages. - if (query_all.exec(QString("SELECT count(*) FROM Messages " - "WHERE feed = %1 AND is_deleted = 0 AND is_read = 0;").arg(id())) && - query_all.next()) { + if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = %1 AND is_deleted = 0 AND is_read = 0;").arg(id())) && query_all.next()) { int new_unread_count = query_all.value(0).toInt(); if (update_feed_statuses && m_status == NewMessages && new_unread_count < m_unreadCount) { diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 3e6355589..193fc03b7 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -145,11 +145,11 @@ void FeedMessageViewer::setListHeadersEnabled(bool enable) { m_messagesView->header()->setVisible(enable); } -void FeedMessageViewer::updateTrayIconStatus(int unread_messages, int total_messages) { +void FeedMessageViewer::updateTrayIconStatus(int unread_messages, int total_messages, bool any_unread_messages) { Q_UNUSED(total_messages) if (SystemTrayIcon::isSystemTrayActivated()) { - qApp->trayIcon()->setNumber(unread_messages); + qApp->trayIcon()->setNumber(unread_messages, any_unread_messages); } } @@ -199,7 +199,7 @@ void FeedMessageViewer::createConnections() { connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(int)), m_messagesView, SLOT(reloadSelections(int))); // If counts of unread/all messages change, update the tray icon. - connect(m_feedsView, SIGNAL(messageCountsChanged(int, int)), this, SLOT(updateTrayIconStatus(int, int))); + connect(m_feedsView, SIGNAL(messageCountsChanged(int,int,bool)), this, SLOT(updateTrayIconStatus(int,int,bool))); // Message openers. connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList)), diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 2d7bb66f0..d5001b224 100644 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -95,7 +95,7 @@ class FeedMessageViewer : public TabContent { protected slots: // Updates counts of messages for example in tray icon. - void updateTrayIconStatus(int unread_messages, int total_messages); + void updateTrayIconStatus(int unread_messages, int total_messages, bool any_unread_messages); // Reacts on feed updates. void onFeedUpdatesStarted(); diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 02bba2577..56bc75cb2 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -452,7 +452,8 @@ void FeedsView::openSelectedFeedsInNewspaperMode() { void FeedsView::emptyRecycleBin() { if (MessageBox::show(qApp->mainForm(), QMessageBox::Question, tr("Permanently delete messages"), - tr("You are about to permanenty delete all messages from your recycle bin."), tr("Do you really want to empty your recycle bin?"), + tr("You are about to permanenty delete all messages from your recycle bin."), + tr("Do you really want to empty your recycle bin?"), QString(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { // User changed his mind. return; diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 7a315e34a..bfc04f034 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -131,7 +131,9 @@ class FeedsView : public QTreeView { // Notifies other components about messages // counts. inline void notifyWithCounts() { - emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), m_sourceModel->countOfAllMessages()); + emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), + m_sourceModel->countOfAllMessages(), + m_sourceModel->hasAnyFeedNewMessages()); } // Selects next/previous item (feed/category) in the list. @@ -165,7 +167,7 @@ class FeedsView : public QTreeView { void feedsUpdateRequested(const QList feeds); // Emitted if counts of messages are changed. - void messageCountsChanged(int unread_messages, int total_messages); + void messageCountsChanged(int unread_messages, int total_messages, bool any_feed_has_unread_messages); // Emitted if currently selected feeds needs to be reloaded. void feedsNeedToBeReloaded(int mark_current_index_read); diff --git a/src/gui/systemtrayicon.cpp b/src/gui/systemtrayicon.cpp index a6e1cfd19..8f1a047ba 100755 --- a/src/gui/systemtrayicon.cpp +++ b/src/gui/systemtrayicon.cpp @@ -115,10 +115,9 @@ void SystemTrayIcon::show() { #endif } -void SystemTrayIcon::setNumber(int number) { +void SystemTrayIcon::setNumber(int number, bool any_unread_message) { if (number <= 0) { setToolTip(APP_LONG_NAME); - QSystemTrayIcon::setIcon(QIcon(m_normalIcon)); } else { @@ -127,10 +126,12 @@ void SystemTrayIcon::setNumber(int number) { QPixmap background(m_plainPixmap); QPainter tray_painter; + // TODO: Here draw different background instead of different color of number. + tray_painter.begin(&background); - tray_painter.setBrush(Qt::black); + tray_painter.setPen(any_unread_message ? Qt::blue : Qt::black); tray_painter.setRenderHint(QPainter::SmoothPixmapTransform, true); - tray_painter.setRenderHint(QPainter::TextAntialiasing, false); + tray_painter.setRenderHint(QPainter::TextAntialiasing, true); // Numbers with more than 2 digits won't be readable, display // infinity symbol in that case. @@ -138,9 +139,7 @@ void SystemTrayIcon::setNumber(int number) { m_font.setPixelSize(100); tray_painter.setFont(m_font); - tray_painter.drawText(QRect(0, 0, 128, 128), - Qt::AlignVCenter | Qt::AlignCenter , - QChar(8734)); + tray_painter.drawText(QRect(0, 0, 128, 128), Qt::AlignVCenter | Qt::AlignCenter, QChar(8734)); } else { // Smaller number if it has 3 digits. @@ -156,9 +155,7 @@ void SystemTrayIcon::setNumber(int number) { } tray_painter.setFont(m_font); - tray_painter.drawText(QRect(0, 0, 128, 128), - Qt::AlignVCenter | Qt::AlignCenter , - QString::number(number)); + tray_painter.drawText(QRect(0, 0, 128, 128), Qt::AlignVCenter | Qt::AlignCenter, QString::number(number)); } tray_painter.end(); diff --git a/src/gui/systemtrayicon.h b/src/gui/systemtrayicon.h index 1d6a97723..5d938e361 100644 --- a/src/gui/systemtrayicon.h +++ b/src/gui/systemtrayicon.h @@ -55,7 +55,7 @@ class SystemTrayIcon : public QSystemTrayIcon { virtual ~SystemTrayIcon(); // Sets the number to be visible in the tray icon, number <= 0 removes it. - void setNumber(int number = -1); + void setNumber(int number = -1, bool any_unread_message = false); void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int milliseconds_timeout_hint = TRAY_ICON_BUBBLE_TIMEOUT, QObject *click_target = NULL,