From ad0771ffe019c5e43218b9eb99f14e757ce9dde6 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 13 Nov 2015 08:44:37 +0100 Subject: [PATCH] Some changes for notifications and some tiny preps for messages part of new "plugin" API. --- resources/text/CHANGELOG | 2 ++ src/core/messagesmodel.cpp | 7 +++--- src/core/messagesmodel.h | 3 ++- src/core/rootitem.cpp | 6 +++++ src/core/rootitem.h | 3 +++ src/definitions/definitions.h.in | 2 +- src/gui/dialogs/formabout.ui | 8 +++---- src/gui/messagesview.cpp | 8 +++---- src/gui/messagesview.h | 32 +++++++++++++------------- src/gui/notifications/notification.cpp | 0 src/main.cpp | 10 +++++++- src/services/abstract/feed.h | 3 --- 12 files changed, 51 insertions(+), 33 deletions(-) mode change 100644 => 100755 src/gui/dialogs/formabout.ui mode change 100644 => 100755 src/gui/notifications/notification.cpp diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index a5c6fd6ca..0985b6079 100644 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -21,6 +21,8 @@ Fixed: diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index 2ac6e9e42..cae3e6e30 100755 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -394,7 +394,7 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int } } -bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int read) { +bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, RootItem::ReadStatus read) { QSqlDatabase db_handle = database(); QSqlQuery query_read_msg(db_handle); QStringList message_ids; @@ -406,8 +406,9 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re message_ids.append(QString::number(messageId(message.row()))); } - if (query_read_msg.exec(QString(QSL("UPDATE Messages SET is_read = %2 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")), - QString::number(read)))) { + if (query_read_msg.exec(QString(QSL("UPDATE Messages SET is_read = %2 WHERE id IN (%1);")) + .arg(message_ids.join(QSL(", ")), + read == RootItem::Read ? QSL("1") : QSL("0")))) { select(); fetchAll(); diff --git a/src/core/messagesmodel.h b/src/core/messagesmodel.h index ad0d42a24..312982288 100755 --- a/src/core/messagesmodel.h +++ b/src/core/messagesmodel.h @@ -22,6 +22,7 @@ #include "core/feedsselection.h" #include "core/message.h" +#include "core/rootitem.h" #include #include @@ -80,7 +81,7 @@ class MessagesModel : public QSqlTableModel { // changes ARE written to the database. bool switchBatchMessageImportance(const QModelIndexList &messages); bool setBatchMessagesDeleted(const QModelIndexList &messages, int deleted); - bool setBatchMessagesRead(const QModelIndexList &messages, int read); + bool setBatchMessagesRead(const QModelIndexList &messages, RootItem::ReadStatus read); bool setBatchMessagesRestored(const QModelIndexList &messages); // Fetches ALL available data to the model. diff --git a/src/core/rootitem.cpp b/src/core/rootitem.cpp index ea0d35090..6cd3d9412 100755 --- a/src/core/rootitem.cpp +++ b/src/core/rootitem.cpp @@ -88,6 +88,12 @@ bool RootItem::cleanMessages(bool clear_only_read) { return result; } +void RootItem::updateCounts(bool including_total_count) { + foreach (RootItem *child, m_childItems) { + child->updateCounts(including_total_count); + } +} + void RootItem::setupFonts() { m_normalFont = Application::font("FeedsView"); m_boldFont = m_normalFont; diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 4ccc84947..1faf2f308 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -107,6 +107,9 @@ class RootItem : public QObject { // service account, it should not do anything. virtual bool cleanMessages(bool clear_only_read); + // Updates counts of all/unread messages for this feed. + virtual void updateCounts(bool including_total_count); + virtual int row() const; virtual QVariant data(int column, int role) const; diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in index adc147a8d..1a44da62a 100755 --- a/src/definitions/definitions.h.in +++ b/src/definitions/definitions.h.in @@ -82,7 +82,7 @@ #define ACCEPT_HEADER_FOR_FEED_DOWNLOADER "application/atom+xml,application/xml;q=0.9,text/xml;q=0.8,*/*;q=0.7" #define MIME_TYPE_ITEM_POINTER "@APP_LOW_NAME@/itempointer" #define DOWNLOADER_ICON_SIZE 48 -#define NOTIFICATION_ICON_SIZE 64 +#define NOTIFICATION_ICON_SIZE 32 #define GOOGLE_SEARCH_URL "https://www.google.com/search?q=%1&ie=utf-8&oe=utf-8" #define GOOGLE_SUGGEST_URL "http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=%1" #define ENCRYPTION_FILE_NAME "key.private" diff --git a/src/gui/dialogs/formabout.ui b/src/gui/dialogs/formabout.ui old mode 100644 new mode 100755 index 696b2d41e..c30ecdfc5 --- a/src/gui/dialogs/formabout.ui +++ b/src/gui/dialogs/formabout.ui @@ -104,7 +104,7 @@ - 3 + 2 @@ -166,8 +166,8 @@ p, li { white-space: pre-wrap; } 0 0 - 685 - 184 + 98 + 69 @@ -242,7 +242,7 @@ p, li { white-space: pre-wrap; } 0 0 - 83 + 98 69 diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 7484ed092..d80cc415f 100755 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -318,14 +318,14 @@ void MessagesView::sendSelectedMessageViaEmail() { } void MessagesView::markSelectedMessagesRead() { - setSelectedMessagesReadStatus(1); + setSelectedMessagesReadStatus(RootItem::Read); } void MessagesView::markSelectedMessagesUnread() { - setSelectedMessagesReadStatus(0); + setSelectedMessagesReadStatus(RootItem::Unread); } -void MessagesView::setSelectedMessagesReadStatus(int read) { +void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) { QModelIndex current_index = selectionModel()->currentIndex(); if (!current_index.isValid()) { @@ -342,7 +342,7 @@ void MessagesView::setSelectedMessagesReadStatus(int read) { selected_indexes = m_proxyModel->mapListFromSource(mapped_indexes, true); current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(), mapped_current_index.column())); - if (read == 0) { + if (read == RootItem::Unread) { // User selected to mark some messages as unread, if one // of them will be marked as current, then it will be read again. m_batchUnreadSwitch = true; diff --git a/src/gui/messagesview.h b/src/gui/messagesview.h index c84c4dd77..5d97a6318 100755 --- a/src/gui/messagesview.h +++ b/src/gui/messagesview.h @@ -21,6 +21,7 @@ #include "core/messagesmodel.h" #include "core/feedsselection.h" +#include "core/rootitem.h" #include #include @@ -47,9 +48,6 @@ class MessagesView : public QTreeView { return m_sourceModel; } - // Creates needed connections. - void createConnections(); - public slots: void keyboardSearch(const QString &search); @@ -70,7 +68,7 @@ class MessagesView : public QTreeView { void sendSelectedMessageViaEmail(); // Works with SELECTED messages only. - void setSelectedMessagesReadStatus(int read); + void setSelectedMessagesReadStatus(RootItem::ReadStatus read); void markSelectedMessagesRead(); void markSelectedMessagesUnread(); void switchSelectedMessagesImportance(); @@ -94,7 +92,20 @@ class MessagesView : public QTreeView { // Saves current sort state. void saveSortState(int column, Qt::SortOrder order); - protected: + signals: + // Link/message openers. + void openLinkNewTab(const QString &link); + void openLinkMiniBrowser(const QString &link); + void openMessagesInNewspaperView(const QList &messages); + + // Notify others about message selections. + void currentMessagesChanged(const QList &messages); + void currentMessagesRemoved(); + + private: + // Creates needed connections. + void createConnections(); + // Initializes context menu. void initializeContextMenu(); @@ -108,17 +119,6 @@ class MessagesView : public QTreeView { void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); - signals: - // Link/message openers. - void openLinkNewTab(const QString &link); - void openLinkMiniBrowser(const QString &link); - void openMessagesInNewspaperView(const QList &messages); - - // Notify others about message selections. - void currentMessagesChanged(const QList &messages); - void currentMessagesRemoved(); - - private: QMenu *m_contextMenu; MessagesProxyModel *m_proxyModel; diff --git a/src/gui/notifications/notification.cpp b/src/gui/notifications/notification.cpp old mode 100644 new mode 100755 diff --git a/src/main.cpp b/src/main.cpp index 9ce0874b6..2ed89e78e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -120,7 +120,15 @@ int main(int argc, char *argv[]) { // Setup single-instance behavior. QObject::connect(&application, SIGNAL(messageReceived(QString)), &application, SLOT(processExecutionMessage(QString))); - qApp->showGuiMessage(QSL(APP_NAME), QObject::tr("Welcome to %1 %2.").arg(APP_NAME, APP_VERSION), QSystemTrayIcon::NoIcon); + + if (qApp->isFirstRun() || qApp->isFirstRun(APP_VERSION)) { + qApp->showGuiMessage(QSL(APP_NAME), QObject::tr("Welcome to %1.\n\nPlease, check NEW stuff included in this\n" + "version by clicking this popup notification.").arg(APP_LONG_NAME), + QSystemTrayIcon::NoIcon, 0, false, QIcon(), &main_window, SLOT(showAbout())); + } + else { + qApp->showGuiMessage(QSL(APP_NAME), QObject::tr("Welcome to %1.").arg(APP_LONG_NAME), QSystemTrayIcon::NoIcon); + } // Enter global event loop. return Application::exec(); diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index fdfde7f54..992f3174d 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -59,9 +59,6 @@ class Feed : public RootItem { // Performs synchronous update and returns number of newly updated messages. virtual int update() = 0; - // Updates counts of all/unread messages for this feed. - virtual void updateCounts(bool including_total_count) = 0; - // Get ALL undeleted messages from this feed in one single list. virtual QList undeletedMessages() const = 0;