|
1 /* |
|
2 * Copyright (c) 2006 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: implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <CoreApplicationUIsSDKCRKeys.h> |
|
19 #include <centralrepository.h> |
|
20 #include "CWLanConnUsagePermissionMonitor.h" |
|
21 #include "MWLanConnUsagePermissionObserver.h" |
|
22 |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // CWLanConnUsagePermissionMonitor::NewL |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 CWLanConnUsagePermissionMonitor* CWLanConnUsagePermissionMonitor::NewL( |
|
29 MWLanConnUsagePermissionObserver& aObserver ) |
|
30 { |
|
31 CWLanConnUsagePermissionMonitor* self = |
|
32 new ( ELeave ) CWLanConnUsagePermissionMonitor( aObserver ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CWLanConnUsagePermissionMonitor::~CWLanConnUsagePermissionMonitor |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CWLanConnUsagePermissionMonitor::~CWLanConnUsagePermissionMonitor() |
|
44 { |
|
45 Cancel(); |
|
46 delete iRepository; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CWLanConnUsagePermissionMonitor::RunL |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CWLanConnUsagePermissionMonitor::RunL() |
|
54 { |
|
55 TInt status( iStatus.Int() ); |
|
56 |
|
57 CurrentUsagePermissionL(); |
|
58 |
|
59 // Strangely cenrep may complete the request with positive value, |
|
60 // do not interpret it as an error. |
|
61 if ( status >= KErrNone ) |
|
62 { |
|
63 status = KErrNone; |
|
64 IssueMonitoringL(); |
|
65 } |
|
66 |
|
67 iObserver.UsagePermissionChanged( iCurrentUsagePermission, status ); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CWLanConnUsagePermissionMonitor::DoCancel |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CWLanConnUsagePermissionMonitor::DoCancel() |
|
75 { |
|
76 iRepository->NotifyCancelAll(); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CWLanConnUsagePermissionMonitor::RunError |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CWLanConnUsagePermissionMonitor::RunError( TInt aError ) |
|
84 { |
|
85 iObserver.UsagePermissionChanged( iCurrentUsagePermission, aError ); |
|
86 if ( aError != KErrNoMemory ) |
|
87 { |
|
88 return KErrNone; |
|
89 } |
|
90 return aError; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CWLanConnUsagePermissionMonitor::CurrentUsagePermissionL |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 TBool CWLanConnUsagePermissionMonitor::CurrentUsagePermissionL() |
|
98 { |
|
99 TInt value( KErrNotFound ); |
|
100 User::LeaveIfError( |
|
101 iRepository->Get( KCoreAppUIsNetworkConnectionAllowed, value ) ); |
|
102 |
|
103 iCurrentUsagePermission = TranslateConnectionAllowedValue( value ); |
|
104 |
|
105 return iCurrentUsagePermission; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CWLanConnUsagePermissionMonitor::CWLanConnUsagePermissionMonitor |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 CWLanConnUsagePermissionMonitor::CWLanConnUsagePermissionMonitor( |
|
113 MWLanConnUsagePermissionObserver& aObserver) : |
|
114 CActive( EPriorityStandard ), |
|
115 iObserver( aObserver ), |
|
116 iCurrentUsagePermission( EFalse ) |
|
117 { |
|
118 CActiveScheduler::Add( this ); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CWLanConnUsagePermissionMonitor::ConstructL |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CWLanConnUsagePermissionMonitor::ConstructL() |
|
126 { |
|
127 iRepository = CRepository::NewL( KCRUidCoreApplicationUIs ); |
|
128 |
|
129 IssueMonitoringL(); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CWLanConnUsagePermissionMonitor::IssueMonitoringL |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CWLanConnUsagePermissionMonitor::IssueMonitoringL() |
|
137 { |
|
138 if ( !IsActive() ) |
|
139 { |
|
140 User::LeaveIfError( |
|
141 iRepository->NotifyRequest( KCoreAppUIsNetworkConnectionAllowed, |
|
142 iStatus ) ); |
|
143 SetActive(); |
|
144 } |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CWLanConnUsagePermissionMonitor::TranslateConnectionAllowedValue |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TBool CWLanConnUsagePermissionMonitor::TranslateConnectionAllowedValue( |
|
152 TInt aValue ) |
|
153 { |
|
154 TBool retVal( EFalse ); |
|
155 switch ( aValue ) |
|
156 { |
|
157 case ECoreAppUIsNetworkConnectionNotAllowed: |
|
158 { |
|
159 retVal = EFalse; |
|
160 break; |
|
161 } |
|
162 case ECoreAppUIsNetworkConnectionAllowed: |
|
163 { |
|
164 retVal = ETrue; |
|
165 break; |
|
166 } |
|
167 default: |
|
168 { |
|
169 break; |
|
170 } |
|
171 } |
|
172 return retVal; |
|
173 } |
|
174 |
|
175 // End of file |
|
176 |