connection.h Source File

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

connection.h
1
23 #ifndef _TelepathyQt_connection_h_HEADER_GUARD_
24 #define _TelepathyQt_connection_h_HEADER_GUARD_
25
26 #ifndef IN_TP_QT_HEADER
27 #error IN_TP_QT_HEADER
28 #endif
29
30 #include <TelepathyQt/_gen/cli-connection.h>
31
32 #include <TelepathyQt/ConnectionCapabilities>
33 #include <TelepathyQt/Contact>
34 #include <TelepathyQt/DBus>
35 #include <TelepathyQt/DBusProxy>
36 #include <TelepathyQt/OptionalInterfaceFactory>
37 #include <TelepathyQt/ReadinessHelper>
38 #include <TelepathyQt/Types>
39 #include <TelepathyQt/SharedPtr>
40
41 #include <TelepathyQt/Constants>
42 #include <TelepathyQt/Types>
43
44 #include <QSet>
45 #include <QString>
46 #include <QStringList>
47
48 namespace Tp
49 {
50
51 class Channel;
52 class ConnectionCapabilities;
53 class ConnectionLowlevel;
54 class Contact;
55 class ContactManager;
56 class PendingChannel;
57 class PendingContactAttributes;
58 class PendingHandles;
59 class PendingOperation;
60 class PendingReady;
61
62 class TP_QT_EXPORT Connection : public StatefulDBusProxy,
63 public OptionalInterfaceFactory<Connection>
64 {
65 Q_OBJECT
66 Q_DISABLE_COPY(Connection)
67
68 public:
69 static const Feature FeatureCore;
70 static const Feature FeatureSelfContact;
71 static const Feature FeatureSimplePresence;
72 static const Feature FeatureRoster;
73 static const Feature FeatureRosterGroups;
74 static const Feature FeatureAccountBalance; // TODO unit tests for this
75 static const Feature FeatureConnected;
76
77 static ConnectionPtr create(const QString &busName,
78 const QString &objectPath,
79 const ChannelFactoryConstPtr &channelFactory,
80 const ContactFactoryConstPtr &contactFactory);
81 static ConnectionPtr create(const QDBusConnection &bus,
82 const QString &busName, const QString &objectPath,
83 const ChannelFactoryConstPtr &channelFactory,
84 const ContactFactoryConstPtr &contactFactory);
85
86 virtual ~Connection();
87
88 ChannelFactoryConstPtr channelFactory() const;
89 ContactFactoryConstPtr contactFactory() const;
90
91 QString cmName() const;
92 QString protocolName() const;
93
94 ConnectionStatus status() const;
95 ConnectionStatusReason statusReason() const;
96
97 class ErrorDetails
98 {
99 public:
100 ErrorDetails();
101 ErrorDetails(const QVariantMap &details);
102 ErrorDetails(const ErrorDetails &other);
103 ~ErrorDetails();
104
105 ErrorDetails &operator=(const ErrorDetails &other);
106
107 bool isValid() const { return mPriv.constData() != 0; }
108
109 bool hasDebugMessage() const
110 {
111 return allDetails().contains(QLatin1String("debug-message"));
112 }
113
114 QString debugMessage() const
115 {
116 return qdbus_cast<QString>(allDetails().value(QLatin1String("debug-message")));
117 }
118
119 bool hasServerMessage() const
120 {
121 return allDetails().contains(QLatin1String("server-message"));
122 }
123
124 QString serverMessage() const
125 {
126 return qdbus_cast<QString>(allDetails().value(QLatin1String("server-message")));
127 }
128
129 bool hasUserRequested() const
130 {
131 return allDetails().contains(QLatin1String("user-requested"));
132 }
133
134 bool userRequested() const
135 {
136 return qdbus_cast<bool>(allDetails().value(QLatin1String("user-requested")));
137 }
138
139 bool hasExpectedHostname() const
140 {
141 return allDetails().contains(QLatin1String("expected-hostname"));
142 }
143
144 QString expectedHostname() const
145 {
146 return qdbus_cast<QString>(allDetails().value(QLatin1String("expected-hostname")));
147 }
148
149 bool hasCertificateHostname() const
150 {
151 return allDetails().contains(QLatin1String("certificate-hostname"));
152 }
153
154 QString certificateHostname() const
155 {
156 return qdbus_cast<QString>(allDetails().value(QLatin1String("certificate-hostname")));
157 }
158
159 QVariantMap allDetails() const;
160
161 private:
162 friend class Connection;
163
164 struct Private;
165 friend struct Private;
166 QSharedDataPointer<Private> mPriv;
167 };
168
169 const ErrorDetails &errorDetails() const;
170
171 uint selfHandle() const;
172 ContactPtr selfContact() const;
173
174 CurrencyAmount accountBalance() const;
175
176 ConnectionCapabilities capabilities() const;
177
178 ContactManagerPtr contactManager() const;
179
180 #if defined(BUILDING_TP_QT) || defined(TP_QT_ENABLE_LOWLEVEL_API)
181 ConnectionLowlevelPtr lowlevel();
182 ConnectionLowlevelConstPtr lowlevel() const;
183 #endif
184
185 Q_SIGNALS:
186 void statusChanged(Tp::ConnectionStatus newStatus);
187
188 void selfHandleChanged(uint newHandle);
189 // FIXME: might not need this when Renaming is fixed and mapped to Contacts
190 void selfContactChanged();
191
192 void accountBalanceChanged(const Tp::CurrencyAmount &accountBalance);
193
194 protected:
195 Connection(const QDBusConnection &bus, const QString &busName,
196 const QString &objectPath,
197 const ChannelFactoryConstPtr &channelFactory,
198 const ContactFactoryConstPtr &contactFactory,
199 const Feature &coreFeature);
200
201 Client::ConnectionInterface *baseInterface() const;
202
203 private Q_SLOTS:
204 TP_QT_NO_EXPORT void onStatusReady(uint status);
205 TP_QT_NO_EXPORT void onStatusChanged(uint status, uint reason);
206 TP_QT_NO_EXPORT void onConnectionError(const QString &error, const QVariantMap &details);
207 TP_QT_NO_EXPORT void gotMainProperties(QDBusPendingCallWatcher *watcher);
208 TP_QT_NO_EXPORT void gotStatus(QDBusPendingCallWatcher *watcher);
209 TP_QT_NO_EXPORT void gotInterfaces(QDBusPendingCallWatcher *watcher);
210 TP_QT_NO_EXPORT void gotSelfHandle(QDBusPendingCallWatcher *watcher);
211 TP_QT_NO_EXPORT void gotCapabilities(QDBusPendingCallWatcher *watcher);
212 TP_QT_NO_EXPORT void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
213 TP_QT_NO_EXPORT void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
214 TP_QT_NO_EXPORT void gotSelfContact(Tp::PendingOperation *op);
215
216 TP_QT_NO_EXPORT void onIntrospectRosterFinished(Tp::PendingOperation *op);
217 TP_QT_NO_EXPORT void onIntrospectRosterGroupsFinished(Tp::PendingOperation *op);
218
219 TP_QT_NO_EXPORT void doReleaseSweep(uint handleType);
220
221 TP_QT_NO_EXPORT void onSelfHandleChanged(uint);
222
223 TP_QT_NO_EXPORT void gotBalance(QDBusPendingCallWatcher *watcher);
224 TP_QT_NO_EXPORT void onBalanceChanged(const Tp::CurrencyAmount &);
225
226 private:
227 class PendingConnect;
228 friend class ConnectionLowlevel;
229 friend class PendingChannel;
230 friend class PendingConnect;
231 friend class PendingContactAttributes;
232 friend class PendingContacts;
233 friend class PendingHandles;
234 friend class ReferencedHandles;
235
236 TP_QT_NO_EXPORT void refHandle(HandleType handleType, uint handle);
237 TP_QT_NO_EXPORT void unrefHandle(HandleType handleType, uint handle);
238 TP_QT_NO_EXPORT void handleRequestLanded(HandleType handleType);
239
240 struct Private;
241 friend struct Private;
242 Private *mPriv;
243 };
244
245 } // Tp
246
247 Q_DECLARE_METATYPE(Tp::Connection::ErrorDetails);
248
249 #endif
Tp::HandleType
HandleType
Definition: build/TelepathyQt/_gen/constants.h:1375
Tp::Connection::ErrorDetails::hasCertificateHostname
bool hasCertificateHostname() const
Definition: connection.h:149
Tp::Connection::FeatureRoster
static const Feature FeatureRoster
Definition: connection.h:72
Tp::PendingHandles
The PendingHandles class represents the parameters of and the reply to an asynchronous handle request...
Definition: pending-handles.h:46
Tp::CurrencyAmount
Definition: build/TelepathyQt/_gen/types.h:1352
Tp::Feature
The Feature class represents a feature that can be enabled on demand.
Definition: feature.h:41
Tp::StatefulDBusProxy
The StatefulDBusProxy class is a base class representing a remote object whose API is stateful...
Definition: dbus-proxy.h:96
Tp::Connection::ErrorDetails::hasServerMessage
bool hasServerMessage() const
Definition: connection.h:119
Tp::ConnectionStatusReason
ConnectionStatusReason
Definition: build/TelepathyQt/_gen/constants.h:1465
Tp::Client::ConnectionInterface
Definition: cli-connection.h:44
Tp::PendingOperation
The PendingOperation class is a base class for pending asynchronous operations.
Definition: pending-operation.h:45
Tp::Connection::ErrorDetails::hasDebugMessage
bool hasDebugMessage() const
Definition: connection.h:109
Tp::Connection::FeatureAccountBalance
static const Feature FeatureAccountBalance
Definition: connection.h:74
Tp::Connection::ErrorDetails::hasExpectedHostname
bool hasExpectedHostname() const
Definition: connection.h:139
Tp::Connection::ErrorDetails::certificateHostname
QString certificateHostname() const
Definition: connection.h:154
Tp::Connection::ErrorDetails::isValid
bool isValid() const
Definition: connection.h:107
Tp::PendingContacts
The PendingContacts class is used by ContactManager when creating/updating Contact objects...
Definition: pending-contacts.h:46
Tp::Connection
The Connection class represents a Telepathy connection.
Definition: connection.h:62
Tp::ReferencedHandles
Helper container for safe management of handle lifetimes. Every handle in a ReferencedHandles contain...
Definition: referenced-handles.h:47
Tp::Connection::FeatureSelfContact
static const Feature FeatureSelfContact
Definition: connection.h:70
Tp::ConnectionStatus
ConnectionStatus
Definition: build/TelepathyQt/_gen/constants.h:1420
Tp::Connection::ErrorDetails::hasUserRequested
bool hasUserRequested() const
Definition: connection.h:129
Tp::PendingChannel
The PendingChannel class represents the parameters of and the reply to an asynchronous channel reques...
Definition: pending-channel.h:44
Tp::Connection::ErrorDetails::serverMessage
QString serverMessage() const
Definition: connection.h:124
Tp::Connection::ErrorDetails
The Connection::ErrorDetails class represents the details of a connection error.
Definition: connection.h:97
Tp::Connection::FeatureRosterGroups
static const Feature FeatureRosterGroups
Definition: connection.h:73
Tp::Connection::FeatureSimplePresence
static const Feature FeatureSimplePresence
Definition: connection.h:71
Tp::Connection::ErrorDetails::userRequested
bool userRequested() const
Definition: connection.h:134
Tp::ConnectionLowlevel
The ConnectionLowlevel class extends Connection with support to low-level features.
Definition: connection-lowlevel.h:43
Tp::Connection::ErrorDetails::expectedHostname
QString expectedHostname() const
Definition: connection.h:144
Tp::ConnectionCapabilities
The ConnectionCapabilities class represents the capabilities of a Connection.
Definition: connection-capabilities.h:38
Tp::Connection::FeatureConnected
static const Feature FeatureConnected
Definition: connection.h:75
Tp::Connection::ErrorDetails::debugMessage
QString debugMessage() const
Definition: connection.h:114
Tp::Connection::FeatureCore
static const Feature FeatureCore
Definition: connection.h:69
Tp::OptionalInterfaceFactory
The OptionalInterfaceFactory class is a helper class for high-level D-Bus proxy classes willing to of...
Definition: optional-interface-factory.h:65
Tp::PendingContactAttributes
The PendingContactAttributes class represents the parameters of and the reply to an asynchronous requ...
Definition: pending-contact-attributes.h:40