From b17284ee7d674416e0d11f1699f73fcc606262d4 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Tue, 16 Aug 2022 21:00:15 +0200 Subject: Introduce QXmppTask & QXmppPromise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #502. Co-authored-by: Jonah BrĂ¼chert --- src/client/QXmppTrustManager.cpp | 59 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'src/client/QXmppTrustManager.cpp') diff --git a/src/client/QXmppTrustManager.cpp b/src/client/QXmppTrustManager.cpp index a5031a52..2772a4a5 100644 --- a/src/client/QXmppTrustManager.cpp +++ b/src/client/QXmppTrustManager.cpp @@ -5,6 +5,8 @@ #include "QXmppTrustManager.h" #include "QXmppFutureUtils_p.h" +#include "QXmppPromise.h" +#include "QXmppTask.h" #include "QXmppTrustStorage.h" using namespace QXmpp; @@ -40,7 +42,7 @@ QXmppTrustManager::~QXmppTrustManager() = default; /// \param encryption encryption protocol namespace /// \param securityPolicy security policy being applied /// -QFuture QXmppTrustManager::setSecurityPolicy(const QString &encryption, TrustSecurityPolicy securityPolicy) +QXmppTask QXmppTrustManager::setSecurityPolicy(const QString &encryption, TrustSecurityPolicy securityPolicy) { return m_trustStorage->setSecurityPolicy(encryption, securityPolicy); } @@ -50,7 +52,7 @@ QFuture QXmppTrustManager::setSecurityPolicy(const QString &encryption, Tr /// /// \param encryption encryption protocol namespace /// -QFuture QXmppTrustManager::resetSecurityPolicy(const QString &encryption) +QXmppTask QXmppTrustManager::resetSecurityPolicy(const QString &encryption) { return m_trustStorage->resetSecurityPolicy(encryption); } @@ -62,7 +64,7 @@ QFuture QXmppTrustManager::resetSecurityPolicy(const QString &encryption) /// /// \return the set security policy /// -QFuture QXmppTrustManager::securityPolicy(const QString &encryption) +QXmppTask QXmppTrustManager::securityPolicy(const QString &encryption) { return m_trustStorage->securityPolicy(encryption); } @@ -74,7 +76,7 @@ QFuture QXmppTrustManager::securityPolicy(const QString &en /// \param encryption encryption protocol namespace /// \param keyId ID of the key /// -QFuture QXmppTrustManager::setOwnKey(const QString &encryption, const QByteArray &keyId) +QXmppTask QXmppTrustManager::setOwnKey(const QString &encryption, const QByteArray &keyId) { return m_trustStorage->setOwnKey(encryption, keyId); } @@ -85,7 +87,7 @@ QFuture QXmppTrustManager::setOwnKey(const QString &encryption, const QByt /// /// \param encryption encryption protocol namespace /// -QFuture QXmppTrustManager::resetOwnKey(const QString &encryption) +QXmppTask QXmppTrustManager::resetOwnKey(const QString &encryption) { return m_trustStorage->resetOwnKey(encryption); } @@ -98,7 +100,7 @@ QFuture QXmppTrustManager::resetOwnKey(const QString &encryption) /// /// \return the ID of the own key /// -QFuture QXmppTrustManager::ownKey(const QString &encryption) +QXmppTask QXmppTrustManager::ownKey(const QString &encryption) { return m_trustStorage->ownKey(encryption); } @@ -111,7 +113,7 @@ QFuture QXmppTrustManager::ownKey(const QString &encryption) /// \param keyIds IDs of the keys /// \param trustLevel trust level of the keys /// -QFuture QXmppTrustManager::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel) +QXmppTask QXmppTrustManager::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, TrustLevel trustLevel) { return m_trustStorage->addKeys(encryption, keyOwnerJid, keyIds, trustLevel); } @@ -122,7 +124,7 @@ QFuture QXmppTrustManager::addKeys(const QString &encryption, const QStrin /// \param encryption encryption protocol namespace /// \param keyIds IDs of the keys /// -QFuture QXmppTrustManager::removeKeys(const QString &encryption, const QList &keyIds) +QXmppTask QXmppTrustManager::removeKeys(const QString &encryption, const QList &keyIds) { return m_trustStorage->removeKeys(encryption, keyIds); } @@ -133,7 +135,7 @@ QFuture QXmppTrustManager::removeKeys(const QString &encryption, const QLi /// \param encryption encryption protocol namespace /// \param keyOwnerJid key owner's bare JID /// -QFuture QXmppTrustManager::removeKeys(const QString &encryption, const QString &keyOwnerJid) +QXmppTask QXmppTrustManager::removeKeys(const QString &encryption, const QString &keyOwnerJid) { return m_trustStorage->removeKeys(encryption, keyOwnerJid); } @@ -143,7 +145,7 @@ QFuture QXmppTrustManager::removeKeys(const QString &encryption, const QSt /// /// \param encryption encryption protocol namespace /// -QFuture QXmppTrustManager::removeKeys(const QString &encryption) +QXmppTask QXmppTrustManager::removeKeys(const QString &encryption) { return m_trustStorage->removeKeys(encryption); } @@ -159,7 +161,7 @@ QFuture QXmppTrustManager::removeKeys(const QString &encryption) /// /// \return the key owner JIDs mapped to their keys with specific trust levels /// -QFuture>> QXmppTrustManager::keys(const QString &encryption, QXmpp::TrustLevels trustLevels) +QXmppTask>> QXmppTrustManager::keys(const QString &encryption, QXmpp::TrustLevels trustLevels) { return m_trustStorage->keys(encryption, trustLevels); } @@ -177,7 +179,7 @@ QFuture>> QXmppTrustMan /// /// \return the key IDs mapped to their trust levels for specific key owners /// -QFuture>> QXmppTrustManager::keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels) +QXmppTask>> QXmppTrustManager::keys(const QString &encryption, const QList &keyOwnerJids, QXmpp::TrustLevels trustLevels) { return m_trustStorage->keys(encryption, keyOwnerJids, trustLevels); } @@ -192,7 +194,7 @@ QFuture>> QXmppTrustManager: /// /// \return whether a key of the key owner with a passed trust level is stored /// -QFuture QXmppTrustManager::hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) +QXmppTask QXmppTrustManager::hasKey(const QString &encryption, const QString &keyOwnerJid, TrustLevels trustLevels) { return m_trustStorage->hasKey(encryption, keyOwnerJid, trustLevels); } @@ -206,17 +208,17 @@ QFuture QXmppTrustManager::hasKey(const QString &encryption, const QString /// \param keyIds key owners' bare JIDs mapped to the IDs of their keys /// \param trustLevel trust level being set /// -QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) +QXmppTask QXmppTrustManager::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) { - QFutureInterface interface(QFutureInterfaceBase::Started); + QXmppPromise promise; auto future = m_trustStorage->setTrustLevel(encryption, keyIds, trustLevel); - await(future, this, [=](QHash> modifiedKeys) mutable { + future.then(this, [=](QHash> modifiedKeys) mutable { Q_EMIT trustLevelsChanged(modifiedKeys); - interface.reportFinished(); + promise.finish(); }); - return interface.future(); + return promise.task(); } /// @@ -227,17 +229,16 @@ QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const /// \param oldTrustLevel trust level being changed /// \param newTrustLevel trust level being set /// -QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) +QXmppTask QXmppTrustManager::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) { - QFutureInterface interface(QFutureInterfaceBase::Started); + QXmppPromise promise; + m_trustStorage->setTrustLevel(encryption, keyOwnerJids, oldTrustLevel, newTrustLevel) + .then(this, [=](QHash> modifiedKeys) mutable { + Q_EMIT trustLevelsChanged(modifiedKeys); + promise.finish(); + }); - auto future = m_trustStorage->setTrustLevel(encryption, keyOwnerJids, oldTrustLevel, newTrustLevel); - await(future, this, [=](QHash> modifiedKeys) mutable { - Q_EMIT trustLevelsChanged(modifiedKeys); - interface.reportFinished(); - }); - - return interface.future(); + return promise.task(); } /// @@ -251,7 +252,7 @@ QFuture QXmppTrustManager::setTrustLevel(const QString &encryption, const /// /// \return the key's trust level /// -QFuture QXmppTrustManager::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) +QXmppTask QXmppTrustManager::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) { return m_trustStorage->trustLevel(encryption, keyOwnerJid, keyId); } @@ -261,7 +262,7 @@ QFuture QXmppTrustManager::trustLevel(const QString &encryption, con /// /// \param encryption encryption protocol namespace /// -QFuture QXmppTrustManager::resetAll(const QString &encryption) +QXmppTask QXmppTrustManager::resetAll(const QString &encryption) { return m_trustStorage->resetAll(encryption); } -- cgit v1.2.3