📄 localview.cpp
字号:
/*
* ============================================================================
* Name : CLocalView from LocalView.h
* Part of : Netfrog
* Created : 14.11.2006 by Patrick Chen
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: Qianxun Investment Holding Ltd
* ============================================================================
*/
// INCLUDE FILES
#include <AknsUtils.h> //Link against: aknskins.lib aknskinsrv.lib
#include <aknnotewrappers.h> //for note dialog
#include <aknglobalnote.h>
#include <aknmessagequerydialog.h> //显示关于和帮助
#include <eikbtgpc.h>
#include <aknviewappui.h>
#include <avkon.hrh>
#include <avkon.rsg>
#include <eikmenup.h> //for menu
#include <StringLoader.h>
#include <eikappui.h>
#include <eikapp.h>
#include <f32file.h>
#include <bautils.h>
#include <utf.h> //转换为UniCode
#include <stringloader.h>
#include "LocalView.h"
#include "LocalContainer.h"
#include "LaunchSysAppEngine.h"
#include "ToUnicode.h"
#include "FileListView.h"
#include "localrsgfile.h"
_LIT(DefaultPwd,"123");
_LIT(PwdFileName,"pwd.txt");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CLocalView::ConstructL(const TRect& aRect)
// EPOC two-phased constructor
// ---------------------------------------------------------
//
void CLocalView::ConstructL()
{
AknsUtils::SetAvkonSkinEnabledL(ETrue);
BaseConstructL( R_MYZONE_LOCALVIEW );
iPwd.Copy(DefaultPwd);
if(!Login())
{
AppUi()->HandleCommandL(EEikCmdExit);
}
}
// ---------------------------------------------------------
// CLocalView::~CLocalView()
// destructor
// ---------------------------------------------------------
//
CLocalView::~CLocalView()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
if(iLaunchApp)
{
delete iLaunchApp;
iLaunchApp = NULL;
}
delete iContainer;
}
// ---------------------------------------------------------
// TUid CLocalView::Id()
//
// ---------------------------------------------------------
//
TUid CLocalView::Id() const
{
return KLocalViewId;
}
// ---------------------------------------------------------
// CLocalView::HandleCommandL(TInt aCommand)
// takes care of view command handling
// ---------------------------------------------------------
//
void CLocalView::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyOk:
{
iEikonEnv->InfoMsg( _L("view1 ok") );
break;
}
case EAknSoftkeyBack:
{
AppUi()->HandleCommandL(EEikCmdExit);
break;
}
case 123:
{
}
break;
//打开选中的文件夹
case EMyzoneCmdOpenFolder:
{
if(iContainer && !iContainer->IsFolderOpen())
{
iContainer->OpenFolder();
}
}
break;
//打开选中的文件
case EMyzoneCmdFileOpen:
{
if(iContainer)
{
iContainer->OpenSelectFile();
}
}
break;
//从文件列表返回到文件夹视图,此时要更新文件视图
case EMyzoneCbaBack:
{
if(iContainer)
{
TRAPD(ERROR,iContainer->BackFromFileList());
}
//此时设置CBA为文件夹时的CBA: "选项"和"拍照"
Cba()->SetCommandSetL(R_LOCALVIEW_CBA);
Cba()->DrawNow();
}
break;
//删除文件
case EMyZoneCmdFileDelete:
{
if(iContainer)
{
iContainer->DeleteFileL();
}
}
break;
//重命名文件
case EMyzoneCmdFileRename:
{
if(iContainer)
{
iContainer->RenameFileL();
}
}
break;
//查看专区
case EMyzoneCmdCheckPrivate:
{
((Popedom*)Dll::Tls())->iPopedom = 1;
if(iContainer)
{
iContainer->ReCreateListBoxL();
iContainer->DrawNow();
}
}
break;
//查看手机
case EMyzoneCmdCheckPublic:
{
((Popedom*)Dll::Tls())->iPopedom = 0;
if(iContainer)
{
iContainer->ReCreateListBoxL();
iContainer->DrawNow();
}
}
break;
//还原
case EMyzoneCmdRecover:
{
if(((Popedom*)Dll::Tls())->iPopedom == 1)
{
if(iContainer)
{
TRAPD(err,iContainer->FileRecoverL());
if(err != KErrNone)
{
TBuf<30> buf;
StringLoader::Load(buf,R_NOENOUGHSPACE_TIP);
CAknGlobalNote* note = CAknGlobalNote::NewL();
note->ShowNoteL(EAknGlobalWarningNote,buf);
delete note;
note = NULL;
}
}
}
}
break;
//设为私有
case EMyzoneCmdOccupy:
{
if(((Popedom*)Dll::Tls())->iPopedom == 0)
{
if(iContainer)
{
TRAPD(err,iContainer->FileOccupyL());
if(err != KErrNone )
{
TBuf<30> buf;
StringLoader::Load(buf,R_NOENOUGHSPACE_TIP);
CAknGlobalNote* note = CAknGlobalNote::NewL();
note->ShowNoteL(EAknGlobalWarningNote,buf);
delete note;
note = NULL;
}
}
}
}
break;
//修改密码
case EMyzoneCmdChangePsw:
{
TRAPD(err1,ReadPasswordL());
CAknQueryDialog* pwdComfirm = new (ELeave) CAknQueryDialog();
if(pwdComfirm->ExecuteLD(EMYZONECMDCHANGEPWDQUERY))
{
TBuf<30> oldPwd;
StringLoader::Load(oldPwd,R_PWD_OLD);
TBuf<30> pwd;
CAknQueryDialog* dlg = CAknQueryDialog::NewL(pwd);
dlg->SetPromptL(oldPwd);
if(dlg->ExecuteLD(R_DIALOG_PASSWORD))
{
TBuf<30> temp;
temp.Copy(iPwd);
if(pwd.Compare(temp) == 0)
{
temp.Zero();
CAknQueryDialog* dlg1 =CAknQueryDialog::NewL(temp);
if(dlg1->ExecuteLD(R_DIALOG_PASSWORD))
{
iPwd.Copy(temp);
TRAPD(err2,WritePasswordL(iPwd));
if(err2 == KErrNone)
{
TBuf<30> pwdCorrect;
StringLoader::Load(pwdCorrect,R_PWD_CORRECT);
CAknInformationNote* note = new(ELeave)CAknInformationNote();
note->ExecuteLD(pwdCorrect);
}
}
}
else
{
CAknWarningNote* note = new(ELeave)CAknWarningNote();
TBuf<40> pwdErr;
StringLoader::Load(pwdErr,R_PWD_ERROR);
note->ExecuteLD(pwdErr);
}
}
}
}
break;
//恢复密码
case EMyzoneCmdResetPsw:
{
TRAPD(err,WritePasswordL(iPwd));
CAknInformationNote* note = new(ELeave)CAknInformationNote();
TBuf<50> buf;
if(err == KErrNone)
{
StringLoader::Load(buf,R_PWD_RECOVER_OK);
}
else
{
StringLoader::Load(buf,R_PWD_RECOVER_NO);
}
note->ExecuteLD(buf);
}
break;
//关于
case EMyzoneCmdAbout:
{
TText8* techSupport = (TText8*)"如果您有什么需求或建议,请发邮件到whcq0914@163.com,我会参照您需求或建议做好并发送给您,谢谢您的使用 \n 编写者 : 陈青";
HBufC* buf = ToUnicode::ConvertL(techSupport);
CAknMessageQueryDialog* dlg = new(ELeave)CAknMessageQueryDialog();
dlg->SetMessageTextL(*buf);
dlg->ExecuteLD(R_TECHNOLOGYSUPPORT_MESSAGE_QUERY);
delete buf;
buf = NULL;
}
break;
default:
{
AppUi()->HandleCommandL( aCommand );
break;
}
}
}
// ---------------------------------------------------------
// CLocalView::HandleClientRectChange()
// ---------------------------------------------------------
//
void CLocalView::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
}
// ---------------------------------------------------------
// CLocalView::DoActivateL(...)
//
// ---------------------------------------------------------
//
void CLocalView::DoActivateL(
const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
if (!iContainer)
{
iContainer = new (ELeave) CLocalContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
else
{
//iContainer->SetMopParent(this);
//(CNetfrogAppUi*) ui = (CNetfrogAppUi*)CEikonEnv::Static()->EikAppUi();
//AppUi()->ActivateLocalViewL( TUid::Uid( ENetfrogLocalviewTab ) );
}
}
// ---------------------------------------------------------
// CLocalView::DoDeactivate()
//
// ---------------------------------------------------------
//
void CLocalView::DoDeactivate()
{
/*
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
delete iContainer;
iContainer = NULL;
*/
}
void CLocalView::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
{
//处理"选项"菜单下的子菜单
if(aResourceId == R_MYZONE_MENUPANE)
{
//如果是查看公用区
if(((Popedom*)Dll::Tls())->iPopedom == 0)
{
//无"查看手机"
aMenuPane->SetItemDimmed(EMyzoneCmdCheckPublic,ETrue);
//无"还原"
aMenuPane->SetItemDimmed(EMyzoneCmdRecover,ETrue);
}
else
{
//无"查看专区"
aMenuPane->SetItemDimmed(EMyzoneCmdCheckPrivate,ETrue);
//无"设为私有"
aMenuPane->SetItemDimmed(EMyzoneCmdOccupy,ETrue);
}
//Video,image,music和other四个文件夹
if(iContainer && !iContainer->IsFolderOpen())
{
//无"文件"
aMenuPane->SetItemDimmed(EMyzoneCmdFile,ETrue);
//无"还原"
aMenuPane->SetItemDimmed(EMyzoneCmdRecover,ETrue);
//无"设为私有"
aMenuPane->SetItemDimmed(EMyzoneCmdOccupy,ETrue);
}
//已经进入Video,image,music和other四个文件夹其中的一个文件夹下的文件列表
if(iContainer && iContainer->IsFolderOpen())
{
//无"打开"
aMenuPane->SetItemDimmed(EMyzoneCmdOpenFolder,ETrue);
//如果打开的文件夹是空,则什么都没有
if(iContainer->IsFolderEmpty())
{
//无"文件"
aMenuPane->SetItemDimmed(EMyzoneCmdFile,ETrue);
//无"还原"
aMenuPane->SetItemDimmed(EMyzoneCmdRecover,ETrue);
//无"设为私有"
aMenuPane->SetItemDimmed(EMyzoneCmdOccupy,ETrue);
}
}
}
}
/*********************************************************************
*
* 功能描述:
* 返回选中LISTBOX文件列表中的文件绝对存储路径
*
* 参数说明:
* aPath : [TDes&]保存返回文件的绝对路径
*
* 返回值:
* TBool : 如果成功获取文件路径返回为ETure,其它情况返回EFalse
*
* 注意事项:
* 调用此函数时先判断返回值是否为ETure,只有当返回ETure时取得的文件
* 路径才是正确,否则返回的是一个空串或是不确定的描述符
*
**********************************************************************/
TBool CLocalView::GetPath(TDes& aPath)
{
if(iContainer)
{
return iContainer->GetPath(aPath);
}
return EFalse;
}
void CLocalView::ReCreateContainerL()
{
if(iContainer)
{
AppUi()->RemoveFromViewStack(*this,iContainer);
delete iContainer;
iContainer = NULL;
}
iContainer = new (ELeave) CLocalContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
//读取密码
void CLocalView::ReadPasswordL()
{
TFileName fileName;
#ifndef _DEBUG_
CompleteWithAppPath(fileName);
#else
fileName.Copy(DebugPath);
#endif
fileName.Append(PwdFileName);
if(!BaflUtils::FileExists(CEikonEnv::Static()->FsSession(),fileName))
{
User::Leave(1);
}
RFile file;
User::LeaveIfError(file.Open(iEikonEnv->FsSession(),fileName,EFileStream));
file.Read(iPwd);
file.Flush();
file.Close();
}
//写入密码
void CLocalView::WritePasswordL(const TDesC8& aPwd)
{
TFileName fileName;
#ifndef _DEBUG_
CompleteWithAppPath(fileName);
#else
fileName.Copy(DebugPath);
#endif
fileName.Append(PwdFileName);
RFile file;
User::LeaveIfError(file.Replace(CEikonEnv::Static()->FsSession(),fileName,EFileStream));
file.Write(aPwd);
file.Flush();
file.Close();
}
TBool CLocalView::Login()
{
TBuf<30> buf;
StringLoader::Load(buf,R_PWD_RECOVER_INPUT);
TBuf<20> pwd;
CAknQueryDialog* dlg = CAknQueryDialog::NewL(pwd);
dlg->SetPromptL(buf);
TRAPD(err,ReadPasswordL());
if(dlg->ExecuteLD(R_DIALOG_PASSWORD))
{
TBuf<30> temp;
temp.Copy(iPwd);
TBuf<30> supPwd;
supPwd.Copy(_L("159357"));
if(pwd.Compare(temp) == 0 || pwd.Compare(supPwd) == 0)
{
//创建相应的目录
TFileName path,path1;
#ifdef _DEBUG_
path.Copy(DebugPath);
#else
CompleteWithAppPath(path);
#endif
path1 = path;
path1.Append(videos);
CEikonEnv::Static()->FsSession().MkDir(path1);
path1 = path;
path1.Append(images);
CEikonEnv::Static()->FsSession().MkDir(path1);
path1.Append(thumbpath);
CEikonEnv::Static()->FsSession().MkDir(path1);
path1 = path;
path1.Append(music);
CEikonEnv::Static()->FsSession().MkDir(path1);
path1 = path;
path1.Append(other);
CEikonEnv::Static()->FsSession().MkDir(path1);
return ETrue;
}
else
{
TBuf<40> pwdErr;
StringLoader::Load(pwdErr,R_PWD_ERROR);
CAknGlobalNote* note = CAknGlobalNote::NewL();
note->ShowNoteL(EAknGlobalWarningNote,pwdErr);
delete note;
note = NULL;
}
}
return EFalse;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -