Fix for 45866
[apps/osp/Call.git] / src / CallInfo.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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        CallCallInfo.cpp
19  * @brief       Call Information class
20  */
21 #include "CallAppUtility.h"
22 #include "CallInfo.h"
23 #include <FMedia.h>
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Media;
29 using namespace Tizen::Social;
30 using namespace Tizen::Telephony;
31
32 AppCallInfo::AppCallInfo(void)
33 {
34         //by Default, neither a conference call nor emergency call
35         __isConfCall = false;
36         __isEmergency = false;
37         __callType = VOICE_CALL;
38         __isOnHold = false;
39         __callConnectTime = 0;
40         __callNotificationTime = 0;
41         __pCallHandle = null;
42         __pEndCallCause = null;
43         __pParticipantCallHandles = null;
44         __pContact = null;
45         __pAddressBook = null;
46 }
47
48 AppCallInfo::~AppCallInfo(void)
49 {
50         if (__pCallHandle)
51         {
52                 delete __pCallHandle;
53         }
54
55         if (__pEndCallCause)
56         {
57                 delete __pEndCallCause;
58         }
59
60         if (__pParticipantCallHandles)
61         {
62                 delete __pParticipantCallHandles;
63                 __pParticipantCallHandles = null;
64         }
65         if (__pContact != null)
66         {
67                 delete __pContact;
68         }
69         if(__pAddressBook != null)
70         {
71                 delete __pAddressBook;
72         }
73 }
74
75 Long*
76 AppCallInfo::GetCallHandle(void)
77 {
78         return __pCallHandle;
79 }
80
81 void
82 AppCallInfo::SetCallHandle(unsigned int handle)
83 {
84         if (__pCallHandle != null)
85         {
86                 delete __pCallHandle;
87         }
88         __pCallHandle = new (std::nothrow) Long(handle);
89 }
90
91 bool
92 AppCallInfo::IsConferenceCall(void)
93 {
94         return __isConfCall;
95 }
96
97 void
98 AppCallInfo::SetConference(bool isConferenceCall)
99 {
100         __isConfCall = isConferenceCall;
101 }
102
103 bool
104 AppCallInfo::IsEmergency(void)
105 {
106         return __isEmergency;
107 }
108
109 void
110 AppCallInfo::SetEmergency(bool isEmergency)
111 {
112         __isEmergency = isEmergency;
113 }
114
115 String&
116 AppCallInfo::GetContactNumber(void)
117 {
118         return __contactNumber;
119 }
120
121 void
122 AppCallInfo::ResetContactNumber(String* contactNumber)
123 {
124         if(contactNumber == null)
125         {
126                 if (__isConfCall == false)
127                 {
128                         __contactNumber = null;
129                 }
130         }
131
132 }
133
134 void
135 AppCallInfo::ResetContactInfo(const Contact* contact)
136 {
137         if(contact == null)
138         {
139                 if (__pContact != null)
140                 {
141                         delete __pContact;
142                         __pContact = null;
143                 }
144         }
145 }
146 void
147 AppCallInfo::SetContactNumber(String& contactNumber)
148 {
149         if (__isConfCall == false)
150         {
151                 __contactNumber = contactNumber;
152         }
153 }
154
155 void
156 AppCallInfo::SetContactInfo(const Contact& contact)
157 {
158         if (__pContact != null)
159         {
160                 delete __pContact;
161                 __pContact = null;
162         }
163         __pContact = new (std::nothrow) Contact(contact);
164 }
165
166 bool
167 AppCallInfo::IsOnHold(void)
168 {
169         return __isOnHold;
170 }
171
172 void
173 AppCallInfo::SetOnHold(bool onHold)
174 {
175         __isOnHold = onHold;
176 }
177
178 long long
179 AppCallInfo::GetCallConnectTime(void)
180 {
181         return __callConnectTime;
182 }
183
184 void
185 AppCallInfo::SetCallConnectTime(long long connectTime)
186 {
187         __callConnectTime = connectTime;
188 }
189
190 long long
191 AppCallInfo::GetCallNotificationTime(void)
192 {
193         return __callNotificationTime;
194 }
195
196 void
197 AppCallInfo::SetCallNotificationTime(long long callNotificationTime)
198 {
199         __callNotificationTime = callNotificationTime;
200 }
201
202 String&
203 AppCallInfo::GetEndCallCause(void)
204 {
205         return *(__pEndCallCause);
206 }
207
208 void
209 AppCallInfo::SetEndCallCause(String& pEndCause)
210 {
211         if (__pEndCallCause != null)
212         {
213                 delete __pEndCallCause;
214         }
215         __pEndCallCause = new (std::nothrow) String(pEndCause);
216 }
217
218 IListT<AppCallInfo>*
219 AppCallInfo::GetCallerList(void)
220 {
221         return __pParticipantCallHandles;
222 }
223
224 int
225 AppCallInfo::GetCallerListCount(void)
226 {
227         if (__pParticipantCallHandles != null)
228         {
229                 return __pParticipantCallHandles->GetCount();
230         }
231         return -1;
232 }
233
234 result
235 AppCallInfo::AddCallToCallerList(AppCallInfo& callInfo)
236 {
237         if (__pParticipantCallHandles == NULL)
238         {
239                 __pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
240         }
241         result r = E_FAILURE;
242         AppCallInfo* pNewCallInfo = new (std::nothrow) AppCallInfo();
243         *pNewCallInfo = callInfo;
244         r = __pParticipantCallHandles->Add(*pNewCallInfo);
245         pNewCallInfo = NULL;
246         return r;
247 }
248
249 result
250 AppCallInfo::RemoveCallFromCallerList(int index)
251 {
252         result r = E_FAILURE;
253         if (__pParticipantCallHandles == NULL)
254         {
255                 return r;
256         }
257         r = __pParticipantCallHandles->RemoveAt(index);
258         return r;
259 }
260
261 void
262 AppCallInfo::SetCalllogType(CallLogType callLogType)
263 {
264         __calllogType = callLogType;
265 }
266
267 CallLogType
268 AppCallInfo::GetCalllogType(void)
269 {
270         return __calllogType;
271 }
272
273 bool
274 AppCallInfo::operator ==(const AppCallInfo& rhs) const
275 {
276         return (this->__pCallHandle->Equals(*(rhs.__pCallHandle)));
277 }
278
279 bool
280 AppCallInfo::operator !=(const AppCallInfo& rhs) const
281 {
282         return (!(this->__pCallHandle->Equals(*(rhs.__pCallHandle))));
283 }
284
285 AppCallInfo&
286 AppCallInfo::operator =(const AppCallInfo& rhs)
287 {
288         if (this != null)
289         {
290                 this->__isConfCall = rhs.__isConfCall;
291                 this->__callType = rhs.__callType;
292                 this->__isEmergency = rhs.__isEmergency;
293                 this->__contactNumber = rhs.__contactNumber;
294                 this->__isOnHold = rhs.__isOnHold;
295                 //call connected time
296                 this->__callConnectTime = rhs.__callConnectTime;
297                 //call notification time
298                 this->__callNotificationTime = rhs.__callNotificationTime;
299                 this->__calllogType = rhs.__calllogType;
300                 //copy call handle, if exist
301                 if (this->__pCallHandle != null)
302                 {
303                         delete this->__pCallHandle;
304                         this->__pCallHandle = null;
305                 }
306                 if (rhs.__pCallHandle != null)
307                 {
308                         this->__pCallHandle = new (std::nothrow) Long(*(rhs.__pCallHandle));
309                 }
310
311                 //copy end call cause, if any exist
312                 if (this->__pEndCallCause != null)
313                 {
314                         delete this->__pEndCallCause;
315                         this->__pEndCallCause = null;
316                 }
317                 if (rhs.__pEndCallCause)
318                 {
319                         this->__pEndCallCause = new (std::nothrow) String(*(rhs.__pEndCallCause));
320                 }
321
322                 //Add participant call list
323                 if (this->__pParticipantCallHandles != null)
324                 {
325                         delete this->__pParticipantCallHandles;
326                         this->__pParticipantCallHandles = null;
327                 }
328                 if (rhs.__pParticipantCallHandles != null)
329                 {
330                         this->__pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
331                         this->__pParticipantCallHandles->Construct(*(rhs.__pParticipantCallHandles));
332                 }
333                 if (this->__pContact != null)
334                 {
335                         delete this->__pContact;
336                         this->__pContact = null;
337                 }
338                 if (rhs.__pContact != null)
339                 {
340                         this->__pContact = new (std::nothrow) Contact(*(rhs.__pContact));
341                 }
342         }
343
344         return *this;
345 }
346
347 String*
348 AppCallInfo::FetchCallerNameN(void)
349 {
350         String displayName(L"");
351         //get caller name from already fetched contact info
352         if (__pContact != null)
353         {
354                 //fetch name to be displayed
355                         String firstName(L"");
356                         String lastName(L"");
357                 String middlename(L"");
358                 __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
359                 __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
360                 __pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
361                 displayName.Append(firstName + middlename + lastName);
362
363                 if (displayName.IsEmpty() == false)
364                 {
365                         __pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
366                 }
367         }
368
369         return new (std::nothrow) String(displayName);
370 }
371
372 Contact*
373 AppCallInfo::FetchContactN(const Tizen::Base::String& phoneNumber)
374 {
375         Tizen::Social::Contact* pFoundContact = null;
376         if(__pAddressBook == null)
377         {
378                 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
379         }
380         IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
381         if (pContactList == null || IsFailed(GetLastResult()))
382         {
383                 return null;
384         }
385
386         //Fetch the contact's info to be displayed
387         IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
388         while (E_SUCCESS == pContactEnum->MoveNext())
389         {
390                 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
391
392                 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
393                 if (pPhoneNumberList != null)
394                 {
395                         IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
396                         while (E_SUCCESS == pPhoneEnum->MoveNext())
397                         {
398                                 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
399                                 //Check if this is the correct contact
400                                 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumber))
401                                 {
402                                         //save newly fetched contact info.
403                                         pFoundContact = new (std::nothrow) Contact(*pContact);
404                                         break;
405                                 }
406                         }
407                         delete pPhoneEnum;
408                                 pPhoneNumberList->RemoveAll(true);
409                                 delete pPhoneNumberList;
410                         }
411                 }
412                 delete pContactEnum;
413                 pContactList->RemoveAll(true);
414                 delete pContactList;
415
416         if(pFoundContact == null)
417         {
418                 return null;
419         }
420
421         return pFoundContact;
422
423 }
424
425
426 String*
427 AppCallInfo::FetchLatestCallerNameN(const Tizen::Base::String& phoneNumber)
428 {
429         String displayName(L"");
430         Tizen::Social::Contact* pContact = null;
431         //Fetch the contact for a number from address book
432         pContact = FetchContactN(phoneNumber);
433         if(pContact != null)
434         {
435                 String firstName(L"");
436                 String lastName(L"");
437                 String middlename(L"");
438                 pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
439                 pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
440                 pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
441                 displayName.Append(firstName + middlename + lastName);
442
443                 if (displayName.IsEmpty() == false)
444                 {
445                         pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
446                 }
447         }
448
449         return new (std::nothrow) String(displayName);
450
451
452 }
453 Bitmap*
454 AppCallInfo::FetchLatestCallerPhotoN(const Tizen::Base::String& phoneNumber)
455 {
456         result r = E_FAILURE;
457         Tizen::Social::Contact* pContact = null;
458         String thumbnailPath;
459         Bitmap* pThumbnail = null;
460         pContact = FetchContactN(phoneNumber);
461         if(pContact != null)
462         {
463                 pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL,thumbnailPath);
464                 if(thumbnailPath.IsEmpty() == true)
465                 {
466                         IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(pContact->GetRecordId());
467                         if(pCategoryList != null && pCategoryList->GetCount() > 0)
468                         {
469                                 AppLogDebug("Changes to get thumbnail group photo");
470                                 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
471                                 thumbnailPath = pCategory->GetThumbnailPath();
472                         }
473                 }
474                 ImageBuffer thumbnailImageBuffer;
475                 r = thumbnailImageBuffer.Construct(thumbnailPath);
476                 if (r == E_SUCCESS)
477                 {
478                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
479                 }
480
481                 if(pThumbnail != null)
482                 {
483                         return pThumbnail;
484                 }
485         }
486
487         return null;
488
489 }
490
491 Bitmap*
492 AppCallInfo::FetchCallerPhotoN(void)
493 {
494
495         if (__pContact != null)
496         {
497                 String thumbnailPath;
498                 Bitmap* pThumbnail = null;
499                 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
500
501                 result r = __pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL, thumbnailPath);
502                 //Now check if there is a group ring tone
503                 if(thumbnailPath.IsEmpty() == true)
504                 {
505                         IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(__pContact->GetRecordId());
506                         if(pCategoryList != null && pCategoryList->GetCount() > 0)
507                         {
508                                 AppLogDebug("Changes to get thumbnail group photo");
509                                 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
510                                 thumbnailPath = pCategory->GetThumbnailPath();
511                         }
512                 }
513                 //thumbnailPath = __pContact->GetThumbnailPath();
514                 ImageBuffer thumbnailImageBuffer;
515                 r = thumbnailImageBuffer.Construct(thumbnailPath);
516                 if (r == E_SUCCESS)
517                 {
518                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
519                 }
520                 return pThumbnail;
521         }
522         return null;
523 }
524
525 const Contact*
526 AppCallInfo::GetContactInfo(void)
527 {
528         return __pContact;
529 }