[Request]Update Flora license version
[apps/home/clock.git] / stopwatch / src / stopwatch_main.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "stopwatch_main.h"
18 #include "stopwatch_util.h"
19
20 /**********************************************************************
21 ******************define, struct ,typedef, union, enum, global val *************************************
22 ***********************************************************************/
23
24 /**********************************************************************
25 ******************Local function declear, extern function declear*************************************
26 ***********************************************************************/
27 static  void _stw_btn_update(struct appdata *ad);
28 static void _stw_panel_set(void *data);
29 static void _stw_panel_time_update(void *data, double show_time);
30 //
31 static Eina_Bool _stw_timer_cb(void *data);
32 static void _stw_lbtn_cb(void *data, Evas_Object * obj, const char *emission,
33                          const char *source);
34 static void _stw_rbtn_cb(void *data, Evas_Object * obj, const char *emission,
35                          const char *source);
36 static void _stw_backbtn_cb(void *data, Evas_Object * obj, void *event_info);
37 //
38 static char *_stw_gl_label_get(void *data, Evas_Object * obj, const char *part);
39 static Evas_Object *_stw_gl_icon_get(void *data, Evas_Object * obj,
40                                      const char *part);
41 static Eina_Bool _stw_gl_state_get(void *data, Evas_Object * obj,
42                                    const char *part);
43 static void _stw_gl_del(void *data, Evas_Object * obj);
44 static void _stw_gl_sel(void *data, Evas_Object * obj, void *event_info);
45 //
46 static void _stw_lap_cb(void *data);
47 static void _stw_stop_cb(void *data);
48 static void _stw_start_cb(void *data);
49 static void _stw_restart_cb(void *data);
50 static void _stw_reset_cb(void *data);
51 /**********************************************************************
52 ******************Global val , static global val*************************************
53 ***********************************************************************/
54 //
55 static Elm_Genlist_Item_Class g_itc = {
56         .item_style = STRING_STW_LAPLIST,
57         .func.text_get = _stw_gl_label_get,
58         .func.content_get = _stw_gl_icon_get,
59         .func.state_get = _stw_gl_state_get,
60         .func.del = _stw_gl_del,
61 };
62
63 static Edje_Color_Class g_color_class_lbtn_hl = {
64         .name = STRING_STW_LBTN_TXT_COLOR,
65         .r = 249,.g = 249,.b = 249,.a = 255,
66         .r2 = 0,.g2 = 0,.b2 = 0,.a2 = 102,
67         .r3 = 0,.g3 = 0,.b3 = 0,.a3 = 0,
68 };
69
70 static Edje_Color_Class g_color_class_rbtn_hl = {
71         .name = STRING_STW_RBTN_TXT_COLOR,
72         .r = 249,.g = 249,.b = 249,.a = 255,
73         .r2 = 0,.g2 = 0,.b2 = 0,.a2 = 102,
74         .r3 = 0,.g3 = 0,.b3 = 0,.a3 = 0,
75 };
76
77 /**********************************************************************
78 ******************Local function ref*************************************
79 ***********************************************************************/
80 /**
81  * Debug function: to update btn
82  *
83  * _stw_btn_update()
84  * @param[in] data                  Pointer to struct appdata
85  *
86  * @return      SUCCESS if success or FAILED if failed
87  */
88 static void _stw_btn_update(struct appdata *ad)
89 {
90         retm_if(NULL_CHECK(ad), "ad null");
91         switch (ad->cur_state) {
92         case STW_STATE_TYPE_RESET:
93                 {
94                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
95                                                   STRING_STW_TXT,
96                                                   STRING_STW_IDS_COM_SK_START_S_);
97                         edje_object_color_class_set(_EDJ(ad->eo_btn_lft),
98                                                     STRING_STW_LBTN_TXT_COLOR,
99                                                     249, 249, 249, 255, 0, 0, 0,
100                                                     102, 0, 0, 0, 0);
101                         edje_object_signal_emit(_EDJ(ad->eo_btn_lft),
102                                                 STRING_STW_NORMAL,
103                                                 STRING_STW_IMAGE);
104                         edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
105                                                 STRING_STW_HIDE,
106                                                 STRING_STW_RECT);
107                         edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
108                                                 STRING_STW_DIM,
109                                                 STRING_STW_IMAGE);
110                         edje_object_part_text_set(_EDJ(ad->eo_btn_rht),
111                                                   STRING_STW_TXT,
112                                                   STRING_STW_IDS_COM_BODY_RESET_S_);
113                         edje_object_color_class_set(_EDJ(ad->eo_btn_rht),
114                                                     STRING_STW_RBTN_TXT_COLOR,
115                                                     249, 249, 249, 102, 0, 0, 0,
116                                                     102, 0, 0, 0, 0);
117                         edje_object_signal_emit(_EDJ(ad->ly_main), "btn/initial", "btn/initial");
118                 }
119                 break;
120         case STW_STATE_TYPE_START:
121                 {
122                         edje_object_signal_emit(_EDJ(ad->ly_main), "btn/normal", "btn/normal");
123                         edje_object_signal_emit(_EDJ(ad->eo_btn_lft), "lbtn/running", "lbtn/running");
124                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
125                                                   STRING_STW_TXT,
126                                                   STRING_STW_IDS_COM_SK_STOP_S_);
127                         edje_object_color_class_set(_EDJ(ad->eo_btn_lft),
128                                                     STRING_STW_LBTN_TXT_COLOR,
129                                                     249, 249, 249, 255, 0, 0, 0,
130                                                     102, 0, 0, 0, 0);
131
132                         edje_object_part_text_set(_EDJ(ad->eo_btn_rht),
133                                                   STRING_STW_TXT,
134                                                   STRING_STW_IDS_SWT_BUTTON_LAP_);
135                         if (ad->lap_num < MAX_TAP_SIZE) {
136                                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
137                                                         STRING_STW_SHOW,
138                                                         STRING_STW_RECT);
139                                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
140                                                         STRING_STW_NORMAL,
141                                                         STRING_STW_IMAGE);
142                                 edje_object_color_class_set(_EDJ
143                                                             (ad->eo_btn_rht),
144                                                             STRING_STW_RBTN_TXT_COLOR,
145                                                             249, 249, 249, 255,
146                                                             0, 0, 0, 102, 0, 0,
147                                                             0, 0);
148                         } else {
149                                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
150                                                         STRING_STW_HIDE,
151                                                         STRING_STW_RECT);
152                                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
153                                                         STRING_STW_DIM,
154                                                         STRING_STW_IMAGE);
155                                 edje_object_color_class_set(_EDJ
156                                                             (ad->eo_btn_rht),
157                                                             STRING_STW_RBTN_TXT_COLOR,
158                                                             249, 249, 249, 102,
159                                                             0, 0, 0, 102, 0, 0,
160                                                             0, 0);
161                         }
162                 }
163                 break;
164         case STW_STATE_TYPE_STOP:
165                 {
166                         edje_object_signal_emit(_EDJ(ad->ly_main), "btn/normal", "btn/normal");
167                         edje_object_signal_emit(_EDJ(ad->eo_btn_lft), "lbtn/stop", "lbtn/stop");
168                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
169                                                   STRING_STW_TXT,
170                                                   STRING_STW_IDS_SWT_BUTTON_RESTART_);
171                         edje_object_color_class_set(_EDJ(ad->eo_btn_lft),
172                                                     STRING_STW_LBTN_TXT_COLOR,
173                                                     249, 249, 249, 255, 0, 0, 0,
174                                                     102, 0, 0, 0, 0);
175
176                         edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
177                                                 STRING_STW_SHOW,
178                                                 STRING_STW_RECT);
179                         edje_object_signal_emit(_EDJ(ad->eo_btn_rht),
180                                                 STRING_STW_NORMAL,
181                                                 STRING_STW_IMAGE);
182                         edje_object_part_text_set(_EDJ(ad->eo_btn_rht),
183                                                   STRING_STW_TXT,
184                                                   STRING_STW_IDS_COM_BODY_RESET_S_);
185                         edje_object_color_class_set(_EDJ(ad->eo_btn_rht),
186                                                     STRING_STW_RBTN_TXT_COLOR,
187                                                     249, 249, 249, 255, 0, 0, 0,
188                                                     102, 0, 0, 0, 0);
189                 }
190                 break;
191         default:
192                 CLK_ERR("error type");
193                 break;
194         }
195 }
196
197 /**
198  * Debug function: to set time panel: STW_PANEL_TYPE_WITHOUT_HOUR/STW_PANEL_TYPE_WITH_HOUR
199  *
200  * _stw_panel_set()
201  * @param[in] data          Pointer to struct appdata
202  *
203  * @return      void
204  */
205 static void _stw_panel_set(void *data)
206 {
207         retm_if(!data, "data null");
208         struct appdata *ad = (struct appdata *)data;
209         if (ad->eo_panel) {
210                 return;
211         }
212         //
213         char *str_panel = STRING_STW_PANEL_WITH_HOUR;
214         //del old
215         elm_object_part_content_unset(ad->ly_main, STRING_STW_TIME_PANEL);
216         EVAS_OBJECT_DELIF(ad->eo_panel);
217         //create new
218         ad->eo_panel = load_edj(ad->ly_main, EDJ_FILE, str_panel);
219         elm_object_part_content_set(ad->ly_main, STRING_STW_TIME_PANEL,
220                                     ad->eo_panel);
221 }
222
223 /**
224  * Debug function: to update time_panel
225  *
226  * _stw_panel_time_update()
227  * @param[in] data          Pointer to struct appdata
228  * @param[in] show_time     Double to show
229  *
230  * @return      void
231  */
232 static void _stw_panel_time_update(void *data, double show_time)
233 {
234         retm_if(!data, "data null");
235         struct appdata *ad = (struct appdata *)data;
236         char time_str[6] = { 0 };
237         time_t sec = stw_systime_double_to_time_t(show_time, STW_TIME_TYPE_SEC);
238         struct tm tm_show_time;
239         gmtime_r(&sec, &tm_show_time);
240 //    retm_if(!tm_show_time, "tm_show_time null");
241         time_t usec =
242             stw_systime_double_to_time_t(show_time, STW_TIME_TYPE_USEC);
243
244
245
246         // begin to display time elapsing:--> hour unit of time
247         snprintf(time_str, sizeof(time_str), "%d",
248                  (int)(tm_show_time.tm_hour / 10));
249         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_H1);
250         snprintf(time_str, sizeof(time_str), "%d",
251                  (int)(tm_show_time.tm_hour % 10));
252         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_H2);
253
254         // begin to display time elapsing:--> minute unit of time
255         snprintf(time_str, sizeof(time_str), "%d",
256                  (int)(tm_show_time.tm_min / 10));
257         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_M1);
258         snprintf(time_str, sizeof(time_str), "%d",
259                  (int)(tm_show_time.tm_min % 10));
260         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_M2);
261
262         // begin to display time elapsing:--> second unit of time
263         snprintf(time_str, sizeof(time_str), "%d",
264                  (int)(tm_show_time.tm_sec / 10));
265         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_S1);
266         snprintf(time_str, sizeof(time_str), "%d",
267                  (int)(tm_show_time.tm_sec % 10));
268         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_S2);
269
270         // begin to display time elapsing:--> microsecond unit of time
271         snprintf(time_str, sizeof(time_str), "%d", (int)(usec / 10));
272         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_SM1);
273         snprintf(time_str, sizeof(time_str), "%d", (int)(usec % 10));
274         edje_object_signal_emit(_EDJ(ad->eo_panel), time_str, STRING_STW_SM2);
275 }
276
277 /**
278  * Debug function: timer callback
279  *
280  * _stw_timer_cb()
281  * @param[in] data          Pointer to struct appdata
282  *
283  * @return      EINA_TRUE
284  */
285 static Eina_Bool _stw_timer_cb(void *data)
286 {
287         retvm_if(!data, EINA_FALSE, "data null");
288         struct appdata *ad = (struct appdata *)data;
289         double panel_time;
290         //
291         panel_time = stw_get_systime() - ad->start_time + ad->elapsed_time;
292         //frist, update panel
293         _stw_panel_time_update(ad, panel_time);
294         return EINA_TRUE;
295 }
296
297 /**
298  * Debug function: to handle main button click logic
299  * This function requires data as parameters
300  *
301  * _stw_lbtn_cb()
302  * @param[in] data                  Pointer to user data, which contains the data of application
303  * @param[in] obj                    Pointer to button object
304  * @param[in] emission             Pointer to signal
305  * @param[in] source               Pointer to the source from which signal is emitted
306  *
307  * @return      void
308  */
309 static void _stw_lbtn_cb(void *data, Evas_Object * obj, const char *emission,
310                          const char *source)
311 {
312         CLK_FUN_BEG();
313         retm_if(NULL_CHECK(data), "data null");
314         struct appdata *ad = (struct appdata *)data;
315         const char *str = NULL;
316         str = edje_object_part_text_get(obj, STRING_STW_TXT);
317         if (IS_STR_EQUAL(str, STRING_STW_IDS_COM_SK_START_S_)) {
318                 _stw_start_cb(ad);
319         } else if (IS_STR_EQUAL(str, STRING_STW_IDS_COM_SK_STOP_S_)) {
320                 _stw_stop_cb(ad);
321         } else if (IS_STR_EQUAL(str, STRING_STW_IDS_SWT_BUTTON_RESTART_)) {
322                 _stw_restart_cb(ad);
323         }
324         CLK_FUN_END();
325 }
326
327 /**
328  * Debug function: to handle main button click logic
329  * This function requires data as parameters
330  *
331  * _stw_rbtn_cb()
332  * @param[in] data                  Pointer to user data, which contains the data of application
333  * @param[in] obj                    Pointer to button object
334  * @param[in] emission             Pointer to signal
335  * @param[in] source               Pointer to the source from which signal is emitted
336  *
337  * @return      void
338  */
339 static void _stw_rbtn_cb(void *data, Evas_Object * obj, const char *emission,
340                          const char *source)
341 {
342         retm_if(NULL_CHECK(data), "data null");
343         struct appdata *ad = (struct appdata *)data;
344         const char *str = NULL;
345         str = edje_object_part_text_get(obj, STRING_STW_TXT);
346         if (IS_STR_EQUAL(str, STRING_STW_IDS_SWT_BUTTON_LAP_)) {
347                 _stw_lap_cb(ad);
348         } else if (IS_STR_EQUAL(str, STRING_STW_IDS_COM_BODY_RESET_S_)) {
349                 _stw_reset_cb(ad);
350         }
351 }
352
353 static void _stw_backbtn_cb(void *data, Evas_Object * obj, void *event_info)
354 {
355         ret_if(!data);
356         Evas_Object *win = (Evas_Object *) data;
357         elm_win_lower(win);
358 }
359
360 /**
361  * Debug function: to get label text for genlist item
362  * This function requires data, obj and part as parameters
363  *
364  * gl_label_get()
365  * @param[in] data        Pointer to user data, which contains the part text of genlist item
366  * @param[in] obj          Pointer to part object of current item
367  * @param[in] part        Pointer to part name of current item
368  *
369  * @return      char*, It is the pointer to label text.
370  */
371 static char *_stw_gl_label_get(void *data, Evas_Object * obj, const char *part)
372 {
373         struct lap_data *items = (struct lap_data *)data;
374
375         if (IS_STR_EQUAL(part, STRING_STW_INDEX)) {
376                 return strdup(items->index);
377         } else if (IS_STR_EQUAL(part, STRING_STW_LAP_TXT)) {
378                 return strdup(items->lap_data);
379         } else if (IS_STR_EQUAL(part, STRING_STW_LAP_SMALL_TXT)) {
380                 return strdup(items->lap_data_small);
381         } else if (IS_STR_EQUAL(part, "lap_text_interval")) {
382                 return strdup(items->interval_data);
383         }
384         return NULL;
385 }
386
387 /**
388  * Debug function: to get icons for genlist item
389  * This function requires data, obj and part as parameters
390  *
391  * gl_icon_get()
392  * @param[in] data        Pointer to user data, which contains the icon of genlist item
393  * @param[in] obj          Pointer to part object of current item
394  * @param[in] part        Pointer to part name of current item
395  *
396  * @return      Evas_Object*, It is the pointer to icon.
397  */
398 static Evas_Object *_stw_gl_icon_get(void *data, Evas_Object * obj,
399                                      const char *part)
400 {
401         return NULL;
402 }
403
404 /**
405  * Debug function: to get state for genlist item
406  * This function requires data, obj and part as parameters
407  *
408  * gl_state_get()
409  * @param[in] data        Pointer to user data, which contains the data of genlist item
410  * @param[in] obj          Pointer to part object of current item
411  * @param[in] part        Pointer to part name of current item
412  *
413  * @return      Eina_Bool
414  */
415 static Eina_Bool _stw_gl_state_get(void *data, Evas_Object * obj,
416                                    const char *part)
417 {
418         return EINA_FALSE;
419 }
420
421 /**
422  * Debug function: to delete the current genlist item
423  * This function requires data, obj as parameters
424  *
425  * gl_del()
426  * @param[in] data        Pointer to user data, which contains the data of genlist item
427  * @param[in] obj          Pointer to current item
428  *
429  * @return      void
430  */
431 static void _stw_gl_del(void *data, Evas_Object * obj)
432 {
433         struct lap_data *item_data = (struct lap_data *)data;
434         FREEIF(item_data);
435 }
436
437 /**
438  * Debug function: to select genlist item
439  * This function requires data, obj and event_info as parameters
440  *
441  * gl_sel()
442  * @param[in] data             Pointer to user data, which contains the data of genlist item
443  * @param[in] obj               Pointer to current item
444  * @param[in] event_info     Pointer to current item
445  *
446  * @return      void
447  */
448 static void _stw_gl_sel(void *data, Evas_Object * obj, void *event_info)
449 {
450         Elm_Object_Item *gli = (Elm_Object_Item *) (event_info);
451         elm_genlist_item_selected_set(gli, 0);
452 }
453
454 /**
455  * Debug function: to implement lap logic when lap button is pressed
456  * This function requires data as parameters
457  *
458  * _stw_lap_cb()
459  * @param[in] data                  Pointer to user data, which contains the data of application
460  *
461  * @return      void
462  */
463 static void _stw_lap_cb(void *data)
464 {
465         retm_if(!data, "data null");
466         double interval_time;
467
468         struct appdata *ad = (struct appdata *)data;
469         struct lap_data *items = CALLOC(1, struct lap_data);
470         retm_if(NULL_CHECK(items), "items null");
471
472         interval_time = ad->last_lap_time;
473         //Update lap time
474         ad->last_lap_time =
475             stw_get_systime() - ad->start_time + ad->elapsed_time;
476
477         /* The interval is the difference between the previous lap time and this
478          * lap time */
479         interval_time = ad->last_lap_time - interval_time;
480
481         time_t sec = stw_systime_double_to_time_t(interval_time, STW_TIME_TYPE_SEC);
482         time_t usec =
483             stw_systime_double_to_time_t(interval_time, STW_TIME_TYPE_USEC);
484
485         char *str_format = "%02H:%02M:%S.";
486                 //IS_EQUAL(ad->cur_panel, STW_PANEL_TYPE_WITH_HOUR) ?
487             //"%02H:%02M:%S." : "%02M:%S.";
488
489         struct tm tm_show_time;
490         gmtime_r(&sec, &tm_show_time);
491         //   retm_if(!tm_show_time, "tm_show_time null");
492         strftime(items->interval_data, sizeof(items->interval_data), str_format, &tm_show_time);
493         snprintf(items->lap_data_small, sizeof(items->lap_data_small), "%02d", (int)usec);
494
495         sec =
496             stw_systime_double_to_time_t(ad->last_lap_time, STW_TIME_TYPE_SEC);
497         char tmp_str_time[BUF_SIZE] = { 0 };
498         str_format = "%02H:%02M:%S:";
499         gmtime_r(&sec, &tm_show_time);
500         strftime(tmp_str_time, sizeof(tmp_str_time), str_format, &tm_show_time);
501
502         usec =
503             stw_systime_double_to_time_t(ad->last_lap_time, STW_TIME_TYPE_USEC);
504         snprintf(items->lap_data, sizeof(items->lap_data), "%s%02d", tmp_str_time, (int)usec);
505         ++ad->lap_num;
506         // to check terminate condition
507         if (ad->lap_num >= MAX_TAP_SIZE) {
508                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht), STRING_STW_HIDE,
509                                         STRING_STW_RECT);
510                 edje_object_signal_emit(_EDJ(ad->eo_btn_rht), STRING_STW_DIM,
511                                         STRING_STW_IMAGE);
512                 edje_object_part_text_set(_EDJ(ad->eo_btn_rht), STRING_STW_TXT,
513                                           STRING_STW_IDS_SWT_BUTTON_LAP_);
514                 edje_object_color_class_set(_EDJ(ad->eo_btn_rht),
515                                             STRING_STW_RBTN_TXT_COLOR, 255, 255,
516                                             255, 102, 0, 0, 0, 102, 0, 0, 0, 0);
517         }
518         snprintf(items->index, sizeof(items->index), "%.2d", ad->lap_num);
519         // to add a genlist item before genlist
520         Elm_Object_Item *new_item = elm_genlist_item_prepend(ad->gl, &g_itc,
521                                                              (void *)items,
522                                                              NULL,
523                                                              ELM_GENLIST_ITEM_NONE,
524                                                              _stw_gl_sel,
525                                                              NULL);
526         // show new item on the top
527         elm_genlist_item_show(new_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
528 }
529
530 /**
531  * Debug function: to implement stop logic when stop button is pressed
532  * This function requires data as parameters
533  *
534  * _stw_stop_cb()
535  * @param[in] data                  Pointer to user data, which contains the data of application
536  *
537  * @return      void
538  */
539 static void _stw_stop_cb(void *data)
540 {
541         retm_if(!data, "data null");
542         struct appdata *ad = (struct appdata *)data;
543         //
544         ad->cur_state = STW_STATE_TYPE_STOP;
545         ad->elapsed_time += stw_get_systime() - ad->start_time;
546         ecore_timer_freeze(ad->timer);
547         //
548         _stw_btn_update(ad);
549 }
550
551 /**
552  * Debug function: to implement start logic when start button is pressed
553  * This function requires data as parameters
554  *
555  * _stw_start_cb()
556  * @param[in] data                  Pointer to user data, which contains the data of application
557  *
558  * @return      void
559  */
560 static void _stw_start_cb(void *data)
561 {
562         retm_if(!data, "data null");
563         struct appdata *ad = (struct appdata *)data;
564         //
565         ad->cur_state = STW_STATE_TYPE_START;
566         ad->start_time = stw_get_systime();
567         ecore_timer_thaw(ad->timer);
568         //
569         _stw_btn_update(ad);
570 }
571
572 /**
573  * Debug function: to implement restart logic when restart button is pressed
574  * This function requires data as parameters
575  *
576  * _stw_restart_cb()
577  * @param[in] data                  Pointer to user data, which contains the data of application
578  *
579  * @return      void
580  */
581 static void _stw_restart_cb(void *data)
582 {
583         _stw_start_cb(data);
584 }
585
586 /**
587  * Debug function: to implement reset logic when reset button is pressed
588  * This function requires data as parameters
589  *
590  * _stw_reset_cb()
591  * @param[in] data                  Pointer to user data, which contains the data of application
592  *
593  * @return      void
594  */
595 static void _stw_reset_cb(void *data)
596 {
597         retm_if(!data, "data null");
598         struct appdata *ad = (struct appdata *)data;
599         //
600         ad->cur_state = STW_STATE_TYPE_RESET;
601         ad->start_time = 0;
602         ad->elapsed_time = 0;
603         ad->last_lap_time = 0;
604         ad->lap_num = 0;
605         elm_genlist_clear(ad->gl);
606         //
607         _stw_panel_time_update(ad, 0);
608         _stw_btn_update(ad);
609 }
610
611 /**********************************************************************
612 ******************Global function ref*************************************
613 ***********************************************************************/
614
615 //
616 int stw_create_main_view(struct appdata *ad)
617 {
618         ad->layout_main = widget_create_layout_empty(ad->parent);
619         ad->ly_main = load_edj(ad->layout_main, EDJ_FILE, GRP_MAIN);
620         //create button
621         ad->eo_btn_lft =
622             clk_widget_create_button(ad->layout_main, EDJ_FILE,
623                                      STRING_STW_STW_LBTN,
624                                      &g_color_class_lbtn_hl, _stw_lbtn_cb, ad);
625         elm_object_part_content_set(ad->ly_main, STRING_STW_LBTN,
626                                     ad->eo_btn_lft);
627         ad->eo_btn_rht =
628             clk_widget_create_button(ad->layout_main, EDJ_FILE,
629                                      STRING_STW_STW_RBTN,
630                                      &g_color_class_rbtn_hl, _stw_rbtn_cb, ad);
631         elm_object_part_content_set(ad->ly_main, STRING_STW_RBTN,
632                                     ad->eo_btn_rht);
633         ad->eo_btn_back =
634             widget_create_button(ad->layout_main,
635                                  STRING_STW_NAVIFRAME_END_BTN_DEFAULT, NULL,
636                                  NULL, _stw_backbtn_cb, ad->win);
637
638         //create navigation bar
639         ad->navi_bar = elm_naviframe_add(ad->layout_main);
640         ad->ei_naviframe =
641             widget_naviframe_push(ad->navi_bar,
642                                   STRING_STW_IDS_COM_BODY_STOPWATCH_S_,
643                                   ad->eo_btn_back, NULL, ad->ly_main, "tabbar",
644                                   NULL);
645         elm_naviframe_item_title_visible_set(ad->ei_naviframe, EINA_FALSE);
646         elm_object_part_content_set(ad->layout_main,
647                                     STRING_STW_SLM_SWALLOW_CONTENT,
648                                     ad->navi_bar);
649         //create genlist
650         ad->gl = elm_genlist_add(ad->ly_main);
651         elm_object_part_content_set(ad->ly_main, STRING_STW_GENLIST, ad->gl);
652         //create timer
653         ad->timer = ecore_timer_add(STW_TIMER_VALUE, _stw_timer_cb, ad);
654         ecore_timer_freeze(ad->timer);
655         //reset state
656         ad->cur_state = STW_STATE_TYPE_RESET;
657         ad->start_time = 0;
658         ad->elapsed_time = 0;
659         ad->last_lap_time = 0;
660         ad->lap_num = 0;
661         _stw_panel_set(ad);
662         _stw_btn_update(ad);
663         return SUCCESS;
664 }
665
666 int stw_update_main_view(struct appdata *ad)
667 {
668         retm_if(NULL_CHECK(ad), "ad null");
669         switch (ad->cur_state) {
670         case STW_STATE_TYPE_RESET:
671                 {
672                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
673                                                   STRING_STW_TXT,
674                                                   STRING_STW_IDS_COM_SK_START_S_);
675                         edje_object_part_text_set(_EDJ(ad->eo_btn_rht),
676                                                   STRING_STW_TXT,
677                                                   STRING_STW_IDS_COM_BODY_RESET_S_);
678                 }
679                 break;
680         case STW_STATE_TYPE_START:
681                 {
682                         
683                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
684                                                   STRING_STW_TXT,
685                                                   STRING_STW_IDS_COM_SK_STOP_S_);
686                         edje_object_part_text_set(_EDJ(ad->eo_btn_rht),
687                                                   STRING_STW_TXT,
688                                                   STRING_STW_IDS_SWT_BUTTON_LAP_);
689                         
690                 }
691                 break;
692         case STW_STATE_TYPE_STOP:
693                 {
694                         edje_object_part_text_set(_EDJ(ad->eo_btn_lft),
695                                                   STRING_STW_TXT,
696                                                   STRING_STW_IDS_SWT_BUTTON_RESTART_);
697                 }
698                 break;
699         default:
700                 CLK_ERR("error type");
701                 break;
702         }
703         return SUCCESS;
704 }
705