[gnome-software] trivial: Start sealing plugin internals to increase future API stability
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Start sealing plugin internals to increase future API stability
- Date: Wed, 20 Apr 2016 18:07:52 +0000 (UTC)
commit 945f975426d5f61d4a750f14f6bcadf48f80a641
Author: Richard Hughes <richard hughsie com>
Date: Wed Apr 20 12:36:19 2016 +0100
trivial: Start sealing plugin internals to increase future API stability
This is the first part of slowly changing GsPlugin into a GObject and
un-exporting things from gs-plugin.h that plugins should not be modifying.
src/Makefile.am | 1 +
src/gs-plugin-loader.c | 353 ++++++++++-----------
src/gs-plugin-private.h | 65 ++++
src/gs-plugin.c | 403 +++++++++++++++++++++++-
src/gs-plugin.h | 102 ++-----
src/plugins/gs-appstream.c | 8 +-
src/plugins/gs-plugin-appstream.c | 71 +++--
src/plugins/gs-plugin-dummy.c | 12 +-
src/plugins/gs-plugin-fedora-distro-upgrades.c | 50 ++--
src/plugins/gs-plugin-fedora-tagger-usage.c | 2 +-
src/plugins/gs-plugin-fwupd.c | 119 ++++----
src/plugins/gs-plugin-icons.c | 8 +-
src/plugins/gs-plugin-limba.c | 21 +-
src/plugins/gs-plugin-odrs.c | 85 +++---
src/plugins/gs-plugin-ostree.c | 22 +-
src/plugins/gs-plugin-packagekit-history.c | 17 +-
src/plugins/gs-plugin-packagekit-origin.c | 29 +-
src/plugins/gs-plugin-packagekit-proxy.c | 53 ++--
src/plugins/gs-plugin-packagekit-refine.c | 53 ++--
src/plugins/gs-plugin-packagekit-refresh.c | 31 +-
src/plugins/gs-plugin-packagekit.c | 58 ++--
src/plugins/gs-plugin-provenance.c | 26 +-
src/plugins/gs-plugin-shell-extensions.c | 44 ++-
src/plugins/gs-plugin-systemd-updates.c | 16 +-
src/plugins/gs-plugin-ubuntu-reviews.c | 50 ++--
src/plugins/gs-plugin-xdg-app.c | 109 ++++---
26 files changed, 1150 insertions(+), 658 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c2deba3..dbfc813 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -156,6 +156,7 @@ gnome_software_SOURCES = \
gs-page.h \
gs-plugin.c \
gs-plugin.h \
+ gs-plugin-private.h \
gs-progress-button.c \
gs-progress-button.h \
gs-review.c \
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 38c840b..606ed32 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -27,6 +27,7 @@
#include "gs-plugin-loader.h"
#include "gs-plugin.h"
+#include "gs-plugin-private.h"
#include "gs-utils.h"
#define GS_PLUGIN_LOADER_UPDATES_CHANGED_DELAY 3 /* s */
@@ -63,6 +64,60 @@ enum {
static guint signals [SIGNAL_LAST] = { 0 };
+typedef void (*GsPluginFunc) (GsPlugin *plugin);
+typedef gboolean (*GsPluginSetupFunc) (GsPlugin *plugin,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginSearchFunc) (GsPlugin *plugin,
+ gchar **value,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginCategoryFunc) (GsPlugin *plugin,
+ GsCategory *category,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginResultsFunc) (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginActionFunc) (GsPlugin *plugin,
+ GsApp *app,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginReviewFunc) (GsPlugin *plugin,
+ GsApp *app,
+ GsReview *review,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginRefineFunc) (GsPlugin *plugin,
+ GList **list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginRefineAppFunc) (GsPlugin *plugin,
+ GsApp *app,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginRefreshFunc ) (GsPlugin *plugin,
+ guint cache_age,
+ GsPluginRefreshFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginFilenameToAppFunc) (GsPlugin *plugin,
+ GList **list,
+ const gchar *filename,
+ GCancellable *cancellable,
+ GError **error);
+typedef gboolean (*GsPluginUpdateFunc) (GsPlugin *plugin,
+ GList *apps,
+ GCancellable *cancellable,
+ GError **error);
+typedef void (*GsPluginAdoptAppFunc) (GsPlugin *plugin,
+ GsApp *app);
+
/* async state */
typedef struct {
const gchar *function_name;
@@ -119,39 +174,18 @@ gs_plugin_loader_action_start (GsPluginLoader *plugin_loader,
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
guint i;
- /* lock plugin */
- if (exclusive) {
- g_rw_lock_writer_lock (&plugin->rwlock);
- plugin->flags |= GS_PLUGIN_FLAGS_EXCLUSIVE;
- } else {
- g_rw_lock_reader_lock (&plugin->rwlock);
- }
-
/* set plugin as SELF and all plugins as OTHER */
- plugin->flags |= GS_PLUGIN_FLAGS_RUNNING_SELF;
+ gs_plugin_action_start (plugin, exclusive);
for (i = 0; i < priv->plugins->len; i++) {
GsPlugin *plugin_tmp;
plugin_tmp = g_ptr_array_index (priv->plugins, i);
- if (!plugin_tmp->enabled)
+ if (!gs_plugin_get_enabled (plugin_tmp))
continue;
- plugin_tmp->flags |= GS_PLUGIN_FLAGS_RUNNING_OTHER;
+ gs_plugin_set_running_other (plugin_tmp, TRUE);
}
}
/**
- * gs_plugin_loader_action_delay_cb:
- **/
-static gboolean
-gs_plugin_loader_action_delay_cb (gpointer user_data)
-{
- GsPlugin *plugin = GS_PLUGIN (user_data);
- g_debug ("plugin no longer recently active: %s", plugin->name);
- plugin->flags &= ~GS_PLUGIN_FLAGS_RECENT;
- plugin->timer_id = 0;
- return FALSE;
-}
-
-/**
* gs_plugin_loader_action_stop:
**/
static void
@@ -161,30 +195,14 @@ gs_plugin_loader_action_stop (GsPluginLoader *plugin_loader, GsPlugin *plugin)
guint i;
/* clear plugin as SELF and all plugins as OTHER */
- plugin->flags &= ~GS_PLUGIN_FLAGS_RUNNING_SELF;
+ gs_plugin_action_stop (plugin);
for (i = 0; i < priv->plugins->len; i++) {
GsPlugin *plugin_tmp;
plugin_tmp = g_ptr_array_index (priv->plugins, i);
- if (!plugin_tmp->enabled)
+ if (!gs_plugin_get_enabled (plugin_tmp))
continue;
- plugin_tmp->flags &= ~GS_PLUGIN_FLAGS_RUNNING_OTHER;
- }
-
- /* unlock plugin */
- if (plugin->flags & GS_PLUGIN_FLAGS_EXCLUSIVE) {
- g_rw_lock_writer_unlock (&plugin->rwlock);
- plugin->flags &= ~GS_PLUGIN_FLAGS_EXCLUSIVE;
- } else {
- g_rw_lock_reader_unlock (&plugin->rwlock);
+ gs_plugin_set_running_other (plugin_tmp, FALSE);
}
-
- /* unset this flag after 5 seconds */
- plugin->flags |= GS_PLUGIN_FLAGS_RECENT;
- if (plugin->timer_id > 0)
- g_source_remove (plugin->timer_id);
- plugin->timer_id = g_timeout_add (5000,
- gs_plugin_loader_action_delay_cb,
- plugin);
}
/**
@@ -201,9 +219,10 @@ gs_plugin_loader_run_adopt (GsPluginLoader *plugin_loader, GList *list)
for (i = 0; i < priv->plugins->len; i++) {
GsPluginAdoptAppFunc adopt_app_func = NULL;
GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
- g_module_symbol (plugin->module, "gs_plugin_adopt_app",
+ g_module_symbol (gs_plugin_get_module (plugin),
+ "gs_plugin_adopt_app",
(gpointer *) &adopt_app_func);
if (adopt_app_func == NULL)
continue;
@@ -262,13 +281,15 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
g_autoptr(AsProfileTask) ptask = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
/* load the possible symbols */
- g_module_symbol (plugin->module, function_name,
+ g_module_symbol (gs_plugin_get_module (plugin),
+ function_name,
(gpointer *) &plugin_func);
- g_module_symbol (plugin->module, function_name_app,
+ g_module_symbol (gs_plugin_get_module (plugin),
+ function_name_app,
(gpointer *) &plugin_app_func);
if (plugin_func == NULL && plugin_app_func == NULL)
continue;
@@ -423,7 +444,7 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
g_autoptr(AsProfileTask) ptask2 = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_cancellable_set_error_if_cancelled (cancellable, error);
if (ret) {
@@ -432,7 +453,7 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
}
/* get symbol */
- exists = g_module_symbol (plugin->module,
+ exists = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!exists)
@@ -740,11 +761,11 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
- exists = g_module_symbol (plugin->module,
+ exists = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!exists)
@@ -1636,12 +1657,12 @@ gs_plugin_loader_search_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -1797,12 +1818,12 @@ gs_plugin_loader_search_files_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -1959,12 +1980,12 @@ gs_plugin_loader_search_what_provides_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -2127,12 +2148,12 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -2267,12 +2288,12 @@ gs_plugin_loader_get_category_apps_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -2591,12 +2612,12 @@ gs_plugin_loader_review_action_thread_cb (GTask *task,
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
if (g_cancellable_set_error_if_cancelled (cancellable, &error))
g_task_return_error (task, error);
- exists = g_module_symbol (plugin->module,
+ exists = g_module_symbol (gs_plugin_get_module (plugin),
state->function_name,
(gpointer *) &plugin_func);
if (!exists)
@@ -2988,7 +3009,7 @@ gs_plugin_loader_run (GsPluginLoader *plugin_loader, const gchar *function_name)
for (i = 0; i < priv->plugins->len; i++) {
g_autoptr(AsProfileTask) ptask = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -3034,7 +3055,7 @@ gs_plugin_loader_get_enabled (GsPluginLoader *plugin_loader,
plugin = gs_plugin_loader_find_plugin (plugin_loader, plugin_name);
if (plugin == NULL)
return FALSE;
- return plugin->enabled;
+ return gs_plugin_get_enabled (plugin);
}
/**
@@ -3100,75 +3121,32 @@ gs_plugin_loader_updates_changed_cb (GsPlugin *plugin, gpointer user_data)
/**
* gs_plugin_loader_open_plugin:
*/
-static GsPlugin *
+static void
gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
const gchar *filename)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- gboolean ret;
- GModule *module;
- GsPluginGetNameFunc plugin_name = NULL;
- GsPluginGetDepsFunc order_after = NULL;
- GsPluginGetDepsFunc order_before = NULL;
- GsPluginGetDepsFunc plugin_conflicts = NULL;
- GsPlugin *plugin = NULL;
-
- module = g_module_open (filename, 0);
- if (module == NULL) {
- g_warning ("failed to open plugin %s: %s",
- filename, g_module_error ());
- return NULL;
- }
+ GsPlugin *plugin;
+ g_autoptr(GError) error = NULL;
- /* get description */
- ret = g_module_symbol (module,
- "gs_plugin_get_name",
- (gpointer *) &plugin_name);
- if (!ret) {
- g_warning ("Plugin %s requires name", filename);
- g_module_close (module);
+ /* create plugin from file */
+ plugin = gs_plugin_create (filename, &error);
+ if (plugin == NULL) {
+ g_warning ("Failed to load %s: %s", filename, error->message);
return NULL;
}
-
- /* get plugins this plugin depends on */
- g_module_symbol (module,
- "gs_plugin_order_after",
- (gpointer *) &order_after);
- g_module_symbol (module,
- "gs_plugin_order_before",
- (gpointer *) &order_before);
- g_module_symbol (module,
- "gs_plugin_get_conflicts",
- (gpointer *) &plugin_conflicts);
-
- /* print what we know */
- plugin = g_slice_new0 (GsPlugin);
- plugin->enabled = TRUE;
- plugin->module = module;
- plugin->pixbuf_size = 64;
- plugin->priority = 0.f;
- plugin->order_after = order_after != NULL ? order_after (plugin) : NULL;
- plugin->order_before = order_before != NULL ? order_before (plugin) : NULL;
- plugin->conflicts = plugin_conflicts != NULL ? plugin_conflicts (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;
plugin->updates_changed_user_data = plugin_loader;
- plugin->profile = g_object_ref (priv->profile);
- plugin->soup_session = g_object_ref (priv->soup_session);
- plugin->scale = gs_plugin_loader_get_scale (plugin_loader);
- plugin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) g_object_unref);
+ gs_plugin_set_soup_session (plugin, priv->soup_session);
+ gs_plugin_set_profile (plugin, priv->profile);
+ gs_plugin_set_locale (plugin, priv->locale);
+ gs_plugin_set_scale (plugin, gs_plugin_loader_get_scale (plugin_loader));
g_debug ("opened plugin %s: %s", filename, plugin->name);
- /* rwlock */
- g_rw_lock_init (&plugin->rwlock);
-
/* add to array */
g_ptr_array_add (priv->plugins, plugin);
- return plugin;
}
/**
@@ -3185,7 +3163,7 @@ gs_plugin_loader_set_scale (GsPluginLoader *plugin_loader, gint scale)
priv->scale = scale;
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
- plugin->scale = scale;
+ gs_plugin_set_scale (plugin, scale);
}
}
@@ -3229,9 +3207,9 @@ gs_plugin_loader_plugin_sort_fn (gconstpointer a, gconstpointer b)
{
GsPlugin **pa = (GsPlugin **) a;
GsPlugin **pb = (GsPlugin **) b;
- if ((*pa)->priority < (*pb)->priority)
+ if (gs_plugin_get_priority (*pa) < gs_plugin_get_priority (*pb))
return -1;
- if ((*pa)->priority > (*pb)->priority)
+ if (gs_plugin_get_priority (*pa) > gs_plugin_get_priority (*pb))
return 1;
return 0;
}
@@ -3246,10 +3224,10 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
const gchar *filename_tmp;
- const gdouble dep_increment = 1.f;
gboolean changes;
GsPlugin *dep;
GsPlugin *plugin;
+ const gchar **deps;
guint dep_loop_check = 0;
guint i;
guint j;
@@ -3282,11 +3260,13 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
/* optional whitelist */
if (whitelist != NULL) {
for (i = 0; i < priv->plugins->len; i++) {
+ gboolean ret;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
- plugin->enabled = g_strv_contains ((const gchar * const *) whitelist,
- plugin->name);
+ ret = g_strv_contains ((const gchar * const *) whitelist,
+ plugin->name);
+ gs_plugin_set_enabled (plugin, ret);
}
}
@@ -3295,50 +3275,56 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
changes = FALSE;
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
- if (plugin->order_after == NULL)
+ deps = gs_plugin_get_order_after (plugin);
+ if (deps == NULL)
continue;
- for (j = 0; plugin->order_after[j] != NULL && !changes; j++) {
+ for (j = 0; deps[j] != NULL && !changes; j++) {
dep = gs_plugin_loader_find_plugin (plugin_loader,
- plugin->order_after[j]);
+ deps[j]);
if (dep == NULL) {
g_debug ("cannot find plugin '%s'",
- plugin->order_after[j]);
+ deps[j]);
continue;
}
- if (!dep->enabled)
+ if (!gs_plugin_get_enabled (dep))
continue;
- if (plugin->priority <= dep->priority) {
- g_debug ("%s [%.1f] to be ordered after %s [%.1f] "
- "so promoting to [%.1f]",
- plugin->name, plugin->priority,
- dep->name, dep->priority,
- dep->priority + dep_increment);
- plugin->priority = dep->priority + dep_increment;
+ if (gs_plugin_get_priority (plugin) <= gs_plugin_get_priority (dep)) {
+ g_debug ("%s [%i] to be ordered after %s [%i] "
+ "so promoting to [%i]",
+ plugin->name,
+ gs_plugin_get_priority (plugin),
+ dep->name,
+ gs_plugin_get_priority (dep),
+ gs_plugin_get_priority (dep) + 1);
+ gs_plugin_set_priority (plugin, gs_plugin_get_priority (dep) + 1);
changes = TRUE;
}
}
}
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
- if (plugin->order_before == NULL)
+ deps = gs_plugin_get_order_before (plugin);
+ if (deps == NULL)
continue;
- for (j = 0; plugin->order_before[j] != NULL && !changes; j++) {
+ for (j = 0; deps[j] != NULL && !changes; j++) {
dep = gs_plugin_loader_find_plugin (plugin_loader,
- plugin->order_before[j]);
+ deps[j]);
if (dep == NULL) {
g_debug ("cannot find plugin '%s'",
- plugin->order_before[j]);
+ deps[j]);
continue;
}
- if (!dep->enabled)
+ if (!gs_plugin_get_enabled (dep))
continue;
- if (plugin->priority <= dep->priority) {
- g_debug ("%s [%.1f] to be ordered before %s [%.1f] "
- "so promoting to [%.1f]",
- plugin->name, plugin->priority,
- dep->name, dep->priority,
- dep->priority + dep_increment);
- dep->priority = plugin->priority + dep_increment;
+ if (gs_plugin_get_priority (plugin) <= gs_plugin_get_priority (dep)) {
+ g_debug ("%s [%i] to be ordered before %s [%i] "
+ "so promoting to [%i]",
+ plugin->name,
+ gs_plugin_get_priority (plugin),
+ dep->name,
+ gs_plugin_get_priority (dep),
+ gs_plugin_get_priority (dep) + 1);
+ gs_plugin_set_priority (dep, gs_plugin_get_priority (plugin) + 1);
changes = TRUE;
}
}
@@ -3364,20 +3350,21 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
/* check for conflicts */
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
- if (plugin->conflicts == NULL)
+ deps = gs_plugin_get_conflicts (plugin);
+ if (deps == NULL)
continue;
- for (j = 0; plugin->conflicts[j] != NULL && !changes; j++) {
+ for (j = 0; deps[j] != NULL && !changes; j++) {
dep = gs_plugin_loader_find_plugin (plugin_loader,
- plugin->conflicts[j]);
+ deps[j]);
if (dep == NULL)
continue;
- if (!dep->enabled)
+ if (!gs_plugin_get_enabled (dep))
continue;
g_debug ("disabling %s as conflicts with %s",
dep->name, plugin->name);
- dep->enabled = FALSE;
+ gs_plugin_set_enabled (dep, FALSE);
}
}
@@ -3391,9 +3378,9 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
/* run setup() if it exists */
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -3408,7 +3395,7 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
if (!ret) {
g_debug ("disabling %s as setup failed: %s",
plugin->name, error_local->message);
- plugin->enabled = FALSE;
+ gs_plugin_set_enabled (plugin, FALSE);
}
}
@@ -3431,32 +3418,14 @@ gs_plugin_loader_dump_state (GsPluginLoader *plugin_loader)
/* print what the priorities are */
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
- g_debug ("[%s]\t%.1f\t->\t%s",
- plugin->enabled ? "enabled" : "disabld",
- plugin->priority,
+ g_debug ("[%s]\t%i\t->\t%s",
+ gs_plugin_get_enabled (plugin) ? "enabled" : "disabld",
+ gs_plugin_get_priority (plugin),
plugin->name);
}
}
/**
- * gs_plugin_loader_plugin_free:
- **/
-static void
-gs_plugin_loader_plugin_free (GsPlugin *plugin)
-{
- if (plugin->timer_id > 0)
- g_source_remove (plugin->timer_id);
- g_free (plugin->priv);
- g_free (plugin->name);
- g_rw_lock_clear (&plugin->rwlock);
- g_object_unref (plugin->profile);
- g_object_unref (plugin->soup_session);
- g_hash_table_unref (plugin->cache);
- g_module_close (plugin->module);
- g_slice_free (GsPlugin, plugin);
-}
-
-/**
* gs_plugin_loader_dispose:
* @object: The object to dispose
**/
@@ -3545,7 +3514,7 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
guint i;
priv->scale = 1;
- priv->plugins = g_ptr_array_new_with_free_func ((GDestroyNotify) gs_plugin_loader_plugin_free);
+ priv->plugins = g_ptr_array_new_with_free_func ((GDestroyNotify) gs_plugin_free);
priv->status_last = GS_PLUGIN_STATUS_LAST;
priv->pending_apps = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
priv->profile = as_profile_new ();
@@ -3692,12 +3661,12 @@ gs_plugin_loader_run_refresh (GsPluginLoader *plugin_loader,
g_autoptr(AsProfileTask) ptask = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
- exists = g_module_symbol (plugin->module,
+ exists = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!exists)
@@ -3834,12 +3803,12 @@ gs_plugin_loader_filename_to_app_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -3977,12 +3946,12 @@ gs_plugin_loader_update_thread_cb (GTask *task,
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_func);
if (!ret)
@@ -4009,12 +3978,12 @@ gs_plugin_loader_update_thread_cb (GTask *task,
GList *l;
plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
ret = g_task_return_error_if_cancelled (task);
if (ret)
return;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &plugin_app_func);
if (!ret)
@@ -4112,9 +4081,9 @@ gs_plugin_loader_get_plugin_supported (GsPluginLoader *plugin_loader,
for (i = 0; i < priv->plugins->len; i++) {
GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
continue;
- ret = g_module_symbol (plugin->module,
+ ret = g_module_symbol (gs_plugin_get_module (plugin),
function_name,
(gpointer *) &dummy);
if (ret)
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
new file mode 100644
index 0000000..44fbb2d
--- /dev/null
+++ b/src/gs-plugin-private.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GS_PLUGIN_PRIVATE_H
+#define __GS_PLUGIN_PRIVATE_H
+
+#include <appstream-glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+#include <libsoup/soup.h>
+
+#include "gs-plugin.h"
+
+G_BEGIN_DECLS
+
+GsPlugin *gs_plugin_new (void);
+GsPlugin *gs_plugin_create (const gchar *filename,
+ GError **error);
+
+void gs_plugin_free (GsPlugin *plugin);
+void gs_plugin_action_start (GsPlugin *plugin,
+ gboolean exclusive);
+void gs_plugin_action_stop (GsPlugin *plugin);
+void gs_plugin_set_scale (GsPlugin *plugin,
+ guint scale);
+guint gs_plugin_get_priority (GsPlugin *plugin);
+void gs_plugin_set_priority (GsPlugin *plugin,
+ guint priority);
+void gs_plugin_set_locale (GsPlugin *plugin,
+ const gchar *locale);
+void gs_plugin_set_profile (GsPlugin *plugin,
+ AsProfile *profile);
+void gs_plugin_set_soup_session (GsPlugin *plugin,
+ SoupSession *soup_session);
+void gs_plugin_set_running_other (GsPlugin *plugin,
+ gboolean running_other);
+const gchar **gs_plugin_get_order_after (GsPlugin *plugin);
+const gchar **gs_plugin_get_order_before (GsPlugin *plugin);
+const gchar **gs_plugin_get_conflicts (GsPlugin *plugin);
+
+GModule *gs_plugin_get_module (GsPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* __GS_PLUGIN_PRIVATE_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 208f7a3..3373f33 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -42,9 +42,32 @@
#include <glib.h>
#include <gio/gdesktopappinfo.h>
-#include "gs-plugin.h"
+#include "gs-plugin-private.h"
#include "gs-os-release.h"
+struct GsPluginPrivate {
+ AsProfile *profile;
+ GHashTable *cache;
+ GModule *module;
+ GRWLock rwlock;
+ GsPluginData *data; /* for gs-plugin-{name}.c */
+ GsPluginFlags flags;
+ SoupSession *soup_session;
+ const gchar **conflicts; /* allow-none */
+ const gchar **order_after; /* allow-none */
+ const gchar **order_before; /* allow-none */
+ gboolean enabled;
+ gchar *locale; /* allow-none */
+ gint scale;
+ guint priority;
+ guint timer_id;
+};
+
+typedef const gchar *(*GsPluginGetNameFunc) (void);
+typedef const gchar **(*GsPluginGetDepsFunc) (GsPlugin *plugin);
+
+#define gs_plugin_get_instance_private(p) (p->priv);
+
/**
* gs_plugin_status_to_string:
*/
@@ -69,12 +92,372 @@ gs_plugin_status_to_string (GsPluginStatus status)
}
/**
+ * gs_plugin_new:
+ **/
+GsPlugin *
+gs_plugin_new (void)
+{
+ GsPlugin *plugin = g_slice_new0 (GsPlugin);
+ plugin->priv = g_new0 (GsPluginPrivate, 1);
+ plugin->priv->enabled = TRUE;
+ plugin->priv->priority = 0.f;
+ plugin->priv->scale = 1;
+ plugin->priv->profile = as_profile_new ();
+ plugin->priv->cache = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) g_object_unref);
+ g_rw_lock_init (&plugin->priv->rwlock);
+ return plugin;
+}
+
+/**
+ * gs_plugin_create:
+ **/
+GsPlugin *
+gs_plugin_create (const gchar *filename, GError **error)
+{
+ GModule *module;
+ GsPluginGetNameFunc plugin_name = NULL;
+ GsPluginGetDepsFunc order_after = NULL;
+ GsPluginGetDepsFunc order_before = NULL;
+ GsPluginGetDepsFunc plugin_conflicts = NULL;
+ GsPlugin *plugin = NULL;
+ gboolean ret;
+
+ module = g_module_open (filename, 0);
+ if (module == NULL) {
+ g_warning ("failed to open plugin %s: %s",
+ filename, g_module_error ());
+ return NULL;
+ }
+
+ /* get description */
+ ret = g_module_symbol (module,
+ "gs_plugin_get_name",
+ (gpointer *) &plugin_name);
+ if (!ret) {
+ g_warning ("Plugin %s requires name", filename);
+ g_module_close (module);
+ return NULL;
+ }
+
+ /* get plugins this plugin depends on */
+ g_module_symbol (module,
+ "gs_plugin_order_after",
+ (gpointer *) &order_after);
+ g_module_symbol (module,
+ "gs_plugin_order_before",
+ (gpointer *) &order_before);
+ g_module_symbol (module,
+ "gs_plugin_get_conflicts",
+ (gpointer *) &plugin_conflicts);
+
+ /* create new plugin */
+ plugin = gs_plugin_new ();
+ plugin->priv->module = module;
+ plugin->priv->order_after = order_after != NULL ? order_after (plugin) : NULL;
+ plugin->priv->order_before = order_before != NULL ? order_before (plugin) : NULL;
+ plugin->priv->conflicts = plugin_conflicts != NULL ? plugin_conflicts (plugin) : NULL;
+ plugin->name = g_strdup (plugin_name ());
+ return plugin;
+}
+
+/**
+ * gs_plugin_free:
+ **/
+void
+gs_plugin_free (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ if (priv->timer_id > 0)
+ g_source_remove (priv->timer_id);
+ g_free (plugin->name);
+ g_free (priv->data);
+ g_free (priv->locale);
+ g_rw_lock_clear (&priv->rwlock);
+ g_object_unref (priv->profile);
+ g_object_unref (priv->soup_session);
+ g_hash_table_unref (priv->cache);
+ g_module_close (priv->module);
+ g_free (priv);
+ g_slice_free (GsPlugin, plugin);
+}
+
+/**
+ * gs_plugin_get_data:
+ **/
+GsPluginData *
+gs_plugin_get_data (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_assert (priv->data != NULL);
+ return priv->data;
+}
+
+/**
+ * gs_plugin_alloc_data:
+ **/
+GsPluginData *
+gs_plugin_alloc_data (GsPlugin *plugin, gsize sz)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_assert (priv->data == NULL);
+ priv->data = g_malloc0 (sz);
+ return priv->data;
+}
+
+/**
+ * gs_plugin_action_start:
+ *
+ * FIXME: unexport soon
+ **/
+void
+gs_plugin_action_start (GsPlugin *plugin, gboolean exclusive)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+
+ /* lock plugin */
+ if (exclusive) {
+ g_rw_lock_writer_lock (&priv->rwlock);
+ priv->flags |= GS_PLUGIN_FLAGS_EXCLUSIVE;
+ } else {
+ g_rw_lock_reader_lock (&priv->rwlock);
+ }
+
+ /* set plugin as SELF */
+ priv->flags |= GS_PLUGIN_FLAGS_RUNNING_SELF;
+}
+
+/**
+ * gs_plugin_action_delay_cb:
+ **/
+static gboolean
+gs_plugin_action_delay_cb (gpointer user_data)
+{
+ GsPlugin *plugin = GS_PLUGIN (user_data);
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+
+ g_debug ("plugin no longer recently active: %s", plugin->name);
+ priv->flags &= ~GS_PLUGIN_FLAGS_RECENT;
+ priv->timer_id = 0;
+ return FALSE;
+}
+
+/**
+ * gs_plugin_action_stop:
+ *
+ * FIXME: unexport soon
+ **/
+void
+gs_plugin_action_stop (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+
+ /* clear plugin as SELF */
+ priv->flags &= ~GS_PLUGIN_FLAGS_RUNNING_SELF;
+
+ /* unlock plugin */
+ if (priv->flags & GS_PLUGIN_FLAGS_EXCLUSIVE) {
+ g_rw_lock_writer_unlock (&priv->rwlock);
+ priv->flags &= ~GS_PLUGIN_FLAGS_EXCLUSIVE;
+ } else {
+ g_rw_lock_reader_unlock (&priv->rwlock);
+ }
+
+ /* unset this flag after 5 seconds */
+ priv->flags |= GS_PLUGIN_FLAGS_RECENT;
+ if (priv->timer_id > 0)
+ g_source_remove (priv->timer_id);
+ priv->timer_id = g_timeout_add (5000,
+ gs_plugin_action_delay_cb,
+ plugin);
+}
+
+/**
+ * gs_plugin_get_module:
+ *
+ * FIXME: unexport soon
+ **/
+GModule *
+gs_plugin_get_module (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->module;
+}
+
+/**
+ * gs_plugin_get_enabled:
+ **/
+gboolean
+gs_plugin_get_enabled (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->enabled;
+}
+
+/**
* gs_plugin_set_enabled:
**/
void
gs_plugin_set_enabled (GsPlugin *plugin, gboolean enabled)
{
- plugin->enabled = enabled;
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ priv->enabled = enabled;
+}
+
+/**
+ * gs_plugin_get_scale:
+ **/
+guint
+gs_plugin_get_scale (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->scale;
+}
+
+/**
+ * gs_plugin_set_scale:
+ **/
+void
+gs_plugin_set_scale (GsPlugin *plugin, guint scale)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ priv->scale = scale;
+}
+
+/**
+ * gs_plugin_get_priority:
+ **/
+guint
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->priority;
+}
+
+/**
+ * gs_plugin_set_priority:
+ **/
+void
+gs_plugin_set_priority (GsPlugin *plugin, guint priority)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ priv->priority = priority;
+}
+
+/**
+ * gs_plugin_get_locale:
+ **/
+const gchar *
+gs_plugin_get_locale (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->locale;
+}
+
+/**
+ * gs_plugin_set_locale:
+ **/
+void
+gs_plugin_set_locale (GsPlugin *plugin, const gchar *locale)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_free (priv->locale);
+ priv->locale = g_strdup (locale);
+}
+
+/**
+ * gs_plugin_get_profile:
+ **/
+AsProfile *
+gs_plugin_get_profile (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->profile;
+}
+
+/**
+ * gs_plugin_set_profile:
+ **/
+void
+gs_plugin_set_profile (GsPlugin *plugin, AsProfile *profile)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_set_object (&priv->profile, profile);
+}
+
+/**
+ * gs_plugin_get_soup_session:
+ **/
+SoupSession *
+gs_plugin_get_soup_session (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->soup_session;
+}
+
+/**
+ * gs_plugin_set_soup_session:
+ **/
+void
+gs_plugin_set_soup_session (GsPlugin *plugin, SoupSession *soup_session)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ g_set_object (&priv->soup_session, soup_session);
+}
+
+/**
+ * gs_plugin_has_flags:
+ **/
+gboolean
+gs_plugin_has_flags (GsPlugin *plugin, GsPluginFlags flags)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return (priv->flags & flags) > 0;
+}
+
+/**
+ * gs_plugin_set_running_other:
+ **/
+void
+gs_plugin_set_running_other (GsPlugin *plugin, gboolean running_other)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ if (running_other)
+ priv->flags |= GS_PLUGIN_FLAGS_RUNNING_OTHER;
+ else
+ priv->flags &= ~GS_PLUGIN_FLAGS_RUNNING_OTHER;
+}
+
+/**
+ * gs_plugin_get_order_after:
+ **/
+const gchar **
+gs_plugin_get_order_after (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->order_after;
+}
+
+/**
+ * gs_plugin_get_order_before:
+ **/
+const gchar **
+gs_plugin_get_order_before (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->order_before;
+}
+
+/**
+ * gs_plugin_get_conflicts:
+ **/
+const gchar **
+gs_plugin_get_conflicts (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ return priv->conflicts;
}
/**
@@ -265,7 +648,7 @@ gs_plugin_download_chunk_cb (SoupMessage *msg, SoupBuffer *chunk,
if (g_cancellable_is_cancelled (helper->cancellable)) {
g_debug ("cancelling download of %s",
gs_app_get_id (helper->app));
- soup_session_cancel_message (helper->plugin->soup_session,
+ soup_session_cancel_message (helper->plugin->priv->soup_session,
msg,
SOUP_STATUS_CANCELLED);
return;
@@ -308,6 +691,7 @@ gs_plugin_download_data (GsPlugin *plugin,
GsPluginDownloadHelper helper;
guint status_code;
g_autoptr(SoupMessage) msg = NULL;
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
g_debug ("downloading %s from %s", uri, plugin->name);
msg = soup_message_new (SOUP_METHOD_GET, uri);
@@ -319,7 +703,7 @@ gs_plugin_download_data (GsPlugin *plugin,
G_CALLBACK (gs_plugin_download_chunk_cb),
&helper);
}
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (priv->soup_session, msg);
if (status_code != SOUP_STATUS_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -347,6 +731,7 @@ gs_plugin_download_file (GsPlugin *plugin,
guint status_code;
g_autoptr(GError) error_local = NULL;
g_autoptr(SoupMessage) msg = NULL;
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
g_debug ("downloading %s to %s from %s", uri, filename, plugin->name);
msg = soup_message_new (SOUP_METHOD_GET, uri);
@@ -358,7 +743,7 @@ gs_plugin_download_file (GsPlugin *plugin,
G_CALLBACK (gs_plugin_download_chunk_cb),
&helper);
}
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (priv->soup_session, msg);
if (status_code != SOUP_STATUS_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -388,7 +773,8 @@ GsApp *
gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
{
GsApp *app;
- app = g_hash_table_lookup (plugin->cache, key);
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ app = g_hash_table_lookup (priv->cache, key);
if (app == NULL)
return NULL;
return g_object_ref (app);
@@ -400,9 +786,10 @@ gs_plugin_cache_lookup (GsPlugin *plugin, const gchar *key)
void
gs_plugin_cache_add (GsPlugin *plugin, const gchar *key, GsApp *app)
{
- if (g_hash_table_lookup (plugin->cache, key) == app)
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ if (g_hash_table_lookup (priv->cache, key) == app)
return;
- g_hash_table_insert (plugin->cache, g_strdup (key), g_object_ref (app));
+ g_hash_table_insert (priv->cache, g_strdup (key), g_object_ref (app));
}
/* vim: set noexpandtab: */
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 0dc9b42..a5b25f3 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -35,6 +35,7 @@
G_BEGIN_DECLS
+typedef struct GsPluginData GsPluginData;
typedef struct GsPluginPrivate GsPluginPrivate;
typedef struct GsPlugin GsPlugin;
@@ -67,27 +68,12 @@ typedef enum {
} GsPluginFlags;
struct GsPlugin {
- GModule *module;
- gdouble priority; /* largest number gets run first */
- const gchar **order_after; /* allow-none */
- const gchar **order_before; /* allow-none */
- const gchar **conflicts; /* allow-none */
- gboolean enabled;
gchar *name;
GsPluginPrivate *priv;
- guint pixbuf_size;
- gint scale;
- const gchar *locale;
GsPluginStatusUpdate status_update_fn;
gpointer status_update_user_data;
GsPluginUpdatesChanged updates_changed_fn;
gpointer updates_changed_user_data;
- AsProfile *profile;
- SoupSession *soup_session;
- GHashTable *cache;
- GRWLock rwlock;
- GsPluginFlags flags;
- guint timer_id;
};
typedef enum {
@@ -151,72 +137,23 @@ typedef enum {
/* helpers */
#define GS_PLUGIN_ERROR 1
-#define GS_PLUGIN_GET_PRIVATE(x) g_new0 (x,1)
-#define GS_PLUGIN(x) ((GsPlugin *) x);
+#define GS_PLUGIN(x) ((GsPlugin *) x)
-typedef const gchar *(*GsPluginGetNameFunc) (void);
-typedef const gchar **(*GsPluginGetDepsFunc) (GsPlugin *plugin);
-typedef void (*GsPluginFunc) (GsPlugin *plugin);
-typedef gboolean (*GsPluginSetupFunc) (GsPlugin *plugin,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginSearchFunc) (GsPlugin *plugin,
- gchar **value,
- GList **list,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginCategoryFunc) (GsPlugin *plugin,
- GsCategory *category,
- GList **list,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginResultsFunc) (GsPlugin *plugin,
- GList **list,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginActionFunc) (GsPlugin *plugin,
- GsApp *app,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginReviewFunc) (GsPlugin *plugin,
- GsApp *app,
- GsReview *review,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginRefineFunc) (GsPlugin *plugin,
- GList **list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginRefineAppFunc) (GsPlugin *plugin,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginRefreshFunc ) (GsPlugin *plugin,
- guint cache_age,
- GsPluginRefreshFlags flags,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginFilenameToAppFunc) (GsPlugin *plugin,
- GList **list,
- const gchar *filename,
- GCancellable *cancellable,
- GError **error);
-typedef gboolean (*GsPluginUpdateFunc) (GsPlugin *plugin,
- GList *apps,
- GCancellable *cancellable,
- GError **error);
-typedef void (*GsPluginAdoptAppFunc) (GsPlugin *plugin,
- GsApp *app);
-
-const gchar *gs_plugin_get_name (void);
-void gs_plugin_initialize (GsPlugin *plugin);
-void gs_plugin_destroy (GsPlugin *plugin);
-void gs_plugin_adopt_app (GsPlugin *plugin,
- GsApp *app);
+/* public getters and setters */
+GsPluginData *gs_plugin_alloc_data (GsPlugin *plugin,
+ gsize sz);
+GsPluginData *gs_plugin_get_data (GsPlugin *plugin);
+gboolean gs_plugin_get_enabled (GsPlugin *plugin);
void gs_plugin_set_enabled (GsPlugin *plugin,
gboolean enabled);
+gboolean gs_plugin_has_flags (GsPlugin *plugin,
+ GsPluginFlags flags);
+guint gs_plugin_get_scale (GsPlugin *plugin);
+const gchar *gs_plugin_get_locale (GsPlugin *plugin);
+AsProfile *gs_plugin_get_profile (GsPlugin *plugin);
+SoupSession *gs_plugin_get_soup_session (GsPlugin *plugin);
+
+/* helpers */
GBytes *gs_plugin_download_data (GsPlugin *plugin,
GsApp *app,
const gchar *uri,
@@ -230,13 +167,11 @@ gboolean gs_plugin_download_file (GsPlugin *plugin,
GError **error);
gboolean gs_plugin_check_distro_id (GsPlugin *plugin,
const gchar *distro_id);
-
GsApp *gs_plugin_cache_lookup (GsPlugin *plugin,
const gchar *key);
void gs_plugin_cache_add (GsPlugin *plugin,
const gchar *key,
GsApp *app);
-
void gs_plugin_status_update (GsPlugin *plugin,
GsApp *app,
GsPluginStatus status);
@@ -248,6 +183,13 @@ gboolean gs_plugin_app_launch (GsPlugin *plugin,
GError **error);
void gs_plugin_updates_changed (GsPlugin *plugin);
const gchar *gs_plugin_status_to_string (GsPluginStatus status);
+
+/* vfuncs */
+const gchar *gs_plugin_get_name (void);
+void gs_plugin_initialize (GsPlugin *plugin);
+void gs_plugin_destroy (GsPlugin *plugin);
+void gs_plugin_adopt_app (GsPlugin *plugin,
+ GsApp *app);
gboolean gs_plugin_add_search (GsPlugin *plugin,
gchar **values,
GList **list,
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 34bf9f8..f5133e7 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -52,7 +52,7 @@ gs_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
}
if (g_file_test (fn, G_FILE_TEST_EXISTS)) {
as_icon_set_kind (icon, AS_ICON_KIND_LOCAL);
- ret = gs_app_load_icon (app, plugin->scale, &error);
+ ret = gs_app_load_icon (app, gs_plugin_get_scale (plugin), &error);
if (!ret) {
g_warning ("failed to load icon %s: %s",
as_icon_get_name (icon),
@@ -71,7 +71,7 @@ gs_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
/* load */
- ret = gs_app_load_icon (app, plugin->scale, &error);
+ ret = gs_app_load_icon (app, gs_plugin_get_scale (plugin), &error);
if (!ret) {
g_warning ("failed to load %s icon %s: %s",
as_icon_kind_to_string (as_icon_get_kind (icon)),
@@ -81,7 +81,7 @@ gs_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
}
break;
case AS_ICON_KIND_CACHED:
- if (plugin->scale == 2)
+ if (gs_plugin_get_scale (plugin) == 2)
icon = as_app_get_icon_for_size (item, 128, 128);
if (icon == NULL)
icon = as_app_get_icon_for_size (item, 64, 64);
@@ -496,7 +496,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE);
/* add kudos */
- if (as_app_get_language (item, plugin->locale) > 50)
+ if (as_app_get_language (item, gs_plugin_get_locale (plugin)) > 50)
gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE);
/* add a kudo to featured and popular apps */
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 7939fe7..5cfdfaf 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -40,7 +40,7 @@
* Refines: | [source]->[name,summary,pixbuf,id,kind]
*/
-struct GsPluginPrivate {
+struct GsPluginData {
AsStore *store;
};
@@ -63,7 +63,7 @@ gs_plugin_appstream_store_changed_cb (AsStore *store, GsPlugin *plugin)
/* this is not strictly true, but it causes all the UI to be reloaded
* which is what we really want */
- if ((plugin->flags & GS_PLUGIN_FLAGS_RUNNING_OTHER) == 0)
+ if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_RUNNING_OTHER))
gs_plugin_updates_changed (plugin);
}
@@ -73,9 +73,9 @@ gs_plugin_appstream_store_changed_cb (AsStore *store, GsPlugin *plugin)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->store = as_store_new ();
- as_store_set_watch_flags (plugin->priv->store,
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->store = as_store_new ();
+ as_store_set_watch_flags (priv->store,
AS_STORE_WATCH_FLAG_ADDED |
AS_STORE_WATCH_FLAG_REMOVED);
}
@@ -99,7 +99,8 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->store);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->store);
}
/**
@@ -155,6 +156,7 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *app;
GPtrArray *items;
gboolean ret;
@@ -166,7 +168,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* Parse the XML */
if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
- as_store_set_add_flags (plugin->priv->store,
+ as_store_set_add_flags (priv->store,
AS_STORE_ADD_FLAG_PREFER_LOCAL);
}
@@ -174,10 +176,10 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
tmp = g_getenv ("GS_SELF_TEST_APPSTREAM_XML");
if (tmp != NULL) {
g_debug ("using self test data of %s", tmp);
- if (!as_store_from_xml (plugin->priv->store, tmp, NULL, error))
+ if (!as_store_from_xml (priv->store, tmp, NULL, error))
return FALSE;
} else {
- ret = as_store_load (plugin->priv->store,
+ ret = as_store_load (priv->store,
AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM |
AS_STORE_LOAD_FLAG_APP_INFO_USER |
AS_STORE_LOAD_FLAG_APPDATA |
@@ -189,7 +191,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
if (!ret)
return FALSE;
}
- items = as_store_get_apps (plugin->priv->store);
+ items = as_store_get_apps (priv->store);
if (items->len == 0) {
g_warning ("No AppStream data, try 'make install-sample-data' in data/");
g_set_error (error,
@@ -200,7 +202,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
}
/* watch for changes */
- g_signal_connect (plugin->priv->store, "changed",
+ g_signal_connect (priv->store, "changed",
G_CALLBACK (gs_plugin_appstream_store_changed_cb),
plugin);
@@ -252,6 +254,7 @@ gs_plugin_refine_from_id (GsPlugin *plugin,
gboolean *found,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *id;
AsApp *item = NULL;
@@ -262,10 +265,10 @@ gs_plugin_refine_from_id (GsPlugin *plugin,
id = gs_app_get_id (app);
if (id == NULL)
return TRUE;
- item = as_store_get_app_by_id (plugin->priv->store, id);
+ item = as_store_get_app_by_id (priv->store, id);
if (item == NULL &&
gs_app_has_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX)) {
- item = as_store_get_app_by_id_ignore_prefix (plugin->priv->store, id);
+ item = as_store_get_app_by_id_ignore_prefix (priv->store, id);
if (item != NULL)
g_debug ("found %s for wildcard %s", as_app_get_id (item), id);
}
@@ -288,6 +291,7 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
GsApp *app,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item = NULL;
GPtrArray *sources;
const gchar *pkgname;
@@ -297,7 +301,7 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
sources = gs_app_get_sources (app);
for (i = 0; i < sources->len && item == NULL; i++) {
pkgname = g_ptr_array_index (sources, i);
- item = as_store_get_app_by_pkgname (plugin->priv->store,
+ item = as_store_get_app_by_pkgname (priv->store,
pkgname);
if (item == NULL)
g_debug ("no AppStream match for {pkgname} %s", pkgname);
@@ -320,12 +324,13 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item;
GPtrArray *array;
guint i;
/* find any upgrades */
- array = as_store_get_apps (plugin->priv->store);
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
g_autoptr(GsApp) app = NULL;
item = g_ptr_array_index (array, i);
@@ -377,6 +382,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *search_id1;
const gchar *search_id2 = NULL;
AsApp *item;
@@ -386,7 +392,8 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
g_autoptr(AsProfileTask) ptask = NULL;
/* get the two search terms */
- ptask = as_profile_start_literal (plugin->profile, "appstream::add-category-apps");
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::add-category-apps");
search_id1 = gs_category_get_id (category);
parent = gs_category_get_parent (category);
if (parent != NULL)
@@ -399,7 +406,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
}
/* just look at each app in turn */
- array = as_store_get_apps (plugin->priv->store);
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
g_autoptr(GsApp) app = NULL;
item = g_ptr_array_index (array, i);
@@ -468,6 +475,7 @@ gs_plugin_add_search (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item;
GPtrArray *array;
gboolean ret = TRUE;
@@ -475,8 +483,9 @@ gs_plugin_add_search (GsPlugin *plugin,
g_autoptr(AsProfileTask) ptask = NULL;
/* search categories for the search term */
- ptask = as_profile_start_literal (plugin->profile, "appstream::search");
- array = as_store_get_apps (plugin->priv->store);
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::search");
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
@@ -498,14 +507,16 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item;
GPtrArray *array;
guint i;
g_autoptr(AsProfileTask) ptask = NULL;
/* search categories for the search term */
- ptask = as_profile_start_literal (plugin->profile, "appstream::add_installed");
- array = as_store_get_apps (plugin->priv->store);
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::add_installed");
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
item = g_ptr_array_index (array, i);
if (as_app_get_state (item) == AS_APP_STATE_INSTALLED) {
@@ -574,14 +585,16 @@ gs_plugin_add_categories (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *app;
GPtrArray *array;
guint i;
g_autoptr(AsProfileTask) ptask = NULL;
/* find out how many packages are in each category */
- ptask = as_profile_start_literal (plugin->profile, "appstream::add-categories");
- array = as_store_get_apps (plugin->priv->store);
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::add-categories");
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
app = g_ptr_array_index (array, i);
if (as_app_get_id (app) == NULL)
@@ -602,14 +615,16 @@ gs_plugin_add_popular (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item;
GPtrArray *array;
guint i;
g_autoptr(AsProfileTask) ptask = NULL;
/* find out how many packages are in each category */
- ptask = as_profile_start_literal (plugin->profile, "appstream::add-popular");
- array = as_store_get_apps (plugin->priv->store);
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::add-popular");
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
g_autoptr(GsApp) app = NULL;
item = g_ptr_array_index (array, i);
@@ -633,14 +648,16 @@ gs_plugin_add_featured (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
AsApp *item;
GPtrArray *array;
guint i;
g_autoptr(AsProfileTask) ptask = NULL;
/* find out how many packages are in each category */
- ptask = as_profile_start_literal (plugin->profile, "appstream::add-featured");
- array = as_store_get_apps (plugin->priv->store);
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::add-featured");
+ array = as_store_get_apps (priv->store);
for (i = 0; i < array->len; i++) {
g_autoptr(GsApp) app = NULL;
item = g_ptr_array_index (array, i);
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 3353532..4eb1572 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -28,7 +28,7 @@
* Provides some dummy data that is useful in self test programs.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
guint quirk_id;
};
@@ -47,7 +47,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
if (g_getenv ("GS_SELF_TEST_DUMMY_ENABLE") == NULL) {
g_debug ("disabling '%s' as not in self test", plugin->name);
gs_plugin_set_enabled (plugin, FALSE);
@@ -60,8 +60,9 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->quirk_id > 0)
- g_source_remove (plugin->priv->quirk_id);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->quirk_id > 0)
+ g_source_remove (priv->quirk_id);
}
/**
@@ -197,6 +198,7 @@ gs_plugin_add_search (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GsApp) app = NULL;
g_autoptr(AsIcon) ic = NULL;
@@ -213,7 +215,7 @@ gs_plugin_add_search (GsPlugin *plugin,
}
/* set up a timeout to emulate getting a GFileMonitor callback */
- plugin->priv->quirk_id =
+ priv->quirk_id =
g_timeout_add_seconds (1, gs_plugin_dummy_poll_cb, plugin);
/* use a generic stock icon */
diff --git a/src/plugins/gs-plugin-fedora-distro-upgrades.c b/src/plugins/gs-plugin-fedora-distro-upgrades.c
index 6730d8d..c1a80ea 100644
--- a/src/plugins/gs-plugin-fedora-distro-upgrades.c
+++ b/src/plugins/gs-plugin-fedora-distro-upgrades.c
@@ -29,7 +29,7 @@
#define FEDORA_PKGDB_COLLECTIONS_API_URI "https://admin.fedoraproject.org/pkgdb/api/collections/"
-struct GsPluginPrivate {
+struct GsPluginData {
gchar *cachefn;
GFileMonitor *cachefn_monitor;
gchar *os_name;
@@ -51,7 +51,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
/* check that we are running on Fedora */
if (!gs_plugin_check_distro_id (plugin, "fedora")) {
gs_plugin_set_enabled (plugin, FALSE);
@@ -66,10 +66,11 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->cachefn_monitor != NULL)
- g_object_unref (plugin->priv->cachefn_monitor);
- g_free (plugin->priv->os_name);
- g_free (plugin->priv->cachefn);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->cachefn_monitor != NULL)
+ g_object_unref (priv->cachefn_monitor);
+ g_free (priv->os_name);
+ g_free (priv->cachefn);
}
/**
@@ -86,11 +87,11 @@ gs_plugin_fedora_distro_upgrades_changed_cb (GFileMonitor *monitor,
/* only reload the update list if the plugin is NOT running itself
* and the time since it ran is greater than 5 seconds (inotify FTW) */
- if (plugin->flags & GS_PLUGIN_FLAGS_RUNNING_SELF) {
+ if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_RUNNING_SELF)) {
g_debug ("no notify as plugin %s active", plugin->name);
return;
}
- if (plugin->flags & GS_PLUGIN_FLAGS_RECENT) {
+ if (gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_RECENT)) {
g_debug ("no notify as plugin %s recently active", plugin->name);
return;
}
@@ -104,6 +105,7 @@ gs_plugin_fedora_distro_upgrades_changed_cb (GFileMonitor *monitor,
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gchar *endptr = NULL;
g_autofree gchar *cachedir = NULL;
g_autofree gchar *verstr = NULL;
@@ -113,30 +115,30 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
cachedir = gs_utils_get_cachedir ("upgrades", error);
if (cachedir == NULL)
return FALSE;
- plugin->priv->cachefn = g_build_filename (cachedir, "fedora.json", NULL);
+ priv->cachefn = g_build_filename (cachedir, "fedora.json", NULL);
/* watch this in case it is changed by the user */
- file = g_file_new_for_path (plugin->priv->cachefn);
- plugin->priv->cachefn_monitor = g_file_monitor (file,
+ file = g_file_new_for_path (priv->cachefn);
+ priv->cachefn_monitor = g_file_monitor (file,
G_FILE_MONITOR_NONE,
cancellable,
error);
- if (plugin->priv->cachefn_monitor == NULL)
+ if (priv->cachefn_monitor == NULL)
return FALSE;
- g_signal_connect (plugin->priv->cachefn_monitor, "changed",
+ g_signal_connect (priv->cachefn_monitor, "changed",
G_CALLBACK (gs_plugin_fedora_distro_upgrades_changed_cb), plugin);
/* read os-release for the current versions */
- plugin->priv->os_name = gs_os_release_get_name (error);
- if (plugin->priv->os_name == NULL)
+ priv->os_name = gs_os_release_get_name (error);
+ if (priv->os_name == NULL)
return FALSE;
verstr = gs_os_release_get_version_id (error);
if (verstr == NULL)
return FALSE;
/* parse the version */
- plugin->priv->os_version = g_ascii_strtoull (verstr, &endptr, 10);
- if (endptr == verstr || plugin->priv->os_version > G_MAXUINT) {
+ priv->os_version = g_ascii_strtoull (verstr, &endptr, 10);
+ if (endptr == verstr || priv->os_version > G_MAXUINT) {
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
@@ -157,14 +159,15 @@ gs_plugin_fedora_distro_upgrades_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
/* check cache age */
if (cache_age > 0) {
guint tmp;
- g_autoptr(GFile) file = g_file_new_for_path (plugin->priv->cachefn);
+ g_autoptr(GFile) file = g_file_new_for_path (priv->cachefn);
tmp = gs_utils_get_file_age (file);
if (tmp < cache_age) {
g_debug ("%s is only %i seconds old",
- plugin->priv->cachefn, tmp);
+ priv->cachefn, tmp);
return TRUE;
}
}
@@ -172,7 +175,7 @@ gs_plugin_fedora_distro_upgrades_refresh (GsPlugin *plugin,
/* download new file */
return gs_plugin_download_file (plugin, NULL,
FEDORA_PKGDB_COLLECTIONS_API_URI,
- plugin->priv->cachefn,
+ priv->cachefn,
cancellable,
error);
}
@@ -312,6 +315,7 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gsize len;
guint i;
g_autofree gchar *data = NULL;
@@ -325,7 +329,7 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
return FALSE;
/* get cached file */
- if (!g_file_get_contents (plugin->priv->cachefn, &data, &len, error))
+ if (!g_file_get_contents (priv->cachefn, &data, &len, error))
return FALSE;
/* parse data */
@@ -341,11 +345,11 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
g_autoptr(GsApp) app = NULL;
/* only interested in upgrades to the same distro */
- if (g_strcmp0 (distro_info->name, plugin->priv->os_name) != 0)
+ if (g_strcmp0 (distro_info->name, priv->os_name) != 0)
continue;
/* only interested in newer versions */
- if (distro_info->version <= plugin->priv->os_version)
+ if (distro_info->version <= priv->os_version)
continue;
/* only interested in non-devel distros */
diff --git a/src/plugins/gs-plugin-fedora-tagger-usage.c b/src/plugins/gs-plugin-fedora-tagger-usage.c
index e2665ab..2e7e21e 100644
--- a/src/plugins/gs-plugin-fedora-tagger-usage.c
+++ b/src/plugins/gs-plugin-fedora-tagger-usage.c
@@ -109,7 +109,7 @@ gs_plugin_app_set_usage_pkg (GsPlugin *plugin,
SOUP_MEMORY_COPY, data, strlen (data));
/* set sync request */
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
g_debug ("Failed to set usage on fedora-tagger: %s",
soup_status_get_phrase (status_code));
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index a4f97bf..6d3cf50 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -40,7 +40,7 @@
* added or removed or if a device has been updated live.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
FwupdClient *client;
GPtrArray *to_download;
GPtrArray *to_ignore;
@@ -65,16 +65,16 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->client = fwupd_client_new ();
- plugin->priv->to_download = g_ptr_array_new_with_free_func (g_free);
- plugin->priv->to_ignore = g_ptr_array_new_with_free_func (g_free);
- plugin->priv->config_fn = g_build_filename (SYSCONFDIR, "fwupd.conf", NULL);
- if (!g_file_test (plugin->priv->config_fn, G_FILE_TEST_EXISTS)) {
- g_free (plugin->priv->config_fn);
- plugin->priv->config_fn = g_strdup ("/etc/fwupd.conf");
- }
- if (!g_file_test (plugin->priv->config_fn, G_FILE_TEST_EXISTS)) {
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->client = fwupd_client_new ();
+ priv->to_download = g_ptr_array_new_with_free_func (g_free);
+ priv->to_ignore = g_ptr_array_new_with_free_func (g_free);
+ priv->config_fn = g_build_filename (SYSCONFDIR, "fwupd.conf", NULL);
+ if (!g_file_test (priv->config_fn, G_FILE_TEST_EXISTS)) {
+ g_free (priv->config_fn);
+ priv->config_fn = g_strdup ("/etc/fwupd.conf");
+ }
+ if (!g_file_test (priv->config_fn, G_FILE_TEST_EXISTS)) {
g_debug ("fwupd configuration not found, disabling plugin.");
gs_plugin_set_enabled (plugin, FALSE);
}
@@ -86,13 +86,14 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_free (plugin->priv->cachedir);
- g_free (plugin->priv->lvfs_sig_fn);
- g_free (plugin->priv->lvfs_sig_hash);
- g_free (plugin->priv->config_fn);
- g_object_unref (plugin->priv->client);
- g_ptr_array_unref (plugin->priv->to_download);
- g_ptr_array_unref (plugin->priv->to_ignore);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_free (priv->cachedir);
+ g_free (priv->lvfs_sig_fn);
+ g_free (priv->lvfs_sig_hash);
+ g_free (priv->config_fn);
+ g_object_unref (priv->client);
+ g_ptr_array_unref (priv->to_download);
+ g_ptr_array_unref (priv->to_ignore);
}
/**
@@ -120,32 +121,33 @@ gs_plugin_fwupd_changed_cb (FwupdClient *client, GsPlugin *plugin)
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gsize len;
g_autofree gchar *data = NULL;
/* already done */
- if (plugin->priv->cachedir != NULL)
+ if (priv->cachedir != NULL)
return TRUE;
/* register D-Bus errors */
fwupd_error_quark ();
- g_signal_connect (plugin->priv->client, "changed",
+ g_signal_connect (priv->client, "changed",
G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin);
/* create the cache location */
- plugin->priv->cachedir = gs_utils_get_cachedir ("firmware", error);
- if (plugin->priv->cachedir == NULL)
+ priv->cachedir = gs_utils_get_cachedir ("firmware", error);
+ if (priv->cachedir == NULL)
return FALSE;
/* get the hash of the previously downloaded file */
- plugin->priv->lvfs_sig_fn = g_build_filename (plugin->priv->cachedir,
+ priv->lvfs_sig_fn = g_build_filename (priv->cachedir,
"firmware.xml.gz.asc",
NULL);
- if (g_file_test (plugin->priv->lvfs_sig_fn, G_FILE_TEST_EXISTS)) {
- if (!g_file_get_contents (plugin->priv->lvfs_sig_fn,
+ if (g_file_test (priv->lvfs_sig_fn, G_FILE_TEST_EXISTS)) {
+ if (!g_file_get_contents (priv->lvfs_sig_fn,
&data, &len, error))
return FALSE;
- plugin->priv->lvfs_sig_hash =
+ priv->lvfs_sig_hash =
g_compute_checksum_for_data (G_CHECKSUM_SHA1, (guchar *) data, len);
}
@@ -158,19 +160,20 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
static void
gs_plugin_fwupd_add_required_location (GsPlugin *plugin, const gchar *location)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *tmp;
guint i;
- for (i = 0; i < plugin->priv->to_ignore->len; i++) {
- tmp = g_ptr_array_index (plugin->priv->to_ignore, i);
+ for (i = 0; i < priv->to_ignore->len; i++) {
+ tmp = g_ptr_array_index (priv->to_ignore, i);
if (g_strcmp0 (tmp, location) == 0)
return;
}
- for (i = 0; i < plugin->priv->to_download->len; i++) {
- tmp = g_ptr_array_index (plugin->priv->to_download, i);
+ for (i = 0; i < priv->to_download->len; i++) {
+ tmp = g_ptr_array_index (priv->to_download, i);
if (g_strcmp0 (tmp, location) == 0)
return;
}
- g_ptr_array_add (plugin->priv->to_download, g_strdup (location));
+ g_ptr_array_add (priv->to_download, g_strdup (location));
}
/**
@@ -280,6 +283,7 @@ gs_plugin_add_update_app (GsPlugin *plugin,
FwupdResult *res,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
FwupdDeviceFlags flags = 0;
const gchar *update_hash;
const gchar *update_uri;
@@ -341,7 +345,7 @@ gs_plugin_add_update_app (GsPlugin *plugin,
/* does the firmware already exist in the cache? */
basename = g_path_get_basename (update_uri);
- filename_cache = g_build_filename (plugin->priv->cachedir,
+ filename_cache = g_build_filename (priv->cachedir,
basename, NULL);
if (!g_file_test (filename_cache, G_FILE_TEST_EXISTS)) {
gs_plugin_fwupd_add_required_location (plugin, update_uri);
@@ -386,12 +390,13 @@ gs_plugin_add_updates_historical (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GError) error_local = NULL;
g_autoptr(GsApp) app = NULL;
g_autoptr(FwupdResult) res = NULL;
/* get historical updates */
- res = fwupd_client_get_results (plugin->priv->client,
+ res = fwupd_client_get_results (priv->client,
FWUPD_DEVICE_ID_ANY,
cancellable,
&error_local);
@@ -426,12 +431,13 @@ gs_plugin_add_updates (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) results = NULL;
/* get current list of updates */
- results = fwupd_client_get_updates (plugin->priv->client,
+ results = fwupd_client_get_updates (priv->client,
cancellable, &error_local);
if (results == NULL) {
if (g_error_matches (error_local,
@@ -465,6 +471,7 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GError) error_local = NULL;
g_autofree gchar *basename_data = NULL;
g_autofree gchar *cache_fn_data = NULL;
@@ -477,18 +484,18 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
/* read config file */
config = g_key_file_new ();
- if (!g_key_file_load_from_file (config, plugin->priv->config_fn, G_KEY_FILE_NONE, error))
+ if (!g_key_file_load_from_file (config, priv->config_fn, G_KEY_FILE_NONE, error))
return FALSE;
/* check cache age */
if (cache_age > 0) {
guint tmp;
g_autoptr(GFile) file = NULL;
- file = g_file_new_for_path (plugin->priv->lvfs_sig_fn);
+ file = g_file_new_for_path (priv->lvfs_sig_fn);
tmp = gs_utils_get_file_age (file);
if (tmp < cache_age) {
g_debug ("%s is only %i seconds old, so ignoring refresh",
- plugin->priv->lvfs_sig_fn, tmp);
+ priv->lvfs_sig_fn, tmp);
return TRUE;
}
}
@@ -512,14 +519,14 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1,
(const guchar *) g_bytes_get_data (data, NULL),
g_bytes_get_size (data));
- if (g_strcmp0 (checksum, plugin->priv->lvfs_sig_hash) == 0) {
+ if (g_strcmp0 (checksum, priv->lvfs_sig_hash) == 0) {
g_debug ("signature of %s is unchanged", url_sig);
return TRUE;
}
/* save to a file */
- g_debug ("saving new LVFS signature to %s:", plugin->priv->lvfs_sig_fn);
- if (!g_file_set_contents (plugin->priv->lvfs_sig_fn,
+ g_debug ("saving new LVFS signature to %s:", priv->lvfs_sig_fn);
+ if (!g_file_set_contents (priv->lvfs_sig_fn,
g_bytes_get_data (data, NULL),
g_bytes_get_size (data),
&error_local)) {
@@ -532,12 +539,12 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
}
/* save the new checksum so we don't downoad the payload unless it's changed */
- g_free (plugin->priv->lvfs_sig_hash);
- plugin->priv->lvfs_sig_hash = g_strdup (checksum);
+ g_free (priv->lvfs_sig_hash);
+ priv->lvfs_sig_hash = g_strdup (checksum);
/* download the payload and save to file */
basename_data = g_path_get_basename (url_data);
- cache_fn_data = g_build_filename (plugin->priv->cachedir, basename_data, NULL);
+ cache_fn_data = g_build_filename (priv->cachedir, basename_data, NULL);
g_debug ("saving new LVFS data to %s:", cache_fn_data);
if (!gs_plugin_download_file (plugin,
app_dl,
@@ -548,9 +555,9 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
return FALSE;
/* phew, lets send all this to fwupd */
- if (!fwupd_client_update_metadata (plugin->priv->client,
+ if (!fwupd_client_update_metadata (priv->client,
cache_fn_data,
- plugin->priv->lvfs_sig_fn,
+ priv->lvfs_sig_fn,
cancellable,
error))
return FALSE;
@@ -568,6 +575,7 @@ gs_plugin_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *tmp;
guint i;
@@ -585,26 +593,26 @@ gs_plugin_refresh (GsPlugin *plugin,
return TRUE;
/* download the files to the cachedir */
- for (i = 0; i < plugin->priv->to_download->len; i++) {
+ for (i = 0; i < priv->to_download->len; i++) {
guint status_code;
g_autoptr(GError) error_local = NULL;
g_autofree gchar *basename = NULL;
g_autofree gchar *filename_cache = NULL;
g_autoptr(SoupMessage) msg = NULL;
- tmp = g_ptr_array_index (plugin->priv->to_download, i);
+ tmp = g_ptr_array_index (priv->to_download, i);
basename = g_path_get_basename (tmp);
- filename_cache = g_build_filename (plugin->priv->cachedir, basename, NULL);
+ filename_cache = g_build_filename (priv->cachedir, basename, NULL);
g_debug ("downloading %s to %s", tmp, filename_cache);
/* set sync request */
msg = soup_message_new (SOUP_METHOD_GET, tmp);
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
g_warning ("Failed to download %s, ignoring: %s",
tmp, soup_status_get_phrase (status_code));
- g_ptr_array_remove_index (plugin->priv->to_download, i--);
- g_ptr_array_add (plugin->priv->to_ignore, g_strdup (tmp));
+ g_ptr_array_remove_index (priv->to_download, i--);
+ g_ptr_array_add (priv->to_ignore, g_strdup (tmp));
continue;
}
@@ -634,6 +642,7 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *device_id;
const gchar *filename;
FwupdInstallFlags install_flags = 0;
@@ -658,7 +667,7 @@ gs_plugin_fwupd_install (GsPlugin *plugin,
install_flags |= FWUPD_INSTALL_FLAG_OFFLINE;
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- if (!fwupd_client_install (plugin->priv->client, device_id,
+ if (!fwupd_client_install (priv->client, device_id,
filename, install_flags,
cancellable, error)) {
gs_app_set_state_recover (app);
@@ -697,6 +706,7 @@ gs_plugin_update_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
/* only process this app if was created by this plugin */
if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
return TRUE;
@@ -712,7 +722,7 @@ gs_plugin_update_app (GsPlugin *plugin,
"not enough data for fwupd unlock");
return FALSE;
}
- return fwupd_client_unlock (plugin->priv->client, device_id,
+ return fwupd_client_unlock (priv->client, device_id,
cancellable, error);
}
@@ -729,6 +739,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *content_type = NULL;
g_autoptr(FwupdResult) res = NULL;
g_autoptr(GsApp) app = NULL;
@@ -744,7 +755,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
return TRUE;
/* get results */
- res = fwupd_client_get_details (plugin->priv->client,
+ res = fwupd_client_get_details (priv->client,
filename,
cancellable,
error);
diff --git a/src/plugins/gs-plugin-icons.c b/src/plugins/gs-plugin-icons.c
index e16b0c5..279068a 100644
--- a/src/plugins/gs-plugin-icons.c
+++ b/src/plugins/gs-plugin-icons.c
@@ -82,7 +82,7 @@ gs_plugin_icons_download (GsPlugin *plugin, const gchar *uri, const gchar *filen
}
/* set sync request */
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -142,7 +142,9 @@ gs_plugin_refine_app (GsPlugin *plugin,
if (g_str_has_prefix (as_icon_get_url (ic), "file://")) {
as_icon_set_filename (ic, as_icon_get_url (ic) + 7);
as_icon_set_kind (ic, AS_ICON_KIND_LOCAL);
- return gs_app_load_icon (app, plugin->scale, error);
+ return gs_app_load_icon (app,
+ gs_plugin_get_scale (plugin),
+ error);
}
/* convert filename from jpg to png */
@@ -157,5 +159,5 @@ gs_plugin_refine_app (GsPlugin *plugin,
if (!gs_plugin_icons_download (plugin, as_icon_get_url (ic), fn, error))
return FALSE;
as_icon_set_kind (ic, AS_ICON_KIND_LOCAL);
- return gs_app_load_icon (app, plugin->scale, error);
+ return gs_app_load_icon (app, gs_plugin_get_scale (plugin), error);
}
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index f8d4f3d..dce1184 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -31,7 +31,7 @@
* Adds and removes limba packages.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
LiManager *mgr;
};
@@ -62,9 +62,8 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->mgr = li_manager_new ();
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->mgr = li_manager_new ();
}
/**
@@ -73,7 +72,8 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->mgr);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->mgr);
}
/**
@@ -86,6 +86,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
LiPkgInfo *pki;
g_autoptr(GError) error_local = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
@@ -95,7 +96,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
/* profile */
- ptask = as_profile_start (plugin->profile,
+ ptask = as_profile_start (gs_plugin_get_profile (plugin),
"limba::refine{%s}",
gs_app_get_id (app));
@@ -103,7 +104,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
if (gs_app_get_source_default (app) == NULL)
return TRUE;
- pki = li_manager_get_software_by_pkid (plugin->priv->mgr,
+ pki = li_manager_get_software_by_pkid (priv->mgr,
gs_app_get_source_default (app),
&error_local);
if (error_local != NULL) {
@@ -365,13 +366,14 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_autoptr(GPtrArray) swlist = NULL;
g_autoptr(GError) error_local = NULL;
/* HINT: We also emit not-installed but available software here. */
- swlist = li_manager_get_software_list (plugin->priv->mgr, &error_local);
+ swlist = li_manager_get_software_list (priv->mgr, &error_local);
if (error_local != NULL) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -401,11 +403,12 @@ gs_plugin_add_updates (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GList) updates = NULL;
GList *l;
g_autoptr(GError) error_local = NULL;
- updates = li_manager_get_update_list (plugin->priv->mgr, &error_local);
+ updates = li_manager_get_update_list (priv->mgr, &error_local);
if (error_local != NULL) {
g_set_error (error,
GS_PLUGIN_ERROR,
diff --git a/src/plugins/gs-plugin-odrs.c b/src/plugins/gs-plugin-odrs.c
index 058218f..53629b4 100644
--- a/src/plugins/gs-plugin-odrs.c
+++ b/src/plugins/gs-plugin-odrs.c
@@ -39,7 +39,7 @@
#define XDG_APP_REVIEW_CACHE_AGE_MAX 237000 /* 1 week */
#define XDG_APP_REVIEW_NUMBER_RESULTS_MAX 5
-struct GsPluginPrivate {
+struct GsPluginData {
GSettings *settings;
gchar *distro;
gchar *user_hash;
@@ -61,24 +61,25 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
g_autoptr(GError) error = NULL;
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->settings = g_settings_new ("org.gnome.software");
- plugin->priv->review_server = g_settings_get_string (plugin->priv->settings,
+
+ priv->settings = g_settings_new ("org.gnome.software");
+ priv->review_server = g_settings_get_string (priv->settings,
"review-server");
/* get the machine+user ID hash value */
- plugin->priv->user_hash = gs_utils_get_user_hash (&error);
- if (plugin->priv->user_hash == NULL) {
+ priv->user_hash = gs_utils_get_user_hash (&error);
+ if (priv->user_hash == NULL) {
g_warning ("Failed to get machine+user hash: %s", error->message);
return;
}
/* get the distro name (e.g. 'Fedora') but allow a fallback */
- plugin->priv->distro = gs_os_release_get_name (&error);
- if (plugin->priv->distro == NULL) {
+ priv->distro = gs_os_release_get_name (&error);
+ if (priv->distro == NULL) {
g_warning ("Failed to get distro name: %s", error->message);
- plugin->priv->distro = g_strdup ("Unknown");
+ priv->distro = g_strdup ("Unknown");
}
}
@@ -102,9 +103,10 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_free (plugin->priv->user_hash);
- g_free (plugin->priv->distro);
- g_object_unref (plugin->priv->settings);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_free (priv->user_hash);
+ g_free (priv->distro);
+ g_object_unref (priv->settings);
}
/**
@@ -407,6 +409,7 @@ gs_plugin_odrs_parse_ratings (const gchar *data, gsize data_len, GError **error)
static GArray *
gs_plugin_odrs_get_ratings (GsPlugin *plugin, GsApp *app, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GArray *ratings;
guint status_code;
g_autofree gchar *cachedir = NULL;
@@ -434,10 +437,10 @@ gs_plugin_odrs_get_ratings (GsPlugin *plugin, GsApp *app, GError **error)
/* create the GET data *with* the machine hash so we can later
* review the application ourselves */
uri = g_strdup_printf ("%s/ratings/%s",
- plugin->priv->review_server,
+ priv->review_server,
gs_app_get_id_no_prefix (app));
msg = soup_message_new (SOUP_METHOD_GET, uri);
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
if (!gs_plugin_odrs_parse_success (msg->response_body->data,
msg->response_body->length,
@@ -508,6 +511,7 @@ gs_plugin_refine_ratings (GsPlugin *plugin,
static GPtrArray *
gs_plugin_odrs_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *version;
guint karma_min;
guint status_code;
@@ -546,19 +550,19 @@ gs_plugin_odrs_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
builder = json_builder_new ();
json_builder_begin_object (builder);
json_builder_set_member_name (builder, "user_hash");
- json_builder_add_string_value (builder, plugin->priv->user_hash);
+ json_builder_add_string_value (builder, priv->user_hash);
json_builder_set_member_name (builder, "app_id");
json_builder_add_string_value (builder, gs_app_get_id_no_prefix (app));
json_builder_set_member_name (builder, "locale");
- json_builder_add_string_value (builder, plugin->locale);
+ json_builder_add_string_value (builder, gs_plugin_get_locale (plugin));
json_builder_set_member_name (builder, "distro");
- json_builder_add_string_value (builder, plugin->priv->distro);
+ json_builder_add_string_value (builder, priv->distro);
json_builder_set_member_name (builder, "version");
json_builder_add_string_value (builder, version);
json_builder_set_member_name (builder, "limit");
json_builder_add_int_value (builder, XDG_APP_REVIEW_NUMBER_RESULTS_MAX);
json_builder_set_member_name (builder, "karma");
- karma_min = g_settings_get_int (plugin->priv->settings,
+ karma_min = g_settings_get_int (priv->settings,
"review-karma-required");
json_builder_add_int_value (builder, karma_min);
json_builder_end_object (builder);
@@ -571,11 +575,11 @@ gs_plugin_odrs_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
data = json_generator_to_data (json_generator, NULL);
if (data == NULL)
return NULL;
- uri = g_strdup_printf ("%s/fetch", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/fetch", priv->review_server);
msg = soup_message_new (SOUP_METHOD_POST, uri);
soup_message_set_request (msg, "application/json",
SOUP_MEMORY_COPY, data, strlen (data));
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
if (!gs_plugin_odrs_parse_success (msg->response_body->data,
msg->response_body->length,
@@ -615,6 +619,7 @@ gs_plugin_refine_reviews (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GsReview *review;
guint i;
g_autoptr(GPtrArray) reviews = NULL;
@@ -641,7 +646,7 @@ gs_plugin_refine_reviews (GsPlugin *plugin,
/* the user_hash matches, so mark this as our own review */
if (g_strcmp0 (gs_review_get_metadata_item (review, "user_hash"),
- plugin->priv->user_hash) == 0) {
+ priv->user_hash) == 0) {
gs_review_set_flags (review, GS_REVIEW_FLAG_SELF);
}
gs_app_add_review (app, review);
@@ -732,6 +737,7 @@ gs_plugin_review_submit (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *data = NULL;
g_autofree gchar *uri = NULL;
g_autofree gchar *version = NULL;
@@ -749,7 +755,7 @@ gs_plugin_review_submit (GsPlugin *plugin,
builder = json_builder_new ();
json_builder_begin_object (builder);
json_builder_set_member_name (builder, "user_hash");
- json_builder_add_string_value (builder, plugin->priv->user_hash);
+ json_builder_add_string_value (builder, priv->user_hash);
json_builder_set_member_name (builder, "user_skey");
json_builder_add_string_value (builder,
gs_review_get_metadata_item (review, "user_skey"));
@@ -757,9 +763,9 @@ gs_plugin_review_submit (GsPlugin *plugin,
json_builder_add_string_value (builder,
gs_review_get_metadata_item (review, "app_id"));
json_builder_set_member_name (builder, "locale");
- json_builder_add_string_value (builder, plugin->locale);
+ json_builder_add_string_value (builder, gs_plugin_get_locale (plugin));
json_builder_set_member_name (builder, "distro");
- json_builder_add_string_value (builder, plugin->priv->distro);
+ json_builder_add_string_value (builder, priv->distro);
json_builder_set_member_name (builder, "version");
version = gs_plugin_odrs_sanitize_version (gs_review_get_version (review));
json_builder_add_string_value (builder, version);
@@ -785,8 +791,8 @@ gs_plugin_review_submit (GsPlugin *plugin,
return FALSE;
/* POST */
- uri = g_strdup_printf ("%s/submit", plugin->priv->review_server);
- return gs_plugin_odrs_json_post (plugin->soup_session,
+ uri = g_strdup_printf ("%s/submit", priv->review_server);
+ return gs_plugin_odrs_json_post (gs_plugin_get_soup_session (plugin),
uri, data, error);
}
@@ -797,6 +803,7 @@ static gboolean
gs_plugin_odrs_vote (GsPlugin *plugin, GsReview *review,
const gchar *uri, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *tmp;
g_autofree gchar *data = NULL;
g_autoptr(JsonBuilder) builder = NULL;
@@ -808,7 +815,7 @@ gs_plugin_odrs_vote (GsPlugin *plugin, GsReview *review,
json_builder_begin_object (builder);
json_builder_set_member_name (builder, "user_hash");
- json_builder_add_string_value (builder, plugin->priv->user_hash);
+ json_builder_add_string_value (builder, priv->user_hash);
json_builder_set_member_name (builder, "user_skey");
json_builder_add_string_value (builder,
gs_review_get_metadata_item (review, "user_skey"));
@@ -838,7 +845,7 @@ gs_plugin_odrs_vote (GsPlugin *plugin, GsReview *review,
return FALSE;
/* send to server */
- if (!gs_plugin_odrs_json_post (plugin->soup_session,
+ if (!gs_plugin_odrs_json_post (gs_plugin_get_soup_session (plugin),
uri, data, error))
return FALSE;
@@ -859,8 +866,9 @@ gs_plugin_review_report (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *uri = NULL;
- uri = g_strdup_printf ("%s/report", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/report", priv->review_server);
return gs_plugin_odrs_vote (plugin, review, uri, error);
}
@@ -874,8 +882,9 @@ gs_plugin_review_upvote (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *uri = NULL;
- uri = g_strdup_printf ("%s/upvote", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/upvote", priv->review_server);
return gs_plugin_odrs_vote (plugin, review, uri, error);
}
@@ -889,8 +898,9 @@ gs_plugin_review_downvote (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *uri = NULL;
- uri = g_strdup_printf ("%s/downvote", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/downvote", priv->review_server);
return gs_plugin_odrs_vote (plugin, review, uri, error);
}
@@ -904,8 +914,9 @@ gs_plugin_review_dismiss (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *uri = NULL;
- uri = g_strdup_printf ("%s/dismiss", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/dismiss", priv->review_server);
return gs_plugin_odrs_vote (plugin, review, uri, error);
}
@@ -919,8 +930,9 @@ gs_plugin_review_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *uri = NULL;
- uri = g_strdup_printf ("%s/remove", plugin->priv->review_server);
+ uri = g_strdup_printf ("%s/remove", priv->review_server);
return gs_plugin_odrs_vote (plugin, review, uri, error);
}
@@ -950,6 +962,7 @@ gs_plugin_add_unvoted_reviews (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint status_code;
guint i;
g_autofree gchar *uri = NULL;
@@ -960,10 +973,10 @@ gs_plugin_add_unvoted_reviews (GsPlugin *plugin,
/* create the GET data *with* the machine hash so we can later
* review the application ourselves */
uri = g_strdup_printf ("%s/moderate/%s",
- plugin->priv->review_server,
- plugin->priv->user_hash);
+ priv->review_server,
+ priv->user_hash);
msg = soup_message_new (SOUP_METHOD_GET, uri);
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
if (!gs_plugin_odrs_parse_success (msg->response_body->data,
msg->response_body->length,
diff --git a/src/plugins/gs-plugin-ostree.c b/src/plugins/gs-plugin-ostree.c
index f63a220..57cad40 100644
--- a/src/plugins/gs-plugin-ostree.c
+++ b/src/plugins/gs-plugin-ostree.c
@@ -29,7 +29,7 @@
#include "gs-utils.h"
-struct GsPluginPrivate {
+struct GsPluginData {
OstreeRepo *ostree_repo;
};
@@ -48,7 +48,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
/* only works on OSTree */
if (!g_file_test ("/run/ostree-booted", G_FILE_TEST_EXISTS)) {
@@ -82,8 +82,9 @@ gs_plugin_get_conflicts (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->ostree_repo != NULL)
- g_object_unref (plugin->priv->ostree_repo);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->ostree_repo != NULL)
+ g_object_unref (priv->ostree_repo);
}
/**
@@ -92,13 +93,15 @@ gs_plugin_destroy (GsPlugin *plugin)
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+
/* already started */
- if (plugin->priv->ostree_repo != NULL)
+ if (priv->ostree_repo != NULL)
return TRUE;
/* open */
- plugin->priv->ostree_repo = ostree_repo_new_default ();
- if (!ostree_repo_open (plugin->priv->ostree_repo, cancellable, error))
+ priv->ostree_repo = ostree_repo_new_default ();
+ if (!ostree_repo_open (priv->ostree_repo, cancellable, error))
return FALSE;
return TRUE;
}
@@ -112,11 +115,12 @@ gs_plugin_add_sources (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_auto(GStrv) names = NULL;
/* get all remotes */
- names = ostree_repo_remote_list (plugin->priv->ostree_repo, NULL);
+ names = ostree_repo_remote_list (priv->ostree_repo, NULL);
if (names == NULL)
return TRUE;
for (i = 0; names[i] != NULL; i++) {
@@ -124,7 +128,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
g_autoptr(GsApp) app = NULL;
/* get info */
- if (!ostree_repo_remote_get_url (plugin->priv->ostree_repo,
+ if (!ostree_repo_remote_get_url (priv->ostree_repo,
names[i], &url, error))
return FALSE;
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index 2e37c9e..435cca5 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -33,7 +33,7 @@
* This returns update history using the system PackageKit instance.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
GDBusConnection *connection;
};
@@ -52,7 +52,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
}
/**
@@ -74,8 +74,9 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->connection != NULL)
- g_object_unref (plugin->priv->connection);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->connection != NULL)
+ g_object_unref (priv->connection);
}
/**
@@ -137,10 +138,11 @@ gs_plugin_packagekit_refine_add_history (GsApp *app, GVariant *dict)
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
- plugin->priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ priv->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
cancellable,
error);
- return plugin->priv->connection != NULL;
+ return priv->connection != NULL;
}
static gboolean
@@ -149,6 +151,7 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gboolean ret;
GError *error_local = NULL;
GList *l;
@@ -168,7 +171,7 @@ gs_plugin_packagekit_refine (GsPlugin *plugin,
}
g_debug ("getting history for %i packages", g_list_length (list));
- result = g_dbus_connection_call_sync (plugin->priv->connection,
+ result = g_dbus_connection_call_sync (priv->connection,
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit",
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
index 2cdc86f..7ef0b51 100644
--- a/src/plugins/gs-plugin-packagekit-origin.c
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -38,7 +38,7 @@
* Refines: | [origin-ui]
*/
-struct GsPluginPrivate {
+struct GsPluginData {
PkClient *client;
GHashTable *sources;
};
@@ -58,12 +58,12 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->client = pk_client_new ();
- pk_client_set_background (plugin->priv->client, FALSE);
- pk_client_set_interactive (plugin->priv->client, FALSE);
- pk_client_set_cache_age (plugin->priv->client, G_MAXUINT);
- plugin->priv->sources = g_hash_table_new_full (g_str_hash,
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->client = pk_client_new ();
+ pk_client_set_background (priv->client, FALSE);
+ pk_client_set_interactive (priv->client, FALSE);
+ pk_client_set_cache_age (priv->client, G_MAXUINT);
+ priv->sources = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_free);
@@ -87,8 +87,9 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_hash_table_unref (plugin->priv->sources);
- g_object_unref (plugin->priv->client);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_hash_table_unref (priv->sources);
+ g_object_unref (priv->client);
}
/**
@@ -99,17 +100,18 @@ gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkRepoDetail *rd;
guint i;
g_autoptr(PkResults) results = NULL;
g_autoptr(GPtrArray) array = NULL;
/* already done */
- if (g_hash_table_size (plugin->priv->sources) > 0)
+ if (g_hash_table_size (priv->sources) > 0)
return TRUE;
/* ask PK for the repo details */
- results = pk_client_get_repo_list (plugin->priv->client,
+ results = pk_client_get_repo_list (priv->client,
pk_bitfield_from_enums (PK_FILTER_ENUM_NONE, -1),
cancellable,
NULL, plugin,
@@ -119,7 +121,7 @@ gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
array = pk_results_get_repo_detail_array (results);
for (i = 0; i < array->len; i++) {
rd = g_ptr_array_index (array, i);
- g_hash_table_insert (plugin->priv->sources,
+ g_hash_table_insert (priv->sources,
g_strdup (pk_repo_detail_get_id (rd)),
g_strdup (pk_repo_detail_get_description (rd)));
}
@@ -136,6 +138,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *origin_id;
const gchar *origin_ui;
@@ -168,7 +171,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
return FALSE;
/* set new value */
- origin_ui = g_hash_table_lookup (plugin->priv->sources, origin_id);
+ origin_ui = g_hash_table_lookup (priv->sources, origin_id);
if (origin_ui != NULL)
gs_app_set_origin_ui (app, origin_ui);
return TRUE;
diff --git a/src/plugins/gs-plugin-packagekit-proxy.c b/src/plugins/gs-plugin-packagekit-proxy.c
index 466880c..f840cdc 100644
--- a/src/plugins/gs-plugin-packagekit-proxy.c
+++ b/src/plugins/gs-plugin-packagekit-proxy.c
@@ -35,7 +35,7 @@
* Sets the session proxy on the system PackageKit instance
*/
-struct GsPluginPrivate {
+struct GsPluginData {
PkControl *control;
GSettings *settings;
GSettings *settings_http;
@@ -54,6 +54,7 @@ gs_plugin_get_name (void)
static gchar *
get_proxy_http (GsPlugin *plugin)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gboolean ret;
GString *string = NULL;
guint port;
@@ -62,22 +63,22 @@ get_proxy_http (GsPlugin *plugin)
g_autofree gchar *password = NULL;
g_autofree gchar *username = NULL;
- proxy_mode = g_settings_get_enum (plugin->priv->settings, "mode");
+ proxy_mode = g_settings_get_enum (priv->settings, "mode");
if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL)
return NULL;
- host = g_settings_get_string (plugin->priv->settings_http, "host");
+ host = g_settings_get_string (priv->settings_http, "host");
if (host == NULL)
return NULL;
- port = g_settings_get_int (plugin->priv->settings_http, "port");
+ port = g_settings_get_int (priv->settings_http, "port");
- ret = g_settings_get_boolean (plugin->priv->settings_http,
+ ret = g_settings_get_boolean (priv->settings_http,
"use-authentication");
if (ret) {
- username = g_settings_get_string (plugin->priv->settings_http,
+ username = g_settings_get_string (priv->settings_http,
"authentication-user");
- password = g_settings_get_string (plugin->priv->settings_http,
+ password = g_settings_get_string (priv->settings_http,
"authentication-password");
}
@@ -97,19 +98,20 @@ get_proxy_http (GsPlugin *plugin)
static gchar *
get_proxy_ftp (GsPlugin *plugin)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GString *string = NULL;
guint port;
GDesktopProxyMode proxy_mode;
g_autofree gchar *host = NULL;
- proxy_mode = g_settings_get_enum (plugin->priv->settings, "mode");
+ proxy_mode = g_settings_get_enum (priv->settings, "mode");
if (proxy_mode != G_DESKTOP_PROXY_MODE_MANUAL)
return NULL;
- host = g_settings_get_string (plugin->priv->settings_ftp, "host");
+ host = g_settings_get_string (priv->settings_ftp, "host");
if (host == NULL)
return NULL;
- port = g_settings_get_int (plugin->priv->settings_ftp, "port");
+ port = g_settings_get_int (priv->settings_ftp, "port");
if (port == 0)
return NULL;
@@ -133,6 +135,7 @@ set_proxy_cb (GObject *object, GAsyncResult *res, gpointer user_data)
static void
reload_proxy_settings (GsPlugin *plugin, GCancellable *cancellable)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *proxy_http = NULL;
g_autofree gchar *proxy_ftp = NULL;
g_autoptr(GPermission) permission = NULL;
@@ -154,7 +157,7 @@ reload_proxy_settings (GsPlugin *plugin, GCancellable *cancellable)
g_debug ("Setting proxies (http: %s, ftp: %s)", proxy_http, proxy_ftp);
- pk_control_set_proxy_async (plugin->priv->control,
+ pk_control_set_proxy_async (priv->control,
proxy_http,
proxy_ftp,
cancellable,
@@ -170,7 +173,7 @@ gs_plugin_packagekit_proxy_changed_cb (GSettings *settings,
const gchar *key,
GsPlugin *plugin)
{
- if (!plugin->enabled)
+ if (!gs_plugin_get_enabled (plugin))
return;
reload_proxy_settings (plugin, NULL);
}
@@ -181,17 +184,16 @@ gs_plugin_packagekit_proxy_changed_cb (GSettings *settings,
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->control = pk_control_new ();
- plugin->priv->settings = g_settings_new ("org.gnome.system.proxy");
- g_signal_connect (plugin->priv->settings, "changed",
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->control = pk_control_new ();
+ priv->settings = g_settings_new ("org.gnome.system.proxy");
+ g_signal_connect (priv->settings, "changed",
G_CALLBACK (gs_plugin_packagekit_proxy_changed_cb), plugin);
- plugin->priv->settings_http = g_settings_new ("org.gnome.system.proxy.http");
- g_signal_connect (plugin->priv->settings_http, "changed",
+ priv->settings_http = g_settings_new ("org.gnome.system.proxy.http");
+ g_signal_connect (priv->settings_http, "changed",
G_CALLBACK (gs_plugin_packagekit_proxy_changed_cb), plugin);
- plugin->priv->settings_ftp = g_settings_new ("org.gnome.system.proxy.ftp");
- g_signal_connect (plugin->priv->settings_ftp, "changed",
+ priv->settings_ftp = g_settings_new ("org.gnome.system.proxy.ftp");
+ g_signal_connect (priv->settings_ftp, "changed",
G_CALLBACK (gs_plugin_packagekit_proxy_changed_cb), plugin);
}
@@ -211,8 +213,9 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->control);
- g_object_unref (plugin->priv->settings);
- g_object_unref (plugin->priv->settings_http);
- g_object_unref (plugin->priv->settings_ftp);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->control);
+ g_object_unref (priv->settings);
+ g_object_unref (priv->settings_http);
+ g_object_unref (priv->settings_ftp);
}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 27f564a..2d3accc 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -40,7 +40,7 @@
* Refines: | [source-id], [installed]
*/
-struct GsPluginPrivate {
+struct GsPluginData {
PkControl *control;
PkClient *client;
GHashTable *sources;
@@ -83,16 +83,16 @@ gs_plugin_packagekit_cache_invalid_cb (PkControl *control, GsPlugin *plugin)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->client = pk_client_new ();
- plugin->priv->control = pk_control_new ();
- g_signal_connect (plugin->priv->control, "updates-changed",
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->client = pk_client_new ();
+ priv->control = pk_control_new ();
+ g_signal_connect (priv->control, "updates-changed",
G_CALLBACK (gs_plugin_packagekit_cache_invalid_cb), plugin);
- g_signal_connect (plugin->priv->control, "repo-list-changed",
+ g_signal_connect (priv->control, "repo-list-changed",
G_CALLBACK (gs_plugin_packagekit_cache_invalid_cb), plugin);
- pk_client_set_background (plugin->priv->client, FALSE);
- pk_client_set_interactive (plugin->priv->client, FALSE);
- pk_client_set_cache_age (plugin->priv->client, G_MAXUINT);
+ pk_client_set_background (priv->client, FALSE);
+ pk_client_set_interactive (priv->client, FALSE);
+ pk_client_set_cache_age (priv->client, G_MAXUINT);
}
/**
@@ -114,8 +114,9 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->client);
- g_object_unref (plugin->priv->control);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->client);
+ g_object_unref (priv->control);
}
/**
@@ -162,7 +163,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
/* profile */
if (status == PK_STATUS_ENUM_SETUP) {
- data->ptask = as_profile_start (plugin->profile,
+ data->ptask = as_profile_start (gs_plugin_get_profile (plugin),
"packagekit-refine::transaction[%s]",
data->profile_id);
/* this isn't awesome, but saves us handling it in the caller */
@@ -291,6 +292,7 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GList *l;
GPtrArray *sources;
GsApp *app;
@@ -317,7 +319,7 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
data.profile_id = NULL;
/* resolve them all at once */
- results = pk_client_resolve (plugin->priv->client,
+ results = pk_client_resolve (priv->client,
pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1),
(gchar **) package_ids->pdata,
cancellable,
@@ -344,6 +346,7 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *to_array[] = { NULL, NULL };
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -354,7 +357,7 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
data.profile_id = g_path_get_basename (filename);
to_array[0] = filename;
- results = pk_client_search_files (plugin->priv->client,
+ results = pk_client_search_files (priv->client,
pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED, -1),
(gchar **) to_array,
cancellable,
@@ -412,6 +415,7 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *package_id;
GList *l;
GsApp *app;
@@ -436,7 +440,7 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
data.profile_id = NULL;
/* get any update details */
- results = pk_client_get_update_detail (plugin->priv->client,
+ results = pk_client_get_update_detail (priv->client,
(gchar **) package_ids,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -548,6 +552,7 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GList *l;
GPtrArray *source_ids;
GsApp *app;
@@ -574,7 +579,7 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
data.profile_id = g_strjoinv (",", (gchar **) package_ids->pdata);
/* get any details */
- results = pk_client_get_details (plugin->priv->client,
+ results = pk_client_get_details (priv->client,
(gchar **) package_ids->pdata,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -600,6 +605,7 @@ gs_plugin_packagekit_refine_update_urgency (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GList *l;
GsApp *app;
const gchar *package_id;
@@ -614,7 +620,7 @@ gs_plugin_packagekit_refine_update_urgency (GsPlugin *plugin,
/* get the list of updates */
filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
- results = pk_client_get_updates (plugin->priv->client,
+ results = pk_client_get_updates (priv->client,
filter,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -693,7 +699,8 @@ gs_plugin_refine_require_details (GsPlugin *plugin,
g_autoptr(GList) list_tmp = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
- ptask = as_profile_start_literal (plugin->profile, "packagekit-refine[source->license]");
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "packagekit-refine[source->license]");
for (l = list; l != NULL; l = l->next) {
app = GS_APP (l->data);
if (gs_app_get_kind (app) == AS_APP_KIND_WEB_APP)
@@ -796,6 +803,7 @@ gs_plugin_packagekit_refine_distro_upgrade (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GList *l;
GsApp *app2;
ProgressData data;
@@ -807,7 +815,7 @@ gs_plugin_packagekit_refine_distro_upgrade (GsPlugin *plugin,
data.profile_id = NULL;
/* ask PK to simulate upgrading the system */
- results = pk_client_upgrade_system (plugin->priv->client,
+ results = pk_client_upgrade_system (priv->client,
pk_bitfield_from_enums (PK_TRANSACTION_FLAG_ENUM_SIMULATE, -1),
gs_app_get_id (app),
PK_UPGRADE_KIND_ENUM_COMPLETE,
@@ -865,7 +873,8 @@ gs_plugin_refine (GsPlugin *plugin,
}
/* can we resolve in one go? */
- ptask = as_profile_start_literal (plugin->profile, "packagekit-refine[name->id]");
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "packagekit-refine[name->id]");
for (l = *list; l != NULL; l = l->next) {
app = GS_APP (l->data);
if (gs_app_get_kind (app) == AS_APP_KIND_WEB_APP)
@@ -894,7 +903,7 @@ gs_plugin_refine (GsPlugin *plugin,
as_profile_task_free (ptask);
/* set the package-id for an installed desktop file */
- ptask = as_profile_start_literal (plugin->profile,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
"packagekit-refine[installed-filename->id]");
for (l = *list; l != NULL; l = l->next) {
g_autofree gchar *fn = NULL;
@@ -933,7 +942,7 @@ gs_plugin_refine (GsPlugin *plugin,
as_profile_task_free (ptask);
/* any update details missing? */
- ptask = as_profile_start_literal (plugin->profile,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
"packagekit-refine[id->update-details]");
for (l = *list; l != NULL; l = l->next) {
app = GS_APP (l->data);
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index e623a63..e6598b0 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -36,7 +36,7 @@
* also convert any package files to applications the best we can.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
PkTask *task;
};
@@ -67,10 +67,9 @@ gs_plugin_get_conflicts (GsPlugin *plugin)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->task = pk_task_new ();
- pk_client_set_interactive (PK_CLIENT (plugin->priv->task), FALSE);
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->task = pk_task_new ();
+ pk_client_set_interactive (PK_CLIENT (priv->task), FALSE);
}
/**
@@ -79,7 +78,8 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->task);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->task);
}
typedef struct {
@@ -108,7 +108,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
/* profile */
if (status == PK_STATUS_ENUM_SETUP) {
- data->ptask = as_profile_start_literal (plugin->profile,
+ data->ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
"packagekit-refresh::transaction");
} else if (status == PK_STATUS_ENUM_FINISHED) {
g_clear_pointer (&data->ptask, as_profile_task_free);
@@ -129,6 +129,7 @@ gs_plugin_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -137,7 +138,7 @@ gs_plugin_refresh (GsPlugin *plugin,
return TRUE;
/* cache age of 0 is user-initiated */
- pk_client_set_background (PK_CLIENT (plugin->priv->task), cache_age > 0);
+ pk_client_set_background (PK_CLIENT (priv->task), cache_age > 0);
data.plugin = plugin;
data.ptask = NULL;
@@ -148,9 +149,9 @@ gs_plugin_refresh (GsPlugin *plugin,
PkBitfield filter;
filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
- pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), cache_age);
+ pk_client_set_cache_age (PK_CLIENT (priv->task), cache_age);
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- results = pk_client_get_updates (PK_CLIENT (plugin->priv->task),
+ results = pk_client_get_updates (PK_CLIENT (priv->task),
filter,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -174,7 +175,7 @@ gs_plugin_refresh (GsPlugin *plugin,
package_ids = pk_package_sack_get_ids (sack);
transaction_flags = pk_bitfield_value (PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD);
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- results2 = pk_client_update_packages (PK_CLIENT (plugin->priv->task),
+ results2 = pk_client_update_packages (PK_CLIENT (priv->task),
transaction_flags,
package_ids,
cancellable,
@@ -232,6 +233,7 @@ gs_plugin_packagekit_refresh_guess_app_id (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkFiles *item;
ProgressData data;
guint i;
@@ -246,7 +248,7 @@ gs_plugin_packagekit_refresh_guess_app_id (GsPlugin *plugin,
/* get file list so we can work out ID */
files = g_strsplit (filename, "\t", -1);
- results = pk_client_get_files_local (PK_CLIENT (plugin->priv->task),
+ results = pk_client_get_files_local (PK_CLIENT (priv->task),
files,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -294,6 +296,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *package_id;
PkDetails *item;
ProgressData data;
@@ -324,8 +327,8 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
/* get details */
files = g_strsplit (filename, "\t", -1);
- pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), G_MAXUINT);
- results = pk_client_get_details_local (PK_CLIENT (plugin->priv->task),
+ pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
+ results = pk_client_get_details_local (PK_CLIENT (priv->task),
files,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index b1a7ad7..5dabc58 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -38,7 +38,7 @@
* Refines: | [source-id], [source], [update-details], [management-plugin]
*/
-struct GsPluginPrivate {
+struct GsPluginData {
PkTask *task;
};
@@ -57,12 +57,11 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->task = pk_task_new ();
- pk_client_set_background (PK_CLIENT (plugin->priv->task), FALSE);
- pk_client_set_interactive (PK_CLIENT (plugin->priv->task), FALSE);
- pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), G_MAXUINT);
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->task = pk_task_new ();
+ pk_client_set_background (PK_CLIENT (priv->task), FALSE);
+ pk_client_set_interactive (PK_CLIENT (priv->task), FALSE);
+ pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
}
/**
@@ -71,7 +70,8 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_object_unref (plugin->priv->task);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_object_unref (priv->task);
}
typedef struct {
@@ -100,7 +100,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
/* profile */
if (status == PK_STATUS_ENUM_SETUP) {
- data->ptask = as_profile_start_literal (plugin->profile,
+ data->ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
"packagekit-refine::transaction");
} else if (status == PK_STATUS_ENUM_FINISHED) {
g_clear_pointer (&data->ptask, as_profile_task_free);
@@ -129,6 +129,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkBitfield filter;
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -147,7 +148,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
PK_FILTER_ENUM_APPLICATION,
PK_FILTER_ENUM_NOT_COLLECTIONS,
-1);
- results = pk_client_get_packages (PK_CLIENT(plugin->priv->task),
+ results = pk_client_get_packages (PK_CLIENT(priv->task),
filter,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -168,6 +169,7 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GList *l;
GsApp *app;
GsApp *app_tmp;
@@ -183,13 +185,14 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
data.plugin = plugin;
data.ptask = NULL;
- ptask = as_profile_start_literal (plugin->profile, "packagekit::add-sources-related");
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "packagekit::add-sources-related");
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED,
PK_FILTER_ENUM_NEWEST,
PK_FILTER_ENUM_ARCH,
PK_FILTER_ENUM_NOT_COLLECTIONS,
-1);
- results = pk_client_get_packages (PK_CLIENT(plugin->priv->task),
+ results = pk_client_get_packages (PK_CLIENT(priv->task),
filter,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -228,6 +231,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkBitfield filter;
PkRepoDetail *rd;
ProgressData data;
@@ -246,7 +250,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
PK_FILTER_ENUM_NOT_SUPPORTED,
PK_FILTER_ENUM_INSTALLED,
-1);
- results = pk_client_get_repo_list (PK_CLIENT(plugin->priv->task),
+ results = pk_client_get_repo_list (PK_CLIENT(priv->task),
filter,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -289,6 +293,7 @@ gs_plugin_app_source_enable (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -298,7 +303,7 @@ gs_plugin_app_source_enable (GsPlugin *plugin,
/* do sync call */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- results = pk_client_repo_enable (PK_CLIENT (plugin->priv->task),
+ results = pk_client_repo_enable (PK_CLIENT (priv->task),
gs_app_get_origin (app),
TRUE,
cancellable,
@@ -318,6 +323,7 @@ gs_plugin_app_install (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GPtrArray *addons;
GPtrArray *source_ids;
ProgressData data;
@@ -355,7 +361,7 @@ gs_plugin_app_install (GsPlugin *plugin,
/* actually install the package */
gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- results = pk_task_install_packages_sync (plugin->priv->task,
+ results = pk_task_install_packages_sync (priv->task,
package_ids,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -425,7 +431,7 @@ gs_plugin_app_install (GsPlugin *plugin,
if (gs_app_get_to_be_installed (addon))
gs_app_set_state (addon, AS_APP_STATE_INSTALLING);
}
- results = pk_task_install_packages_sync (plugin->priv->task,
+ results = pk_task_install_packages_sync (priv->task,
(gchar **) array_package_ids->pdata,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -451,7 +457,7 @@ gs_plugin_app_install (GsPlugin *plugin,
}
package_ids = g_strsplit (package_id, "\t", -1);
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- results = pk_task_install_files_sync (plugin->priv->task,
+ results = pk_task_install_files_sync (priv->task,
package_ids,
cancellable,
gs_plugin_packagekit_progress_cb, &data,
@@ -494,6 +500,7 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -503,7 +510,7 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
/* do sync call */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- results = pk_client_repo_enable (PK_CLIENT (plugin->priv->task),
+ results = pk_client_repo_enable (PK_CLIENT (priv->task),
gs_app_get_id (app),
FALSE,
cancellable,
@@ -523,6 +530,7 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
ProgressData data;
g_autoptr(GError) error_local = NULL;
g_autoptr(PkResults) results = NULL;
@@ -533,7 +541,7 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
/* do sync call */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- results = pk_client_repo_remove (PK_CLIENT (plugin->priv->task),
+ results = pk_client_repo_remove (PK_CLIENT (priv->task),
pk_bitfield_from_enums (PK_TRANSACTION_FLAG_ENUM_NONE, -1),
gs_app_get_id (app),
TRUE,
@@ -559,6 +567,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *package_id;
GPtrArray *source_ids;
ProgressData data;
@@ -607,7 +616,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
/* do the action */
gs_app_set_state (app, AS_APP_STATE_REMOVING);
- results = pk_task_remove_packages_sync (plugin->priv->task,
+ results = pk_task_remove_packages_sync (priv->task,
package_ids,
TRUE, FALSE,
cancellable,
@@ -636,6 +645,7 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -655,7 +665,7 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
/* ask PK to download enough packages to upgrade the system */
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- results = pk_client_upgrade_system (PK_CLIENT (plugin->priv->task),
+ results = pk_client_upgrade_system (PK_CLIENT (priv->task),
pk_bitfield_from_enums (PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD,
-1),
gs_app_get_version (app),
PK_UPGRADE_KIND_ENUM_COMPLETE,
@@ -682,6 +692,7 @@ gs_plugin_add_search_files (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkBitfield filter;
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -695,7 +706,7 @@ gs_plugin_add_search_files (GsPlugin *plugin,
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
PK_FILTER_ENUM_ARCH,
-1);
- results = pk_client_search_files (PK_CLIENT (plugin->priv->task),
+ results = pk_client_search_files (PK_CLIENT (priv->task),
filter,
search,
cancellable,
@@ -718,6 +729,7 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
PkBitfield filter;
ProgressData data;
g_autoptr(PkResults) results = NULL;
@@ -731,7 +743,7 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
PK_FILTER_ENUM_ARCH,
-1);
- results = pk_client_what_provides (PK_CLIENT (plugin->priv->task),
+ results = pk_client_what_provides (PK_CLIENT (priv->task),
filter,
search,
cancellable,
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index dd424a4..4b3afae 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -31,7 +31,7 @@
* software source.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
GSettings *settings;
gchar **sources;
};
@@ -51,13 +51,14 @@ gs_plugin_get_name (void)
static gchar **
gs_plugin_provenance_get_sources (GsPlugin *plugin)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *tmp;
tmp = g_getenv ("GS_SELF_TEST_PROVENANCE_SOURCES");
if (tmp != NULL) {
g_debug ("using custom provenance sources of %s", tmp);
return g_strsplit (tmp, ",", -1);
}
- return g_settings_get_strv (plugin->priv->settings, "official-sources");
+ return g_settings_get_strv (priv->settings, "official-sources");
}
/**
@@ -68,9 +69,10 @@ gs_plugin_provenance_settings_changed_cb (GSettings *settings,
const gchar *key,
GsPlugin *plugin)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
if (g_strcmp0 (key, "official-sources") == 0) {
- g_strfreev (plugin->priv->sources);
- plugin->priv->sources = gs_plugin_provenance_get_sources (plugin);
+ g_strfreev (priv->sources);
+ priv->sources = gs_plugin_provenance_get_sources (plugin);
}
}
@@ -80,11 +82,11 @@ gs_plugin_provenance_settings_changed_cb (GSettings *settings,
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
- plugin->priv->settings = g_settings_new ("org.gnome.software");
- g_signal_connect (plugin->priv->settings, "changed",
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ priv->settings = g_settings_new ("org.gnome.software");
+ g_signal_connect (priv->settings, "changed",
G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
- plugin->priv->sources = gs_plugin_provenance_get_sources (plugin);
+ priv->sources = gs_plugin_provenance_get_sources (plugin);
}
/**
@@ -105,8 +107,9 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_strfreev (plugin->priv->sources);
- g_object_unref (plugin->priv->settings);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_strfreev (priv->sources);
+ g_object_unref (priv->settings);
}
/**
@@ -139,6 +142,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *origin;
gchar **sources;
@@ -149,7 +153,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
/* nothing to search */
- sources = plugin->priv->sources;
+ sources = priv->sources;
if (sources == NULL || sources[0] == NULL) {
gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
return TRUE;
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index b849280..0b71140 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -42,7 +42,7 @@
* for the source to the web application.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
GDBusProxy *proxy;
gchar *shell_version;
};
@@ -79,7 +79,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
}
/**
@@ -88,9 +88,10 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- g_free (plugin->priv->shell_version);
- if (plugin->priv->proxy != NULL)
- g_object_unref (plugin->priv->proxy);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_free (priv->shell_version);
+ if (priv->proxy != NULL)
+ g_object_unref (priv->proxy);
}
/**
@@ -238,11 +239,12 @@ gs_plugin_shell_extensions_add_app (const gchar *uuid,
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GVariant) version = NULL;
- if (plugin->priv->proxy != NULL)
+ if (priv->proxy != NULL)
return TRUE;
- plugin->priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.gnome.Shell",
@@ -252,10 +254,10 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
error);
/* get the GNOME Shell version */
- version = g_dbus_proxy_get_cached_property (plugin->priv->proxy,
+ version = g_dbus_proxy_get_cached_property (priv->proxy,
"ShellVersion");
if (version != NULL)
- plugin->priv->shell_version = g_variant_dup_string (version, NULL);
+ priv->shell_version = g_variant_dup_string (version, NULL);
return TRUE;
}
@@ -268,13 +270,14 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GVariantIter *ext_iter;
gchar *ext_uuid;
g_autoptr(GVariantIter) iter = NULL;
g_autoptr(GVariant) retval = NULL;
/* installed */
- retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
+ retval = g_dbus_proxy_call_sync (priv->proxy,
"ListExtensions",
NULL,
G_DBUS_CALL_FLAGS_NONE,
@@ -340,21 +343,22 @@ gs_plugin_shell_extensions_parse_version (GsPlugin *plugin,
JsonObject *ver_map,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
JsonObject *json_ver = NULL;
gint64 version;
g_autofree gchar *shell_version = NULL;
g_autoptr(AsRelease) release = NULL;
/* look for version, major.minor.micro */
- if (json_object_has_member (ver_map, plugin->priv->shell_version)) {
+ if (json_object_has_member (ver_map, priv->shell_version)) {
json_ver = json_object_get_object_member (ver_map,
- plugin->priv->shell_version);
+ priv->shell_version);
}
/* look for version, major.minor */
if (json_ver == NULL) {
g_auto(GStrv) ver_majmin = NULL;
- ver_majmin = g_strsplit (plugin->priv->shell_version, ".", -1);
+ ver_majmin = g_strsplit (priv->shell_version, ".", -1);
if (g_strv_length (ver_majmin) >= 2) {
g_autofree gchar *tmp = NULL;
tmp = g_strdup_printf ("%s.%s", ver_majmin[0], ver_majmin[1]);
@@ -367,7 +371,7 @@ gs_plugin_shell_extensions_parse_version (GsPlugin *plugin,
if (json_ver == NULL) {
g_debug ("no version_map for %s: %s",
as_app_get_id (app),
- plugin->priv->shell_version);
+ priv->shell_version);
return TRUE;
}
@@ -587,6 +591,7 @@ gs_plugin_shell_extensions_get_apps (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GPtrArray *apps;
g_autofree gchar *cachedir = NULL;
g_autofree gchar *cachefn = NULL;
@@ -616,7 +621,7 @@ gs_plugin_shell_extensions_get_apps (GsPlugin *plugin,
"?shell_version=%s"
"&page=1&n_per_page=1000",
SHELL_EXTENSIONS_API_URI,
- plugin->priv->shell_version);
+ priv->shell_version);
data = gs_plugin_download_data (plugin, dummy, uri, cancellable, error);
if (data == NULL)
return NULL;
@@ -720,6 +725,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *uuid;
gboolean ret;
g_autoptr(GVariant) retval = NULL;
@@ -731,7 +737,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
/* remove */
gs_app_set_state (app, AS_APP_STATE_REMOVING);
uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
- retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
+ retval = g_dbus_proxy_call_sync (priv->proxy,
"UninstallExtension",
g_variant_new ("(s)", uuid),
G_DBUS_CALL_FLAGS_NONE,
@@ -770,6 +776,7 @@ gs_plugin_app_install (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *uuid;
const gchar *retstr;
g_autoptr(GVariant) retval = NULL;
@@ -781,7 +788,7 @@ gs_plugin_app_install (GsPlugin *plugin,
/* install */
uuid = gs_app_get_metadata_item (app, "shell-extensions::uuid");
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
+ retval = g_dbus_proxy_call_sync (priv->proxy,
"InstallRemoteExtension",
g_variant_new ("(s)", uuid),
G_DBUS_CALL_FLAGS_NONE,
@@ -820,6 +827,7 @@ gs_plugin_launch (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *uuid;
g_autoptr(GVariant) retval = NULL;
@@ -837,7 +845,7 @@ gs_plugin_launch (GsPlugin *plugin,
gs_app_get_id (app));
return FALSE;
}
- retval = g_dbus_proxy_call_sync (plugin->priv->proxy,
+ retval = g_dbus_proxy_call_sync (priv->proxy,
"LaunchExtensionPrefs",
g_variant_new ("(s)", uuid),
G_DBUS_CALL_FLAGS_NONE,
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
index 566b079..ad46ef0 100644
--- a/src/plugins/gs-plugin-systemd-updates.c
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -33,7 +33,7 @@
* scheduling the offline update.
*/
-struct GsPluginPrivate {
+struct GsPluginData {
GFileMonitor *monitor;
};
@@ -52,7 +52,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
}
/**
@@ -61,8 +61,9 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->monitor != NULL)
- g_object_unref (plugin->priv->monitor);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->monitor != NULL)
+ g_object_unref (priv->monitor);
}
/**
@@ -84,10 +85,11 @@ gs_plugin_systemd_updates_changed_cb (GFileMonitor *monitor,
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
- plugin->priv->monitor = pk_offline_get_prepared_monitor (cancellable, error);
- if (plugin->priv->monitor == NULL)
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ priv->monitor = pk_offline_get_prepared_monitor (cancellable, error);
+ if (priv->monitor == NULL)
return FALSE;
- g_signal_connect (plugin->priv->monitor, "changed",
+ g_signal_connect (priv->monitor, "changed",
G_CALLBACK (gs_plugin_systemd_updates_changed_cb),
plugin);
return TRUE;
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 21a9e1f..6c5a0f9 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -32,7 +32,7 @@
#include "gs-os-release.h"
-struct GsPluginPrivate {
+struct GsPluginData {
gchar *db_path;
sqlite3 *db;
gsize db_loaded;
@@ -61,8 +61,7 @@ gs_plugin_get_name (void)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
/* check that we are running on Ubuntu */
if (!gs_plugin_check_distro_id (plugin, "ubuntu")) {
@@ -71,7 +70,7 @@ gs_plugin_initialize (GsPlugin *plugin)
return;
}
- plugin->priv->db_path = g_build_filename (g_get_user_data_dir (),
+ priv->db_path = g_build_filename (g_get_user_data_dir (),
"gnome-software",
"ubuntu-reviews.db",
NULL);
@@ -99,8 +98,7 @@ gs_plugin_get_conflicts (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- GsPluginPrivate *priv = plugin->priv;
-
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_clear_pointer (&priv->db, sqlite3_close);
g_free (priv->db_path);
}
@@ -120,6 +118,7 @@ set_package_stats (GsPlugin *plugin,
Histogram *histogram,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
char *error_msg = NULL;
gint result;
g_autofree gchar *statement = NULL;
@@ -130,7 +129,7 @@ set_package_stats (GsPlugin *plugin,
"VALUES ('%s', '%" G_GINT64_FORMAT "', '%" G_GINT64_FORMAT"', '%"
G_GINT64_FORMAT "', '%" G_GINT64_FORMAT "', '%" G_GINT64_FORMAT "');",
package_name, histogram->one_star_count, histogram->two_star_count,
histogram->three_star_count, histogram->four_star_count,
histogram->five_star_count);
- result = sqlite3_exec (plugin->priv->db, statement, NULL, NULL, &error_msg);
+ result = sqlite3_exec (priv->db, statement, NULL, NULL, &error_msg);
if (result != SQLITE_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -156,7 +155,7 @@ set_timestamp (GsPlugin *plugin,
"VALUES ('%s', '%" G_GINT64_FORMAT "');",
type,
g_get_real_time () / G_USEC_PER_SEC);
- result = sqlite3_exec (plugin->priv->db, statement, NULL, NULL, &error_msg);
+ result = sqlite3_exec (priv->db, statement, NULL, NULL, &error_msg);
if (result != SQLITE_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -190,6 +189,7 @@ get_review_stats (GsPlugin *plugin,
gint *review_ratings,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
Histogram histogram = { 0, 0, 0, 0, 0 };
gchar *error_msg = NULL;
gint result, n_ratings;
@@ -198,7 +198,7 @@ get_review_stats (GsPlugin *plugin,
/* Get histogram from the database */
statement = g_strdup_printf ("SELECT one_star_count, two_star_count, three_star_count,
four_star_count, five_star_count FROM review_stats "
"WHERE package_name = '%s'", package_name);
- result = sqlite3_exec (plugin->priv->db,
+ result = sqlite3_exec (priv->db,
statement,
get_review_stats_sqlite_cb,
&histogram,
@@ -323,7 +323,7 @@ send_review_request (GsPlugin *plugin, const gchar *method, const gchar *path, J
soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, data, length);
}
- status_code = soup_session_send_message (plugin->soup_session, msg);
+ status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);
if (status_code != SOUP_STATUS_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
@@ -378,6 +378,7 @@ download_review_stats (GsPlugin *plugin, GError **error)
static gboolean
load_database (GsPlugin *plugin, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *statement;
gboolean rebuild_ratings = FALSE;
char *error_msg = NULL;
@@ -386,25 +387,25 @@ load_database (GsPlugin *plugin, GError **error)
gint64 now;
g_autoptr(GError) error_local = NULL;
- g_debug ("trying to open database '%s'", plugin->priv->db_path);
- if (!gs_mkdir_parent (plugin->priv->db_path, error))
+ g_debug ("trying to open database '%s'", priv->db_path);
+ if (!gs_mkdir_parent (priv->db_path, error))
return FALSE;
- result = sqlite3_open (plugin->priv->db_path, &plugin->priv->db);
+ result = sqlite3_open (priv->db_path, &priv->db);
if (result != SQLITE_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"Can't open Ubuntu review statistics database: %s",
- sqlite3_errmsg (plugin->priv->db));
+ sqlite3_errmsg (priv->db));
return FALSE;
}
/* We don't need to keep doing fsync */
- sqlite3_exec (plugin->priv->db, "PRAGMA synchronous=OFF",
+ sqlite3_exec (priv->db, "PRAGMA synchronous=OFF",
NULL, NULL, NULL);
/* Create a table to store the stats */
- result = sqlite3_exec (plugin->priv->db, "SELECT * FROM review_stats LIMIT 1", NULL, NULL,
&error_msg);
+ result = sqlite3_exec (priv->db, "SELECT * FROM review_stats LIMIT 1", NULL, NULL, &error_msg);
if (result != SQLITE_OK) {
g_debug ("creating table to repair: %s", error_msg);
sqlite3_free (error_msg);
@@ -415,12 +416,12 @@ load_database (GsPlugin *plugin, GError **error)
"three_star_count INTEGER DEFAULT 0,"
"four_star_count INTEGER DEFAULT 0,"
"five_star_count INTEGER DEFAULT 0);";
- sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL);
+ sqlite3_exec (priv->db, statement, NULL, NULL, NULL);
rebuild_ratings = TRUE;
}
/* Create a table to store local reviews */
- result = sqlite3_exec (plugin->priv->db, "SELECT * FROM reviews LIMIT 1", NULL, NULL, &error_msg);
+ result = sqlite3_exec (priv->db, "SELECT * FROM reviews LIMIT 1", NULL, NULL, &error_msg);
if (result != SQLITE_OK) {
g_debug ("creating table to repair: %s", error_msg);
sqlite3_free (error_msg);
@@ -432,12 +433,12 @@ load_database (GsPlugin *plugin, GError **error)
"rating INTEGER,"
"summary TEXT,"
"text TEXT);";
- sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL);
+ sqlite3_exec (priv->db, statement, NULL, NULL, NULL);
rebuild_ratings = TRUE;
}
/* Create a table to store timestamps */
- result = sqlite3_exec (plugin->priv->db,
+ result = sqlite3_exec (priv->db,
"SELECT value FROM timestamps WHERE key = 'stats_mtime' LIMIT 1",
get_timestamp_sqlite_cb, &stats_mtime,
&error_msg);
@@ -447,7 +448,7 @@ load_database (GsPlugin *plugin, GError **error)
statement = "CREATE TABLE timestamps ("
"key TEXT PRIMARY KEY,"
"value INTEGER DEFAULT 0);";
- sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL);
+ sqlite3_exec (priv->db, statement, NULL, NULL, NULL);
/* Set the time of database creation */
if (!set_timestamp (plugin, "stats_ctime", error))
@@ -565,7 +566,7 @@ get_language (GsPlugin *plugin)
gchar *language, *c;
/* Convert locale into language */
- language = g_strdup (plugin->locale);
+ language = g_strdup (gs_plugin_get_locale (plugin));
c = strchr (language, '_');
if (c)
*c = '\0';
@@ -593,13 +594,14 @@ download_reviews (GsPlugin *plugin, GsApp *app, const gchar *package_name, GErro
static gboolean
refine_rating (GsPlugin *plugin, GsApp *app, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GPtrArray *sources;
guint i;
/* Load database once */
- if (g_once_init_enter (&plugin->priv->db_loaded)) {
+ if (g_once_init_enter (&priv->db_loaded)) {
gboolean ret = load_database (plugin, error);
- g_once_init_leave (&plugin->priv->db_loaded, TRUE);
+ g_once_init_leave (&priv->db_loaded, TRUE);
if (!ret)
return FALSE;
}
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 8dc0e59..5634713 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -44,7 +44,7 @@ static gboolean gs_plugin_refine_item_metadata (GsPlugin *plugin,
GCancellable *cancellable,
GError **error);
-struct GsPluginPrivate {
+struct GsPluginData {
XdgAppInstallation *installation;
GFileMonitor *monitor;
};
@@ -76,8 +76,7 @@ gs_plugin_order_after (GsPlugin *plugin)
void
gs_plugin_initialize (GsPlugin *plugin)
{
- /* create private area */
- plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+ gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
}
/**
@@ -86,10 +85,11 @@ gs_plugin_initialize (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->installation != NULL)
- g_object_unref (plugin->priv->installation);
- if (plugin->priv->monitor != NULL)
- g_object_unref (plugin->priv->monitor);
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ if (priv->installation != NULL)
+ g_object_unref (priv->installation);
+ if (priv->monitor != NULL)
+ g_object_unref (priv->monitor);
}
/**
@@ -199,11 +199,12 @@ gs_plugin_refresh_appstream (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gboolean ret;
guint i;
g_autoptr(GPtrArray) xremotes = NULL;
- xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
+ xremotes = xdg_app_installation_list_remotes (priv->installation,
cancellable,
error);
if (xremotes == NULL)
@@ -233,7 +234,7 @@ gs_plugin_refresh_appstream (GsPlugin *plugin,
}
/* download new data */
- ret = xdg_app_installation_update_appstream_sync (plugin->priv->installation,
+ ret = xdg_app_installation_update_appstream_sync (priv->installation,
xdg_app_remote_get_name (xremote),
NULL, /* arch */
NULL, /* out_changed */
@@ -269,6 +270,7 @@ gs_plugin_refresh_appstream (GsPlugin *plugin,
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autofree gchar *install_path = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GFile) install_file = NULL;
@@ -285,22 +287,23 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* FIXME: this should default to system-wide, but we need a permissions
* helper to elevate privs */
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::ensure-origin");
- plugin->priv->installation = xdg_app_installation_new_for_path (install_file,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::ensure-origin");
+ priv->installation = xdg_app_installation_new_for_path (install_file,
TRUE,
cancellable,
error);
- if (plugin->priv->installation == NULL)
+ if (priv->installation == NULL)
return FALSE;
/* watch for changes */
- plugin->priv->monitor =
- xdg_app_installation_create_monitor (plugin->priv->installation,
+ priv->monitor =
+ xdg_app_installation_create_monitor (priv->installation,
cancellable,
error);
- if (plugin->priv->monitor == NULL)
+ if (priv->monitor == NULL)
return FALSE;
- g_signal_connect (plugin->priv->monitor, "changed",
+ g_signal_connect (priv->monitor, "changed",
G_CALLBACK (gs_plugin_xdg_app_changed_cb), plugin);
/* success */
@@ -464,6 +467,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GError) error_md = NULL;
g_autoptr(GPtrArray) xrefs = NULL;
guint i;
@@ -478,7 +482,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
}
/* get apps and runtimes */
- xrefs = xdg_app_installation_list_installed_refs (plugin->priv->installation,
+ xrefs = xdg_app_installation_list_installed_refs (priv->installation,
cancellable, error);
if (xrefs == NULL)
return FALSE;
@@ -512,10 +516,11 @@ gs_plugin_add_sources (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GPtrArray) xremotes = NULL;
guint i;
- xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
+ xremotes = xdg_app_installation_list_remotes (priv->installation,
cancellable,
error);
if (xremotes == NULL)
@@ -556,11 +561,12 @@ gs_plugin_add_updates (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_autoptr(GPtrArray) xrefs = NULL;
/* get all the installed apps (no network I/O) */
- xrefs = xdg_app_installation_list_installed_refs (plugin->priv->installation,
+ xrefs = xdg_app_installation_list_installed_refs (priv->installation,
cancellable,
error);
if (xrefs == NULL)
@@ -609,6 +615,7 @@ gs_plugin_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GsPluginHelper helper;
guint i;
g_autoptr(GPtrArray) xrefs = NULL;
@@ -628,7 +635,7 @@ gs_plugin_refresh (GsPlugin *plugin,
helper.plugin = plugin;
/* get all the updates available from all remotes */
- xrefs = xdg_app_installation_list_installed_refs_for_update (plugin->priv->installation,
+ xrefs = xdg_app_installation_list_installed_refs_for_update (priv->installation,
cancellable,
error);
if (xrefs == NULL)
@@ -645,7 +652,7 @@ gs_plugin_refresh (GsPlugin *plugin,
/* fetch but do not deploy */
g_debug ("pulling update for %s",
xdg_app_ref_get_name (XDG_APP_REF (xref)));
- xref2 = xdg_app_installation_update (plugin->priv->installation,
+ xref2 = xdg_app_installation_update (priv->installation,
XDG_APP_UPDATE_FLAGS_NO_DEPLOY,
xdg_app_ref_get_kind (XDG_APP_REF (xref)),
xdg_app_ref_get_name (XDG_APP_REF (xref)),
@@ -669,6 +676,7 @@ gs_plugin_refine_item_origin_ui (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *origin;
guint i;
g_autoptr(GPtrArray) xremotes = NULL;
@@ -680,8 +688,9 @@ gs_plugin_refine_item_origin_ui (GsPlugin *plugin,
return TRUE;
/* find list of remotes */
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin-ui");
- xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::refine-origin-ui");
+ xremotes = xdg_app_installation_list_remotes (priv->installation,
cancellable,
error);
if (xremotes == NULL)
@@ -707,6 +716,7 @@ gs_plugin_refine_item_origin (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_autoptr(GPtrArray) xremotes = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
@@ -716,7 +726,8 @@ gs_plugin_refine_item_origin (GsPlugin *plugin,
return TRUE;
/* ensure metadata exists */
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-origin");
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::refine-origin");
if (!gs_plugin_refine_item_metadata (plugin, app, cancellable, error))
return FALSE;
@@ -725,7 +736,7 @@ gs_plugin_refine_item_origin (GsPlugin *plugin,
gs_app_get_xdgapp_name (app),
gs_app_get_xdgapp_arch (app),
gs_app_get_xdgapp_branch (app));
- xremotes = xdg_app_installation_list_remotes (plugin->priv->installation,
+ xremotes = xdg_app_installation_list_remotes (priv->installation,
cancellable,
error);
if (xremotes == NULL)
@@ -736,7 +747,7 @@ gs_plugin_refine_item_origin (GsPlugin *plugin,
g_autoptr(XdgAppRemoteRef) xref = NULL;
remote_name = xdg_app_remote_get_name (xremote);
g_debug ("looking at remote %s", remote_name);
- xref = xdg_app_installation_fetch_remote_ref_sync (plugin->priv->installation,
+ xref = xdg_app_installation_fetch_remote_ref_sync (priv->installation,
remote_name,
gs_app_get_xdgapp_kind (app),
gs_app_get_xdgapp_name (app),
@@ -769,6 +780,7 @@ gs_plugin_refine_item_commit (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(XdgAppRemoteRef) xref_remote = NULL;
@@ -780,8 +792,9 @@ gs_plugin_refine_item_commit (GsPlugin *plugin,
return FALSE;
}
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::fetch-remote-ref");
- xref_remote = xdg_app_installation_fetch_remote_ref_sync (plugin->priv->installation,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::fetch-remote-ref");
+ xref_remote = xdg_app_installation_fetch_remote_ref_sync (priv->installation,
gs_app_get_origin (app),
gs_app_get_xdgapp_kind (app),
gs_app_get_xdgapp_name (app),
@@ -869,6 +882,7 @@ gs_plugin_refine_item_state (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
guint i;
g_autoptr(GPtrArray) xrefs = NULL;
g_autoptr(AsProfileTask) ptask = NULL;
@@ -882,8 +896,9 @@ gs_plugin_refine_item_state (GsPlugin *plugin,
return FALSE;
/* get apps and runtimes */
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-action");
- xrefs = xdg_app_installation_list_installed_refs (plugin->priv->installation,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::refine-action");
+ xrefs = xdg_app_installation_list_installed_refs (priv->installation,
cancellable, error);
if (xrefs == NULL)
return FALSE;
@@ -906,7 +921,7 @@ gs_plugin_refine_item_state (GsPlugin *plugin,
if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN &&
gs_app_get_origin (app) != NULL) {
g_autoptr(XdgAppRemote) xremote = NULL;
- xremote = xdg_app_installation_get_remote_by_name (plugin->priv->installation,
+ xremote = xdg_app_installation_get_remote_by_name (priv->installation,
gs_app_get_origin (app),
cancellable, NULL);
if (xremote != NULL) {
@@ -964,6 +979,7 @@ gs_plugin_refine_item_runtime (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *commit;
const gchar *str;
gsize len = -1;
@@ -983,7 +999,7 @@ gs_plugin_refine_item_runtime (GsPlugin *plugin,
return TRUE;
/* this is quicker than doing network IO */
- installation_path = xdg_app_installation_get_path (plugin->priv->installation);
+ installation_path = xdg_app_installation_get_path (priv->installation);
installation_path_str = g_file_get_path (installation_path);
install_path = g_build_filename (installation_path_str,
gs_app_get_xdgapp_kind_as_str (app),
@@ -1005,7 +1021,7 @@ gs_plugin_refine_item_runtime (GsPlugin *plugin,
/* fetch from the server */
commit = gs_app_get_xdgapp_commit (app);
- data = xdg_app_installation_fetch_remote_metadata_sync (plugin->priv->installation,
+ data = xdg_app_installation_fetch_remote_metadata_sync (priv->installation,
gs_app_get_origin (app),
commit,
cancellable,
@@ -1030,6 +1046,7 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
gboolean ret;
guint64 download_size;
guint64 installed_size;
@@ -1084,8 +1101,9 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
}
/* just get the size of the runtime */
- ptask = as_profile_start_literal (plugin->profile, "xdg-app::refine-size");
- ret = xdg_app_installation_fetch_remote_size_sync (plugin->priv->installation,
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "xdg-app::refine-size");
+ ret = xdg_app_installation_fetch_remote_size_sync (priv->installation,
gs_app_get_origin (app),
gs_app_get_xdgapp_commit (app),
&download_size,
@@ -1124,7 +1142,7 @@ gs_plugin_xdg_app_refine_app (GsPlugin *plugin,
return TRUE;
/* profile */
- ptask = as_profile_start (plugin->profile,
+ ptask = as_profile_start (gs_plugin_get_profile (plugin),
"xdg-app::refine{%s}",
gs_app_get_id (app));
@@ -1181,6 +1199,7 @@ gs_plugin_launch (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
const gchar *branch = NULL;
/* only process this app if was created by this plugin */
@@ -1190,7 +1209,7 @@ gs_plugin_launch (GsPlugin *plugin,
branch = gs_app_get_xdgapp_branch (app);
if (branch == NULL)
branch = "master";
- return xdg_app_installation_launch (plugin->priv->installation,
+ return xdg_app_installation_launch (priv->installation,
gs_app_get_xdgapp_name (app),
NULL,
branch,
@@ -1208,6 +1227,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GsPluginHelper helper;
/* only process this app if was created by this plugin */
@@ -1220,7 +1240,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
/* remove */
gs_app_set_state (app, AS_APP_STATE_REMOVING);
- if (!xdg_app_installation_uninstall (plugin->priv->installation,
+ if (!xdg_app_installation_uninstall (priv->installation,
XDG_APP_REF_KIND_APP,
gs_app_get_xdgapp_name (app),
gs_app_get_xdgapp_arch (app),
@@ -1245,6 +1265,7 @@ gs_plugin_app_install (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GsPluginHelper helper;
g_autoptr(XdgAppInstalledRef) xref = NULL;
@@ -1289,7 +1310,7 @@ gs_plugin_app_install (GsPlugin *plugin,
g_debug ("%s is not already installed, so installing",
gs_app_get_id (runtime));
gs_app_set_state (runtime, AS_APP_STATE_INSTALLING);
- xref = xdg_app_installation_install (plugin->priv->installation,
+ xref = xdg_app_installation_install (priv->installation,
gs_app_get_origin (runtime),
gs_app_get_xdgapp_kind (runtime),
gs_app_get_xdgapp_name (runtime),
@@ -1312,14 +1333,14 @@ gs_plugin_app_install (GsPlugin *plugin,
if (gs_app_get_state (app) == AS_APP_STATE_AVAILABLE_LOCAL) {
g_autoptr(GFile) file = NULL;
file = g_file_new_for_path (gs_app_get_source_default (app));
- xref = xdg_app_installation_install_bundle (plugin->priv->installation,
+ xref = xdg_app_installation_install_bundle (priv->installation,
file,
gs_plugin_xdg_app_progress_cb,
&helper,
cancellable, error);
} else {
g_debug ("installing %s", gs_app_get_id (app));
- xref = xdg_app_installation_install (plugin->priv->installation,
+ xref = xdg_app_installation_install (priv->installation,
gs_app_get_origin (app),
gs_app_get_xdgapp_kind (app),
gs_app_get_xdgapp_name (app),
@@ -1347,6 +1368,7 @@ gs_plugin_update_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
GsPluginHelper helper;
g_autoptr(XdgAppInstalledRef) xref = NULL;
@@ -1360,7 +1382,7 @@ gs_plugin_update_app (GsPlugin *plugin,
/* install */
gs_app_set_state (app, AS_APP_STATE_INSTALLING);
- xref = xdg_app_installation_update (plugin->priv->installation,
+ xref = xdg_app_installation_update (priv->installation,
XDG_APP_UPDATE_FLAGS_NONE,
gs_app_get_xdgapp_kind (app),
gs_app_get_xdgapp_name (app),
@@ -1478,7 +1500,8 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
}
/* load icon */
- icon_data = xdg_app_bundle_ref_get_icon (xref_bundle, 64 * plugin->scale);
+ icon_data = xdg_app_bundle_ref_get_icon (xref_bundle,
+ 64 * gs_plugin_get_scale (plugin));
if (icon_data == NULL)
icon_data = xdg_app_bundle_ref_get_icon (xref_bundle, 64);
if (icon_data != NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]