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

connection.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008-2010 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008-2010 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/ConnectionCapabilities>
00032 #include <TelepathyQt4/Contact>
00033 #include <TelepathyQt4/DBus>
00034 #include <TelepathyQt4/DBusProxy>
00035 #include <TelepathyQt4/OptionalInterfaceFactory>
00036 #include <TelepathyQt4/ReadinessHelper>
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 ConnectionLowlevel;
00053 class Contact;
00054 class ContactManager;
00055 class PendingChannel;
00056 class PendingContactAttributes;
00057 class PendingHandles;
00058 class PendingOperation;
00059 class PendingReady;
00060 
00061 class TELEPATHY_QT4_EXPORT Connection : public StatefulDBusProxy,
00062                    public OptionalInterfaceFactory<Connection>
00063 {
00064     Q_OBJECT
00065     Q_DISABLE_COPY(Connection)
00066 
00067 public:
00068     static const Feature FeatureCore;
00069     static const Feature FeatureSelfContact;
00070     static const Feature FeatureSimplePresence;
00071     static const Feature FeatureRoster;
00072     static const Feature FeatureRosterGroups;
00073     static const Feature FeatureAccountBalance; // TODO unit tests for this
00074 
00075     static ConnectionPtr create(const QString &busName,
00076             const QString &objectPath,
00077             const ChannelFactoryConstPtr &channelFactory,
00078             const ContactFactoryConstPtr &contactFactory);
00079     static ConnectionPtr create(const QDBusConnection &bus,
00080             const QString &busName, const QString &objectPath,
00081             const ChannelFactoryConstPtr &channelFactory,
00082             const ContactFactoryConstPtr &contactFactory);
00083 
00084     virtual ~Connection();
00085 
00086     ChannelFactoryConstPtr channelFactory() const;
00087     ContactFactoryConstPtr contactFactory() const;
00088 
00089     QString cmName() const;
00090     QString protocolName() const;
00091 
00092     ConnectionStatus status() const;
00093     ConnectionStatusReason statusReason() const;
00094 
00095     class ErrorDetails
00096     {
00097         public:
00098             ErrorDetails();
00099             ErrorDetails(const QVariantMap &details);
00100             ErrorDetails(const ErrorDetails &other);
00101             ~ErrorDetails();
00102 
00103             ErrorDetails &operator=(const ErrorDetails &other);
00104 
00105             bool isValid() const { return mPriv.constData() != 0; }
00106 
00107             bool hasDebugMessage() const
00108             {
00109                 return allDetails().contains(QLatin1String("debug-message"));
00110             }
00111 
00112             QString debugMessage() const
00113             {
00114                 return qdbus_cast<QString>(allDetails().value(QLatin1String("debug-message")));
00115             }
00116 
00117 #if 0
00118             /*
00119              * TODO: these are actually specified in a draft interface only. Probably shouldn't
00120              * include them yet.
00121              */
00122             bool hasExpectedHostname() const
00123             {
00124                 return allDetails().contains(QLatin1String("expected-hostname"));
00125             }
00126 
00127             QString expectedHostname() const
00128             {
00129                 return qdbus_cast<QString>(allDetails().value(QLatin1String("expected-hostname")));
00130             }
00131 
00132             bool hasCertificateHostname() const
00133             {
00134                 return allDetails().contains(QLatin1String("certificate-hostname"));
00135             }
00136 
00137             QString certificateHostname() const
00138             {
00139                 return qdbus_cast<QString>(allDetails().value(QLatin1String("certificate-hostname")));
00140             }
00141 #endif
00142 
00143             QVariantMap allDetails() const;
00144 
00145         private:
00146             friend class Connection;
00147 
00148             struct Private;
00149             friend struct Private;
00150             QSharedDataPointer<Private> mPriv;
00151     };
00152 
00153     const ErrorDetails &errorDetails() const;
00154 
00155     uint selfHandle() const;
00156     ContactPtr selfContact() const;
00157 
00158     CurrencyAmount accountBalance() const;
00159 
00160     ConnectionCapabilities capabilities() const;
00161 
00162     ContactManagerPtr contactManager() const;
00163 
00164 #if defined(BUILDING_TELEPATHY_QT4) || defined(TP_QT4_ENABLE_LOWLEVEL_API)
00165     ConnectionLowlevelPtr lowlevel();
00166     ConnectionLowlevelConstPtr lowlevel() const;
00167 #endif
00168 
00169 Q_SIGNALS:
00170     void statusChanged(Tp::ConnectionStatus newStatus);
00171 
00172     void selfHandleChanged(uint newHandle);
00173     // FIXME: might not need this when Renaming is fixed and mapped to Contacts
00174     void selfContactChanged();
00175 
00176     void accountBalanceChanged(const Tp::CurrencyAmount &accountBalance);
00177 
00178 protected:
00179     Connection(const QDBusConnection &bus, const QString &busName,
00180             const QString &objectPath,
00181             const ChannelFactoryConstPtr &channelFactory,
00182             const ContactFactoryConstPtr &contactFactory,
00183             const Feature &coreFeature);
00184 
00185     Client::ConnectionInterface *baseInterface() const;
00186 
00187 private Q_SLOTS:
00188     void onStatusReady(uint status);
00189     void onStatusChanged(uint status, uint reason);
00190     void onConnectionError(const QString &error, const QVariantMap &details);
00191     void gotMainProperties(QDBusPendingCallWatcher *watcher);
00192     void gotStatus(QDBusPendingCallWatcher *watcher);
00193     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00194     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00195     void gotCapabilities(QDBusPendingCallWatcher *watcher);
00196     void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
00197     void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
00198     void gotSelfContact(Tp::PendingOperation *op);
00199 
00200     void onIntrospectRosterFinished(Tp::PendingOperation *op);
00201     void onIntrospectRosterGroupsFinished(Tp::PendingOperation *op);
00202 
00203     void doReleaseSweep(uint handleType);
00204 
00205     void onSelfHandleChanged(uint);
00206 
00207     void gotBalance(QDBusPendingCallWatcher *watcher);
00208     void onBalanceChanged(const Tp::CurrencyAmount &);
00209 
00210 private:
00211     class PendingConnect;
00212     friend class ConnectionLowlevel;
00213     friend class PendingChannel;
00214     friend class PendingConnect;
00215     friend class PendingContactAttributes;
00216     friend class PendingContacts;
00217     friend class PendingHandles;
00218     friend class ReferencedHandles;
00219 
00220     void refHandle(HandleType handleType, uint handle);
00221     void unrefHandle(HandleType handleType, uint handle);
00222     void handleRequestLanded(HandleType handleType);
00223 
00224     struct Private;
00225     friend struct Private;
00226     Private *mPriv;
00227 };
00228 
00229 } // Tp
00230 
00231 Q_DECLARE_METATYPE(Tp::Connection::ErrorDetails);
00232 
00233 #endif


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