Extend filtering (#678)
* Unified naming in message highlighter related code * Added extended filtering logic * Added UI for extended filtering * Removed ShowOnlyUnreadMessages from Articles menu * Added filter to messagestoolbar defaults * Implemented QToolButton state saving * Review fixes * Changed titles for article filter buttons
This commit is contained in:
parent
d3ec7ac4b3
commit
e3096aee4f
15 changed files with 275 additions and 65 deletions
|
@ -172,8 +172,8 @@ bool MessagesModel::setMessageImportantById(int id, RootItem::Importance importa
|
|||
return false;
|
||||
}
|
||||
|
||||
void MessagesModel::highlightMessages(MessagesModel::MessageHighlighter highlight) {
|
||||
m_messageHighlighter = highlight;
|
||||
void MessagesModel::highlightMessages(MessagesModel::MessageHighlighter highlighter) {
|
||||
m_messageHighlighter = highlighter;
|
||||
emit layoutAboutToBeChanged();
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
|
|||
|
||||
public:
|
||||
|
||||
// Enum which describes basic filtering schemes
|
||||
// Enum which describes basic highlighting schemes
|
||||
// for messages.
|
||||
enum class MessageHighlighter {
|
||||
NoHighlighting = 100,
|
||||
|
@ -70,7 +70,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
|
|||
bool setBatchMessagesRestored(const QModelIndexList& messages);
|
||||
|
||||
// Highlights messages.
|
||||
void highlightMessages(MessageHighlighter highlight);
|
||||
void highlightMessages(MessageHighlighter highlighter);
|
||||
|
||||
// Loads messages of given feeds.
|
||||
void loadMessages(RootItem* item);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <QTimer>
|
||||
|
||||
MessagesProxyModel::MessagesProxyModel(MessagesModel* source_model, QObject* parent)
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_showUnreadOnly(false) {
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_filter(MessageListFilter::NoFiltering) {
|
||||
setObjectName(QSL("MessagesProxyModel"));
|
||||
|
||||
setSortRole(Qt::ItemDataRole::EditRole);
|
||||
|
@ -100,6 +100,81 @@ bool MessagesProxyModel::lessThan(const QModelIndex& left, const QModelIndex& ri
|
|||
return false;
|
||||
}
|
||||
|
||||
bool MessagesProxyModel::filterAcceptsMessage(Message currentMessage) const {
|
||||
switch (m_filter) {
|
||||
case MessageListFilter::NoFiltering:
|
||||
return true;
|
||||
|
||||
case MessageListFilter::ShowUnread:
|
||||
return !currentMessage.m_isRead;
|
||||
|
||||
case MessageListFilter::ShowImportant:
|
||||
return currentMessage.m_isImportant;
|
||||
|
||||
case MessageListFilter::ShowToday:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDate.startOfDay() <= currentMessage.m_created &&
|
||||
currentMessage.m_created <= currentDate.endOfDay();
|
||||
}
|
||||
|
||||
case MessageListFilter::ShowYesterday:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDate.addDays(-1).startOfDay() <= currentMessage.m_created &&
|
||||
currentMessage.m_created <= currentDate.addDays(-1).endOfDay();
|
||||
}
|
||||
|
||||
case MessageListFilter::ShowLast24Hours:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDateTime.addSecs(-24 * 60 * 60) <= currentMessage.m_created &&
|
||||
currentMessage.m_created <= currentDateTime;
|
||||
}
|
||||
|
||||
case MessageListFilter::ShowLast48Hours:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDateTime.addSecs(-48 * 60 * 60) <= currentMessage.m_created &&
|
||||
currentMessage.m_created <= currentDateTime;
|
||||
}
|
||||
|
||||
case MessageListFilter::ShowThisWeek:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDate.year() == currentMessage.m_created.date().year() &&
|
||||
currentDate.weekNumber() == currentMessage.m_created.date().weekNumber();
|
||||
}
|
||||
|
||||
case MessageListFilter::ShowLastWeek:
|
||||
{
|
||||
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||
const QDate currentDate = currentDateTime.date();
|
||||
|
||||
return
|
||||
currentDate.addDays(-7).year() == currentMessage.m_created.date().year() &&
|
||||
currentDate.addDays(-7).weekNumber() == currentMessage.m_created.date().weekNumber();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MessagesProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const {
|
||||
// We want to show only regexped messages when "all" should be visible
|
||||
// and we want to show only regexped AND unread messages when unread should be visible.
|
||||
|
@ -110,16 +185,11 @@ bool MessagesProxyModel::filterAcceptsRow(int source_row, const QModelIndex& sou
|
|||
return
|
||||
QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) &&
|
||||
(m_sourceModel->cache()->containsData(source_row) ||
|
||||
(!m_showUnreadOnly || !m_sourceModel->messageAt(source_row).m_isRead));
|
||||
filterAcceptsMessage(m_sourceModel->messageAt(source_row)));
|
||||
}
|
||||
|
||||
bool MessagesProxyModel::showUnreadOnly() const {
|
||||
return m_showUnreadOnly;
|
||||
}
|
||||
|
||||
void MessagesProxyModel::setShowUnreadOnly(bool show_unread_only) {
|
||||
m_showUnreadOnly = show_unread_only;
|
||||
qApp->settings()->setValue(GROUP(Messages), Messages::ShowOnlyUnreadMessages, show_unread_only);
|
||||
void MessagesProxyModel::setFilter(MessageListFilter filter) {
|
||||
m_filter = filter;
|
||||
}
|
||||
|
||||
QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList& indexes, bool deep) const {
|
||||
|
|
|
@ -6,11 +6,27 @@
|
|||
#include <QSortFilterProxyModel>
|
||||
|
||||
class MessagesModel;
|
||||
class Message;
|
||||
|
||||
class MessagesProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
// Enum which describes basic filtering schemes
|
||||
// for messages.
|
||||
enum class MessageListFilter {
|
||||
NoFiltering = 100,
|
||||
ShowUnread = 101,
|
||||
ShowImportant = 102,
|
||||
ShowToday = 103,
|
||||
ShowYesterday = 104,
|
||||
ShowLast24Hours = 105,
|
||||
ShowLast48Hours = 106,
|
||||
ShowThisWeek = 107,
|
||||
ShowLastWeek = 108
|
||||
};
|
||||
|
||||
explicit MessagesProxyModel(MessagesModel* source_model, QObject* parent = nullptr);
|
||||
virtual ~MessagesProxyModel();
|
||||
|
||||
|
@ -27,19 +43,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);
|
||||
void setFilter(MessageListFilter filter);
|
||||
|
||||
private:
|
||||
QModelIndex getNextImportantItemIndex(int default_row, int max_row) const;
|
||||
QModelIndex getNextUnreadItemIndex(int default_row, int max_row) const;
|
||||
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
|
||||
bool filterAcceptsMessage(Message currentMessage) const;
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
|
||||
|
||||
// Source model pointer.
|
||||
MessagesModel* m_sourceModel;
|
||||
bool m_showUnreadOnly;
|
||||
MessageListFilter m_filter;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(MessagesProxyModel::MessageListFilter)
|
||||
|
||||
#endif // MESSAGESPROXYMODEL_H
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
#define FLAG_ICON_SUBFOLDER "flags"
|
||||
#define SEARCH_BOX_ACTION_NAME "search"
|
||||
#define HIGHLIGHTER_ACTION_NAME "highlighter"
|
||||
#define FILTER_ACTION_NAME "filter"
|
||||
#define SPACER_ACTION_NAME "spacer"
|
||||
#define SEPARATOR_ACTION_NAME "separator"
|
||||
#define FILTER_WIDTH 125
|
||||
|
|
|
@ -197,7 +197,6 @@ QList<QAction*> FormMain::allActions() const {
|
|||
actions << m_ui->m_actionSortFeedsAlphabetically;
|
||||
actions << m_ui->m_actionShowTreeBranches;
|
||||
actions << m_ui->m_actionAutoExpandItemsWhenSelected;
|
||||
actions << m_ui->m_actionShowOnlyUnreadMessages;
|
||||
actions << m_ui->m_actionMarkSelectedMessagesAsRead;
|
||||
actions << m_ui->m_actionMarkSelectedMessagesAsUnread;
|
||||
actions << m_ui->m_actionSwitchImportanceOfSelectedMessages;
|
||||
|
@ -599,7 +598,6 @@ void FormMain::setupIcons() {
|
|||
m_ui->m_actionSelectNextUnreadMessage->setIcon(icon_theme_factory->fromTheme(QSL("mail-mark-unread")));
|
||||
m_ui->m_actionSortFeedsAlphabetically->setIcon(icon_theme_factory->fromTheme(QSL("format-text-bold")));
|
||||
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_actionExpandCollapseItemRecursively->setIcon(icon_theme_factory->fromTheme(QSL("format-indent-more")));
|
||||
m_ui->m_actionRestoreSelectedMessages->setIcon(icon_theme_factory->fromTheme(QSL("view-refresh")));
|
||||
|
@ -683,8 +681,6 @@ void FormMain::loadSize() {
|
|||
SETTING(Feeds::ShowTreeBranches)).toBool());
|
||||
m_ui->m_actionAutoExpandItemsWhenSelected->setChecked(settings->value(GROUP(Feeds),
|
||||
SETTING(Feeds::AutoExpandOnSelection)).toBool());
|
||||
m_ui->m_actionShowOnlyUnreadMessages->setChecked(settings->value(GROUP(Messages),
|
||||
SETTING(Messages::ShowOnlyUnreadMessages)).toBool());
|
||||
m_ui->m_actionAlternateColorsInLists->setChecked(settings->value(GROUP(GUI),
|
||||
SETTING(GUI::AlternateRowColorsInLists)).toBool());
|
||||
}
|
||||
|
@ -876,8 +872,6 @@ void FormMain::createConnections() {
|
|||
tabWidget()->feedMessageViewer(), &FeedMessageViewer::toggleItemsAutoExpandingOnSelection);
|
||||
connect(m_ui->m_actionAlternateColorsInLists, &QAction::toggled,
|
||||
tabWidget()->feedMessageViewer(), &FeedMessageViewer::alternateRowColorsInLists);
|
||||
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,
|
||||
|
|
|
@ -155,7 +155,6 @@
|
|||
<addaction name="m_actionOpenSelectedMessagesInternallyNoTab"/>
|
||||
<addaction name="m_actionSendMessageViaEmail"/>
|
||||
<addaction name="m_actionMessagePreviewEnabled"/>
|
||||
<addaction name="m_actionShowOnlyUnreadMessages"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="m_actionSelectNextMessage"/>
|
||||
<addaction name="m_actionSelectPreviousMessage"/>
|
||||
|
@ -792,14 +791,6 @@
|
|||
<string>&Copy URL of selected item</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="m_actionShowOnlyUnreadMessages">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show &unread articles only</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="m_actionMessageFilters">
|
||||
<property name="text">
|
||||
<string>Article &filters</string>
|
||||
|
|
|
@ -183,15 +183,8 @@ void FeedMessageViewer::switchFeedComponentVisibility() {
|
|||
}
|
||||
}
|
||||
|
||||
void FeedMessageViewer::toggleShowOnlyUnreadMessages() {
|
||||
const QAction* origin = qobject_cast<QAction*>(sender());
|
||||
|
||||
if (origin == nullptr) {
|
||||
m_messagesView->switchShowUnreadOnly(true, false);
|
||||
}
|
||||
else {
|
||||
m_messagesView->switchShowUnreadOnly(true, origin->isChecked());
|
||||
}
|
||||
void FeedMessageViewer::changeMessageFilter(MessagesProxyModel::MessageListFilter filter) {
|
||||
m_messagesView->changeFilter(filter);
|
||||
}
|
||||
|
||||
void FeedMessageViewer::toggleShowOnlyUnreadFeeds() {
|
||||
|
@ -244,7 +237,8 @@ void FeedMessageViewer::createConnections() {
|
|||
// Filtering & searching.
|
||||
connect(m_toolBarMessages, &MessagesToolBar::messageSearchPatternChanged, m_messagesView, &MessagesView::searchMessages);
|
||||
connect(m_toolBarFeeds, &FeedsToolBar::feedsFilterPatternChanged, m_feedsView, &FeedsView::filterItems);
|
||||
connect(m_toolBarMessages, &MessagesToolBar::messageFilterChanged, m_messagesView, &MessagesView::filterMessages);
|
||||
connect(m_toolBarMessages, &MessagesToolBar::messageHighlighterChanged, m_messagesView, &MessagesView::highlightMessages);
|
||||
connect(m_toolBarMessages, &MessagesToolBar::messageFilterChanged, this, &FeedMessageViewer::changeMessageFilter);
|
||||
|
||||
connect(m_feedSplitter, &QSplitter::splitterMoved, this, &FeedMessageViewer::onFeedSplitterResized);
|
||||
connect(m_messageSplitter, &QSplitter::splitterMoved, this, &FeedMessageViewer::onMessageSplitterResized);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gui/tabcontent.h"
|
||||
|
||||
#include "core/messagesmodel.h"
|
||||
#include "core/messagesproxymodel.h"
|
||||
|
||||
class WebBrowser;
|
||||
class MessagePreviewer;
|
||||
|
@ -57,7 +58,7 @@ class RSSGUARD_DLLSPEC FeedMessageViewer : public TabContent {
|
|||
// toolbar.
|
||||
void switchFeedComponentVisibility();
|
||||
|
||||
void toggleShowOnlyUnreadMessages();
|
||||
void changeMessageFilter(MessagesProxyModel::MessageListFilter filter);
|
||||
void toggleShowOnlyUnreadFeeds();
|
||||
void toggleShowFeedTreeBranches();
|
||||
void toggleItemsAutoExpandingOnSelection();
|
||||
|
|
|
@ -499,11 +499,8 @@ void MessagesView::loadItem(RootItem* item) {
|
|||
emit currentMessageRemoved();
|
||||
}
|
||||
|
||||
void MessagesView::switchShowUnreadOnly(bool set_new_value, bool show_unread_only) {
|
||||
if (set_new_value) {
|
||||
m_proxyModel->setShowUnreadOnly(show_unread_only);
|
||||
}
|
||||
|
||||
void MessagesView::changeFilter(MessagesProxyModel::MessageListFilter filter) {
|
||||
m_proxyModel->setFilter(filter);
|
||||
reloadSelections();
|
||||
}
|
||||
|
||||
|
@ -784,8 +781,8 @@ void MessagesView::searchMessages(const QString& pattern) {
|
|||
}
|
||||
}
|
||||
|
||||
void MessagesView::filterMessages(MessagesModel::MessageHighlighter filter) {
|
||||
m_sourceModel->highlightMessages(filter);
|
||||
void MessagesView::highlightMessages(MessagesModel::MessageHighlighter highlighter) {
|
||||
m_sourceModel->highlightMessages(highlighter);
|
||||
}
|
||||
|
||||
void MessagesView::openSelectedMessagesWithExternalTool() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gui/reusable/basetreeview.h"
|
||||
|
||||
#include "core/messagesmodel.h"
|
||||
#include "core/messagesproxymodel.h"
|
||||
#include "services/abstract/rootitem.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
@ -62,9 +63,8 @@ class MessagesView : public BaseTreeView {
|
|||
|
||||
// Searchs the visible message according to given pattern.
|
||||
void searchMessages(const QString& pattern);
|
||||
void filterMessages(MessagesModel::MessageHighlighter filter);
|
||||
|
||||
void switchShowUnreadOnly(bool set_new_value = false, bool show_unread_only = false);
|
||||
void highlightMessages(MessagesModel::MessageHighlighter highlighter);
|
||||
void changeFilter(MessagesProxyModel::MessageListFilter filter);
|
||||
|
||||
private slots:
|
||||
void openSelectedMessagesWithExternalTool();
|
||||
|
|
|
@ -25,6 +25,7 @@ QList<QAction*> MessagesToolBar::availableActions() const {
|
|||
|
||||
available_actions.append(m_actionSearchMessages);
|
||||
available_actions.append(m_actionMessageHighlighter);
|
||||
available_actions.append(m_actionMessageFilter);
|
||||
|
||||
return available_actions;
|
||||
}
|
||||
|
@ -66,9 +67,15 @@ QList<QAction*> MessagesToolBar::convertActions(const QStringList& actions) {
|
|||
// Add search box.
|
||||
spec_actions.append(m_actionSearchMessages);
|
||||
}
|
||||
else if (action_name == QSL(HIGHLIGHTER_ACTION_NAME)) {
|
||||
// Add filter button.
|
||||
else if (action_name.startsWith(QSL(HIGHLIGHTER_ACTION_NAME))) {
|
||||
// Add highlighter button.
|
||||
spec_actions.append(m_actionMessageHighlighter);
|
||||
activateAction(action_name, m_actionMessageHighlighter);
|
||||
}
|
||||
else if (action_name.startsWith(QSL(FILTER_ACTION_NAME))) {
|
||||
// Add filter button.
|
||||
spec_actions.append(m_actionMessageFilter);
|
||||
activateAction(action_name, m_actionMessageFilter);
|
||||
}
|
||||
else if (action_name == QSL(SPACER_ACTION_NAME)) {
|
||||
// Add new spacer.
|
||||
|
@ -99,9 +106,17 @@ void MessagesToolBar::loadSpecificActions(const QList<QAction*>& actions, bool i
|
|||
}
|
||||
|
||||
void MessagesToolBar::handleMessageHighlighterChange(QAction* action) {
|
||||
m_btnMessageHighlighter->setIcon(action->icon());
|
||||
m_btnMessageHighlighter->setToolTip(action->text());
|
||||
emit messageFilterChanged(action->data().value<MessagesModel::MessageHighlighter>());
|
||||
m_btnMessageHighlighter->setDefaultAction(action);
|
||||
saveToolButtonSelection(HIGHLIGHTER_ACTION_NAME, action);
|
||||
|
||||
emit messageHighlighterChanged(action->data().value<MessagesModel::MessageHighlighter>());
|
||||
}
|
||||
|
||||
void MessagesToolBar::handleMessageFilterChange(QAction* action) {
|
||||
m_btnMessageFilter->setDefaultAction(action);
|
||||
saveToolButtonSelection(FILTER_ACTION_NAME, action);
|
||||
|
||||
emit messageFilterChanged(action->data().value<MessagesProxyModel::MessageListFilter>());
|
||||
}
|
||||
|
||||
void MessagesToolBar::initializeSearchBox() {
|
||||
|
@ -125,26 +140,133 @@ void MessagesToolBar::initializeSearchBox() {
|
|||
});
|
||||
}
|
||||
|
||||
void MessagesToolBar::addActionToMenu(QMenu* menu, const QIcon& icon, const QString& title, const QVariant& value, const QString& name) {
|
||||
QAction* action = menu->addAction(icon, title);
|
||||
|
||||
action->setData(value);
|
||||
action->setObjectName(name);
|
||||
}
|
||||
|
||||
void MessagesToolBar::initializeHighlighter() {
|
||||
m_menuMessageHighlighter = new QMenu(tr("Menu for highlighting articles"), this);
|
||||
m_menuMessageHighlighter->addAction(qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("No extra highlighting"))->setData(QVariant::fromValue(MessagesModel::MessageHighlighter::NoHighlighting));
|
||||
m_menuMessageHighlighter->addAction(qApp->icons()->fromTheme(QSL("mail-mark-unread")),
|
||||
tr("Highlight unread articles"))->setData(QVariant::fromValue(MessagesModel::MessageHighlighter::HighlightUnread));
|
||||
m_menuMessageHighlighter->addAction(qApp->icons()->fromTheme(QSL("mail-mark-important")),
|
||||
tr("Highlight important articles"))->setData(QVariant::fromValue(MessagesModel::MessageHighlighter::HighlightImportant));
|
||||
addActionToMenu(m_menuMessageHighlighter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("No extra highlighting"),
|
||||
QVariant::fromValue(MessagesModel::MessageHighlighter::NoHighlighting),
|
||||
"no_highlighting");
|
||||
addActionToMenu(m_menuMessageHighlighter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-unread")),
|
||||
tr("Highlight unread articles"),
|
||||
QVariant::fromValue(MessagesModel::MessageHighlighter::HighlightUnread),
|
||||
"highlight_unread");
|
||||
addActionToMenu(m_menuMessageHighlighter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-important")),
|
||||
tr("Highlight important articles"),
|
||||
QVariant::fromValue(MessagesModel::MessageHighlighter::HighlightImportant),
|
||||
"highlight_important");
|
||||
|
||||
m_menuMessageFilter = new QMenu(tr("Menu for filtering articles"), this);
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("No extra filtering"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::NoFiltering),
|
||||
"no_filtering");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-unread")),
|
||||
tr("Show unread articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowUnread),
|
||||
"show_unread");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-important")),
|
||||
tr("Show important articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowImportant),
|
||||
"show_important");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show today's articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowToday),
|
||||
"show_today");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show yesterday's articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowYesterday),
|
||||
"show_yesterday");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show articles in last 24 hours"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowLast24Hours),
|
||||
"show_last24hours");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show articles in last 48 hours"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowLast48Hours),
|
||||
"show_last48hours");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show this week's articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowThisWeek),
|
||||
"show_this_week");
|
||||
addActionToMenu(m_menuMessageFilter,
|
||||
qApp->icons()->fromTheme(QSL("mail-mark-read")),
|
||||
tr("Show last week's articles"),
|
||||
QVariant::fromValue(MessagesProxyModel::MessageListFilter::ShowLastWeek),
|
||||
"show_last_week");
|
||||
|
||||
m_btnMessageHighlighter = new QToolButton(this);
|
||||
m_btnMessageHighlighter->setToolTip(tr("Display all articles"));
|
||||
m_btnMessageHighlighter->setMenu(m_menuMessageHighlighter);
|
||||
m_btnMessageHighlighter->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
|
||||
m_btnMessageHighlighter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
||||
m_btnMessageHighlighter->setDefaultAction(m_menuMessageHighlighter->actions().front());
|
||||
m_btnMessageFilter = new QToolButton(this);
|
||||
m_btnMessageFilter->setToolTip(tr("Display all articles"));
|
||||
m_btnMessageFilter->setMenu(m_menuMessageFilter);
|
||||
m_btnMessageFilter->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup);
|
||||
m_btnMessageFilter->setIcon(qApp->icons()->fromTheme(QSL("mail-mark-read")));
|
||||
m_btnMessageFilter->setDefaultAction(m_menuMessageFilter->actions().front());
|
||||
m_actionMessageHighlighter = new QWidgetAction(this);
|
||||
m_actionMessageHighlighter->setDefaultWidget(m_btnMessageHighlighter);
|
||||
m_actionMessageHighlighter->setIcon(m_btnMessageHighlighter->icon());
|
||||
m_actionMessageHighlighter->setProperty("type", HIGHLIGHTER_ACTION_NAME);
|
||||
m_actionMessageHighlighter->setProperty("name", tr("Article highlighter"));
|
||||
m_actionMessageFilter = new QWidgetAction(this);
|
||||
m_actionMessageFilter->setDefaultWidget(m_btnMessageFilter);
|
||||
m_actionMessageFilter->setIcon(m_btnMessageFilter->icon());
|
||||
m_actionMessageFilter->setProperty("type", FILTER_ACTION_NAME);
|
||||
m_actionMessageFilter->setProperty("name", tr("Article filter"));
|
||||
|
||||
connect(m_menuMessageHighlighter, &QMenu::triggered, this, &MessagesToolBar::handleMessageHighlighterChange);
|
||||
connect(m_menuMessageFilter, &QMenu::triggered, this, &MessagesToolBar::handleMessageFilterChange);
|
||||
}
|
||||
|
||||
void MessagesToolBar::saveToolButtonSelection(const QString& button_name, const QAction* action) const {
|
||||
QStringList action_names = savedActions();
|
||||
|
||||
for (QString& action_name : action_names) {
|
||||
if (action_name.startsWith(button_name)) {
|
||||
action_name = button_name + (action->objectName().isEmpty() ? "" : "[" + action->objectName().toStdString() + "]").c_str();
|
||||
}
|
||||
}
|
||||
|
||||
qApp->settings()->setValue(GROUP(GUI), GUI::MessagesToolbarDefaultButtons, action_names.join(QSL(",")));
|
||||
}
|
||||
|
||||
void MessagesToolBar::activateAction(const QString& action_name, QWidgetAction* widget_action) {
|
||||
const int start = action_name.indexOf('[');
|
||||
const int end = action_name.indexOf(']');
|
||||
|
||||
if (start != -1 && end != -1 && end == action_name.length() - 1) {
|
||||
const QString menu_action_name = action_name.chopped(1).right(end - start - 1);
|
||||
auto toolButton = qobject_cast<QToolButton*>(widget_action->defaultWidget());
|
||||
|
||||
for (QAction* action : toolButton->menu()->actions()) {
|
||||
if (action->objectName() == menu_action_name) {
|
||||
toolButton->setDefaultAction(action);
|
||||
toolButton->menu()->triggered(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStringList MessagesToolBar::defaultActions() const {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gui/toolbars/basetoolbar.h"
|
||||
|
||||
#include "core/messagesmodel.h"
|
||||
#include "core/messagesproxymodel.h"
|
||||
|
||||
class BaseLineEdit;
|
||||
class QWidgetAction;
|
||||
|
@ -29,20 +30,28 @@ class MessagesToolBar : public BaseToolBar {
|
|||
|
||||
signals:
|
||||
void messageSearchPatternChanged(const QString& pattern);
|
||||
void messageFilterChanged(MessagesModel::MessageHighlighter filter);
|
||||
void messageHighlighterChanged(MessagesModel::MessageHighlighter highlighter);
|
||||
void messageFilterChanged(MessagesProxyModel::MessageListFilter filter);
|
||||
|
||||
private slots:
|
||||
void onSearchPatternChanged(const QString& search_pattern);
|
||||
void handleMessageHighlighterChange(QAction* action);
|
||||
void handleMessageFilterChange(QAction* action);
|
||||
|
||||
private:
|
||||
void initializeSearchBox();
|
||||
void addActionToMenu(QMenu* menu, const QIcon& icon, const QString& title, const QVariant& value, const QString& name);
|
||||
void initializeHighlighter();
|
||||
void activateAction(const QString& action_name, QWidgetAction* widget_action);
|
||||
void saveToolButtonSelection(const QString& button_name, const QAction* action) const;
|
||||
|
||||
private:
|
||||
QWidgetAction* m_actionMessageHighlighter;
|
||||
QWidgetAction* m_actionMessageFilter;
|
||||
QToolButton* m_btnMessageHighlighter;
|
||||
QToolButton* m_btnMessageFilter;
|
||||
QMenu* m_menuMessageHighlighter;
|
||||
QMenu* m_menuMessageFilter;
|
||||
QWidgetAction* m_actionSearchMessages;
|
||||
BaseLineEdit* m_txtSearchMessages;
|
||||
QTimer* m_tmrSearchPattern;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gui/toolbars/basetoolbar.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QWidgetAction>
|
||||
|
||||
ToolBarEditor::ToolBarEditor(QWidget* parent)
|
||||
: QWidget(parent), m_ui(new Ui::ToolBarEditor), m_toolBar(nullptr) {
|
||||
|
@ -86,6 +87,18 @@ void ToolBarEditor::loadEditor(const QList<QAction*>& activated_actions, const Q
|
|||
action_item->setData(Qt::ItemDataRole::UserRole, action->objectName());
|
||||
action_item->setToolTip(action->toolTip());
|
||||
}
|
||||
|
||||
if (auto widgetAction = qobject_cast<const QWidgetAction*>(action); widgetAction) {
|
||||
if (auto toolButton = qobject_cast<const QToolButton*>(widgetAction->defaultWidget()); toolButton) {
|
||||
if (const QAction* action = toolButton->defaultAction(); action) {
|
||||
const QString objectName = action->objectName();
|
||||
const QString name = action_item->data(Qt::ItemDataRole::UserRole).toString() +
|
||||
(objectName.isEmpty() ? "" : "[" + objectName.toStdString() + "]").c_str();
|
||||
|
||||
action_item->setData(Qt::ItemDataRole::UserRole, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (QAction* action : available_actions) {
|
||||
|
|
|
@ -281,7 +281,7 @@ DVALUE(bool) GUI::HideTabBarIfOnlyOneTabDef = false;
|
|||
|
||||
DKEY GUI::MessagesToolbarDefaultButtons = "messages_toolbar";
|
||||
DVALUE(char*) GUI::MessagesToolbarDefaultButtonsDef =
|
||||
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,separator,highlighter,spacer,search";
|
||||
"m_actionMarkSelectedMessagesAsRead,m_actionMarkSelectedMessagesAsUnread,m_actionSwitchImportanceOfSelectedMessages,separator,highlighter,filter,spacer,search";
|
||||
|
||||
DKEY GUI::DefaultSortColumnFeeds = "default_sort_column_feeds";
|
||||
DVALUE(int) GUI::DefaultSortColumnFeedsDef = FDS_MODEL_TITLE_INDEX;
|
||||
|
|
Loading…
Add table
Reference in a new issue