|
1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "FBFileUtils.h" |
|
20 #include "FBFileOps.h" |
|
21 #include "engine.h" |
|
22 #include "FB.hrh" |
|
23 #include <filebrowser.rsg> |
|
24 |
|
25 #include <textresolver.h> |
|
26 #include <eikprogi.h> |
|
27 #include <e32svr.h> |
|
28 #include <eikfutil.h> |
|
29 #include <apparc.h> |
|
30 #include <apaid.h> |
|
31 #include <apaidpartner.h> |
|
32 #include <eikenv.h> |
|
33 #include <bautils.h> |
|
34 #include <gulicon.h> |
|
35 #include <babackup.h> |
|
36 //#include <aknmemorycardui.mbg> |
|
37 //#include <sendui.h> |
|
38 #include <CMessageData.h> |
|
39 #include <ezgzip.h> |
|
40 #include <e32hal.h> |
|
41 #include <pathinfo.h> |
|
42 #include <apgcli.h> |
|
43 #include <apmstd.h> |
|
44 #include <apgtask.h> |
|
45 #include <apacmdln.h> |
|
46 #include <DocumentHandler.h> |
|
47 #include <msvapi.h> |
|
48 #include <msvids.h> |
|
49 #include <msvstd.h> |
|
50 #include <msvstore.h> |
|
51 #include <mmsvattachmentmanager.h> |
|
52 #include <cmsvattachment.h> |
|
53 #include <hash.h> |
|
54 //#include <sbeclient.h> |
|
55 #include <e32property.h> |
|
56 #if (!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
57 #include <driveinfo.h> |
|
58 #endif // !defined __SERIES60_30__ && !defined __SERIES60_31__ |
|
59 |
|
60 #ifndef __SERIES60_30__ |
|
61 // #include <akniconconfig.h> |
|
62 #endif |
|
63 |
|
64 //_LIT(KGZipExt, ".gz"); |
|
65 _LIT8(KFileNewLine, "\r\n"); |
|
66 const TInt KForcedFormatTimeout = 1000000; |
|
67 |
|
68 // copied from coreapplicationuisdomainpskeys.h |
|
69 const TUid KPSUidCoreApplicationUIs = { 0x101F8767 }; |
|
70 const TUint32 KCoreAppUIsMmcRemovedWithoutEject = 0x00000109; |
|
71 enum TCoreAppUIsMmcRemovedWithoutEject |
|
72 { |
|
73 ECoreAppUIsEjectCommandUsedUninitialized = 0, |
|
74 ECoreAppUIsEjectCommandNotUsed, |
|
75 ECoreAppUIsEjectCommandUsed, |
|
76 ECoreAppUIsEjectCommandUsedToDrive // Low 16-bits contain this value and high 16-bits TDriveNumber to eject |
|
77 }; |
|
78 const TInt KDriveLetterStringLength = 3; // e.g. C:\ |
|
79 |
|
80 // ================= MEMBER FUNCTIONS ======================= |
|
81 |
|
82 CFileBrowserFileUtils* CFileBrowserFileUtils::NewL(CEngine* aEngine) |
|
83 { |
|
84 CFileBrowserFileUtils* self = new(ELeave) CFileBrowserFileUtils(aEngine); |
|
85 CleanupStack::PushL(self); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop(); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------------------------- |
|
92 |
|
93 CFileBrowserFileUtils::CFileBrowserFileUtils(CEngine* aEngine) : CActive(EPriorityStandard), iEngine(aEngine) |
|
94 { |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------------------------- |
|
98 |
|
99 void CFileBrowserFileUtils::ConstructL() |
|
100 { |
|
101 User::LeaveIfError(iTimer.CreateLocal()); |
|
102 User::LeaveIfError(iFs.Connect()); |
|
103 User::LeaveIfError(iTz.Connect()); |
|
104 |
|
105 iState = EIdle; |
|
106 iListingMode = ENormalEntries; |
|
107 |
|
108 iSortMode = EFileBrowserCmdViewSortByName; |
|
109 iOrderMode = EFileBrowserCmdViewOrderAscending; |
|
110 iCurrentPath = KNullDesC; |
|
111 |
|
112 iFileOps = CFileBrowserFileOps::NewL(iEngine); |
|
113 |
|
114 iDriveEntryList = new(ELeave) CDriveEntryList(8); |
|
115 iFileEntryList = new(ELeave) CFileEntryList(64); |
|
116 iFindFileEntryList = new(ELeave) CFileEntryList(64); |
|
117 iAppIconList = new(ELeave) CAppIconList(16); |
|
118 iClipBoardList = new(ELeave) CFileEntryList(64); |
|
119 iCurrentSelectionList = new(ELeave) CFileEntryList(64); |
|
120 |
|
121 iDocHandler = CDocumentHandler::NewL(); |
|
122 // iDocHandler->SetExitObserver(this); |
|
123 |
|
124 // set defaults to the search settings |
|
125 iSearchAttributes.iSearchDir = KNullDesC; |
|
126 iSearchAttributes.iWildCards = _L("*.jpg"); |
|
127 iSearchAttributes.iTextInFile = KNullDesC; |
|
128 iSearchAttributes.iMinSize = 0; |
|
129 iSearchAttributes.iMaxSize = 999999999; |
|
130 iSearchAttributes.iMinDate = TDateTime(1980, EJanuary, 0,0,0,0,0); |
|
131 iSearchAttributes.iMaxDate = TDateTime(2060, EDecember, 30,0,0,0,0); |
|
132 iSearchAttributes.iRecurse = ETrue; |
|
133 |
|
134 // init the command array |
|
135 iCommandArray = new(ELeave) CCommandArray(64); |
|
136 |
|
137 // get current path from settings |
|
138 if (iEngine->Settings().iRememberLastPath) |
|
139 { |
|
140 TFileName settingPath = iEngine->Settings().iLastPath; |
|
141 if (BaflUtils::PathExists(iFs, settingPath)) |
|
142 iCurrentPath = settingPath; |
|
143 |
|
144 if (iCurrentPath != KNullDesC) |
|
145 GetDriveListL(); |
|
146 } |
|
147 |
|
148 CActiveScheduler::Add(this); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------------------------- |
|
152 |
|
153 CFileBrowserFileUtils::~CFileBrowserFileUtils() |
|
154 { |
|
155 Cancel(); |
|
156 |
|
157 // save current path from settings |
|
158 if (iEngine->Settings().iRememberLastPath) |
|
159 { |
|
160 iEngine->Settings().iLastPath = iCurrentPath; |
|
161 TRAP_IGNORE(iEngine->SaveSettingsL(EFalse)); |
|
162 } |
|
163 |
|
164 // if (iWaitDialog) |
|
165 // TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); |
|
166 // |
|
167 // if (iProgressDialog) |
|
168 // TRAP_IGNORE(iProgressDialog->ProcessFinishedL()); |
|
169 |
|
170 delete iFileOps; |
|
171 |
|
172 delete iDocHandler; |
|
173 |
|
174 // if (iOpenFileService) |
|
175 // delete iOpenFileService; |
|
176 |
|
177 delete iCurrentSelectionList; |
|
178 delete iClipBoardList; |
|
179 delete iAppIconList; |
|
180 delete iFindFileEntryList; |
|
181 delete iFileEntryList; |
|
182 delete iDriveEntryList; |
|
183 |
|
184 delete iFileMan; |
|
185 |
|
186 if (iCommandArray) |
|
187 { |
|
188 ResetCommandArray(); |
|
189 delete iCommandArray; |
|
190 } |
|
191 |
|
192 iTz.Close(); |
|
193 iFs.Close(); |
|
194 iTimer.Close(); |
|
195 } |
|
196 |
|
197 // -------------------------------------------------------------------------------------------- |
|
198 |
|
199 void CFileBrowserFileUtils::DoCancel() |
|
200 { |
|
201 iTimer.Cancel(); |
|
202 } |
|
203 |
|
204 // -------------------------------------------------------------------------------------------- |
|
205 |
|
206 void CFileBrowserFileUtils::StartExecutingCommandsL(const TDesC& aLabel) |
|
207 { |
|
208 if (iCommandArray->Count() >= 2) |
|
209 { |
|
210 // init progress bar |
|
211 // iProgressDialog = new(ELeave) CAknProgressDialog((reinterpret_cast<CEikDialog**>(&iProgressDialog)), ETrue); |
|
212 // iProgressDialog->SetCallback(this); |
|
213 // iProgressDialog->PrepareLC(R_GENERAL_PROGRESS_NOTE); |
|
214 // iProgressDialog->SetCurrentLabelL( EAknCtNote, aLabel ); |
|
215 // iProgressInfo = iProgressDialog->GetProgressInfoL(); |
|
216 // iProgressInfo->SetFinalValue( CommandArrayCount() ); |
|
217 // iProgressDialog->RunLD(); |
|
218 // iProgressDialog->MakeVisible( ETrue ); |
|
219 iEngine->FileBrowserUI()->ShowProgressDialog(aLabel, 0, CommandArrayCount()); |
|
220 isProgressDialog = ETrue; |
|
221 } |
|
222 else if (iCommandArray->Count() >= 1) |
|
223 { |
|
224 // init wait dialog |
|
225 // iWaitDialog = new(ELeave) CAknWaitDialog((reinterpret_cast<CEikDialog**>(&iWaitDialog)), ETrue); |
|
226 // iWaitDialog->SetCallback(this); |
|
227 // iWaitDialog->PrepareLC(R_GENERAL_WAIT_NOTE); |
|
228 // iWaitDialog->SetTextL( aLabel ); |
|
229 // iWaitDialog->RunLD(); |
|
230 iEngine->FileBrowserUI()->ShowWaitDialog(aLabel); |
|
231 isWaitDialog = ETrue; |
|
232 } |
|
233 else |
|
234 { |
|
235 // no commands, just do nothing |
|
236 return; |
|
237 } |
|
238 |
|
239 |
|
240 // start with the first operation |
|
241 iCurrentEntry = 0; |
|
242 iSucceededOperations = 0; |
|
243 iFailedOperations = 0; |
|
244 |
|
245 // starts executing commands |
|
246 ExecuteCommand(); |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------------------------- |
|
250 |
|
251 void CFileBrowserFileUtils::ExecuteCommand() |
|
252 { |
|
253 // make sure the engine isn't active, should never happen |
|
254 __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("FileUtils:IsActive"), 333)); |
|
255 |
|
256 // execute a command after a very short delay (25ms) |
|
257 if (isWaitDialog) |
|
258 { |
|
259 iEngine->FileBrowserUI()->ProcessEvents(); |
|
260 } |
|
261 if (isProgressDialog) |
|
262 { |
|
263 TInt newValue = iCurrentEntry; |
|
264 iEngine->FileBrowserUI()->SetProgressValue(newValue); |
|
265 } |
|
266 iTimer.After(iStatus, 25); |
|
267 SetActive(); |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------------------------- |
|
271 |
|
272 void CFileBrowserFileUtils::RunL() |
|
273 { |
|
274 TInt err(KErrNone); |
|
275 TInt currentCommand = iCommandArray->At(iCurrentEntry).iCommandId; |
|
276 |
|
277 // execute a command from the queue |
|
278 switch(currentCommand) |
|
279 { |
|
280 case EFileBrowserFileOpCommandAttribs: |
|
281 { |
|
282 CCommandParamsAttribs* params = static_cast<CCommandParamsAttribs*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
283 err = iFileOps->Attribs(params->iSourceEntry, params->iSetMask, params->iClearMask, params->iTime, params->iSwitch); |
|
284 } |
|
285 break; |
|
286 |
|
287 case EFileBrowserFileOpCommandCopy: |
|
288 { |
|
289 CCommandParamsCopyOrMove* params = static_cast<CCommandParamsCopyOrMove*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
290 err = iFileOps->Copy(params->iSourceEntry, params->iTargetPath, params->iSwitch); |
|
291 } |
|
292 break; |
|
293 |
|
294 case EFileBrowserFileOpCommandMove: |
|
295 { |
|
296 CCommandParamsCopyOrMove* params = static_cast<CCommandParamsCopyOrMove*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
297 err = iFileOps->Copy(params->iSourceEntry, params->iTargetPath, params->iSwitch, ETrue); |
|
298 } |
|
299 break; |
|
300 |
|
301 case EFileBrowserFileOpCommandRename: |
|
302 { |
|
303 CCommandParamsRename* params = static_cast<CCommandParamsRename*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
304 err = iFileOps->Rename(params->iSourceEntry, params->iTargetPath, params->iSwitch); |
|
305 } |
|
306 break; |
|
307 |
|
308 case EFileBrowserFileOpCommandDelete: |
|
309 { |
|
310 CCommandParamsDelete* params = static_cast<CCommandParamsDelete*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
311 err = iFileOps->Delete(params->iSourceEntry, params->iSwitch); |
|
312 } |
|
313 break; |
|
314 |
|
315 case EFileBrowserFileOpCommandDriveSnapShot: |
|
316 { |
|
317 CCommandParamsDriveSnapShot* params = static_cast<CCommandParamsDriveSnapShot*>(iCommandArray->At(iCurrentEntry).iParameters); |
|
318 err = iFileOps->DriveSnapShot(params->iSourceDriveLetter, params->iTargetDriveLetter); |
|
319 } |
|
320 break; |
|
321 |
|
322 default: |
|
323 User::Panic (_L("Unknown command"), 400); |
|
324 break; |
|
325 } |
|
326 |
|
327 |
|
328 if (err == KErrNone) |
|
329 { |
|
330 iSucceededOperations++; |
|
331 } |
|
332 else if ( err != KErrCancel ) |
|
333 { |
|
334 iFailedOperations++; |
|
335 } |
|
336 |
|
337 iLastError = err; |
|
338 |
|
339 // check for more commands in queue |
|
340 TRAP_IGNORE( CheckForMoreCommandsL() ); |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 |
|
345 TInt CFileBrowserFileUtils::RunError(TInt aError) |
|
346 { |
|
347 _LIT(KMessage, "Command error %d"); |
|
348 TBuf<128> noteMsg; |
|
349 noteMsg.Format(KMessage, aError); |
|
350 |
|
351 iEngine->EikonEnv()->InfoMsg(noteMsg); |
|
352 |
|
353 TRAP_IGNORE( CheckForMoreCommandsL() ); |
|
354 |
|
355 return KErrNone; |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 |
|
360 void CFileBrowserFileUtils::CheckForMoreCommandsL() |
|
361 { |
|
362 //LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL"); |
|
363 |
|
364 // update the progress bar |
|
365 // if (iProgressInfo) |
|
366 // iProgressInfo->IncrementAndDraw(1); |
|
367 |
|
368 // check if we have more commands to be executed |
|
369 if (iCurrentEntry >= CommandArrayCount() - 1) |
|
370 { |
|
371 //LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL all done"); |
|
372 |
|
373 // all done, free resources |
|
374 ResetCommandArray(); |
|
375 |
|
376 // deactive secure backup if it was activated by a file command |
|
377 iFileOps->DeActivateSecureBackUpViaFileOp(); |
|
378 |
|
379 // dismiss any wait/progress dialogs |
|
380 if (isWaitDialog) |
|
381 { |
|
382 iEngine->FileBrowserUI()->CancelWaitDialog(); |
|
383 isWaitDialog = EFalse; |
|
384 } |
|
385 if (isProgressDialog) |
|
386 { |
|
387 iEngine->FileBrowserUI()->CancelProgressDialog(); |
|
388 isProgressDialog = EFalse; |
|
389 } |
|
390 // if (iWaitDialog) |
|
391 // { |
|
392 // TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); |
|
393 // iWaitDialog = NULL; |
|
394 // } |
|
395 // if (iProgressDialog) |
|
396 // { |
|
397 // TRAP_IGNORE(iProgressDialog->ProcessFinishedL()); |
|
398 // iProgressDialog = NULL; |
|
399 // } |
|
400 |
|
401 |
|
402 // show result note |
|
403 if ( iSucceededOperations == 0 && iFailedOperations == 0 ) |
|
404 { |
|
405 // single operation cancelled -> show nothing |
|
406 } |
|
407 else if (iSucceededOperations == 1 && iFailedOperations == 0) |
|
408 { |
|
409 _LIT(KMessage, "Operation succeeded"); |
|
410 iEngine->FileBrowserUI()->ShowConfirmationNote(KMessage); |
|
411 } |
|
412 else if (iSucceededOperations > 0 && iFailedOperations == 0) |
|
413 { |
|
414 _LIT(KMessage, "%d operations succeeded"); |
|
415 TBuf<128> noteMsg; |
|
416 noteMsg.Format(KMessage, iSucceededOperations); |
|
417 iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg); |
|
418 } |
|
419 else if (iSucceededOperations == 0 && iFailedOperations > 1) |
|
420 { |
|
421 _LIT(KMessage, "%d operations failed"); |
|
422 TBuf<128> noteMsg; |
|
423 noteMsg.Format(KMessage, iFailedOperations); |
|
424 |
|
425 iEngine->FileBrowserUI()->ShowErrorNote(noteMsg); |
|
426 } |
|
427 else if (iSucceededOperations > 0 && iFailedOperations > 0) |
|
428 { |
|
429 _LIT(KMessage, "%d operations succeeded, %d failed"); |
|
430 TBuf<128> noteMsg; |
|
431 noteMsg.Format(KMessage, iSucceededOperations, iFailedOperations); |
|
432 |
|
433 iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
434 } |
|
435 else |
|
436 { |
|
437 iEngine->FileBrowserUI()->ShowErrorNote(ResolveErrorMessage(iLastError)); |
|
438 } |
|
439 |
|
440 RefreshViewL(); |
|
441 iEngine->FileBrowserUI()->NotifyModelHasChanged(); |
|
442 |
|
443 } |
|
444 else |
|
445 { |
|
446 // maintain requests |
|
447 iCurrentEntry++; |
|
448 |
|
449 //LOGSTRING2("Creator: CCreatorEngine::CheckForMoreCommandsL iCurrentEntry=%d", iCurrentEntry); |
|
450 |
|
451 ExecuteCommand(); |
|
452 } |
|
453 } |
|
454 // -------------------------------------------------------------------------------------------- |
|
455 |
|
456 // This callback function is called when cancel button of the progress bar was pressed |
|
457 void CFileBrowserFileUtils::DialogDismissedL(/*TInt aButtonId*/) |
|
458 { |
|
459 // iProgressDialog = NULL; |
|
460 // iProgressInfo = NULL; |
|
461 // iWaitDialog = NULL; |
|
462 |
|
463 // check if cancel button was pressed |
|
464 // if (aButtonId == EAknSoftkeyCancel) |
|
465 // { |
|
466 // cancel the active object, command executer |
|
467 Cancel(); |
|
468 |
|
469 iFileOps->CancelOp(); |
|
470 |
|
471 ResetCommandArray(); |
|
472 |
|
473 isProgressDialog = EFalse; |
|
474 |
|
475 iEngine->FileBrowserUI()->ShowInformationNote(_L("Cancelled"), _L("")); |
|
476 // } |
|
477 } |
|
478 |
|
479 // -------------------------------------------------------------------------------------------- |
|
480 |
|
481 void CFileBrowserFileUtils::AppendToCommandArrayL(TInt aCommand, CCommandParamsBase* aParameters) |
|
482 { |
|
483 if (iCommandArray) |
|
484 iCommandArray->AppendL( TCommand(aCommand, aParameters) ); |
|
485 else |
|
486 User::Leave(KErrNotReady); |
|
487 } |
|
488 |
|
489 // -------------------------------------------------------------------------------------------- |
|
490 |
|
491 TInt CFileBrowserFileUtils::CommandArrayCount() const |
|
492 { |
|
493 TInt count(0); |
|
494 |
|
495 if (iCommandArray) |
|
496 count = iCommandArray->Count(); |
|
497 |
|
498 return count; |
|
499 } |
|
500 |
|
501 // -------------------------------------------------------------------------------------------- |
|
502 |
|
503 void CFileBrowserFileUtils::ResetCommandArray() |
|
504 { |
|
505 // delete params first |
|
506 for (TInt i=0; i<CommandArrayCount(); i++) |
|
507 { |
|
508 if ( iCommandArray->At(i).iParameters ) |
|
509 { |
|
510 delete iCommandArray->At(i).iParameters; |
|
511 iCommandArray->At(i).iParameters = NULL; |
|
512 } |
|
513 } |
|
514 |
|
515 // reset the entries |
|
516 iCommandArray->Reset(); |
|
517 } |
|
518 |
|
519 // -------------------------------------------------------------------------------------------- |
|
520 |
|
521 void CFileBrowserFileUtils::HandleSettingsChangeL() |
|
522 { |
|
523 // TODO |
|
524 |
|
525 // if (iEngine->FileListContainer()) |
|
526 // { |
|
527 // iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode); |
|
528 // iEngine->FileListContainer()->CreateListBoxL(iEngine->Settings().iFileViewMode); |
|
529 //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
530 RefreshViewL(); |
|
531 // } |
|
532 } |
|
533 |
|
534 // -------------------------------------------------------------------------------------------- |
|
535 |
|
536 void CFileBrowserFileUtils::SetSortModeL(TInt aSortMode) |
|
537 { |
|
538 iSortMode = aSortMode; |
|
539 RefreshViewL(); |
|
540 } |
|
541 |
|
542 // -------------------------------------------------------------------------------------------- |
|
543 |
|
544 void CFileBrowserFileUtils::SetOrderModeL(TInt aOrderMode) |
|
545 { |
|
546 iOrderMode = aOrderMode; |
|
547 RefreshViewL(); |
|
548 } |
|
549 |
|
550 // -------------------------------------------------------------------------------------------- |
|
551 |
|
552 TKeyResponse CFileBrowserFileUtils::HandleOfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
553 { |
|
554 // TODO |
|
555 /* |
|
556 if(aType != EEventKey) |
|
557 return EKeyWasNotConsumed; |
|
558 |
|
559 TBool shiftKeyPressed = (aKeyEvent.iModifiers & EModifierShift) || |
|
560 (aKeyEvent.iModifiers & EModifierLeftShift) || |
|
561 (aKeyEvent.iModifiers & EModifierRightShift); |
|
562 TBool controlKeyPressed = (aKeyEvent.iModifiers & EModifierCtrl) || |
|
563 (aKeyEvent.iModifiers & EModifierRightCtrl); |
|
564 |
|
565 // handle left arrow key press |
|
566 if (aKeyEvent.iCode == EKeyLeftArrow) |
|
567 { |
|
568 MoveUpOneLevelL(); |
|
569 return EKeyWasConsumed; |
|
570 } |
|
571 |
|
572 // handle right arrow key press |
|
573 else if (aKeyEvent.iCode == EKeyRightArrow) |
|
574 { |
|
575 if (IsDriveListViewActive() && iDriveEntryList->Count() > 0) |
|
576 { |
|
577 MoveDownToDirectoryL(); |
|
578 return EKeyWasConsumed; |
|
579 } |
|
580 else if (iFileEntryList->Count() > 0) |
|
581 { |
|
582 MoveDownToDirectoryL(); |
|
583 return EKeyWasConsumed; |
|
584 } |
|
585 } |
|
586 |
|
587 // skip OK/Enter keys when shift or ctrl is pressed because those are needed by the listbox |
|
588 else if ((aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) && (shiftKeyPressed || controlKeyPressed)) |
|
589 { |
|
590 return EKeyWasNotConsumed; |
|
591 } |
|
592 |
|
593 // handle OK/Enter keys |
|
594 else if (aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter) |
|
595 { |
|
596 if (IsDriveListViewActive() && iDriveEntryList->Count() > 0) |
|
597 { |
|
598 MoveDownToDirectoryL(); |
|
599 return EKeyWasConsumed; |
|
600 } |
|
601 else if (iFileEntryList->Count() > 0) |
|
602 { |
|
603 TFileEntry fileEntry = iFileEntryList->At(iEngine->FileListContainer()->CurrentListBoxItemIndex()); |
|
604 |
|
605 if (fileEntry.iEntry.IsDir()) |
|
606 MoveDownToDirectoryL(); |
|
607 else |
|
608 OpenCommonFileActionQueryL(); |
|
609 |
|
610 return EKeyWasConsumed; |
|
611 } |
|
612 } |
|
613 |
|
614 // handle Delete/Backspace keys |
|
615 else if (!iEngine->FileListContainer()->SearchField() && (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete) && |
|
616 !iEngine->FileUtils()->IsCurrentDriveReadOnly() && !iEngine->FileUtils()->IsDriveListViewActive()) |
|
617 { |
|
618 DeleteL(); |
|
619 return EKeyWasConsumed; |
|
620 } |
|
621 */ |
|
622 return EKeyWasNotConsumed; |
|
623 } |
|
624 // -------------------------------------------------------------------------------------------- |
|
625 |
|
626 void CFileBrowserFileUtils::RefreshViewL() |
|
627 { |
|
628 // if (iEngine->FileListContainer()) |
|
629 // { |
|
630 // |
|
631 // // make sure that the search field is disabled |
|
632 // iEngine->FileListContainer()->DisableSearchFieldL(); |
|
633 |
|
634 // read directory listing |
|
635 GenerateDirectoryDataL(); |
|
636 |
|
637 // // set an icon array |
|
638 // iEngine->FileListContainer()->SetListBoxIconArrayL(GenerateIconArrayL()); |
|
639 // |
|
640 // // set text items |
|
641 // iEngine->FileListContainer()->SetListBoxTextArrayL(GenerateItemTextArrayL()); |
|
642 // } |
|
643 } |
|
644 |
|
645 // -------------------------------------------------------------------------------------------- |
|
646 |
|
647 //CAknIconArray* CFileBrowserFileUtils::GenerateIconArrayL(TBool aGenerateNewBasicIconArray) |
|
648 // { |
|
649 // // TODO |
|
650 // |
|
651 // CAknIconArray* iconArray = NULL; |
|
652 // |
|
653 // if (aGenerateNewBasicIconArray) |
|
654 // { |
|
655 // iconArray = new(ELeave) CAknIconArray(16); |
|
656 // } |
|
657 // else |
|
658 // { |
|
659 // if (iEngine->FileListContainer()) |
|
660 // iconArray = iEngine->FileListContainer()->ListBoxIconArrayL(); |
|
661 // |
|
662 // if (!iconArray) |
|
663 // iconArray = new(ELeave) CAknIconArray(16); |
|
664 // } |
|
665 // |
|
666 // |
|
667 // CleanupStack::PushL(iconArray); |
|
668 // |
|
669 // // generate basic items if not already existing |
|
670 // if (iconArray->Count() < EFixedIconListLength) |
|
671 // { |
|
672 // // reset arrays |
|
673 // iconArray->Reset(); |
|
674 // iAppIconList->Reset(); |
|
675 // |
|
676 // // get default control color |
|
677 // TRgb defaultColor; |
|
678 // defaultColor = iEngine->EikonEnv()->Color(EColorControlText); |
|
679 // |
|
680 // // create a color icon of the marking indicator |
|
681 // CFbsBitmap* markBitmap = NULL; |
|
682 // CFbsBitmap* markBitmapMask = NULL; |
|
683 // |
|
684 // AknsUtils::CreateColorIconL(AknsUtils::SkinInstance(), |
|
685 // KAknsIIDQgnIndiMarkedAdd, |
|
686 // KAknsIIDQsnIconColors, |
|
687 // EAknsCIQsnIconColorsCG13, |
|
688 // markBitmap, |
|
689 // markBitmapMask, |
|
690 // AknIconUtils::AvkonIconFileName(), |
|
691 // EMbmAvkonQgn_indi_marked_add, |
|
692 // EMbmAvkonQgn_indi_marked_add_mask, |
|
693 // defaultColor |
|
694 // ); |
|
695 // |
|
696 // // 0 marking indicator |
|
697 // CGulIcon* markIcon = CGulIcon::NewL(markBitmap, markBitmapMask); |
|
698 // iconArray->AppendL(markIcon); |
|
699 // |
|
700 // // 1 empty |
|
701 // AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(), |
|
702 // EMbmAvkonQgn_prop_empty, EMbmAvkonQgn_prop_empty_mask, KAknsIIDQgnPropEmpty); |
|
703 // // 2 phone memory |
|
704 // AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(), |
|
705 // EMbmAvkonQgn_prop_phone_memc, EMbmAvkonQgn_prop_phone_memc_mask, KAknsIIDQgnPropPhoneMemc); |
|
706 // // 3 memory card |
|
707 // AppendGulIconToIconArrayL(iconArray, KMemoryCardUiBitmapFile, |
|
708 // EMbmAknmemorycarduiQgn_prop_mmc_memc, EMbmAknmemorycarduiQgn_prop_mmc_memc_mask, KAknsIIDQgnPropMmcMemc); |
|
709 // // 4 memory card disabled |
|
710 // AppendGulIconToIconArrayL(iconArray, KMemoryCardUiBitmapFile, |
|
711 // EMbmAknmemorycarduiQgn_prop_mmc_non, EMbmAknmemorycarduiQgn_prop_mmc_non_mask, KAknsIIDQgnPropMmcNon); |
|
712 // // 5 folder |
|
713 // AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(), |
|
714 // EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask, KAknsIIDQgnPropFolderSmall); |
|
715 // // 6 folder with subfolders |
|
716 // AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(), |
|
717 // EMbmAvkonQgn_prop_folder_sub_small, EMbmAvkonQgn_prop_folder_sub_small_mask, KAknsIIDQgnPropFolderSubSmall); |
|
718 // // 7 current folder |
|
719 // AppendGulIconToIconArrayL(iconArray, AknIconUtils::AvkonIconFileName(), |
|
720 // EMbmAvkonQgn_prop_folder_current, EMbmAvkonQgn_prop_folder_current_mask, KAknsIIDQgnPropFolderCurrent); |
|
721 // } |
|
722 // |
|
723 // // append custom icons if not in drive list view and setting is enabled |
|
724 // if (!aGenerateNewBasicIconArray && !IsDriveListViewActive() && iEngine->Settings().iShowAssociatedIcons) |
|
725 // { |
|
726 // // init id counter |
|
727 // TInt idCounter(EFixedIconListLength + iAppIconList->Count()); |
|
728 // |
|
729 // // loop all items in the file list |
|
730 // for (TInt i=0; i<iFileEntryList->Count(); i++) |
|
731 // { |
|
732 // TFileEntry& fileEntry = iFileEntryList->At(i); |
|
733 // |
|
734 // // just check for normal files |
|
735 // if (!fileEntry.iEntry.IsDir()) |
|
736 // { |
|
737 // TUid appUid = GetAppUid(fileEntry); |
|
738 // TInt iconId = AppIconIdForUid(appUid); |
|
739 // |
|
740 // if (appUid != KNullUid && iconId == KErrNotFound) |
|
741 // { |
|
742 // // icon not found from the icon array, generate it |
|
743 // CFbsBitmap* bitmap = NULL; |
|
744 // CFbsBitmap* mask = NULL; |
|
745 // CGulIcon* appIcon = NULL; |
|
746 // |
|
747 // TRAPD(err, |
|
748 // AknsUtils::CreateAppIconLC(AknsUtils::SkinInstance(), appUid, EAknsAppIconTypeList, bitmap, mask); |
|
749 // appIcon = CGulIcon::NewL(bitmap, mask); |
|
750 // CleanupStack::Pop(2); //bitmap, mask |
|
751 // ); |
|
752 // |
|
753 // if (err == KErrNone) |
|
754 // { |
|
755 // TAppIcon appIconEntry; |
|
756 // appIconEntry.iId = idCounter; |
|
757 // appIconEntry.iUid = appUid; |
|
758 // |
|
759 // appIcon->SetBitmapsOwnedExternally(EFalse); |
|
760 // iconArray->AppendL(appIcon); |
|
761 // iAppIconList->AppendL(appIconEntry); |
|
762 // |
|
763 // fileEntry.iIconId = idCounter; |
|
764 // |
|
765 // idCounter++; |
|
766 // } |
|
767 // else |
|
768 // { |
|
769 // delete bitmap; |
|
770 // delete mask; |
|
771 // |
|
772 // TAppIcon appIconEntry; |
|
773 // appIconEntry.iId = EFixedIconEmpty; |
|
774 // appIconEntry.iUid = appUid; |
|
775 // |
|
776 // iAppIconList->AppendL(appIconEntry); |
|
777 // } |
|
778 // } |
|
779 // |
|
780 // else if (appUid != KNullUid && iconId >= 0) |
|
781 // { |
|
782 // // we already have already generated an icon for this uid, use it |
|
783 // fileEntry.iIconId = iconId; |
|
784 // } |
|
785 // } |
|
786 // } |
|
787 // } |
|
788 // |
|
789 // CleanupStack::Pop(); //iconArray |
|
790 // return iconArray; |
|
791 // |
|
792 // } |
|
793 // |
|
794 // -------------------------------------------------------------------------------------------- |
|
795 |
|
796 //void CFileBrowserFileUtils::AppendGulIconToIconArrayL(CAknIconArray* aIconArray, const TDesC& aIconFile, TInt aIconId, TInt aMaskId, const TAknsItemID aAknsItemId) |
|
797 // { |
|
798 // CGulIcon* icon = AknsUtils::CreateGulIconL( |
|
799 // AknsUtils::SkinInstance(), |
|
800 // aAknsItemId, |
|
801 // aIconFile, |
|
802 // aIconId, |
|
803 // aMaskId); |
|
804 // CleanupStack::PushL(icon); |
|
805 // |
|
806 // icon->SetBitmapsOwnedExternally(EFalse); |
|
807 // aIconArray->AppendL(icon); |
|
808 // |
|
809 // CleanupStack::Pop(); //icon |
|
810 // } |
|
811 |
|
812 // -------------------------------------------------------------------------------------------- |
|
813 |
|
814 TInt CFileBrowserFileUtils::AppIconIdForUid(TUid aUid) |
|
815 { |
|
816 TInt result(KErrNotFound); |
|
817 |
|
818 for (TInt i=0; i<iAppIconList->Count(); i++) |
|
819 { |
|
820 if (iAppIconList->At(i).iUid == aUid) |
|
821 { |
|
822 result = iAppIconList->At(i).iId; |
|
823 break; |
|
824 } |
|
825 } |
|
826 |
|
827 return result; |
|
828 } |
|
829 |
|
830 // -------------------------------------------------------------------------------------------- |
|
831 |
|
832 TUid CFileBrowserFileUtils::GetAppUid(const TFileEntry &aFileEntry) |
|
833 { |
|
834 TFileName fullPath; |
|
835 fullPath.Copy(aFileEntry.iPath); |
|
836 fullPath.Append(aFileEntry.iEntry.iName); |
|
837 |
|
838 TParse parsedName; |
|
839 parsedName.Set(fullPath, NULL, NULL); |
|
840 |
|
841 // this will boost performance in \sys\bin folder |
|
842 if (parsedName.Ext().CompareF(_L(".dll")) == 0 || parsedName.Ext().CompareF(_L(".rsc")) == 0) |
|
843 return KNullUid; |
|
844 |
|
845 TInt err1(KErrNone), err2(KErrNone); |
|
846 TUid appUid; |
|
847 TDataType dataType; |
|
848 TBool isProgram; |
|
849 |
|
850 err1 = iEngine->LsSession().AppForDocument(fullPath, appUid, dataType); |
|
851 err2 = iEngine->LsSession().IsProgram(fullPath, isProgram); |
|
852 |
|
853 if (err1 == KErrNone && err2 == KErrNone) |
|
854 { |
|
855 if (isProgram) |
|
856 { |
|
857 // get the real app Uid from the app list |
|
858 TApaAppInfo appInfo; |
|
859 iEngine->LsSession().GetAllApps(); |
|
860 |
|
861 while (iEngine->LsSession().GetNextApp(appInfo) == KErrNone) |
|
862 { |
|
863 if (fullPath.CompareF(appInfo.iFullName) == 0) |
|
864 return appInfo.iUid; |
|
865 } |
|
866 } |
|
867 else |
|
868 { |
|
869 // return the app Uid associated for it |
|
870 return appUid; |
|
871 } |
|
872 } |
|
873 |
|
874 return KNullUid; |
|
875 } |
|
876 |
|
877 // -------------------------------------------------------------------------------------------- |
|
878 |
|
879 CFileEntryList* CFileBrowserFileUtils::FileEntries() const |
|
880 { |
|
881 return iFileEntryList; |
|
882 } |
|
883 |
|
884 // -------------------------------------------------------------------------------------------- |
|
885 |
|
886 CDriveEntryList* CFileBrowserFileUtils::DriveEntries() const |
|
887 { |
|
888 return iDriveEntryList; |
|
889 } |
|
890 |
|
891 // -------------------------------------------------------------------------------------------- |
|
892 |
|
893 TFileName CFileBrowserFileUtils::ResolveErrorMessage(TInt aErrCode) |
|
894 { |
|
895 TPtrC buf; |
|
896 CTextResolver* textResolver = CTextResolver::NewLC(*iEngine->EikonEnv()); |
|
897 buf.Set(textResolver->ResolveErrorString(aErrCode, CTextResolver::ECtxNoCtxNoSeparator)); |
|
898 |
|
899 TFileName errorMessage; |
|
900 errorMessage.Copy(buf); |
|
901 |
|
902 CleanupStack::PopAndDestroy(); //textResolver |
|
903 return errorMessage; |
|
904 } |
|
905 |
|
906 //// -------------------------------------------------------------------------------------------- |
|
907 // |
|
908 //CDesCArray* CFileBrowserFileUtils::GenerateItemTextArrayL() |
|
909 // { |
|
910 // iTextArray = new(ELeave) CDesCArrayFlat(64); |
|
911 //// CleanupStack::PushL(textArray); |
|
912 // |
|
913 // if (IsDriveListViewActive()) |
|
914 // { |
|
915 // _LIT(KSimpleDriveEntry, "%d\t%c: <%S>\t\t"); |
|
916 // _LIT(KExtendedDriveEntry, "%d\t%c: <%S>\t%LD / %LD kB\t"); |
|
917 // |
|
918 // for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
919 // { |
|
920 // TFileName textEntry; |
|
921 // TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
922 // |
|
923 // if (iEngine->Settings().iFileViewMode == EFileViewModeSimple) |
|
924 // { |
|
925 // textEntry.Format(KSimpleDriveEntry, driveEntry.iIconId, TUint(driveEntry.iLetter), &driveEntry.iMediaTypeDesc); |
|
926 // } |
|
927 // else if (iEngine->Settings().iFileViewMode == EFileViewModeExtended) |
|
928 // { |
|
929 // textEntry.Format(KExtendedDriveEntry, driveEntry.iIconId, TUint(driveEntry.iLetter), &driveEntry.iMediaTypeDesc, driveEntry.iVolumeInfo.iFree/1024, driveEntry.iVolumeInfo.iSize/1024); |
|
930 // } |
|
931 // |
|
932 // iTextArray->AppendL(textEntry); |
|
933 // } |
|
934 // } |
|
935 // |
|
936 // else |
|
937 // { |
|
938 // _LIT(KSimpleFileEntry, "%d\t%S\t\t"); |
|
939 // _LIT(KExtendedFileEntry, "%d\t%S\t%S\t"); |
|
940 // |
|
941 // for (TInt i=0; i<iFileEntryList->Count(); i++) |
|
942 // { |
|
943 // TFileName textEntry; |
|
944 // TFileEntry fileEntry = iFileEntryList->At(i); |
|
945 // |
|
946 // // format text line entries |
|
947 // if (iEngine->Settings().iFileViewMode == EFileViewModeSimple) |
|
948 // { |
|
949 // textEntry.Format(KSimpleFileEntry, fileEntry.iIconId, &fileEntry.iEntry.iName); |
|
950 // } |
|
951 // else if (iEngine->Settings().iFileViewMode == EFileViewModeExtended) |
|
952 // { |
|
953 // TBuf<128> extraData; |
|
954 // |
|
955 // // append entry date |
|
956 // TTime entryModified = fileEntry.iEntry.iModified; |
|
957 // if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone ) |
|
958 // { |
|
959 // entryModified = fileEntry.iEntry.iModified; |
|
960 // } |
|
961 // |
|
962 // _LIT(KCurrentDate,"%D%M%*Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
963 // entryModified.FormatL(extraData, KCurrentDate); |
|
964 // |
|
965 // // for a directory append number of entries and for a file the file size |
|
966 // if (fileEntry.iEntry.IsDir() && fileEntry.iDirEntries >= 0) |
|
967 // { |
|
968 // extraData.Append(_L(" - ")); |
|
969 // extraData.AppendNum(fileEntry.iDirEntries); |
|
970 // |
|
971 // if (fileEntry.iDirEntries == 1) |
|
972 // extraData.Append(_L(" entry")); |
|
973 // else |
|
974 // extraData.Append(_L(" entries")); |
|
975 // } |
|
976 // |
|
977 // // normal file entry |
|
978 // else if (!fileEntry.iEntry.IsDir()) |
|
979 // { |
|
980 // extraData.Append(_L(" - ")); |
|
981 // |
|
982 // if (fileEntry.iEntry.iSize < 1024) |
|
983 // { |
|
984 // extraData.AppendNum(fileEntry.iEntry.iSize); |
|
985 // extraData.Append(_L(" B")); |
|
986 // } |
|
987 // else if (fileEntry.iEntry.iSize < 1024*1024) |
|
988 // { |
|
989 // TReal sizeKB = (TReal)fileEntry.iEntry.iSize / 1024; |
|
990 // extraData.AppendNum(sizeKB, TRealFormat(KDefaultRealWidth, 1)); |
|
991 // extraData.Append(_L(" kB")); |
|
992 // } |
|
993 // else |
|
994 // { |
|
995 // TReal sizeMB = (TReal)fileEntry.iEntry.iSize / (1024*1024); |
|
996 // extraData.AppendNum(sizeMB, TRealFormat(KDefaultRealWidth, 1)); |
|
997 // extraData.Append(_L(" MB")); |
|
998 // } |
|
999 // } |
|
1000 // |
|
1001 // // append attribute flags if any |
|
1002 // TBuf<4> atts; |
|
1003 // if (fileEntry.iEntry.IsArchive()) |
|
1004 // atts.Append(_L("A")); |
|
1005 // if (fileEntry.iEntry.IsHidden()) |
|
1006 // atts.Append(_L("H")); |
|
1007 // if (fileEntry.iEntry.IsReadOnly()) |
|
1008 // atts.Append(_L("R")); |
|
1009 // if (fileEntry.iEntry.IsSystem()) |
|
1010 // atts.Append(_L("S")); |
|
1011 // |
|
1012 // if (atts.Length() > 0) |
|
1013 // { |
|
1014 // extraData.Append(_L(" - [")); |
|
1015 // extraData.Append(atts); |
|
1016 // extraData.Append(_L("]")); |
|
1017 // } |
|
1018 // |
|
1019 // // format |
|
1020 // textEntry.Format(KExtendedFileEntry, fileEntry.iIconId, &fileEntry.iEntry.iName, &extraData); |
|
1021 // } |
|
1022 // |
|
1023 // iTextArray->AppendL(textEntry); |
|
1024 // } |
|
1025 // } |
|
1026 // |
|
1027 //// CleanupStack::Pop(); //textArray |
|
1028 // return iTextArray; |
|
1029 // } |
|
1030 |
|
1031 // -------------------------------------------------------------------------------------------- |
|
1032 |
|
1033 void CFileBrowserFileUtils::GenerateDirectoryDataL() |
|
1034 { |
|
1035 if (iListingMode == ENormalEntries) |
|
1036 { |
|
1037 if (IsDriveListViewActive()) |
|
1038 GetDriveListL(); |
|
1039 else |
|
1040 GetDirectoryListingL(); |
|
1041 } |
|
1042 } |
|
1043 |
|
1044 // -------------------------------------------------------------------------------------------- |
|
1045 |
|
1046 void CFileBrowserFileUtils::GetDriveListL() |
|
1047 { |
|
1048 TDriveList driveList; |
|
1049 |
|
1050 // get drive listing depending of the support for network drives |
|
1051 if (iEngine->Settings().iSupportNetworkDrives) |
|
1052 { |
|
1053 #ifndef __SERIES60_30__ |
|
1054 #ifndef __SERIES60_31__ |
|
1055 User::LeaveIfError(iFs.DriveList(driveList, KDriveAttAll)); |
|
1056 #endif |
|
1057 #else |
|
1058 User::LeaveIfError(iFs.DriveList(driveList)); |
|
1059 #endif |
|
1060 } |
|
1061 else |
|
1062 { |
|
1063 User::LeaveIfError(iFs.DriveList(driveList)); |
|
1064 } |
|
1065 |
|
1066 iDriveEntryList->Reset(); |
|
1067 |
|
1068 for (TInt i=0; i<KMaxDrives; i++) |
|
1069 { |
|
1070 if (driveList[i]) |
|
1071 { |
|
1072 TDriveEntry driveEntry; |
|
1073 |
|
1074 // set default icon |
|
1075 driveEntry.iIconId = EFixedIconPhoneMemory; |
|
1076 |
|
1077 // get drive letter and number |
|
1078 driveEntry.iLetter = 'A' + i; |
|
1079 iFs.CharToDrive(driveEntry.iLetter, driveEntry.iNumber); |
|
1080 |
|
1081 // get volume info and check errors |
|
1082 if (iFs.Volume(driveEntry.iVolumeInfo, driveEntry.iNumber) == KErrNone) |
|
1083 { |
|
1084 // set media type descriptor |
|
1085 TInt mediaType = driveEntry.iVolumeInfo.iDrive.iType; |
|
1086 TBool extMountable( EFalse ); |
|
1087 |
|
1088 if (mediaType == EMediaNotPresent) |
|
1089 driveEntry.iMediaTypeDesc = _L("Not present"); |
|
1090 else if (mediaType ==EMediaUnknown ) |
|
1091 driveEntry.iMediaTypeDesc = _L("Unknown"); |
|
1092 else if (mediaType ==EMediaFloppy ) |
|
1093 driveEntry.iMediaTypeDesc = _L("Floppy"); |
|
1094 else if (mediaType == EMediaHardDisk) |
|
1095 driveEntry.iMediaTypeDesc = _L("Mass storage"); |
|
1096 else if (mediaType == EMediaCdRom) |
|
1097 driveEntry.iMediaTypeDesc = _L("CD-ROM"); |
|
1098 else if (mediaType == EMediaRam) |
|
1099 driveEntry.iMediaTypeDesc = _L("RAM"); |
|
1100 else if (mediaType == EMediaFlash) |
|
1101 driveEntry.iMediaTypeDesc = _L("Flash"); |
|
1102 else if (mediaType == EMediaRom) |
|
1103 driveEntry.iMediaTypeDesc = _L("ROM"); |
|
1104 else if (mediaType == EMediaRemote) |
|
1105 driveEntry.iMediaTypeDesc = _L("Remote"); |
|
1106 else if (mediaType == EMediaNANDFlash) |
|
1107 driveEntry.iMediaTypeDesc = _L("NAND flash"); |
|
1108 |
|
1109 // get real size of the ROM drive |
|
1110 if (mediaType == EMediaRom) |
|
1111 { |
|
1112 TMemoryInfoV1Buf ramMemory; |
|
1113 UserHal::MemoryInfo(ramMemory); |
|
1114 driveEntry.iVolumeInfo.iSize = ramMemory().iTotalRomInBytes; |
|
1115 } |
|
1116 |
|
1117 // set attribute descripitions |
|
1118 if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatNotSupported) |
|
1119 driveEntry.iAttributesDesc.Append(_L("Battery not supported")); |
|
1120 else if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatGood) |
|
1121 driveEntry.iAttributesDesc.Append(_L("Battery good")); |
|
1122 else if (driveEntry.iVolumeInfo.iDrive.iBattery == EBatLow) |
|
1123 driveEntry.iAttributesDesc.Append(_L("Battery low")); |
|
1124 else |
|
1125 driveEntry.iAttributesDesc.Append(_L("Battery state unknown")); |
|
1126 |
|
1127 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttLocal) |
|
1128 driveEntry.iAttributesDesc.Append(_L(" + Local")); |
|
1129 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRom) |
|
1130 driveEntry.iAttributesDesc.Append(_L(" + ROM")); |
|
1131 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRedirected) |
|
1132 driveEntry.iAttributesDesc.Append(_L("+ Redirected")); |
|
1133 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttSubsted) |
|
1134 driveEntry.iAttributesDesc.Append(_L(" + Substed")); |
|
1135 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttInternal) |
|
1136 driveEntry.iAttributesDesc.Append(_L(" + Internal")); |
|
1137 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable) |
|
1138 { |
|
1139 driveEntry.iAttributesDesc.Append(_L(" + Removable")); |
|
1140 #if (!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
1141 TUint drvStatus( 0 ); |
|
1142 if ( !DriveInfo::GetDriveStatus( iFs, driveEntry.iNumber, drvStatus ) && |
|
1143 drvStatus & DriveInfo::EDriveExternallyMountable && |
|
1144 drvStatus & DriveInfo::EDriveInternal ) |
|
1145 { |
|
1146 extMountable = ETrue; |
|
1147 // iMediaTypeDesc already set as "Mass storage" |
|
1148 } |
|
1149 else |
|
1150 { |
|
1151 driveEntry.iMediaTypeDesc = _L("Memory card"); |
|
1152 } |
|
1153 #else |
|
1154 driveEntry.iMediaTypeDesc = _L("Memory card"); |
|
1155 #endif |
|
1156 } |
|
1157 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemote) |
|
1158 driveEntry.iAttributesDesc.Append(_L(" + Remote")); |
|
1159 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttTransaction) |
|
1160 driveEntry.iAttributesDesc.Append(_L(" + Transaction")); |
|
1161 |
|
1162 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttVariableSize) |
|
1163 driveEntry.iAttributesDesc.Append(_L(" + Variable size")); |
|
1164 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttDualDensity) |
|
1165 driveEntry.iAttributesDesc.Append(_L(" + Dual density")); |
|
1166 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttFormattable) |
|
1167 driveEntry.iAttributesDesc.Append(_L(" + Formattable")); |
|
1168 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected) |
|
1169 driveEntry.iAttributesDesc.Append(_L(" + Write protected")); |
|
1170 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLockable) |
|
1171 driveEntry.iAttributesDesc.Append(_L(" + Lockable")); |
|
1172 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked) |
|
1173 driveEntry.iAttributesDesc.Append(_L(" + Locked")); |
|
1174 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttHasPassword) |
|
1175 driveEntry.iAttributesDesc.Append(_L(" + Has password")); |
|
1176 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttReadWhileWrite) |
|
1177 driveEntry.iAttributesDesc.Append(_L(" + Read while write")); |
|
1178 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttDeleteNotify) |
|
1179 driveEntry.iAttributesDesc.Append(_L(" + Supports DeleteNotify")); |
|
1180 |
|
1181 |
|
1182 // mark a removable media with memory card icon |
|
1183 if (driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAttRemovable && !extMountable) |
|
1184 { |
|
1185 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAbsent) |
|
1186 { |
|
1187 driveEntry.iIconId = EFixedIconMemoryCardDisabled; |
|
1188 } |
|
1189 else |
|
1190 { |
|
1191 driveEntry.iIconId = EFixedIconMemoryCard; |
|
1192 } |
|
1193 } |
|
1194 } |
|
1195 |
|
1196 // if this fails, likely it's a memory card which is not present |
|
1197 else |
|
1198 { |
|
1199 TVolumeInfo volumeInfo; |
|
1200 volumeInfo.iSize = 0; |
|
1201 volumeInfo.iFree = 0; |
|
1202 volumeInfo.iDrive.iDriveAtt = KDriveAttRemovable; |
|
1203 volumeInfo.iDrive.iMediaAtt = KMediaAttWriteProtected; |
|
1204 driveEntry.iVolumeInfo = volumeInfo; |
|
1205 |
|
1206 driveEntry.iMediaTypeDesc = _L("Not ready"); |
|
1207 driveEntry.iIconId = EFixedIconMemoryCardDisabled; |
|
1208 } |
|
1209 |
|
1210 if ( iPrevFolderName != KNullDesC && iPrevFolderName[0] == driveEntry.iLetter ) |
|
1211 { |
|
1212 iPrevFolderIndex = iDriveEntryList->Count(); |
|
1213 } |
|
1214 |
|
1215 iDriveEntryList->AppendL(driveEntry); |
|
1216 } |
|
1217 } |
|
1218 |
|
1219 } |
|
1220 |
|
1221 // -------------------------------------------------------------------------------------------- |
|
1222 |
|
1223 void CFileBrowserFileUtils::GetDirectoryListingL() |
|
1224 { |
|
1225 iFileEntryList->Reset(); |
|
1226 |
|
1227 TInt sortMode(ESortByName); |
|
1228 if (iSortMode == EFileBrowserCmdViewSortByExtension) |
|
1229 sortMode = ESortByExt; |
|
1230 else if (iSortMode == EFileBrowserCmdViewSortBySize) |
|
1231 sortMode = ESortBySize; |
|
1232 else if (iSortMode == EFileBrowserCmdViewSortByDate) |
|
1233 sortMode = ESortByDate; |
|
1234 |
|
1235 TInt orderMode(EAscending); |
|
1236 if (iOrderMode == EFileBrowserCmdViewOrderDescending) |
|
1237 orderMode = EDescending; |
|
1238 |
|
1239 CDir* dir = NULL; |
|
1240 if (iFs.GetDir(iCurrentPath, KEntryAttMatchMask, sortMode | orderMode | EDirsFirst, dir) == KErrNone) |
|
1241 { |
|
1242 CleanupStack::PushL(dir); |
|
1243 |
|
1244 for (TInt i=0; i<dir->Count(); i++) |
|
1245 { |
|
1246 TFileEntry fileEntry; |
|
1247 fileEntry.iPath = iCurrentPath; |
|
1248 fileEntry.iEntry = (*dir)[i]; |
|
1249 fileEntry.iDirEntries = KErrNotFound; |
|
1250 fileEntry.iIconId = EFixedIconEmpty; |
|
1251 |
|
1252 if ( iPrevFolderName != KNullDesC && iPrevFolderName == fileEntry.iEntry.iName ) |
|
1253 { |
|
1254 iPrevFolderIndex = i; |
|
1255 } |
|
1256 |
|
1257 // check for directory entries |
|
1258 if (fileEntry.iEntry.IsDir()) |
|
1259 { |
|
1260 fileEntry.iIconId = EFixedIconFolder; |
|
1261 |
|
1262 TFileName subPath = fileEntry.iPath; |
|
1263 subPath.Append(fileEntry.iEntry.iName); |
|
1264 subPath.Append(_L("\\")); |
|
1265 |
|
1266 // get number of entries in this directory if extended info about sub directories enabled |
|
1267 if (iEngine->Settings().iShowSubDirectoryInfo && iEngine->Settings().iFileViewMode == EFileViewModeExtended) |
|
1268 { |
|
1269 CDir* subDir = NULL; |
|
1270 if (iFs.GetDir(subPath, KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone) |
|
1271 { |
|
1272 fileEntry.iDirEntries = subDir->Count(); |
|
1273 delete subDir; |
|
1274 } |
|
1275 } |
|
1276 |
|
1277 // apply subfolder icon for known directories (speed improvement) |
|
1278 if (subPath[0]=='Z' && (subPath.CompareF(_L("Z:\\data\\"))==0 || subPath.CompareF(_L("Z:\\Nokia\\"))==0 |
|
1279 || subPath.Compare(_L("Z:\\private\\"))==0 || subPath.Compare(_L("Z:\\resource\\"))==0 |
|
1280 || subPath.Compare(_L("Z:\\sys\\"))==0 || subPath.Compare(_L("Z:\\system\\"))==0)) |
|
1281 { |
|
1282 fileEntry.iIconId = EFixedIconFolderSub; |
|
1283 } |
|
1284 else if (subPath[0]=='Z' && (subPath.CompareF(_L("Z:\\sys\\bin\\"))==0)) |
|
1285 { |
|
1286 // normal folder icon for these ones |
|
1287 fileEntry.iIconId = EFixedIconFolder; |
|
1288 } |
|
1289 else |
|
1290 { |
|
1291 // check if this folder has subdirectories |
|
1292 CDir* subDir = NULL; |
|
1293 if (iFs.GetDir(subPath, KEntryAttDir|KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone) |
|
1294 { |
|
1295 for (TInt j=0; j<subDir->Count(); j++) |
|
1296 { |
|
1297 TEntry entry = (*subDir)[j]; |
|
1298 |
|
1299 if (entry.IsDir()) |
|
1300 { |
|
1301 fileEntry.iIconId = EFixedIconFolderSub; |
|
1302 break; |
|
1303 } |
|
1304 } |
|
1305 |
|
1306 delete subDir; |
|
1307 } |
|
1308 } |
|
1309 } |
|
1310 |
|
1311 iFileEntryList->AppendL(fileEntry); |
|
1312 } |
|
1313 |
|
1314 CleanupStack::PopAndDestroy(); //dir |
|
1315 } |
|
1316 } |
|
1317 |
|
1318 // -------------------------------------------------------------------------------------------- |
|
1319 |
|
1320 void CFileBrowserFileUtils::MoveUpOneLevelL() |
|
1321 { |
|
1322 iPrevFolderIndex = KErrNotFound; |
|
1323 iPrevFolderName.Zero(); |
|
1324 |
|
1325 // change back to normal mode or move up |
|
1326 if (iListingMode != ENormalEntries) |
|
1327 { |
|
1328 iListingMode = ENormalEntries; |
|
1329 } |
|
1330 else |
|
1331 { |
|
1332 // do nothing if displaying drive list view |
|
1333 if (IsDriveListViewActive()) |
|
1334 return; |
|
1335 |
|
1336 if (iCurrentPath.Length() <= KDriveLetterStringLength) |
|
1337 { |
|
1338 if ( iCurrentPath.Length() > 0 ) |
|
1339 { |
|
1340 iPrevFolderName.Append( iCurrentPath[0] ); |
|
1341 } |
|
1342 // move to drive list view if the current path is already short enough |
|
1343 iCurrentPath = KNullDesC; |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 // move one directory up |
|
1348 TInt marker(iCurrentPath.Length()); |
|
1349 |
|
1350 // find second last dir marker |
|
1351 for (TInt i=iCurrentPath.Length()-2; i>=0; i--) |
|
1352 { |
|
1353 if (iCurrentPath[i] == '\\') |
|
1354 { |
|
1355 marker = i; |
|
1356 break; |
|
1357 } |
|
1358 |
|
1359 } |
|
1360 |
|
1361 // update iPrevDir with the directory name that we just left |
|
1362 iPrevFolderName.Copy( iCurrentPath.RightTPtr( iCurrentPath.Length() - marker - 1 ) ); |
|
1363 iPrevFolderName.Delete( iPrevFolderName.Length() -1, 2 ); // remove extra '\\' |
|
1364 |
|
1365 iCurrentPath = iCurrentPath.LeftTPtr(marker+1); |
|
1366 } |
|
1367 } |
|
1368 |
|
1369 // if (iEngine->FileListContainer()) |
|
1370 // { |
|
1371 //iEngine->FileListContainer()->DisableSearchFieldL(); |
|
1372 //iEngine->FileListContainer()->ListBox()->ClearSelection(); |
|
1373 //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0); |
|
1374 //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
1375 // } |
|
1376 |
|
1377 // update view |
|
1378 RefreshViewL(); |
|
1379 |
|
1380 if (iEngine->Settings().iRememberFolderSelection |
|
1381 //&& iEngine->FileListContainer() |
|
1382 && iPrevFolderIndex > KErrNotFound ) |
|
1383 { |
|
1384 |
|
1385 // TInt visibleItems = iEngine->FileListContainer()->ListBox()->Rect().Height() / |
|
1386 // iEngine->FileListContainer()->ListBox()->ItemHeight() |
|
1387 // - 1; // for the title row |
|
1388 // |
|
1389 // // By default, the selected item would be the last visible item on the listbox. |
|
1390 // // We want the selected item be displayed at the middle of the listbox, so we |
|
1391 // // select one of the successor items first to scroll down a bit |
|
1392 // iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex( |
|
1393 // Min( iEngine->FileListContainer()->ListBox()->Model()->ItemTextArray()->MdcaCount() -1, |
|
1394 // iPrevFolderIndex + visibleItems / 2 ) ); |
|
1395 // |
|
1396 // // ...and after that we select the the correct item. |
|
1397 // iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex( iPrevFolderIndex ); |
|
1398 |
|
1399 // update view |
|
1400 RefreshViewL(); |
|
1401 } |
|
1402 } |
|
1403 |
|
1404 // -------------------------------------------------------------------------------------------- |
|
1405 |
|
1406 void CFileBrowserFileUtils::MoveDownToDirectoryL(TInt aIndex) |
|
1407 { |
|
1408 |
|
1409 // change back to normal mode |
|
1410 if (iListingMode != ENormalEntries) |
|
1411 { |
|
1412 iListingMode = ENormalEntries; |
|
1413 } |
|
1414 |
|
1415 if (aIndex >= 0) |
|
1416 { |
|
1417 TBool needsRefresh(EFalse); |
|
1418 |
|
1419 if (IsDriveListViewActive()) |
|
1420 { |
|
1421 // currently in a drive list view, move to root of selected drive |
|
1422 if (iDriveEntryList->Count() > aIndex) |
|
1423 { |
|
1424 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
1425 |
|
1426 iCurrentPath.Append(driveEntry.iLetter); |
|
1427 iCurrentPath.Append(_L(":\\")); |
|
1428 |
|
1429 needsRefresh = ETrue; |
|
1430 } |
|
1431 } |
|
1432 else |
|
1433 { |
|
1434 // otherwise just append the new directory |
|
1435 if (iFileEntryList->Count() > aIndex) |
|
1436 { |
|
1437 TFileEntry fileEntry = iFileEntryList->At(aIndex); |
|
1438 |
|
1439 if (fileEntry.iEntry.IsDir()) |
|
1440 { |
|
1441 iCurrentPath.Copy(fileEntry.iPath); |
|
1442 iCurrentPath.Append(fileEntry.iEntry.iName); |
|
1443 iCurrentPath.Append(_L("\\")); |
|
1444 |
|
1445 needsRefresh = ETrue; |
|
1446 } |
|
1447 } |
|
1448 } |
|
1449 |
|
1450 if (needsRefresh /*&& iEngine->FileListContainer()*/) |
|
1451 { |
|
1452 //iEngine->FileListContainer()->DisableSearchFieldL(); |
|
1453 //iEngine->FileListContainer()->ListBox()->ClearSelection(); |
|
1454 //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0); |
|
1455 //iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
1456 |
|
1457 // update view |
|
1458 RefreshViewL(); |
|
1459 } |
|
1460 } |
|
1461 } |
|
1462 |
|
1463 // -------------------------------------------------------------------------------------------- |
|
1464 |
|
1465 TBool CFileBrowserFileUtils::IsCurrentDriveReadOnly() |
|
1466 { |
|
1467 if (iListingMode !=ENormalEntries || iCurrentPath.Length() < 2) |
|
1468 return EFalse; |
|
1469 else |
|
1470 { |
|
1471 for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
1472 { |
|
1473 TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
1474 |
|
1475 if (driveEntry.iLetter == iCurrentPath[0]) |
|
1476 { |
|
1477 if (driveEntry.iVolumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected || driveEntry.iVolumeInfo.iDrive.iMediaAtt == KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt == KDriveAbsent) |
|
1478 return ETrue; |
|
1479 else |
|
1480 return EFalse; |
|
1481 } |
|
1482 } |
|
1483 } |
|
1484 |
|
1485 return EFalse; |
|
1486 } |
|
1487 |
|
1488 // -------------------------------------------------------------------------------------------- |
|
1489 |
|
1490 TBool CFileBrowserFileUtils::IsItemDirectory(TInt aCurrentItemIndex) |
|
1491 { |
|
1492 if (aCurrentItemIndex < 0) |
|
1493 { |
|
1494 return EFalse; |
|
1495 } |
|
1496 else |
|
1497 { |
|
1498 if (iFileEntryList->Count() > aCurrentItemIndex) |
|
1499 { |
|
1500 TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex) ; |
|
1501 return fileEntry.iEntry.IsDir(); |
|
1502 } |
|
1503 else |
|
1504 { |
|
1505 return EFalse; |
|
1506 } |
|
1507 } |
|
1508 } |
|
1509 |
|
1510 // -------------------------------------------------------------------------------------------- |
|
1511 |
|
1512 TInt CFileBrowserFileUtils::SetSelectedItemsOrCurrentItemL(const CArrayFix<TInt>* selectionIndexes, |
|
1513 CFileEntryList* aFileEntryList) |
|
1514 { |
|
1515 aFileEntryList->Reset(); |
|
1516 |
|
1517 // by default use selected items |
|
1518 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
1519 { |
|
1520 TInt ref(0); |
|
1521 TKeyArrayFix key(0, ECmpTUint16); |
|
1522 TInt index(0); |
|
1523 |
|
1524 for (TInt i=0; i<iFileEntryList->Count(); i++) |
|
1525 { |
|
1526 ref = i; |
|
1527 |
|
1528 if (selectionIndexes->Find(ref, key, index) == 0) |
|
1529 { |
|
1530 aFileEntryList->AppendL(iFileEntryList->At(i)); |
|
1531 } |
|
1532 } |
|
1533 } |
|
1534 return aFileEntryList->Count(); |
|
1535 } |
|
1536 |
|
1537 // -------------------------------------------------------------------------------------------- |
|
1538 |
|
1539 TInt CFileBrowserFileUtils::ClipboardCutL(const CArrayFix<TInt>* aSelectionIndices) |
|
1540 { |
|
1541 |
|
1542 iClipBoardMode = EClipBoardModeCut; |
|
1543 TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iClipBoardList); |
|
1544 return operations; |
|
1545 } |
|
1546 |
|
1547 // -------------------------------------------------------------------------------------------- |
|
1548 |
|
1549 TInt CFileBrowserFileUtils::ClipboardCopyL(const CArrayFix<TInt>* aSelectionIndices) |
|
1550 { |
|
1551 iClipBoardMode = EClipBoardModeCopy; |
|
1552 TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iClipBoardList); |
|
1553 return operations; |
|
1554 } |
|
1555 |
|
1556 // -------------------------------------------------------------------------------------------- |
|
1557 |
|
1558 void CFileBrowserFileUtils::ClipboardPasteL(const TOverwriteOptions &aOverwriteOptions) |
|
1559 { |
|
1560 if (iClipBoardMode == EClipBoardModeCut) |
|
1561 { |
|
1562 DoCopyToFolderL(iClipBoardList, iCurrentPath, aOverwriteOptions, ETrue ); |
|
1563 iClipBoardList->Reset(); |
|
1564 } |
|
1565 else if (iClipBoardMode == EClipBoardModeCopy) |
|
1566 { |
|
1567 DoCopyToFolderL(iClipBoardList, iCurrentPath, aOverwriteOptions, EFalse); |
|
1568 } |
|
1569 } |
|
1570 |
|
1571 // -------------------------------------------------------------------------------------------- |
|
1572 |
|
1573 TInt CFileBrowserFileUtils::SetCurrentSelection(const CArrayFix<TInt>* aSelectionIndices) |
|
1574 { |
|
1575 TInt operations = SetSelectedItemsOrCurrentItemL(aSelectionIndices, iCurrentSelectionList); |
|
1576 return operations; |
|
1577 } |
|
1578 |
|
1579 // -------------------------------------------------------------------------------------------- |
|
1580 |
|
1581 void CFileBrowserFileUtils::CopyToFolderL(const TFileName &aTargetDir, |
|
1582 const TOverwriteOptions &aOverwriteOptions, |
|
1583 TBool aMove) |
|
1584 { |
|
1585 |
|
1586 // TFileName destinationFolder; |
|
1587 |
|
1588 // generate an icon array |
|
1589 // CAknIconArray* iconArray = GenerateIconArrayL(ETrue); |
|
1590 // CleanupStack::PushL(iconArray); |
|
1591 |
|
1592 // run folder selection dialog |
|
1593 // CFileBrowserDestinationFolderSelectionDlg* dlg = CFileBrowserDestinationFolderSelectionDlg::NewL(destinationFolder, iDriveEntryList, iconArray); |
|
1594 |
|
1595 // do the file operations |
|
1596 //DoCopyToFolderL(entryList, aTargetDir, aOverwriteOptions, aMove); |
|
1597 DoCopyToFolderL(iCurrentSelectionList, aTargetDir, aOverwriteOptions, aMove); |
|
1598 |
|
1599 // CleanupStack::Pop(); //iconArray |
|
1600 } |
|
1601 |
|
1602 // -------------------------------------------------------------------------------------------- |
|
1603 |
|
1604 TBool CFileBrowserFileUtils::IsDestinationEntriesExists(const TDesC& aTargetDir) |
|
1605 { |
|
1606 TBool someEntryExists(EFalse); |
|
1607 if (iCurrentSelectionList && iCurrentSelectionList->Count() > 0) |
|
1608 { |
|
1609 // check if some destination entries also exists |
|
1610 for (TInt i=0; i<iCurrentSelectionList->Count(); i++) |
|
1611 { |
|
1612 TFileEntry fileEntry = iCurrentSelectionList->At(i); |
|
1613 |
|
1614 TFileName targetEntry = aTargetDir; |
|
1615 targetEntry.Append(fileEntry.iEntry.iName); |
|
1616 |
|
1617 if (fileEntry.iEntry.IsDir()) |
|
1618 { |
|
1619 targetEntry.Append(_L("\\")); |
|
1620 |
|
1621 if (BaflUtils::PathExists(iFs, targetEntry)) |
|
1622 { |
|
1623 someEntryExists = ETrue; |
|
1624 break; |
|
1625 } |
|
1626 } |
|
1627 else |
|
1628 { |
|
1629 if (BaflUtils::FileExists(iFs, targetEntry)) |
|
1630 { |
|
1631 someEntryExists = ETrue; |
|
1632 break; |
|
1633 } |
|
1634 } |
|
1635 } |
|
1636 } |
|
1637 return someEntryExists; |
|
1638 } |
|
1639 |
|
1640 // -------------------------------------------------------------------------------------------- |
|
1641 |
|
1642 void CFileBrowserFileUtils::DoCopyToFolderL(CFileEntryList* aEntryList, |
|
1643 const TDesC& aTargetDir, |
|
1644 const TOverwriteOptions &aOverwriteOptions, |
|
1645 TBool aDeleteSource) |
|
1646 { |
|
1647 if (aEntryList && aEntryList->Count() > 0) |
|
1648 { |
|
1649 if (aOverwriteOptions.iDoFileOperations) |
|
1650 { |
|
1651 // set correct command id depending if we are copying or moving |
|
1652 TInt commandId(EFileBrowserFileOpCommandCopy); |
|
1653 if (aDeleteSource) |
|
1654 commandId = EFileBrowserFileOpCommandMove; |
|
1655 |
|
1656 // do the file operations for each entry |
|
1657 for (TInt i=0; i<aEntryList->Count(); i++) |
|
1658 { |
|
1659 TFileEntry fileEntry = aEntryList->At(i); |
|
1660 |
|
1661 TFileName targetEntry = aTargetDir; |
|
1662 targetEntry.Append(fileEntry.iEntry.iName); |
|
1663 |
|
1664 if (aOverwriteOptions.iQueryIndex == EFileActionGenerateUniqueFilenames) |
|
1665 { |
|
1666 CApaApplication::GenerateFileName(iFs, targetEntry); |
|
1667 } |
|
1668 else if (aOverwriteOptions.iQueryIndex == EFileActionQueryPostFix) |
|
1669 { |
|
1670 targetEntry.Append(aOverwriteOptions.iPostFix); |
|
1671 } |
|
1672 |
|
1673 |
|
1674 // append the new command to the command array |
|
1675 if (fileEntry.iEntry.IsDir()) |
|
1676 { |
|
1677 AppendToCommandArrayL(commandId, |
|
1678 new(ELeave)CCommandParamsCopyOrMove(fileEntry, targetEntry, aOverwriteOptions.iOverWriteFlags|CFileMan::ERecurse) |
|
1679 ); |
|
1680 } |
|
1681 else |
|
1682 { |
|
1683 AppendToCommandArrayL(commandId, |
|
1684 new(ELeave)CCommandParamsCopyOrMove(fileEntry, targetEntry, aOverwriteOptions.iOverWriteFlags) |
|
1685 ); |
|
1686 } |
|
1687 |
|
1688 } |
|
1689 } |
|
1690 } |
|
1691 } |
|
1692 |
|
1693 // -------------------------------------------------------------------------------------------- |
|
1694 |
|
1695 void CFileBrowserFileUtils::DeleteL() |
|
1696 { |
|
1697 // do the file operations for each entry |
|
1698 for (TInt i=0; i<iCurrentSelectionList->Count(); i++) |
|
1699 { |
|
1700 TFileEntry fileEntry = iCurrentSelectionList->At(i); |
|
1701 |
|
1702 // append the new command to the command array |
|
1703 if (fileEntry.iEntry.IsDir()) |
|
1704 { |
|
1705 AppendToCommandArrayL(EFileBrowserFileOpCommandDelete, |
|
1706 new(ELeave)CCommandParamsDelete(fileEntry, CFileMan::ERecurse) |
|
1707 ); |
|
1708 } |
|
1709 else |
|
1710 { |
|
1711 AppendToCommandArrayL(EFileBrowserFileOpCommandDelete, |
|
1712 new(ELeave)CCommandParamsDelete(fileEntry, 0) |
|
1713 ); |
|
1714 } |
|
1715 |
|
1716 } |
|
1717 } |
|
1718 |
|
1719 |
|
1720 // -------------------------------------------------------------------------------------------- |
|
1721 |
|
1722 TBool CFileBrowserFileUtils::SelectionHasDirs() |
|
1723 { |
|
1724 TBool isDir(EFalse); |
|
1725 |
|
1726 // check if any directories and ask recursion |
|
1727 for (TInt i=0; i<iCurrentSelectionList->Count(); i++) |
|
1728 { |
|
1729 TFileEntry fileEntry = iCurrentSelectionList->At(i); |
|
1730 |
|
1731 if (fileEntry.iEntry.IsDir()) |
|
1732 { |
|
1733 isDir = ETrue; |
|
1734 break; |
|
1735 } |
|
1736 } |
|
1737 return isDir; |
|
1738 } |
|
1739 |
|
1740 // -------------------------------------------------------------------------------------------- |
|
1741 |
|
1742 void CFileBrowserFileUtils::TouchL(TBool aRecurse) |
|
1743 { |
|
1744 // now go through all entries |
|
1745 for (TInt i=0; i<iCurrentSelectionList->Count(); i++) |
|
1746 { |
|
1747 TFileEntry fileEntry = iCurrentSelectionList->At(i); |
|
1748 |
|
1749 // touch to current time |
|
1750 TTime now; |
|
1751 now.UniversalTime(); |
|
1752 |
|
1753 |
|
1754 // append the new command to the command array |
|
1755 if (fileEntry.iEntry.IsDir() && aRecurse) |
|
1756 { |
|
1757 AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs, |
|
1758 new(ELeave)CCommandParamsAttribs(fileEntry, NULL, NULL, now, CFileMan::ERecurse) |
|
1759 ); |
|
1760 } |
|
1761 else |
|
1762 { |
|
1763 AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs, |
|
1764 new(ELeave)CCommandParamsAttribs(fileEntry, NULL, NULL, now, 0) |
|
1765 ); |
|
1766 } |
|
1767 } |
|
1768 } |
|
1769 |
|
1770 TBool CFileBrowserFileUtils::TargetExists(const TInt aIndex, const TFileName &newName) |
|
1771 { |
|
1772 TBool alreadyExists(EFalse); |
|
1773 if (iFileEntryList->Count() > aIndex && aIndex >= 0) |
|
1774 { |
|
1775 |
|
1776 TFileEntry fileEntry = iFileEntryList->At(aIndex); |
|
1777 TFileName targetEntry = fileEntry.iPath; |
|
1778 targetEntry.Append(newName); |
|
1779 if (fileEntry.iEntry.IsDir()) |
|
1780 { |
|
1781 //targetEntry.Append(_L("\\")); |
|
1782 alreadyExists = BaflUtils::PathExists(iFs, targetEntry); |
|
1783 } |
|
1784 else |
|
1785 { |
|
1786 alreadyExists = BaflUtils::FileExists(iFs, targetEntry); |
|
1787 } |
|
1788 } |
|
1789 return alreadyExists; |
|
1790 } |
|
1791 |
|
1792 // -------------------------------------------------------------------------------------------- |
|
1793 |
|
1794 void CFileBrowserFileUtils::RenameL(const TInt aIndex, const TFileName &newName) |
|
1795 { |
|
1796 if (iFileEntryList->Count() > aIndex && aIndex >= 0) |
|
1797 { |
|
1798 TFileEntry fileEntry = iFileEntryList->At(aIndex); |
|
1799 |
|
1800 TFileName targetEntry = fileEntry.iPath; |
|
1801 targetEntry.Append(newName); |
|
1802 |
|
1803 // append the new command to the command array |
|
1804 AppendToCommandArrayL(EFileBrowserFileOpCommandRename, |
|
1805 new(ELeave)CCommandParamsRename(fileEntry, targetEntry, CFileMan::EOverWrite) |
|
1806 ); |
|
1807 } |
|
1808 } |
|
1809 |
|
1810 // -------------------------------------------------------------------------------------------- |
|
1811 |
|
1812 void CFileBrowserFileUtils::SetAttributesL(TUint &aSetAttMask, TUint &aClearAttMask, TBool &aRecurse) |
|
1813 { |
|
1814 for (TInt i=0; i<iCurrentSelectionList->Count(); i++) |
|
1815 { |
|
1816 TFileEntry fileEntry = iCurrentSelectionList->At(i); |
|
1817 |
|
1818 // append the new command to the command array |
|
1819 if (fileEntry.iEntry.IsDir() && aRecurse) |
|
1820 { |
|
1821 AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs, |
|
1822 new(ELeave)CCommandParamsAttribs(fileEntry, aSetAttMask, aClearAttMask, fileEntry.iEntry.iModified, CFileMan::ERecurse) |
|
1823 ); |
|
1824 } |
|
1825 else |
|
1826 { |
|
1827 AppendToCommandArrayL(EFileBrowserFileOpCommandAttribs, |
|
1828 new(ELeave)CCommandParamsAttribs(fileEntry, aSetAttMask, aClearAttMask, fileEntry.iEntry.iModified, 0) |
|
1829 ); |
|
1830 } |
|
1831 } |
|
1832 |
|
1833 // execute all operations |
|
1834 StartExecutingCommandsL(_L("Changing attributes")); |
|
1835 } |
|
1836 |
|
1837 // -------------------------------------------------------------------------------------------- |
|
1838 |
|
1839 void CFileBrowserFileUtils::SearchL() |
|
1840 { |
|
1841 // iEngine->FileListContainer()->SetScreenLayoutL(EDisplayModeNormal); |
|
1842 // iEngine->FileListContainer()->SetNaviPaneTextL(KNullDesC); |
|
1843 // |
|
1844 // iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode); |
|
1845 // iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
1846 // |
|
1847 iEngine->FileBrowserUI()->ShowWaitDialog(_L("Searching")); |
|
1848 iFileEntryList->Reset(); |
|
1849 |
|
1850 // if search dir is empty, find from all drives |
|
1851 if (iSearchAttributes.iSearchDir == KNullDesC) |
|
1852 { |
|
1853 for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
1854 { |
|
1855 TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
1856 |
|
1857 TBuf<10> driveRoot; |
|
1858 driveRoot.Append(driveEntry.iLetter); |
|
1859 driveRoot.Append(_L(":\\")); |
|
1860 |
|
1861 DoSearchFiles(iSearchAttributes.iWildCards, driveRoot); |
|
1862 |
|
1863 if (iSearchAttributes.iRecurse) |
|
1864 DoSearchFilesRecursiveL(iSearchAttributes.iWildCards, driveRoot); |
|
1865 } |
|
1866 |
|
1867 } |
|
1868 |
|
1869 // otherwise just search from the selected directory |
|
1870 else |
|
1871 { |
|
1872 DoSearchFiles(iSearchAttributes.iWildCards, iSearchAttributes.iSearchDir); |
|
1873 |
|
1874 if (iSearchAttributes.iRecurse) |
|
1875 DoSearchFilesRecursiveL(iSearchAttributes.iWildCards, iSearchAttributes.iSearchDir); |
|
1876 } |
|
1877 |
|
1878 iEngine->FileBrowserUI()->CancelWaitDialog(); |
|
1879 |
|
1880 iListingMode = ESearchResults; |
|
1881 RefreshViewL(); |
|
1882 } |
|
1883 |
|
1884 // -------------------------------------------------------------------------------------------- |
|
1885 |
|
1886 TInt CFileBrowserFileUtils::DoSearchFiles(const TDesC& aFileName, const TDesC& aPath) |
|
1887 { |
|
1888 TFindFile fileFinder(iFs); |
|
1889 CDir* dir; |
|
1890 TInt err = fileFinder.FindWildByPath(aFileName, &aPath, dir); |
|
1891 iEngine->FileBrowserUI()->ProcessEvents(); |
|
1892 |
|
1893 while (err == KErrNone && iAllowProcessing) |
|
1894 { |
|
1895 iEngine->FileBrowserUI()->ProcessEvents(); |
|
1896 for (TInt i=0; i<dir->Count(); i++) |
|
1897 { |
|
1898 TEntry entry = (*dir)[i]; |
|
1899 |
|
1900 TTime entryModified = entry.iModified; |
|
1901 // convert from universal time |
|
1902 if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone ) |
|
1903 { |
|
1904 entryModified = entry.iModified; |
|
1905 } |
|
1906 if ((entry.IsDir() && entryModified >= iSearchAttributes.iMinDate && entryModified <= iSearchAttributes.iMaxDate) || |
|
1907 (!entry.IsDir() &&entry.iSize >= iSearchAttributes.iMinSize && entry.iSize <= iSearchAttributes.iMaxSize && |
|
1908 entryModified >= iSearchAttributes.iMinDate && entryModified <= iSearchAttributes.iMaxDate)) |
|
1909 { |
|
1910 TParse parsedName; |
|
1911 parsedName.Set(entry.iName, &fileFinder.File(), NULL); |
|
1912 |
|
1913 if (parsedName.Drive().Length() && aPath.Length() && parsedName.Drive()[0] == aPath[0]) |
|
1914 { |
|
1915 TFileEntry fileEntry; |
|
1916 fileEntry.iPath = parsedName.DriveAndPath(); |
|
1917 fileEntry.iEntry = entry; |
|
1918 fileEntry.iDirEntries = KErrNotFound; |
|
1919 |
|
1920 TBool appendToArray(EFalse); |
|
1921 |
|
1922 // append directories always |
|
1923 if (entry.IsDir() && !iSearchAttributes.iTextInFile.Length()) |
|
1924 { |
|
1925 fileEntry.iIconId = EFixedIconFolder; |
|
1926 appendToArray = ETrue; |
|
1927 } |
|
1928 |
|
1929 // normal file |
|
1930 else |
|
1931 { |
|
1932 fileEntry.iIconId = EFixedIconEmpty; |
|
1933 |
|
1934 // check if a string needs to be found inside the file |
|
1935 if (iSearchAttributes.iTextInFile.Length()) |
|
1936 { |
|
1937 // currently only 8-bit searching, so convert from 16-bit |
|
1938 TBuf8<256> searchText; |
|
1939 searchText.Copy(iSearchAttributes.iTextInFile); |
|
1940 |
|
1941 // specify buffer size and create a buffer |
|
1942 const TInt KReadBufSize = 1024*1024; |
|
1943 HBufC8* buffer = HBufC8::NewLC(KReadBufSize); |
|
1944 TPtr8 bufferPtr = buffer->Des(); |
|
1945 |
|
1946 // open the file for reading |
|
1947 RFile file; |
|
1948 if (file.Open(iFs, parsedName.FullName(), EFileRead) == KErrNone) |
|
1949 { |
|
1950 TInt currentPos(0); |
|
1951 |
|
1952 for (;;) |
|
1953 { |
|
1954 // read from the file |
|
1955 file.Read(currentPos, bufferPtr, KReadBufSize); |
|
1956 |
|
1957 // stop looping if the read buffer isn't long enough |
|
1958 if (bufferPtr.Length() < searchText.Length()) |
|
1959 { |
|
1960 break; |
|
1961 } |
|
1962 |
|
1963 // try to find the text |
|
1964 if (bufferPtr.FindF(searchText) >= 0) |
|
1965 { |
|
1966 // match found! |
|
1967 appendToArray = ETrue; |
|
1968 break; |
|
1969 } |
|
1970 |
|
1971 // calculate the next position |
|
1972 currentPos += KReadBufSize - searchText.Length(); |
|
1973 } |
|
1974 |
|
1975 file.Close(); |
|
1976 } |
|
1977 |
|
1978 CleanupStack::PopAndDestroy(); //buffer |
|
1979 } |
|
1980 else |
|
1981 { |
|
1982 appendToArray = ETrue; |
|
1983 } |
|
1984 } |
|
1985 |
|
1986 if (appendToArray) |
|
1987 TRAP(err, iFileEntryList->AppendL(fileEntry)); |
|
1988 } |
|
1989 } |
|
1990 } |
|
1991 |
|
1992 delete dir; |
|
1993 err = fileFinder.FindWild(dir); |
|
1994 } |
|
1995 |
|
1996 return err; |
|
1997 } |
|
1998 |
|
1999 // -------------------------------------------------------------------------------------------- |
|
2000 |
|
2001 TInt CFileBrowserFileUtils::DoSearchFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath) |
|
2002 { |
|
2003 TInt err(KErrNone); |
|
2004 CDirScan* scan = CDirScan::NewLC(iFs); |
|
2005 scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchMask, ESortByName | EAscending | EDirsFirst); |
|
2006 CDir* dir = NULL; |
|
2007 |
|
2008 for(;;) |
|
2009 { |
|
2010 TRAP(err, scan->NextL(dir)); |
|
2011 if (!dir || (err != KErrNone)) |
|
2012 break; |
|
2013 |
|
2014 for (TInt i=0; i<dir->Count(); i++) |
|
2015 { |
|
2016 TEntry entry = (*dir)[i]; |
|
2017 |
|
2018 if (entry.IsDir()) |
|
2019 { |
|
2020 TFileName path(scan->FullPath()); |
|
2021 |
|
2022 if (path.Length()) |
|
2023 { |
|
2024 path.Append(entry.iName); |
|
2025 path.Append(_L("\\")); |
|
2026 DoSearchFiles(aFileName, path); |
|
2027 } |
|
2028 } |
|
2029 } |
|
2030 delete(dir); |
|
2031 } |
|
2032 |
|
2033 CleanupStack::PopAndDestroy(scan); |
|
2034 return err; |
|
2035 } |
|
2036 |
|
2037 // -------------------------------------------------------------------------------------------- |
|
2038 |
|
2039 void CFileBrowserFileUtils::NewFileL(const TFileName &aNewFileName) |
|
2040 { |
|
2041 TFileName fullPath = iCurrentPath; |
|
2042 fullPath.Append(aNewFileName); |
|
2043 |
|
2044 TParse nameParser; |
|
2045 User::LeaveIfError(nameParser.SetNoWild(fullPath, NULL, NULL)); |
|
2046 |
|
2047 // do not try to recreate the file if it already exists |
|
2048 if (BaflUtils::PathExists(iFs, nameParser.DriveAndPath())) |
|
2049 { |
|
2050 User::LeaveIfError(iFileOps->CreateEmptyFile(fullPath)); |
|
2051 } |
|
2052 else |
|
2053 { |
|
2054 User::Leave(KErrAlreadyExists); |
|
2055 } |
|
2056 } |
|
2057 |
|
2058 // -------------------------------------------------------------------------------------------- |
|
2059 |
|
2060 void CFileBrowserFileUtils::NewDirectoryL(const TFileName &aNewDirectoryName) |
|
2061 { |
|
2062 TFileName fullPath = iCurrentPath; |
|
2063 fullPath.Append(aNewDirectoryName); |
|
2064 fullPath.Append(_L("\\")); |
|
2065 |
|
2066 User::LeaveIfError(iFileOps->MkDirAll(fullPath, 0, ETrue)); |
|
2067 } |
|
2068 |
|
2069 // -------------------------------------------------------------------------------------------- |
|
2070 |
|
2071 void CFileBrowserFileUtils::SendToL() |
|
2072 { |
|
2073 // CFileEntryList* entries = new(ELeave) CFileEntryList(32); |
|
2074 // GetSelectedItemsOrCurrentItemL(entries); |
|
2075 // CleanupStack::PushL(entries); |
|
2076 // |
|
2077 // TInt operations(0); |
|
2078 // |
|
2079 // CSendUi* sendUi = CSendUi::NewL(); |
|
2080 // CleanupStack::PushL(sendUi); |
|
2081 // CMessageData* messageData = CMessageData::NewL(); |
|
2082 // CleanupStack::PushL(messageData); |
|
2083 // |
|
2084 // for (TInt i=0; i<entries->Count(); i++) |
|
2085 // { |
|
2086 // TFileEntry fileEntry = entries->At(i); |
|
2087 // |
|
2088 // // only supported for normal file entries |
|
2089 // if (!fileEntry.iEntry.IsDir()) |
|
2090 // { |
|
2091 // TFileName fullPath = fileEntry.iPath; |
|
2092 // fullPath.Append(fileEntry.iEntry.iName); |
|
2093 // |
|
2094 // messageData->AppendAttachmentL(fullPath); |
|
2095 // operations++; |
|
2096 // |
|
2097 // } |
|
2098 // } |
|
2099 // |
|
2100 // if (operations > 0) |
|
2101 // { |
|
2102 // sendUi->ShowQueryAndSendL(messageData, TSendingCapabilities(0, 0, TSendingCapabilities::ESupportsAttachments)); |
|
2103 // |
|
2104 // // I guess this note is not needed.. |
|
2105 //// _LIT(KMessage, "%d entries sent"); |
|
2106 //// TFileName noteMsg; |
|
2107 //// noteMsg.Format(KMessage, operations); |
|
2108 //// |
|
2109 //// iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg); |
|
2110 // } |
|
2111 // else |
|
2112 // { |
|
2113 // _LIT(KMessage, "Nothing to send"); |
|
2114 // iEngine->FileBrowserUI()->ShowInformationNote(KMessage, _L("")); |
|
2115 // } |
|
2116 // |
|
2117 // CleanupStack::PopAndDestroy(3); // entries, sendUi, messageData |
|
2118 } |
|
2119 |
|
2120 // -------------------------------------------------------------------------------------------- |
|
2121 |
|
2122 void CFileBrowserFileUtils::CompressL() |
|
2123 { |
|
2124 // CFileEntryList* entries = new(ELeave) CFileEntryList(16); |
|
2125 // GetSelectedItemsOrCurrentItemL(entries); |
|
2126 // CleanupStack::PushL(entries); |
|
2127 // |
|
2128 // for (TInt i=0; i<entries->Count(); i++) |
|
2129 // { |
|
2130 // TFileEntry fileEntry = entries->At(i); |
|
2131 // |
|
2132 // TFileName sourceEntry = fileEntry.iPath; |
|
2133 // sourceEntry.Append(fileEntry.iEntry.iName); |
|
2134 // |
|
2135 // TFileName targetEntry = sourceEntry; |
|
2136 // targetEntry.Append(KGZipExt); |
|
2137 // |
|
2138 // TFileName targetEntryShort; |
|
2139 // targetEntryShort.Copy(fileEntry.iEntry.iName); |
|
2140 // targetEntryShort.Append(KGZipExt); |
|
2141 // |
|
2142 // if (BaflUtils::FileExists(iFs, targetEntry)) |
|
2143 // { |
|
2144 // _LIT(KMessage, "%S already exists"); |
|
2145 // TFileName noteMsg; |
|
2146 // noteMsg.Format(KMessage, &targetEntryShort); |
|
2147 // |
|
2148 // iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
2149 // } |
|
2150 // else |
|
2151 // { |
|
2152 // TRAPD(err, |
|
2153 // RFile inputFile; |
|
2154 // User::LeaveIfError(inputFile.Open(iFs, sourceEntry, EFileStream | EFileRead | EFileShareAny)); |
|
2155 // CleanupClosePushL(inputFile); |
|
2156 // |
|
2157 // CEZFileToGZip* gZip = CEZFileToGZip::NewLC(iFs, targetEntry, inputFile); |
|
2158 // |
|
2159 // while (gZip->DeflateL()) |
|
2160 // ; |
|
2161 // |
|
2162 // CleanupStack::PopAndDestroy(2); //inputFile, gZip |
|
2163 // ); |
|
2164 // |
|
2165 // if (err == KErrNone) |
|
2166 // { |
|
2167 // _LIT(KMessage, "%S created succesfully"); |
|
2168 // TFileName noteMsg; |
|
2169 // noteMsg.Format(KMessage, &targetEntryShort); |
|
2170 // |
|
2171 // iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg); |
|
2172 // } |
|
2173 // else |
|
2174 // { |
|
2175 // _LIT(KMessage, "Unable to create %S"); |
|
2176 // TFileName noteMsg; |
|
2177 // noteMsg.Format(KMessage, &targetEntryShort); |
|
2178 // |
|
2179 // iEngine->FileBrowserUI()->ShowErrorNote(noteMsg); |
|
2180 // } |
|
2181 // |
|
2182 // RefreshViewL(); |
|
2183 // } |
|
2184 // } |
|
2185 // |
|
2186 // CleanupStack::PopAndDestroy(); //entries |
|
2187 } |
|
2188 |
|
2189 // -------------------------------------------------------------------------------------------- |
|
2190 |
|
2191 void CFileBrowserFileUtils::DecompressL() |
|
2192 { |
|
2193 // CFileEntryList* entries = new(ELeave) CFileEntryList(16); |
|
2194 // GetSelectedItemsOrCurrentItemL(entries); |
|
2195 // CleanupStack::PushL(entries); |
|
2196 // |
|
2197 // for (TInt i=0; i<entries->Count(); i++) |
|
2198 // { |
|
2199 // TFileEntry fileEntry = entries->At(i); |
|
2200 // |
|
2201 // TFileName sourceEntry = fileEntry.iPath; |
|
2202 // sourceEntry.Append(fileEntry.iEntry.iName); |
|
2203 // |
|
2204 // TFileName targetEntry; |
|
2205 // TFileName targetEntryShort; |
|
2206 // |
|
2207 // TInt sourceNameLen = fileEntry.iEntry.iName.Length(); |
|
2208 // TInt gZipExtLen = KGZipExt().Length(); |
|
2209 // |
|
2210 // if (sourceNameLen > gZipExtLen && sourceEntry.Right(gZipExtLen).CompareF(KGZipExt) == 0) |
|
2211 // { |
|
2212 // targetEntry = sourceEntry.Left(sourceEntry.Length() - gZipExtLen); |
|
2213 // targetEntryShort = fileEntry.iEntry.iName.Left(sourceNameLen - gZipExtLen); |
|
2214 // |
|
2215 // if (BaflUtils::FileExists(iFs, targetEntry)) |
|
2216 // { |
|
2217 // _LIT(KMessage, "%S already exists"); |
|
2218 // TFileName noteMsg; |
|
2219 // noteMsg.Format(KMessage, &targetEntryShort); |
|
2220 // |
|
2221 // iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
2222 // } |
|
2223 // else |
|
2224 // { |
|
2225 // TRAPD(err, |
|
2226 // RFile outputFile; |
|
2227 // User::LeaveIfError(outputFile.Create(iFs, targetEntry, EFileStream | EFileWrite | EFileShareExclusive)); |
|
2228 // CleanupClosePushL(outputFile); |
|
2229 // |
|
2230 // CEZGZipToFile* gZip = CEZGZipToFile::NewLC(iFs, sourceEntry, outputFile); |
|
2231 // |
|
2232 // while (gZip->InflateL()) |
|
2233 // ; |
|
2234 // |
|
2235 // CleanupStack::PopAndDestroy(2); //outputFile, gZip |
|
2236 // ); |
|
2237 // |
|
2238 // if (err == KErrNone) |
|
2239 // { |
|
2240 // _LIT(KMessage, "%S decompressed succesfully"); |
|
2241 // TFileName noteMsg; |
|
2242 // noteMsg.Format(KMessage, &fileEntry.iEntry.iName); |
|
2243 // |
|
2244 // iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg); |
|
2245 // } |
|
2246 // else |
|
2247 // { |
|
2248 // _LIT(KMessage, "Unable to decompress %S"); |
|
2249 // TFileName noteMsg; |
|
2250 // noteMsg.Format(KMessage, &fileEntry.iEntry.iName); |
|
2251 // |
|
2252 // iEngine->FileBrowserUI()->ShowErrorNote(noteMsg); |
|
2253 // } |
|
2254 // |
|
2255 // RefreshViewL(); |
|
2256 // } |
|
2257 // } |
|
2258 // else |
|
2259 // { |
|
2260 // _LIT(KMessage, "%S does not have %S extension"); |
|
2261 // TFileName noteMsg; |
|
2262 // noteMsg.Format(KMessage, &fileEntry.iEntry.iName, &KGZipExt); |
|
2263 // |
|
2264 // iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
2265 // } |
|
2266 // } |
|
2267 // |
|
2268 // CleanupStack::PopAndDestroy(); //entries |
|
2269 } |
|
2270 |
|
2271 // -------------------------------------------------------------------------------------------- |
|
2272 |
|
2273 TInt CFileBrowserFileUtils::GetFilesCount(const TFileName &aFullPath) |
|
2274 { |
|
2275 iFindFileEntryList->Reset(); |
|
2276 |
|
2277 SetAllowProcessing(ETrue); |
|
2278 DoFindFiles(_L("*"), aFullPath); |
|
2279 DoFindFilesRecursiveL(_L("*"), aFullPath); |
|
2280 SetAllowProcessing(EFalse); |
|
2281 |
|
2282 TInt filesCount = iFindFileEntryList->Count(); |
|
2283 |
|
2284 iFindFileEntryList->Reset(); |
|
2285 |
|
2286 return filesCount; |
|
2287 } |
|
2288 |
|
2289 // -------------------------------------------------------------------------------------------- |
|
2290 |
|
2291 TInt CFileBrowserFileUtils::GetFilesCountAndSize(const TFileName &aFullPath, TInt64 &aSize) |
|
2292 { |
|
2293 iFindFileEntryList->Reset(); |
|
2294 |
|
2295 SetAllowProcessing(ETrue); |
|
2296 DoFindFiles(_L("*"), aFullPath); |
|
2297 DoFindFilesRecursiveL(_L("*"), aFullPath); |
|
2298 SetAllowProcessing(EFalse); |
|
2299 |
|
2300 // number of files |
|
2301 TInt filesCount = iFindFileEntryList->Count(); |
|
2302 |
|
2303 // size |
|
2304 TInt64 size(0); |
|
2305 for (TInt i=0; i<iFindFileEntryList->Count(); i++) |
|
2306 { |
|
2307 TFileEntry fileEntry = iFindFileEntryList->At(i); |
|
2308 size += fileEntry.iEntry.iSize; |
|
2309 } |
|
2310 aSize = size; |
|
2311 |
|
2312 iFindFileEntryList->Reset(); |
|
2313 |
|
2314 return filesCount; |
|
2315 } |
|
2316 |
|
2317 // -------------------------------------------------------------------------------------------- |
|
2318 |
|
2319 TInt CFileBrowserFileUtils::GetEntriesCount(const TFileName &aFullPath) |
|
2320 { |
|
2321 // number of entries |
|
2322 CDir* subDir = NULL; |
|
2323 TInt entriesCount = -1; |
|
2324 if (iFs.GetDir(aFullPath, KEntryAttMatchMask, ESortNone | EDirsFirst, subDir) == KErrNone) |
|
2325 { |
|
2326 entriesCount = subDir->Count(); |
|
2327 } |
|
2328 return entriesCount; |
|
2329 } |
|
2330 |
|
2331 // -------------------------------------------------------------------------------------------- |
|
2332 |
|
2333 TFileName CFileBrowserFileUtils::GetMimeType(const TFileName &aFullPath) |
|
2334 { |
|
2335 // mime type |
|
2336 TDataType dataType; |
|
2337 TUid appUid; |
|
2338 TBuf<128> mimeTypeBuf; |
|
2339 if (iEngine->LsSession().AppForDocument(aFullPath, appUid, dataType) == KErrNone) |
|
2340 { |
|
2341 mimeTypeBuf.Copy(dataType.Des8()); |
|
2342 if (mimeTypeBuf == KNullDesC) |
|
2343 mimeTypeBuf.Copy(_L("N/A")); |
|
2344 } |
|
2345 return mimeTypeBuf; |
|
2346 } |
|
2347 |
|
2348 // -------------------------------------------------------------------------------------------- |
|
2349 |
|
2350 TFileName CFileBrowserFileUtils::GetOpenWith(const TFileName &aFullPath) |
|
2351 { |
|
2352 // opens with |
|
2353 TDataType dataType; |
|
2354 TUid appUid; |
|
2355 TApaAppInfo appInfo; |
|
2356 TFileName opensWithBuf; |
|
2357 if (iEngine->LsSession().AppForDocument(aFullPath, appUid, dataType) == KErrNone) |
|
2358 { |
|
2359 if (iEngine->LsSession().GetAppInfo(appInfo, appUid) == KErrNone) |
|
2360 { |
|
2361 _LIT(KOpensWithFormat, "%S (0x%08X)"); |
|
2362 opensWithBuf.Format(KOpensWithFormat, &appInfo.iCaption, appInfo.iUid); |
|
2363 } |
|
2364 } |
|
2365 return opensWithBuf; |
|
2366 } |
|
2367 |
|
2368 // -------------------------------------------------------------------------------------------- |
|
2369 |
|
2370 void CFileBrowserFileUtils::OpenWithApparcL(const TFileName &aFileName) |
|
2371 { |
|
2372 |
|
2373 TFileName fullPath = aFileName; |
|
2374 TInt err1(KErrNone), err2(KErrNone); |
|
2375 TUid appUid; |
|
2376 TDataType dataType; |
|
2377 TBool isProgram; |
|
2378 |
|
2379 |
|
2380 err1 = iEngine->LsSession().AppForDocument(fullPath, appUid, dataType); |
|
2381 err2 = iEngine->LsSession().IsProgram(fullPath, isProgram); |
|
2382 |
|
2383 if (err1 == KErrNone && err2 == KErrNone) |
|
2384 { |
|
2385 if (appUid != KNullUid) |
|
2386 { |
|
2387 // found an app, run using it |
|
2388 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
2389 TApaTask task = (taskList.FindApp(appUid)); |
|
2390 if (task.Exists()) |
|
2391 { |
|
2392 User::LeaveIfError(task.SwitchOpenFile(fullPath)); |
|
2393 task.BringToForeground(); |
|
2394 } |
|
2395 else |
|
2396 { |
|
2397 TThreadId id; |
|
2398 iEngine->LsSession().StartDocument(fullPath, appUid, id, RApaLsSession::ESwitchFiles); |
|
2399 } |
|
2400 } |
|
2401 else if (isProgram) |
|
2402 { |
|
2403 LaunchProgramL(fullPath); |
|
2404 } |
|
2405 } |
|
2406 //} |
|
2407 } |
|
2408 |
|
2409 // -------------------------------------------------------------------------------------------- |
|
2410 |
|
2411 //void CFileBrowserFileUtils::HandleServerAppExit(TInt aReason) |
|
2412 // { |
|
2413 // if (iOpenFileService) |
|
2414 // { |
|
2415 // delete iOpenFileService; |
|
2416 // iOpenFileService = NULL; |
|
2417 // } |
|
2418 // MAknServerAppExitObserver::HandleServerAppExit(aReason); |
|
2419 // } |
|
2420 |
|
2421 // -------------------------------------------------------------------------------------------- |
|
2422 |
|
2423 void CFileBrowserFileUtils::OpenWithDocHandlerL(const TFileName &aFileName, TBool aEmbed) |
|
2424 { |
|
2425 TFileName fullPath = aFileName; |
|
2426 RFile sharableFile; |
|
2427 iDocHandler->OpenTempFileL(fullPath, sharableFile); |
|
2428 CleanupClosePushL(sharableFile); |
|
2429 TDataType dataType; |
|
2430 if (aEmbed) |
|
2431 { |
|
2432 iDocHandler->OpenFileEmbeddedL(sharableFile, dataType); |
|
2433 } |
|
2434 else |
|
2435 { |
|
2436 iDocHandler->OpenFileL(sharableFile, dataType); |
|
2437 } |
|
2438 CleanupStack::PopAndDestroy(); //sharableFile |
|
2439 // } |
|
2440 } |
|
2441 |
|
2442 // -------------------------------------------------------------------------------------------- |
|
2443 |
|
2444 void CFileBrowserFileUtils::OpenWithFileServiceL(TInt aCurrentItemIndex) |
|
2445 { |
|
2446 if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0) |
|
2447 { |
|
2448 TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex); |
|
2449 |
|
2450 TFileName fullPath = fileEntry.iPath; |
|
2451 fullPath.Append(fileEntry.iEntry.iName); |
|
2452 |
|
2453 // TBool itemSelected(EFalse); |
|
2454 RFile sharableFile; |
|
2455 // TUid appUidExtracted; |
|
2456 |
|
2457 TRAPD(err, |
|
2458 |
|
2459 // use doc handler to get a sharable file handle |
|
2460 iDocHandler->OpenTempFileL(fullPath, sharableFile); |
|
2461 CleanupClosePushL(sharableFile); |
|
2462 |
|
2463 // find the data type |
|
2464 TDataRecognitionResult dataType; |
|
2465 User::LeaveIfError(iEngine->LsSession().RecognizeData(sharableFile, dataType)); |
|
2466 |
|
2467 // get all apps that support OpenFileService for this datatype |
|
2468 CApaAppServiceInfoArray* apps = iEngine->LsSession().GetServiceImplementationsLC(KOpenServiceUid, dataType.iDataType); |
|
2469 TArray<TApaAppServiceInfo> appServiceInfos = apps->Array(); |
|
2470 |
|
2471 if (appServiceInfos.Count() > 0) |
|
2472 { |
|
2473 // build an array of the app names |
|
2474 CDesCArray* names = new (ELeave) CDesCArrayFlat(16); |
|
2475 CleanupStack::PushL(names); |
|
2476 for (TInt ii=0; ii<appServiceInfos.Count(); ii++) |
|
2477 { |
|
2478 TUid appUid = appServiceInfos[ii].Uid(); |
|
2479 TApaAppInfo appInfo; |
|
2480 if (iEngine->LsSession().GetAppInfo(appInfo, appUid) == KErrNone) |
|
2481 { |
|
2482 names->AppendL(appInfo.iCaption); |
|
2483 } |
|
2484 else |
|
2485 { |
|
2486 TBuf<10> buf; |
|
2487 buf.Format(_L("0x%08x"), appUid); |
|
2488 names->AppendL(buf); |
|
2489 } |
|
2490 } |
|
2491 |
|
2492 // use a list query to select the app |
|
2493 // TInt index(0); |
|
2494 // CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog(&index); |
|
2495 // dlg->PrepareLC(R_APP_SELECTION_QUERY); |
|
2496 // dlg->SetItemTextArray(names); |
|
2497 // dlg->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
2498 // |
|
2499 // if(dlg->RunLD()) |
|
2500 // { |
|
2501 // // extract the chosen UID |
|
2502 // appUidExtracted = appServiceInfos[index].Uid(); |
|
2503 // itemSelected = ETrue; |
|
2504 // } |
|
2505 |
|
2506 CleanupStack::PopAndDestroy(); // names |
|
2507 } |
|
2508 |
|
2509 // if (itemSelected) |
|
2510 // { |
|
2511 // // start OpenFileService for the selected app |
|
2512 // CAiwGenericParamList& paramList = iDocHandler->InParamListL(); |
|
2513 // (void)paramList; |
|
2514 // if (iOpenFileService) |
|
2515 // { |
|
2516 // delete iOpenFileService; |
|
2517 // iOpenFileService = NULL; |
|
2518 // } |
|
2519 // |
|
2520 // iOpenFileService = CAknOpenFileService::NewL(appUidExtracted, sharableFile, this, ¶mList); |
|
2521 // } |
|
2522 |
|
2523 CleanupStack::PopAndDestroy(2); // sharableFile, apps |
|
2524 |
|
2525 ); // TRAPD |
|
2526 |
|
2527 if (err != KErrNone) |
|
2528 { |
|
2529 _LIT(KMessage, "No file service available for %S"); |
|
2530 TFileName noteMsg; |
|
2531 noteMsg.Format(KMessage, &fileEntry.iEntry.iName); |
|
2532 |
|
2533 iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
2534 } |
|
2535 } |
|
2536 } |
|
2537 |
|
2538 // -------------------------------------------------------------------------------------------- |
|
2539 |
|
2540 TBool CFileBrowserFileUtils::FileExists(const TDesC& aPath) |
|
2541 { |
|
2542 return BaflUtils::FileExists(iFs, aPath); |
|
2543 } |
|
2544 |
|
2545 // -------------------------------------------------------------------------------------------- |
|
2546 |
|
2547 TInt CFileBrowserFileUtils::LaunchProgramL(const TDesC& aPath) |
|
2548 { |
|
2549 CApaCommandLine* commandLine = CApaCommandLine::NewLC(); |
|
2550 commandLine->SetExecutableNameL(aPath); |
|
2551 commandLine->SetCommandL(EApaCommandRun); |
|
2552 TInt err = iEngine->LsSession().StartApp(*commandLine); |
|
2553 CleanupStack::PopAndDestroy(); //commandLine |
|
2554 return err; |
|
2555 } |
|
2556 |
|
2557 // -------------------------------------------------------------------------------------------- |
|
2558 |
|
2559 void CFileBrowserFileUtils::MemoryInfoPopupL() |
|
2560 { |
|
2561 _LIT(KUsedBytesEntry, "Used: %S bytes\n"); |
|
2562 _LIT(KFreeBytesEntry, "Free: %S bytes\n"); |
|
2563 _LIT(KSizeBytesEntry, "Size: %S bytes\n"); |
|
2564 |
|
2565 HBufC* messageBuf = HBufC::NewLC(2048); |
|
2566 TPtr messagePtr = messageBuf->Des(); |
|
2567 TBuf<128> entryLine; |
|
2568 |
|
2569 // RAM |
|
2570 TMemoryInfoV1Buf ramMemory; |
|
2571 UserHal::MemoryInfo(ramMemory); |
|
2572 messagePtr.Append(_L("RAM\n")); |
|
2573 |
|
2574 // used |
|
2575 TBuf<32> usedBuf; |
|
2576 usedBuf.AppendNum(ramMemory().iMaxFreeRamInBytes-ramMemory().iFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0)); |
|
2577 entryLine.Format(KUsedBytesEntry, &usedBuf); |
|
2578 messagePtr.Append(entryLine); |
|
2579 |
|
2580 // free |
|
2581 TBuf<32> freeBuf; |
|
2582 freeBuf.AppendNum(ramMemory().iFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0)); |
|
2583 entryLine.Format(KFreeBytesEntry, &freeBuf); |
|
2584 messagePtr.Append(entryLine); |
|
2585 |
|
2586 // size |
|
2587 TBuf<32> sizeBuf; |
|
2588 sizeBuf.AppendNum(ramMemory().iMaxFreeRamInBytes, TRealFormat(KDefaultRealWidth, 0)); |
|
2589 entryLine.Format(KSizeBytesEntry, &sizeBuf); |
|
2590 messagePtr.Append(entryLine); |
|
2591 |
|
2592 // All drives |
|
2593 for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
2594 { |
|
2595 TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
2596 |
|
2597 messagePtr.Append(_L("\n")); |
|
2598 messagePtr.Append(driveEntry.iLetter); |
|
2599 messagePtr.Append(_L(":\n")); |
|
2600 |
|
2601 // used |
|
2602 TBuf<32> usedBuf; |
|
2603 usedBuf.AppendNum(driveEntry.iVolumeInfo.iSize-driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0)); |
|
2604 entryLine.Format(KUsedBytesEntry, &usedBuf); |
|
2605 messagePtr.Append(entryLine); |
|
2606 |
|
2607 // free |
|
2608 TBuf<32> freeBuf; |
|
2609 freeBuf.AppendNum(driveEntry.iVolumeInfo.iFree, TRealFormat(KDefaultRealWidth, 0)); |
|
2610 entryLine.Format(KFreeBytesEntry, &freeBuf); |
|
2611 messagePtr.Append(entryLine); |
|
2612 |
|
2613 // size |
|
2614 TBuf<32> sizeBuf; |
|
2615 sizeBuf.AppendNum(driveEntry.iVolumeInfo.iSize, TRealFormat(KDefaultRealWidth, 0)); |
|
2616 entryLine.Format(KSizeBytesEntry, &sizeBuf); |
|
2617 messagePtr.Append(entryLine); |
|
2618 } |
|
2619 |
|
2620 // CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog; |
|
2621 // dialog->PrepareLC(R_MEMORYINFO_DIALOG); |
|
2622 // dialog->SetMessageTextL(messagePtr); |
|
2623 // dialog->RunLD(); |
|
2624 |
|
2625 CleanupStack::PopAndDestroy(); //messageBuf |
|
2626 } |
|
2627 |
|
2628 // -------------------------------------------------------------------------------------------- |
|
2629 |
|
2630 void CFileBrowserFileUtils::ShowFileCheckSumsL(TInt aCurrentItemIndex, TInt aType) |
|
2631 { |
|
2632 if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0) |
|
2633 { |
|
2634 TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex); |
|
2635 TFileName fullPath = fileEntry.iPath; |
|
2636 fullPath.Append(fileEntry.iEntry.iName); |
|
2637 |
|
2638 // try to open the file for reading |
|
2639 RFile fileP; |
|
2640 User::LeaveIfError(fileP.Open(iEngine->EikonEnv()->FsSession(), |
|
2641 fullPath, |
|
2642 EFileRead|EFileShareReadersOnly)); |
|
2643 |
|
2644 CleanupClosePushL(fileP); |
|
2645 |
|
2646 TBuf<128> checkSum; |
|
2647 HBufC* messageBuf = HBufC::NewLC(2048); |
|
2648 TPtr messagePtr = messageBuf->Des(); |
|
2649 |
|
2650 // get MD5 checksum |
|
2651 if (aType == EFileChecksumsMD5) |
|
2652 { |
|
2653 CMD5* md5 = CMD5::NewL(); |
|
2654 CleanupStack::PushL(md5); |
|
2655 HBufC8* md5Buf = MessageDigestInHexLC(md5, fileP); |
|
2656 checkSum.Copy(*md5Buf); |
|
2657 messagePtr.Append(_L("MD5\n")); |
|
2658 messagePtr.Append(checkSum); |
|
2659 CleanupStack::PopAndDestroy(2); // md5, md5Buf |
|
2660 } |
|
2661 |
|
2662 // get MD2 checksum |
|
2663 else if (aType == EFileChecksumsMD2) |
|
2664 { |
|
2665 CMD2* md2 = CMD2::NewL(); |
|
2666 CleanupStack::PushL(md2); |
|
2667 HBufC8* md2Buf = MessageDigestInHexLC(md2, fileP); |
|
2668 checkSum.Copy(*md2Buf); |
|
2669 messagePtr.Append(_L("MD2\n")); |
|
2670 messagePtr.Append(checkSum); |
|
2671 CleanupStack::PopAndDestroy(2); // md2, md2Buf |
|
2672 } |
|
2673 |
|
2674 // get SHA-1 checksum |
|
2675 else if (aType == EFileChecksumsSHA1) |
|
2676 { |
|
2677 CSHA1* sha1 = CSHA1::NewL(); |
|
2678 CleanupStack::PushL(sha1); |
|
2679 HBufC8* sha1Buf = MessageDigestInHexLC(sha1, fileP); |
|
2680 checkSum.Copy(*sha1Buf); |
|
2681 messagePtr.Append(_L("SHA-1\n")); |
|
2682 messagePtr.Append(checkSum); |
|
2683 CleanupStack::PopAndDestroy(2); // sha1, sha1Buf |
|
2684 } |
|
2685 |
|
2686 else |
|
2687 { |
|
2688 User::Panic(_L("Inv.CS.Type"), 723); |
|
2689 } |
|
2690 |
|
2691 // show dialog |
|
2692 iEngine->FileBrowserUI()->ShowInformationNote(messagePtr, fileEntry.iEntry.iName); |
|
2693 |
|
2694 CleanupStack::PopAndDestroy(2); // messageBuf, fileP |
|
2695 } |
|
2696 } |
|
2697 |
|
2698 // -------------------------------------------------------------------------------------------- |
|
2699 |
|
2700 HBufC8* CFileBrowserFileUtils::MessageDigestInHexLC(CMessageDigest* aMD, RFile& aFile) |
|
2701 { |
|
2702 // seek to file start |
|
2703 TInt startPos(0); |
|
2704 aFile.Seek(ESeekStart, startPos); |
|
2705 |
|
2706 // create result buffer |
|
2707 HBufC8* result = HBufC8::NewLC(128); |
|
2708 |
|
2709 const TInt KBufSize(1024); |
|
2710 TInt fileSize(0); |
|
2711 TInt fileOffset(0); |
|
2712 |
|
2713 // get file size |
|
2714 aFile.Size(fileSize); |
|
2715 |
|
2716 HBufC8* buf = HBufC8::NewMaxLC(KBufSize); |
|
2717 TPtr8 bufPtr(buf->Des()); |
|
2718 |
|
2719 // read to buffer |
|
2720 while (fileOffset < fileSize - KBufSize) |
|
2721 { |
|
2722 aFile.Read(bufPtr, KBufSize); |
|
2723 aMD->Hash(bufPtr); |
|
2724 fileOffset += bufPtr.Length(); |
|
2725 } |
|
2726 |
|
2727 aFile.Read(bufPtr, fileSize - fileOffset); |
|
2728 bufPtr.SetLength(fileSize - fileOffset); |
|
2729 |
|
2730 // get final message digest |
|
2731 TPtrC8 hashedSig(aMD->Final(bufPtr)); |
|
2732 |
|
2733 // change size of the result buffer |
|
2734 result->ReAllocL(hashedSig.Length() * 2); |
|
2735 TPtr8 resultPtr = result->Des(); |
|
2736 |
|
2737 // convert to hex format |
|
2738 for (TInt i=0; i<hashedSig.Length(); i++) |
|
2739 { |
|
2740 resultPtr.AppendFormat(_L8("%+02x"), hashedSig[i]); |
|
2741 } |
|
2742 |
|
2743 CleanupStack::PopAndDestroy(); // buf |
|
2744 |
|
2745 return result; |
|
2746 } |
|
2747 |
|
2748 // -------------------------------------------------------------------------------------------- |
|
2749 |
|
2750 void CFileBrowserFileUtils::SetErrRdL(TBool aEnable) |
|
2751 { |
|
2752 #ifndef FILEBROWSER_LITE |
|
2753 if (iEngine->Settings().iBypassPlatformSecurity) |
|
2754 { |
|
2755 TInt err(KErrNone); |
|
2756 |
|
2757 if (aEnable) |
|
2758 { |
|
2759 // make sure that the directory exists |
|
2760 iFileOps->MkDirAll(KErrRdPath); |
|
2761 |
|
2762 // create the file |
|
2763 err = iFileOps->CreateEmptyFile(KErrRdPath); |
|
2764 } |
|
2765 else |
|
2766 { |
|
2767 // get TEntry of ErrRd |
|
2768 TEntry entry; |
|
2769 err = iFs.Entry(KErrRdPath, entry); |
|
2770 |
|
2771 if (err == KErrNone) |
|
2772 { |
|
2773 TFileEntry fileEntry; |
|
2774 fileEntry.iPath = KErrRdDir; |
|
2775 fileEntry.iEntry = entry; |
|
2776 |
|
2777 err = iFileOps->Delete(fileEntry); |
|
2778 } |
|
2779 } |
|
2780 |
|
2781 // update view |
|
2782 RefreshViewL(); |
|
2783 |
|
2784 if (err == KErrNone) |
|
2785 { |
|
2786 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("State changed")); |
|
2787 } |
|
2788 else |
|
2789 { |
|
2790 iEngine->FileBrowserUI()->ShowErrorNote(_L("Cannot change the state")); |
|
2791 } |
|
2792 } |
|
2793 else |
|
2794 { |
|
2795 iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L("")); |
|
2796 } |
|
2797 #else |
|
2798 aEnable = aEnable; |
|
2799 iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L("")); |
|
2800 #endif |
|
2801 } |
|
2802 |
|
2803 // -------------------------------------------------------------------------------------------- |
|
2804 |
|
2805 //void CFileBrowserFileUtils::EnableAvkonIconCacheL(TBool aEnable) |
|
2806 // { |
|
2807 //#ifndef __SERIES60_30__ |
|
2808 // if (AknIconConfig::EnableAknIconSrvCache(aEnable) == KErrNone) |
|
2809 // { |
|
2810 // iEngine->FileBrowserUI()->ShowConfirmationNote(_L("State changed")); |
|
2811 // } |
|
2812 // else |
|
2813 // { |
|
2814 // iEngine->FileBrowserUI()->ShowErrorNote(_L("Unknown error occured")); |
|
2815 // } |
|
2816 // #else |
|
2817 // aEnable = aEnable; |
|
2818 // iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in S60 3.0"), _L("")); |
|
2819 // #endif |
|
2820 // |
|
2821 // } |
|
2822 |
|
2823 // -------------------------------------------------------------------------------------------- |
|
2824 |
|
2825 void CFileBrowserFileUtils::SimulateLeaveL(TInt aLeaveCode) |
|
2826 { |
|
2827 User::Leave(aLeaveCode); |
|
2828 } |
|
2829 |
|
2830 // -------------------------------------------------------------------------------------------- |
|
2831 |
|
2832 void CFileBrowserFileUtils::SimulatePanicL(const TDesC& aPanicCategory, TInt aPanicCode) |
|
2833 { |
|
2834 User::Panic(aPanicCategory, aPanicCode); |
|
2835 } |
|
2836 |
|
2837 // -------------------------------------------------------------------------------------------- |
|
2838 |
|
2839 void CFileBrowserFileUtils::SimulateExceptionL(TInt aExceptionCode) |
|
2840 { |
|
2841 User::RaiseException((TExcType)aExceptionCode); |
|
2842 } |
|
2843 |
|
2844 // -------------------------------------------------------------------------------------------- |
|
2845 |
|
2846 TUint32 CFileBrowserFileUtils::GetDebugMask() |
|
2847 { |
|
2848 return UserSvr::DebugMask(); |
|
2849 } |
|
2850 |
|
2851 // -------------------------------------------------------------------------------------------- |
|
2852 |
|
2853 void CFileBrowserFileUtils::SetDebugMaskL(TUint32 aDbgMask) |
|
2854 { |
|
2855 User::SetDebugMask(aDbgMask); |
|
2856 } |
|
2857 |
|
2858 // -------------------------------------------------------------------------------------------- |
|
2859 |
|
2860 void CFileBrowserFileUtils::WriteAllAppsL() |
|
2861 { |
|
2862 _LIT(KAllAppsFileName, "AllApps.txt"); |
|
2863 TFileName allAppsPath = PathInfo::PhoneMemoryRootPath(); |
|
2864 allAppsPath.Append(KAllAppsFileName); |
|
2865 |
|
2866 RFile file; |
|
2867 if (file.Replace(iFs, allAppsPath, EFileWrite) == KErrNone) |
|
2868 { |
|
2869 CleanupClosePushL(file); |
|
2870 |
|
2871 CDesC8Array* appsArray = new(ELeave) CDesC8ArrayFlat(192); |
|
2872 CleanupStack::PushL(appsArray); |
|
2873 |
|
2874 TBuf8<KMaxFileName> fileEntry; |
|
2875 TBuf8<KMaxFileName> appFullPath; |
|
2876 _LIT8(KAppEntryFormat, "%S (0x%08X)%S"); |
|
2877 TApaAppInfo appInfo; |
|
2878 |
|
2879 iEngine->LsSession().GetAllApps(); |
|
2880 |
|
2881 while (iEngine->LsSession().GetNextApp(appInfo) == KErrNone) |
|
2882 { |
|
2883 appFullPath.Copy(appInfo.iFullName); |
|
2884 fileEntry.Format(KAppEntryFormat, &appFullPath, appInfo.iUid, &KFileNewLine); |
|
2885 appsArray->AppendL(fileEntry); |
|
2886 } |
|
2887 |
|
2888 appsArray->Sort(); |
|
2889 |
|
2890 for (TInt i=0; i<appsArray->Count(); i++) |
|
2891 { |
|
2892 file.Write(appsArray->MdcaPoint(i)); |
|
2893 } |
|
2894 |
|
2895 CleanupStack::PopAndDestroy(2); //appsArray, file |
|
2896 |
|
2897 _LIT(KMessage, "App list written to %S"); |
|
2898 TFileName noteMsg; |
|
2899 noteMsg.Format(KMessage, &allAppsPath); |
|
2900 |
|
2901 iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, ETrue); // NoTimeout |
|
2902 } |
|
2903 else |
|
2904 { |
|
2905 _LIT(KMessage, "Failed writing to %S"); |
|
2906 TFileName noteMsg; |
|
2907 noteMsg.Format(KMessage, &allAppsPath); |
|
2908 |
|
2909 iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout |
|
2910 } |
|
2911 } |
|
2912 |
|
2913 // -------------------------------------------------------------------------------------------- |
|
2914 |
|
2915 void CFileBrowserFileUtils::WriteAllFilesL() |
|
2916 { |
|
2917 _LIT(KAllFilesFileName, "AllFiles.txt"); |
|
2918 TFileName allFilesPath = PathInfo::PhoneMemoryRootPath(); |
|
2919 allFilesPath.Append(KAllFilesFileName); |
|
2920 |
|
2921 RFile file; |
|
2922 if (file.Replace(iFs, allFilesPath, EFileWrite) == KErrNone) |
|
2923 { |
|
2924 CleanupClosePushL(file); |
|
2925 iFindFileEntryList->Reset(); |
|
2926 |
|
2927 iEngine->FileBrowserUI()->ShowWaitDialog(_L("Generating")); |
|
2928 |
|
2929 for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
2930 { |
|
2931 TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
2932 |
|
2933 TBuf<10> driveRoot; |
|
2934 driveRoot.Append(driveEntry.iLetter); |
|
2935 driveRoot.Append(_L(":\\")); |
|
2936 |
|
2937 // current dir |
|
2938 DoFindFiles(_L("*"), driveRoot); |
|
2939 |
|
2940 // recurse into sub directories |
|
2941 DoFindFilesRecursiveL(_L("*"), driveRoot); |
|
2942 } |
|
2943 |
|
2944 // write entries |
|
2945 TBuf8<KMaxFileName> writeBuf; |
|
2946 for (TInt i=0; i<iFindFileEntryList->Count(); i++) |
|
2947 { |
|
2948 TFileEntry fileEntry = iFindFileEntryList->At(i); |
|
2949 |
|
2950 writeBuf.Copy(fileEntry.iPath); |
|
2951 writeBuf.Append(fileEntry.iEntry.iName); |
|
2952 writeBuf.Append(_L(",")); |
|
2953 writeBuf.AppendNum(fileEntry.iEntry.iSize); |
|
2954 writeBuf.Append(_L(" B")); |
|
2955 |
|
2956 // // date |
|
2957 // TTime entryModified = fileEntry.iEntry.iModified; |
|
2958 // // convert from universal time |
|
2959 // if ( iTz.ConvertToLocalTime( entryModified ) == KErrNone ) |
|
2960 // { |
|
2961 // entryModified = fileEntry.iEntry.iModified; // use universal time |
|
2962 // } |
|
2963 // |
|
2964 // _LIT(KDateFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3"); |
|
2965 // TBuf<32> dateBuf; |
|
2966 // entryModified.FormatL(dateBuf, KDateFormat); |
|
2967 // writeBuf.Append(dateBuf); |
|
2968 // |
|
2969 // writeBuf.Append(_L(" ")); |
|
2970 // // time |
|
2971 // _LIT(KTimeFormat, "%-B%:0%J%:1%T%:2%S%:3%+B"); |
|
2972 // TBuf<32> timeBuf; |
|
2973 // entryModified.FormatL(timeBuf, KTimeFormat); |
|
2974 // writeBuf.Append(timeBuf); |
|
2975 // |
|
2976 writeBuf.Append(KFileNewLine); |
|
2977 file.Write(writeBuf); |
|
2978 } |
|
2979 |
|
2980 iEngine->FileBrowserUI()->CancelWaitDialog(); |
|
2981 |
|
2982 CleanupStack::PopAndDestroy(); //file |
|
2983 iFindFileEntryList->Reset(); |
|
2984 |
|
2985 _LIT(KMessage, "File list written to %S"); |
|
2986 TFileName noteMsg; |
|
2987 noteMsg.Format(KMessage, &allFilesPath); |
|
2988 |
|
2989 iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, EFalse); // NoTimeout |
|
2990 } |
|
2991 else |
|
2992 { |
|
2993 _LIT(KMessage, "Failed writing to %S"); |
|
2994 TFileName noteMsg; |
|
2995 noteMsg.Format(KMessage, &allFilesPath); |
|
2996 |
|
2997 iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout |
|
2998 } |
|
2999 } |
|
3000 |
|
3001 // -------------------------------------------------------------------------------------------- |
|
3002 |
|
3003 TInt CFileBrowserFileUtils::DoFindFiles(const TDesC& aFileName, const TDesC& aPath) |
|
3004 { |
|
3005 TFindFile fileFinder(iFs); |
|
3006 CDir* dir; |
|
3007 TInt err = fileFinder.FindWildByPath(aFileName, &aPath, dir); |
|
3008 |
|
3009 while (err == KErrNone && iAllowProcessing) |
|
3010 { |
|
3011 iEngine->FileBrowserUI()->ProcessEvents(); |
|
3012 for (TInt i=0; i<dir->Count(); i++) |
|
3013 { |
|
3014 TEntry entry = (*dir)[i]; |
|
3015 |
|
3016 // ignore any directory entries |
|
3017 if (!entry.IsDir() && entry.iName.Length() && aPath.Length()) |
|
3018 { |
|
3019 TParse parsedName; |
|
3020 parsedName.Set(entry.iName, &fileFinder.File(), NULL); |
|
3021 |
|
3022 if (parsedName.Drive().Length() && aPath.Length() && parsedName.Drive()[0] == aPath[0]) |
|
3023 { |
|
3024 TFileEntry fileEntry; |
|
3025 fileEntry.iPath = parsedName.DriveAndPath(); |
|
3026 fileEntry.iEntry = entry; |
|
3027 fileEntry.iDirEntries = KErrNotFound; |
|
3028 fileEntry.iIconId = EFixedIconEmpty; |
|
3029 |
|
3030 TRAP(err, iFindFileEntryList->AppendL(fileEntry)); |
|
3031 } |
|
3032 } |
|
3033 } |
|
3034 |
|
3035 delete dir; |
|
3036 dir = NULL; |
|
3037 err = fileFinder.FindWild(dir); |
|
3038 } |
|
3039 |
|
3040 return err; |
|
3041 } |
|
3042 |
|
3043 // -------------------------------------------------------------------------------------------- |
|
3044 |
|
3045 TInt CFileBrowserFileUtils::DoFindFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath) |
|
3046 { |
|
3047 TInt err(KErrNone); |
|
3048 CDirScan* scan = CDirScan::NewLC(iFs); |
|
3049 scan->SetScanDataL(aPath, KEntryAttDir|KEntryAttMatchMask, ESortByName | EAscending | EDirsFirst); |
|
3050 CDir* dir = NULL; |
|
3051 |
|
3052 for(;;) |
|
3053 { |
|
3054 TRAP(err, scan->NextL(dir)); |
|
3055 if (!dir || (err != KErrNone)) |
|
3056 break; |
|
3057 |
|
3058 for (TInt i=0; i<dir->Count(); i++) |
|
3059 { |
|
3060 TEntry entry = (*dir)[i]; |
|
3061 |
|
3062 if (entry.IsDir()) |
|
3063 { |
|
3064 TFileName path(scan->FullPath()); |
|
3065 |
|
3066 if (path.Length()) |
|
3067 { |
|
3068 path.Append(entry.iName); |
|
3069 path.Append(_L("\\")); |
|
3070 DoFindFiles(aFileName, path); |
|
3071 } |
|
3072 } |
|
3073 } |
|
3074 delete(dir); |
|
3075 } |
|
3076 |
|
3077 CleanupStack::PopAndDestroy(scan); |
|
3078 return err; |
|
3079 } |
|
3080 |
|
3081 // -------------------------------------------------------------------------------------------- |
|
3082 |
|
3083 void CFileBrowserFileUtils::ListOpenFilesL() |
|
3084 { |
|
3085 iFileEntryList->Reset(); |
|
3086 |
|
3087 CFileList* dir = NULL; |
|
3088 TOpenFileScan fileScan(iFs); |
|
3089 fileScan.NextL(dir); |
|
3090 |
|
3091 while (dir) |
|
3092 { |
|
3093 for (TInt i=0; i<dir->Count(); i++) |
|
3094 { |
|
3095 TEntry entry = (*dir)[i]; |
|
3096 TFileName fullPath; |
|
3097 |
|
3098 // TOpenFileScan does not return drive letters for the entries, so try to guess it |
|
3099 if (entry.iName.Length() > 2 && entry.iName[1] != ':') |
|
3100 { |
|
3101 for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
3102 { |
|
3103 TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
3104 |
|
3105 TFileName guessPath; |
|
3106 guessPath.Append(driveEntry.iLetter); |
|
3107 guessPath.Append(_L(":")); |
|
3108 guessPath.Append(entry.iName); |
|
3109 |
|
3110 // check if the file exists |
|
3111 if (BaflUtils::FileExists(iFs, guessPath)) |
|
3112 { |
|
3113 // if it's on read only drive, then take it or check if it's really in use |
|
3114 TBool readOnlyDrive(ETrue); |
|
3115 BaflUtils::DiskIsReadOnly(iFs, guessPath, readOnlyDrive); |
|
3116 |
|
3117 if (readOnlyDrive || iFs.SetEntry(guessPath, entry.iModified, NULL, NULL) == KErrInUse) |
|
3118 { |
|
3119 fullPath = guessPath; |
|
3120 break; |
|
3121 } |
|
3122 } |
|
3123 } |
|
3124 } |
|
3125 else |
|
3126 { |
|
3127 fullPath = entry.iName; |
|
3128 } |
|
3129 |
|
3130 TParse nameParser; |
|
3131 if (fullPath.Length() && nameParser.SetNoWild(fullPath, NULL, NULL) == KErrNone) |
|
3132 { |
|
3133 entry.iName = nameParser.NameAndExt(); |
|
3134 |
|
3135 TFileEntry fileEntry; |
|
3136 fileEntry.iPath = nameParser.DriveAndPath(); |
|
3137 fileEntry.iEntry = entry; |
|
3138 fileEntry.iDirEntries = KErrNotFound; |
|
3139 fileEntry.iIconId = EFixedIconEmpty; |
|
3140 |
|
3141 iFileEntryList->AppendL(fileEntry); |
|
3142 } |
|
3143 } |
|
3144 |
|
3145 delete dir; |
|
3146 dir = NULL; |
|
3147 fileScan.NextL(dir); |
|
3148 } |
|
3149 |
|
3150 TInt operations = iFileEntryList->Count(); |
|
3151 |
|
3152 iListingMode = EOpenFiles; |
|
3153 // TODO |
|
3154 //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0); |
|
3155 RefreshViewL(); |
|
3156 |
|
3157 _LIT(KMessage, "%d open files found"); |
|
3158 TFileName noteMsg; |
|
3159 noteMsg.Format(KMessage, operations); |
|
3160 |
|
3161 iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
3162 } |
|
3163 |
|
3164 // -------------------------------------------------------------------------------------------- |
|
3165 |
|
3166 void CFileBrowserFileUtils::ListMessageAttachmentsL(TInt aType) |
|
3167 { |
|
3168 iFileEntryList->Reset(); |
|
3169 |
|
3170 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
3171 CleanupStack::PushL(session); |
|
3172 |
|
3173 CMsvEntry* context = NULL; |
|
3174 |
|
3175 if (aType == EFileBrowserCmdToolsMsgAttachmentsInbox) |
|
3176 context = session->GetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
3177 else if (aType == EFileBrowserCmdToolsMsgAttachmentsDrafts) |
|
3178 context = session->GetEntryL(KMsvDraftEntryId); |
|
3179 else if (aType == EFileBrowserCmdToolsMsgAttachmentsSentItems) |
|
3180 context = session->GetEntryL(KMsvSentEntryId); |
|
3181 else if (aType == EFileBrowserCmdToolsMsgAttachmentsOutbox) |
|
3182 context = session->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
3183 else |
|
3184 User::Panic(_L("MsgAtt.Mode"), 100); |
|
3185 |
|
3186 CleanupStack::PushL(context); |
|
3187 |
|
3188 CDesCArray* attPaths = new(ELeave) CDesCArrayFlat(128); |
|
3189 CleanupStack::PushL(attPaths); |
|
3190 |
|
3191 // read attachment paths |
|
3192 ReadAttachmentPathsRecursiveL(session, context, attPaths); |
|
3193 |
|
3194 // create file entries of the paths |
|
3195 for (TInt i=0; i<attPaths->MdcaCount(); i++) |
|
3196 { |
|
3197 TFileEntry fileEntry; |
|
3198 TEntry entry; |
|
3199 TParse nameParser; |
|
3200 |
|
3201 if (attPaths->MdcaPoint(i).Length() && |
|
3202 nameParser.SetNoWild(attPaths->MdcaPoint(i), NULL, NULL) == KErrNone && |
|
3203 iFs.Entry(attPaths->MdcaPoint(i), entry) == KErrNone) |
|
3204 { |
|
3205 TFileEntry fileEntry; |
|
3206 fileEntry.iPath = nameParser.DriveAndPath(); |
|
3207 fileEntry.iEntry = entry; |
|
3208 fileEntry.iDirEntries = KErrNotFound; |
|
3209 fileEntry.iIconId = EFixedIconEmpty; |
|
3210 |
|
3211 iFileEntryList->AppendL(fileEntry); |
|
3212 } |
|
3213 } |
|
3214 |
|
3215 CleanupStack::PopAndDestroy(3); //session, context, attPaths |
|
3216 |
|
3217 TInt operations = iFileEntryList->Count(); |
|
3218 |
|
3219 if (aType == EFileBrowserCmdToolsMsgAttachmentsInbox) |
|
3220 iListingMode = EMsgAttachmentsInbox; |
|
3221 else if (aType == EFileBrowserCmdToolsMsgAttachmentsDrafts) |
|
3222 iListingMode = EMsgAttachmentsDrafts; |
|
3223 else if (aType == EFileBrowserCmdToolsMsgAttachmentsSentItems) |
|
3224 iListingMode = EMsgAttachmentsSentItems; |
|
3225 else if (aType == EFileBrowserCmdToolsMsgAttachmentsOutbox) |
|
3226 iListingMode = EMsgAttachmentsOutbox; |
|
3227 |
|
3228 // TODO |
|
3229 //iEngine->FileListContainer()->ListBox()->SetCurrentItemIndex(0); |
|
3230 RefreshViewL(); |
|
3231 |
|
3232 _LIT(KMessage, "%d files found"); |
|
3233 TFileName noteMsg; |
|
3234 noteMsg.Format(KMessage, operations); |
|
3235 |
|
3236 iEngine->FileBrowserUI()->ShowInformationNote(noteMsg, _L("")); |
|
3237 } |
|
3238 |
|
3239 // -------------------------------------------------------------------------------------------- |
|
3240 |
|
3241 void CFileBrowserFileUtils::ReadAttachmentPathsRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, CDesCArray* aAttPaths) |
|
3242 { |
|
3243 CMsvEntrySelection* entrySelection = aContext->ChildrenL(); |
|
3244 CleanupStack::PushL(entrySelection); |
|
3245 |
|
3246 for (TInt i=0; i<entrySelection->Count(); i++) |
|
3247 { |
|
3248 CMsvEntry* entry = aSession->GetEntryL((*entrySelection)[i]); |
|
3249 CleanupStack::PushL(entry); |
|
3250 |
|
3251 CMsvStore* store = NULL; |
|
3252 TRAPD(err, store = entry->ReadStoreL()); |
|
3253 |
|
3254 if (err == KErrNone) |
|
3255 { |
|
3256 CleanupStack::PushL(store); |
|
3257 |
|
3258 for (TInt j=0; j<store->AttachmentManagerL().AttachmentCount(); j++) |
|
3259 { |
|
3260 CMsvAttachment* attachment = store->AttachmentManagerL().GetAttachmentInfoL(j); |
|
3261 CleanupStack::PushL(attachment); |
|
3262 |
|
3263 aAttPaths->AppendL(attachment->FilePath()); |
|
3264 |
|
3265 CleanupStack::PopAndDestroy(); //attachment |
|
3266 } |
|
3267 CleanupStack::PopAndDestroy(); // store |
|
3268 } |
|
3269 |
|
3270 // recurse into children |
|
3271 if (entry->Count() > 0) |
|
3272 { |
|
3273 ReadAttachmentPathsRecursiveL(aSession, entry, aAttPaths); |
|
3274 } |
|
3275 |
|
3276 CleanupStack::PopAndDestroy(); // entry |
|
3277 } |
|
3278 } |
|
3279 |
|
3280 // -------------------------------------------------------------------------------------------- |
|
3281 |
|
3282 void CFileBrowserFileUtils::WriteMsgStoreWalkL() |
|
3283 { |
|
3284 _LIT(KAllAppsFileName, "MsgStoreWalk.txt"); |
|
3285 TFileName allAppsPath = PathInfo::PhoneMemoryRootPath(); |
|
3286 allAppsPath.Append(KAllAppsFileName); |
|
3287 |
|
3288 if (iMsgStoreWalkFile.Replace(iFs, allAppsPath, EFileWrite) == KErrNone) |
|
3289 { |
|
3290 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
3291 CleanupStack::PushL(session); |
|
3292 |
|
3293 CMsvEntry* context = session->GetEntryL(KMsvRootIndexEntryId); |
|
3294 CleanupStack::PushL(context); |
|
3295 |
|
3296 iMsgStoreWalkFile.Write(_L8("id service_id related_id type mtm date size error biotype mtmdata1 mtmdata2 mtmdata3 description details\r\n\r\n")); |
|
3297 |
|
3298 // write details about the root entry |
|
3299 DoWriteMessageEntryInfoL(context, iMsgStoreWalkFile, 0); |
|
3300 |
|
3301 // get and write info recursively |
|
3302 TInt level(1); |
|
3303 WriteMessageEntryInfoRecursiveL(session, context, iMsgStoreWalkFile, level); |
|
3304 |
|
3305 CleanupStack::PopAndDestroy(2); //session, context |
|
3306 |
|
3307 iMsgStoreWalkFile.Flush(); |
|
3308 iMsgStoreWalkFile.Close(); |
|
3309 |
|
3310 _LIT(KMessage, "Msg. store walk written to %S"); |
|
3311 TFileName noteMsg; |
|
3312 noteMsg.Format(KMessage, &allAppsPath); |
|
3313 |
|
3314 iEngine->FileBrowserUI()->ShowConfirmationNote(noteMsg, ETrue); // NoTimeout |
|
3315 } |
|
3316 else |
|
3317 { |
|
3318 _LIT(KMessage, "Failed writing to %S"); |
|
3319 TFileName noteMsg; |
|
3320 noteMsg.Format(KMessage, &allAppsPath); |
|
3321 |
|
3322 iEngine->FileBrowserUI()->ShowErrorNote(noteMsg, ETrue); // NoTimeout |
|
3323 } |
|
3324 } |
|
3325 |
|
3326 // -------------------------------------------------------------------------------------------- |
|
3327 |
|
3328 void CFileBrowserFileUtils::WriteMessageEntryInfoRecursiveL(CMsvSession* aSession, CMsvEntry* aContext, RFile& aFile, TInt& aLevel) |
|
3329 { |
|
3330 CMsvEntrySelection* entrySelection = aContext->ChildrenL(); |
|
3331 CleanupStack::PushL(entrySelection); |
|
3332 |
|
3333 for (TInt i=0; i<entrySelection->Count(); i++) |
|
3334 { |
|
3335 CMsvEntry* entry = aSession->GetEntryL((*entrySelection)[i]); |
|
3336 CleanupStack::PushL(entry); |
|
3337 |
|
3338 DoWriteMessageEntryInfoL(entry, aFile, aLevel); |
|
3339 |
|
3340 // recurse into children |
|
3341 if (entry->Count() > 0) |
|
3342 { |
|
3343 aLevel++; |
|
3344 WriteMessageEntryInfoRecursiveL(aSession, entry, aFile, aLevel); |
|
3345 aLevel--; |
|
3346 } |
|
3347 |
|
3348 CleanupStack::PopAndDestroy(); // entry |
|
3349 } |
|
3350 } |
|
3351 |
|
3352 // -------------------------------------------------------------------------------------------- |
|
3353 |
|
3354 void CFileBrowserFileUtils::DoWriteMessageEntryInfoL(CMsvEntry* aContext, RFile& aFile, TInt aLevel) |
|
3355 { |
|
3356 TMsvEntry messageEntry = aContext->Entry(); |
|
3357 |
|
3358 for (TInt j=0; j<aLevel; j++) |
|
3359 { |
|
3360 aFile.Write(_L8(" ")); |
|
3361 } |
|
3362 |
|
3363 TBuf8<256> desc; |
|
3364 desc.Copy(messageEntry.iDescription); |
|
3365 |
|
3366 TBuf8<256> details; |
|
3367 details.Copy(messageEntry.iDetails); |
|
3368 |
|
3369 _LIT8(KLine, "-> %d %d %d %d %d %Ld %d %d %d %d %d %d %S %S\r\n"); |
|
3370 TBuf8<1024> buf; |
|
3371 buf.Format(KLine, messageEntry.Id(), messageEntry.iServiceId, messageEntry.iRelatedId, messageEntry.iType.iUid, |
|
3372 messageEntry.iMtm.iUid, messageEntry.iDate.Int64(), messageEntry.iSize, messageEntry.iError, messageEntry.iBioType, |
|
3373 messageEntry.iMtmData1, messageEntry.iMtmData2, messageEntry.iMtmData3, &desc, &details); |
|
3374 |
|
3375 aFile.Write(buf); |
|
3376 } |
|
3377 |
|
3378 // -------------------------------------------------------------------------------------------- |
|
3379 |
|
3380 void CFileBrowserFileUtils::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
3381 { |
|
3382 } |
|
3383 |
|
3384 // -------------------------------------------------------------------------------------------- |
|
3385 |
|
3386 void CFileBrowserFileUtils::FileEditorL(TInt aCurrentItemIndex, TInt /*aType*/) |
|
3387 { |
|
3388 // TODO |
|
3389 // just get current item |
|
3390 //TInt currentItemIndex = iEngine->QueryCurrentItemIndex(); |
|
3391 |
|
3392 if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0) |
|
3393 { |
|
3394 TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex); |
|
3395 |
|
3396 // only valid for files |
|
3397 if (!fileEntry.iEntry.IsDir()) |
|
3398 { |
|
3399 TFileName fullPath = fileEntry.iPath; |
|
3400 fullPath.Append(fileEntry.iEntry.iName); |
|
3401 |
|
3402 // iEngine->FileListContainer()->SetNaviPaneTextL(fileEntry.iEntry.iName); |
|
3403 // |
|
3404 // TInt editorMode(0); |
|
3405 // |
|
3406 // if (aType == EFileBrowserCmdFileViewText) |
|
3407 // editorMode = EFileEditorViewAsText; |
|
3408 // else if (aType == EFileBrowserCmdFileViewHex) |
|
3409 // editorMode = EFileEditorViewAsHex; |
|
3410 // else if (aType == EFileBrowserCmdFileEditText) |
|
3411 // editorMode = EFileEditorEditAsText; |
|
3412 // else if (aType == EFileBrowserCmdFileEditHex) |
|
3413 // editorMode = EFileEditorEditAsHex; |
|
3414 // else |
|
3415 // User::Panic(_L("Inv.Ed.Mode"), 843); |
|
3416 // |
|
3417 // // launch dialog |
|
3418 // CFileBrowserFileEditorDlg* dlg = CFileBrowserFileEditorDlg::NewL(fullPath, editorMode); |
|
3419 // dlg->RunDlgLD(); |
|
3420 // |
|
3421 // iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
3422 // |
|
3423 // if (aType == EFileBrowserCmdFileEditText || aType == EFileBrowserCmdFileEditHex) |
|
3424 // { |
|
3425 // RefreshViewL(); |
|
3426 // } |
|
3427 } |
|
3428 } |
|
3429 } |
|
3430 |
|
3431 // -------------------------------------------------------------------------------------------- |
|
3432 |
|
3433 TBool CFileBrowserFileUtils::DriveSnapShotPossible() |
|
3434 { |
|
3435 // // TODO |
|
3436 // // check that E-drive is available |
|
3437 // TBool EDriveIsOK(EFalse); |
|
3438 // |
|
3439 // for (TInt i=0; i<iDriveEntryList->Count(); i++) |
|
3440 // { |
|
3441 // TDriveEntry driveEntry = iDriveEntryList->At(i); |
|
3442 // |
|
3443 // if (driveEntry.iNumber == EDriveE) |
|
3444 // { |
|
3445 // if (driveEntry.iVolumeInfo.iDrive.iMediaAtt & KMediaAttLocked || driveEntry.iVolumeInfo.iDrive.iDriveAtt & KDriveAbsent) |
|
3446 // EDriveIsOK = EFalse; |
|
3447 // else |
|
3448 // EDriveIsOK = ETrue; |
|
3449 // } |
|
3450 // } |
|
3451 // |
|
3452 // if (!EDriveIsOK) |
|
3453 // return EFalse; |
|
3454 // |
|
3455 // // get current item |
|
3456 // TInt currentItemIndex = iEngine->QueryCurrentItemIndex(); |
|
3457 // |
|
3458 // if (iDriveEntryList->Count() > currentItemIndex && currentItemIndex >= 0) |
|
3459 // { |
|
3460 // TDriveEntry driveEntry = iDriveEntryList->At(currentItemIndex); |
|
3461 // |
|
3462 // // drive snapshot not possible when E-drive is highlighted, since that's where we are copying |
|
3463 // if (driveEntry.iNumber == EDriveE) |
|
3464 // return EFalse; |
|
3465 // else |
|
3466 // return ETrue; |
|
3467 // } |
|
3468 return EFalse; |
|
3469 } |
|
3470 |
|
3471 // -------------------------------------------------------------------------------------------- |
|
3472 |
|
3473 void CFileBrowserFileUtils::DriveSnapShotL() |
|
3474 { |
|
3475 // if (iEngine->Settings().iBypassPlatformSecurity) |
|
3476 // { |
|
3477 // // get current item |
|
3478 // TInt currentItemIndex = iEngine->QueryCurrentItemIndex(); |
|
3479 // |
|
3480 // if (iDriveEntryList->Count() > currentItemIndex && currentItemIndex >= 0) |
|
3481 // { |
|
3482 // TDriveEntry driveEntry = iDriveEntryList->At(currentItemIndex); |
|
3483 // |
|
3484 // TChar sourceDriveLetter = driveEntry.iLetter; |
|
3485 // TChar targetDriveLetter = 'E'; // hardcoded drive letter, could be better if would be queried from the user |
|
3486 // |
|
3487 // // append to the command array |
|
3488 // AppendToCommandArrayL(EFileBrowserFileOpCommandDriveSnapShot, |
|
3489 // new(ELeave)CCommandParamsDriveSnapShot(sourceDriveLetter, targetDriveLetter) |
|
3490 // ); |
|
3491 // |
|
3492 // // execute the operation |
|
3493 // StartExecutingCommandsL(_L("Copying")); |
|
3494 // } |
|
3495 // } |
|
3496 // else |
|
3497 // { |
|
3498 // iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L("")); |
|
3499 // } |
|
3500 } |
|
3501 |
|
3502 // -------------------------------------------------------------------------------------------- |
|
3503 |
|
3504 void CFileBrowserFileUtils::SetDrivePasswordL(TInt aIndex, |
|
3505 const TFileName &aOldPassword, |
|
3506 const TFileName &aNewPassword) |
|
3507 { |
|
3508 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3509 { |
|
3510 TMediaPassword oldPassword; |
|
3511 TMediaPassword newPassword; |
|
3512 |
|
3513 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3514 |
|
3515 ConvertCharsToPwd(aOldPassword, oldPassword); |
|
3516 ConvertCharsToPwd(aNewPassword, newPassword); |
|
3517 |
|
3518 // set the password, does not actually lock the drive |
|
3519 User::LeaveIfError(iFs.LockDrive(driveEntry.iNumber, oldPassword, newPassword, ETrue)); |
|
3520 } |
|
3521 } |
|
3522 |
|
3523 // -------------------------------------------------------------------------------------------- |
|
3524 |
|
3525 void CFileBrowserFileUtils::UnlockDriveL(TInt aIndex, const TFileName &aOldPassword) |
|
3526 { |
|
3527 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3528 { |
|
3529 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3530 |
|
3531 TMediaPassword oldPassword; |
|
3532 ConvertCharsToPwd(aOldPassword, oldPassword); |
|
3533 |
|
3534 // unlock the drive |
|
3535 User::LeaveIfError(iFs.UnlockDrive(driveEntry.iNumber, oldPassword, ETrue)); |
|
3536 } |
|
3537 } |
|
3538 |
|
3539 // -------------------------------------------------------------------------------------------- |
|
3540 |
|
3541 void CFileBrowserFileUtils::ClearDrivePasswordL(TInt aIndex, const TFileName &aOldPassword) |
|
3542 { |
|
3543 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3544 { |
|
3545 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3546 |
|
3547 TMediaPassword oldPassword; |
|
3548 |
|
3549 ConvertCharsToPwd(aOldPassword, oldPassword); |
|
3550 |
|
3551 // clear the password from the drive |
|
3552 User::LeaveIfError(iFs.ClearPassword(driveEntry.iNumber, oldPassword)); |
|
3553 } |
|
3554 } |
|
3555 |
|
3556 // -------------------------------------------------------------------------------------------- |
|
3557 |
|
3558 void CFileBrowserFileUtils::EraseDrivePasswordL(TInt aIndex) |
|
3559 { |
|
3560 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3561 { |
|
3562 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3563 |
|
3564 // erase the password from the drive |
|
3565 User::LeaveIfError(iFs.ErasePassword(driveEntry.iNumber)); |
|
3566 } |
|
3567 } |
|
3568 |
|
3569 // -------------------------------------------------------------------------------------------- |
|
3570 |
|
3571 void CFileBrowserFileUtils::FormatDriveL(TInt aIndex, TBool aQuickFormat) |
|
3572 { |
|
3573 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3574 { |
|
3575 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3576 |
|
3577 TInt err(KErrNone); |
|
3578 TInt formatCount(0); |
|
3579 |
|
3580 TBuf<10> driveRoot; |
|
3581 driveRoot.Append(driveEntry.iLetter); |
|
3582 driveRoot.Append(_L(":")); |
|
3583 |
|
3584 TUint formatMode(0); |
|
3585 if (aQuickFormat) |
|
3586 formatMode = ESpecialFormat|EQuickFormat; |
|
3587 else |
|
3588 formatMode = ESpecialFormat|EFullFormat; |
|
3589 |
|
3590 // set as system application to prevent getting shut down events |
|
3591 iEngine->EikonEnv()->SetSystem(ETrue); |
|
3592 |
|
3593 // first close any open applications |
|
3594 CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL(); |
|
3595 CleanupStack::PushL(BSWrapper); |
|
3596 |
|
3597 TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
3598 BSWrapper->NotifyBackupOperationL(atts); |
|
3599 |
|
3600 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
3601 BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus ); |
|
3602 waiter->StartAndWait(); |
|
3603 CleanupStack::PopAndDestroy(); //waiter |
|
3604 |
|
3605 // some delay to make sure all applications have been closed |
|
3606 User::After(1000000); |
|
3607 |
|
3608 // format the drive |
|
3609 RFormat format; |
|
3610 err = format.Open(iFs, driveRoot, formatMode, formatCount); |
|
3611 |
|
3612 // Forced format for locked card |
|
3613 if ( err == KErrLocked ) |
|
3614 { |
|
3615 // Erase password and try again |
|
3616 err = iFs.ErasePassword( driveEntry.iNumber ); |
|
3617 if ( !err ) |
|
3618 { |
|
3619 err = format.Open(iFs, driveRoot, formatMode, formatCount); |
|
3620 } |
|
3621 } |
|
3622 |
|
3623 if( err != KErrNone && err != KErrLocked ) |
|
3624 { |
|
3625 // CAknQueryDialog* lockQuery = CAknQueryDialog::NewL(); |
|
3626 // if ( lockQuery->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, _L("Memory card in use by other application. Proceed anyway?"))) |
|
3627 // TODO Dialog should be opened in UI part |
|
3628 if (iEngine->FileBrowserUI()->ShowConfirmationQuery(_L("Memory card in use by other application. Proceed anyway?"))) |
|
3629 { |
|
3630 // If format could not be started, someone is still keeping |
|
3631 // files open on media. Let's try to dismount file system, then |
|
3632 // remount with own extension embedded and try again. |
|
3633 |
|
3634 TFullName fsName; |
|
3635 err = iFs.FileSystemName( fsName, driveEntry.iNumber ); |
|
3636 |
|
3637 if ( err == KErrNone && fsName.Length() > 0 ) |
|
3638 { |
|
3639 // Prevent SysAp shutting down applications |
|
3640 RProperty::Set( |
|
3641 KPSUidCoreApplicationUIs, |
|
3642 KCoreAppUIsMmcRemovedWithoutEject, |
|
3643 ECoreAppUIsEjectCommandUsed ); |
|
3644 |
|
3645 TRequestStatus stat; |
|
3646 iFs.NotifyDismount( driveEntry.iNumber, stat, EFsDismountForceDismount ); |
|
3647 User::WaitForRequest( stat ); |
|
3648 |
|
3649 // Unfortunately, at the moment we have to wait until clients have received |
|
3650 // notification about card dismount. Otherwise at least causes problems with |
|
3651 // theme selected from card. In future clients should use new notify-API. |
|
3652 User::After( KForcedFormatTimeout ); |
|
3653 |
|
3654 // Let's set priority higher than normally. This is done to decrease the chance |
|
3655 // that someone reopens files on memory card after mandatory file system |
|
3656 // remounting hence preventing formatting again. |
|
3657 TThreadPriority priority( RThread().Priority() ); |
|
3658 RThread().SetPriority( EPriorityAbsoluteHigh ); |
|
3659 |
|
3660 // Mount file system back... |
|
3661 err = iFs.MountFileSystem( fsName, driveEntry.iNumber ); |
|
3662 err = format.Open(iFs, driveRoot, formatMode, formatCount); |
|
3663 RThread().SetPriority( priority ); |
|
3664 } |
|
3665 } |
|
3666 } |
|
3667 |
|
3668 |
|
3669 if (err == KErrNone) |
|
3670 { |
|
3671 // needs to be implemented with active objects |
|
3672 // CAknProgressDialog* dlg = new(ELeave) CAknProgressDialog(formatCount, 1, 1, NULL); |
|
3673 // dlg->SetTone(CAknNoteDialog::ENoTone); |
|
3674 // dlg->ExecuteLD(R_FORMAT_PROGRESS_NOTE); |
|
3675 |
|
3676 while (formatCount && err == KErrNone) |
|
3677 { |
|
3678 err = format.Next(formatCount); |
|
3679 } |
|
3680 } |
|
3681 |
|
3682 format.Close(); |
|
3683 |
|
3684 // restart closed applications |
|
3685 TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
3686 BSWrapper->NotifyBackupOperationL(atts2); |
|
3687 BSWrapper->RestartAll(); |
|
3688 CleanupStack::PopAndDestroy(); //BSWrapper |
|
3689 |
|
3690 // system status not needed anymore |
|
3691 iEngine->EikonEnv()->SetSystem(EFalse); |
|
3692 |
|
3693 |
|
3694 if (err == KErrNone) |
|
3695 { |
|
3696 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Format succeeded")); |
|
3697 } |
|
3698 else if (err == KErrNotSupported) |
|
3699 { |
|
3700 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive")); |
|
3701 } |
|
3702 else |
|
3703 { |
|
3704 iEngine->FileBrowserUI()->ShowErrorNote(ResolveErrorMessage(err)); |
|
3705 } |
|
3706 |
|
3707 RefreshViewL(); |
|
3708 } |
|
3709 } |
|
3710 |
|
3711 // -------------------------------------------------------------------------------------------- |
|
3712 |
|
3713 void CFileBrowserFileUtils::EraseMBRL(TInt aIndex) |
|
3714 { |
|
3715 // TODO |
|
3716 #ifndef FILEBROWSER_LITE |
|
3717 if (iEngine->Settings().iBypassPlatformSecurity) |
|
3718 { |
|
3719 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3720 { |
|
3721 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3722 |
|
3723 TInt err(KErrNone); |
|
3724 |
|
3725 iEngine->FileBrowserUI()->ShowInformationNote(_L("Please wait, this may take 30 seconds"), _L("")); |
|
3726 |
|
3727 // set as system application to prevent getting shut down events |
|
3728 iEngine->EikonEnv()->SetSystem(ETrue); |
|
3729 |
|
3730 // first close any open applications |
|
3731 CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL(); |
|
3732 CleanupStack::PushL(BSWrapper); |
|
3733 |
|
3734 TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
3735 BSWrapper->NotifyBackupOperationL(atts); |
|
3736 |
|
3737 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
3738 BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus ); |
|
3739 waiter->StartAndWait(); |
|
3740 CleanupStack::PopAndDestroy(); //waiter |
|
3741 |
|
3742 // some delay to make sure all applications have been closed |
|
3743 User::After(1000000); |
|
3744 |
|
3745 |
|
3746 // do the erase MBR operation |
|
3747 err = iFileOps->EraseMBR(driveEntry.iNumber); |
|
3748 |
|
3749 |
|
3750 // restart closed applications |
|
3751 TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
3752 BSWrapper->NotifyBackupOperationL(atts2); |
|
3753 BSWrapper->RestartAll(); |
|
3754 CleanupStack::PopAndDestroy(); //BSWrapper |
|
3755 |
|
3756 // system status not needed anymore |
|
3757 iEngine->EikonEnv()->SetSystem(EFalse); |
|
3758 |
|
3759 |
|
3760 if (err == KErrNone) |
|
3761 { |
|
3762 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Erase MBR succeeded")); |
|
3763 } |
|
3764 else if (err == KErrNotSupported) |
|
3765 { |
|
3766 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive")); |
|
3767 } |
|
3768 else |
|
3769 { |
|
3770 iEngine->FileBrowserUI()->ShowErrorNote(ResolveErrorMessage(err)); |
|
3771 } |
|
3772 |
|
3773 RefreshViewL(); |
|
3774 } |
|
3775 } |
|
3776 else |
|
3777 { |
|
3778 iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L("")); |
|
3779 } |
|
3780 #else |
|
3781 iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L("")); |
|
3782 #endif |
|
3783 } |
|
3784 |
|
3785 // -------------------------------------------------------------------------------------------- |
|
3786 |
|
3787 void CFileBrowserFileUtils::PartitionDriveL(TInt aIndex, TBool aEraseMBR, TInt aAmountOfPartitions) |
|
3788 { |
|
3789 // TODO |
|
3790 #ifndef FILEBROWSER_LITE |
|
3791 if (iEngine->Settings().iBypassPlatformSecurity) |
|
3792 { |
|
3793 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3794 { |
|
3795 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3796 |
|
3797 TInt err(KErrNone); |
|
3798 |
|
3799 iEngine->FileBrowserUI()->ShowInformationNote(_L("Please wait, this may take 30 seconds"), _L("")); |
|
3800 |
|
3801 // set as system application to prevent getting shut down events |
|
3802 iEngine->EikonEnv()->SetSystem(ETrue); |
|
3803 |
|
3804 // first close any open applications |
|
3805 CBaBackupSessionWrapper* BSWrapper = CBaBackupSessionWrapper::NewL(); |
|
3806 CleanupStack::PushL(BSWrapper); |
|
3807 |
|
3808 TBackupOperationAttributes atts(MBackupObserver::EReleaseLockNoAccess, MBackupOperationObserver::EStart); |
|
3809 BSWrapper->NotifyBackupOperationL(atts); |
|
3810 |
|
3811 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
3812 BSWrapper->CloseAll( MBackupObserver::EReleaseLockNoAccess, waiter->iStatus ); |
|
3813 waiter->StartAndWait(); |
|
3814 CleanupStack::PopAndDestroy(); //waiter |
|
3815 |
|
3816 // some delay to make sure all applications have been closed |
|
3817 User::After(1000000); |
|
3818 |
|
3819 // do the erase operation |
|
3820 if (aEraseMBR) |
|
3821 { |
|
3822 err = iFileOps->EraseMBR(driveEntry.iNumber); |
|
3823 |
|
3824 if (err != KErrNone) |
|
3825 { |
|
3826 iEngine->FileBrowserUI()->ShowErrorNote(_L("Erase MBR failed")); |
|
3827 } |
|
3828 |
|
3829 User::After(500000); |
|
3830 } |
|
3831 |
|
3832 |
|
3833 // do the partition operation |
|
3834 err = iFileOps->PartitionDrive(driveEntry.iNumber, aAmountOfPartitions); |
|
3835 |
|
3836 |
|
3837 // restart closed applications |
|
3838 TBackupOperationAttributes atts2(MBackupObserver::ETakeLock, MBackupOperationObserver::EEnd); |
|
3839 BSWrapper->NotifyBackupOperationL(atts2); |
|
3840 BSWrapper->RestartAll(); |
|
3841 CleanupStack::PopAndDestroy(); //BSWrapper |
|
3842 |
|
3843 // system status not needed anymore |
|
3844 iEngine->EikonEnv()->SetSystem(EFalse); |
|
3845 |
|
3846 |
|
3847 if (err == KErrNone) |
|
3848 { |
|
3849 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Partition succeeded")); |
|
3850 } |
|
3851 else if (err == KErrNotSupported) |
|
3852 { |
|
3853 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive")); |
|
3854 } |
|
3855 else |
|
3856 { |
|
3857 iEngine->FileBrowserUI()->ShowErrorNote(ResolveErrorMessage(err)); |
|
3858 } |
|
3859 |
|
3860 RefreshViewL(); |
|
3861 } |
|
3862 } |
|
3863 else |
|
3864 { |
|
3865 iEngine->FileBrowserUI()->ShowInformationNote(_L("Enable \"bypass platform security\" from the settings first"), _L("")); |
|
3866 } |
|
3867 #else |
|
3868 iEngine->FileBrowserUI()->ShowInformationNote(_L("Not supported in lite version"), _L("")); |
|
3869 #endif |
|
3870 } |
|
3871 |
|
3872 // -------------------------------------------------------------------------------------------- |
|
3873 |
|
3874 void CFileBrowserFileUtils::CheckDiskL(TInt aIndex) |
|
3875 { |
|
3876 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3877 { |
|
3878 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3879 |
|
3880 TBuf<10> driveRoot; |
|
3881 driveRoot.Append(driveEntry.iLetter); |
|
3882 driveRoot.Append(_L(":")); |
|
3883 |
|
3884 // check disk |
|
3885 TInt err = iFs.CheckDisk(driveRoot); |
|
3886 |
|
3887 if (err == KErrNone) |
|
3888 { |
|
3889 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Integrity of the disk is ok")); |
|
3890 } |
|
3891 else if (err == KErrNotReady) |
|
3892 { |
|
3893 iEngine->FileBrowserUI()->ShowInformationNote(_L("Disk is empty"), _L("")); |
|
3894 } |
|
3895 else if (err == KErrNotSupported) |
|
3896 { |
|
3897 iEngine->FileBrowserUI()->ShowErrorNote(_L("Not supported for this drive")); |
|
3898 } |
|
3899 else |
|
3900 { |
|
3901 iEngine->FileBrowserUI()->ShowErrorNote(_L("Disk is corrupted")); |
|
3902 } |
|
3903 |
|
3904 RefreshViewL(); |
|
3905 } |
|
3906 } |
|
3907 |
|
3908 // -------------------------------------------------------------------------------------------- |
|
3909 |
|
3910 void CFileBrowserFileUtils::ScanDriveL(TInt aIndex) |
|
3911 { |
|
3912 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3913 { |
|
3914 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3915 |
|
3916 TBuf<10> driveRoot; |
|
3917 driveRoot.Append(driveEntry.iLetter); |
|
3918 driveRoot.Append(_L(":")); |
|
3919 |
|
3920 // scan disk |
|
3921 User::LeaveIfError(iFs.ScanDrive(driveRoot)); |
|
3922 } |
|
3923 } |
|
3924 |
|
3925 // -------------------------------------------------------------------------------------------- |
|
3926 |
|
3927 void CFileBrowserFileUtils::GetDriveName(TInt aIndex, TFileName &aDriveName) |
|
3928 { |
|
3929 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3930 { |
|
3931 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3932 |
|
3933 // get existing drive name |
|
3934 iFs.GetDriveName(driveEntry.iNumber, aDriveName); |
|
3935 } |
|
3936 } |
|
3937 |
|
3938 // -------------------------------------------------------------------------------------------- |
|
3939 |
|
3940 void CFileBrowserFileUtils::SetDriveNameL(TInt aIndex, const TFileName &aDriveName) |
|
3941 { |
|
3942 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3943 { |
|
3944 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3945 |
|
3946 // set drive name |
|
3947 User::LeaveIfError(iFs.SetDriveName(driveEntry.iNumber, aDriveName)); |
|
3948 } |
|
3949 } |
|
3950 |
|
3951 // -------------------------------------------------------------------------------------------- |
|
3952 |
|
3953 void CFileBrowserFileUtils::GetDriveVolumeLabel(TInt aIndex, TFileName &aVolumeLabel) |
|
3954 { |
|
3955 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3956 { |
|
3957 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3958 |
|
3959 // get existing volume label |
|
3960 aVolumeLabel.Copy(driveEntry.iVolumeInfo.iName); |
|
3961 } |
|
3962 } |
|
3963 |
|
3964 // -------------------------------------------------------------------------------------------- |
|
3965 |
|
3966 void CFileBrowserFileUtils::SetDriveVolumeLabelL(TInt aIndex, const TFileName &aVolumeLabel) |
|
3967 { |
|
3968 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3969 { |
|
3970 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3971 |
|
3972 // set volume label |
|
3973 User::LeaveIfError(iFs.SetVolumeLabel(aVolumeLabel, driveEntry.iNumber)); |
|
3974 } |
|
3975 } |
|
3976 |
|
3977 // -------------------------------------------------------------------------------------------- |
|
3978 |
|
3979 void CFileBrowserFileUtils::EjectDriveL(TInt aIndex) |
|
3980 { |
|
3981 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
3982 { |
|
3983 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
3984 |
|
3985 TInt err(KErrNone); |
|
3986 |
|
3987 // get current filesystem name |
|
3988 TFileName fileSystemName; |
|
3989 User::LeaveIfError(iFs.FileSystemName(fileSystemName, driveEntry.iNumber)); |
|
3990 |
|
3991 // Prevent SysAp shutting down applications |
|
3992 RProperty::Set( |
|
3993 KPSUidCoreApplicationUIs, |
|
3994 KCoreAppUIsMmcRemovedWithoutEject, |
|
3995 ECoreAppUIsEjectCommandUsed ); |
|
3996 |
|
3997 // dismount the file system |
|
3998 User::LeaveIfError(iFs.DismountFileSystem(fileSystemName, driveEntry.iNumber)); |
|
3999 |
|
4000 // remount the file system |
|
4001 err = iFs.MountFileSystem(fileSystemName, driveEntry.iNumber); |
|
4002 |
|
4003 if (err == KErrInUse) |
|
4004 { |
|
4005 // try to remount after a while if locked |
|
4006 User::After(1000000); |
|
4007 err = iFs.MountFileSystem(fileSystemName, driveEntry.iNumber); |
|
4008 } |
|
4009 User::LeaveIfError(err); |
|
4010 } |
|
4011 } |
|
4012 |
|
4013 // -------------------------------------------------------------------------------------------- |
|
4014 |
|
4015 void CFileBrowserFileUtils::DismountFileSystemL(TInt aIndex) |
|
4016 { |
|
4017 if (iDriveEntryList->Count() > aIndex && aIndex >= 0) |
|
4018 { |
|
4019 TDriveEntry driveEntry = iDriveEntryList->At(aIndex); |
|
4020 |
|
4021 // get current filesystem name |
|
4022 TFileName fileSystemName; |
|
4023 User::LeaveIfError(iFs.FileSystemName(fileSystemName, driveEntry.iNumber)); |
|
4024 |
|
4025 // Prevent SysAp shutting down applications |
|
4026 RProperty::Set( |
|
4027 KPSUidCoreApplicationUIs, |
|
4028 KCoreAppUIsMmcRemovedWithoutEject, |
|
4029 ECoreAppUIsEjectCommandUsed ); |
|
4030 |
|
4031 // dismount the file system |
|
4032 User::LeaveIfError(iFs.DismountFileSystem(fileSystemName, driveEntry.iNumber)); |
|
4033 } |
|
4034 } |
|
4035 |
|
4036 // -------------------------------------------------------------------------------------------- |
|
4037 |
|
4038 void CFileBrowserFileUtils::ConvertCharsToPwd(const TDesC& aWord, TDes8& aConverted) const |
|
4039 { |
|
4040 aConverted.FillZ(aConverted.MaxLength()); |
|
4041 aConverted.Zero(); |
|
4042 |
|
4043 if (aWord.Length()) |
|
4044 { |
|
4045 aConverted.Copy( (TUint8*)(&aWord[0]), aWord.Size() ); |
|
4046 } |
|
4047 } |
|
4048 |
|
4049 // -------------------------------------------------------------------------------------------- |
|
4050 |
|
4051 void CFileBrowserFileUtils::EditDataTypesL() |
|
4052 { |
|
4053 // TODO |
|
4054 /* |
|
4055 iEngine->FileListContainer()->SetScreenLayoutL(EDisplayModeNormal); |
|
4056 iEngine->FileListContainer()->SetNaviPaneTextL(KNullDesC); |
|
4057 |
|
4058 CFileBrowserDataTypesDlg* dlg = CFileBrowserDataTypesDlg::NewL(); |
|
4059 dlg->RunQueryLD(); |
|
4060 |
|
4061 iEngine->FileListContainer()->SetScreenLayoutL(iEngine->Settings().iDisplayMode); |
|
4062 iEngine->FileListContainer()->SetNaviPaneTextL(iCurrentPath); |
|
4063 */ |
|
4064 } |
|
4065 |
|
4066 // -------------------------------------------------------------------------------------------- |
|
4067 |
|
4068 void CFileBrowserFileUtils::SecureBackupL(TInt aType) |
|
4069 { |
|
4070 TInt err(KErrNone); |
|
4071 TInt showStatus(EFalse); |
|
4072 |
|
4073 if (aType == EFileBrowserCmdToolsSecureBackupStartBackup || aType == EFileBrowserCmdToolsSecureBackupStartRestore) |
|
4074 { |
|
4075 // TInt queryIndexState(0); |
|
4076 // TInt queryIndexType(0); |
|
4077 |
|
4078 // CAknListQueryDialog* listQueryDlgState = new(ELeave) CAknListQueryDialog(&queryIndexState); |
|
4079 // if (listQueryDlgState->ExecuteLD(R_SECUREBACKUP_STATE_QUERY)) |
|
4080 // { |
|
4081 // |
|
4082 // CAknListQueryDialog* listQueryDlgType = new(ELeave) CAknListQueryDialog(&queryIndexType); |
|
4083 // if (listQueryDlgType->ExecuteLD(R_SECUREBACKUP_TYPE_QUERY)) |
|
4084 // { |
|
4085 // conn::TBURPartType partType = conn::EBURNormal; |
|
4086 // conn::TBackupIncType backupIncType = conn::ENoBackup; |
|
4087 // |
|
4088 // if (aType == EFileBrowserCmdToolsSecureBackupStartBackup) |
|
4089 // { |
|
4090 // if (queryIndexState == ESecureBackupStateFull) |
|
4091 // partType = conn::EBURBackupFull; |
|
4092 // else if (queryIndexState == ESecureBackupStatePartial) |
|
4093 // partType = conn::EBURBackupPartial; |
|
4094 // } |
|
4095 // else if (aType == EFileBrowserCmdToolsSecureBackupStartRestore) |
|
4096 // { |
|
4097 // if (queryIndexState == ESecureBackupStateFull) |
|
4098 // partType = conn::EBURRestoreFull; |
|
4099 // else if (queryIndexState == ESecureBackupStatePartial) |
|
4100 // partType = conn::EBURRestorePartial; |
|
4101 // } |
|
4102 // |
|
4103 // if (queryIndexType == ESecureBackupTypeBase) |
|
4104 // backupIncType = conn::EBackupBase; |
|
4105 // else if (queryIndexType == ESecureBackupTypeIncremental) |
|
4106 // backupIncType = conn::EBackupIncrement; |
|
4107 // |
|
4108 // // start secure backup |
|
4109 // err = iFileOps->ActivateSecureBackUp(partType, backupIncType); |
|
4110 // showStatus = ETrue; |
|
4111 // } |
|
4112 // } |
|
4113 } |
|
4114 |
|
4115 else if (aType == EFileBrowserCmdToolsSecureBackupStop) |
|
4116 { |
|
4117 err = iFileOps->DeActivateSecureBackUp(); |
|
4118 showStatus = ETrue; |
|
4119 } |
|
4120 |
|
4121 else |
|
4122 User::Panic(_L("Sec.br.mode"), 101); |
|
4123 |
|
4124 |
|
4125 if (showStatus) |
|
4126 { |
|
4127 if (err == KErrNone) |
|
4128 { |
|
4129 iEngine->FileBrowserUI()->ShowConfirmationNote(_L("Succeeded")); |
|
4130 } |
|
4131 else |
|
4132 { |
|
4133 iEngine->FileBrowserUI()->ShowErrorNote(ResolveErrorMessage(err)); |
|
4134 } |
|
4135 } |
|
4136 } |
|
4137 |
|
4138 // -------------------------------------------------------------------------------------------- |
|
4139 |
|
4140 void CFileBrowserFileUtils::OpenCommonFileActionQueryL(TInt aCurrentItemIndex) |
|
4141 { |
|
4142 // TODO |
|
4143 // just get current item |
|
4144 // TInt currentItemIndex = iEngine->QueryCurrentItemIndex(); |
|
4145 |
|
4146 if (iFileEntryList->Count() > aCurrentItemIndex && aCurrentItemIndex >= 0) |
|
4147 { |
|
4148 // TInt queryIndex(0); |
|
4149 // |
|
4150 // CAknListQueryDialog* listQueryDlg = new(ELeave) CAknListQueryDialog(&queryIndex); |
|
4151 // |
|
4152 // if (listQueryDlg->ExecuteLD(R_COMMON_FILE_ACTION_QUERY)) |
|
4153 // { |
|
4154 // if (queryIndex == ECommonFileActionViewAsTextHex) |
|
4155 // { |
|
4156 // TFileEntry fileEntry = iFileEntryList->At(aCurrentItemIndex); |
|
4157 // |
|
4158 // TFileName fullPath = fileEntry.iPath; |
|
4159 // fullPath.Append(fileEntry.iEntry.iName); |
|
4160 // |
|
4161 // TInt viewerType(EFileBrowserCmdFileViewHex); |
|
4162 // |
|
4163 // // check from mime type if it's text |
|
4164 // TDataType dataType; |
|
4165 // TUid appUid; |
|
4166 // if (iEngine->LsSession().AppForDocument(fullPath, appUid, dataType) == KErrNone) |
|
4167 // { |
|
4168 // TBuf<128> mimeTypeBuf; |
|
4169 // mimeTypeBuf.Copy(dataType.Des8()); |
|
4170 // if (mimeTypeBuf == KNullDesC) |
|
4171 // mimeTypeBuf.Copy(_L("N/A")); |
|
4172 // |
|
4173 // if (mimeTypeBuf.CompareF(_L("text/plain")) == 0) |
|
4174 // viewerType = EFileBrowserCmdFileViewText; |
|
4175 // } |
|
4176 // |
|
4177 // FileEditorL(viewerType); |
|
4178 // } |
|
4179 // |
|
4180 // else if (queryIndex == ECommonFileActionOpenWithApparc) |
|
4181 // { |
|
4182 // // TODO |
|
4183 // //OpenWithApparcL(); |
|
4184 // } |
|
4185 // |
|
4186 // else if (queryIndex == ECommonFileActionOpenWithDocHandlerEmbed) |
|
4187 // { |
|
4188 // // TODO |
|
4189 // //OpenWithDocHandlerL(ETrue); |
|
4190 // } |
|
4191 // |
|
4192 // else |
|
4193 // User::Panic(_L("Unk.Com.Act"), 221); |
|
4194 // } |
|
4195 } |
|
4196 } |
|
4197 |
|
4198 // -------------------------------------------------------------------------------------------- |
|
4199 |
|
4200 // End of File |