⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passwordappui.cpp

📁 symbian S60 密码本源代码 主要用于保存用户网站,BBS网址,用户名以及密码
💻 CPP
字号:
/* ====================================================================
 * File: PasswordAppUi.cpp
 * Created: 11/06/07
 * Author: 
 * Copyright (c):  All rights reserved
 * ==================================================================== */

#include <avkon.hrh>
#include <aknnotewrappers.h> 
#include <aknmessagequerydialog.h>

#include <eikapp.h>
#include "Password.pan"
#include "Password0x2936360A.rsg"
#include "PasswordAppUi.h"
#include "PasswordAppView.h"
#include "PasswordInfoView.h"
#include "Password.hrh"
#include <bautils.h>    // file helpers

_LIT(KCDrive, "C:");

// ConstructL is called by the application framework
void CPasswordAppUi::ConstructL()
    {
    BaseConstructL(CAknAppUi::EAknEnableSkin);

    //iAppView = CPasswordAppView::NewL(ClientRect());    

    //AddToStackL(iAppView);
    iInfoView = new (ELeave) CPasswordInfoView();
	iInfoView->ConstructL( ClientRect() );
	iInfoView->SetMopParent(this);
	iInfoView->MakeVisible(EFalse);

	iAppView = new (ELeave) CPasswordAppView;
	//iAppView->SetParms(aLogsView);
	iAppView->ConstructL( ClientRect() );
	iAppView->SetMopParent(this);
	iAppView->MakeVisible(ETrue);

	iCurrent=iAppView;
	
	AddToStackL( iCurrent );
    
    iAppView->NewLPassword();
	
	#if defined __SERIES60_3X__
		iDatabaseFile = DatabaseDriveAndPathL();
	#else
    	iDatabaseFile = ApplicationDriveAndPathL();
	#endif

    iDatabaseFile.Append(_L("PasswordDatabase.db"));
    
	if(!BaflUtils::FileExists(CCoeEnv::Static()->FsSession(),iDatabaseFile))
	{
		iAppView->CreatePassword(iDatabaseFile);
	}

	iAppView->OpenPassword(iDatabaseFile);
    
    isNew = false;
	isSaved = false;
	iTitleChanged = false;
	isUpdated = false;
	iOtherChanged = false;
    
    iAppView->UpdateList();
    }

CPasswordAppUi::CPasswordAppUi()                              
    {
	// no implementation required
    }

void CPasswordAppUi::HandleResourceChangeL(TInt aType)
{
    CAknAppUi::HandleResourceChangeL(aType);
    if(iCurrent!=iAppView) iAppView->HandleResourceChange(aType);
    if(iCurrent!=iInfoView) iInfoView->HandleResourceChange(aType);
}

CPasswordAppUi::~CPasswordAppUi()
    {
	    if (iCurrent)
		{
			RemoveFromStack( iCurrent );
		}
		if (iInfoView)
		{
			delete iInfoView;
			iInfoView = NULL;
		}
		if (iAppView)
		{
			delete iAppView;
			iAppView = NULL;
		}
    }

void CPasswordAppUi::ShowAboutDialog()
{
	TBuf<255> aBuf;
	TBuf<255> astr;
	
	//aBuf.Copy(_L("Counter\nfor S60 3rd Etd.\n\n30/10/2007\nasdjksdj jksajd jks huy\nm-internet-cn.com\n"));
	iCoeEnv->ReadResource( aBuf, L_UI_ABOUT_F);
	CAknMessageQueryDialog* dlgx = CAknMessageQueryDialog::NewL(aBuf);
	dlgx->PrepareLC(R_AVKON_MESSAGE_QUERY_DIALOG);

	iCoeEnv->ReadResource( aBuf, L_UI_ABOUTTITLE_F);
	astr.Copy(aBuf);
//	astr.Copy(_L("About"));
	dlgx->SetHeaderTextL(astr);
	iCoeEnv->ReadResource( aBuf, L_BACK);
	astr.Copy(aBuf);
//	iCoeEnv->ReadResource( astr, R_LABEL_BACK);
	dlgx->ButtonGroupContainer().SetCommandL(EAknSoftkeyCancel, astr);
    dlgx->ButtonGroupContainer().MakeCommandVisible(EAknSoftkeyOk,EFalse);
	dlgx->RunLD();
}

// handle any menu commands
void CPasswordAppUi::HandleCommandL(TInt aCommand)
    {
    switch(aCommand)
        {
        case EEikCmdExit:
        	Exit();
        case EAknSoftkeyExit:
        	Exit();
            break;
        case EPasswordCommand1:
			ShowAboutDialog();
            break;
       case EcmdNew:
       		if(iCurrent!=iInfoView)
         	{
 				ShowInfo();
 				isNew = true;
         	}
       		break;
       case EcmdEdit:
       		PasswordId = iAppView->GetID();
       		index = iAppView->GetIndex();
       		ShowDeatils();
       		iInfoView->SetIsEdit(true);
       		isNew = false;
       		break;	
       case EcmdDelete:
            index = iAppView->GetIndex();
			DeletePassword();
       		break;
       case EAknSoftkeyBack:
        	if(iCurrent==iInfoView)
        	{
	        	SetParms(iInfoView->GetTitleChanged());
	        	SetParmsOtherChange(iInfoView->GetOtherChanged());
	            if(!iTitleChanged && isNew)
	        	{
	        	    if(iOtherChanged)
	        	    {
	        	    	CheckItemText();
	        	    }
	        		isNew = false;
	        		SwitchToMain();
	        	}
	        	else if(iTitleChanged && isNew)
	        	{
		       		ShowSaveDialog();
		       		if(isSaved)
		       		{
						SaveSuccess();
					}
	        	}
	        	else if(!isNew)
	        	{
	        		if(iTitleChanged || iOtherChanged)
	        		{
			       		ShowUpdateDialog();
			       		if(isUpdated)
			       		{
							UpdateSuccess();
						}
	        		}
	        		else if(!iTitleChanged && !iOtherChanged)
	        		{
	        			SwitchToMain();
	        			iAppView->SetCurrentIndex(index);
	        		}
	        	}
	        	if(iInfoView->GetTitleChanged())
	        		iInfoView->SetTitleChanged(false);
	        	if(iInfoView->GetOtherChanged())
	        	    iInfoView->SetOtherChanged(false);
        	}
            break;
       case EcmdSave:
       		ShowSaveDialog();
       		if(isSaved)
       		{
				SaveSuccess();
            }
       		break;
        case EcmdUpdate:
        	isNew = false;
        	ShowUpdateDialog();
        	if(isUpdated)
        	{
				UpdateSuccess();
        	}
       		break;
        default:
            Panic(EPasswordBasicUi);
            break;
        }
    }

TKeyResponse CPasswordAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
   if (! IsDisplayingMenuOrDialog() && iCurrent==iAppView)
   {
		if(aType==EEventKeyDown)
			switch(aKeyEvent.iScanCode)
			{
				case 1:
					index = iAppView->GetIndex();
					DeletePassword();
					break;
				case EStdKeyDevice3:
					PasswordId = iAppView->GetID();
		       		index = iAppView->GetIndex();
		       		ShowDeatils();
		       	    iInfoView->SetIsEdit(true);
		       		isNew = false;
		       		iInfoView->SetIsFirst(true);
					break;
				default:
		            break;
			}
		return EKeyWasConsumed;
   }
	return EKeyWasNotConsumed;
}

void CPasswordAppUi::SwitchToMain()
{
  RemoveFromStack(iCurrent);
  iCurrent->MakeVisible(EFalse);
  iCurrent=iAppView;
  AddToStackL(iCurrent);
  CEikonEnv::Static()->AppUiFactory()->Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
  CEikonEnv::Static()->AppUiFactory()->Cba()->DrawDeferred();
  iCurrent->MakeVisible(ETrue);
  iCurrent->DrawNow();
  iInfoView->SetIsFirst(false);
}

void CPasswordAppUi::SwitchToInfoView()
{
  RemoveFromStack(iCurrent);
  iCurrent->MakeVisible(EFalse);
  iCurrent=iInfoView;
  AddToStackL(iCurrent);
  iCurrent->MakeVisible(ETrue);
  iCurrent->DrawNow();
}

void CPasswordAppUi::ShowInfo()
{
	CEikonEnv::Static()->AppUiFactory()->Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
	CEikonEnv::Static()->AppUiFactory()->Cba()->DrawDeferred();
	
	iInfoView->UpdateList();
	SwitchToInfoView();
}

TBool CPasswordAppUi::SavePassword()
{
	TBuf<255> aTitle;
    TBuf<255> aUsername;
    TBuf<255> aPassword;
    TBuf<300> aDescription;

	iInfoView->GetInfo(aTitle,aUsername,aPassword,aDescription);
    
    if(aTitle.Compare(_L(""))==0)
    {
		TBuf<256> msg;
		TBuf<256> aBuf;
		iCoeEnv->ReadResource( aBuf, L_CHECKITEM_F);
		msg.Copy(aBuf);

   		CAknQueryDialog* dlg = CAknQueryDialog::NewL( );

   		if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
	    {
	 	    SwitchToMain();
		   	return false;
	       // yes/ok pressed    
	    }
	    else 
	    {
	    	iInfoView->SetCurrentIndex(0);
	    	return false;
	    }
    }
    else 
   	{
   		iAppView->AddPassword(aTitle,aUsername,aPassword,aDescription);
   		return true;	
   	}
}

void CPasswordAppUi::CheckItemText()
{
	TBuf<255> aTitle;
    TBuf<255> aUsername;
    TBuf<255> aPassword;
    TBuf<300> aDescription;

	iInfoView->GetInfo(aTitle,aUsername,aPassword,aDescription);
    
    if(aTitle.Compare(_L(""))==0)
    {
		TBuf<256> msg;
		TBuf<256> aBuf;
		iCoeEnv->ReadResource( aBuf, L_CHECKITEM_F);
		msg.Copy(aBuf);
		
   		CAknQueryDialog* dlg = CAknQueryDialog::NewL( );

   		if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
	    {
	 	    SwitchToMain();
		   	iAppView->SetCurrentIndex(index);
	       // yes/ok pressed    
	    }
	    else 
	    {
	    	iInfoView->SetCurrentIndex(0);
	    }
    }

}

TBool CPasswordAppUi::UpdatePassword()
{
	TBuf<255> aTitle;
    TBuf<255> aUsername;
    TBuf<255> aPassword;
    TBuf<300> aDescription;
    
	iInfoView->GetInfo(aTitle,aUsername,aPassword,aDescription);
    
    iAppView->UpdatePassword(iAppView->GetID(),aTitle,aUsername,aPassword,aDescription);
    return true;
}

void CPasswordAppUi::ShowDeatils()
{
	CEikonEnv::Static()->AppUiFactory()->Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
	CEikonEnv::Static()->AppUiFactory()->Cba()->DrawDeferred();

	iInfoView->generateCurrentListBoxItemsL(iAppView->ShowDeatils());
	SwitchToInfoView();
}

void CPasswordAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
	if (aResourceId == R_PASSWORD_MENU)
	{
	   if(iCurrent==iAppView) 
	   {
			aMenuPane->SetItemDimmed(EcmdSave,ETrue);
			aMenuPane->SetItemDimmed(EcmdUpdate,ETrue);
			if(iAppView->GetNumberOfItems() == 0)
			{
				aMenuPane->SetItemDimmed(EcmdEdit,ETrue);
				aMenuPane->SetItemDimmed(EcmdDelete,ETrue);
			}
	   }
	   else if(iCurrent==iInfoView)
	   {	
	   		aMenuPane->SetItemDimmed(EcmdNew,ETrue);
	   		aMenuPane->SetItemDimmed(EcmdEdit,ETrue);
	   		aMenuPane->SetItemDimmed(EcmdDelete,ETrue);
	   		if(isNew)
	   		{
	   			aMenuPane->SetItemDimmed(EcmdUpdate,ETrue);
	   		}
	   		else 	aMenuPane->SetItemDimmed(EcmdSave,ETrue);
	   		SetParmsOtherChange(iInfoView->GetTitleChanged());
	   		SetParms(iInfoView->GetOtherChanged());
	   		if(!iTitleChanged && !iOtherChanged)
	   		{
	   			aMenuPane->SetItemDimmed(EcmdUpdate,ETrue);
	   			aMenuPane->SetItemDimmed(EcmdSave,ETrue);
	   		}
	   }
	}
}

void CPasswordAppUi::DeletePassword()
{
   TBuf<256> msg;//(_L("Delete this?"));
            //_LIT(message,L_UI_ABOUT_F);
   iCoeEnv->ReadResource( msg, L_UI_DELETE_F);

   CAknQueryDialog* dlg = CAknQueryDialog::NewL( );

   if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
       {
			iAppView->DeletePassword();
       		iAppView->UpdateList();
			index--;
		    if(index < 0)
		    {
		       	index = 0;
		    }
		    iAppView->SetCurrentIndex(index);
		    iAppView->DrawNow();
       // yes/ok pressed    
       }
}

void CPasswordAppUi::ShowSaveDialog()
{
	TBuf<256> msg;
	TBuf<256> aBuf;
	iCoeEnv->ReadResource( aBuf, L_UI_CHECKSAVE_F);
	msg.Copy(aBuf);

   CAknQueryDialog* dlg = CAknQueryDialog::NewL( );

   if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
       {
       		isSaved = SavePassword();
       		iTitleChanged = false;
       		iInfoView->SetTitleChanged(false);
       // yes/ok pressed    
       }
    else
    {
    	SwitchToMain();
	   	iAppView->UpdateList();
	   	isNew = false;
	   	iTitleChanged = false;
	   	iInfoView->SetTitleChanged(false);
    }

}

void CPasswordAppUi::ShowUpdateDialog()
{
//	TBuf<256> msg;//(_L("Delete this?"));
//	msg.Copy(_L("Update the record?"));
//   iCoeEnv->ReadResource( msg, L_UI_DELETE_F);
	TBuf<256> msg;
	TBuf<256> aBuf;
	iCoeEnv->ReadResource( aBuf, L_UI_CHECKUPDATE_F);
	msg.Copy(aBuf);

   CAknQueryDialog* dlg = CAknQueryDialog::NewL( );

   if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
       {
       		isUpdated = UpdatePassword();
       		iInfoView->SetTitleChanged(false);
       		iInfoView->SetOtherChanged(false);
       		iTitleChanged = false;
       		iOtherChanged = false;
       // yes/ok pressed    
       }
    else
    {
    	SwitchToMain();
	   	iAppView->UpdateList();
       	iInfoView->SetTitleChanged(false);
       	iInfoView->SetOtherChanged(false);
	   	iTitleChanged = false;
	   	iOtherChanged = false;
    }

}

void CPasswordAppUi::SaveSuccess()
{
	TBuf<255> aBuf;
	iCoeEnv->ReadResource( aBuf, L_UI_SAVE_F);
	//_LIT(message,"Save Success!");
	CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
	informationNote->ExecuteLD(aBuf);
	isNew = false;
	isSaved = false;
	SwitchToMain();
	iAppView->UpdateList();
	iAppView->SetCurrentIndex(iAppView->GetNumberOfItems()-1);
	iAppView->DrawNow();
}

void CPasswordAppUi::UpdateSuccess()
{
	TBuf<255> aBuf;
	//_LIT(message,L_UI_ABOUT_F);
	iCoeEnv->ReadResource( aBuf, L_UI_UPDATE_F);
	CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
	informationNote->ExecuteLD(aBuf);
	SwitchToMain();
	iAppView->UpdateList();
	iAppView->SetCurrentIndex(index);
	iInfoView->SetIsEdit(false);
}

void CPasswordAppUi::SetParms(TBool iChanged)
{
	iTitleChanged = iChanged;
}

void CPasswordAppUi::SetParmsOtherChange(TBool iChanged)
{
	iOtherChanged = iChanged;
}

TFileName CPasswordAppUi::ApplicationDriveAndPathL() const
    {
    TFileName appfullname(Application()->AppFullName());
    TParse parse;

#ifdef __WINS__   // See macro definition in DBMSDb.mmp

    // On development environment the AppFullName points to z drive.
    // Replace it to point to C drive, which is writable by our application.

    parse.Set(KCDrive, &appfullname, NULL);

#else // In device use the application fullname directly.

    parse.Set(appfullname, NULL, NULL);

#endif

    TFileName fn = parse.DriveAndPath();
    // Make sure the path exists (create if not). This is needed in EMULATOR.
    BaflUtils::EnsurePathExistsL(CCoeEnv::Static()->FsSession(), fn);
    return fn;
    }

#if defined __SERIES60_3X__
// ---------------------------------------------------------------------------
// CDBMSAppUi::DatabaseDriveAndPathL()
// ---------------------------------------------------------------------------
//
TFileName CPasswordAppUi::DatabaseDriveAndPathL() const
{	
	RFs fsSession;
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);
	
    TFileName appfullname, fn;
    appfullname = Application()->AppFullName();
	fsSession.PrivatePath(fn);

#ifdef __WINS__   // See macro definition in DBMS.mmp
	fn.Insert(0,KCDrive);

#else // In device use the application fullname directly.
    TParse parse;
    parse.Set(appfullname, NULL, NULL);
    fn.Insert(0,parse.Drive());   
#endif

    BaflUtils::EnsurePathExistsL(fsSession, fn);
	CleanupStack::PopAndDestroy(&fsSession);
	
    return fn;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -