|
1 /* |
|
2 * Copyright (c) 2002-2006 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include "CAknFileSelectionDialog.h" |
|
22 |
|
23 #include <barsread.h> // TResourceReader |
|
24 #include <eikfrlb.h> // CEikFormattedCellListBox |
|
25 #include <aknlists.h> // CAknPopupList |
|
26 #include <avkon.mbg> |
|
27 #include <aknconsts.h> |
|
28 #include <commondialogs.mbg> |
|
29 #include <AknIconArray.h> |
|
30 #include <AknsUtils.h> |
|
31 #include <AknsConstants.h> |
|
32 #include <commondialogs.rsg> |
|
33 |
|
34 #include "CAknFileSelectionModel.h" |
|
35 #include "CAknFileSelectionEventHandler.h" |
|
36 #include "CAknCommonDialogsPopupList.h" |
|
37 #include "AknFileFilterFactory.h" |
|
38 #include "AknCFDUtility.h" |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // ?classname::?classname |
|
46 // |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CAknFileSelectionDialog::CAknFileSelectionDialog( TCommonDialogType aDialogType ) |
|
51 : iDialogType( aDialogType ), |
|
52 iExecuted( EFalse ) |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CAknFileSelectionDialog::ConstructFromResourceL |
|
58 // |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CAknFileSelectionDialog::ConstructFromResourceL( TInt aResourceId ) |
|
62 { |
|
63 BaseConstructL(); |
|
64 iModel = CAknFileSelectionModel::NewL( iDialogType, *iCoeEnv ); |
|
65 |
|
66 if( aResourceId ) |
|
67 { |
|
68 // If a resource id is given, read settings from it. |
|
69 ReadFromResourceL( aResourceId ); |
|
70 } |
|
71 // After user resource is read, "patch" the missing values with defaults |
|
72 // by reading all missing settings from default resource. |
|
73 SetResourceId( aResourceId, iDialogType ); |
|
74 ReadFromResourceL( aResourceId ); |
|
75 |
|
76 iEventHandler = CAknFileSelectionEventHandler::NewL( |
|
77 iCoeEnv, iModel, iDialogType, iObserver, |
|
78 ( const HBufC*& ) iLeftSoftkeyFile, |
|
79 ( const HBufC*& ) iLeftSoftkeyFolder, |
|
80 ( const HBufC*& ) iRightSoftkeyRootFolder, |
|
81 ( const HBufC*& ) iRightSoftkeySubfolder ); |
|
82 } |
|
83 |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAknFileSelectionDialog::NewL |
|
87 // |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C CAknFileSelectionDialog* CAknFileSelectionDialog::NewL( |
|
91 TCommonDialogType aDialogType ) |
|
92 { |
|
93 return NewL( aDialogType, 0 ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CAknFileSelectionDialog::NewL |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C CAknFileSelectionDialog* CAknFileSelectionDialog::NewL( |
|
102 TCommonDialogType aDialogType, |
|
103 TInt aResourceId ) |
|
104 { |
|
105 CAknFileSelectionDialog* self = new( ELeave ) CAknFileSelectionDialog( aDialogType ); |
|
106 CleanupStack::PushL( self ); |
|
107 self->ConstructFromResourceL( aResourceId ); |
|
108 CleanupStack::Pop(); |
|
109 return self; |
|
110 } |
|
111 |
|
112 // Destructor |
|
113 EXPORT_C CAknFileSelectionDialog::~CAknFileSelectionDialog() |
|
114 { |
|
115 delete iModel; |
|
116 delete iEventHandler; |
|
117 delete iDefaultFolder; |
|
118 delete iRootPath; |
|
119 delete iTitle; |
|
120 delete iRightSoftkeySubfolder; |
|
121 delete iRightSoftkeyRootFolder; |
|
122 delete iLeftSoftkeyFolder; |
|
123 delete iLeftSoftkeyFile; |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CAknFileSelectionDialog::SetObserver |
|
129 // |
|
130 // |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C void CAknFileSelectionDialog::SetObserver( |
|
134 MAknFileSelectionObserver* aObserver ) |
|
135 { |
|
136 iObserver = aObserver; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CAknFileSelectionDialog::AddFilterL |
|
141 // |
|
142 // |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CAknFileSelectionDialog::AddFilterL( MAknFileFilter* aFilter ) |
|
146 { |
|
147 iModel->AddFilterL( aFilter ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CAknFileSelectionDialog::SetDefaultFolderL |
|
152 // |
|
153 // |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C void CAknFileSelectionDialog::SetDefaultFolderL( const TDesC& aDefaultFolder ) |
|
157 { |
|
158 AknCFDUtility::AllocateIfValidL( iDefaultFolder, aDefaultFolder ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CAknFileSelectionDialog::SetTitleL |
|
163 // |
|
164 // |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CAknFileSelectionDialog::SetTitleL( const TDesC& aText ) |
|
168 { |
|
169 AknCFDUtility::AllocateIfValidL( iTitle, aText ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CAknFileSelectionDialog::SetLeftSoftkeyFileL |
|
174 // |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C void CAknFileSelectionDialog::SetLeftSoftkeyFileL( const TDesC& aText ) |
|
179 { |
|
180 AknCFDUtility::AllocateIfValidL( iLeftSoftkeyFile, aText ); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CAknFileSelectionDialog::SetLeftSoftkeyFolderL |
|
185 // |
|
186 // |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C void CAknFileSelectionDialog::SetLeftSoftkeyFolderL( const TDesC& aText ) |
|
190 { |
|
191 AknCFDUtility::AllocateIfValidL( iLeftSoftkeyFolder, aText ); |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CAknFileSelectionDialog::SetRightSoftkeyRootFolderL |
|
196 // |
|
197 // |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C void CAknFileSelectionDialog::SetRightSoftkeyRootFolderL( const TDesC& aText ) |
|
201 { |
|
202 AknCFDUtility::AllocateIfValidL( iRightSoftkeyRootFolder, aText ); |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CAknFileSelectionDialog::SetRightSoftkeySubfolderL |
|
207 // |
|
208 // |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C void CAknFileSelectionDialog::SetRightSoftkeySubfolderL( const TDesC& aText ) |
|
212 { |
|
213 AknCFDUtility::AllocateIfValidL( iRightSoftkeySubfolder, aText ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CAknFileSelectionDialog::ExecuteL |
|
218 // |
|
219 // |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C TBool CAknFileSelectionDialog::ExecuteL( TDes& aFileName ) |
|
223 { |
|
224 __ASSERT_DEBUG( iTitle && iLeftSoftkeyFolder && iLeftSoftkeyFile && |
|
225 iRightSoftkeyRootFolder && iRightSoftkeySubfolder, |
|
226 User::Panic( KCFDPanicText, ECFDPanicTitleOrSoftkeyNotSet ) ); |
|
227 |
|
228 // Initialize model and set default values |
|
229 if( ( !iExecuted ) && |
|
230 ( !PrepareL( aFileName ) ) ) |
|
231 { |
|
232 // If root folder is empty, do not browse, returns ESelectionKey |
|
233 if( AknCFDUtility::IsRemoteDrive( aFileName ) ) |
|
234 { |
|
235 return ERightSoftkey; |
|
236 } |
|
237 else |
|
238 { |
|
239 return ESelectionKey; |
|
240 } |
|
241 } |
|
242 |
|
243 // Listbox creation |
|
244 CEikFormattedCellListBox* listBox = |
|
245 new( ELeave ) CAknSingleGraphicPopupMenuStyleListBox(); |
|
246 CleanupStack::PushL( listBox ); |
|
247 TBool isEndKeyPress = EFalse; |
|
248 CAknCommonDialogsPopupList* popupList = CAknCommonDialogsPopupList::NewL( |
|
249 *iEventHandler, listBox, AknPopupLayouts::EMenuGraphicWindow, isEndKeyPress ); |
|
250 CleanupStack::PushL( popupList ); |
|
251 listBox->ConstructL( popupList, 0 ); // Listbox construction |
|
252 listBox->CreateScrollBarFrameL( ETrue ); // Create scroll indicator |
|
253 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
254 CEikScrollBarFrame::EAuto ); |
|
255 // Pass model to listbox |
|
256 listBox->Model()->SetItemTextArray( iModel ); |
|
257 // Set model ownership type |
|
258 listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
259 |
|
260 // Add icons to listbox, granularity 15 |
|
261 CEikonEnv* eikEnv = CEikonEnv::Static(); |
|
262 CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 20 ); |
|
263 CleanupStack::PushL( iconArray ); |
|
264 |
|
265 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
266 |
|
267 // Add folder icon. |
|
268 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
269 skin, KAknsIIDQgnPropFolderSmall, KAvkonBitmapFile, |
|
270 EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask ); |
|
271 |
|
272 // Add file icon. |
|
273 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
274 skin, KAknsIIDQgnPropFileSmall, KAvkonBitmapFile, |
|
275 EMbmAvkonQgn_prop_file_small, EMbmAvkonQgn_prop_file_small_mask ); |
|
276 |
|
277 // Add sub folder icon. |
|
278 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
279 skin, KAknsIIDQgnPropFolderSubSmall, KAvkonBitmapFile, |
|
280 EMbmAvkonQgn_prop_folder_sub_small, EMbmAvkonQgn_prop_folder_sub_small_mask ); |
|
281 |
|
282 // Add current folder icon. |
|
283 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
284 skin, KAknsIIDQgnPropFolderCurrent, KAvkonBitmapFile, |
|
285 EMbmAvkonQgn_prop_folder_current, EMbmAvkonQgn_prop_folder_current_mask ); |
|
286 |
|
287 // Add image file icon. |
|
288 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
289 KAknsIIDQgnPropFmgrFileImage, KCommonDialogsBitmapFile, |
|
290 EMbmCommondialogsQgn_prop_fmgr_file_image, EMbmCommondialogsQgn_prop_fmgr_file_image_mask ); |
|
291 |
|
292 // Add graphical message image file icon. |
|
293 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
294 KAknsIIDQgnPropFmgrFileGms, KCommonDialogsBitmapFile, |
|
295 EMbmCommondialogsQgn_prop_fmgr_file_gms, EMbmCommondialogsQgn_prop_fmgr_file_gms_mask ); |
|
296 |
|
297 // Add link file icon. |
|
298 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
299 KAknsIIDQgnPropFmgrFileLink, KCommonDialogsBitmapFile, |
|
300 EMbmCommondialogsQgn_prop_fmgr_file_link, EMbmCommondialogsQgn_prop_fmgr_file_link_mask ); |
|
301 |
|
302 // Add voicerec file icon. |
|
303 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
304 KAknsIIDQgnPropFmgrFileVoicerec, KCommonDialogsBitmapFile, |
|
305 EMbmCommondialogsQgn_prop_fmgr_file_voicerec, EMbmCommondialogsQgn_prop_fmgr_file_voicerec_mask ); |
|
306 |
|
307 // Add sound file icon. |
|
308 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
309 KAknsIIDQgnPropFmgrFileSound, KCommonDialogsBitmapFile, |
|
310 EMbmCommondialogsQgn_prop_fmgr_file_sound, EMbmCommondialogsQgn_prop_fmgr_file_sound_mask ); |
|
311 |
|
312 // Add playlist file icon. |
|
313 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
314 KAknsIIDQgnPropFmgrFilePlaylist, KCommonDialogsBitmapFile, |
|
315 EMbmCommondialogsQgn_prop_fmgr_file_playlist, EMbmCommondialogsQgn_prop_fmgr_file_playlist_mask ); |
|
316 |
|
317 // Add compo file icon. |
|
318 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
319 KAknsIIDQgnPropFmgrFileCompo, KCommonDialogsBitmapFile, |
|
320 EMbmCommondialogsQgn_prop_fmgr_file_compo, EMbmCommondialogsQgn_prop_fmgr_file_compo_mask ); |
|
321 |
|
322 // Add note file icon. |
|
323 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
324 KAknsIIDQgnPropNrtypNote, KAvkonBitmapFile, |
|
325 EMbmAvkonQgn_prop_nrtyp_note, EMbmAvkonQgn_prop_nrtyp_note_mask ); |
|
326 |
|
327 // Add sis file icon. |
|
328 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
329 KAknsIIDQgnPropAmSis, KCommonDialogsBitmapFile, |
|
330 EMbmCommondialogsQgn_prop_am_sis, EMbmCommondialogsQgn_prop_am_sis_mask ); |
|
331 |
|
332 // Add video file icon. |
|
333 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
334 KAknsIIDQgnPropFmgrFileVideo, KCommonDialogsBitmapFile, |
|
335 EMbmCommondialogsQgn_prop_fmgr_file_video, EMbmCommondialogsQgn_prop_fmgr_file_video_mask ); |
|
336 |
|
337 // Add game file icon. |
|
338 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, skin, |
|
339 KAknsIIDQgnPropFmgrFileGame, KCommonDialogsBitmapFile, |
|
340 EMbmCommondialogsQgn_prop_fmgr_file_game, EMbmCommondialogsQgn_prop_fmgr_file_game_mask ); |
|
341 |
|
342 // Add java file icon. |
|
343 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
344 skin, KAknsIIDQgnPropAmMidlet, KCommonDialogsBitmapFile, |
|
345 EMbmCommondialogsQgn_prop_am_midlet, EMbmCommondialogsQgn_prop_am_midlet_mask ); |
|
346 |
|
347 // Add unknow file type icon. |
|
348 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
349 skin, KAknsIIDQgnPropFmgrFileOther, KCommonDialogsBitmapFile, |
|
350 EMbmCommondialogsQgn_prop_fmgr_file_other, EMbmCommondialogsQgn_prop_fmgr_file_other_mask ); |
|
351 |
|
352 // Add empty folder icon. |
|
353 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
354 skin, KAknsIIDQgnPropFolderEmpty, KCommonDialogsBitmapFile, |
|
355 EMbmCommondialogsQgn_prop_folder_empty, EMbmCommondialogsQgn_prop_folder_empty_mask ); |
|
356 |
|
357 // Add flash file icon. |
|
358 AknCFDUtility::AppendSkinnedImageToArrayL( *eikEnv, *iconArray, |
|
359 skin, KAknsIIDQgnPropFileSwfSmall, KCommonDialogsBitmapFile, |
|
360 EMbmCommondialogsQgn_prop_file_swf_small, EMbmCommondialogsQgn_prop_file_swf_small_mask ); |
|
361 |
|
362 // Set icon array |
|
363 listBox->ItemDrawer()->FormattedCellData()->SetIconArrayL( iconArray ); |
|
364 CleanupStack::Pop(); // iconArray |
|
365 |
|
366 popupList->SetTitleL( *iTitle ); |
|
367 |
|
368 TInt focus( 0 ); |
|
369 TInt topIndex( 0 ); |
|
370 if( iExecuted ) |
|
371 { |
|
372 // File selection has been executed already before, get the last |
|
373 // selection from the index stack: |
|
374 iEventHandler->PopIndices( topIndex, focus); |
|
375 } |
|
376 CListBoxView* view = listBox->View(); |
|
377 if( focus > 0 ) |
|
378 { |
|
379 view->SetCurrentItemIndex( focus ); |
|
380 } |
|
381 if( topIndex > 0 ) |
|
382 { |
|
383 view->SetTopItemIndex( topIndex ); |
|
384 } |
|
385 |
|
386 iEventHandler->ResetSoftkeyStatus(); |
|
387 iEventHandler->UpdateSoftkeysL( focus, popupList->ButtonGroupContainer() ); |
|
388 |
|
389 TBool returnValue( popupList->ExecuteLD() ); |
|
390 if( returnValue ) |
|
391 { |
|
392 TInt selectedIndex( listBox->CurrentItemIndex() ); |
|
393 iModel->GetCurrentPath( aFileName ); |
|
394 const TEntry& entry = iModel->Entry( selectedIndex ); |
|
395 if( ( selectedIndex ) || ( !AknCFDUtility::DirectoriesOnly( iDialogType ) ) ) |
|
396 { |
|
397 aFileName.Append( entry.iName ); |
|
398 if( entry.IsDir() ) |
|
399 { |
|
400 // Append trailing backslash to a folder name, ignore return value |
|
401 AknCFDUtility::AddTrailingBackslash( aFileName ); |
|
402 } |
|
403 } |
|
404 } |
|
405 |
|
406 CleanupStack::Pop(); // popupList |
|
407 CleanupStack::PopAndDestroy(); // listBox |
|
408 |
|
409 iExecuted = ETrue; |
|
410 |
|
411 if ( isEndKeyPress ) |
|
412 { |
|
413 User::Leave( KErrAbort ); |
|
414 } |
|
415 |
|
416 return returnValue; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CAknFileSelectionDialog::RunDlgLD |
|
421 // |
|
422 // |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 EXPORT_C TBool CAknFileSelectionDialog::RunDlgLD( |
|
426 TDes& aFileName, |
|
427 const TDesC& aDefaultFolder, |
|
428 MAknFileSelectionObserver* aObserver ) |
|
429 { |
|
430 return RunL( 0, aFileName, aDefaultFolder, KNullDesC, aObserver ); |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CAknFileSelectionDialog::RunDlgLD |
|
435 // |
|
436 // |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 EXPORT_C TBool CAknFileSelectionDialog::RunDlgLD( |
|
440 TDes& aFileName, |
|
441 const TDesC& aDefaultFolder, |
|
442 const TDesC& aTitle, |
|
443 MAknFileSelectionObserver* aObserver ) |
|
444 { |
|
445 return RunL( 0, aFileName, aDefaultFolder, aTitle, aObserver ); |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // CAknFileSelectionDialog::RunDlgLD |
|
450 // |
|
451 // |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 EXPORT_C TBool CAknFileSelectionDialog::RunDlgLD( |
|
455 TDes& aFileName, |
|
456 const TDesC& aDefaultFolder, |
|
457 TInt aResourceId, |
|
458 MAknFileSelectionObserver* aObserver ) |
|
459 { |
|
460 return RunL( aResourceId, aFileName, aDefaultFolder, KNullDesC, aObserver ); |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CAknFileSelectionDialog::RunL |
|
465 // |
|
466 // |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 TBool CAknFileSelectionDialog::RunL( |
|
470 TInt aResourceId, |
|
471 TDes& aFileName, |
|
472 const TDesC& aDefaultFolder, |
|
473 const TDesC& aTitle, |
|
474 MAknFileSelectionObserver* aObserver ) |
|
475 { |
|
476 CAknFileSelectionDialog* self; |
|
477 self = CAknFileSelectionDialog::NewL( ECFDDialogTypeSelect, aResourceId ); |
|
478 CleanupStack::PushL( self ); |
|
479 self->SetDefaultFolderL( aDefaultFolder ); |
|
480 self->SetTitleL( aTitle ); |
|
481 self->iObserver = aObserver; |
|
482 |
|
483 TBool returnValue( self->ExecuteL( aFileName ) ); |
|
484 |
|
485 CleanupStack::PopAndDestroy(); // self |
|
486 return returnValue; |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CAknFileSelectionDialog::PrepareL |
|
491 // |
|
492 // |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 TBool CAknFileSelectionDialog::PrepareL( const TDesC& aFileName ) |
|
496 { |
|
497 // A root path written in resource file overrides the root path in parameter |
|
498 // If the root path field is not defined in resource, parameter is used |
|
499 TPtrC rootPath = iRootPath ? ( const TDesC& ) ( *iRootPath ) : aFileName; |
|
500 TInt itemCount( iModel->SetPathL( rootPath ) ); |
|
501 if( itemCount <= 0 ) |
|
502 { |
|
503 if( iDialogType == ECFDDialogTypeSelect ) |
|
504 { |
|
505 // In select dialog allow open empty list |
|
506 return ETrue; |
|
507 } |
|
508 // The root folder is empty, or returned error |
|
509 return EFalse; |
|
510 } |
|
511 |
|
512 if( iDefaultFolder ) |
|
513 { |
|
514 // This is a path variable that has the remaining path that needs |
|
515 // to be gone into |
|
516 |
|
517 //TPath remainingPath( *iDefaultFolder ); |
|
518 HBufC *bufRemainingPath = HBufC::NewLC(KMaxPath); |
|
519 *bufRemainingPath = *iDefaultFolder; |
|
520 TPtr remainingPath = bufRemainingPath->Des(); |
|
521 |
|
522 TInt folderIndex( 0 ); |
|
523 TInt topIndex( 0 ); |
|
524 if( AknCFDUtility::AddTrailingBackslash( remainingPath ) == KErrNone ) |
|
525 { |
|
526 TInt folderCount( AknCFDUtility::DirectoryCount( remainingPath ) ); |
|
527 TInt backslashPosition; |
|
528 |
|
529 //TPath currentFolder; |
|
530 HBufC *bufCurrentFolder = HBufC::NewLC(KMaxPath); |
|
531 TPtr currentFolder = bufCurrentFolder->Des(); |
|
532 |
|
533 for( TInt index( 0 ); index < folderCount; index++ ) |
|
534 { |
|
535 backslashPosition = remainingPath.Locate( TChar( '\\' ) ); |
|
536 if( backslashPosition != KErrNotFound ) |
|
537 { |
|
538 currentFolder = remainingPath.Left( backslashPosition + 1 ); |
|
539 remainingPath.Delete( 0, backslashPosition + 1 ); |
|
540 } |
|
541 |
|
542 folderIndex = iModel->FolderIndex( currentFolder ); |
|
543 if( folderIndex < KErrNone ) |
|
544 { |
|
545 break; |
|
546 } |
|
547 |
|
548 const TInt KNumberOfViewableItems( 5 ); |
|
549 |
|
550 // Focused item is in the middle |
|
551 topIndex = folderIndex - KNumberOfViewableItems / 2; |
|
552 |
|
553 // Check boundaries |
|
554 if( topIndex < 0 ) |
|
555 { |
|
556 topIndex = 0; |
|
557 } |
|
558 else if( topIndex + KNumberOfViewableItems > itemCount - 1 ) |
|
559 // itemCount - 1 == the last index |
|
560 { |
|
561 topIndex = itemCount - 1 - KNumberOfViewableItems; |
|
562 } |
|
563 |
|
564 if( iEventHandler->HandleEventL( |
|
565 MAknCommonDialogsEventObserver::ESelectionKeyPress, |
|
566 folderIndex, topIndex, NULL ) != |
|
567 MAknCommonDialogsEventObserver::EItemsUpdated ) |
|
568 { |
|
569 break; |
|
570 } |
|
571 } |
|
572 |
|
573 CleanupStack::PopAndDestroy();// bufCurrentFolder |
|
574 |
|
575 } |
|
576 // If we find that the folder we are going into first is empty, |
|
577 // we must come back one folder, because CAknPopupList::ExecuteLD |
|
578 // won't run if listbox has 0 items |
|
579 if( iModel->MdcaCount() == 0 ) |
|
580 { |
|
581 iEventHandler->HandleEventL( |
|
582 MAknCommonDialogsEventObserver::ERightSoftkeyPress, |
|
583 folderIndex, topIndex, NULL ); |
|
584 } |
|
585 |
|
586 |
|
587 CleanupStack::PopAndDestroy();// bufRemainingPath |
|
588 |
|
589 } |
|
590 |
|
591 |
|
592 return ETrue; |
|
593 } |
|
594 |
|
595 // ----------------------------------------------------------------------------- |
|
596 // CAknFileSelectionDialog::SetResourceId |
|
597 // |
|
598 // |
|
599 // ----------------------------------------------------------------------------- |
|
600 // |
|
601 void CAknFileSelectionDialog::SetResourceId( TInt& aResourceId, TCommonDialogType aType ) const |
|
602 { |
|
603 switch( aType ) |
|
604 { |
|
605 case ECFDDialogTypeBrowse: |
|
606 { |
|
607 aResourceId = R_CFD_DEFAULT_BROWSE_FILE_SELECTION; |
|
608 break; |
|
609 } |
|
610 case ECFDDialogTypeMove: |
|
611 { |
|
612 aResourceId = R_CFD_DEFAULT_MOVE_FILE_SELECTION; |
|
613 break; |
|
614 } |
|
615 case ECFDDialogTypeSave: |
|
616 { |
|
617 aResourceId = R_CFD_DEFAULT_SAVE_FILE_SELECTION; |
|
618 break; |
|
619 } |
|
620 case ECFDDialogTypeCopy: |
|
621 { |
|
622 aResourceId = R_CFD_DEFAULT_COPY_FILE_SELECTION; |
|
623 break; |
|
624 } |
|
625 default: |
|
626 { |
|
627 aResourceId = R_CFD_DEFAULT_SELECT_FILE_SELECTION; |
|
628 break; |
|
629 } |
|
630 } |
|
631 } |
|
632 |
|
633 // ----------------------------------------------------------------------------- |
|
634 // CAknFileSelectionDialog::ReadFromResourceL |
|
635 // |
|
636 // |
|
637 // ----------------------------------------------------------------------------- |
|
638 // |
|
639 void CAknFileSelectionDialog::ReadFromResourceL( TInt aResourceId ) |
|
640 { |
|
641 TResourceReader reader; |
|
642 iCoeEnv->CreateResourceReaderLC( reader, aResourceId ); |
|
643 AknCFDUtility::AllocateIfNullL( iTitle, reader.ReadTPtrC() ); |
|
644 AknCFDUtility::AllocateIfNullL( iLeftSoftkeyFile, reader.ReadTPtrC() ); |
|
645 AknCFDUtility::AllocateIfNullL( iLeftSoftkeyFolder, reader.ReadTPtrC() ); |
|
646 AknCFDUtility::AllocateIfNullL( iRightSoftkeyRootFolder, reader.ReadTPtrC() ); |
|
647 AknCFDUtility::AllocateIfNullL( iRightSoftkeySubfolder, reader.ReadTPtrC() ); |
|
648 AknCFDUtility::AllocateIfNullL( iRootPath, reader.ReadTPtrC() ); |
|
649 AknCFDUtility::AllocateIfNullL( iDefaultFolder, reader.ReadTPtrC() ); |
|
650 |
|
651 // Read filter count from resource |
|
652 TInt numOfFilters( reader.ReadInt16() ); |
|
653 // Create filters and pass ownership to model |
|
654 MAknFileFilter* filter; |
|
655 for( TInt index( 0 ); index < numOfFilters; index++ ) |
|
656 { |
|
657 filter = AknFileFilterFactory::CreateFilterLC( reader ); |
|
658 iModel->AddFilterL( filter ); // Ownership is transferred to the model |
|
659 CleanupStack::Pop(); // filter |
|
660 } |
|
661 CleanupStack::PopAndDestroy(); // reader |
|
662 } |
|
663 |
|
664 // End of File |