* Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com> * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * This library 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 * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <https://www.gnu.org/licenses/>. #include <gplugin-gtk-store.h> #include <gplugin-gtk-view.h> * A [class@Gtk.TreeView] widget that displays all the plugins and some basic * information about them. /****************************************************************************** *****************************************************************************/ /****************************************************************************** *****************************************************************************/ static GParamSpec *properties[N_PROPERTIES] = { /****************************************************************************** *****************************************************************************/ gplugin_gtk_view_plugin_toggled_cb( G_GNUC_UNUSED GtkCellRendererToggle *rend, GPluginGtkView *view = GPLUGIN_GTK_VIEW(data); GPluginManager *manager = NULL; GPluginPlugin *plugin = NULL; GPluginPluginState state; GtkTreeModel *model = NULL; GtkTreePath *tree_path = NULL; manager = gplugin_manager_get_default(); 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); GPLUGIN_GTK_STORE_PLUGIN_COLUMN, if(!GPLUGIN_IS_PLUGIN(plugin)) { state = gplugin_plugin_get_state(plugin); if(state == GPLUGIN_PLUGIN_STATE_LOADED) { gplugin_manager_unload_plugin(manager, plugin, &error); g_warning("Failed to unload plugin: %s", error->message); gplugin_manager_load_plugin(manager, plugin, &error); g_warning("Failed to load plugin: %s", error->message); g_object_unref(G_OBJECT(plugin)); /****************************************************************************** *****************************************************************************/ G_DEFINE_TYPE(GPluginGtkView, gplugin_gtk_view, GTK_TYPE_TREE_VIEW) gplugin_gtk_view_set_property( GPluginGtkView *view = GPLUGIN_GTK_VIEW(obj); gplugin_gtk_view_set_show_internal( g_value_get_boolean(value)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); gplugin_gtk_view_get_property( GPluginGtkView *view = GPLUGIN_GTK_VIEW(obj); gplugin_gtk_view_get_show_internal(view)); G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); gplugin_gtk_view_init(GPluginGtkView *view) GtkTreeViewColumn *col = NULL; GtkCellRenderer *rend = NULL; /* create the first column */ col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "Enabled"); gtk_tree_view_column_set_resizable(col, FALSE); rend = gtk_cell_renderer_toggle_new(); gtk_tree_view_column_pack_start(col, rend, FALSE); G_CALLBACK(gplugin_gtk_view_plugin_toggled_cb), gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); gtk_tree_view_column_set_attributes( GPLUGIN_GTK_STORE_LOADED_COLUMN, GPLUGIN_GTK_STORE_ENABLED_COLUMN, /* create the markup column */ col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "Name"); gtk_tree_view_column_set_resizable(col, FALSE); rend = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, rend, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); gtk_tree_view_column_set_attributes( GPLUGIN_GTK_STORE_MARKUP_COLUMN, GPLUGIN_GTK_STORE_ENABLED_COLUMN, gplugin_gtk_view_class_init(GPluginGtkViewClass *klass) GObjectClass *obj_class = G_OBJECT_CLASS(klass); obj_class->get_property = gplugin_gtk_view_get_property; obj_class->set_property = gplugin_gtk_view_set_property; * GPluginGtkView:show-internal: * Whether or not to show internal plugins. properties[PROP_SHOW_INTERNAL] = g_param_spec_boolean( "Whether or not to show internal plugins", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties(obj_class, N_PROPERTIES, properties); /****************************************************************************** *****************************************************************************/ * Creates a new [class@GPluginGtk3.View]. * Returns: (transfer full): The new view. gplugin_gtk_view_new(void) GPluginGtkStore *store = gplugin_gtk_store_new(); "model", GTK_TREE_MODEL(store), * gplugin_gtk_view_set_show_internal: * @view: The GTK view instance. * @show_internal: Whether or not to show internal plugins. * This function will toggle whether or not the widget will show internal gplugin_gtk_view_set_show_internal(GPluginGtkView *view, gboolean show_internal) g_return_if_fail(GPLUGIN_GTK_IS_VIEW(view)); view->show_internal = show_internal; g_object_notify(G_OBJECT(view), "show-internal"); * gplugin_gtk_view_get_show_internal: * @view: The GTK view instance. * Returns whether or not @view is showing internal plugins. gplugin_gtk_view_get_show_internal(GPluginGtkView *view) g_return_val_if_fail(GPLUGIN_GTK_IS_VIEW(view), FALSE); return view->show_internal;