tizen_2.0_build
[framework/pim/calendar-service.git] / include / calendar-svc-struct.h
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #ifndef __CALENDAR_SVC_STRUCT_H__
20 #define __CALENDAR_SVC_STRUCT_H__
21
22
23 /**
24  * @defgroup CALENDAR_SVC Calendar Service
25  * @section intro 2.0 calendar engine
26  * - this document maded for calendar service
27  * - this document contain api signature & usage
28  *
29  * @section CREATEINFO author infomation
30  * - author      :   heungjae jeong(hj98.jeong@samsung.com)
31  * - date          :   2010/09/06
32  *
33  * @section DEPENDENCY DEPENDENCY
34  * - GLIB
35  *
36  * @section MODIFYINFO Revision history
37  * - maximus/2010-09-06           : make api signature
38  * - maximus/2010-09-16       : add calendar type & exception date, change api name(remove _event)
39  * - maximus/2010-09-16       : add utility function(for vcalendar)
40  *
41  *
42  */
43
44
45 /**
46  *cal_struct is an opaque type, it must be used via accessor functions.
47  *@ingroup common
48  *@see also:
49  * calendar_svc_struct_new(), calendar_svc_struct_free()
50  * calendar_svc_struct_get_value(), calendar_svc_struct_get_list(),
51  * calendar_svc_struct_store_value(), calendar_svc_struct_store_list()
52  */
53 typedef struct _cal_struct cal_struct;
54
55
56 /**
57  * cal_value is an opaque type, it must be
58  * used via accessor functions.
59  * @ingroup common
60  * @see calendar_svc_struct_new(), calendar_svc_struct_free()
61  */
62 typedef struct _cal_value cal_value;
63
64
65
66 /**
67  * cal_struct is an opaque type, it must be used via accessor functions.
68  * @ingroup common
69  * @see calendar_svc_find_event_list(), calendar_svc_event_get_changes()
70  *      calendar_svc_get_event_by_period(), calendar_svc_iter_get_info(),
71  *      calendar_svc_iter_next(), calendar_svc_iter_remove()
72  */
73 typedef struct _cal_iter cal_iter;
74
75
76
77 /**
78  * @defgroup example example
79  * @ingroup CALENDAR_SVC
80  * @li
81  *      insert example
82  * @code
83    void insert_test(void)
84    {
85       cal_struct *event=NULL;
86       cal_value *attendee1=NULL,*attendee2=NULL;
87       GList *attendee_list=NULL;
88
89       calendar_svc_connect();
90       event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
91
92       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_SUMMARY, "weekly meeting");
93       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_DESCRIPTION, "review : project status");
94       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_LOCATION, "meeting room #1");
95
96       attendee1 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
97       if(attendee1) {
98          calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "heungjae jeong");
99          calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
100          calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 1);
101       }
102       attendee_list = g_list_append(attendee_list, attendee1);
103
104       attendee2 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
105       if(attendee2) {
106          calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "boncheol gu");
107          calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
108          calendar_svc_value_set_str(attendee2, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 0);
109       }
110       attendee_list = g_list_append(attendee_list, attendee2);
111
112       calendar_svc_struct_store_list(event, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list);
113
114       calendar_svc_insert(event);
115       calendar_svc_struct_free(&event);
116
117       calendar_svc_close();
118    }
119  * @endcode
120  */
121
122 /**
123  * @addtogroup example
124  * @li
125  *      update example
126  * @code
127    void update_test(void)
128    {
129       cal_struct *event=NULL;
130       cal_value *attendee1,*attendee2;
131       GList *attendee_list=NULL;
132       char * attendee_name = NULL;
133
134       calendar_svc_connect();
135
136       calendar_svc_get(CAL_STRUCT_SCHEDULE,1,&event)
137
138       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_SUMMARY, "weekly meeting2");
139
140       attendee_list = calendar_svc_struct_get_list(event,CAL_VALUE_LST_ATTENDEE_LIST);
141
142       while(attendee_list)
143       {
144
145          attendee1 = attendee_list->data;
146
147          attendee_name = calendar_svc_value_get_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
148
149          if(strcmp(attendee_name,"boncheol gu")==0)
150          {
151             calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME,"boncheol gu2");
152          }
153          else if(strcmp(attendee_name,"heungjae jeong")==0)
154          {
155             calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_DETAIL_DELETE,true); // set delete flag
156          }
157       }
158
159       attendee2 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
160       if(attendee2) {
161          calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "jihwa park");
162          calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
163       }
164       attendee_list = g_list_append(attendee_list, attendee2);
165
166       calendar_svc_struct_store_list(event, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list);
167
168       calendar_svc_update(event);
169       calendar_svc_struct_free(&event);
170
171       calendar_svc_close();
172    }
173  * @endcode
174  */
175
176
177 /**
178  * @addtogroup example
179  * @li
180  *      get list/delete example
181  * @code
182    void delete_test(void)
183    {
184       cal_struct *event=NULL;
185       cal_value *attendee1=NULL,*attendee2=NULL;
186       GList *attendee_list=NULL;
187       cal_iter *iter=NULL;
188       int ret = 0;
189       int index = 0;
190           int version = 0;
191
192       calendar_svc_connect();
193
194       calendar_svc_event_get_changes(0, version, &iter);
195       ret = calendar_svc_iter_next(iter);
196       while(CAL_SUCCESS == ret)
197       {
198          calendar_svc_iter_get_info(iter, &event);
199          index = calendar_svc_struct_get_int(event,CAL_VALUE_INT_INDEX);
200
201          calendar_svc_delete(CAL_STRUCT_SCHEDULE,index);
202
203          calendar_svc_struct_free(&event);
204          ret = calendar_svc_iter_next(iter);
205       }
206
207       calendar_svc_iter_remove(&iter);
208       calendar_svc_close();
209    }
210  * @endcode
211  */
212
213
214
215 /**
216  * @addtogroup example
217  * @li
218  *      get event example
219  * @code
220
221    void get_test(void)
222    {
223       int index, ret=-1;
224       cal_struct *event = NULL;
225       cal_value *name;
226       GList *get_list, *cursor;
227       index = 1;
228       char *summary;
229       ui_event_t appEvent={0,};
230
231       ret = calendar_svc_get(CAL_STRUCT_SCHEDULE,index,CAL_VALUE_MAIN_FILED, &event);
232
233       summary = calendar_svc_struct_get_str(event, CAL_VALUE_TXT_SUMMARY);
234       strncpy(appEvent.summay,summary,sizeof(appEvent.summay)-1);
235
236
237       get_list = NULL;
238       calendar_svc_struct_get_list(event, CAL_VALUE_LST_ATTENDEE_LIST, &get_list);
239
240       cursor = get_list;
241       for(;cursor;cursor=g_slist_next(cursor))
242       {
243          DBG("number Type = %d",
244             calendar_svc_value_get_int((cal_value*)cursor->data, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS));
245
246          DBG("Number = %s\n",
247             calendar_svc_value_get_str((cal_value*)cursor->data, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME));
248       }
249
250       calendar_svc_struct_free(&event);
251
252    }
253 * @endcode
254 */
255
256
257 #endif /* __CALENDAR_SVC_STRUCT_H__ */
258