From 5f5de68e8267cd3c3f4effa2e552b66a03951cce Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 29 Mar 2006 20:08:23 +0000 Subject: [PATCH] Add a test suite for GtkRecentChooser. 2006-03-29 Emmanuele Bassi * tests/Makefile.am: * tests/testrecentchooser.c: Add a test suite for GtkRecentChooser. --- ChangeLog | 5 + ChangeLog.pre-2-10 | 5 + tests/Makefile.am | 7 ++ tests/testrecentchooser.c | 205 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 tests/testrecentchooser.c diff --git a/ChangeLog b/ChangeLog index 7b95bb054..05fcd04cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-03-29 Emmanuele Bassi + + * tests/Makefile.am: + * tests/testrecentchooser.c: Add a test suite for GtkRecentChooser. + 2006-03-29 Emmanuele Bassi Import GtkRecent* from libegg. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 7b95bb054..05fcd04cd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2006-03-29 Emmanuele Bassi + + * tests/Makefile.am: + * tests/testrecentchooser.c: Add a test suite for GtkRecentChooser. + 2006-03-29 Emmanuele Bassi Import GtkRecent* from libegg. diff --git a/tests/Makefile.am b/tests/Makefile.am index f82f6e5a4..db204ce80 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -53,6 +53,7 @@ noinst_PROGRAMS = \ testmultiscreen \ testnotebookdnd \ testrgb \ + testrecentchooser \ testselection \ $(testsocket_programs) \ testspinbutton \ @@ -103,6 +104,7 @@ testmenubars_DEPENDENCIES = $(TEST_DEPS) testmultidisplay_DEPENDENCIES = $(TEST_DEPS) testmultiscreen_DEPENDENCIES = $(TEST_DEPS) testnotebookdnd_DEPENDENCIES = $(TEST_DEPS) +testrecentchooser_DEPENDENCIES = $(TEST_DEPS) testrgb_DEPENDENCIES = $(TEST_DEPS) testselection_DEPENDENCIES = $(TEST_DEPS) testsocket_DEPENDENCIES = $(DEPS) @@ -148,6 +150,7 @@ testmenubars_LDADD = $(LDADDS) testmultidisplay_LDADD = $(LDADDS) testmultiscreen_LDADD = $(LDADDS) testnotebookdnd_LDADD = $(LDADDS) +testrecentchooser_LDADD = $(LDADDS) testrgb_LDADD = $(LDADDS) testselection_LDADD = $(LDADDS) testsocket_LDADD = $(LDADDS) @@ -236,6 +239,10 @@ testiconview_SOURCES = \ testiconview.c \ prop-editor.c +testrecentchooser_SOURCES = \ + prop-editor.c \ + testrecentchooser.c + EXTRA_DIST = \ prop-editor.h \ testgtk.1 \ diff --git a/tests/testrecentchooser.c b/tests/testrecentchooser.c new file mode 100644 index 000000000..eeb80238d --- /dev/null +++ b/tests/testrecentchooser.c @@ -0,0 +1,205 @@ +/* testrecentchooser.c + * Copyright (C) 2006 Emmanuele Bassi. + * + * 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 + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include + +#ifdef G_OS_WIN32 +# include +# define localtime_r(t,b) *(b) = localtime (t) +# ifndef S_ISREG +# define S_ISREG(m) ((m) & _S_IFREG) +# endif +#endif + +#include "prop-editor.h" + +static void +print_current_item (GtkRecentChooser *chooser) +{ + gchar *uri; + + uri = gtk_recent_chooser_get_current_uri (chooser); + g_print ("Current item changed :\n %s\n", uri ? uri : "null"); + g_free (uri); +} + +static void +print_selected (GtkRecentChooser *chooser) +{ + gsize uris_len, i; + gchar **uris = gtk_recent_chooser_get_uris (chooser, &uris_len); + + g_print ("Selection changed :\n"); + for (i = 0; i < uris_len; i++) + g_print (" %s\n", uris[i]); + g_print ("\n"); + + g_strfreev (uris); +} + +static void +response_cb (GtkDialog *dialog, + gint response_id) +{ + if (response_id == GTK_RESPONSE_OK) + { + } + else + g_print ("Dialog was closed\n"); + + gtk_main_quit (); +} + +static void +filter_changed (GtkRecentChooserDialog *dialog, + gpointer data) +{ + g_print ("recent filter changed\n"); +} + +static void +notify_multiple_cb (GtkWidget *dialog, + GParamSpec *pspec, + GtkWidget *button) +{ + gboolean multiple; + + multiple = gtk_recent_chooser_get_select_multiple (GTK_RECENT_CHOOSER (dialog)); + + gtk_widget_set_sensitive (button, multiple); +} + +static void +kill_dependent (GtkWindow *win, + GtkObject *dep) +{ + gtk_object_destroy (dep); + g_object_unref (dep); +} + +int +main (int argc, + char *argv[]) +{ + GtkWidget *control_window; + GtkWidget *vbbox; + GtkWidget *button; + GtkWidget *dialog; + GtkWidget *prop_editor; + GtkRecentFilter *filter; + gint i; + gboolean multiple = FALSE; + + gtk_init (&argc, &argv); + + /* to test rtl layout, set RTL=1 in the environment */ + if (g_getenv ("RTL")) + gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL); + + for (i = 1; i < argc; i++) + { + if (!strcmp ("--multiple", argv[i])) + multiple = TRUE; + } + + dialog = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG, + "select-multiple", multiple, + NULL); + gtk_window_set_title (GTK_WINDOW (dialog), "Select a file"); + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); + + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); + + g_signal_connect (dialog, "item-activated", + G_CALLBACK (print_current_item), NULL); + g_signal_connect (dialog, "selection-changed", + G_CALLBACK (print_selected), NULL); + g_signal_connect (dialog, "response", + G_CALLBACK (response_cb), NULL); + + /* filters */ + filter = gtk_recent_filter_new (); + gtk_recent_filter_set_name (filter, "All Files"); + gtk_recent_filter_add_pattern (filter, "*"); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter); + + filter = gtk_recent_filter_new (); + gtk_recent_filter_set_name (filter, "Only PDF Files"); + gtk_recent_filter_add_mime_type (filter, "application/pdf"); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter); + + g_signal_connect (dialog, "notify::filter", + G_CALLBACK (filter_changed), NULL); + + gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (dialog), filter); + + filter = gtk_recent_filter_new (); + gtk_recent_filter_set_name (filter, "PNG and JPEG"); + gtk_recent_filter_add_mime_type (filter, "image/png"); + gtk_recent_filter_add_mime_type (filter, "image/jpeg"); + gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter); + + gtk_widget_show_all (dialog); + + prop_editor = create_prop_editor (G_OBJECT (dialog), GTK_TYPE_RECENT_CHOOSER); + + control_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + vbbox = gtk_vbutton_box_new (); + gtk_container_add (GTK_CONTAINER (control_window), vbbox); + + button = gtk_button_new_with_mnemonic ("_Select all"); + gtk_widget_set_sensitive (button, multiple); + gtk_container_add (GTK_CONTAINER (vbbox), button); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (gtk_recent_chooser_select_all), dialog); + g_signal_connect (dialog, "notify::select-multiple", + G_CALLBACK (notify_multiple_cb), button); + + button = gtk_button_new_with_mnemonic ("_Unselect all"); + gtk_container_add (GTK_CONTAINER (vbbox), button); + g_signal_connect_swapped (button, "clicked", + G_CALLBACK (gtk_recent_chooser_unselect_all), dialog); + + gtk_widget_show_all (control_window); + + g_object_ref (control_window); + g_signal_connect (dialog, "destroy", + G_CALLBACK (kill_dependent), control_window); + + g_object_ref (dialog); + gtk_main (); + gtk_widget_destroy (dialog); + g_object_unref (dialog); + + return 0; +} -- 2.43.2