3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.tizenopensource.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 static bool __cal_account_get_capability_callback(account_capability_type_e capability_type, account_capability_state_e capability_value, void* user_data)
22 c_retvm_if(!user_data, FALSE, "user_data is null");
24 bool *has_calendar = user_data;
26 if (capability_type == ACCOUNT_CAPABILITY_CALENDAR && capability_value == ACCOUNT_CAPABILITY_ENABLED)
35 static void __cal_account_free_acct(struct _acct *at)
48 static bool __cal_account_get_callback(account_h handle, void* user_data)
50 c_retvm_if(!handle, FALSE, "handle is null");
51 c_retvm_if(!user_data, FALSE, "user_data is null");
53 Eina_List** account_list = user_data;
54 struct _acct *at = NULL;
57 bool has_calendar = FALSE;
59 ret = account_get_capability(handle, __cal_account_get_capability_callback, &has_calendar);
60 c_retvm_if(ret != ACCOUNT_ERROR_NONE, FALSE, "account_get_capability is failed(%x)", ret);
62 if (has_calendar == TRUE) {
63 at = calloc(1, sizeof(struct _acct));
64 c_retvm_if(!at, FALSE,"calloc is failed");
70 ret = account_get_email_address(handle, &text);
71 if (ret != ACCOUNT_ERROR_NONE) {
72 ERR("account_get_email_address is failed(%x)", ret);
73 __cal_account_free_acct(at);
77 if (!CAL_STRLEN(text)) {
78 ret = account_get_user_name(handle, &text);
79 if (ret != ACCOUNT_ERROR_NONE) {
80 ERR("account_get_user_name is failed(%x)", ret);
81 __cal_account_free_acct(at);
93 ret = account_get_icon_path(handle, &text);
94 if (ret != ACCOUNT_ERROR_NONE) {
95 ERR("account_get_icon_path is failed(%x)", ret);
96 __cal_account_free_acct(at);
100 if (CAL_STRLEN(text))
107 ret = account_get_domain_name(handle, &text);
108 if (ret != ACCOUNT_ERROR_NONE) {
109 ERR("account_get_domain_name is failed(%x)", ret);
110 __cal_account_free_acct(at);
114 if (CAL_STRLEN(text))
121 ret = account_get_account_id(handle, &at->id);
122 if (ret != ACCOUNT_ERROR_NONE)
124 ERR("account_get_account_id is failed(%x)", ret);
125 __cal_account_free_acct(at);
129 *account_list = eina_list_append(*account_list, at);
134 Eina_List* cal_account_svc_get_account_list(void)
138 Eina_List *account_list = NULL;
141 ret = account_foreach_account_from_db(__cal_account_get_callback, &account_list);
142 if (ret != ACCOUNT_ERROR_NONE)
144 ERR("account_foreach_account_from_db is failed(%x)", ret);
156 void cal_account_svc_free_account_list(Eina_List **h)
164 EINA_LIST_FOREACH(*h, l, at) {
180 *h = eina_list_free(*h);
183 char* cal_account_svc_get_account_icon_path(int account_id)
188 char* icon_path = NULL;
190 ret = account_create(&account);
191 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_create is failed(%d)", ret);
193 ret = account_query_account_by_account_id(account_id, &account);
194 if (ret != ACCOUNT_ERROR_NONE)
196 ERR("account_query_account_by_account_id is failed(%x)", ret);
198 ret = account_destroy(account);
199 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
204 ret = account_get_icon_path(account, &text);
205 if (ret != ACCOUNT_ERROR_NONE)
207 ERR("account_get_icon_path is failed(%x)", ret);
209 ret = account_destroy(account);
210 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
216 icon_path = strdup(text);
218 ret = account_destroy(account);
219 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
224 int cal_account_svc_get_facebook_calendar_id(void)
227 Eina_List *web_account_list = NULL;
228 Eina_List *calendar_list = NULL;
229 Eina_List* list_account;
230 Eina_List* list_calendar;
235 list_account = cal_account_svc_get_account_list();
238 web_account_list = eina_list_merge(web_account_list, list_account);
240 EINA_LIST_FOREACH(web_account_list, list_account, at) {
242 at->data = CALENDAR_SVC_GET_ALL(at->id, ALL_CALENDAR_ID, CAL_STRUCT_CALENDAR);
245 EINA_LIST_FOREACH(at->data, list_calendar, cs) {
247 char *calendar_name = CALENDAR_SVC_STRUCT_GET_STR(cs, CAL_TABLE_TXT_NAME);
249 if (!CAL_STRCMP(calendar_name, "Facebook")) {
250 r = CALENDAR_SVC_STRUCT_GET_INT(cs, CAL_TABLE_INT_INDEX);
251 CALENDAR_SVC_FREE_CS_LIST(&at->data);
252 cal_account_svc_free_account_list(&web_account_list);
260 CALENDAR_SVC_FREE_CS_LIST(&at->data);
263 cal_account_svc_free_account_list(&web_account_list);