24 #include "account-service.h"
27 #include <libaccounts-glib/ag-account.h>
28 #include <libaccounts-glib/ag-account-service.h>
29 #include <libaccounts-glib/ag-auth-data.h>
105 class AccountServicePrivate
110 AccountServicePrivate(Account *account,
113 ~AccountServicePrivate();
116 static
void onEnabled(
AccountService *accountService, gboolean isEnabled);
119 ServiceList m_serviceList;
120 AgAccountService *m_accountService;
128 using namespace Accounts;
130 static QChar slash = QChar::fromLatin1('/');
132 AccountServicePrivate::AccountServicePrivate(Account *account,
135 m_manager(account->manager()),
136 q_ptr(accountService)
138 m_accountService = ag_account_service_new(account->account(),
140 g_signal_connect_swapped(m_accountService,
"enabled",
141 G_CALLBACK(&onEnabled), accountService);
142 g_signal_connect_swapped(m_accountService,
"changed",
143 G_CALLBACK(&onChanged), accountService);
146 AccountServicePrivate::~AccountServicePrivate()
149 g_signal_handlers_disconnect_by_func(m_accountService,
150 (
void *)&onEnabled, q);
151 g_signal_handlers_disconnect_by_func(m_accountService,
152 (
void *)&onChanged, q);
153 g_object_unref(m_accountService);
154 m_accountService = 0;
157 void AccountServicePrivate::onEnabled(
AccountService *accountService,
162 Q_EMIT accountService->
enabled(isEnabled);
165 void AccountServicePrivate::onChanged(
AccountService *accountService)
169 Q_EMIT accountService->
changed();
179 d_ptr(new AccountServicePrivate(account, service, this))
192 d_ptr(new AccountServicePrivate(account, service, this))
210 AgAccount *account = ag_account_service_get_account(d->m_accountService);
211 return new Account(account, d->m_manager);
220 AgService *service = ag_account_service_get_service(d->m_accountService);
230 return ag_account_service_get_enabled(d->m_accountService);
240 AgAccountSettingIter iter;
245 QByteArray tmp = d->prefix.toLatin1();
246 ag_account_service_settings_iter_init(d->m_accountService,
247 &iter, tmp.constData());
248 while (ag_account_settings_iter_get_next(&iter, &key, &val))
250 allKeys.append(ASCII(key));
262 d->prefix += prefix + slash;
270 QStringList groups, all_keys;
273 Q_FOREACH (QString key, all_keys)
275 if (key.contains(slash)) {
276 QString
group = key.section(slash, 0, 0);
277 if (!groups.contains(group))
278 groups.append(group);
289 QStringList keys, all_keys;
292 Q_FOREACH (QString key, all_keys)
294 if (!key.contains(slash))
309 QString saved_prefix = d->prefix;
310 d->prefix = QString();
312 d->prefix = saved_prefix;
330 d->prefix = d->prefix.section(slash, 0, -3,
331 QString::SectionIncludeTrailingSep);
332 if (d->prefix[0] == slash) d->prefix.remove(0, 1);
341 if (d->prefix.endsWith(slash))
342 return d->prefix.left(d->prefix.size() - 1);
358 Q_FOREACH (QString key, keys)
366 QString full_key = d->prefix + key;
367 QByteArray tmpkey = full_key.toLatin1();
368 ag_account_service_set_variant(d->m_accountService,
379 void AccountService::setValue(
const QString &key,
const QVariant &value)
383 GVariant *variant = qVariantToGVariant(value);
388 QString full_key = d->prefix + key;
389 QByteArray tmpkey = full_key.toLatin1();
390 ag_account_service_set_variant(d->m_accountService,
395 void AccountService::setValue(
const char *key,
const QVariant &value)
397 setValue(ASCII(key), value);
412 const QVariant &defaultValue,
413 SettingSource *source)
const
416 QString full_key = d->prefix + key;
417 QByteArray ba = full_key.toLatin1();
418 AgSettingSource settingSource;
420 ag_account_service_get_variant(d->m_accountService,
424 switch (settingSource) {
425 case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT;
break;
426 case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE;
break;
427 default: *source = NONE;
break;
431 return (variant != 0) ? gVariantToQVariant(variant) : defaultValue;
444 return value(key, QVariant(), source);
449 return value(ASCII(key), source);
464 ag_account_service_get_changed_fields(d->m_accountService);
467 if (changedFields == 0)
472 keyList.append(QString(ASCII(*keys)));
476 g_strfreev(changedFields);
493 AgAuthData *agAuthData =
494 ag_account_service_get_auth_data(d->m_accountService);