[gnome-panel] clock, fish, wncklet: Use a GBinding to track locked-down for popup menu
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] clock, fish, wncklet: Use a GBinding to track locked-down for popup menu
- Date: Thu, 24 Feb 2011 01:01:30 +0000 (UTC)
commit 21578a8d3cb8c39039b15fc6c547d26a5b0af71e
Author: Vincent Untz <vuntz gnome org>
Date: Thu Feb 24 02:00:08 2011 +0100
clock, fish, wncklet: Use a GBinding to track locked-down for popup menu
We don't need to monitor the property to change visibility of items in
popup menus: GBinding can do it for us.
applets/clock/clock.c | 14 ++++++-----
applets/fish/fish.c | 41 ++++++++++------------------------
applets/wncklet/window-list.c | 40 ++++++++++-----------------------
applets/wncklet/workspace-switcher.c | 40 ++++++++++-----------------------
4 files changed, 44 insertions(+), 91 deletions(-)
---
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index aec028b..3229103 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -2509,13 +2509,15 @@ fill_clock_applet (PanelApplet *applet)
ui_path, action_group);
g_free (ui_path);
- if (panel_applet_get_locked_down (PANEL_APPLET (cd->applet))) {
- action = gtk_action_group_get_action (action_group, "ClockPreferences");
- gtk_action_set_visible (action, FALSE);
+ action = gtk_action_group_get_action (action_group, "ClockPreferences");
+ g_object_bind_property (cd->applet, "locked-down",
+ action, "visible",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
- action = gtk_action_group_get_action (action_group, "ClockConfig");
- gtk_action_set_visible (action, FALSE);
- }
+ action = gtk_action_group_get_action (action_group, "ClockConfig");
+ g_object_bind_property (cd->applet, "locked-down",
+ action, "visible",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
cd->systz = system_timezone_new ();
g_signal_connect (cd->systz, "changed",
diff --git a/applets/fish/fish.c b/applets/fish/fish.c
index cdb185e..8d05ae9 100644
--- a/applets/fish/fish.c
+++ b/applets/fish/fish.c
@@ -82,8 +82,6 @@ typedef struct {
GdkPixbuf *pixbuf;
- GtkActionGroup *action_group;
-
GtkWidget *preferences_dialog;
GtkWidget *name_entry;
GtkWidget *command_label;
@@ -1621,20 +1619,6 @@ fish_applet_change_orient (PanelApplet *applet,
}
static void
-fish_applet_locked_down_notified (FishApplet *fish,
- GParamSpec *pspec,
- gpointer user_data)
-{
- gboolean locked_down;
- GtkAction *action;
-
- locked_down = panel_applet_get_locked_down (PANEL_APPLET (fish));
-
- action = gtk_action_group_get_action (fish->action_group, "FishPreferences");
- gtk_action_set_visible (action, !locked_down);
-}
-
-static void
change_water (FishApplet *fish)
{
GtkWidget *dialog;
@@ -1822,6 +1806,8 @@ static gboolean
fish_applet_fill (FishApplet *fish)
{
PanelApplet *applet = (PanelApplet *) fish;
+ GtkActionGroup *action_group;
+ GtkAction *action;
gchar *ui_path;
GError *error = NULL;
@@ -1887,21 +1873,22 @@ fish_applet_fill (FishApplet *fish)
fish->rotate = FALSE; /* Fallback */
}
- fish->action_group = gtk_action_group_new ("Fish Applet Actions");
- gtk_action_group_set_translation_domain (fish->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (fish->action_group,
+ action_group = gtk_action_group_new ("Fish Applet Actions");
+ gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (action_group,
fish_menu_verbs,
G_N_ELEMENTS (fish_menu_verbs),
fish);
ui_path = g_build_filename (FISH_MENU_UI_DIR, "fish-menu.xml", NULL);
- panel_applet_setup_menu_from_file (applet, ui_path, fish->action_group);
+ panel_applet_setup_menu_from_file (applet, ui_path, action_group);
g_free (ui_path);
- g_signal_connect (G_OBJECT (fish),
- "notify::locked-down",
- G_CALLBACK (fish_applet_locked_down_notified),
- NULL);
- fish_applet_locked_down_notified (fish, NULL, NULL);
+ action = gtk_action_group_get_action (action_group, "FishPreferences");
+ g_object_bind_property (applet, "locked-down",
+ action, "visible",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
+
+ g_object_unref (action_group);
#ifndef FISH_INPROCESS
gtk_window_set_default_icon_name (FISH_ICON);
@@ -1965,10 +1952,6 @@ fish_applet_dispose (GObject *object)
g_object_unref (fish->pixbuf);
fish->pixbuf = NULL;
- if (fish->action_group)
- g_object_unref (fish->action_group);
- fish->action_group = NULL;
-
if (fish->preferences_dialog)
gtk_widget_destroy (fish->preferences_dialog);
fish->preferences_dialog = NULL;
diff --git a/applets/wncklet/window-list.c b/applets/wncklet/window-list.c
index b2a6391..b0424f4 100644
--- a/applets/wncklet/window-list.c
+++ b/applets/wncklet/window-list.c
@@ -39,8 +39,6 @@ typedef struct {
int size;
GtkIconTheme *icon_theme;
-
- GtkActionGroup *action_group;
/* Properties: */
GtkWidget *properties_dialog;
@@ -136,20 +134,6 @@ applet_change_background (PanelApplet *applet,
}
static void
-applet_locked_down_notified (PanelApplet *applet,
- GParamSpec *pspec,
- TasklistData *tasklist)
-{
- gboolean locked_down;
- GtkAction *action;
-
- locked_down = panel_applet_get_locked_down (applet);
-
- action = gtk_action_group_get_action (tasklist->action_group, "TasklistPreferences");
- gtk_action_set_visible (action, !locked_down);
-}
-
-static void
applet_change_pixel_size (PanelApplet *applet,
gint size,
TasklistData *tasklist)
@@ -180,9 +164,6 @@ destroy_tasklist(GtkWidget * widget, TasklistData *tasklist)
if (tasklist->properties_dialog)
gtk_widget_destroy (tasklist->properties_dialog);
- if (tasklist->action_group)
- g_object_unref (tasklist->action_group);
-
g_free (tasklist);
}
@@ -452,6 +433,8 @@ gboolean
window_list_applet_fill (PanelApplet *applet)
{
TasklistData *tasklist;
+ GtkActionGroup *action_group;
+ GtkAction *action;
gchar *ui_path;
GError *error;
GConfValue *value;
@@ -542,26 +525,27 @@ window_list_applet_fill (PanelApplet *applet)
"change_background",
G_CALLBACK (applet_change_background),
tasklist);
- g_signal_connect (G_OBJECT (tasklist->applet),
- "notify::locked-down",
- G_CALLBACK (applet_locked_down_notified),
- tasklist);
panel_applet_set_background_widget (PANEL_APPLET (tasklist->applet),
GTK_WIDGET (tasklist->applet));
- tasklist->action_group = gtk_action_group_new ("Tasklist Applet Actions");
- gtk_action_group_set_translation_domain (tasklist->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (tasklist->action_group,
+ action_group = gtk_action_group_new ("Tasklist Applet Actions");
+ gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (action_group,
tasklist_menu_actions,
G_N_ELEMENTS (tasklist_menu_actions),
tasklist);
ui_path = g_build_filename (WNCK_MENU_UI_DIR, "window-list-menu.xml", NULL);
panel_applet_setup_menu_from_file (PANEL_APPLET (tasklist->applet),
- ui_path, tasklist->action_group);
+ ui_path, action_group);
g_free (ui_path);
- applet_locked_down_notified (applet, NULL, tasklist);
+ action = gtk_action_group_get_action (action_group, "TasklistPreferences");
+ g_object_bind_property (tasklist->applet, "locked-down",
+ action, "visible",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
+
+ g_object_unref (action_group);
gtk_widget_show (tasklist->applet);
diff --git a/applets/wncklet/workspace-switcher.c b/applets/wncklet/workspace-switcher.c
index 97e718b..f578139 100644
--- a/applets/wncklet/workspace-switcher.c
+++ b/applets/wncklet/workspace-switcher.c
@@ -52,8 +52,6 @@ typedef struct {
WnckScreen *screen;
PagerWM wm;
- GtkActionGroup *action_group;
-
/* Properties: */
GtkWidget *properties_dialog;
GtkWidget *workspaces_frame;
@@ -215,20 +213,6 @@ applet_change_background (PanelApplet *applet,
}
static void
-applet_locked_down_notified (PanelApplet *applet,
- GParamSpec *pspec,
- PagerData *pager)
-{
- gboolean locked_down;
- GtkAction *action;
-
- locked_down = panel_applet_get_locked_down (applet);
-
- action = gtk_action_group_get_action (pager->action_group, "PagerPreferences");
- gtk_action_set_visible (action, !locked_down);
-}
-
-static void
destroy_pager(GtkWidget * widget, PagerData *pager)
{
GConfClient *client = gconf_client_get_default ();
@@ -246,9 +230,6 @@ destroy_pager(GtkWidget * widget, PagerData *pager)
if (pager->properties_dialog)
gtk_widget_destroy (pager->properties_dialog);
- if (pager->action_group)
- g_object_unref (pager->action_group);
-
g_free (pager);
}
@@ -382,6 +363,8 @@ gboolean
workspace_switcher_applet_fill (PanelApplet *applet)
{
PagerData *pager;
+ GtkActionGroup *action_group;
+ GtkAction *action;
gchar *ui_path;
GError *error;
gboolean display_names;
@@ -471,28 +454,29 @@ workspace_switcher_applet_fill (PanelApplet *applet)
"change_background",
G_CALLBACK (applet_change_background),
pager);
- g_signal_connect (G_OBJECT (pager->applet),
- "notify::locked-down",
- G_CALLBACK (applet_locked_down_notified),
- pager);
gtk_widget_show (pager->applet);
panel_applet_set_background_widget (PANEL_APPLET (pager->applet),
GTK_WIDGET (pager->applet));
- pager->action_group = gtk_action_group_new ("WorkspaceSwitcher Applet Actions");
- gtk_action_group_set_translation_domain (pager->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (pager->action_group,
+ action_group = gtk_action_group_new ("WorkspaceSwitcher Applet Actions");
+ gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
+ gtk_action_group_add_actions (action_group,
pager_menu_actions,
G_N_ELEMENTS (pager_menu_actions),
pager);
ui_path = g_build_filename (WNCK_MENU_UI_DIR, "workspace-switcher-menu.xml", NULL);
panel_applet_setup_menu_from_file (PANEL_APPLET (pager->applet),
- ui_path, pager->action_group);
+ ui_path, action_group);
g_free (ui_path);
- applet_locked_down_notified (applet, NULL, pager);
+ action = gtk_action_group_get_action (action_group, "PagerPreferences");
+ g_object_bind_property (pager->applet, "locked-down",
+ action, "visible",
+ G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
+
+ g_object_unref (action_group);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]