]> www.fi.muni.cz Git - evince.git/blobdiff - shell/main.c
[windows] Make evince relocatable on windows - stock icons
[evince.git] / shell / main.c
index 4d48fb203c383843aff671369b01f0022e3a13f2..43fca484baf5d36662f17850ff28bc732fbeb924 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <glib/gstdio.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
@@ -225,14 +226,27 @@ arguments_parse (void)
        return args;
 }
 
+static gint
+find_window_list (EvWindow    *window,
+                 const gchar *uri)
+{
+       return g_ascii_strcasecmp (uri, ev_window_get_uri (window));
+}
+
 static void
 load_files (const char **files,
            GHashTable  *args)
 {
-       int i;
+       int    i;
+       GList *windows;
+
+       windows = ev_application_get_windows (EV_APP);
 
        if (!files) {
-               ev_application_open_window (EV_APP, args, GDK_CURRENT_TIME, NULL);
+               if (!windows)
+                       ev_application_open_window (EV_APP, args, GDK_CURRENT_TIME, NULL);
+               else
+                       g_list_free (windows);
                return;
        }
 
@@ -245,7 +259,12 @@ load_files (const char **files,
                file = g_file_new_for_commandline_arg (files[i]);
                uri = g_file_get_uri (file);
                g_object_unref (file);
-               
+
+               if (g_list_find_custom (windows, uri, (GCompareFunc) find_window_list)) {
+                       g_free (uri);
+                       continue;
+               }
+
                label = strchr (uri, '#');
 
                if (label) {
@@ -271,6 +290,8 @@ load_files (const char **files,
                
                g_free (uri);
         }
+
+       g_list_free (windows);
 }
 
 #ifdef ENABLE_DBUS
@@ -409,7 +430,7 @@ main (int argc, char *argv[])
                }
        }
 #endif /* ENABLE_DBUS */
-
+       
         if (!ev_init ())
                 return 1;
 
@@ -423,10 +444,15 @@ main (int argc, char *argv[])
        egg_set_desktop_file (GNOMEDATADIR "/applications/evince.desktop");
 #endif /* G_OS_WIN32 */
 
-       if (!ev_application_load_session (EV_APP))
-               load_files (file_arguments, args);
+       ev_application_load_session (EV_APP);
+       load_files (file_arguments, args);
        g_hash_table_destroy (args);
 
+       /* Change directory so we don't prevent unmounting in case the initial cwd
+        * is on an external device (see bug #575436)
+        */
+       g_chdir (g_get_home_dir ());    
+
        gtk_main ();
 
        ev_shutdown ();