]> www.fi.muni.cz Git - evince.git/blobdiff - shell/main.c
[print] Fixes segmentation violation when format is empty
[evince.git] / shell / main.c
index 22d42afc5c096f2f25fe59f25fea75b034e00d06..214e9c0e2ea77625e246411488cc946adac31d5e 100644 (file)
 #include "ev-init.h"
 #include "ev-file-helpers.h"
 #include "ev-stock-icons.h"
+
+#ifdef WITH_SMCLIENT
 #include "eggsmclient.h"
-#ifndef G_OS_WIN32
+#ifdef GDK_WINDOWING_X11
 #include "eggdesktopfile.h"
 #endif
+#endif /* WITH_SMCLIENT */
+
+#ifdef G_OS_WIN32
+#ifdef DATADIR
+#undef DATADIR
+#endif
+#include <io.h>
+#include <conio.h>
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#endif
 
 static gchar   *ev_page_label;
 static gchar   *ev_find_string;
@@ -226,14 +239,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;
        }
 
@@ -246,7 +272,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) {
@@ -272,6 +303,8 @@ load_files (const char **files,
                
                g_free (uri);
         }
+
+       g_list_free (windows);
 }
 
 #ifdef ENABLE_DBUS
@@ -364,6 +397,31 @@ main (int argc, char *argv[])
        GHashTable *args;
        GError *error = NULL;
 
+#ifdef G_OS_WIN32
+
+    if (fileno (stdout) != -1 &&
+         _get_osfhandle (fileno (stdout)) != -1)
+       {
+         /* stdout is fine, presumably redirected to a file or pipe */
+       }
+    else
+    {
+         typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
+
+         AttachConsole_t p_AttachConsole =
+           (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
+
+         if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
+      {
+             freopen ("CONOUT$", "w", stdout);
+             dup2 (fileno (stdout), 1);
+             freopen ("CONOUT$", "w", stderr);
+             dup2 (fileno (stderr), 2);
+
+      }
+       }
+#endif
+
        /* Init glib threads asap */
        if (!g_thread_supported ())
                g_thread_init (NULL);
@@ -378,8 +436,11 @@ main (int argc, char *argv[])
        context = g_option_context_new (N_("GNOME Document Viewer"));
        g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
        g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
-       
+
+#ifdef WITH_SMCLIENT
        g_option_context_add_group (context, egg_sm_client_get_option_group ());
+#endif
+
        g_option_context_add_group (context, gtk_get_option_group (TRUE));
 
        if (!g_option_context_parse (context, &argc, &argv, &error)) {
@@ -416,16 +477,16 @@ main (int argc, char *argv[])
 
        ev_stock_icons_init ();
 
-#ifdef G_OS_WIN32
-       /* Manually set name and icon in win32 */
-       g_set_application_name (_("Evince"));
-       gtk_window_set_default_icon_name ("evince");
-#else
+#if defined(WITH_SMCLIENT) && defined(GDK_WINDOWING_X11)
        egg_set_desktop_file (GNOMEDATADIR "/applications/evince.desktop");
-#endif /* G_OS_WIN32 */
+#else
+       /* Manually set name and icon */
+       g_set_application_name (_("Document Viewer"));
+       gtk_window_set_default_icon_name ("evince");
+#endif /* WITH_SMCLIENT && GDK_WINDOWING_X11 */
 
-       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