1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2007 Johannes Buchner
7 * Johannes Buchner <buchner.johannes@gmx.at>
8 * Lukas Bezdicka <255993@mail.muni.cz>
10 * Evince is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * Evince is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <glib/gi18n.h>
32 #include "ev-dualscreen.h"
33 #include "ev-window.h"
35 #include "ev-view-presentation.h"
37 #include "ev-sidebar.h"
38 #include "ev-sidebar-thumbnails.h"
39 #include "ev-presentation-timer.h"
41 struct _EvDSCWindowPrivate {
47 EvDocumentModel *model;
48 EvDocumentModel *notes_model;
49 EvDocument *presentation_document;
50 EvDocument *notes_document;
52 GtkWidget *presentation_window;
53 GtkWidget *overview_scrolled_window;
54 GtkWidget *notesview_scrolled_window;
56 EvViewPresentation *presentation_view;
57 gint moveback_monitor;
60 #define EV_DSCWINDOW_GET_PRIVATE(object) \
61 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
62 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
64 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
67 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
69 if (!EV_IS_DSCWINDOW (ev_dscwindow))
72 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
74 if (num_monitors == 2) {
75 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
76 GdkScreen *screen = gtk_window_get_screen (presentation_window);
78 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
79 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
81 gint monitor_2 = (monitor_1 + 1) % 2;
84 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
85 gtk_window_move (presentation_window, coords.x, coords.y);
86 ev_dscwindow->priv->moveback_monitor = monitor_1;
88 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
89 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
90 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
91 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
97 ev_dscwindow_sidebar_visibility(GtkWidget *sidebar)
99 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
103 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
105 EvDSCWindow *ev_dscwindow)
107 gint page = ev_document_model_get_page (model);
108 if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view)) {
109 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
110 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
111 ev_document_model_set_page(ev_dscwindow->priv->model, page);
112 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
113 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
118 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
120 EvDSCWindow *ev_dscwindow)
122 gint page = ev_view_presentation_get_current_page (pview);
123 if( ev_document_model_get_page (ev_dscwindow->priv->model) != page)
124 ev_document_model_set_page(ev_dscwindow->priv->model, page);
125 if( ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
126 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
130 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
134 dialog = gtk_file_chooser_dialog_new (
136 GTK_WINDOW (ev_dscwindow),
137 GTK_FILE_CHOOSER_ACTION_OPEN,
138 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
139 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
142 ev_document_factory_add_filters (dialog, NULL);
143 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
144 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
146 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
148 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
149 GError * error = NULL;
150 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
152 if (ev_dscwindow->priv->notes_document) {
153 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
155 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
160 ev_dscwindow->priv->notes_model = ev_document_model_new ();
161 ev_document_model_set_document (ev_dscwindow->priv->notes_model, ev_dscwindow->priv->notes_document);
162 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model, FALSE);
163 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model, FALSE);
164 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model, EV_SIZING_BEST_FIT);
165 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
166 ev_document_model_get_page (ev_dscwindow->priv->model));
167 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
168 ev_dscwindow->priv->notes_model);
169 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
171 G_CALLBACK (ev_dscwindow_page_changed_cb),
175 gtk_widget_destroy (dialog);
181 ev_dscwindow_get_control (void)
183 static EvDSCWindow * control = NULL;
185 if (!control || !EV_IS_DSCWINDOW (control)) {
186 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
193 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
195 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
196 GdkScreen * screen = gtk_window_get_screen (presentation_window);
197 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
198 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
199 gint presentation_monitor = (work_monitor + 1) % 2;
201 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
204 gtk_window_move (presentation_window, coords.x, coords.y);
205 ev_dscwindow->priv->moveback_monitor = work_monitor;
206 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
210 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
211 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
213 if (!EV_IS_WINDOW (presentation_window))
216 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
217 ev_dscwindow->priv->presentation_document = document;
218 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
220 ev_document_model_set_document(ev_dscwindow->priv->model, document);
221 ev_document_model_set_page(ev_dscwindow->priv->model, ev_view_presentation_get_current_page (pview));
223 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
225 G_CALLBACK (gtk_widget_destroy),
227 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
229 G_CALLBACK (ev_dscwindow_page_changed_cb),
231 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
233 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
236 ev_dscwindow_window_placement (ev_dscwindow);
240 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
242 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
247 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
250 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
251 ev_dscwindow->priv->moveback_monitor = -1;
252 ev_dscwindow->priv->notes_document = NULL;
254 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
256 GtkWidget *hpaned = gtk_hpaned_new ();
257 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
259 ev_dscwindow->priv->model = ev_document_model_new ();
260 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
261 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
262 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
264 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
265 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
266 ev_dscwindow->priv->model);
267 GtkWidget *sidebar_widget;
268 sidebar_widget = ev_sidebar_thumbnails_new ();
269 gtk_widget_show (sidebar_widget);
270 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
272 gtk_widget_show (ev_dscwindow->priv->sidebar);
273 gtk_paned_add1(GTK_PANED(hpaned), ev_dscwindow->priv->sidebar);
275 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (
276 g_object_new (GTK_TYPE_SCROLLED_WINDOW,"shadow-type",
277 GTK_SHADOW_IN, NULL));
278 gtk_paned_add2 (GTK_PANED (hpaned), ev_dscwindow->priv->notesview_scrolled_window);
280 ev_dscwindow->priv->notesview = ev_view_new ();
281 g_object_ref (ev_dscwindow->priv->notesview);
282 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
283 ev_dscwindow->priv->notesview);
284 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
285 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->notes_model);
286 gtk_widget_show_all (hpaned);
287 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
289 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
290 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
291 GtkWidget *toolbar = gtk_toolbar_new ();
293 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
294 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
295 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
296 g_signal_connect (b_switch, "clicked",
297 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
299 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
300 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
301 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
302 g_signal_connect (b_notes, "clicked",
303 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
305 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
306 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
307 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
308 g_signal_connect (b_close, "clicked",
309 G_CALLBACK (ev_dscwindow_end), NULL);
311 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
312 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
313 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
314 g_signal_connect_swapped (b_sidebar, "clicked",
315 G_CALLBACK (ev_dscwindow_sidebar_visibility), ev_dscwindow->priv->sidebar);
317 gtk_container_add (GTK_CONTAINER (expander), toolbar);
319 GtkWidget *hbox = gtk_hbox_new (FALSE,0);
320 gtk_box_pack_start (GTK_BOX (hbox), expander, FALSE, TRUE, 0);
321 ev_dscwindow->priv->timer = ev_presentation_timer_new ();
322 gtk_box_pack_end (GTK_BOX (hbox), ev_dscwindow->priv->timer, TRUE, TRUE, 0);
323 gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
324 gtk_widget_show_all(vbox);
325 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
329 ev_dscwindow_dispose (GObject *obj)
331 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
332 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
334 if (priv->moveback_monitor >= 0) {
335 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
338 gdk_screen_get_monitor_geometry (
339 gtk_window_get_screen (presentation_window),
340 priv->moveback_monitor, &coords);
342 gtk_window_move (presentation_window, coords.x, coords.y);
344 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
345 /*if (priv->overview) {
346 g_object_unref (priv->overview);
347 priv->overview = NULL;
350 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
354 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
356 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
357 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
358 g_object_class->dispose = ev_dscwindow_dispose;
362 ev_dscwindow_new (void)
364 EvDSCWindow *ev_dscwindow;
366 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
367 return GTK_WIDGET (ev_dscwindow);