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);
231 return ag_account_service_get_enabled(d->m_accountService);
241 AgAccountSettingIter iter;
246 QByteArray tmp = d->prefix.toLatin1();
247 ag_account_service_settings_iter_init(d->m_accountService,
248 &iter, tmp.constData());
249 while (ag_account_settings_iter_get_next(&iter, &key, &val))
251 allKeys.append(ASCII(key));
263 d->prefix += prefix + slash;
271 QStringList groups, all_keys;
274 Q_FOREACH (QString key, all_keys)
276 if (key.contains(slash)) {
277 QString
group = key.section(slash, 0, 0);
278 if (!groups.contains(group))
279 groups.append(group);
290 QStringList keys, all_keys;
293 Q_FOREACH (QString key, all_keys)
295 if (!key.contains(slash))
310 QString saved_prefix = d->prefix;
311 d->prefix = QString();
313 d->prefix = saved_prefix;
331 d->prefix = d->prefix.section(slash, 0, -3,
332 QString::SectionIncludeTrailingSep);
333 if (d->prefix[0] == slash) d->prefix.remove(0, 1);
342 if (d->prefix.endsWith(slash))
343 return d->prefix.left(d->prefix.size() - 1);
359 Q_FOREACH (QString key, keys)
367 QString full_key = d->prefix + key;
368 QByteArray tmpkey = full_key.toLatin1();
369 ag_account_service_set_variant(d->m_accountService,
380 void AccountService::setValue(
const QString &key,
const QVariant &value)
384 GVariant *variant = qVariantToGVariant(value);
389 QString full_key = d->prefix + key;
390 QByteArray tmpkey = full_key.toLatin1();
391 ag_account_service_set_variant(d->m_accountService,
396 void AccountService::setValue(
const char *key,
const QVariant &value)
398 setValue(ASCII(key), value);
413 const QVariant &defaultValue,
414 SettingSource *source)
const
417 QString full_key = d->prefix + key;
418 QByteArray ba = full_key.toLatin1();
419 AgSettingSource settingSource;
421 ag_account_service_get_variant(d->m_accountService,
425 switch (settingSource) {
426 case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT;
break;
427 case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE;
break;
428 default: *source = NONE;
break;
432 return (variant != 0) ? gVariantToQVariant(variant) : defaultValue;
445 return value(key, QVariant(), source);
450 return value(ASCII(key), source);
465 ag_account_service_get_changed_fields(d->m_accountService);
468 if (changedFields == 0)
473 keyList.append(QString(ASCII(*keys)));
477 g_strfreev(changedFields);
494 AgAuthData *agAuthData =
495 ag_account_service_get_auth_data(d->m_accountService);