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"
30 #include "ev-file-helpers.h"
33 #include <glib/gi18n.h>
34 #include <glib-object.h>
35 #include <gtk/gtkfilechooserdialog.h>
36 #include <gtk/gtkstock.h>
37 #include <gtk/gtkwidget.h>
38 #include <gtk/gtkmain.h>
42 #include "ev-application-service.h"
43 #include <dbus/dbus-glib-bindings.h>
46 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
48 #define EV_APPLICATION_GET_PRIVATE(object) \
49 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_APPLICATION, EvApplicationPrivate))
51 #define APPLICATION_SERVICE_NAME "org.gnome.evince.ApplicationService"
55 ev_application_register_service (EvApplication *application)
57 DBusGConnection *connection;
58 DBusGProxy *driver_proxy;
60 guint request_name_result;
62 connection = dbus_g_bus_get (DBUS_BUS_STARTER, &err);
63 if (connection == NULL) {
64 g_warning ("Service registration failed.");
70 driver_proxy = dbus_g_proxy_new_for_name (connection,
75 if (!org_freedesktop_DBus_request_name (driver_proxy,
76 APPLICATION_SERVICE_NAME,
77 0, &request_name_result, &err)) {
78 g_warning ("Service registration failed.");
82 if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) {
86 #if DBUS_VERSION == 33
87 dbus_g_object_class_install_info (G_OBJECT_GET_CLASS (application),
88 &dbus_glib_ev_application_object_info);
90 dbus_g_object_type_install_info (EV_TYPE_APPLICATION,
91 &dbus_glib_ev_application_object_info);
94 dbus_g_connection_register_g_object (connection,
95 "/org/gnome/evince/Evince",
96 G_OBJECT (application));
100 #endif /* ENABLE_DBUS */
103 ev_application_get_instance (void)
105 static EvApplication *instance;
108 instance = EV_APPLICATION (g_object_new (EV_TYPE_APPLICATION, NULL));
115 ev_application_open_window (EvApplication *application,
118 gtk_widget_show (ev_window_new ());
124 ev_application_get_empty_window (EvApplication *application)
126 EvWindow *empty_window = NULL;
127 GList *windows = gtk_window_list_toplevels ();
130 for (l = windows; l != NULL; l = l->next) {
131 if (EV_IS_WINDOW (l->data)) {
132 EvWindow *window = EV_WINDOW (l->data);
134 if (ev_window_is_empty (window)) {
135 empty_window = window;
141 g_list_free (windows);
147 ev_application_get_uri_window (EvApplication *application, const char *uri)
149 EvWindow *uri_window = NULL;
150 GList *windows = gtk_window_list_toplevels ();
153 g_return_val_if_fail (uri != NULL, NULL);
155 for (l = windows; l != NULL; l = l->next) {
156 if (EV_IS_WINDOW (l->data)) {
157 EvWindow *window = EV_WINDOW (l->data);
158 const char *window_uri = ev_window_get_uri (window);
160 if (window_uri && strcmp (window_uri, uri) == 0) {
167 g_list_free (windows);
173 ev_application_open_uri (EvApplication *application,
175 const char *page_label,
178 EvWindow *new_window;
180 g_return_val_if_fail (uri != NULL, FALSE);
182 new_window = ev_application_get_uri_window (application, uri);
183 if (new_window != NULL) {
184 gtk_window_present (GTK_WINDOW (new_window));
189 new_window = ev_application_get_empty_window (application);
191 if (new_window == NULL) {
192 new_window = EV_WINDOW (ev_window_new ());
195 ev_window_open_uri (new_window, uri);
197 gtk_window_present (GTK_WINDOW (new_window));
199 if (page_label != NULL) {
200 ev_window_open_page_label (new_window, page_label);
207 ev_application_open_uri_list (EvApplication *application, GSList *uri_list)
211 for (l = uri_list; l != NULL; l = l->next) {
212 ev_application_open_uri (application, (char *)l->data, NULL, NULL);
217 ev_application_shutdown (EvApplication *application)
219 if (application->toolbars_model) {
220 g_object_unref (application->toolbars_model);
221 g_free (application->toolbars_file);
222 application->toolbars_model = NULL;
223 application->toolbars_file = NULL;
226 if (application->recent_model) {
227 g_object_unref (application->recent_model);
228 application->recent_model = NULL;
231 g_object_unref (application);
236 ev_application_class_init (EvApplicationClass *ev_application_class)
241 ev_application_init (EvApplication *ev_application)
243 ev_application->toolbars_model = egg_toolbars_model_new ();
245 ev_application->toolbars_file = g_build_filename
246 (ev_dot_dir (), "evince_toolbar.xml", NULL);
248 if (!g_file_test (ev_application->toolbars_file, G_FILE_TEST_EXISTS)) {
249 egg_toolbars_model_load (ev_application->toolbars_model,
250 DATADIR"/evince-toolbar.xml");
252 egg_toolbars_model_load (ev_application->toolbars_model,
253 ev_application->toolbars_file);
256 egg_toolbars_model_set_flags (ev_application->toolbars_model, 0,
257 EGG_TB_MODEL_NOT_REMOVABLE);
259 ev_application->recent_model = egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU);
260 egg_recent_model_set_limit (ev_application->recent_model, 5);
261 egg_recent_model_set_filter_groups (ev_application->recent_model,
265 EggToolbarsModel *ev_application_get_toolbars_model (EvApplication *application)
267 return application->toolbars_model;
270 EggRecentModel *ev_application_get_recent_model (EvApplication *application)
272 return application->recent_model;
275 void ev_application_save_toolbars_model (EvApplication *application)
277 egg_toolbars_model_save (application->toolbars_model,
278 application->toolbars_file, "1.0");