]> www.fi.muni.cz Git - evince.git/blob - shell/main.c
Ever build metadata manager since it's just disabled at runtime now.
[evince.git] / shell / main.c
1 /*
2  *  Copyright (C) 2004 Marco Pesenti Gritti
3  *
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)
7  *  any later version.
8  *
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.
13  *
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.
17  *
18  *  $Id$
19  */
20
21 #include "config.h"
22
23 #include "ev-application.h"
24 #include "ev-metadata-manager.h"
25
26 #include <glib/gi18n.h>
27 #include <gtk/gtkmain.h>
28 #include <libgnome/gnome-program.h>
29 #include <libgnomeui/gnome-ui-init.h>
30 #include <libgnomeui/gnome-app-helper.h>
31 #include <libgnomeui/gnome-authentication-manager.h>
32 #include <libgnomevfs/gnome-vfs-utils.h>
33
34 #ifdef ENABLE_DBUS
35 #include <dbus/dbus-glib-bindings.h>
36 #endif
37
38 #include "ev-stock-icons.h"
39 #include "ev-debug.h"
40 #include "ev-job-queue.h"
41 #include "ev-file-helpers.h"
42
43 static char *ev_page_label;
44
45 static struct poptOption popt_options[] =
46 {
47         { "page-label", 'p', POPT_ARG_STRING, &ev_page_label, 0, N_("The page of the document to display."), N_("PAGE")},
48         { NULL, 0, 0, NULL, 0, NULL, NULL }
49 };
50
51 static void
52 load_files (const char **files)
53 {
54         int i;
55
56         if (!files) {
57                 ev_application_open_window (EV_APP, NULL);
58                 return;
59         }
60
61         for (i = 0; files[i]; i++) {
62                 char *uri;
63
64                 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
65                 ev_application_open_uri (EV_APP, uri, ev_page_label, NULL);             
66                 g_free (uri);
67         }
68 }
69
70 #ifdef ENABLE_DBUS
71 static gboolean
72 load_files_remote (const char **files)
73 {
74         int i;
75         GError *error = NULL;
76         DBusGConnection *connection;
77 #if DBUS_VERSION < 35
78         DBusGPendingCall *call;
79 #endif
80         DBusGProxy *remote_object;
81
82         connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
83         if (connection == NULL) {
84                 g_warning (error->message);
85                 g_error_free (error);   
86
87                 return FALSE;
88         }
89
90         remote_object = dbus_g_proxy_new_for_name (connection,
91                                                    "org.gnome.evince.ApplicationService",
92                                                    "/org/gnome/evince/Evince",
93                                                    "org.gnome.evince.Application");
94         if (!files) {
95 #if DBUS_VERSION < 35
96                 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow", G_TYPE_INVALID);
97
98                 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
99                         g_warning (error->message);
100                         g_clear_error (&error);
101                         return FALSE;
102                 }
103 #else
104                 if (!dbus_g_proxy_call (remote_object, "OpenWindow", &error, G_TYPE_INVALID)) {
105                         g_warning (error->message);
106                         g_clear_error (&error);
107                         return FALSE;
108                 }
109 #endif
110                 return TRUE;
111         }
112
113         for (i = 0; files[i]; i++) {
114                 gboolean result = TRUE;
115                 const char *page_label;
116                 char *uri;
117
118                 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
119                 page_label = ev_page_label ? ev_page_label : ""; 
120 #if DBUS_VERSION < 35
121                 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
122                                                 G_TYPE_STRING, uri,
123                                                 G_TYPE_STRING, page_label,
124                                                 G_TYPE_INVALID);
125
126                 if (!dbus_g_proxy_end_call (remote_object, call, &error, G_TYPE_INVALID)) {
127                         g_warning (error->message);
128                         g_clear_error (&error);
129                         result = FALSE;
130                 }
131 #else
132                 if (!dbus_g_proxy_call (remote_object, "OpenURI", &error,
133                                         G_TYPE_STRING, uri,
134                                         G_TYPE_STRING, page_label,
135                                         G_TYPE_INVALID)) {
136                         g_warning (error->message);
137                         g_clear_error (&error);
138                         result = FALSE;
139                 }
140 #endif
141                 g_free (uri);
142                 return result;
143         }
144
145         return TRUE;
146 }
147 #endif /* ENABLE_DBUS */
148
149 int
150 main (int argc, char *argv[])
151 {
152         gboolean enable_metadata = FALSE;
153         poptContext context;
154         GValue context_as_value = { 0 };
155         GnomeProgram *program;
156
157 #ifdef ENABLE_NLS
158         /* Initialize the i18n stuff */
159         bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
160         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
161         textdomain(GETTEXT_PACKAGE);
162 #endif
163
164         program = gnome_program_init (PACKAGE, VERSION,
165                                       LIBGNOMEUI_MODULE, argc, argv,
166                                       GNOME_PARAM_POPT_TABLE, popt_options,
167                                       GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
168                                       GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
169                                       NULL);
170         g_object_get_property (G_OBJECT (program),
171                                GNOME_PARAM_POPT_CONTEXT,
172                                g_value_init (&context_as_value, G_TYPE_POINTER));
173         context = g_value_get_pointer (&context_as_value);
174
175
176 #ifdef ENABLE_DBUS
177         if (!ev_application_register_service (EV_APP)) {
178                 if (load_files_remote (poptGetArgs (context))) {
179                         g_warning ("Another process was running.");
180                         return 0;
181                 }
182         } else {
183                 g_warning ("Starting evince process.");
184                 enable_metadata = TRUE;
185         }
186 #endif
187
188         gnome_authentication_manager_init ();
189
190
191         if (enable_metadata) {
192                 ev_metadata_manager_init ();
193         }
194
195         ev_job_queue_init ();
196         g_set_application_name (_("Evince Document Viewer"));
197
198         ev_file_helpers_init ();
199         ev_debug_init ();
200         ev_stock_icons_init ();
201         gtk_window_set_default_icon_name ("postscript-viewer");
202
203         load_files (poptGetArgs (context));
204
205         gtk_main ();
206
207         gnome_accelerators_sync ();
208         poptFreeContext (context);
209         ev_file_helpers_shutdown ();
210
211         if (enable_metadata) {
212                 ev_metadata_manager_shutdown ();
213         }
214
215         return 0;
216 }