]> www.fi.muni.cz Git - evince.git/blob - shell/main.c
Metadata manager from gedit but modified to use GValue, so that we dont
[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 <libgnomevfs/gnome-vfs-utils.h>
32
33 #ifdef ENABLE_DBUS
34 #include <dbus/dbus-glib-bindings.h>
35 #endif
36
37 #include "ev-stock-icons.h"
38 #include "ev-debug.h"
39 #include "ev-job-queue.h"
40 #include "ev-file-helpers.h"
41
42 static char *ev_page_label;
43
44 static struct poptOption popt_options[] =
45 {
46         { "page-label", 'p', POPT_ARG_STRING, &ev_page_label, 0, N_("The page of the document to display."), N_("PAGE")},
47         { NULL, 0, 0, NULL, 0, NULL, NULL }
48 };
49
50 static void
51 load_files (const char **files)
52 {
53         int i;
54
55         if (!files) {
56                 ev_application_open_window (EV_APP);
57                 return;
58         }
59
60         for (i = 0; files[i]; i++) {
61                 char *uri;
62
63                 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
64                 ev_application_open_uri (EV_APP, uri, ev_page_label);           
65                 g_free (uri);
66         }
67 }
68
69 #ifdef ENABLE_DBUS
70 static void
71 load_files_remote (const char **files)
72 {
73         int i;
74         GError *error;
75         DBusGConnection *connection;
76         DBusGPendingCall *call;
77         DBusGProxy *remote_object;
78
79         connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
80         if (connection == NULL) {
81                 g_warning (error->message);
82                 return;
83         }
84
85         remote_object = dbus_g_proxy_new_for_name (connection,
86                                                    "org.gnome.evince.ApplicationService",
87                                                    "/org/gnome/evince/Evince",
88                                                    "org.gnome.evince.Application");
89         if (!files) {
90                 call = dbus_g_proxy_begin_call (remote_object, "OpenWindow", DBUS_TYPE_INVALID);
91                 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
92                         g_warning (error->message);
93                 }
94                 return;
95         }
96
97         for (i = 0; files[i]; i++) {
98                 const char *page_label;
99                 char *uri;
100
101                 uri = gnome_vfs_make_uri_from_shell_arg (files[i]);
102                 page_label = ev_page_label ? ev_page_label : ""; 
103
104                 call = dbus_g_proxy_begin_call (remote_object, "OpenURI",
105                                                 DBUS_TYPE_STRING, &uri,
106                                                 DBUS_TYPE_STRING, &page_label,
107                                                 DBUS_TYPE_INVALID);
108                 if (!dbus_g_proxy_end_call (remote_object, call, &error, DBUS_TYPE_INVALID)) {
109                         g_warning (error->message);
110                 }
111                 
112                 g_free (uri);
113         }
114 }
115 #endif
116
117 int
118 main (int argc, char *argv[])
119 {
120         poptContext context;
121         GValue context_as_value = { 0 };
122         GnomeProgram *program;
123
124 #ifdef ENABLE_NLS
125         /* Initialize the i18n stuff */
126         bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
127         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
128         textdomain(GETTEXT_PACKAGE);
129 #endif
130
131         program = gnome_program_init (PACKAGE, VERSION,
132                                       LIBGNOMEUI_MODULE, argc, argv,
133                                       GNOME_PARAM_POPT_TABLE, popt_options,
134                                       GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"),
135                                       GNOME_PARAM_APP_DATADIR, GNOMEDATADIR,
136                                       NULL);
137         g_object_get_property (G_OBJECT (program),
138                                GNOME_PARAM_POPT_CONTEXT,
139                                g_value_init (&context_as_value, G_TYPE_POINTER));
140         context = g_value_get_pointer (&context_as_value);
141
142
143 #ifdef ENABLE_DBUS
144         if (!ev_application_register_service (EV_APP)) {
145                 load_files_remote (poptGetArgs (context));
146                 g_warning ("Another process was running.");
147                 return 0;
148         } else {
149                 g_warning ("Starting evince process.");
150         }
151 #endif
152
153         ev_job_queue_init ();
154         g_set_application_name (_("Evince Document Viewer"));
155
156         ev_file_helpers_init ();
157         ev_debug_init ();
158         ev_stock_icons_init ();
159         gtk_window_set_default_icon_name ("postscript-viewer");
160
161         load_files (poptGetArgs (context));
162
163         gtk_main ();
164
165         gnome_accelerators_sync ();
166         poptFreeContext (context);
167         ev_file_helpers_shutdown ();
168 #if ENABLE_METADATA
169         ev_metadata_manager_shutdown ();
170 #endif
171
172         return 0;
173 }