3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include "detail-common.h"
23 #include "external-ug.h"
25 void cal_detail_common_ctx_callback_for_voice_call(void *data, Evas_Object *obj, void *ei)
27 c_retm_if(!data, "data is null");
28 c_retm_if(!obj, "obj is null");
30 const char *num = data;
32 char telnum[255]={0,};
34 appsvc_set_operation(b, APPSVC_OPERATION_CALL);
35 snprintf(telnum, sizeof(telnum), "tel:%s", num);
36 appsvc_set_uri(b, telnum);
37 appsvc_add_data(b, "ctindex", "-1");
38 appsvc_run_service(b, 0, NULL, NULL);
42 elm_ctxpopup_dismiss(obj);
45 void cal_detail_common_ctx_callback_for_contact(void *data, Evas_Object *obj, void *ei)
47 c_retm_if(!data, "data is null");
49 c_retm_if(!obj, "obj is null");
51 const char *email = data;
54 snprintf(type, sizeof(type), "%d", 22);
55 cal_launch_ug_with_var(NULL, CAL_CONTACT_UG, NULL, "type", type, "ct_email", email, NULL);
57 elm_ctxpopup_dismiss(obj);
60 void cal_detail_common_get_person_default_number(int person_id, char **default_num)
62 c_ret_if(person_id < 0);
64 contacts_error_e error = CONTACTS_ERROR_NONE;
66 contacts_record_h person = NULL;
68 error = contacts_db_get_record(_contacts_person._uri, person_id, &person);
69 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record() is failed(%x)", error);
73 error = contacts_record_get_int(person, _contacts_person.display_contact_id, &contact_id);
74 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_int() is failed(%x)", error);
76 contacts_record_h contact = NULL;
78 error = contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
79 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record() is failed(%x)", error);
81 contacts_record_h number = NULL;
83 error = contacts_record_get_child_record_at_p(contact, _contacts_contact.number, 0, &number);
84 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_child_record_at_p() is failed(%x)", error);
86 char *default_number = NULL;
88 error = contacts_record_get_str_p(number, _contacts_number.number, &default_number);
89 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_str_p() is failed(%x)", error);
91 if (CAL_STRLEN(default_number))
92 *default_num = strdup(default_number);
94 ERR("person_id(%d)'s default number is null", person_id);
96 error = contacts_record_destroy(contact, true);
97 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
99 error = contacts_record_destroy(person, false);
100 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
103 static void __cal_detail_get_start_time(calendar_record_h record, char *buf, int sz)
110 time = CAL_UTIL_TIME_FORMAT_6;
112 time = CAL_UTIL_TIME_FORMAT_1;
116 calendar_time_s start_time = {0};
118 _calendar_get_start_time(record, &start_time);
120 _calendar_convert_calendar_time_to_tm(&start_time, &tm);
122 if (_calendar_is_allday_record(record))
123 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, NULL, &tm);
125 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, time, &tm);
128 static void __cal_detail_get_end_time(calendar_record_h record, char *buf, int sz)
135 time = CAL_UTIL_TIME_FORMAT_6;
137 time = CAL_UTIL_TIME_FORMAT_1;
141 calendar_time_s end_time = {0};
143 _calendar_get_end_time(record, &end_time);
145 _calendar_convert_calendar_time_to_tm(&end_time, &tm);
147 if (_calendar_is_allday_record(record))
148 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, NULL, &tm);
150 cal_util_get_time_text(buf, sz, CAL_UTIL_DATE_FORMAT_1, time, &tm);
153 static void __cal_detail_common_get_message_content(calendar_record_h record, char *body , int nsize)
160 char *location = NULL;
161 char start[1024] = "Start\n";
162 char end[1024] = "End\n";
163 char buf_start[1024] = {0};
164 char buf_end[1024] = {0};
167 content = _("Check this schedule, please.");
169 title = _calendar_get_summary(record);
171 location = _calendar_get_location(record);
173 __cal_detail_get_start_time(record, buf_start, sizeof(buf_start));
175 __cal_detail_get_end_time(record, buf_end, sizeof(buf_end));
177 snprintf(body, nsize, "%s\n%s\n%s\n%s%s\n%s%s",content, title, location, start, buf_start, end, buf_end);
183 void cal_detail_common_ctx_callback_for_message(void *data, Evas_Object *obj, void *ei)
188 calendar_record_h record = evas_object_data_get(obj, "record");
190 const char *num = data;
192 char message[512] = {0};
194 __cal_detail_common_get_message_content(record, message, sizeof(message));
196 cal_launch_ug_with_var(NULL, CAL_MESSAGE_COMPOSER_UG, NULL, "TO", num, "BODY", message, NULL);
198 elm_ctxpopup_dismiss(obj);
201 void cal_detail_common_ctx_callback_for_email(void *data, Evas_Object *obj, void *ei)
206 calendar_record_h record = evas_object_data_get(obj, "record");
208 const char *email = data;
210 char message[512] = {0};
212 __cal_detail_common_get_message_content(record, message, sizeof(message));
214 cal_launch_ug_with_var(NULL, CAL_EMAIL_COMPOSER_UG, NULL, "RUN_TYPE", "5", "TO", email, "BODY", message, NULL);
216 elm_ctxpopup_dismiss(obj);