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>
28 #include <gtk/gtkmain.h>
29 #include <libgnome/gnome-program.h>
30 #include <libgnomeui/gnome-ui-init.h>
31 #include <libgnomeui/gnome-app-helper.h>
32 #include <libgnomeui/gnome-authentication-manager.h>
33 #include <libgnomevfs/gnome-vfs-utils.h>
36 #include <dbus/dbus-glib-bindings.h>
39 #include "ev-stock-icons.h"
41 #include "ev-job-queue.h"
42 #include "ev-file-helpers.h"
44 static char *ev_page_label;
46 static struct poptOption popt_options[] =
48 { "page-label", 'p', POPT_ARG_STRING, &ev_page_label, 0, N_("The page of the document to display."), N_("PAGE")},
49 { NULL, 0, 0, NULL, 0, NULL, NULL }
53 load_files (const char **files)
58 ev_application_open_window (EV_APP, GDK_CURRENT_TIME, NULL);
62 for (i = 0; files[i]; i++) {
65 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
66 ev_application_open_uri (EV_APP, uri, ev_page_label,
67 GDK_CURRENT_TIME, NULL);
74 load_files_remote (const char **files)
78 DBusGConnection *connection;
79 gboolean result = FALSE;
81 DBusGPendingCall *call;
83 DBusGProxy *remote_object;
87 display = gdk_display_get_default();
88 timestamp = gdk_x11_display_get_user_time (display);
90 connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
91 if (connection == NULL) {
92 g_warning (error->message);
98 remote_object = dbus_g_proxy_new_for_name (connection,
99 "org.gnome.evince.ApplicationService",
100 "/org/gnome/evince/Evince",
101 "org.gnome.evince.Application");
103 #if DBUS_VERSION <= 33
104 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
105 DBUS_TYPE_UINT32, timestamp,
108 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
109 g_warning (error->message);
110 g_clear_error (&error);
113 #elif DBUS_VERSION == 34
114 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
115 G_TYPE_UINT, timestamp,
118 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
119 g_warning (error->message);
120 g_clear_error (&error);
124 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
125 G_TYPE_UINT, timestamp,
128 g_warning (error->message);
129 g_clear_error (&error);
136 for (i = 0; files[i]; i++) {
137 const char *page_label;
140 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
141 page_label = ev_page_label ? ev_page_label : "";
142 #if DBUS_VERSION <= 33
143 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
144 DBUS_TYPE_STRING, &uri,
145 DBUS_TYPE_STRING, &page_label,
146 DBUS_TYPE_UINT32, timestamp,
149 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
150 g_warning (error->message);
151 g_clear_error (&error);
155 #elif DBUS_VERSION == 34
156 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
158 G_TYPE_STRING, page_label,
159 G_TYPE_UINT, timestamp,
162 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
163 g_warning (error->message);
164 g_clear_error (&error);
169 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
171 G_TYPE_STRING, page_label,
172 G_TYPE_UINT, timestamp,
175 g_warning (error->message);
176 g_clear_error (&error);
185 gdk_notify_startup_complete ();
189 #endif /* ENABLE_DBUS */
192 main (int argc, char *argv[])
194 gboolean enable_metadata = FALSE;
196 GValue context_as_value = { 0 };
197 GnomeProgram *program;
200 /* Initialize the i18n stuff */
201 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
202 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
203 textdomain(GETTEXT_PACKAGE);
206 program = gnome_program_init (PACKAGE, VERSION,
207 LIBGNOMEUI_MODULE, argc, argv,
208 GNOME_PARAM_POPT_TABLE, popt_options,
209 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
210 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
212 g_object_get_property (G_OBJECT (program),
213 GNOME_PARAM_POPT_CONTEXT,
214 g_value_init (&context_as_value, G_TYPE_POINTER));
215 context = g_value_get_pointer (&context_as_value);
219 if (!ev_application_register_service (EV_APP)) {
220 if (load_files_remote (poptGetArgs (context))) {
224 enable_metadata = TRUE;
228 gnome_authentication_manager_init ();
231 if (enable_metadata) {
232 ev_metadata_manager_init ();
235 ev_job_queue_init ();
236 g_set_application_name (_("Evince Document Viewer"));
238 ev_file_helpers_init ();
240 ev_stock_icons_init ();
241 gtk_window_set_default_icon_name ("postscript-viewer");
243 load_files (poptGetArgs (context));
247 gnome_accelerators_sync ();
248 poptFreeContext (context);
249 ev_file_helpers_shutdown ();
251 if (enable_metadata) {
252 ev_metadata_manager_shutdown ();