|
1 /* |
|
2 * Copyright (c) 2000-2009 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: Drive monitor implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <pathinfo.h> |
|
20 #include <f32file.h> |
|
21 #include "StoreDriveMonitor.h" |
|
22 #include <coreapplicationuisdomainpskeys.h> |
|
23 |
|
24 // --------------------------------------------------------- |
|
25 // CDriveWatcher::NewL |
|
26 // Second phase constructor |
|
27 // --------------------------------------------------------- |
|
28 // |
|
29 CStoreDriveMonitor* CStoreDriveMonitor::NewL( MStoreDriveStateObserver& aDriveStateObserver ) |
|
30 { |
|
31 CStoreDriveMonitor* self = CStoreDriveMonitor::NewLC( aDriveStateObserver ); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CDriveWatcher::NewLC |
|
38 // Second phase constructor |
|
39 // --------------------------------------------------------- |
|
40 // |
|
41 CStoreDriveMonitor* CStoreDriveMonitor::NewLC( MStoreDriveStateObserver& aDriveStateObserver ) |
|
42 { |
|
43 CStoreDriveMonitor* self = new(ELeave) CStoreDriveMonitor( aDriveStateObserver ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CDriveWatcher::~CDriveWatcher |
|
51 // Destructor |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 CStoreDriveMonitor::~CStoreDriveMonitor() |
|
55 { |
|
56 |
|
57 delete iDriveLetter; |
|
58 Cancel(); |
|
59 |
|
60 iFs.Close(); |
|
61 |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // CDriveWatcher::CDriveWatcher |
|
66 // Default constructor |
|
67 // --------------------------------------------------------- |
|
68 // |
|
69 CStoreDriveMonitor::CStoreDriveMonitor( MStoreDriveStateObserver& aDriveStateObserver ) |
|
70 : CActive( CActive::EPriorityStandard ), |
|
71 iDriveStateObserver( aDriveStateObserver ) |
|
72 { |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CDriveWatcher::ConstructL |
|
77 // default Symbian OS constructor |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CStoreDriveMonitor::ConstructL() |
|
81 { |
|
82 CActiveScheduler::Add(this); |
|
83 User::LeaveIfError( iFs.Connect() ); |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CDriveWatcher::WaitForChangeL() |
|
89 // Request notification for disk change |
|
90 // --------------------------------------------------------- |
|
91 // |
|
92 void CStoreDriveMonitor::WaitForChange() |
|
93 { |
|
94 |
|
95 if ( !IsActive() ) |
|
96 { |
|
97 |
|
98 iFs.NotifyChange( ENotifyEntry, iStatus, *iDriveLetter ); |
|
99 |
|
100 SetActive(); |
|
101 } |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CDriveWatcher::MediaPresentL() |
|
106 // Call scanning if the memory card exists |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 void CStoreDriveMonitor::MediaPresentL() |
|
110 { |
|
111 TVolumeInfo volumeInfo; |
|
112 // Returns KErrNone, if drive exists |
|
113 TInt err=iFs.Volume( volumeInfo, iDrive ); |
|
114 |
|
115 if ( err == KErrNone ) |
|
116 { |
|
117 iDriveStateObserver.DriveStateChangedL( ETrue ); |
|
118 } |
|
119 else |
|
120 { |
|
121 iDriveStateObserver.DriveStateChangedL( EFalse ); |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // Return true if drive is present and false otherwise. |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 TBool CStoreDriveMonitor::IsDrivePresent() |
|
130 { |
|
131 |
|
132 TVolumeInfo volumeInfo; |
|
133 // Returns KErrNone, if drive exists |
|
134 TInt err=iFs.Volume( volumeInfo, iDrive ); |
|
135 |
|
136 return ( KErrNone == err ); |
|
137 |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CDriveWatcher::DoCancel() |
|
142 // Derived from CActive, cancel request |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 void CStoreDriveMonitor::DoCancel() |
|
146 { |
|
147 iFs.NotifyChangeCancel(); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------- |
|
151 // CDriveWatcher::RunL() |
|
152 // Derived from CActive, called when notification received |
|
153 // Check if media is present and call new notification request |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 void CStoreDriveMonitor::RunL() |
|
157 { |
|
158 if ( iStatus.Int() != KErrCancel ) |
|
159 { |
|
160 WaitForChange(); |
|
161 MediaPresentL(); |
|
162 } |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------- |
|
166 // CDriveWatcher::RunError() |
|
167 // --------------------------------------------------------- |
|
168 // |
|
169 |
|
170 TInt CStoreDriveMonitor::RunError(TInt /*aError*/) |
|
171 { |
|
172 return KErrNone; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // CStoreDriveMonitor::SetDriveL() |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CStoreDriveMonitor::SetDriveL( TDriveNumber aDrive ) |
|
180 { |
|
181 |
|
182 if (iDrive == aDrive) |
|
183 { |
|
184 //if drives are the same don't need to do nothing |
|
185 return; |
|
186 } |
|
187 else if ( IsActive() ) |
|
188 { |
|
189 //cancel request if drive to monitor changed |
|
190 Cancel(); |
|
191 } |
|
192 |
|
193 const TUint KDriveBufSize = 2; |
|
194 |
|
195 iDrive = aDrive; |
|
196 |
|
197 TChar driveAsChar = 0; |
|
198 RFs::DriveToChar( iDrive, driveAsChar ); |
|
199 |
|
200 delete iDriveLetter; |
|
201 iDriveLetter = NULL; |
|
202 iDriveLetter = HBufC::NewL( KDriveBufSize ); |
|
203 |
|
204 iDriveLetter->Des().Append( driveAsChar ); |
|
205 iDriveLetter->Des().Append(':'); |
|
206 |
|
207 } |
|
208 |
|
209 |