]> www.fi.muni.cz Git - evince.git/blob - shell/ev-dualscreen.c
[dualscreen] beta pageswitch [shell] todo change run_presentation [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         EvView *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         g_printf ("num_monitors: %d \n",num_monitors);
174         //if (num_monitors == 2) {
175                 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
176                 GdkScreen * screen = gtk_window_get_screen (presentation_window);
177                 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
178                         gtk_widget_get_window (GTK_WIDGET (presentation_window)));
179                 gint presentation_monitor = (work_monitor + 1) % 2;
180                 GdkRectangle coords;
181                 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
182                         &coords);
183
184                 gtk_window_move (presentation_window, coords.x, coords.y);
185                 //ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
186                 ev_dscwindow->priv->moveback_monitor = work_monitor;
187                 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
188         //}
189 }
190 /**
191  * ev_dscwindow_page_changed_cb: Callback to change page on all views
192  *
193  **/
194 static void
195 ev_dscwindow_page_changed_cb (EvDocumentModel *model,
196                            GParamSpec      *pspec,
197                            EvDSCWindow     *ev_dscwindow)
198 {
199         gint page = ev_document_model_get_page (model);
200         g_printf("page:%d\n",page);
201
202         ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
203 }
204 static void
205 ev_dscwindow_presentation_page_changed_cb (EvDocumentModel *model,
206                            GParamSpec      *pspec,
207                            EvDSCWindow     *ev_dscwindow)
208 {
209         gint page = ev_view_presentation_get_current_page (ev_dscwindow->priv->presentation_view);
210         ev_document_model_set_page (ev_dscwindow->priv->model, page);
211 }
212
213 /**
214  * ev_dscwindow_set_presentation: Set presentation document
215  * @presentation_window: Main window we can reuse for presentation
216  **/
217 void
218 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
219         EvWindow *presentation_window, EvDocument *document, GtkWidget *pview)
220 {
221         if (!EV_IS_WINDOW (presentation_window))
222                 return;
223
224         ev_dscwindow->priv->presentation_window = presentation_window;
225         ev_dscwindow->priv->presentation_document = document;
226         ev_dscwindow->priv->presentation_view = pview;
227         g_signal_connect (ev_dscwindow->priv->presentation_view,
228                           "notify::page",
229                           G_CALLBACK (ev_dscwindow_presentation_page_changed_cb),
230                           ev_dscwindow);
231         ev_document_model_set_document(ev_dscwindow->priv->model,
232                 document);
233         ev_dscwindow_window_placement (ev_dscwindow);
234 }
235
236 /**
237  * ev_dscwindow_end: Stop presentation mode.
238  */
239 static gboolean
240 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
241 {
242         gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
243         return TRUE;
244 }
245
246 /**
247 * ev_dscwindow_init: Initialize multihead presentation
248 *
249 * @ev_dscwindow: EvDSCWindow.
250 *
251 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
252 **/
253 static void
254 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
255 {
256         ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
257         ev_dscwindow->priv->moveback_monitor = -1;
258         ev_dscwindow->priv->notesdocument = NULL;
259
260         gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
261
262         GtkWidget *h = gtk_hpaned_new ();
263         GtkWidget *v = gtk_vbox_new (FALSE, 0);
264
265         ev_dscwindow->priv->model = ev_document_model_new ();
266         g_signal_connect (ev_dscwindow->priv->model,
267                           "notify::page",
268                           G_CALLBACK (ev_dscwindow_page_changed_cb),
269                           ev_dscwindow);
270         ev_dscwindow->priv->overview = ev_sidebar_new ();
271         ev_sidebar_set_model (EV_SIDEBAR (ev_dscwindow->priv->overview),
272                               ev_dscwindow->priv->model);
273         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview, TRUE , TRUE, 0);
274         gtk_widget_show (ev_dscwindow->priv->overview);
275
276         GtkWidget *sidebar_widget;
277         sidebar_widget = ev_sidebar_thumbnails_new ();
278         /*g_signal_connect (sidebar_widget,
279                           "notify::main-widget",
280                           G_CALLBACK (sidebar_page_main_widget_update_cb),
281                           ev_window);
282         sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);*/
283         gtk_widget_show (sidebar_widget);
284         ev_sidebar_add_page (EV_SIDEBAR (ev_dscwindow->priv->overview),
285                              sidebar_widget);
286
287 /*      ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
288                         GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
289         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
290
291
292         ev_dscwindow->priv->overview = ev_view_new ();
293         ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
294         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);*/
295
296         ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
297         ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
298         ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
299
300         GtkWidget *e = gtk_expander_new (_("Expensive features"));
301         gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
302
303         GtkWidget *t = gtk_toolbar_new ();
304
305         GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
306         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
307         gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
308         g_signal_connect (b_switch, "clicked",
309                 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
310
311         GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
312         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
313         gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
314         g_signal_connect (b_notes, "clicked",
315                 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
316
317         GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
318         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
319         gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
320         g_signal_connect (b_close, "clicked",
321                 G_CALLBACK (ev_dscwindow_end), NULL);
322
323         gtk_container_add (GTK_CONTAINER (e), t);
324         gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
325         gtk_paned_add1 (GTK_PANED (h), v);
326
327         ev_dscwindow->priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
328                 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
329         gtk_paned_add2 (GTK_PANED (h), ev_dscwindow->priv->notesview_scrolled_window);
330
331         ev_dscwindow->priv->notesview = ev_view_new ();
332         g_object_ref (ev_dscwindow->priv->notesview);
333         gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->notesview_scrolled_window),
334                 ev_dscwindow->priv->notesview);
335         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->notesview), ev_dscwindow->priv->model);
336         gtk_widget_show_all (h);
337         gtk_container_add (GTK_CONTAINER (ev_dscwindow), h);
338
339 /* fallback if we have >2 monitors (see window placement) */
340 /*+     gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
341 +
342 +
343 +       /* This would just open new windows. */
344 /*+     gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
345 +       gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
346 +
347 +       gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
348 +       gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
349 +       g_signal_connect (priv->notesview, "button-press-event",
350 +                         G_CALLBACK (ev_dscwindow_notes_clicked), self);
351 */
352 }
353
354
355 static void
356 ev_dscwindow_dispose (GObject *obj)
357 {
358         EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
359         EvDSCWindowPrivate *priv = ev_dscwindow->priv;
360
361 //      if (EV_IS_VIEW (priv->overview) {
362 //              ev_document_model_set_document (priv->model, NULL);
363
364 //              ev_view_set_document (EV_VIEW (priv->overview),  NULL);
365                 g_object_unref (priv->overview);
366 //      }
367 //      if (EV_IS_VIEW (priv->notesview)) {
368 //              ev_view_set_document (EV_VIEW (priv->notesview), NULL);
369 //              g_object_unref (priv->notesview);
370 //      }
371 /*TODO: save fulscreen state*/
372         ev_window_stop_presentation (priv->presentation_window, 0);
373
374         if (priv->moveback_monitor >= 0) {
375                 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
376                 GdkRectangle coords;
377
378                 gdk_screen_get_monitor_geometry (
379                         gtk_window_get_screen (presentation_window),
380                         priv->moveback_monitor, &coords);
381
382                 gtk_window_move (presentation_window, coords.x, coords.y);
383         }
384
385         G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
386 }
387
388 static void
389 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
390 {
391         GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
392         /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
393         g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
394         g_object_class->dispose  = ev_dscwindow_dispose;
395 }
396
397 GtkWidget *
398 ev_dscwindow_new (void)
399 {
400         EvDSCWindow *ev_dscwindow;
401
402         ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
403         return GTK_WIDGET (ev_dscwindow);
404 }