summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2022-04-22 20:34:15 -0400
committerLoren Burkholder <computersemiexpert@outlook.com>2022-06-29 22:04:37 -0400
commit863eaa1910e84c0657a718f880462e661c220528 (patch)
tree4b1708a52eb9a126a484c52e030a02ce0afea6ed /src
parentAdd space notifs to room list (diff)
downloadnheko-863eaa1910e84c0657a718f880462e661c220528.tar.xz
Add space notification configuration
Diffstat (limited to 'src')
-rw-r--r--src/UserSettingsPage.cpp52
-rw-r--r--src/UserSettingsPage.h16
2 files changed, 65 insertions, 3 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp

index 666a03b4..c4cc339b 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp
@@ -88,7 +88,15 @@ UserSettings::load(std::optional<QString> profile) openImageExternal_ = settings.value(QStringLiteral("user/open_image_external"), false).toBool(); openVideoExternal_ = settings.value(QStringLiteral("user/open_video_external"), false).toBool(); decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool(); - privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool(); + auto tempSpaceNotifs = settings.value(QStringLiteral("user/space_notifications"), QString{}) + .toString() + .toStdString(); + auto spaceNotifsValue = + QMetaEnum::fromType<SpaceNotificationOptions>().keyToValue(tempSpaceNotifs.c_str()); + if (spaceNotifsValue < 0) + spaceNotifsValue = 0; + spaceNotifications_ = static_cast<SpaceNotificationOptions>(spaceNotifsValue); + privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool(); privacyScreenTimeout_ = settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt(); exposeDBusApi_ = settings.value(QStringLiteral("user/expose_dbus_api"), false).toBool(); @@ -417,6 +425,16 @@ UserSettings::setDecryptSidebar(bool state) } void +UserSettings::setSpaceNotifications(SpaceNotificationOptions state) +{ + if (state == spaceNotifications_) + return; + spaceNotifications_ = state; + emit spaceNotificationsChanged(state); + save(); +} + +void UserSettings::setPrivacyScreen(bool state) { if (state == privacyScreen_) { @@ -777,6 +795,9 @@ UserSettings::save() settings.setValue(QStringLiteral("avatar_circles"), avatarCircles_); settings.setValue(QStringLiteral("decrypt_sidebar"), decryptSidebar_); + settings.setValue(QStringLiteral("space_notifications"), + QString::fromUtf8(QMetaEnum::fromType<SpaceNotificationOptions>().valueToKey( + static_cast<int>(spaceNotifications_)))); settings.setValue(QStringLiteral("privacy_screen"), privacyScreen_); settings.setValue(QStringLiteral("privacy_screen_timeout"), privacyScreenTimeout_); settings.setValue(QStringLiteral("mobile_mode"), mobileMode_); @@ -923,6 +944,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return tr("Open videos with external program"); case DecryptSidebar: return tr("Decrypt messages in sidebar"); + case SpaceNotifications: + return tr("Show message counts for spaces"); case PrivacyScreen: return tr("Privacy Screen"); case PrivacyScreenTimeout: @@ -1053,6 +1076,8 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return i->openVideoExternal(); case DecryptSidebar: return i->decryptSidebar(); + case SpaceNotifications: + return static_cast<int>(i->spaceNotifications()); case PrivacyScreen: return i->privacyScreen(); case PrivacyScreenTimeout: @@ -1208,6 +1233,9 @@ UserSettingsModel::data(const QModelIndex &index, int role) const case DecryptSidebar: return tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in " "encrypted chats."); + case SpaceNotifications: + return tr( + "Choose where to show the total number of notifications contained within a space."); case PrivacyScreen: return tr("When the window loses focus, the timeline will\nbe blurred."); case MobileMode: @@ -1283,6 +1311,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const case CameraResolution: case CameraFrameRate: case Ringtone: + case SpaceNotifications: return Options; case TimelineMaxWidth: case PrivacyScreenTimeout: @@ -1409,7 +1438,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const return fontDb.families(); case EmojiFont: return fontDb.families(QFontDatabase::WritingSystem::Symbol); - case Ringtone: + case Ringtone: { QStringList l{ QStringLiteral("Mute"), QStringLiteral("Default"), @@ -1419,6 +1448,12 @@ UserSettingsModel::data(const QModelIndex &index, int role) const l.push_back(i->ringtone()); return l; } + case SpaceNotifications: + return QStringList{QStringLiteral("Sidebar and room list"), + QStringLiteral("Sidebar"), + QStringLiteral("Sidebar (hidden rooms only)"), + QStringLiteral("Off")}; + } } else if (role == Good) { switch (index.row()) { case OnlineBackupKey: @@ -1624,6 +1659,15 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int return false; } return i->decryptSidebar(); + case SpaceNotifications: { + if (value.toInt() > + static_cast<int>(UserSettings::SpaceNotificationOptions::SpaceNotificationsOff) || + value.toInt() < 0) + return false; + + i->setSpaceNotifications(value.value<UserSettings::SpaceNotificationOptions>()); + return true; + } case PrivacyScreen: { if (value.userType() == QMetaType::Bool) { i->setPrivacyScreen(value.toBool()); @@ -1936,7 +1980,9 @@ UserSettingsModel::UserSettingsModel(QObject *p) connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() { emit dataChanged(index(DecryptSidebar), index(DecryptSidebar), {Value}); }); - + connect(s.get(), &UserSettings::spaceNotificationsChanged, this, [this] { + emit dataChanged(index(SpaceNotifications), index(SpaceNotifications), {Value}); + }); connect(s.get(), &UserSettings::trayChanged, this, [this]() { emit dataChanged(index(Tray), index(Tray), {Value}); emit dataChanged(index(StartInTray), index(StartInTray), {Enabled}); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h
index 1fb3ddcf..daf41383 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h
@@ -58,6 +58,8 @@ class UserSettings : public QObject bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) Q_PROPERTY( bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY decryptSidebarChanged) + Q_PROPERTY(SpaceNotificationOptions spaceNotifications READ spaceNotifications WRITE + setSpaceNotifications NOTIFY spaceNotificationsChanged) Q_PROPERTY( bool privacyScreen READ privacyScreen WRITE setPrivacyScreen NOTIFY privacyScreenChanged) Q_PROPERTY(int privacyScreenTimeout READ privacyScreenTimeout WRITE setPrivacyScreenTimeout @@ -134,6 +136,15 @@ public: }; Q_ENUM(Presence) + enum class SpaceNotificationOptions + { + SidebarAndRoomlist = 0, + Sidebar, + SidebarHiddenRooms, + SpaceNotificationsOff, + }; + Q_ENUM(SpaceNotificationOptions) + void save(); void load(std::optional<QString> profile); void applyTheme(); @@ -162,6 +173,7 @@ public: void setAlertOnNotification(bool state); void setAvatarCircles(bool state); void setDecryptSidebar(bool state); + void setSpaceNotifications(SpaceNotificationOptions state); void setPrivacyScreen(bool state); void setPrivacyScreenTimeout(int state); void setPresence(Presence state); @@ -202,6 +214,7 @@ public: bool groupView() const { return groupView_; } bool avatarCircles() const { return avatarCircles_; } bool decryptSidebar() const { return decryptSidebar_; } + SpaceNotificationOptions spaceNotifications() const { return spaceNotifications_; } bool privacyScreen() const { return privacyScreen_; } int privacyScreenTimeout() const { return privacyScreenTimeout_; } bool markdown() const { return markdown_; } @@ -278,6 +291,7 @@ signals: void alertOnNotificationChanged(bool state); void avatarCirclesChanged(bool state); void decryptSidebarChanged(bool state); + void spaceNotificationsChanged(SpaceNotificationOptions state); void privacyScreenChanged(bool state); void privacyScreenTimeoutChanged(int state); void timelineMaxWidthChanged(int state); @@ -340,6 +354,7 @@ private: bool hasAlertOnNotification_; bool avatarCircles_; bool decryptSidebar_; + SpaceNotificationOptions spaceNotifications_; bool privacyScreen_; int privacyScreenTimeout_; bool shareKeysWithTrustedUsers_; @@ -424,6 +439,7 @@ class UserSettingsModel : public QAbstractListModel GroupView, SortByImportance, DecryptSidebar, + SpaceNotifications, TraySection, Tray,