2010-11-29 11:19:18 +00:00
|
|
|
/* testappchooserbutton.c
|
2010-11-24 17:45:42 +00:00
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-24 17:45:42 +00:00
|
|
|
*/
|
|
|
|
|
2012-11-06 19:51:15 +00:00
|
|
|
#include "config.h"
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2012-11-06 19:51:15 +00:00
|
|
|
#include <stdlib.h>
|
2010-11-24 17:45:42 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
#define CUSTOM_ITEM "custom-item"
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
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;
|
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info));
|
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
|
2010-11-29 11:19:18 +00:00
|
|
|
special_item_activated_cb (GtkAppChooserButton *b,
|
2010-11-29 15:04:59 +00:00
|
|
|
const gchar *item_name,
|
2010-11-24 23:32:05 +00:00
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
2017-11-15 00:43:13 +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_label_set_text (GTK_LABEL (sel_name), "Special Item");
|
2010-11-24 17:45:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
static void
|
|
|
|
action_cb (GtkAppChooserButton *b,
|
|
|
|
const gchar *item_name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_print ("Activated custom item %s\n", item_name);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (toplevel), box);
|
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
combobox = gtk_app_chooser_button_new ("image/jpeg");
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), combobox);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
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>");
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), w);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), w);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
sel_image = gtk_image_new ();
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (w), sel_image);
|
2010-11-24 17:45:42 +00:00
|
|
|
sel_name = gtk_label_new (NULL);
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (w), sel_name);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2011-01-25 00:25:08 +00:00
|
|
|
gtk_app_chooser_button_set_heading (GTK_APP_CHOOSER_BUTTON (combobox), "Choose one, <i>not</i> two");
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (combobox));
|
|
|
|
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
2010-11-29 15:04:59 +00:00
|
|
|
CUSTOM_ITEM,
|
2010-11-29 11:19:18 +00:00
|
|
|
"Hey, I'm special!",
|
2010-11-29 15:04:59 +00:00
|
|
|
g_themed_icon_new ("face-smile"));
|
|
|
|
|
|
|
|
/* this one will trigger a warning, and will not be added */
|
|
|
|
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
|
|
|
CUSTOM_ITEM,
|
|
|
|
"Hey, I'm fake!",
|
|
|
|
g_themed_icon_new ("face-evil"));
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2010-11-29 11:19:18 +00:00
|
|
|
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
|
|
|
TRUE);
|
2011-09-10 05:40:05 +00:00
|
|
|
gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
|
|
|
TRUE);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
/* connect to the detailed signal */
|
|
|
|
g_signal_connect (combobox, "custom-item-activated::" CUSTOM_ITEM,
|
|
|
|
G_CALLBACK (special_item_activated_cb), NULL);
|
|
|
|
|
|
|
|
/* connect to the generic signal too */
|
|
|
|
g_signal_connect (combobox, "custom-item-activated",
|
|
|
|
G_CALLBACK (action_cb), NULL);
|
|
|
|
|
2010-11-24 18:08:17 +00:00
|
|
|
/* test refresh on a combo */
|
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (combobox));
|
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
#if 0
|
2010-12-01 11:12:03 +00:00
|
|
|
gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (combobox),
|
|
|
|
CUSTOM_ITEM);
|
2011-09-10 05:40:05 +00:00
|
|
|
#endif
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (toplevel);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2017-12-31 17:52:54 +00:00
|
|
|
g_signal_connect (toplevel, "destroy", G_CALLBACK (gtk_main_quit), NULL);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|