|
1 /* |
|
2 * Copyright (c) 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: Wait note dialog for scanning |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <StringLoader.h> |
|
21 #include <avkon.mbg> |
|
22 #include <aknconsts.h> |
|
23 #include <StringLoader.h> |
|
24 #include <aknnotedialog.h> |
|
25 #include <featmgr.h> |
|
26 #include <driveinfo.h> |
|
27 |
|
28 #include <mpxlog.h> |
|
29 #include <mpxcollectionframeworkdefs.h> |
|
30 #include <mpxcollectionmessagedefs.h> |
|
31 #include <mpxcollectionmessage.h> |
|
32 #include <mpxwaitnotedialog.rsg> |
|
33 #include <mpxharvesterutility.h> |
|
34 #include <mpxcollectionutility.h> |
|
35 #include <mpxmessagegeneraldefs.h> |
|
36 #include <mpxcollectionplugin.hrh> |
|
37 #include <mpxcollectionmessagedefs.h> |
|
38 #include <mpxmessagecontainerdefs.h> |
|
39 #include <mpxmediageneraldefs.h> |
|
40 #include <mpxcommandgeneraldefs.h> |
|
41 #include <mpxcollectioncommanddefs.h> |
|
42 #include "mpxscanningdialog.h" |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Default Constructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CMPXScanningWaitDialog::CMPXScanningWaitDialog( MMPXWaitNoteObserver* aObs, |
|
50 TWaitNoteType aType ) : |
|
51 CMPXWaitNoteDialog( aObs, aType ) |
|
52 { |
|
53 iNumItemsAdded = 0; |
|
54 iInitialMMCCount = 0; |
|
55 iTotalNewTracks = 0; |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // 2nd Phased constructor |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CMPXScanningWaitDialog::ConstructL() |
|
64 { |
|
65 iHarvesterUtil = CMPXHarvesterFactory::NewL(); |
|
66 BaseConstructL(); |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Two Phased constructor |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CMPXScanningWaitDialog* CMPXScanningWaitDialog::NewL( MMPXWaitNoteObserver* aObs, |
|
75 TWaitNoteType aType ) |
|
76 { |
|
77 CMPXScanningWaitDialog* self = new(ELeave)CMPXScanningWaitDialog( aObs, |
|
78 aType ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop( self ); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Virtual destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CMPXScanningWaitDialog::~CMPXScanningWaitDialog() |
|
90 { |
|
91 if( iHarvesterUtil ) |
|
92 { |
|
93 iHarvesterUtil->Close(); |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CMPXScanningWaitDialog::PreNoteDisplayHandleL() |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CMPXScanningWaitDialog::PreNoteDisplayHandleL() |
|
102 { |
|
103 // CBA |
|
104 SetCBAL( R_MPX_WAITNOTE_SOFTKEYS_EMPTY_STOP ); |
|
105 |
|
106 // Text |
|
107 HBufC* text = NULL; |
|
108 if( iWaitNoteType == EMPXScanningNote ) |
|
109 { |
|
110 text = StringLoader::LoadLC( R_MPX_SCANNING_DB_TXT ); |
|
111 } |
|
112 else if( iWaitNoteType == EMPXRefreshingNote ) |
|
113 { |
|
114 text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_TXT, 0 ); |
|
115 } |
|
116 else // iWaitNoteType == EMPXCorruptScanningNote |
|
117 { |
|
118 text = StringLoader::LoadLC( R_MPX_REPAIRING_CORRUPT_DB ); |
|
119 } |
|
120 |
|
121 SetTextL( *text ); |
|
122 CleanupStack::PopAndDestroy( text ); |
|
123 |
|
124 // Icon |
|
125 TNoteIconInfo icon( (TInt)EMbmAvkonQgn_note_progress, |
|
126 (TInt)EMbmAvkonQgn_note_progress_mask, |
|
127 TFileName(KAvkonBitmapFile) ); |
|
128 SetIconL( icon ); |
|
129 |
|
130 // If we are repairing a corrupt db, we first clean up the old ones |
|
131 // |
|
132 if( iWaitNoteType == EMPXCorruptScanningNote ) |
|
133 { |
|
134 HandleDatabaseCorruptionL(); |
|
135 } |
|
136 |
|
137 // Start the scanning in harvester |
|
138 iHarvesterUtil->ScanL(); |
|
139 iScanningError = KErrNone; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CMPXScanningWaitDialog::PostNoteHandleL() |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CMPXScanningWaitDialog::PostNoteHandleL( TInt aButtonId ) |
|
147 { |
|
148 MPX_DEBUG1("CMPXScanningWaitDialog::PostNoteHandleL --->"); |
|
149 |
|
150 MPX_DEBUG1(" BUGHUNT: cover display"); |
|
151 TInt textRsc( KErrNotFound ); |
|
152 |
|
153 HBufC* text = NULL; |
|
154 if( aButtonId == EAknSoftkeyCancel ) |
|
155 { |
|
156 iScanningError = KErrCancel; |
|
157 // If harvester crashed,..... restart it. |
|
158 MPX_TRAPD( err, iHarvesterUtil->CancelScanL() ); |
|
159 if( err != KErrNone ) |
|
160 { |
|
161 iHarvesterUtil->Close(); |
|
162 iHarvesterUtil = NULL; |
|
163 iHarvesterUtil = CMPXHarvesterFactory::NewL(); |
|
164 } |
|
165 } |
|
166 else if( iScanningError >= KErrNone ) |
|
167 { |
|
168 // Show completed scan note |
|
169 // |
|
170 if( iWaitNoteType == EMPXScanningNote || |
|
171 iWaitNoteType == EMPXCorruptScanningNote ) |
|
172 { |
|
173 text = StringLoader::LoadLC( R_MPX_SCANNING_COMPLETE_TXT, |
|
174 iNumItemsAdded ); |
|
175 textRsc = R_MPX_SCANNING_COMPLETE_TXT; |
|
176 } |
|
177 else // iWaitNoteType == EMPXRefreshNote |
|
178 { |
|
179 text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_COMPLETE_TXT, |
|
180 iNumItemsAdded ); |
|
181 textRsc = R_MPX_REFRESHING_DB_COMPLETE_TXT; |
|
182 } |
|
183 } |
|
184 else if( iScanningError == KErrDiskFull ) |
|
185 { |
|
186 // If the error was disk full |
|
187 // |
|
188 text = StringLoader::LoadLC( R_MPX_MEM_LO_NOT_ENOUGH_MEMORY, |
|
189 iNumItemsAdded ); |
|
190 } |
|
191 else |
|
192 { |
|
193 // Show stopped notes |
|
194 // |
|
195 if( iWaitNoteType == EMPXScanningNote || |
|
196 iWaitNoteType == EMPXCorruptScanningNote ) |
|
197 { |
|
198 textRsc = R_MPX_SCANNING_STOPPED_TXT; |
|
199 text = StringLoader::LoadLC( R_MPX_SCANNING_STOPPED_TXT, |
|
200 iNumItemsAdded ); |
|
201 } |
|
202 else // iWaitNoteType == EMPXRefreshNote |
|
203 { |
|
204 textRsc = R_MPX_REFRESHING_DB_STOPPED_TXT; |
|
205 text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_STOPPED_TXT, |
|
206 iNumItemsAdded ); |
|
207 } |
|
208 } |
|
209 |
|
210 // Show the note |
|
211 if( text ) |
|
212 { |
|
213 if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) ) |
|
214 { |
|
215 DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, textRsc, iNumItemsAdded, |
|
216 *text, CAknNoteDialog::EConfirmationTone ); |
|
217 } |
|
218 else |
|
219 { |
|
220 DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, *text, |
|
221 CAknNoteDialog::EConfirmationTone ); |
|
222 } |
|
223 CleanupStack::PopAndDestroy( text ); |
|
224 } |
|
225 |
|
226 MPX_DEBUG1("<--CMPXScanningWaitDialog::PostNoteHandleL"); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Handle the collection message |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CMPXScanningWaitDialog::HandleCollectionMessage( |
|
234 CMPXMessage* aMessage, TInt aError ) |
|
235 { |
|
236 if ( aError == KErrNone && aMessage ) |
|
237 { |
|
238 TRAP_IGNORE( DoHandleCollectionMessageL( *aMessage ) ); |
|
239 } |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // Cleanup both collection and harvester databases |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CMPXScanningWaitDialog::HandleDatabaseCorruptionL() |
|
247 { |
|
248 // Cleanup Harvester |
|
249 iHarvesterUtil->RecreateDatabasesL(); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // MMPXCollectionObserver |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CMPXScanningWaitDialog::DoHandleCollectionMessageL( |
|
257 const CMPXMessage& aMessage ) |
|
258 { |
|
259 MPX_FUNC( "CMPXScanningWaitDialog::DoHandleCollectionMessageL" ); |
|
260 TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
261 if ( KMPXMessageGeneral == id ) |
|
262 { |
|
263 TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ); |
|
264 TInt op( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ); |
|
265 TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) ); |
|
266 |
|
267 if(event == TMPXCollectionMessage::EBroadcastEvent && |
|
268 ((op == EMcMsgRefreshStart) || (op == EMcMsgRefreshEnd))) |
|
269 { |
|
270 TInt mmcCount = 0; |
|
271 if ( iWaitNoteType == EMPXScanningNote) |
|
272 { |
|
273 //get removable drive number |
|
274 TInt removableDrive( EDriveF ); |
|
275 #ifdef RD_MULTIPLE_DRIVE |
|
276 User::LeaveIfError( DriveInfo::GetDefaultDrive( |
|
277 DriveInfo::EDefaultRemovableMassStorage, |
|
278 removableDrive ) ); |
|
279 #endif // RD_MULTIPLE_DRIVE |
|
280 |
|
281 //get count from music db |
|
282 |
|
283 CMPXCommand* cmdCount = CMPXMedia::NewL(); |
|
284 CleanupStack::PushL( cmdCount ); |
|
285 cmdCount->SetTObjectValueL<TMPXCommandId>( |
|
286 KMPXCommandGeneralId, |
|
287 KMPXCommandCollectionGetCount ); |
|
288 cmdCount->SetTObjectValueL<TBool>( |
|
289 KMPXCommandGeneralDoSync, |
|
290 ETrue ); |
|
291 cmdCount->SetTObjectValueL<TInt>( |
|
292 KMPXCommandCollectionCountDrive, |
|
293 removableDrive); |
|
294 |
|
295 cmdCount->SetTObjectValueL<TInt>( |
|
296 KMPXCommandCollectionCountTable, |
|
297 EMPXCollectionCountTotal ); |
|
298 |
|
299 // Get the collection UIDs |
|
300 RArray<TUid> ary; |
|
301 CleanupClosePushL( ary ); |
|
302 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) ); |
|
303 TUid musicCollectionId = |
|
304 iCollection->CollectionIDL( ary.Array() ); |
|
305 CleanupStack::PopAndDestroy( &ary ); |
|
306 cmdCount->SetTObjectValueL<TInt>( |
|
307 KMPXCommandGeneralCollectionId, |
|
308 musicCollectionId.iUid ); |
|
309 |
|
310 TRAPD(err, iCollection->Collection().CommandL( *cmdCount ) ); |
|
311 |
|
312 if ( KErrNotFound != err ) |
|
313 { |
|
314 User::LeaveIfError( err ); |
|
315 } |
|
316 |
|
317 // returned command should contain count |
|
318 if ( cmdCount->IsSupported( KMPXCommandCollectionCountValue ) ) |
|
319 { |
|
320 mmcCount = |
|
321 cmdCount->ValueTObjectL<TInt>( |
|
322 KMPXCommandCollectionCountValue ); |
|
323 } |
|
324 CleanupStack::PopAndDestroy( cmdCount ); |
|
325 } |
|
326 if( op == EMcMsgRefreshStart ) |
|
327 { |
|
328 MPX_DEBUG1("refreshStart store the initial count"); |
|
329 iInitialMMCCount = mmcCount; |
|
330 } |
|
331 |
|
332 if( op == EMcMsgRefreshEnd ) |
|
333 { |
|
334 MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL refresh end"); |
|
335 iNumItemsAdded = mmcCount; |
|
336 switch ( iWaitNoteType ) |
|
337 { |
|
338 case EMPXScanningNote: |
|
339 { |
|
340 //total new tracks on external memory |
|
341 TInt totalNewOnMMC = iNumItemsAdded - iInitialMMCCount; |
|
342 |
|
343 //total new tracks on internal memory |
|
344 TInt newOnPhone = iTotalNewTracks - totalNewOnMMC; |
|
345 |
|
346 //total new tracks to dispaly |
|
347 iNumItemsAdded += newOnPhone; |
|
348 |
|
349 break; |
|
350 } |
|
351 |
|
352 case EMPXOpeningNote: |
|
353 case EMPXRefreshingNote: |
|
354 case EMPXCorruptScanningNote: |
|
355 case EMPXUsbEventNote: |
|
356 case EMPXMTPEventNote: |
|
357 case EMPXFormatScanningNote: |
|
358 case EMPXMediaNotAvailableNote: |
|
359 case EMPXNoteNotDefined: |
|
360 // fall through |
|
361 default: |
|
362 { |
|
363 // Synchronize the number of items added if we had no errors |
|
364 // |
|
365 if( data >= KErrNone ) |
|
366 { |
|
367 iNumItemsAdded = data; |
|
368 } |
|
369 break; |
|
370 } |
|
371 }; |
|
372 |
|
373 // If cancel was pressed, iWaitDialog is NULL |
|
374 // |
|
375 if( iWaitDialog ) |
|
376 { |
|
377 MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL killing dialog"); |
|
378 iScanningError = data; |
|
379 iWaitDialog->ProcessFinishedL(); |
|
380 } |
|
381 |
|
382 // Delay showing the number added dialog |
|
383 if( iScanningError == KErrCancel ) |
|
384 { |
|
385 PostNoteHandleL( EAknSoftkeyOk ); |
|
386 } |
|
387 |
|
388 // Save the error code |
|
389 iScanningError = data; |
|
390 } |
|
391 } |
|
392 else if( event == TMPXCollectionMessage::EBroadcastEvent && |
|
393 op == EMcMsgDiskInserted ) |
|
394 { |
|
395 // Dismiss this scanning note because scanning will be restarted |
|
396 // |
|
397 MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL \ |
|
398 dismissing scan because of refresh msg "); |
|
399 if( iWaitDialog ) |
|
400 { |
|
401 MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL killing dialog"); |
|
402 iWaitDialog->ProcessFinishedL(); |
|
403 } |
|
404 |
|
405 iScanningError = KErrNone; |
|
406 } |
|
407 } |
|
408 else if(id == KMPXMessageIdItemChanged) |
|
409 { |
|
410 // Loop through messages for arrays. |
|
411 // |
|
412 if (aMessage.IsSupported(KMPXMessageArrayContents)) |
|
413 { |
|
414 const CMPXMessageArray* messageArray = |
|
415 aMessage.Value<CMPXMessageArray>(KMPXMessageArrayContents); |
|
416 User::LeaveIfNull(const_cast<CMPXMessageArray*>(messageArray)); |
|
417 |
|
418 for( TInt i=0; i<messageArray->Count(); ++i ) |
|
419 { |
|
420 HandleCollectionMessage( messageArray->AtL( i ), KErrNone ); |
|
421 } |
|
422 } |
|
423 // Single item |
|
424 else |
|
425 { |
|
426 MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL KMPXMessageIdItemChanged"); |
|
427 TMPXChangeEventType changeType( aMessage.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) ); |
|
428 TMPXGeneralCategory cat(aMessage.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory)); |
|
429 if( changeType == EMPXItemInserted && |
|
430 (cat == EMPXSong || cat == EMPXPlaylist || cat == EMPXPodcast) ) |
|
431 { |
|
432 iNumItemsAdded++; |
|
433 iTotalNewTracks++; |
|
434 // Update wait note text if refreshing |
|
435 if( iWaitNoteType == EMPXRefreshingNote && |
|
436 iScanningError == KErrNone ) |
|
437 { |
|
438 HBufC* text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_TXT, |
|
439 iNumItemsAdded ); |
|
440 SetTextL( *text ); |
|
441 CleanupStack::PopAndDestroy( text ); |
|
442 } |
|
443 } |
|
444 } |
|
445 } |
|
446 } |
|
447 |
|
448 // END OF FILE |
|
449 |