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 gchar *ev_page_label;
47 static gboolean preview_mode = FALSE;
48 static gboolean fullscren_mode = FALSE;
49 static gboolean presentation_mode = FALSE;
50 static gboolean unlink_temp_file = FALSE;
51 static const char **file_arguments = NULL;
53 static const GOptionEntry goption_options[] =
55 { "page-label", 'p', 0, G_OPTION_ARG_STRING, &ev_page_label, N_("The page of the document to display."), N_("PAGE")},
56 { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscren_mode, N_("Run evince in fullscreen mode"), NULL },
57 { "presentation", 's', 0, G_OPTION_ARG_NONE, &presentation_mode, N_("Run evince in presentation mode"), NULL },
58 { "preview", 'w', 0, G_OPTION_ARG_NONE, &preview_mode, N_("Run evince as a previewer"), NULL },
59 { "unlink-temp-file", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &unlink_temp_file, NULL, NULL },
60 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, N_("[FILE...]") },
65 value_free (GValue *value)
67 g_value_unset (value);
72 arguments_parse (void)
79 const gchar *display_name;
82 args = g_hash_table_new_full (g_str_hash,
84 (GDestroyNotify)g_free,
85 (GDestroyNotify)value_free);
87 screen = gdk_screen_get_default ();
88 display = gdk_screen_get_display (screen);
90 display_name = gdk_display_get_name (display);
91 screen_number = gdk_screen_get_number (screen);
93 value = g_new0 (GValue, 1);
94 g_value_init (value, G_TYPE_STRING);
95 g_value_set_string (value, display_name);
96 g_hash_table_insert (args, g_strdup ("display"), value);
98 value = g_new0 (GValue, 1);
99 g_value_init (value, G_TYPE_INT);
100 g_value_set_int (value, screen_number);
101 g_hash_table_insert (args, g_strdup ("screen"), value);
104 value = g_new0 (GValue, 1);
105 g_value_init (value, G_TYPE_STRING);
106 g_value_set_string (value, ev_page_label);
108 g_hash_table_insert (args, g_strdup ("page-label"), value);
112 mode = EV_WINDOW_MODE_FULLSCREEN;
113 else if (presentation_mode)
114 mode = EV_WINDOW_MODE_PRESENTATION;
115 else if (preview_mode)
116 mode = EV_WINDOW_MODE_PREVIEW;
120 value = g_new0 (GValue, 1);
121 g_value_init (value, G_TYPE_UINT);
122 g_value_set_uint (value, mode);
124 g_hash_table_insert (args, g_strdup ("mode"), value);
126 if (mode == EV_WINDOW_MODE_PREVIEW && unlink_temp_file) {
127 value = g_new0 (GValue, 1);
128 g_value_init (value, G_TYPE_BOOLEAN);
129 g_value_set_boolean (value, unlink_temp_file);
131 g_hash_table_insert (args,
132 g_strdup ("unlink-temp-file"),
140 load_files (const char **files,
146 ev_application_open_window (EV_APP, args, GDK_CURRENT_TIME, NULL);
150 for (i = 0; files[i]; i++) {
155 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
157 label = strchr (uri, GNOME_VFS_URI_MAGIC_CHR);
164 old = g_hash_table_lookup (args, "page-label");
166 new = g_new0 (GValue, 1);
167 g_value_init (new, G_TYPE_STRING);
168 g_value_set_string (new, label);
170 g_hash_table_insert (args, g_strdup ("page-label"), new);
174 ev_application_open_uri (EV_APP, uri, args,
175 GDK_CURRENT_TIME, NULL);
178 g_hash_table_insert (args, g_strdup ("page-label"), old);
187 load_files_remote (const char **files,
191 GError *error = NULL;
192 DBusGConnection *connection;
193 gboolean result = FALSE;
194 #if DBUS_VERSION < 35
195 DBusGPendingCall *call;
197 DBusGProxy *remote_object;
201 display = gdk_display_get_default ();
202 timestamp = gdk_x11_display_get_user_time (display);
203 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
205 if (connection == NULL) {
206 g_warning (error->message);
207 g_error_free (error);
212 remote_object = dbus_g_proxy_new_for_name (connection,
213 "org.gnome.evince.ApplicationService",
214 "/org/gnome/evince/Evince",
215 "org.gnome.evince.Application");
217 #if DBUS_VERSION <= 33
218 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
219 DBUS_TYPE_UINT32, ×tamp,
222 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
223 g_warning (error->message);
224 g_clear_error (&error);
225 g_object_unref (remote_object);
226 dbus_g_connection_unref (connection);
229 #elif DBUS_VERSION == 34
230 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
231 G_TYPE_UINT, timestamp,
234 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
235 g_warning (error->message);
236 g_clear_error (&error);
237 g_object_unref (remote_object);
238 dbus_g_connection_unref (connection);
242 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
243 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), args,
244 G_TYPE_UINT, timestamp,
247 g_warning (error->message);
248 g_clear_error (&error);
249 g_object_unref (remote_object);
250 dbus_g_connection_unref (connection);
254 g_object_unref (remote_object);
255 dbus_g_connection_unref (connection);
260 for (i = 0; files[i]; i++) {
261 const char *page_label;
264 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
265 page_label = ev_page_label ? ev_page_label : "";
266 #if DBUS_VERSION <= 33
267 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
268 DBUS_TYPE_STRING, &uri,
269 DBUS_TYPE_STRING, &page_label,
270 DBUS_TYPE_UINT32, ×tamp,
273 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
274 g_warning (error->message);
275 g_clear_error (&error);
279 #elif DBUS_VERSION == 34
280 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
282 G_TYPE_STRING, page_label,
283 G_TYPE_UINT, timestamp,
286 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
287 g_warning (error->message);
288 g_clear_error (&error);
293 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
295 dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), args,
296 G_TYPE_UINT, timestamp,
299 g_warning (error->message);
300 g_clear_error (&error);
309 g_object_unref (remote_object);
310 dbus_g_connection_unref (connection);
312 gdk_notify_startup_complete ();
316 #endif /* ENABLE_DBUS */
319 main (int argc, char *argv[])
321 gboolean enable_metadata = FALSE;
322 GOptionContext *context;
324 GnomeProgram *program;
326 context = g_option_context_new (_("GNOME Document Viewer"));
329 /* Initialize the i18n stuff */
330 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
331 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
332 textdomain(GETTEXT_PACKAGE);
333 g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
335 g_option_context_add_main_entries (context, goption_options, NULL);
338 program = gnome_program_init (PACKAGE, VERSION,
339 LIBGNOMEUI_MODULE, argc, argv,
340 GNOME_PARAM_GOPTION_CONTEXT, context,
341 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
342 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
345 args = arguments_parse ();
348 if (!ev_application_register_service (EV_APP)) {
349 if (load_files_remote (file_arguments, args)) {
350 g_hash_table_destroy (args);
351 g_object_unref (program);
356 enable_metadata = TRUE;
361 gnome_authentication_manager_init ();
363 if (enable_metadata) {
364 ev_metadata_manager_init ();
367 ev_job_queue_init ();
368 g_set_application_name (_("Evince Document Viewer"));
370 ev_file_helpers_init ();
372 ev_stock_icons_init ();
373 gtk_window_set_default_icon_name ("evince");
375 load_files (file_arguments, args);
376 g_hash_table_destroy (args);
380 gnome_accelerators_sync ();
381 ev_file_helpers_shutdown ();
383 if (enable_metadata) {
384 ev_metadata_manager_shutdown ();
386 g_object_unref (program);