diff options
author | Perberos <[email protected]> | 2011-12-01 22:24:23 -0300 |
---|---|---|
committer | Perberos <[email protected]> | 2011-12-01 22:24:23 -0300 |
commit | 0e004c696b0e68b2cff37a4c3315b022a35eaf43 (patch) | |
tree | 43261e815529cb9518ed7be37af13b846af8b26b /test | |
download | caja-0e004c696b0e68b2cff37a4c3315b022a35eaf43.tar.bz2 caja-0e004c696b0e68b2cff37a4c3315b022a35eaf43.tar.xz |
moving from https://github.com/perberos/mate-desktop-environment
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 46 | ||||
-rw-r--r-- | test/test-caja-directory-async.c | 104 | ||||
-rw-r--r-- | test/test-caja-search-engine.c | 58 | ||||
-rw-r--r-- | test/test-caja-wrap-table.c | 96 | ||||
-rw-r--r-- | test/test-copy.c | 93 | ||||
-rw-r--r-- | test/test-eel-background.c | 38 | ||||
-rw-r--r-- | test/test-eel-editable-label.c | 58 | ||||
-rw-r--r-- | test/test-eel-image-scrolled.c | 187 | ||||
-rw-r--r-- | test/test-eel-image-table.c | 304 | ||||
-rw-r--r-- | test/test-eel-labeled-image.c | 79 | ||||
-rw-r--r-- | test/test-eel-pixbuf-scale.c | 83 | ||||
-rw-r--r-- | test/test.c | 152 | ||||
-rw-r--r-- | test/test.h | 38 |
13 files changed, 1336 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 00000000..9e3d2099 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,46 @@ +NULL= + +INCLUDES =\ + -I$(top_srcdir) \ + $(CORE_CFLAGS) \ + $(WARNING_CFLAGS) \ + -DVERSION="\"$(VERSION)\"" \ + -DCAJA_DATADIR=\""$(datadir)/caja"\" \ + -DMATELOCALEDIR=\""$(prefix)/${DATADIRNAME}/locale"\" \ + $(NULL) + +LDADD =\ + $(top_builddir)/libcaja-private/libcaja-private.la \ + $(CORE_LIBS) \ + $(NULL) + +noinst_PROGRAMS =\ + test-caja-wrap-table \ + test-caja-search-engine \ + test-caja-directory-async \ + test-caja-copy \ + test-eel-background \ + test-eel-editable-label \ + test-eel-image-scrolled \ + test-eel-image-table \ + test-eel-labeled-image \ + test-eel-pixbuf-scale \ + $(NULL) + +test_caja_copy_SOURCES = test-copy.c test.c + +test_caja_wrap_table_SOURCES = test-caja-wrap-table.c test.c + +test_caja_search_engine_SOURCES = test-caja-search-engine.c + +test_caja_directory_async_SOURCES = test-caja-directory-async.c + +test_eel_background_SOURCES = test-eel-background.c +test_eel_image_scrolled_SOURCES = test-eel-image-scrolled.c test.c test.h +test_eel_image_table_SOURCES = test-eel-image-table.c test.c +test_eel_labeled_image_SOURCES = test-eel-labeled-image.c test.c test.h +test_eel_pixbuf_scale_SOURCES = test-eel-pixbuf-scale.c test.c test.h + +EXTRA_DIST = \ + test.h \ + $(NULL) diff --git a/test/test-caja-directory-async.c b/test/test-caja-directory-async.c new file mode 100644 index 00000000..e581abb5 --- /dev/null +++ b/test/test-caja-directory-async.c @@ -0,0 +1,104 @@ +#include <gtk/gtk.h> +#include <libcaja-private/caja-directory.h> +#include <libcaja-private/caja-search-directory.h> +#include <libcaja-private/caja-file.h> +#include <unistd.h> + +void *client1, *client2; + +#if 0 +static gboolean +quit_cb (gpointer data) +{ + gtk_main_quit (); + + return FALSE; +} +#endif + +static void +files_added (CajaDirectory *directory, + GList *added_files) +{ +#if 0 + GList *list; + + for (list = added_files; list != NULL; list = list->next) { + CajaFile *file = list->data; + + g_print (" - %s\n", caja_file_get_uri (file)); + } +#endif + + g_print ("files added: %d files\n", + g_list_length (added_files)); +} + +static void +files_changed (CajaDirectory *directory, + GList *changed_files) +{ +#if 0 + GList *list; + + for (list = changed_files; list != NULL; list = list->next) { + CajaFile *file = list->data; + + g_print (" - %s\n", caja_file_get_uri (file)); + } +#endif + g_print ("files changed: %d\n", + g_list_length (changed_files)); +} + +static gboolean +force_reload (CajaDirectory *directory) +{ + g_print ("forcing reload!\n"); + + caja_directory_force_reload (directory); + + return FALSE; +} + +static void +done_loading (CajaDirectory *directory) +{ + static int i = 0; + + g_print ("done loading\n"); + + if (i == 0) { + g_timeout_add (5000, (GSourceFunc)force_reload, directory); + i++; + } else { + } +} + +int +main (int argc, char **argv) +{ + CajaDirectory *directory; + CajaQuery *query; + client1 = g_new0 (int, 1); + client2 = g_new0 (int, 1); + + gtk_init (&argc, &argv); + + query = caja_query_new (); + caja_query_set_text (query, "richard hult"); + directory = caja_directory_get_by_uri ("x-caja-search://0/"); + caja_search_directory_set_query (CAJA_SEARCH_DIRECTORY (directory), query); + g_object_unref (query); + + g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL); + g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL); + g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL); + caja_directory_file_monitor_add (directory, client1, TRUE, TRUE, + CAJA_FILE_ATTRIBUTE_INFO, + NULL, NULL); + + + gtk_main (); + return 0; +} diff --git a/test/test-caja-search-engine.c b/test/test-caja-search-engine.c new file mode 100644 index 00000000..6a4ace70 --- /dev/null +++ b/test/test-caja-search-engine.c @@ -0,0 +1,58 @@ +#include <libcaja-private/caja-search-engine.h> +#include <gtk/gtk.h> + +static void +hits_added_cb (CajaSearchEngine *engine, GSList *hits) +{ + g_print ("hits added\n"); + while (hits) { + g_print (" - %s\n", (char *)hits->data); + hits = hits->next; + } +} + +static void +hits_subtracted_cb (CajaSearchEngine *engine, GSList *hits) +{ + g_print ("hits subtracted\n"); + while (hits) { + g_print (" - %s\n", (char *)hits->data); + hits = hits->next; + } +} + +static void +finished_cb (CajaSearchEngine *engine) +{ + g_print ("finished!\n"); +// gtk_main_quit (); +} + +int +main (int argc, char* argv[]) +{ + CajaSearchEngine *engine; + CajaQuery *query; + + g_thread_init (NULL); + + gtk_init (&argc, &argv); + + engine = caja_search_engine_new (); + g_signal_connect (engine, "hits-added", + G_CALLBACK (hits_added_cb), NULL); + g_signal_connect (engine, "hits-subtracted", + G_CALLBACK (hits_subtracted_cb), NULL); + g_signal_connect (engine, "finished", + G_CALLBACK (finished_cb), NULL); + + query = caja_query_new (); + caja_query_set_text (query, "richard hult"); + caja_search_engine_set_query (engine, query); + g_object_unref (query); + + caja_search_engine_start (engine); + + gtk_main (); + return 0; +} diff --git a/test/test-caja-wrap-table.c b/test/test-caja-wrap-table.c new file mode 100644 index 00000000..c95c3e7c --- /dev/null +++ b/test/test-caja-wrap-table.c @@ -0,0 +1,96 @@ +#include "test.h" + +#include <eel/eel-wrap-table.h> +#include <eel/eel-labeled-image.h> +#include <eel/eel-vfs-extensions.h> +#include <libcaja-private/caja-customization-data.h> +#include <libcaja-private/caja-icon-info.h> + +int +main (int argc, char* argv[]) +{ + CajaCustomizationData *customization_data; + GtkWidget *window; + GtkWidget *emblems_table, *button, *scroller; + char *emblem_name, *stripped_name; + GdkPixbuf *pixbuf; + char *label; + + test_init (&argc, &argv); + + window = test_window_new ("Wrap Table Test", 10); + + gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); + + /* The emblems wrapped table */ + emblems_table = eel_wrap_table_new (TRUE); + + gtk_widget_show (emblems_table); + gtk_container_set_border_width (GTK_CONTAINER (emblems_table), 8); + + scroller = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + + /* Viewport */ + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroller), + emblems_table); + + gtk_container_add (GTK_CONTAINER (window), scroller); + + gtk_widget_show (scroller); + +#if 0 + /* Get rid of default lowered shadow appearance. + * This must be done after the widget is realized, due to + * an apparent bug in gtk_viewport_set_shadow_type. + */ + g_signal_connect (GTK_BIN (scroller->child), + "realize", + remove_default_viewport_shadow, + NULL); +#endif + + + /* Use caja_customization to make the emblem widgets */ + customization_data = caja_customization_data_new ("emblems", TRUE, + CAJA_ICON_SIZE_SMALL, + CAJA_ICON_SIZE_SMALL); + + while (caja_customization_data_get_next_element_for_display (customization_data, + &emblem_name, + &pixbuf, + &label)) { + + stripped_name = eel_filename_strip_extension (emblem_name); + g_free (emblem_name); + + if (strcmp (stripped_name, "erase") == 0) { + g_object_unref (pixbuf); + g_free (label); + g_free (stripped_name); + continue; + } + + button = eel_labeled_image_check_button_new (label, pixbuf); + g_free (label); + g_object_unref (pixbuf); + + /* Attach parameters and signal handler. */ + g_object_set_data_full (G_OBJECT (button), + "caja_property_name", + stripped_name, + (GDestroyNotify) g_free); + + gtk_container_add (GTK_CONTAINER (emblems_table), button); + } + + gtk_widget_show_all (emblems_table); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} diff --git a/test/test-copy.c b/test/test-copy.c new file mode 100644 index 00000000..5eaab1e5 --- /dev/null +++ b/test/test-copy.c @@ -0,0 +1,93 @@ +#include "test.h" + +#include <libcaja-private/caja-file-operations.h> +#include <libcaja-private/caja-progress-info.h> + +static void +copy_done (GHashTable *debuting_uris, gpointer data) +{ + g_print ("Copy done\n"); +} + +static void +changed_cb (CajaProgressInfo *info, + gpointer data) +{ + g_print ("Changed: %s -- %s\n", + caja_progress_info_get_status (info), + caja_progress_info_get_details (info)); +} + +static void +progress_changed_cb (CajaProgressInfo *info, + gpointer data) +{ + g_print ("Progress changed: %f\n", + caja_progress_info_get_progress (info)); +} + +static void +finished_cb (CajaProgressInfo *info, + gpointer data) +{ + g_print ("Finished\n"); + gtk_main_quit (); +} + +int +main (int argc, char* argv[]) +{ + GtkWidget *window; + GList *sources; + GFile *dest; + GFile *source; + int i; + GList *infos; + CajaProgressInfo *progress_info; + + g_thread_init (NULL); + + test_init (&argc, &argv); + + if (argc < 3) { + g_print ("Usage test-copy <sources...> <dest dir>\n"); + return 1; + } + + sources = NULL; + for (i = 1; i < argc - 1; i++) { + source = g_file_new_for_commandline_arg (argv[i]); + sources = g_list_prepend (sources, source); + } + sources = g_list_reverse (sources); + + dest = g_file_new_for_commandline_arg (argv[i]); + + window = test_window_new ("copy test", 5); + + gtk_widget_show (window); + + caja_file_operations_copy (sources, + NULL /* GArray *relative_item_points */, + dest, + GTK_WINDOW (window), + copy_done, NULL); + + infos = caja_get_all_progress_info (); + + if (infos == NULL) { + return 0; + } + + progress_info = CAJA_PROGRESS_INFO (infos->data); + + g_signal_connect (progress_info, "changed", (GCallback)changed_cb, NULL); + g_signal_connect (progress_info, "progress-changed", (GCallback)progress_changed_cb, NULL); + g_signal_connect (progress_info, "finished", (GCallback)finished_cb, NULL); + + gtk_main (); + + return 0; +} + + diff --git a/test/test-eel-background.c b/test/test-eel-background.c new file mode 100644 index 00000000..6f5bba23 --- /dev/null +++ b/test/test-eel-background.c @@ -0,0 +1,38 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +#include <eel/eel-background.h> +#include <gtk/gtk.h> + +#define PATTERNS_DIR "/mate-source/eel/data/patterns" + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + EelBackground *background; + char *image_uri; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy", + gtk_main_quit, NULL); + + background = eel_get_widget_background (window); + + eel_background_set_color (background, + "red-blue:h"); + + image_uri = g_filename_to_uri (PATTERNS_DIR "/50s.png", NULL, NULL); + +#if 1 + eel_background_set_image_uri (background, image_uri); +#endif + g_free (image_uri); + + + gtk_widget_show_all (window); + gtk_main (); + + return 0; +} diff --git a/test/test-eel-editable-label.c b/test/test-eel-editable-label.c new file mode 100644 index 00000000..f2ba6961 --- /dev/null +++ b/test/test-eel-editable-label.c @@ -0,0 +1,58 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +#include <config.h> + +#include <gtk/gtk.h> + +#include <eel/eel-editable-label.h> + + +static void +quit (GtkWidget *widget, gpointer data) +{ + gtk_main_quit (); +} + +int +main (int argc, char* argv[]) +{ + GtkWidget *window; + GtkWidget *label; + GtkWidget *vbox; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (quit), NULL); + + vbox = gtk_vbox_new (FALSE, 0); + + gtk_container_add (GTK_CONTAINER (window), vbox); + + label = eel_editable_label_new ("Centered dsau dsfgsdfgoydsfiugy oiusdyfg iouysdf goiuys dfioguy siodufgy iusdyfgiu ydsf giusydf gouiysdfgoiuysdfg oiudyfsg Label"); + + gtk_widget_set_size_request (label, 200, -1); + eel_editable_label_set_line_wrap (EEL_EDITABLE_LABEL (label), TRUE); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 4); + + label = eel_editable_label_new ("Left aligned label"); + + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 4); + + label = eel_editable_label_new ("Right aligned label"); + + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 4); + + gtk_window_set_default_size (GTK_WINDOW (window), 300, 300); + + gtk_widget_show_all (window); + + gtk_main (); + + return 0; +} diff --git a/test/test-eel-image-scrolled.c b/test/test-eel-image-scrolled.c new file mode 100644 index 00000000..c89cfe9f --- /dev/null +++ b/test/test-eel-image-scrolled.c @@ -0,0 +1,187 @@ +#include "test.h" + +#if 0 +typedef struct +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *entry; + GtkWidget *hbox; + GtkWidget *smooth_toggle; + GtkWidget *frame; + GtkWidget *label; +} Window; + +#if 0 +static void +toggle_smooth_callback (GtkWidget *widget, gpointer callback_data) +{ + Window *window; + EelLabel *label; + + window = (Window *) callback_data; + + if (!EEL_IS_LABEL (window->label)) { + return; + } + + label = GTK_LABEL (window->label); + + gtk_label_set_is_smooth (label, !gtk_label_get_is_smooth (label)); +} +#endif + +static Window * +window_new (const char *title, guint border_width) +{ + Window *window; + GtkWidget *main_vbox; + + window = g_new0 (Window, 1); + + window->window = test_window_new (title, border_width); + + main_vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window->window), main_vbox); + + window->vbox = gtk_vbox_new (FALSE, 0); + window->entry = gtk_entry_new (); + window->hbox = gtk_hbox_new (FALSE, 0); +// window->smooth_toggle = gtk_check_button_new_with_label ("Smooth"); + + gtk_box_pack_start (GTK_BOX (main_vbox), window->vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), window->hbox, FALSE, FALSE, 0); + gtk_box_pack_end (GTK_BOX (main_vbox), window->entry, FALSE, FALSE, 0); + +// gtk_box_pack_start (GTK_BOX (window->hbox), window->smooth_toggle, FALSE, FALSE, 0); + + gtk_widget_show (main_vbox); + gtk_widget_show (window->vbox); + gtk_widget_show (window->hbox); + gtk_widget_show (window->entry); + + return window; +} + +static Window * +label_window_new (const char *title, + guint border_width, + const char *file_name, + const char *tile_file_name) +{ + Window *window; + + window = window_new (title, border_width); + + window->frame = gtk_frame_new ("Foo"); + window->label = gtk_label_new (file_name); + + if (tile_file_name != NULL) { + gtk_label_set_tile_pixbuf_from_file_name (GTK_LABEL (window->label), + tile_file_name); + } + + gtk_container_add (GTK_CONTAINER (window->frame), window->label); + + gtk_box_pack_start (GTK_BOX (window->vbox), window->frame, TRUE, TRUE, 0); + + gtk_widget_show (window->label); + gtk_widget_show (window->frame); + + return window; +} +#endif + +static const char text[] = +"The Eel shell is under development; it's not " +"ready for daily use. Some features are not yet done, " +"partly done, or unstable. The program doesn't look " +"or act exactly the way it will in version 1.0." +"\n\n" +"If you do decide to test this version of Eel, " +"beware. The program could do something " +"unpredictable and may even delete or overwrite " +"files on your computer." +"\n\n" +"For more information, visit http://eel.eazel.com."; + +static GtkWidget * +label_window_new (void) +{ + GtkWidget *window; + GtkWidget *label; + EelBackground *background; + + window = test_window_new ("Scrolled Label Test", 10); + + background = eel_get_widget_background (GTK_WIDGET (window)); + eel_background_set_color (background, "white"); + + /* Label */ + label = gtk_label_new (text); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + + gtk_container_add (GTK_CONTAINER (window), label); + + gtk_widget_show (label); + + return window; +} + +static GtkWidget * +label_window_new_scrolled (void) +{ + GtkWidget *window; + GtkWidget *scrolled; + GtkWidget *viewport; + GtkWidget *label; + EelBackground *background; + + window = test_window_new ("Scrolled Label Test", 10); + + /* Scrolled window */ + scrolled = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (window), scrolled); + + /* Viewport */ + viewport = gtk_viewport_new (NULL, NULL); + gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_OUT); + gtk_container_add (GTK_CONTAINER (scrolled), viewport); + + background = eel_get_widget_background (GTK_WIDGET (viewport)); + eel_background_set_color (background, "white"); + + /* Label */ + label = gtk_label_new (text); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + + gtk_container_add (GTK_CONTAINER (viewport), label); + + gtk_widget_show (label); + gtk_widget_show (viewport); + gtk_widget_show (scrolled); + + return window; +} + +int +main (int argc, char* argv[]) +{ + GtkWidget *label_window; + GtkWidget *scrolled_label_window; + + test_init (&argc, &argv); + + label_window = label_window_new (); + scrolled_label_window = label_window_new_scrolled (); + + gtk_widget_show (scrolled_label_window); + gtk_widget_show (label_window); + + gtk_main (); + + return 0; +} diff --git a/test/test-eel-image-table.c b/test/test-eel-image-table.c new file mode 100644 index 00000000..d60aa91b --- /dev/null +++ b/test/test-eel-image-table.c @@ -0,0 +1,304 @@ +#include "test.h" + +#include <eel/eel-image-table.h> +#include <gtk/gtk.h> +#include <stdlib.h> + +static const char pixbuf_name[] = "/usr/share/pixmaps/mate-about-logo.png"; + +#define BG_COLOR 0xFFFFFF +#define BG_COLOR_SPEC "white" + +static const char *names[] = +{ + "Tomaso Albinoni", + "Isaac Alb�niz", + "Georges Bizet", + "Luigi Boccherini", + "Alexander Borodin", + "Johannes Brahms", + "Max Bruch", + "Anton Bruckner", + "Fr�d�ric Chopin", + "Aaron Copland", + "John Corigliano", + "Claude Debussy", + "L�o Delibes", + "Anton�n Dvor�k", + "Edward Elgar", + "Manuel de Falla", + "George Gershwin", + "Alexander Glazunov", + "Mikhail Glinka", + "Enrique Granados", + "Edvard Grieg", + "Joseph Haydn", + "Scott Joplin", + "Franz Liszt", + "Gustav Mahler", + "Igor Markevitch", + "Felix Mendelssohn", + "Modest Mussorgsky", + "Sergei Prokofiev", + "Giacomo Puccini", + "Maurice Ravel", + "Ottorino Respighi", + "Joaquin Rodrigo", + "Gioachino Rossini", + "Domenico Scarlatti", + "Franz Schubert", + "Robert Schumann", + "Jean Sibelius", + "Bedrich Smetana", + "Johann Strauss", + "Igor Stravinsky", + "Giuseppe Verdi", + "Antonio Vivaldi", + "Richard Wagner", +}; + +static GtkWidget * +labeled_image_new (const char *text, + const char *icon_name) +{ + GtkWidget *image; + GdkPixbuf *pixbuf = NULL; + + if (icon_name) { + float sizes[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, + 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0 }; + pixbuf = test_pixbuf_new_named (icon_name, sizes[random () % G_N_ELEMENTS (sizes)]); + } + + image = eel_labeled_image_new (text, pixbuf); + + eel_gdk_pixbuf_unref_if_not_null (pixbuf); + + return image; +} + + +static void +image_table_child_enter_callback (GtkWidget *image_table, + GtkWidget *item, + gpointer callback_data) +{ +#if 0 + char *text; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (EEL_IS_LABELED_IMAGE (item)); + + text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item)); + + g_print ("%s(%s)\n", G_STRFUNC, text); +#endif +} + +static void +image_table_child_leave_callback (GtkWidget *image_table, + GtkWidget *item, + gpointer callback_data) +{ +#if 0 + char *text; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (EEL_IS_LABELED_IMAGE (item)); + + text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item)); + + g_print ("%s(%s)\n", G_STRFUNC, text); +#endif +} + +static void +image_table_child_pressed_callback (GtkWidget *image_table, + GtkWidget *item, + gpointer callback_data) +{ + char *text; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (EEL_IS_LABELED_IMAGE (item)); + + text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item)); + + g_print ("%s(%s)\n", G_STRFUNC, text); +} + +static void +image_table_child_released_callback (GtkWidget *image_table, + GtkWidget *item, + gpointer callback_data) +{ + char *text; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (EEL_IS_LABELED_IMAGE (item)); + + text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item)); + + g_print ("%s(%s)\n", G_STRFUNC, text); +} + +static void +image_table_child_clicked_callback (GtkWidget *image_table, + GtkWidget *item, + gpointer callback_data) +{ + char *text; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (EEL_IS_LABELED_IMAGE (item)); + + text = eel_labeled_image_get_text (EEL_LABELED_IMAGE (item)); + + g_print ("%s(%s)\n", G_STRFUNC, text); +} + +static int +foo_timeout (gpointer callback_data) +{ + static int recursion_count = 0; + g_return_val_if_fail (GTK_IS_WINDOW (callback_data), FALSE); + + recursion_count++; + + g_print ("%s(%d)\n", G_STRFUNC, recursion_count); + gtk_widget_queue_resize (GTK_WIDGET (callback_data)); + + recursion_count--; + + return FALSE; +} + +static void +image_table_size_allocate (GtkWidget *image_table, + GtkAllocation *allocation, + gpointer callback_data) +{ + static int recursion_count = 0; + GtkAllocation w_allocation; + + g_return_if_fail (EEL_IS_IMAGE_TABLE (image_table)); + g_return_if_fail (allocation != NULL); + g_return_if_fail (GTK_IS_WINDOW (callback_data)); + + recursion_count++; + + if (0) g_timeout_add (0, foo_timeout, callback_data); + + /*gtk_widget_queue_resize (GTK_WIDGET (callback_data));*/ + + gtk_widget_get_allocation (GTK_WIDGET (image_table), &w_allocation); + if (0) gtk_widget_size_allocate (GTK_WIDGET (image_table), + &w_allocation); + + g_print ("%s(%d)\n", G_STRFUNC, recursion_count); + + recursion_count--; +} + +static GtkWidget * +image_table_new_scrolled (void) +{ + GtkWidget *scrolled; + GtkWidget *viewport; + GtkWidget *window; + GtkWidget *image_table; + int i; + + window = test_window_new ("Image Table Test", 10); + + gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); + + /* Scrolled window */ + scrolled = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (window), scrolled); + + /* Viewport */ + viewport = gtk_viewport_new (NULL, NULL); + gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_OUT); + gtk_container_add (GTK_CONTAINER (scrolled), viewport); + + image_table = eel_image_table_new (FALSE); + + if (0) g_signal_connect (image_table, + "size_allocate", + G_CALLBACK (image_table_size_allocate), + window); + + eel_wrap_table_set_x_justification (EEL_WRAP_TABLE (image_table), + EEL_JUSTIFICATION_MIDDLE); + eel_wrap_table_set_y_justification (EEL_WRAP_TABLE (image_table), + EEL_JUSTIFICATION_END); + + gtk_container_add (GTK_CONTAINER (viewport), image_table); + + g_signal_connect (image_table, + "child_enter", + G_CALLBACK (image_table_child_enter_callback), + NULL); + + g_signal_connect (image_table, + "child_leave", + G_CALLBACK (image_table_child_leave_callback), + NULL); + + g_signal_connect (image_table, + "child_pressed", + G_CALLBACK (image_table_child_pressed_callback), + NULL); + + g_signal_connect (image_table, + "child_released", + G_CALLBACK (image_table_child_released_callback), + NULL); + + g_signal_connect (image_table, + "child_clicked", + G_CALLBACK (image_table_child_clicked_callback), + NULL); + + eel_gtk_widget_set_background_color (viewport, BG_COLOR_SPEC); + + for (i = 0; i < 100; i++) { + char *text; + GtkWidget *image; + + text = g_strdup_printf ("%s %d", + names[random () % G_N_ELEMENTS (names)], + i); + image = labeled_image_new (text, pixbuf_name); + g_free (text); + + gtk_container_add (GTK_CONTAINER (image_table), image); + gtk_widget_show (image); + } + + gtk_widget_show (viewport); + gtk_widget_show (scrolled); + gtk_widget_show (image_table); + + return window; +} + +int +main (int argc, char* argv[]) +{ + GtkWidget *window = NULL; + + test_init (&argc, &argv); + + window = image_table_new_scrolled (); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} diff --git a/test/test-eel-labeled-image.c b/test/test-eel-labeled-image.c new file mode 100644 index 00000000..a90afebc --- /dev/null +++ b/test/test-eel-labeled-image.c @@ -0,0 +1,79 @@ +#include "test.h" + +#include <eel/eel-labeled-image.h> + + +static const char pixbuf_name[] = "/usr/share/pixmaps/mate-globe.png"; + +static void +button_callback (GtkWidget *button, + gpointer callback_data) +{ + const char *info = callback_data; + g_return_if_fail (GTK_IS_BUTTON (button)); + + g_print ("%s(%p)\n", info, button); +} + +static GtkWidget * +labeled_image_button_window_new (const char *title, + GdkPixbuf *pixbuf) +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *button; + GtkWidget *toggle_button; + GtkWidget *check_button; + GtkWidget *plain; + + window = test_window_new (title, 20); + vbox = gtk_vbox_new (FALSE, 10); + gtk_container_add (GTK_CONTAINER (window), vbox); + + if (1) button = eel_labeled_image_button_new ("GtkButton with LabeledImage", pixbuf); + if (1) toggle_button = eel_labeled_image_toggle_button_new ("GtkToggleButton with LabeledImage", pixbuf); + if (1) check_button = eel_labeled_image_check_button_new ("GtkCheckButton with LabeledImage", pixbuf); + if (1) { + plain = eel_labeled_image_new ("Plain LabeledImage", pixbuf); + eel_labeled_image_set_can_focus (EEL_LABELED_IMAGE (plain), TRUE); + } + + if (button) gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); + if (toggle_button) gtk_box_pack_start (GTK_BOX (vbox), toggle_button, TRUE, TRUE, 0); + if (check_button) gtk_box_pack_start (GTK_BOX (vbox), check_button, TRUE, TRUE, 0); + if (plain) gtk_box_pack_start (GTK_BOX (vbox), plain, TRUE, TRUE, 0); + + if (button) { + g_signal_connect (button, "enter", G_CALLBACK (button_callback), "enter"); + g_signal_connect (button, "leave", G_CALLBACK (button_callback), "leave"); + g_signal_connect (button, "pressed", G_CALLBACK (button_callback), "pressed"); + g_signal_connect (button, "released", G_CALLBACK (button_callback), "released"); + g_signal_connect (button, "clicked", G_CALLBACK (button_callback), "clicked"); + } + + gtk_widget_show_all (vbox); + + return window; +} + +int +main (int argc, char* argv[]) +{ + GtkWidget *labeled_image_window = NULL; + GtkWidget *labeled_image_button_window = NULL; + GdkPixbuf *pixbuf = NULL; + + test_init (&argc, &argv); + + if (1) pixbuf = test_pixbuf_new_named (pixbuf_name, 1.0); + if (1) labeled_image_button_window = labeled_image_button_window_new ("LabeledImage in GtkButton Test", pixbuf); + + eel_gdk_pixbuf_unref_if_not_null (pixbuf); + + if (labeled_image_window) gtk_widget_show (labeled_image_window); + if (labeled_image_button_window) gtk_widget_show (labeled_image_button_window); + + gtk_main (); + + return test_quit (EXIT_SUCCESS); +} diff --git a/test/test-eel-pixbuf-scale.c b/test/test-eel-pixbuf-scale.c new file mode 100644 index 00000000..485c922f --- /dev/null +++ b/test/test-eel-pixbuf-scale.c @@ -0,0 +1,83 @@ +#include "test.h" + +#include <eel/eel-gdk-pixbuf-extensions.h> + +#include <sys/time.h> + + +#define N_SCALES 100 + +#define DEST_WIDTH 32 +#define DEST_HEIGHT 32 + +int +main (int argc, char* argv[]) +{ + GdkPixbuf *pixbuf, *scaled; + GError *error; + struct timeval t1, t2; + int i; + + test_init (&argc, &argv); + + if (argc != 2) { + printf ("Usage: test <image filename>\n"); + exit (1); + } + + error = NULL; + pixbuf = gdk_pixbuf_new_from_file (argv[1], &error); + + if (pixbuf == NULL) { + printf ("error loading pixbuf: %s\n", error->message); + exit (1); + } + + printf ("scale factors: %f, %f\n", + (double)gdk_pixbuf_get_width(pixbuf)/DEST_WIDTH, + (double)gdk_pixbuf_get_height(pixbuf)/DEST_HEIGHT); + + gettimeofday(&t1, NULL); + for (i = 0; i < N_SCALES; i++) { + scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT); + g_object_unref (scaled); + } + gettimeofday(&t2, NULL); + g_print ("Time for eel_gdk_pixbuf_scale_down: %ld msecs\n", + (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000); + + + + gettimeofday(&t1, NULL); + for (i = 0; i < N_SCALES; i++) { + scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_NEAREST); + g_object_unref (scaled); + } + gettimeofday(&t2, NULL); + g_print ("Time for INTERP_NEAREST: %ld msecs\n", + (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000); + + + gettimeofday(&t1, NULL); + for (i = 0; i < N_SCALES; i++) { + scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_BILINEAR); + g_object_unref (scaled); + } + gettimeofday(&t2, NULL); + g_print ("Time for INTERP_BILINEAR: %ld msecs\n", + (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000); + + scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT); + gdk_pixbuf_save (scaled, "eel_scaled.png", "png", NULL, NULL); + g_object_unref (scaled); + + scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_NEAREST); + gdk_pixbuf_save (scaled, "nearest_scaled.png", "png", NULL, NULL); + g_object_unref (scaled); + + scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_BILINEAR); + gdk_pixbuf_save (scaled, "bilinear_scaled.png", "png", NULL, NULL); + g_object_unref (scaled); + + return 0; +} diff --git a/test/test.c b/test/test.c new file mode 100644 index 00000000..5ea5e646 --- /dev/null +++ b/test/test.c @@ -0,0 +1,152 @@ +#include "test.h" +#include <sys/types.h> +#include <unistd.h> + +#include <eel/eel-preferences.h> + +void +test_init (int *argc, + char ***argv) +{ + gtk_init (argc, argv); + + eel_make_warnings_and_criticals_stop_in_debugger (); +} + +int +test_quit (int exit_code) +{ + if (gtk_main_level () > 0) { + gtk_main_quit (); + } + + return exit_code; +} + +void +test_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer callback_data) +{ + test_quit (0); +} + +GtkWidget * +test_window_new (const char *title, guint border_width) +{ + GtkWidget *window; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + if (title != NULL) { + gtk_window_set_title (GTK_WINDOW (window), title); + } + + g_signal_connect (window, "delete_event", + G_CALLBACK (test_delete_event), NULL); + + gtk_container_set_border_width (GTK_CONTAINER (window), border_width); + + return window; +} + +void +test_gtk_widget_set_background_image (GtkWidget *widget, + const char *image_name) +{ + EelBackground *background; + char *uri; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (image_name != NULL); + + background = eel_get_widget_background (widget); + + uri = g_strdup_printf ("file://%s/%s", CAJA_DATADIR, image_name); + + eel_background_set_image_uri (background, uri); + + g_free (uri); +} + +void +test_gtk_widget_set_background_color (GtkWidget *widget, + const char *color_spec) +{ + EelBackground *background; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (color_spec != NULL); + + background = eel_get_widget_background (widget); + + eel_background_set_color (background, color_spec); +} + +GdkPixbuf * +test_pixbuf_new_named (const char *name, float scale) +{ + GdkPixbuf *pixbuf; + char *path; + + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (scale >= 0.0, NULL); + + if (name[0] == '/') { + path = g_strdup (name); + } else { + path = g_strdup_printf ("%s/%s", CAJA_DATADIR, name); + } + + pixbuf = gdk_pixbuf_new_from_file (path, NULL); + + g_free (path); + + g_return_val_if_fail (pixbuf != NULL, NULL); + + if (scale != 1.0) { + GdkPixbuf *scaled; + float width = gdk_pixbuf_get_width (pixbuf) * scale; + float height = gdk_pixbuf_get_width (pixbuf) * scale; + + scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + + g_object_unref (pixbuf); + + g_return_val_if_fail (scaled != NULL, NULL); + + pixbuf = scaled; + } + + return pixbuf; +} + +GtkWidget * +test_label_new (const char *text, + gboolean with_background, + int num_sizes_larger) +{ + GtkWidget *label; + + if (text == NULL) { + text = "Foo"; + } + + label = gtk_label_new (text); + + return label; +} + +void +test_window_set_title_with_pid (GtkWindow *window, + const char *title) +{ + char *tmp; + + g_return_if_fail (GTK_IS_WINDOW (window)); + + tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title); + gtk_window_set_title (GTK_WINDOW (window), tmp); + g_free (tmp); +} + diff --git a/test/test.h b/test/test.h new file mode 100644 index 00000000..45e3d45c --- /dev/null +++ b/test/test.h @@ -0,0 +1,38 @@ +#ifndef TEST_H +#define TEST_H + +#include <config.h> +#include <gtk/gtk.h> + +#include <eel/eel-debug.h> +#include <eel/eel.h> +#include <libcaja-private/caja-file-utilities.h> + +void test_init (int *argc, + char ***argv); +int test_quit (int exit_code); +void test_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer callback_data); +GtkWidget *test_window_new (const char *title, + guint border_width); +void test_gtk_widget_set_background_image (GtkWidget *widget, + const char *image_name); +void test_gtk_widget_set_background_color (GtkWidget *widget, + const char *color_spec); +GdkPixbuf *test_pixbuf_new_named (const char *name, + float scale); +GtkWidget *test_label_new (const char *text, + gboolean with_background, + int num_sizes_larger); +void test_pixbuf_draw_rectangle_tiled (GdkPixbuf *pixbuf, + const char *tile_name, + int x0, + int y0, + int x1, + int y1, + int opacity); +void test_window_set_title_with_pid (GtkWindow *window, + const char *title); + +#endif /* TEST_H */ |