|
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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <mpxlog.h> |
|
24 #include <vcxmyvideosdefs.h> |
|
25 #include "vcxmyvideosdrivemonitor.h" |
|
26 #include "vcxmyvideosdrivemonitorevent.h" |
|
27 #include <bldvariant.hrh> |
|
28 #include <driveinfo.h> //multiple drive stuff |
|
29 #include <centralrepository.h> |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 #ifdef _DEBUG |
|
37 _LIT( KVcxMyVideosMediaNotPresentDes, "EMediaNotPresent"); |
|
38 _LIT( KVcxMyVideosMediaUnknownDes, "EMediaUnknown"); |
|
39 _LIT( KVcxMyVideosMediaFloppyDes, "EMediaFloppy"); |
|
40 _LIT( KVcxMyVideosMediaHardDiskDes, "EMediaHardDisk"); |
|
41 _LIT( KVcxMyVideosMediaCdRomDes, "EMediaCdRom"); |
|
42 _LIT( KVcxMyVideosMediaRamDes, "EMediaRam"); |
|
43 _LIT( KVcxMyVideosMediaFlashDes, "EMediaFlash"); |
|
44 _LIT( KVcxMyVideosMediaRomDes, "EMediaRom"); |
|
45 _LIT( KVcxMyVideosMediaRemoteDes, "EMediaRemote"); |
|
46 _LIT( KVcxMyVideosMediaNANDFlashDes, "EMediaNANDFlash"); |
|
47 #endif |
|
48 |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 |
|
52 |
|
53 // ============================ MEMBER FUNCTIONS =============================== |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CVcxMyVideosDriveMonitor::CVcxMyVideosDriveMonitor |
|
57 // C++ default constructor can NOT contain any code, that |
|
58 // might leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CVcxMyVideosDriveMonitor::CVcxMyVideosDriveMonitor() |
|
62 : CActive( EPriorityStandard ) |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CVcxMyVideosDriveMonitor::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CVcxMyVideosDriveMonitor::ConstructL( const RFs& aFileSession ) |
|
72 { |
|
73 iFs = aFileSession; |
|
74 iIfsIsProvidedByUser = ETrue; |
|
75 |
|
76 ConstructL(); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CVcxMyVideosDriveMonitor::ConstructL |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CVcxMyVideosDriveMonitor::ConstructL() |
|
85 { |
|
86 iObservers.Reset(); |
|
87 iAvailableDrives.Reset(); |
|
88 iPreviousAvailableDrives.Reset(); |
|
89 |
|
90 if ( !iIfsIsProvidedByUser ) |
|
91 { |
|
92 User::LeaveIfError( iFs.Connect() ); |
|
93 } |
|
94 |
|
95 CActiveScheduler::Add( this ); |
|
96 RefreshAvailableDrivesL(); |
|
97 |
|
98 #if 0 |
|
99 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: PhoneMemoryDrive() returns %d", |
|
100 PhoneMemoryDrive()); |
|
101 #endif |
|
102 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: MemoryCardDrive() returns %d", |
|
103 MemoryCardDrive()); |
|
104 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: MassStorageDrive() returns %d", |
|
105 MassStorageDrive()); |
|
106 #if 0 |
|
107 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: FixedDrive(c-drive excluded) returns %d", |
|
108 FixedDrive( ETrue )); |
|
109 #endif |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CVcxMyVideosDriveMonitor::NewL |
|
114 // Two-phased constructor. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 CVcxMyVideosDriveMonitor* CVcxMyVideosDriveMonitor::NewL() |
|
118 { |
|
119 CVcxMyVideosDriveMonitor* self = new( ELeave ) CVcxMyVideosDriveMonitor(); |
|
120 |
|
121 CleanupStack::PushL( self ); |
|
122 self->ConstructL(); |
|
123 CleanupStack::Pop(self); |
|
124 |
|
125 return self; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CVcxMyVideosDriveMonitor::NewL |
|
130 // Two-phased constructor. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 CVcxMyVideosDriveMonitor* CVcxMyVideosDriveMonitor::NewL( const RFs& aFileSession ) |
|
134 { |
|
135 CVcxMyVideosDriveMonitor* self = new( ELeave ) CVcxMyVideosDriveMonitor(); |
|
136 |
|
137 CleanupStack::PushL( self ); |
|
138 self->ConstructL( aFileSession ); |
|
139 CleanupStack::Pop(self); |
|
140 |
|
141 return self; |
|
142 } |
|
143 |
|
144 // Destructor |
|
145 CVcxMyVideosDriveMonitor::~CVcxMyVideosDriveMonitor() |
|
146 { |
|
147 iObservers.Close(); |
|
148 iAvailableDrives.Close(); |
|
149 iPreviousAvailableDrives.Close(); |
|
150 Cancel(); |
|
151 |
|
152 if ( !iIfsIsProvidedByUser ) |
|
153 { |
|
154 iFs.Close(); |
|
155 } |
|
156 } |
|
157 |
|
158 #if 0 // not used in mpx my videos collection |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CVcxMyVideosDriveMonitor::RegisterObserverL |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CVcxMyVideosDriveMonitor::RegisterObserverL( MVcxMyVideosDriveMonitorObserver* aObserver ) |
|
164 { |
|
165 iObservers.AppendL( aObserver ); |
|
166 |
|
167 if ( !IsActive() ) |
|
168 { |
|
169 iFs.NotifyChange( ENotifyDisk, iStatus ); |
|
170 SetActive(); |
|
171 } |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CVcxMyVideosDriveMonitor::RemoveObserverL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CVcxMyVideosDriveMonitor::RemoveObserverL( MVcxMyVideosDriveMonitorObserver* aObserver ) |
|
179 { |
|
180 TInt i; |
|
181 for ( i = 0; i < iObservers.Count(); i++ ) |
|
182 { |
|
183 if ( aObserver == iObservers[i] ) |
|
184 { |
|
185 iObservers.Remove( i ); |
|
186 iObservers.Compress(); |
|
187 break; |
|
188 } |
|
189 } |
|
190 |
|
191 if ( iObservers.Count() == 0 ) |
|
192 { |
|
193 iFs.NotifyChangeCancel(); |
|
194 } |
|
195 } |
|
196 #endif |
|
197 |
|
198 /* |
|
199 N96 without memory card: |
|
200 26/09/2007 11:37:22 CIptvDriveMonitor:: drive[2]: type = EMediaNANDFlash |
|
201 26/09/2007 11:37:22 CIptvDriveMonitor:: MediaAtt flags = 104 DriveAtt flags = 11 |
|
202 26/09/2007 11:37:22 CIptvDriveMonitor:: drive[3]: type = EMediaRam |
|
203 26/09/2007 11:37:22 CIptvDriveMonitor:: MediaAtt flags = 5 DriveAtt flags = 11 |
|
204 26/09/2007 11:37:22 CIptvDriveMonitor:: drive[4]: type = EMediaHardDisk |
|
205 26/09/2007 11:37:22 CIptvDriveMonitor:: MediaAtt flags = 14 DriveAtt flags = 21 |
|
206 26/09/2007 11:37:22 CIptvDriveMonitor:: drive[5]: type = EMediaNotPresent |
|
207 26/09/2007 11:37:22 CIptvDriveMonitor:: MediaAtt flags = 0 DriveAtt flags = 21 |
|
208 26/09/2007 11:37:22 CIptvDriveMonitor:: drive[25]: type = EMediaRom |
|
209 26/09/2007 11:37:22 CIptvDriveMonitor:: MediaAtt flags = 8 DriveAtt flags = 12 |
|
210 |
|
211 N96 with memory card: |
|
212 27/09/2007 6:01:07 CIptvDriveMonitor:: drive[2]: type = EMediaNANDFlash |
|
213 27/09/2007 6:01:07 CIptvDriveMonitor:: MediaAtt flags = 104 DriveAtt flags = 11 |
|
214 27/09/2007 6:01:07 CIptvDriveMonitor:: drive[3]: type = EMediaRam |
|
215 27/09/2007 6:01:07 CIptvDriveMonitor:: MediaAtt flags = 5 DriveAtt flags = 11 |
|
216 27/09/2007 6:01:07 CIptvDriveMonitor:: drive[4]: type = EMediaHardDisk |
|
217 27/09/2007 6:01:07 CIptvDriveMonitor:: MediaAtt flags = 14 DriveAtt flags = 21 |
|
218 27/09/2007 6:01:07 CIptvDriveMonitor:: drive[5]: type = EMediaHardDisk |
|
219 27/09/2007 6:01:07 CIptvDriveMonitor:: MediaAtt flags = 14 DriveAtt flags = 21 |
|
220 27/09/2007 6:01:07 CIptvDriveMonitor:: drive[25]: type = EMediaRom |
|
221 27/09/2007 6:01:07 CIptvDriveMonitor:: MediaAtt flags = 8 DriveAtt flags = 12 |
|
222 |
|
223 N95: |
|
224 |
|
225 N95 8GB: |
|
226 |
|
227 */ |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CVcxMyVideosDriveMonitor::RefreshAvailableDrivesL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CVcxMyVideosDriveMonitor::RefreshAvailableDrivesL() |
|
234 { |
|
235 MPX_FUNC("CVcxMyVideosDriveMonitor::RefreshAvailableDrivesL()"); |
|
236 |
|
237 TDriveList driveList; |
|
238 User::LeaveIfError( iFs.DriveList( driveList ) ); |
|
239 |
|
240 iPreviousAvailableDrives.Reset(); |
|
241 TInt i; |
|
242 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
243 { |
|
244 iPreviousAvailableDrives.Append( iAvailableDrives[i] ); |
|
245 } |
|
246 |
|
247 iAvailableDrives.Reset(); |
|
248 |
|
249 for ( i = 0; i < driveList.Length(); i++ ) |
|
250 { |
|
251 if ( driveList[i] != 0 && i != EDriveY ) // N95 8GB has a 1MB small flash drive at y-drive, rule it out |
|
252 { |
|
253 TDriveInfo driveInfo; |
|
254 User::LeaveIfError( iFs.Drive( driveInfo, i ) ); |
|
255 |
|
256 /* |
|
257 From e32cost.h: |
|
258 const TUint KMediaAttVariableSize = 0x01; |
|
259 const TUint KMediaAttDualDensity = 0x02; |
|
260 const TUint KMediaAttFormattable = 0x04; |
|
261 const TUint KMediaAttWriteProtected = 0x08; |
|
262 const TUint KMediaAttLockable = 0x10; |
|
263 const TUint KMediaAttLocked = 0x20; |
|
264 const TUint KMediaAttHasPassword = 0x40; |
|
265 const TUint KMediaAttReadWhileWrite = 0x80; |
|
266 const TUint KMediaAttDeleteNotify = 0x100; |
|
267 |
|
268 The drive attributes. |
|
269 |
|
270 const TUint KDriveAttLocal = 0x01; |
|
271 const TUint KDriveAttRom = 0x02; |
|
272 const TUint KDriveAttRedirected = 0x04; |
|
273 const TUint KDriveAttSubsted = 0x08; |
|
274 const TUint KDriveAttInternal = 0x10; |
|
275 const TUint KDriveAttRemovable = 0x20; |
|
276 const TUint KDriveAttRemote = 0x40; |
|
277 const TUint KDriveAttTransaction = 0x80; |
|
278 */ |
|
279 |
|
280 MPX_DEBUG3("CVcxMyVideosDriveMonitor:: drive[%d]: type = %S", |
|
281 i, &DriveTypeDes( driveInfo.iType )); |
|
282 |
|
283 MPX_DEBUG3( |
|
284 "CVcxMyVideosDriveMonitor:: MediaAtt flags = %x DriveAtt flags = %x", |
|
285 driveInfo.iMediaAtt, |
|
286 driveInfo.iDriveAtt ); |
|
287 |
|
288 #ifdef __WINSCW__ |
|
289 // (2) c-drive is EMediaRam |
|
290 // (3) d-drive is EMediaHardDisk |
|
291 // (4) e-drive is EMediaHardDisk or EMediaNotPresent |
|
292 // (25) z-drive is EMediaRom |
|
293 if ( (driveInfo.iType == EMediaRam) || // c |
|
294 ((driveInfo.iType == EMediaHardDisk) && i != EDriveD /* skip d */) || // e |
|
295 (driveInfo.iType == EMediaNANDFlash) || // nothing |
|
296 (driveInfo.iType == EMediaNotPresent) ) // e |
|
297 #else |
|
298 // (2) c-drive is EMediaNANDFlash |
|
299 // (3) d-drive is EMediaRam |
|
300 // (4) e-drive is EMediaHardDisk or EMediaNotPresent |
|
301 // (5) f-drive is EMediaHardDisk or EMediaNotPresent |
|
302 // (25) z-drive is EMediaRom |
|
303 if ( (driveInfo.iType == EMediaHardDisk) || // e,f |
|
304 (driveInfo.iType == EMediaNANDFlash) || // c |
|
305 (driveInfo.iType == EMediaNotPresent) ) // e,f |
|
306 #endif // __WINSCW__ |
|
307 { |
|
308 if ( !(driveInfo.iMediaAtt & KMediaAttWriteProtected) && |
|
309 (driveInfo.iDriveAtt & KDriveAttLocal) ) |
|
310 { |
|
311 TVcxMyVideosDriveInfo iptvDriveInfo; |
|
312 TVolumeInfo volumeInfo; |
|
313 TChar ch; |
|
314 |
|
315 iFs.DriveToChar( i, ch ); |
|
316 |
|
317 iptvDriveInfo.iDrive = i; |
|
318 iptvDriveInfo.iDriveChar = ch; |
|
319 iptvDriveInfo.iType = driveInfo.iType; |
|
320 |
|
321 TUint driveStatus; |
|
322 TInt err = DriveInfo::GetDriveStatus( iFs, i, driveStatus ); |
|
323 if ( err == KErrNone ) |
|
324 { |
|
325 if ( driveStatus & DriveInfo::EDriveRemovable ) |
|
326 { |
|
327 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::ERemovable; |
|
328 } |
|
329 } |
|
330 |
|
331 TInt massStorageDrive; |
|
332 err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, |
|
333 massStorageDrive ); |
|
334 if ( err == KErrNone ) |
|
335 { |
|
336 if ( i == massStorageDrive ) |
|
337 { |
|
338 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::EMassStorage; |
|
339 } |
|
340 } |
|
341 |
|
342 if ( driveInfo.iMediaAtt & KMediaAttLocked ) |
|
343 { |
|
344 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::ELocked; |
|
345 } |
|
346 if ( driveInfo.iType == EMediaNotPresent ) |
|
347 { |
|
348 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::EMediaNotPresent; |
|
349 } |
|
350 |
|
351 // When mass storage mode is activated while application is running, |
|
352 // the only hint about that is the TVolumeInfo not being available. |
|
353 // Therefore we mark drive as EMediaNotPresent if that structure |
|
354 // is not available. |
|
355 if ( iFs.Volume( volumeInfo, i ) != KErrNone ) |
|
356 { |
|
357 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::EMediaNotPresent; |
|
358 iptvDriveInfo.iVolumeName.Zero(); |
|
359 } |
|
360 else |
|
361 { |
|
362 iptvDriveInfo.iVolumeName = volumeInfo.iName; |
|
363 } |
|
364 |
|
365 if ( iptvDriveInfo.iFlags & TVcxMyVideosDriveInfo::EMediaNotPresent ) |
|
366 { |
|
367 iptvDriveInfo.iFlags |= TVcxMyVideosDriveInfo::ERemovable; |
|
368 } |
|
369 |
|
370 iAvailableDrives.AppendL( iptvDriveInfo ); |
|
371 } |
|
372 } |
|
373 } |
|
374 } // for |
|
375 |
|
376 // if e and f-drives are available, then c-drive is removed from the available drives list |
|
377 if ( ArrayPos( EDriveE ) != KErrNotFound && |
|
378 ArrayPos( EDriveF ) != KErrNotFound ) |
|
379 { |
|
380 TInt cDrivePos = ArrayPos( EDriveC ); |
|
381 if ( cDrivePos != KErrNotFound ) |
|
382 { |
|
383 MPX_DEBUG1( |
|
384 "CIptvDriveMonitor:: e & f-drives available -> removing c from available drives"); |
|
385 iAvailableDrives.Remove( cDrivePos ); |
|
386 iAvailableDrives.Compress(); |
|
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CVcxMyVideosDriveMonitor::ArrayPos |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 TInt CVcxMyVideosDriveMonitor::ArrayPos( TInt aDrive ) |
|
396 { |
|
397 TInt i; |
|
398 for (i = 0; i < iAvailableDrives.Count(); i++ ) |
|
399 { |
|
400 if ( iAvailableDrives[i].iDrive == aDrive ) |
|
401 { |
|
402 return i; |
|
403 } |
|
404 } |
|
405 return KErrNotFound; |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CVcxMyVideosDriveMonitor::ArrayPosL |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 TInt CVcxMyVideosDriveMonitor::ArrayPosL( TInt aDrive ) |
|
413 { |
|
414 TInt pos; |
|
415 User::LeaveIfError( pos = ArrayPos( aDrive ) ); |
|
416 return pos; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CVcxMyVideosDriveMonitor::MemoryCardDriveL |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 TInt CVcxMyVideosDriveMonitor::MemoryCardDriveL() |
|
424 { |
|
425 TInt drive; |
|
426 User::LeaveIfError( drive = MemoryCardDrive() ); |
|
427 return drive; |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CVcxMyVideosDriveMonitor::MemoryCardDrive |
|
432 // ----------------------------------------------------------------------------- |
|
433 // |
|
434 TInt CVcxMyVideosDriveMonitor::MemoryCardDrive() |
|
435 { |
|
436 TInt i; |
|
437 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
438 { |
|
439 if ( iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ERemovable ) |
|
440 { |
|
441 return iAvailableDrives[i].iDrive; |
|
442 } |
|
443 } |
|
444 return KErrNotFound; |
|
445 } |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // CVcxMyVideosDriveMonitor::MassStorageDriveL |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CVcxMyVideosDriveMonitor::MassStorageDriveL() |
|
452 { |
|
453 TInt drive; |
|
454 User::LeaveIfError( drive = MassStorageDrive() ); |
|
455 return drive; |
|
456 } |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CVcxMyVideosDriveMonitor::MassStorageDrive |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 TInt CVcxMyVideosDriveMonitor::MassStorageDrive() |
|
463 { |
|
464 TInt i; |
|
465 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
466 { |
|
467 if ( iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::EMassStorage ) |
|
468 { |
|
469 return iAvailableDrives[i].iDrive; |
|
470 } |
|
471 } |
|
472 return KErrNotFound; |
|
473 } |
|
474 |
|
475 #if 0 // not used by mpx my videos collection |
|
476 |
|
477 // ----------------------------------------------------------------------------- |
|
478 // CVcxMyVideosDriveMonitor::PhoneMemoryDriveL |
|
479 // ----------------------------------------------------------------------------- |
|
480 // |
|
481 TInt CVcxMyVideosDriveMonitor::PhoneMemoryDriveL() |
|
482 { |
|
483 TInt drive; |
|
484 User::LeaveIfError( drive = PhoneMemoryDrive() ); |
|
485 return drive; |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CVcxMyVideosDriveMonitor::PhoneMemoryDrive |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 TInt CVcxMyVideosDriveMonitor::PhoneMemoryDrive() |
|
493 { |
|
494 TInt i; |
|
495 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
496 { |
|
497 if ( iAvailableDrives[i].iDrive == EDriveC ) |
|
498 { |
|
499 return iAvailableDrives[i].iDrive; |
|
500 } |
|
501 } |
|
502 return KErrNotFound; |
|
503 } |
|
504 |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CVcxMyVideosDriveMonitor::FixedDriveL |
|
508 // ----------------------------------------------------------------------------- |
|
509 // |
|
510 TInt CVcxMyVideosDriveMonitor::FixedDriveL( TBool aExcludeCDrive ) |
|
511 { |
|
512 TInt drive; |
|
513 User::LeaveIfError( drive = FixedDrive( aExcludeCDrive ) ); |
|
514 return drive; |
|
515 } |
|
516 |
|
517 // ----------------------------------------------------------------------------- |
|
518 // CVcxMyVideosDriveMonitor::FixedDrive |
|
519 // ----------------------------------------------------------------------------- |
|
520 // |
|
521 TInt CVcxMyVideosDriveMonitor::FixedDrive( TBool aExcludeCDrive ) |
|
522 { |
|
523 TInt i; |
|
524 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
525 { |
|
526 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: iAvailableDrives[%d]", i); |
|
527 |
|
528 if ( !(iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ERemovable) ) |
|
529 { |
|
530 if ( iAvailableDrives[i].iDrive != EDriveC ) |
|
531 { |
|
532 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive); |
|
533 return iAvailableDrives[i].iDrive; |
|
534 } |
|
535 else |
|
536 { |
|
537 if ( !aExcludeCDrive ) |
|
538 { |
|
539 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive); |
|
540 return iAvailableDrives[i].iDrive; |
|
541 } |
|
542 } |
|
543 } |
|
544 } |
|
545 MPX_DEBUG1("CVcxMyVideosDriveMonitor:: FixedDrive() fixed drive not found"); |
|
546 return KErrNotFound; |
|
547 } |
|
548 |
|
549 // ----------------------------------------------------------------------------- |
|
550 // CVcxMyVideosDriveMonitor::IsMmcInserted() |
|
551 // ----------------------------------------------------------------------------- |
|
552 // |
|
553 TBool CVcxMyVideosDriveMonitor::IsMmcInserted() |
|
554 { |
|
555 TInt drive = MemoryCardDrive(); |
|
556 |
|
557 if ( drive == KErrNotFound ) |
|
558 { |
|
559 return EFalse; |
|
560 } |
|
561 |
|
562 TInt arrayPos = ArrayPos( drive ); |
|
563 |
|
564 if ( arrayPos == KErrNotFound ) |
|
565 { |
|
566 return EFalse; |
|
567 } |
|
568 |
|
569 TUint32 flags = iAvailableDrives[arrayPos].iFlags; |
|
570 |
|
571 if ( (flags & TVcxMyVideosDriveInfo::ELocked) || (flags & TVcxMyVideosDriveInfo::EMediaNotPresent) ) |
|
572 { |
|
573 return EFalse; |
|
574 } |
|
575 |
|
576 return ETrue; |
|
577 } |
|
578 #endif |
|
579 |
|
580 // ----------------------------------------------------------------------------- |
|
581 // CVcxMyVideosDriveMonitor::RunL() |
|
582 // ----------------------------------------------------------------------------- |
|
583 // |
|
584 void CVcxMyVideosDriveMonitor::RunL() |
|
585 { |
|
586 MPX_FUNC("CVcxMyVideosDriveMonitor::RunL()"); |
|
587 |
|
588 if ( iStatus == KErrNone ) |
|
589 { |
|
590 iFs.NotifyChange( ENotifyDisk, iStatus ); |
|
591 |
|
592 TRAPD( err, RefreshAvailableDrivesL() ); |
|
593 if ( err != KErrNone ) |
|
594 { |
|
595 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: RefreshAvailableDrivesL leaved with error code %d, ignoring", err); |
|
596 } |
|
597 CompareOldAndNewAvailableDrives(); |
|
598 SetActive(); |
|
599 } |
|
600 else |
|
601 { |
|
602 iFs.NotifyChange( ENotifyDisk, iStatus ); |
|
603 SetActive(); |
|
604 } |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // CVcxMyVideosDriveMonitor::DoCancel() |
|
609 // ----------------------------------------------------------------------------- |
|
610 // |
|
611 void CVcxMyVideosDriveMonitor::DoCancel() |
|
612 { |
|
613 iFs.NotifyChangeCancel( iStatus ); |
|
614 } |
|
615 |
|
616 // ----------------------------------------------------------------------------- |
|
617 // CVcxMyVideosDriveMonitor::RunError() |
|
618 // ----------------------------------------------------------------------------- |
|
619 // |
|
620 TInt CVcxMyVideosDriveMonitor::RunError( TInt /* aError */ ) |
|
621 { |
|
622 MPX_DEBUG1("CVcxMyVideosDriveMonitor::RunL() leaved (should never happen)."); |
|
623 return KErrNone; |
|
624 } |
|
625 |
|
626 // ----------------------------------------------------------------------------- |
|
627 // CVcxMyVideosDriveMonitor::SendEvent() |
|
628 // ----------------------------------------------------------------------------- |
|
629 // |
|
630 void CVcxMyVideosDriveMonitor::SendEvent( TVcxMyVideosDriveMonitorEvent::TEvent aEvent, |
|
631 TInt aDrive ) |
|
632 { |
|
633 MPX_DEBUG4("CVcxMyVideosDriveMonitor:: Sending event: %S(%d), drive: %d", |
|
634 &TVcxMyVideosDriveMonitorEvent::EventDes( aEvent ), |
|
635 aEvent, |
|
636 aDrive ); |
|
637 |
|
638 TVcxMyVideosDriveMonitorEvent event; |
|
639 |
|
640 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
641 { |
|
642 event.iEvent = static_cast<TInt>(aEvent); |
|
643 event.iDrive = aDrive; |
|
644 iObservers[i]->HandleDriveMonitorEvent( event ); |
|
645 } |
|
646 |
|
647 #ifdef _DEBUG |
|
648 PrintAvailableDrives(); |
|
649 #endif |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CVcxMyVideosDriveMonitor::CompareOldAndNewAvailableDrives |
|
654 // ----------------------------------------------------------------------------- |
|
655 // |
|
656 void CVcxMyVideosDriveMonitor::CompareOldAndNewAvailableDrives() |
|
657 { |
|
658 // Run through old drives list to detect changes |
|
659 TInt i; |
|
660 for ( i = 0; i < iPreviousAvailableDrives.Count(); i++ ) |
|
661 { |
|
662 TInt pos = ArrayPos( iPreviousAvailableDrives[i].iDrive ); |
|
663 if ( pos == KErrNotFound ) |
|
664 { |
|
665 // drive was dismounted |
|
666 SendEvent( TVcxMyVideosDriveMonitorEvent::EDriveDismounted, |
|
667 iPreviousAvailableDrives[i].iDrive ); |
|
668 } |
|
669 else |
|
670 { |
|
671 // drive still present |
|
672 if ( iPreviousAvailableDrives[i].iFlags != iAvailableDrives[pos].iFlags ) |
|
673 { |
|
674 // drive was changed |
|
675 if ( (iPreviousAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::EMediaNotPresent) && |
|
676 !(iAvailableDrives[pos].iFlags & EMediaNotPresent) ) |
|
677 { |
|
678 SendEvent( TVcxMyVideosDriveMonitorEvent::EMediaInserted, |
|
679 iAvailableDrives[pos].iDrive ); |
|
680 } |
|
681 |
|
682 if ( !(iPreviousAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::EMediaNotPresent) && |
|
683 (iAvailableDrives[pos].iFlags & TVcxMyVideosDriveInfo::EMediaNotPresent) ) |
|
684 { |
|
685 SendEvent( TVcxMyVideosDriveMonitorEvent::EMediaRemoved, |
|
686 iAvailableDrives[pos].iDrive ); |
|
687 } |
|
688 |
|
689 if ( !(iPreviousAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ELocked) && |
|
690 (iAvailableDrives[pos].iFlags & TVcxMyVideosDriveInfo::ELocked) ) |
|
691 { |
|
692 SendEvent( TVcxMyVideosDriveMonitorEvent::EDriveLocked, |
|
693 iAvailableDrives[pos].iDrive ); |
|
694 } |
|
695 |
|
696 if ( (iPreviousAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ELocked) && |
|
697 !(iAvailableDrives[pos].iFlags & TVcxMyVideosDriveInfo::ELocked) ) |
|
698 { |
|
699 SendEvent( TVcxMyVideosDriveMonitorEvent::EDriveUnlocked, |
|
700 iAvailableDrives[pos].iDrive ); |
|
701 } |
|
702 |
|
703 } |
|
704 // drive volume name was changed |
|
705 if ( iPreviousAvailableDrives[i].iVolumeName.Compare( |
|
706 iAvailableDrives[pos].iVolumeName ) != 0 ) |
|
707 { |
|
708 SendEvent( TVcxMyVideosDriveMonitorEvent::EDriveVolumeNameChanged, |
|
709 iAvailableDrives[pos].iDrive ); |
|
710 } |
|
711 } |
|
712 } |
|
713 |
|
714 // Run through new drives list to detect mounted drives |
|
715 for ( i = 0; i < iAvailableDrives.Count(); i++ ) |
|
716 { |
|
717 TBool found = EFalse; |
|
718 for ( TInt j = 0; j < iPreviousAvailableDrives.Count(); j++ ) |
|
719 { |
|
720 if ( iPreviousAvailableDrives[j].iDrive == iAvailableDrives[i].iDrive ) |
|
721 { |
|
722 found = ETrue; |
|
723 break; |
|
724 } |
|
725 } |
|
726 if ( !found ) |
|
727 { |
|
728 SendEvent( TVcxMyVideosDriveMonitorEvent::EDriveMounted, |
|
729 iAvailableDrives[i].iDrive ); |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 // ----------------------------------------------------------------------------- |
|
735 // CVcxMyVideosDriveMonitor::DriveType() |
|
736 // ----------------------------------------------------------------------------- |
|
737 // |
|
738 #ifdef _DEBUG |
|
739 const TDesC& CVcxMyVideosDriveMonitor::DriveTypeDes( TInt aType ) |
|
740 { |
|
741 switch (aType) |
|
742 { |
|
743 case EMediaNotPresent: |
|
744 return KVcxMyVideosMediaNotPresentDes; |
|
745 case EMediaUnknown: |
|
746 return KVcxMyVideosMediaUnknownDes; |
|
747 case EMediaFloppy: |
|
748 return KVcxMyVideosMediaFloppyDes; |
|
749 case EMediaHardDisk: |
|
750 return KVcxMyVideosMediaHardDiskDes; |
|
751 case EMediaCdRom: |
|
752 return KVcxMyVideosMediaCdRomDes; |
|
753 case EMediaRam: |
|
754 return KVcxMyVideosMediaRamDes; |
|
755 case EMediaFlash: |
|
756 return KVcxMyVideosMediaFlashDes; |
|
757 case EMediaRom: |
|
758 return KVcxMyVideosMediaRomDes; |
|
759 case EMediaRemote: |
|
760 return KVcxMyVideosMediaRemoteDes; |
|
761 case EMediaNANDFlash: |
|
762 return KVcxMyVideosMediaNANDFlashDes; |
|
763 default: |
|
764 return KVcxMyVideosMediaUnknownDes; |
|
765 } |
|
766 } |
|
767 #else |
|
768 const TDesC& CVcxMyVideosDriveMonitor::DriveTypeDes( TInt /*aType*/ ) |
|
769 { |
|
770 return KNullDesC; |
|
771 } |
|
772 #endif |
|
773 |
|
774 // ----------------------------------------------------------------------------- |
|
775 // CVcxMyVideosDriveMonitor::PrintAvailableDrives() |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 void CVcxMyVideosDriveMonitor::PrintAvailableDrives() |
|
779 { |
|
780 #ifdef _DEBUG |
|
781 for ( TInt i = 0; i < iAvailableDrives.Count(); i++ ) |
|
782 { |
|
783 MPX_DEBUG3("CVcxMyVideosDriveMonitor:: iAvailableDrives[%d].iDrive = %d", |
|
784 i, iAvailableDrives[i].iDrive); |
|
785 MPX_DEBUG2(" ERemovableDrive = %d", |
|
786 !!(iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ERemovable)); |
|
787 MPX_DEBUG2(" EMassStorage = %d", |
|
788 !!(iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::EMassStorage)); |
|
789 MPX_DEBUG2(" ELockedDrive = %d", |
|
790 !!(iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::ELocked)); |
|
791 MPX_DEBUG2(" EMediaNotPresent = %d", |
|
792 !!(iAvailableDrives[i].iFlags & TVcxMyVideosDriveInfo::EMediaNotPresent)); |
|
793 } |
|
794 #endif |
|
795 } |
|
796 |
|
797 // ----------------------------------------------------------------------------- |
|
798 // CVcxMyVideosDriveMonitor::GetPreferredMemoryL |
|
799 // Gets the preferred memory, this doesn't mean yet that it can be actually used. |
|
800 // Media might not be present or it might be locked. |
|
801 // ----------------------------------------------------------------------------- |
|
802 // |
|
803 void CVcxMyVideosDriveMonitor::GetPreferredMemoryL( TInt& aPreferredMemory ) |
|
804 { |
|
805 MPX_FUNC("CVcxMyVideosDriveMonitor::GetPreferredMemoryL()"); |
|
806 |
|
807 TInt cenRepMemory = KErrNotFound; //init to some non valid drive value, in case that cenrep wont change it at all |
|
808 |
|
809 TUid uid; |
|
810 uid.iUid = KVcxMyVideosCenRepUid; |
|
811 CRepository* cenRep = CRepository::NewL( uid ); |
|
812 CleanupStack::PushL( cenRep ); // 1-> |
|
813 |
|
814 TInt cenRepError = cenRep->Get( KVcxMyVideosCenRepPreferredMemoryKey, cenRepMemory ); |
|
815 |
|
816 aPreferredMemory = EDriveC; |
|
817 |
|
818 if ( ArrayPos( cenRepMemory ) == KErrNotFound |
|
819 || cenRepError != KErrNone ) |
|
820 { |
|
821 MPX_DEBUG1( |
|
822 "CVcxMyVideosDriveMonitor:: cenrep value for used memory was not valid or not found."); |
|
823 |
|
824 // Non existing drive or no cen rep value -> figure out the default drive |
|
825 TInt massStorageDrive = MassStorageDrive(); |
|
826 if ( massStorageDrive != KErrNotFound ) |
|
827 { |
|
828 MPX_DEBUG1("CVcxMyVideosDriveMonitor:: using mass storage"); |
|
829 aPreferredMemory = massStorageDrive; |
|
830 } |
|
831 else |
|
832 { |
|
833 TInt memoryCardDrive = MemoryCardDrive(); |
|
834 if ( memoryCardDrive != KErrNotFound ) |
|
835 { |
|
836 MPX_DEBUG1("CVcxMyVideosDriveMonitor:: using memory card"); |
|
837 aPreferredMemory = memoryCardDrive; |
|
838 } |
|
839 } |
|
840 |
|
841 MPX_DEBUG2( |
|
842 "CVcxMyVideosDriveMonitor:: writing new value to cenrep (%d)", aPreferredMemory); |
|
843 |
|
844 cenRep->Set( KVcxMyVideosCenRepPreferredMemoryKey, aPreferredMemory ); |
|
845 } |
|
846 else |
|
847 { |
|
848 //Cenrep value was valid, use it |
|
849 MPX_DEBUG1( |
|
850 "CVcxMyVideosDriveMonitor:: cenrep value for used memory was valid, using it."); |
|
851 aPreferredMemory = cenRepMemory; |
|
852 } |
|
853 |
|
854 CleanupStack::PopAndDestroy( cenRep ); // <-1 |
|
855 |
|
856 MPX_DEBUG2("CVcxMyVideosDriveMonitor:: preferred memory: %d", aPreferredMemory); |
|
857 } |
|
858 |
|
859 // ----------------------------------------------------------------------------- |
|
860 // CVcxMyVideosDriveMonitor::GetUsedMemoryL |
|
861 // Gets the memory for usage. Tries first the preferred memory, if it is not |
|
862 // available (locked or not present), tries the next drive from iAvailable drives. |
|
863 // If suitable drive is not found, returns system drive (c-drive). |
|
864 // ----------------------------------------------------------------------------- |
|
865 // |
|
866 void CVcxMyVideosDriveMonitor::GetUsedMemoryL( TInt& aUsedMemory ) |
|
867 { |
|
868 TInt preferredDrive; |
|
869 GetPreferredMemoryL( preferredDrive ); |
|
870 |
|
871 TInt startPos = ArrayPos( preferredDrive ); |
|
872 TInt currentPos = startPos; |
|
873 TUint32 flags; |
|
874 TBool found = EFalse; |
|
875 while ( !found ) |
|
876 { |
|
877 flags = iAvailableDrives[currentPos].iFlags; |
|
878 |
|
879 if ( (flags & TVcxMyVideosDriveInfo::ELocked) || |
|
880 (flags & TVcxMyVideosDriveInfo::EMediaNotPresent) ) |
|
881 { |
|
882 MPX_DEBUG1("CVcxMyVideosDownloadUtil:: drive was locked or not present -> trying next available drive"); |
|
883 currentPos++; |
|
884 if ( currentPos > (iAvailableDrives.Count()-1) ) |
|
885 { |
|
886 currentPos = 0; |
|
887 } |
|
888 if ( currentPos == startPos ) |
|
889 { |
|
890 // we went full round and couldnt find drive -> use c-drive |
|
891 MPX_DEBUG1("CVcxMyVideosDownloadUtil:: no suitable drive found from iAvailable drives, using c-drive"); |
|
892 aUsedMemory = iFs.GetSystemDrive(); |
|
893 found = ETrue; |
|
894 } |
|
895 } |
|
896 else |
|
897 { |
|
898 aUsedMemory = iAvailableDrives[currentPos].iDrive; |
|
899 found = ETrue; |
|
900 } |
|
901 } |
|
902 MPX_DEBUG2("CVcxMyVideosDownloadUtil::GetUsedMemoryL() returns %d", aUsedMemory); |
|
903 } |
|
904 |
|
905 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
906 |
|
907 |
|
908 // End of File |