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 25 /* This seems like bug in gtk to me */
66 #define MAX_PRESENTATION_TIME 1440 /*60*24 ONE DAY*/
68 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
72 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
74 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
75 GdkScreen *screen = gtk_window_get_screen (presentation_window);
76 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
77 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
78 gint presentation_monitor = (work_monitor + 1) % 2;
80 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
83 gtk_window_move (presentation_window, coords.x, coords.y);
84 ev_dscwindow->priv->moveback_monitor = work_monitor;
85 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
89 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow)
91 if (!EV_IS_DSCWINDOW (ev_dscwindow))
94 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
96 if (num_monitors == 2) {
97 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
98 GdkScreen *screen = gtk_window_get_screen (presentation_window);
100 gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
101 gtk_widget_get_window (GTK_WIDGET (presentation_window)));
103 gint monitor_2 = (monitor_1 + 1) % 2;
106 gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
107 gtk_window_move (presentation_window, coords.x, coords.y);
108 ev_dscwindow->priv->moveback_monitor = monitor_1;
110 gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
111 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
112 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
113 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
119 ev_dscwindow_sidebar_visibility_cb (GtkWidget *sidebar)
121 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
125 ev_dscwindow_set_page (EvDSCWindow *ev_dscwindow, gint page)
127 if((ev_dscwindow->priv->page == 0) && (page == 1))
128 ev_presentation_timer_start (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer));
129 if(ev_dscwindow->priv->page != page) {
130 if(ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view)) != page);
131 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
132 if(ev_document_model_get_page (ev_dscwindow->priv->model) != page)
133 ev_document_model_set_page(ev_dscwindow->priv->model, page);
134 if(ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
135 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
136 ev_dscwindow->priv->page = page;
138 ev_presentation_timer_set_page (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), page);
142 ev_dscwindow_presentation_time_cb (EvDSCWindow *ev_dscwindow)
144 gint time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ev_dscwindow->priv->spinner));
145 ev_presentation_timer_set_time (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer),time);
149 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
151 EvDSCWindow *ev_dscwindow)
153 ev_dscwindow_set_page (ev_dscwindow, ev_document_model_get_page (model));
157 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
159 EvDSCWindow *ev_dscwindow)
161 ev_dscwindow_set_page (ev_dscwindow, ev_view_presentation_get_current_page (pview));
165 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
169 dialog = gtk_file_chooser_dialog_new (
171 GTK_WINDOW (ev_dscwindow),
172 GTK_FILE_CHOOSER_ACTION_OPEN,
173 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
174 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
177 ev_document_factory_add_filters (dialog, NULL);
178 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
179 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
181 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
183 char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
184 GError * error = NULL;
185 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
187 if (ev_dscwindow->priv->notes_document) {
188 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
190 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
195 ev_dscwindow->priv->notes_model = ev_document_model_new ();
196 ev_document_model_set_document (ev_dscwindow->priv->notes_model,
197 ev_dscwindow->priv->notes_document);
198 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model,
200 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model,
202 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model,
204 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
205 ev_document_model_get_page (ev_dscwindow->priv->model));
206 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
207 ev_dscwindow->priv->notes_model);
208 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
210 G_CALLBACK (ev_dscwindow_page_changed_cb),
214 gtk_widget_destroy (dialog);
220 ev_dscwindow_get_control (void)
222 static EvDSCWindow *control = NULL;
224 if (!control || !EV_IS_DSCWINDOW (control)) {
225 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
232 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
233 EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
235 if (!EV_IS_WINDOW (presentation_window))
238 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
239 ev_dscwindow->priv->presentation_document = document;
240 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
241 ev_dscwindow->priv->page = ev_view_presentation_get_current_page (pview);
243 ev_document_model_set_document(ev_dscwindow->priv->model, document);
244 ev_document_model_set_page(ev_dscwindow->priv->model, ev_dscwindow->priv->page);
246 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
248 G_CALLBACK (gtk_widget_destroy),
249 GTK_WIDGET (ev_dscwindow));
250 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
252 G_CALLBACK (ev_dscwindow_page_changed_cb),
254 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
256 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
258 ev_presentation_timer_set_pages (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer),
259 ev_document_get_n_pages (document));
261 ev_dscwindow_window_placement (ev_dscwindow);
265 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
267 gtk_widget_destroy (widget);
272 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
275 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
276 ev_dscwindow->priv->page = 0;
277 ev_dscwindow->priv->moveback_monitor = -1;
278 ev_dscwindow->priv->notes_document = NULL;
280 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
282 GtkWidget *hpaned = gtk_hpaned_new ();
283 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
285 ev_dscwindow->priv->model = ev_document_model_new ();
286 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
287 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
288 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model,
291 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
292 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
293 ev_dscwindow->priv->model);
295 GtkWidget *sidebar_widget;
296 sidebar_widget = ev_sidebar_thumbnails_new ();
297 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
300 ev_dscwindow->priv->notesview_scrolled_window =
301 GTK_WIDGET (g_object_new(GTK_TYPE_SCROLLED_WINDOW,
305 ev_dscwindow->priv->notesview = ev_view_new ();
306 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
307 ev_dscwindow->priv->notesview);
308 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
309 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview),
310 ev_dscwindow->priv->notes_model);
311 gtk_paned_pack1 (GTK_PANED (hpaned),
312 ev_dscwindow->priv->sidebar,
315 gtk_paned_pack2 (GTK_PANED (hpaned),
316 ev_dscwindow->priv->notesview_scrolled_window,
320 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
322 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
323 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
324 GtkWidget *toolbar = gtk_toolbar_new ();
326 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
327 gtk_tool_item_set_tooltip_text (b_switch,
328 _("Switch monitors, In case of more than two monitor window placing has to be manual."));
329 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
330 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
331 g_signal_connect (b_switch, "clicked",
332 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
334 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
335 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
336 gtk_tool_item_set_tooltip_text (b_notes, _("Load your notes document"));
337 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
338 g_signal_connect (b_notes, "clicked",
339 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
341 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
342 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
343 gtk_tool_item_set_tooltip_text (b_close, _("End presentation"));
344 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
345 g_signal_connect_swapped (b_close, "clicked",
346 G_CALLBACK (ev_dscwindow_end), ev_dscwindow);
348 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
349 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
350 gtk_tool_item_set_tooltip_text (b_sidebar, _("Show/hide sidebar"));
351 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
352 g_signal_connect_swapped (b_sidebar, "clicked",
353 G_CALLBACK (ev_dscwindow_sidebar_visibility_cb), ev_dscwindow->priv->sidebar);
355 GtkToolItem *b_spinner = gtk_tool_item_new ();
356 GtkWidget* alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
357 GtkAdjustment *timer_adjust = gtk_adjustment_new (-1.0, -1.0,
358 MAX_PRESENTATION_TIME, 1.0, 10.0, 10.0);
359 ev_dscwindow->priv->spinner = gtk_spin_button_new (timer_adjust, 1.0, 0);
360 g_signal_connect_swapped (ev_dscwindow->priv->spinner, "value-changed",
361 G_CALLBACK (ev_dscwindow_presentation_time_cb), ev_dscwindow);
362 gtk_container_add (GTK_CONTAINER (b_spinner), alignment);
363 gtk_container_add (GTK_CONTAINER (alignment), ev_dscwindow->priv->spinner);
364 gtk_tool_item_set_tooltip_text (b_spinner,
365 _("To enable timer, set presentation timer to expected time in minutes. Timer starts by changing from first slide to second one. Value -1 means disabled."));
366 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_spinner, -1);
368 gtk_container_add (GTK_CONTAINER (expander), toolbar);
370 GtkWidget *hpan = gtk_hpaned_new ();
371 gtk_paned_pack1 (GTK_PANED(hpan), expander, FALSE, TRUE);
372 ev_dscwindow->priv->timer = ev_presentation_timer_new ();
373 gtk_paned_pack2 (GTK_PANED(hpan),ev_dscwindow->priv->timer, FALSE, FALSE);
375 gtk_box_pack_end (GTK_BOX (vbox), hpan, FALSE, TRUE, 0);
376 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
377 gtk_widget_show_all(vbox);
378 gtk_paned_set_position (GTK_PANED (hpan), SIDEBAR_DEFAULT_SIZE);
379 gtk_paned_set_position (GTK_PANED (hpaned), SIDEBAR_DEFAULT_SIZE);
383 ev_dscwindow_dispose (GObject *obj)
385 EvDSCWindow *ev_dscwindow = EV_DSCWINDOW (obj);
386 EvDSCWindowPrivate *priv = EV_DSCWINDOW (ev_dscwindow)->priv;
388 if (priv->moveback_monitor >= 0) {
389 GtkWindow *presentation_window = GTK_WINDOW (priv->presentation_window);
392 gdk_screen_get_monitor_geometry (
393 gtk_window_get_screen (presentation_window),
394 priv->moveback_monitor, &coords);
396 gtk_window_move (presentation_window, coords.x, coords.y);
398 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
399 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
403 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
405 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
406 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
407 g_object_class->dispose = ev_dscwindow_dispose;
411 ev_dscwindow_new (void)
413 EvDSCWindow *ev_dscwindow;
415 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
416 return GTK_WIDGET (ev_dscwindow);