1 /* testappchooserbutton.c
2 * Copyright (C) 2010 Red Hat, Inc.
3 * Authors: Cosimo Cecchi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #define CUSTOM_ITEM "custom-item"
27 static GtkWidget *toplevel, *combobox, *box;
28 static GtkWidget *sel_image, *sel_name;
31 combo_changed_cb (GtkComboBox *cb,
36 app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));
41 gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
42 GTK_ICON_SIZE_DIALOG);
43 gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));
45 g_object_unref (app_info);
49 special_item_activated_cb (GtkAppChooserButton *b,
50 const gchar *item_name,
53 gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_themed_icon_new ("face-smile"),
54 GTK_ICON_SIZE_DIALOG);
55 gtk_label_set_text (GTK_LABEL (sel_name), "Special Item");
59 action_cb (GtkAppChooserButton *b,
60 const gchar *item_name,
63 g_print ("Activated custom item %s\n", item_name);
73 gtk_init (&argc, &argv);
75 toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
76 gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
78 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
79 gtk_container_add (GTK_CONTAINER (toplevel), box);
81 combobox = gtk_app_chooser_button_new ("image/jpeg");
82 gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);
84 g_signal_connect (combobox, "changed",
85 G_CALLBACK (combo_changed_cb), NULL);
87 w = gtk_label_new (NULL);
88 gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
89 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
91 w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
92 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
94 sel_image = gtk_image_new ();
95 gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
96 sel_name = gtk_label_new (NULL);
97 gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);
99 gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
100 gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
103 g_themed_icon_new ("face-smile"));
105 /* this one will trigger a warning, and will not be added */
106 gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
109 g_themed_icon_new ("face-evil"));
111 gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
114 /* connect to the detailed signal */
115 g_signal_connect (combobox, "custom-item-activated::" CUSTOM_ITEM,
116 G_CALLBACK (special_item_activated_cb), NULL);
118 /* connect to the generic signal too */
119 g_signal_connect (combobox, "custom-item-activated",
120 G_CALLBACK (action_cb), NULL);
122 /* test refresh on a combo */
123 gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
125 gtk_widget_show_all (toplevel);
127 g_signal_connect (toplevel, "delete-event",
128 G_CALLBACK (gtk_main_quit), NULL);