25#include "account-service.h" 
   29#include <libaccounts-glib/ag-account.h> 
   30#include <libaccounts-glib/ag-account-service.h> 
   31#include <libaccounts-glib/ag-auth-data.h> 
  107class AccountServicePrivate
 
  112    AccountServicePrivate(Account *account,
 
  115    ~AccountServicePrivate();
 
  118    static void onEnabled(
AccountService *accountService, gboolean isEnabled);
 
  121    ServiceList m_serviceList;
 
  122    AgAccountService *m_accountService;
 
  123    QPointer<Account> m_account;
 
  130using namespace Accounts;
 
  132static QChar slash = QChar::fromLatin1(
'/');
 
  134AccountServicePrivate::AccountServicePrivate(Account *account,
 
  138    q_ptr(accountService)
 
  140    m_accountService = ag_account_service_new(account->account(),
 
  142    g_signal_connect_swapped(m_accountService, 
"enabled",
 
  143                             G_CALLBACK(&onEnabled), accountService);
 
  144    g_signal_connect_swapped(m_accountService, 
"changed",
 
  145                             G_CALLBACK(&onChanged), accountService);
 
  148AccountServicePrivate::~AccountServicePrivate()
 
  151    g_signal_handlers_disconnect_by_func(m_accountService,
 
  152                                         (
void *)&onEnabled, q);
 
  153    g_signal_handlers_disconnect_by_func(m_accountService,
 
  154                                         (
void *)&onChanged, q);
 
  155    g_object_unref(m_accountService);
 
  156    m_accountService = 
nullptr;
 
  159void AccountServicePrivate::onEnabled(
AccountService *accountService,
 
  162    Q_EMIT accountService->
enabled(isEnabled);
 
  165void AccountServicePrivate::onChanged(
AccountService *accountService)
 
  167    Q_EMIT accountService->
changed();
 
  177    d_ptr(new AccountServicePrivate(account, service, this))
 
 
  190    d_ptr(new AccountServicePrivate(account, service, this))
 
 
  217    AgService *
service = ag_account_service_get_service(d->m_accountService);
 
 
  238    return ag_account_service_get_enabled(d->m_accountService);
 
 
  248    AgAccountSettingIter iter;
 
  253    QByteArray tmp = d->prefix.toLatin1();
 
  254    ag_account_service_settings_iter_init(d->m_accountService,
 
  255                                          &iter, tmp.constData());
 
  256    while (ag_account_settings_iter_get_next(&iter, &key, &val))
 
 
  270    d->prefix += prefix + slash;
 
 
  278    QStringList groups, all_keys;
 
  281    Q_FOREACH (
const QString &key, all_keys)
 
  283        if (key.contains(slash)) {
 
  284            QString 
group = key.section(slash, 0, 0);
 
  285            if (!groups.contains(
group))
 
  286                groups.append(
group);
 
 
  297    QStringList keys, all_keys;
 
  300    Q_FOREACH (
const QString &key, all_keys)
 
  302        if (!key.contains(slash))
 
 
  317    QString saved_prefix = d->prefix;
 
  318    d->prefix = QString();
 
  320    d->prefix = saved_prefix;
 
 
  338    d->prefix = d->prefix.section(slash, 0, -3,
 
  339                                  QString::SectionIncludeTrailingSep);
 
  340    if (d->prefix[0] == slash) d->prefix.remove(0, 1);
 
 
  349    if (d->prefix.endsWith(slash))
 
  350        return d->prefix.left(d->prefix.size() - 1);
 
 
  366        Q_FOREACH (
const QString &key, keys)
 
  374        QString full_key = d->prefix + key;
 
  375        QByteArray tmpkey = full_key.toLatin1();
 
  376        ag_account_service_set_variant(d->m_accountService,
 
 
  387void AccountService::setValue(
const QString &key, 
const QVariant &value)
 
  391    GVariant *variant = qVariantToGVariant(
value);
 
  392    if (variant == 
nullptr) {
 
  396    QString full_key = d->prefix + key;
 
  397    QByteArray tmpkey = full_key.toLatin1();
 
  398    ag_account_service_set_variant(d->m_accountService,
 
 
  403void AccountService::setValue(
const char *key, 
const QVariant &value)
 
  405    setValue(ASCII(key), 
value);
 
  420                               const QVariant &defaultValue,
 
  421                               SettingSource *source)
 const 
  424    QString full_key = d->prefix + key;
 
  425    QByteArray ba = full_key.toLatin1();
 
  426    AgSettingSource settingSource;
 
  428        ag_account_service_get_variant(d->m_accountService,
 
  431    if (source != 
nullptr) {
 
  432        switch (settingSource) {
 
  433        case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT; 
break;
 
  434        case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE; 
break;
 
  435        default: *source = NONE; 
break;
 
  439    return (variant != 
nullptr) ? gVariantToQVariant(variant) : defaultValue;
 
 
  452    return value(key, QVariant(), source);
 
 
  457    return value(ASCII(key), source);
 
  472        ag_account_service_get_changed_fields(d->m_accountService);
 
  479    while (*keys != 
nullptr) {
 
  480        keyList.append(QString(ASCII(*keys)));
 
 
  501    AgAuthData *agAuthData =
 
  502        ag_account_service_get_auth_data(d->m_accountService);
 
  504    ag_auth_data_unref(agAuthData);
 
 
Account settings for a specific service.
Service service() const
Return the Service.
virtual ~AccountService()
Destructor.
QStringList allKeys() const
Return all the keys in the current group.
void changed()
Emitted when some setting has changed on the account service.
QStringList childGroups() const
Return all the groups which are direct children of the current group.
Account * account() const
Return the Account.
bool contains(const QString &key) const
Check whether the given key is in the current group.
QVariant value(const QString &key, const QVariant &defaultValue, SettingSource *source=nullptr) const
Retrieves the value of an account setting, as a QVariant.
AuthData authData() const
Read the authentication data stored in the account (merging the service-specific settings with the gl...
void remove(const QString &key)
Remove the given key.
QStringList childKeys() const
Return all the keys which are direct children of the current group.
void beginGroup(const QString &prefix)
Enter a group.
bool isEnabled() const
Check whether the account service is enabled.
QStringList changedFields() const
This method should be called only in the context of a handler of the AccountService::changed() signal...
void clear()
Remove all the keys.
QString group() const
Return the name of the current group.
AccountService(Account *account, const Service &service)
Constructor.
bool enabled() const
Check whether the account service is enabled.
void endGroup()
Exit a group.
Information for account authentication.
Representation of an account service.