save work
This commit is contained in:
parent
46fe50df91
commit
87e461e717
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "core/articlelistnotificationmodel.h"
|
#include "core/articlelistnotificationmodel.h"
|
||||||
|
|
||||||
|
#include "definitions/definitions.h"
|
||||||
|
|
||||||
ArticleListNotificationModel::ArticleListNotificationModel(QObject* parent)
|
ArticleListNotificationModel::ArticleListNotificationModel(QObject* parent)
|
||||||
: QAbstractListModel(parent), m_currentPage(-1) {}
|
: QAbstractListModel(parent), m_currentPage(-1) {}
|
||||||
|
|
||||||
|
@ -10,14 +12,38 @@ ArticleListNotificationModel::~ArticleListNotificationModel() {}
|
||||||
void ArticleListNotificationModel::setArticles(const QList<Message>& msgs) {
|
void ArticleListNotificationModel::setArticles(const QList<Message>& msgs) {
|
||||||
m_articles = msgs;
|
m_articles = msgs;
|
||||||
m_currentPage = 0;
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "core/message.h"
|
#include "core/message.h"
|
||||||
|
|
||||||
class ArticleListNotificationModel : public QAbstractListModel {
|
class ArticleListNotificationModel : public QAbstractListModel {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ArticleListNotificationModel(QObject* parent = nullptr);
|
explicit ArticleListNotificationModel(QObject* parent = nullptr);
|
||||||
virtual ~ArticleListNotificationModel();
|
virtual ~ArticleListNotificationModel();
|
||||||
|
@ -21,6 +23,8 @@ class ArticleListNotificationModel : public QAbstractListModel {
|
||||||
virtual int columnCount(const QModelIndex& parent) const;
|
virtual int columnCount(const QModelIndex& parent) const;
|
||||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||||
|
|
||||||
|
void reloadWholeLayout();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nextPagePossibleChanged(bool possible);
|
void nextPagePossibleChanged(bool possible);
|
||||||
void previousPagePossibleChanged(bool possible);
|
void previousPagePossibleChanged(bool possible);
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
#define WEB_BROWSER_SCROLL_STEP 50.0
|
#define WEB_BROWSER_SCROLL_STEP 50.0
|
||||||
|
|
||||||
#define NOTIFICATIONS_MARGIN 16
|
#define NOTIFICATIONS_MARGIN 16
|
||||||
#define NOTIFICATIONS_WIDTH 256
|
#define NOTIFICATIONS_WIDTH 300
|
||||||
#define NOTIFICATIONS_TIMEOUT 15s
|
#define NOTIFICATIONS_TIMEOUT 15s
|
||||||
#define NOTIFICATIONS_PAGE_SIZE 10
|
#define NOTIFICATIONS_PAGE_SIZE 10
|
||||||
|
|
||||||
|
@ -165,6 +165,7 @@
|
||||||
#define LOGSEC_MESSAGEMODEL "message-model: "
|
#define LOGSEC_MESSAGEMODEL "message-model: "
|
||||||
#define LOGSEC_JS "javascript: "
|
#define LOGSEC_JS "javascript: "
|
||||||
#define LOGSEC_GUI "gui: "
|
#define LOGSEC_GUI "gui: "
|
||||||
|
#define LOGSEC_NOTIFICATIONS "notifications: "
|
||||||
#define LOGSEC_CORE "core: "
|
#define LOGSEC_CORE "core: "
|
||||||
#define LOGSEC_NODEJS "nodejs: "
|
#define LOGSEC_NODEJS "nodejs: "
|
||||||
#define LOGSEC_DB "database: "
|
#define LOGSEC_DB "database: "
|
||||||
|
|
|
@ -2,21 +2,57 @@
|
||||||
|
|
||||||
#include "gui/notifications/articlelistnotification.h"
|
#include "gui/notifications/articlelistnotification.h"
|
||||||
|
|
||||||
|
#include "core/articlelistnotificationmodel.h"
|
||||||
#include "miscellaneous/iconfactory.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);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
|
setupHeading(m_ui.m_lblTitle);
|
||||||
setupCloseButton(m_ui.m_btnClose);
|
setupCloseButton(m_ui.m_btnClose);
|
||||||
|
|
||||||
m_ui.m_btnNextPage->setIcon(qApp->icons()->fromTheme(QSL("arrow-right"), QSL("stock_right")));
|
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_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_btnOpenArticleList->setIcon(qApp->icons()->fromTheme(QSL("view-list-details")));
|
||||||
m_ui.m_btnOpenWebBrowser->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
|
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<Feed*, QList<Message>>& new_messages) {
|
void ArticleListNotification::loadResults(const QHash<Feed*, QList<Message>>& new_messages) {
|
||||||
setupTimedClosing();
|
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<Feed*>()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "ui_articlelistnotification.h"
|
#include "ui_articlelistnotification.h"
|
||||||
|
|
||||||
class Feed;
|
class Feed;
|
||||||
|
class ArticleListNotificationModel;
|
||||||
|
|
||||||
class ArticleListNotification : public BaseToastNotification {
|
class ArticleListNotification : public BaseToastNotification {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -19,8 +20,13 @@ class ArticleListNotification : public BaseToastNotification {
|
||||||
|
|
||||||
void loadResults(const QHash<Feed*, QList<Message>>& new_messages);
|
void loadResults(const QHash<Feed*, QList<Message>>& new_messages);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void showFeed(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ArticleListNotification m_ui;
|
Ui::ArticleListNotification m_ui;
|
||||||
|
ArticleListNotificationModel* m_model;
|
||||||
|
QHash<Feed*, QList<Message>> m_newMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ARTICLELISTNOTIFICATION_H
|
#endif // ARTICLELISTNOTIFICATION_H
|
||||||
|
|
|
@ -25,6 +25,15 @@
|
||||||
</property>
|
</property>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
<widget class="QTreeView" name="m_treeArticles">
|
<widget class="QTreeView" name="m_treeArticles">
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="indentation">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="uniformRowHeights">
|
<property name="uniformRowHeights">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -35,7 +44,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="headerVisible">
|
<attribute name="headerVisible">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -92,6 +101,22 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="m_cmbFeeds"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="PlainToolButton" name="m_btnOpenArticleList">
|
<widget class="PlainToolButton" name="m_btnOpenArticleList">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
@ -122,6 +147,7 @@
|
||||||
<tabstop>m_treeArticles</tabstop>
|
<tabstop>m_treeArticles</tabstop>
|
||||||
<tabstop>m_btnPreviousPage</tabstop>
|
<tabstop>m_btnPreviousPage</tabstop>
|
||||||
<tabstop>m_btnNextPage</tabstop>
|
<tabstop>m_btnNextPage</tabstop>
|
||||||
|
<tabstop>m_cmbFeeds</tabstop>
|
||||||
<tabstop>m_btnOpenArticleList</tabstop>
|
<tabstop>m_btnOpenArticleList</tabstop>
|
||||||
<tabstop>m_btnOpenWebBrowser</tabstop>
|
<tabstop>m_btnOpenWebBrowser</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
|
|
|
@ -40,14 +40,29 @@ void BaseToastNotification::setupCloseButton(QAbstractButton* btn) {
|
||||||
connect(btn, &QAbstractButton::clicked, this, &BaseToastNotification::close);
|
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() {
|
void BaseToastNotification::stopTimedClosing() {
|
||||||
killTimer(m_timerId);
|
if (m_timerId >= 0) {
|
||||||
m_timerId = -1;
|
killTimer(m_timerId);
|
||||||
|
m_timerId = -1;
|
||||||
|
|
||||||
|
qDebugNN << LOGSEC_NOTIFICATIONS << "Stopping timed closing for notification.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseToastNotification::setupTimedClosing() {
|
void BaseToastNotification::setupTimedClosing() {
|
||||||
if (m_timerId < 0) {
|
if (m_timerId < 0) {
|
||||||
m_timerId = startTimer(NOTIFICATIONS_TIMEOUT);
|
m_timerId = startTimer(NOTIFICATIONS_TIMEOUT);
|
||||||
|
|
||||||
|
qDebugNN << LOGSEC_NOTIFICATIONS << "Starting timed closing for notification.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
class BaseToastNotification : public QDialog {
|
class BaseToastNotification : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -22,6 +23,7 @@ class BaseToastNotification : public QDialog {
|
||||||
virtual void timerEvent(QTimerEvent* event);
|
virtual void timerEvent(QTimerEvent* event);
|
||||||
virtual void closeEvent(QCloseEvent* event);
|
virtual void closeEvent(QCloseEvent* event);
|
||||||
|
|
||||||
|
void setupHeading(QLabel* lbl);
|
||||||
void setupTimedClosing();
|
void setupTimedClosing();
|
||||||
void setupCloseButton(QAbstractButton* btn);
|
void setupCloseButton(QAbstractButton* btn);
|
||||||
void stopTimedClosing();
|
void stopTimedClosing();
|
||||||
|
|
|
@ -8,15 +8,6 @@
|
||||||
#include <Carbon/Carbon.h>
|
#include <Carbon/Carbon.h>
|
||||||
#endif
|
#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,
|
ToastNotification::ToastNotification(Notification::Event event,
|
||||||
const GuiMessage& msg,
|
const GuiMessage& msg,
|
||||||
const GuiAction& action,
|
const GuiAction& action,
|
||||||
|
@ -24,7 +15,7 @@ ToastNotification::ToastNotification(Notification::Event event,
|
||||||
: BaseToastNotification() {
|
: BaseToastNotification() {
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
setupHeading();
|
setupHeading(m_ui.m_lblTitle);
|
||||||
setupCloseButton(m_ui.m_btnClose);
|
setupCloseButton(m_ui.m_btnClose);
|
||||||
setupTimedClosing();
|
setupTimedClosing();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ class ToastNotification : public BaseToastNotification {
|
||||||
QWidget* parent = nullptr);
|
QWidget* parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupHeading();
|
|
||||||
void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action);
|
void loadNotification(Notification::Event event, const GuiMessage& msg, const GuiAction& action);
|
||||||
QIcon iconForType(QSystemTrayIcon::MessageIcon icon) const;
|
QIcon iconForType(QSystemTrayIcon::MessageIcon icon) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue