1.Disconnecting call when no network 2.Support for Automatic:4dir
[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
31 AppCallInfo::AppCallInfo(void)
32 {
33         //by Default, neither a conference call nor emergency call
34         __isConfCall = false;
35         __isEmergency = false;
36         __callType = VOICE_CALL;
37         __isOnHold = false;
38         __callConnectTime = 0;
39         __callNotificationTime = 0;
40         __pCallHandle = null;
41         __pEndCallCause = null;
42         __pParticipantCallHandles = null;
43         __pContact = null;
44 }
45
46 AppCallInfo::~AppCallInfo(void)
47 {
48         if (__pCallHandle)
49         {
50                 delete __pCallHandle;
51         }
52
53         if (__pEndCallCause)
54         {
55                 delete __pEndCallCause;
56         }
57
58         if (__pParticipantCallHandles)
59         {
60                 delete __pParticipantCallHandles;
61                 __pParticipantCallHandles = null;
62         }
63         if (__pContact != null)
64         {
65                 delete __pContact;
66         }
67 }
68
69 Long*
70 AppCallInfo::GetCallHandle(void)
71 {
72         return __pCallHandle;
73 }
74
75 void
76 AppCallInfo::SetCallHandle(unsigned int handle)
77 {
78         if (__pCallHandle != null)
79         {
80                 delete __pCallHandle;
81         }
82         __pCallHandle = new (std::nothrow) Long(handle);
83 }
84
85 bool
86 AppCallInfo::IsConferenceCall(void)
87 {
88         return __isConfCall;
89 }
90
91 void
92 AppCallInfo::SetConference(bool isConferenceCall)
93 {
94         __isConfCall = isConferenceCall;
95 }
96
97 bool
98 AppCallInfo::IsEmergency(void)
99 {
100         return __isEmergency;
101 }
102
103 void
104 AppCallInfo::SetEmergency(bool isEmergency)
105 {
106         __isEmergency = isEmergency;
107 }
108
109 String&
110 AppCallInfo::GetContactNumber(void)
111 {
112         return __contactNumber;
113 }
114
115 void
116 AppCallInfo::SetContactNumber(String& contactNumber)
117 {
118         if (__isConfCall == false)
119         {
120                 __contactNumber = contactNumber;
121         }
122 }
123
124 void
125 AppCallInfo::SetContactInfo(const Contact& contact)
126 {
127         if (__pContact != null)
128         {
129                 delete __pContact;
130                 __pContact = null;
131         }
132         __pContact = new (std::nothrow) Contact(contact);
133 }
134
135 bool
136 AppCallInfo::IsOnHold(void)
137 {
138         return __isOnHold;
139 }
140
141 void
142 AppCallInfo::SetOnHold(bool onHold)
143 {
144         __isOnHold = onHold;
145 }
146
147 long long
148 AppCallInfo::GetCallConnectTime(void)
149 {
150         return __callConnectTime;
151 }
152
153 void
154 AppCallInfo::SetCallConnectTime(long long connectTime)
155 {
156         __callConnectTime = connectTime;
157 }
158
159 long long
160 AppCallInfo::GetCallNotificationTime(void)
161 {
162         return __callNotificationTime;
163 }
164
165 void
166 AppCallInfo::SetCallNotificationTime(long long callNotificationTime)
167 {
168         __callNotificationTime = callNotificationTime;
169 }
170
171 String&
172 AppCallInfo::GetEndCallCause(void)
173 {
174         return *(__pEndCallCause);
175 }
176
177 void
178 AppCallInfo::SetEndCallCause(String& pEndCause)
179 {
180         if (__pEndCallCause != null)
181         {
182                 delete __pEndCallCause;
183         }
184         __pEndCallCause = new (std::nothrow) String(pEndCause);
185 }
186
187 IListT<AppCallInfo>*
188 AppCallInfo::GetCallerList(void)
189 {
190         return __pParticipantCallHandles;
191 }
192
193 int
194 AppCallInfo::GetCallerListCount(void)
195 {
196         if (__pParticipantCallHandles != null)
197         {
198                 return __pParticipantCallHandles->GetCount();
199         }
200         return -1;
201 }
202
203 result
204 AppCallInfo::AddCallToCallerList(AppCallInfo& callInfo)
205 {
206         if (__pParticipantCallHandles == NULL)
207         {
208                 __pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
209         }
210         result r = E_FAILURE;
211         AppCallInfo* pNewCallInfo = new (std::nothrow) AppCallInfo();
212         *pNewCallInfo = callInfo;
213         r = __pParticipantCallHandles->Add(*pNewCallInfo);
214         pNewCallInfo = NULL;
215         return r;
216 }
217
218 result
219 AppCallInfo::RemoveCallFromCallerList(int index)
220 {
221         result r = E_FAILURE;
222         if (__pParticipantCallHandles == NULL)
223         {
224                 return r;
225         }
226         r = __pParticipantCallHandles->RemoveAt(index);
227         return r;
228 }
229
230 void
231 AppCallInfo::SetCalllogType(CallLogType callLogType)
232 {
233         __calllogType = callLogType;
234 }
235
236 CallLogType
237 AppCallInfo::GetCalllogType(void)
238 {
239         return __calllogType;
240 }
241
242 bool
243 AppCallInfo::operator ==(const AppCallInfo& rhs) const
244 {
245         return (this->__pCallHandle->Equals(*(rhs.__pCallHandle)));
246 }
247
248 bool
249 AppCallInfo::operator !=(const AppCallInfo& rhs) const
250 {
251         return (!(this->__pCallHandle->Equals(*(rhs.__pCallHandle))));
252 }
253
254 AppCallInfo&
255 AppCallInfo::operator =(const AppCallInfo& rhs)
256 {
257         if (this != null)
258         {
259                 this->__isConfCall = rhs.__isConfCall;
260                 this->__callType = rhs.__callType;
261                 this->__isEmergency = rhs.__isEmergency;
262                 this->__contactNumber = rhs.__contactNumber;
263                 this->__isOnHold = rhs.__isOnHold;
264                 //call connected time
265                 this->__callConnectTime = rhs.__callConnectTime;
266                 //call notification time
267                 this->__callNotificationTime = rhs.__callNotificationTime;
268                 this->__calllogType = rhs.__calllogType;
269                 //copy call handle, if exist
270                 if (this->__pCallHandle != null)
271                 {
272                         delete this->__pCallHandle;
273                         this->__pCallHandle = null;
274                 }
275                 if (rhs.__pCallHandle != null)
276                 {
277                         this->__pCallHandle = new (std::nothrow) Long(*(rhs.__pCallHandle));
278                 }
279
280                 //copy end call cause, if any exist
281                 if (this->__pEndCallCause != null)
282                 {
283                         delete this->__pEndCallCause;
284                         this->__pEndCallCause = null;
285                 }
286                 if (rhs.__pEndCallCause)
287                 {
288                         this->__pEndCallCause = new (std::nothrow) String(*(rhs.__pEndCallCause));
289                 }
290
291                 //Add participant call list
292                 if (this->__pParticipantCallHandles != null)
293                 {
294                         delete this->__pParticipantCallHandles;
295                         this->__pParticipantCallHandles = null;
296                 }
297                 if (rhs.__pParticipantCallHandles != null)
298                 {
299                         this->__pParticipantCallHandles = new (std::nothrow) ArrayListT<AppCallInfo>();
300                         this->__pParticipantCallHandles->Construct(*(rhs.__pParticipantCallHandles));
301                 }
302                 if (this->__pContact != null)
303                 {
304                         delete this->__pContact;
305                         this->__pContact = null;
306                 }
307                 if (rhs.__pContact != null)
308                 {
309                         this->__pContact = new (std::nothrow) Contact(*(rhs.__pContact));
310                 }
311         }
312
313         return *this;
314 }
315
316 String*
317 AppCallInfo::FetchCallerNameN(void)
318 {
319         String displayName(L"");
320
321         //get caller name from already fetched contact info
322         if (__pContact != null)
323         {
324                 //fetch name to be displayed
325                 __pContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME, displayName);
326                 if (displayName.IsEmpty())
327                 {
328                         String firstName(L"");
329                         String lastName(L"");
330                         __pContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME, firstName);
331                         __pContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME, lastName);
332                         displayName.Append(firstName + " " + lastName);
333                 }
334         }
335
336         return new (std::nothrow) String(displayName);
337 }
338
339 Bitmap*
340 AppCallInfo::FetchCallerPhotoN(void)
341 {
342
343         if (__pContact != null)
344         {
345                 String thumbnailPath;
346                 Bitmap* pThumbnail = null;
347         //      __pContact->GetValue(CONTACT_PROPERTY_ID_THUMBNAIL, thumbnailPath);
348                 thumbnailPath = __pContact->GetThumbnailPath();
349                 ImageBuffer thumbnailImageBuffer;
350                 result r = thumbnailImageBuffer.Construct(thumbnailPath);
351                 if (r == E_SUCCESS)
352                 {
353                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
354                 }
355                 return pThumbnail;
356         }
357         return null;
358 }
359
360 const Contact*
361 AppCallInfo::GetContactInfo(void)
362 {
363         return __pContact;
364 }