Home · All Classes · All Namespaces · Modules · Functions · Files
Classes | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions

Tp::Connection Class Reference
[Connection proxies]

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

#include <TelepathyQt4/Connection>

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

List of all members.

Classes

Signals

Public Member Functions

Static Public Member Functions

Static Public Attributes

Protected Member Functions


Detailed Description

The Connection class provides an object representing a Telepathy connection.

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 ConnectionStatusConnected 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


Constructor & Destructor Documentation

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

Class destructor.

Tp::Connection::Connection ( const QDBusConnection &  bus,
const QString &  busName,
const QString &  objectPath,
const ChannelFactoryConstPtr channelFactory,
const ContactFactoryConstPtr contactFactory,
const Feature coreFeature 
) [protected]

Construct a new connection object using the given bus.

A warning is printed if the factories are not for bus.

Parameters:
bus QDBusConnection to use.
busName The connection's well-known bus name (sometimes called a "service name").
objectPath The connection object path.
channelFactory The channel factory to use.
contactFactory The contact factory to use.
coreFeature The core feature of the Connection subclass. The corresponding introspectable should depend on Connection::FeatureCore.

Member Function Documentation

ConnectionPtr Tp::Connection::create ( const QString &  busName,
const QString &  objectPath,
const ChannelFactoryConstPtr channelFactory,
const ContactFactoryConstPtr contactFactory 
) [static]

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

A warning is printed if the factories are not for QDBusConnection::sessionBus().

Parameters:
busName The connection well-known bus name (sometimes called a "service name").
objectPath The connection object path.
channelFactory The channel factory to use.
contactFactory The contact factory to use.
Returns:
A ConnectionPtr pointing to the newly created Connection.
ConnectionPtr Tp::Connection::create ( const QDBusConnection &  bus,
const QString &  busName,
const QString &  objectPath,
const ChannelFactoryConstPtr channelFactory,
const ContactFactoryConstPtr contactFactory 
) [static]

Create a new connection object using the given bus.

A warning is printed if the factories are not for bus.

Parameters:
bus QDBusConnection to use.
busName The connection well-known bus name (sometimes called a "service name").
objectPath The connection object path.
channelFactory The channel factory to use.
contactFactory The contact factory to use.
Returns:
A ConnectionPtr pointing to the newly created Connection.
ChannelFactoryConstPtr Tp::Connection::channelFactory (  )  const

Get the channel factory used by this connection.

Only read access is provided. This allows constructing object instances and examining the object construction settings, but not changing settings. Allowing changes would lead to tricky situations where objects constructed at different times by the account would have unpredictably different construction settings (eg. subclass).

Returns:
Read-only pointer to the factory.
ContactFactoryConstPtr Tp::Connection::contactFactory (  )  const

Get the contact factory used by this connection.

Only read access is provided. This allows constructing object instances and examining the object construction settings, but not changing settings. Allowing changes would lead to tricky situations where objects constructed at different times by the account would have unpredictably different construction settings (eg. subclass).

Returns:
Read-only pointer to the factory.
QString Tp::Connection::cmName (  )  const
QString Tp::Connection::protocolName (  )  const
ConnectionStatus 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 ConnectionStatus.
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.

The status reason should be only used as a fallback in error handling when the application doesn't understand an error name given as the invalidation reason, which may in some cases be domain/UI-specific.

See also:
invalidated(), invalidationReason()
Returns:
The reason, as defined in ConnectionStatusReason.
const Connection::ErrorDetails & Tp::Connection::errorDetails (  )  const

Returns detailed information about the reason for the connection going invalidated().

Some services may provide additional error information in the ConnectionError D-Bus signal, when a Connection is disconnected / has become unusable. If the service didn't provide any, or has not been invalidated yet, an invalid instance is returned.

The information provided by invalidationReason() and this method should always be used in error handling in preference to statusReason(). The status reason can be used as a fallback, however, if the client doesn't understand what a particular value returned by invalidationReason() means, as it may be domain-specific with some services.

Returns:
The error details.
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 ConnectionStatusConnected 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.
CurrencyAmount Tp::Connection::accountBalance (  )  const

Return the user's balance on the account corresponding to this connection. A negative amount may be possible on some services, and indicates that the user owes money to the service provider.

Returns:
The user's balance.
See also:
accountBalanceChanged()
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.
ContactManagerPtr 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:
Pointer to this connection ContactManager object.
void Tp::Connection::statusChanged ( Tp::ConnectionStatus  newStatus  )  [signal]

Indicates that the connection's status has changed and that all previously requested features are now ready to use for the new status.

Legitimate uses for this signal, apart from waiting for a given connection status to be ready, include updating an animation based on the connection being in ConnectionStatusConnecting, ConnectionStatusConnected and ConnectionStatusDisconnected, and otherwise showing progress indication to the user. It should, however, NEVER be used for error handling:

This signal doesn't contain the status reason as an argument, because statusChanged() shouldn't be used for error-handling. There are numerous cases in which a Connection may become unusable without there being an status change to ConnectionStatusDisconnected. All of these cases, and being disconnected itself, are signaled by invalidated() with appropriate error names. On the other hand, the reason for the status going to ConnectionStatusConnecting or ConnectionStatusConnected will always be ConnectionStatusReasonRequested, so signaling that would be useless.

The status reason, as returned by statusReason(), may however be used as a fallback for error handling in slots connected to the invalidated() signal, if the client doesn't understand a particular (likely domain-specific if so) error name given by invalidateReason().

Parameters:
newStatus The new status of the connection, as would be returned by status().
void Tp::Connection::selfHandleChanged ( uint  newHandle  )  [signal]
void Tp::Connection::selfContactChanged (  )  [signal]
void Tp::Connection::accountBalanceChanged ( const Tp::CurrencyAmount accountBalance  )  [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

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.

Feature used to retrieve the connection self contact.

See self contact specific methods' documentation for more details.

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

See simple presence specific methods' documentation for more details.

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

See ContactManager roster specific methods' documentation for more details.

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

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

Feature used to retrieve/keep track of the connection account balance.

See account balance specific methods' documentation for more details.

When this feature is prepared, it means that the connection status() is ConnectionStatusConnected.

Note that if ConnectionFactory is being used with FeatureConnected set, Connection objects will only be signalled by the library when the corresponding connection is in status() ConnectionStatusConnected.


Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.5.14