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, see <http://www.gnu.org/licenses/>.
23 #define CUSTOM_ITEM "custom-item"
25 static GtkWidget *toplevel, *combobox, *box;
26 static GtkWidget *sel_image, *sel_name;
29 combo_changed_cb (GtkComboBox *cb,
34 app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));
39 gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
40 GTK_ICON_SIZE_DIALOG);
41 gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));
43 g_object_unref (app_info);
47 special_item_activated_cb (GtkAppChooserButton *b,
48 const gchar *item_name,
51 gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_themed_icon_new ("face-smile"),
52 GTK_ICON_SIZE_DIALOG);
53 gtk_label_set_text (GTK_LABEL (sel_name), "Special Item");
57 action_cb (GtkAppChooserButton *b,
58 const gchar *item_name,
61 g_print ("Activated custom item %s\n", item_name);
70 gtk_init (&argc, &argv);
72 toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
73 gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
75 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
76 gtk_container_add (GTK_CONTAINER (toplevel), box);
78 combobox = gtk_app_chooser_button_new ("image/jpeg");
79 gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);
81 g_signal_connect (combobox, "changed",
82 G_CALLBACK (combo_changed_cb), NULL);
84 w = gtk_label_new (NULL);
85 gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
86 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
88 w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
89 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
91 sel_image = gtk_image_new ();
92 gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
93 sel_name = gtk_label_new (NULL);
94 gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);
96 gtk_app_chooser_button_set_heading (GTK_APP_CHOOSER_BUTTON (combobox), "Choose one, <i>not</i> two");
97 gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
98 gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
101 g_themed_icon_new ("face-smile"));
103 /* this one will trigger a warning, and will not be added */
104 gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
107 g_themed_icon_new ("face-evil"));
109 gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
111 gtk_app_chooser_button_set_show_default_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));
126 gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
129 gtk_widget_show_all (toplevel);
131 g_signal_connect (toplevel, "delete-event",
132 G_CALLBACK (gtk_main_quit), NULL);