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();
178 d_ptr(new AccountServicePrivate(account, service, this))
196 AgAccount *account = ag_account_service_get_account(d->m_accountService);
197 AgAccountId account_id = account->id;
199 return d->m_manager->account(account_id);
208 AgService *service = ag_account_service_get_service(d->m_accountService);
218 return ag_account_service_get_enabled(d->m_accountService);
228 AgAccountSettingIter iter;
233 QByteArray tmp = d->prefix.toLatin1();
234 ag_account_service_settings_iter_init(d->m_accountService,
235 &iter, tmp.constData());
236 while (ag_account_service_settings_iter_next(&iter, &key, &val))
238 allKeys.append(ASCII(key));
250 d->prefix += prefix + slash;
258 QStringList groups, all_keys;
261 foreach (QString key, all_keys)
263 if (key.contains(slash)) {
264 QString
group = key.section(slash, 0, 0);
265 if (!groups.contains(group))
266 groups.append(group);
277 QStringList keys, all_keys;
280 foreach (QString key, all_keys)
282 if (!key.contains(slash))
297 QString saved_prefix = d->prefix;
298 d->prefix = QString();
300 d->prefix = saved_prefix;
318 d->prefix = d->prefix.section(slash, 0, -3,
319 QString::SectionIncludeTrailingSep);
320 if (d->prefix[0] == slash) d->prefix.remove(0, 1);
329 if (d->prefix.endsWith(slash))
330 return d->prefix.left(d->prefix.size() - 1);
346 foreach (QString key, keys)
354 QString full_key = d->prefix + key;
355 QByteArray tmpkey = full_key.toLatin1();
356 ag_account_service_set_value(d->m_accountService,
367 void AccountService::setValue(
const QString &key,
const QVariant &value)
371 GValue val= {0, {{0}}};
373 if (!variantToGValue(value, &val)) {
377 QString full_key = d->prefix + key;
378 QByteArray tmpkey = full_key.toLatin1();
379 ag_account_service_set_value(d->m_accountService,
385 void AccountService::setValue(
const char *key,
const QVariant &value)
387 setValue(ASCII(key), value);
401 GValue val= {0, {{0}}};
402 g_value_init(&val, G_TYPE_STRING);
403 QString full_key = d->prefix + key;
404 QByteArray ba = full_key.toLatin1();
405 AgSettingSource agSource =
406 ag_account_service_get_value(d->m_accountService,
407 ba.constData(), &val);
410 case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT;
break;
411 case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE;
break;
412 default: *source = NONE;
break;
417 if (agSource == AG_SETTING_SOURCE_NONE)
420 variant = UTF8(g_value_get_string(&val));
428 return value(ASCII(key), source);
443 ag_account_service_get_changed_fields(d->m_accountService);
446 if (changedFields == 0)
451 keyList.append(QString(ASCII(*keys)));
455 g_strfreev(changedFields);
472 AgAuthData *agAuthData =
473 ag_account_service_get_auth_data(d->m_accountService);