tizen 2.4 release accepted/tizen_2.4_mobile tizen_2.4 accepted/tizen/2.4/mobile/20151029.034140 submit/tizen_2.4/20151028.063817 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:29:33 +0000 (16:29 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:29:33 +0000 (16:29 +0900)
src/appcore-watch-i18n.c
src/appcore-watch.c
src/watch_app_main.c

index 9fd2e44..9ddcc16 100755 (executable)
@@ -30,9 +30,6 @@
 #include "appcore-watch-log.h"
 #include "appcore-watch-internal.h"
 
-#define BASE_LANG "en_GB.UTF-8"
-#define CSC_DEFAULT_INI "/opt/system/csc-default/data/csc-default-data.ini"
-
 #define PKGNAME_MAX 256
 #define PATH_APP_ROOT "/opt/usr/apps"
 #define PATH_RO_APP_ROOT "/usr/apps"
index 4444be0..6371f1d 100755 (executable)
@@ -86,6 +86,7 @@ enum sys_event {
        SE_LOWBAT,
        SE_LANGCHG,
        SE_REGIONCHG,
+       SE_TIMECHG,
        SE_MAX
 };
 
@@ -120,6 +121,7 @@ static enum watch_core_event to_ae[SE_MAX] = {
        WATCH_CORE_EVENT_REGION_CHANGE,
 };
 
+static int watch_core_event_initialized[SE_MAX] = {0};
 
 enum cb_type {                 /* callback */
        _CB_NONE,
@@ -607,47 +609,74 @@ static void __vconf_cb(keynode_t *key, void *data)
        }
 }
 
-static int __add_vconf(struct watch_core *wc)
+static int __add_vconf(struct watch_core *wc, enum sys_event se)
 {
-       int i;
        int r;
 
-       for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
-               struct evt_ops *eo = &evtops[i];
-
-               switch (eo->type) {
-               case _CB_VCONF:
-                       r = vconf_notify_key_changed(eo->key.vkey, __vconf_cb, wc);
-                       if (r < 0)
-                               _E("vconf_notify_key_changed error: %d", r);
-                       break;
-               default:
-                       break;
-               }
+       switch (se) {
+       case SE_LOWMEM:
+               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb, wc);
+               break;
+       case SE_LOWBAT:
+               r = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb, wc);
+               break;
+       case SE_LANGCHG:
+               r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, wc);
+               break;
+       case SE_REGIONCHG:
+               r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb, wc);
+               break;
+       case SE_TIMECHG:
+               r = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_cb, &priv);
+               break;
+       default:
+               r = -1;
+               break;
        }
 
-       // Add a vconf key for time changed
-       r = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_cb, &priv);
-       if (r < 0)
-               _E("vconf_notify_key_changed error: %d", r);
-
-       return 0;
+       return r;
 }
 
-static int __del_vconf(void)
+static int __del_vconf(enum sys_event se)
 {
-       int i;
        int r;
 
-       for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
-               struct evt_ops *eo = &evtops[i];
+       switch (se) {
+       case SE_LOWMEM:
+               r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb);
+               break;
+       case SE_LOWBAT:
+               r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb);
+               break;
+       case SE_LANGCHG:
+               r = vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
+               break;
+       case SE_REGIONCHG:
+               r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb);
+               break;
+       case SE_TIMECHG:
+               r = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, __vconf_cb);
+               break;
+       default:
+               r = -1;
+               break;
+       }
 
-               switch (eo->type) {
-               case _CB_VCONF:
-                       r = vconf_ignore_key_changed(eo->key.vkey, __vconf_cb);
-                       break;
-               default:
-                       break;
+       return r;
+}
+
+static int __del_vconf_list(void)
+{
+       int r;
+       enum sys_event se;
+
+       for (se = SE_LOWMEM; se < SE_MAX; se++) {
+               if (watch_core_event_initialized[se]) {
+                       r = __del_vconf(se);
+                       if (r < 0)
+                               _E("Delete vconf callback failed");
+                       else
+                               watch_core_event_initialized[se] = 0;
                }
        }
 
@@ -680,6 +709,7 @@ EXPORT_API int watch_core_set_event_callback(enum watch_core_event event,
        struct watch_core *wc = &core;
        struct sys_op *op;
        enum sys_event se;
+       int r = 0;
 
        for (se = SE_UNKNOWN; se < SE_MAX; se++) {
                if (event == to_ae[se])
@@ -697,6 +727,20 @@ EXPORT_API int watch_core_set_event_callback(enum watch_core_event event,
        op->func = cb;
        op->data = data;
 
+       if (op->func && !watch_core_event_initialized[se]) {
+               r = __add_vconf(wc, se);
+               if (r < 0)
+                       _E("Add vconf callback failed");
+               else
+                       watch_core_event_initialized[se] = 1;
+       } else if (!op->func && watch_core_event_initialized[se]) {
+               r = __del_vconf(se);
+               if (r < 0)
+                       _E("Delete vconf callback failed");
+               else
+                       watch_core_event_initialized[se] = 0;
+       }
+
        return 0;
 }
 
@@ -773,8 +817,8 @@ int watch_core_init(const char *name, const struct watch_ops *ops,
        r = _set_i18n(name);
        _retv_if(r == -1, -1);
 
-       r = __add_vconf(&core);
-       if (r == -1) {
+       r = __add_vconf(&core, SE_TIMECHG);
+       if (r < 0) {
                _E("Add vconf callback failed");
                goto err;
        }
@@ -1060,7 +1104,7 @@ static void __after_loop(struct watch_priv *watch)
 
        priv.state = WS_DYING;
 
-       // Cancel the time_tick callback
+       /* Cancel the time_tick callback */
        __watch_core_time_tick_cancel();
 
        if (watch->ops && watch->ops->terminate)
@@ -1084,6 +1128,7 @@ EXPORT_API int watch_core_main(const char *appid, int argc, char **argv,
 
        r = __before_loop(&priv, argc, argv);
        if (r != 0) {
+               __del_vconf_list();
                return r;
        }
 
index d321885..d92530a 100755 (executable)
@@ -78,6 +78,7 @@ struct _watch_time_s
 #define WATCH_APP_EVENT_MAX 5
 static Eina_List *handler_list[WATCH_APP_EVENT_MAX] = {NULL, };
 static int _initialized = 0;
+static int watch_core_initialized = 0;
 
 struct app_event_handler {
        app_event_type_e type;
@@ -182,23 +183,25 @@ static int _watch_core_region_changed(void *event_info, void *data)
        return APP_ERROR_NONE;
 }
 
-
 static void _watch_core_set_appcore_event_cb(struct watch_app_context *app_context)
 {
        watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY, _watch_core_low_memory, app_context);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, _watch_core_low_battery, app_context);
        watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE, _watch_core_lang_changed, app_context);
        watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE, _watch_core_region_changed, app_context);
+
+       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, _watch_core_low_battery, app_context);
 }
 
 static void _watch_core_unset_appcore_event_cb(void)
 {
        watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_MEMORY, NULL, NULL);
-       watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, NULL, NULL);
        watch_core_set_event_callback(WATCH_CORE_EVENT_LANG_CHANGE, NULL, NULL);
        watch_core_set_event_callback(WATCH_CORE_EVENT_REGION_CHANGE, NULL, NULL);
-}
 
+       if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, NULL, NULL);
+}
 
 static int _watch_core_create(int w, int h, void *data)
 {
@@ -210,6 +213,7 @@ static int _watch_core_create(int w, int h, void *data)
                return watch_app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
        }
 
+       watch_core_initialized = 1;
        _watch_core_set_appcore_event_cb(app_context);
 
        create_cb = app_context->callback->create;
@@ -418,6 +422,12 @@ EXPORT_API int watch_app_add_event_handler(app_event_handler_h *event_handler, a
        handler->type = event_type;
        handler->cb = callback;
        handler->data = user_data;
+
+       if (watch_core_initialized
+                       && event_type == APP_EVENT_LOW_BATTERY
+                       && eina_list_count(handler_list[event_type]) == 0)
+               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, _watch_core_low_battery, NULL);
+
        handler_list[event_type] = eina_list_append(handler_list[event_type], handler);
 
        *event_handler = handler;
@@ -448,6 +458,12 @@ EXPORT_API int watch_app_remove_event_handler(app_event_handler_h event_handler)
                if (handler == event_handler) {
                        free(handler);
                        handler_list[type] = eina_list_remove_list(handler_list[type], l_itr);
+
+                       if (watch_core_initialized
+                                       && type == APP_EVENT_LOW_BATTERY
+                                       && eina_list_count(handler_list[type]) == 0)
+                               watch_core_set_event_callback(WATCH_CORE_EVENT_LOW_BATTERY, NULL, NULL);
+
                        return APP_ERROR_NONE;
                }
        }
@@ -616,7 +632,7 @@ EXPORT_API int watch_app_get_elm_win(Evas_Object **win)
                        widget_parent = evas_object_rectangle_add(e);
 
                        if (widget_parent) {
-                               ret_win = elm_win_add(widget_parent, id, ELM_WIN_TIZEN_WIDGET);
+                               ret_win = elm_win_tizen_widget_add(id, widget_parent);
                                evas_object_del(widget_parent);
                                if (!ret_win) {
                                        LOGE("win is NULL\n");