3 * Copyright 2012 Samsung Electronics Co., Ltd
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
9 * http://www.tizenopensource.org/license
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.
21 #include <appcore-efl.h>
22 #include <ui-gadget.h> /* ug_send_key_event */
30 static int heynoti_fd = -1;
31 Eina_Bool launch_by_new = EINA_FALSE; /*check wether clicked new icon*/
32 Eina_Bool is_previous_edit_view = EINA_FALSE;/*check wether previous view is edit view*/
33 Eina_Bool normal_memo_launch = EINA_FALSE;
36 static void on_time_format_update(appdata *ad)
39 Elm_Object_Item *top_it = elm_naviframe_top_item_get(ad->navigator);
40 Evas_Object *eo = elm_object_item_content_get(top_it);
42 Evas_Smart_Cb cb = evas_object_data_get(eo, "time_format_update_cb");
44 void *cb_data = evas_object_data_get(eo, "time_format_update_data");
45 cb(cb_data, NULL, NULL);
50 void memo_timezone_changed_cb(void *data)
57 on_time_format_update(ad);
61 int tzone_heynoti_init(void *data)
65 if((fd = heynoti_init()) < 0) {
68 if(heynoti_subscribe(fd, "setting_time_changed", memo_timezone_changed_cb, data)) {
71 if(heynoti_attach_handler(fd)) {
74 LOGD("tzone heynoti register success!\n");
79 void tzone_heynoti_fini()
87 heynoti_unsubscribe(fd, "setting_time_changed", memo_timezone_changed_cb);
92 static void win_del(void *data, Evas_Object *obj, void *event)
95 if(normal_memo_launch) {
96 normal_memo_launch = EINA_FALSE;
102 static void app_lang(void *data)
104 //Take necessary actions when system language setting changes
107 static void app_region(void *data)
110 //Take necessary actions when system region settings changes
112 /* time format 12/24 chanaged, update ICU */
114 /* update top view */
115 on_time_format_update(ad);
119 static Evas_Object *create_win(const char *name)
125 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
127 elm_win_title_set(eo, name);
128 elm_win_borderless_set(eo, EINA_TRUE);
129 evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
130 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
131 evas_object_resize(eo, w, h);
138 static void _on_reload_cb(void *data, Evas_Object *obj, void *event_info)
141 evas_object_del((Evas_Object *)data);
142 if(normal_memo_launch) {
143 normal_memo_launch = EINA_FALSE;
149 void on_change(keynode_t *node, void *user_data)
152 appdata *ad = (appdata *)user_data;
153 int sync = vconf_keynode_get_int(node);
155 if (ad->popup == NULL) {
156 Evas_Object *popup = elm_popup_add(ad->win_main);
157 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
158 elm_object_text_set(popup, "Memo data changed unexpectedly, close application and reload!");
159 Evas_Object *btn1 = elm_button_add(popup);
160 elm_object_text_set(btn1, MEMO_I18N_YES);
161 elm_object_part_content_set(popup, "button1", btn1);
162 evas_object_smart_callback_add(btn1, "clicked", _on_reload_cb, popup);
163 evas_object_show(popup);
170 static int app_create_delay(void *data)
173 appdata *ad = (appdata *)data;
178 win = create_win(PACKAGE);
182 normal_memo_launch = EINA_TRUE;
185 /* monitor update of memo database from external application */
187 if (vconf_get_int("memory/mobex_engine/memo_sync_status", &sync) == 0) {
188 if (sync == 1) { /* KIES syncing */
189 Evas_Object *popup = elm_popup_add(ad->win_main);
190 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
191 elm_object_text_set(popup, "Memo data changed unexpectedly, close application and reload!");
192 Evas_Object *btn1 = elm_button_add(popup);
193 elm_object_text_set(btn1, MEMO_I18N_YES);
194 elm_object_part_content_set(popup, "button1", btn1);
195 evas_object_smart_callback_add(btn1, "clicked", _on_reload_cb, popup);
196 evas_object_show(popup);
200 vconf_notify_key_changed("memory/mobex_engine/memo_sync_status", on_change, ad);
202 /* theme extension */
203 elm_theme_extension_add(NULL, EDJ_FILE);
206 elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
209 memo_ug_init(ad->win_main);
212 Evas_Object *bg = elm_bg_add(win);
213 elm_bg_color_set(bg, 0, 0, 0); /* black */
214 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215 elm_win_resize_object_add(win, bg);
216 evas_object_show(bg);
218 ad->ly_main = elm_layout_add(win);
219 elm_layout_theme_set(ad->ly_main, "layout", "application", "default");
220 evas_object_size_hint_weight_set(ad->ly_main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
221 elm_win_resize_object_add(ad->win_main, ad->ly_main);
222 evas_object_show(ad->ly_main);
225 ad->navigator = elm_naviframe_add(ad->ly_main);
226 elm_object_part_content_set(ad->ly_main, "elm.swallow.content", ad->navigator);
228 if (ad->init_view == MEMO_LIST_VIEW) {
229 memo_load_list_view(ad);
230 } else if (ad->init_view == MEMO_DETAIL_VIEW) {
231 memo_load_detail_view(ad);
232 } else if (ad->init_view == MEMO_EDIT_VIEW) {
233 memo_load_edit_view(ad);
236 /* init internationalization */
237 r = appcore_set_i18n(PACKAGE, LOCALEDIR);
245 heynoti_fd = tzone_heynoti_init(ad);
251 static bool app_create(void *data)
254 /* init memo database */
260 static void app_terminate(void *data)
263 appdata *ad = (appdata *)data;
264 /* fini memo database */
267 tzone_heynoti_fini();
269 evas_object_del(ad->win_main);
274 static void app_pause(void *data)
276 // Take necessary actions when application becomes invisible.
279 static void app_resume(void *data)
281 // Take necessary actions when application becomes visible.
284 static void app_service(service_h service, void *data)
287 appdata *ad = (appdata *)data;
289 int lanuch_by_normal = EINA_FALSE;
291 ad->init_view = MEMO_LIST_VIEW;
294 int r = service_get_operation(service, &value);
296 if (!strcmp(value, SERVICE_OPERATION_DEFAULT)) {
298 r= service_get_extra_data(service, "caller", &value);
299 if(value && !strcmp(value,"New")){
300 ad->init_view = MEMO_EDIT_VIEW;
304 launch_by_new = TRUE;
305 } else if ((value && !strcmp(value,"Normal")) || (value && !strcmp(value,"Search"))) {
306 ad->init_view = MEMO_LIST_VIEW;
310 lanuch_by_normal = EINA_TRUE;
314 if (ad->win_main != NULL) { /* memo has already launced. */
315 elm_win_activate(ad->win_main);
316 if (is_previous_edit_view && !lanuch_by_normal && launch_by_new) { /* previous view is edit view and click the new icon go the create view again*/
319 if (is_previous_edit_view && lanuch_by_normal && launch_by_new) { /*first click new ,then back and click normal memo */
320 is_previous_edit_view = EINA_FALSE;
321 launch_by_new = EINA_FALSE;
322 memo_load_list_view(ad);
326 if (ad->init_view == MEMO_EDIT_VIEW) {
327 memo_load_edit_view(ad);
330 if( normal_memo_launch ) { /* normal click memo icon in livebox*/
335 app_create_delay(ad);
336 evas_object_show(ad->win_main);
344 * The entry of the program
351 int main(int argc, char *argv[])
356 app_event_callback_s event_callback;
358 event_callback.create = app_create;
359 event_callback.terminate = app_terminate;
360 event_callback.pause = app_pause;
361 event_callback.resume = app_resume;
362 event_callback.service = app_service;
363 event_callback.low_memory = NULL;
364 event_callback.low_battery = NULL;
365 event_callback.device_orientation = NULL;
366 event_callback.language_changed = app_lang;
367 event_callback.region_format_changed = app_region;
369 memset(&ad, 0x0, sizeof(appdata));
372 return app_efl_main(&argc, &argv, &event_callback, &ad);