Home · All Classes · All Namespaces · Modules · Functions · Files

connection.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008, 2009 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008, 2009 Nokia Corporation
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _TelepathyQt4_connection_h_HEADER_GUARD_
00023 #define _TelepathyQt4_connection_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <TelepathyQt4/_gen/cli-connection.h>
00030 
00031 #include <TelepathyQt4/Contact>
00032 #include <TelepathyQt4/DBus>
00033 #include <TelepathyQt4/DBusProxy>
00034 #include <TelepathyQt4/OptionalInterfaceFactory>
00035 #include <TelepathyQt4/ReadinessHelper>
00036 #include <TelepathyQt4/ReadyObject>
00037 #include <TelepathyQt4/Types>
00038 #include <TelepathyQt4/SharedPtr>
00039 
00040 #include <TelepathyQt4/Constants>
00041 #include <TelepathyQt4/Types>
00042 
00043 #include <QSet>
00044 #include <QString>
00045 #include <QStringList>
00046 
00047 namespace Tp
00048 {
00049 
00050 class Channel;
00051 class ConnectionCapabilities;
00052 class Contact;
00053 class ContactManager;
00054 class PendingChannel;
00055 class PendingContactAttributes;
00056 class PendingHandles;
00057 class PendingOperation;
00058 class PendingReady;
00059 
00060 class TELEPATHY_QT4_EXPORT Connection : public StatefulDBusProxy,
00061                    public OptionalInterfaceFactory<Connection>,
00062                    public ReadyObject,
00063                    public RefCounted
00064 {
00065     Q_OBJECT
00066     Q_DISABLE_COPY(Connection)
00067     Q_ENUMS(Status)
00068 
00069 public:
00070     static const Feature FeatureCore;
00071     static const Feature FeatureSelfContact;
00072     static const Feature FeatureSimplePresence;
00073     static const Feature FeatureRoster;
00074     static const Feature FeatureRosterGroups;
00075     static const Feature FeatureAccountBalance; // TODO unit tests for this
00076 
00077     enum Status {
00078         StatusDisconnected = ConnectionStatusDisconnected,
00079         StatusConnecting = ConnectionStatusConnecting,
00080         StatusConnected = ConnectionStatusConnected,
00081         StatusUnknown = 0xFFFFFFFF
00082     };
00083 
00084     static ConnectionPtr create(const QString &busName,
00085             const QString &objectPath);
00086     static ConnectionPtr create(const QDBusConnection &bus,
00087             const QString &busName, const QString &objectPath);
00088 
00089     virtual ~Connection();
00090 
00091     QString cmName() const;
00092     QString protocolName() const;
00093 
00094     Status status() const;
00095     ConnectionStatusReason statusReason() const;
00096 
00097     class ErrorDetails
00098     {
00099         public:
00100             ErrorDetails();
00101             ErrorDetails(const QVariantMap &details);
00102             ErrorDetails(const ErrorDetails &other);
00103             ~ErrorDetails();
00104 
00105             ErrorDetails &operator=(const ErrorDetails &other);
00106 
00107             bool isValid() const { return mPriv.constData() != 0; }
00108 
00109             bool hasDebugMessage() const
00110             {
00111                 return allDetails().contains(QLatin1String("debug-message"));
00112             }
00113 
00114             QString debugMessage() const
00115             {
00116                 return qdbus_cast<QString>(allDetails().value(QLatin1String("debug-message")));
00117             }
00118 
00119 #if 0
00120             /*
00121              * TODO: these are actually specified in a draft interface only. Probably shouldn't
00122              * include them yet.
00123              */
00124             bool hasExpectedHostname() const
00125             {
00126                 return allDetails().contains(QLatin1String("expected-hostname"));
00127             }
00128 
00129             QString expectedHostname() const
00130             {
00131                 return qdbus_cast<QString>(allDetails().value(QLatin1String("expected-hostname")));
00132             }
00133 
00134             bool hasCertificateHostname() const
00135             {
00136                 return allDetails().contains(QLatin1String("certificate-hostname"));
00137             }
00138 
00139             QString certificateHostname() const
00140             {
00141                 return qdbus_cast<QString>(allDetails().value(QLatin1String("certificate-hostname")));
00142             }
00143 #endif
00144 
00145             QVariantMap allDetails() const;
00146 
00147         private:
00148             friend class Connection;
00149 
00150             struct Private;
00151             friend struct Private;
00152             QSharedDataPointer<Private> mPriv;
00153     };
00154 
00155     const ErrorDetails &errorDetails() const;
00156 
00157     uint selfHandle() const;
00158     ContactPtr selfContact() const;
00159 
00160     SimpleStatusSpecMap allowedPresenceStatuses() const;
00161     PendingOperation *setSelfPresence(const QString &status, const QString &statusMessage);
00162 
00163     CurrencyAmount accountBalance() const;
00164 
00165     ConnectionCapabilities *capabilities() const;
00166 
00167     PendingChannel *createChannel(const QVariantMap &request);
00168     PendingChannel *ensureChannel(const QVariantMap &request);
00169 
00170     PendingReady *requestConnect(const Features &requestedFeatures = Features());
00171     PendingOperation *requestDisconnect();
00172 
00173     PendingHandles *requestHandles(uint handleType, const QStringList &names);
00174     PendingHandles *referenceHandles(uint handleType, const UIntList &handles);
00175 
00176     PendingContactAttributes *contactAttributes(const UIntList &handles,
00177             const QStringList &interfaces, bool reference = true);
00178     QStringList contactAttributeInterfaces() const;
00179     ContactManager *contactManager() const;
00180 
00181     inline Client::DBus::PropertiesInterface *propertiesInterface() const
00182     {
00183         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
00184     }
00185 
00186     inline Client::ConnectionInterfaceAliasingInterface *aliasingInterface(
00187             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00188     {
00189         return optionalInterface<Client::ConnectionInterfaceAliasingInterface>(check);
00190     }
00191 
00192     inline Client::ConnectionInterfaceAnonymityInterface *anonymityInterface(
00193             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00194     {
00195         return optionalInterface<Client::ConnectionInterfaceAnonymityInterface>(check);
00196     }
00197 
00198     inline Client::ConnectionInterfaceAvatarsInterface *avatarsInterface(
00199             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00200     {
00201         return optionalInterface<Client::ConnectionInterfaceAvatarsInterface>(check);
00202     }
00203 
00204     inline Client::ConnectionInterfaceCapabilitiesInterface *capabilitiesInterface(
00205             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00206     {
00207         return optionalInterface<Client::ConnectionInterfaceCapabilitiesInterface>(check);
00208     }
00209 
00210     inline Client::ConnectionInterfaceContactCapabilitiesInterface *contactCapabilitiesInterface(
00211             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00212     {
00213         return optionalInterface<Client::ConnectionInterfaceContactCapabilitiesInterface>(check);
00214     }
00215 
00216     inline Client::ConnectionInterfaceLocationInterface *locationInterface(
00217             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00218     {
00219         return optionalInterface<Client::ConnectionInterfaceLocationInterface>(check);
00220     }
00221 
00222     inline Client::ConnectionInterfaceContactInfoInterface *contactInfoInterface(
00223             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00224     {
00225         return optionalInterface<Client::ConnectionInterfaceContactInfoInterface>(check);
00226     }
00227 
00228     inline Client::ConnectionInterfacePresenceInterface *presenceInterface(
00229             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00230     {
00231         return optionalInterface<Client::ConnectionInterfacePresenceInterface>(check);
00232     }
00233 
00234     inline Client::ConnectionInterfaceServicePointInterface *servicePointInterface(
00235             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00236     {
00237         return optionalInterface<Client::ConnectionInterfaceServicePointInterface>(check);
00238     }
00239 
00240     inline Client::ConnectionInterfaceSimplePresenceInterface *simplePresenceInterface(
00241             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00242     {
00243         return optionalInterface<Client::ConnectionInterfaceSimplePresenceInterface>(check);
00244     }
00245 
00246     inline Client::ConnectionInterfaceRequestsInterface *requestsInterface(
00247             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00248     {
00249         return optionalInterface<Client::ConnectionInterfaceRequestsInterface>(check);
00250     }
00251 
00252     inline Client::ConnectionInterfaceBalanceInterface *balanceInterface(
00253             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00254     {
00255         return optionalInterface<Client::ConnectionInterfaceBalanceInterface>(check);
00256     }
00257 
00258     inline Client::ConnectionInterfaceCellularInterface *cellularInterface(
00259             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00260     {
00261         return optionalInterface<Client::ConnectionInterfaceCellularInterface>(check);
00262     }
00263 
00264 Q_SIGNALS:
00265     void statusChanged(Tp::Connection::Status newStatus);
00266     TELEPATHY_QT4_DEPRECATED void statusChanged(Tp::Connection::Status newStatus,
00267             Tp::ConnectionStatusReason newStatusReason);
00268     void selfHandleChanged(uint newHandle);
00269     // FIXME: might not need this when Renaming is fixed and mapped to Contacts
00270     void selfContactChanged();
00271 
00272     void accountBalanceChanged(const Tp::CurrencyAmount &accountBalance);
00273 
00274 protected:
00275     Connection(const QString &busName, const QString &objectPath);
00276     Connection(const QDBusConnection &bus, const QString &busName,
00277             const QString &objectPath);
00278 
00279     Client::ConnectionInterface *baseInterface() const;
00280 
00281 private Q_SLOTS:
00282     void onStatusReady(uint status);
00283     void onStatusChanged(uint status, uint reason);
00284     void onConnectionError(const QString &error, const QVariantMap &details);
00285     void gotMainProperties(QDBusPendingCallWatcher *watcher);
00286     void gotStatus(QDBusPendingCallWatcher *watcher);
00287     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00288     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00289     void gotCapabilities(QDBusPendingCallWatcher *watcher);
00290     void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
00291     void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
00292     void gotSelfContact(Tp::PendingOperation *op);
00293     void gotContactListsHandles(Tp::PendingOperation *op);
00294     void gotContactListChannel(Tp::PendingOperation *op);
00295     void contactListChannelReady();
00296     void onNewChannels(const Tp::ChannelDetailsList &channelDetailsList);
00297     void onContactListGroupChannelReady(Tp::PendingOperation *op);
00298     void gotChannels(QDBusPendingCallWatcher *watcher);
00299 
00300     void doReleaseSweep(uint type);
00301 
00302     void onSelfHandleChanged(uint);
00303 
00304     void gotBalance(QDBusPendingCallWatcher *watcher);
00305     void onBalanceChanged(const Tp::CurrencyAmount &);
00306 
00307 private:
00308     class PendingConnect;
00309     friend class PendingChannel;
00310     friend class PendingConnect;
00311     friend class PendingContactAttributes;
00312     friend class PendingContacts;
00313     friend class PendingHandles;
00314     friend class ReferencedHandles;
00315 
00316     void refHandle(uint type, uint handle);
00317     void unrefHandle(uint type, uint handle);
00318     void handleRequestLanded(uint type);
00319 
00320     struct Private;
00321     friend struct Private;
00322     Private *mPriv;
00323 };
00324 
00325 } // Tp
00326 
00327 #endif


Copyright © 2008-2010 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.3.10