hxsym_mmc_utils.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:4k
源码类别:

Symbian

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  * chxavmisc.cpp
  3.  * -------------
  4.  *
  5.  * Synopsis:
  6.  * mmc utils for Symbian players
  7.  *
  8.  *
  9.  *
  10.  * Target:
  11.  * Symbian OS
  12.  *
  13.  *
  14.  * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
  15.  *
  16.  *****************************************************************************/
  17. // Symbian includes...
  18. #include <coeutils.h>
  19. #include <aknenv.h>
  20. //#include <apgcli.h>
  21. #include <avkon.rsg>
  22. // Includes from this project...
  23. #include "chxavutil.h"
  24. #include "chxavmisc.h"
  25. #include "chxavfileutil.h"
  26. #include "chxavmessagedialog.h"
  27. #include "chxavcleanstring.h"
  28. #include "chxavcleanupstack.h"
  29. #include "realplayer.rsg"
  30. #include "realplayer.hrh"
  31. #include "hxsym_mmc_utils.h"
  32. #include "hxsym_debug.h"
  33. namespace util
  34. {
  35. ////////////////////////////////////////////////
  36. // prompt user for a password
  37. //
  38. // return true if password supplied
  39. //
  40. bool GetPasswordFromUserL(TDes& password, const TDesC& prompt)
  41. {
  42.     CAknTextQueryDialog* pDlg = CAknTextQueryDialog::NewL(password);
  43.     // R_CFD_PASSWORD_QUERY_DIALOG
  44.     return 0 != pDlg->ExecuteLD(R_AVP_MMC_PASSWORD_QUERY, prompt);
  45. }
  46. ///////////////////////////////////////////////
  47. //
  48. TInt DoUnlockDriveUi(TInt idxDrive)
  49. {
  50.     TBuf<KMaxMediaPassword> pwText;
  51.     TMediaPassword pwBuf;
  52.     TInt err = KErrGeneral;
  53.     CHXAvFile::DriveInfo info = CHXAvFile::GetDriveInfo(idxDrive);
  54.     if( CHXAvFile::dsLocked == info.state )
  55.     {
  56.         if(CHXAvMessageDialog::DoQueryL(R_AVP_UNLOCK_MMC_QUERY)) // R_CFD_QTN_MEMC_UNLOCK_QUERY1
  57.         {
  58.             CHXAvCleanString pwPrompt(R_AVP_PASSWORD_QUERY_PROMPT); //R_CFD_PASSWORD_QUERY_TEXT
  59.             for( ; ; )
  60.             {
  61.                 pwText.Zero();
  62.                 if( GetPasswordFromUserL(pwText, pwPrompt()))
  63.                 {
  64.                     // a password was entered; copy to media password buffer
  65.                     CHXAvUtil::Copy8(pwText, pwBuf);
  66.                     // attempt to unlock mmc with password
  67.                     RFs& fs = CCoeEnv::Static()->FsSession();
  68.                     err = fs.UnlockDrive( idxDrive, pwBuf, ETrue /* cache password*/ );
  69.                     if(KErrNone == err)
  70.                     {
  71.                         // drive unlocked; now mount (important!) via lock check
  72.                         if(CHXAvFile::IsDriveLocked(idxDrive))
  73.                         {
  74.                             err = KErrLocked;
  75.                         }
  76.                         break;
  77.                     }
  78.                     else
  79.                     {
  80.                         CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_AVP_PASSWORD_INCORRECT_PASSWORD/*R_CFD_INCORRECT_PASSWORD_TEXT*/)(), true, CAknNoteDialog::ELongTimeout);
  81.                     }
  82.                 }
  83.                 else
  84.                 {
  85.                     // user cancelled
  86.                     err = KErrCancel;
  87.                     break;
  88.                 }
  89.             }
  90.         }
  91.     }
  92.     
  93.     return err;
  94. }
  95. #if defined(SYMBIANPLAYER_INCLUDE_LOCK_DRIVE_UI)
  96. //
  97. // Debugging helper:
  98. //
  99. // Enable user to clear password cache and reset 
  100. // password for current mmc
  101. //
  102. void DoLockDriveUiL()
  103. {
  104.     TBuf<KMaxMediaPassword> pwText;
  105.     TMediaPassword pwNew, pwOld;
  106.     if(GetPasswordFromUserL(pwText, CHXAvCleanString(R_AVP_PASSWORD_QUERY_PROMPT/*R_CFD_PASSWORD_QUERY_TEXT*/)()))
  107.     {
  108.         CHXAvUtil::Copy8(pwText, pwNew);
  109.         RFs& fs = CCoeEnv::Static()->FsSession();
  110.         // assume no password
  111.         TInt err = fs.LockDrive( EDriveE, pwOld, pwNew, EFalse );
  112.         if(KErrNone != err)
  113.         {
  114.             // assume current pw is same as that entered and try again
  115.             CHXAvUtil::Copy8(pwText, pwOld);
  116.             err = fs.ClearPassword(EDriveE, pwOld);
  117.             if( KErrNone == err )
  118.             {
  119.                 // note if pwOld == pwNew, password remains cached
  120.                 pwOld.Zero();
  121.                 err = fs.LockDrive(EDriveE, pwOld, pwNew, EFalse );
  122.             }
  123.         }
  124.         if( KErrNone == err )
  125.         {
  126.             CHXAvMessageDialog::DoAlertInfoL(_L("MMC locked (goes into effect after reboot)"));
  127.         }
  128.         else
  129.         {
  130.             CHXAvMessageDialog::DoAlertInfoL(_L("Failed!"));
  131.         }                   
  132.     }
  133. }
  134. #endif // SYMBIANPLAYER_INCLUDE_LOCK_DRIVE_UI
  135. } // ns util