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"
|
|
|
|
|
2018-11-13 14:13:47 +00:00
|
|
|
static GtkWidget *toplevel, *button, *box;
|
2010-11-24 17:45:42 +00:00
|
|
|
static GtkWidget *sel_image, *sel_name;
|
|
|
|
|
|
|
|
static void
|
2020-03-06 17:05:43 +00:00
|
|
|
combo_changed_cb (GtkAppChooserButton *chooser_button,
|
2018-11-13 14:13:47 +00:00
|
|
|
gpointer user_data)
|
2010-11-24 17:45:42 +00:00
|
|
|
{
|
|
|
|
GAppInfo *app_info;
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser_button));
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:45:42 +00:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
toplevel = gtk_window_new ();
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_margin_top (box, 12);
|
|
|
|
gtk_widget_set_margin_bottom (box, 12);
|
|
|
|
gtk_widget_set_margin_start (box, 12);
|
|
|
|
gtk_widget_set_margin_end (box, 12);
|
|
|
|
gtk_window_set_child (GTK_WINDOW (toplevel), box);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:13:47 +00:00
|
|
|
button = gtk_app_chooser_button_new ("image/jpeg");
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_vexpand (button, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:13:47 +00:00
|
|
|
g_signal_connect (button, "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>");
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_vexpand (w, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), w);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_vexpand (w, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), w);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
sel_image = gtk_image_new ();
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_hexpand (sel_image, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (w), sel_image);
|
2010-11-24 17:45:42 +00:00
|
|
|
sel_name = gtk_label_new (NULL);
|
2020-05-10 21:46:50 +00:00
|
|
|
gtk_widget_set_hexpand (sel_name, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (w), sel_name);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_button_set_heading (GTK_APP_CHOOSER_BUTTON (button), "Choose one, <i>not</i> two");
|
|
|
|
gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON (button));
|
|
|
|
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (button),
|
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 */
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON (button),
|
2010-11-29 15:04:59 +00:00
|
|
|
CUSTOM_ITEM,
|
|
|
|
"Hey, I'm fake!",
|
|
|
|
g_themed_icon_new ("face-evil"));
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (button),
|
2010-11-29 11:19:18 +00:00
|
|
|
TRUE);
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (button),
|
2011-09-10 05:40:05 +00:00
|
|
|
TRUE);
|
2010-11-25 16:17:45 +00:00
|
|
|
|
2010-11-29 15:04:59 +00:00
|
|
|
/* connect to the detailed signal */
|
2018-11-13 14:13:47 +00:00
|
|
|
g_signal_connect (button, "custom-item-activated::" CUSTOM_ITEM,
|
2010-11-29 15:04:59 +00:00
|
|
|
G_CALLBACK (special_item_activated_cb), NULL);
|
|
|
|
|
|
|
|
/* connect to the generic signal too */
|
2018-11-13 14:13:47 +00:00
|
|
|
g_signal_connect (button, "custom-item-activated",
|
2010-11-29 15:04:59 +00:00
|
|
|
G_CALLBACK (action_cb), NULL);
|
|
|
|
|
2010-11-24 18:08:17 +00:00
|
|
|
/* test refresh on a combo */
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_refresh (GTK_APP_CHOOSER (button));
|
2010-11-24 18:08:17 +00:00
|
|
|
|
2011-09-10 05:40:05 +00:00
|
|
|
#if 0
|
2018-11-13 14:13:47 +00:00
|
|
|
gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON (button),
|
2010-12-01 11:12:03 +00:00
|
|
|
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
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (toplevel, "destroy", G_CALLBACK (quit_cb), &done);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2010-11-24 17:45:42 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|