From ce1a64bc19ffc21e115bdf2587bb053d7a417f3e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 19 Jun 2023 01:38:40 +0200 Subject: Move to automatic type registration --- src/encryption/Olm.h | 3 +++ src/encryption/SelfVerificationStatus.cpp | 5 +++++ src/encryption/SelfVerificationStatus.h | 4 ++++ src/encryption/VerificationManager.cpp | 1 + src/encryption/VerificationManager.h | 27 ++++++++++++++++++++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src/encryption') diff --git a/src/encryption/Olm.h b/src/encryption/Olm.h index f0e51070..726b9590 100644 --- a/src/encryption/Olm.h +++ b/src/encryption/Olm.h @@ -9,10 +9,13 @@ #include #include +#include + #include namespace olm { Q_NAMESPACE +QML_NAMED_ELEMENT(Olm) enum DecryptionErrorCode { diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp index 6fa737d4..d9d3d787 100644 --- a/src/encryption/SelfVerificationStatus.cpp +++ b/src/encryption/SelfVerificationStatus.cpp @@ -29,6 +29,11 @@ SelfVerificationStatus::SelfVerificationStatus(QObject *o) Qt::UniqueConnection); cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()}); }); + + connect(ChatPage::instance(), + &ChatPage::initializeEmptyViews, + this, + &SelfVerificationStatus::invalidate); } void diff --git a/src/encryption/SelfVerificationStatus.h b/src/encryption/SelfVerificationStatus.h index ea790c8b..c65fffd0 100644 --- a/src/encryption/SelfVerificationStatus.h +++ b/src/encryption/SelfVerificationStatus.h @@ -5,11 +5,15 @@ #pragma once #include +#include class SelfVerificationStatus final : public QObject { Q_OBJECT + QML_ELEMENT + QML_SINGLETON + Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(bool hasSSSS READ hasSSSS NOTIFY hasSSSSChanged) diff --git a/src/encryption/VerificationManager.cpp b/src/encryption/VerificationManager.cpp index 802a8177..d1248755 100644 --- a/src/encryption/VerificationManager.cpp +++ b/src/encryption/VerificationManager.cpp @@ -15,6 +15,7 @@ VerificationManager::VerificationManager(TimelineViewManager *o) : QObject(o) , rooms_(o->rooms()) { + instance_ = this; } static bool diff --git a/src/encryption/VerificationManager.h b/src/encryption/VerificationManager.h index 7b32bc98..cdc8af30 100644 --- a/src/encryption/VerificationManager.h +++ b/src/encryption/VerificationManager.h @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -21,8 +22,30 @@ class VerificationManager final : public QObject { Q_OBJECT + QML_ELEMENT + QML_SINGLETON + public: - VerificationManager(TimelineViewManager *o = nullptr); + VerificationManager(TimelineViewManager *o); + + static VerificationManager *create(QQmlEngine *qmlEngine, QJSEngine *) + { + // The instance has to exist before it is used. We cannot replace it. + Q_ASSERT(instance_); + + // The engine has to have the same thread affinity as the singleton. + Q_ASSERT(qmlEngine->thread() == instance_->thread()); + + // There can only be one engine accessing the singleton. + static QJSEngine *s_engine = nullptr; + if (s_engine) + Q_ASSERT(qmlEngine == s_engine); + else + s_engine = qmlEngine; + + QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership); + return instance_; + } Q_INVOKABLE void removeVerificationFlow(DeviceVerificationFlow *flow); void verifyUser(QString userid); @@ -45,4 +68,6 @@ private: QHash> dvList; bool isInitialSync_ = false; RoomlistModel *rooms_; + + inline static VerificationManager *instance_ = nullptr; }; -- cgit 1.5.1