|
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 "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: Monitors a folder in the file system for file changes |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #ifdef RD_MULTIPLE_DRIVE |
|
21 #include <pathinfo.h> |
|
22 #include <driveinfo.h> |
|
23 #endif //RD_MULTIPLE_DRIVE |
|
24 #include <mpxlog.h> |
|
25 #include "mpxfoldermonitor.h" |
|
26 #include "mpxfileadditionobserver.h" |
|
27 #include "mpxfoldermonitorobserver.h" |
|
28 |
|
29 // CONSTANTS |
|
30 #ifdef RD_MULTIPLE_DRIVE |
|
31 _LIT( KMPXMusicPath, "\\Music\\"); |
|
32 #else |
|
33 _LIT( KMPXMusicPath, "\\Music\\"); |
|
34 _LIT( KMPXDataPath, "\\Data\\"); |
|
35 #endif //RD_MULTIPLE_DRIVE |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Constructor |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CMPXFolderMonitor::CMPXFolderMonitor( MMPXFolderMonitorObserver& aObserver, |
|
43 RFs& aFs ) : CActive( EPriorityNormal ), |
|
44 iObserver( aObserver ), |
|
45 iFs( aFs ) |
|
46 |
|
47 { |
|
48 CActiveScheduler::Add( this ); |
|
49 } |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Second Phase Constructor |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CMPXFolderMonitor::ConstructL() |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Two-phased constructor |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CMPXFolderMonitor* CMPXFolderMonitor::NewL( MMPXFolderMonitorObserver& aObserver, |
|
65 RFs& aFs ) |
|
66 { |
|
67 CMPXFolderMonitor* self = new( ELeave ) CMPXFolderMonitor( aObserver, aFs ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Destructor |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CMPXFolderMonitor::~CMPXFolderMonitor() |
|
80 { |
|
81 Cancel(); |
|
82 delete iFolderName; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Starts monitoring a particular drive |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CMPXFolderMonitor::StartL( TDriveNumber aDrive ) |
|
90 { |
|
91 MPX_DEBUG1("CMPXFolderMonitor::Start <---"); |
|
92 |
|
93 // What is the drive name? |
|
94 delete iFolderName; |
|
95 iFolderName = NULL; |
|
96 |
|
97 #ifdef RD_MULTIPLE_DRIVE |
|
98 switch( aDrive ) |
|
99 { |
|
100 case EDriveC: |
|
101 { |
|
102 // Use the default path for the phone memory |
|
103 iFolderName = |
|
104 PathInfo::PhoneMemoryRootPath().AllocL(); |
|
105 break; |
|
106 } |
|
107 default: |
|
108 { |
|
109 // Ensure that the drive is available |
|
110 // Get the drive status |
|
111 TUint driveStatus(0); |
|
112 const TInt err = DriveInfo::GetDriveStatus( |
|
113 iFs, aDrive, driveStatus ); |
|
114 |
|
115 if ( ( err == KErrNone ) && |
|
116 (driveStatus & DriveInfo::EDriveUserVisible ) ) |
|
117 { |
|
118 // Use the music path for the drive |
|
119 iFolderName = HBufC::NewL(KMaxFileName); |
|
120 TPtr folderPtr( iFolderName->Des() ); |
|
121 User::LeaveIfError( |
|
122 PathInfo::GetRootPath( folderPtr, aDrive ) ); |
|
123 folderPtr.Append( KMPXMusicPath() ); |
|
124 } |
|
125 else |
|
126 { |
|
127 TChar driveChar; |
|
128 User::LeaveIfError( |
|
129 iFs.DriveToChar( aDrive, driveChar ) ); |
|
130 MPX_DEBUG2("CMPXFolderMonitor::Start: Drive %c: not supported!", |
|
131 driveChar ); |
|
132 User::Leave( KErrNotSupported ); |
|
133 } |
|
134 break; |
|
135 } |
|
136 } |
|
137 MPX_DEBUG2("CMPXFolderMonitor::Start: Use %S path", iFolderName); |
|
138 #else |
|
139 switch( aDrive ) |
|
140 { |
|
141 case EDriveC: |
|
142 { |
|
143 TDriveName driveName = TDriveUnit( aDrive ).Name(); |
|
144 TInt length = KMPXDataPath().Length() + driveName.Length(); |
|
145 |
|
146 iFolderName = HBufC::NewL(length); |
|
147 |
|
148 TPtr folderPtr( iFolderName->Des() ); |
|
149 folderPtr.Append( driveName ); |
|
150 folderPtr.Append( KMPXDataPath ); |
|
151 |
|
152 break; |
|
153 } |
|
154 case EDriveE: |
|
155 // deliberate fall through, same actions for E & F drive |
|
156 |
|
157 case EDriveF: |
|
158 { |
|
159 |
|
160 TDriveName driveName = TDriveUnit( aDrive ).Name(); |
|
161 TInt length = KMPXMusicPath().Length() + driveName.Length(); |
|
162 |
|
163 iFolderName = HBufC::NewL(length); |
|
164 |
|
165 TPtr folderPtr( iFolderName->Des() ); |
|
166 folderPtr.Append( driveName ); |
|
167 folderPtr.Append( KMPXMusicPath ); |
|
168 |
|
169 break; |
|
170 } |
|
171 |
|
172 default: |
|
173 { |
|
174 User::Leave( KErrNotSupported ); |
|
175 } |
|
176 } |
|
177 #endif // RD_MULTIPLE_DRIVE |
|
178 |
|
179 // Start listening |
|
180 // |
|
181 TNotifyType notType = ENotifyFile; |
|
182 iFs.NotifyChange( notType, iStatus, *iFolderName ); |
|
183 SetActive(); |
|
184 |
|
185 MPX_DEBUG1("CMPXFolderMonitor::Start --->"); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // Start monitoring a particular folder |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CMPXFolderMonitor::StartL( const TDesC& aFolder ) |
|
193 { |
|
194 MPX_DEBUG1("CMPXFolderMonitor::StartL <---"); |
|
195 |
|
196 // Copy folder |
|
197 // |
|
198 delete iFolderName; |
|
199 iFolderName = NULL; |
|
200 iFolderName = aFolder.AllocL(); |
|
201 |
|
202 // Start listening |
|
203 // |
|
204 TNotifyType notType = ENotifyFile; |
|
205 iFs.NotifyChange( notType, iStatus, *iFolderName ); |
|
206 SetActive(); |
|
207 |
|
208 MPX_DEBUG1("CMPXFolderMonitor::StartL --->"); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // RunL callback |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CMPXFolderMonitor::RunL() |
|
216 { |
|
217 MPX_DEBUG1("CMPXFolderMonitor::RunL <---"); |
|
218 |
|
219 // Tell the observer that this folder has changed |
|
220 // It should go and scan it for files? |
|
221 iObserver.HandleDirectoryChangedL( *iFolderName ); |
|
222 |
|
223 // Listen again |
|
224 TNotifyType notType(ENotifyFile); |
|
225 iFs.NotifyChange( notType, iStatus, *iFolderName ); |
|
226 SetActive(); |
|
227 MPX_DEBUG1("CMPXFolderMonitor::RunL --->"); |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // Handle Cancelling |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CMPXFolderMonitor::DoCancel() |
|
235 { |
|
236 MPX_DEBUG1("CMPXFolderMonitor::DoCancel <---"); |
|
237 |
|
238 // Stop monitoring |
|
239 iFs.NotifyChangeCancel(); |
|
240 } |
|
241 |
|
242 // ---------------------------------------------------------------------------- |
|
243 // Handles a leave occurring in the request completion event handler RunL() |
|
244 // ---------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CMPXFolderMonitor::RunError(TInt aError) |
|
247 { |
|
248 MPX_DEBUG2("CMPXFolderMonitor::RunError(%d)", aError ); |
|
249 (void)aError; |
|
250 |
|
251 // Listen again |
|
252 TNotifyType notType(ENotifyFile); |
|
253 iFs.NotifyChange( notType, iStatus, *iFolderName ); |
|
254 SetActive(); |
|
255 |
|
256 return KErrNone; |
|
257 } |