nautilus-3.6.3/test/test.c

No issues found

  1 #include "test.h"
  2 #include <sys/types.h>
  3 #include <unistd.h>
  4 
  5 void
  6 test_init (int *argc,
  7 	   char ***argv)
  8 {
  9 	gtk_init (argc, argv);
 10 
 11 	eel_make_warnings_and_criticals_stop_in_debugger ();
 12 }
 13 
 14 int
 15 test_quit (int exit_code)
 16 {
 17 	if (gtk_main_level () > 0) {
 18 		gtk_main_quit ();
 19 	}
 20 
 21 	return exit_code;
 22 }
 23 
 24 void
 25 test_delete_event (GtkWidget *widget,
 26 		   GdkEvent *event,
 27 		   gpointer callback_data)
 28 {
 29 	test_quit (0);
 30 }
 31 
 32 GtkWidget *
 33 test_window_new (const char *title, guint border_width)
 34 {
 35 	GtkWidget *window;
 36 
 37 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 38 	
 39 	if (title != NULL) {
 40 		gtk_window_set_title (GTK_WINDOW (window), title);
 41 	}
 42 
 43 	g_signal_connect (window, "delete_event",
 44                           G_CALLBACK (test_delete_event), NULL);
 45 	
 46 	gtk_container_set_border_width (GTK_CONTAINER (window), border_width);
 47 	
 48 	return window;
 49 }
 50 
 51 GdkPixbuf *
 52 test_pixbuf_new_named (const char *name, float scale)
 53 {
 54 	GdkPixbuf *pixbuf;
 55 	char *path;
 56 
 57 	g_return_val_if_fail (name != NULL, NULL);
 58 	g_return_val_if_fail (scale >= 0.0, NULL);
 59 
 60 	if (name[0] == '/') {
 61 		path = g_strdup (name);
 62 	} else {
 63 		path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name);
 64 	}
 65 
 66 	pixbuf = gdk_pixbuf_new_from_file (path, NULL);
 67 
 68 	g_free (path);
 69 
 70 	g_return_val_if_fail (pixbuf != NULL, NULL);
 71 	
 72 	if (scale != 1.0) {
 73 		GdkPixbuf *scaled;
 74 		float width = gdk_pixbuf_get_width (pixbuf) * scale;
 75 		float height = gdk_pixbuf_get_width (pixbuf) * scale;
 76 
 77 		scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
 78 
 79 		g_object_unref (pixbuf);
 80 
 81 		g_return_val_if_fail (scaled != NULL, NULL);
 82 
 83 		pixbuf = scaled;
 84 	}
 85 
 86 	return pixbuf;
 87 }
 88 
 89 GtkWidget *
 90 test_label_new (const char *text,
 91 		gboolean with_background,
 92 		int num_sizes_larger)
 93 {
 94 	GtkWidget *label;
 95 
 96 	if (text == NULL) {
 97 		text = "Foo";
 98 	}
 99 	
100 	label = gtk_label_new (text);
101 
102 	return label;
103 }
104 
105 void 
106 test_window_set_title_with_pid (GtkWindow *window,
107 				const char *title)
108 {
109 	char *tmp;
110 	
111 	g_return_if_fail (GTK_IS_WINDOW (window));
112 
113 	tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title);
114 	gtk_window_set_title (GTK_WINDOW (window), tmp);
115 	g_free (tmp);
116 }