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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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 <tizen.h>
#include <contacts.h>
#include <contacts_address.h>
#include <contacts-svc.h>
#include <contacts_private.h>
#include <stdlib.h>
#include <string.h>
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_CONTACTS"
#define LOG_MODE (1)
int contact_address_create(contact_address_h* address)
{
if(address == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
CTSvalue* ret = contacts_svc_value_new(CTS_VALUE_POSTAL);
if(ret == NULL) {
LOGE("[%s] CONTACTS_ERROR_OUT_OF_MEMORY(0x%08x)", __FUNCTION__, CONTACTS_ERROR_OUT_OF_MEMORY);
return CONTACTS_ERROR_OUT_OF_MEMORY;
}
*address = (contact_address_h)ret;
return CONTACTS_ERROR_NONE;
}
int contact_address_destroy(contact_address_h address)
{
if(address == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
if(contacts_svc_value_free((CTSvalue*)address) == CTS_SUCCESS) {
return CONTACTS_ERROR_NONE;
}
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
int contact_address_get_type(contact_address_h address, contact_address_type_e* type)
{
if(type == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
CTSvalue * CTSaddress = (CTSvalue *)address;
*type = contacts_svc_value_get_int(CTSaddress, CTS_POSTAL_VAL_TYPE_INT);
return CONTACTS_ERROR_NONE;
}
int contact_address_set_type(contact_address_h address, contact_address_type_e type)
{
if(address == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
CTSvalue * CTSaddress = (CTSvalue *)address;
contacts_svc_value_set_int(CTSaddress, CTS_POSTAL_VAL_TYPE_INT, type);
return CONTACTS_ERROR_NONE;
}
int contact_address_get_detail(contact_address_h address, contact_address_detail_e detail_type, char** data)
{
if(address == NULL || data == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
*data = NULL;
CTSvalue * CTSaddress = (CTSvalue *)address;
switch(detail_type)
{
case CONTACT_ADDRESS_DETAIL_POBOX:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_POBOX_STR));
break;
case CONTACT_ADDRESS_DETAIL_POSTALCODE:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_POSTALCODE_STR));
break;
case CONTACT_ADDRESS_DETAIL_REGION:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_REGION_STR));
break;
case CONTACT_ADDRESS_DETAIL_LOCALITY:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_LOCALITY_STR));
break;
case CONTACT_ADDRESS_DETAIL_STREET:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_STREET_STR));
break;
case CONTACT_ADDRESS_DETAIL_EXTENDED:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_EXTENDED_STR));
break;
case CONTACT_ADDRESS_DETAIL_COUNTRY:
*data = _contacts_safe_strdup(contacts_svc_value_get_str(CTSaddress, CTS_POSTAL_VAL_COUNTRY_STR));
break;
default:
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
break;
}
return CONTACTS_ERROR_NONE;
}
int contact_address_set_detail(contact_address_h address, contact_address_detail_e detail_type, const char* data)
{
if(address == NULL || data == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
CTSvalue * CTSaddress = (CTSvalue *)address;
int ret = CTS_ERR_ARG_INVALID;
switch(detail_type)
{
case CONTACT_ADDRESS_DETAIL_POBOX:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_POBOX_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_POSTALCODE:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_POSTALCODE_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_REGION:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_REGION_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_LOCALITY:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_LOCALITY_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_STREET:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_STREET_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_EXTENDED:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_EXTENDED_STR,data);
break;
case CONTACT_ADDRESS_DETAIL_COUNTRY:
ret=contacts_svc_value_set_str(CTSaddress, CTS_POSTAL_VAL_COUNTRY_STR,data);
break;
}
if(ret == CTS_SUCCESS)
return CONTACTS_ERROR_NONE;
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
int contact_address_iterator_next(contact_address_iterator_h* address_iterator, contact_address_h* address)
{
if(address_iterator == NULL || address == NULL) {
LOGE("[%s] CONTACTS_ERROR_INVALID_PARAMETER(0x%08x)", __FUNCTION__, CONTACTS_ERROR_INVALID_PARAMETER);
return CONTACTS_ERROR_INVALID_PARAMETER;
}
*address = NULL;
GSList* gslist = (GSList*)*address_iterator;
gslist = _contacts_gslist_next_until_not_deleted(gslist);
if(gslist != NULL)
{
*address = (contact_address_h)(gslist)->data;
gslist = g_slist_next(gslist);
*address_iterator = (contact_address_iterator_h)gslist;
return CONTACTS_ERROR_NONE;
}
*address_iterator = NULL;
return CONTACTS_ERROR_ITERATOR_END;
}
bool contact_address_iterator_has_next(contact_address_iterator_h address_iterator)
{
if(address_iterator == NULL) {
return false;
}
GSList* gslist = (GSList*)address_iterator;
CTSvalue* value = (CTSvalue*)gslist->data;
if(value == NULL) {
return false;
}
gslist = _contacts_gslist_next_until_not_deleted(gslist);
if(gslist == NULL) {
return false;
}
return true;
}
|