|
1 /* |
|
2 * Copyright (c) 2007 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: Mail icon off/on handling. Uses parts from previous Bridge |
|
15 * implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <e32property.h> |
|
22 |
|
23 #include "fsmailiconhandler.h" |
|
24 #include "fsnotificationhandlertimer.h" |
|
25 |
|
26 // Define startup Max retry counter for trying to set icon property |
|
27 static const TInt KMaxIconRetry = 5; |
|
28 |
|
29 // Timeout value for retrying to set the icon property again |
|
30 static const TInt KIconRetryTimeout = 10*1000*1000; |
|
31 |
|
32 |
|
33 CFSMailIconHandler* CFSMailIconHandler::NewL( |
|
34 MFSNotificationHandlerMgr& aOwner ) |
|
35 { |
|
36 FUNC_LOG; |
|
37 CFSMailIconHandler* self = |
|
38 new (ELeave) CFSMailIconHandler( aOwner ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CFSMailIconHandler::CFSMailIconHandler( |
|
46 MFSNotificationHandlerMgr& aOwner ) : |
|
47 CFSNotificationHandlerBase( aOwner ), |
|
48 iState( EStarting ), |
|
49 iRetryCount( 0 ) |
|
50 { |
|
51 FUNC_LOG; |
|
52 } |
|
53 |
|
54 void CFSMailIconHandler::ConstructL() |
|
55 { |
|
56 FUNC_LOG; |
|
57 CFSNotificationHandlerBase::ConstructL(); |
|
58 |
|
59 iTimer = CFSNotificationHandlerTimer::NewL( *this ); |
|
60 |
|
61 // Initialize |
|
62 TimerCallBackL( KErrNone ); |
|
63 } |
|
64 |
|
65 CFSMailIconHandler::~CFSMailIconHandler() |
|
66 { |
|
67 FUNC_LOG; |
|
68 SetObserving( EFalse ); |
|
69 delete iTimer; |
|
70 iTimer = NULL; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // At startup this function will try up to KMaxIconRetry times |
|
75 // to set the inital Icon property. If the property still fails to be set, we will |
|
76 // assume that the Icon is not supported by the hardware, and we won't continue. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CFSMailIconHandler::TimerCallBackL( TInt aError ) |
|
80 { |
|
81 FUNC_LOG; |
|
82 // Active object request complete handler |
|
83 if ( aError == KErrNone ) |
|
84 { |
|
85 |
|
86 switch ( iState ) |
|
87 { |
|
88 case EStarting: |
|
89 { |
|
90 TInt ret( KErrNone ); |
|
91 ret = TestIcon(); |
|
92 |
|
93 if ( KErrNone != ret ) |
|
94 { |
|
95 // Setting Icon Failed |
|
96 iRetryCount++; |
|
97 if ( iRetryCount > KMaxIconRetry ) |
|
98 { |
|
99 // Give up, assume Email Icon is Not supported |
|
100 // Message store will not be observed for changes |
|
101 ERROR_1( ret, "CFSMailIconHandler startup failed %d", ret ); |
|
102 iState = EFailed; |
|
103 } |
|
104 else |
|
105 { |
|
106 // Start a timer to wait 10 seconds |
|
107 iTimer->After( KIconRetryTimeout ); |
|
108 } |
|
109 |
|
110 } |
|
111 else |
|
112 { |
|
113 SetObserving( ETrue ); |
|
114 iState = EStarted; |
|
115 } |
|
116 |
|
117 break; |
|
118 } |
|
119 case EStarted: |
|
120 { |
|
121 // Unexpected Icon started state |
|
122 break; |
|
123 } |
|
124 default: |
|
125 { |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
|
132 // Error |
|
133 } |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // HandleEvent is implemented also here because we need to check the |
|
138 // Home Screen status. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CFSMailIconHandler::HandleEventL( |
|
142 TFSMailEvent aEvent, |
|
143 TFSMailMsgId aMailbox, |
|
144 TAny* aParam1, |
|
145 TAny* aParam2, |
|
146 TAny* aParam3 ) |
|
147 { |
|
148 FUNC_LOG; |
|
149 // Event is checked also in CFSNotificationHandlerBase::HandleEventL. |
|
150 // Implementation could be improved so that there would be no need |
|
151 // for doing it twice. Now it must be done here as we don't want |
|
152 // to check HS if this would not be a new mail. Also |
|
153 // CFSNotificationHandlerBase::HandleEventL needs the check the event |
|
154 // because CFSNotificationHandlerBase::HandleEventL is used in some |
|
155 // cases alone. (without the kind of prechecking that this function |
|
156 // does) |
|
157 if ( aEvent == TFSEventNewMail ) |
|
158 { |
|
159 CFSNotificationHandlerBase::HandleEventL( aEvent, |
|
160 aMailbox, |
|
161 aParam1, |
|
162 aParam2, |
|
163 aParam3 ); |
|
164 } |
|
165 } |
|
166 |
|
167 TInt CFSMailIconHandler::SetProperty( TUid aCategory, TUint aKey, TInt aValue ) |
|
168 { |
|
169 FUNC_LOG; |
|
170 RProperty property; |
|
171 TInt ret = property.Attach( aCategory, aKey ); |
|
172 |
|
173 if ( KErrNone == ret ) |
|
174 { |
|
175 ret = property.Set( aValue ); |
|
176 } |
|
177 ERROR_2( ret, "Error %d in setting property %d", ret, aKey ) |
|
178 |
|
179 property.Close(); |
|
180 |
|
181 return ret; |
|
182 } |
|
183 |
|
184 TInt CFSMailIconHandler::TestIcon() |
|
185 { |
|
186 FUNC_LOG; |
|
187 RProperty property; |
|
188 TInt ret = property.Attach( KPSUidCoreApplicationUIs, |
|
189 KCoreAppUIsNewEmailStatus ); |
|
190 |
|
191 // Intention here is just to test the icon by first readin it and then |
|
192 // writing the same value back. Notice that it might be possible that |
|
193 // something has turned the icon off in between the reading and writing. |
|
194 // If thisproves to be a problem then change this. |
|
195 if ( KErrNone == ret ) |
|
196 { |
|
197 TInt currentValue( 0 ); |
|
198 ret = property.Get( currentValue ); |
|
199 |
|
200 |
|
201 if ( KErrNone == ret ) |
|
202 { |
|
203 ret = property.Set( currentValue ); |
|
204 } |
|
205 } |
|
206 property.Close(); |
|
207 return ret; |
|
208 } |
|
209 |
|
210 void CFSMailIconHandler::TurnNotificationOn() |
|
211 { |
|
212 FUNC_LOG; |
|
213 SetProperty( KPSUidCoreApplicationUIs, |
|
214 KCoreAppUIsNewEmailStatus, ECoreAppUIsNewEmail ); |
|
215 } |
|
216 |
|
217 void CFSMailIconHandler::TurnNotificationOff() |
|
218 { |
|
219 FUNC_LOG; |
|
220 SetProperty( KPSUidCoreApplicationUIs, |
|
221 KCoreAppUIsNewEmailStatus, ECoreAppUIsNoNewEmail ); |
|
222 } |
|
223 |