2 * Copyright (C) 2006 Emmanuele Bassi.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/types.h>
32 # define localtime_r(t,b) *(b) = localtime (t)
34 # define S_ISREG(m) ((m) & _S_IFREG)
38 #include "prop-editor.h"
41 print_current_item (GtkRecentChooser *chooser)
45 uri = gtk_recent_chooser_get_current_uri (chooser);
46 g_print ("Current item changed :\n %s\n", uri ? uri : "null");
51 print_selected (GtkRecentChooser *chooser)
54 gchar **uris = gtk_recent_chooser_get_uris (chooser, &uris_len);
56 g_print ("Selection changed :\n");
57 for (i = 0; i < uris_len; i++)
58 g_print (" %s\n", uris[i]);
65 response_cb (GtkDialog *dialog,
68 if (response_id == GTK_RESPONSE_OK)
72 g_print ("Dialog was closed\n");
78 filter_changed (GtkRecentChooserDialog *dialog,
81 g_print ("recent filter changed\n");
85 notify_multiple_cb (GtkWidget *dialog,
91 multiple = gtk_recent_chooser_get_select_multiple (GTK_RECENT_CHOOSER (dialog));
93 gtk_widget_set_sensitive (button, multiple);
97 kill_dependent (GtkWindow *win,
100 gtk_widget_destroy (dep);
101 g_object_unref (dep);
108 GtkWidget *control_window;
112 GtkRecentFilter *filter;
114 gboolean multiple = FALSE;
116 gtk_init (&argc, &argv);
118 /* to test rtl layout, set RTL=1 in the environment */
119 if (g_getenv ("RTL"))
120 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
122 for (i = 1; i < argc; i++)
124 if (!strcmp ("--multiple", argv[i]))
128 dialog = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
129 "select-multiple", multiple,
133 gtk_window_set_title (GTK_WINDOW (dialog), "Select a file");
134 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
135 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
136 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
139 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
141 g_signal_connect (dialog, "item-activated",
142 G_CALLBACK (print_current_item), NULL);
143 g_signal_connect (dialog, "selection-changed",
144 G_CALLBACK (print_selected), NULL);
145 g_signal_connect (dialog, "response",
146 G_CALLBACK (response_cb), NULL);
149 filter = gtk_recent_filter_new ();
150 gtk_recent_filter_set_name (filter, "All Files");
151 gtk_recent_filter_add_pattern (filter, "*");
152 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
154 filter = gtk_recent_filter_new ();
155 gtk_recent_filter_set_name (filter, "Only PDF Files");
156 gtk_recent_filter_add_mime_type (filter, "application/pdf");
157 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
159 g_signal_connect (dialog, "notify::filter",
160 G_CALLBACK (filter_changed), NULL);
162 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (dialog), filter);
164 filter = gtk_recent_filter_new ();
165 gtk_recent_filter_set_name (filter, "PNG and JPEG");
166 gtk_recent_filter_add_mime_type (filter, "image/png");
167 gtk_recent_filter_add_mime_type (filter, "image/jpeg");
168 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
170 gtk_widget_show_all (dialog);
172 create_prop_editor (G_OBJECT (dialog), GTK_TYPE_RECENT_CHOOSER);
174 control_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
176 vbbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
177 gtk_container_add (GTK_CONTAINER (control_window), vbbox);
179 button = gtk_button_new_with_mnemonic ("_Select all");
180 gtk_widget_set_sensitive (button, multiple);
181 gtk_container_add (GTK_CONTAINER (vbbox), button);
182 g_signal_connect_swapped (button, "clicked",
183 G_CALLBACK (gtk_recent_chooser_select_all), dialog);
184 g_signal_connect (dialog, "notify::select-multiple",
185 G_CALLBACK (notify_multiple_cb), button);
187 button = gtk_button_new_with_mnemonic ("_Unselect all");
188 gtk_container_add (GTK_CONTAINER (vbbox), button);
189 g_signal_connect_swapped (button, "clicked",
190 G_CALLBACK (gtk_recent_chooser_unselect_all), dialog);
192 gtk_widget_show_all (control_window);
194 g_object_ref (control_window);
195 g_signal_connect (dialog, "destroy",
196 G_CALLBACK (kill_dependent), control_window);
198 g_object_ref (dialog);
200 gtk_widget_destroy (dialog);
201 g_object_unref (dialog);