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