Skip to content
Snippets Groups Projects
UserSettingsPage.cpp 78.9 KiB
Newer Older
  • Learn to ignore specific revisions
  •     if (!i)
            return {};
    
        if (role == Name) {
            switch (index.row()) {
            case Theme:
                return tr("Theme");
            case ScaleFactor:
                return tr("Scale factor");
            case MessageHoverHighlight:
                return tr("Highlight message on hover");
            case EnlargeEmojiOnlyMessages:
                return tr("Large Emoji in timeline");
            case Tray:
                return tr("Minimize to tray");
            case StartInTray:
                return tr("Start in tray");
            case GroupView:
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                return tr("Communities sidebar");
    
            case ScrollbarsInRoomlist:
                return tr("Scrollbars in room list");
    
            case Markdown:
                return tr("Send messages as Markdown");
    
    LordMZTE's avatar
    LordMZTE committed
            case InvertEnterKey:
                return tr("Use shift+enter to send and enter to start a new line");
    
    Malte E's avatar
    Malte E committed
            case Bubbles:
    
    Malte E's avatar
    Malte E committed
                return tr("Enable message bubbles");
    
            case SmallAvatars:
                return tr("Enable small Avatars");
    
            case AnimateImagesOnHover:
                return tr("Play animated images only on hover");
            case TypingNotifications:
                return tr("Typing notifications");
            case SortByImportance:
                return tr("Sort rooms by unreads");
    
            case SortByAlphabet:
    
                return tr("Sort rooms alphabetically");
    
            case ButtonsInTimeline:
                return tr("Show buttons in timeline");
            case TimelineMaxWidth:
                return tr("Limit width of timeline");
            case ReadReceipts:
                return tr("Read receipts");
    
            case HiddenTimelineEvents:
                return tr("Hidden events");
    
            case IgnoredUsers:
                return tr("Ignored users");
    
            case DesktopNotifications:
                return tr("Desktop notifications");
            case AlertOnNotification:
                return tr("Alert on notification");
            case AvatarCircles:
                return tr("Circular Avatars");
            case UseIdenticon:
                return tr("Use identicons");
    
            case OpenImageExternal:
    
                return tr("Open images with external program");
    
            case OpenVideoExternal:
                return tr("Open videos with external program");
    
            case DecryptSidebar:
                return tr("Decrypt messages in sidebar");
    
            case DecryptNotifications:
                return tr("Decrypt notifications");
    
            case SpaceNotifications:
    
                return tr("Show message counts for communities and tags");
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case FancyEffects:
                return tr("Display fancy effects such as confetti");
    
            case ReducedMotion:
                return tr("Reduce or disable animations");
    
            case PrivacyScreen:
                return tr("Privacy Screen");
            case PrivacyScreenTimeout:
                return tr("Privacy screen timeout (in seconds [0 - 3600])");
            case MobileMode:
                return tr("Touchscreen mode");
            case FontSize:
                return tr("Font size");
            case Font:
                return tr("Font Family");
            case EmojiFont:
                return tr("Emoji Font Family");
            case Ringtone:
                return tr("Ringtone");
            case Microphone:
                return tr("Microphone");
            case Camera:
                return tr("Camera");
            case CameraResolution:
                return tr("Camera resolution");
            case CameraFrameRate:
                return tr("Camera frame rate");
            case UseStunServer:
                return tr("Allow fallback call assist server");
            case OnlyShareKeysWithVerifiedUsers:
                return tr("Send encrypted messages to verified users only");
            case ShareKeysWithTrustedUsers:
                return tr("Share keys with verified users and devices");
            case UseOnlineKeyBackup:
                return tr("Online Key Backup");
            case Profile:
                return tr("Profile");
            case UserId:
                return tr("User ID");
            case AccessToken:
                return tr("Accesstoken");
            case DeviceId:
                return tr("Device ID");
            case DeviceFingerprint:
                return tr("Device Fingerprint");
            case Homeserver:
                return tr("Homeserver");
            case Version:
                return tr("Version");
            case Platform:
                return tr("Platform");
            case GeneralSection:
                return tr("GENERAL");
    
            case AccessibilitySection:
                return tr("ACCESSIBILITY");
    
            case TimelineSection:
                return tr("TIMELINE");
            case SidebarSection:
                return tr("SIDEBAR");
            case TraySection:
                return tr("TRAY");
    
            case MessageVisibilitySection:
                return tr("GLOBAL MESSAGE VISIBILITY");
    
            case NotificationsSection:
                return tr("NOTIFICATIONS");
            case VoipSection:
                return tr("CALLS");
            case EncryptionSection:
                return tr("ENCRYPTION");
            case LoginInfoSection:
                return tr("INFO");
            case SessionKeys:
                return tr("Session Keys");
            case CrossSigningSecrets:
                return tr("Cross Signing Secrets");
            case OnlineBackupKey:
                return tr("Online backup key");
            case SelfSigningKey:
                return tr("Self signing key");
            case UserSigningKey:
                return tr("User signing key");
            case MasterKey:
                return tr("Master signing key");
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case ExposeDBusApi:
                return tr("Expose room information via D-Bus");
    
            case UpdateSpaceVias:
                return tr("Periodically update community routing information");
    
            case ExpireEvents:
                return tr("Periodically delete expired events");
    
        } else if (role == Value) {
            switch (index.row()) {
            case Theme:
                return QStringList{
                  QStringLiteral("light"),
                  QStringLiteral("dark"),
                  QStringLiteral("system"),
    
                  .indexOf(i->theme());
            case ScaleFactor:
                return utils::scaleFactor();
            case MessageHoverHighlight:
                return i->messageHoverHighlight();
            case EnlargeEmojiOnlyMessages:
                return i->enlargeEmojiOnlyMessages();
            case Tray:
                return i->tray();
            case StartInTray:
                return i->startInTray();
            case GroupView:
                return i->groupView();
    
            case ScrollbarsInRoomlist:
                return i->scrollbarsInRoomlist();
    
            case Markdown:
                return i->markdown();
    
    LordMZTE's avatar
    LordMZTE committed
            case InvertEnterKey:
                return i->invertEnterKey();
    
    Malte E's avatar
    Malte E committed
            case Bubbles:
                return i->bubbles();
    
            case SmallAvatars:
                return i->smallAvatars();
    
            case AnimateImagesOnHover:
                return i->animateImagesOnHover();
            case TypingNotifications:
                return i->typingNotifications();
            case SortByImportance:
                return i->sortByImportance();
    
            case SortByAlphabet:
                return i->sortByAlphabet();
    
            case ButtonsInTimeline:
                return i->buttonsInTimeline();
            case TimelineMaxWidth:
                return i->timelineMaxWidth();
            case ReadReceipts:
                return i->readReceipts();
            case DesktopNotifications:
                return i->hasDesktopNotifications();
            case AlertOnNotification:
                return i->hasAlertOnNotification();
            case AvatarCircles:
                return i->avatarCircles();
            case UseIdenticon:
                return i->useIdenticon();
    
            case OpenImageExternal:
    
                return i->openImageExternal();
    
            case OpenVideoExternal:
                return i->openVideoExternal();
    
            case DecryptSidebar:
                return i->decryptSidebar();
    
            case DecryptNotifications:
                return i->decryptNotifications();
    
            case SpaceNotifications:
    
                return i->spaceNotifications();
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case FancyEffects:
                return i->fancyEffects();
    
            case ReducedMotion:
                return i->reducedMotion();
    
            case PrivacyScreen:
                return i->privacyScreen();
            case PrivacyScreenTimeout:
                return i->privacyScreenTimeout();
            case MobileMode:
                return i->mobileMode();
            case FontSize:
                return i->fontSize();
    
            case Font: {
                if (i->font().isEmpty())
                    return 0;
                else
                    return data(index, Values).toStringList().indexOf(i->font());
            }
            case EmojiFont: {
                if (i->emojiFont().isEmpty())
                    return 0;
                else
                    return data(index, Values).toStringList().indexOf(i->emojiFont());
            }
    
            case Ringtone: {
                auto v = i->ringtone();
                if (v == QStringView(u"Mute"))
                    return 0;
                else if (v == QStringView(u"Default"))
                    return 1;
                else if (v == QStringView(u"Other"))
                    return 2;
                else
                    return 3;
    
            case Microphone:
                return data(index, Values).toStringList().indexOf(i->microphone());
            case Camera:
                return data(index, Values).toStringList().indexOf(i->camera());
            case CameraResolution:
                return data(index, Values).toStringList().indexOf(i->cameraResolution());
            case CameraFrameRate:
                return data(index, Values).toStringList().indexOf(i->cameraFrameRate());
            case UseStunServer:
                return i->useStunServer();
            case OnlyShareKeysWithVerifiedUsers:
                return i->onlyShareKeysWithVerifiedUsers();
            case ShareKeysWithTrustedUsers:
                return i->shareKeysWithTrustedUsers();
            case UseOnlineKeyBackup:
                return i->useOnlineKeyBackup();
            case Profile:
                return i->profile().isEmpty() ? tr("Default") : i->profile();
            case UserId:
                return i->userId();
            case AccessToken:
                return i->accessToken();
            case DeviceId:
                return i->deviceId();
            case DeviceFingerprint:
                return utils::humanReadableFingerprint(olm::client()->identity_keys().ed25519);
            case Homeserver:
                return i->homeserver();
            case Version:
                return QString::fromStdString(nheko::version);
            case Platform:
                return QString::fromStdString(nheko::build_os);
            case OnlineBackupKey:
                return cache::secret(mtx::secret_storage::secrets::megolm_backup_v1).has_value();
            case SelfSigningKey:
                return cache::secret(mtx::secret_storage::secrets::cross_signing_self_signing)
                  .has_value();
            case UserSigningKey:
                return cache::secret(mtx::secret_storage::secrets::cross_signing_user_signing)
                  .has_value();
            case MasterKey:
                return cache::secret(mtx::secret_storage::secrets::cross_signing_master).has_value();
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case ExposeDBusApi:
                return i->exposeDBusApi();
    
            case UpdateSpaceVias:
                return i->updateSpaceVias();
    
            case ExpireEvents:
                return i->expireEvents();
    
            }
        } else if (role == Description) {
            switch (index.row()) {
            case Theme:
            case Font:
            case EmojiFont:
                return {};
            case Microphone:
                return tr("Set the notification sound to play when a call invite arrives");
            case Camera:
            case CameraResolution:
            case CameraFrameRate:
            case Ringtone:
                return {};
            case TimelineMaxWidth:
                return tr("Set the max width of messages in the timeline (in pixels). This can help "
    
                          "readability on wide screen when Nheko is maximized");
    
            case PrivacyScreenTimeout:
                return tr(
                  "Set timeout (in seconds) for how long after window loses\nfocus before the screen"
                  " will be blurred.\nSet to 0 to blur immediately after focus loss. Max value of 1 "
                  "hour (3600 seconds)");
            case FontSize:
                return {};
            case MessageHoverHighlight:
                return tr("Change the background color of messages when you hover over them.");
            case EnlargeEmojiOnlyMessages:
                return tr("Make font size larger if messages with only a few emojis are displayed.");
            case Tray:
                return tr(
                  "Keep the application running in the background after closing the client window.");
            case StartInTray:
                return tr("Start the application in the background without showing the client window.");
            case GroupView:
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                return tr("Show a column containing communities and tags next to the room list.");
    
            case ScrollbarsInRoomlist:
                return tr("Shows scrollbars in the room list and communities list.");
    
            case Markdown:
                return tr(
                  "Allow using markdown in messages.\nWhen disabled, all messages are sent as a plain "
                  "text.");
    
    LordMZTE's avatar
    LordMZTE committed
            case InvertEnterKey:
                return tr(
                  "Invert the behavior of the enter key in the text input, making it send the message "
                  "when shift+enter is pressed and starting a new line when enter is pressed.");
    
    Malte E's avatar
    Malte E committed
            case Bubbles:
    
    Malte E's avatar
    Malte E committed
                return tr(
                  "Messages get a bubble background. This also triggers some layout changes (WIP).");
    
                return tr("Avatars are resized to fit above the message.");
    
            case AnimateImagesOnHover:
                return tr("Plays media like GIFs or WEBPs only when explicitly hovering over them.");
            case TypingNotifications:
                return tr(
                  "Show who is typing in a room.\nThis will also enable or disable sending typing "
                  "notifications to others.");
            case SortByImportance:
                return tr(
                  "Display rooms with new messages first.\nIf this is off, the list of rooms will only "
    
                  "be sorted by the preferred sorting order.\nIf this is on, rooms "
    
                  "which "
                  "have active notifications (the small circle with a number in it) will be sorted on "
    
                  "top. Rooms that you have muted will still be sorted by the preferred sorting order, "
                  "since you don't "
    
                  "seem to consider them as important as the other rooms.");
    
            case SortByAlphabet:
                return tr(
                  "Sort rooms alphabetically.\nIf this is off, the list of rooms will be sorted by the "
                  "timestamp of the last message in a room.\nIf this is on, rooms that come first "
                  "alphabetically "
                  "will be sorted earlier than ones that come later.");
    
            case ButtonsInTimeline:
                return tr(
                  "Show buttons to quickly reply, react or access additional options next to each "
                  "message.");
            case ReadReceipts:
    
                return tr(
                  "Show if your message was read.\nStatus is displayed next to timestamps.\nWarning: "
                  "If your homeserver does not support this, your rooms will never be marked as read!");
    
            case HiddenTimelineEvents:
                return tr("Configure whether to show or hide certain events like room joins.");
    
            case DesktopNotifications:
    
                return tr("Notify about received messages when the client is not currently focused.");
    
            case AlertOnNotification:
                return tr(
                  "Show an alert when a message is received.\nThis usually causes the application "
                  "icon in the task bar to animate in some fashion.");
            case AvatarCircles:
                return tr(
    
                  "Change the appearance of user avatars in chats.\nOFF - square, ON - circle.");
    
            case UseIdenticon:
                return tr("Display an identicon instead of a letter when no avatar is set.");
    
            case OpenImageExternal:
    
                return tr("Opens images with an external program when tapping the image.\nNote that "
                          "when this option is ON, opened files are left unencrypted on disk and must "
                          "be manually deleted.");
    
            case OpenVideoExternal:
    
                return tr("Opens videos with an external program when tapping the video.\nNote that "
                          "when this option is ON, opened files are left unencrypted on disk and must "
                          "be manually deleted.");
    
            case DecryptSidebar:
                return tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in "
                          "encrypted chats.");
    
            case DecryptNotifications:
                return tr("Decrypt messages shown in notifications for encrypted chats.");
    
            case SpaceNotifications:
    
                return tr("Choose where to show the total number of notifications contained within a "
                          "community or tag.");
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case FancyEffects:
                return tr("Some messages can be sent with fancy effects. For example, messages sent "
                          "with '/confetti' will show confetti on screen.");
    
            case ReducedMotion:
                return tr("Nheko uses animations in several places to make stuff pretty. This allows "
                          "you to turn those off if they make you feel unwell.");
    
            case PrivacyScreen:
                return tr("When the window loses focus, the timeline will\nbe blurred.");
            case MobileMode:
                return tr(
                  "Will prevent text selection in the timeline to make touch scrolling easier.");
            case ScaleFactor:
                return tr("Change the scale factor of the whole user interface.");
            case UseStunServer:
                return tr(
                  "Will use turn.matrix.org as assist when your home server does not offer one.");
            case OnlyShareKeysWithVerifiedUsers:
                return tr("Requires a user to be verified to send encrypted messages to them. This "
                          "improves safety but makes E2EE more tedious.");
            case ShareKeysWithTrustedUsers:
                return tr(
    
                  "Automatically replies to key requests from other users if they are verified, "
    
                  "even if that device shouldn't have access to those keys otherwise.");
            case UseOnlineKeyBackup:
                return tr(
                  "Download message encryption keys from and upload to the encrypted online key "
                  "backup.");
            case Profile:
            case UserId:
            case AccessToken:
            case DeviceId:
            case DeviceFingerprint:
            case Homeserver:
            case Version:
            case Platform:
            case GeneralSection:
    
            case AccessibilitySection:
    
            case TimelineSection:
            case SidebarSection:
            case TraySection:
    
            case MessageVisibilitySection:
    
            case NotificationsSection:
            case VoipSection:
            case EncryptionSection:
            case LoginInfoSection:
            case SessionKeys:
            case CrossSigningSecrets:
                return {};
            case OnlineBackupKey:
                return tr(
                  "The key to decrypt online key backups. If it is cached, you can enable online "
                  "key backup to store encryption keys securely encrypted on the server.");
            case SelfSigningKey:
                return tr(
                  "The key to verify your own devices. If it is cached, verifying one of your devices "
    
    Eldred Habert's avatar
    Eldred Habert committed
                  "will mark it verified for all your other devices and for users that have verified "
    
                  "you.");
            case UserSigningKey:
                return tr(
                  "The key to verify other users. If it is cached, verifying a user will verify "
                  "all their devices.");
            case MasterKey:
                return tr(
                  "Your most important key. You don't need to have it cached, since not caching "
                  "it makes it less likely it can be stolen and it is only needed to rotate your "
                  "other signing keys.");
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case ExposeDBusApi:
                return tr("Allow third-party plugins and applications to load information about rooms "
                          "you are in via D-Bus. "
                          "This can have useful applications, but it also could be used for nefarious "
                          "purposes. Enable at your own risk.\n\n"
                          "This setting will take effect upon restart.");
    
            case UpdateSpaceVias:
                return tr(
                  "To allow new users to join a community, the community needs to expose some "
                  "information about what servers participate in a room to community members. Since "
                  "the room participants can change over time, this needs to be updated from time to "
                  "time. This setting enables a background job to do that automatically.");
    
            case ExpireEvents:
                return tr("Regularly redact expired events as specified in the event expiration "
                          "configuration. Since this is currently not executed server side, you need "
                          "to have one client running this regularly.");
    
            case IgnoredUsers:
                return tr("Manage your ignored users.");
    
            }
        } else if (role == Type) {
            switch (index.row()) {
            case Theme:
            case Font:
            case EmojiFont:
            case Microphone:
            case Camera:
            case CameraResolution:
            case CameraFrameRate:
            case Ringtone:
                return Options;
            case TimelineMaxWidth:
            case PrivacyScreenTimeout:
    
            case FontSize:
            case ScaleFactor:
    
            case MessageHoverHighlight:
            case EnlargeEmojiOnlyMessages:
            case Tray:
            case StartInTray:
            case GroupView:
    
            case ScrollbarsInRoomlist:
    
            case Markdown:
    
    LordMZTE's avatar
    LordMZTE committed
            case InvertEnterKey:
    
    Malte E's avatar
    Malte E committed
            case Bubbles:
    
            case AnimateImagesOnHover:
            case TypingNotifications:
            case SortByImportance:
    
            case SortByAlphabet:
    
            case ButtonsInTimeline:
            case ReadReceipts:
            case DesktopNotifications:
            case AlertOnNotification:
            case AvatarCircles:
            case UseIdenticon:
    
            case OpenImageExternal:
            case OpenVideoExternal:
    
            case DecryptSidebar:
    
            case DecryptNotifications:
    
            case PrivacyScreen:
            case MobileMode:
            case UseStunServer:
            case OnlyShareKeysWithVerifiedUsers:
            case ShareKeysWithTrustedUsers:
            case UseOnlineKeyBackup:
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case ExposeDBusApi:
    
            case ExpireEvents:
    
            case SpaceNotifications:
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case FancyEffects:
    
            case ReducedMotion:
    
                return Toggle;
            case Profile:
            case UserId:
            case AccessToken:
            case DeviceId:
            case DeviceFingerprint:
            case Homeserver:
            case Version:
            case Platform:
                return ReadOnlyText;
            case GeneralSection:
    
            case AccessibilitySection:
    
            case TimelineSection:
            case SidebarSection:
            case TraySection:
    
            case MessageVisibilitySection:
    
            case NotificationsSection:
            case VoipSection:
            case EncryptionSection:
            case LoginInfoSection:
                return SectionTitle;
            case SessionKeys:
                return SessionKeyImportExport;
            case CrossSigningSecrets:
                return XSignKeysRequestDownload;
            case OnlineBackupKey:
            case SelfSigningKey:
            case UserSigningKey:
            case MasterKey:
                return KeyStatus;
    
            case HiddenTimelineEvents:
                return ConfigureHiddenEvents;
    
            case IgnoredUsers:
                return ManageIgnoredUsers;
    
            }
        } else if (role == ValueLowerBound) {
            switch (index.row()) {
            case TimelineMaxWidth:
                return 0;
            case PrivacyScreenTimeout:
                return 0;
            case FontSize:
                return 8.0;
            case ScaleFactor:
                return 1.0;
            }
        } else if (role == ValueUpperBound) {
            switch (index.row()) {
            case TimelineMaxWidth:
                return 20000;
            case PrivacyScreenTimeout:
                return 3600;
            case FontSize:
                return 24.0;
            case ScaleFactor:
                return 3.0;
            }
        } else if (role == ValueStep) {
            switch (index.row()) {
            case TimelineMaxWidth:
                return 20;
            case PrivacyScreenTimeout:
                return 10;
            case FontSize:
                return 0.5;
            case ScaleFactor:
                return .25;
            }
        } else if (role == Values) {
            auto vecToList = [](const std::vector<std::string> &vec) {
                QStringList l;
                for (const auto &d : vec)
                    l.push_back(QString::fromStdString(d));
                return l;
            };
            switch (index.row()) {
            case Theme:
                return QStringList{
                  QStringLiteral("Light"),
                  QStringLiteral("Dark"),
                  QStringLiteral("System"),
                };
            case Microphone:
                return vecToList(CallDevices::instance().names(false, i->microphone().toStdString()));
            case Camera:
                return vecToList(CallDevices::instance().names(true, i->camera().toStdString()));
            case CameraResolution:
                return vecToList(CallDevices::instance().resolutions(i->camera().toStdString()));
            case CameraFrameRate:
                return vecToList(CallDevices::instance().frameRates(
                  i->camera().toStdString(), i->cameraResolution().toStdString()));
    
    
            case Font: {
                auto fonts = QFontDatabase::families();
                fonts.prepend(tr("System font"));
                return fonts;
            }
            case EmojiFont: {
                auto fonts = QFontDatabase::families(QFontDatabase::WritingSystem::Symbol);
                fonts.prepend(tr("System emoji font"));
                return fonts;
            }
    
            case Ringtone: {
    
                QStringList l{
                  QStringLiteral("Mute"),
                  QStringLiteral("Default"),
                  QStringLiteral("Other"),
                };
                if (!l.contains(i->ringtone()))
                    l.push_back(i->ringtone());
                return l;
            }
    
        } else if (role == Good) {
            switch (index.row()) {
            case OnlineBackupKey:
                return cache::secret(mtx::secret_storage::secrets::megolm_backup_v1).has_value();
            case SelfSigningKey:
                return cache::secret(mtx::secret_storage::secrets::cross_signing_self_signing)
                  .has_value();
            case UserSigningKey:
                return cache::secret(mtx::secret_storage::secrets::cross_signing_user_signing)
                  .has_value();
            case MasterKey:
                return true;
            }
        } else if (role == Enabled) {
            switch (index.row()) {
            case StartInTray:
                return i->tray();
            case PrivacyScreenTimeout:
                return i->privacyScreen();
            case UseIdenticon:
                return JdenticonProvider::isAvailable();
            default:
                return true;
            }
        }
    
        return {};
    
    bool
    UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int role)
    
        auto i = UserSettings::instance();
        if (role == Value) {
            switch (index.row()) {
            case Theme: {
                if (value == 0) {
                    i->setTheme("light");
                    return true;
                } else if (value == 1) {
                    i->setTheme("dark");
                    return true;
                } else if (value == 2) {
                    i->setTheme("system");
                    return true;
                } else
                    return false;
            }
            case MessageHoverHighlight: {
                if (value.userType() == QMetaType::Bool) {
                    i->setMessageHoverHighlight(value.toBool());
                    return true;
                } else
                    return false;
            }
            case ScaleFactor: {
    
                if (value.canConvert(QMetaType::fromType<double>())) {
    
                    utils::setScaleFactor(static_cast<float>(value.toDouble()));
                    return true;
                } else
                    return false;
            }
            case EnlargeEmojiOnlyMessages: {
                if (value.userType() == QMetaType::Bool) {
                    i->setEnlargeEmojiOnlyMessages(value.toBool());
                    return true;
                } else
                    return false;
            }
            case Tray: {
                if (value.userType() == QMetaType::Bool) {
                    i->setTray(value.toBool());
                    return true;
                } else
                    return false;
            }
            case StartInTray: {
                if (value.userType() == QMetaType::Bool) {
                    i->setStartInTray(value.toBool());
                    return true;
                } else
                    return false;
            }
            case GroupView: {
                if (value.userType() == QMetaType::Bool) {
                    i->setGroupView(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case ScrollbarsInRoomlist: {
                if (value.userType() == QMetaType::Bool) {
                    i->setScrollbarsInRoomlist(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case Markdown: {
                if (value.userType() == QMetaType::Bool) {
                    i->setMarkdown(value.toBool());
                    return true;
                } else
                    return false;
            }
    
    LordMZTE's avatar
    LordMZTE committed
            case InvertEnterKey: {
    
    Malte E's avatar
    Malte E committed
                if (value.userType() == QMetaType::Bool) {
    
    LordMZTE's avatar
    LordMZTE committed
                    i->setInvertEnterKey(value.toBool());
    
    Malte E's avatar
    Malte E committed
                    return true;
                } else
                    return false;
            }
    
    LordMZTE's avatar
    LordMZTE committed
            case Bubbles: {
    
                if (value.userType() == QMetaType::Bool) {
    
    LordMZTE's avatar
    LordMZTE committed
                    i->setBubbles(value.toBool());
    
                    return true;
                } else
                    return false;
            }
    
    LordMZTE's avatar
    LordMZTE committed
            case SmallAvatars: {
    
    LordMZTE's avatar
    LordMZTE committed
                if (value.userType() == QMetaType::Bool) {
    
    LordMZTE's avatar
    LordMZTE committed
                    i->setSmallAvatars(value.toBool());
    
    LordMZTE's avatar
    LordMZTE committed
                    return true;
                } else
                    return false;
            }
    
            case AnimateImagesOnHover: {
                if (value.userType() == QMetaType::Bool) {
                    i->setAnimateImagesOnHover(value.toBool());
                    return true;
                } else
                    return false;
            }
            case TypingNotifications: {
                if (value.userType() == QMetaType::Bool) {
                    i->setTypingNotifications(value.toBool());
                    return true;
                } else
                    return false;
            }
            case SortByImportance: {
                if (value.userType() == QMetaType::Bool) {
                    i->setSortByImportance(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case SortByAlphabet: {
                if (value.userType() == QMetaType::Bool) {
                    i->setSortByAlphabet(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case ButtonsInTimeline: {
                if (value.userType() == QMetaType::Bool) {
                    i->setButtonsInTimeline(value.toBool());
                    return true;
                } else
                    return false;
            }
            case TimelineMaxWidth: {
    
                if (value.canConvert(QMetaType::fromType<int>())) {
    
                    i->setTimelineMaxWidth(value.toInt());
                    return true;
                } else
                    return false;
            }
            case ReadReceipts: {
                if (value.userType() == QMetaType::Bool) {
                    i->setReadReceipts(value.toBool());
                    return true;
                } else
                    return false;
            }
            case DesktopNotifications: {
                if (value.userType() == QMetaType::Bool) {
                    i->setDesktopNotifications(value.toBool());
                    return true;
                } else
                    return false;
            }
            case AlertOnNotification: {
                if (value.userType() == QMetaType::Bool) {
                    i->setAlertOnNotification(value.toBool());
                    return true;
                } else
                    return false;
            }
            case AvatarCircles: {
                if (value.userType() == QMetaType::Bool) {
                    i->setAvatarCircles(value.toBool());
                    return true;
                } else
                    return false;
            }
            case UseIdenticon: {
                if (value.userType() == QMetaType::Bool) {
                    i->setUseIdenticon(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case OpenImageExternal: {
    
                if (value.userType() == QMetaType::Bool) {
                    i->setOpenImageExternal(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case OpenVideoExternal: {
                if (value.userType() == QMetaType::Bool) {
                    i->setOpenVideoExternal(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case DecryptSidebar: {
                if (value.userType() == QMetaType::Bool) {
                    i->setDecryptSidebar(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case DecryptNotifications: {
                if (value.userType() == QMetaType::Bool) {
                    i->setDecryptNotifications(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case SpaceNotifications: {
    
                if (value.userType() == QMetaType::Bool) {
                    i->setSpaceNotifications(value.toBool());
                    return true;
                } else
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            case FancyEffects: {
                if (value.userType() == QMetaType::Bool) {
                    i->setFancyEffects(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case ReducedMotion: {
                if (value.userType() == QMetaType::Bool) {
                    i->setReducedMotion(value.toBool());
                    return true;
                } else
                    return false;
            }
    
            case PrivacyScreen: {
                if (value.userType() == QMetaType::Bool) {
                    i->setPrivacyScreen(value.toBool());
                    return true;
                } else
                    return false;
            }
            case PrivacyScreenTimeout: {
    
                if (value.canConvert(QMetaType::fromType<int>())) {
    
                    i->setPrivacyScreenTimeout(value.toInt());
                    return true;
                } else
                    return false;
            }
            case MobileMode: {
                if (value.userType() == QMetaType::Bool) {
                    i->setMobileMode(value.toBool());
                    return true;
                } else
                    return false;
            }
            case FontSize: {
    
                if (value.canConvert(QMetaType::fromType<double>())) {
    
                    i->setFontSize(value.toDouble());
    
                    return true;
                } else
                    return false;
            }
            case Font: {
                if (value.userType() == QMetaType::Int) {
    
                    // Special handling to grab our injected system font option
                    auto v = value.toInt();
                    i->setFontFamily(v == 0 ? QString{} : QFontDatabase::families().at(v - 1));
    
                    return true;
                } else
                    return false;
            }
            case EmojiFont: {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                if (value.userType() == QMetaType::Int) {
    
                    // More special handling for the default font option
                    auto v = value.toInt();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    i->setEmojiFontFamily(
    
                      v == 0 ? QStringLiteral("emoji")
                             : QFontDatabase::families(QFontDatabase::WritingSystem::Symbol).at(v - 1));
    
                    return true;
                } else
                    return false;
            }
            case Ringtone: {
                if (value.userType() == QMetaType::Int) {
                    int ringtone = value.toInt();
    
                    // setRingtone is called twice, because updating the list breaks the set value,
                    // because it does not exist yet!
                    if (ringtone == 2) {
                        QString homeFolder =
                          QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
                        auto filepath = QFileDialog::getOpenFileName(
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                          nullptr, tr("Select a file"), homeFolder, tr("All Files (*)"));
    
                        if (!filepath.isEmpty()) {
                            i->setRingtone(filepath);
                            i->setRingtone(filepath);
                        }
                    } else if (ringtone == 0) {
                        i->setRingtone(QStringLiteral("Mute"));
                        i->setRingtone(QStringLiteral("Mute"));
                    } else if (ringtone == 1) {
                        i->setRingtone(QStringLiteral("Default"));
                        i->setRingtone(QStringLiteral("Default"));
                    }
                    return true;
                }
                return false;
            }
            case Microphone: {
                if (value.userType() == QMetaType::Int) {
                    i->setMicrophone(data(index, Values).toStringList().at(value.toInt()));
                    return true;
                } else
                    return false;
            }
            case Camera: {
                if (value.userType() == QMetaType::Int) {
                    i->setCamera(data(index, Values).toStringList().at(value.toInt()));
                    return true;
                } else
                    return false;
            }
            case CameraResolution: {
                if (value.userType() == QMetaType::Int) {