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