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

# Tp::Connection Class Reference
[Connection proxies]

The Connection class provides an object representing a Telepathy connection. More...

`#include <TelepathyQt4/Connection>`

Inherits Tp::StatefulDBusProxy, OptionalInterfaceFactory< Connection >, Tp::ReadyObject, and Tp::RefCounted.

List of all members.

## Public Types

- enum Status { StatusDisconnected, StatusConnecting, StatusConnected, StatusUnknown }

## Signals

- void statusChanged (Tp::Connection::Status newStatus, Tp::ConnectionStatusReason newStatusReason)
- void selfHandleChanged (uint newHandle)
- void selfContactChanged ()

## Public Member Functions

- virtual ~Connection ()
- Status status () const
- ConnectionStatusReason statusReason () const
- uint selfHandle () const
- ContactPtr selfContact () const
- SimpleStatusSpecMap allowedPresenceStatuses () const
- PendingOperation * setSelfPresence (const QString &status, const QString &statusMessage)
- ConnectionCapabilities * capabilities () const
- PendingChannel * createChannel (const QVariantMap &request)
- PendingChannel * ensureChannel (const QVariantMap &request)
- PendingReady * requestConnect (const Features &requestedFeatures=Features())
- PendingOperation * requestDisconnect ()
- PendingHandles * requestHandles (uint handleType, const QStringList &names)
- PendingHandles * referenceHandles (uint handleType, const UIntList &handles)
- PendingContactAttributes * contactAttributes (const UIntList &handles, const QStringList &interfaces, bool reference=true)
- QStringList contactAttributeInterfaces () const
- ContactManager * contactManager () const
- Client::DBus::PropertiesInterface * propertiesInterface () const
- Client::ConnectionInterfaceAliasingInterface * aliasingInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceAvatarsInterface * avatarsInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceCapabilitiesInterface * capabilitiesInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceContactCapabilitiesInterface * contactCapabilitiesInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceLocationInterface * locationInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfacePresenceInterface * presenceInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceSimplePresenceInterface * simplePresenceInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const
- Client::ConnectionInterfaceRequestsInterface * requestsInterface (InterfaceSupportedChecking check=CheckInterfaceSupported) const

## Static Public Member Functions

- static ConnectionPtr create (const QString &busName, const QString &objectPath)
- static ConnectionPtr create (const QDBusConnection &bus, const QString &busName, const QString &objectPath)

## Static Public Attributes

- static const Feature FeatureCore
- static const Feature FeatureSelfContact
- static const Feature FeatureSimplePresence
- static const Feature FeatureRoster
- static const Feature FeatureRosterGroups

## Protected Member Functions

- Connection (const QString &busName, const QString &objectPath)
- Connection (const QDBusConnection &bus, const QString &busName, const QString &objectPath)
- Client::ConnectionInterface * baseInterface () const

## Detailed Description

The Connection class provides an object representing a Telepathy connection.

Connection adds the following features compared to using Client::ConnectionInterface directly:

- Status tracking
- Getting the list of supported interfaces automatically
- Getting the valid presence statuses automatically

This models a connection to a single user account on a communication service. Its basic capability is to provide the facility to request and receive channels of differing types (such as text channels or streaming media channels) which are used to carry out further communication.

Contacts, and server-stored lists (such as subscribed contacts, block lists, or allow lists) on a service are all represented using the ContactManager object on the connection, which is valid only for the lifetime of the connection object.

The remote object state accessor functions on this object (status(), statusReason(), and so on) don't make any DBus calls; instead, they return values cached from a previous introspection run. The introspection process populates their values in the most efficient way possible based on what the service implements. Their return value is mostly undefined until the introspection process is completed, i.e. isReady() returns true. See the individual accessor descriptions for more details. A status change to StatusConnected indicates that the introspection process is finished

Signals are emitted to indicate that properties have changed for example statusChanged()(), selfContactChanged(), etc.

## Usage

### Creating a connection object

The easiest way to create connection objects is through Account. One can just use the Account::connection method to get an account active connection.

If you already know the object path, you can just call create(). For example:

     ConnectionPtr conn = Connection::create(busName, objectPath);

A ConnectionPtr object is returned, which will automatically keep track of object lifetime.

You can also provide a D-Bus connection as a QDBusConnection:

     ConnectionPtr conn = Connection::create(QDBusConnection::sessionBus(),
             busName, objectPath);

### Making connection ready to use

A Connection object needs to become ready before usage, meaning that the introspection process finished and the object accessors can be used.

To make the object ready, use becomeReady() and wait for the PendingOperation::finished() signal to be emitted.

     class MyClass : public QObject
     {
         QOBJECT

     public:
         MyClass(QObject *parent = 0);
         ~MyClass() { }

     private Q_SLOTS:
         void onConnectionReady(Tp::PendingOperation*);

     private:
         ConnectionPtr conn;
     };

     MyClass::MyClass(const QString &busName, const QString &objectPath,
             QObject *parent)
         : QObject(parent)
           conn(Connection::create(busName, objectPath))
     {
         // connect and become ready
         connect(conn->requestConnect(),
                 SIGNAL(finished(Tp::PendingOperation*)),
                 SLOT(onConnectionReady(Tp::PendingOperation*)));
     }

     void MyClass::onConnectionReady(Tp::PendingOperation *op)
     {
         if (op->isError()) {
             qWarning() << "Account cannot become ready:" <<
                 op->errorName() << "-" << op->errorMessage();
             return;
         }

         // Connection is now ready
     }

See Asynchronous Object Model, Shared Pointer Usage

## Member Enumeration Documentation

enum Tp::Connection::Status

Enumerator:

  StatusDisconnected |
  StatusConnecting |
  StatusConnected |
  StatusUnknown |

## Constructor & Destructor Documentation

Tp::Connection::~Connection | ( |  | ) | `[virtual]`

Class destructor.

Tp::Connection::Connection | ( | const QString & | busName,
|  | const QString & | objectPath |
| ) |  |  | `[protected]`

Construct a new connection object using QDBusConnection::sessionBus().

Parameters:

  | busName | The connection's well-known bus name (sometimes called a "service name").
  | objectPath | The connection object path.

Tp::Connection::Connection | ( | const QDBusConnection & | bus,
|  | const QString & | busName,
|  | const QString & | objectPath |
| ) |  |  | `[protected]`

Construct a new connection object using the given .

Parameters:

  | bus | QDBusConnection to use.
  | busName | The connection's well-known bus name (sometimes called a "service name").
  | objectPath | The connection object path.

## Member Function Documentation

ConnectionPtr Tp::Connection::create | ( | const QString & | busName,
|  | const QString & | objectPath |
| ) |  |  | `[static]`

Create a new connection object using QDBusConnection::sessionBus().

Parameters:

  | busName | The connection well-known bus name (sometimes called a "service name").
  | objectPath | The connection object path.

Returns:
  A ConnectionPtr pointing to the newly created Connection.

ConnectionPtr Tp::Connection::create | ( | const QDBusConnection & | bus,
|  | const QString & | busName,
|  | const QString & | objectPath |
| ) |  |  | `[static]`

Create a new connection object using the given bus.

Parameters:

  | bus | QDBusConnection to use.
  | busName | The connection well-known bus name (sometimes called a "service name").
  | objectPath | The connection object path.

Returns:
  A ConnectionPtr pointing to the newly created Connection.

Connection::Status Tp::Connection::status | ( |  | ) | const

Return the status of this connection.

This method requires Connection::FeatureCore to be enabled.

Returns:
  The status of this connection, as defined in Connection::Status.

See also:
  statusChanged()

ConnectionStatusReason Tp::Connection::statusReason | ( |  | ) | const

Return the reason for this connection's status (which is returned by status()). The validity and change rules are the same as for status().

This method requires Connection::FeatureCore to be enabled.

Returns:
  The reason, as defined in ConnectionStatusReason.

uint Tp::Connection::selfHandle | ( |  | ) | const

Return the handle which represents the user on this connection, which will remain valid for the lifetime of this connection, or until a change in the user's identifier is signalled by the selfHandleChanged() signal. If the connection is not yet in the StatusConnected state, the value of this property may be zero.

This method requires Connection::FeatureCore to be enabled.

Returns:
  Self handle.

ContactPtr Tp::Connection::selfContact | ( |  | ) | const

Return the object that represents the contact of this connection.

This method requires Connection::FeatureSelfContact to be enabled.

Returns:
  The connection self contact.

SimpleStatusSpecMap Tp::Connection::allowedPresenceStatuses | ( |  | ) | const

Return a dictionary of presence statuses valid for use in this connection.

The value may have changed arbitrarily during the time the Connection spends in status StatusConnecting, again staying fixed for the entire time in StatusConnected.

This method requires Connection::FeatureSimplePresence to be enabled.

Returns:
  Dictionary from string identifiers to structs for each valid status.

PendingOperation * Tp::Connection::setSelfPresence | ( | const QString & | status,
|  | const QString & | statusMessage |
| ) |  |  |

Set the self presence status.

status must be one of the allowed statuses returned by allowedPresenceStatuses().

Note that clients SHOULD set the status message for the local user to the empty string, unless the user has actually provided a specific message (i.e. one that conveys more information than the Status).

Parameters:

  | status | The desired status.
  | statusMessage | The desired status message.

Returns:
  A PendingOperation which will emit PendingOperation::finished when the call has finished.

See also:
  allowedPresenceStatuses()

ConnectionCapabilities * Tp::Connection::capabilities | ( |  | ) | const

Return the capabilities that are expected to be available on this connection, i.e. those for which createChannel() can reasonably be expected to succeed. User interfaces can use this information to show or hide UI components.

This property cannot change after the connection has gone to state() TpConnection_Status_Connected, so there is no change notification.

This method requires Connection::FeatureCore to be enabled.

Returns:
  An object representing the connection capabilities or 0 if FeatureCore is not ready.

PendingChannel * Tp::Connection::createChannel | ( | const QVariantMap & | request | ) |

Asynchronously creates a channel satisfying the given request.

The request MUST contain the following keys: org.freedesktop.Telepathy.Channel.ChannelType org.freedesktop.Telepathy.Channel.TargetHandleType

Upon completion, the reply to the request can be retrieved through the returned PendingChannel object. The object also provides access to the parameters with which the call was made and a signal to connect to get notification of the request finishing processing. See the documentation for that class for more info.

The returned PendingChannel object should be freed using its QObject::deleteLater() method after it is no longer used. However, all PendingChannel objects resulting from requests to a particular Connection will be freed when the Connection itself is freed. Conversely, this means that the PendingChannel object should not be used after the Connection is destroyed.

See also:
  PendingChannel

Parameters:

  | request | A dictionary containing the desirable properties.

Returns:
  Pointer to a newly constructed PendingChannel object, tracking the progress of the request.

PendingChannel * Tp::Connection::ensureChannel | ( | const QVariantMap & | request | ) |

Asynchronously ensures a channel exists satisfying the given request.

The request MUST contain the following keys: org.freedesktop.Telepathy.Channel.ChannelType org.freedesktop.Telepathy.Channel.TargetHandleType

Upon completion, the reply to the request can be retrieved through the returned PendingChannel object. The object also provides access to the parameters with which the call was made and a signal to connect to get notification of the request finishing processing. See the documentation for that class for more info.

The returned PendingChannel object should be freed using its QObject::deleteLater() method after it is no longer used. However, all PendingChannel objects resulting from requests to a particular Connection will be freed when the Connection itself is freed. Conversely, this means that the PendingChannel object should not be used after the Connection is destroyed.

See also:
  PendingChannel

Parameters:

  | request | A dictionary containing the desirable properties.

Returns:
  Pointer to a newly constructed PendingChannel object, tracking the progress of the request.

PendingReady * Tp::Connection::requestConnect | ( | const Features & | requestedFeatures = `Features()` | ) |

Start an asynchronous request that the connection be connected.

The returned PendingOperation will finish successfully when the connection has reached StatusConnected and the requested features are all ready, or finish with an error if a fatal error occurs during that process.

Parameters:

  | requestedFeatures | The features which should be enabled

Returns:
  A PendingReady object which will emit finished when the Connection has reached StatusConnected, and initial setup for basic functionality, plus the given features, has succeeded or failed

PendingOperation * Tp::Connection::requestDisconnect | ( |  | ) |

Start an asynchronous request that the connection be disconnected. The returned PendingOperation object will signal the success or failure of this request; under normal circumstances, it can be expected to succeed.

Returns:
  A PendingOperation, which will emit finished when the request finishes.

PendingHandles * Tp::Connection::requestHandles | ( | uint | handleType,
|  | const QStringList & | names |
| ) |  |  |

Request handles of the given type for the given entities (contacts, rooms, lists, etc.).

Upon completion, the reply to the request can be retrieved through the returned PendingHandles object. The object also provides access to the parameters with which the call was made and a signal to connect to to get notification of the request finishing processing. See the documentation for that class for more info.

The returned PendingHandles object should be freed using its QObject::deleteLater() method after it is no longer used. However, all PendingHandles objects resulting from requests to a particular Connection will be freed when the Connection itself is freed. Conversely, this means that the PendingHandles object should not be used after the Connection is destroyed.

See also:
  PendingHandles

Parameters:

  | handleType | Type for the handles to request, as specified in HandleType.
  | names | Names of the entities to request handles for.

Returns:
  Pointer to a newly constructed PendingHandles object, tracking the progress of the request.

PendingHandles * Tp::Connection::referenceHandles | ( | uint | handleType,
|  | const UIntList & | handles |
| ) |  |  |

Request a reference to the given handles. Handles not explicitly requested (via requestHandles()) but eg. observed in a signal need to be referenced to guarantee them staying valid.

Upon completion, the reply to the operation can be retrieved through the returned PendingHandles object. The object also provides access to the parameters with which the call was made and a signal to connect to to get notification of the request finishing processing. See the documentation for that class for more info.

The returned PendingHandles object should be freed using its QObject::deleteLater() method after it is no longer used. However, all PendingHandles objects resulting from requests to a particular Connection will be freed when the Connection itself is freed. Conversely, this means that the PendingHandles object should not be used after the Connection is destroyed.

See also:
  PendingHandles

Parameters:

  | handleType | Type of the handles given, as specified in HandleType.
  | handles | Handles to request a reference to.

Returns:
  Pointer to a newly constructed PendingHandles object, tracking the progress of the request.

PendingContactAttributes * Tp::Connection::contactAttributes | ( | const UIntList & | handles,
|  | const QStringList & | interfaces,
|  | bool | reference = `true` |
| ) |  |  |

Requests attributes for contacts. Optionally, the handles of the contacts will be referenced automatically. Essentially, this method wraps ConnectionInterfaceContactsInterface::GetContactAttributes(), integrating it with the rest of the handle-referencing machinery.

Upon completion, the reply to the request can be retrieved through the returned PendingContactAttributes object. The object also provides access to the parameters with which the call was made and a signal to connect to to get notification of the request finishing processing. See the documentation for that class for more info.

If the remote object doesn't support the Contacts interface (as signified by the list returned by interfaces() not containing TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS), the returned PendingContactAttributes instance will fail instantly with the error TELEPATHY_ERROR_NOT_IMPLEMENTED.

Similarly, if the connection isn't both connected and ready (`status() == StatusConnected && isReady()`), the returned PendingContactAttributes instance will fail instantly with the error TELEPATHY_ERROR_NOT_AVAILABLE.

This method requires Connection::FeatureCore to be enabled.

See also:
  PendingContactAttributes

Parameters:

  | handles | A list of handles of type HandleTypeContact
  | interfaces | D-Bus interfaces for which the client requires information
  | reference | Whether the handles should additionally be referenced.

Returns:
  Pointer to a newly constructed PendingContactAttributes, tracking the progress of the request.

QStringList Tp::Connection::contactAttributeInterfaces | ( |  | ) | const

ContactManager * Tp::Connection::contactManager | ( |  | ) | const

Return the ContactManager object for this connection.

The contact manager is responsible for all contact handling in this connection, including adding, removing, authorizing, etc.

Returns:
  A pointer to this connection ContactManager object. The returned object is owned by this connection and should not be freed.

DBus::PropertiesInterface * Tp::Connection::propertiesInterface | ( |  | ) | const`[inline]`

Convenience function for getting a Properties interface proxy. The Properties interface is not necessarily reported by the services, so a `check` parameter is not provided, and the interface is always assumed to be present.

See also:
  optionalInterface()

Returns:
  `optionalInterface<DBus::PropertiesInterface>(BypassInterfaceCheck)`

ConnectionInterfaceAliasingInterface * Tp::Connection::aliasingInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Convenience function for getting an Aliasing interface proxy.

Parameters:

  | check | Passed to optionalInterface()

Returns:
  `optionalInterface<ConnectionInterfaceAliasingInterface>(check)`

ConnectionInterfaceAvatarsInterface * Tp::Connection::avatarsInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Convenience function for getting an Avatars interface proxy.

Parameters:

  | check | Passed to optionalInterface()

Returns:
  `optionalInterface<ConnectionInterfaceAvatarsInterface>(check)`

ConnectionInterfaceCapabilitiesInterface * Tp::Connection::capabilitiesInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Convenience function for getting a Capabilities interface proxy.

Parameters:

  | check | Passed to optionalInterface()

Returns:
  `optionalInterface<ConnectionInterfaceCapabilitiesInterface>(check)`

Client::ConnectionInterfaceContactCapabilitiesInterface* Tp::Connection::contactCapabilitiesInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Client::ConnectionInterfaceLocationInterface* Tp::Connection::locationInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

ConnectionInterfacePresenceInterface * Tp::Connection::presenceInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Convenience function for getting a Presence interface proxy.

Parameters:

  | check | Passed to optionalInterface()

Returns:
  `optionalInterface<ConnectionInterfacePresenceInterface>(check)`

ConnectionInterfaceSimplePresenceInterface * Tp::Connection::simplePresenceInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

Convenience function for getting a SimplePresence interface proxy.

Parameters:

  | check | Passed to optionalInterface()

Returns:
  `optionalInterface<ConnectionInterfaceSimplePresenceInterface>(check)`

Client::ConnectionInterfaceRequestsInterface* Tp::Connection::requestsInterface | ( | InterfaceSupportedChecking | check = `CheckInterfaceSupported` | ) | const`[inline]`

void Tp::Connection::statusChanged | ( | Tp::Connection::Status | newStatus,
|  | Tp::ConnectionStatusReason | newStatusReason |
| ) |  |  | `[signal]`

void Tp::Connection::selfHandleChanged | ( | uint | newHandle | ) | `[signal]`

void Tp::Connection::selfContactChanged | ( |  | ) | `[signal]`

Client::ConnectionInterface * Tp::Connection::baseInterface | ( |  | ) | const`[protected]`

Return the ConnectionInterface for this Connection. This method is protected since the convenience methods provided by this class should generally be used instead of calling D-Bus methods directly.

Returns:
  A pointer to the existing ConnectionInterface for this Connection.

## Member Data Documentation

const Feature Tp::Connection::FeatureCore`[static]`

Feature representing the core that needs to become ready to make the Connection object usable.

Note that this feature must be enabled in order to use most Connection methods. See specific methods documentation for more details.

When calling isReady(), becomeReady(), this feature is implicitly added to the requested features.

const Feature Tp::Connection::FeatureSelfContact`[static]`

Feature used to retrieve the connection self contact.

See self contact specific methods' documentation for more details.

const Feature Tp::Connection::FeatureSimplePresence`[static]`

Feature used to retrieve/keep track of the connection self presence.

See simple presence specific methods' documentation for more details.

const Feature Tp::Connection::FeatureRoster`[static]`

Feature used to enable roster support on Connection::contactManager.

See ContactManager roster specific methods' documentation for more details.

const Feature Tp::Connection::FeatureRosterGroups`[static]`

Feature used to enable roster groups support on Connection::contactManager.

See ContactManager roster groups specific methods' documentation for more details.