chxavfileui.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:35k
- /************************************************************************
- * chxavfileui.h
- * -------------
- *
- * Synopsis:
- * Description:
- *
- * encapsulates UI logic for file/folder renaming, deleting,Target:
- * moving, etc.Symbian OS
- *
- * uses CHXAvFileStore to do actual operations
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Symbian includes...
- #include <coeutils.h>
- #include <aknlists.h>
- #include <aknutils.h>
- #include <barsread.h>
- // Helix includes...
- #include "hxassert.h"
- // Include from this project...
- #include "chxavplayerui.h"
- #include "chxavdirectoryreader.h"
- #include "chxavcleanstring.h"
- #include "chxavcleanupstack.h"
- #include "chxavfilestore.h"
- #include "chxavmessagedialog.h"
- #include "realplayer.rsg"
- #include "realplayer.hrh"
- #include "chxavmisc.h"
- #include "hxsym_debug.h"
- #include "chxavfolderpopuplist.h"
- #include "chxavpathselector.h"
- #include "chxavfileui.h"
- namespace
- {
- //const TUint k_msActionNoteDelay = 1000;
- inline
- bool IsNonCancelError(TInt err)
- {
- return err != KErrNone && err != KErrCancel;
- }
- } // local
- CHXAvFileUI::CHXAvFileUI(bool bHideExtensions)
- : CHXAvNameDisplayTrait(bHideExtensions)
- , m_pCone(CCoeEnv::Static())
- , m_playerUI(0)
- , m_bIsCancelOpPending(false)
- {
- }
- CHXAvFileUI::~CHXAvFileUI()
- {
- }
- void CHXAvFileUI::EnableWaitNoteCancelButtonL(bool bEnable)
- {
- if( bEnable )
- {
- const CHXAvCommand& userCancelCmd =
- MakeCommand(this, &CHXAvFileUI::UserCancelPendingFileOp);
- m_spWaitNote->SetCancelCommandL(userCancelCmd);
- }
- else
- {
- m_spWaitNote->ClearCancelCommand();
- }
- }
- ////////////////////////////////////////////////////////////
- //
- void CHXAvFileUI::ConstructL(CHXAvPlayerUI* playerUI, const CHXAvFileStorePtr& spStore)
- {
- HX_ASSERT(playerUI != 0);
- HX_ASSERT(spStore);
- m_playerUI = playerUI;
- m_spStore = spStore;
- m_spStore->SetObserver(this);
- m_spWaitNote = new (ELeave) CHXAvWaitNote();
- m_spLastUniqueName = KNullDesC().AllocL();
- }
- ////////////////////////////////////////////////////
- // get folder name from user and create it under current path
- //
- // KErrNone if created
- // KErrCancel if user cancels
- //
- TInt CHXAvFileUI::DoNewFolderL(TInt resIdPrompt)
- {
- CHXAvCleanString defFolderName(R_DEFAULT_NEW_FOLDER_NAME);
- const TUint flags = fSuggestUniqueDefaultName | fWantFolder;
- QueryTargetNameResult res = QueryTargetNameL(CHXAvCleanString(resIdPrompt)(),
- m_spStore->GetCurrentPath(), defFolderName(), flags);
- TInt err = KErrGeneral;
- switch (res)
- {
- case qtrUnique:
- case qtrOverwrite:
- // got name...
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoNewFolderL(): creating '%s'n", dbg::CharPtr(m_nameBuf)()));
- err = m_spStore->CreateChildFolderL(m_nameBuf, res == qtrOverwrite);
- break;
- case qtrAbort:
- // user canceled
- err = KErrCancel;
- break;
- default:
- err = KErrGeneral;
- break;
- }
- if( IsNonCancelError(err) )
- {
- HandleDiskFullCase(err);
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_CREATE_FOLDER_FAILED)());
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // save playlist
- TInt CHXAvFileUI::DoSavePlaylistL(const TDesC& fullPathSource, const TDesC& targetName)
- {
- const CopyFileResourceIds k_savePlaylistIds =
- {
- R_PROMPT_ENTER_SAVE_NAME,
- R_PROMPT_SAVE_TO,
- R_AVP_SAVE_BUTTON_TEXT,
- R_NOW_SAVING_ITEM_FORMAT,
- R_INFO_PLAYLIST_SAVED,
- R_ERR_SAVE_PLAYLIST_FAILED
- };
- return DoCopyFileL(fullPathSource, k_savePlaylistIds, targetName);
-
- }
- ////////////////////////////////////////////////////////////
- // save clip
- TInt CHXAvFileUI::DoSaveClipL(const TDesC& fullPathSource, const TDesC& targetName)
- {
- static const CopyFileResourceIds k_saveClipIds =
- {
- R_PROMPT_ENTER_SAVE_NAME,
- R_PROMPT_SAVE_TO,
- R_AVP_SAVE_BUTTON_TEXT,
- R_NOW_SAVING_ITEM_FORMAT,
- R_INFO_CLIP_SAVED,
- R_ERR_SAVE_CLIP_FAILED
- };
- return DoCopyFileL(fullPathSource, k_saveClipIds, targetName);
- }
- ////////////////////////////////////////////////////////////
- // prompt user for target folder, than do copy file to that
- // folder
- TInt CHXAvFileUI::DoCopyFileL(const TDesC& fullPathSource,
- const CopyFileResourceIds& resIds,
- const TDesC& targetName)
- {
- TInt err = KErrCancel;
- bool bGotIt = DoGetTargetFolderPathL(resIds.idPromptTargetPath,
- resIds.idPromptTargetPathSelectButtonText);
- if(bGotIt)
- {
- err = DoCopyFileL(m_targetFolderPath, fullPathSource, resIds, targetName);
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // helper: called from DoCopyFileL()
- TInt CHXAvFileUI::DoCopyFileHelperL(const TDesC& pathDest,
- const TDesC& fullPathSource,
- const CopyFileResourceIds& resIds,bool bAllowOverwrite)
- {
- CHXAvCleanString msg(resIds.idInfoNowCopying, m_nameBuf);
- m_spWaitNote->SetTextL(msg());
- #if defined(ASYNC_COPYMOVE)
- EnableWaitNoteCancelButtonL(true);
- #endif
- m_spWaitNote->StartAndKickL();
-
- TInt err = m_spStore->CopyFileL(pathDest, m_nameBuf, fullPathSource, bAllowOverwrite);
- // handle case where file is opened read-only with fopen
- if( err == KErrInUse )
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoCopyFileHelperL(): file is locked; doing locked file copyn"));
- err = m_spStore->CopyFileAlternateL(pathDest, m_nameBuf, fullPathSource, bAllowOverwrite);
- }
- m_spWaitNote->EndL();
- return err;
- }
- ////////////////////////////////////////////////////////////
- // prompt user for target name within target folder,
- // then copy the source
- //
- // pathDest - folder path; absolute or relative to current root
- //
- // pathSource - Full absolute path
- //
- TInt CHXAvFileUI::DoCopyFileL(const TDesC& pathDest,
- const TDesC& fullPathSource,
- const CopyFileResourceIds& resIds,
- const TDesC& targetName)
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoCopyFileL(): '%s' -> '%s'n", dbg::CharPtr(fullPathSource)(), dbg::CharPtr(pathDest)()));
- TInt err = KErrCancel;
- // determine target filename
- TPtrC ptrName(targetName);
- if(ptrName.Length() == 0)
- {
- // no default name provide; use name of source file
- ptrName.Set(CHXAvFile::GetNakedPathNode(fullPathSource));
- }
-
- // get a unique name within destination folder
- QueryTargetNameResult res = QueryTargetNameL(CHXAvCleanString(resIds.idPromptTargetName)(), pathDest,
- ptrName, fSuggestUniqueDefaultName);
- switch (res)
- {
- case qtrUnique:
- case qtrOverwrite:
- // got name...
- err = DoCopyFileHelperL(pathDest, fullPathSource, resIds, (res == qtrOverwrite));
- // display confirmation after successful copy
- if( err == KErrNone )
- {
- CHXAvMessageDialog::DoAlertConfirmL(CHXAvCleanString(resIds.idInfoConfirmCopy)());
- }
- break;
- case qtrAbort:
- // user canceled
- err = KErrCancel;
- break;
- default:
- err = KErrGeneral;
- break;
- }
- if( IsNonCancelError(err) )
- {
- HandleDiskFullCase(err);
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(resIds.idInfoCopyFailed)());
- }
- return err;
- }
- #if(0)
- ////////////////////////////////////////////////////////////
- // prompt user for folder, then move item to it
- TInt CHXAvFileUI::DoCopyItemL(TInt idxItem,
- TInt resIdPrompt)
- {
- TInt err = KErrCancel;
- // guard against index becoming invalid (by refresh) while waiting for user input
- SUSPEND_REFRESH(m_spStore);
- bool bGotIt = DoGetTargetFolderPathL(resIdPrompt, R_AVP_COPY_BUTTON_TEXT);
- if(bGotIt)
- {
- err = DoCopyItemL(m_targetFolderPath, idxItem);
- }
- return err;
- }
- #endif
- ////////////////////////////////////////////////////////////
- // prompt user for folder, then move item to it
- TInt CHXAvFileUI::DoMoveItemL(TInt idxItem,
- TInt resIdPrompt)
- {
- TInt err = KErrCancel;
- SUSPEND_REFRESH(m_spStore);
- bool bGotIt = DoGetTargetFolderPathL(resIdPrompt, R_AVP_MOVE_BUTTON_TEXT);
- if(bGotIt)
- {
- err = DoMoveItemL(m_targetFolderPath, idxItem);
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // prompt user for folder, then move multiple items to it
- TInt CHXAvFileUI::DoMoveItemsL(const CArrayFix<TInt>& items,
- TInt resIdPrompt)
- {
- TInt err = KErrCancel;
- SUSPEND_REFRESH(m_spStore);
- bool bGotIt = DoGetTargetFolderPathL(resIdPrompt, R_AVP_MOVE_BUTTON_TEXT);
- if(bGotIt)
- {
- err = DoMoveItemsL(m_targetFolderPath, items);
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // helper
- TPtrC CHXAvFileUI::NameFromIndex(TInt idxItem)
- {
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- const TEntry& entry = entries[idxItem].m_entry;
- NameExt pair = GetDisplayText(entry.iName, entry.IsDir());
- return pair.first;
- }
- #if(0)
- ////////////////////////////////////////////////////////////
- // move single item to specified folder path
- //
- // return error if error other than user cancel occurs
- //
- // pathDest - absolute or relative to current root
- //
- TInt CHXAvFileUI::DoCopyItemL(const TDesC& pathDest,
- TInt idxItem)
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoCopyItemL(): copying idx %d to '%s'n", idxItem, dbg::CharPtr(pathDest)()));
- SUSPEND_REFRESH(m_spStore);
- CHXAvCleanString msg(R_NOW_COPYING_ITEM_FORMAT, NameFromIndex(idxItem));
- m_spWaitNote->SetTextL(msg());
- m_spWaitNote->StartAndKickL();
- // move one item
- TInt err = CopyItemHelperL(pathDest, idxItem);
- m_spWaitNote->EndL();
- if( IsNonCancelError(err) )
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_COPY_FAILED)());
- }
- return err;
- }
- #endif
- ////////////////////////////////////////////////////////////
- // move single item to specified folder path
- //
- // return error if error other than user cancel occurs
- //
- // pathDest - absolute or relative to current root
- //
- TInt CHXAvFileUI::DoMoveItemL(const TDesC& pathDest,
- TInt idxItem)
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoMoveItemL(): moving idx %d to '%s'n", idxItem, dbg::CharPtr(pathDest)()));
- SUSPEND_REFRESH(m_spStore);
- CHXAvCleanString msg(R_NOW_MOVING_ITEM_FORMAT, NameFromIndex(idxItem));
- m_spWaitNote->SetTextL(msg());
- m_spWaitNote->StartAndKickL();
- // move one item
- TInt err = MoveItemHelperL(pathDest, idxItem);
- m_spWaitNote->EndL();
- if( IsNonCancelError(err) )
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_MOVE_FAILED)());
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // move multipe items to specified folder path
- //
- // return error if error other than user cancel occurs
- //
- // pathDest - absolute or relative to current root
- //
- TInt CHXAvFileUI::DoMoveItemsL(const TDesC& pathDest,
- const CArrayFix<TInt>& items)
- {
- TInt err = KErrNone;
- SUSPEND_REFRESH(m_spStore);
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoMoveItemsL(): moving %d items to '%s'n", items.Count(), dbg::CharPtr(pathDest)()));
- m_spWaitNote->SetTextL(CHXAvCleanString(R_NOW_MOVING_MULT_ITEMS_FORMAT, items.Count())());
- #if defined(ASYNC_COPYMOVE)
- EnableWaitNoteCancelButtonL(true);
- #endif
- m_spWaitNote->StartAndKickL();
- for( TInt idx = 0; idx < items.Count(); ++idx )
- {
- err = MoveItemHelperL(pathDest, items[idx]);
- if( IsNonCancelError(err) )
- {
- // XXXLCM offer continue, cancel choice?
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::DoMoveItemsL(): move failed (err = %ld)n", err));
- break;
- }
- }
- m_spWaitNote->EndL();
- if( IsNonCancelError(err) )
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_MOVE_FAILED)());
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // pathDest fully qualified path (with drive letter), or relative to epStore root
- //
- TFileName* CHXAvFileUI::AllocSuggestedFileNameL(const TDesC& pathDest, const TDesC& defaultName, TUint flags )
- {
- TFileName* pName = 0;
- if( flags & fSuggestUniqueDefaultName )
- {
- // AllocUniqueDefaultNameL() needs full path...
- TFileName* pFullPathDest = m_spStore->AllocFullPathL(pathDest, KNullDesC, CHXAvFile::ntFolder);
- AUTO_PUSH_POP_DEL(pFullPathDest);
- // pick a default file/folder name; we get full path ('c:realnetworksrootfoo.rm')
- pName = CHXAvFile::AllocUniqueDefaultNameL(*pFullPathDest, defaultName, flags & fWantFolder, *this);
- if(!pName)
- {
- // rare case; display no default name
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::AllocSuggestedFileNameL(): could not find unique name"));
- pName = CHXAvFile::AllocFileNameL(KNullDesC);
- }
- }
- else
- {
- // we don't know/care whether this name would be unique within the destination path
- pName = CHXAvFile::AllocFileNameL(defaultName);
- }
- return pName;
- }
- ////////////////////////////////////////////////////////////
- // get a unique, valid file or folder name from the
- // user
- //
- // args:
- //
- // pathDest - absolute or relative to current root
- //
- // defaultName - filename to use for initializing text in dialog edit box
- // - also provides default extension;
- // - for folders, trailing '' is optional (handled)
- //
- // returns :
- //
- // m_nameBuf is set as "name" or "name/" (depending on bWantFolder)
- //
- // return false if user cancels
- //
- // notes:
- //
- // if extensions are hidden, they are automatically added to what user enters
- //
- // defaultName prompt user entry result
- //
- // cat cat dog.rm dog.rm
- // cat cat poop poop
- // cat.rm cat flee flee.rm
- // cat.rm cat cat.rm cat.rm.rm
- // .rm bob bob.rm
- // bob bob
- //
- // same examples, if extensions are not hidden:
- //
- // cat cat dog.rm dog.rm
- // cat cat poop poop
- // cat.rm cat.rm flee flee
- // cat.rm cat.rm cat cat.rm
- // .rm .rm bob bob
- // bob bob
- //
- CHXAvFileUI::QueryTargetNameResult
- CHXAvFileUI::QueryTargetNameL(const TDesC& prompt,const TDesC& pathDest,
- const TDesC& defaultName, TUint flags)
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::QueryTargetNameL(): in folder '%s'n", dbg::CharPtr(pathDest)()));
- QueryTargetNameResult res = qtrAbort;
- // reset working buffer
- m_nameBuf.SetLength(0);
- //
- // determine how many chars are left for new filename within given path; we'll
- // restrict user input so we don't overflow filename buffer
- //
- TFileName* pFullPathDest = m_spStore->AllocFullPathL(pathDest, KNullDesC, CHXAvFile::ntFolder);
- AUTO_PUSH_POP_DEL(pFullPathDest);
- TInt cchMaxName = KMaxFileName - pFullPathDest->Length();
- // possibly subtract length of hidden extension or folder suffix
- NameExt ext = GetDisplayText(defaultName, flags & fWantFolder);
- cchMaxName -= ext.second.Length();
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::QueryTargetNameL(): max chars left for name = %dn", cchMaxName));
- if( cchMaxName <= 0 )
- {
- // destination path is too long!
- return qtrPathTooLong;
- }
-
- // ui spec requires that we arbitrarily limit names to 40 chars; code does not care
- if (cchMaxName > CHXAvMisc::KAVPMaxNakedFileName )
- {
- cchMaxName = CHXAvMisc::KAVPMaxNakedFileName;
- }
- InitNameBufWithSuggestionL(pathDest, defaultName, flags);
-
- for( bool bNeedToPrompt = true; bNeedToPrompt ; )
- {
- //
- // name buf should have something like 'foo.rm'; now possibly split name into
- // user-display version ('foo') and ext ('.rm')
- //
- HBufC* pbuffNameInfo = m_nameBuf.AllocL(); // nameInfo will refer into this buffer
- AUTO_PUSH_POP_DEL(pbuffNameInfo);
- NameExt nameInfo = GetDisplayText(*pbuffNameInfo, flags & fWantFolder);
- TFileName* pName = CHXAvMessageDialog::GetFileNameFromUserL(prompt, nameInfo.first, cchMaxName);
- if( pName )
- {
- // update name buf, re-adding extension that we might have lopped off for display purposes
- m_nameBuf.Copy(*pName);
- HX_DELETE(pName);
- m_nameBuf.Append(nameInfo.second);
- // assume we'll be able to use this name for now...
- bNeedToPrompt = false;
- DPRINTF(SYMP_FILE_UI, ("FileUi::QueryTargetNameL(): name requested = '%s'n", dbg::CharPtr(m_nameBuf)()));
- // check for existence of file or folder having same name
- bool bFileNameExists = m_spStore->PathExistsL(pathDest, m_nameBuf, CHXAvFile::ntFile);
- bool bFolderNameExists = m_spStore->PathExistsL(pathDest, m_nameBuf, CHXAvFile::ntFolder);
- if( bFolderNameExists )
- {
- DPRINTF(SYMP_FILE_UI, ("FileUi::QueryTargetNameL(): folder matching name already existsn"));
- // overwrite of folder (or creation of file having same name as existing folder) never allowed
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_NAME_ALREADY_EXISTS)());
- bNeedToPrompt = true;
- }
- else if(flags & fWantFolder)
- {
- // looking for folder target
- if( bFileNameExists )
- {
- // overwrite of file (or creeating of folder having same name as existing file never allowed
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_NAME_ALREADY_EXISTS)());
- bNeedToPrompt = true;
- }
- else
- {
- // user selected a unique folder name (path already checked above)
- res = qtrUnique;
- }
- }
- else
- {
- // looking for file target
- if( bFileNameExists )
- {
- if( flags & fDisallowFileOverwrite )
- {
- // overwrite of file not allowed
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_NAME_ALREADY_EXISTS)());
- bNeedToPrompt = true;
- }
- else
- {
- // ask user if we should overwrite selected filename
- NameExt newNameInfo = GetDisplayText(m_nameBuf, flags & fWantFolder);
- DPRINTF(SYMP_FILE_UI, ("FileUi::QueryTargetNameL(): file matching name already existsn"));
-
- bNeedToPrompt = !CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_CONF_OVERWRITE_ITEM_FORMAT, newNameInfo.first)());
- if( !bNeedToPrompt)
- {
- // user opted to overwrite existing file
- res = qtrOverwrite;
- }
- }
- }
- else
- {
- // user selected a unique folder name
- res = qtrUnique;
- }
- }
- if( bNeedToPrompt )
- {
- // we will prompt again; ensure that we suggest a unique name from now on
- InitNameBufWithSuggestionL(pathDest, m_nameBuf, flags | fSuggestUniqueDefaultName);
- }
- }
- else
- {
- // user canceled
- m_nameBuf.Copy(KNullDesC);
- bNeedToPrompt = false;
- }
- }
- // remember this...
- m_spLastUniqueName = m_nameBuf.AllocL();
- return res;
- }
- ////////////////////////////////////////////////////////
- // initialize name buffer with a default filename
- //
- // may or may not be slightly modified to ensure unique within
- // destination path (depends on flags)
- //
- void CHXAvFileUI::InitNameBufWithSuggestionL(const TDesC& pathDest, const TDesC& fileName, TUint flags)
- {
- TFileName* pNameToSuggest = AllocSuggestedFileNameL(pathDest, fileName, flags);
- AUTO_PUSH_POP_DEL(pNameToSuggest);
- // work with leaf (filename) part of path ('foo.rm')
- TPtrC ptrNode (CHXAvFile::GetNakedPathNode(*pNameToSuggest));
- m_nameBuf.Copy(ptrNode);
- }
- ////////////////////////////////////////////////////////////
- // helper: called from MoveItemHelperL
- //
- // prompt for a name, then (if user gives good name) do the move
- //
- TInt CHXAvFileUI::DoPromptMoveItemHelperL(const TDesC& pathDest, TInt idxItem)
- {
- SUSPEND_REFRESH(m_spStore);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- const TEntry& entry = entries[idxItem].m_entry;
- TInt err = KErrGeneral;
- TUint flags = fSuggestUniqueDefaultName;
- if (entry.IsDir())
- {
- flags |= fWantFolder;
- }
-
- // ask for a suitable filename for the target file
- QueryTargetNameResult res = QueryTargetNameL(CHXAvCleanString(R_PROMPT_ENTER_NEW_NAME)(),
- pathDest,
- entry.iName, flags);
- switch (res)
- {
- case qtrUnique:
- case qtrOverwrite:
- // got target name...
- err = m_spStore->MoveItemL(idxItem, pathDest,
- m_nameBuf, res == qtrOverwrite);
- break;
- case qtrAbort:
- // user canceled
- err = KErrCancel;
- break;
- default:
- err = KErrGeneral;
- break;
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // helper: called from MoveItemHelperL
- //
- // confirm overwrite, then (if user accepts) do the move
- //
- TInt CHXAvFileUI::DoOverwriteMoveItemHelperL(const TDesC& pathDest, TInt idxItem)
- {
- TInt err = KErrGeneral;
- SUSPEND_REFRESH(m_spStore);
- // check for move to self
- if(m_spStore->IsSamePathL(pathDest, idxItem))
- {
- // do nothing; pretend user canceled (same effect as moving to self)
- err = KErrCancel;
- }
- else
- {
- //
- // in case where move target path is a folder (and source is either file or folder) we
- // force the user to create a unique name; other apps like Photo Album behave this
- // way (there are some hassles with underlying API when specifying folder as move target,
- // although there are work-arounds)
- //
- bool bFolderExists = m_spStore->NameExistsInTargetPathL(pathDest, idxItem, CHXAvFile::ntFolder);
- if(bFolderExists)
- {
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_NAME_ALREADY_EXISTS)());
- // prompt for new target name
- err = DoPromptMoveItemHelperL(pathDest, idxItem);
- }
- else
- {
- HX_ASSERT(m_spStore->NameExistsInTargetPathL(pathDest, idxItem, CHXAvFile::ntFile));
- // file exists; confirm that delete is ok
- TPtrC name = NameFromIndex(idxItem);
- if(CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_CONF_OVERWRITE_ITEM_FORMAT, name)()) )
- {
- // user opts to overwrite target...
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- const TEntry& entry = entries[idxItem].m_entry;
- err = m_spStore->MoveItemL(idxItem, pathDest, entry.iName, true /*overwrite*/);
- }
- else
- {
- // user opted not to overwrite target; prompt for new target name
- err = DoPromptMoveItemHelperL(pathDest, idxItem);
- }
- }
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // move a file from disk; if successful, delete the name from the
- // current list
- //
- // if successful, 'text items' are updated and 'remove indexes' contains
- // indexes of deleted items
- //
- // pathDest - absolute or relative to current root
- //
- // idxItem - index of item in current folder path
- //
- TInt CHXAvFileUI::MoveItemHelperL(const TDesC& pathDest, TInt idxItem)
- {
- DPRINTF(SYMP_FILE_UI, ("AvFileUI::MoveItemHelperL(): moving item %d to '%s'n", idxItem, dbg::CharPtr(pathDest)()));
- SUSPEND_REFRESH(m_spStore);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- HX_ASSERT(idxItem < entries.Nelements());
- TInt err = KErrGeneral;
- if( idxItem < entries.Nelements())
- {
- HX_ASSERT(m_spStore->PathExistsL(pathDest, KNullDesC));
-
- if(!m_spStore->IsSafeFileNameLengthL(pathDest, idxItem))
- {
- // name can't fit in target path; prompt for safer (smaller) name
- err = DoPromptMoveItemHelperL(pathDest, idxItem);
- }
- else if(m_spStore->NameExistsInTargetPathL(pathDest, idxItem))
- {
- err = DoOverwriteMoveItemHelperL(pathDest, idxItem);
- }
- else
- {
- const TEntry& entry = entries[idxItem].m_entry;
- // target doesn't exist; go ahead and move
- err = m_spStore->MoveItemL(idxItem, pathDest, entry.iName, false /*rename*/);
- }
- }
- HandleDiskFullCase(err);
- return err;
- }
- ////////////////////////////////////////////////////
- // prompt user to select a folder via a pop-up
- // folder navigation list
- //
- // set folder name in working buffer if folder is selected
- //
- bool CHXAvFileUI::DoGetTargetFolderPathL(TInt resIdPrompt, TInt resIdSelectButton)
- {
- m_targetFolderPath.Zero();
- CHXAvPathSelector selector;
- selector.InitL(m_playerUI->GetMediaStoreInfoL(), resIdPrompt, resIdSelectButton);
- bool bSelected = selector.PromptUserSelectPathL();
- if( bSelected )
- {
- m_targetFolderPath.Copy(selector.GetSelectedPath());
- }
- return bSelected;
-
- }
- ////////////////////////////////////////////////////////////
- // delete selected item
- //
- // return KErrCancel if user cancels
- //
- TInt CHXAvFileUI::DoDeleteItemL(TInt idxItem)
- {
- TInt err = KErrCancel;
- SUSPEND_REFRESH(m_spStore);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- const TEntry& entry = entries[idxItem].m_entry;
- bool bUserConfirmed = false;
- if( entry.IsDir() )
- {
- bUserConfirmed = CHXAvMessageDialog::DoQueryL(R_CONF_DELETE_FOLDER);
- }
- else
- {
- TPtrC name = NameFromIndex(idxItem);
- bUserConfirmed = CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_CONF_DELETE_ITEM_FORMAT, name)());
- }
-
- if( bUserConfirmed )
- {
- CHXAvCleanString msg(R_NOW_DELETING_ITEM_FORMAT, NameFromIndex(idxItem));
- //CHXAvCleanString msg(R_NOW_DELETING);
- m_spWaitNote->SetTextL(msg());
- //EnableWaitNoteCancelButtonL(true);
- m_spWaitNote->StartAndKickL();
-
- err = m_spStore->DeleteItemL(idxItem);
- m_spWaitNote->EndL();
- if(IsNonCancelError(err))
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_DELETE_FAILED)());
- }
- }
- return err;
- }
- ////////////////////////////////////////////////////////////
- // delete multiple items (query just once)
- //
- // only files (not folder) may be deleted this way
- //
- // return KErrCancel if user cancels
- //
- TInt CHXAvFileUI::DoDeleteItemsL(const CArrayFix<TInt>& items)
- {
- SUSPEND_REFRESH(m_spStore);
-
- TInt count = items.Count();
- //
- // confirm with user
- //
- bool bUserConfirmed = false;
- if( 1 == count )
- {
- TPtrC name = NameFromIndex(items[0]);
- bUserConfirmed = CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_CONF_DELETE_ITEM_FORMAT, name)());
- }
- else
- {
- bUserConfirmed = CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_CONF_DELETE_MULT_ITEMS_FORMAT, count)());
- }
- //
- // do the deed if user said 'ok'
- //
- TInt err = KErrCancel;
- if(bUserConfirmed)
- {
-
- m_spWaitNote->SetTextL(CHXAvCleanString(R_NOW_DELETING_MULT_ITEMS_FORMAT, count)());
- //EnableWaitNoteCancelButtonL(true);
- m_spWaitNote->StartAndKickL();
- for( TInt idx = 0; idx < count; ++idx )
- {
- TInt idxDeleteItem = items[idx];
- HX_ASSERT(!m_spStore->GetEntries()[idxDeleteItem].m_entry.IsDir()); // folders can't be in multiple item list!
-
- err = m_spStore->DeleteItemL(idxDeleteItem);
- if(IsNonCancelError(err))
- {
- // XXXLCM ask to continue/cancel?
- break;
- }
- }
- m_spWaitNote->EndL();
- if( IsNonCancelError(err) )
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_DELETE_FAILED)());
- }
- }
- return err;
- }
- ////////////////////////////////////////////////////
- // show error message if err indicates disk full
- void CHXAvFileUI::HandleDiskFullCase(TInt err)
- {
- // display error message if copy failed due to low disk space
- if( KErrDiskFull == err || KErrNoMemory == err)
- {
- CHXAvMessageDialog::DoSystemErrorNoteL(err);
- }
- }
- ////////////////////////////////////////////////////
- // prompt user for a new name for the currently
- // hilighted file or folder
- //
- TInt CHXAvFileUI::DoRenameL(TInt idxItem, TInt resIdPrompt)
- {
- DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::DoRenameL(): idx = n", idxItem));
- SUSPEND_REFRESH(m_spStore);
- const CHXAvFileStore::Entries& entries = m_spStore->GetEntries();
- HX_ASSERT(idxItem < entries.Nelements());
- const TEntry& entry = entries[idxItem].m_entry;
- TInt err = KErrGeneral;
- TUint flags = 0;
- if(entry.IsDir())
- {
- flags |= fWantFolder;
- }
- // get new file name...
- QueryTargetNameResult res = QueryTargetNameL(CHXAvCleanString(resIdPrompt)(),
- m_spStore->GetCurrentPath(),
- entry.iName, flags);
- switch (res)
- {
- case qtrUnique:
- case qtrOverwrite:
- // got name...
- err = m_spStore->MoveItemL(idxItem, m_nameBuf, res == qtrOverwrite, true /*use rename*/);
- break;
- case qtrAbort:
- // user canceled
- err = KErrCancel;
- break;
- default:
- err = KErrGeneral;
- break;
- }
- if(IsNonCancelError(err))
- {
- HandleDiskFullCase(err);
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_RENAME_FAILED)());
- }
- DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::DoRenameL(): exitn"));
- return err;
- }
- ////////////////////////////////////////
- // query folder name, then do save link
- // to that folder
- TInt
- CHXAvFileUI::DoCreateLinkL(const CHXString& url, const TDesC& defaultName)
- {
- TInt err = KErrCancel;
- bool bGotIt = DoGetTargetFolderPathL(R_PROMPT_SAVE_TO, R_AVP_SAVE_BUTTON_TEXT);
- if(bGotIt)
- {
- err = DoCreateLinkL(m_targetFolderPath, url, defaultName);
- }
- return err;
- }
- ////////////////////////////////////////
- // create a link file pointing to the given
- // URL in the given folder
- //
- // return KErrCancel if user cancels
- //
- TInt
- CHXAvFileUI::DoCreateLinkL(const TDesC& folder,
- const CHXString& url,
- const TDesC& defaultName)
- {
- TInt err = KErrGeneral;
- TFileName* pDefaultName = CHXAvFile::AllocFileNameL(defaultName);
- AUTO_PUSH_POP_DEL(pDefaultName);
- if( pDefaultName->Length() == 0 )
- {
- // no default name given...
- CHXAvCleanString lastResortName(R_DEFAULT_NEW_LINK_NAME);
- pDefaultName->Copy(lastResortName());
- }
- pDefaultName->Append(CHXAvUtil::KLinkFileExt);
- // get a unique name within destination folder
- QueryTargetNameResult res = QueryTargetNameL(CHXAvCleanString(R_PROMPT_ENTER_SAVE_NAME)(),
- folder, *pDefaultName, fSuggestUniqueDefaultName);
- // XXXLCM check for low disk?
- switch (res)
- {
- case qtrUnique:
- case qtrOverwrite:
- // got name...
- {
- FILE* pFile = m_spStore->OpenFileL(folder, m_nameBuf, "wt");
- if(pFile)
- {
- ::fprintf(pFile, "%sn", static_cast<const char*>(url));
- ::fclose(pFile);
- err = KErrNone;
- CHXAvMessageDialog::DoAlertConfirmL(CHXAvCleanString(R_INFO_LINK_SAVED)());
- }
- else
- {
- err = KErrGeneral;
- }
- }
- break;
- case qtrAbort:
- // user canceled
- err = KErrCancel;
- break;
- default:
- err = KErrGeneral;
- break;
- }
- if( IsNonCancelError(err) )
- {
- HandleDiskFullCase(err);
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_CREATE_LINK_FAILED)());
- }
- return err;
- }
- void CHXAvFileUI::UserCancelPendingFileOp()
- {
- DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::UserCancelPendingFileOp()n"));
- m_bIsCancelOpPending = true;
- #if defined(ASYNC_COPYMOVE)
- m_spStore->CancelAsyncFileOp();
- #endif
- }
- void CHXAvFileUI::OnFileOpStart(FileStoreOperationObserver::OperationType type, const TDesC& source, const TDesC& target)
- {
- //DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::OnFileOpStart(): op = %d; src = '%s'; dst = '%s'n", type, dbg::CharPtr(source)(), dbg::CharPtr(target)()));
- m_bIsCancelOpPending = false;
- }
- bool CHXAvFileUI::OnFileOpTick(FileStoreOperationObserver::OperationType type, const TDesC& source, const TDesC& target, TInt64 cbCopied)
- {
- //DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::OnFileOpTick(): op = %d; src = '%s'; dst = '%s'; cb = %lun", type, dbg::CharPtr(source)(), dbg::CharPtr(target)(), cbCopied.Low()));
- return !m_bIsCancelOpPending;
- }
- void CHXAvFileUI::OnFileOpEnd(FileStoreOperationObserver::OperationType type, TInt err, const TDesC& source, const TDesC& target)
- {
- //DPRINTF(SYMP_FILE_UI, ("CHXAvFileUI::OnFileOpEnd(): op = %d; err = %d, src = '%s'; dst = '%s'n", type, err, dbg::CharPtr(source)(), dbg::CharPtr(target)()));
-
- m_bIsCancelOpPending = false;
- }