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.
23 #include "ev-application.h"
26 #include <glib/gi18n.h>
27 #include <glib-object.h>
28 #include <gtk/gtkfilechooserdialog.h>
29 #include <gtk/gtkstock.h>
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkmain.h>
32 #include <libgnomevfs/gnome-vfs-utils.h>
34 #include "ev-window.h"
36 struct _EvApplicationPrivate {
40 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
42 #define EV_APPLICATION_GET_PRIVATE(object) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_APPLICATION, EvApplicationPrivate))
46 ev_application_get_instance (void)
48 static EvApplication *instance;
51 instance = EV_APPLICATION (
52 g_object_new (EV_TYPE_APPLICATION, NULL));
58 window_destroy_cb (GtkObject *object, gpointer user_data)
60 EvApplication *application;
62 g_return_if_fail (EV_IS_WINDOW (object));
63 g_return_if_fail (EV_IS_APPLICATION (user_data));
65 application = EV_APPLICATION (user_data);
66 application->priv->windows =
67 g_list_remove (application->priv->windows, object);
69 if (application->priv->windows == NULL)
74 ev_application_new_window (EvApplication *application)
78 ev_window = EV_WINDOW (g_object_new (EV_TYPE_WINDOW,
79 "type", GTK_WINDOW_TOPLEVEL,
80 "default-height", 600,
83 application->priv->windows =
84 g_list_prepend (application->priv->windows, ev_window);
85 g_signal_connect (G_OBJECT (ev_window), "destroy",
86 G_CALLBACK (window_destroy_cb), application);
92 is_window_empty (const EvWindow *ev_window, gconstpointer dummy)
94 g_return_val_if_fail (EV_IS_WINDOW (ev_window), 0);
96 return ev_window_is_empty (ev_window)
102 ev_application_get_empty_window (EvApplication *application)
106 node = g_list_find_custom (application->priv->windows, NULL,
107 (GCompareFunc)is_window_empty);
109 return node && node->data
110 ? EV_WINDOW (node->data)
111 : ev_application_new_window (application);
115 ev_application_open (EvApplication *application, GError *err)
119 GtkFileFilter *both_filter, *pdf_filter, *ps_filter, *pixbuf_filter, *all_filter;
121 ev_window = ev_application_get_empty_window (application);
123 chooser = gtk_file_chooser_dialog_new (_("Open document"),
124 GTK_WINDOW (ev_window),
125 GTK_FILE_CHOOSER_ACTION_OPEN,
128 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
131 both_filter = gtk_file_filter_new ();
132 gtk_file_filter_set_name (both_filter,
133 _("PostScript and PDF Documents"));
134 gtk_file_filter_add_mime_type (both_filter, "application/postscript");
135 gtk_file_filter_add_mime_type (both_filter, "application/pdf");
136 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), both_filter);
138 ps_filter = gtk_file_filter_new ();
139 gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
140 gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
141 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
143 pdf_filter = gtk_file_filter_new ();
144 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
145 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
146 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
148 pixbuf_filter = gtk_file_filter_new ();
149 gtk_file_filter_set_name (pixbuf_filter, _("Images"));
150 gtk_file_filter_add_pixbuf_formats (pixbuf_filter);
151 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter);
153 all_filter = gtk_file_filter_new ();
154 gtk_file_filter_set_name (all_filter, _("All Files"));
155 gtk_file_filter_add_pattern (all_filter, "*");
156 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter);
158 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), both_filter);
160 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
163 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
164 ev_window_open (ev_window, uri);
165 gtk_widget_show (GTK_WIDGET (ev_window));
169 gtk_widget_destroy (GTK_WIDGET (chooser));
173 ev_application_open_bookmark (EvApplication *application,
175 EvBookmark *bookmark,
181 type = ev_bookmark_get_bookmark_type (bookmark);
184 case EV_BOOKMARK_TYPE_TITLE:
186 case EV_BOOKMARK_TYPE_LINK:
187 ev_window_open_bookmark (window, bookmark);
189 case EV_BOOKMARK_TYPE_EXTERNAL_URI:
190 uri = ev_bookmark_get_uri (bookmark);
191 gnome_vfs_url_show (uri);
197 ev_application_class_init (EvApplicationClass *ev_application_class)
199 GObjectClass *g_object_class;
201 g_object_class = G_OBJECT_CLASS (ev_application_class);
203 g_type_class_add_private (g_object_class,
204 sizeof (EvApplicationPrivate));
208 ev_application_init (EvApplication *ev_application)
210 ev_application->priv = EV_APPLICATION_GET_PRIVATE (ev_application);