[libpeas] Show dialog when disabling a plugin which is depended on
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Show dialog when disabling a plugin which is depended on
- Date: Fri, 18 Feb 2011 01:09:08 +0000 (UTC)
commit 8a125f613d1a7303b9124380f73c398b4fbf00af
Author: Garrett Regier <alias301 gmail com>
Date: Tue Jan 25 09:43:47 2011 -0800
Show dialog when disabling a plugin which is depended on
docs/reference/Makefile.am | 1 +
libpeas-gtk/Makefile.am | 8 +-
libpeas-gtk/peas-gtk-disable-plugins-dialog.c | 308 +++++++++++++++++++++++++
libpeas-gtk/peas-gtk-disable-plugins-dialog.h | 63 +++++
libpeas-gtk/peas-gtk-plugin-manager-view.c | 75 ++++++-
po/POTFILES.in | 1 +
6 files changed, 450 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 477d87c..4f41c9c 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -61,6 +61,7 @@ IGNORE_HFILES= \
peas-extension-seed.h \
peas-extension-python.h \
peas-introspection.h \
+ peas-gtk-disable-plugins-dialog.h \
peas-gtk-plugin-manager-store.h \
peas-demo-window.h \
peasdemo-hello-world-plugin.h \
diff --git a/libpeas-gtk/Makefile.am b/libpeas-gtk/Makefile.am
index ae439c2..94326b7 100644
--- a/libpeas-gtk/Makefile.am
+++ b/libpeas-gtk/Makefile.am
@@ -24,12 +24,14 @@ INST_H_FILES = \
peas-gtk.h
NOINST_H_FILES = \
+ peas-gtk-disable-plugins-dialog.h \
peas-gtk-plugin-manager-store.h
C_FILES = \
- peas-gtk-configurable.c \
- peas-gtk-plugin-manager.c \
- peas-gtk-plugin-manager-store.c \
+ peas-gtk-configurable.c \
+ peas-gtk-plugin-manager.c \
+ peas-gtk-disable-plugins-dialog.c \
+ peas-gtk-plugin-manager-store.c \
peas-gtk-plugin-manager-view.c
libpeas_gtk_1_0_la_SOURCES = \
diff --git a/libpeas-gtk/peas-gtk-disable-plugins-dialog.c b/libpeas-gtk/peas-gtk-disable-plugins-dialog.c
new file mode 100644
index 0000000..bc12741
--- /dev/null
+++ b/libpeas-gtk/peas-gtk-disable-plugins-dialog.c
@@ -0,0 +1,308 @@
+/*
+ * peas-gtk-disable-plugins-dialog.c
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 Garrett Regier
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libpeas/peas-i18n.h>
+#include <libpeas/peas-plugin-info.h>
+
+#include "peas-gtk-disable-plugins-dialog.h"
+
+enum {
+ PLUGIN_INFO_NAME_COLUMN = 0
+};
+
+struct _PeasGtkDisablePluginsDialogPrivate {
+ PeasPluginInfo *plugin_info;
+ GList *dep_plugins;
+};
+
+/* Properties */
+enum {
+ PROP_0,
+ PROP_PLUGIN_INFO,
+ PROP_DEPENDANT_PLUGINS
+};
+
+G_DEFINE_TYPE (PeasGtkDisablePluginsDialog,
+ peas_gtk_disable_plugins_dialog,
+ GTK_TYPE_MESSAGE_DIALOG);
+
+static gint
+model_name_sort_func (GtkListStore *store,
+ GtkTreeIter *iter1,
+ GtkTreeIter *iter2,
+ gpointer user_data)
+{
+ gchar *name1, *name2;
+ gint retval;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (store), iter1,
+ PLUGIN_INFO_NAME_COLUMN, &name1,
+ -1);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (store), iter1,
+ PLUGIN_INFO_NAME_COLUMN, &name2,
+ -1);
+
+ retval = g_utf8_collate (name1, name2);
+
+ g_free (name1);
+ g_free (name2);
+
+ return retval;
+}
+
+static void
+build_multiple_dependant_plugins (PeasGtkDisablePluginsDialog *dialog)
+{
+ gchar *message;
+ GtkWidget *message_area;
+ GtkWidget *sw;
+ GtkListStore *store;
+ GList *dep_plugin;
+ GtkWidget *tree_view;
+ GtkCellRenderer *cell;
+
+ message = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
+ _("Additional plugins must be disabled"),
+ "</span>", NULL);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), message);
+ g_free (message);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("The following plugins depend on '%s' and will also be disabled:"),
+ peas_plugin_info_get_name (dialog->priv->plugin_info));
+
+ message_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
+ GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (message_area), sw, TRUE, TRUE, 0);
+
+ store = gtk_list_store_new (1, G_TYPE_STRING);
+
+ /* Sort on the plugin names */
+ gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
+ (GtkTreeIterCompareFunc) model_name_sort_func,
+ NULL, NULL);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+ GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
+ GTK_SORT_ASCENDING);
+
+ for (dep_plugin = dialog->priv->dep_plugins; dep_plugin != NULL;
+ dep_plugin = dep_plugin->next)
+ {
+ PeasPluginInfo *plugin = (PeasPluginInfo *) dep_plugin->data;
+ GtkTreeIter iter;
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ PLUGIN_INFO_NAME_COLUMN, peas_plugin_info_get_name (plugin),
+ -1);
+ }
+
+ tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
+ gtk_tree_view_set_enable_search (GTK_TREE_VIEW (tree_view), FALSE);
+ gtk_widget_set_size_request (tree_view, 260, 120);
+ gtk_container_add (GTK_CONTAINER (sw), tree_view);
+
+ cell = gtk_cell_renderer_text_new ();
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
+ 0, _("Plugins"),
+ cell,
+ "text", PLUGIN_INFO_NAME_COLUMN,
+ NULL);
+
+ g_object_unref (store);
+
+ gtk_widget_show_all (sw);
+}
+
+static void
+build_single_dependant_plugin (PeasGtkDisablePluginsDialog *dialog)
+{
+ gchar *message;
+
+ message = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
+ _("An additional plugin must be disabled"),
+ "</span>", NULL);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), message);
+ g_free (message);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("The '%s' plugin depends on the '%s' plugin.\n"
+ "If you disable '%s', '%s' will also be disabled."),
+ peas_plugin_info_get_name (dialog->priv->plugin_info),
+ peas_plugin_info_get_name (dialog->priv->dep_plugins->data),
+ peas_plugin_info_get_name (dialog->priv->plugin_info),
+ peas_plugin_info_get_name (dialog->priv->dep_plugins->data));
+}
+
+static void
+peas_gtk_disable_plugins_dialog_init (PeasGtkDisablePluginsDialog *dialog)
+{
+ dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
+ PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG,
+ PeasGtkDisablePluginsDialogPrivate);
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+#if !GTK_CHECK_VERSION(2,90,7)
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+#endif
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("Disable Plugins"), GTK_RESPONSE_OK);
+}
+
+static void
+peas_gtk_disable_plugins_dialog_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
+
+ switch (prop_id)
+ {
+ case PROP_PLUGIN_INFO:
+ dialog->priv->plugin_info = g_value_get_pointer (value);
+ break;
+ case PROP_DEPENDANT_PLUGINS:
+ dialog->priv->dep_plugins = g_value_get_pointer (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+peas_gtk_disable_plugins_dialog_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
+
+ switch (prop_id)
+ {
+ case PROP_PLUGIN_INFO:
+ g_value_set_pointer (value, dialog->priv->plugin_info);
+ break;
+ case PROP_DEPENDANT_PLUGINS:
+ g_value_set_pointer (value, dialog->priv->dep_plugins);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+peas_gtk_disable_plugins_dialog_constructed (GObject *object)
+{
+ PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
+
+ if (dialog->priv->dep_plugins->next == NULL)
+ build_single_dependant_plugin (dialog);
+ else
+ build_multiple_dependant_plugins (dialog);
+
+ if (G_OBJECT_CLASS (peas_gtk_disable_plugins_dialog_parent_class)->constructed != NULL)
+ G_OBJECT_CLASS (peas_gtk_disable_plugins_dialog_parent_class)->constructed (object);
+}
+
+static void
+peas_gtk_disable_plugins_dialog_finalize (GObject *object)
+{
+ PeasGtkDisablePluginsDialog *dialog = PEAS_GTK_DISABLE_PLUGINS_DIALOG (object);
+
+ g_list_free (dialog->priv->dep_plugins);
+
+ G_OBJECT_CLASS (peas_gtk_disable_plugins_dialog_parent_class)->finalize (object);
+}
+
+static void
+peas_gtk_disable_plugins_dialog_class_init (PeasGtkDisablePluginsDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = peas_gtk_disable_plugins_dialog_get_property;
+ object_class->set_property = peas_gtk_disable_plugins_dialog_set_property;
+ object_class->constructed = peas_gtk_disable_plugins_dialog_constructed;
+ object_class->finalize = peas_gtk_disable_plugins_dialog_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_PLUGIN_INFO,
+ g_param_spec_pointer ("plugin-info",
+ "Plugin Information",
+ "Plugin that is being disabled",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_DEPENDANT_PLUGINS,
+ g_param_spec_pointer ("dependant-plugins",
+ "Dependant plugins",
+ "Dependant plugins",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (object_class, sizeof (PeasGtkDisablePluginsDialogPrivate));
+}
+
+/*
+ * peas_gtk_disable_plugins_dialog_new:
+ * @parent: transient window.
+ * @info: the #PeasPluginInfo being disabled.
+ * @dep_plugins: (transfer container) (element-type Peas.PluginInfo):
+ * list of plugins that are dependant on @info.
+ *
+ * Creates a new #PeasGtkDisablePluginsDialog.
+ *
+ * Returns: the new #PeasGtkDisablePluginsDialog.
+ */
+GtkWidget *
+peas_gtk_disable_plugins_dialog_new (GtkWindow *parent,
+ PeasPluginInfo *info,
+ GList *dep_plugins)
+{
+ return GTK_WIDGET (g_object_new (PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG,
+ "transient-for", parent,
+ "plugin-info", info,
+ "dependant-plugins", dep_plugins,
+ "message-type", GTK_MESSAGE_QUESTION,
+ NULL));
+}
diff --git a/libpeas-gtk/peas-gtk-disable-plugins-dialog.h b/libpeas-gtk/peas-gtk-disable-plugins-dialog.h
new file mode 100644
index 0000000..ee06d44
--- /dev/null
+++ b/libpeas-gtk/peas-gtk-disable-plugins-dialog.h
@@ -0,0 +1,63 @@
+/*
+ * peas-gtk-disable-plugins-dialog.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 Garrett Regier
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PEAS_GTK_DISABLE_PLUGINS_DIALOG_H__
+#define __PEAS_GTK_DISABLE_PLUGINS_DIALOG_H__
+
+#include <gtk/gtk.h>
+#include <libpeas/peas-plugin-info.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG (peas_gtk_disable_plugins_dialog_get_type())
+#define PEAS_GTK_DISABLE_PLUGINS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG, PeasGtkDisablePluginsDialog))
+#define PEAS_GTK_DISABLE_PLUGINS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG, PeasGtkDisablePluginsDialogClass))
+#define PEAS_GTK_IS_DISABLE_PLUGINS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG))
+#define PEAS_GTK_IS_DISABLE_PLUGINS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG))
+#define PEAS_GTK_DISABLE_PLUGINS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PEAS_GTK_TYPE_DISABLE_PLUGINS_DIALOG, PeasGtkDisablePluginsDialogClass))
+
+typedef struct _PeasGtkDisablePluginsDialog PeasGtkDisablePluginsDialog;
+typedef struct _PeasGtkDisablePluginsDialogClass PeasGtkDisablePluginsDialogClass;
+typedef struct _PeasGtkDisablePluginsDialogPrivate PeasGtkDisablePluginsDialogPrivate;
+
+struct _PeasGtkDisablePluginsDialog {
+ GtkMessageDialog parent;
+
+ /*< private > */
+ PeasGtkDisablePluginsDialogPrivate *priv;
+};
+
+struct _PeasGtkDisablePluginsDialogClass {
+ GtkMessageDialogClass parent_class;
+};
+
+GType peas_gtk_disable_plugins_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget *peas_gtk_disable_plugins_dialog_new (GtkWindow *parent,
+ PeasPluginInfo *info,
+ GList *dep_plugins);
+
+G_END_DECLS
+
+#endif /* __PEAS_GTK_DISABLE_PLUGINS_DIALOG_H__ */
diff --git a/libpeas-gtk/peas-gtk-plugin-manager-view.c b/libpeas-gtk/peas-gtk-plugin-manager-view.c
index 2209591..ea862e4 100644
--- a/libpeas-gtk/peas-gtk-plugin-manager-view.c
+++ b/libpeas-gtk/peas-gtk-plugin-manager-view.c
@@ -28,9 +28,11 @@
#include <string.h>
+#include <libpeas/peas-engine.h>
#include <libpeas/peas-i18n.h>
#include "peas-gtk-plugin-manager-view.h"
+#include "peas-gtk-disable-plugins-dialog.h"
#include "peas-gtk-plugin-manager-store.h"
#include "peas-gtk-configurable.h"
@@ -118,6 +120,73 @@ convert_child_iter_to_iter (PeasGtkPluginManagerView *view,
return success;
}
+static GList *
+get_dependant_plugins (PeasGtkPluginManagerView *view,
+ PeasPluginInfo *info)
+{
+ const gchar *module_name;
+ const GList *plugins;
+ GList *dep_plugins = NULL;
+
+ module_name = peas_plugin_info_get_module_name (info);
+ plugins = peas_engine_get_plugin_list (view->priv->engine);
+
+ for (; plugins != NULL; plugins = plugins->next)
+ {
+ PeasPluginInfo *plugin = (PeasPluginInfo *) plugins->data;
+
+ if (!peas_plugin_info_is_loaded (plugin))
+ continue;
+
+ /* Don't add builtin plugins if they are not shown */
+ if (!view->priv->show_builtin && peas_plugin_info_is_builtin (plugin))
+ continue;
+
+ if (peas_plugin_info_has_dependency (plugin, module_name))
+ dep_plugins = g_list_prepend (dep_plugins, plugin);
+ }
+
+ return dep_plugins;
+}
+
+static void
+toggle_enabled (PeasGtkPluginManagerView *view,
+ GtkTreeIter *iter)
+{
+ PeasPluginInfo *info;
+
+ info = peas_gtk_plugin_manager_store_get_plugin (view->priv->store, iter);
+
+ if (peas_plugin_info_is_loaded (info))
+ {
+ GList *dep_plugins;
+
+ dep_plugins = get_dependant_plugins (view, info);
+
+ if (dep_plugins != NULL)
+ {
+ GtkWindow *parent;
+ GtkWidget *dialog;
+ gint response;
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
+
+ /* The dialog takes the list so don't free it */
+ dialog = peas_gtk_disable_plugins_dialog_new (parent, info,
+ dep_plugins);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ if (response != GTK_RESPONSE_OK)
+ return;
+ }
+ }
+
+ peas_gtk_plugin_manager_store_toggle_enabled (view->priv->store, iter);
+}
+
static void
plugin_list_changed_cb (PeasEngine *engine,
GParamSpec *pspec,
@@ -184,7 +253,7 @@ enabled_toggled_cb (GtkCellRendererToggle *cell,
if (gtk_tree_model_get_iter (model, &iter, path))
{
convert_iter_to_child_iter (view, &iter);
- peas_gtk_plugin_manager_store_toggle_enabled (view->priv->store, &iter);
+ toggle_enabled (view, &iter);
}
gtk_tree_path_free (path);
@@ -244,7 +313,7 @@ enabled_menu_cb (GtkMenu *menu,
convert_iter_to_child_iter (view, &iter);
- peas_gtk_plugin_manager_store_toggle_enabled (view->priv->store, &iter);
+ toggle_enabled (view, &iter);
}
static void
@@ -594,7 +663,7 @@ peas_gtk_plugin_manager_view_row_activated (GtkTreeView *tree_view,
convert_iter_to_child_iter (view, &iter);
if (peas_gtk_plugin_manager_store_can_enable (view->priv->store, &iter))
- peas_gtk_plugin_manager_store_toggle_enabled (view->priv->store, &iter);
+ toggle_enabled (view, &iter);
}
static void
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 210c932..7d1b725 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ libpeas/peas-engine.c
libpeas/peas-object-module.c
libpeas/peas-plugin-info.c
libpeas/peas-plugin-loader.c
+libpeas-gtk/peas-gtk-disable-plugins-dialog.c
libpeas-gtk/peas-gtk-plugin-manager.c
libpeas-gtk/peas-gtk-plugin-manager-view.c
peas-demo/peas-demo.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]