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
|
/*
* Contacts Service
*
* Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Youngjae Shin <yj99.shin@samsung.com>
*
* 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 <stdio.h>
#include <glib.h>
#include <contacts-svc.h>
void insert_group(const char *group_name)
{
int ret;
CTSvalue *group;
group = contacts_svc_value_new(CTS_VALUE_GROUP);
contacts_svc_value_set_str(group, CTS_GROUP_VAL_NAME_STR, group_name);
contacts_svc_value_set_str(group, CTS_GROUP_VAL_RINGTONE_STR,"/tmp/test.mp3");
ret = contacts_svc_insert_group(0, group);
if (ret < CTS_SUCCESS)
printf("contacts_svc_insert_group() Failed\n");
contacts_svc_value_free(group);
}
void get_group(void)
{
int ret;
CTSvalue *group = NULL;
ret = contacts_svc_get_group(2, &group);
if (CTS_SUCCESS != ret) {
printf("contacts_svc_get_group() Failed\n");
return;
}
printf("Addressbook ID : %d\n",
contacts_svc_value_get_int(group, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT));
printf("Name : %s\n",
contacts_svc_value_get_str(group, CTS_GROUP_VAL_NAME_STR));
if (contacts_svc_value_get_str(group, CTS_GROUP_VAL_RINGTONE_STR))
printf("ringtone : %s\n",
contacts_svc_value_get_str(group, CTS_GROUP_VAL_RINGTONE_STR));
}
void update_group(void)
{
int ret;
CTSvalue *group = NULL;
ret = contacts_svc_get_group(2, &group);
if (CTS_SUCCESS != ret) {
printf("contacts_svc_get_group() Failed\n");
return;
}
contacts_svc_value_set_str(group, CTS_GROUP_VAL_NAME_STR,"Fix-Friends");
contacts_svc_value_set_str(group, CTS_GROUP_VAL_RINGTONE_STR,"/tmp/change.mp3");
//free("Fix-Friends");
//free("/tmp/change.mp3");
ret = contacts_svc_update_group(group);
if (ret < CTS_SUCCESS)
printf("contacts_svc_update_group() Failed\n");
contacts_svc_value_free(group);
}
void delete_group(void)
{
int ret;
ret = contacts_svc_delete_group(3);
if (CTS_SUCCESS != ret)
printf("Error : contacts_svc_delete_group() Failed(%d)\n", ret);
}
void delete_group_with_members(void)
{
int ret;
ret = contacts_svc_delete_group_with_members(1);
if (CTS_SUCCESS != ret)
printf("Error : contacts_svc_delete_group_with_members() Failed(%d)\n", ret);
}
void group_list(void)
{
int ret;
CTSiter *iter;
ret = contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter);
if (CTS_SUCCESS != ret) {
printf("contacts_svc_get_list() Failed\n");
return;
}
while (CTS_SUCCESS == contacts_svc_iter_next(iter))
{
CTSvalue *group;
const char *name;
group = contacts_svc_iter_get_info(iter);
printf("%8d", contacts_svc_value_get_int(group, CTS_LIST_GROUP_ID_INT));
printf("(%d)", contacts_svc_value_get_int(group, CTS_LIST_GROUP_ADDRESSBOOK_ID_INT));
name = contacts_svc_value_get_str(group, CTS_LIST_GROUP_NAME_STR);
if (name)
printf("%s :", name);
printf("\n");
contacts_svc_value_free(group);
}
contacts_svc_iter_remove(iter);
}
int main()
{
contacts_svc_connect();
insert_group("Friends");
insert_group("Home");
get_group();
update_group();
group_list();
delete_group();
delete_group_with_members();
contacts_svc_disconnect();
return 0;
}
|