summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2014-09-24 17:10:45 +0100
committerTom Hacohen <tom@stosb.com>2014-09-24 17:10:45 +0100
commit141437aad7fb43726e0e024535da215892b5686e (patch)
treee1cabd8c6db7b2d08890e8f53391f06b7c4c0189
parentfe5e09784fc001438ec078a2655f64c63659601a (diff)
Add basic countdown support.
-rw-r--r--src/bin/main.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 0d525b1..ee255ba 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -23,9 +23,12 @@ typedef struct _Gifter_Win {
23typedef struct _Gifter_Context { 23typedef struct _Gifter_Context {
24 Gifter_Win main, preview; 24 Gifter_Win main, preview;
25 Eina_Stringshare *filename; 25 Eina_Stringshare *filename;
26 Ecore_Timer *countdown;
27 double ratio;
26 int page; 28 int page;
27 int num_pages; 29 int num_pages;
28 double ratio; 30 int total_time; /* Seconds */
31 int remaining_time; /* Seconds */
29} Gifter_Context; 32} Gifter_Context;
30 33
31static Gifter_Context ctx; 34static Gifter_Context ctx;
@@ -41,6 +44,47 @@ my_win_del(void *data, Evas_Object *obj, void *event_info)
41 elm_exit(); 44 elm_exit();
42} 45}
43 46
47static Eina_Bool
48_countdown_timer_tick(void *data EINA_UNUSED)
49{
50 char buf[20];
51
52 ctx.remaining_time--;
53
54 int abs_time = abs(ctx.remaining_time);
55
56 snprintf(buf, sizeof(buf), "%s%02d:%02d:%02d",
57 (ctx.remaining_time > 0) ? "" : "-",
58 abs_time / 60 / 60,
59 (abs_time / 60) % 60,
60 abs_time % 60);
61
62 eo_do(ctx.preview.layout, elm_obj_widget_part_text_set("countdown_text", buf));
63 return ECORE_CALLBACK_RENEW;
64}
65
66static void
67_countdown_timer_start(void)
68{
69 /* FIXME: Timer ticks are not guarenteed, better to keep track of time too. */
70 double interval = 1.0;
71
72 if (ctx.countdown)
73 {
74 eo_do(ctx.countdown, ecore_obj_timer_reset());
75 }
76 else
77 {
78 ctx.countdown = eo_add(ECORE_TIMER_CLASS, ctx.preview.win,
79 ecore_obj_timer_constructor(interval, _countdown_timer_tick, NULL));
80 }
81
82 ctx.remaining_time = ctx.total_time + 1;
83 _countdown_timer_tick(NULL);
84
85 eo_unref(ctx.countdown);
86}
87
44static void 88static void
45_pdf_page_set(int page) 89_pdf_page_set(int page)
46{ 90{
@@ -258,6 +302,9 @@ main(int argc, char *argv[])
258 elm_app_info_set(main, "gifter", "themes/default.edj"); 302 elm_app_info_set(main, "gifter", "themes/default.edj");
259 303
260 304
305 /* FIXME: Actually load it from somewhere */
306 ctx.total_time = 50 * 60; /* 50 minutes. */
307
261 ctx.filename = eina_stringshare_add(argv[optind]); 308 ctx.filename = eina_stringshare_add(argv[optind]);
262 DBG("Opening filename: '%s'", ctx.filename); 309 DBG("Opening filename: '%s'", ctx.filename);
263 310
@@ -279,6 +326,8 @@ main(int argc, char *argv[])
279 evas_object_resize(ctx.main.win, w, h); 326 evas_object_resize(ctx.main.win, w, h);
280 evas_object_resize(ctx.preview.win, w, h); 327 evas_object_resize(ctx.preview.win, w, h);
281 328
329 _countdown_timer_start();
330
282 elm_run(); 331 elm_run();
283 332
284 gifter_cfg_shutdown(); 333 gifter_cfg_shutdown();