]> Pileus Git - ~andy/gtk/commitdiff
Add a --backend option. (#516073, Christian Persch)
authorMatthias Clasen <mclasen@redhat.com>
Sat, 16 Feb 2008 01:23:18 +0000 (01:23 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 16 Feb 2008 01:23:18 +0000 (01:23 +0000)
2008-02-15  Matthias Clasen  <mclasen@redhat.com>

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

svn path=/trunk/; revision=19588

ChangeLog
tests/testfilechooser.c

index 5b2188bd4cab06ca77e75ec9e84424438d3dfb72..304aaca377d237c9dff8bb1a86a2861988b64701 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-15  Matthias Clasen  <mclasen@redhat.com>
+
+       * tests/testfilechooser.c: Add a --backend option.
+       (#516073, Christian Persch)
+
 2008-02-16  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkprivate-quartz.h:
index 548114fd17902762c8fcaf18ddd8bc5175c89f16..4164d739b23828b6a50c8c05c96108eb465d0d05 100644 (file)
@@ -481,37 +481,56 @@ main (int argc, char **argv)
   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 }
+  };
+
+  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;
+    }
 
-  gtk_init (&argc, &argv);
-
-  /* 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: