From 769911c613cbae55a3630a6056961582b834aea3 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 12 Mar 2022 22:58:06 +0100 Subject: Stanza::Error: Add optional overloads for Condition/Type Currently Condition(-1)/Type(-1) is used for an unset error. This should be deprecated and replaced by the new optional functions. --- src/base/QXmppStanza.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/base/QXmppStanza.cpp') diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index 848693da..8dabb07a 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2009 Manjeet Dahiya // SPDX-FileCopyrightText: 2010 Jeremy Lainé // SPDX-FileCopyrightText: 2015 Georg Rudoy <0xd34df00d@gmail.com> +// SPDX-FileCopyrightText: 2019 Linus Jahn // SPDX-FileCopyrightText: 2022 Melvin Keskin // // SPDX-License-Identifier: LGPL-2.1-or-later @@ -388,11 +389,27 @@ void QXmppStanza::Error::setCode(int code) /// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect /// can be used in combination with redirectUri(). /// +/// \warning Due to compatibility this returns \c Condition(-1) when no +/// condition is set. When possible you should use conditionOpt(). +/// QXmppStanza::Error::Condition QXmppStanza::Error::condition() const { return d->condition.value_or(QXmppStanza::Error::Condition(-1)); } +/// +/// Returns the error condition. +/// +/// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect +/// can be used in combination with redirectUri(). +/// +/// \since QXmpp 1.5 +/// +auto QXmppStanza::Error::conditionOpt() const -> std::optional +{ + return d->condition; +} + /// /// Sets the error condition. /// @@ -408,14 +425,40 @@ void QXmppStanza::Error::setCondition(QXmppStanza::Error::Condition cond) d->condition = cond; } +/// +/// Sets the error condition. +/// +/// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect +/// can be used in combination with setRedirectUri(). +/// +/// \since QXmpp 1.5 +/// +void QXmppStanza::Error::setCondition(std::optional cond) +{ + d->condition = cond; +} + /// /// Returns the type of the error. /// +/// \warning Due to compatibility this returns \c Type(-1) when no type is set. +/// When possible you should use typeOpt(). +/// QXmppStanza::Error::Type QXmppStanza::Error::type() const { return d->type.value_or(QXmppStanza::Error::Type(-1)); } +/// +/// Returns the type of the error. +/// +/// \since QXmpp 1.5 +/// +std::optional QXmppStanza::Error::typeOpt() const +{ + return d->type; +} + /// /// Returns the optional JID of the creator of the error. /// @@ -454,6 +497,16 @@ void QXmppStanza::Error::setType(QXmppStanza::Error::Type type) d->type = type; } +/// +/// Sets the type of the error. +/// +/// \since QXmpp 1.5 +/// +void QXmppStanza::Error::setType(std::optional type) +{ + d->type = type; +} + /// /// Returns the optionally included redirection URI for the error conditions /// QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect. -- cgit v1.2.3