[Goodies-commits] r3983 - ristretto/trunk/src

Stephan Arts stephan at xfce.org
Sat Feb 23 12:57:31 CET 2008


Author: stephan
Date: 2008-02-23 11:57:31 +0000 (Sat, 23 Feb 2008)
New Revision: 3983

Modified:
   ristretto/trunk/src/main.c
   ristretto/trunk/src/navigator.c
   ristretto/trunk/src/picture_viewer.c
Log:
Improve behaviour when opening files from cli

- open files while inside g_main_loop



Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c	2008-02-23 11:15:06 UTC (rev 3982)
+++ ristretto/trunk/src/main.c	2008-02-23 11:57:31 UTC (rev 3983)
@@ -26,6 +26,11 @@
 #include "picture_viewer.h"
 #include "main_window.h"
 
+typedef struct {
+    RsttoNavigator *navigator;
+    GSList *files;
+} RsttoOpenFiles;
+
 static ThunarVfsMimeDatabase *mime_dbase = NULL;
 
 static XfceRc *xfce_rc;
@@ -38,6 +43,9 @@
 static gboolean
 cb_rstto_main_window_configure_event (GtkWidget *widget, GdkEventConfigure *event);
 
+static gboolean
+cb_rstto_open_files (RsttoOpenFiles *rof);
+
 gboolean version = FALSE;
 
 static GOptionEntry entries[] =
@@ -49,6 +57,7 @@
     { NULL }
 };
 
+
 #if GTK_CHECK_VERSION(2,12,0)
 #define RSTTO_COLOR_PARSE gdk_color_parse
 #define RSTTO_COLOR_TO_STRING gdk_color_to_string
@@ -267,70 +276,16 @@
     /* When more then one file is provided over the CLI,
      * just open those files and don't index the folder
      */
-    if (argc > 2)
+    if (argc > 1)
     {
+        RsttoOpenFiles rof;
+        rof.navigator = navigator;
         for (n = 1; n < argc; ++n)
         {
-            if (g_path_is_absolute(argv[1]))
-            {
-                path_dir = g_strdup(argv[1]);
-            }
-            else
-            {
-                gchar *base_dir = g_get_current_dir();
-
-                path_dir = g_build_path("/", base_dir, argv[1], NULL);
-
-                g_free(base_dir);
-            }
-            if(g_file_test(path_dir, G_FILE_TEST_EXISTS))
-            {
-
-                if(g_file_test(path_dir, G_FILE_TEST_IS_DIR))
-                {
-                    rstto_navigator_open_folder (navigator, path_dir, TRUE, NULL);
-                }
-                else
-                {
-                    rstto_navigator_open_file (navigator, path_dir, TRUE, NULL);
-                }
-            }
-
-            g_free(path_dir);
+            rof.files = g_slist_prepend(rof.files, argv[n]);
         }
-        rstto_navigator_jump_first(navigator);
-    }
-    else
-    {
-        if (argc == 2)
-        {
-            if (g_path_is_absolute(argv[1]))
-            {
-                path_dir = g_strdup(argv[1]);
-            }
-            else
-            {
-                gchar *base_dir = g_get_current_dir();
 
-                path_dir = g_build_path("/", base_dir, argv[1], NULL);
-
-                g_free(base_dir);
-            }
-            if(g_file_test(path_dir, G_FILE_TEST_EXISTS))
-            {
-
-                if(g_file_test(path_dir, G_FILE_TEST_IS_DIR))
-                {
-                    rstto_navigator_open_folder (navigator, path_dir, TRUE, NULL);
-                }
-                else
-                {
-                    rstto_navigator_open_file (navigator, path_dir, TRUE, NULL);
-                }
-            }
-
-            g_free(path_dir);
-        }
+        gtk_init_add((GtkFunction)cb_rstto_open_files, &rof);
     }
 
     g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
@@ -447,3 +402,50 @@
     /* let Gtk+ handle the configure event */
     return FALSE;
 }
+
+static gboolean
+cb_rstto_open_files (RsttoOpenFiles *rof)
+{
+    gchar *path_dir = NULL;
+    RsttoNavigator *navigator = rof->navigator;
+
+    if (g_slist_length(rof->files) >= 1)
+    {
+        GSList *_iter = rof->files;
+        while(_iter)
+        {
+            if (g_path_is_absolute(_iter->data))
+            {
+                path_dir = g_strdup(_iter->data);
+            }
+            else
+            {
+                gchar *base_dir = g_get_current_dir();
+
+                path_dir = g_build_path("/", base_dir, _iter->data, NULL);
+
+                g_free(base_dir);
+            }
+            if(g_file_test(path_dir, G_FILE_TEST_EXISTS))
+            {
+
+                if(g_file_test(path_dir, G_FILE_TEST_IS_DIR))
+                {
+                    rstto_navigator_open_folder (navigator, path_dir, TRUE, NULL);
+                }
+                else
+                {
+                    rstto_navigator_open_file (navigator, path_dir, TRUE, NULL);
+                }
+            }
+
+            g_free(path_dir);
+
+            _iter = g_slist_next(_iter);
+        }
+
+        if (g_slist_length(rof->files) > 1)
+            rstto_navigator_jump_first(navigator);
+    }
+    return FALSE;
+}

Modified: ristretto/trunk/src/navigator.c
===================================================================
--- ristretto/trunk/src/navigator.c	2008-02-23 11:15:06 UTC (rev 3982)
+++ ristretto/trunk/src/navigator.c	2008-02-23 11:57:31 UTC (rev 3983)
@@ -1425,6 +1425,10 @@
             {
                 rstto_navigator_entry_select((RsttoNavigatorEntry*)iter->data);
             }
+            else
+            {
+                g_critical("not found");
+            }
         }
         else
         {

Modified: ristretto/trunk/src/picture_viewer.c
===================================================================
--- ristretto/trunk/src/picture_viewer.c	2008-02-23 11:15:06 UTC (rev 3982)
+++ ristretto/trunk/src/picture_viewer.c	2008-02-23 11:57:31 UTC (rev 3983)
@@ -1235,17 +1235,22 @@
 
     while(*_array)
     {
-        if (g_file_test(*_array, G_FILE_TEST_EXISTS))
+        ThunarVfsPath *vfs_path = thunar_vfs_path_new(*_array, NULL);
+        gchar *path = thunar_vfs_path_dup_string(vfs_path);
+        if (g_file_test(path, G_FILE_TEST_EXISTS))
         {
-            if (g_file_test(*_array, G_FILE_TEST_IS_DIR))
+            if (g_file_test(path, G_FILE_TEST_IS_DIR))
             {
-                rstto_navigator_open_folder(picture_viewer->priv->navigator, *_array, FALSE, NULL);
+                rstto_navigator_open_folder(picture_viewer->priv->navigator, path, FALSE, NULL);
             }
             else
             {
-                rstto_navigator_open_file(picture_viewer->priv->navigator, *_array, FALSE, NULL);
+                rstto_navigator_open_file(picture_viewer->priv->navigator, path, FALSE, NULL);
             }
         }
+
+        g_free(path);
+        thunar_vfs_path_unref(vfs_path);
         _array++;
     }
     
@@ -1291,6 +1296,7 @@
     if (G_UNLIKELY (target != gdk_atom_intern ("text/uri-list", FALSE)))
     {
         /* we cannot handle the drop */
+        g_debug("FAAAAAAAAAAAAAALSE");
         return FALSE;
     }
     return TRUE;




More information about the Goodies-commits mailing list