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.
24 static GtkWidget *toplevel;
26 static GtkWidget *grid, *file_l, *open;
27 static GtkWidget *radio_file, *radio_content, *dialog;
28 static GtkWidget *app_chooser_widget;
29 static GtkWidget *recommended, *fallback, *other, *all;
32 dialog_response (GtkDialog *d,
39 g_print ("Response: %d\n", response_id);
41 if (response_id == GTK_RESPONSE_OK)
43 app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (d));
44 name = g_app_info_get_name (app_info);
45 g_print ("Application selected: %s\n", name);
47 g_object_unref (app_info);
50 gtk_widget_destroy (GTK_WIDGET (d));
57 g_object_bind_property (recommended, "active",
58 app_chooser_widget, "show-recommended",
59 G_BINDING_SYNC_CREATE);
60 g_object_bind_property (fallback, "active",
61 app_chooser_widget, "show-fallback",
62 G_BINDING_SYNC_CREATE);
63 g_object_bind_property (other, "active",
64 app_chooser_widget, "show-other",
65 G_BINDING_SYNC_CREATE);
66 g_object_bind_property (all, "active",
67 app_chooser_widget, "show-all",
68 G_BINDING_SYNC_CREATE);
74 gboolean use_file = FALSE;
75 gchar *content_type = NULL;
77 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
79 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content)))
84 dialog = gtk_app_chooser_dialog_new (GTK_WINDOW (toplevel), 0, file);
90 info = g_file_query_info (file,
91 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
93 content_type = g_strdup (g_file_info_get_content_type (info));
95 g_object_unref (info);
97 dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (toplevel),
101 g_signal_connect (dialog, "response",
102 G_CALLBACK (dialog_response), NULL);
104 g_free (content_type);
106 app_chooser_widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
111 display_dialog (void)
116 gtk_widget_show (dialog);
120 button_clicked (GtkButton *b,
126 w = gtk_file_chooser_dialog_new ("Select file",
127 GTK_WINDOW (toplevel),
128 GTK_FILE_CHOOSER_ACTION_OPEN,
129 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
130 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
133 gtk_dialog_run (GTK_DIALOG (w));
134 file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (w));
135 path = g_file_get_path (file);
136 gtk_button_set_label (GTK_BUTTON (file_l), path);
138 gtk_widget_destroy (w);
140 gtk_widget_set_sensitive (open, TRUE);
146 main (int argc, char **argv)
152 gtk_init (&argc, &argv);
154 toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
155 gtk_container_set_border_width (GTK_CONTAINER (toplevel), 12);
156 grid = gtk_grid_new ();
158 w1 = gtk_label_new ("File:");
159 gtk_widget_set_halign (w1, GTK_ALIGN_START);
160 gtk_grid_attach (GTK_GRID (grid),
163 file_l = gtk_button_new ();
164 path = g_build_filename (g_get_current_dir (), "apple-red.png", NULL);
165 file = g_file_new_for_path (path);
166 gtk_button_set_label (GTK_BUTTON (file_l), path);
169 gtk_widget_set_halign (file_l, GTK_ALIGN_START);
170 gtk_grid_attach_next_to (GTK_GRID (grid), file_l,
171 w1, GTK_POS_RIGHT, 3, 1);
172 g_signal_connect (file_l, "clicked",
173 G_CALLBACK (button_clicked), NULL);
175 radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile");
176 radio_content = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file),
179 gtk_grid_attach (GTK_GRID (grid), radio_file,
181 gtk_grid_attach_next_to (GTK_GRID (grid), radio_content,
182 radio_file, GTK_POS_BOTTOM, 1, 1);
184 open = gtk_button_new_with_label ("Trigger App Chooser dialog");
185 gtk_grid_attach_next_to (GTK_GRID (grid), open,
186 radio_content, GTK_POS_BOTTOM, 1, 1);
188 recommended = gtk_check_button_new_with_label ("Show recommended");
189 gtk_grid_attach_next_to (GTK_GRID (grid), recommended,
190 open, GTK_POS_BOTTOM, 1, 1);
191 g_object_set (recommended, "active", TRUE, NULL);
193 fallback = gtk_check_button_new_with_label ("Show fallback");
194 gtk_grid_attach_next_to (GTK_GRID (grid), fallback,
195 recommended, GTK_POS_RIGHT, 1, 1);
197 other = gtk_check_button_new_with_label ("Show other");
198 gtk_grid_attach_next_to (GTK_GRID (grid), other,
199 fallback, GTK_POS_RIGHT, 1, 1);
201 all = gtk_check_button_new_with_label ("Show all");
202 gtk_grid_attach_next_to (GTK_GRID (grid), all,
203 other, GTK_POS_RIGHT, 1, 1);
206 g_signal_connect (open, "clicked",
207 G_CALLBACK (display_dialog), NULL);
209 gtk_container_add (GTK_CONTAINER (toplevel), grid);
211 gtk_widget_show_all (toplevel);
212 g_signal_connect (toplevel, "delete-event",
213 G_CALLBACK (gtk_main_quit), NULL);