From 87e461e717227de798b44e60e3f35d31c4c26d83 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 22 Sep 2023 13:14:04 +0200 Subject: [PATCH] save work --- .../core/articlelistnotificationmodel.cpp | 36 ++++++++++++++--- .../core/articlelistnotificationmodel.h | 4 ++ src/librssguard/definitions/definitions.h | 3 +- .../notifications/articlelistnotification.cpp | 40 ++++++++++++++++++- .../notifications/articlelistnotification.h | 6 +++ .../notifications/articlelistnotification.ui | 28 ++++++++++++- .../notifications/basetoastnotification.cpp | 19 ++++++++- .../gui/notifications/basetoastnotification.h | 2 + .../gui/notifications/toastnotification.cpp | 11 +---- .../gui/notifications/toastnotification.h | 1 - 10 files changed, 128 insertions(+), 22 deletions(-) diff --git a/src/librssguard/core/articlelistnotificationmodel.cpp b/src/librssguard/core/articlelistnotificationmodel.cpp index 4b1998dfd..4cb601706 100644 --- a/src/librssguard/core/articlelistnotificationmodel.cpp +++ b/src/librssguard/core/articlelistnotificationmodel.cpp @@ -2,6 +2,8 @@ #include "core/articlelistnotificationmodel.h" +#include "definitions/definitions.h" + ArticleListNotificationModel::ArticleListNotificationModel(QObject* parent) : QAbstractListModel(parent), m_currentPage(-1) {} @@ -10,14 +12,38 @@ ArticleListNotificationModel::~ArticleListNotificationModel() {} void ArticleListNotificationModel::setArticles(const QList& msgs) { m_articles = msgs; m_currentPage = 0; + + reloadWholeLayout(); } -void ArticleListNotificationModel::nextPage() {} +void ArticleListNotificationModel::nextPage() { + emit nextPagePossibleChanged(true); + emit previousPagePossibleChanged(true); +} -void ArticleListNotificationModel::previousPage() {} +void ArticleListNotificationModel::previousPage() { + emit nextPagePossibleChanged(true); + emit previousPagePossibleChanged(true); +} -int ArticleListNotificationModel::rowCount(const QModelIndex& parent) const {} +int ArticleListNotificationModel::rowCount(const QModelIndex& parent) const { + return std::min(int(m_articles.size() - (NOTIFICATIONS_PAGE_SIZE * m_currentPage)), NOTIFICATIONS_PAGE_SIZE); +} -int ArticleListNotificationModel::columnCount(const QModelIndex& parent) const {} +int ArticleListNotificationModel::columnCount(const QModelIndex& parent) const { + return 1; +} -QVariant ArticleListNotificationModel::data(const QModelIndex& index, int role) const {} +QVariant ArticleListNotificationModel::data(const QModelIndex& index, int role) const { + switch (role) { + case Qt::ItemDataRole::DisplayRole: + return m_articles.at((m_currentPage * NOTIFICATIONS_PAGE_SIZE) + index.row()).m_title; + } + + return QVariant(); +} + +void ArticleListNotificationModel::reloadWholeLayout() { + emit layoutAboutToBeChanged(); + emit layoutChanged(); +} diff --git a/src/librssguard/core/articlelistnotificationmodel.h b/src/librssguard/core/articlelistnotificationmodel.h index 96a898a97..c97574d6f 100644 --- a/src/librssguard/core/articlelistnotificationmodel.h +++ b/src/librssguard/core/articlelistnotificationmodel.h @@ -8,6 +8,8 @@ #include "core/message.h" class ArticleListNotificationModel : public QAbstractListModel { + Q_OBJECT + public: explicit ArticleListNotificationModel(QObject* parent = nullptr); virtual ~ArticleListNotificationModel(); @@ -21,6 +23,8 @@ class ArticleListNotificationModel : public QAbstractListModel { virtual int columnCount(const QModelIndex& parent) const; virtual QVariant data(const QModelIndex& index, int role) const; + void reloadWholeLayout(); + signals: void nextPagePossibleChanged(bool possible); void previousPagePossibleChanged(bool possible); diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 61b67d787..1ca9f06f8 100644 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -101,7 +101,7 @@ #define WEB_BROWSER_SCROLL_STEP 50.0 #define NOTIFICATIONS_MARGIN 16 -#define NOTIFICATIONS_WIDTH 256 +#define NOTIFICATIONS_WIDTH 300 #define NOTIFICATIONS_TIMEOUT 15s #define NOTIFICATIONS_PAGE_SIZE 10 @@ -165,6 +165,7 @@ #define LOGSEC_MESSAGEMODEL "message-model: " #define LOGSEC_JS "javascript: " #define LOGSEC_GUI "gui: " +#define LOGSEC_NOTIFICATIONS "notifications: " #define LOGSEC_CORE "core: " #define LOGSEC_NODEJS "nodejs: " #define LOGSEC_DB "database: " diff --git a/src/librssguard/gui/notifications/articlelistnotification.cpp b/src/librssguard/gui/notifications/articlelistnotification.cpp index ecb38c997..321cd8425 100644 --- a/src/librssguard/gui/notifications/articlelistnotification.cpp +++ b/src/librssguard/gui/notifications/articlelistnotification.cpp @@ -2,21 +2,57 @@ #include "gui/notifications/articlelistnotification.h" +#include "core/articlelistnotificationmodel.h" #include "miscellaneous/iconfactory.h" -ArticleListNotification::ArticleListNotification(QWidget* parent) : BaseToastNotification(parent) { +ArticleListNotification::ArticleListNotification(QWidget* parent) + : BaseToastNotification(parent), m_model(new ArticleListNotificationModel(this)) { m_ui.setupUi(this); + setupHeading(m_ui.m_lblTitle); setupCloseButton(m_ui.m_btnClose); m_ui.m_btnNextPage->setIcon(qApp->icons()->fromTheme(QSL("arrow-right"), QSL("stock_right"))); m_ui.m_btnPreviousPage->setIcon(qApp->icons()->fromTheme(QSL("arrow-left"), QSL("stock_left"))); m_ui.m_btnOpenArticleList->setIcon(qApp->icons()->fromTheme(QSL("view-list-details"))); m_ui.m_btnOpenWebBrowser->setIcon(qApp->icons()->fromTheme(QSL("document-open"))); + + connect(m_model, + &ArticleListNotificationModel::nextPagePossibleChanged, + m_ui.m_btnNextPage, + &PlainToolButton::setEnabled); + connect(m_model, + &ArticleListNotificationModel::previousPagePossibleChanged, + m_ui.m_btnPreviousPage, + &PlainToolButton::setEnabled); + + m_ui.m_treeArticles->setAttribute(Qt::WA_NoSystemBackground, true); + + auto pal = m_ui.m_treeArticles->palette(); + + // Make background transparent. + pal.setColor(QPalette::ColorRole::Base, Qt::transparent); + + m_ui.m_treeArticles->setPalette(pal); + m_ui.m_treeArticles->setModel(m_model); + + connect(m_ui.m_cmbFeeds, &QComboBox::currentIndexChanged, this, &ArticleListNotification::showFeed); } void ArticleListNotification::loadResults(const QHash>& new_messages) { setupTimedClosing(); - m_ui.m_treeArticles->setModel() + m_newMessages = new_messages; + + m_ui.m_lblTitle->setText(tr("%n feeds fetched", nullptr, new_messages.size())); + + m_ui.m_cmbFeeds->clear(); + + for (Feed* fd : new_messages.keys()) { + m_ui.m_cmbFeeds->addItem(fd->sanitizedTitle(), QVariant::fromValue(fd)); + } +} + +void ArticleListNotification::showFeed(int index) { + m_model->setArticles(m_newMessages.value(m_ui.m_cmbFeeds->itemData(index).value())); } diff --git a/src/librssguard/gui/notifications/articlelistnotification.h b/src/librssguard/gui/notifications/articlelistnotification.h index f8888165f..d7590abbf 100644 --- a/src/librssguard/gui/notifications/articlelistnotification.h +++ b/src/librssguard/gui/notifications/articlelistnotification.h @@ -10,6 +10,7 @@ #include "ui_articlelistnotification.h" class Feed; +class ArticleListNotificationModel; class ArticleListNotification : public BaseToastNotification { Q_OBJECT @@ -19,8 +20,13 @@ class ArticleListNotification : public BaseToastNotification { void loadResults(const QHash>& new_messages); + private slots: + void showFeed(int index); + private: Ui::ArticleListNotification m_ui; + ArticleListNotificationModel* m_model; + QHash> m_newMessages; }; #endif // ARTICLELISTNOTIFICATION_H diff --git a/src/librssguard/gui/notifications/articlelistnotification.ui b/src/librssguard/gui/notifications/articlelistnotification.ui index fda69a518..4cba4fad9 100644 --- a/src/librssguard/gui/notifications/articlelistnotification.ui +++ b/src/librssguard/gui/notifications/articlelistnotification.ui @@ -25,6 +25,15 @@ + + Qt::ScrollBarAlwaysOff + + + 0 + + + false + true @@ -35,7 +44,7 @@ false - true + false @@ -92,6 +101,22 @@ + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -122,6 +147,7 @@ m_treeArticles m_btnPreviousPage m_btnNextPage + m_cmbFeeds m_btnOpenArticleList m_btnOpenWebBrowser diff --git a/src/librssguard/gui/notifications/basetoastnotification.cpp b/src/librssguard/gui/notifications/basetoastnotification.cpp index a2a59addc..1976557a0 100644 --- a/src/librssguard/gui/notifications/basetoastnotification.cpp +++ b/src/librssguard/gui/notifications/basetoastnotification.cpp @@ -40,14 +40,29 @@ void BaseToastNotification::setupCloseButton(QAbstractButton* btn) { connect(btn, &QAbstractButton::clicked, this, &BaseToastNotification::close); } +void BaseToastNotification::setupHeading(QLabel* lbl) { + auto fon = lbl->font(); + + fon.setBold(true); + fon.setPointSize(fon.pointSize() * 1.2); + + lbl->setFont(fon); +} + void BaseToastNotification::stopTimedClosing() { - killTimer(m_timerId); - m_timerId = -1; + if (m_timerId >= 0) { + killTimer(m_timerId); + m_timerId = -1; + + qDebugNN << LOGSEC_NOTIFICATIONS << "Stopping timed closing for notification."; + } } void BaseToastNotification::setupTimedClosing() { if (m_timerId < 0) { m_timerId = startTimer(NOTIFICATIONS_TIMEOUT); + + qDebugNN << LOGSEC_NOTIFICATIONS << "Starting timed closing for notification."; } } diff --git a/src/librssguard/gui/notifications/basetoastnotification.h b/src/librssguard/gui/notifications/basetoastnotification.h index 7749b073d..d29ac5ceb 100644 --- a/src/librssguard/gui/notifications/basetoastnotification.h +++ b/src/librssguard/gui/notifications/basetoastnotification.h @@ -6,6 +6,7 @@ #include class QAbstractButton; +class QLabel; class BaseToastNotification : public QDialog { Q_OBJECT @@ -22,6 +23,7 @@ class BaseToastNotification : public QDialog { virtual void timerEvent(QTimerEvent* event); virtual void closeEvent(QCloseEvent* event); + void setupHeading(QLabel* lbl); void setupTimedClosing(); void setupCloseButton(QAbstractButton* btn); void stopTimedClosing(); diff --git a/src/librssguard/gui/notifications/toastnotification.cpp b/src/librssguard/gui/notifications/toastnotification.cpp index c057be392..1062c82e6 100644 --- a/src/librssguard/gui/notifications/toastnotification.cpp +++ b/src/librssguard/gui/notifications/toastnotification.cpp @@ -8,15 +8,6 @@ #include #endif -void ToastNotification::setupHeading() { - auto fon = m_ui.m_lblTitle->font(); - - fon.setBold(true); - fon.setPointSize(fon.pointSize() * 1.2); - - m_ui.m_lblTitle->setFont(fon); -} - ToastNotification::ToastNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action, @@ -24,7 +15,7 @@ ToastNotification::ToastNotification(Notification::Event event, : BaseToastNotification() { m_ui.setupUi(this); - setupHeading(); + setupHeading(m_ui.m_lblTitle); setupCloseButton(m_ui.m_btnClose); setupTimedClosing(); diff --git a/src/librssguard/gui/notifications/toastnotification.h b/src/librssguard/gui/notifications/toastnotification.h index c919fe023..463671914 100644 --- a/src/librssguard/gui/notifications/toastnotification.h +++ b/src/librssguard/gui/notifications/toastnotification.h @@ -19,7 +19,6 @@ class ToastNotification : public BaseToastNotification { QWidget* parent = nullptr); private: - void setupHeading(); void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action); QIcon iconForType(QSystemTrayIcon::MessageIcon icon) const;