|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 server application start-up monitor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2ServerAppMonitor.h" |
|
21 |
|
22 // Phonebook2 |
|
23 #include "mpbk2serverappstartupobserver.h" |
|
24 #include "CPbk2ServerAppAppUi.h" |
|
25 #include <CPbk2StoreProperty.h> |
|
26 #include <CPbk2StorePropertyArray.h> |
|
27 #include <MPbk2StoreObservationRegister.h> |
|
28 #include <CPbk2AppUiBase.h> |
|
29 #include <MPbk2StartupObserver.h> |
|
30 #include <MPbk2ApplicationServices.h> |
|
31 #include <Pbk2CommonUi.rsg> |
|
32 #include <Pbk2UIControls.rsg> |
|
33 |
|
34 // Virtual Phonebook |
|
35 #include <MVPbkContactStore.h> |
|
36 #include <MVPbkContactStoreProperties.h> |
|
37 #include <MVPbkContactStoreList.h> |
|
38 |
|
39 // System includes |
|
40 #include <StringLoader.h> |
|
41 #include <aknnotewrappers.h> |
|
42 |
|
43 /// Unnamed namespace for local definitions |
|
44 namespace { |
|
45 |
|
46 const TInt KGranularity( 4 ); |
|
47 |
|
48 } /// namespace |
|
49 |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // CPbk2ServerAppMonitor::CPbk2ServerAppMonitor |
|
53 // -------------------------------------------------------------------------- |
|
54 // |
|
55 CPbk2ServerAppMonitor::CPbk2ServerAppMonitor |
|
56 ( const MVPbkContactStoreList& aStoreList, |
|
57 MPbk2ServerAppStartupObserver& aObserver ) : |
|
58 iContactStoreList( &aStoreList ), |
|
59 iServerAppObserver( aObserver ) |
|
60 { |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2ServerAppMonitor::~CPbk2ServerAppMonitor |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CPbk2ServerAppMonitor::~CPbk2ServerAppMonitor() |
|
68 { |
|
69 delete iUnavailableStoreNames; |
|
70 iObservers.Close(); |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CPbk2ServerAppMonitor::NewL |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 CPbk2ServerAppMonitor* CPbk2ServerAppMonitor::NewL( |
|
78 const MVPbkContactStoreList& aStoreList, |
|
79 MPbk2ServerAppStartupObserver& aObserver ) |
|
80 { |
|
81 CPbk2ServerAppMonitor* self = |
|
82 new ( ELeave ) CPbk2ServerAppMonitor( aStoreList, aObserver ); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2ServerAppMonitor::ConstructL |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 void CPbk2ServerAppMonitor::ConstructL() |
|
94 { |
|
95 iEikEnv = CEikonEnv::Static(); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2ServerAppMonitor::StartupBeginsL |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 void CPbk2ServerAppMonitor::StartupBeginsL() |
|
103 { |
|
104 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
105 StoreObservationRegister().RegisterStoreEventsL( *this ); |
|
106 } |
|
107 |
|
108 // -------------------------------------------------------------------------- |
|
109 // CPbk2ServerAppMonitor::HandleStartupComplete |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 void CPbk2ServerAppMonitor::HandleStartupComplete() |
|
113 { |
|
114 // Do nothing |
|
115 } |
|
116 |
|
117 // -------------------------------------------------------------------------- |
|
118 // CPbk2ServerAppMonitor::HandleStartupFailed |
|
119 // -------------------------------------------------------------------------- |
|
120 // |
|
121 void CPbk2ServerAppMonitor::HandleStartupFailed( TInt aError ) |
|
122 { |
|
123 HandleError( aError ); |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CPbk2ServerAppMonitor::RegisterEventsL |
|
128 // -------------------------------------------------------------------------- |
|
129 // |
|
130 void CPbk2ServerAppMonitor::RegisterEventsL |
|
131 ( MPbk2StartupObserver& aObserver ) |
|
132 { |
|
133 if ( iObservers.Find( &aObserver ) == KErrNotFound ) |
|
134 { |
|
135 iObservers.AppendL( &aObserver ); |
|
136 } |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2ServerAppMonitor::DeregisterEvents |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 void CPbk2ServerAppMonitor::DeregisterEvents |
|
144 ( MPbk2StartupObserver& aObserver ) |
|
145 { |
|
146 TInt pos = iObservers.Find( &aObserver ); |
|
147 if ( pos != KErrNotFound ) |
|
148 { |
|
149 iObservers.Remove( pos ); |
|
150 } |
|
151 } |
|
152 |
|
153 // -------------------------------------------------------------------------- |
|
154 // CPbk2ServerAppMonitor::NotifyViewActivationL |
|
155 // -------------------------------------------------------------------------- |
|
156 // |
|
157 void CPbk2ServerAppMonitor::NotifyViewActivationL( TUid /*aViewId*/ ) |
|
158 { |
|
159 // UI services are based on dialogs not application views |
|
160 } |
|
161 |
|
162 // -------------------------------------------------------------------------- |
|
163 // CPbk2ServerAppMonitor::NotifyViewActivationL |
|
164 // -------------------------------------------------------------------------- |
|
165 // |
|
166 void CPbk2ServerAppMonitor::NotifyViewActivationL( |
|
167 TUid /*aViewId*/, MVPbkContactViewBase& /*aContactView*/ ) |
|
168 { |
|
169 // UI services are based on dialogs not application views |
|
170 } |
|
171 |
|
172 // -------------------------------------------------------------------------- |
|
173 // CPbk2ServerAppMonitor::StoreReady |
|
174 // -------------------------------------------------------------------------- |
|
175 // |
|
176 void CPbk2ServerAppMonitor::StoreReady( MVPbkContactStore& aContactStore ) |
|
177 { |
|
178 HandleStoreNotification( aContactStore ); |
|
179 } |
|
180 |
|
181 // -------------------------------------------------------------------------- |
|
182 // CPbk2ServerAppMonitor::StoreUnavailable |
|
183 // -------------------------------------------------------------------------- |
|
184 // |
|
185 void CPbk2ServerAppMonitor::StoreUnavailable |
|
186 ( MVPbkContactStore& aContactStore, TInt /*aReason*/ ) |
|
187 { |
|
188 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
189 ( *iEikEnv->EikAppUi() ); |
|
190 |
|
191 // Get the property of the failed store |
|
192 const CPbk2StoreProperty* prop = appUi.ApplicationServices(). |
|
193 StoreProperties().FindProperty |
|
194 ( aContactStore.StoreProperties().Uri() ); |
|
195 |
|
196 if ( prop && prop->StoreName().Length() > 0 ) |
|
197 { |
|
198 TRAPD(res, AddUnavailableStoreNameL( prop->StoreName() ) ); |
|
199 HandleError( res ); |
|
200 } |
|
201 else |
|
202 { |
|
203 TRAPD(res, AddUnavailableStoreNameL( |
|
204 aContactStore.StoreProperties().Uri().UriDes() ) ); |
|
205 HandleError( res ); |
|
206 } |
|
207 |
|
208 HandleStoreNotification( aContactStore ); |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CPbk2ServerAppMonitor::HandleStoreEventL |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 void CPbk2ServerAppMonitor::HandleStoreEventL |
|
216 ( MVPbkContactStore& /*aContactStore*/, |
|
217 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
218 { |
|
219 // Do nothing |
|
220 } |
|
221 |
|
222 // -------------------------------------------------------------------------- |
|
223 // CPbk2ServerAppMonitor::AddUnavailableStoreNameL |
|
224 // -------------------------------------------------------------------------- |
|
225 // |
|
226 void CPbk2ServerAppMonitor::AddUnavailableStoreNameL( const TDesC& aName ) |
|
227 { |
|
228 if (!iUnavailableStoreNames) |
|
229 { |
|
230 iUnavailableStoreNames = new(ELeave) CDesCArrayFlat( KGranularity ); |
|
231 } |
|
232 |
|
233 TInt dummy = 0; |
|
234 if ( iUnavailableStoreNames->Find( aName, dummy ) != 0 ) |
|
235 { |
|
236 iUnavailableStoreNames->AppendL( aName ); |
|
237 } |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CPbk2ServerAppMonitor::ShowUnavailableStoresL |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 void CPbk2ServerAppMonitor::ShowUnavailableStoresL() |
|
245 { |
|
246 if ( iUnavailableStoreNames ) |
|
247 { |
|
248 const TInt count = iUnavailableStoreNames->MdcaCount(); |
|
249 for ( TInt i = 0; i < count ;++i ) |
|
250 { |
|
251 // Get the store name |
|
252 HBufC* text = StringLoader::LoadLC( |
|
253 R_QTN_PHOB_STORE_NOT_AVAILABLE, |
|
254 iUnavailableStoreNames->MdcaPoint( i ) ); |
|
255 CAknInformationNote* note = |
|
256 new ( ELeave ) CAknInformationNote( ETrue ); |
|
257 // Show "not available" note |
|
258 note->ExecuteLD( *text ); |
|
259 CleanupStack::PopAndDestroy( text ); |
|
260 } |
|
261 } |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CPbk2ServerAppMonitor::HandleStoreNotification |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 void CPbk2ServerAppMonitor::HandleStoreNotification |
|
269 ( MVPbkContactStore& /*aContactStore*/ ) |
|
270 { |
|
271 ++iHandledStores; |
|
272 if ( iContactStoreList->Count() == iHandledStores ) |
|
273 { |
|
274 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
275 StoreObservationRegister().DeregisterStoreEvents( *this ); |
|
276 // Show unavailable stores if exists |
|
277 TRAP_IGNORE( ShowUnavailableStoresL() ); |
|
278 SendMessageToObservers(); |
|
279 } |
|
280 } |
|
281 |
|
282 // -------------------------------------------------------------------------- |
|
283 // CPbk2ServerAppMonitor::SendMessageToObservers |
|
284 // -------------------------------------------------------------------------- |
|
285 // |
|
286 void CPbk2ServerAppMonitor::SendMessageToObservers() |
|
287 { |
|
288 TInt err( KErrNone ); |
|
289 const TInt count = iObservers.Count(); |
|
290 { |
|
291 for ( TInt i = 0; i < count && err == KErrNone; ++i ) |
|
292 { |
|
293 TRAP( err, iObservers[i]->ContactUiReadyL( *this ) ); |
|
294 HandleError( err ); |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 // -------------------------------------------------------------------------- |
|
300 // CPbk2ServerAppMonitor::HandleError |
|
301 // -------------------------------------------------------------------------- |
|
302 // |
|
303 void CPbk2ServerAppMonitor::HandleError( TInt aResult ) |
|
304 { |
|
305 if ( aResult != KErrNone ) |
|
306 { |
|
307 iServerAppObserver.StartupCanceled( aResult ); |
|
308 } |
|
309 } |
|
310 |
|
311 // End of File |