Port usersettings to qml

This commit is contained in:
Nicolas Werner 2022-01-09 00:28:03 +01:00
parent 8d52c17f29
commit f1a23355bd
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
16 changed files with 1330 additions and 859 deletions

View file

@ -56,11 +56,10 @@ MainWindow::MainWindow(QWidget *parent)
trayIcon_ = new TrayIcon(QStringLiteral(":/logos/nheko.svg"), this);
welcome_page_ = new WelcomePage(this);
login_page_ = new LoginPage(this);
register_page_ = new RegisterPage(this);
chat_page_ = new ChatPage(userSettings_, this);
userSettingsPage_ = new UserSettingsPage(userSettings_, this);
welcome_page_ = new WelcomePage(this);
login_page_ = new LoginPage(this);
register_page_ = new RegisterPage(this);
chat_page_ = new ChatPage(userSettings_, this);
// Initialize sliding widget manager.
pageStack_ = new QStackedWidget(this);
@ -68,7 +67,6 @@ MainWindow::MainWindow(QWidget *parent)
pageStack_->addWidget(login_page_);
pageStack_->addWidget(register_page_);
pageStack_->addWidget(chat_page_);
pageStack_->addWidget(userSettingsPage_);
setCentralWidget(pageStack_);
@ -93,13 +91,7 @@ MainWindow::MainWindow(QWidget *parent)
showLoginPage();
});
connect(userSettingsPage_, &UserSettingsPage::moveBack, this, [this]() {
pageStack_->setCurrentWidget(chat_page_);
});
connect(userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool)));
connect(
userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged);
connect(userSettings_.get(), &UserSettings::trayChanged, trayIcon_, &TrayIcon::setVisible);
connect(trayIcon_,
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,
@ -109,8 +101,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(this, &MainWindow::focusChanged, chat_page_, &ChatPage::chatFocusChanged);
connect(chat_page_, &ChatPage::showUserSettingsPage, this, &MainWindow::showUserSettingsPage);
connect(login_page_, &LoginPage::loginOk, this, [this](const mtx::responses::Login &res) {
http::client()->set_user(res.user_id);
showChatPage();
@ -247,14 +237,8 @@ MainWindow::showChatPage()
login_page_->reset();
chat_page_->bootstrap(userid, homeserver, token);
connect(cache::client(),
&Cache::databaseReady,
userSettingsPage_,
&UserSettingsPage::updateSecretStatus);
connect(cache::client(),
&Cache::secretChanged,
userSettingsPage_,
&UserSettingsPage::updateSecretStatus);
connect(cache::client(), &Cache::databaseReady, this, &MainWindow::secretsChanged);
connect(cache::client(), &Cache::secretChanged, this, &MainWindow::secretsChanged);
emit reload();
}
@ -403,9 +387,3 @@ MainWindow::showRegisterPage()
pageStack_->addWidget(register_page_);
pageStack_->setCurrentWidget(register_page_);
}
void
MainWindow::showUserSettingsPage()
{
pageStack_->setCurrentWidget(userSettingsPage_);
}

View file

@ -84,9 +84,6 @@ private slots:
//! Show the register page in the main window.
void showRegisterPage();
//! Show user settings page.
void showUserSettingsPage();
//! Show the chat page and start communicating with the given access token.
void showChatPage();
@ -98,6 +95,7 @@ private slots:
signals:
void focusChanged(const bool focused);
void reload();
void secretsChanged();
private:
void showDialog(QWidget *dialog);
@ -120,7 +118,6 @@ private:
QStackedWidget *pageStack_;
//! The main chat area.
ChatPage *chat_page_;
UserSettingsPage *userSettingsPage_;
QSharedPointer<UserSettings> userSettings_;
//! Tray icon that shows the unread message count.
TrayIcon *trayIcon_;

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@
#pragma once
#include <QAbstractListModel>
#include <QFontDatabase>
#include <QFrame>
#include <QProcessEnvironment>
@ -353,89 +354,125 @@ private:
static QSharedPointer<UserSettings> instance_;
};
class HorizontalLine : public QFrame
class UserSettingsModel : public QAbstractListModel
{
Q_OBJECT
public:
HorizontalLine(QWidget *parent = nullptr);
};
enum Indices
{
GeneralSection,
Theme,
MobileMode,
#ifndef Q_OS_MAC
ScaleFactor,
#endif
Font,
FontSize,
EmojiFont,
AvatarCircles,
UseIdenticon,
PrivacyScreen,
PrivacyScreenTimeout,
class UserSettingsPage : public QWidget
{
Q_OBJECT
TimelineSection,
TimelineMaxWidth,
MessageHoverHighlight,
EnlargeEmojiOnlyMessages,
AnimateImagesOnHover,
TypingNotifications,
ReadReceipts,
ButtonsInTimeline,
Markdown,
SidebarSection,
GroupView,
SortByImportance,
DecryptSidebar,
TraySection,
Tray,
StartInTray,
NotificationsSection,
DesktopNotifications,
AlertOnNotification,
VoipSection,
UseStunServer,
Microphone,
Camera,
CameraResolution,
CameraFrameRate,
Ringtone,
EncryptionSection,
OnlyShareKeysWithVerifiedUsers,
ShareKeysWithTrustedUsers,
SessionKeys,
UseOnlineKeyBackup,
OnlineBackupKey,
SelfSigningKey,
UserSigningKey,
MasterKey,
CrossSigningSecrets,
DeviceId,
DeviceFingerprint,
LoginInfoSection,
UserId,
Homeserver,
Profile,
Version,
Platform,
COUNT,
// hidden for now
AccessToken,
#ifdef Q_OS_MAC
ScaleFactor,
#endif
};
public:
UserSettingsPage(QSharedPointer<UserSettings> settings, QWidget *parent = nullptr);
enum Types
{
Toggle,
ReadOnlyText,
Options,
Number,
SectionTitle,
SectionBar,
KeyStatus,
SessionKeyImportExport,
XSignKeysRequestDownload,
};
Q_ENUM(Types);
protected:
void showEvent(QShowEvent *event) override;
void paintEvent(QPaintEvent *event) override;
enum Roles
{
Name,
Description,
Value,
Type,
ValueLowerBound,
ValueUpperBound,
ValueStep,
Values,
Good,
Enabled,
};
signals:
void moveBack();
void trayOptionChanged(bool value);
void themeChanged();
void decryptSidebarChanged();
UserSettingsModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
(void)parent;
return (int)COUNT;
}
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
public slots:
void updateSecretStatus();
private slots:
void importSessionKeys();
void exportSessionKeys();
private:
// Layouts
QVBoxLayout *topLayout_;
QHBoxLayout *topBarLayout_;
QFormLayout *formLayout_;
// Shared settings object.
QSharedPointer<UserSettings> settings_;
Toggle *trayToggle_;
Toggle *startInTrayToggle_;
Toggle *groupViewToggle_;
Toggle *timelineButtonsToggle_;
Toggle *typingNotifications_;
Toggle *messageHoverHighlight_;
Toggle *enlargeEmojiOnlyMessages_;
Toggle *sortByImportance_;
Toggle *readReceipts_;
Toggle *markdown_;
Toggle *animateImagesOnHover_;
Toggle *desktopNotifications_;
Toggle *alertOnNotification_;
Toggle *avatarCircles_;
Toggle *useIdenticon_;
Toggle *useStunServer_;
Toggle *decryptSidebar_;
Toggle *privacyScreen_;
QSpinBox *privacyScreenTimeout_;
Toggle *shareKeysWithTrustedUsers_;
Toggle *onlyShareKeysWithVerifiedUsers_;
Toggle *useOnlineKeyBackup_;
Toggle *mobileMode_;
QLabel *deviceFingerprintValue_;
QLabel *deviceIdValue_;
QLabel *backupSecretCached;
QLabel *masterSecretCached;
QLabel *selfSigningSecretCached;
QLabel *userSigningSecretCached;
QComboBox *themeCombo_;
QComboBox *scaleFactorCombo_;
QComboBox *fontSizeCombo_;
QFontComboBox *fontSelectionCombo_;
QComboBox *emojiFontSelectionCombo_;
QComboBox *ringtoneCombo_;
QComboBox *microphoneCombo_;
QComboBox *cameraCombo_;
QComboBox *cameraResolutionCombo_;
QComboBox *cameraFrameRateCombo_;
QSpinBox *timelineMaxWidthSpin_;
int sideMargin_ = 0;
Q_INVOKABLE void importSessionKeys();
Q_INVOKABLE void exportSessionKeys();
Q_INVOKABLE void requestCrossSigningSecrets();
Q_INVOKABLE void downloadCrossSigningSecrets();
};

View file

@ -394,7 +394,7 @@ utils::humanReadableFingerprint(const QString &ed25519)
QString fingerprint;
for (int i = 0; i < ed25519.length(); i = i + 4) {
fingerprint.append(QStringView(ed25519).mid(i, 4));
if (i > 0 && i % 16 == 12)
if (i > 0 && i == 20)
fingerprint.append('\n');
else if (i < ed25519.length())
fingerprint.append(' ');

View file

@ -259,6 +259,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"im.nheko", 1, 0, "Nheko", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new Nheko();
});
qmlRegisterSingletonType<UserSettingsModel>(
"im.nheko", 1, 0, "UserSettingsModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new UserSettingsModel();
});
qmlRegisterSingletonInstance("im.nheko", 1, 0, "VerificationManager", verificationManager_);
qmlRegisterSingletonInstance("im.nheko", 1, 0, "Presence", presenceEmitter);
qmlRegisterSingletonType<SelfVerificationStatus>(