summaryrefslogtreecommitdiff
path: root/lib/common/ph-detail-log.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/ph-detail-log.c')
-rwxr-xr-xlib/common/ph-detail-log.c495
1 files changed, 495 insertions, 0 deletions
diff --git a/lib/common/ph-detail-log.c b/lib/common/ph-detail-log.c
new file mode 100755
index 0000000..fb81596
--- /dev/null
+++ b/lib/common/ph-detail-log.c
@@ -0,0 +1,495 @@
+/*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include "phone.h"
+#include <unicode/udat.h>
+#include <unicode/udatpg.h>
+#include <unicode/ucal.h>
+#include <unicode/ustring.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <runtime_info.h>
+
+#include "phone-common.h"
+
+enum{
+ LOG_FORMAT_TIME_12 = 0,
+ LOG_FORMAT_TIME_24,
+ LOG_FORMAT_DATE,
+ LOG_FORMAT_MAX,
+};
+
+static const char *date_time_format[] = {
+ "hm",
+ "Hm",
+ "yMMMdd",
+ "yMMMddhm",
+ "yMMMddHm",
+};
+
+static char *m_img_logtype_tbl[LOG_TYPE_MAX] = {
+ IMGDIR"/C01-4_list_icon_call.png",
+ IMGDIR"/C01-4_list_icon_vt-call.png",
+ IMGDIR"/C01-4_list_icon_sms.png",
+ IMGDIR"/C01-4_list_icon_mms.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 bool is_24hour_enabled = false;
+
+int phone_detail_log_is_call_ing_type(int type)
+{
+ switch (type) {
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
+ case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
+ case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+static int detail_log_is_voice_call_type(int type)
+{
+ switch (type) {
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
+ case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
+ case CONTACTS_PLOG_TYPE_VOICE_REJECT:
+ case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+int phone_detail_log_is_mms_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_MMS_INCOMMING
+ || type == CONTACTS_PLOG_TYPE_MMS_OUTGOING
+ || type == CONTACTS_PLOG_TYPE_MMS_BLOCKED)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+int phone_detail_log_is_sms_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_SMS_INCOMMING
+ || type == CONTACTS_PLOG_TYPE_SMS_OUTGOING
+ || type == CONTACTS_PLOG_TYPE_SMS_BLOCKED)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+int phone_detail_log_is_email_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_EMAIL_RECEIVED
+ || type == CONTACTS_PLOG_TYPE_EMAIL_SENT)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+
+static int detail_log_is_video_call_type(int type)
+{
+ switch (type) {
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
+ case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
+ case CONTACTS_PLOG_TYPE_VIDEO_REJECT:
+ case CONTACTS_PLOG_TYPE_VIDEO_BLOCKED:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+static int phone_detail_log_is_call_dial_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_VOICE_OUTGOING
+ || type == CONTACTS_PLOG_TYPE_VIDEO_OUTGOING)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static int detail_log_is_msg_out_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_MMS_OUTGOING
+ || type == CONTACTS_PLOG_TYPE_SMS_OUTGOING
+ || type == CONTACTS_PLOG_TYPE_EMAIL_SENT)
+ return TRUE;
+ else
+ return FALSE;
+
+}
+
+static int detail_log_is_call_receive_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_VOICE_INCOMMING
+ || type == CONTACTS_PLOG_TYPE_VIDEO_INCOMMING)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static int detail_log_is_msg_income_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_MMS_INCOMMING
+ || type == CONTACTS_PLOG_TYPE_SMS_INCOMMING
+ || type == CONTACTS_PLOG_TYPE_EMAIL_RECEIVED)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static int detail_log_is_call_miss_type(int type)
+{
+ switch (type) {
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
+ case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
+ case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+static int detail_log_is_call_rejected_type(int type)
+{
+ if (type == CONTACTS_PLOG_TYPE_VOICE_REJECT
+ || type == CONTACTS_PLOG_TYPE_VIDEO_REJECT)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static int detail_log_is_blocked_type(int type)
+{
+ switch (type) {
+ case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
+ case CONTACTS_PLOG_TYPE_VIDEO_BLOCKED:
+ case CONTACTS_PLOG_TYPE_SMS_BLOCKED:
+ case CONTACTS_PLOG_TYPE_MMS_BLOCKED:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+char* phone_detail_log_get_icon_type(int log_type)
+{
+ Log_Type type = -1;
+ char buf[PATH_MAX]={0};
+
+ if (TRUE == detail_log_is_voice_call_type(log_type))
+ type = LOG_TYPE_CALL;
+ else if (TRUE == detail_log_is_video_call_type(log_type))
+ type = LOG_TYPE_VIDEO_CALL;
+ else if (TRUE == phone_detail_log_is_sms_type(log_type))
+ type = LOG_TYPE_SMS_MESSAGE;
+ else if (TRUE == phone_detail_log_is_mms_type(log_type))
+ type = LOG_TYPE_MMS_MESSAGE;
+ else if (TRUE == phone_detail_log_is_email_type(log_type))
+ type = LOG_TYPE_MMS_MESSAGE;
+ else {
+ PH_DBG("error invalid type");
+ return NULL;
+ }
+ snprintf(buf, sizeof(buf), "%s", m_img_logtype_tbl[type]);
+ return strdup(buf);
+}
+
+char* phone_detail_log_get_duration_from_number(int number)
+{
+ int sec, min, hour, day;
+ struct tm tmp={0};
+ char buf[PATH_MAX]={0};
+ char buf_t[PATH_MAX]={0};
+
+ sec = number;
+ day = sec/(60*60*24);
+ sec %= (60*60*24);
+ hour = sec/(60*60);
+ sec %= (60*60);
+ min = sec/(60);
+ sec %= (60);
+ tmp.tm_mday = day;
+ tmp.tm_hour = hour;
+ tmp.tm_min = min;
+ tmp.tm_sec = sec;
+ strftime(buf_t, sizeof(buf_t), "%H:%M:%S", &tmp);
+ snprintf(buf, sizeof(buf), "%s", buf_t);
+
+ return strdup(buf_t);
+}
+
+void phone_detail_log_init_time_format(void)
+{
+ PH_FN_CALL;
+ static int already_init = FALSE;
+
+ if (!already_init) {
+ UErrorCode status = U_ZERO_ERROR;
+
+ uloc_setDefault(getenv("LC_TIME"), &status);
+ PH_DBG("phone_detail_log_init_time_format : %s", getenv("LC_TIME") );
+ already_init = TRUE;
+ }
+}
+
+void phone_detail_log_delete_date_format(UDateFormat **formatter)
+{
+ PH_FN_CALL;
+ int i;
+ for (i=LOG_FORMAT_TIME_12;i<LOG_FORMAT_MAX;i++) {
+ if (formatter[i]) {
+ udat_close(formatter[i]);
+ formatter[i] = NULL;
+ }
+ }
+}
+
+static void _ph_set_default_timezone_id()
+{
+ PH_FN_CALL;
+ UErrorCode error = U_ZERO_ERROR;
+ UChar utimezone_id [PH_TEXT_SHORT_LEN] = {0};
+ char timezone_buffer[PH_TEXT_SHORT_LEN] = {0};
+ char timezone_id[PH_TEXT_SHORT_LEN] = {0};
+
+ int timezone_str_size;
+
+ strncpy(timezone_id, vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID), sizeof(timezone_id));
+ timezone_str_size = readlink("/opt/etc/localtime", timezone_buffer, sizeof(timezone_buffer));
+
+
+ if (timezone_str_size > 0)
+ {
+ char *ptr, *sp, *zone= NULL, *city= NULL;
+ ptr = strtok_r(timezone_buffer, "/", &sp);
+
+ while((ptr = strtok_r(NULL, "/", &sp)))
+ {
+ zone = city;
+ city = ptr;
+ }
+
+ if(zone != NULL && city != NULL) {
+ if(strcmp("zoneinfo", zone) == 0)
+ sprintf(timezone_id, "%s", city);
+ else
+ sprintf(timezone_id, "%s/%s", zone, city);
+ }
+ }
+
+ else
+ {
+ PH_DBG("%s", "readlink fail");
+ }
+
+ if (*timezone_id) {
+ u_uastrncpy(utimezone_id, timezone_id, sizeof(timezone_buffer)/2);
+ ucal_setDefaultTimeZone(utimezone_id , &error);
+ }
+ else {
+ p_retm_if(NULL == timezone_id, "get timezone_id is failed(%d)", error);
+ }
+}
+
+void phone_detail_log_generate_date_format(UDateFormat **formatter)
+{
+ PH_FN_CALL;
+ UDateTimePatternGenerator *generator;
+ UErrorCode error = U_ZERO_ERROR;
+
+ int i;
+ int ret;
+ const char *locale = NULL;
+
+ _ph_set_default_timezone_id();
+
+ ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &is_24hour_enabled);
+ if (RUNTIME_INFO_ERROR_NONE != ret || false == is_24hour_enabled)
+ is_24hour_enabled = false;
+
+ locale = uloc_getDefault();
+ phone_detail_log_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);
+}
+
+char* phone_detail_log_get_icon_path_with_action(int log_type)
+{
+ char buf[PATH_MAX]={0};
+ Log_Action action = -1;
+
+ if (TRUE == phone_detail_log_is_call_dial_type(log_type) || TRUE == detail_log_is_msg_out_type(log_type))
+ action = LOG_ACTION_DIALLED;
+ else if (TRUE == detail_log_is_call_miss_type(log_type))
+ action = LOG_ACTION_MISSED;
+ else if (TRUE == detail_log_is_call_receive_type(log_type) || TRUE == detail_log_is_msg_income_type(log_type))
+ action = LOG_ACTION_RECEIVED;
+ else if (TRUE == detail_log_is_call_rejected_type(log_type))
+ action = LOG_ACTION_REJECTED;
+ else if (TRUE == detail_log_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_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 (true == is_24hour_enabled)
+ type = LOG_FORMAT_TIME_24;
+ else
+ type = LOG_FORMAT_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 *phone_detail_log_get_date(UDateFormat ** formatter, int log_time)
+{
+ return ph_log_util_get_formatted_date(formatter, log_time, PH_LOG_DATE_ONLY);
+}
+
+char *phone_detail_log_get_time(UDateFormat ** formatter, int log_time)
+{
+ return ph_log_util_get_formatted_date(formatter, log_time, PH_LOG_TIME_ONLY);;
+}
+
+
+// 0: today, 1: yesterday, 2: previous
+int phone_detail_log_get_date_type(int log_time, int log_duration)
+{
+ time_t stime;
+ struct timeval timeval;
+ struct tm *tmp;
+ int yday, cur_yday;
+
+ gettimeofday(&timeval, 0);
+ tmp = localtime(&timeval.tv_sec);
+ p_retvm_if(NULL == tmp, 2, "localtime is null");
+ cur_yday = tmp->tm_yday;
+
+ stime = log_time - log_duration;
+ tmp = localtime(&stime);
+ p_retvm_if(NULL == tmp, 2, "localtime is null");
+
+ yday = tmp->tm_yday;
+
+ if (yday == cur_yday)
+ return 0;
+ else if (yday == cur_yday-1)
+ return 1;
+ else
+ return 2;
+}
+
+int phone_detail_log_get_phonenumber_type(int number_type)
+{
+ if (number_type & CONTACTS_NUMBER_TYPE_CUSTOM) {
+ return (CTTEXT_TYPE_OTHER);
+ }
+ else if (number_type & CONTACTS_NUMBER_TYPE_CELL) {
+ if (number_type & CONTACTS_NUMBER_TYPE_HOME)
+ return (CTTEXT_TYPE_HOME2);
+ else if (number_type & CONTACTS_NUMBER_TYPE_WORK)
+ return (CTTEXT_TYPE_WORK2);
+ else
+ return (CTTEXT_TYPE_MOBILE);
+ }
+ else if (number_type & CONTACTS_NUMBER_TYPE_VOICE) {
+ if (number_type & CONTACTS_NUMBER_TYPE_HOME)
+ return (CTTEXT_TYPE_HOME);
+ else if (number_type & CONTACTS_NUMBER_TYPE_WORK)
+ return (CTTEXT_TYPE_WORK);
+ else
+ return (CTTEXT_TYPE_TELEPHONE);
+ }
+ else if (number_type & CONTACTS_NUMBER_TYPE_FAX) {
+ if (number_type & CONTACTS_NUMBER_TYPE_HOME)
+ return (CTTEXT_TYPE_FAX_HOME);
+ else if (number_type & CONTACTS_NUMBER_TYPE_WORK)
+ return (CTTEXT_TYPE_FAX_WORK);
+ else
+ return (CTTEXT_TYPE_FAX);
+ }
+ else if (number_type & CONTACTS_NUMBER_TYPE_PAGER)
+ return (CTTEXT_TYPE_PAGER);
+ else if (number_type & CONTACTS_NUMBER_TYPE_CAR)
+ return (CTTEXT_TYPE_CAR);
+ else if (number_type & CONTACTS_NUMBER_TYPE_ASSISTANT)
+ return (CTTEXT_TYPE_ASSISTANT);
+ else {
+ if (number_type == CONTACTS_NUMBER_TYPE_HOME)
+ return (CTTEXT_TYPE_HOME);
+ else if (number_type == CONTACTS_NUMBER_TYPE_WORK)
+ return (CTTEXT_TYPE_WORK);
+ else
+ return (CTTEXT_TYPE_OTHER);
+ }
+}