summaryrefslogtreecommitdiff
path: root/lib/details/ct-detail-activity.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/details/ct-detail-activity.c')
-rwxr-xr-xlib/details/ct-detail-activity.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/lib/details/ct-detail-activity.c b/lib/details/ct-detail-activity.c
new file mode 100755
index 0000000..bd59617
--- /dev/null
+++ b/lib/details/ct-detail-activity.c
@@ -0,0 +1,263 @@
+/*
+* 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 "phone-common.h"
+#include <account-types.h>
+#include <account.h>
+
+typedef struct
+{
+ int activity_id;
+ int contact_id;
+ int address_book_id;
+ char *acc_name;
+ char *status;
+ int time;
+ char *data;
+ char *icon_path;
+}ct_detail_activity_info;
+
+enum ACTIVITY_ITC_TYPE {
+ ACTIVITY_ITC_NUM_UTIL_BTN = 0,
+ ACTIVITY_ITC_ACTIVITY,
+ ACTIVITY_ITC_ACTIVITY_NO_IMG,
+ ACTIVITY_ITC_MAX,
+};
+
+static Elm_Genlist_Item_Class activity_itcs[] = {
+ {.item_style="detail.3icon"},
+ {.item_style="activity_list"},
+ {.item_style="activity_list_no_img"},
+};
+
+static void detail_activity_fill_genlist(ct_activity_data *cactivity_d)
+{
+ PH_FN_CALL;
+ Evas_Object *genlist;
+ Eina_List *l;
+ ct_detail_activity_info *l_info;
+
+ if (NULL == cactivity_d->activity_genlist) {
+ genlist = elm_genlist_add(cactivity_d->layout);
+ elm_object_theme_set(genlist, cactivity_d->th);
+ cactivity_d->activity_genlist = genlist;
+ evas_object_data_set(genlist, "cactivity_d", cactivity_d);
+ elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+ }
+ else {
+ genlist = cactivity_d->activity_genlist;
+ elm_genlist_clear(genlist);
+ }
+
+ EINA_LIST_FOREACH(cactivity_d->list, l, l_info) {
+ /* Temporary code need to fix l_info->data for activity image*/
+ /*
+ if (l_info->data && *l_info->data)
+ elm_genlist_item_append(genlist, &activity_itcs[ACTIVITY_ITC_ACTIVITY], l_info, NULL,
+ ELM_GENLIST_ITEM_NONE, NULL, l_info);
+ else */
+ elm_genlist_item_append(genlist, &activity_itcs[ACTIVITY_ITC_ACTIVITY_NO_IMG], l_info, NULL,
+ ELM_GENLIST_ITEM_NONE, NULL, l_info);
+ }
+}
+
+static Evas_Object *detail_activity_gl_icon_get(void *data, Evas_Object *obj, const char *part)
+{
+ ct_detail_activity_info * l_info = data;
+
+ char buf[PATH_MAX]={0};
+ Evas_Object *ic;
+
+ ic = elm_icon_add(obj);
+ p_retvm_if(NULL == ic, NULL, "elm_icon_add() return NULL");
+
+ // Temporary code need to fix l_info->data for activity image
+ if (0 == strcmp(part, "elm.icon.2")) {
+ if ('\0' == *l_info->data)
+ return NULL;
+
+ snprintf(buf, sizeof(buf), "%s", l_info->data);
+ elm_icon_file_set(ic, buf, NULL);
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ return ic;
+ }
+ else if (0 == strcmp(part, "elm.icon.1")) {
+ if (NULL == l_info->icon_path || '\0' == *l_info->icon_path)
+ return NULL;
+ elm_icon_file_set(ic, l_info->icon_path, NULL);
+ evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+ return ic;
+ }
+ else
+ return NULL;
+}
+
+static char* detail_activity_gl_label_get(void *data, Evas_Object *obj, const char *part)
+{
+ ct_detail_activity_info * activity_info = data;
+ ct_activity_data *cactivity_d;
+ cactivity_d = evas_object_data_get(obj, "cactivity_d");
+ if (0 == strcmp(part, "elm.text.1")) {
+ return SAFE_STRDUP(activity_info->status);
+ }
+ else if (0 == strcmp(part, "elm.text.2")) {
+ return phone_detail_log_get_time(cactivity_d->hformatter, activity_info->time);
+ }
+ return NULL;
+}
+
+void ct_detail_activity_create_itcs()
+{
+ activity_itcs[ACTIVITY_ITC_ACTIVITY].func.text_get = detail_activity_gl_label_get;
+ activity_itcs[ACTIVITY_ITC_ACTIVITY].func.content_get = detail_activity_gl_icon_get;
+
+ activity_itcs[ACTIVITY_ITC_ACTIVITY_NO_IMG].func.text_get = detail_activity_gl_label_get;
+ activity_itcs[ACTIVITY_ITC_ACTIVITY_NO_IMG].func.content_get = detail_activity_gl_icon_get;
+}
+
+void ct_detail_activity_load_data(ct_activity_data *cactivity_d)
+{
+ contacts_error_e err = CONTACTS_ERROR_NONE;
+ contacts_list_h list_activity = NULL;
+ contacts_record_h record_activity = NULL;
+ Eina_List *list = NULL;
+ int count = 0;
+ int i = 0;
+
+ err = phone_cts_get_list(_contacts_contact_activity._uri, _contacts_contact_activity.person_id, cactivity_d->person_id, &list_activity);
+ p_retm_if(CONTACTS_ERROR_NONE != err, "phone_cts_get_list(list_activity) Failed(%d)", err);
+
+ while (CONTACTS_ERROR_NONE == err) {
+ ct_detail_activity_info *activity_info;
+
+ err = contacts_list_get_current_record_p(list_activity, &record_activity);
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_list_get_current_record_p() Failed(%d)", err);
+ if (CONTACTS_ERROR_NONE != err) {
+ ERR("contacts_list_get_current_record_p() Failed(%d)", err);
+ break;
+ }
+ activity_info = calloc(1, sizeof(ct_detail_activity_info));
+
+ err = contacts_record_get_int(record_activity, _contacts_contact_activity.activity_id, &(activity_info->activity_id));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(id) Failed(%d)", err);
+ err = contacts_record_get_int(record_activity, _contacts_contact_activity.contact_id, &(activity_info->contact_id));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(contact_id) Failed(%d)", err);
+ err = contacts_record_get_int(record_activity, _contacts_contact_activity.address_book_id, &(activity_info->address_book_id));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(address_book_id) Failed(%d)", err);
+ err = contacts_record_get_str(record_activity, _contacts_contact_activity.source_name, &(activity_info->acc_name));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(source_name) Failed(%d)", err);
+ err = contacts_record_get_str(record_activity, _contacts_contact_activity.status, &(activity_info->status));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(status) Failed(%d)", err);
+ err = contacts_record_get_int(record_activity, _contacts_contact_activity.timestamp, &(activity_info->time));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(timestamp) Failed(%d)", err);
+ for (i = 0; i < cactivity_d->acc_cnt; i++) {
+ if (cactivity_d->acc_types[i].id == activity_info->address_book_id)
+ activity_info->icon_path = cactivity_d->acc_types[i].icon_path;
+ }
+ /* Need To Fix Facebook Sync Data*/
+ /*
+ err = contacts_record_get_str(record_activity, _contacts_contact_activity.sync_data1, &(activity_info->data));
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_record_get_int(sync_data1) Failed(%d)", err);
+ */
+
+ list = eina_list_append(list, (void*)activity_info);
+ PH_DBG("status = %s", activity_info->status);
+
+ err = contacts_list_next(list_activity);
+ if (CONTACTS_ERROR_NONE != err) {
+ ERR("contacts_list_next() Failed(%d)", err);
+ break;
+ }
+ }
+
+ err = contacts_list_destroy(list_activity, true);
+ p_warn_if(CONTACTS_ERROR_NONE != err, "contacts_list_destroy(list_activity) Failed(%d)", err);
+ cactivity_d->list = list;
+}
+
+static void detail_activity_free_list(ct_activity_data *cactivity_d)
+{
+ ct_detail_activity_info *l_info;
+
+ EINA_LIST_FREE(cactivity_d->list, l_info) {
+ if (NULL == l_info) continue;
+ free(l_info->acc_name);
+ free(l_info->status);
+ free(l_info->data);
+ free(l_info);
+ }
+ cactivity_d->list = NULL;
+}
+
+static void detail_activity_view_delete_cb(void *data, Evas *e, Evas_Object *obj,
+ void *event_info)
+{
+ ct_activity_data *cactivity_d = data;
+
+ detail_activity_free_list(cactivity_d);
+
+ if (cactivity_d->activity_genlist)
+ evas_object_del(cactivity_d->activity_genlist);
+
+ if (cactivity_d->th) {
+ elm_theme_extension_del(cactivity_d->th, DETAIL_THEME_EDJ);
+ elm_theme_free(cactivity_d->th);
+ }
+
+ free(cactivity_d);
+}
+
+static void detail_activity_back_btn_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ ct_activity_data *cactivity_d = (ct_activity_data *)data;
+ elm_naviframe_item_pop(cactivity_d->navi);
+}
+
+static void detail_activity_back_btn(ct_activity_data *cactivity_d)
+{
+ Evas_Object *back_btn;
+ back_btn = elm_button_add(cactivity_d->navi);
+ p_retm_if(NULL == back_btn, "elm_button_add() return NULL");
+ elm_object_style_set(back_btn, "naviframe/back_btn/default");
+ elm_object_item_part_content_set(cactivity_d->navi_item, "prev_btn", back_btn);
+ evas_object_smart_callback_add(back_btn, "clicked", detail_activity_back_btn_cb, cactivity_d);
+}
+
+static void detail_activity_set_navi(ct_activity_data *cactivity_d)
+{
+ p_retm_if(NULL == cactivity_d->navi_item, "navi item is NULL");
+
+ phone_navi_item_clear(cactivity_d->navi_item);
+ detail_activity_back_btn(cactivity_d);
+}
+
+void ct_detail_activity_fill_layout(ct_activity_data *cactivity_d)
+{
+ Evas_Object *layout;
+
+ layout = phone_create_base_layout(cactivity_d->navi, false);
+ cactivity_d->layout = layout;
+
+ detail_activity_fill_genlist(cactivity_d);
+ elm_object_part_content_set(layout, "elm.swallow.content", cactivity_d->activity_genlist);
+
+ cactivity_d->navi_item = elm_naviframe_item_push(cactivity_d->navi, "Activity", NULL, NULL, cactivity_d->layout, NULL);
+ elm_naviframe_item_title_visible_set(cactivity_d->navi_item, EINA_TRUE);
+ evas_object_event_callback_add(cactivity_d->layout, EVAS_CALLBACK_DEL, detail_activity_view_delete_cb, cactivity_d);
+ detail_activity_set_navi(cactivity_d);
+}