qulogic/gplugin

Connect GPluginGtkStore to the manager's load/unload signals.
feature/gplugin-gtk-view-cleanups
2019-11-07, Gary Kramlich
193af070e88d
Parents a5e251b58087
Children b640f9a13a27
Connect GPluginGtkStore to the manager's load/unload signals.
--- a/gplugin-gtk/gplugin-gtk-store.c Thu Nov 07 21:33:40 2019 -0600
+++ b/gplugin-gtk/gplugin-gtk-store.c Thu Nov 07 22:07:30 2019 -0600
@@ -110,11 +110,72 @@
gplugin_manager_free_plugin_list(plugins);
}
+static gboolean
+gplugin_gtk_store_update_plugin_state_cb(GtkTreeModel *model, GtkTreePath *path,
+ GtkTreeIter *iter, gpointer data)
+{
+ GPluginPlugin *plugin_a = GPLUGIN_PLUGIN(data);
+ GPluginPlugin *plugin_b = NULL;
+ gboolean ret = FALSE;
+
+ gtk_tree_model_get(
+ model, iter,
+ GPLUGIN_GTK_STORE_PLUGIN_COLUMN, &plugin_b,
+ -1
+ );
+
+ if(plugin_a == plugin_b) {
+ gboolean loaded = gplugin_plugin_get_state(plugin_a) == GPLUGIN_PLUGIN_STATE_LOADED;
+
+ gtk_list_store_set(
+ GTK_LIST_STORE(model), iter,
+ GPLUGIN_GTK_STORE_LOADED_COLUMN, loaded,
+ -1
+ );
+
+ /* tell gplugin_gtk_store_update_plugin_state that we're done */
+ ret = TRUE;
+ }
+
+ g_object_unref(G_OBJECT(plugin_b));
+
+ return ret;
+}
+
+static void
+gplugin_gtk_store_update_plugin_state(GPluginGtkStore *store,
+ GPluginPlugin *plugin)
+{
+ gtk_tree_model_foreach(
+ GTK_TREE_MODEL(store),
+ gplugin_gtk_store_update_plugin_state_cb,
+ plugin
+ );
+}
+
/******************************************************************************
- * GObject Stuff
+ * Callbacks
+ *****************************************************************************/
+static void
+gplugin_gtk_store_plugin_loaded_cb(GObject *manager, GPluginPlugin *plugin,
+ gpointer data)
+{
+ gplugin_gtk_store_update_plugin_state(GPLUGIN_GTK_STORE(data), plugin);
+}
+
+static void
+gplugin_gtk_store_plugin_unloaded_cb(GObject *manager, GPluginPlugin *plugin,
+ gpointer data)
+{
+ gplugin_gtk_store_update_plugin_state(GPLUGIN_GTK_STORE(data), plugin);
+}
+
+/******************************************************************************
+ * GObject Implementation
*****************************************************************************/
static void
gplugin_gtk_store_constructed(GObject *obj) {
+ GObject *manager = NULL;
GList *l, *ids = NULL;
G_OBJECT_CLASS(gplugin_gtk_store_parent_class)->constructed(obj);
@@ -124,6 +185,12 @@
gplugin_gtk_store_add_plugin_by_id(GPLUGIN_GTK_STORE(obj),
(const gchar *)l->data);
g_list_free(ids);
+
+ manager = gplugin_manager_get_instance();
+ g_signal_connect(manager, "loaded-plugin",
+ G_CALLBACK(gplugin_gtk_store_plugin_loaded_cb), obj);
+ g_signal_connect(manager, "unloaded-plugin",
+ G_CALLBACK(gplugin_gtk_store_plugin_unloaded_cb), obj);
}
static void
--- a/gplugin-gtk/gplugin-gtk-view.c Thu Nov 07 21:33:40 2019 -0600
+++ b/gplugin-gtk/gplugin-gtk-view.c Thu Nov 07 22:07:30 2019 -0600
@@ -74,7 +74,6 @@
GtkTreeModel *model = NULL;
GtkTreeIter iter;
GtkTreePath *tree_path = NULL;
- gboolean loaded = FALSE;
tree_path = gtk_tree_path_new_from_string(path);
@@ -97,22 +96,17 @@
if(state == GPLUGIN_PLUGIN_STATE_LOADED) {
GError *error = NULL;
- gboolean unloaded = gplugin_manager_unload_plugin(plugin, &error);
+ gplugin_manager_unload_plugin(plugin, &error);
if(error != NULL) {
g_warning("Failed to unload plugin: %s", error->message);
g_error_free(error);
}
-
- /* if unload failed, unloaded is set to false, which mean the plugin is
- * still loaded. So we set loaded to the negated value of unloaded.
- */
- loaded = !unloaded;
} else {
GError *error = NULL;
- loaded = gplugin_manager_load_plugin(plugin, &error);
+ gplugin_manager_load_plugin(plugin, &error);
if(error != NULL) {
g_warning("Failed to load plugin: %s", error->message);
@@ -120,13 +114,6 @@
g_error_free(error);
}
}
-
- gtk_list_store_set(
- GTK_LIST_STORE(model),
- &iter,
- GPLUGIN_GTK_STORE_LOADED_COLUMN, loaded,
- -1
- );
}
/******************************************************************************
--- a/gplugin/gplugin-manager.c Thu Nov 07 21:33:40 2019 -0600
+++ b/gplugin/gplugin-manager.c Thu Nov 07 22:07:30 2019 -0600
@@ -974,7 +974,6 @@
* GPluginManager::loaded-plugin:
* @manager: the #gpluginpluginmanager instance. treat as a #gobject.
* @plugin: the #gpluginplugin that's about to be loaded.
- * @error: return address for a #gerror.
*
* emitted after a plugin is loaded.
*/
@@ -1034,7 +1033,6 @@
* GPluginManager::unloaded-plugin:
* @manager: the #gpluginpluginmanager instance. treat as a #gobject.
* @plugin: the #gpluginplugin that's about to be loaded.
- * @error: return address for a #gerror.
*
* emitted after a plugin is unloaded.
*/