Feature to show group image if a call comes from a group member
[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.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://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::SetContactNumber(String& contactNumber)
123 {
124         if (__isConfCall == false)
125         {
126                 __contactNumber = contactNumber;
127         }
128 }
129
130 void
131 AppCallInfo::SetContactInfo(const Contact& contact)
132 {
133         if (__pContact != null)
134         {
135                 delete __pContact;
136                 __pContact = null;
137         }
138         __pContact = new (std::nothrow) Contact(contact);
139 }
140
141 bool
142 AppCallInfo::IsOnHold(void)
143 {
144         return __isOnHold;
145 }
146
147 void
148 AppCallInfo::SetOnHold(bool onHold)
149 {
150         __isOnHold = onHold;
151 }
152
153 long long
154 AppCallInfo::GetCallConnectTime(void)
155 {
156         return __callConnectTime;
157 }
158
159 void
160 AppCallInfo::SetCallConnectTime(long long connectTime)
161 {
162         __callConnectTime = connectTime;
163 }
164
165 long long
166 AppCallInfo::GetCallNotificationTime(void)
167 {
168         return __callNotificationTime;
169 }
170
171 void
172 AppCallInfo::SetCallNotificationTime(long long callNotificationTime)
173 {
174         __callNotificationTime = callNotificationTime;
175 }
176
177 String&
178 AppCallInfo::GetEndCallCause(void)
179 {
180         return *(__pEndCallCause);
181 }
182
183 void
184 AppCallInfo::SetEndCallCause(String& pEndCause)
185 {
186         if (__pEndCallCause != null)
187         {
188                 delete __pEndCallCause;
189         }
190         __pEndCallCause = new (std::nothrow) String(pEndCause);
191 }
192
193 IListT<AppCallInfo>*
194 AppCallInfo::GetCallerList(void)
195 {
196         return __pParticipantCallHandles;
197 }
198
199 int
200 AppCallInfo::GetCallerListCount(void)
201 {
202         if (__pParticipantCallHandles != null)
203         {
204                 return __pParticipantCallHandles->GetCount();
205         }
206         return -1;
207 }
208
209 result
210 AppCallInfo::AddCallToCallerList(AppCallInfo& callInfo)
211 {
212         if (__pParticipantCallHandles == NULL)
213         {
214                 __pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
215         }
216         result r = E_FAILURE;
217         AppCallInfo* pNewCallInfo = new (std::nothrow) AppCallInfo();
218         *pNewCallInfo = callInfo;
219         r = __pParticipantCallHandles->Add(*pNewCallInfo);
220         pNewCallInfo = NULL;
221         return r;
222 }
223
224 result
225 AppCallInfo::RemoveCallFromCallerList(int index)
226 {
227         result r = E_FAILURE;
228         if (__pParticipantCallHandles == NULL)
229         {
230                 return r;
231         }
232         r = __pParticipantCallHandles->RemoveAt(index);
233         return r;
234 }
235
236 void
237 AppCallInfo::SetCalllogType(CallLogType callLogType)
238 {
239         __calllogType = callLogType;
240 }
241
242 CallLogType
243 AppCallInfo::GetCalllogType(void)
244 {
245         return __calllogType;
246 }
247
248 bool
249 AppCallInfo::operator ==(const AppCallInfo& rhs) const
250 {
251         return (this->__pCallHandle->Equals(*(rhs.__pCallHandle)));
252 }
253
254 bool
255 AppCallInfo::operator !=(const AppCallInfo& rhs) const
256 {
257         return (!(this->__pCallHandle->Equals(*(rhs.__pCallHandle))));
258 }
259
260 AppCallInfo&
261 AppCallInfo::operator =(const AppCallInfo& rhs)
262 {
263         if (this != null)
264         {
265                 this->__isConfCall = rhs.__isConfCall;
266                 this->__callType = rhs.__callType;
267                 this->__isEmergency = rhs.__isEmergency;
268                 this->__contactNumber = rhs.__contactNumber;
269                 this->__isOnHold = rhs.__isOnHold;
270                 //call connected time
271                 this->__callConnectTime = rhs.__callConnectTime;
272                 //call notification time
273                 this->__callNotificationTime = rhs.__callNotificationTime;
274                 this->__calllogType = rhs.__calllogType;
275                 //copy call handle, if exist
276                 if (this->__pCallHandle != null)
277                 {
278                         delete this->__pCallHandle;
279                         this->__pCallHandle = null;
280                 }
281                 if (rhs.__pCallHandle != null)
282                 {
283                         this->__pCallHandle = new (std::nothrow) Long(*(rhs.__pCallHandle));
284                 }
285
286                 //copy end call cause, if any exist
287                 if (this->__pEndCallCause != null)
288                 {
289                         delete this->__pEndCallCause;
290                         this->__pEndCallCause = null;
291                 }
292                 if (rhs.__pEndCallCause)
293                 {
294                         this->__pEndCallCause = new (std::nothrow) String(*(rhs.__pEndCallCause));
295                 }
296
297                 //Add participant call list
298                 if (this->__pParticipantCallHandles != null)
299                 {
300                         delete this->__pParticipantCallHandles;
301                         this->__pParticipantCallHandles = null;
302                 }
303                 if (rhs.__pParticipantCallHandles != null)
304                 {
305                         this->__pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
306                         this->__pParticipantCallHandles->Construct(*(rhs.__pParticipantCallHandles));
307                 }
308                 if (this->__pContact != null)
309                 {
310                         delete this->__pContact;
311                         this->__pContact = null;
312                 }
313                 if (rhs.__pContact != null)
314                 {
315                         this->__pContact = new (std::nothrow) Contact(*(rhs.__pContact));
316                 }
317         }
318
319         return *this;
320 }
321
322 String*
323 AppCallInfo::FetchCallerNameN(void)
324 {
325         String displayName(L"");
326
327         //get caller name from already fetched contact info
328         if (__pContact != null)
329         {
330                 //fetch name to be displayed
331                         String firstName(L"");
332                         String lastName(L"");
333                 String middlename(L"");
334                         __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
335                         __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
336                 __pContact->GetValue(CONTACT_PROPERTY_ID_MIDDLE_NAME, middlename);
337                 displayName.Append(firstName + middlename + lastName);
338
339                 if (displayName.IsEmpty() == false)
340                 {
341                         __pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
342                 }
343         }
344
345         return new (std::nothrow) String(displayName);
346 }
347
348 Bitmap*
349 AppCallInfo::FetchCallerPhotoN(void)
350 {
351
352         if (__pContact != null)
353         {
354                 String thumbnailPath;
355                 Bitmap* pThumbnail = null;
356                 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
357
358                 result r = __pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL, thumbnailPath);
359                 //Now check if there is a group ring tone
360                 if(thumbnailPath.IsEmpty() == true)
361                 {
362                         IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(__pContact->GetRecordId());
363                         if(pCategoryList != null && pCategoryList->GetCount() > 0)
364                         {
365                                 AppLogDebug("Changes to get thumbnail group photo");
366                                 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
367                                 thumbnailPath = pCategory->GetThumbnailPath();
368                         }
369                 }
370                 //thumbnailPath = __pContact->GetThumbnailPath();
371                 ImageBuffer thumbnailImageBuffer;
372                 r = thumbnailImageBuffer.Construct(thumbnailPath);
373                 if (r == E_SUCCESS)
374                 {
375                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
376                 }
377                 return pThumbnail;
378         }
379         return null;
380 }
381
382 const Contact*
383 AppCallInfo::GetContactInfo(void)
384 {
385         return __pContact;
386 }