[gnome-software] Allow the locale value to be shared between all plugins



commit 457ead6481997d12df17120a3f9f6f003b7370cd
Author: Richard Hughes <richard hughsie com>
Date:   Tue Dec 22 06:47:11 2015 +0000

    Allow the locale value to be shared between all plugins

 src/gs-plugin-loader.c            |   11 +++++++++++
 src/gs-plugin.h                   |    1 +
 src/plugins/gs-plugin-appstream.c |   12 +-----------
 3 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 0c3cdb8..5d13889 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include <locale.h>
 #include <glib/gi18n.h>
 #include <appstream-glib.h>
 
@@ -33,6 +34,7 @@ typedef struct
 {
        GPtrArray               *plugins;
        gchar                   *location;
+       gchar                   *locale;
        GsPluginStatus           status_last;
        AsProfile               *profile;
 
@@ -2877,6 +2879,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->priority = 0.f;
        plugin->deps = plugin_deps != NULL ? plugin_deps (plugin) : NULL;
        plugin->name = g_strdup (plugin_name ());
+       plugin->locale = priv->locale;
        plugin->status_update_fn = gs_plugin_loader_status_update_cb;
        plugin->status_update_user_data = plugin_loader;
        plugin->updates_changed_fn = gs_plugin_loader_updates_changed_cb;
@@ -3138,6 +3141,7 @@ gs_plugin_loader_finalize (GObject *object)
 
        g_strfreev (priv->compatible_projects);
        g_free (priv->location);
+       g_free (priv->locale);
 
        g_mutex_clear (&priv->pending_apps_mutex);
        g_mutex_clear (&priv->app_cache_mutex);
@@ -3185,6 +3189,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;
 
@@ -3199,6 +3204,12 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
                                                                g_free,
                                                                (GFreeFunc) g_object_unref);
 
+       /* get the locale without the UTF-8 suffix */
+       priv->locale = g_strdup (setlocale (LC_MESSAGES, NULL));
+       match = g_strstr_len (priv->locale, -1, ".UTF-8");
+       if (match != NULL)
+               *match = '\0';
+
        g_mutex_init (&priv->pending_apps_mutex);
        g_mutex_init (&priv->app_cache_mutex);
 
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index ebb8a26..0c9ae09 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -70,6 +70,7 @@ struct GsPlugin {
        GsPluginPrivate         *priv;
        guint                    pixbuf_size;
        gint                     scale;
+       const gchar             *locale;
        GsPluginStatusUpdate     status_update_fn;
        gpointer                 status_update_user_data;
        GsPluginUpdatesChanged   updates_changed_fn;
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 84593b4..9a1be27 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -21,7 +21,6 @@
 
 #include <config.h>
 #include <glib/gi18n.h>
-#include <locale.h>
 #include <appstream-glib.h>
 
 #include <gs-plugin.h>
@@ -32,7 +31,6 @@
 struct GsPluginPrivate {
        AsStore                 *store;
        GMutex                   store_mutex;
-       gchar                   *locale;
        gsize                    done_init;
 };
 
@@ -118,7 +116,6 @@ gs_plugin_get_deps (GsPlugin *plugin)
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {
-       g_free (plugin->priv->locale);
        g_object_unref (plugin->priv->store);
        g_mutex_clear (&plugin->priv->store_mutex);
 }
@@ -180,7 +177,6 @@ gs_plugin_startup (GsPlugin *plugin, GError **error)
        GPtrArray *items;
        gboolean ret;
        const gchar *origin;
-       gchar *tmp;
        guint *perc;
        guint i;
        g_autoptr(GHashTable) origins = NULL;
@@ -192,12 +188,6 @@ gs_plugin_startup (GsPlugin *plugin, GError **error)
        /* clear all existing applications if the store was invalidated */
        as_store_remove_all (plugin->priv->store);
 
-       /* get the locale without the UTF-8 suffix */
-       plugin->priv->locale = g_strdup (setlocale (LC_MESSAGES, NULL));
-       tmp = g_strstr_len (plugin->priv->locale, -1, ".UTF-8");
-       if (tmp != NULL)
-               *tmp = '\0';
-
        /* Parse the XML */
        if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
                as_store_set_add_flags (plugin->priv->store,
@@ -643,7 +633,7 @@ gs_plugin_refine_item (GsPlugin *plugin,
                gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE);
 
        /* add kudos */
-       if (as_app_get_language (item, plugin->priv->locale) > 50)
+       if (as_app_get_language (item, plugin->locale) > 50)
                gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE);
 
        /* add new-style kudos */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]