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;
123 QPointer<Account> m_account;
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 =
nullptr;
159 void AccountServicePrivate::onEnabled(
AccountService *accountService,
162 Q_EMIT accountService->
enabled(isEnabled);
165 void AccountServicePrivate::onChanged(
AccountService *accountService)
167 Q_EMIT accountService->
changed();
175 AccountService::AccountService(Account *account,
const Service &service):
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,
387 void 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,
403 void 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);