- ev_window = ev_application_get_empty_window (application);
-
- chooser = gtk_file_chooser_dialog_new (_("Open document"),
- GTK_WINDOW (ev_window),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_OK,
- NULL);
-
- if (folder) {
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
- folder);
- }
-
- documents_filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (documents_filter,
- _("All Documents"));
- gtk_file_filter_add_mime_type (documents_filter, "application/postscript");
- gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript");
- gtk_file_filter_add_mime_type (documents_filter, "image/x-eps");
- gtk_file_filter_add_mime_type (documents_filter, "application/pdf");
-#ifdef ENABLE_DVI
- gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi");
-#endif
- gtk_file_filter_add_pixbuf_formats (documents_filter);
-#ifdef ENABLE_DJVU
- gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu");
-#endif
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
-
- ps_filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
- gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
- gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript");
- gtk_file_filter_add_mime_type (ps_filter, "image/x-eps");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
-
- pdf_filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
- gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
-
-#ifdef ENABLE_DVI
- dvi_filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (dvi_filter, _("DVI Documents"));
- gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi");
- gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter);
+ g_return_if_fail (uri != NULL);
+
+ if (application->uri && strcmp (application->uri, uri) != 0) {
+ /* spawn a new evince process */
+ ev_spawn (uri, screen, dest, mode, search_string, timestamp);
+ return;
+ } else {
+#ifdef ENABLE_DBUS
+ GHashTable *args = build_args (screen, dest, mode, search_string);
+ gboolean ret;
+
+ /* Register the uri or send OpenURI to
+ * remote instance if already registered
+ */
+ ret = ev_application_register_uri (application, uri, args, timestamp);
+ g_hash_table_destroy (args);
+ if (!ret)
+ return;
+#endif /* ENABLE_DBUS */
+
+ ev_window = ev_application_get_empty_window (application, screen);
+ if (!ev_window)
+ ev_window = EV_WINDOW (ev_window_new ());
+ }
+
+ application->uri = g_strdup (uri);
+
+ ev_application_open_uri_in_window (application, uri, ev_window,
+ screen, dest, mode,
+ search_string,
+ timestamp);
+}
+
+/**
+ * ev_application_open_window:
+ * @application: The instance of the application.
+ * @timestamp: Current time value.
+ *
+ * Creates a new window
+ */
+void
+ev_application_open_window (EvApplication *application,
+ GdkScreen *screen,
+ guint32 timestamp)
+{
+ GtkWidget *new_window = ev_window_new ();
+
+ if (screen) {
+ ev_stock_icons_set_screen (screen);
+ gtk_window_set_screen (GTK_WINDOW (new_window), screen);
+ }
+
+ if (!GTK_WIDGET_REALIZED (new_window))
+ gtk_widget_realize (new_window);
+
+#ifdef GDK_WINDOWING_X11
+ if (timestamp <= 0)
+ timestamp = gdk_x11_get_server_time (new_window->window);
+ gdk_x11_window_set_user_time (new_window->window, timestamp);
+
+ gtk_window_present (GTK_WINDOW (new_window));
+#else
+ gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
+#endif /* GDK_WINDOWING_X11 */
+}
+
+/**
+ * ev_application_open_uri:
+ * @application: The instance of the application.
+ * @uri: The uri to be opened
+ * @args: A #GHashTable with the arguments data.
+ * @timestamp: Current time value.
+ * @error: The #GError facility.
+ */
+static gboolean
+ev_application_open_uri (EvApplication *application,
+ const char *uri,
+ GHashTable *args,
+ guint timestamp,
+ GError **error)
+{
+ GList *windows, *l;
+ EvLinkDest *dest = NULL;
+ EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
+ const gchar *search_string = NULL;
+ GdkScreen *screen = NULL;
+
+ g_assert (application->uri != NULL);
+
+ /* FIXME: we don't need uri anymore,
+ * maybe this method should be renamed
+ * as reload, refresh or something like that
+ */
+ if (!application->uri || strcmp (application->uri, uri)) {
+ g_warning ("Invalid uri: %s, expected %s\n",
+ uri, application->uri);
+ return TRUE;
+ }
+
+ if (args) {
+ screen = get_screen_from_args (args);
+ dest = get_destination_from_args (args);
+ mode = get_window_run_mode_from_args (args);
+ search_string = get_find_string_from_args (args);
+ }
+
+ windows = ev_application_get_windows (application);
+ for (l = windows; l != NULL; l = g_list_next (l)) {
+ EvWindow *ev_window = EV_WINDOW (l->data);
+
+ ev_application_open_uri_in_window (application, uri, ev_window,
+ screen, dest, mode,
+ search_string,
+ timestamp);
+ }
+ g_list_free (windows);
+
+ if (dest)
+ g_object_unref (dest);
+
+ return TRUE;
+}
+
+void
+ev_application_open_uri_list (EvApplication *application,
+ GSList *uri_list,
+ GdkScreen *screen,
+ guint timestamp)
+{
+ GSList *l;
+
+ for (l = uri_list; l != NULL; l = l->next) {
+ ev_application_open_uri_at_dest (application, (char *)l->data,
+ screen, NULL, 0, NULL,
+ timestamp);
+ }
+}
+
+static void
+ev_application_accel_map_save (EvApplication *application)
+{
+ gchar *accel_map_file;
+ gchar *tmp_filename;
+ gint fd;
+
+ accel_map_file = g_build_filename (g_get_home_dir (),
+ ".gnome2", "accels",
+ "evince", NULL);
+
+ tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file);
+
+ fd = g_mkstemp (tmp_filename);
+ if (fd == -1) {
+ g_free (accel_map_file);
+ g_free (tmp_filename);
+
+ return;
+ }
+ gtk_accel_map_save_fd (fd);
+ close (fd);
+
+ if (g_rename (tmp_filename, accel_map_file) == -1) {
+ /* FIXME: win32? */
+ g_unlink (tmp_filename);
+ }
+
+ g_free (accel_map_file);
+ g_free (tmp_filename);
+}
+
+static void
+ev_application_accel_map_load (EvApplication *application)
+{
+ gchar *accel_map_file;
+
+ accel_map_file = g_build_filename (g_get_home_dir (),
+ ".gnome2", "accels",
+ "evince", NULL);
+ gtk_accel_map_load (accel_map_file);
+ g_free (accel_map_file);
+}
+
+void
+ev_application_shutdown (EvApplication *application)
+{
+ if (application->uri) {
+#ifdef ENABLE_DBUS
+ ev_application_unregister_uri (application,
+ application->uri);