summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/UserSettingsPage.cpp51
-rw-r--r--src/UserSettingsPage.h3
-rw-r--r--src/Utils.cpp15
-rw-r--r--src/Utils.h9
4 files changed, 77 insertions, 1 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp
index b41de3a9..3b14088e 100644
--- a/src/UserSettingsPage.cpp
+++ b/src/UserSettingsPage.cpp
@@ -24,6 +24,8 @@
 #include <QSettings>
 
 #include "Config.h"
+#include "MatrixClient.h"
+#include "Olm.h"
 #include "UserSettingsPage.h"
 #include "Utils.h"
 #include "ui/FlatButton.h"
@@ -229,7 +231,46 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
         themeOptionLayout_->addWidget(themeLabel_);
         themeOptionLayout_->addWidget(themeCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
 
+        auto encryptionLayout_ = new QVBoxLayout;
+        encryptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
+
+        QFont monospaceFont = QFont(font);
+        monospaceFont.setFamily("Courier New");
+        monospaceFont.setStyleHint(QFont::Courier);
+        monospaceFont.setPointSizeF(monospaceFont.pointSizeF() * 0.9);
+
+        auto deviceIdWidget = new QHBoxLayout;
+        deviceIdWidget->setContentsMargins(0, OptionMargin, 0, OptionMargin);
+
+        auto deviceIdLabel = new QLabel(tr("Device ID"), this);
+        deviceIdLabel->setFont(font);
+        deviceIdValue_ = new QLabel();
+        deviceIdValue_->setTextInteractionFlags(Qt::TextSelectableByMouse);
+        deviceIdValue_->setFont(monospaceFont);
+        deviceIdWidget->addWidget(deviceIdLabel, 1);
+        deviceIdWidget->addWidget(deviceIdValue_);
+
+        auto deviceFingerprintWidget = new QHBoxLayout;
+        deviceFingerprintWidget->setContentsMargins(0, OptionMargin, 0, OptionMargin);
+
+        auto deviceFingerprintLabel = new QLabel(tr("Device Fingerprint"), this);
+        deviceFingerprintLabel->setFont(font);
+        deviceFingerprintValue_ = new QLabel();
+        deviceFingerprintValue_->setTextInteractionFlags(Qt::TextSelectableByMouse);
+        deviceFingerprintValue_->setFont(monospaceFont);
+        deviceFingerprintWidget->addWidget(deviceFingerprintLabel, 1);
+        deviceFingerprintWidget->addWidget(deviceFingerprintValue_);
+
+        encryptionLayout_->addLayout(deviceIdWidget);
+        encryptionLayout_->addLayout(deviceFingerprintWidget);
+
         font.setWeight(65);
+
+        auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this);
+        encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
+        encryptionLabel_->setFont(font);
+        // encryptionLabel_->setContentsMargins(0, 50, 0, 0);
+
         auto general_ = new QLabel(tr("GENERAL"), this);
         general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
         general_->setFont(font);
@@ -263,6 +304,12 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
 
         mainLayout_->addLayout(themeOptionLayout_);
         mainLayout_->addWidget(new HorizontalLine(this));
+
+        mainLayout_->addSpacing(50);
+
+        mainLayout_->addWidget(encryptionLabel_, 1, Qt::AlignLeft | Qt::AlignBottom);
+        mainLayout_->addWidget(new HorizontalLine(this));
+        mainLayout_->addLayout(encryptionLayout_);
         mainLayout_->addStretch(1);
 
         auto scrollArea_ = new QScrollArea(this);
@@ -343,6 +390,10 @@ UserSettingsPage::showEvent(QShowEvent *)
         typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
         readReceipts_->setState(!settings_->isReadReceiptsEnabled());
         desktopNotifications_->setState(!settings_->hasDesktopNotifications());
+        deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));
+
+        deviceFingerprintValue_->setText(
+          utils::humanReadableFingerprint(olm::client()->identity_keys().ed25519));
 }
 
 void
diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h
index db40e43b..c6aeb300 100644
--- a/src/UserSettingsPage.h
+++ b/src/UserSettingsPage.h
@@ -19,6 +19,7 @@
 
 #include <QComboBox>
 #include <QFrame>
+#include <QLabel>
 #include <QLayout>
 #include <QSharedPointer>
 #include <QWidget>
@@ -151,6 +152,8 @@ private:
         Toggle *typingNotifications_;
         Toggle *readReceipts_;
         Toggle *desktopNotifications_;
+        QLabel *deviceFingerprintValue_;
+        QLabel *deviceIdValue_;
 
         QComboBox *themeCombo_;
         QComboBox *scaleFactorCombo_;
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 944fdcd5..d6fff47e 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -263,3 +263,18 @@ utils::mxcToHttp(const QUrl &url, const QString &server, int port)
           .arg(QString::fromStdString(mxcParts.server))
           .arg(QString::fromStdString(mxcParts.media_id));
 }
+
+QString
+utils::humanReadableFingerprint(const std::string &ed25519)
+{
+        return humanReadableFingerprint(QString::fromStdString(ed25519));
+}
+QString
+utils::humanReadableFingerprint(const QString &ed25519)
+{
+        QStringList fingerprintList;
+        for (int i = 0; i < ed25519.length(); i = i + 4) {
+                fingerprintList << ed25519.mid(i, 4);
+        }
+        return fingerprintList.join(" ");
+}
\ No newline at end of file
diff --git a/src/Utils.h b/src/Utils.h
index 7f544835..faa67faa 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -185,4 +185,11 @@ scaleImageToPixmap(const QImage &img, int size);
 //! Convert a Content Matrix URI to an HTTP link.
 QString
 mxcToHttp(const QUrl &url, const QString &server, int port);
-}
+
+//! Convert a ed25519 fingerprint into a human readable form
+QString
+humanReadableFingerprint(const std::string &ed25519);
+
+QString
+humanReadableFingerprint(const QString &ed25519);
+}
\ No newline at end of file