Home · All Classes · All Namespaces · Modules · Functions · Files |
The Connection class represents a Telepathy connection. More...
#include <TelepathyQt4/Connection>
Inherits Tp::StatefulDBusProxy, and OptionalInterfaceFactory< Connection >.
The Connection class represents a Telepathy connection.
This models a connection to a single user account on a communication service.
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 accessor functions on this object (status(), statusReason(), and so on) don't make any D-Bus calls; instead, they return/use 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.
To avoid unnecessary D-Bus traffic, some accessors only return valid information after specific features have been enabled. For instance, to retrieve the connection self contact, it is necessary to enable the feature Connection::FeatureSelfContact. See the individual methods descriptions for more details.
Connection features can be enabled by constructing a ConnectionFactory and enabling the desired features, and passing it to AccountManager, Account or ClientRegistrar when creating them as appropriate. However, if a particular feature is only ever used in a specific circumstance, such as an user opening some settings dialog separate from the general view of the application, features can be later enabled as needed by calling becomeReady() with the additional features, and waiting for the resulting PendingOperation to finish.
As an addition to accessors, signals are emitted to indicate that properties have changed, for example statusChanged()(), selfContactChanged(), etc.
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);
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
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.
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. |
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().
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. |
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.
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. |
ChannelFactoryConstPtr Tp::Connection::channelFactory | ( | ) | const |
Return 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).
ContactFactoryConstPtr Tp::Connection::contactFactory | ( | ) | const |
Return 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).
QString Tp::Connection::cmName | ( | ) | const |
Return the connection manager name of this connection.
QString Tp::Connection::protocolName | ( | ) | const |
Return the protocol name of this connection.
ConnectionStatus Tp::Connection::status | ( | ) | const |
Return the status of this connection.
Change notification is via the statusChanged() signal.
This method requires Connection::FeatureCore to be ready.
ConnectionStatusReason Tp::Connection::statusReason | ( | ) | const |
Return the reason for this connection status.
The validity and change rules are the same as for status().
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.
This method requires Connection::FeatureCore to be ready.
const Connection::ErrorDetails & Tp::Connection::errorDetails | ( | ) | const |
Return 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.
uint Tp::Connection::selfHandle | ( | ) | const |
Return the handle representing the user on this connection.
Note that if the connection is not yet in the ConnectionStatusConnected state, the value of this property may be zero.
Change notification is via the selfHandleChanged() signal.
This method requires Connection::FeatureCore to be ready.
ContactPtr Tp::Connection::selfContact | ( | ) | const |
Return the object representing the user on this connection.
Note that if the connection is not yet in the ConnectionStatusConnected state, the value of this property may be null.
Change notification is via the selfContactChanged() signal.
This method requires Connection::FeatureSelfContact to be ready.
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.
Change notification is via the accountBalanceChanged() signal.
This method requires Connection::FeatureAccountBalance to be ready.
ConnectionCapabilities Tp::Connection::capabilities | ( | ) | const |
Return the capabilities for this connection.
User interfaces can use this information to show or hide UI components.
This property cannot change after the connection has gone to state ConnectionStatusConnected, so there is no change notification.
This method requires Connection::FeatureCore to be ready.
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.
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 a 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().
newStatus | The new status of the connection, as would be returned by status(). |
void Tp::Connection::selfHandleChanged | ( | uint | newHandle | ) | [signal] |
Emitted when the value of selfHandle() changes.
newHandle | The new connection self handle. |
void Tp::Connection::selfContactChanged | ( | ) | [signal] |
Emitted when the value of selfContact() changes.
void Tp::Connection::accountBalanceChanged | ( | const Tp::CurrencyAmount & | accountBalance | ) | [signal] |
Emitted when the value of accountBalance() changes.
accountBalance | The new user's balance of this connection. |
Client::ConnectionInterface * Tp::Connection::baseInterface | ( | ) | const [protected] |
Return the Client::ConnectionInterface interface proxy object 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.
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.
const Feature Tp::Connection::FeatureAccountBalance [static] |
Feature used to retrieve/keep track of the connection account balance.
See account balance specific methods' documentation for more details.
const Feature Tp::Connection::FeatureConnected [static] |
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.6.5
|