Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnDialContactInfo.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    PhnDialContactInfo.cpp
19  * @brief       Dial Contact Info class
20  */
21 #include "PhnDialContactInfo.h"
22
23 using namespace Tizen::Base;
24 using namespace Tizen::Graphics;
25 using namespace Tizen::Social;
26 using namespace Tizen::Base::Collection;
27
28 DialContactInfo::DialContactInfo(void) {
29         __pDisplayName = null;
30         __pPhoneNumber = null;
31         __pThumbnail = null;
32         __pSearchKeyList = null;
33         //By default, value is '0' - indicates it is not fetched from call logs
34         __callLogDbId = 0;
35 }
36
37 DialContactInfo*
38 DialContactInfo::CloneN(void)
39 {
40         //Used to create new 'DialContactInfo' object which is clone of 'this' object.
41         //We cant use Copy Contructor, since we will need 2-phase constructor in this case.
42
43         result r = E_SUCCESS;
44         DialContactInfo* cloneObj = new (std::nothrow) DialContactInfo();
45         cloneObj->__pDisplayName = new (std::nothrow) String(*this->__pDisplayName);
46         cloneObj->__pPhoneNumber = new (std::nothrow) String(*this->__pPhoneNumber);
47
48         //Thumbnail
49         if(this->__pThumbnail != null)
50         {
51                 Bitmap& pSrcTn = *(this->__pThumbnail);
52                 cloneObj->__pThumbnail = new (std::nothrow) Bitmap();
53                 r = cloneObj->__pThumbnail->Construct( pSrcTn, Rectangle(0, 0, pSrcTn.GetWidth(), pSrcTn.GetHeight()));
54         }
55         TryCatch(r == E_SUCCESS,,"Object Cloning failed");
56
57         //list of search key.
58         if(this->__pSearchKeyList != null && this->__pSearchKeyList->GetCount() > 0)
59         {
60                 cloneObj->__pSearchKeyList = new (std::nothrow) ArrayList(SingleObjectDeleter);
61                 r = cloneObj->__pSearchKeyList->Construct();
62                 TryCatch(r == E_SUCCESS,,"Object Cloning failed");
63
64                 for (int index = 0; index < this->__pSearchKeyList->GetCount(); index++)
65                 {
66                         String* key = static_cast<String*>(this->__pSearchKeyList->GetAt(index));
67                         r = cloneObj->__pSearchKeyList->Add(new (std::nothrow) String(*key));
68                         TryCatch(r == E_SUCCESS,,"Object Cloning failed");
69                 }
70         }
71
72         return cloneObj;
73         CATCH:
74         //failed
75         delete cloneObj;
76         cloneObj = null;
77         return cloneObj;
78 }
79
80 DialContactInfo::~DialContactInfo(void) {
81         if(__pDisplayName != null)
82         {
83                 delete __pDisplayName;
84         }
85         if(__pPhoneNumber != null)
86         {
87                 delete __pPhoneNumber;
88         }
89         if(__pSearchKeyList != null)
90         {
91                 __pSearchKeyList->RemoveAll();
92                 delete __pSearchKeyList;
93         }
94         if(__pThumbnail != null)
95         {
96                 delete __pThumbnail;
97         }
98 }
99
100 bool
101 DialContactInfo::Equals(const Object& obj) const
102 {
103         DialContactInfo* objInfo = dynamic_cast<DialContactInfo*>(const_cast<Object*>(&obj));
104         if(objInfo != null && __pPhoneNumber->Equals(objInfo->GetPhoneNumber()))
105         {
106                 return true;
107         }
108         return false;
109 }
110
111 void
112 DialContactInfo::AddSearchKey(String& pSearchString)
113 {
114         if(__pSearchKeyList == null)
115         {
116                 __pSearchKeyList = new (std::nothrow) ArrayList(SingleObjectDeleter);
117                 __pSearchKeyList->Construct();
118         }
119         __pSearchKeyList->Add(new (std::nothrow) String(pSearchString));
120 }
121
122 void
123 DialContactInfo::RemoveSearchKey(int index)
124 {
125         if(__pSearchKeyList != null && index >= 0 && index < __pSearchKeyList->GetCount())
126         {
127                 __pSearchKeyList->RemoveAt(index);
128         }
129 }
130
131 void
132 DialContactInfo::ReplaceSearchKey(int index, String& pSearchString)
133 {
134         if(__pSearchKeyList != null && (index >= 0 && index < __pSearchKeyList->GetCount()))
135         {
136                 __pSearchKeyList->RemoveAt(index);
137                 __pSearchKeyList->InsertAt(new String(pSearchString),index);
138         }
139 }
140
141 IList*
142 DialContactInfo::GetSearchKeyList(void)
143 {
144         return __pSearchKeyList;
145 }
146
147 String*
148 DialContactInfo::GetSearchKey(void)
149 {
150         if(__pSearchKeyList != null && __pSearchKeyList->GetCount() > 0)
151         {
152                 return (static_cast<String*>(__pSearchKeyList->GetAt(0)));
153         }
154         return null;
155 }
156
157 void
158 DialContactInfo::SetDisplayName(String& pDisplayName)
159 {
160         if(__pDisplayName != null)
161         {
162                 delete __pDisplayName;
163         }
164         __pDisplayName = new (std::nothrow) String(pDisplayName);
165 }
166
167 String&
168 DialContactInfo::GetDisplayName(void) const
169 {
170         return *__pDisplayName;
171 }
172
173 void
174 DialContactInfo::SetPhoneNumber(String& pPhoneNumber)
175 {
176         if(__pPhoneNumber != null)
177         {
178                 delete __pPhoneNumber;
179         }
180         __pPhoneNumber = new (std::nothrow) String(pPhoneNumber);
181 }
182
183 String&
184 DialContactInfo::GetPhoneNumber(void) const
185 {
186         return *__pPhoneNumber;
187 }
188
189 void
190 DialContactInfo::SetThumbnail(Bitmap* pBitmap)
191 {
192         if(__pThumbnail != null)
193         {
194                 delete __pThumbnail;
195                 __pThumbnail = null;
196         }
197
198         if(pBitmap != null)
199         {
200         __pThumbnail = pBitmap;
201         __pThumbnail->SetScalingQuality(BITMAP_SCALING_QUALITY_MID);
202         __pThumbnail->Scale(Dimension(96, 96));
203         }
204 }
205
206 Bitmap*
207 DialContactInfo::GetThumbnailN(void) const
208 {
209         Bitmap* pThumbnail = null;
210         result r = E_FAILURE;
211         if(__pThumbnail != null)
212         {
213                 pThumbnail = new (std::nothrow) Bitmap();
214                 r = pThumbnail->Construct( *__pThumbnail, Rectangle(0, 0, __pThumbnail->GetWidth(),
215                                                 __pThumbnail->GetHeight()));
216                 TryCatch(r == E_SUCCESS,,"[%s] Thumbnail contruction failed", GetErrorMessage(r));
217         }
218         return pThumbnail;
219
220 CATCH:
221         delete pThumbnail;
222         return null;
223 }
224
225 void
226 DialContactInfo::SetCallLogDbId(int callLogDbId)
227 {
228         __callLogDbId = callLogDbId;
229 }
230
231 int
232 DialContactInfo::GetCallLogDbId(void)
233 {
234         return __callLogDbId;
235 }