Experimental show unread msgs only. #113
This commit is contained in:
parent
be027aaa95
commit
daad0760e1
@ -5,14 +5,19 @@
|
||||
#include "core/messagesmodel.h"
|
||||
#include "miscellaneous/regexfactory.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
MessagesProxyModel::MessagesProxyModel(MessagesModel* source_model, QObject* parent)
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model) {
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_showUnreadOnly(false) {
|
||||
setObjectName(QSL("MessagesProxyModel"));
|
||||
|
||||
setSortRole(Qt::EditRole);
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
setFilterKeyColumn(-1);
|
||||
setFilterRole(Qt::EditRole);
|
||||
|
||||
setDynamicSortFilter(false);
|
||||
setSourceModel(m_sourceModel);
|
||||
}
|
||||
@ -60,6 +65,28 @@ bool MessagesProxyModel::lessThan(const QModelIndex& left, const QModelIndex& ri
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MessagesProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const {
|
||||
return
|
||||
(!m_showUnreadOnly || !m_sourceModel->messageAt(source_row).m_isRead) &&
|
||||
QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||
}
|
||||
|
||||
bool MessagesProxyModel::showUnreadOnly() const {
|
||||
return m_showUnreadOnly;
|
||||
}
|
||||
|
||||
void MessagesProxyModel::setShowUnreadOnly(bool show_unread_only) {
|
||||
m_showUnreadOnly = show_unread_only;
|
||||
}
|
||||
|
||||
void MessagesProxyModel::invalidateUnreadMessagesFilter(bool set_new_value, bool show_unread_only) {
|
||||
if (set_new_value) {
|
||||
setShowUnreadOnly(show_unread_only);
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, this, &MessagesProxyModel::invalidateFilter);
|
||||
}
|
||||
|
||||
QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList& indexes, bool deep) const {
|
||||
QModelIndexList mapped_indexes;
|
||||
|
||||
|
@ -11,9 +11,7 @@ class MessagesProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
// Constructors and destructors.
|
||||
explicit MessagesProxyModel(MessagesModel* source_model, QObject* parent = 0);
|
||||
explicit MessagesProxyModel(MessagesModel* source_model, QObject* parent = nullptr);
|
||||
virtual ~MessagesProxyModel();
|
||||
|
||||
QModelIndex getNextPreviousUnreadItemIndex(int default_row);
|
||||
@ -28,14 +26,21 @@ class MessagesProxyModel : public QSortFilterProxyModel {
|
||||
// Performs sort of items.
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
bool showUnreadOnly() const;
|
||||
void setShowUnreadOnly(bool show_unread_only);
|
||||
|
||||
public slots:
|
||||
void invalidateUnreadMessagesFilter(bool set_new_value = false, bool show_unread_only = false);
|
||||
|
||||
private:
|
||||
QModelIndex getNextUnreadItemIndex(int default_row, int max_row) const;
|
||||
|
||||
// Compares two rows of data.
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
|
||||
|
||||
// Source model pointer.
|
||||
MessagesModel* m_sourceModel;
|
||||
bool m_showUnreadOnly;
|
||||
};
|
||||
|
||||
#endif // MESSAGESPROXYMODEL_H
|
||||
|
@ -160,6 +160,7 @@ QList<QAction*> FormMain::allActions() const {
|
||||
actions << m_ui->m_actionClearSelectedItems;
|
||||
actions << m_ui->m_actionClearAllItems;
|
||||
actions << m_ui->m_actionShowOnlyUnreadItems;
|
||||
actions << m_ui->m_actionShowOnlyUnreadMessages;
|
||||
actions << m_ui->m_actionMarkSelectedMessagesAsRead;
|
||||
actions << m_ui->m_actionMarkSelectedMessagesAsUnread;
|
||||
actions << m_ui->m_actionSwitchImportanceOfSelectedMessages;
|
||||
@ -514,6 +515,7 @@ void FormMain::setupIcons() {
|
||||
m_ui->m_actionSelectPreviousMessage->setIcon(icon_theme_factory->fromTheme(QSL("go-up")));
|
||||
m_ui->m_actionSelectNextUnreadMessage->setIcon(icon_theme_factory->fromTheme(QSL("mail-mark-unread")));
|
||||
m_ui->m_actionShowOnlyUnreadItems->setIcon(icon_theme_factory->fromTheme(QSL("mail-mark-unread")));
|
||||
m_ui->m_actionShowOnlyUnreadMessages->setIcon(icon_theme_factory->fromTheme(QSL("mail-mark-unread")));
|
||||
m_ui->m_actionExpandCollapseItem->setIcon(icon_theme_factory->fromTheme(QSL("format-indent-more")));
|
||||
m_ui->m_actionRestoreSelectedMessages->setIcon(icon_theme_factory->fromTheme(QSL("view-refresh")));
|
||||
m_ui->m_actionRestoreAllRecycleBins->setIcon(icon_theme_factory->fromTheme(QSL("view-refresh")));
|
||||
@ -740,6 +742,8 @@ void FormMain::createConnections() {
|
||||
tabWidget()->feedMessageViewer(), &FeedMessageViewer::switchMessageSplitterOrientation);
|
||||
connect(m_ui->m_actionShowOnlyUnreadItems, &QAction::toggled,
|
||||
tabWidget()->feedMessageViewer(), &FeedMessageViewer::toggleShowOnlyUnreadFeeds);
|
||||
connect(m_ui->m_actionShowOnlyUnreadMessages, &QAction::toggled,
|
||||
tabWidget()->feedMessageViewer(), &FeedMessageViewer::toggleShowOnlyUnreadMessages);
|
||||
connect(m_ui->m_actionRestoreSelectedMessages, &QAction::triggered,
|
||||
tabWidget()->feedMessageViewer()->messagesView(), &MessagesView::restoreSelectedMessages);
|
||||
connect(m_ui->m_actionRestoreAllRecycleBins, &QAction::triggered,
|
||||
|
@ -136,6 +136,7 @@
|
||||
<addaction name="m_actionOpenSelectedMessagesInternally"/>
|
||||
<addaction name="m_actionSendMessageViaEmail"/>
|
||||
<addaction name="m_actionMessagePreviewEnabled"/>
|
||||
<addaction name="m_actionShowOnlyUnreadMessages"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="m_actionSelectNextMessage"/>
|
||||
<addaction name="m_actionSelectPreviousMessage"/>
|
||||
@ -750,6 +751,14 @@
|
||||
<string>&Copy URLs of selected items</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="m_actionShowOnlyUnreadMessages">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show only &unread messages</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -167,6 +167,17 @@ void FeedMessageViewer::switchFeedComponentVisibility() {
|
||||
}
|
||||
}
|
||||
|
||||
void FeedMessageViewer::toggleShowOnlyUnreadMessages() {
|
||||
const QAction* origin = qobject_cast<QAction*>(sender());
|
||||
|
||||
if (origin == nullptr) {
|
||||
m_messagesView->model()->invalidateUnreadMessagesFilter(true, false);
|
||||
}
|
||||
else {
|
||||
m_messagesView->model()->invalidateUnreadMessagesFilter(true, origin->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
void FeedMessageViewer::toggleShowOnlyUnreadFeeds() {
|
||||
const QAction* origin = qobject_cast<QAction*>(sender());
|
||||
|
||||
|
@ -64,7 +64,7 @@ class RSSGUARD_DLLSPEC FeedMessageViewer : public TabContent {
|
||||
// toolbar.
|
||||
void switchFeedComponentVisibility();
|
||||
|
||||
// Toggles displayed feeds.
|
||||
void toggleShowOnlyUnreadMessages();
|
||||
void toggleShowOnlyUnreadFeeds();
|
||||
|
||||
private slots:
|
||||
|
Loading…
x
Reference in New Issue
Block a user