eda5333f8ac5389cf28aee944798a6de55f6eeb5
[framework/web/wrt-plugins-common.git] / src / modules / API / Contact / Contact.cpp
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  *
18  * @file        Contact.cpp
19  * @author      Lukasz Marek (l.marek@samsung.com)
20  * @version     0.1
21  *
22  */
23
24 #include "Contact.h"
25
26 namespace WrtDeviceApis {
27 namespace Contact {
28 namespace Api {
29
30 Contact::Contact() :
31     //initialize fields
32     m_id(-1),
33     m_fullNameIsSet(false),
34     m_firstNameIsSet(false),
35     m_lastNameIsSet(false),
36     m_phoneticNameIsSet(false),
37     m_companyIsSet(false),
38     m_titleIsSet(false),
39     m_photoUriIsSet(false),
40     m_ringTonePathIsSet(false)
41 {
42     LogDebug("entered");
43 }
44
45 Contact::~Contact()
46 {
47     //nothing to do in destructor
48     LogDebug("entered");
49 }
50
51 int Contact::getId() const
52 {
53     //return id of contact
54     return m_id;
55 }
56
57 void Contact::setId(int value)
58 {
59     //set new id of contact
60     m_id = value;
61 }
62
63 std::string Contact::getFullName() const
64 {
65     //return fullname
66     //when fullname is not set then return concatendation of first name and last name
67     return m_fullName.empty() ? m_firstName + " " + m_lastName : m_fullName;
68 }
69
70 void Contact::setFullName(const std::string &value)
71 {
72     //set fullname value
73     m_fullName = value;
74     //mark full name as set
75     m_fullNameIsSet = true;
76 }
77
78 std::string Contact::getFirstName() const
79 {
80     //return first name
81     return m_firstName;
82 }
83
84 void Contact::setFirstName(const std::string &value)
85 {
86     //set first name
87     m_firstName = value;
88     //mark first name as set
89     m_firstNameIsSet = true;
90 }
91
92 std::string Contact::getLastName() const
93 {
94     //return last name
95     return m_lastName;
96 }
97
98 void Contact::setLastName(const std::string &value)
99 {
100     //set last name
101     m_lastName = value;
102     //mark last name as set
103     m_lastNameIsSet = true;
104 }
105
106 const std::vector<std::string> &Contact::getNickNames() const
107 {
108     //returns nicknames array
109     return m_nicknames;
110 }
111
112 void Contact::setNickNames(const std::vector<std::string> &value)
113 {
114     //set new nicknames
115     m_nicknames = value;
116 }
117
118 std::string Contact::getPhoneticName() const
119 {
120     //return phoneticName
121     return m_phoneticName;
122 }
123
124 void Contact::setPhoneticName(const std::string &value)
125 {
126     //set new phoneticName
127     m_phoneticName = value;
128     m_phoneticNameIsSet = true;
129 }
130
131 const std::vector<ContactAddressPtr> &Contact::getAddresses() const
132 {
133     //return addresses array
134     return m_addresses;
135 }
136
137 void Contact::setAddresses(const std::vector<ContactAddressPtr> &value)
138 {
139     //set new addresses
140     m_addresses = value;
141 }
142
143 std::string Contact::getPhotoUri() const
144 {
145     //return photo uri
146     return m_photoUri;
147 }
148
149 void Contact::setPhotoUri(const std::string &value)
150 {
151     //set new photo uri
152     m_photoUri = value;
153     //mark photo uri as set
154     m_photoUriIsSet = true;
155 }
156
157 std::string Contact::getRingTonePath() const
158 {
159     //return ring tone
160     return m_ringTonePath;
161 }
162
163 void Contact::setRingTonePath(const std::string &value)
164 {
165     //set new ring tone
166     m_ringTonePath = value;
167     //mark ringtone as set
168     m_ringTonePathIsSet = true;
169 }
170
171 const std::vector<ContactPhoneNumberPtr> &Contact::getPhoneNumbers() const
172 {
173     //return phone numbers
174     return m_phoneNumbers;
175 }
176
177 void Contact::setPhoneNumbers(const std::vector<ContactPhoneNumberPtr> &value)
178 {
179     //set new phone numbers
180     m_phoneNumbers = value;
181 }
182
183 const std::vector<ContactEmailPtr> &Contact::getEmails() const
184 {
185     //return emails
186     return m_emails;
187 }
188
189 void Contact::setEmails(const std::vector<ContactEmailPtr> &value)
190 {
191     //set new emails
192     m_emails = value;
193 }
194
195 std::string Contact::getCompany() const
196 {
197     //return company
198     return m_company;
199 }
200
201 void Contact::setCompany(const std::string &value)
202 {
203     //set new company
204     m_company = value;
205     //mark company as set
206     m_companyIsSet = true;
207 }
208
209 std::string Contact::getTitle() const
210 {
211     //return title
212     return m_title;
213 }
214
215 void Contact::setTitle(const std::string &value)
216 {
217     //set new title
218     m_title = value;
219     //mark title as set
220     m_titleIsSet = true;
221 }
222
223 const std::vector<std::string> &Contact::getGroups() const
224 {
225     //returns groups
226     return m_groups;
227 }
228
229 void Contact::setGroups(const std::vector<std::string> &value)
230 {
231     //set new groups
232     m_groups = value;
233 }
234
235 bool Contact::getIdIsSet() const
236 {
237     //return true when id is set
238     return m_id != -1;
239 }
240
241 bool Contact::getFullNameIsSet() const
242 {
243     //return true when fullname is set
244     return m_fullNameIsSet;
245 }
246
247 bool Contact::getFirstNameIsSet() const
248 {
249     //return true when first name is set
250     return m_firstNameIsSet;
251 }
252
253 bool Contact::getLastNameIsSet() const
254 {
255     //return true when last name is set
256     return m_lastNameIsSet;
257 }
258
259 bool Contact::getCompanyIsSet() const
260 {
261     //return true when company is set
262     return m_companyIsSet;
263 }
264
265 bool Contact::getTitleIsSet() const
266 {
267     //return true when title is set
268     return m_titleIsSet;
269 }
270
271 bool Contact::getPhotoIsSet() const
272 {
273     //return true when photo uri is set
274     return m_photoUriIsSet;
275 }
276
277 bool Contact::getRingPathIsSet() const
278 {
279     //return true when ring tone is set
280     return m_ringTonePathIsSet;
281 }
282
283 bool Contact::getNicknameIsSet() const
284 {
285     //return true when nicknames is set
286     return m_nicknames.size() != 0;
287 }
288
289 bool Contact::getPhoneticIsSet() const
290 {
291     //return true when phoneticName is set
292     return m_phoneticNameIsSet;
293 }
294
295 bool Contact::getAddressIsSet() const
296 {
297     //return true when addressess are set
298     return m_addresses.size() != 0;
299 }
300
301 bool Contact::getPhoneNumberIsSet() const
302 {
303     //return true when phone numbers are set
304     return m_phoneNumbers.size() != 0;
305 }
306
307 bool Contact::getEmailIsSet() const
308 {
309     //return true when emails are set
310     return m_emails.size() != 0;
311 }
312
313 void Contact::clear()
314 {
315     LogDebug("entered");
316     //clear all fields
317     m_id = -1;
318     m_fullName.clear();
319     m_firstName.clear();
320     m_lastName.clear();
321     m_nicknames.clear();
322     m_addresses.clear();
323     m_photoUri.clear();
324     m_phoneNumbers.clear();
325     m_emails.clear();
326     m_company.clear();
327     m_title.clear();
328     m_groups.clear();
329     //mark fields as not set
330     m_fullNameIsSet = false;
331     m_firstNameIsSet = false;
332     m_lastNameIsSet = false;
333     m_phoneticNameIsSet = false;
334     m_companyIsSet = false;
335     m_titleIsSet = false;
336     m_photoUriIsSet = false;
337     m_ringTonePathIsSet = false;
338 }
339
340 ContactPtr Contact::clone()
341 {
342     //clone object
343     //use defaul copy constructor
344     ContactPtr result(new Contact(*this));
345     std::vector<ContactAddressPtr> addresses;
346     std::vector<ContactPhoneNumberPtr> phoneNumbers;
347     std::vector<ContactEmailPtr> emails;
348     //clone internal representation of addresses
349     for (std::size_t i = 0; i < m_addresses.size(); ++i) {
350         addresses.push_back(m_addresses[i]->clone());
351     }
352     result->setAddresses(addresses);
353     //clone internal representation of phone numbers
354     for (std::size_t i = 0; i < m_phoneNumbers.size(); ++i) {
355         phoneNumbers.push_back(m_phoneNumbers[i]->clone());
356     }
357     result->setPhoneNumbers(phoneNumbers);
358     //clone internal representation of emails
359     for (std::size_t i = 0; i < m_emails.size(); ++i) {
360         emails.push_back(m_emails[i]->clone());
361     }
362     result->setEmails(emails);
363     return result;
364 }
365
366 }
367 }
368 }