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://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.
18 #include <ui-gadget.h>
20 #include "external-ug.h"
21 #include "edit-attendee.h"
23 void cal_edit_attendee_free_list(Eina_List **h)
26 cal_participant *participant = NULL;
28 EINA_LIST_FOREACH(*h, l, participant) {
29 if (participant->image)
30 free(participant->image);
32 if (participant->name)
33 free(participant->name);
35 if (participant->email)
36 free(participant->email);
38 if (participant->number)
39 free(participant->number);
44 *h = eina_list_free(*h);
47 void cal_edit_attendee_get_person_id_by_email_id(int email_id, int *person_id)
49 c_ret_if(email_id < 0);
52 contacts_record_h email = NULL;
54 contacts_error_e error = contacts_db_get_record(_contacts_email._uri, email_id, &email);
55 c_retm_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record(%d) is failed(%x)", email_id, error);
59 error = contacts_record_get_int(email, _contacts_email.contact_id, &contact_id);
60 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_int() is failed(%x)", error);
62 contacts_record_h contact = NULL;
64 error = contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
65 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record(%d) is failed(%x)", contact_id, error);
67 error = contacts_record_get_int(contact, _contacts_contact.person_id, person_id);
68 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_int() is failed(%x)", error);
70 error = contacts_record_destroy(contact, true);
71 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
73 error = contacts_record_destroy(email, true);
74 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
77 Eina_Bool cal_edit_attendee_check_is_exist(Evas_Object *mbe, const char *label, Elm_Object_Item *cur)
82 // TODO: check contact id??
83 it = elm_multibuttonentry_first_item_get(mbe);
88 l = elm_object_item_text_get(it);
89 if (l && !CAL_STRCMP(l, label))
93 it = elm_multibuttonentry_item_next_get(it);
99 void cal_edit_attendee_get_email_by_person_id(char *buf, int size, int person_id)
101 c_retm_if(!buf, "buf is null");
102 c_retm_if(size < 1, "size is smaller than 1");
103 c_retm_if(person_id < 0, "email id is invalid.");
105 contacts_record_h person = NULL;
107 contacts_error_e error = contacts_db_get_record(_contacts_person._uri, person_id, &person);
108 c_retm_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record(%d) is failed(%x)", person_id, error);
112 error = contacts_record_get_int(person, _contacts_person.display_contact_id, &contact_id);
113 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_int() is failed(%x)", error);
115 contacts_record_h contact = NULL;
117 error = contacts_db_get_record(_contacts_contact._uri, contact_id, &contact);
118 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record() is failed(%x)", error);
120 contacts_record_h email = NULL;
122 error = contacts_record_get_child_record_at_p(contact, _contacts_contact.email, 0, &email);
123 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_child_record_at_p() is failed(%x)", error);
125 char *email_address = NULL;
127 error = contacts_record_get_str_p(email, _contacts_email.email, &email_address);
128 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_str_p() is failed(%x)", error);
130 if (CAL_STRLEN(email_address))
131 snprintf(buf, size, "%s", email_address);
133 error = contacts_record_destroy(contact, true);
134 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
136 error = contacts_record_destroy(person, true);
137 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
140 void cal_edit_attendee_get_name_by_person_id(char *buf, int sz, int person_id)
142 c_retm_if(!buf, "buf is null");
143 c_retm_if(sz < 1, "size is smaller than 1");
144 c_retm_if(person_id < 1, "person_id is smaller than 1");
146 contacts_record_h person = NULL;
148 contacts_error_e error = contacts_db_get_record(_contacts_person._uri, person_id, &person);
149 c_retm_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_record(%d) is failed(%x)", person_id, error);
151 char *display_name = NULL;
153 error = contacts_record_get_str_p(person, _contacts_person.display_name, &display_name);
154 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_str_p(%d) is failed(%x)", person_id, error);
156 if (CAL_STRLEN(display_name))
157 snprintf(buf, sz, "%s", display_name);
159 error = contacts_record_destroy(person, true);
160 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_destroy() is failed(%x)", error);
163 Eina_Bool cal_edit_attendee_check_email_vailidity(const char* email)
165 c_retvm_if(!email, EINA_FALSE, "email is null");
167 const char* temp = strchr(email, '@');
168 c_retvm_if(!temp, EINA_FALSE, "%s is invalid address", email);
169 c_retvm_if(*(temp+1) == '.', EINA_FALSE, "%s is invalid address", email);
171 temp = strchr(temp, '.');
172 c_retvm_if(!temp, EINA_FALSE, "%s is invalid address", email);
173 c_retvm_if(strlen(temp) <= 1, EINA_FALSE, "%s is invalid address", email);
178 int cal_edit_attendee_check_email_is_in_contact(const char *email)
180 c_retv_if(!CAL_STRLEN(email), 0);
182 contacts_error_e error = CONTACTS_ERROR_NONE;
184 contacts_query_h query = NULL;
186 error = contacts_query_create(_contacts_person_email._uri, &query);
187 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_query_create() is failed(%x)", error);
189 contacts_filter_h filter = NULL;
191 error = contacts_filter_create(_contacts_person_email._uri, &filter);
192 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_filter_create() is failed(%x)", error);
194 error = contacts_filter_add_str(filter, _contacts_person_email.email, CONTACTS_MATCH_CONTAINS, email);
195 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_filter_add_str() is failed(%x)", error);
197 error = contacts_query_set_filter(query, filter);
198 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_query_set_filter() is failed(%x)", error);
200 contacts_list_h list = NULL;
202 error = contacts_db_get_records_with_query(query, 0, 0, &list);
203 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_db_get_records_with_query() is failed(%x)", error);
205 error = contacts_list_first(list);
206 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_list_first() is failed(%x)", error);
208 contacts_record_h person = NULL;
210 error = contacts_list_get_current_record_p(list, &person);
211 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_list_get_current_record_p() is failed(%x)", error);
215 error = contacts_record_get_int(person, _contacts_person.id, &person_id);
216 c_warn_if(error != CONTACTS_ERROR_NONE, "contacts_record_get_int() is failed(%x)", error);
218 error = contacts_list_destroy(list, true);
219 c_warn_if(error != CONTACTS_ERROR_NONE, "calendar_list_destroy() is failed(%x)", error);
221 error = contacts_filter_destroy(filter);
222 c_warn_if(error != CONTACTS_ERROR_NONE, "calendar_filter_destroy() is failed(%x)", error);
224 error = contacts_query_destroy(query);
225 c_warn_if(error != CONTACTS_ERROR_NONE, "calendar_query_destroy() is failed(%x)", error);
230 static Eina_Bool __cal_edit_attendee_check_list_exist(Eina_List *list, const char *label)
233 cal_participant* part;
235 EINA_LIST_FOREACH(list, l, part) {
237 if(!CAL_STRCMP(part->name, label))
244 void cal_edit_attendee_copy_items_from_mbe(Evas_Object *from, Eina_List **to)
248 cal_participant* part;
250 it = elm_multibuttonentry_first_item_get(from);
252 label = elm_object_item_text_get(it);
254 if (!__cal_edit_attendee_check_list_exist(*to, label)) {
256 part = elm_object_item_data_get(it);
257 c_retm_if(!part, "part is null");
259 *to = eina_list_append(*to, part);
263 it = elm_multibuttonentry_item_next_get(it);