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>
107 class AccountServicePrivate
112 AccountServicePrivate(
Account *account,
115 ~AccountServicePrivate();
118 static
void onEnabled(
AccountService *accountService, gboolean isEnabled);
121 ServiceList m_serviceList;
122 AgAccountService *m_accountService;
130 using namespace Accounts;
132 static QChar slash = QChar::fromLatin1('/');
134 AccountServicePrivate::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);
148 AccountServicePrivate::~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 = 0;
159 void AccountServicePrivate::onEnabled(
AccountService *accountService,
164 Q_EMIT accountService->
enabled(isEnabled);
167 void AccountServicePrivate::onChanged(
AccountService *accountService)
171 Q_EMIT accountService->
changed();
181 d_ptr(new AccountServicePrivate(account, service, this))
194 d_ptr(new AccountServicePrivate(account, service, this))
221 AgService *service = ag_account_service_get_service(d->m_accountService);
242 return ag_account_service_get_enabled(d->m_accountService);
252 AgAccountSettingIter iter;
257 QByteArray tmp = d->prefix.toLatin1();
258 ag_account_service_settings_iter_init(d->m_accountService,
259 &iter, tmp.constData());
260 while (ag_account_settings_iter_get_next(&iter, &key, &val))
262 allKeys.append(ASCII(key));
274 d->prefix += prefix + slash;
282 QStringList groups, all_keys;
285 Q_FOREACH (QString key, all_keys)
287 if (key.contains(slash)) {
288 QString
group = key.section(slash, 0, 0);
289 if (!groups.contains(group))
290 groups.append(group);
301 QStringList keys, all_keys;
304 Q_FOREACH (QString key, all_keys)
306 if (!key.contains(slash))
321 QString saved_prefix = d->prefix;
322 d->prefix = QString();
324 d->prefix = saved_prefix;
342 d->prefix = d->prefix.section(slash, 0, -3,
343 QString::SectionIncludeTrailingSep);
344 if (d->prefix[0] == slash) d->prefix.remove(0, 1);
353 if (d->prefix.endsWith(slash))
354 return d->prefix.left(d->prefix.size() - 1);
370 Q_FOREACH (QString key, keys)
378 QString full_key = d->prefix + key;
379 QByteArray tmpkey = full_key.toLatin1();
380 ag_account_service_set_variant(d->m_accountService,
391 void AccountService::setValue(
const QString &key,
const QVariant &value)
395 GVariant *variant = qVariantToGVariant(value);
400 QString full_key = d->prefix + key;
401 QByteArray tmpkey = full_key.toLatin1();
402 ag_account_service_set_variant(d->m_accountService,
407 void AccountService::setValue(
const char *key,
const QVariant &value)
409 setValue(ASCII(key), value);
424 const QVariant &defaultValue,
425 SettingSource *source)
const
428 QString full_key = d->prefix + key;
429 QByteArray ba = full_key.toLatin1();
430 AgSettingSource settingSource;
432 ag_account_service_get_variant(d->m_accountService,
436 switch (settingSource) {
437 case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT;
break;
438 case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE;
break;
439 default: *source = NONE;
break;
443 return (variant != 0) ? gVariantToQVariant(variant) : defaultValue;
456 return value(key, QVariant(), source);
461 return value(ASCII(key), source);
476 ag_account_service_get_changed_fields(d->m_accountService);
479 if (changedFields == 0)
484 keyList.append(QString(ASCII(*keys)));
488 g_strfreev(changedFields);
505 AgAuthData *agAuthData =
506 ag_account_service_get_auth_data(d->m_accountService);