3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (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://floralicense.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(const char* capability_type,
21 account_capability_state_e capability_value, void* user_data)
23 c_retvm_if(!user_data, FALSE, "user_data is null");
25 bool *has_calendar = user_data;
27 if (strcmp(capability_type, ACCOUNT_SUPPORTS_CAPABILITY_CALENDAR) == 0 &&
28 capability_value == ACCOUNT_CAPABILITY_ENABLED)
37 static void __cal_account_free_acct(struct _acct *at)
50 static bool __cal_account_get_callback(account_h handle, void* user_data)
52 c_retvm_if(!handle, FALSE, "handle is null");
53 c_retvm_if(!user_data, FALSE, "user_data is null");
55 Eina_List** account_list = user_data;
56 struct _acct *at = NULL;
59 bool has_calendar = FALSE;
61 ret = account_get_capability_all(handle, __cal_account_get_capability_callback, &has_calendar);
62 c_retvm_if(ret != ACCOUNT_ERROR_NONE, FALSE, "account_get_capability is failed(%x)", ret);
64 if (has_calendar == TRUE) {
65 at = calloc(1, sizeof(struct _acct));
66 c_retvm_if(!at, FALSE,"calloc is failed");
72 ret = account_get_email_address(handle, &text);
73 if (ret != ACCOUNT_ERROR_NONE) {
74 ERR("account_get_email_address is failed(%x)", ret);
75 __cal_account_free_acct(at);
79 if (!CAL_STRLEN(text)) {
80 ret = account_get_user_name(handle, &text);
81 if (ret != ACCOUNT_ERROR_NONE) {
82 ERR("account_get_user_name is failed(%x)", ret);
83 __cal_account_free_acct(at);
95 ret = account_get_icon_path(handle, &text);
96 if (ret != ACCOUNT_ERROR_NONE) {
97 ERR("account_get_icon_path is failed(%x)", ret);
98 __cal_account_free_acct(at);
102 if (CAL_STRLEN(text))
109 ret = account_get_domain_name(handle, &text);
110 if (ret != ACCOUNT_ERROR_NONE) {
111 ERR("account_get_domain_name is failed(%x)", ret);
112 __cal_account_free_acct(at);
116 if (CAL_STRLEN(text))
123 ret = account_get_account_id(handle, &at->id);
124 if (ret != ACCOUNT_ERROR_NONE)
126 ERR("account_get_account_id is failed(%x)", ret);
127 __cal_account_free_acct(at);
131 *account_list = eina_list_append(*account_list, at);
136 Eina_List* cal_account_svc_get_account_list(void)
140 Eina_List *account_list = NULL;
143 ret = account_foreach_account_from_db(__cal_account_get_callback, &account_list);
144 if (ret != ACCOUNT_ERROR_NONE)
146 ERR("account_foreach_account_from_db is failed(%x)", ret);
158 void cal_account_svc_free_account_list(Eina_List **h)
166 EINA_LIST_FOREACH(*h, l, at) {
182 *h = eina_list_free(*h);
185 char* cal_account_svc_get_account_icon_path(int account_id)
187 account_error_e ret = ACCOUNT_ERROR_NONE;
188 account_h account = NULL;
190 char* icon_path = NULL;
192 ret = account_create(&account);
193 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_create is failed(%d)", ret);
195 ret = account_query_account_by_account_id(account_id, &account);
196 if (ret != ACCOUNT_ERROR_NONE)
198 ERR("account_query_account_by_account_id is failed(%x)", ret);
200 ret = account_destroy(account);
201 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
206 ret = account_get_icon_path(account, &text);
207 if (ret != ACCOUNT_ERROR_NONE)
209 ERR("account_get_icon_path is failed(%x)", ret);
211 ret = account_destroy(account);
212 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
218 icon_path = strdup(text);
220 ret = account_destroy(account);
221 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
226 char* cal_account_svc_get_account_name(int account_id)
228 account_error_e ret = ACCOUNT_ERROR_NONE;
229 account_h account = NULL;
233 ret = account_create(&account);
234 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_create is failed(%d)", ret);
236 ret = account_query_account_by_account_id(account_id, &account);
237 if (ret != ACCOUNT_ERROR_NONE) {
238 ERR("account_query_account_by_account_id is failed(%x)", ret);
240 ret = account_destroy(account);
241 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
246 ret = account_get_user_name(account, &text);
247 if (ret != ACCOUNT_ERROR_NONE) {
248 ERR("account_get_user_name is failed(%x)", ret);
250 ret = account_destroy(account);
251 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);
256 if (CAL_STRLEN(text))
259 ret = account_destroy(account);
260 c_retvm_if(ret != ACCOUNT_ERROR_NONE, NULL, "account_destroy is failed(%d)", ret);