Simplify space notification options

This commit is contained in:
Loren Burkholder 2022-06-06 12:07:25 -04:00
parent f264941615
commit 885a790b1f
4 changed files with 18 additions and 75 deletions

View file

@ -88,14 +88,7 @@ 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);
spaceNotifications_ = settings.value(QStringLiteral("user/space_notifications"), true).toBool();
privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool();
privacyScreenTimeout_ =
settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt();
@ -433,7 +426,7 @@ UserSettings::setDecryptSidebar(bool state)
}
void
UserSettings::setSpaceNotifications(SpaceNotificationOptions state)
UserSettings::setSpaceNotifications(bool state)
{
if (state == spaceNotifications_)
return;
@ -803,9 +796,7 @@ 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("space_notifications"), spaceNotifications_);
settings.setValue(QStringLiteral("privacy_screen"), privacyScreen_);
settings.setValue(QStringLiteral("privacy_screen_timeout"), privacyScreenTimeout_);
settings.setValue(QStringLiteral("mobile_mode"), mobileMode_);
@ -1086,7 +1077,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case DecryptSidebar:
return i->decryptSidebar();
case SpaceNotifications:
return static_cast<int>(i->spaceNotifications());
return i->spaceNotifications();
case PrivacyScreen:
return i->privacyScreen();
case PrivacyScreenTimeout:
@ -1320,7 +1311,6 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case CameraResolution:
case CameraFrameRate:
case Ringtone:
case SpaceNotifications:
return Options;
case TimelineMaxWidth:
case PrivacyScreenTimeout:
@ -1355,6 +1345,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
case ShareKeysWithTrustedUsers:
case UseOnlineKeyBackup:
case ExposeDBusApi:
case SpaceNotifications:
return Toggle;
case Profile:
case UserId:
@ -1457,11 +1448,6 @@ 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 spaces and tags only)"),
QStringLiteral("Off")};
}
} else if (role == Good) {
switch (index.row()) {
@ -1669,13 +1655,11 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
}
return i->decryptSidebar();
case SpaceNotifications: {
if (value.toInt() >
static_cast<int>(UserSettings::SpaceNotificationOptions::SpaceNotificationsOff) ||
value.toInt() < 0)
if (value.userType() == QMetaType::Bool) {
i->setSpaceNotifications(value.toBool());
return true;
} else
return false;
i->setSpaceNotifications(value.value<UserSettings::SpaceNotificationOptions>());
return true;
}
case PrivacyScreen: {
if (value.userType() == QMetaType::Bool) {