summaryrefslogtreecommitdiff
path: root/lib/common/ph-dialer-speed.c
blob: a527e157d033e0d5d0cbf175ac28ca8b0ef898a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * 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://www.tizenopensource.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 <contacts-svc.h>
#include "msg.h"
#include "phone.h"
#include "phone-common.h"

static char *get_voice_mail_number()
{
	int ret;
	msg_handle_t handle;
	msg_struct_t voice_mail;
	char strValue[MAX_PHONE_NUMBER_LEN+1] = {0,};
	
	ret = msg_open_msg_handle(&handle);
	p_retvm_if (MSG_SUCCESS != ret, NULL, "msg_open_msg_handle is Failed(%d)", ret);

	voice_mail = msg_create_struct(MSG_STRUCT_SETTING_VOICE_MSG_OPT);
	ret = msg_get_voice_msg_opt(handle, voice_mail);

	if (ret != MSG_SUCCESS) {
		ERR("msg_get_confi is faild(%d)", ret);
		ret = msg_close_msg_handle(&handle);
		p_warn_if (MSG_SUCCESS != ret, "msg_close_msg_handles is Failed(%d)", ret);
		return NULL;
	}

	msg_get_str_value(voice_mail, MSG_VOICEMSG_ADDRESS_STR, strValue, MAX_PHONE_NUMBER_LEN);

	ret = msg_close_msg_handle(&handle);
	p_warn_if (MSG_SUCCESS != ret, "msg_close_msg_handles is Failed(%d)", ret);

	return strdup(strValue);
}

Eina_List *phone_load_speeddial_data(int *ref_count)
{
	Eina_List *list = NULL;
	int count = 0;
	int ret = 0;
	CTSiter *iter;
	ph_speeddial_info *voice_mail;

	ret = contacts_svc_get_list(CTS_LIST_ALL_SPEEDDIAL, &iter);
	if (CTS_SUCCESS != ret) {
		ERR("contacts_svc_get_list is failed(%d)", ret);
		*ref_count = count;
		return NULL;
	}

	while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
		CTSvalue *pfav= NULL;
		ph_speeddial_info *speed_info;
		pfav = contacts_svc_iter_get_info(iter);

		speed_info = calloc(1, sizeof(ph_speeddial_info));
		speed_info->ph_number = SAFE_STRDUP((char*)contacts_svc_value_get_str(pfav, CTS_LIST_SHORTCUT_NUMBER_STR));
		speed_info->contact_id = contacts_svc_value_get_int(pfav, CTS_LIST_SHORTCUT_CONTACT_ID_INT);
		speed_info->dial_number = contacts_svc_value_get_int(pfav, CTS_LIST_SHORTCUT_SPEEDDIAL_INT);

		speed_info->display = phone_get_display_name_from_value(pfav, CTS_LIST_SHORTCUT_DISPLAY_NAME_STR,
				CTS_LIST_SHORTCUT_FIRST_NAME_STR, CTS_LIST_SHORTCUT_LAST_NAME_STR);
		speed_info->img_path = contacts_svc_value_steal_str(pfav, CTS_LIST_SHORTCUT_IMG_PATH_STR);

		list = eina_list_append(list, (void*)speed_info);
		count++;
		contacts_svc_value_free(pfav);
	}
	contacts_svc_iter_remove(iter);

	voice_mail = calloc(1, sizeof(ph_speeddial_info));
	if (NULL == voice_mail) {
		ERR("calloc Failed");
		*ref_count = count;
		phone_free_speeddial_data(list);
		return NULL;
	}
	voice_mail->ph_number = get_voice_mail_number();
	voice_mail->contact_id = 0;
	voice_mail->dial_number = 1;
	voice_mail->display = strdup(T_(PH_GET_TEXT_BASIC, PHTEXT_VOICE_MAIL));
	voice_mail->img_path = strdup(IMG_VOICEMAIL_ICON);
	list = eina_list_prepend(list, (void*)voice_mail);

	*ref_count = count;
	return list;
}

void phone_free_speeddial_data(Eina_List *list)
{
	PH_FN_CALL;
	Eina_List *l;
	ph_speeddial_info *s_info;

	p_retm_if(NULL == list, "List is null");

	EINA_LIST_FOREACH(list, l, s_info) {
		if (NULL == s_info)
			continue;
		free(s_info->display);
		free(s_info->img_path);
		free(s_info->ph_number);
		free(s_info);
	}
	eina_list_free(list);
	PH_FN_END;
}