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"
35 #include "ev-sidebar.h"
36 #include "ev-sidebar-thumbnails.h"
37 #include "ev-presentation-timer.h"
39 struct _EvDSCWindowPrivate {
46 GtkWidget *presentation_window;
47 GtkWidget *overview_scrolled_window;
48 GtkWidget *notesview_scrolled_window;
50 EvDocumentModel *model;
51 EvDocumentModel *notes_model;
52 EvDocument *presentation_document;
53 EvDocument *notes_document;
55 EvViewPresentation *presentation_view;
57 gint moveback_monitor;
58 gint presentation_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 30 /* 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)
71 ev_dscwindow_get_presentation_window_monitor (EvDSCWindow *ev_dscwindow)
73 GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
74 GdkScreen *screen = gtk_window_get_screen (presentation_window);
75 gint work_monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (GTK_WIDGET (presentation_window)));
80 ev_dscwindow_setup_from_metadata (EvDSCWindow *ev_dscwindow)
82 if (!ev_dscwindow->priv->metadata)
86 if (ev_metadata_get_double (ev_dscwindow->priv->metadata, "presentation-time", &double_value))
87 gtk_spin_button_set_value (GTK_SPIN_BUTTON (ev_dscwindow->priv->spinner),double_value);
88 if (ev_metadata_get_int (ev_dscwindow->priv->metadata, "presentation-monitor", &int_value)) {
89 ev_dscwindow->priv->presentation_monitor = int_value;
91 ev_dscwindow->priv->presentation_monitor = (ev_dscwindow->priv->moveback_monitor + 1) % 2;
96 ev_dscwindow_windows_placement (EvDSCWindow *ev_dscwindow)
98 if (!EV_IS_DSCWINDOW (ev_dscwindow))
101 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
102 if (num_monitors == 2) {
104 GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (ev_dscwindow));
105 gint presentation_monitor = ev_dscwindow->priv->presentation_monitor;
106 gint control_monitor = (presentation_monitor + 1) % 2;
108 gdk_screen_get_monitor_geometry (screen, control_monitor, &coords);
109 gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow));
110 gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y);
111 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
113 gdk_screen_get_monitor_geometry (screen, presentation_monitor,&coords);
114 gtk_window_move (GTK_WINDOW (ev_dscwindow->priv->presentation_window), coords.x, coords.y);
122 ev_dscwindow_switch_monitors (EvDSCWindow *ev_dscwindow)
124 gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
125 if (num_monitors == 2) {
126 ev_dscwindow->priv->presentation_monitor = (ev_dscwindow->priv->presentation_monitor + 1) % 2;
127 if (ev_dscwindow->priv->metadata)
128 ev_metadata_set_int (ev_dscwindow->priv->metadata,
129 "presentation-monitor", ev_dscwindow->priv->presentation_monitor);
131 ev_dscwindow_windows_placement (ev_dscwindow);
135 ev_dscwindow_sidebar_visibility_cb (GtkWidget *sidebar)
137 gtk_widget_set_visible (sidebar, !(gtk_widget_get_visible(sidebar)));
141 ev_dscwindow_set_page (EvDSCWindow *ev_dscwindow, gint page)
143 if((ev_dscwindow->priv->page == 0) && (page == 1))
144 ev_presentation_timer_start (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer));
145 if(!(ev_dscwindow->priv->page == page)) {
146 ev_dscwindow->priv->page = page;
147 if(ev_document_model_get_page (ev_dscwindow->priv->model) != page)
148 ev_document_model_set_page(ev_dscwindow->priv->model, page);
149 if(ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
150 ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
151 if(ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view)) != page);
152 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
153 ev_presentation_timer_set_page (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), page);
158 ev_dscwindow_presentation_time_cb (EvDSCWindow *ev_dscwindow)
160 gint time = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ev_dscwindow->priv->spinner));
161 ev_presentation_timer_set_time (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer),time);
162 if (ev_dscwindow->priv->metadata)
163 ev_metadata_set_double (ev_dscwindow->priv->metadata, "presentation-time", time);
167 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
169 EvDSCWindow *ev_dscwindow)
171 ev_dscwindow_set_page (ev_dscwindow, ev_document_model_get_page (model));
175 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
177 EvDSCWindow *ev_dscwindow)
179 ev_dscwindow_set_page (ev_dscwindow, ev_view_presentation_get_current_page (pview));
183 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *ev_dscwindow)
187 dialog = gtk_file_chooser_dialog_new (
189 GTK_WINDOW (ev_dscwindow),
190 GTK_FILE_CHOOSER_ACTION_OPEN,
191 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
192 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
195 ev_document_factory_add_filters (dialog, NULL);
196 gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
197 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
199 if (ev_dscwindow->priv->metadata &&
200 ev_metadata_get_string (ev_dscwindow->priv->metadata, "notes-uri", &uri))
201 gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog),uri);
203 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
205 uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
206 GError * error = NULL;
207 ev_view_set_loading (EV_VIEW (ev_dscwindow->priv->notesview), TRUE);
209 if (ev_dscwindow->priv->notes_document) {
210 ev_document_load (ev_dscwindow->priv->notes_document, uri, &error);
212 ev_dscwindow->priv->notes_document = ev_document_factory_get_document (uri,
216 if (ev_dscwindow->priv->metadata)
217 ev_metadata_set_string (ev_dscwindow->priv->metadata,
219 ev_dscwindow->priv->notes_model = ev_document_model_new ();
220 ev_document_model_set_document (ev_dscwindow->priv->notes_model,
221 ev_dscwindow->priv->notes_document);
222 ev_document_model_set_continuous (ev_dscwindow->priv->notes_model,
224 ev_document_model_set_dual_page (ev_dscwindow->priv->notes_model,
226 ev_document_model_set_sizing_mode (ev_dscwindow->priv->notes_model,
228 ev_document_model_set_page (ev_dscwindow->priv->notes_model,
229 ev_document_model_get_page (ev_dscwindow->priv->model));
230 ev_view_set_model(EV_VIEW(ev_dscwindow->priv->notesview),
231 ev_dscwindow->priv->notes_model);
232 g_signal_connect (G_OBJECT(ev_dscwindow->priv->notes_model),
234 G_CALLBACK (ev_dscwindow_page_changed_cb),
239 gtk_widget_destroy (dialog);
245 ev_dscwindow_get_control (void)
247 static EvDSCWindow *control = NULL;
249 if (!control || !EV_IS_DSCWINDOW (control)) {
250 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
257 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
258 EvWindow *presentation_window,
259 EvDocument *document,
260 EvViewPresentation *pview,
261 EvMetadata *metadata)
263 if (!EV_IS_WINDOW (presentation_window) || !EV_IS_DSCWINDOW (ev_dscwindow) ||
264 !EV_IS_VIEW_PRESENTATION (pview) || !EV_IS_DOCUMENT (document) )
267 ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
268 ev_dscwindow->priv->presentation_document = document;
269 ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
270 ev_dscwindow->priv->page = ev_view_presentation_get_current_page (pview);
271 ev_dscwindow->priv->moveback_monitor = ev_dscwindow_get_presentation_window_monitor (ev_dscwindow);
272 ev_dscwindow->priv->metadata = metadata;
274 ev_document_model_set_document(ev_dscwindow->priv->model, document);
275 ev_document_model_set_page(ev_dscwindow->priv->model, ev_dscwindow->priv->page);
277 g_signal_connect_swapped (ev_dscwindow->priv->presentation_view,
279 G_CALLBACK (gtk_widget_destroy),
280 GTK_WIDGET (ev_dscwindow));
281 g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
283 G_CALLBACK (ev_dscwindow_page_changed_cb),
285 g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
287 G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
289 ev_presentation_timer_set_pages (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer),
290 ev_document_get_n_pages (document));
291 /* Wait for windows to get shown before moving them */
292 while(gtk_events_pending())
293 gtk_main_iteration();
294 /* something like http://mail.gnome.org/archives/gtk-list/2008-June/msg00061.html */
295 ev_dscwindow_setup_from_metadata (ev_dscwindow);
296 ev_dscwindow_windows_placement (ev_dscwindow);
300 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
302 gtk_widget_destroy (widget);
307 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
310 ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
311 ev_dscwindow->priv->page = 0;
312 ev_dscwindow->priv->moveback_monitor = -1;
313 ev_dscwindow->priv->notes_document = NULL;
315 gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
317 GtkWidget *hpaned = gtk_hpaned_new ();
318 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
320 ev_dscwindow->priv->model = ev_document_model_new ();
321 ev_document_model_set_continuous (ev_dscwindow->priv->model, FALSE);
322 ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
323 ev_document_model_set_sizing_mode (ev_dscwindow->priv->model,
326 ev_dscwindow->priv->sidebar = ev_sidebar_new ();
327 ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
328 ev_dscwindow->priv->model);
330 GtkWidget *sidebar_widget;
331 sidebar_widget = ev_sidebar_thumbnails_new ();
332 ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->sidebar),
335 ev_dscwindow->priv->notesview_scrolled_window =
336 GTK_WIDGET (g_object_new(GTK_TYPE_SCROLLED_WINDOW,
340 ev_dscwindow->priv->notesview = ev_view_new ();
341 gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
342 ev_dscwindow->priv->notesview);
343 ev_dscwindow->priv->notes_model = ev_dscwindow->priv->model;
344 ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview),
345 ev_dscwindow->priv->notes_model);
346 gtk_paned_pack1 (GTK_PANED (hpaned),
347 ev_dscwindow->priv->sidebar,
350 gtk_paned_pack2 (GTK_PANED (hpaned),
351 ev_dscwindow->priv->notesview_scrolled_window,
355 gtk_box_pack_start(GTK_BOX(vbox),hpaned,TRUE,TRUE,0);
357 GtkWidget *expander = gtk_expander_new (_("Expensive features"));
358 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
359 GtkWidget *toolbar = gtk_toolbar_new ();
361 GtkToolItem *b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
362 gtk_tool_item_set_tooltip_text (b_switch,
363 _("Switch monitors, In case of more than two monitor window placing has to be manual."));
364 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
365 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1);
366 g_signal_connect_swapped (b_switch, "clicked",
367 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
369 GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
370 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes..."));
371 gtk_tool_item_set_tooltip_text (b_notes, _("Load your notes document"));
372 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_notes, -1);
373 g_signal_connect (b_notes, "clicked",
374 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
376 GtkToolItem *b_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
377 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_close), _("End presentation"));
378 gtk_tool_item_set_tooltip_text (b_close, _("End presentation"));
379 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_close, -1);
380 g_signal_connect_swapped (b_close, "clicked",
381 G_CALLBACK (ev_dscwindow_end), ev_dscwindow);
383 GtkToolItem *b_sidebar = gtk_tool_button_new_from_stock (GTK_STOCK_PAGE_SETUP);
384 gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_sidebar), _("Show sidebar"));
385 gtk_tool_item_set_tooltip_text (b_sidebar, _("Show/hide sidebar"));
386 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_sidebar, -1);
387 g_signal_connect_swapped (b_sidebar, "clicked",
388 G_CALLBACK (ev_dscwindow_sidebar_visibility_cb), ev_dscwindow->priv->sidebar);
390 GtkToolItem *b_spinner = gtk_tool_item_new ();
391 GtkWidget* alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
392 GtkAdjustment *timer_adjust = gtk_adjustment_new (-1.0, -1.0,
393 MAX_PRESENTATION_TIME, 1.0, 10.0, 10.0);
394 ev_dscwindow->priv->spinner = gtk_spin_button_new (timer_adjust, 1.0, 0);
395 g_signal_connect_swapped (ev_dscwindow->priv->spinner, "value-changed",
396 G_CALLBACK (ev_dscwindow_presentation_time_cb), ev_dscwindow);
397 gtk_container_add (GTK_CONTAINER (b_spinner), alignment);
398 gtk_container_add (GTK_CONTAINER (alignment), ev_dscwindow->priv->spinner);
399 gtk_tool_item_set_tooltip_text (b_spinner,
400 _("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."));
401 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_spinner, -1);
403 gtk_container_add (GTK_CONTAINER (expander), toolbar);
405 GtkWidget *hpan = gtk_hpaned_new ();
406 gtk_paned_pack1 (GTK_PANED(hpan), expander, FALSE, TRUE);
407 ev_dscwindow->priv->timer = ev_presentation_timer_new ();
408 gtk_paned_pack2 (GTK_PANED(hpan),ev_dscwindow->priv->timer, FALSE, FALSE);
410 gtk_box_pack_end (GTK_BOX (vbox), hpan, FALSE, TRUE, 0);
411 gtk_container_add (GTK_CONTAINER (ev_dscwindow), vbox);
412 gtk_widget_show_all(vbox);
413 gtk_paned_set_position (GTK_PANED (hpan), SIDEBAR_DEFAULT_SIZE);
414 gtk_paned_set_position (GTK_PANED (hpaned), SIDEBAR_DEFAULT_SIZE);
418 ev_dscwindow_dispose (GObject *obj)
420 EvDSCWindow *ev_dscwindow = EV_DSCWINDOW (obj);
421 EvDSCWindowPrivate *priv = EV_DSCWINDOW (ev_dscwindow)->priv;
423 if (priv->moveback_monitor >= 0) {
424 GtkWindow *presentation_window = GTK_WINDOW (priv->presentation_window);
427 gdk_screen_get_monitor_geometry (gtk_window_get_screen (presentation_window),
428 priv->moveback_monitor, &coords);
429 gtk_window_move (presentation_window, coords.x, coords.y);
431 ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
432 G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
436 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
438 GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
439 g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
440 g_object_class->dispose = ev_dscwindow_dispose;
444 ev_dscwindow_new (void)
446 EvDSCWindow *ev_dscwindow;
448 ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
449 return GTK_WIDGET (ev_dscwindow);