1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
/**
* This file is part of TelepathyQt4
*
* @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
* @copyright Copyright (C) 2010 Nokia Corporation
* @license LGPL 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <TelepathyQt4/ProtocolInfo>
#include <TelepathyQt4/ConnectionCapabilities>
namespace Tp
{
struct TP_QT_NO_EXPORT ProtocolInfo::Private : public QSharedData
{
Private()
{
}
Private(const QString &cmName, const QString &name)
: cmName(cmName),
name(name),
iconName(QString(QLatin1String("im-%1")).arg(name))
{
}
QString cmName;
QString name;
ProtocolParameterList params;
ConnectionCapabilities caps;
QString vcardField;
QString englishName;
QString iconName;
PresenceSpecList statuses;
AvatarSpec avatarRequirements;
};
/**
* \class ProtocolInfo
* \ingroup clientcm
* \headerfile TelepathyQt4/protocol-info.h <TelepathyQt4/ProtocolInfo>
*
* \brief The ProtocolInfo class represents a <a
* href="http://telepathy.freedesktop.org/spec/Protocol.html">Telepathy Protocol</a>.
*/
ProtocolInfo::ProtocolInfo()
{
}
/**
* Construct a new ProtocolInfo object.
*
* \param cmName Connection manager name.
* \param name Protocol name.
*/
ProtocolInfo::ProtocolInfo(const QString &cmName, const QString &name)
: mPriv(new Private(cmName, name))
{
}
ProtocolInfo::ProtocolInfo(const ProtocolInfo &other)
: mPriv(other.mPriv)
{
}
/**
* Class destructor.
*/
ProtocolInfo::~ProtocolInfo()
{
}
ProtocolInfo &ProtocolInfo::operator=(const ProtocolInfo &other)
{
this->mPriv = other.mPriv;
return *this;
}
/**
* Return the short name of the connection manager (e.g. "gabble") for this protocol.
*
* \return The name of the connection manager for this protocol.
*/
QString ProtocolInfo::cmName() const
{
if (!isValid()) {
return QString();
}
return mPriv->cmName;
}
/**
* Return the string identifying this protocol as described in the \telepathy_spec
* (e.g. "jabber").
*
* This identifier is not intended to be displayed to users directly; user
* interfaces are responsible for mapping them to localized strings.
*
* \return A string identifying this protocol.
*/
QString ProtocolInfo::name() const
{
if (!isValid()) {
return QString();
}
return mPriv->name;
}
/**
* Return all supported parameters for this protocol. The parameters' names
* may either be the well-known strings specified by the \telepathy_spec
* (e.g. "account" and "password"), or implementation-specific strings.
*
* \return A list of parameters for this protocol.
*/
ProtocolParameterList ProtocolInfo::parameters() const
{
if (!isValid()) {
return ProtocolParameterList();
}
return mPriv->params;
}
/**
* Return whether a given parameter can be passed to the connection
* manager when creating a connection to this protocol.
*
* \param name The name of a parameter.
* \return true if the given parameter exists.
*/
bool ProtocolInfo::hasParameter(const QString &name) const
{
if (!isValid()) {
return false;
}
foreach (const ProtocolParameter ¶m, mPriv->params) {
if (param.name() == name) {
return true;
}
}
return false;
}
/**
* Return whether it might be possible to register new accounts on this
* protocol, by setting the special parameter named
* <code>register</code> to <code>true</code>.
*
* \return The same thing as hasParameter("register").
* \sa hasParameter()
*/
bool ProtocolInfo::canRegister() const
{
if (!isValid()) {
return false;
}
return hasParameter(QLatin1String("register"));
}
/**
* Return the capabilities that are expected to be available from a connection
* to this protocol, i.e. those for which Connection::createChannel() can
* reasonably be expected to succeed.
* User interfaces can use this information to show or hide UI components.
*
* @return An object representing the capabilities expected to be available from
* a connection to this protocol.
*/
ConnectionCapabilities ProtocolInfo::capabilities() const
{
if (!isValid()) {
return ConnectionCapabilities();
}
return mPriv->caps;
}
/**
* Return the name of the most common vCard field used for this protocol's
* contact identifiers, normalized to lower case.
*
* One valid use of this field is to answer the question: given a contact's
* vCard containing an X-JABBER field, how can you communicate with the contact?
* By iterating through protocols looking for an x-jabber VCardField, one can
* build up a list of protocols that handle x-jabber, then offer the user a list
* of accounts for those protocols and/or the option to create a new account for
* one of those protocols.
* It is not necessarily valid to interpret contacts' identifiers as values of
* this vCard field. For instance, telepathy-sofiasip supports contacts whose
* identifiers are of the form sip:jenny@example.com or tel:8675309, which would
* not normally both be represented by any single vCard field.
*
* \return The most common vCard field used for this protocol's contact
* identifiers, or an empty string if there is no such field.
*/
QString ProtocolInfo::vcardField() const
{
if (!isValid()) {
return QString();
}
return mPriv->vcardField;
}
/**
* Return the English-language name of this protocol, such as "AIM" or "Yahoo!".
*
* The name can be used as a fallback if an application doesn't have a localized name for this
* protocol.
*
* If the manager file or the CM service doesn't specify the english name, it is inferred from this
* protocol name, such that for example "google-talk" becomes "Google Talk", but "local-xmpp"
* becomes "Local Xmpp".
*
* \return An English-language name for this protocol.
*/
QString ProtocolInfo::englishName() const
{
if (!isValid()) {
return QString();
}
return mPriv->englishName;
}
/**
* Return the name of an icon for this protocol in the system's icon theme, such as "im-msn".
*
* If the manager file or the CM service doesn't specify the icon name, "im-<protocolname>" is
* assumed.
*
* \return The likely name of an icon for this protocol.
*/
QString ProtocolInfo::iconName() const
{
if (!isValid()) {
return QString();
}
return mPriv->iconName;
}
/**
* Return a list of PresenceSpec representing the possible presence statuses
* from a connection to this protocol.
*
* \return A list of PresenceSpec representing the possible presence statuses
* from a connection to this protocol.
*/
PresenceSpecList ProtocolInfo::allowedPresenceStatuses() const
{
if (!isValid()) {
return PresenceSpecList();
}
return mPriv->statuses;
}
/**
* Return the requirements (size limits, supported MIME types, etc)
* for avatars used on to this protocol.
*
* \return The requirements for avatars used on this protocol.
*/
AvatarSpec ProtocolInfo::avatarRequirements() const
{
if (!isValid()) {
return AvatarSpec();
}
return mPriv->avatarRequirements;
}
void ProtocolInfo::addParameter(const ParamSpec &spec)
{
if (!isValid()) {
mPriv = new Private;
}
QVariant defaultValue;
if (spec.flags & ConnMgrParamFlagHasDefault) {
defaultValue = spec.defaultValue.variant();
}
uint flags = spec.flags;
if (spec.name.endsWith(QLatin1String("password"))) {
flags |= ConnMgrParamFlagSecret;
}
ProtocolParameter param(spec.name,
QDBusSignature(spec.signature),
defaultValue,
(ConnMgrParamFlag) flags);
mPriv->params.append(param);
}
void ProtocolInfo::setVCardField(const QString &vcardField)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->vcardField = vcardField;
}
void ProtocolInfo::setEnglishName(const QString &englishName)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->englishName = englishName;
}
void ProtocolInfo::setIconName(const QString &iconName)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->iconName = iconName;
}
void ProtocolInfo::setRequestableChannelClasses(
const RequestableChannelClassList &caps)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->caps.updateRequestableChannelClasses(caps);
}
void ProtocolInfo::setAllowedPresenceStatuses(const PresenceSpecList &statuses)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->statuses = statuses;
}
void ProtocolInfo::setAvatarRequirements(const AvatarSpec &avatarRequirements)
{
if (!isValid()) {
mPriv = new Private;
}
mPriv->avatarRequirements = avatarRequirements;
}
} // Tp
|