diff --git a/modules/Lith/Core/lith.cpp b/modules/Lith/Core/lith.cpp index b4c6029..67ac8dd 100644 --- a/modules/Lith/Core/lith.cpp +++ b/modules/Lith/Core/lith.cpp @@ -357,6 +357,7 @@ void Lith::handleHotlistInitialization(const WeeChatProtocol::HData& hda) { } addHotlist(ptr, item); } + emit hotlistUpdated(); } void Lith::handleNicklistInitialization(const WeeChatProtocol::HData& hda) { @@ -427,6 +428,7 @@ void Lith::handleHotlist(const WeeChatProtocol::HData& hda) { hl->setProperty(qPrintable(key), value); } } + emit hotlistUpdated(); } void Lith::_buffer_opened(const WeeChatProtocol::HData& hda) { @@ -770,18 +772,41 @@ QSharedPointer Lith::getHotlist(pointer_t ptr) const { return {}; } -ProxyBufferList::ProxyBufferList(QObject* parent, QAbstractListModel* parentModel) +ProxyBufferList::ProxyBufferList(Lith* parent, QAbstractListModel* parentModel) : QSortFilterProxyModel(parent) { setSourceModel(parentModel); setFilterRole(Qt::UserRole); connect(this, &ProxyBufferList::filterWordChanged, [this] { setFilterFixedString(filterWordGet()); }); + connect(Lith::settingsGet(), &Settings::bufferListShowsOnlyBuffersWithNewMessagesChanged, this, [this]() { + showOnlyBuffersWithNewMessagesSet(Lith::settingsGet()->bufferListShowsOnlyBuffersWithNewMessagesGet()); + invalidateFilter(); + }); + connect(parent, &Lith::hotlistUpdated, this, [this] { + if (showOnlyBuffersWithNewMessagesGet()) { + invalidateFilter(); + } + }); + showOnlyBuffersWithNewMessagesSet(Lith::settingsGet()->bufferListShowsOnlyBuffersWithNewMessagesGet()); } + bool ProxyBufferList::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { + // If there are no conditions, just bail early + if (filterWordGet().isEmpty() && !showOnlyBuffersWithNewMessagesGet()) { + return true; + } + auto index = sourceModel()->index(source_row, 0, source_parent); auto v = sourceModel()->data(index); auto* b = qvariant_cast(v); if (b) { - return b->nameGet().toLower().contains(filterWordGet().toLower()); + if (filterWordGet().isEmpty()) { + if (showOnlyBuffersWithNewMessagesGet()) { + return b->totalUnreadMessagesGet() > 0; + } + return true; + } else { + return b->nameGet().toLower().contains(filterWordGet().toLower()); + } } return false; } diff --git a/modules/Lith/Core/lith.h b/modules/Lith/Core/lith.h index d8ed5b0..aeb3489 100644 --- a/modules/Lith/Core/lith.h +++ b/modules/Lith/Core/lith.h @@ -170,6 +170,7 @@ public slots: signals: void selectedBufferChanged(); void errorStringChanged(); + void hotlistUpdated(); void pongReceived(qint64 id); @@ -203,8 +204,9 @@ public slots: class LITHCORE_EXPORT ProxyBufferList : public QSortFilterProxyModel { Q_OBJECT PROPERTY(QString, filterWord) + PROPERTY(bool, showOnlyBuffersWithNewMessages, false) public: - ProxyBufferList(QObject* parent = nullptr, QAbstractListModel* parentModel = nullptr); + ProxyBufferList(Lith* parent = nullptr, QAbstractListModel* parentModel = nullptr); bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; }; diff --git a/modules/Lith/Core/settings.h b/modules/Lith/Core/settings.h index 2c72297..84a85f8 100644 --- a/modules/Lith/Core/settings.h +++ b/modules/Lith/Core/settings.h @@ -153,6 +153,7 @@ class LITHCORE_EXPORT Settings : public QObject { SETTING(bool, showBufferListOnStartup, false) SETTING(bool, platformBufferControlPosition, true) + SETTING(bool, bufferListShowsOnlyBuffersWithNewMessages, false) SETTING(bool, showInternalData, false) SETTING(bool, enableLogging, false) diff --git a/modules/Lith/UI/SettingsInterface.qml b/modules/Lith/UI/SettingsInterface.qml index 1172a91..b2b4ad3 100644 --- a/modules/Lith/UI/SettingsInterface.qml +++ b/modules/Lith/UI/SettingsInterface.qml @@ -55,6 +55,7 @@ ScrollView { Lith.settings.baseFontFamily = fontDialog.currentFont.family Lith.settings.showBufferListOnStartup = showBufferListOnStartupCheckbox.checked Lith.settings.platformBufferControlPosition = platformBufferControlPositionCheckbox.checked + Lith.settings.bufferListShowsOnlyBuffersWithNewMessages = bufferListShowsOnlyBuffersWithNewMessagesCheckbox.checked Lith.settings.enableNotifications = enableNotificationsCheckbox.checked } function restore() { @@ -92,6 +93,7 @@ ScrollView { fontDialog.currentFont.family = Lith.settings.baseFontFamily showBufferListOnStartupCheckbox.checked = Lith.settings.showBufferListOnStartup platformBufferControlPositionCheckbox.checked = Lith.settings.platformBufferControlPosition + bufferListShowsOnlyBuffersWithNewMessagesCheckbox.checked = Lith.settings.bufferListShowsOnlyBuffersWithNewMessages enableNotificationsCheckbox.checked = Lith.settings.enableNotifications } @@ -309,6 +311,13 @@ ScrollView { checked: Lith.settings.platformBufferControlPosition } + Fields.Boolean { + id: bufferListShowsOnlyBuffersWithNewMessagesCheckbox + summary: qsTr("Show only buffers with new messages") + details: qsTr("When using the text filter, all buffers will be shown.") + checked: Lith.settings.bufferListShowsOnlyBuffersWithNewMessages + } + ////////////////////////// URL HANDLING Fields.Header { text: qsTr("URL handling")