[gnome-software] Add gs_plugin_get_language()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add gs_plugin_get_language()
- Date: Mon, 4 Jul 2016 19:44:16 +0000 (UTC)
commit 613aaea61ad081699a63fcf274b6f5ad1de330b6
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 4 20:31:48 2016 +0100
Add gs_plugin_get_language()
Two plugins require this, so it makes sense to share code.
src/gs-plugin-loader.c | 11 ++++++++++-
src/gs-plugin-private.h | 2 ++
src/gs-plugin.c | 32 ++++++++++++++++++++++++++++++++
src/gs-plugin.h | 1 +
4 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 679300a..f9ff859 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -41,6 +41,7 @@ typedef struct
GPtrArray *plugins;
gchar *location;
gchar *locale;
+ gchar *language;
GsPluginStatus status_last;
AsProfile *profile;
SoupSession *soup_session;
@@ -3405,6 +3406,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
gs_plugin_set_auth_array (plugin, priv->auth_array);
gs_plugin_set_profile (plugin, priv->profile);
gs_plugin_set_locale (plugin, priv->locale);
+ gs_plugin_set_language (plugin, priv->language);
gs_plugin_set_scale (plugin, gs_plugin_loader_get_scale (plugin_loader));
g_debug ("opened plugin %s: %s", filename, gs_plugin_get_name (plugin));
@@ -3798,6 +3800,7 @@ gs_plugin_loader_finalize (GObject *object)
g_strfreev (priv->compatible_projects);
g_free (priv->location);
g_free (priv->locale);
+ g_free (priv->language);
g_mutex_clear (&priv->pending_apps_mutex);
@@ -3843,6 +3846,7 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
const gchar *tmp;
+ gchar *match;
gchar **projects;
guint i;
@@ -3867,7 +3871,6 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
g_debug ("using self test locale of %s", tmp);
priv->locale = g_strdup (tmp);
} else {
- gchar *match;
priv->locale = g_strdup (setlocale (LC_MESSAGES, NULL));
match = g_strstr_len (priv->locale, -1, ".UTF-8");
if (match != NULL)
@@ -3877,6 +3880,12 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
*match = '\0';
}
+ /* get the language from the locale */
+ priv->language = g_strdup (priv->locale);
+ match = g_strrstr (priv->language, "_");
+ if (match != NULL)
+ *match = '\0';
+
g_mutex_init (&priv->pending_apps_mutex);
/* by default we only show project-less apps or compatible projects */
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index 4ce3579..3566449 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -48,6 +48,8 @@ void gs_plugin_set_priority (GsPlugin *plugin,
guint priority);
void gs_plugin_set_locale (GsPlugin *plugin,
const gchar *locale);
+void gs_plugin_set_language (GsPlugin *plugin,
+ const gchar *language);
void gs_plugin_set_profile (GsPlugin *plugin,
AsProfile *profile);
void gs_plugin_set_auth_array (GsPlugin *plugin,
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 302d107..a14ec53 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -66,6 +66,7 @@ typedef struct
GPtrArray *rules[GS_PLUGIN_RULE_LAST];
gboolean enabled;
gchar *locale; /* allow-none */
+ gchar *language; /* allow-none */
gchar *name;
gint scale;
guint order;
@@ -182,6 +183,7 @@ gs_plugin_finalize (GObject *object)
g_free (priv->name);
g_free (priv->data);
g_free (priv->locale);
+ g_free (priv->language);
g_rw_lock_clear (&priv->rwlock);
g_object_unref (priv->profile);
g_ptr_array_unref (priv->auth_array);
@@ -466,6 +468,21 @@ gs_plugin_get_locale (GsPlugin *plugin)
}
/**
+ * gs_plugin_get_language:
+ * @plugin: a #GsPlugin
+ *
+ * Gets the user language from the locale.
+ *
+ * Returns: the language string, e.g. "fr"
+ **/
+const gchar *
+gs_plugin_get_language (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->language;
+}
+
+/**
* gs_plugin_set_locale:
* @plugin: a #GsPlugin
* @locale: a locale string, e.g. "en_GB"
@@ -481,6 +498,21 @@ gs_plugin_set_locale (GsPlugin *plugin, const gchar *locale)
}
/**
+ * gs_plugin_set_language:
+ * @plugin: a #GsPlugin
+ * @language: a language string, e.g. "fr"
+ *
+ * Sets the plugin language.
+ **/
+void
+gs_plugin_set_language (GsPlugin *plugin, const gchar *language)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_free (priv->language);
+ priv->language = g_strdup (language);
+}
+
+/**
* gs_plugin_set_auth_array:
* @plugin: a #GsPlugin
* @auth_array: (element-type GsAuth): an array
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index fc8d9fa..aa2bb86 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -245,6 +245,7 @@ gboolean gs_plugin_has_flags (GsPlugin *plugin,
GsPluginFlags flags);
guint gs_plugin_get_scale (GsPlugin *plugin);
const gchar *gs_plugin_get_locale (GsPlugin *plugin);
+const gchar *gs_plugin_get_language (GsPlugin *plugin);
AsProfile *gs_plugin_get_profile (GsPlugin *plugin);
SoupSession *gs_plugin_get_soup_session (GsPlugin *plugin);
void gs_plugin_add_auth (GsPlugin *plugin,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]