Skip to content
Snippets Groups Projects
UserSettingsPage.cpp 73.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •     }
    
        // Open file dialog to save the file.
        const QString homeFolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
    
        const QString fileName   = QFileDialog::getSaveFileName(
    
    Nicolas Werner's avatar
    Nicolas Werner committed
          nullptr, tr("File to save the exported session keys"), homeFolder);
    
    
        QFile file(fileName);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            QMessageBox::warning(nullptr, tr("Error"), file.errorString());
    
            return;
        }
    
        // Export sessions & save to file.
        try {
            auto encrypted_blob = mtx::crypto::encrypt_exported_sessions(cache::exportSessionKeys(),
                                                                         password.toStdString());
    
            QString b64 = QString::fromStdString(mtx::crypto::bin2base64(encrypted_blob));
    
    
            QString prefix(QStringLiteral("-----BEGIN MEGOLM SESSION DATA-----"));
            QString suffix(QStringLiteral("-----END MEGOLM SESSION DATA-----"));
            QString newline(QStringLiteral("\n"));
    
            QTextStream out(&file);
            out << prefix << newline << b64 << newline << suffix << newline;
            file.close();
        } catch (const std::exception &e) {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            QMessageBox::warning(nullptr, tr("Error"), e.what());
    
    UserSettingsModel::requestCrossSigningSecrets()
    {
        olm::request_cross_signing_keys();
    }
    void
    UserSettingsModel::downloadCrossSigningSecrets()
    {
        olm::download_cross_signing_keys();
    }
    
    UserSettingsModel::UserSettingsModel(QObject *p)
      : QAbstractListModel(p)
    {
        auto s = UserSettings::instance();
        connect(s.get(), &UserSettings::themeChanged, this, [this]() {
            emit dataChanged(index(Theme), index(Theme), {Value});
        });
        connect(s.get(), &UserSettings::mobileModeChanged, this, [this]() {
            emit dataChanged(index(MobileMode), index(MobileMode), {Value});
        });
    
        connect(s.get(), &UserSettings::fontChanged, this, [this]() {
            emit dataChanged(index(Font), index(Font), {Value});
        });
        connect(s.get(), &UserSettings::fontSizeChanged, this, [this]() {
            emit dataChanged(index(FontSize), index(FontSize), {Value});
        });
        connect(s.get(), &UserSettings::emojiFontChanged, this, [this]() {
            emit dataChanged(index(EmojiFont), index(EmojiFont), {Value});
        });
        connect(s.get(), &UserSettings::avatarCirclesChanged, this, [this]() {
            emit dataChanged(index(AvatarCircles), index(AvatarCircles), {Value});
        });
        connect(s.get(), &UserSettings::useIdenticonChanged, this, [this]() {
            emit dataChanged(index(UseIdenticon), index(UseIdenticon), {Value});
        });
    
        connect(s.get(), &UserSettings::openImageExternalChanged, this, [this]() {
            emit dataChanged(index(OpenImageExternal), index(OpenImageExternal), {Value});
        });
    
        connect(s.get(), &UserSettings::openVideoExternalChanged, this, [this]() {
            emit dataChanged(index(OpenVideoExternal), index(OpenVideoExternal), {Value});
        });
    
        connect(s.get(), &UserSettings::privacyScreenChanged, this, [this]() {
            emit dataChanged(index(PrivacyScreen), index(PrivacyScreen), {Value});
            emit dataChanged(index(PrivacyScreenTimeout), index(PrivacyScreenTimeout), {Enabled});
        });
        connect(s.get(), &UserSettings::privacyScreenTimeoutChanged, this, [this]() {
            emit dataChanged(index(PrivacyScreenTimeout), index(PrivacyScreenTimeout), {Value});
        });
    
        connect(s.get(), &UserSettings::timelineMaxWidthChanged, this, [this]() {
            emit dataChanged(index(TimelineMaxWidth), index(TimelineMaxWidth), {Value});
        });
        connect(s.get(), &UserSettings::messageHoverHighlightChanged, this, [this]() {
            emit dataChanged(index(MessageHoverHighlight), index(MessageHoverHighlight), {Value});
        });
        connect(s.get(), &UserSettings::enlargeEmojiOnlyMessagesChanged, this, [this]() {
            emit dataChanged(index(EnlargeEmojiOnlyMessages), index(EnlargeEmojiOnlyMessages), {Value});
        });
        connect(s.get(), &UserSettings::animateImagesOnHoverChanged, this, [this]() {
            emit dataChanged(index(AnimateImagesOnHover), index(AnimateImagesOnHover), {Value});
        });
        connect(s.get(), &UserSettings::typingNotificationsChanged, this, [this]() {
            emit dataChanged(index(TypingNotifications), index(TypingNotifications), {Value});
        });
        connect(s.get(), &UserSettings::readReceiptsChanged, this, [this]() {
            emit dataChanged(index(ReadReceipts), index(ReadReceipts), {Value});
        });
        connect(s.get(), &UserSettings::buttonInTimelineChanged, this, [this]() {
            emit dataChanged(index(ButtonsInTimeline), index(ButtonsInTimeline), {Value});
        });
        connect(s.get(), &UserSettings::markdownChanged, this, [this]() {
            emit dataChanged(index(Markdown), index(Markdown), {Value});
        });
    
    LordMZTE's avatar
    LordMZTE committed
        connect(s.get(), &UserSettings::invertEnterKeyChanged, this, [this]() {
            emit dataChanged(index(InvertEnterKey), index(InvertEnterKey), {Value});
        });
    
    Malte E's avatar
    Malte E committed
        connect(s.get(), &UserSettings::bubblesChanged, this, [this]() {
            emit dataChanged(index(Bubbles), index(Bubbles), {Value});
        });
    
        connect(s.get(), &UserSettings::smallAvatarsChanged, this, [this]() {
            emit dataChanged(index(SmallAvatars), index(SmallAvatars), {Value});
        });
    
        connect(s.get(), &UserSettings::groupViewStateChanged, this, [this]() {
            emit dataChanged(index(GroupView), index(GroupView), {Value});
        });
    
        connect(s.get(), &UserSettings::scrollbarsInRoomlistChanged, this, [this]() {
            emit dataChanged(index(ScrollbarsInRoomlist), index(ScrollbarsInRoomlist), {Value});
        });
    
        connect(s.get(), &UserSettings::roomSortingChanged, this, [this]() {
            emit dataChanged(index(SortByImportance), index(SortByImportance), {Value});
        });
        connect(s.get(), &UserSettings::decryptSidebarChanged, this, [this]() {
            emit dataChanged(index(DecryptSidebar), index(DecryptSidebar), {Value});
        });
    
        connect(s.get(), &UserSettings::decryptNotificationsChanged, this, [this]() {
            emit dataChanged(index(DecryptNotifications), index(DecryptNotifications), {Value});
        });
    
    LordMZTE's avatar
    LordMZTE committed
        connect(s.get(), &UserSettings::spaceNotificationsChanged, this, [this]() {
    
            emit dataChanged(index(SpaceNotifications), index(SpaceNotifications), {Value});
        });
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        connect(s.get(), &UserSettings::fancyEffectsChanged, this, [this]() {
            emit dataChanged(index(FancyEffects), index(FancyEffects), {Value});
        });
    
        connect(s.get(), &UserSettings::reducedMotionChanged, this, [this]() {
            emit dataChanged(index(ReducedMotion), index(ReducedMotion), {Value});
        });
    
        connect(s.get(), &UserSettings::trayChanged, this, [this]() {
            emit dataChanged(index(Tray), index(Tray), {Value});
            emit dataChanged(index(StartInTray), index(StartInTray), {Enabled});
        });
        connect(s.get(), &UserSettings::startInTrayChanged, this, [this]() {
            emit dataChanged(index(StartInTray), index(StartInTray), {Value});
        });
    
        connect(s.get(), &UserSettings::desktopNotificationsChanged, this, [this]() {
            emit dataChanged(index(DesktopNotifications), index(DesktopNotifications), {Value});
        });
        connect(s.get(), &UserSettings::alertOnNotificationChanged, this, [this]() {
            emit dataChanged(index(AlertOnNotification), index(AlertOnNotification), {Value});
        });
    
        connect(s.get(), &UserSettings::useStunServerChanged, this, [this]() {
            emit dataChanged(index(UseStunServer), index(UseStunServer), {Value});
        });
        connect(s.get(), &UserSettings::microphoneChanged, this, [this]() {
            emit dataChanged(index(Microphone), index(Microphone), {Value, Values});
        });
        connect(s.get(), &UserSettings::cameraChanged, this, [this]() {
            emit dataChanged(index(Camera), index(Camera), {Value, Values});
        });
        connect(s.get(), &UserSettings::cameraResolutionChanged, this, [this]() {
            emit dataChanged(index(CameraResolution), index(CameraResolution), {Value, Values});
        });
        connect(s.get(), &UserSettings::cameraFrameRateChanged, this, [this]() {
            emit dataChanged(index(CameraFrameRate), index(CameraFrameRate), {Value, Values});
        });
        connect(s.get(), &UserSettings::ringtoneChanged, this, [this]() {
            emit dataChanged(index(Ringtone), index(Ringtone), {Values, Value});
        });
    
        connect(s.get(), &UserSettings::onlyShareKeysWithVerifiedUsersChanged, this, [this]() {
            emit dataChanged(
              index(OnlyShareKeysWithVerifiedUsers), index(OnlyShareKeysWithVerifiedUsers), {Value});
        });
        connect(s.get(), &UserSettings::shareKeysWithTrustedUsersChanged, this, [this]() {
            emit dataChanged(
              index(ShareKeysWithTrustedUsers), index(ShareKeysWithTrustedUsers), {Value});
        });
        connect(s.get(), &UserSettings::useOnlineKeyBackupChanged, this, [this]() {
            emit dataChanged(index(UseOnlineKeyBackup), index(UseOnlineKeyBackup), {Value});
        });
        connect(MainWindow::instance(), &MainWindow::secretsChanged, this, [this]() {
            emit dataChanged(index(OnlineBackupKey), index(MasterKey), {Value, Good});
        });
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        connect(s.get(), &UserSettings::exposeDBusApiChanged, this, [this] {
            emit dataChanged(index(ExposeDBusApi), index(ExposeDBusApi), {Value});
        });