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