|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Class to handle mail led turning on. Uses parts from previous |
|
15 * Bridge implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <e32property.h> |
|
22 #include "EmailLedValues.h" |
|
23 #include "fsmailledhandler.h" |
|
24 #include "fsnotificationhandlertimer.h" |
|
25 |
|
26 |
|
27 // Timeout value for retrying to set the led property again |
|
28 static const TInt KLedRetryTimeout = 15*1000*1000; |
|
29 |
|
30 |
|
31 CFSMailLedHandler* CFSMailLedHandler::NewL( |
|
32 MFSNotificationHandlerMgr& aOwner ) |
|
33 { |
|
34 FUNC_LOG; |
|
35 CFSMailLedHandler* self = |
|
36 new (ELeave) CFSMailLedHandler( aOwner ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CFSMailLedHandler::CFSMailLedHandler( |
|
44 MFSNotificationHandlerMgr& aOwner ) : |
|
45 CFSNotificationHandlerBase( aOwner ), |
|
46 iState( EStarting ), |
|
47 iRetryCount( 0 ) |
|
48 { |
|
49 FUNC_LOG; |
|
50 } |
|
51 |
|
52 void CFSMailLedHandler::ConstructL() |
|
53 { |
|
54 FUNC_LOG; |
|
55 CFSNotificationHandlerBase::ConstructL(); |
|
56 |
|
57 iTimer = CFSNotificationHandlerTimer::NewL( *this ); |
|
58 |
|
59 // Now try and retrieve the property value |
|
60 TimerCallBackL( KErrNone ); |
|
61 } |
|
62 |
|
63 CFSMailLedHandler::~CFSMailLedHandler() |
|
64 { |
|
65 FUNC_LOG; |
|
66 delete iTimer; |
|
67 iTimer = NULL; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // At startup this function will try up to KMaxLedRetry times |
|
72 // to open the LED property. If the property still fails to open, we will |
|
73 // assume that the LED is not supported by the hardware. |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CFSMailLedHandler::TimerCallBackL( TInt aError ) |
|
77 { |
|
78 FUNC_LOG; |
|
79 // request complete handler |
|
80 if ( aError == KErrNone ) |
|
81 { |
|
82 switch ( iState ) |
|
83 { |
|
84 case EStarting: |
|
85 { |
|
86 // Check if LED property exists. If not then this handler |
|
87 // is not necessary. |
|
88 RProperty property; |
|
89 |
|
90 TInt ret = property.Attach( KPropertyUidEmailLedCategory, |
|
91 KEmailLEDOnRequest ); |
|
92 if ( KErrNone != ret ) |
|
93 { |
|
94 // Led Starting Attach Failed |
|
95 property.Close(); |
|
96 |
|
97 // timer not needed any more |
|
98 delete iTimer; |
|
99 iTimer = NULL; |
|
100 |
|
101 ERROR_1( ret, "Attaching prop KPropertyUidEmailLedCategory failed: %d", ret ) |
|
102 return; |
|
103 } |
|
104 |
|
105 TInt val; |
|
106 ret = property.Get( val ); |
|
107 |
|
108 if ( KErrNone != ret ) |
|
109 { |
|
110 iRetryCount++; |
|
111 if ( iRetryCount > KMaxLedRetry ) |
|
112 { |
|
113 // Done Retrying, assume Led not supported |
|
114 iState = ENotSupportLED; |
|
115 } |
|
116 else |
|
117 { |
|
118 //start a timer to wait 15 seconds |
|
119 iTimer->After( KLedRetryTimeout ); |
|
120 } |
|
121 } |
|
122 else |
|
123 { |
|
124 // We are now ready to observe mail events |
|
125 SetObserving( ETrue ); |
|
126 iState = ESupportLED; |
|
127 } |
|
128 property.Close(); |
|
129 break; |
|
130 } |
|
131 case ESupportLED: |
|
132 case ENotSupportLED: |
|
133 default: |
|
134 { |
|
135 break; |
|
136 } |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // HandleEvent is implemented also here because we need to check the |
|
143 // Home Screen status. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CFSMailLedHandler::HandleEventL( |
|
147 TFSMailEvent aEvent, |
|
148 TFSMailMsgId aMailbox, |
|
149 TAny* aParam1, |
|
150 TAny* aParam2, |
|
151 TAny* aParam3 ) |
|
152 { |
|
153 FUNC_LOG; |
|
154 // Event is checked also in CFSNotificationHandlerBase::HandleEventL. |
|
155 // Implementation could be improved so that there would be no need |
|
156 // for doing it twice. Now it has must be done here as we don't want |
|
157 // to check HS if this would not be a new mail. Also |
|
158 // CFSNotificationHandlerBase::HandleEventL needs the check the event |
|
159 // because CFSNotificationHandlerBase::HandleEventL is used in some |
|
160 // cases alone. (without the kind of prechecking that this function |
|
161 // does) |
|
162 if ( aEvent == TFSEventNewMail ) |
|
163 { |
|
164 CFSNotificationHandlerBase::HandleEventL( aEvent, |
|
165 aMailbox, |
|
166 aParam1, |
|
167 aParam2, |
|
168 aParam3 ); |
|
169 } |
|
170 } |
|
171 |
|
172 |
|
173 |
|
174 void CFSMailLedHandler::TurnNotificationOn() |
|
175 { |
|
176 FUNC_LOG; |
|
177 RProperty property; |
|
178 |
|
179 TInt ret = property.Attach( KPropertyUidEmailLedCategory, KEmailLEDOnRequest ); |
|
180 |
|
181 if ( KErrNone != ret ) |
|
182 { |
|
183 // Led Attach Failed |
|
184 property.Close(); |
|
185 return; |
|
186 } |
|
187 |
|
188 ret = property.Set( KSetEmailLedOn ); |
|
189 property.Close(); |
|
190 ERROR_1( ret, "TurnLedOn failed: %d", ret ) |
|
191 } |
|
192 |
|
193 void CFSMailLedHandler::TurnNotificationOff() |
|
194 { |
|
195 FUNC_LOG; |
|
196 return; |
|
197 } |
|
198 |
|
199 // End of file |
|
200 |