tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Contact / AddressBook.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        AddressBook.h
18  * @author      Lukasz Marek (l.marek@samsung.com)
19  * @version     0.1
20  */
21
22 #ifndef WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
23 #define WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_
24
25 #include <string>
26 #include <vector>
27 #include <contacts-svc.h>
28 #include <download-agent-interface.h>
29 #include <Contact/IAddressBook.h>
30 #include <Contact/Contact.h>
31
32 namespace WrtDeviceApis {
33 namespace Contact {
34
35 class AddressBook : public Api::IAddressBookObject
36 {
37   private:
38     class DownImgInfo
39     {
40       private:
41         DPL::WaitableEvent* m_waitableEvent;
42         std::string m_downloadedImgPath;
43
44       public:
45         DownImgInfo() : m_waitableEvent(NULL)
46         {
47         }
48         void setWaitableEvent (DPL::WaitableEvent* waitableEvent)
49         {
50             m_waitableEvent = waitableEvent;
51         }
52         DPL::WaitableEvent* getWaitableEvent (void) const
53         {
54             return m_waitableEvent;
55         }
56         void setdownloadedImgPath (const std::string &downloadedImgPath)
57         {
58             m_downloadedImgPath = downloadedImgPath;
59         }
60         std::string getdownloadedImgPath (void) const
61         {
62             return m_downloadedImgPath;
63         }
64     };
65
66   public:
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);
75
76   protected:
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);
86
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)
97     const;
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,
103             int startIndex = -1,
104             int endIndex = -1,
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;
120
121     std::string m_name;
122   private:
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,
138             void *user_data);
139     static void daGetDdInfoCb(user_dd_info_t *dd_info,
140             void *user_data);
141     static void daUpdateDownloadInfoCb(user_download_info_t *download_info,
142             void *user_data);
143     static void setDaClientIdByDaInit(void);
144     static void unsetDaClientIdByDaDeinit(void);
145
146     static bool m_isDaInit;
147 };
148 }
149 }
150
151 #endif /* WRTDEVICEAPIS_CONTACT_ADDRESS_BOOK_H_ */