]> www.fi.muni.cz Git - evince.git/commitdiff
[dualscreen] cleanup [timer] let's call this stable
authorxbezdick <255993@mail.muni.cz>
Tue, 3 May 2011 12:26:58 +0000 (14:26 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 1 Jun 2011 11:09:22 +0000 (13:09 +0200)
shell/ev-dualscreen.c
shell/ev-presentation-timer.c

index c439e84df2612b1c9b30c291e42252d007f51b2d..0fa9782179e591efeba0be1756013fa49c6e79be 100644 (file)
@@ -108,16 +108,18 @@ static void
 ev_dscwindow_set_page (EvDSCWindow *ev_dscwindow, gint page)
 {
        guint n_pages = ev_document_get_n_pages(ev_dscwindow->priv->presentation_document);
-
        if((ev_dscwindow->priv->page == 0) && (page == 1))
-               ;
-       if((ev_dscwindow->priv->page == n_pages-1) && (page == n_pages))
-               ;
-       ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
-       ev_document_model_set_page(ev_dscwindow->priv->model, page);
-       ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
+               ev_presentation_timer_start (EV_PRESENTATION_TIMER (ev_dscwindow->priv->timer));
+       if(ev_dscwindow->priv->page != page) {
+               if(ev_view_presentation_get_current_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view)) != page);
+                       ev_view_presentation_set_page (EV_VIEW_PRESENTATION(ev_dscwindow->priv->presentation_view), page);
+               if(ev_document_model_get_page (ev_dscwindow->priv->model) != page)
+                       ev_document_model_set_page(ev_dscwindow->priv->model, page);
+               if(ev_document_model_get_page (ev_dscwindow->priv->notes_model) != page)
+                       ev_document_model_set_page(ev_dscwindow->priv->notes_model, page);
+               ev_dscwindow->priv->page = page;
+       }
        ev_presentation_timer_set_page (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), page);
-       ev_dscwindow->priv->page = page;
 }
 
 static void
@@ -360,7 +362,7 @@ ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
 static void
 ev_dscwindow_dispose (GObject *obj)
 {
-       EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
+       EvDSCWindow *ev_dscwindow = EV_DSCWINDOW (obj);
        EvDSCWindowPrivate *priv = ev_dscwindow->priv;
 
        if (priv->moveback_monitor >= 0) {
@@ -373,12 +375,12 @@ ev_dscwindow_dispose (GObject *obj)
 
                gtk_window_move (presentation_window, coords.x, coords.y);
        }
-       ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
-       /*if (priv->overview) {
-               g_object_unref (priv->overview);
-               priv->overview = NULL;
+       /*if (priv->timer) {
+               g_object_unref (priv->timer);
+               priv->timer = NULL;
        }*/
-
+       ev_presentation_timer_stop(priv->timer);
+       ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE);
        G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
 }
 
index 72a97152ac340212269827771c0e0f5acc0c821e..3b2a000dda055f636942eccb1e335bf77fb9875e 100644 (file)
 
 struct _EvPresentationTimerPrivate
 {
-       guint page;
-       guint pages;
+       gint       time;
+       gint       remaining;
+       guint      page;
+       guint      pages;
+       guint      running;
 };
 
 #define EV_PRESENTATION_TIMER_GET_PRIVATE(object) \
@@ -42,37 +45,64 @@ struct _EvPresentationTimerPrivate
 
 G_DEFINE_TYPE (EvPresentationTimer, ev_presentation_timer, GTK_TYPE_DRAWING_AREA);
 
+static gdouble
+ev_presentation_timer_progress (gdouble time, gdouble remaining)
+{
+       return remaining/(time*60);
+}
 
 static gboolean
 ev_presentation_timer_draw(GtkWidget *timer, cairo_t *cr)
 {
-  EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER(timer);
-  GtkAllocation allocation;
-  gtk_widget_get_allocation (timer, &allocation);
-  //cairo_translate(cr,allocation.x,allocation.y);
-  cairo_set_source_rgb (cr, 0, 0, 0);
-  cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
-      CAIRO_FONT_WEIGHT_NORMAL);
-  cairo_set_font_size (cr, 40);
-  guint pos = (allocation.width/ev_timer->priv->pages)*ev_timer->priv->page;
-  cairo_move_to (cr, pos, 40);
-  cairo_show_text (cr, "Disziplin ist Macht.");
-
-
+       EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER(timer);
+       GtkAllocation allocation;
+       gtk_widget_get_allocation (timer, &allocation);
+       cairo_set_source_rgb (cr, 0, 0, 0);
+       cairo_set_line_width (cr, 5);
+       guint pos = (allocation.width/ev_timer->priv->pages)*ev_timer->priv->page;
+       cairo_move_to (cr,pos,2);
+       cairo_line_to (cr,pos,allocation.height);
+       cairo_stroke (cr);
+       if(ev_timer->priv->running && ev_timer->priv->time > 0 && ev_timer->priv->remaining > 0)
+       {
+               gdouble progress = ev_presentation_timer_progress (ev_timer->priv->time, ev_timer->priv->remaining)*(allocation.width);
+               cairo_rectangle (cr, allocation.width-progress, 10, (allocation.width-(allocation.width-progress))-10, allocation.height-5);
+               cairo_stroke_preserve (cr);
+               cairo_fill(cr);
+       }
        return FALSE;
 }
 
+static gboolean
+timeout_cb (gpointer data)
+{
+       EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER(data);
+       ev_timer->priv->remaining--;
+
+       if(time >= 0 && ev_timer->priv->remaining >= 0)
+       {
+               gtk_widget_queue_draw(GTK_WIDGET(ev_timer));
+       } else
+               ev_timer->priv->running = FALSE;
+       return ev_timer->priv->running;
+}
+
 void
 ev_presentation_timer_set_pages (EvPresentationTimer *ev_timer, guint pages)
 {
-       ev_timer->priv->pages = pages;
+       ev_timer->priv->pages = pages -1;
 }
 
 void
 ev_presentation_timer_set_page (EvPresentationTimer *ev_timer, guint page)
 {
+       if (page >= ev_timer->priv->pages)
+       {
+               page = ev_timer->priv->pages;
+               ev_timer->priv->running=FALSE;
+       }
        ev_timer->priv->page = page;
-        gtk_widget_queue_draw(GTK_WIDGET(ev_timer));
+       gtk_widget_queue_draw(GTK_WIDGET(ev_timer));
 }
 
 static void
@@ -81,19 +111,36 @@ ev_presentation_timer_init (EvPresentationTimer *ev_timer)
        ev_timer->priv = EV_PRESENTATION_TIMER_GET_PRIVATE (ev_timer);
        ev_timer->priv->page = 0;
        ev_timer->priv->pages = 0;
+       ev_timer->priv->remaining = 0;
+       ev_timer->priv->time = 0;
+       ev_timer->priv->running = FALSE;
 }
 
-void                   ev_presentation_timer_start             (EvPresentationTimer *ev_timer)
+void
+ev_presentation_timer_start (EvPresentationTimer *ev_timer)
 {
+       if (ev_timer->priv->running == FALSE)
+       {
+               ev_timer->priv->remaining = (ev_timer->priv->time)*60;
+               ev_timer->priv->running = TRUE;
+               g_timeout_add_seconds (1, timeout_cb, ev_timer);
+       }
 }
 
-void                   ev_presentation_timer_stop              (EvPresentationTimer *ev_timer)
+void
+ev_presentation_timer_stop (EvPresentationTimer *ev_timer)
 {
+       ev_timer->priv->remaining = 0;
 }
 
-void                   ev_presentation_timer_set_time          (EvPresentationTimer *ev_timer,
-                                                                gint time)
+void
+ev_presentation_timer_set_time (EvPresentationTimer *ev_timer,
+                               gint time)
 {
+       if(ev_timer->priv->running)
+               ev_timer->priv->remaining = ((ev_timer->priv->remaining)/(ev_timer->priv->time)*time);
+
+       ev_timer->priv->time = (time < -1)? -1:time;
 }
 
 static void
@@ -101,10 +148,8 @@ ev_presentation_timer_class_init (EvPresentationTimerClass *klass)
 {
        GObjectClass    *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass  *widget_class = GTK_WIDGET_CLASS (klass);
-       //GtkDrawingAreaClass     *drawing_area_class = GTK_DRAWING_AREA_CLASS (klass);
        g_type_class_add_private (object_class, sizeof (EvPresentationTimerPrivate));
        widget_class->draw = ev_presentation_timer_draw;
-
        /*object_class->finalize = ev_presentation_timer_finalize;*/
 }