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 {
48 GtkWidget *presentation_window;
49 GtkWidget *overview_scrolled_window;
50 GtkWidget *notesview_scrolled_window;
52 EvDocumentModel *model;
53 EvDocumentModel *notes_model;
54 EvDocument *presentation_document;
55 EvDocument *notes_document;
57 EvViewPresentation *presentation_view;
58 gint moveback_monitor;
62 #define EV_DSCWINDOW_GET_PRIVATE(object) \
63 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
64 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
65 #define SIDEBAR_DEFAULT_SIZE 300
66 #define MAX_PRESENTATION_TIME 1440 /*60*24: ONE DAY*/
68 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
72 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
74 if (!EV_IS_DSCWINDOW (ev_dscwindow))
77 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
79 if (num_monitors == 2) {
80 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
81 GdkScreen *screen = gtk_window_get_screen (presentation_window);
83 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
84 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
86 gint monitor_2 = (monitor_1 + 1) % 2;
89 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
90 gtk_window_move (presentation_window, coords.x, coords.y);
91 ev_dscwindow->priv->moveback_monitor = monitor_1;
93 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
94 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
95 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
96 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
102 ev_dscwindow_sidebar_visibility_cb (GtkWidget *sidebar)
104 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
108 ev_dscwindow_set_page (EvDSCWindow *ev_dscwindow, gint page)
110 guint n_pages = ev_document_get_n_pages(ev_dscwindow->priv->presentation_document);
112 if((ev_dscwindow->priv->page == 0) && (page == 1))
114 if((ev_dscwindow->priv->page == n_pages-1) && (page == n_pages))
116 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
117 ev_document_model_set_page(ev_dscwindow->priv->model, page);
118 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
119 ev_presentation_timer_set_page (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), page);
120 ev_dscwindow->priv->page = page;
124 ev_dscwindow_presentation_time_cb (EvDSCWindow *ev_dscwindow)
126 gint time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ev_dscwindow->priv->spinner));
127 ev_presentation_timer_set_time (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer),time);
131 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
133 EvDSCWindow *ev_dscwindow)
135 ev_dscwindow_set_page (ev_dscwindow, ev_document_model_get_page (model));
139 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
141 EvDSCWindow *ev_dscwindow)
143 ev_dscwindow_set_page (ev_dscwindow, ev_view_presentation_get_current_page (pview));
147 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
151 dialog = gtk_file_chooser_dialog_new (
153 GTK_WINDOW (ev_dscwindow),
154 GTK_FILE_CHOOSER_ACTION_OPEN,
155 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
156 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
159 ev_document_factory_add_filters (dialog, NULL);
160 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
161 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
163 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
165 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
166 GError * error = NULL;
167 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
169 if (ev_dscwindow->priv->notes_document) {
170 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
172 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
177 ev_dscwindow->priv->notes_model = ev_document_model_new ();
178 ev_document_model_set_document (ev_dscwindow->priv->notes_model, ev_dscwindow->priv->notes_document);
179 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model, FALSE);
180 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model, FALSE);
181 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model, EV_SIZING_BEST_FIT);
182 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
183 ev_document_model_get_page (ev_dscwindow->priv->model));
184 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
185 ev_dscwindow->priv->notes_model);
186 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
188 G_CALLBACK (ev_dscwindow_page_changed_cb),
192 gtk_widget_destroy (dialog);
198 ev_dscwindow_get_control (void)
200 static EvDSCWindow * control = NULL;
202 if (!control || !EV_IS_DSCWINDOW (control)) {
203 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
210 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
212 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
213 GdkScreen * screen = gtk_window_get_screen (presentation_window);
214 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
215 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
216 gint presentation_monitor = (work_monitor + 1) % 2;
218 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
221 gtk_window_move (presentation_window, coords.x, coords.y);
222 ev_dscwindow->priv->moveback_monitor = work_monitor;
223 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
227 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
228 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
230 if (!EV_IS_WINDOW (presentation_window))
233 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
234 ev_dscwindow->priv->presentation_document = document;
235 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
236 ev_dscwindow->priv->page = ev_view_presentation_get_current_page (pview);
238 ev_document_model_set_document(ev_dscwindow->priv->model, document);
239 ev_document_model_set_page(ev_dscwindow->priv->model, ev_dscwindow->priv->page);
241 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
243 G_CALLBACK (gtk_widget_destroy),
245 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
247 G_CALLBACK (ev_dscwindow_page_changed_cb),
249 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
251 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
253 ev_presentation_timer_set_pages (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), ev_document_get_n_pages (document));
255 ev_dscwindow_window_placement (ev_dscwindow);
259 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
261 gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
266 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
269 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
270 ev_dscwindow->priv->page = 0;
271 ev_dscwindow->priv->moveback_monitor = -1;
272 ev_dscwindow->priv->notes_document = NULL;
274 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
276 GtkWidget *hpaned = gtk_hpaned_new ();
277 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
279 ev_dscwindow->priv->model = ev_document_model_new ();
280 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
281 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
282 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
284 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
285 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
286 ev_dscwindow->priv->model);
288 GtkWidget *sidebar_widget;
289 sidebar_widget = ev_sidebar_thumbnails_new ();
290 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
293 ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (
294 g_object_new (GTK_TYPE_SCROLLED_WINDOW,"shadow-type",
295 GTK_SHADOW_IN, NULL));
296 gtk_paned_pack1 (GTK_PANED (hpaned), ev_dscwindow->priv->sidebar, FALSE, TRUE);
297 gtk_paned_pack2 (GTK_PANED (hpaned), ev_dscwindow->priv->notesview_scrolled_window, TRUE, TRUE);
298 gtk_paned_set_position (GTK_PANED (hpaned), SIDEBAR_DEFAULT_SIZE);
300 ev_dscwindow->priv->notesview = ev_view_new ();
301 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
302 ev_dscwindow->priv->notesview);
304 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
305 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->notes_model);
307 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
309 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
310 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
311 GtkWidget *toolbar = gtk_toolbar_new ();
313 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
314 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
315 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
316 g_signal_connect (b_switch, "clicked",
317 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
319 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
320 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
321 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
322 g_signal_connect (b_notes, "clicked",
323 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
325 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
326 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
327 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
328 g_signal_connect (b_close, "clicked",
329 G_CALLBACK (ev_dscwindow_end), NULL);
331 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
332 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
333 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
334 g_signal_connect_swapped (b_sidebar, "clicked",
335 G_CALLBACK (ev_dscwindow_sidebar_visibility_cb), ev_dscwindow->priv->sidebar);
337 GtkToolItem *b_spinner = gtk_tool_item_new ();
338 GtkWidget* alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
339 GtkAdjustment *timer_adjust = gtk_adjustment_new (-1.0, -1.0,
340 MAX_PRESENTATION_TIME, 1.0, 10.0, 10.0);
341 ev_dscwindow->priv->spinner = gtk_spin_button_new (timer_adjust, 1.0, 0);
342 g_signal_connect_swapped (ev_dscwindow->priv->spinner, "value-changed",
343 G_CALLBACK (ev_dscwindow_presentation_time_cb), ev_dscwindow);
344 gtk_container_add (GTK_CONTAINER (b_spinner), alignment);
345 gtk_container_add (GTK_CONTAINER (alignment), ev_dscwindow->priv->spinner);
346 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_spinner, -1);
348 gtk_container_add (GTK_CONTAINER (expander), toolbar);
350 GtkWidget *hpan = gtk_hpaned_new ();
351 gtk_paned_pack1 (GTK_PANED(hpan), expander, FALSE, TRUE);
352 ev_dscwindow->priv->timer = ev_presentation_timer_new ();
353 gtk_paned_pack2 (GTK_PANED(hpan),ev_dscwindow->priv->timer, TRUE, TRUE);
354 gtk_paned_set_position (GTK_PANED (hpan), SIDEBAR_DEFAULT_SIZE);
355 gtk_box_pack_end (GTK_BOX (vbox), hpan, FALSE, TRUE, 0);
356 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
357 gtk_widget_show_all(vbox);
361 ev_dscwindow_dispose (GObject *obj)
363 EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
364 EvDSCWindowPrivate *priv = ev_dscwindow->priv;
366 if (priv->moveback_monitor >= 0) {
367 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
370 gdk_screen_get_monitor_geometry (
371 gtk_window_get_screen (presentation_window),
372 priv->moveback_monitor, &coords);
374 gtk_window_move (presentation_window, coords.x, coords.y);
376 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
377 /*if (priv->overview) {
378 g_object_unref (priv->overview);
379 priv->overview = NULL;
382 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
386 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
388 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
389 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
390 g_object_class->dispose = ev_dscwindow_dispose;
394 ev_dscwindow_new (void)
396 EvDSCWindow *ev_dscwindow;
398 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
399 return GTK_WIDGET (ev_dscwindow);