gtk+ r19588 - in trunk: . tests



Author: matthiasc
Date: Sat Feb 16 01:23:18 2008
New Revision: 19588
URL: http://svn.gnome.org/viewvc/gtk+?rev=19588&view=rev

Log:
2008-02-15  Matthias Clasen  <mclasen redhat com>

        * tests/testfilechooser.c: Add a --backend option.
        (#516073, Christian Persch)



Modified:
   trunk/ChangeLog
   trunk/tests/testfilechooser.c

Modified: trunk/tests/testfilechooser.c
==============================================================================
--- trunk/tests/testfilechooser.c	(original)
+++ trunk/tests/testfilechooser.c	Sat Feb 16 01:23:18 2008
@@ -481,37 +481,56 @@
   GtkWidget *extra;
   GtkFileFilter *filter;
   GtkWidget *preview_vbox;
-  int i;
+  gboolean force_rtl = FALSE;
   gboolean multiple = FALSE;
+  char *action_arg = NULL;
+  char *backend = NULL;
+  GError *error = NULL;
+  GOptionEntry options[] = {
+    { "action", 'a', 0, G_OPTION_ARG_STRING, &action, "Filechooser action", "ACTION" },
+    { "backend", 'b', 0, G_OPTION_ARG_STRING, &backend, "Filechooser backend (default: gtk+)", "BACKEND" },
+    { "multiple", 'm', 0, G_OPTION_ARG_NONE, &multiple, "Select-multiple", NULL },
+    { "right-to-left", 'r', 0, G_OPTION_ARG_NONE, &force_rtl, "Force right-to-left layout.", NULL },
+    { NULL }
+  };
 
-  gtk_init (&argc, &argv);
+  if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error))
+    {
+      g_print ("Failed to parse args: %s\n", error->message);
+      g_error_free (error);
+      return 1;
+    }
 
-  /* to test rtl layout, set RTL=1 in the environment */
-  if (g_getenv ("RTL"))
+  if (force_rtl)
     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
 
   action = GTK_FILE_CHOOSER_ACTION_OPEN;
 
-  /* lame-o arg parsing */
-  for (i = 1; i < argc; i++)
+  if (action_arg != NULL)
     {
-      if (! strcmp ("--action=open", argv[i]))
+      if (! strcmp ("open", action_arg))
 	action = GTK_FILE_CHOOSER_ACTION_OPEN;
-      else if (! strcmp ("--action=save", argv[i]))
+      else if (! strcmp ("save", action_arg))
 	action = GTK_FILE_CHOOSER_ACTION_SAVE;
-      else if (! strcmp ("--action=select_folder", argv[i]))
+      else if (! strcmp ("select_folder", action_arg))
 	action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
-      else if (! strcmp ("--action=create_folder", argv[i]))
+      else if (! strcmp ("create_folder", action_arg))
 	action = GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
-      else if (! strcmp ("--multiple", argv[i]))
-	multiple = TRUE;
+
+      g_free (action_arg);
     }
 
+  if (backend == NULL)
+    backend = g_strdup ("gtk+");
+
   dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
 			 "action", action,
-			 "file-system-backend", "gtk+",
+			 "file-system-backend", backend,
 			 "select-multiple", multiple,
 			 NULL);
+
+  g_free (backend);
+
   switch (action)
     {
     case GTK_FILE_CHOOSER_ACTION_OPEN:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]