2010-11-24 17:45:42 +00:00
|
|
|
/* testappchoosercombo.c
|
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
* Authors: Cosimo Cecchi
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static GtkWidget *toplevel, *combobox, *box;
|
|
|
|
static GtkWidget *sel_image, *sel_name;
|
|
|
|
|
|
|
|
static void
|
|
|
|
combo_changed_cb (GtkComboBox *cb,
|
2010-11-24 23:32:05 +00:00
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GAppInfo *app_info;
|
|
|
|
|
|
|
|
app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb));
|
|
|
|
|
|
|
|
if (app_info == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info),
|
2010-11-24 23:32:05 +00:00
|
|
|
GTK_ICON_SIZE_DIALOG);
|
2010-11-24 17:45:42 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info));
|
|
|
|
|
|
|
|
g_object_unref (app_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
special_item_activated_cb (GtkAppChooserComboBox *cb,
|
2010-11-24 23:32:05 +00:00
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_themed_icon_new ("face-smile"),
|
2010-11-24 23:32:05 +00:00
|
|
|
GTK_ICON_SIZE_DIALOG);
|
|
|
|
gtk_label_set_text (GTK_LABEL (sel_name), "Special Item");
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
g_type_init ();
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (toplevel), box);
|
|
|
|
|
|
|
|
combobox = gtk_app_chooser_combo_box_new ("image/jpeg");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), combobox, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
g_signal_connect (combobox, "changed",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (combo_changed_cb), NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
w = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (w), "<b>Selected app info</b>");
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
sel_image = gtk_image_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (w), sel_image, TRUE, TRUE, 0);
|
|
|
|
sel_name = gtk_label_new (NULL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (w), sel_name, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gtk_app_chooser_combo_box_append_separator (GTK_APP_CHOOSER_COMBO_BOX (combobox));
|
|
|
|
gtk_app_chooser_combo_box_append_custom_item (GTK_APP_CHOOSER_COMBO_BOX (combobox),
|
2010-11-24 23:32:05 +00:00
|
|
|
"Hey, I'm special!",
|
|
|
|
g_themed_icon_new ("face-smile"),
|
|
|
|
special_item_activated_cb,
|
|
|
|
NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-25 16:17:45 +00:00
|
|
|
gtk_app_chooser_combo_box_set_show_dialog_item (GTK_APP_CHOOSER_COMBO_BOX (combobox),
|
|
|
|
TRUE);
|
|
|
|
|
2010-11-24 18:08:17 +00:00
|
|
|
/* test refresh on a combo */
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
gtk_widget_show_all (toplevel);
|
|
|
|
|
|
|
|
g_signal_connect (toplevel, "delete-event",
|
2010-11-24 23:32:05 +00:00
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|