|
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: Implements the class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32def.h> |
|
22 #include <msvids.h> // Entry Ids |
|
23 #include <e32property.h> |
|
24 #include <PSVariables.h> |
|
25 |
|
26 #include <NcnListInternalPSKeys.h> |
|
27 #include <NcnListInternalCRKeys.h> |
|
28 #include <NcnListSDKPSKeys.h> |
|
29 |
|
30 #include "NcnDebug.h" |
|
31 #include "NcnOutboxSender.h" |
|
32 #include "NcnOutboxObserver.h" |
|
33 #include "NcnModelBase.h" |
|
34 #include "CNcnMsvSessionHandler.h" |
|
35 #include "CNcnMobileSignalStrengthHandler.h" |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CNcnOutboxObserver::CNcnOutboxObserver |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CNcnOutboxObserver::CNcnOutboxObserver( CNcnModelBase* aModel ) : |
|
44 iModel( aModel ) |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // CNcnOutboxObserver::ConstructL |
|
50 // --------------------------------------------------------- |
|
51 // |
|
52 void CNcnOutboxObserver::ConstructL() |
|
53 { |
|
54 NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Constructing signal strength handler") ); |
|
55 |
|
56 // instantiate the signal strength handler |
|
57 iSignalStrengthHandler = CNcnMobileSignalStrengthHandler::NewL(); |
|
58 |
|
59 // Set observer and start observing, if supported |
|
60 if( iSignalStrengthHandler->ObservingSupported() ) |
|
61 { |
|
62 iSignalStrengthHandler->SetSignalStrengthObserverL( this ); |
|
63 iSignalStrengthHandler->StartObservingL(); |
|
64 NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Signal strength observing started") ); |
|
65 } |
|
66 else |
|
67 { |
|
68 NCN_RDEBUG( _L("CNcnOutboxObserver::ConstructL - Signal strength observing not supported") ); |
|
69 } |
|
70 |
|
71 // add observer to msv session handler |
|
72 iModel->MsvSessionHandler().AddObserverL( this ); |
|
73 } |
|
74 |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // CNcnOutboxObserver::NewL |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 CNcnOutboxObserver* CNcnOutboxObserver::NewL( CNcnModelBase* aModel ) |
|
81 { |
|
82 // Create the instance of the outbox observer |
|
83 CNcnOutboxObserver* self = new (ELeave) CNcnOutboxObserver( aModel ); |
|
84 |
|
85 // Push it to stack while executing the constructor |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL(); |
|
88 CleanupStack::Pop(); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CNcnOutboxObserver::~CNcnOutboxObserver |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 CNcnOutboxObserver::~CNcnOutboxObserver() |
|
98 { |
|
99 if( iModel ) |
|
100 { |
|
101 // remove observer from msv session handler |
|
102 iModel->MsvSessionHandler().RemoveObserver( this ); |
|
103 } |
|
104 |
|
105 delete iSignalStrengthHandler; |
|
106 |
|
107 EndSessions(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CNcnOutboxObserver::CheckOutboxAndNotifyL |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CNcnOutboxObserver::CheckOutboxAndNotifyL() |
|
115 { |
|
116 NCN_RDEBUG( _L("CNcnOutboxObserver::CheckOutboxAndNotifyL" ) ); |
|
117 // Check messagecount in outbox |
|
118 TInt msgCount = iOutboxFolder->Count(); |
|
119 |
|
120 // Set msg count to the CR key |
|
121 NCN_RDEBUG_INT( _L("CNcnOutboxObserver::CheckOutboxAndNotifyL SetCRInt(KNcnMessageCountInOutbox) %d" ), msgCount ); |
|
122 User::LeaveIfError( iModel->SetCRInt( |
|
123 KCRUidNcnList, KNcnMessageCountInOutbox, msgCount ) ); |
|
124 |
|
125 if( msgCount ) |
|
126 { |
|
127 // Turn indicator on, if any messages in outbox |
|
128 iModel->NotifyPublishAndSubscribe( |
|
129 KUidSystemCategory, |
|
130 KPSNcnOutboxStatus, |
|
131 ENcnDocumentsInOutbox ); |
|
132 } |
|
133 else |
|
134 { |
|
135 // If no messages in outbox, remove indicator |
|
136 iModel->NotifyPublishAndSubscribe( |
|
137 KUidSystemCategory, |
|
138 KPSNcnOutboxStatus, |
|
139 ENcnOutboxEmpty ); |
|
140 } |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------- |
|
144 // CNcnOutboxObserver::SignalStrengthUpdatedL |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 void CNcnOutboxObserver::SignalStrengthAndBarUpdatedL( TInt /*aNewSignalValue*/, TInt aNewBarValue ) |
|
148 { |
|
149 NCN_RDEBUG_INT( _L("CNcnOutboxObserver::SignalStrengthUpdatedL - Signal bars %d"), aNewBarValue ); |
|
150 |
|
151 // pass new bar value to outbox sender |
|
152 InformOutboxSenderL( aNewBarValue ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CNcnOutboxObserver::InformOutboxSenderL |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 void CNcnOutboxObserver::InformOutboxSenderL( const TInt& aNetworkBars ) |
|
160 { |
|
161 if( iOutboxSender ) |
|
162 { |
|
163 NCN_RDEBUG( _L("CNcnOutboxObserver::InformOutboxSenderL - Informing outbox sender.") ); |
|
164 |
|
165 iOutboxSender->CheckAndStartSendingL( aNetworkBars ); |
|
166 } |
|
167 else |
|
168 { |
|
169 NCN_RDEBUG( _L("CNcnOutboxObserver::InformOutboxSenderL - Outbox sender not initialized." ) ); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CNcnOutboxObserver::StartSessionsL |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CNcnOutboxObserver::StartSessionsL( CMsvSession& aMsvSession ) |
|
178 { |
|
179 // Set outbox folder |
|
180 iOutboxFolder = aMsvSession.GetEntryL( KMsvGlobalOutBoxIndexEntryId ); |
|
181 iOutboxFolder->AddObserverL( *this ); |
|
182 |
|
183 // Remove the Sender, if it exists |
|
184 delete iOutboxSender; |
|
185 iOutboxSender = NULL; |
|
186 |
|
187 // Check if feature is supported |
|
188 if( iModel->IsSupported( KNcnOfflineSupport ) ) |
|
189 { |
|
190 NCN_RDEBUG( _L("CNcnOutboxObserver::StartSessionsL - Initializing outbox sender.." ) ); |
|
191 iOutboxSender = CNcnOutboxSender::NewL( iModel, aMsvSession ); |
|
192 |
|
193 NCN_RDEBUG( _L("CNcnOutboxObserver::StartSessionsL - Informing outbox sender of network status.." ) ); |
|
194 |
|
195 // get current signal bar value |
|
196 TInt signalBars = 0; |
|
197 TRAPD( err, signalBars = iSignalStrengthHandler->BarValueL() ); |
|
198 |
|
199 // check error |
|
200 if( err == KErrNone ) |
|
201 { |
|
202 NCN_RDEBUG_INT( _L( "CNcnOutboxObserver::StartSessionsL - Got signal bar value %d, notifying.."), signalBars ); |
|
203 iOutboxSender->CheckAndStartSendingL( signalBars ); |
|
204 } |
|
205 else |
|
206 { |
|
207 NCN_RDEBUG_INT( _L("CNcnOutboxObserver::StartSessionsL - Failed to get signal bar value (err = %d)"), err ); |
|
208 } |
|
209 } |
|
210 |
|
211 // Check if there are messages in the OutBox. |
|
212 CheckOutboxAndNotifyL(); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CNcnOutboxObserver::EndSessions |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 void CNcnOutboxObserver::EndSessions() |
|
220 { |
|
221 // Delete Outbox sender |
|
222 delete iOutboxSender; |
|
223 iOutboxSender = NULL; |
|
224 |
|
225 if( iOutboxFolder ) |
|
226 { |
|
227 // Delete outbox folder |
|
228 iOutboxFolder->RemoveObserver( *this ); |
|
229 delete iOutboxFolder; |
|
230 iOutboxFolder = NULL; |
|
231 } |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CNcnOutboxObserver::HandleMsvSessionReadyL |
|
236 // --------------------------------------------------------- |
|
237 // |
|
238 void CNcnOutboxObserver::HandleMsvSessionReadyL( CMsvSession& aMsvSession ) |
|
239 { |
|
240 StartSessionsL( aMsvSession ); |
|
241 } |
|
242 // --------------------------------------------------------- |
|
243 // CNcnOutboxObserver::HandleMsvSessionClosedL |
|
244 // --------------------------------------------------------- |
|
245 // |
|
246 void CNcnOutboxObserver::HandleMsvSessionClosedL() |
|
247 { |
|
248 EndSessions(); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CNcnOutboxObserver::HandleEntryEventL |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CNcnOutboxObserver::HandleEntryEventL( |
|
256 TMsvEntryEvent /*aEvent*/, |
|
257 TAny* /*aArg1*/, |
|
258 TAny* /*aArg2*/, |
|
259 TAny* /*aArg3*/ ) |
|
260 { |
|
261 // Count objects in folders for every event |
|
262 CheckOutboxAndNotifyL(); |
|
263 } |
|
264 |
|
265 // End of File |