]> www.fi.muni.cz Git - evince.git/blob - shell/ev-dualscreen.c
[dualscreen] [presentation] make presentation control dscwindow, presentation ->...
[evince.git] / shell / ev-dualscreen.c
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
3  *
4  *
5  * Evince is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Evince is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
26
27 #include "ev-dualscreen.h"
28 #include "ev-window.h"
29 #include "ev-view.h"
30 #include "ev-view-presentation.h"
31 #include "ev-utils.h"
32 #include "ev-sidebar.h"
33 #include "ev-sidebar-thumbnails.h"
34
35 struct _EvDSCWindowPrivate {
36         GtkWidget *main_box;
37         GtkWidget *menubar;
38         GtkWidget *overview;
39         GtkWidget *notesview;
40         EvDocumentModel *model;
41         EvDocument * notesdocument;
42
43         GtkWidget *overview_scrolled_window;
44         GtkWidget *notesview_scrolled_window;
45         GtkWidget *presentation_window;
46
47         EvViewPresentation *presentation_view;
48         EvDocument * presentation_document;
49         gint moveback_monitor;
50 };
51
52 #define EV_DSCWINDOW_GET_PRIVATE(object) \
53         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
54 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
55 #define SIDEBAR_DEFAULT_SIZE    132
56
57 /*static gpointer parent_class = NULL;*/
58
59 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
60
61 /**
62  * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
63  *
64  * @widget: Callback widget
65  * @self: EvDSCWindow
66  **/
67 static gboolean
68 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
69 {
70 /*
71 +       if (!EV_IS_DSCWINDOW (self))
72 +               return FALSE;
73 +
74 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
75 +
76 +       gint num_monitors = get_num_monitors (GTK_WINDOW (self));
77 +
78 +       if (num_monitors == 2) {
79 +               GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
80 +               GdkScreen * screen = gtk_window_get_screen (presentation_window);
81 +
82 +               gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
83 +                       GTK_WIDGET (presentation_window)->window);
84 +
85 +               gint monitor_2 = (monitor_1 + 1) % 2;
86 +
87 +               GdkRectangle coords;
88 +               gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
89 +               ev_window_stop_presentation (priv->presentation_window);
90 +               gtk_window_move (presentation_window, coords.x, coords.y);
91 +               ev_window_run_presentation (priv->presentation_window);
92 +               priv->moveback_monitor = monitor_1;
93 +
94 +               gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
95 +               gtk_window_unmaximize (GTK_WINDOW (self));
96 +               gtk_window_move (GTK_WINDOW (self), coords.x, coords.y);
97 +               gtk_window_maximize (GTK_WINDOW (self));
98 +       }*/
99         return TRUE;
100 }
101
102 /**
103  * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
104  **/
105 static gboolean
106 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
107 {
108 /*
109 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
110 +       GtkWidget *dialog;
111 +
112 +       dialog = gtk_file_chooser_dialog_new (
113 +               _("Open Document"),
114 +               GTK_WINDOW (self),
115 +               GTK_FILE_CHOOSER_ACTION_OPEN,
116 +               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
117 +               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
118 +               NULL);
119 +
120 +       ev_document_factory_add_filters (dialog, NULL);
121 +       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
122 +       gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
123 +
124 +       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
125 +       {
126 +               char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
127 +               GError * error = NULL;
128 +               ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
129 +
130 +               if (priv->notesdocument) {
131 +                       ev_document_load (priv->notesdocument, uri, &error);
132 +               } else {
133 +                       priv->notesdocument = ev_document_factory_get_document (uri,
134 +                               &error);
135 +               }
136 +               g_free (uri);
137 +               if (error == NULL){
138 +                       ev_view_set_document (EV_VIEW (priv->notesview),
139 +                               priv->notesdocument);
140 +                       /* TODO: go to the same page that is open at the moment, or
141 +                        * move the presentation to the beginning. *//*
142 +               }
143 +       }
144 +       gtk_widget_destroy (dialog);
145 */
146         return TRUE;
147 }
148
149 /**
150  * ev_dscwindow_get_control: Get the control instance.
151  *
152  * If there is none, create one.
153  *
154  * Returns: control instance
155  **/
156 EvDSCWindow *
157 ev_dscwindow_get_control (void)
158 {
159         static EvDSCWindow * control = NULL;
160
161         if (!control || !EV_IS_DSCWINDOW (control)) {
162                 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
163         }
164
165         return control;
166 }
167
168 /*TODO: Fix me!*/
169 static void
170 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
171 {
172         gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
173         //if (num_monitors == 2) {
174                 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
175                 GdkScreen * screen = gtk_window_get_screen (presentation_window);
176                 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
177                         gtk_widget_get_window (GTK_WIDGET (presentation_window)));
178                 gint presentation_monitor = (work_monitor + 1) % 2;
179                 GdkRectangle coords;
180                 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
181                         &coords);
182
183                 gtk_window_move (presentation_window, coords.x, coords.y);
184                 //ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
185                 ev_dscwindow->priv->moveback_monitor = work_monitor;
186                 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
187         //}
188 }
189 /**
190  * ev_dscwindow_page_changed_cb: Callback to change page on all views
191  *
192  **/
193 static void
194 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
195                            GParamSpec      *pspec,
196                            EvDSCWindow     *ev_dscwindow)
197 {
198         gint page = ev_document_model_get_page (model);
199         if(page != ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view))
200                 ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
201 }
202 static void
203 ev_dscwindow_presentation_page_changed_cb (EvViewPresentation *pview,
204                            GParamSpec      *pspec,
205                            EvDSCWindow     *ev_dscwindow)
206 {
207         gint page = ev_view_presentation_get_current_page (pview);
208         ev_document_model_set_page (ev_dscwindow->priv->model, page);
209 }
210
211 /**
212  * ev_dscwindow_set_presentation: Set presentation document
213  * @presentation_window: Main window we can reuse for presentation
214  **/
215 void
216 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
217         EvWindow *presentation_window, EvDocument *document, EvViewPresentation *pview)
218 {
219         if (!EV_IS_WINDOW (presentation_window))
220                 return;
221
222         ev_dscwindow->priv->presentation_window = GTK_WIDGET(presentation_window);
223         ev_dscwindow->priv->presentation_document = document;
224         ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview);
225         ev_document_model_set_document(ev_dscwindow->priv->model,
226                 document);
227         g_signal_connect (G_OBJECT(ev_dscwindow->priv->presentation_view),
228                           "notify::page",
229                           G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
230                           ev_dscwindow);
231         ev_dscwindow_window_placement (ev_dscwindow);
232 }
233
234 /**
235  * ev_dscwindow_end: Stop presentation mode.
236  */
237 static gboolean
238 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
239 {
240         gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
241         return TRUE;
242 }
243
244 /**
245 * ev_dscwindow_init: Initialize multihead presentation
246 *
247 * @ev_dscwindow: EvDSCWindow.
248 *
249 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
250 **/
251 static void
252 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
253 {
254         ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
255         ev_dscwindow->priv->moveback_monitor = -1;
256         ev_dscwindow->priv->notesdocument = NULL;
257
258         gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
259
260         GtkWidget *h = gtk_hpaned_new ();
261         GtkWidget *v = gtk_vbox_new (FALSE, 0);
262
263         ev_dscwindow->priv->model = ev_document_model_new ();
264         g_signal_connect (G_OBJECT(ev_dscwindow->priv->model),
265                           "notify::page",
266                           G_CALLBACK (ev_dscwindow_page_changed_cb),
267                           ev_dscwindow);
268         ev_dscwindow->priv->overview = ev_sidebar_new ();
269         ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->overview),
270                               ev_dscwindow->priv->model);
271         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview, TRUE , TRUE, 0);
272         gtk_widget_show (ev_dscwindow->priv->overview);
273
274         GtkWidget *sidebar_widget;
275         sidebar_widget = ev_sidebar_thumbnails_new ();
276         /*g_signal_connect (sidebar_widget,
277                           "notify::main-widget",
278                           G_CALLBACK (sidebar_page_main_widget_update_cb),
279                           ev_window);
280         sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
281         gtk_widget_show (sidebar_widget);
282         ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
283                              sidebar_widget);
284
285 /*      ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
286                         GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
287         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
288
289
290         ev_dscwindow->priv->overview = ev_view_new ();
291         ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
292         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
293
294         ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
295         ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
296         ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
297
298         GtkWidget *e = gtk_expander_new (_("Expensive features"));
299         gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
300
301         GtkWidget *t = gtk_toolbar_new ();
302
303         GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
304         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
305         gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
306         g_signal_connect (b_switch, "clicked",
307                 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
308
309         GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
310         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
311         gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
312         g_signal_connect (b_notes, "clicked",
313                 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
314
315         GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
316         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
317         gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
318         g_signal_connect (b_close, "clicked",
319                 G_CALLBACK (ev_dscwindow_end), NULL);
320
321         gtk_container_add (GTK_CONTAINER (e), t);
322         gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
323         gtk_paned_add1 (GTK_PANED (h), v);
324
325         ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
326                 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
327         gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
328
329         ev_dscwindow->priv->notesview = ev_view_new ();
330         g_object_ref (ev_dscwindow->priv->notesview);
331         gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
332                 ev_dscwindow->priv->notesview);
333         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
334         gtk_widget_show_all (h);
335         gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
336
337 /* fallback if we have >2 monitors (see window placement) */
338 /*+     gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
339 +
340 +
341 +       /* This would just open new windows. */
342 /*+     gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
343 +       gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
344 +
345 +       gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
346 +       gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
347 +       g_signal_connect (priv->notesview, "button-press-event",
348 +                         G_CALLBACK (ev_dscwindow_notes_clicked), self);
349 */
350 }
351
352
353 static void
354 ev_dscwindow_dispose (GObject *obj)
355 {
356         EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
357         EvDSCWindowPrivate *priv = ev_dscwindow->priv;
358
359 //      if (EV_IS_VIEW (priv->overview) {
360 //              ev_document_model_set_document (priv->model, NULL);
361
362 //              ev_view_set_document (EV_VIEW (priv->overview),  NULL);
363 //              g_object_unref (priv->overview);
364 //      }
365 //      if (EV_IS_VIEW (priv->notesview)) {
366 //              ev_view_set_document (EV_VIEW (priv->notesview), NULL);
367 //              g_object_unref (priv->notesview);
368 //      }
369 /*TODO: save fulscreen state*/
370         ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), 0);
371
372         if (priv->moveback_monitor >= 0) {
373                 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
374                 GdkRectangle coords;
375
376                 gdk_screen_get_monitor_geometry (
377                         gtk_window_get_screen (presentation_window),
378                         priv->moveback_monitor, &coords);
379
380                 gtk_window_move (presentation_window, coords.x, coords.y);
381         }
382
383         G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
384 }
385
386 static void
387 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
388 {
389         GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
390         /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
391         g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
392         g_object_class->dispose  = ev_dscwindow_dispose;
393 }
394
395 GtkWidget *
396 ev_dscwindow_new (void)
397 {
398         EvDSCWindow *ev_dscwindow;
399
400         ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
401         return GTK_WIDGET (ev_dscwindow);
402 }