2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "msg-ui-composer-data.h"
19 #include "msg-ui-composer-external.h"
20 #include "msg-ui-composer-common.h"
21 #include "msg-ui-composer-util.h"
22 #include "msg-ui-composer-popup.h"
23 #include "msg-ui-composer-body.h"
24 #include "msg-ui-composer-recipient.h"
26 #include <ui-gadget.h>
29 #include <contacts-svc.h>
30 #include <contacts-ug.h>
33 static void __msg_ui_composer_external_closed(MSG_COMPOSER_VIEW_DATA_S *cd)
37 if (cd->loaded_aul || cd->state == COMPOSER_STATE_TYPE_RUNNING) {
38 if(!msg_ui_composer_popup_exist(cd)) {
39 msg_ui_composer_last_focus_load(cd);
46 static void __ug_calllog_return_cb(struct ui_gadget *ug, bundle *result, void *priv)
50 MSG_COMPOSER_VIEW_DATA_S *cd;
52 bool bMaxCount = false;
53 bool bInvalidNum = false;
56 if (!ug || !priv || !result) {
57 D_EMSG("parameter error ug = %p, priv = %p, result = %p", ug, priv, result);
61 cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
62 D_MSG_RETM_IF(cd->recipient == NULL, "Recipient Data is NULL");
69 encoded_str = (char *)bundle_get_val(result, MSG_BUNDLE_KEY_GET_SEL_LIST);
70 list = (int *)g_base64_decode(encoded_str, (gsize *)&len);
72 for (i = 0; i < len / sizeof(int); i++) {
74 if (msg_ui_composer_recipient_count_get(cd->recipient) >= COMPOSER_RECIPIENT_COUNT_MAX) {
79 CTSvalue *plog = NULL;
80 int ret = contacts_svc_get_phonelog(list[i], &plog);
81 if (ret == CTS_SUCCESS) {
82 const char *number = contacts_svc_value_get_str(plog, CTS_PLOG_VAL_NUMBER_STR);
84 if (msg_ui_composer_recipient_duplicate_check(cd->recipient, number) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
86 contacts_svc_value_free(plog);
90 if (msg_ui_composer_recipient_vaild_check(number) == EINA_FALSE) {
94 int contact_id = contacts_svc_value_get_int(plog, CTS_PLOG_VAL_RELATED_ID_INT);
96 msg_ui_composer_recipient_append(cd->recipient, number, contact_id);
99 contacts_svc_value_free(plog);
103 D_MSG("bMaxCount = %d, bInvalidNum = %d, bDup = %d", bMaxCount, bInvalidNum, bDup);
105 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
106 } else if (bInvalidNum) {
107 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_INVALID_RECP);
109 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
116 static void __ug_layout_cb(struct ui_gadget *ug, enum ug_mode mode, void *priv)
119 MSG_COMPOSER_VIEW_DATA_S *cd;
127 cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
128 base = ug_get_layout(ug);
137 case UG_MODE_FULLVIEW:
139 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
140 elm_win_resize_object_add(ug_get_window(), base);
141 evas_object_show(base);
143 case UG_MODE_FRAMEVIEW:
152 static void __ug_closed_cb(struct ui_gadget *ug, void *priv)
156 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
159 ug_destroy(cd->loaded_ug);
160 cd->loaded_ug = NULL;
163 __msg_ui_composer_external_closed(cd);
171 struct ui_gadget * msg_ui_composer_launch_contact_detail_ug(MSG_COMPOSER_VIEW_DATA_S *cd, int ct_id)
174 D_MSG_RETVM_IF(cd == NULL, NULL, "Composer data is NULL");
176 struct ui_gadget *ug;
177 struct ug_cbs cbs = { 0, };
179 bundle *kb = bundle_create();
184 char contactId[DEF_BUF_LEN_S] = { 0, };
185 char buf[DEF_BUF_LEN_D] = { 0, };
187 snprintf(contactId, sizeof(contactId), "%d", ct_id);
188 snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_DETAIL);
190 bundle_add(kb, CT_UG_BUNDLE_TYPE, buf);
191 bundle_add(kb, CT_UG_BUNDLE_ID, contactId);
193 cbs.layout_cb = __ug_layout_cb;
194 cbs.result_cb = NULL;
195 cbs.destroy_cb = __ug_closed_cb;
198 ug = ug_create(cd->ug, UG_CONTACTS_DETAILS, UG_MODE_FULLVIEW, kb, &cbs);
206 struct ui_gadget * msg_ui_composer_launch_contact_list_ug(MSG_COMPOSER_VIEW_DATA_S *cd, int type, const char *str)
209 D_MSG_RETVM_IF(cd == NULL, NULL, "Composer data is NULL");
210 struct ui_gadget *ug;
211 struct ug_cbs cbs = { 0, };
213 bundle *kb = bundle_create();
218 char buf[DEF_BUF_LEN_D] = { 0, };
220 if (type == CT_UG_REQUEST_UPDATE_WITH_EMAIL) {
221 snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_UPDATE_WITH_EMAIL);
222 bundle_add(kb, CT_UG_BUNDLE_TYPE, buf);
223 bundle_add(kb, CT_UG_BUNDLE_EMAIL, str);
224 } else if (type == CT_UG_REQUEST_UPDATE_WITH_NUM) {
225 snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_UPDATE_WITH_NUM);
226 bundle_add(kb, CT_UG_BUNDLE_TYPE, buf);
227 bundle_add(kb, CT_UG_BUNDLE_NUM, str);
234 cbs.layout_cb = __ug_layout_cb;
235 cbs.result_cb = NULL;
236 cbs.destroy_cb = __ug_closed_cb;
239 ug = ug_create(cd->ug, UG_CONTACTS_LIST, UG_MODE_FULLVIEW, kb, &cbs);
247 struct ui_gadget *ug_calllog_create(void *data)
251 struct ui_gadget *ug;
252 struct ug_cbs cbs = { 0, };
254 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
256 bundle *kb = bundle_create();
258 cbs.layout_cb = __ug_layout_cb;
259 cbs.result_cb = __ug_calllog_return_cb;
260 cbs.destroy_cb = __ug_closed_cb;
262 ug = ug_create(cd->ug, TXT_UG_NAME_LOG, UG_MODE_FULLVIEW, kb, &cbs);
269 static void __ug_contacts_checklist_result_cb(struct ui_gadget *ug, bundle *result, void *priv)
272 D_MSG_RETM_IF(!ug,"ug data is NULL");
273 D_MSG_RETM_IF(!result,"bundle result data is NULL");
274 D_MSG_RETM_IF(!priv,"priv data is NULL");
276 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
277 D_MSG_RETM_IF(cd->recipient == NULL,"Recipient data is NULL");
280 int *num_id_list = NULL;
283 const char *number_str;
284 const char *bundle_val;
286 bool bMaxCount = false;
287 bool bInvalidNum = false;
290 bundle_val = bundle_get_val(result, CT_UG_BUNDLE_RESULT_NUMBER_ID_LIST);
291 D_MSG_RETM_IF(!bundle_val,"bundle_val data is NULL");
293 num_id_list = (int *)g_base64_decode(bundle_val, (gsize *)&len);
294 D_MSG_RETM_IF(!num_id_list,"number_id list is NULL");
296 for (i = 0; i < len / sizeof(int); i++) {
298 if (msg_ui_composer_recipient_count_get(cd->recipient) >= COMPOSER_RECIPIENT_COUNT_MAX) {
303 CTSvalue *value = NULL;
304 contact_index = contacts_svc_get_contact_value(CTS_GET_NUMBER_VALUE, num_id_list[i], &value);
305 if (contact_index <= 0 ) {
306 D_EMSG("Fail to get contact value");
310 number_str = contacts_svc_value_get_str(value, CTS_NUM_VAL_NUMBER_STR);
311 D_MSG("selected number_id = %d, contact_id = %d, number = %s", num_id_list[i], contact_index, number_str);
314 if (msg_ui_composer_recipient_duplicate_check(cd->recipient, number_str) == COMPOSER_RETURN_RECIPIENT_DUPLICATE) {
316 contacts_svc_value_free(value);
320 if (msg_ui_composer_recipient_vaild_check(number_str) == EINA_FALSE) {
324 msg_ui_composer_recipient_append(cd->recipient, number_str, contact_index);
327 D_EMSG("contact index[%d] is unuseable !!", contact_index);
330 contacts_svc_value_free(value);
333 D_MSG("bMaxCount = %d, bInvalidNum = %d, bDup = %d", bMaxCount, bInvalidNum, bDup);
335 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_COUNT_MAX);
336 } else if (bInvalidNum) {
337 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_INVALID_RECP);
339 msg_ui_composer_common_tickernoti(cd, COMPOSER_TICKERNOTI_DUP_RECP);
347 struct ui_gadget *ug_contact_checklist_create(void *data)
351 struct ui_gadget *ug;
352 struct ug_cbs cbs = {0,};
360 char contact_ug[DEF_BUF_LEN] = { 0, };
362 snprintf(contact_ug, sizeof(contact_ug)-1, "%d", CT_UG_REQUEST_CHECK_FOR_NUMBER);
363 bundle_add(b, MSG_BUNDLE_KEY_TYPE, contact_ug);
364 bundle_add(b, MSG_BUNDLE_KEY_REQUEST_TYPE, MSG_BUNDLE_VALUE_CONTACT_CHECK_LIST);
366 cbs.layout_cb = __ug_layout_cb;
367 cbs.result_cb = __ug_contacts_checklist_result_cb;
368 cbs.destroy_cb = __ug_closed_cb;
371 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
373 ug = ug_create(cd->ug, TXT_UG_NAME_CONTACT, UG_MODE_FULLVIEW, b, &cbs);
381 struct ui_gadget *msg_ui_composer_launch_composer_create(MSG_COMPOSER_VIEW_DATA_S *cd, bundle *b)
384 D_MSG_RETVM_IF(cd == NULL, NULL, "Composer data is NULL");
386 struct ui_gadget *ug;
389 cbs.layout_cb = __ug_layout_cb;
390 cbs.result_cb = NULL;
391 cbs.destroy_cb = __ug_closed_cb;
394 ug = ug_create(cd->ug, MSG_COMPOSER_UG_NAME, UG_MODE_FULLVIEW, b, &cbs);
400 COMPOSER_RETURN_TYPE_E msg_ui_composer_external_ug_call(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_EXT_TYPE_E ext_type, void *reserved)
404 COMPOSER_RETURN_TYPE_E ret = COMPOSER_RETURN_SUCCESS;
405 struct ui_gadget *external_ug = NULL;
408 case COMPOSER_EXT_TYPE_LOG:
409 external_ug = ug_calllog_create(cd);
412 case COMPOSER_EXT_TYPE_CONTACTLIST:
413 external_ug = ug_contact_checklist_create(cd);
416 D_MSG("ERROR ext type = %d!!!!!!!!!!!!", ext_type);
417 ret = COMPOSER_RETURN_FAIL;
422 cd->loaded_ug = external_ug;
423 elm_object_focus_set(msg_ui_composer_last_focused_entry_get(cd), EINA_FALSE);
430 COMPOSER_RETURN_TYPE_E msg_ui_composer_external_call(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_EXT_TYPE_E ext_type, void *reserved)
434 COMPOSER_RETURN_TYPE_E ret = COMPOSER_RETURN_SUCCESS;
435 D_MSG("Launch external call type[%d]",ext_type);
438 case COMPOSER_EXT_TYPE_LOG:
439 case COMPOSER_EXT_TYPE_CONTACTLIST:
440 ret = msg_ui_composer_external_ug_call(cd, ext_type, reserved);
443 D_MSG("ERROR ext type = %d!!!!!!!!!!!!", ext_type);
444 ret = COMPOSER_RETURN_FAIL;