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 const 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++) {
70 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
72 label = strchr (uri, GNOME_VFS_URI_MAGIC_CHR);
76 ev_application_open_uri (EV_APP, uri, label,
77 GDK_CURRENT_TIME, NULL);
79 ev_application_open_uri (EV_APP, uri, ev_page_label,
80 GDK_CURRENT_TIME, NULL);
89 load_files_remote (const char **files)
93 DBusGConnection *connection;
94 gboolean result = FALSE;
96 DBusGPendingCall *call;
98 DBusGProxy *remote_object;
102 display = gdk_display_get_default();
103 timestamp = gdk_x11_display_get_user_time (display);
104 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error);
106 if (connection == NULL) {
107 g_warning (error->message);
108 g_error_free (error);
113 remote_object = dbus_g_proxy_new_for_name (connection,
114 "org.gnome.evince.ApplicationService",
115 "/org/gnome/evince/Evince",
116 "org.gnome.evince.Application");
118 #if DBUS_VERSION <= 33
119 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
120 DBUS_TYPE_UINT32, ×tamp,
123 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
124 g_warning (error->message);
125 g_clear_error (&error);
126 g_object_unref (remote_object);
127 dbus_g_connection_unref (connection);
130 #elif DBUS_VERSION == 34
131 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow",
132 G_TYPE_UINT, timestamp,
135 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
136 g_warning (error->message);
137 g_clear_error (&error);
138 g_object_unref (remote_object);
139 dbus_g_connection_unref (connection);
143 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error,
144 G_TYPE_UINT, timestamp,
147 g_warning (error->message);
148 g_clear_error (&error);
149 g_object_unref (remote_object);
150 dbus_g_connection_unref (connection);
154 g_object_unref (remote_object);
155 dbus_g_connection_unref (connection);
160 for (i = 0; files[i]; i++) {
161 const char *page_label;
164 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
165 page_label = ev_page_label ? ev_page_label : "";
166 #if DBUS_VERSION <= 33
167 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
168 DBUS_TYPE_STRING, &uri,
169 DBUS_TYPE_STRING, &page_label,
170 DBUS_TYPE_UINT32, ×tamp,
173 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
174 g_warning (error->message);
175 g_clear_error (&error);
179 #elif DBUS_VERSION == 34
180 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
182 G_TYPE_STRING, page_label,
183 G_TYPE_UINT, timestamp,
186 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
187 g_warning (error->message);
188 g_clear_error (&error);
193 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
195 G_TYPE_STRING, page_label,
196 G_TYPE_UINT, timestamp,
199 g_warning (error->message);
200 g_clear_error (&error);
209 g_object_unref (remote_object);
210 dbus_g_connection_unref (connection);
212 gdk_notify_startup_complete ();
216 #endif /* ENABLE_DBUS */
219 main (int argc, char *argv[])
221 gboolean enable_metadata = FALSE;
222 GOptionContext *context;
223 GnomeProgram *program;
225 context = g_option_context_new (_("GNOME Document Viewer"));
228 /* Initialize the i18n stuff */
229 bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
230 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
231 textdomain(GETTEXT_PACKAGE);
232 g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
234 g_option_context_add_main_entries (context, goption_options, NULL);
237 program = gnome_program_init (PACKAGE, VERSION,
238 LIBGNOMEUI_MODULE, argc, argv,
239 GNOME_PARAM_GOPTION_CONTEXT, context,
240 GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
241 GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
245 if (!ev_application_register_service (EV_APP)) {
246 if (load_files_remote (file_arguments)) {
250 enable_metadata = TRUE;
255 gnome_authentication_manager_init ();
257 if (enable_metadata) {
258 ev_metadata_manager_init ();
261 ev_job_queue_init ();
262 g_set_application_name (_("Evince Document Viewer"));
264 ev_file_helpers_init ();
266 ev_stock_icons_init ();
267 gtk_window_set_default_icon_name ("evince");
269 load_files (file_arguments);
273 gnome_accelerators_sync ();
274 ev_file_helpers_shutdown ();
276 if (enable_metadata) {
277 ev_metadata_manager_shutdown ();
279 g_object_unref(program);