[Telepathy-commits] [telepathy-qt4/master] Port PendingHandles to PendingOperation
Olli Salli
olli.salli at collabora.co.uk
Wed Jan 21 04:42:15 PST 2009
---
TelepathyQt4/cli-pending-handles.cpp | 43 ++++++---------------------
TelepathyQt4/cli-pending-handles.h | 53 +--------------------------------
2 files changed, 11 insertions(+), 85 deletions(-)
diff --git a/TelepathyQt4/cli-pending-handles.cpp b/TelepathyQt4/cli-pending-handles.cpp
index dbdc688..d0326ff 100644
--- a/TelepathyQt4/cli-pending-handles.cpp
+++ b/TelepathyQt4/cli-pending-handles.cpp
@@ -37,12 +37,11 @@ struct PendingHandles::Private
bool isRequest;
QStringList namesRequested;
UIntList handlesToReference;
- QDBusError error;
ReferencedHandles handles;
};
PendingHandles::PendingHandles(Connection* connection, uint handleType, const QStringList& names)
- : QObject(connection), mPriv(new Private)
+ : PendingOperation(connection), mPriv(new Private)
{
mPriv->connection = connection;
mPriv->handleType = handleType;
@@ -51,15 +50,17 @@ PendingHandles::PendingHandles(Connection* connection, uint handleType, const QS
}
PendingHandles::PendingHandles(Connection* connection, uint handleType, const UIntList& handles, bool allHeld)
- : QObject(connection), mPriv(new Private)
+ : PendingOperation(connection), mPriv(new Private)
{
mPriv->connection = connection;
mPriv->handleType = handleType;
mPriv->isRequest = false;
mPriv->handlesToReference = handles;
- if (allHeld)
+ if (allHeld) {
mPriv->handles = ReferencedHandles(connection, handleType, handles);
+ setFinished();
+ }
}
PendingHandles::~PendingHandles()
@@ -97,31 +98,6 @@ const UIntList& PendingHandles::handlesToReference() const
return mPriv->handlesToReference;
}
-bool PendingHandles::isFinished() const
-{
- return mPriv->handles.connection() == connection() || !mPriv->error.message().isEmpty();
-}
-
-bool PendingHandles::isError() const
-{
- return !mPriv->error.message().isEmpty();
-}
-
-const QDBusError& PendingHandles::error() const
-{
- if (isValid())
- warning() << "PendingHandles::error() called when valid";
- else if (!isFinished())
- warning() << "PendingHandles::error() called before finished";
-
- return mPriv->error;
-}
-
-bool PendingHandles::isValid() const
-{
- return isFinished() && !isError();
-}
-
ReferencedHandles PendingHandles::handles() const
{
return mPriv->handles;
@@ -137,9 +113,10 @@ void PendingHandles::onCallFinished(QDBusPendingCallWatcher* watcher)
if (reply.isError()) {
debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
- mPriv->error = reply.error();
+ setFinishedWithError(reply.error());
} else {
mPriv->handles = ReferencedHandles(connection(), handleType(), reply.value());
+ setFinished();
}
} else {
QDBusPendingReply<void> reply;
@@ -148,15 +125,13 @@ void PendingHandles::onCallFinished(QDBusPendingCallWatcher* watcher)
if (reply.isError()) {
debug().nospace() << " Failure: error " << reply.error().name() << ": " << reply.error().message();
- mPriv->error = reply.error();
+ setFinishedWithError(reply.error());
} else {
mPriv->handles = ReferencedHandles(connection(), handleType(), handlesToReference());
+ setFinished();
}
}
- debug() << " Emitting finished()";
- emit finished(this);
-
watcher->deleteLater();
}
diff --git a/TelepathyQt4/cli-pending-handles.h b/TelepathyQt4/cli-pending-handles.h
index 8db253d..04c82b8 100644
--- a/TelepathyQt4/cli-pending-handles.h
+++ b/TelepathyQt4/cli-pending-handles.h
@@ -52,6 +52,7 @@ class PendingHandles;
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Types>
#include <TelepathyQt4/Client/Connection>
+#include <TelepathyQt4/Client/PendingOperation>
#include <TelepathyQt4/Client/ReferencedHandles>
namespace Telepathy
@@ -69,7 +70,7 @@ namespace Client
* only ways to get one are to use Connection::requestHandles() or
* Connection::referenceHandles().
*/
-class PendingHandles : public QObject
+class PendingHandles : public PendingOperation
{
Q_OBJECT
@@ -132,45 +133,6 @@ public:
const UIntList& handlesToReference() const;
/**
- * Returns whether or not the operation has finished processing.
- *
- * \sa finished()
- *
- * \return If the operation is finished.
- */
- bool isFinished() const;
-
- /**
- * Returns whether or not the operation resulted in an error. If the
- * operation has not yet finished processing (isFinished() returns
- * <code>false</code>), this cannot yet be known, and <code>false</code>
- * will be returned.
- *
- * \return <code>true</code> iff the operation has finished processing AND
- * has resulted in an error.
- */
- bool isError() const;
-
- /**
- * Returns the error which the operation resulted in, if any. If isError()
- * returns <code>false</code>, the operation has not (at least yet) resulted
- * in an error, and an undefined value will be returned.
- *
- * \return The error as a QDBusError.
- */
- const QDBusError& error() const;
-
- /**
- * Returns whether or not the operation completed successfully. If the operation
- * has not yet finished processing (isFinished() returns <code>false</code>),
- * this cannot yet be known, and <code>false</code> will be returned.
- *
- * \return <code>true</code> iff the operation has finished processing AND has
- * completed successfully.
- */
- bool isValid() const;
-
- /**
* Returns the now-referenced handles resulting from the operation. If the
* operation has not (yet) finished successfully (isFinished() returns
* <code>false</code>), the return value is undefined.
@@ -184,17 +146,6 @@ public:
*/
ReferencedHandles handles() const;
-Q_SIGNALS:
- /**
- * Emitted when the operation finishes processing. isFinished() will then
- * start returning <code>true</code> and isError(), error(), isValid() and
- * handles() will become meaningful to use.
- *
- * \param pendingHandles The PendingHandles object for which the operation has
- * finished.
- */
- void finished(Telepathy::Client::PendingHandles* pendingHandles);
-
private Q_SLOTS:
void onCallFinished(QDBusPendingCallWatcher* watcher);
--
1.5.6.5
More information about the Telepathy-commits
mailing list