[Telepathy-commits] [telepathy-qt4/master] Make Account::becomeReady() return a PendingReadyAccount instead of a PendingOperation.
George Goldberg
george.goldberg at collabora.co.uk
Thu Jan 29 13:53:01 PST 2009
---
TelepathyQt4/Client/account.cpp | 57 ++++++++++++++++----------------------
TelepathyQt4/Client/account.h | 3 +-
2 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/TelepathyQt4/Client/account.cpp b/TelepathyQt4/Client/account.cpp
index 4bdaae8..3c2cfdc 100644
--- a/TelepathyQt4/Client/account.cpp
+++ b/TelepathyQt4/Client/account.cpp
@@ -30,6 +30,7 @@
#include <TelepathyQt4/Client/AccountManager>
#include <TelepathyQt4/Client/Connection>
#include <TelepathyQt4/Client/ConnectionManager>
+#include <TelepathyQt4/Client/PendingReadyAccount>
#include <TelepathyQt4/Client/PendingVoidMethodCall>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Debug>
@@ -59,11 +60,9 @@ struct Account::Private
Private(Account *parent);
~Private();
- class PendingReady;
-
AccountInterface *baseInterface;
bool ready;
- QList<PendingReady *> pendingOperations;
+ QList<PendingReadyAccount *> pendingOperations;
QQueue<void (Account::*)()> introspectQueue;
QStringList interfaces;
Account::Features features;
@@ -90,23 +89,6 @@ struct Account::Private
Telepathy::SimplePresence requestedPresence;
};
-class Account::Private::PendingReady : public PendingOperation
-{
- // Account is a friend so it can call finished() etc.
- friend class Account;
-
-public:
- PendingReady(Account::Features features, QObject *parent = 0);
-
- Account::Features features;
-};
-
-Account::Private::PendingReady::PendingReady(Account::Features features, QObject *parent)
- : PendingOperation(parent),
- features(features)
-{
-}
-
Account::Private::Private(Account *parent)
: baseInterface(new AccountInterface(parent->dbusConnection(),
parent->busName(), parent->objectPath(), parent)),
@@ -622,16 +604,19 @@ bool Account::isReady(Features features) const
* \return A PendingOperation which will emit PendingOperation::finished
* when this object has finished or failed its initial setup.
*/
-PendingOperation *Account::becomeReady(Features requestedFeatures)
+PendingReadyAccount *Account::becomeReady(Features requestedFeatures)
{
if (isReady(requestedFeatures)) {
- return new PendingSuccess(this);
+ PendingReadyAccount *operation =
+ new PendingReadyAccount(requestedFeatures, this);
+ operation->setFinished();
+ return operation;
}
debug() << "calling becomeReady with requested features:"
<< requestedFeatures;
- Q_FOREACH (Private::PendingReady *operation, mPriv->pendingOperations) {
- if (operation->features == requestedFeatures) {
+ Q_FOREACH (PendingReadyAccount *operation, mPriv->pendingOperations) {
+ if (operation->features() == requestedFeatures) {
debug() << "returning cached pending operation";
return operation;
}
@@ -642,7 +627,10 @@ PendingOperation *Account::becomeReady(Features requestedFeatures)
// supported, just finish silently
if (requestedFeatures == FeatureAvatar &&
mPriv->missingFeatures & FeatureAvatar) {
- return new PendingSuccess(this);
+ PendingReadyAccount *operation =
+ new PendingReadyAccount(requestedFeatures, this);
+ operation->setFinished();
+ return operation;
}
// if we know that avatar is not supported, no need to
@@ -659,9 +647,12 @@ PendingOperation *Account::becomeReady(Features requestedFeatures)
// but we already know that protocol info is not supported, so
// fail directly
if (mPriv->missingFeatures & FeatureProtocolInfo) {
- return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+ PendingReadyAccount *operation =
+ new PendingReadyAccount(requestedFeatures, this);
+ operation->setFinishedWithError(TELEPATHY_ERROR_NOT_IMPLEMENTED,
QString("ProtocolInfo not found for protocol %1 on CM %2")
.arg(mPriv->protocol).arg(mPriv->cmName));
+ return operation;
}
if (!(mPriv->features & FeatureProtocolInfo) &&
@@ -675,8 +666,8 @@ PendingOperation *Account::becomeReady(Features requestedFeatures)
QTimer::singleShot(0, this, SLOT(continueIntrospection()));
debug() << "Creating new pending operation";
- Private::PendingReady *operation =
- new Private::PendingReady(requestedFeatures, this);
+ PendingReadyAccount *operation =
+ new PendingReadyAccount(requestedFeatures, this);
mPriv->pendingOperations.append(operation);
return operation;
}
@@ -972,8 +963,8 @@ void Account::onConnectionManagerReady(PendingOperation *operation)
// signal all pending operations that cares about protocol info that
// it failed, as FeatureProtocolInfo is mandatory
- Q_FOREACH (Private::PendingReady *operation, mPriv->pendingOperations) {
- if (operation->features & FeatureProtocolInfo) {
+ Q_FOREACH (PendingReadyAccount *operation, mPriv->pendingOperations) {
+ if (operation->features() & FeatureProtocolInfo) {
operation->setFinishedWithError(operation->errorName(),
operation->errorMessage());
mPriv->pendingOperations.removeOne(operation);
@@ -1002,10 +993,10 @@ void Account::onRemoved()
void Account::continueIntrospection()
{
if (mPriv->introspectQueue.isEmpty()) {
- Q_FOREACH (Private::PendingReady *operation, mPriv->pendingOperations) {
+ Q_FOREACH (PendingReadyAccount *operation, mPriv->pendingOperations) {
if (mPriv->ready &&
- ((operation->features &
- (mPriv->features | mPriv->missingFeatures)) == operation->features)) {
+ ((operation->features() &
+ (mPriv->features | mPriv->missingFeatures)) == operation->features())) {
operation->setFinished();
}
if (operation->isFinished()) {
diff --git a/TelepathyQt4/Client/account.h b/TelepathyQt4/Client/account.h
index c471f40..119e266 100644
--- a/TelepathyQt4/Client/account.h
+++ b/TelepathyQt4/Client/account.h
@@ -47,6 +47,7 @@ class AccountManager;
class Connection;
class PendingConnection;
class PendingOperation;
+class PendingReadyAccount;
class ProtocolInfo;
class Account : public StatelessDBusProxy,
@@ -127,7 +128,7 @@ public:
bool isReady(Features features = 0) const;
- PendingOperation *becomeReady(Features features = 0);
+ PendingReadyAccount *becomeReady(Features features = 0);
QStringList interfaces() const;
--
1.5.6.5
More information about the telepathy-commits
mailing list