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
6 * Lukas Bezdicka <255993@mail.muni.cz>
8 * Evince is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Evince is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <glib/gi18n.h>
32 #include "ev-presentation-timer.h"
34 struct _EvPresentationTimerPrivate
44 #define EV_PRESENTATION_TIMER_GET_PRIVATE(object) \
45 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_PRESENTATION_TIMER, EvPresentationTimerPrivate))
47 G_DEFINE_TYPE (EvPresentationTimer, ev_presentation_timer, GTK_TYPE_DRAWING_AREA);
50 ev_presentation_timer_progress (gdouble time, gdouble remaining)
52 return remaining/(time*60);
56 ev_presentation_timer_draw(GtkWidget *timer, cairo_t *cr)
58 EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER(timer);
59 GtkAllocation allocation;
60 gtk_widget_get_allocation (timer, &allocation);
61 cairo_set_source_rgb (cr, 0, 0, 0);
62 cairo_set_line_width (cr, 5);
63 guint pos = (allocation.width/ev_timer->priv->pages)*ev_timer->priv->page;
64 cairo_move_to (cr,pos,2);
65 cairo_line_to (cr,pos,allocation.height);
67 if(ev_timer->priv->running && ev_timer->priv->time > 0 && ev_timer->priv->remaining > 0)
69 gdouble progress = ev_presentation_timer_progress (ev_timer->priv->time,
70 ev_timer->priv->remaining)*(allocation.width);
71 cairo_rectangle (cr, allocation.width-progress,
73 (allocation.width-(allocation.width-progress))-10,
75 cairo_stroke_preserve (cr);
82 timeout_cb (gpointer data)
84 EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER(data);
85 ev_timer->priv->remaining--;
87 if(time >= 0 && ev_timer->priv->remaining >= 0)
89 gtk_widget_queue_draw(GTK_WIDGET(ev_timer));
91 ev_timer->priv->running = FALSE;
92 return ev_timer->priv->running;
96 ev_presentation_timer_set_pages (EvPresentationTimer *ev_timer, guint pages)
98 if(!EV_IS_PRESENTATION_TIMER (ev_timer))
100 ev_timer->priv->pages = pages -1;
104 ev_presentation_timer_set_page (EvPresentationTimer *ev_timer, guint page)
106 if(!EV_IS_PRESENTATION_TIMER (ev_timer))
108 if (page >= ev_timer->priv->pages)
110 page = ev_timer->priv->pages;
111 ev_timer->priv->running=FALSE;
113 ev_timer->priv->page = page;
114 gtk_widget_queue_draw(GTK_WIDGET(ev_timer));
118 ev_presentation_timer_init (EvPresentationTimer *ev_timer)
120 ev_timer->priv = EV_PRESENTATION_TIMER_GET_PRIVATE (ev_timer);
121 ev_timer->priv->page = 0;
122 ev_timer->priv->pages = 0;
123 ev_timer->priv->remaining = 0;
124 ev_timer->priv->time = 0;
125 ev_timer->priv->timeout = 0;
126 ev_timer->priv->running = FALSE;
130 ev_presentation_timer_start (EvPresentationTimer *ev_timer)
132 if (!EV_IS_PRESENTATION_TIMER (ev_timer))
134 if (ev_timer->priv->running == FALSE)
136 ev_timer->priv->remaining = (ev_timer->priv->time)*60;
137 ev_timer->priv->running = TRUE;
138 ev_timer->priv->timeout = g_timeout_add_seconds (1, timeout_cb, ev_timer);
143 ev_presentation_timer_stop (EvPresentationTimer *ev_timer)
145 if (!EV_IS_PRESENTATION_TIMER (ev_timer))
147 if (priv->timeout > 0)
148 g_source_remove (priv->timeout);
149 ev_timer->priv->remaining = 0;
153 ev_presentation_timer_set_time (EvPresentationTimer *ev_timer,
156 if (!EV_IS_PRESENTATION_TIMER (ev_timer))
158 if(ev_timer->priv->running)
159 ev_timer->priv->remaining = ((ev_timer->priv->remaining)/(ev_timer->priv->time)*time);
160 ev_timer->priv->time = (time < -1)? -1:time;
164 ev_presentation_timer_dispose (GObject *gobject)
166 EvPresentationTimer *ev_timer = EV_PRESENTATION_TIMER (gobject);
167 EvPresentationTimerPrivate *priv = EV_PRESENTATION_TIMER (ev_timer)->priv;
168 if (priv->timeout > 0)
169 g_source_remove (priv->timeout);
170 G_OBJECT_CLASS (ev_presentation_timer_parent_class)->dispose (gobject);
174 ev_presentation_timer_class_init (EvPresentationTimerClass *klass)
176 GObjectClass *object_class = G_OBJECT_CLASS (klass);
177 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
178 g_type_class_add_private (object_class, sizeof (EvPresentationTimerPrivate));
179 widget_class->draw = ev_presentation_timer_draw;
180 object_class->dispose = ev_presentation_timer_dispose;
184 ev_presentation_timer_new (void)
186 EvPresentationTimer *ev_timer;
188 ev_timer = g_object_new (EV_TYPE_PRESENTATION_TIMER, NULL);
189 return GTK_WIDGET (ev_timer);