[Telepathy-commits] [telepathy-qt4/master] Remove the self presence bits from Connection in favor of using selfContact()->presence*

Olli Salli olli.salli at collabora.co.uk
Thu Feb 5 00:30:18 PST 2009


---
 TelepathyQt4/Client/connection.cpp |  175 ++++++------------------------------
 TelepathyQt4/Client/connection.h   |    6 +-
 tests/dbus/conn-basics.cpp         |   17 +---
 tests/pinocchio/conn-basics.cpp    |    6 +-
 4 files changed, 35 insertions(+), 169 deletions(-)

diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index dbd8af6..13e2758 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -119,15 +119,12 @@ struct Connection::Private
     void introspectContacts();
     void introspectSimplePresence();
     void introspectSelfContact();
-    void introspectSelfPresence();
     void introspectSelfHandle();
 
     void changeReadiness(Readiness newReadiness);
 
     void updatePendingOperations();
 
-    void changeSelfPresence(const Telepathy::SimplePresence &presence);
-
     struct HandleContext;
     class PendingReady;
 
@@ -164,7 +161,6 @@ struct Connection::Private
     bool haveInitialStatus;
     SimpleStatusSpecMap simplePresenceStatuses;
     QSharedPointer<Contact> selfContact;
-    SimplePresence selfPresence;
     QStringList contactAttributeInterfaces;
 
     uint selfHandle;
@@ -239,7 +235,6 @@ Connection::Private::Private(Connection *parent)
       handleContext(0),
       contactManager(new ContactManager(parent))
 {
-    selfPresence.type = Telepathy::ConnectionPresenceTypeUnknown;
 }
 
 Connection::Private::~Private()
@@ -381,28 +376,6 @@ void Connection::Private::introspectSelfContact()
             SLOT(gotSelfContact(Telepathy::Client::PendingOperation *)));
 }
 
-void Connection::Private::introspectSelfPresence()
-{
-    if (!simplePresence) {
-        simplePresence = parent->simplePresenceInterface();
-        Q_ASSERT(simplePresence != 0);
-    }
-
-    parent->connect(simplePresence,
-                    SIGNAL(PresencesChanged(const Telepathy::SimpleContactPresences&)),
-                    SLOT(onPresenceChanged(const Telepathy::SimpleContactPresences&)));
-
-    debug() << "Getting self presence status";
-    UIntList handles;
-    handles << selfHandle;
-    QDBusPendingCall call = simplePresence->GetPresences(handles);
-    QDBusPendingCallWatcher *watcher =
-        new QDBusPendingCallWatcher(call, parent);
-    parent->connect(watcher,
-                    SIGNAL(finished(QDBusPendingCallWatcher *)),
-                    SLOT(gotSelfPresence(QDBusPendingCallWatcher *)));
-}
-
 void Connection::Private::introspectSelfHandle()
 {
     parent->connect(baseInterface,
@@ -471,17 +444,6 @@ void Connection::Private::updatePendingOperations()
     }
 }
 
-void Connection::Private::changeSelfPresence(const Telepathy::SimplePresence &presence)
-{
-    if (presence.type == selfPresence.type &&
-        presence.status == selfPresence.status &&
-        presence.statusMessage == selfPresence.statusMessage) {
-        return;
-    }
-    selfPresence = presence;
-    parent->emit selfPresenceChanged(presence);
-}
-
 Connection::PendingConnect::PendingConnect(Connection *parent, Connection::Features features)
     : PendingOperation(parent),
       features(features)
@@ -681,15 +643,15 @@ uint Connection::selfHandle() const
  */
 SimpleStatusSpecMap Connection::allowedPresenceStatuses() const
 {
-    if (mPriv->missingFeatures & FeatureSelfPresence) {
+    if (mPriv->missingFeatures & FeatureSimplePresence) {
         warning() << "Trying to retrieve simple presence from connection, but "
                      "simple presence is not supported";
     }
-    else if (!(mPriv->features & FeatureSelfPresence)) {
+    else if (!(mPriv->features & FeatureSimplePresence)) {
         warning() << "Trying to retrieve simple presence from connection without "
-                     "calling Connection::becomeReady(FeatureSelfPresence)";
+                     "calling Connection::becomeReady(FeatureSimplePresence)";
     }
-    else if (mPriv->pendingFeatures & FeatureSelfPresence) {
+    else if (mPriv->pendingFeatures & FeatureSimplePresence) {
         warning() << "Trying to retrieve simple presence from connection, but "
                      "simple presence is still being retrieved";
     }
@@ -725,42 +687,6 @@ PendingOperation *Connection::setSelfPresence(const QString &status,
             simplePresenceInterface()->SetPresence(status, statusMessage));
 }
 
-/**
- * Get the self presence status.
- *
- * Note that in order for this method to work properly,
- * Connection::becomeReady(FeatureSelfPresence) needs to be called, otherwise
- * ConnectionPresenceTypeUnknown will be returned.
- *
- * When Connection::becomeReady(FeatureSelfPresence) is called, if the
- * connection is not yet in the status StatusConnected, the presence will
- * automatically change to ConnectionPresenceTypeOffline and if the connection
- * is already connected it will be set to ConnectionPresenceTypeAvailable.
- * The status will then be correctly signalled with selfStatusChanged signal.
- *
- * \param status The desired status.
- * \param statusMessage The desired status message.
- * \return A PendingOperation which will emit PendingOperation::finished
- *         when the call has finished.
- */
-Telepathy::SimplePresence Connection::selfPresence() const
-{
-    if (mPriv->missingFeatures & FeatureSelfPresence) {
-        warning() << "Trying to retrieve self simple presence from connection, but "
-                     "simple presence is not supported";
-    }
-    else if (!(mPriv->features & FeatureSelfPresence)) {
-        warning() << "Trying to retrieve self simple presence from connection without "
-                     "calling Connection::becomeReady(FeatureSelfPresence)";
-    }
-    else if (mPriv->pendingFeatures & FeatureSelfPresence) {
-        warning() << "Trying to retrieve self simple presence from connection, but "
-                     "simple presence is still being retrieved";
-    }
-
-    return mPriv->selfPresence;
-}
-
 QSharedPointer<Contact> Connection::selfContact() const
 {
     if (!isReady()) {
@@ -1020,9 +946,9 @@ void Connection::gotInterfaces(QDBusPendingCallWatcher *watcher)
             mPriv->ready = true;
         }
 
-        // if FeatureSelfPresence was requested and the interface exists and
+        // if FeatureSimplePresence was requested and the interface exists and
         // the introspect func is not already enqueued, enqueue it.
-        if (mPriv->pendingFeatures & FeatureSelfPresence &&
+        if (mPriv->pendingFeatures & FeatureSimplePresence &&
             mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE) &&
             !mPriv->introspectQueue.contains(&Private::introspectSimplePresence)) {
             mPriv->introspectQueue.enqueue(&Private::introspectSimplePresence);
@@ -1085,18 +1011,18 @@ void Connection::gotSimpleStatuses(QDBusPendingCallWatcher *watcher)
 {
     QDBusPendingReply<QDBusVariant> reply = *watcher;
 
-    mPriv->pendingFeatures &= ~FeatureSelfPresence;
+    mPriv->pendingFeatures &= ~FeatureSimplePresence;
 
     if (!reply.isError()) {
-        mPriv->features |= FeatureSelfPresence;
-        debug() << "Adding FeatureSelfPresence to features";
+        mPriv->features |= FeatureSimplePresence;
+        debug() << "Adding FeatureSimplePresence to features";
 
         mPriv->simplePresenceStatuses = qdbus_cast<SimpleStatusSpecMap>(reply.value().variant());
         debug() << "Got" << mPriv->simplePresenceStatuses.size() << "simple presence statuses";
     }
     else {
-        mPriv->missingFeatures |= FeatureSelfPresence;
-        debug() << "Adding FeatureSelfPresence to missing features";
+        mPriv->missingFeatures |= FeatureSimplePresence;
+        debug() << "Adding FeatureSimplePresence to missing features";
 
         warning().nospace() << "Getting simple presence statuses failed with " <<
             reply.error().name() << ":" << reply.error().message();
@@ -1107,24 +1033,6 @@ void Connection::gotSimpleStatuses(QDBusPendingCallWatcher *watcher)
     watcher->deleteLater();
 }
 
-void Connection::gotSelfPresence(QDBusPendingCallWatcher *watcher)
-{
-    QDBusPendingReply<Telepathy::SimpleContactPresences> reply = *watcher;
-
-    if (!reply.isError()) {
-        mPriv->changeSelfPresence(reply.value()[mPriv->selfHandle]);
-        debug() << "Got self presence:" << mPriv->selfPresence.type;
-    }
-    else {
-        warning().nospace() << "Getting self presence status failed with " <<
-            reply.error().name() << ":" << reply.error().message();
-    }
-
-    continueIntrospection();
-
-    watcher->deleteLater();
-}
-
 void Connection::gotSelfHandle(QDBusPendingCallWatcher *watcher)
 {
     QDBusPendingReply<uint> reply = *watcher;
@@ -1425,52 +1333,32 @@ PendingOperation *Connection::becomeReady(Features requestedFeatures)
         }
     }
 
-    if (requestedFeatures & FeatureSelfPresence) {
+    if (requestedFeatures & FeatureSimplePresence) {
         // as the feature is optional, if it's know to not be supported,
         // just finish silently
-        if (requestedFeatures == FeatureSelfPresence &&
-            mPriv->missingFeatures & FeatureSelfPresence) {
+        if (requestedFeatures == FeatureSimplePresence &&
+            mPriv->missingFeatures & FeatureSimplePresence) {
             return new PendingSuccess(this);
         }
 
         // if we already have the interface simple presence enqueue the call to
         // introspect simple presence, otherwise it will be enqueued when/if the
         // interface is available
-        if (!(mPriv->features & FeatureSelfPresence) &&
-            !(mPriv->pendingFeatures & FeatureSelfPresence) &&
-            !(mPriv->missingFeatures & FeatureSelfPresence) &&
+        if (!(mPriv->features & FeatureSimplePresence) &&
+            !(mPriv->pendingFeatures & FeatureSimplePresence) &&
+            !(mPriv->missingFeatures & FeatureSimplePresence) &&
             mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE)) {
             mPriv->introspectQueue.enqueue(&Private::introspectSimplePresence);
 
-            // we are already connected, so we at least enqueued the call to
-            // getSelfHandle and we can enqueue the call to getSelfPresence
-            if (mPriv->readiness == Private::ReadinessFull) {
-                // we stiff don't have our own presence but we are online
-                // so set selfPresence to available
-                SimplePresence presence = { Telepathy::ConnectionPresenceTypeAvailable, };
-                mPriv->changeSelfPresence(presence);
-                mPriv->introspectQueue.enqueue(&Private::introspectSelfPresence);
-            }
-            else {
-                // we still don't have our own presence but as the user
-                // requested for FeatureSelfPresence, change our presence to
-                // offline
-                SimplePresence presence = { Telepathy::ConnectionPresenceTypeOffline, QLatin1String("offline"), };
-                mPriv->changeSelfPresence(presence);
-            }
-
+            // FIXME: Is not particularly good... this might introspect something completely
+            // unrelated (the head of the queue) at the wrong time
             QTimer::singleShot(0, this, SLOT(continueIntrospection()));
-        }
-        else {
+        } else {
             if (mPriv->readiness == Private::ReadinessFull) {
                 // we don't support simple presence but we are online, so
-                // set selfPresence to available as we are connected
-                SimplePresence presence = { Telepathy::ConnectionPresenceTypeAvailable, QLatin1String("available"), };
-                mPriv->changeSelfPresence(presence);
-
                 // we should have all interfaces now, so if simple presence is not
                 // present, add it to missing features.
-                mPriv->missingFeatures |= FeatureSelfPresence;
+                mPriv->missingFeatures |= FeatureSimplePresence;
             }
         }
     }
@@ -1702,16 +1590,16 @@ void Connection::continueIntrospection()
                 // present and we have a feature for it, add the feature to missing
                 // features.
                 if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE)) {
-                    debug() << "removing FeatureSelfPresence from pending features";
-                    mPriv->pendingFeatures &= ~FeatureSelfPresence;
-                    debug() << "adding FeatureSelfPresence to missing features";
-                    mPriv->missingFeatures |= FeatureSelfPresence;
+                    debug() << "removing FeatureSimplePresence from pending features";
+                    mPriv->pendingFeatures &= ~FeatureSimplePresence;
+                    debug() << "adding FeatureSimplePresence to missing features";
+                    mPriv->missingFeatures |= FeatureSimplePresence;
                 }
                 else {
-                    // the user requested for FeatureSelfPresence so, now we are
+                    // the user requested for FeatureSimplePresence so, now we are
                     // able to get it
-                    if (mPriv->pendingFeatures == FeatureSelfPresence) {
-                        mPriv->introspectQueue.enqueue(&Private::introspectSelfPresence);
+                    if (mPriv->pendingFeatures == FeatureSimplePresence) {
+                        mPriv->introspectQueue.enqueue(&Private::introspectSimplePresence);
                     }
                 }
             }
@@ -1724,13 +1612,6 @@ void Connection::continueIntrospection()
     mPriv->updatePendingOperations();
 }
 
-void Connection::onPresenceChanged(const Telepathy::SimpleContactPresences &presences)
-{
-    if (presences.contains(mPriv->selfHandle)) {
-        mPriv->changeSelfPresence(presences.value(mPriv->selfHandle));
-    }
-}
-
 void Connection::onSelfHandleChanged(uint handle)
 {
     mPriv->selfHandle = handle;
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index b96fd3e..80d5845 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -61,7 +61,7 @@ class Connection : public StatefulDBusProxy,
 
 public:
     enum Feature {
-        FeatureSelfPresence = 1,
+        FeatureSimplePresence = 1,
         _Padding = 0xFFFFFFFF
     };
     Q_DECLARE_FLAGS(Features, Feature)
@@ -93,7 +93,6 @@ public:
 
     SimpleStatusSpecMap allowedPresenceStatuses() const;
     PendingOperation *setSelfPresence(const QString &status, const QString &statusMessage);
-    Telepathy::SimplePresence selfPresence() const;
 
     QSharedPointer<Contact> selfContact() const;
 
@@ -188,15 +187,12 @@ private Q_SLOTS:
     void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
     void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
     void gotSelfContact(Telepathy::Client::PendingOperation *);
-    void gotSelfPresence(QDBusPendingCallWatcher *watcher);
     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
 
     void doReleaseSweep(uint type);
 
     void continueIntrospection();
 
-    void onPresenceChanged(const Telepathy::SimpleContactPresences &);
-
     void onSelfHandleChanged(uint);
 
 private:
diff --git a/tests/dbus/conn-basics.cpp b/tests/dbus/conn-basics.cpp
index 3d88546..a1c256e 100644
--- a/tests/dbus/conn-basics.cpp
+++ b/tests/dbus/conn-basics.cpp
@@ -146,25 +146,14 @@ void TestConnBasics::init()
 
 void TestConnBasics::testSimplePresence()
 {
-    QCOMPARE(mConn->isReady(Connection::FeatureSelfPresence), false);
-    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSelfPresence),
+    QCOMPARE(mConn->isReady(Connection::FeatureSimplePresence), false);
+    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSimplePresence),
                     SIGNAL(finished(Telepathy::Client::PendingOperation*)),
                     SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
     QCOMPARE(mLoop->exec(), 0);
-    QCOMPARE(mConn->isReady(Connection::FeatureSelfPresence), true);
-
-    QVERIFY(connect(mConn,
-                    SIGNAL(selfPresenceChanged(const Telepathy::SimplePresence &)),
-                    SLOT(expectPresenceAvailable(const Telepathy::SimplePresence &))));
-    QCOMPARE(mLoop->exec(), 0);
-    QCOMPARE(mConn->selfPresence().type, (uint) Telepathy::ConnectionPresenceTypeAvailable);
-    QCOMPARE(mConn->selfPresence().status, QString("available"));
+    QCOMPARE(mConn->isReady(Connection::FeatureSimplePresence), true);
 
     qDebug() << "mConn->status:" << mConn->status();
-    qDebug() << "mConn->selfPresence "
-                "type:" << mConn->selfPresence().type <<
-                "status:" << mConn->selfPresence().status <<
-                "status message:" << mConn->selfPresence().statusMessage;
 }
 
 void TestConnBasics::cleanup()
diff --git a/tests/pinocchio/conn-basics.cpp b/tests/pinocchio/conn-basics.cpp
index d1043ab..a9cbb27 100644
--- a/tests/pinocchio/conn-basics.cpp
+++ b/tests/pinocchio/conn-basics.cpp
@@ -165,18 +165,18 @@ void TestConnBasics::testConnect()
         QCOMPARE(mConn->status(), (uint) Connection::StatusConnected);
     }
 
-    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSelfPresence),
+    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSimplePresence),
             SIGNAL(finished(Telepathy::Client::PendingOperation*)),
             this,
             SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
     QCOMPARE(mLoop->exec(), 0);
 
-    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSelfPresence),
+    QVERIFY(connect(mConn->becomeReady(Connection::FeatureSimplePresence),
             SIGNAL(finished(Telepathy::Client::PendingOperation*)),
             this,
             SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
     QCOMPARE(mLoop->exec(), 0);
-    QCOMPARE(mConn->isReady(Connection::FeatureSelfPresence), false);
+    QCOMPARE(mConn->isReady(Connection::FeatureSimplePresence), false);
 
     QCOMPARE(static_cast<uint>(mConn->status()),
         static_cast<uint>(Connection::StatusConnected));
-- 
1.5.6.5




More information about the telepathy-commits mailing list