hxsym_mmc_utils.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:4k
- /*****************************************************************************
- * chxavmisc.cpp
- * -------------
- *
- * Synopsis:
- * mmc utils for Symbian players
- *
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- // Symbian includes...
- #include <coeutils.h>
- #include <aknenv.h>
- //#include <apgcli.h>
- #include <avkon.rsg>
- // Includes from this project...
- #include "chxavutil.h"
- #include "chxavmisc.h"
- #include "chxavfileutil.h"
- #include "chxavmessagedialog.h"
- #include "chxavcleanstring.h"
- #include "chxavcleanupstack.h"
- #include "realplayer.rsg"
- #include "realplayer.hrh"
- #include "hxsym_mmc_utils.h"
- #include "hxsym_debug.h"
- namespace util
- {
- ////////////////////////////////////////////////
- // prompt user for a password
- //
- // return true if password supplied
- //
- bool GetPasswordFromUserL(TDes& password, const TDesC& prompt)
- {
- CAknTextQueryDialog* pDlg = CAknTextQueryDialog::NewL(password);
- // R_CFD_PASSWORD_QUERY_DIALOG
- return 0 != pDlg->ExecuteLD(R_AVP_MMC_PASSWORD_QUERY, prompt);
- }
- ///////////////////////////////////////////////
- //
- TInt DoUnlockDriveUi(TInt idxDrive)
- {
- TBuf<KMaxMediaPassword> pwText;
- TMediaPassword pwBuf;
- TInt err = KErrGeneral;
- CHXAvFile::DriveInfo info = CHXAvFile::GetDriveInfo(idxDrive);
- if( CHXAvFile::dsLocked == info.state )
- {
- if(CHXAvMessageDialog::DoQueryL(R_AVP_UNLOCK_MMC_QUERY)) // R_CFD_QTN_MEMC_UNLOCK_QUERY1
- {
- CHXAvCleanString pwPrompt(R_AVP_PASSWORD_QUERY_PROMPT); //R_CFD_PASSWORD_QUERY_TEXT
- for( ; ; )
- {
- pwText.Zero();
- if( GetPasswordFromUserL(pwText, pwPrompt()))
- {
- // a password was entered; copy to media password buffer
- CHXAvUtil::Copy8(pwText, pwBuf);
- // attempt to unlock mmc with password
- RFs& fs = CCoeEnv::Static()->FsSession();
- err = fs.UnlockDrive( idxDrive, pwBuf, ETrue /* cache password*/ );
- if(KErrNone == err)
- {
- // drive unlocked; now mount (important!) via lock check
- if(CHXAvFile::IsDriveLocked(idxDrive))
- {
- err = KErrLocked;
- }
- break;
- }
- else
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_AVP_PASSWORD_INCORRECT_PASSWORD/*R_CFD_INCORRECT_PASSWORD_TEXT*/)(), true, CAknNoteDialog::ELongTimeout);
- }
- }
- else
- {
- // user cancelled
- err = KErrCancel;
- break;
- }
- }
- }
- }
-
- return err;
- }
- #if defined(SYMBIANPLAYER_INCLUDE_LOCK_DRIVE_UI)
- //
- // Debugging helper:
- //
- // Enable user to clear password cache and reset
- // password for current mmc
- //
- void DoLockDriveUiL()
- {
- TBuf<KMaxMediaPassword> pwText;
- TMediaPassword pwNew, pwOld;
- if(GetPasswordFromUserL(pwText, CHXAvCleanString(R_AVP_PASSWORD_QUERY_PROMPT/*R_CFD_PASSWORD_QUERY_TEXT*/)()))
- {
- CHXAvUtil::Copy8(pwText, pwNew);
- RFs& fs = CCoeEnv::Static()->FsSession();
- // assume no password
- TInt err = fs.LockDrive( EDriveE, pwOld, pwNew, EFalse );
- if(KErrNone != err)
- {
- // assume current pw is same as that entered and try again
- CHXAvUtil::Copy8(pwText, pwOld);
- err = fs.ClearPassword(EDriveE, pwOld);
- if( KErrNone == err )
- {
- // note if pwOld == pwNew, password remains cached
- pwOld.Zero();
- err = fs.LockDrive(EDriveE, pwOld, pwNew, EFalse );
- }
- }
- if( KErrNone == err )
- {
- CHXAvMessageDialog::DoAlertInfoL(_L("MMC locked (goes into effect after reboot)"));
- }
- else
- {
- CHXAvMessageDialog::DoAlertInfoL(_L("Failed!"));
- }
- }
- }
- #endif // SYMBIANPLAYER_INCLUDE_LOCK_DRIVE_UI
- } // ns util