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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include <sys/types.h>
34 # define localtime_r(t,b) *(b) = localtime (t)
36 # define S_ISREG(m) ((m) & _S_IFREG)
40 #include "prop-editor.h"
43 print_current_item (GtkRecentChooser *chooser)
47 uri = gtk_recent_chooser_get_current_uri (chooser);
48 g_print ("Current item changed :\n %s\n", uri ? uri : "null");
53 print_selected (GtkRecentChooser *chooser)
56 gchar **uris = gtk_recent_chooser_get_uris (chooser, &uris_len);
58 g_print ("Selection changed :\n");
59 for (i = 0; i < uris_len; i++)
60 g_print (" %s\n", uris[i]);
67 response_cb (GtkDialog *dialog,
70 if (response_id == GTK_RESPONSE_OK)
74 g_print ("Dialog was closed\n");
80 filter_changed (GtkRecentChooserDialog *dialog,
83 g_print ("recent filter changed\n");
87 notify_multiple_cb (GtkWidget *dialog,
93 multiple = gtk_recent_chooser_get_select_multiple (GTK_RECENT_CHOOSER (dialog));
95 gtk_widget_set_sensitive (button, multiple);
99 kill_dependent (GtkWindow *win,
102 gtk_widget_destroy (dep);
103 g_object_unref (dep);
110 GtkWidget *control_window;
114 GtkRecentFilter *filter;
116 gboolean multiple = FALSE;
118 gtk_init (&argc, &argv);
120 /* to test rtl layout, set RTL=1 in the environment */
121 if (g_getenv ("RTL"))
122 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
124 for (i = 1; i < argc; i++)
126 if (!strcmp ("--multiple", argv[i]))
130 dialog = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
131 "select-multiple", multiple,
135 gtk_window_set_title (GTK_WINDOW (dialog), "Select a file");
136 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
137 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
138 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
141 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
143 g_signal_connect (dialog, "item-activated",
144 G_CALLBACK (print_current_item), NULL);
145 g_signal_connect (dialog, "selection-changed",
146 G_CALLBACK (print_selected), NULL);
147 g_signal_connect (dialog, "response",
148 G_CALLBACK (response_cb), NULL);
151 filter = gtk_recent_filter_new ();
152 gtk_recent_filter_set_name (filter, "All Files");
153 gtk_recent_filter_add_pattern (filter, "*");
154 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
156 filter = gtk_recent_filter_new ();
157 gtk_recent_filter_set_name (filter, "Only PDF Files");
158 gtk_recent_filter_add_mime_type (filter, "application/pdf");
159 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
161 g_signal_connect (dialog, "notify::filter",
162 G_CALLBACK (filter_changed), NULL);
164 gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (dialog), filter);
166 filter = gtk_recent_filter_new ();
167 gtk_recent_filter_set_name (filter, "PNG and JPEG");
168 gtk_recent_filter_add_mime_type (filter, "image/png");
169 gtk_recent_filter_add_mime_type (filter, "image/jpeg");
170 gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
172 gtk_widget_show_all (dialog);
174 create_prop_editor (G_OBJECT (dialog), GTK_TYPE_RECENT_CHOOSER);
176 control_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
178 vbbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
179 gtk_container_add (GTK_CONTAINER (control_window), vbbox);
181 button = gtk_button_new_with_mnemonic ("_Select all");
182 gtk_widget_set_sensitive (button, multiple);
183 gtk_container_add (GTK_CONTAINER (vbbox), button);
184 g_signal_connect_swapped (button, "clicked",
185 G_CALLBACK (gtk_recent_chooser_select_all), dialog);
186 g_signal_connect (dialog, "notify::select-multiple",
187 G_CALLBACK (notify_multiple_cb), button);
189 button = gtk_button_new_with_mnemonic ("_Unselect all");
190 gtk_container_add (GTK_CONTAINER (vbbox), button);
191 g_signal_connect_swapped (button, "clicked",
192 G_CALLBACK (gtk_recent_chooser_unselect_all), dialog);
194 gtk_widget_show_all (control_window);
196 g_object_ref (control_window);
197 g_signal_connect (dialog, "destroy",
198 G_CALLBACK (kill_dependent), control_window);
200 g_object_ref (dialog);
202 gtk_widget_destroy (dialog);
203 g_object_unref (dialog);