1 /* |
|
2 * Copyright (c) 2005-2010 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: |
|
15 * CSysApCenRepOfflineModeObserver is a an observer for the Offline Mode central Repository key. |
|
16 * This class handles the changes to the offline mode changes done from Power Menu or Control Panel |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "sysapcenrepofflinemodeobserver.h" |
|
21 #include "CoreApplicationUIsSDKCRKeys.h" |
|
22 #include "SysAp.hrh" |
|
23 |
|
24 #ifdef _DEBUG |
|
25 #include <e32debug.h> |
|
26 #endif |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CSysApCenRepOfflineModeObserver::NewL( MSysApOfflineModeController& ) |
|
30 // Creates an instance of CSysApCenRepOfflineModeObserver and returns |
|
31 // ---------------------------------------------------------------------------- |
|
32 |
|
33 CSysApCenRepOfflineModeObserver* CSysApCenRepOfflineModeObserver::NewL( |
|
34 MSysApOfflineModeController& aSysApOfflineModeController ) |
|
35 { |
|
36 TRACES( RDebug::Printf("CSysApCenRepOfflineModeObserver::NewL") ); |
|
37 CSysApCenRepOfflineModeObserver* self = |
|
38 new (ELeave) CSysApCenRepOfflineModeObserver(aSysApOfflineModeController); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(); //self |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CSysApCenRepOfflineModeObserver::CSysApCenRepOfflineModeObserver( MSysApOfflineModeController& ) |
|
48 // ---------------------------------------------------------------------------- |
|
49 |
|
50 CSysApCenRepOfflineModeObserver::CSysApCenRepOfflineModeObserver( |
|
51 MSysApOfflineModeController& aSysApOfflineModeController ) |
|
52 : iSysApOfflineModeController( aSysApOfflineModeController ) |
|
53 { |
|
54 TRACES( RDebug::Printf("CSysApCenRepOfflineModeObserver::CSysApCenRepOfflineModeObserver" ) ); |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CSysApCenRepOfflineModeObserver::~CSysApCenRepOfflineModeObserver() |
|
59 // ---------------------------------------------------------------------------- |
|
60 |
|
61 CSysApCenRepOfflineModeObserver::~CSysApCenRepOfflineModeObserver() |
|
62 { |
|
63 TRACES( RDebug::Printf("~CSysApCenRepOfflineModeObserver" ) ); |
|
64 if( iOfflineModeHandler ) |
|
65 { |
|
66 iOfflineModeHandler->StopListening(); |
|
67 } |
|
68 delete iOfflineModeHandler; |
|
69 delete iOfflineCenRep; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // CSysApCenRepOfflineModeObserver::ConstructL() |
|
74 // ---------------------------------------------------------------------------- |
|
75 |
|
76 void CSysApCenRepOfflineModeObserver::ConstructL() |
|
77 { |
|
78 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::ConstructL: trying CRepository::NewL(KCRUidCoreApplicationUIs)")); |
|
79 |
|
80 iOfflineCenRep = CRepository::NewL( KCRUidCoreApplicationUIs ); |
|
81 |
|
82 iOfflineModeHandler = |
|
83 CCenRepNotifyHandler::NewL( *this, |
|
84 *iOfflineCenRep, |
|
85 CCenRepNotifyHandler::EIntKey, |
|
86 KCoreAppUIsNetworkConnectionAllowed ); |
|
87 iOfflineModeHandler->StartListeningL(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // CSysApCenRepOfflineModeObserver::HandleNotifyInt() |
|
92 // Handles the changes to offline mode state |
|
93 // ---------------------------------------------------------------------------- |
|
94 |
|
95 void CSysApCenRepOfflineModeObserver::HandleNotifyInt( TUint32 aId, TInt aNewValue ) |
|
96 { |
|
97 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::HandleNotifyInt(), aId=0x%x, aNewValue=%d", aId, aNewValue)); |
|
98 if ( aId == KCoreAppUIsNetworkConnectionAllowed ) |
|
99 { |
|
100 if( aNewValue == ECoreAppUIsNetworkConnectionNotAllowed ) |
|
101 { |
|
102 // Offline mode enabled. Go Offline |
|
103 TRACES( RDebug::Printf("CSysApCenRepOfflineModeObserver::HandleNotifyInt() Offline mode Enabled")); |
|
104 // Ignore any leave because it will have already been handled by showing an |
|
105 // error notification to the user |
|
106 TRAP_IGNORE(iSysApOfflineModeController.SwitchFromOnlineToOfflineModeL()); |
|
107 } |
|
108 else if( aNewValue == ECoreAppUIsNetworkConnectionAllowed ) |
|
109 { |
|
110 // Offline mode disabled. Go Online |
|
111 TRACES( RDebug::Printf("CSysApCenRepOfflineModeObserver::HandleNotifyInt() Offline mode Disabled")); |
|
112 // Ignore any leave because it will have already been handled by showing an |
|
113 // error notification to the user |
|
114 TRAP_IGNORE(iSysApOfflineModeController.GoOnlineIfOkL()); |
|
115 } |
|
116 else |
|
117 { |
|
118 // Any other value is invalid |
|
119 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::HandleNotifyInt() Invalid Value %d", aNewValue)); |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CSysApCenRepOfflineModeObserver::HandleNotifyError() |
|
126 // ---------------------------------------------------------------------------- |
|
127 |
|
128 void CSysApCenRepOfflineModeObserver::HandleNotifyError( TUint32, TInt, CCenRepNotifyHandler* ) |
|
129 { |
|
130 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::HandleNotifyError()")); |
|
131 // Nothing to do if start listening leaves |
|
132 TRAP_IGNORE(iOfflineModeHandler->StartListeningL()); |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CSysApCenRepOfflineModeObserver::IsOffline() |
|
139 // Fetches the Cen Rep for Offline mode and |
|
140 // Return true if Offline mode is enabled, false otherwise |
|
141 // ---------------------------------------------------------------------------- |
|
142 TBool CSysApCenRepOfflineModeObserver::IsOffline() const |
|
143 { |
|
144 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::IsOffline")); |
|
145 TBool nwConnAllowed = ETrue; |
|
146 iOfflineCenRep->Get(KCoreAppUIsNetworkConnectionAllowed, nwConnAllowed); |
|
147 TRACES(RDebug::Printf("CSysApCenRepOfflineModeObserver::IsOffline returns %d",!nwConnAllowed)); |
|
148 return !nwConnAllowed; |
|
149 } |
|