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;
47 static char **file_arguments = NULL;
49 static const GOptionEntry goption_options[] =
51 { "page-label", 'p', 0, G_OPTION_ARG_STRING, &ev_page_label, N_("The page of the document to display."), N_("PAGE")},
52 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, N_("[FILE...]") },
57 load_files (const char **files)
62 ev_application_open_window (EV_APP, GDK_CURRENT_TIME, NULL);
66 for (i = 0; files[i]; i++) {
69 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
70 ev_application_open_uri (EV_APP, uri, ev_page_label,
71 GDK_CURRENT_TIME, NULL);
79 load_files_remote (const char **files)
83 DBusGConnection *connection;
84 gboolean result = FALSE;
86 DBusGPendingCall *call;
88 DBusGProxy *remote_object;
92 display = gdk_display_get_default();
93 timestamp = gdk_x11_display_get_user_time (display);
94 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
96 if (connection == NULL) {
97 g_warning (error->message);
103 remote_object = dbus_g_proxy_new_for_name (connection,
104 "org.gnome.evince.ApplicationService",
105 "/org/gnome/evince/Evince",
106 "org.gnome.evince.Application");
108 #if DBUS_VERSION <= 33
109 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
110 DBUS_TYPE_UINT32, ×tamp,
113 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
114 g_warning (error->message);
115 g_clear_error (&error);
116 g_object_unref (remote_object);
117 dbus_g_connection_unref (connection);
120 #elif DBUS_VERSION == 34
121 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
122 G_TYPE_UINT, timestamp,
125 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
126 g_warning (error->message);
127 g_clear_error (&error);
128 g_object_unref (remote_object);
129 dbus_g_connection_unref (connection);
133 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
134 G_TYPE_UINT, timestamp,
137 g_warning (error->message);
138 g_clear_error (&error);
139 g_object_unref (remote_object);
140 dbus_g_connection_unref (connection);
144 g_object_unref (remote_object);
145 dbus_g_connection_unref (connection);
150 for (i = 0; files[i]; i++) {
151 const char *page_label;
154 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
155 page_label = ev_page_label ? ev_page_label : "";
156 #if DBUS_VERSION <= 33
157 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
158 DBUS_TYPE_STRING, &uri,
159 DBUS_TYPE_STRING, &page_label,
160 DBUS_TYPE_UINT32, ×tamp,
163 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
164 g_warning (error->message);
165 g_clear_error (&error);
169 #elif DBUS_VERSION == 34
170 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
172 G_TYPE_STRING, page_label,
173 G_TYPE_UINT, timestamp,
176 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
177 g_warning (error->message);
178 g_clear_error (&error);
183 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
185 G_TYPE_STRING, page_label,
186 G_TYPE_UINT, timestamp,
189 g_warning (error->message);
190 g_clear_error (&error);
199 g_object_unref (remote_object);
200 dbus_g_connection_unref (connection);
202 gdk_notify_startup_complete ();
206 #endif /* ENABLE_DBUS */
209 main (int argc, char *argv[])
211 gboolean enable_metadata = FALSE;
212 GOptionContext *context;
213 GnomeProgram *program;
215 context = g_option_context_new (_("GNOME Document Viewer"));
218 /* Initialize the i18n stuff */
219 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
220 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
221 textdomain(GETTEXT_PACKAGE);
222 g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
224 g_option_context_add_main_entries (context, goption_options, NULL);
227 program = gnome_program_init (PACKAGE, VERSION,
228 LIBGNOMEUI_MODULE, argc, argv,
229 GNOME_PARAM_GOPTION_CONTEXT, context,
230 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
231 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
235 if (!ev_application_register_service (EV_APP)) {
236 if (load_files_remote (file_arguments)) {
240 enable_metadata = TRUE;
244 gnome_authentication_manager_init ();
247 if (enable_metadata) {
248 ev_metadata_manager_init ();
251 ev_job_queue_init ();
252 g_set_application_name (_("Evince Document Viewer"));
254 ev_file_helpers_init ();
256 ev_stock_icons_init ();
257 gtk_window_set_default_icon_name ("evince");
259 load_files (file_arguments);
263 gnome_accelerators_sync ();
264 ev_file_helpers_shutdown ();
266 if (enable_metadata) {
267 ev_metadata_manager_shutdown ();
269 g_object_unref(program);