2 * Copyright (C) 2004 Marco Pesenti Gritti
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "ev-application.h"
24 #include "ev-metadata-manager.h"
26 #include <glib/gi18n.h>
27 #include <gtk/gtkmain.h>
28 #include <libgnome/gnome-program.h>
29 #include <libgnomeui/gnome-ui-init.h>
30 #include <libgnomeui/gnome-app-helper.h>
31 #include <libgnomeui/gnome-authentication-manager.h>
32 #include <libgnomevfs/gnome-vfs-utils.h>
35 #include <dbus/dbus-glib-bindings.h>
38 #include "ev-stock-icons.h"
40 #include "ev-job-queue.h"
41 #include "ev-file-helpers.h"
43 static char *ev_page_label;
45 static struct poptOption popt_options[] =
47 { "page-label", 'p', POPT_ARG_STRING, &ev_page_label, 0, N_("The page of the document to display."), N_("PAGE")},
48 { NULL, 0, 0, NULL, 0, NULL, NULL }
52 load_files (const char **files)
57 ev_application_open_window (EV_APP, NULL);
61 for (i = 0; files[i]; i++) {
64 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
65 ev_application_open_uri (EV_APP, uri, ev_page_label, NULL);
72 load_files_remote (const char **files)
76 DBusGConnection *connection;
77 gboolean result = FALSE;
79 DBusGPendingCall *call;
81 DBusGProxy *remote_object;
83 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
84 if (connection == NULL) {
85 g_warning (error->message);
91 remote_object = dbus_g_proxy_new_for_name (connection,
92 "org.gnome.evince.ApplicationService",
93 "/org/gnome/evince/Evince",
94 "org.gnome.evince.Application");
96 #if DBUS_VERSION <= 33
97 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow", DBUS_TYPE_INVALID);
99 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
100 g_warning (error->message);
101 g_clear_error (&error);
104 #elif DBUS_VERSION == 34
105 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow", G_TYPE_INVALID);
107 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
108 g_warning (error->message);
109 g_clear_error (&error);
113 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error, G_TYPE_INVALID)) {
114 g_warning (error->message);
115 g_clear_error (&error);
122 for (i = 0; files[i]; i++) {
123 const char *page_label;
126 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
127 page_label = ev_page_label ? ev_page_label : "";
128 #if DBUS_VERSION <= 33
129 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
130 DBUS_TYPE_STRING, &uri,
131 DBUS_TYPE_STRING, &page_label,
134 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
135 g_warning (error->message);
136 g_clear_error (&error);
140 #elif DBUS_VERSION == 34
141 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
143 G_TYPE_STRING, page_label,
146 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
147 g_warning (error->message);
148 g_clear_error (&error);
153 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
155 G_TYPE_STRING, page_label,
157 g_warning (error->message);
158 g_clear_error (&error);
169 #endif /* ENABLE_DBUS */
172 main (int argc, char *argv[])
174 gboolean enable_metadata = FALSE;
176 GValue context_as_value = { 0 };
177 GnomeProgram *program;
180 /* Initialize the i18n stuff */
181 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
182 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
183 textdomain(GETTEXT_PACKAGE);
186 program = gnome_program_init (PACKAGE, VERSION,
187 LIBGNOMEUI_MODULE, argc, argv,
188 GNOME_PARAM_POPT_TABLE, popt_options,
189 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
190 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
192 g_object_get_property (G_OBJECT (program),
193 GNOME_PARAM_POPT_CONTEXT,
194 g_value_init (&context_as_value, G_TYPE_POINTER));
195 context = g_value_get_pointer (&context_as_value);
199 if (!ev_application_register_service (EV_APP)) {
200 if (load_files_remote (poptGetArgs (context))) {
201 g_warning ("Another process was running.");
205 g_warning ("Starting evince process.");
206 enable_metadata = TRUE;
210 gnome_authentication_manager_init ();
213 if (enable_metadata) {
214 ev_metadata_manager_init ();
217 ev_job_queue_init ();
218 g_set_application_name (_("Evince Document Viewer"));
220 ev_file_helpers_init ();
222 ev_stock_icons_init ();
223 gtk_window_set_default_icon_name ("postscript-viewer");
225 load_files (poptGetArgs (context));
229 gnome_accelerators_sync ();
230 poptFreeContext (context);
231 ev_file_helpers_shutdown ();
233 if (enable_metadata) {
234 ev_metadata_manager_shutdown ();