2.0 alpha
[apps/core/preloaded/calendar.git] / src / main.c
1 /*
2   *
3   *  Copyright 2012  Samsung Electronics Co., Ltd
4   *
5   *  Licensed under the Flora License, Version 1.0 (the "License");
6   *  you may not use this file except in compliance with the License.
7   *  You may obtain a copy of the License at
8   *
9   *       http://www.tizenopensource.org/license
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17
18
19 #include <appcore-efl.h>
20 #include <utilX.h>
21 #include <Ecore_X.h>
22 #include <ui-gadget.h>
23 #include <heynoti.h>
24 #include <vconf.h>
25 #include <vconf-keys.h>
26 #include <aul.h>
27 #include <app.h>
28
29 #include "view.h"
30 #include "detail.h"
31 #include "noti-handler.h"
32
33 #define CAL_APPSVC_PARAM_NAME AUL_K_SERVICE_NAME
34 #define CAL_APPSVC_PARAM_CALLER "caller"
35 #define CAL_APPSVC_PARAM_COUNT "count"
36 #define CAL_APPSVC_PARAM_INDEX "index"
37
38 #define NOTI_TIME_CHANGED "setting_time_changed"
39
40 static void __cal_main_setup_data(struct appdata *ad);
41 static Eina_Bool __cal_main_update_today(void *data);
42
43 static Evas_Object* __cal_main_add_base_layout(Evas_Object *win)
44 {
45         Evas_Object *ly;
46         ly = cal_util_add_layout(win, NULL);
47         if (ly) {
48                 elm_win_resize_object_add(win, ly);
49         }
50         return ly;
51 }
52
53 static void __cal_main_changed_callback(void *data)
54 {
55         CAL_FN_START;
56
57         c_ret_if(!data);
58
59         struct appdata *ad = data;
60
61         __cal_main_setup_data(ad);
62
63         if (ad->is_pause) {
64                 ad->is_update_view = EINA_TRUE;
65                 return;
66         }
67
68         cal_main_update_view(ad);
69
70         return;
71 }
72
73 static void __cal_main_set_today_tm(struct appdata *ad)
74 {
75         struct tm tm;
76
77         time_t now = time(NULL);
78         localtime_r(&now, &tm);
79         tm.tm_min = 0; // min, sec reset for mktime()
80         tm.tm_sec = 0;
81
82         ad->today_tm = tm;
83
84         tm.tm_hour = 0;
85         time_t t = mktime(&tm);
86
87         if (t == (time_t)-1) {
88                 ERR("mktime() is failed");
89                 ad->today_tmr = NULL;
90                 return;
91         }
92
93         t = t + (24 * 60 * 60) - time(NULL);
94         ad->today_tmr = ecore_timer_add((double)t, __cal_main_update_today, ad);
95 }
96
97 static Eina_Bool __cal_main_update_today(void *data)
98 {
99         c_retv_if(!data, ECORE_CALLBACK_CANCEL);
100
101         struct appdata *ad = data;
102
103         __cal_main_set_today_tm(ad);
104
105         if (ad->today_edj)
106                 edje_object_signal_emit(ad->today_edj, "update_today", "prog");
107
108         return ECORE_CALLBACK_CANCEL;
109 }
110
111 static void __cal_main_setup_data(struct appdata *ad)
112 {
113         CAL_FN_START;
114
115         __cal_main_set_today_tm(ad);
116
117         if (ad->base_tm.tm_year == 0)
118                 ad->base_tm = ad->today_tm;
119
120         int val;
121
122         int r = vconf_get_int(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, &val);
123         if (r < 0)
124                 ad->wday_start = 0;
125         else
126                 ad->wday_start = val;
127
128         r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val);
129         if (r < 0)
130                 ad->is_hour24 = 0;
131         else if( val == 1 || val == 2)
132                 ad->is_hour24 = val -1;
133         else
134                 ERR("vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &val); error");
135
136         ad->is_update_view = EINA_TRUE;
137
138         ad->acct_id = ALL_VISIBILITY_ACCOUNT;
139
140         CAL_FN_END;
141 }
142
143 static void __cal_main_time_changed_callback(void *data)
144 {
145         CAL_FN_START;
146
147         struct appdata *ad = data;
148
149         __cal_main_update_today(ad);
150 }
151
152 static int __cal_main_initialize_notification(struct appdata *ad)
153 {
154         int fd = heynoti_init();
155         c_retvm_if(fd < 0, -1, "heynoti_init() is failed(%d)", fd);
156
157         int r = heynoti_subscribe(fd, NOTI_TIME_CHANGED, __cal_main_time_changed_callback, ad);
158         if (r) {
159                 ERR("heynoti_subscribe(%d, NOTI_TIME_CHANGED) is failed(%d)", fd, r);
160                 heynoti_close(fd);
161                 return -1;
162         }
163
164         r = heynoti_attach_handler(fd);
165         if (r) {
166                 ERR("heynoti_attach_handler(%d) is failed(%d)", fd, r);
167                 heynoti_close(fd);
168                 return -1;
169         }
170
171         return fd;
172 }
173
174 static void __cal_main_timezone_vconf_changed_callback(keynode_t *node, void *user_data)
175 {
176         CAL_FN_START;
177
178         c_ret_if(!node);
179         c_ret_if(!user_data);
180
181         Eina_Bool is_lock_timezone = vconf_keynode_get_int(node);
182
183         char *text = NULL;
184
185         if (is_lock_timezone)
186                 text = vconf_get_str(CAL_VCONFKEY_LOCK_TIMEZONE_PATH);
187         else
188                 text = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
189
190         if (CAL_STRLEN(text)) {
191
192                 cal_util_set_timezone(text);
193
194                 free(text);
195
196                 cal_main_update_view(user_data);
197
198         } else
199                 ERR("vconf_get_str is failed.");
200
201         CAL_FN_END;
202 }
203
204 static void __cal_main_week_of_day_format_vconf_changed_callback(keynode_t *node, void *user_data)
205 {
206         CAL_FN_START;
207
208         c_retm_if(!node, "node is null");
209         c_retm_if(!user_data, "user_data is null");
210
211         struct appdata* ad = user_data;
212         int r = vconf_keynode_get_int(node);
213         c_retm_if(r < 0, "vconf_keynode_get_int is failed");
214
215         ad->wday_start = r;
216
217         cal_main_update_view(ad);
218
219         CAL_FN_END;
220 }
221
222 static void __cal_main_view_of_month_format_vconf_changed_callback(keynode_t *node, void *user_data)
223 {
224         CAL_FN_START;
225
226         c_retm_if(!node, "node is null");
227         c_retm_if(!user_data, "user_data is null");
228
229         struct appdata* ad = user_data;
230         int r = vconf_keynode_get_int(node);
231         c_retm_if(r < 0, "vconf_keynode_get_int is failed");
232
233         ad->is_weekly = r;
234
235         cal_main_update_view(ad);
236
237         CAL_FN_END;
238 }
239
240 static void __cal_main_view_of_display_compelete_todo_vconf_changed_callback(keynode_t *node, void *user_data)
241 {
242         CAL_FN_START;
243
244         c_retm_if(!node, "node is null");
245         c_retm_if(!user_data, "user_data is null");
246
247         struct appdata* ad = user_data;
248
249         if (CV_TODO != ad->current_view)
250                 return;
251
252         int r = vconf_keynode_get_int(node);
253         c_retm_if(r < 0, "vconf_keynode_get_int is failed");
254
255         ad->is_display_complete_todo = r;
256
257         cal_main_update_view(ad);
258
259         CAL_FN_END;
260 }
261
262 static void __cal_main_view_of_display_week_number_vconf_changed_callback(keynode_t *node, void *user_data)
263 {
264         CAL_FN_START;
265
266         c_retm_if(!node, "node is null");
267         c_retm_if(!user_data, "user_data is null");
268
269         struct appdata* ad = user_data;
270
271         if (CV_MONTH != ad->current_view && !ad->is_weekly)
272                 return;
273
274         int r = vconf_keynode_get_int(node);
275         c_retm_if(r < 0, "vconf_keynode_get_int is failed");
276
277         ad->is_display_weeknumber = r;
278
279         cal_main_update_view(ad);
280
281         CAL_FN_END;
282 }
283
284 static void __cal_main_time_format_vconf_changed_callback(keynode_t *node, void *user_data)
285 {
286         CAL_FN_START;
287
288         c_retm_if(!node, "node is null");
289         c_retm_if(!user_data, "user_data is null");
290
291         struct appdata* ad = user_data;
292
293         int r = vconf_keynode_get_int(node);
294         c_retm_if(r < 0, "vconf_keynode_get_int is failed");
295
296         ad->is_hour24 = r -1;
297
298         cal_main_update_view(ad);
299
300         CAL_FN_END;
301 }
302
303 static int __cal_main_initialize(struct appdata *ad)
304 {
305         CAL_FN_START;
306
307         c_retvm_if(!ad, -1, "ad is null");
308
309         __cal_main_setup_data(ad);
310
311         int r = CALENDAR_SVC_CONNECT();
312         c_retvm_if(r != CAL_SUCCESS, -1, "CALENDAR_SVC_CONNECT is failed(%d)", r);
313
314         cal_util_connect_pattern_generator();
315
316         cal_util_initialize_timezone();
317
318         elm_theme_extension_add(NULL, "/opt/apps/org.tizen.calendar/res/edje/theme.edj");
319
320         r = vconf_notify_key_changed(CAL_VCONFKEY_FOCUS_VIEW,__cal_main_view_of_month_format_vconf_changed_callback, ad);
321         c_warn_if (r, "vconf_notify_key_changed failed");
322
323         r = vconf_notify_key_changed(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, __cal_main_view_of_display_week_number_vconf_changed_callback, ad);
324         c_warn_if (r, "vconf_notify_key_changed failed");
325
326         r = vconf_notify_key_changed(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, __cal_main_view_of_display_compelete_todo_vconf_changed_callback, ad);
327         c_warn_if (r, "vconf_notify_key_changed failed");
328
329         r = vconf_notify_key_changed(CAL_VCONFKEY_FIRST_DAY_OF_WEEK , __cal_main_week_of_day_format_vconf_changed_callback, ad);
330         c_warn_if (r, "vconf_notify_key_changed failed");
331
332         r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224 , __cal_main_time_format_vconf_changed_callback, ad);
333         c_warn_if (r, "vconf_notify_key_changed failed");
334
335         r = vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT , __cal_main_timezone_vconf_changed_callback, ad);
336         c_warn_if (r, "vconf_notify_key_changed failed");
337
338         r = vconf_notify_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, __cal_main_timezone_vconf_changed_callback, ad);
339         c_warn_if (r, "vconf_notify_key_changed failed");
340
341         r = vconf_notify_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, __cal_main_timezone_vconf_changed_callback, ad);
342         c_warn_if (r, "vconf_notify_key_changed failed");
343
344         ad->notifd = __cal_main_initialize_notification(ad);
345         c_warn_if(ad->notifd < 0, "__cal_main_initialize_notification is failed(%d)", ad->notifd);
346
347         r = account_connect();
348         c_warn_if(r != ACCOUNT_ERROR_NONE, "account_connect is failed(%x)", r);
349
350         r = contacts_svc_connect();
351         c_warn_if(r!=CTS_SUCCESS, "contacts_svc_connect() is failed(%d)", r);
352
353         UG_INIT_EFL(ad->win, UG_OPT_INDICATOR_ENABLE);
354
355         CAL_FN_END;
356
357         return 0;
358 }
359
360 static void __cal_main_finish(struct appdata *ad)
361 {
362         ug_destroy_all();
363
364         if (ad->notifd >= 0)
365                 heynoti_close(ad->notifd);
366
367         cal_util_disconnect_pattern_generator();
368
369         int r = contacts_svc_disconnect();
370         c_warn_if(r!=CTS_SUCCESS, "contacts_svc_disconnect() is failed(%d)", r);
371
372         r = account_disconnect();
373         c_warn_if(r != ACCOUNT_ERROR_NONE, "account_connect is failed(%x)", r);
374
375         r = vconf_ignore_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_PATH, __cal_main_timezone_vconf_changed_callback);
376         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_PATH) failed");
377
378         r = vconf_ignore_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF, __cal_main_timezone_vconf_changed_callback);
379         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_LOCK_TIMEZONE_ON_OFF) failed");
380
381         r = vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT, __cal_main_timezone_vconf_changed_callback);
382         c_warn_if(r, "vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_INT) failed");
383
384         r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __cal_main_time_format_vconf_changed_callback);
385         c_warn_if(r, "vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224) failed");
386
387         r = vconf_ignore_key_changed(CAL_VCONFKEY_FIRST_DAY_OF_WEEK, __cal_main_week_of_day_format_vconf_changed_callback);
388         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_FIRST_DAY_OF_WEEK) failed");
389
390         r = vconf_ignore_key_changed(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF, __cal_main_view_of_display_compelete_todo_vconf_changed_callback);
391         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_COMPLETE_TODO_ON_OFF) failed");
392
393         r = vconf_ignore_key_changed(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF, __cal_main_view_of_display_week_number_vconf_changed_callback);
394         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_WEEK_NMUBER_ON_OFF) failed");
395
396         r = vconf_ignore_key_changed(CAL_VCONFKEY_FOCUS_VIEW, __cal_main_view_of_month_format_vconf_changed_callback);
397         c_warn_if(r, "vconf_ignore_key_changed(CAL_VCONFKEY_FOCUS_VIEW) failed");
398
399         CALENDAR_SVC_DISCONNECT();
400 }
401
402 static int __cal_main_add_naviframe(struct appdata *ad)
403 {
404         c_retvm_if(!ad, -1, "ad is null");
405
406         CAL_FN_START;
407
408         ad->nv = elm_naviframe_add(ad->base);
409         c_retvm_if(!ad->nv, -1, "elm_naviframe_add returned null");
410
411         elm_object_part_content_set(ad->base, "elm.swallow.content", ad->nv);
412
413         CAL_FN_END;
414
415         return 0;
416 }
417
418 static void __cal_main_win_profile_changed_callback(void *data, Evas_Object *obj, void *event)
419 {
420         c_ret_if(!obj);
421         c_ret_if(!data);
422
423         struct appdata *ad = data;
424         c_ret_if(!ad->base);
425
426         Evas_Object *base = ad->base;
427
428         const char *profile = elm_config_profile_get();
429         c_ret_if(!profile);
430
431         if (!CAL_STRCMP(profile, "desktop"))
432                 elm_layout_theme_set(base, "layout", "application", "noindicator");
433         else
434                 elm_layout_theme_set(base, "layout", "application", "default");
435
436         evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
437
438         elm_win_resize_object_add(obj, base);
439
440         evas_object_show(base);
441 }
442
443 static bool cal_create(void *data)
444 {
445         CAL_FN_START;
446
447         c_retvm_if(!data, false, "data is null");
448
449         struct appdata *ad = data;
450
451         // Add code by Graphics part
452         elm_config_preferred_engine_set("opengl_x11");
453
454         ad->win = cal_util_add_window(CALENDAR_PACKAGE, &ad->win_w, &ad->win_h);
455         c_retvm_if(!ad->win, false, "ad->win is null");
456
457         evas_object_smart_callback_add(ad->win, "profile,changed", __cal_main_win_profile_changed_callback, ad);
458
459         ad->bg = cal_util_add_bg(ad->win, EINA_TRUE);
460         c_retvm_if(!ad->bg, false, "ad->bg is null");
461
462         ad->base = __cal_main_add_base_layout(ad->win);
463         c_retvm_if(!ad->base, false, "ad->base is null");
464
465         int r = __cal_main_initialize(ad);
466         c_retvm_if(r, false, "__cal_main_initialize is failed(%d)", r);
467
468         r = __cal_main_add_naviframe(ad);
469         c_retvm_if(r, false, "__cal_main_add_naviframe is failed(%d)", r);
470
471         ad->calendar_facebook_id = cal_account_svc_get_facebook_calendar_id();
472
473         CAL_FN_END;
474
475         return true;
476 }
477
478 static void cal_terminate(void *data)
479 {
480         CAL_FN_START;
481
482         c_retm_if(!data, "data is null");
483
484         struct appdata *ad = data;
485
486         ug_destroy_all();
487
488         __cal_main_finish(ad);
489
490         if (ad->win)
491                 evas_object_del(ad->win);
492
493         CAL_FN_END;
494 }
495
496 static void __cal_main_raise_main_view(struct appdata *ad)
497 {
498         CAL_FN_START;
499
500         c_retm_if(!ad, "ad is null");
501
502         Elm_Object_Item* bottom = elm_naviframe_bottom_item_get(ad->nv);
503         c_ret_if(!bottom);
504
505         elm_naviframe_item_pop_to(bottom);
506
507         if (ad->main_navi_item == bottom)
508                 elm_naviframe_item_pop(ad->nv);
509
510         CAL_FN_END;
511 }
512
513 static inline void __cal_main_add_naviframe_content(struct appdata *ad)
514 {
515         CAL_FN_START;
516
517         switch (ad->request_view) {
518
519                 case CV_YEAR:
520                 case CV_MONTH:
521                 case CV_WEEK:
522                 case CV_DAY:
523                 case CV_LIST:
524                         __cal_main_raise_main_view(ad);
525                         cal_main_create_view(ad);
526                         break;
527
528                 case CV_DETAIL:
529                         cal_detail_create_view(ad,ad->base);
530                         break;
531
532                 case CV_EDIT:
533                         cal_edit_create_view(ad,ad->base);
534                         break;
535
536                 default:
537                         /* TODO: add more */
538                         break;
539         }
540
541         Evas_Object *back_button = elm_object_item_part_content_get(elm_naviframe_bottom_item_get(ad->nv), "prev_btn");
542         c_ret_if(!back_button);
543
544         elm_object_focus_allow_set(back_button, EINA_FALSE);
545
546         CAL_FN_END;
547 }
548
549 static void cal_resume(void *data)
550 {
551         CAL_FN_START;
552
553         c_retm_if(!data, "data is null");
554
555         struct appdata* ad = data;
556
557         ug_resume();
558
559         ad->is_pause = EINA_FALSE;
560
561         if (ad->is_update_view)
562                 __cal_main_changed_callback(ad);
563
564         CAL_FN_END;
565 }
566
567 static void __cal_main_select_view(service_h service, struct appdata* ad)
568 {
569         CAL_FN_START;
570
571         c_ret_if(!service);
572         c_ret_if(!ad);
573
574         char *operation = NULL;
575         char *alarm_id = NULL;
576         char *caller = NULL;
577         char *count = NULL;
578
579         ad->request_view = CV_MONTH;
580
581         int r = service_get_operation(service, &operation);
582         c_warn_if(SERVICE_ERROR_NONE != r, "service_get_opertaion is failed(%d).", r);
583
584         if (!CAL_STRCMP(operation, SERVICE_OPERATION_DEFAULT)) {
585
586                 r = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &alarm_id);
587                 c_warn_if(SERVICE_ERROR_NONE != r, "service_get_extra_data is failed(%d).", r);
588
589                 if (CAL_STRLEN(alarm_id) && (r = atoi(alarm_id))) {
590
591                         cal_noti_handler_callback(r, ad);
592
593                         ad->request_view = CV_NOTI;
594                 } else {
595
596                         r = service_get_extra_data(service, CAL_APPSVC_PARAM_CALLER, &caller);
597                         c_warn_if(SERVICE_ERROR_NONE != r, "service_get_extra_data is failed(%d).", r);
598
599                         if (!CAL_STRCMP(caller, "live")) {
600
601                                 r = service_get_extra_data(service, CAL_APPSVC_PARAM_COUNT, &count);
602                                 c_warn_if(SERVICE_ERROR_NONE != r,"service_get_extra_data is failed(%d).", r);
603
604                                 if (CAL_STRLEN(count) && atoi(count))
605                                         ad->request_view = CV_LIST;
606                                 else {
607                                         ad->request_view = CV_EDIT;
608                                         ad->cid = 0;
609                                 }
610                         }
611                 }
612         }
613
614         if (operation)
615                 free(operation);
616
617         if (alarm_id)
618                 free(alarm_id);
619
620         if (caller)
621                 free(caller);
622
623         if (count)
624                 free(count);
625 }
626
627 static void cal_pause(void *data)
628 {
629         CAL_FN_START;
630
631         c_ret_if(!data);
632
633         struct appdata* ad = data;
634
635         c_ret_if(!ad->nv);
636
637         ug_pause();
638
639         if (ad->is_aul) {
640                 ad->is_aul = EINA_FALSE;                                                                        //unset flag
641
642                 if (ad->content && elm_naviframe_top_item_get(ad->nv) != elm_naviframe_bottom_item_get(ad->nv))
643                         elm_naviframe_item_pop_to(ad->content); //pop to calendar app's content
644                 else
645                         elm_exit();                                                                                     //if there is no calendar app's contents, exit.
646
647                 ad->request_view = CV_UNKNOWN;
648         }
649
650         ad->is_pause = EINA_TRUE;
651
652         CAL_FN_END;
653 }
654
655 static void cal_service(service_h service, void *user_data)
656 {
657         CAL_FN_START;
658
659         c_ret_if(!service);
660         c_ret_if(!user_data);
661
662         struct appdata *ad = user_data;
663
664         ug_destroy_all();
665
666         __cal_main_select_view(service, ad);
667
668         if (ad->request_view == CV_NOTI)
669                 return;
670
671         if (ad->win)
672                 elm_win_activate(ad->win);
673
674         evas_object_show(ad->win);
675
676         __cal_main_add_naviframe_content(ad);
677
678         if (ad->is_landscape_mode)
679                 cal_main_update_view(ad);
680
681         CAL_FN_END;
682 }
683
684 static void cal_device_orientation(app_device_orientation_e orientation, void *user_data)
685 {
686         c_retm_if(!user_data, "user_data is null.");
687
688         struct appdata *ad = user_data;
689         int rotate_val = 0;
690         Eina_Bool is_landscape_mode = EINA_FALSE;
691         int width = 0;
692         int height = 0;
693
694         ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
695
696         switch (orientation){
697         case APP_DEVICE_ORIENTATION_0:
698                 rotate_val = 0;
699                 break;
700         case APP_DEVICE_ORIENTATION_90:
701                 rotate_val = 90;
702                 is_landscape_mode = EINA_TRUE;
703                 break;
704         case APP_DEVICE_ORIENTATION_180:
705                 rotate_val = 180;
706                 break;
707         case APP_DEVICE_ORIENTATION_270:
708                 rotate_val = 270;
709                 is_landscape_mode = EINA_TRUE;
710                 break;
711         default:
712                 break;
713         }
714
715         ad->is_landscape_mode = is_landscape_mode;
716
717         if (ad->is_landscape_mode) {
718                 ad->win_w = height;
719                 ad->win_h = width;
720         } else {
721                 ad->win_w = width;
722                 ad->win_h = height;
723         }
724
725         elm_win_rotation_set(ad->win, rotate_val);
726         cal_main_update_view(ad);
727
728
729 }
730
731 int main(int argc, char *argv[])
732 {
733         struct appdata ad;
734
735         app_event_callback_s event_callback;
736
737         event_callback.create = cal_create;
738         event_callback.terminate = cal_terminate;
739         event_callback.pause = cal_pause;
740         event_callback.resume = cal_resume;
741         event_callback.service = cal_service;
742         event_callback.low_memory = NULL;
743         event_callback.low_battery = NULL;
744         event_callback.device_orientation = cal_device_orientation;
745         event_callback.language_changed = NULL;
746         event_callback.region_format_changed = NULL;
747
748         memset(&ad, 0x0, sizeof(struct appdata));
749
750         return app_efl_main(&argc, &argv, &event_callback, &ad);
751 }