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>
31 #include <libgnome/gnome-program.h>
32 #include <libgnomeui/gnome-ui-init.h>
33 #include <libgnomeui/gnome-app-helper.h>
34 #include <libgnomeui/gnome-authentication-manager.h>
35 #include <libgnomevfs/gnome-vfs-utils.h>
38 #include <dbus/dbus-glib-bindings.h>
41 #include "ev-stock-icons.h"
43 #include "ev-job-queue.h"
44 #include "ev-file-helpers.h"
46 static char *ev_page_label;
48 static struct poptOption popt_options[] =
50 { "page-label", 'p', POPT_ARG_STRING, &ev_page_label, 0, N_("The page of the document to display."), N_("PAGE")},
51 { NULL, 0, 0, NULL, 0, NULL, NULL }
55 load_files (const char **files)
60 ev_application_open_window (EV_APP, GDK_CURRENT_TIME, NULL);
64 for (i = 0; files[i]; i++) {
67 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
68 ev_application_open_uri (EV_APP, uri, ev_page_label,
69 GDK_CURRENT_TIME, NULL);
77 load_files_remote (const char **files)
81 DBusGConnection *connection;
82 gboolean result = FALSE;
84 DBusGPendingCall *call;
86 DBusGProxy *remote_object;
90 display = gdk_display_get_default();
91 timestamp = gdk_x11_display_get_user_time (display);
92 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
94 if (connection == NULL) {
95 g_warning (error->message);
101 remote_object = dbus_g_proxy_new_for_name (connection,
102 "org.gnome.evince.ApplicationService",
103 "/org/gnome/evince/Evince",
104 "org.gnome.evince.Application");
106 #if DBUS_VERSION <= 33
107 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
108 DBUS_TYPE_UINT32, ×tamp,
111 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
112 g_warning (error->message);
113 g_clear_error (&error);
114 g_object_unref (remote_object);
115 dbus_g_connection_unref (connection);
118 #elif DBUS_VERSION == 34
119 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
120 G_TYPE_UINT, timestamp,
123 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
124 g_warning (error->message);
125 g_clear_error (&error);
126 g_object_unref (remote_object);
127 dbus_g_connection_unref (connection);
131 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
132 G_TYPE_UINT, timestamp,
135 g_warning (error->message);
136 g_clear_error (&error);
137 g_object_unref (remote_object);
138 dbus_g_connection_unref (connection);
142 g_object_unref (remote_object);
143 dbus_g_connection_unref (connection);
148 for (i = 0; files[i]; i++) {
149 const char *page_label;
152 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
153 page_label = ev_page_label ? ev_page_label : "";
154 #if DBUS_VERSION <= 33
155 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
156 DBUS_TYPE_STRING, &uri,
157 DBUS_TYPE_STRING, &page_label,
158 DBUS_TYPE_UINT32, ×tamp,
161 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
162 g_warning (error->message);
163 g_clear_error (&error);
167 #elif DBUS_VERSION == 34
168 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
170 G_TYPE_STRING, page_label,
171 G_TYPE_UINT, timestamp,
174 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
175 g_warning (error->message);
176 g_clear_error (&error);
181 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
183 G_TYPE_STRING, page_label,
184 G_TYPE_UINT, timestamp,
187 g_warning (error->message);
188 g_clear_error (&error);
197 g_object_unref (remote_object);
198 dbus_g_connection_unref (connection);
200 gdk_notify_startup_complete ();
204 #endif /* ENABLE_DBUS */
207 main (int argc, char *argv[])
209 gboolean enable_metadata = FALSE;
211 GValue context_as_value = { 0 };
212 GnomeProgram *program;
215 /* Initialize the i18n stuff */
216 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
217 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
218 textdomain(GETTEXT_PACKAGE);
221 program = gnome_program_init (PACKAGE, VERSION,
222 LIBGNOMEUI_MODULE, argc, argv,
223 GNOME_PARAM_POPT_TABLE, popt_options,
224 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
225 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
227 g_object_get_property (G_OBJECT (program),
228 GNOME_PARAM_POPT_CONTEXT,
229 g_value_init (&context_as_value, G_TYPE_POINTER));
230 context = g_value_get_pointer (&context_as_value);
234 if (!ev_application_register_service (EV_APP)) {
235 if (load_files_remote (poptGetArgs (context))) {
239 enable_metadata = TRUE;
243 gnome_authentication_manager_init ();
246 if (enable_metadata) {
247 ev_metadata_manager_init ();
250 ev_job_queue_init ();
251 g_set_application_name (_("Evince Document Viewer"));
253 ev_file_helpers_init ();
255 ev_stock_icons_init ();
256 gtk_window_set_default_icon_name ("evince");
258 load_files (poptGetArgs (context));
262 gnome_accelerators_sync ();
263 poptFreeContext (context);
264 ev_file_helpers_shutdown ();
266 if (enable_metadata) {
267 ev_metadata_manager_shutdown ();