diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-02-06 11:49:26 +0100 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-02-06 12:17:01 +0100 |
| commit | fd0e02233f925cff699c08b135887a09bdc16e5c (patch) | |
| tree | 5eeb54d9c5824d372980a3f50571fbb00d03610c /src/client | |
| parent | dee612210008007a9c011b96081605f6e692287d (diff) | |
| download | qxmpp-fd0e02233f925cff699c08b135887a09bdc16e5c.tar.gz | |
QXmppRegistrationManager: Handle result of deleteAccount()
This adds two signals to make the result easily available to the user.
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/QXmppRegistrationManager.cpp | 34 | ||||
| -rw-r--r-- | src/client/QXmppRegistrationManager.h | 30 |
2 files changed, 48 insertions, 16 deletions
diff --git a/src/client/QXmppRegistrationManager.cpp b/src/client/QXmppRegistrationManager.cpp index 48cd3d47..4f8e97a6 100644 --- a/src/client/QXmppRegistrationManager.cpp +++ b/src/client/QXmppRegistrationManager.cpp @@ -47,8 +47,9 @@ public: QString changePasswordIqId; QString newPassword; - QString registrationIqId; + QString deleteAccountIqIq; + QString registrationIqId; QXmppRegisterIq registrationFormToSend; }; @@ -98,16 +99,15 @@ void QXmppRegistrationManager::changePassword(const QString &newPassword) /// /// Cancels an existing registration on the server. /// -/// \returns The ID of the sent IQ, if it was sent successfully. A null string -/// is returned otherwise. +/// \sa accountDeleted() +/// \sa accountDeletionFailed() /// -QString QXmppRegistrationManager::deleteAccount() +void QXmppRegistrationManager::deleteAccount() { auto iq = QXmppRegisterIq::createUnregistrationRequest(); + d->deleteAccountIqIq = iq.id(); - if (client()->sendPacket(iq)) - return iq.id(); - return {}; + client()->sendPacket(iq); } bool QXmppRegistrationManager::supportedByServer() const @@ -258,6 +258,26 @@ bool QXmppRegistrationManager::handleStanza(const QDomElement &stanza) d->changePasswordIqId.clear(); d->newPassword.clear(); return true; + } else if (!id.isEmpty() && id == d->deleteAccountIqIq) { + QXmppIq iq; + iq.parse(stanza); + + switch (iq.type()) { + case QXmppIq::Result: + info(QStringLiteral("Account deleted successfully.")); + emit accountDeleted(); + client()->disconnectFromServer(); + break; + case QXmppIq::Error: + warning(QStringLiteral("Failed to delete account: ").append(iq.error().text())); + emit accountDeletionFailed(iq.error()); + break; + default: + break; // should never occur + } + + d->deleteAccountIqIq.clear(); + return true; } else if (QXmppRegisterIq::isRegisterIq(stanza)) { QXmppRegisterIq iq; iq.parse(stanza); diff --git a/src/client/QXmppRegistrationManager.h b/src/client/QXmppRegistrationManager.h index eba49d53..712fc9b6 100644 --- a/src/client/QXmppRegistrationManager.h +++ b/src/client/QXmppRegistrationManager.h @@ -92,17 +92,19 @@ class QXmppRegistrationManagerPrivate; /// <h3>Unregistration with the server</h3> /// /// If you want to delete your account on the server, you can do that using -/// deleteAccount(). The result of the IQ request is not handled. If you want -/// to do that manually, you can use the returned ID. +/// deleteAccount(). When the result is received either accountDeleted() or +/// accountDeletionFailed() is emitted. In case it was successful the manager +/// automatically disconnects from the client. /// /// \code /// auto *registrationManager = client->findExtension<QXmppRegistrationManager>(); -/// QString deleteId = registrationManager->deleteAccount(); -/// if (deleteId.isEmpty()) { -/// // stanza could not be sent -/// } else { -/// // stanza was sent, you can handle the result using deleteId -/// } +/// connect(registrationManager, &QXmppRegistrationManager::accountDeleted, [=]() { +/// qDebug() << "Account deleted successfull, the client is disconnecting now"; +/// }); +/// connect(registrationManager, &QXmppRegistrationManager::accountDeletionFailed, [=](QXmppStanza::Error error) { +/// qDebug() << "Couldn't delete account:" << error.text(); +/// }); +/// registrationManager->deleteAccount(); /// \endcode /// /// <h3 id="register-account">Registering with a server</h3> @@ -251,7 +253,7 @@ public: QStringList discoveryFeatures() const override; void changePassword(const QString &newPassword); - QString deleteAccount(); + void deleteAccount(); // documentation needs to be here, see https://stackoverflow.com/questions/49192523/ /// @@ -323,6 +325,16 @@ signals: void registrationFormReceived(const QXmppRegisterIq &iq); /// + /// Emitted, when the account was deleted successfully. + /// + void accountDeleted(); + + /// + /// Emitted, when the account could not be deleted. + /// + void accountDeletionFailed(QXmppStanza::Error error); + + /// /// Emitted, when the registration with a service completed successfully. /// /// To connect with the account you still need to set the correct |
