fix for 38107
[apps/osp/Call.git] / src / CallSettingsPresentationModel.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    CallSettingsPresentationModel.cpp
19  * @brief   Setting Presentation model
20  */
21 #include "CallSettingsConstants.h"
22 #include "CallSettingsManager.h"
23 #include "CallSettingsPresentationModel.h"
24 #include "CallPresentationModel.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         if(__pSettingsMgr != null)
83         {
84         __pSettingsMgr->AddSettingEventListener(this);
85         }
86         return E_SUCCESS;
87 }
88
89 result
90 SettingsPresentationModel::AddSettingEventListener(ISettingsEventListener* pSettingsEventListener)
91 {
92         result r = E_FAILURE;
93         if (__pSettingsEventListener == null && pSettingsEventListener != null)
94         {
95                 __pSettingsEventListener = pSettingsEventListener;
96                 r = E_SUCCESS;
97         }
98         return r;
99 }
100
101 void
102 SettingsPresentationModel::RemoveSettingEventListener(void)
103 {
104         __pSettingsEventListener = null;
105 }
106
107 IMapT<int,String>*
108 SettingsPresentationModel::GetRejectMessageListN(void)
109 {
110         return __pSettingsMgr->GetRejectMessageListN();
111 }
112
113
114 bool
115 SettingsPresentationModel::IsCallToBeRejected(Tizen::Base::String& phoneNumber)
116 {
117         return __pSettingsMgr->IsCallToBeRejected(phoneNumber);
118 }
119
120
121 //////////////////////////////////////////////////
122 //               Settings Event Listener Methods                //
123 //////////////////////////////////////////////////
124
125 void
126 SettingsPresentationModel::HandleGetCallWaitingResponse(bool isCallSuccessful, bool callWaitingActivated)
127 {
128         if (__pSettingsEventListener != null)
129         {
130                 __pSettingsEventListener->HandleGetCallWaitingResponse(isCallSuccessful, callWaitingActivated);
131         }
132 }
133
134 void
135 SettingsPresentationModel::HandleSetCallWaitingResponse(bool isCallSuccessful, bool isCallWaitingEnabled)
136 {
137         if (__pSettingsEventListener != null)
138                 {
139                         __pSettingsEventListener->HandleSetCallWaitingResponse(isCallSuccessful, isCallWaitingEnabled);
140                 }
141 }
142
143 void
144 SettingsPresentationModel::HandleGetCallForwardResponse(bool isCallSuccessful, CallForwardCondition callFwdCondition, const String& callFwdNumber, bool callForwardActivated, int noReplyWaitTime)
145 {
146         if (__pSettingsEventListener != null)
147                 {
148                         __pSettingsEventListener->HandleGetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, callForwardActivated, noReplyWaitTime);
149                 }
150 }
151
152 void
153 SettingsPresentationModel::HandleSetCallForwardResponse(bool isCallSuccessful, CallForwardCondition callFwdCondition, const String& callFwdNumber, bool isCallForwardActivated, int noReplyWaitTime)
154 {
155         if (__pSettingsEventListener != null)
156                 {
157                         __pSettingsEventListener->HandleSetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, isCallForwardActivated, noReplyWaitTime);
158                 }
159 }
160
161 void
162 SettingsPresentationModel::HandleGetCallBarringResponse(bool isCallSuccessful, CallBarringType callBarringType, bool isBarringActivated)
163 {
164         if (__pSettingsEventListener != null)
165         {
166                 __pSettingsEventListener->HandleGetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
167         }
168 }
169
170 void
171 SettingsPresentationModel::HandleSetCallBarringResponse(bool isCallSuccessful, CallBarringType callBarringType, bool isBarringActivated)
172 {
173         if (__pSettingsEventListener != null)
174         {
175                 __pSettingsEventListener->HandleSetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
176         }
177 }
178
179 void
180 SettingsPresentationModel::HandleFlightMode(bool isFlightModeActivated)
181 {
182         CallPresentationModel::GetInstance()->EndAllCall();
183 }
184
185 result
186 SettingsPresentationModel::SetCallState(CallState callState)
187 {
188         return __pSettingsMgr->SetCallState(callState);
189 }
190
191 bool
192 SettingsPresentationModel::GetFlightModeStatus(void)
193 {
194         return __pSettingsMgr->GetFlightModeStatus();
195 }