|
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: Setting item to support multiple drives. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <driveinfo.h> |
|
20 |
|
21 #include "CAknMemorySelectionSettingItemMultiDrive.h" |
|
22 #include "CAknMemorySelectionDialogMultiDrive.h" |
|
23 #include "maknmemoryselectionmodel.h" |
|
24 #include "AknCFDUtility.h" |
|
25 #include "CAknCFDFileSystemEvent.h" |
|
26 #include "MAknCFDFileSystemObserver.h" |
|
27 |
|
28 |
|
29 NONSHARABLE_CLASS(CAknMemorySelectionSettingItemExtension) : public CBase, |
|
30 public MAknCFDFileSystemObserver |
|
31 { |
|
32 |
|
33 public: |
|
34 CAknMemorySelectionSettingItemExtension(CAknMemorySelectionSettingItemMultiDrive* aSettingItem); |
|
35 ~CAknMemorySelectionSettingItemExtension(); |
|
36 |
|
37 // second phase construct |
|
38 void ConstructL(); |
|
39 |
|
40 /** |
|
41 * Static constructor. |
|
42 * |
|
43 * @since S60 5.0 |
|
44 * @param aSettingItem defines a pointer to the setting item. |
|
45 * @return Returns a pointer to an instance of itself. |
|
46 */ |
|
47 static CAknMemorySelectionSettingItemExtension* NewL(CAknMemorySelectionSettingItemMultiDrive* aSettingItem); |
|
48 |
|
49 |
|
50 // Functions from base interface MAknCFDFileSystemObserver |
|
51 /** |
|
52 * From MAknCFDFileSystemObserver |
|
53 */ |
|
54 void NotifyFileSystemChangedL(); |
|
55 |
|
56 // Own: memory selection dialog |
|
57 CAknMemorySelectionDialogMultiDrive* iDialog; |
|
58 |
|
59 // Ref: The external data |
|
60 CAknMemorySelectionSettingItemMultiDrive* iSettingItem; |
|
61 |
|
62 // Own: The extension of setting item |
|
63 CAknCFDFileSystemEvent* iFSEvent; |
|
64 }; |
|
65 |
|
66 // ======== MEMBER FUNCTIONS ======== |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CAknMemorySelectionSettingItem::CAknMemorySelectionSettingItem |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CAknMemorySelectionSettingItemMultiDrive |
|
73 ::CAknMemorySelectionSettingItemMultiDrive( |
|
74 TInt aIdentifier, |
|
75 TDriveNumber& aSelectedDrive ) |
|
76 : CAknSettingItem( aIdentifier ), |
|
77 iExternalData( aSelectedDrive ) |
|
78 { |
|
79 |
|
80 } |
|
81 |
|
82 // Destructor |
|
83 EXPORT_C CAknMemorySelectionSettingItemMultiDrive:: |
|
84 ~CAknMemorySelectionSettingItemMultiDrive() |
|
85 { |
|
86 delete iSettingText; |
|
87 delete iExtension, iExtension = NULL; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CAknMemorySelectionSettingItemMultiDrive::CompleteConstructionL |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CAknMemorySelectionSettingItemMultiDrive::CompleteConstructionL() |
|
96 { |
|
97 iExtension = CAknMemorySelectionSettingItemExtension::NewL(this); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CAknMemorySelectionSettingItemMultiDrive::EditItemL |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C void CAknMemorySelectionSettingItemMultiDrive::EditItemL( |
|
106 TBool aCalledFromMenu ) |
|
107 { |
|
108 if( !iExtension ) |
|
109 { |
|
110 // This in case application hasn't called CompleteConstructionL() |
|
111 CompleteConstructionL(); |
|
112 } |
|
113 |
|
114 if( aCalledFromMenu ) |
|
115 { |
|
116 // Changed with Options/Change |
|
117 iExtension->iDialog->ExecuteL( iInternalData, NULL, NULL ); |
|
118 } |
|
119 else |
|
120 { |
|
121 // Changed with selection key |
|
122 if( ( iExtension->iDialog->NumberOfItems() == 2 ) && |
|
123 ( !iExtension->iDialog->HasUnavailbleMMC() ) ) |
|
124 { |
|
125 // Two items in list, function as binary pop-up setting page |
|
126 TInt selectedIndex = |
|
127 iExtension->iDialog->FindIndexByDrive( |
|
128 iInternalData ); |
|
129 if ( selectedIndex == KErrNotFound ) |
|
130 { |
|
131 selectedIndex = 0; |
|
132 } |
|
133 else |
|
134 { |
|
135 selectedIndex = 1 - selectedIndex; // switch to another one. |
|
136 } |
|
137 iInternalData = |
|
138 iExtension->iDialog->FindDriveByIndex( selectedIndex ); |
|
139 } |
|
140 else |
|
141 { |
|
142 iExtension->iDialog->ExecuteL( |
|
143 iInternalData, NULL, NULL ); |
|
144 } |
|
145 } |
|
146 |
|
147 UpdateListBoxTextL(); |
|
148 |
|
149 } |
|
150 |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CAknMemorySelectionSettingItemMultiDrive::LoadL |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C void CAknMemorySelectionSettingItemMultiDrive::LoadL() |
|
157 { |
|
158 iInternalData = iExternalData; |
|
159 } |
|
160 |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CAknMemorySelectionSettingItemMultiDrive::StoreL |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 EXPORT_C void CAknMemorySelectionSettingItemMultiDrive::StoreL() |
|
167 { |
|
168 iExternalData = iInternalData; |
|
169 |
|
170 } |
|
171 |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CAknMemorySelectionSettingItemMultiDrive::SettingTextL |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C const TDesC& CAknMemorySelectionSettingItemMultiDrive::SettingTextL() |
|
178 { |
|
179 if( !iExtension ) |
|
180 { |
|
181 // This in case application hasn't called CompleteConstructionL() |
|
182 CompleteConstructionL(); |
|
183 } |
|
184 |
|
185 TInt memoryIndex = iExtension->iDialog->FindIndexByDrive( |
|
186 iInternalData ); |
|
187 if ( AknCFDUtility::DriveStatusL( iInternalData ) |
|
188 != EDriveOK ) |
|
189 { |
|
190 TInt drive; |
|
191 User::LeaveIfError( DriveInfo::GetDefaultDrive( |
|
192 DriveInfo::EDefaultSystem, drive ) ); |
|
193 memoryIndex = iExtension->iDialog->FindIndexByDrive( |
|
194 TDriveNumber( drive ) ); |
|
195 } |
|
196 if( !iSettingText ) |
|
197 iSettingText = HBufC::NewL( KMaxName ); |
|
198 TPtr ptrSettingText( iSettingText->Des() ); |
|
199 iExtension->iDialog->GetItem( memoryIndex, ptrSettingText ); |
|
200 return *iSettingText; |
|
201 } |
|
202 |
|
203 |
|
204 void CAknMemorySelectionSettingItemMultiDrive::UpdateSettingItemContentL() |
|
205 { |
|
206 if ( iExtension->iDialog != NULL ) |
|
207 { |
|
208 // Update model. |
|
209 iExtension->iDialog->UpdateModelL(); |
|
210 |
|
211 // Update setting item value. |
|
212 TInt selectedIndex = iExtension->iDialog-> |
|
213 FindIndexByDrive(iInternalData); |
|
214 |
|
215 if (selectedIndex == KErrNotFound) |
|
216 { |
|
217 iInternalData = EDriveC; |
|
218 } |
|
219 else |
|
220 { |
|
221 iInternalData = iExtension->iDialog-> |
|
222 FindDriveByIndex(selectedIndex); |
|
223 } |
|
224 |
|
225 UpdateListBoxTextL(); |
|
226 } |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CAknMemorySelectionSettingItemExtension |
|
232 // Constructor |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 CAknMemorySelectionSettingItemExtension:: |
|
236 CAknMemorySelectionSettingItemExtension(CAknMemorySelectionSettingItemMultiDrive* aSettingItem) |
|
237 : iSettingItem( aSettingItem ) |
|
238 { |
|
239 } |
|
240 |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CAknMemorySelectionSettingItemExtension |
|
244 // Constructor |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 CAknMemorySelectionSettingItemExtension:: |
|
248 ~CAknMemorySelectionSettingItemExtension() |
|
249 { |
|
250 delete iDialog; |
|
251 iDialog = NULL; |
|
252 |
|
253 if ( iFSEvent ) |
|
254 { |
|
255 iFSEvent->Cancel(); |
|
256 delete iFSEvent; |
|
257 iFSEvent = NULL; |
|
258 } |
|
259 |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CAknMemorySelectionSettingItemExtension |
|
264 // NotifyFileSystemChangedL |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CAknMemorySelectionSettingItemExtension::NotifyFileSystemChangedL() |
|
268 { |
|
269 iSettingItem->UpdateSettingItemContentL(); |
|
270 |
|
271 if (iFSEvent != NULL) |
|
272 { |
|
273 iFSEvent->Setup(); |
|
274 } |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CAknMemorySelectionSettingItemExtension |
|
279 // ConstructL |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 void CAknMemorySelectionSettingItemExtension::ConstructL() |
|
283 { |
|
284 |
|
285 iDialog = CAknMemorySelectionDialogMultiDrive::NewL( |
|
286 ECFDDialogTypeNormal, ETrue); |
|
287 |
|
288 iFSEvent = CAknCFDFileSystemEvent::NewL(CCoeEnv::Static()->FsSession(), *this, ENotifyDisk); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CAknMemorySelectionSettingItemExtension |
|
293 // NewL |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 CAknMemorySelectionSettingItemExtension* CAknMemorySelectionSettingItemExtension::NewL(CAknMemorySelectionSettingItemMultiDrive* aSettingItem) |
|
297 { |
|
298 CAknMemorySelectionSettingItemExtension* self = |
|
299 new( ELeave ) CAknMemorySelectionSettingItemExtension(aSettingItem); |
|
300 |
|
301 CleanupStack::PushL( self ); |
|
302 self->ConstructL(); |
|
303 CleanupStack::Pop( self ); |
|
304 |
|
305 return self; |
|
306 } |