Accounts.AccountService

Account settings for a specific service. More...

#include <Accounts/AccountService>

Inherits QObject.

Signals

void isEnabled)
 Emitted when the enabledness state of the account service has changed.
 
void changed ()
 Emitted when some setting has changed on the account service. More...
 

Public Member Functions

 service)
 Constructor. More...
 
 service, QObject *parent)
 Constructor. More...
 
virtual ~AccountService ()
 Destructor.
 
Account * account () const
 Return the Account.
 
service () const
 Return the Service. More...
 
bool enabled () const
 Check whether the account service is enabled. More...
 
bool isEnabled () const
 Check whether the account service is enabled.
 
QStringList allKeys () const
 Return all the keys in the current group.
 
void beginGroup (const QString &prefix)
 Enter a group. More...
 
QStringList childGroups () const
 Return all the groups which are direct children of the current group.
 
QStringList childKeys () const
 Return all the keys which are direct children of the current group.
 
void clear ()
 Remove all the keys. More...
 
bool contains (const QString &key) const
 Check whether the given key is in the current group. More...
 
void endGroup ()
 Exit a group.
 
QString group () const
 Return the name of the current group.
 
void remove (const QString &key)
 Remove the given key. More...
 
void setValue (const char *key, const QVariant &value)
 
void value)
 Change the value of an account setting. More...
 
QVariant value (const QString &key, const QVariant &defaultValue, SettingSource *source=0) const
 Retrieves the value of an account setting, as a QVariant. More...
 
QVariant value (const QString &key, SettingSource *source=0) const
 Retrieves the value of an account setting. More...
 
QVariant value (const char *key, SettingSource *source=0) const
 
QStringList changedFields () const
 This method should be called only in the context of a handler of the AccountService::changed() signal, and can be used to retrieve the set of changes. More...
 
authData () const
 Read the authentication data stored in the account (merging the service-specific settings with the global account settings). More...
 

Detailed Description

Account settings for a specific service.

The AccountService class provides access to the account settings for a specific service type. It is meant to be easier to use than the Account class because it hides the complexity of the account structure and gives access to only the limited subset of account settings which are relevant to a service.

To get an AccountService(Account account, Service service) constructor: this is useful if one already has an Account instance.

This is intended to be a convenient wrapper over the accounts settings specific for a service; as such, it doesn't offer all the editing possibilities offered by the Account class, such as enabling the service itself: these operations should ideally not be performed by consumer applications, but by the account editing UI only.

Example code:

<span class="comment">// Instantiate an account manager interested in e-mail services only.</span>
<a class="code" href="Accounts.Manager.md">Accounts::Manager</a> *manager = <span class="keyword">new</span> <a class="code" href="Accounts.Manager.md">Accounts::Manager</a>(<span class="stringliteral">&quot;e-mail&quot;</span>);
<span class="comment">// Get the list of enabled AccountService objects of type e-mail.</span>
Accounts::AccountServiceList services = manager-&gt;enabledAccountServices();
<span class="comment">// Loop through the account services and do something useful with them.</span>
<span class="keywordflow">foreach</span> (<a class="code" href="#a256dc9d961214d5f60642a290a288998">service</a>, services) {
QString server = service.<a class="code" href="#a299df626e5ca7968fd8b70f9c87acfbb">value</a>(<span class="stringliteral">&quot;pop3/hostname&quot;</span>).toString();
<span class="keywordtype">int</span> port = service.<a class="code" href="#a299df626e5ca7968fd8b70f9c87acfbb">value</a>(<span class="stringliteral">&quot;pop3/port&quot;</span>).toInt();
<span class="comment">// Suppose that the e-mail address is stored in the global account</span>
<span class="comment">// settings; let&#39;s get it from there:</span>
QString fromAddress = service.<a class="code" href="#a490333c2ed4d6f107c5493a9465d993b">account</a>()-&gt;valueAsString(<span class="stringliteral">&quot;username&quot;</span>);
...
}
Note
User applications (with the notable exception of the accounts editing application) should never use account services which are not enabled, and should stop using an account when the account service becomes disabled. The latter can be done by connecting to the isEnabled() still returns true.
Note that if the account gets deleted, it will always get disabled first; so, there is no need to connect to the Account::removed() signal; one can just monitor the AccountService objects.

Definition at line 39 of file account-service.h.

Constructor & Destructor Documentation

AccountService ( Account *  account,
const Service service 
)
explicit

Constructor.

Parameters
accountAn Account.
serviceA Service supported by the account.

Definition at line 179 of file account-service.cpp.

AccountService ( Account *  account,
const Service service,
QObject *  parent 
)
explicit

Constructor.

Parameters
accountAn Account.
serviceA Service supported by the account.
parentThe parent object.

Definition at line 191 of file account-service.cpp.

Member Function Documentation

AuthData authData ( ) const

Read the authentication data stored in the account (merging the service-specific settings with the global account settings).

The method and mechanism are read from the "auth/method" and "auth/mechanism" keys, respectively. The authentication parameters are found under the "auth/<method>/<mechanism>/" group.

Returns
an AuthData object, describing the authentication settings.

Definition at line 501 of file account-service.cpp.

void beginGroup ( const QString &  prefix)

Enter a group.

This method never fails.

Parameters
prefix

Definition at line 271 of file account-service.cpp.

changed ( )
signal

Emitted when some setting has changed on the account service.

You can use the changedFields() method to retrieve the list of the settings which have changed.

QStringList changedFields ( ) const

This method should be called only in the context of a handler of the AccountService::changed() signal, and can be used to retrieve the set of changes.

Returns
a QStringList of the keys which have changed.

Definition at line 471 of file account-service.cpp.

void clear ( )

Remove all the keys.

See also
remove(const QString &key)

Definition at line 316 of file account-service.cpp.

bool contains ( const QString &  key) const

Check whether the given key is in the current group.

Parameters
keyThe key name of the setting.

Definition at line 331 of file account-service.cpp.

References AccountService::childKeys().

bool enabled ( ) const

Check whether the account service is enabled.

Note
this is just a wrapper of isEnabled
See also
isEnabled()
Deprecated:
use isEnabled instead

Definition at line 231 of file account-service.cpp.

References AccountService::isEnabled().

void remove ( const QString &  key)

Remove the given key.

If the key is the empty string, all keys in the current group are removed.

Parameters
keyThe key name of the setting.

Definition at line 363 of file account-service.cpp.

References AccountService::allKeys().

Service service ( ) const

Return the Service.

Do not delete this object explicitly.

Definition at line 218 of file account-service.cpp.

void setValue ( const QString &  key,
const QVariant &  value 
)

Change the value of an account setting.

Parameters
keyThe name of the setting.
valueThe new value of the setting.

Definition at line 391 of file account-service.cpp.

QVariant value ( const QString &  key,
const QVariant &  defaultValue,
SettingSource *  source = 0 
) const

Retrieves the value of an account setting, as a QVariant.

Parameters
keyThe key whose value must be retrieved.
defaultValueValue returned if the key is unset.
sourceIndicates whether the value comes from the account, the service template or was unset.
Returns
The value associated to key.

This method operates on the currently selected service.

Definition at line 423 of file account-service.cpp.

Referenced by AccountService::value().

QVariant value ( const QString &  key,
SettingSource *  source = 0 
) const

Retrieves the value of an account setting.

Parameters
keyThe key whose value must be retrieved
sourceIndicates whether the value comes from the account, the service template or was unset.

Returns the value of the setting, or an invalid QVariant if unset.

Definition at line 454 of file account-service.cpp.

References AccountService::value().