25 #include "account-service.h" 29 #include <libaccounts-glib.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;
121 QPointer<Account> m_account;
130 static QChar slash = QChar::fromLatin1(
'/');
132 AccountServicePrivate::AccountServicePrivate(Account *account,
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 =
nullptr;
157 void AccountServicePrivate::onEnabled(
AccountService *accountService,
160 Q_EMIT accountService->
enabled(isEnabled);
163 void AccountServicePrivate::onChanged(
AccountService *accountService)
165 Q_EMIT accountService->
changed();
173 AccountService::AccountService(Account *account,
const Service &service):
175 d_ptr(new AccountServicePrivate(account, service, this))
188 d_ptr(new AccountServicePrivate(account, service, this))
215 AgService *
service = ag_account_service_get_service(d->m_accountService);
236 return ag_account_service_get_enabled(d->m_accountService);
246 AgAccountSettingIter iter;
251 QByteArray tmp = d->prefix.toLatin1();
252 ag_account_service_settings_iter_init(d->m_accountService,
253 &iter, tmp.constData());
254 while (ag_account_settings_iter_get_next(&iter, &key, &val))
268 d->prefix += prefix + slash;
276 QStringList groups, all_keys;
279 Q_FOREACH (
const QString &key, all_keys)
281 if (key.contains(slash)) {
282 QString
group = key.section(slash, 0, 0);
283 if (!groups.contains(
group))
284 groups.append(
group);
295 QStringList keys, all_keys;
298 Q_FOREACH (
const QString &key, all_keys)
300 if (!key.contains(slash))
315 QString saved_prefix = d->prefix;
316 d->prefix = QString();
318 d->prefix = saved_prefix;
336 d->prefix = d->prefix.section(slash, 0, -3,
337 QString::SectionIncludeTrailingSep);
338 if (!d->prefix.isEmpty() && d->prefix[0] == slash) d->prefix.remove(0, 1);
347 if (d->prefix.endsWith(slash))
348 return d->prefix.left(d->prefix.size() - 1);
364 Q_FOREACH (
const QString &key, keys)
372 QString full_key = d->prefix + key;
373 QByteArray tmpkey = full_key.toLatin1();
374 ag_account_service_set_variant(d->m_accountService,
385 void AccountService::setValue(
const QString &key,
const QVariant &value)
389 GVariant *variant = qVariantToGVariant(
value);
390 if (variant ==
nullptr) {
394 QString full_key = d->prefix + key;
395 QByteArray tmpkey = full_key.toLatin1();
396 ag_account_service_set_variant(d->m_accountService,
401 void AccountService::setValue(
const char *key,
const QVariant &value)
403 setValue(ASCII(key),
value);
418 const QVariant &defaultValue,
419 SettingSource *source)
const 422 QString full_key = d->prefix + key;
423 QByteArray ba = full_key.toLatin1();
424 AgSettingSource settingSource;
426 ag_account_service_get_variant(d->m_accountService,
429 if (source !=
nullptr) {
430 switch (settingSource) {
431 case AG_SETTING_SOURCE_ACCOUNT: *source = ACCOUNT;
break;
432 case AG_SETTING_SOURCE_PROFILE: *source = TEMPLATE;
break;
433 default: *source = NONE;
break;
437 return (variant !=
nullptr) ? gVariantToQVariant(variant) : defaultValue;
450 return value(key, QVariant(), source);
455 return value(ASCII(key), source);
470 ag_account_service_get_changed_fields(d->m_accountService);
477 while (*keys !=
nullptr) {
478 keyList.append(QString(ASCII(*keys)));
499 AgAuthData *agAuthData =
500 ag_account_service_get_auth_data(d->m_accountService);
502 ag_auth_data_unref(agAuthData);
QStringList allKeys() const
Return all the keys in the current group.
AuthData authData() const
Read the authentication data stored in the account (merging the service-specific settings with the gl...
void clear()
Remove all the keys.
Account settings for a specific service.
QStringList childGroups() const
Return all the groups which are direct children of the current group.
bool isEnabled() const
Check whether the account service is enabled.
QVariant value(const QString &key, const QVariant &defaultValue, SettingSource *source=nullptr) const
Retrieves the value of an account setting, as a QVariant.
void remove(const QString &key)
Remove the given key.
QStringList changedFields() const
This method should be called only in the context of a handler of the AccountService::changed() signal...
void endGroup()
Exit a group.
Service service() const
Return the Service.
QStringList childKeys() const
Return all the keys which are direct children of the current group.
virtual ~AccountService()
Destructor.
QString group() const
Return the name of the current group.
bool enabled() const
Check whether the account service is enabled.
Representation of an account service.
Information for account authentication.
void beginGroup(const QString &prefix)
Enter a group.
void changed()
Emitted when some setting has changed on the account service.
Account * account() const
Return the Account.
bool contains(const QString &key) const
Check whether the given key is in the current group.
AccountService(Account *account, const Service &service)
Constructor.