Skip to content

Commit

Permalink
dir: Use new AccountsService feature to get languages
Browse files Browse the repository at this point in the history
Use the new GetUsersLanguages() method from AccountsService to get the
list of all the locales that each user is interested in.

See https://gitlab.freedesktop.org/accountsservice/accountsservice/-/merge_requests/99

Closes: #5006
  • Loading branch information
hadess committed Jul 28, 2022
1 parent bf37034 commit f1c87f1
Showing 1 changed file with 54 additions and 11 deletions.
65 changes: 54 additions & 11 deletions common/flatpak-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -16081,6 +16081,45 @@ get_accounts_dbus_proxy (void)
NULL);
}

static gboolean
get_all_langs_from_accounts_dbus (GDBusProxy *proxy, GPtrArray *langs)
{
g_auto(GStrv) all_langs = NULL;
int i;
g_autoptr(GVariant) ret = NULL;
g_autoptr(GError) error = NULL;

ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),
"GetUsersLanguages",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (!ret)
{
g_debug ("Failed to get languages for all users: %s", error->message);
return FALSE;
}

g_variant_get (ret,
"(^as)",
&all_langs);

if (all_langs != NULL)
{
for (i = 0; all_langs[i] != NULL; i++)
{
g_autofree char *lang = NULL;
lang = flatpak_get_lang_from_locale (all_langs[i]);
if (lang != NULL && !flatpak_g_ptr_array_contains_string (langs, lang))
g_ptr_array_add (langs, g_steal_pointer (&lang));
}
}

return TRUE;
}

static void
get_locale_langs_from_accounts_dbus (GDBusProxy *proxy, GPtrArray *langs)
{
Expand Down Expand Up @@ -16179,20 +16218,24 @@ get_system_locales (FlatpakDir *self)
g_autoptr(GDBusProxy) localed_proxy = NULL;
g_autoptr(GDBusProxy) accounts_proxy = NULL;

/* Get the system default locales */
localed_proxy = get_localed_dbus_proxy ();
if (localed_proxy != NULL)
get_locale_langs_from_localed_dbus (localed_proxy, langs);

/* Now add the user account locales from AccountsService. If accounts_proxy is
* not NULL, it means that AccountsService exists */
accounts_proxy = get_accounts_dbus_proxy ();
if (accounts_proxy != NULL)
get_locale_langs_from_accounts_dbus (accounts_proxy, langs);
if (!get_all_langs_from_accounts_dbus (accounts_proxy, langs))
{

g_ptr_array_add (langs, NULL);
/* Get the system default locales */
localed_proxy = get_localed_dbus_proxy ();
if (localed_proxy != NULL)
get_locale_langs_from_localed_dbus (localed_proxy, langs);

g_once_init_leave (&cached, langs);
/* Now add the user account locales from AccountsService. If accounts_proxy is
* not NULL, it means that AccountsService exists */
if (accounts_proxy != NULL)
get_locale_langs_from_accounts_dbus (accounts_proxy, langs);

g_ptr_array_add (langs, NULL);

g_once_init_leave (&cached, langs);
}
}

return (const GPtrArray *)cached;
Expand Down

0 comments on commit f1c87f1

Please sign in to comment.