[gnome-control-center] shell: Pass args to existing panels
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] shell: Pass args to existing panels
- Date: Thu, 20 Sep 2012 20:59:01 +0000 (UTC)
commit 876d41b141ee102fc383369459827101af406e69
Author: Bastien Nocera <hadess hadess net>
Date: Thu Sep 20 20:58:28 2012 +0200
shell: Pass args to existing panels
When re-activating the same panel, we could destroy and recreate the
panel, or better reuse the panel, and set the new argv
(usually to switch pages).
Since we're changing the "argv" property of panels to not be construct-
only anymore, we reviewed the panels for potential memory leaks as well.
https://bugzilla.gnome.org/show_bug.cgi?id=684490
shell/cc-panel.c | 2 +-
shell/gnome-control-center.c | 29 +++++++++++++++++++++++------
2 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/shell/cc-panel.c b/shell/cc-panel.c
index fd2617c..8c327a2 100644
--- a/shell/cc-panel.c
+++ b/shell/cc-panel.c
@@ -212,7 +212,7 @@ cc_panel_class_init (CcPanelClass *klass)
"Argument vector",
"Additional arguments passed on the command line",
G_TYPE_STRV,
- G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_ARGV, pspec);
}
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index 5321471..1e45188 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -69,6 +69,8 @@ struct _GnomeControlCenterPrivate
GtkWidget *scrolled_window;
GtkWidget *search_scrolled;
GtkWidget *current_panel_box;
+ GtkWidget *current_panel;
+ char *current_panel_id;
GtkWidget *window;
GtkWidget *search_entry;
GtkWidget *lock_button;
@@ -183,7 +185,6 @@ activate_panel (GnomeControlCenter *shell,
GnomeControlCenterPrivate *priv = shell->priv;
GType panel_type = G_TYPE_INVALID;
GList *panels, *l;
- GtkWidget *panel;
GtkWidget *box;
const gchar *icon_name;
@@ -218,17 +219,17 @@ activate_panel (GnomeControlCenter *shell,
}
/* create the panel plugin */
- panel = g_object_new (panel_type, "shell", shell, "argv", argv, NULL);
- cc_shell_set_active_panel (CC_SHELL (shell), CC_PANEL (panel));
- gtk_widget_show (panel);
+ priv->current_panel = g_object_new (panel_type, "shell", shell, "argv", argv, NULL);
+ cc_shell_set_active_panel (CC_SHELL (shell), CC_PANEL (priv->current_panel));
+ gtk_widget_show (priv->current_panel);
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button),
- cc_panel_get_permission (CC_PANEL (panel)));
+ cc_panel_get_permission (CC_PANEL (priv->current_panel)));
box = gtk_alignment_new (0, 0, 1, 1);
gtk_alignment_set_padding (GTK_ALIGNMENT (box), 6, 6, 6, 6);
- gtk_container_add (GTK_CONTAINER (box), panel);
+ gtk_container_add (GTK_CONTAINER (box), priv->current_panel);
gtk_widget_set_name (box, id);
notebook_add_page (priv->notebook, box);
@@ -275,6 +276,7 @@ shell_show_overview_page (GnomeControlCenter *center)
if (priv->current_panel_box)
notebook_remove_page (priv->notebook, priv->current_panel_box);
+ priv->current_panel = NULL;
priv->current_panel_box = NULL;
/* clear the search text */
@@ -956,6 +958,15 @@ _shell_set_active_panel_from_id (CcShell *shell,
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (shell)->priv;
GtkWidget *old_panel;
+ /* When loading the same panel again, just set the argv */
+ if (g_strcmp0 (priv->current_panel_id, start_id) == 0)
+ {
+ g_object_set (G_OBJECT (priv->current_panel), "argv", argv, NULL);
+ return TRUE;
+ }
+
+ g_free (priv->current_panel_id);
+
/* clear any custom widgets */
_shell_remove_all_custom_widgets (priv);
@@ -1011,6 +1022,10 @@ _shell_set_active_panel_from_id (CcShell *shell,
if (old_panel)
notebook_remove_page (priv->notebook, old_panel);
}
+ else
+ {
+ priv->current_panel_id = g_strdup (start_id);
+ }
g_free (name);
g_free (desktop);
@@ -1058,6 +1073,8 @@ gnome_control_center_dispose (GObject *object)
{
GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv;
+ g_free (priv->current_panel_id);
+
if (priv->custom_widgets)
{
g_ptr_array_unref (priv->custom_widgets);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]