Battery code draft 43/103243/2
authorMichal Skorupinski <m.skorupinsk@samsung.com>
Wed, 7 Dec 2016 18:54:16 +0000 (19:54 +0100)
committerRadek Kintop <r.kintop@samsung.com>
Mon, 12 Dec 2016 18:05:23 +0000 (19:05 +0100)
Change-Id: I36f51c6d47d92c4a140f33b3c1bfb8e744225687
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
packaging/org.tizen.setting.spec
setting-smartmanager/smartmanager-battery/CMakeLists.txt
setting-smartmanager/smartmanager-battery/src/smartmanager-battery-main.c

index 912053ba95cf4020efeaeab8560bb049772677e5..9fbfc7458245d7b6460f52f5e282fca879d7f56f 100755 (executable)
@@ -84,6 +84,7 @@ BuildRequires:  pkgconfig(tts)
 BuildRequires:  pkgconfig(tts-setting)
 BuildRequires:  pkgconfig(ui-gadget-1)
 BuildRequires:  pkgconfig(vconf)
+BuildRequires: pkgconfig(context)
 BuildRequires:  libcap-devel
 BuildRequires:  cmake
 BuildRequires:  edje-tools
index 1a0044c941793837ab9f0fc5f3d342d01f516fe7..f9b66b34d7daa0dd30926735fc4d81f4b5d4c114 100644 (file)
@@ -19,7 +19,8 @@ pkg_check_modules(pkgs_smartmanager_battery REQUIRED
        pkgmgr
        storage
        ui-gadget-1
-       vconf)
+       vconf
+       context)
 
 FOREACH(flag ${pkgs_smartmanager_battery_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 7f60195d74bee4fb7775651b526d63744f70eae8..3803c208e1cb23fb03727e3565d58024ff23c678 100755 (executable)
@@ -19,6 +19,7 @@
 //#include <appsvc.h>
 #include <efl_extension.h>
 #include <device/battery.h>
+#include <context_history.h>
 
 #include "smartmanager-battery.h"
 #include "smartmanager-battery-main.h"
@@ -142,33 +143,106 @@ static void _battery_usage_details_list(void * data)
        SmartMgrBattery *ad = data;
        ret_if(NULL == data);
 
-       setting_create_Gendial_field_def(
-                       ad->md.genlist,
-                       &(ad->itc_layout2),
-                       NULL,
-                       ad,
-                       SWALLOW_Type_LAYOUT_SLIDER,
-                       "/usr/share/icons/default/small/org.tizen.setting.png",
-                       "/usr/apps/org.tizen.setting/res/icons/org.tizen.setting.png",
-                       15,
-                       "Application 2",
-                       "25%",
-                       NULL);
+//     setting_create_Gendial_field_def(
+//                     ad->md.genlist,
+//                     &(ad->itc_layout2),
+//                     NULL,
+//                     ad,
+//                     SWALLOW_Type_LAYOUT_SLIDER,
+//                     "/usr/share/icons/default/small/org.tizen.setting.png",
+//                     "/usr/apps/org.tizen.setting/res/icons/org.tizen.setting.png",
+//                     15,
+//                     "Application 2",
+//                     "25%",
+//                     NULL);
+//
+//     setting_create_Gendial_field_def(
+//                     ad->md.genlist,
+//                             &(ad->itc_layout2),
+//                             NULL,
+//                             NULL,
+//                             SWALLOW_Type_LAYOUT_SLIDER,
+//                             "/usr/apps/org.tizen.setting/res/icons/org.tizen.setting.png",
+//                             NULL,
+//                             0,
+//                             "Applic 3",
+//                             "38%",
+//                             NULL);
+
+       context_history_h handle;
+       context_history_filter_h filter;
+       context_history_list_h list;
+
+       int ret =  context_history_create(&handle);
+       if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_create error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
 
-       setting_create_Gendial_field_def(
-                       ad->md.genlist,
-                               &(ad->itc_layout2),
-                               NULL,
-                               NULL,
-                               SWALLOW_Type_LAYOUT_SLIDER,
-                               "/usr/apps/org.tizen.setting/res/icons/org.tizen.setting.png",
-                               NULL,
-                               0,
-                               "Applic 3",
-                               "38%",
-                               NULL);
+       ret = context_history_filter_create(&filter);
+       if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_filter_create() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
 
+       ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);
+       if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] () error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       ret = context_history_get_list(handle, CONTEXT_HISTORY_BATTERY_USAGE, filter, &list);
+       if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_get_list() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       int i;
+       int count = 0;
+       context_history_record_h record;
+       char *value = NULL;
+       double amount;
+
+       ret = context_history_list_get_count(list, &count);
+       if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_get_list() error: %s", __FILE__, __LINE__, get_error_message(ret));
+               return;
+       }
+
+       for (i = 0; i < count; ++i) {
+               ret = context_history_list_get_current(list, &record);
+               if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_list_get_current() error: %s", __FILE__, __LINE__, get_error_message(ret));
+                       continue;
+               }
+
+               ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &value);
+               if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_list_get_current() error: %s", __FILE__, __LINE__, get_error_message(ret));
+                       continue;
+               }
+
+               ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
+               if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_list_get_current() error: %s", __FILE__, __LINE__, get_error_message(ret));
+                       continue;
+               }
+
+               ret = context_history_list_move_next(list);
+               if (ret != CONTEXT_HISTORY_ERROR_NONE) {
+                       dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] context_history_list_move_next() error: %s", __FILE__, __LINE__, get_error_message(ret));
+                       continue;
+               }
+
+               SETTING_TRACE("<MS> APP: %s %g", value, amount);
+               free(value);
+
+               context_history_record_destroy(record);
+       }
 
+       context_history_filter_destroy(filter);
+       context_history_list_destroy(list);
+       context_history_destroy(handle);
 }
 
 static int battery_main_create(void *data)