|
1 /* |
|
2 * Copyright (c) 2008 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: Directory scanner |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "appmngr2scannerdir.h" // CAppMngr2ScannerDir |
|
20 #include "appmngr2scannerdirobserver.h" // MAppMngr2ScannerDirObserver |
|
21 #include <driveinfo.h> // DriveInfo |
|
22 |
|
23 _LIT( KBackslash, "\\" ); |
|
24 |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CAppMngr2ScannerDir::NewLC() |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CAppMngr2ScannerDir* CAppMngr2ScannerDir::NewL( RFs& aFs, const TDesC& aDir, |
|
33 MAppMngr2ScannerDirObserver& aObs ) |
|
34 { |
|
35 CAppMngr2ScannerDir* self = new (ELeave) CAppMngr2ScannerDir( aFs, aObs ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( aDir ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CAppMngr2ScannerDir::~CAppMngr2ScannerDir() |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CAppMngr2ScannerDir::~CAppMngr2ScannerDir() |
|
47 { |
|
48 Cancel(); |
|
49 delete iDir; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CAppMngr2ScannerDir::DirName() |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 const TDesC& CAppMngr2ScannerDir::DirName() const |
|
57 { |
|
58 if( iDir ) |
|
59 { |
|
60 return *iDir; |
|
61 } |
|
62 return KNullDesC; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CAppMngr2ScannerDir::StartWatchingChanges() |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void CAppMngr2ScannerDir::StartWatchingChanges() |
|
70 { |
|
71 if( !IsActive() ) |
|
72 { |
|
73 iFs.NotifyChange( ENotifyEntry, iStatus, *iDir ); |
|
74 SetActive(); |
|
75 } |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CAppMngr2ScannerDir::StopWatchingChanges() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CAppMngr2ScannerDir::StopWatchingChanges() |
|
83 { |
|
84 if( IsActive() ) |
|
85 { |
|
86 Cancel(); |
|
87 } |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CAppMngr2ScannerDir::DoCancel() |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CAppMngr2ScannerDir::DoCancel() |
|
95 { |
|
96 iFs.NotifyChangeCancel(); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CAppMngr2ScannerDir::RunL() |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CAppMngr2ScannerDir::RunL() |
|
104 { |
|
105 // Status is KErrCancel when StopWatchingChanges() has been called |
|
106 if( iStatus.Int() == KErrNone ) |
|
107 { |
|
108 iFs.NotifyChange( ENotifyEntry, iStatus, *iDir ); |
|
109 SetActive(); |
|
110 |
|
111 iObserver.DirectoryChangedL( *iDir ); |
|
112 } |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CAppMngr2ScannerDir::CAppMngr2ScannerDir() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CAppMngr2ScannerDir::CAppMngr2ScannerDir( RFs& aFs, MAppMngr2ScannerDirObserver& aObs ) : |
|
120 CActive( CActive::EPriorityStandard ), iObserver( aObs ), iFs( aFs ) |
|
121 { |
|
122 CActiveScheduler::Add( this ); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CAppMngr2ScannerDir::ConstructL() |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CAppMngr2ScannerDir::ConstructL( const TDesC& aDir ) |
|
130 { |
|
131 // Check if aDir has trailing backslash, add it if it does not have. |
|
132 // RFs::NotifyChange() and also RApaLsSession::RecognizeFilesL() that scanner |
|
133 // uses require trailing backslashes in directory names, hence create iDir so |
|
134 // that is always ends with trailing backslash. |
|
135 if( aDir.Right( 1 ).Compare( KBackslash ) == 0 ) |
|
136 { |
|
137 // RFs::IsValidName() does not accept trailing backslashes, so check the |
|
138 // the directory name first without trailing backslash |
|
139 TPtrC dirWithoutTrailingString( aDir.Left( aDir.Length() - 1 ) ); |
|
140 if( !iFs.IsValidName( dirWithoutTrailingString ) ) |
|
141 { |
|
142 User::LeaveIfError( KErrBadName ); |
|
143 } |
|
144 iDir = aDir.AllocL(); |
|
145 } |
|
146 else |
|
147 { |
|
148 // No trailing backslash, check the dir name and then add the backslash |
|
149 if( !iFs.IsValidName( aDir ) ) |
|
150 { |
|
151 User::LeaveIfError( KErrBadName ); |
|
152 } |
|
153 iDir = HBufC::NewL( aDir.Length() + 1 ); |
|
154 TPtr dirPtr = iDir->Des(); |
|
155 dirPtr.Copy( aDir ); |
|
156 dirPtr.Append( KBackslash ); |
|
157 } |
|
158 } |
|
159 |