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"
30 #include <glib/gi18n.h>
31 #include <glib-object.h>
32 #include <gtk/gtkfilechooserdialog.h>
33 #include <gtk/gtkstock.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkmain.h>
37 struct _EvApplicationPrivate {
41 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
43 #define EV_APPLICATION_GET_PRIVATE(object) \
44 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_APPLICATION, EvApplicationPrivate))
47 ev_application_get_instance (void)
49 static EvApplication *instance;
52 instance = EV_APPLICATION (
53 g_object_new (EV_TYPE_APPLICATION, NULL));
59 window_destroy_cb (GtkObject *object, gpointer user_data)
61 EvApplication *application;
63 g_return_if_fail (EV_IS_WINDOW (object));
64 g_return_if_fail (EV_IS_APPLICATION (user_data));
66 application = EV_APPLICATION (user_data);
67 application->priv->windows =
68 g_list_remove (application->priv->windows, object);
70 if (application->priv->windows == NULL)
75 ev_application_new_window (EvApplication *application)
79 ev_window = EV_WINDOW (g_object_new (EV_TYPE_WINDOW,
80 "type", GTK_WINDOW_TOPLEVEL,
81 "default-height", 600,
84 application->priv->windows =
85 g_list_prepend (application->priv->windows, ev_window);
86 g_signal_connect (G_OBJECT (ev_window), "destroy",
87 G_CALLBACK (window_destroy_cb), application);
93 is_window_empty (const EvWindow *ev_window, gconstpointer dummy)
95 g_return_val_if_fail (EV_IS_WINDOW (ev_window), 0);
97 return ev_window_is_empty (ev_window)
103 ev_application_get_empty_window (EvApplication *application)
107 node = g_list_find_custom (application->priv->windows, NULL,
108 (GCompareFunc)is_window_empty);
110 return node && node->data
111 ? EV_WINDOW (node->data)
112 : ev_application_new_window (application);
116 ev_application_open (EvApplication *application, GError *err)
120 GtkFileFilter *documents_filter;
121 GtkFileFilter *pdf_filter;
122 GtkFileFilter *ps_filter;
123 GtkFileFilter *pixbuf_filter;
124 GtkFileFilter *all_filter;
125 static gchar *folder = NULL;
127 GtkFileFilter *djvu_filter;
130 GtkFileFilter *dvi_filter;
133 ev_window = ev_application_get_empty_window (application);
135 chooser = gtk_file_chooser_dialog_new (_("Open document"),
136 GTK_WINDOW (ev_window),
137 GTK_FILE_CHOOSER_ACTION_OPEN,
140 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
144 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
148 documents_filter = gtk_file_filter_new ();
149 gtk_file_filter_set_name (documents_filter,
151 gtk_file_filter_add_mime_type (documents_filter, "application/postscript");
152 gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript");
153 gtk_file_filter_add_mime_type (documents_filter, "image/x-eps");
154 gtk_file_filter_add_mime_type (documents_filter, "application/pdf");
156 gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi");
158 gtk_file_filter_add_pixbuf_formats (documents_filter);
160 gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu");
162 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
164 ps_filter = gtk_file_filter_new ();
165 gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
166 gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
167 gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript");
168 gtk_file_filter_add_mime_type (ps_filter, "image/x-eps");
169 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
171 pdf_filter = gtk_file_filter_new ();
172 gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
173 gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
174 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
177 dvi_filter = gtk_file_filter_new ();
178 gtk_file_filter_set_name (dvi_filter, _("DVI Documents"));
179 gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi");
180 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter);
183 pixbuf_filter = gtk_file_filter_new ();
184 gtk_file_filter_set_name (pixbuf_filter, _("Images"));
185 gtk_file_filter_add_pixbuf_formats (pixbuf_filter);
186 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter);
189 djvu_filter = gtk_file_filter_new ();
190 gtk_file_filter_set_name (djvu_filter, _("Djvu Documents"));
191 gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu");
192 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter);
195 all_filter = gtk_file_filter_new ();
196 gtk_file_filter_set_name (all_filter, _("All Files"));
197 gtk_file_filter_add_pattern (all_filter, "*");
199 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter);
200 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
202 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
203 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
205 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
208 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
209 folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser));
211 ev_window_open_uri_list (ev_window, uris);
215 if (!GTK_WIDGET_VISIBLE (ev_window))
216 gtk_widget_destroy (GTK_WIDGET (ev_window));
219 gtk_widget_destroy (GTK_WIDGET (chooser));
223 ev_application_class_init (EvApplicationClass *ev_application_class)
225 GObjectClass *g_object_class;
227 g_object_class = G_OBJECT_CLASS (ev_application_class);
229 g_type_class_add_private (g_object_class,
230 sizeof (EvApplicationPrivate));
234 ev_application_init (EvApplication *ev_application)
236 ev_application->priv = EV_APPLICATION_GET_PRIVATE (ev_application);