Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsPresentationModel.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    PhnSettingsPresentationModel.cpp
19  * @brief   Setting Presentation model
20  */
21 #include "PhnSettingsConstants.h"
22 #include "PhnSettingsManager.h"
23 #include "PhnSettingsPresentationModel.h"
24 #include "PhnCallPresentationModel.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Social;
29
30 SettingsPresentationModel* SettingsPresentationModel::__pInstance = null;
31
32 SettingsPresentationModel::SettingsPresentationModel()
33 {
34         __pSettingsMgr = null;
35         __pSettingsEventListener = null;
36 }
37
38 SettingsPresentationModel::~SettingsPresentationModel()
39 {
40 }
41
42 void
43 SettingsPresentationModel::CreateInstance(void)
44 {
45         __pInstance = new (std::nothrow) SettingsPresentationModel();
46         result r = __pInstance->Construct();
47         if(IsFailed(r))
48         {
49                 delete __pInstance;
50                 __pInstance = null;
51                 return;
52         }
53         atexit(&(SettingsPresentationModel::DestroyInstance));
54 }
55
56 SettingsPresentationModel*
57 SettingsPresentationModel::GetInstance(void)
58 {
59         if (__pInstance == null)
60         {
61                 CreateInstance();
62         }
63         return __pInstance;
64 }
65
66 void
67 SettingsPresentationModel::DestroyInstance(void)
68 {
69         if (__pInstance->__pSettingsMgr != null)
70         {
71                 __pInstance->__pSettingsMgr->RemoveSettingEventListener(__pInstance);
72                 __pInstance->__pSettingsMgr = null;
73         }
74         delete __pInstance;
75 }
76
77 result
78 SettingsPresentationModel::Construct(void)
79 {
80         //Construct Settings Manager
81         __pSettingsMgr = SettingsManager::GetInstance();
82         __pSettingsMgr->AddSettingEventListener(this);
83         return E_SUCCESS;
84 }
85
86 result
87 SettingsPresentationModel::AddSettingEventListener(ISettingsEventListener* pSettingsEventListener)
88 {
89         result r = E_FAILURE;
90         if (__pSettingsEventListener == null && pSettingsEventListener != null)
91         {
92                 __pSettingsEventListener = pSettingsEventListener;
93                 r = E_SUCCESS;
94         }
95         return r;
96 }
97
98 void
99 SettingsPresentationModel::RemoveSettingEventListener(void)
100 {
101         __pSettingsEventListener = null;
102 }
103
104 IMapT<int,String>*
105 SettingsPresentationModel::GetRejectMessageListN(void)
106 {
107         return __pSettingsMgr->GetRejectMessageListN();
108 }
109
110 result
111 SettingsPresentationModel::AddToCallRejectList(const String& phoneNumber, CallRejectMatchCondition rejectCondition)
112 {
113         return __pSettingsMgr->AddToCallRejectList(phoneNumber, rejectCondition);
114 }
115
116 IListT<CallRejectInfo>*
117 SettingsPresentationModel::GetCallRejectList(void)
118 {
119         return __pSettingsMgr->GetCallRejectList();
120 }
121
122 result
123 SettingsPresentationModel::SetPrefixDialNumber(int phoneNumberIndex, const String& phoneNumber)
124 {
125         return __pSettingsMgr->SetPrefixDialNumber(phoneNumberIndex, phoneNumber);
126 }
127
128 result
129 SettingsPresentationModel::SetActivePrefixDialingValue(int prefixDialIndex)
130 {
131         return __pSettingsMgr->SetActivePrefixDialingValue(prefixDialIndex);
132 }
133
134 result
135 SettingsPresentationModel::SetPrefixDialingStatus(bool enablePrefixDialing)
136 {
137         return __pSettingsMgr->SetPrefixDialingStatus(enablePrefixDialing);
138 }
139
140 result
141 SettingsPresentationModel::GetActivePrefixDialNumber(Tizen::Base::String& phoneNumber)
142 {
143         result r = E_FAILURE;
144         if(__pSettingsMgr->GetPrefixDialingStatus() == true)
145         {
146                 int activePrefixIndex = -1;
147                 //fetch active prefix index
148                 r = __pSettingsMgr->GetActivePrefixDialingValue(activePrefixIndex);
149                 TryReturn(r == E_SUCCESS, r, "Error while fetching Active Prefix Dialing Index");
150
151                 //fetch phone number mapped to fetched index
152                 r = __pSettingsMgr->GetPrefixDialNumberAtIndex(activePrefixIndex, phoneNumber);
153         }
154         return r;
155 }
156
157 int
158 SettingsPresentationModel::SetCallBarringStatus(const String& password, CallBarringType callBarringType, bool activateBarring)
159 {
160         return __pSettingsMgr->SetCallBarringStatus(password, callBarringType, activateBarring);
161 }
162
163 int
164 SettingsPresentationModel::GetCallForwardStatus(CallForwardCondition callFwdCondition)
165 {
166         return __pSettingsMgr->GetCallForwardStatus(callFwdCondition);
167 }
168
169 int
170 SettingsPresentationModel::SetCallForwardStatus(const String& phoneNumber, CallForwardCondition callFwdCondition, bool activateFwding, int noReplyTime)
171 {
172         return __pSettingsMgr->SetCallForwardStatus(phoneNumber, callFwdCondition, activateFwding, noReplyTime);
173 }
174
175 int
176 SettingsPresentationModel::GetCallBarringStatus(CallBarringType callBarringType)
177 {
178         return __pSettingsMgr->GetCallBarringStatus(callBarringType);
179 }
180
181 int
182 SettingsPresentationModel::SetCallWaitingStatus(bool activateWaiting)
183 {
184         return __pSettingsMgr->SetCallWaitingStatus(activateWaiting);
185 }
186
187 int
188 SettingsPresentationModel::GetCallWaitingStatus(void)
189 {
190         return __pSettingsMgr->GetCallWaitingStatus();
191 }
192
193 result
194 SettingsPresentationModel::SetCallConnectToneStatus(bool activate)
195 {
196         return __pSettingsMgr->SetCallConnectToneStatus(activate);
197 }
198 bool
199 SettingsPresentationModel::GetCallConnectToneStatus(void)
200 {
201         return __pSettingsMgr->GetCallConnectToneStatus();
202 }
203
204 result
205 SettingsPresentationModel::SetMinuteMinderToneStatus(bool activate)
206 {
207         return __pSettingsMgr->SetMinuteMinderToneStatus(activate);
208 }
209
210 bool
211 SettingsPresentationModel::GetMinuteMinderToneStatus(void)
212 {
213         return __pSettingsMgr->GetMinuteMinderToneStatus();
214 }
215
216 result
217 SettingsPresentationModel::SetCallEndToneStatus(bool activate)
218 {
219         return __pSettingsMgr->SetCallEndToneStatus(activate);
220 }
221
222 bool
223 SettingsPresentationModel::GetCallEndToneStatus(void)
224 {
225         return __pSettingsMgr->GetCallEndToneStatus();
226 }
227
228 result
229 SettingsPresentationModel::UpdateCallRejectRow(int rowId, const String& phoneNumber, bool activate, CallRejectMatchCondition rejectCondition)
230 {
231         return __pSettingsMgr->UpdateCallRejectRow(rowId, phoneNumber, activate, rejectCondition);
232 }
233
234 result
235 SettingsPresentationModel::RemoveCallRejectRow(int rowId)
236 {
237         return __pSettingsMgr->RemoveCallRejectRow(rowId);
238 }
239
240 result
241 SettingsPresentationModel::SetRejectMessage(int messageIndex, const String& rejectMessage)
242 {
243         return __pSettingsMgr->SetRejectMessage(messageIndex, rejectMessage);
244 }
245
246 result
247 SettingsPresentationModel::RemoveRejectMessage(const Tizen::Base::Collection::IListT<int>& deleteKeyList)
248 {
249         return __pSettingsMgr->RemoveRejectMessage(deleteKeyList);
250 }
251
252 result
253 SettingsPresentationModel::SetSpeedDialMapping(const String& contactId, int numberToMap)
254 {
255         return __pSettingsMgr->SetSpeedDialMapping(contactId,numberToMap);
256 }
257
258 IMapT<int,SpeedDialInfo>*
259 SettingsPresentationModel::GetSpeedDialMappingN(void)
260 {
261         return __pSettingsMgr->GetSpeedDialMappingN();
262 }
263
264 bool
265 SettingsPresentationModel::IsCallToBeRejected(Tizen::Base::String& phoneNumber)
266 {
267         return __pSettingsMgr->IsCallToBeRejected(phoneNumber);
268 }
269
270 result
271 SettingsPresentationModel::RemoveSpeedDialMapping(int rowId)
272 {
273         return __pSettingsMgr->RemoveSpeedDialMapping(rowId);
274 }
275
276 result
277 SettingsPresentationModel::UpdateSpeedDialMapping(int rowId, const String& contactId, int numberToMap)
278 {
279         return __pSettingsMgr->UpdateSpeedDialMapping(rowId, contactId, numberToMap);
280 }
281
282 result
283 SettingsPresentationModel::SetCallLineIdentity(CallLineIdentity identity)
284 {
285         return __pSettingsMgr->SetCallLineIdentity(identity);
286 }
287
288 result
289 SettingsPresentationModel::GetCallLineIdentity(CallLineIdentity& identity)
290 {
291         return __pSettingsMgr->GetCallLineIdentity(identity);
292 }
293
294 result
295 SettingsPresentationModel::SetCallAlertStatus(CallAlertStatus callAlertStatus)
296 {
297         return __pSettingsMgr->SetCallAlertStatus(callAlertStatus);
298 }
299
300 result
301 SettingsPresentationModel::GetCallAlertStatus(CallAlertStatus& callAlertStatus)
302 {
303         return __pSettingsMgr->GetCallAlertStatus(callAlertStatus);
304 }
305
306 result
307 SettingsPresentationModel::SetUnknownRejectStatus(bool activate)
308 {
309         return __pSettingsMgr->SetUnknownRejectStatus(activate);
310 }
311
312 bool
313 SettingsPresentationModel::GetUnknownRejectStatus(void)
314 {
315         return __pSettingsMgr->GetUnknownRejectStatus();
316 }
317
318 Contact*
319 SettingsPresentationModel::FetchContactDetailsN(const String& contactId)
320 {
321         return __pSettingsMgr->FetchContactDetailsN(contactId);
322 }
323
324 //////////////////////////////////////////////////
325 //               Settings Event Listener Methods                //
326 //////////////////////////////////////////////////
327
328 void
329 SettingsPresentationModel::HandleGetCallWaitingResponse(bool isCallSuccessful, bool callWaitingActivated)
330 {
331         if (__pSettingsEventListener != null)
332         {
333                 __pSettingsEventListener->HandleGetCallWaitingResponse(isCallSuccessful, callWaitingActivated);
334         }
335 }
336
337 void
338 SettingsPresentationModel::HandleSetCallWaitingResponse(bool isCallSuccessful, bool isCallWaitingEnabled)
339 {
340         if (__pSettingsEventListener != null)
341                 {
342                         __pSettingsEventListener->HandleSetCallWaitingResponse(isCallSuccessful, isCallWaitingEnabled);
343                 }
344 }
345
346 void
347 SettingsPresentationModel::HandleGetCallForwardResponse(bool isCallSuccessful, CallForwardCondition callFwdCondition, const String& callFwdNumber, bool callForwardActivated, int noReplyWaitTime)
348 {
349         if (__pSettingsEventListener != null)
350                 {
351                         __pSettingsEventListener->HandleGetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, callForwardActivated, noReplyWaitTime);
352                 }
353 }
354
355 void
356 SettingsPresentationModel::HandleSetCallForwardResponse(bool isCallSuccessful, CallForwardCondition callFwdCondition, const String& callFwdNumber, bool isCallForwardActivated, int noReplyWaitTime)
357 {
358         if (__pSettingsEventListener != null)
359                 {
360                         __pSettingsEventListener->HandleSetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, isCallForwardActivated, noReplyWaitTime);
361                 }
362 }
363
364 void
365 SettingsPresentationModel::HandleGetCallBarringResponse(bool isCallSuccessful, CallBarringType callBarringType, bool isBarringActivated)
366 {
367         if (__pSettingsEventListener != null)
368         {
369                 __pSettingsEventListener->HandleGetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
370         }
371 }
372
373 void
374 SettingsPresentationModel::HandleSetCallBarringResponse(bool isCallSuccessful, CallBarringType callBarringType, bool isBarringActivated)
375 {
376         if (__pSettingsEventListener != null)
377         {
378                 __pSettingsEventListener->HandleSetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
379         }
380 }
381
382 void
383 SettingsPresentationModel::HandleFlightMode(bool isFlightModeActivated)
384 {
385         CallPresentationModel::GetInstance()->EndAllCall();
386 }
387 result
388 SettingsPresentationModel::SetCallState(CallState callState)
389 {
390         return __pSettingsMgr->SetCallState(callState);
391 }
392
393 bool
394 SettingsPresentationModel::GetFlightModeStatus(void)
395 {
396         return __pSettingsMgr->GetFlightModeStatus();
397 }