chxavfileui.cpp
来自「著名的 helix realplayer 基于手机 symbian 系统的 播放」· C++ 代码 · 共 1,125 行 · 第 1/3 页
CPP
1,125 行
/************************************************************************
* 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 copy\n"));
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
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?