|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Methods for CNcnPublishAndSubscribeObserver class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "NcnDebug.h" |
|
22 #include "NcnPublishAndSubscribeObserver.h" |
|
23 #include "NcnModelBase.h" |
|
24 #include "NcnSubscriber.h" |
|
25 |
|
26 #include <featmgr.h> |
|
27 #include <bldvariant.hrh> |
|
28 #include <startupdomainpskeys.h> |
|
29 #include <avkondomainpskeys.h> |
|
30 #include <coreapplicationuisdomainpskeys.h> |
|
31 #include <ctsydomainpskeys.h> |
|
32 #include "CNcnMsgWaitingManager.h" |
|
33 |
|
34 // ================= LOCAL CONSTANTS ======================= |
|
35 namespace |
|
36 { |
|
37 } |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 // C++ default constructor can NOT contain any code that |
|
42 // might leave. |
|
43 // |
|
44 CNcnPublishAndSubscribeObserver::CNcnPublishAndSubscribeObserver( CNcnModelBase* aModel ) |
|
45 : iModel( aModel ) |
|
46 { |
|
47 } |
|
48 |
|
49 // Symbian OS default constructor can leave. |
|
50 void CNcnPublishAndSubscribeObserver::ConstructL() |
|
51 { |
|
52 TInt value = 0; |
|
53 TInt status = KErrNone; |
|
54 |
|
55 //Subscribe the SIM change status |
|
56 iSimChangedSubscriber = CNcnSubscriber::NewL( *this, |
|
57 KPSUidStartup, |
|
58 KPSSimChanged ); |
|
59 iSimChangedSubscriber->Subscribe(); |
|
60 |
|
61 iSimUsableSubscriber = CNcnSubscriber::NewL( *this, |
|
62 KPSUidStartup, |
|
63 KPSSimStatus ); |
|
64 iSimUsableSubscriber->Subscribe(); |
|
65 |
|
66 status = RProperty::Get ( KPSUidStartup, KPSSimStatus, value ); |
|
67 if ( status ==KErrNone && value == ESimUsable ) |
|
68 { |
|
69 iModel->MsgWaitingManager().GetFirstIndicatorStatus(); |
|
70 } |
|
71 |
|
72 //And get the initial value |
|
73 status = RProperty::Get ( KPSUidStartup, KPSSimChanged, value ); |
|
74 NCN_RDEBUG_INT2(_L("CNcnPublishAndSubscribeObserver : Requested SIM change! status: %d value: %d"), status, value ); |
|
75 |
|
76 if( status == KErrNone && value != KErrUnknown && iModel->IsSupported( KNcnIdSimCard ) ) |
|
77 { |
|
78 iModel->SetSimChanged( |
|
79 ( value == ESimChanged ) ? ETrue : EFalse ); |
|
80 } |
|
81 |
|
82 //Subscribe Idle status. Avkon P&S key is used instead of Active Idle's P&S key. |
|
83 //This prevents soft notifications to be deleted when screensaver activates. |
|
84 iPhoneIdleSubscriber = CNcnSubscriber::NewL( *this, |
|
85 KPSUidAvkonDomain, // ActiveIdle state |
|
86 KAknNotificationsInIdleAllowed ); |
|
87 iPhoneIdleSubscriber->Subscribe(); |
|
88 |
|
89 //And get the initial value |
|
90 RProperty::Get ( KPSUidAvkonDomain, KAknNotificationsInIdleAllowed, iPhoneIdleState ); |
|
91 NCN_RDEBUG_INT2(_L("CNcnPublishAndSubscribeObserver : Requested idle! status: %d value: %d"), status, iPhoneIdleState ); |
|
92 |
|
93 |
|
94 //Subscribe Autolock status |
|
95 iAutolockSubscriber = CNcnSubscriber::NewL( *this, |
|
96 KPSUidCoreApplicationUIs, |
|
97 KCoreAppUIsAutolockStatus ); |
|
98 iAutolockSubscriber->Subscribe(); |
|
99 |
|
100 //And get the initial value |
|
101 RProperty::Get ( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, iAutolockStatus ); |
|
102 NCN_RDEBUG_INT2(_L("CNcnPublishAndSubscribeObserver : Requested auto lock! status: %d value: %d"), status, iAutolockStatus ); |
|
103 |
|
104 |
|
105 //Subscribe Calls state |
|
106 iCurrentCallSubscriber = CNcnSubscriber::NewL( *this, |
|
107 KPSUidCtsyCallInformation, |
|
108 KCTsyCallState ); |
|
109 iCurrentCallSubscriber->Subscribe(); |
|
110 |
|
111 //And get the initial value |
|
112 RProperty::Get ( KPSUidCtsyCallInformation, KCTsyCallState, iCurrentCallStatus ); |
|
113 NCN_RDEBUG_INT2(_L("CNcnPublishAndSubscribeObserver : Requested call status! status: %d value: %d"), status, iCurrentCallStatus ); |
|
114 |
|
115 //Determine idle state |
|
116 NCN_RDEBUG(_L("CNcnPublishAndSubscribeObserver Determine idle state in start-up")); |
|
117 DetermineIdleState(); |
|
118 } |
|
119 |
|
120 // Two-phased constructor. |
|
121 CNcnPublishAndSubscribeObserver* CNcnPublishAndSubscribeObserver::NewL( CNcnModelBase* aModel ) |
|
122 { |
|
123 CNcnPublishAndSubscribeObserver* self = |
|
124 new (ELeave) CNcnPublishAndSubscribeObserver( aModel ); |
|
125 |
|
126 CleanupStack::PushL( self ); |
|
127 self->ConstructL(); |
|
128 CleanupStack::Pop(); |
|
129 |
|
130 return self; |
|
131 } |
|
132 |
|
133 |
|
134 // Destructor |
|
135 CNcnPublishAndSubscribeObserver::~CNcnPublishAndSubscribeObserver() |
|
136 { |
|
137 delete iSimUsableSubscriber; |
|
138 delete iSimChangedSubscriber; |
|
139 delete iPhoneIdleSubscriber; |
|
140 delete iAutolockSubscriber; |
|
141 delete iCurrentCallSubscriber; |
|
142 |
|
143 iModel = NULL; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CNcnPublishAndSubscribeObserver::HandlePropertyChangedL() |
|
148 // Handles the subscribed properties changes. |
|
149 // --------------------------------------------------------- |
|
150 // |
|
151 void CNcnPublishAndSubscribeObserver::HandlePropertyChangedL( const TUid& aCategory, TInt aKey ) |
|
152 { |
|
153 TInt state = 0; |
|
154 |
|
155 if( iModel->IsSupported( KNcnIdSimCard ) ) |
|
156 { |
|
157 if ( aKey == KPSSimChanged ) |
|
158 { |
|
159 RProperty::Get( KPSUidStartup, KPSSimChanged, state ); |
|
160 iModel->SetSimChanged( |
|
161 ( state == ESimChanged ) ? ETrue : EFalse ); |
|
162 return; |
|
163 } |
|
164 } |
|
165 |
|
166 TBool ncnIdleRelatedEventReceived = EFalse; |
|
167 |
|
168 // idle status changed |
|
169 if ( aCategory == KPSUidAvkonDomain && aKey == KAknNotificationsInIdleAllowed ) |
|
170 { |
|
171 RProperty::Get( KPSUidAvkonDomain, KAknNotificationsInIdleAllowed, iPhoneIdleState ); |
|
172 ncnIdleRelatedEventReceived = ETrue; |
|
173 } |
|
174 |
|
175 // autolock status changed |
|
176 else if ( aCategory == KPSUidCoreApplicationUIs && aKey == KCoreAppUIsAutolockStatus ) |
|
177 { |
|
178 RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, iAutolockStatus ); |
|
179 ncnIdleRelatedEventReceived = ETrue; |
|
180 } |
|
181 |
|
182 // call state status changed |
|
183 else if ( aCategory == KPSUidCtsyCallInformation && aKey == KCTsyCallState ) |
|
184 { |
|
185 RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, iCurrentCallStatus ); |
|
186 ncnIdleRelatedEventReceived = ETrue; |
|
187 } |
|
188 else if ( aCategory == KPSUidStartup && aKey == KPSSimStatus ) |
|
189 { |
|
190 RProperty::Get( KPSUidStartup, KPSSimStatus , state ); |
|
191 NCN_RDEBUG_INT(_L("CNcnPublishAndSubscribeObserver::HandlePropertyChangedL RProperty::KPSSimStatus %d"), state ); |
|
192 if ( state == ESimUsable ) |
|
193 { |
|
194 iModel->MsgWaitingManager().GetFirstIndicatorStatus(); |
|
195 } |
|
196 } |
|
197 |
|
198 //Determine idle state |
|
199 if( ncnIdleRelatedEventReceived ) |
|
200 { |
|
201 DetermineIdleState(); |
|
202 } |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CNcnPublishAndSubscribeObserver::NotifyPublishAndSubscribe |
|
207 // --------------------------------------------------------- |
|
208 // |
|
209 void CNcnPublishAndSubscribeObserver::NotifyPublishAndSubscribe( |
|
210 const TUid& aCategory, |
|
211 const TUint aVariable, |
|
212 const TInt aState ) |
|
213 { |
|
214 NCN_RDEBUG_INT2(_L("CNcnPublishAndSubscribeObserver::NotifyPublishAndSubscribe : aCategory %d, aVariable: %d"), aCategory, aVariable ); |
|
215 NCN_RDEBUG_INT(_L("CNcnPublishAndSubscribeObserver::NotifyPublishAndSubscribe : aState: %d"), aState ); |
|
216 |
|
217 int err = RProperty::Set( aCategory, aVariable, aState ); |
|
218 |
|
219 if( err != KErrNone ) |
|
220 { |
|
221 NCN_RDEBUG_INT(_L("CNcnPublishAndSubscribeObserver::NotifyPublishAndSubscribe RProperty::Set failed with %d"), err ); |
|
222 } |
|
223 } |
|
224 // --------------------------------------------------------- |
|
225 // CNcnPublishAndSubscribeObserver::DetermineIdleState |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CNcnPublishAndSubscribeObserver::DetermineIdleState() |
|
229 { |
|
230 //Determine idle state based on these three variables |
|
231 TBool idleState = EFalse; // default |
|
232 NCN_RDEBUG_INT(_L("CNcnPublishAndSubscribeObserver::DetermineIdleState AutoLockState::%d"), iAutolockStatus ); |
|
233 if( iAutolockStatus > EAutolockOff ) |
|
234 { |
|
235 NCN_RDEBUG( _L("Autolock is ON and. Setting idle to false") ); |
|
236 } |
|
237 else |
|
238 { |
|
239 if( iPhoneIdleState ) |
|
240 { |
|
241 NCN_RDEBUG( _L("Autolock is OFF and phone is in IDLE. Setting idle to true") ); |
|
242 idleState = ETrue; |
|
243 } |
|
244 else |
|
245 { |
|
246 NCN_RDEBUG( _L("Autolock is OFF and phone is NOT in IDLE. Setting idle to false") ); |
|
247 } |
|
248 } |
|
249 iModel->SetIdleState( idleState ); |
|
250 } |
|
251 |
|
252 // End of File |