1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2004 Martin Kretzschmar
6 * Martin Kretzschmar <martink@gnome.org>
8 * Evince is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Evince is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
27 #include "ev-application.h"
29 #include "ev-document-types.h"
32 #include <glib/gi18n.h>
33 #include <glib-object.h>
34 #include <gtk/gtkfilechooserdialog.h>
35 #include <gtk/gtkstock.h>
36 #include <gtk/gtkwidget.h>
37 #include <gtk/gtkmain.h>
41 #include "ev-application-service.h"
42 #include <dbus/dbus-glib-bindings.h>
45 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
47 #define EV_APPLICATION_GET_PRIVATE(object) \
48 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_APPLICATION, EvApplicationPrivate))
50 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
54 ev_application_register_service (EvApplication *application)
56 DBusGConnection *connection;
57 DBusGProxy *driver_proxy;
59 guint request_name_result;
61 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
62 if (connection == NULL) {
63 g_warning ("Service registration failed.");
66 driver_proxy = dbus_g_proxy_new_for_name (connection,
71 if (!org_freedesktop_DBus_request_name (driver_proxy,
72 APPLICATION_SERVICE_NAME,
73 0, &request_name_result, &err))
75 g_warning ("Service registration failed.");
78 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
82 dbus_g_object_class_install_info (G_OBJECT_GET_CLASS (application),
83 &dbus_glib_ev_application_object_info);
84 dbus_g_connection_register_g_object (connection,
85 "/org/gnome/evince/Evince",
86 G_OBJECT (application));
93 ev_application_get_instance (void)
95 static EvApplication *instance;
98 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
105 ev_application_open_window (EvApplication *application)
107 gtk_widget_show (ev_window_new ());
111 ev_application_get_empty_window (EvApplication *application)
113 EvWindow *empty_window = NULL;
114 GList *windows = gtk_window_list_toplevels ();
117 for (l = windows; l != NULL; l = l->next) {
118 if (EV_IS_WINDOW (l->data)) {
119 EvWindow *window = EV_WINDOW (l->data);
121 if (ev_window_is_empty (window)) {
122 empty_window = window;
128 g_list_free (windows);
134 ev_application_get_uri_window (EvApplication *application, const char *uri)
136 EvWindow *uri_window = NULL;
137 GList *windows = gtk_window_list_toplevels ();
140 g_return_val_if_fail (uri != NULL, NULL);
142 for (l = windows; l != NULL; l = l->next) {
143 if (EV_IS_WINDOW (l->data)) {
144 EvWindow *window = EV_WINDOW (l->data);
145 const char *window_uri = ev_window_get_uri (window);
147 if (window_uri && strcmp (window_uri, uri) == 0) {
154 g_list_free (windows);
160 ev_application_open_uri (EvApplication *application,
162 const char *page_label)
164 EvWindow *new_window;
166 g_return_if_fail (uri != NULL);
168 new_window = ev_application_get_uri_window (application, uri);
169 if (new_window != NULL) {
170 gtk_window_present (GTK_WINDOW (new_window));
174 new_window = ev_application_get_empty_window (application);
176 if (new_window == NULL) {
177 new_window = EV_WINDOW (ev_window_new ());
180 gtk_window_present (GTK_WINDOW (new_window));
182 ev_window_open_uri (new_window, uri);
184 if (page_label != NULL) {
185 ev_window_open_page_label (new_window, page_label);
190 ev_application_open_uri_list (EvApplication *application, GSList *uri_list)
194 for (l = uri_list; l != NULL; l = l->next) {
195 ev_application_open_uri (application, (char *)l->data, NULL);
200 ev_application_shutdown (EvApplication *application)
202 g_object_unref (application);
207 ev_application_class_init (EvApplicationClass *ev_application_class)
212 ev_application_init (EvApplication *ev_application)