diff options
Diffstat (limited to 'lib/log/ph-log-utils.c')
-rwxr-xr-x | lib/log/ph-log-utils.c | 293 |
1 files changed, 13 insertions, 280 deletions
diff --git a/lib/log/ph-log-utils.c b/lib/log/ph-log-utils.c index 544b080..cc1e0e4 100755 --- a/lib/log/ph-log-utils.c +++ b/lib/log/ph-log-utils.c @@ -14,292 +14,25 @@ * limitations under the License. */ -#include <stdlib.h> -#include <unicode/udatpg.h> -#include <Elementary.h> -#include <vconf.h> -#include <appcore-efl.h> - #include "phone.h" -#include "phone-log.h" #include "ph-log-utils.h" -static char *m_img_logtype_tbl[LOG_TYPE_MAX] = { - IMGDIR"/C01-4_icon_vt-call.png", -}; - -static char *m_img_logaction_tbl[LOG_ACTION_MAX] = { - IMGDIR"/C01-4_icon_dialed.png", - IMGDIR"/C01-4_icon_missed-call.png", - IMGDIR"/C01-4_icon_received.png", - IMGDIR"/C01-4_icon_rejected.png", - IMGDIR"/C01-4_icon_Blocked(Auto-rejected).png" -}; - -static const char *date_time_format[] = { - "hm", - "Hm", - "yMMMdd", - "yMMMddhm", - "yMMMddHm", -}; - -static enum appcore_time_format time_format = APPCORE_TIME_FORMAT_12; - -// for removing build warning //////////////////////////////////// -int32_t u_strlen(const UChar *s); -UChar* u_uastrncpy(UChar *dst, const char *src, int32_t n); -char* u_austrncpy(char *dst, const UChar *src, int32_t n); -////////////////////////////////////////////////////////////////// - -int ph_log_util_del_log_by_number(char *number) -{ - if (number) - return contacts_svc_delete_phonelog(CTS_PLOG_DEL_BY_NUMBER, number); - else - return contacts_svc_delete_phonelog(CTS_PLOG_DEL_NO_NUMBER); -} - -static int log_util_is_call_dial_type(int type) -{ - if (type == CTS_PLOG_TYPE_VOICE_OUTGOING - || type == CTS_PLOG_TYPE_VIDEO_OUTGOING) - return TRUE; - else - return FALSE; -} - -static int log_util_is_call_miss_type(int type) -{ - switch (type) { - case CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN: - case CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN: - case CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN: - case CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN: - return TRUE; - default: - return FALSE; - } -} - -static int log_util_is_call_receive_type(int type) -{ - if (type == CTS_PLOG_TYPE_VOICE_INCOMMING - || type == CTS_PLOG_TYPE_VIDEO_INCOMMING) - return TRUE; - else - return FALSE; -} - -static int log_util_is_call_rejected_type(int type) -{ - if (type == CTS_PLOG_TYPE_VOICE_REJECT - || type == CTS_PLOG_TYPE_VIDEO_REJECT) - return TRUE; - else - return FALSE; -} - -static int log_util_is_voice_call_type(int type) -{ - switch (type) { - case CTS_PLOG_TYPE_VOICE_INCOMMING: - case CTS_PLOG_TYPE_VOICE_OUTGOING: - case CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN: - case CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN: - case CTS_PLOG_TYPE_VOICE_REJECT: - case CTS_PLOG_TYPE_VOICE_BLOCKED: - return TRUE; - default: - return FALSE; - } -} - -static int log_util_is_video_call_type(int type) -{ - switch (type) { - case CTS_PLOG_TYPE_VIDEO_INCOMMING: - case CTS_PLOG_TYPE_VIDEO_OUTGOING: - case CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN: - case CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN: - case CTS_PLOG_TYPE_VIDEO_REJECT: - case CTS_PLOG_TYPE_VIDEO_BLOCKED: - return TRUE; - default: - return FALSE; - } -} - -static int log_util_is_blocked_type(int type) -{ - switch (type) { - case CTS_PLOG_TYPE_VOICE_BLOCKED: - case CTS_PLOG_TYPE_VIDEO_BLOCKED: - return TRUE; - default: - return FALSE; - } -} - -char *ph_log_util_get_icon_path_with_action(int log_type) -{ - char buf[PATH_MAX]={0}; - Log_Action action = -1; - - if (TRUE == log_util_is_call_dial_type(log_type)) - action = LOG_ACTION_DIALLED; - else if (TRUE == log_util_is_call_miss_type(log_type)) - action = LOG_ACTION_MISSED; - else if (TRUE == log_util_is_call_receive_type(log_type)) - action = LOG_ACTION_RECEIVED; - else if (TRUE == log_util_is_call_rejected_type(log_type)) - action = LOG_ACTION_REJECTED; - else if (TRUE == log_util_is_blocked_type(log_type)) - action = LOG_ACTION_BLOCKED; - else { - PH_DBG("error invalid type %d", log_type); - return NULL; - } - snprintf(buf, sizeof(buf), "%s", m_img_logaction_tbl[action]); - return strdup(buf); -} - -char *ph_log_util_get_icon_type(int log_type) -{ - Log_Type type = -1; - char buf[PATH_MAX]={0}; - - if (TRUE == log_util_is_voice_call_type(log_type)) - return NULL; - else if (TRUE == log_util_is_video_call_type(log_type)) - type = LOG_TYPE_VIDEO_CALL; - else { - PH_DBG("error invalid type"); - return NULL; - } - snprintf(buf, sizeof(buf), "%s", m_img_logtype_tbl[type]); - return strdup(buf); -} - -static char *log_util_get_formatted_date(UDateFormat **formatter, int log_time, - date_style style) -{ - time_t stime; - UErrorCode status = U_ZERO_ERROR; - UDate date; - UChar formatted[64] = {0}; - int32_t formatted_size; - int32_t formatted_len; - char formatted_str[PH_TEXT_SHORT_LEN] = {0}; - int type = LOG_FORMAT_DATE; - - stime = log_time; - date = (UDate)stime * 1000; - - formatted_size = (int32_t)(sizeof(formatted)/sizeof(UChar)); - if (PH_LOG_TIME_ONLY == style) { - if (APPCORE_TIME_FORMAT_24 == time_format) - type = LOG_FORMAT_TIME_24; - else - type = LOG_FORMAT_TIME_12; - } - else if (PH_LOG_TIME_DATE == style) { - if (APPCORE_TIME_FORMAT_24 == time_format) - type = LOG_FORMAT_DATE_TIME_24; - else - type = LOG_FORMAT_DATE_TIME_12; - } - else if (PH_LOG_DATE_ONLY == style) - type = LOG_FORMAT_DATE; - formatted_len = udat_format(formatter[type], date, formatted, formatted_size, NULL, &status); - u_austrncpy(formatted_str, formatted, PH_TEXT_SHORT_LEN); - return strdup(formatted_str); -} - -char *ph_log_util_get_time_date(UDateFormat ** formatter, int log_time, int log_duration, int display_yesterday) -{ - char buf[PATH_MAX] = {0}; - time_t stime; - struct timeval timeval; - struct tm *tmp; - int yday = -1, cur_yday = -1; - - if (-1 == log_duration) - return log_util_get_formatted_date(formatter, log_time, PH_LOG_DATE_ONLY); - - gettimeofday(&timeval, 0); - tmp = localtime(&timeval.tv_sec); - if (tmp) - cur_yday = tmp->tm_yday; - - stime = log_time - log_duration; - tmp = localtime(&stime); - if (tmp) - yday = tmp->tm_yday; - - if ((0 <= yday && 0 <= cur_yday) && (yday == cur_yday || yday == cur_yday-1)) { - char *time = log_util_get_formatted_date(formatter, log_time, PH_LOG_TIME_ONLY); - if (display_yesterday && (yday == cur_yday-1)) - snprintf(buf, sizeof(buf), "%s %s", S_(PH_SYS_BODY_YESTERDAY), time); - else - snprintf(buf, sizeof(buf), "%s", time); - free(time); - } - else { - char *date = log_util_get_formatted_date(formatter, log_time, PH_LOG_TIME_DATE); - snprintf(buf, sizeof(buf), "%s", date); - free(date); - } - return strdup(buf); -} - -void ph_log_util_generate_date_format(UDateFormat **formatter) +int ph_log_util_del_log_by_id(Eina_List *list, ph_log_info *l_info) { PH_FN_CALL; - UDateTimePatternGenerator *generator; - UErrorCode error = U_ZERO_ERROR; - UChar utimezone_id [256] = {0}; - char *timezone_id = NULL; - const char *locale; - int i; - int ret; + Eina_List *l; + Elm_Object_Item *item; + int ret = CTS_SUCCESS; - timezone_id = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID); - if (timezone_id) { - u_uastrncpy(utimezone_id, timezone_id, strlen(timezone_id)); - ucal_setDefaultTimeZone(utimezone_id , &error); - free(timezone_id); + l = eina_list_data_find_list(list, l_info); + item = l_info->item; + EINA_LIST_FOREACH(l, l, l_info) { + if (item != l_info->item) + break; + ret = contacts_svc_delete_phonelog(CTS_PLOG_DEL_BY_ID, l_info->id); + if (CTS_SUCCESS != ret) + break; } - - ret = appcore_get_timeformat(&time_format); - if (ret < -1 || time_format < APPCORE_TIME_FORMAT_12) - time_format = APPCORE_TIME_FORMAT_12; - - locale = uloc_getDefault(); - ph_log_util_delete_date_format(formatter); - - generator = udatpg_open(locale, &error); - p_retm_if(NULL == generator, "udatpg_open is failed(%d)", error); - - for (i=LOG_FORMAT_TIME_12;i<LOG_FORMAT_MAX;i++) { - UChar skeleton[64]={'\0'}; - UChar best_pattern[64] = {0}; - - u_uastrncpy(skeleton, date_time_format[i], strlen(date_time_format[i])); - udatpg_getBestPattern(generator, skeleton, u_strlen(skeleton), best_pattern, - (int32_t)(sizeof(best_pattern)/sizeof(UChar)), &error); - formatter[i] = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, best_pattern, -1, &error); - } - udatpg_close(generator); + return ret; } -void ph_log_util_delete_date_format(UDateFormat **formatter) -{ - int i; - for (i=LOG_FORMAT_TIME_12;i<LOG_FORMAT_MAX;i++) { - if (formatter[i]) { - udat_close(formatter[i]); - formatter[i] = NULL; - } - } -} |