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.
17 #include "cst-debug.h"
19 #include "cst-common.h"
20 #include "cst-reject-msg.h"
21 #include "cst-widget.h"
24 #include <msg_types.h>
26 #include <contacts-svc.h>
27 #include <contacts-ug.h>
30 #define UG_MODULE_API __attribute__ ((visibility("default")))
33 UG_MODULE_API char *cst_reject_msg_get(int index)
35 ENTER(cst_reject_msg_get);
36 bindtextdomain(UGNAME, CST_LOCALE);
38 char *message = _cst_get_reject_message(index);
42 void _cst_vconf_get_bool(const char *in_key, int *boolval)
44 if ((vconf_get_bool(in_key, boolval)) < 0)
45 DBG("vconf get error : %s", in_key);
48 void _cst_vconf_get_int(const char *in_key, int *intval)
50 if ((vconf_get_int(in_key, intval)) < 0)
51 DBG("vconf get error : %s", in_key);
54 char *_cst_vconf_get_str(const char *in_key)
57 result = vconf_get_str(in_key);
59 DBG("vconf get error : %s", in_key);
64 void _cst_vconf_set_bool(const char *in_key, const int boolval)
66 if (vconf_set_bool(in_key, boolval) < 0)
67 DBG("vconf set error : %s", in_key);
69 DBG("vconf set : %d(%s)", boolval, in_key);
72 void _cst_vconf_set_int(const char *in_key, const int intval)
74 if (vconf_set_int(in_key, intval) < 0)
75 DBG("vconf set error : %s", in_key);
77 DBG("vconf set : %d(%s)", intval, in_key);
80 void _cst_vconf_set_str(const char *in_key, const char *strval)
82 if (vconf_set_str(in_key, strval) < 0)
83 DBG("vconf set error : %s", in_key);
85 DBG("vconf set : %s(%s)", strval, in_key);
88 Eina_Bool _cst_check_flight_mode(void)
90 ENTER(_cst_check_flight_mode);
91 int flight_mode = EINA_FALSE;
93 _cst_vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, &flight_mode);
97 Eina_Bool _cst_check_sim_status(void)
99 ENTER(_cst_check_sim_status);
100 int sim_status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
101 Eina_Bool sim_avail = EINA_FALSE;
103 _cst_vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &sim_status);
104 if (sim_status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
105 sim_avail = EINA_TRUE;
110 int _cst_parse_bundle(service_h service)
112 int type = CST_UG_REQ_NONE;
116 service_get_extra_data(service, CST_UG_BUNDLE_TYPE, &val);
117 if (val) type = atoi(val);
118 DBG("Bundle type = %d", type);
124 static void __cst_contact_list_view_ug_destroy_cb(ui_gadget_h ug, void *priv)
126 ENTER(__cst_contact_list_view_ug_destroy_cb);
131 static void __cst_contact_list_view_ug_result_cb(ui_gadget_h ug, service_h service, void *priv)
133 ENTER(__cst_contact_list_view_ug_result_cb);
134 CstUgData_t *ugd = (CstUgData_t *)priv;
138 int error_code = CTS_SUCCESS;
139 CTSvalue *number = NULL;
140 CTSvalue *name = NULL;
141 const char *first = NULL, *last = NULL, *display_name = NULL, *return_name = NULL, *return_number = NULL;
143 CTSstruct *contact = NULL;
145 service_get_extra_data(service, CT_UG_BUNDLE_RESULT_NUMBER_ID, &temp_p);
146 contact_index = atoi(temp_p);
148 contacts_svc_connect();
149 error_code = contacts_svc_get_contact_value(CTS_GET_NUMBER_VALUE, contact_index, &number);
151 if (error_code >= CTS_SUCCESS) {
152 return_number = contacts_svc_value_get_str(number, CTS_NUM_VAL_NUMBER_STR);
153 if (ugd->dg_entry_contact_number)
154 elm_entry_entry_set(ugd->dg_entry_contact_number, return_number);
156 elm_entry_entry_set(ugd->dg_entry, return_number);
157 DBG("contact number : %s", return_number);
159 DBG(" contact API has a problem \n");
160 error = _cst_create_error_popup(ugd->nf, CST_ERROR_SELECT_VALID_ENTRY);
162 evas_object_show(error);
166 if (ugd->dg_entry_contact_name) {
167 service_get_extra_data(service, CT_UG_BUNDLE_RESULT_CONTACT_ID, &temp_p);
168 contact_index = atoi(temp_p);
170 if (contact_index >= 0 && contacts_svc_get_contact(contact_index, &contact) == CTS_SUCCESS) {
171 contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &name);
172 DBG("after contacts_svc_struct_get_value\n");
173 display_name = contacts_svc_value_get_str(name, CTS_NAME_VAL_DISPLAY_STR);
174 DBG("display name: %s\n", return_name);
175 first = contacts_svc_value_get_str(name, CTS_NAME_VAL_FIRST_STR);
176 DBG("first name: %s\n", return_name);
177 last = contacts_svc_value_get_str(name, CTS_NAME_VAL_LAST_STR);
178 DBG("last name : %s\n", return_name);
180 if (display_name != NULL) {
181 return_name = g_strdup(display_name);
182 } else if (first != NULL && last != NULL) {
183 if (CTS_ORDER_NAME_FIRSTLAST == contacts_svc_get_order(CTS_ORDER_OF_DISPLAY))
184 return_name = g_strdup_printf("%s %s", first, last);
186 return_name = g_strdup_printf("%s %s", last, first);
187 DBG("after contacts_svc_get_order\n");
188 } else if (first != NULL) {
189 return_name = g_strdup_printf("%s", first);
190 } else if (last != NULL) {
191 return_name = g_strdup_printf("%s", last);
193 DBG("No name available");
196 elm_entry_entry_set(ugd->dg_entry_contact_name, return_name);
198 DBG("return_name : %s\n", return_name);
199 g_free((gpointer)return_name);
204 contacts_svc_disconnect();
209 static void __cst_contact_list_view_ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void *priv)
211 ENTER(__cst_contact_list_view_ug_layout_cb);
212 Evas_Object *base = ug_get_layout(ug);
214 ret_if(NULL == base);
216 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217 elm_win_resize_object_add(ug_get_window(), base);
218 evas_object_show(base);
221 static ui_gadget_h __cst_invoke_contact_uigadget(void *data)
223 ENTER(__cst_invoke_contact_uigadget);
225 struct ug_cbs cbs = {0, };
227 retv_if(NULL == data, NULL);
228 CstUgData_t *ugd = (CstUgData_t *)data;
230 service_h service = NULL;
232 service_create(&service);
234 retv_if(NULL == service, NULL);
236 service_set_operation(service, SERVICE_OPERATION_CREATE_CONTENT);
238 snprintf(buf, sizeof(buf), "%d", CT_UG_REQUEST_SELECT_NUMBER);
240 service_add_extra_data(service, CT_UG_BUNDLE_TYPE, buf);
242 cbs.layout_cb = __cst_contact_list_view_ug_layout_cb;
243 cbs.result_cb = __cst_contact_list_view_ug_result_cb;
244 cbs.destroy_cb = __cst_contact_list_view_ug_destroy_cb;
245 cbs.priv = (void *)ugd;
247 ug = ug_create((ui_gadget_h)ugd->ug, UG_CONTACTS_LIST, UG_MODE_FULLVIEW, service, &cbs);
249 service_destroy(service);
254 void _cst_on_click_ime_contact_btn(void *data, Evas_Object *obj, void *event_info)
256 ENTER(_cst_on_click_ime_contact_btn);
257 ret_if(NULL == data);
258 CstUgData_t *ugd = (CstUgData_t *)data;
260 __cst_invoke_contact_uigadget(ugd);
263 void _cst_connect_reject_list_handle(CstUgData_t *ugd)
265 ENTER(_cst_connect_reject_list_handle);
268 ugd->reject_handle = phone_misc_connect();
269 if (NULL == ugd->reject_handle) {
270 DBG("phone_misc_connect Failed");
275 void _cst_disconnect_reject_list_handle(CstUgData_t *ugd)
277 ENTER(_cst_connect_reject_list_handle);
280 int phone_misc_ret = phone_misc_disconnect(ugd->reject_handle);
281 if (phone_misc_ret < 0) {
282 DBG("phone_misc_disconnect() Failed(%d)", phone_misc_ret);