aboutsummaryrefslogtreecommitdiff
path: root/example/menus.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-06-24 02:34:25 +0000
committerTarmac <Unknown>2013-06-24 02:34:25 +0000
commit49b6a15237aad7359f417724288acc8d285e9d71 (patch)
treea0cc26abb75a9d4acfd14d4ea0f490d611dc8e7a /example/menus.c
parent8f8d487e5a29c1d483e9edd2067e17e4b8c0e205 (diff)
parentdb32e752ebd0a368e30d65ffd9c2f360a473fecc (diff)
downloadayatana-ido-49b6a15237aad7359f417724288acc8d285e9d71.tar.gz
ayatana-ido-49b6a15237aad7359f417724288acc8d285e9d71.tar.bz2
ayatana-ido-49b6a15237aad7359f417724288acc8d285e9d71.zip
Adds support for the guest menuitem.
A guest menuitem is the same as a user menuitem except for how it uses its action's state, so instead of adding a new class, this patch adds a new factory method (ido_guest_menu_item_new_from_model) and private action state handler. Approved by Ted Gould, PS Jenkins bot.
Diffstat (limited to 'example/menus.c')
-rw-r--r--example/menus.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/example/menus.c b/example/menus.c
index 1675f45..d30f920 100644
--- a/example/menus.c
+++ b/example/menus.c
@@ -19,6 +19,28 @@ slider_released (GtkWidget *widget, gpointer user_data)
g_print ("released\n");
}
+static GtkWidget *
+create_user_menu (const char * username,
+ const char * filename,
+ gboolean is_logged_in,
+ gboolean is_active)
+{
+ GtkWidget * ret;
+ GFile * file = filename ? g_file_new_for_path (filename) : NULL;
+ GIcon * icon = file ? g_file_icon_new (file) : NULL;
+
+ ret = g_object_new (IDO_USER_MENU_ITEM_TYPE,
+ "label", username,
+ "icon", icon,
+ "is-logged-in", is_logged_in,
+ "is-current-user", is_active,
+ NULL);
+
+ g_clear_object (&icon);
+ g_clear_object (&file);
+ return ret;
+}
+
int
main (int argc, char *argv[])
{
@@ -100,44 +122,28 @@ main (int argc, char *argv[])
*** Users
**/
- menuitem = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = ido_user_menu_item_new ();
- g_object_set (menuitem,
- "label", "Guest",
- "icon-filename", NULL,
- "is-logged-in", FALSE,
- "is-current-user", FALSE,
- NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = ido_user_menu_item_new ();
- g_object_set (menuitem,
- "label", "Bobby Fischer",
- "icon-filename", "/usr/share/pixmaps/faces/chess.jpg",
- "is-logged-in", FALSE,
- "is-current-user", FALSE,
- NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = ido_user_menu_item_new ();
- g_object_set (menuitem,
- "label", "Linus Torvalds",
- "icon-filename", "/usr/share/pixmaps/faces/penguin.jpg",
- "is-logged-in", TRUE,
- "is-current-user", FALSE,
- NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = ido_user_menu_item_new ();
- g_object_set (menuitem, "label", "Mark Shuttleworth",
- "icon-filename", "/usr/share/pixmaps/faces/astronaut.jpg",
- "is-logged-in", TRUE,
- "is-current-user", TRUE,
- NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+ create_user_menu ("Guest",
+ NULL,
+ FALSE, FALSE));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+ create_user_menu ("Bobby Fischer",
+ "/usr/share/pixmaps/faces/chess.jpg",
+ FALSE, FALSE));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+ create_user_menu ("Linus Torvalds",
+ "/usr/share/pixmaps/faces/penguin.jpg",
+ TRUE, FALSE));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+ create_user_menu ("Mark Shuttleworth",
+ "/usr/share/pixmaps/faces/astronaut.jpg",
+ TRUE, TRUE));
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), ido_user_menu_item_new ());
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
/* Add the menubar */
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), root);