accounts-qt: AccountService Class Reference

accounts-qt 1.17

Signals | Public Member Functions | List of all members
AccountService Class Reference

Account settings for a specific service. More...

`#include <Accounts/AccountService>`

Inherits QObject.

## Signals
void | enabled (bool isEnabled)
| Emitted when the enabledness state of the account service has changed.
void | changed ()
| Emitted when some setting has changed on the account service.

## Public Member Functions
| AccountService (Account *account, const Service &service)
| Constructor.
| AccountService (Account *account, const Service &service, QObject *parent)
| Constructor.
virtual | ~AccountService ()
| Destructor.
Account * | account () const
| Return the Account.
Service | service () const
| Return the Service.
bool | enabled () const
| Check whether the account service is enabled.
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.
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.
bool | contains (const QString &key) const
| Check whether the given key is in the current group.
void | endGroup ()
| Exit a group.
QString | group () const
| Return the name of the current group.
void | remove (const QString &key)
| Remove the given key.
void | setValue (const char *key, const QVariant &value)
void | setValue (const QString &key, const QVariant &value)
| Change the value of an account setting.
QVariant | value (const QString &key, const QVariant &defaultValue, SettingSource *source=nullptr) const
| Retrieves the value of an account setting, as a QVariant.
QVariant | value (const QString &key, SettingSource *source=nullptr) const
| Retrieves the value of an account setting.
QVariant | value (const char *key, SettingSource *source=nullptr) 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.
AuthData | authData () const
| Read the authentication data stored in the account (merging the service-specific settings with the global account settings).

## 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 one can use the Manager methods accountServices() or enabledAccountServices(), which both return a QList of account services. Note that if the Manager was instantiated for a specific service type, these lists will contain only those account services matching that service type. The AccountService can also be instantiated with its 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:

// Instantiate an account manager interested in e-mail services only.
Accounts::Manager *manager = new Accounts::Manager("e-mail");
// Get the list of enabled AccountService objects of type e-mail.
Accounts::AccountServiceList services = manager->enabledAccountServices();
// Loop through the account services and do something useful with them.
foreach (Accounts::AccountService service, services) {
QString server = service.value("pop3/hostname").toString();
int port = service.value("pop3/port").toInt();
// Suppose that the e-mail address is stored in the global account
// settings; let's get it from there:
QString fromAddress = service.account()->valueAsString("username");
...
}
Accounts::AccountService
Account settings for a specific service.
Definition: account-service.h:40
Accounts::AccountService::service
Service service() const
Return the Service.
Definition: account-service.cpp:212
Accounts::Manager
Manager of accounts, services and providers.
Definition: manager.h:52

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 changed() signal and checking if 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 changed() signal from the AccountService objects.

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

## Constructor & Destructor Documentation

## ◆ AccountService() [1/2]

AccountService | ( | Account * | account,
|  | const Service & | service
| ) |  |
| explicit

Constructor.

Parameters

  account | An Account.
  service | A Service supported by the account.

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

## ◆ AccountService() [2/2]

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

Constructor.

Parameters

  account | An Account.
  service | A Service supported by the account.
  parent | The parent object.

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

## ◆ ~AccountService()

~AccountService | ( |  | ) |
| virtual

Destructor.

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

## Member Function Documentation

## ◆ account()

Account * account | ( |  | ) | const

Return the Account.

Do not delete this object explicitly.

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

## ◆ allKeys()

QStringList allKeys | ( |  | ) | const

Return all the keys in the current group.

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

References AccountService::allKeys().

Referenced by AccountService::allKeys(), AccountService::childGroups(), AccountService::childKeys(), and AccountService::remove().

## ◆ authData()

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 495 of file account-service.cpp.

References AccountService::authData().

Referenced by AccountService::authData().

## ◆ beginGroup()

void beginGroup | ( | const QString & | prefix | ) |

Enter a group.

This method never fails.

Parameters

  prefix |

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

## ◆ changed

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.

## ◆ changedFields()

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 465 of file account-service.cpp.

References AccountService::changedFields().

Referenced by AccountService::changedFields().

## ◆ childGroups()

QStringList childGroups | ( |  | ) | const

Return all the groups which are direct children of the current group.

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

References AccountService::allKeys(), and AccountService::group().

## ◆ childKeys()

QStringList childKeys | ( |  | ) | const

Return all the keys which are direct children of the current group.

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

References AccountService::allKeys().

Referenced by AccountService::contains().

## ◆ clear()

void clear | ( |  | ) |

Remove all the keys.

See also
  remove(const QString &key)

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

References AccountService::remove().

## ◆ contains()

bool contains | ( | const QString & | key | ) | const

Check whether the given key is in the current group.

Parameters

  key | The key name of the setting.

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

References AccountService::childKeys().

## ◆ enabled()

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 225 of file account-service.cpp.

References AccountService::isEnabled().

## ◆ endGroup()

void endGroup | ( |  | ) |

Exit a group.

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

## ◆ group()

QString group | ( |  | ) | const

Return the name of the current group.

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

Referenced by AccountService::childGroups().

## ◆ isEnabled()

bool isEnabled | ( |  | ) | const

Check whether the account service is enabled.

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

Referenced by AccountService::enabled().

## ◆ remove()

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

  key | The key name of the setting.

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

References AccountService::allKeys(), and AccountService::remove().

Referenced by AccountService::clear(), and AccountService::remove().

## ◆ service()

Service service | ( |  | ) | const

Return the Service.

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

References AccountService::service().

Referenced by AccountService::service().

## ◆ setValue() [1/2]

void setValue | ( | const char * | key,
|  | const QVariant & | value
| ) |  |

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

## ◆ setValue() [2/2]

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

Change the value of an account setting.

Parameters

  key | The name of the setting.
  value | The new value of the setting.

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

References AccountService::value().

## ◆ value() [1/3]

QVariant value | ( | const char * | key,
|  | SettingSource * | source = `nullptr`
| ) |  | const

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

## ◆ value() [2/3]

QVariant value | ( | const QString & | key,
|  | const QVariant & | defaultValue,
|  | SettingSource * | source = `nullptr`
| ) |  | const

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

Parameters

  key | The key whose value must be retrieved.
  defaultValue | Value returned if the key is unset.
  source | Indicates 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 417 of file account-service.cpp.

Referenced by AccountService::setValue(), and AccountService::value().

## ◆ value() [3/3]

QVariant value | ( | const QString & | key,
|  | SettingSource * | source = `nullptr`
| ) |  | const

Retrieves the value of an account setting.

Parameters

  key | The key whose value must be retrieved
  source | Indicates 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 448 of file account-service.cpp.

References AccountService::value().

The documentation for this class was generated from the following files:

- Accounts/account-service.h
- Accounts/account-service.cpp