Add space notification configuration

This commit is contained in:
Loren Burkholder 2022-04-22 20:34:15 -04:00
parent c2b6728955
commit 863eaa1910
4 changed files with 92 additions and 7 deletions

View file

@ -171,7 +171,21 @@ Page {
bubbleBackgroundColor: communityItem.bubbleBackground
bubbleTextColor: communityItem.bubbleText
font.pixelSize: fontMetrics.font.pixelSize * 0.6
mayBeVisible: communitySidebar.collapsed
mayBeVisible: {
if (!communitySidebar.collapsed)
return false
else if (Settings.spaceNotifications === Settings.SpaceNotificationsOff)
return false
else if (Settings.spaceNotifications === Settings.SidebarHiddenRooms)
{
if (communityItem.hidden)
return true
else
return false
}
else
return true
}
anchors.right: avatar.right
anchors.bottom: avatar.bottom
anchors.margins: -Nheko.paddingSmall
@ -198,7 +212,16 @@ Page {
hasLoudNotification: communityItem.hasLoudNotification
bubbleBackgroundColor: communityItem.bubbleBackground
bubbleTextColor: communityItem.bubbleText
mayBeVisible: !communitySidebar.collapsed
mayBeVisible: {
if (communitySidebar.collapsed)
return false
else if (Settings.spaceNotification === Settings.SpaceNotificationsOff)
return false
else if ((Settings.spaceNotifications === Settings.SidebarHiddenRooms) && communityItem.hidden)
return true
else
return true
}
Layout.alignment: Qt.AlignRight
Layout.leftMargin: Nheko.paddingSmall
}

View file

@ -316,7 +316,7 @@ Page {
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: -Nheko.paddingSmall
mayBeVisible: collapsed
mayBeVisible: collapsed && (isSpace ? Settings.spaceNotifications === Settings.SidebarAndRoomlist : true)
}
}
@ -345,7 +345,7 @@ Page {
Layout.leftMargin: Nheko.paddingSmall
Layout.preferredWidth: implicitWidth
Layout.preferredHeight: implicitHeight
mayBeVisible: !collapsed
mayBeVisible: !collapsed && (isSpace ? Settings.spaceNotifications === Settings.SidebarAndRoomlist : true)
}
RowLayout {

View file

@ -88,6 +88,14 @@ 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();
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();
@ -416,6 +424,16 @@ UserSettings::setDecryptSidebar(bool state)
save();
}
void
UserSettings::setSpaceNotifications(SpaceNotificationOptions state)
{
if (state == spaceNotifications_)
return;
spaceNotifications_ = state;
emit spaceNotificationsChanged(state);
save();
}
void
UserSettings::setPrivacyScreen(bool state)
{
@ -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});

View file

@ -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,