]> www.fi.muni.cz Git - evince.git/blob - shell/ev-application.c
Hungarian translation updated.
[evince.git] / shell / ev-application.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2004 Martin Kretzschmar
4  *
5  *  Author:
6  *    Martin Kretzschmar <martink@gnome.org>
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "ev-application.h"
28 #include "ev-utils.h"
29 #include "ev-document-types.h"
30
31 #include <glib.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>
38
39 struct _EvApplicationPrivate {
40         GList *windows;
41 };
42
43 G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT);
44
45 #define EV_APPLICATION_GET_PRIVATE(object) \
46         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_APPLICATION, EvApplicationPrivate))
47
48 EvApplication *
49 ev_application_get_instance (void)
50 {
51         static EvApplication *instance;
52
53         if (!instance)
54                 instance = EV_APPLICATION (
55                         g_object_new (EV_TYPE_APPLICATION, NULL));
56
57         return instance;
58 }
59
60 static void
61 window_destroy_cb (GtkObject *object, gpointer user_data)
62 {
63         EvApplication *application;
64         
65         g_return_if_fail (EV_IS_WINDOW (object));
66         g_return_if_fail (EV_IS_APPLICATION (user_data));
67
68         application = EV_APPLICATION (user_data);
69         application->priv->windows =
70                 g_list_remove (application->priv->windows, object);
71
72         if (application->priv->windows == NULL)
73                 gtk_main_quit ();
74 }
75
76 EvWindow *
77 ev_application_new_window (EvApplication *application)
78 {
79         EvWindow *ev_window;
80
81         ev_window = EV_WINDOW (g_object_new (EV_TYPE_WINDOW,
82                                              "type", GTK_WINDOW_TOPLEVEL,
83                                              "default-height", 600,
84                                              "default-width", 600,
85                                              NULL));
86         application->priv->windows =
87                 g_list_prepend (application->priv->windows, ev_window);
88         g_signal_connect (G_OBJECT (ev_window), "destroy",
89                           G_CALLBACK (window_destroy_cb), application);
90
91         return ev_window;
92 }
93
94 static int
95 is_window_empty (const EvWindow *ev_window, gconstpointer dummy)
96 {
97         g_return_val_if_fail (EV_IS_WINDOW (ev_window), 0);
98
99         return ev_window_is_empty (ev_window)
100                 ? 0
101                 : -1;
102 }
103
104 EvWindow *
105 ev_application_get_empty_window (EvApplication *application)
106 {
107         GList *node;
108
109         node = g_list_find_custom (application->priv->windows, NULL,
110                                    (GCompareFunc)is_window_empty);
111
112         return node && node->data
113                 ? EV_WINDOW (node->data)
114                 : ev_application_new_window (application);
115 }
116
117 void
118 ev_application_open (EvApplication *application, GError *err)
119 {
120         EvWindow *ev_window;
121         GtkWidget *chooser;
122         static char *folder = NULL;
123
124         ev_window = ev_application_get_empty_window (application);
125
126         chooser = gtk_file_chooser_dialog_new (_("Open document"),
127                                                GTK_WINDOW (ev_window),
128                                                GTK_FILE_CHOOSER_ACTION_OPEN,
129                                                GTK_STOCK_CANCEL,
130                                                GTK_RESPONSE_CANCEL,
131                                                GTK_STOCK_OPEN, GTK_RESPONSE_OK,
132                                                NULL);
133
134         if (folder) {
135                 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser),
136                                                          folder);
137         }
138
139         ev_document_types_add_filters (chooser);
140         gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
141         gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
142
143         if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_OK) {
144                 GSList *uris;
145
146                 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
147
148                 if (folder != NULL)
149                         g_free (folder);
150                                 
151                 folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
152
153                 ev_window_open_uri_list (ev_window, uris);
154                 
155                 g_slist_free (uris);
156         } else {
157                 if (!GTK_WIDGET_VISIBLE (ev_window))
158                         gtk_widget_destroy (GTK_WIDGET (ev_window));
159         }
160
161         gtk_widget_destroy (GTK_WIDGET (chooser));
162 }
163
164 static void
165 ev_application_class_init (EvApplicationClass *ev_application_class)
166 {
167         GObjectClass *g_object_class;
168
169         g_object_class = G_OBJECT_CLASS (ev_application_class);
170
171         g_type_class_add_private (g_object_class,
172                                   sizeof (EvApplicationPrivate));
173 }
174
175 static void
176 ev_application_init (EvApplication *ev_application)
177 {
178         ev_application->priv = EV_APPLICATION_GET_PRIVATE (ev_application);
179 }
180