gplugin/gplugin

ff45fa162341
Merged in feature/gplugin-gtk-view-cleanups (pull request #37)

Feature/gplugin gtk view cleanups

Approved-by: Elliott Sales de Andrade
--- a/gplugin-gtk/gplugin-gtk-plugin-info.c Fri Nov 08 04:55:27 2019 +0000
+++ b/gplugin-gtk/gplugin-gtk-plugin-info.c Fri Nov 08 04:55:47 2019 +0000
@@ -314,19 +314,11 @@
gplugin_gtk_plugin_info_set_plugin(GPluginGtkPluginInfo *info,
GPluginPlugin *plugin)
{
- GPluginPlugin *orig_plugin;
-
g_return_if_fail(GPLUGIN_GTK_IS_PLUGIN_INFO(info));
- orig_plugin = info->plugin;
- if(GPLUGIN_IS_PLUGIN(plugin)) {
- info->plugin = GPLUGIN_PLUGIN(g_object_ref(G_OBJECT(plugin)));
- } else {
- info->plugin = NULL;
+ if(g_set_object(&info->plugin, plugin)) {
+ _gplugin_gtk_plugin_info_refresh(info, plugin);
}
- g_object_unref(G_OBJECT(orig_plugin));
-
- _gplugin_gtk_plugin_info_refresh(info, plugin);
}
/**
--- a/gplugin-gtk/gplugin-gtk-store.c Fri Nov 08 04:55:27 2019 +0000
+++ b/gplugin-gtk/gplugin-gtk-store.c Fri Nov 08 04:55:47 2019 +0000
@@ -72,6 +72,7 @@
gplugin_gtk_store_add_plugin(GPluginGtkStore *store, GPluginPlugin *plugin) {
GtkTreeIter iter;
GPluginPluginInfo *info = gplugin_plugin_get_info(plugin);
+ GPluginPluginState state = gplugin_plugin_get_state(plugin);
GString *str = g_string_new("");
gchar *name = NULL, *summary = NULL;
@@ -90,7 +91,7 @@
gtk_list_store_append(GTK_LIST_STORE(store), &iter);
gtk_list_store_set(GTK_LIST_STORE(store), &iter,
- GPLUGIN_GTK_STORE_LOADED_COLUMN, FALSE,
+ GPLUGIN_GTK_STORE_LOADED_COLUMN, state == GPLUGIN_PLUGIN_STATE_LOADED,
GPLUGIN_GTK_STORE_PLUGIN_COLUMN, g_object_ref(plugin),
GPLUGIN_GTK_STORE_MARKUP_COLUMN, str->str,
-1);
@@ -109,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);
@@ -123,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 Fri Nov 08 04:55:27 2019 +0000
+++ b/gplugin-gtk/gplugin-gtk-view.c Fri Nov 08 04:55:47 2019 +0000
@@ -18,6 +18,8 @@
#include <gplugin-gtk/gplugin-gtk-view.h>
#include <gplugin-gtk/gplugin-gtk-store.h>
+#include <gplugin/gplugin.h>
+
/**
* SECTION:gplugin-gtk-view
* @Title: Gtk+ View for gplugins
@@ -59,7 +61,65 @@
static GParamSpec *properties[N_PROPERTIES] = {NULL,};
/******************************************************************************
- * GObject Stuff
+ * Callbacks
+ *****************************************************************************/
+static void
+gplugin_gtk_view_plugin_toggled_cb(GtkCellRendererToggle *rend,
+ gchar *path,
+ gpointer data)
+{
+ GPluginGtkView *view = GPLUGIN_GTK_VIEW(data);
+ GPluginPlugin *plugin = NULL;
+ GPluginPluginState state;
+ GtkTreeModel *model = NULL;
+ GtkTreeIter iter;
+ GtkTreePath *tree_path = NULL;
+
+ tree_path = gtk_tree_path_new_from_string(path);
+
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
+ gtk_tree_model_get_iter(model, &iter, tree_path);
+ gtk_tree_path_free(tree_path);
+
+ gtk_tree_model_get(
+ model,
+ &iter,
+ GPLUGIN_GTK_STORE_PLUGIN_COLUMN, &plugin,
+ -1
+ );
+
+ if(!GPLUGIN_IS_PLUGIN(plugin)) {
+ return;
+ }
+
+ state = gplugin_plugin_get_state(plugin);
+ if(state == GPLUGIN_PLUGIN_STATE_LOADED) {
+ GError *error = NULL;
+
+ gplugin_manager_unload_plugin(plugin, &error);
+
+ if(error != NULL) {
+ g_warning("Failed to unload plugin: %s", error->message);
+
+ g_error_free(error);
+ }
+ } else {
+ GError *error = NULL;
+
+ gplugin_manager_load_plugin(plugin, &error);
+
+ if(error != NULL) {
+ g_warning("Failed to load plugin: %s", error->message);
+
+ g_error_free(error);
+ }
+ }
+
+ g_object_unref(G_OBJECT(plugin));
+}
+
+/******************************************************************************
+ * GObject Implementation
*****************************************************************************/
G_DEFINE_TYPE(GPluginGtkView, gplugin_gtk_view, GTK_TYPE_TREE_VIEW);
@@ -112,10 +172,6 @@
GtkTreeViewColumn *col = NULL;
GtkCellRenderer *rend = NULL;
- gtk_widget_set_has_tooltip(GTK_WIDGET(view), TRUE);
-
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
-
/* create the first column */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Enabled");
@@ -123,6 +179,8 @@
rend = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(col, rend, FALSE);
+ g_signal_connect(G_OBJECT(rend), "toggled",
+ G_CALLBACK(gplugin_gtk_view_plugin_toggled_cb), view);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
gtk_tree_view_column_add_attribute(col, rend, "active",
--- a/gplugin/gplugin-manager.c Fri Nov 08 04:55:27 2019 +0000
+++ b/gplugin/gplugin-manager.c Fri Nov 08 04:55:47 2019 +0000
@@ -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.
*/