2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Lukasz Marek (l.marek@samsung.com)
22 #ifndef WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
23 #define WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
27 #include <contacts-svc.h>
28 #include <download-agent-interface.h>
29 #include <Contact/IAddressBook.h>
30 #include <Contact/Contact.h>
32 namespace WrtDeviceApis {
35 class AddressBook : public Api::IAddressBookObject
41 DPL::WaitableEvent* m_waitableEvent;
42 std::string m_downloadedImgPath;
45 DownImgInfo() : m_waitableEvent(NULL)
48 void setWaitableEvent (DPL::WaitableEvent* waitableEvent)
50 m_waitableEvent = waitableEvent;
52 DPL::WaitableEvent* getWaitableEvent (void) const
54 return m_waitableEvent;
56 void setdownloadedImgPath (const std::string &downloadedImgPath)
58 m_downloadedImgPath = downloadedImgPath;
60 std::string getdownloadedImgPath (void) const
62 return m_downloadedImgPath;
67 explicit AddressBook(Api::IAddressBookObject::BookType type);
68 virtual ~AddressBook();
69 //get name of AddressBook
70 std::string getName() const;
71 //set name of AddressBook
72 void setName(const std::string &value);
73 //get group id or -1 when no group found
74 static int getGroupId(const std::string &groupName);
77 void OnRequestReceived(const Api::EventAddContactPtr &event);
78 void OnRequestReceived(const Api::EventUpdateContactPtr &event);
79 void OnRequestReceived(const Api::EventDeleteContactPtr &event);
80 void OnRequestReceived(const Api::EventFindContactsPtr &event);
81 void OnRequestReceived(const Api::EventGetAddressBookItemCountPtr &event);
82 void OnRequestReceived(const Api::EventAddGroupPtr &event);
83 void OnRequestReceived(const Api::EventDeleteGroupPtr &event);
84 void OnRequestReceived(const Api::EventFindGroupPtr &event);
85 void OnRequestReceived(const Api::EventExportVCardPtr &event);
87 //exports contacts to files and returns paths to it or empty list on error.
88 std::vector<std::string> internalExportToVCard(
89 const std::vector<Api::ContactPtr> &contacts) const;
90 //checks if abstract object matches a filter
91 bool matchToFilter(const Api::ContactFilterPtr &filter,
92 const Api::ContactPtr &contact,
93 bool caseSensitive) const;
94 void internalAddGroup(const std::string &groupName) const;
95 void internalDeleteGroup(const std::string &groupName) const;
96 std::vector<std::string> internalFindGroup(const std::string &groupName)
98 void internalAddContact(const Api::ContactPtr &newContact) const;
99 void internalUpdateContact(const Api::ContactPtr &updatedContact) const;
100 Api::ContactPtr internalFindContactById(int id) const;
101 std::vector<Api::ContactPtr> internalFindContactByFilter(
102 const Api::ContactFilterPtr &filter,
105 bool caseSensitive = true) const;
106 std::vector<Api::ContactPtr> internalFindContactByGroup(
107 const std::string &groupName) const;
108 void internalDeleteContactById(int id) const;
109 unsigned int internalGetNumberOfContacts() const;
110 bool internalSetContactGroups(int id,
111 const std::vector<std::string> &groups) const;
112 std::vector<Api::ContactPtr> mergeRecords(
113 const std::vector<Api::ContactPtr> &contacts) const;
114 std::vector<Api::ContactEmailPtr> mergeEmails(
115 const std::vector<Api::ContactEmailPtr> &emails) const;
116 std::vector<Api::ContactPhoneNumberPtr> mergePhoneNumbers(
117 const std::vector<Api::ContactPhoneNumberPtr> &phoneNumbers) const;
118 std::vector<Api::ContactAddressPtr> mergeAddresses(
119 const std::vector<Api::ContactAddressPtr> &addresses) const;
123 std::string getRealPath(const std::string &path) const;
124 std::string downloadImage(const std::string &imgUrl) const;
125 bool matchToFilterAddress(const Api::ContactFilterPtr &filter,
126 const Api::ContactPtr &contact,
127 bool caseSensitive) const;
128 bool matchToFilterEmail(const Api::ContactFilterPtr &filter,
129 const Api::ContactPtr &contact,
130 bool caseSensitive) const;
131 bool matchToFilterPhoneNumber(const Api::ContactFilterPtr &filter,
132 const Api::ContactPtr &contact,
133 bool caseSensitive) const;
134 bool matchToFilterNickname(const Api::ContactFilterPtr &filter,
135 const Api::ContactPtr &contact,
136 bool caseSensitive) const;
137 static void daNotifyCb(user_notify_info_t *notify_info,
139 static void daGetDdInfoCb(user_dd_info_t *dd_info,
141 static void daUpdateDownloadInfoCb(user_download_info_t *download_info,
143 static void setDaClientIdByDaInit(void);
144 static void unsetDaClientIdByDaDeinit(void);
146 static bool m_isDaInit;
151 #endif /* WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_ */