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

📄 passwordappview.cpp

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

#include <coemain.h>
#include <Password0x2936360A.rsg>

#include "PasswordAppView.h"
#include "PasswordDBMS.h"
#include <aknlists.h>
#include <barsread.h>


// Standard construction sequence
CPasswordAppView* CPasswordAppView::NewL(const TRect& aRect)
    {
    CPasswordAppView* self = CPasswordAppView::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
    }

CPasswordAppView* CPasswordAppView::NewLC(const TRect& aRect)
    {
    CPasswordAppView* self = new (ELeave) CPasswordAppView;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
    }

CPasswordAppView::CPasswordAppView()
    {
	// no implementation required
		iFristLogIndex=0;
		iNumOfLog=0;
    }

CPasswordAppView::~CPasswordAppView()
    {
	// no implementation required
	if(iDataList)
	{
		delete iDataList;
	}
	if(iPasswordDb)
	{
		delete iPasswordDb;
		iPasswordDb = NULL;
	}
    }


void CPasswordAppView::ConstructL(const TRect& aRect)
    {
    // Create a window for this application view
    CreateWindowL();

	activateListBoxL(true);	// false: do not redraw
    // Set the windows size
    SetRect(aRect);
    
    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }

void CPasswordAppView::SizeChanged()
{
        TRect r;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, r);
	if (iDataList)
		iDataList->SetExtent(TPoint(0,0), TSize(r.Width(), r.Height()));
}


TInt CPasswordAppView::CountComponentControls() const
    {
    return 1;
    }


CCoeControl* CPasswordAppView::ComponentControl(TInt aIndex) const
    {
	switch ( aIndex )
	{
		case 0: return iDataList;
		default: return NULL;
    }
}

TKeyResponse CPasswordAppView::OfferKeyEventL(const TKeyEvent& keyEvent, TEventCode type)
{
	if (type != EEventKey )
        return EKeyWasNotConsumed;

	return iDataList->OfferKeyEventL(keyEvent, type);
}
// Draw this application's view to the screen
void CPasswordAppView::Draw(const TRect& /*aRect*/) const
    {
    // Get the standard graphics context 
    CWindowGc& gc = SystemGc();
    
    // Gets the control's extent
    //TRect rect = Rect();
    
    // Clears the screen
    //gc.Clear(rect);
    }

void CPasswordAppView::activateListBoxL(TBool redraw /*true*/)
{
	delete iDataList;
	iDataList = 0;
	
 	iDataList = new (ELeave) CAknSingleStyleListBox;
	iDataList->ConstructL(this);	// default flags
	iDataList->SetContainerWindowL(*this);
    iDataList->SetListBoxObserver(this); // receiving notifications through HandleListBoxEventL

    iDataList->CreateScrollBarFrameL(ETrue);
    iDataList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);


	// Items could be read also from a resource file (ARRAY structure in .rss file),
	// in cases where items are not modifiable (and perhaps language-dependent)
	// CDesCArrayFlat* listBoxItems = iCoeEnv->ReadDesCArrayResourceL(R_MYAPPiDataList_ITEMS);

	CDesCArray* listBoxItems = generateListBoxItemsL();

	CTextListBoxModel* model = iDataList->Model();
    model->SetItemTextArray(listBoxItems);
    model->SetOwnershipType(ELbmOwnsItemArray); // transfers ownership

	if (redraw)
	{
		SizeChanged();
		iDataList->ActivateL();
		DrawNow();
	}
}

void CPasswordAppView::HandleControlEventL(CCoeControl* control, TCoeEvent eventType)
{

}

void CPasswordAppView::HandleListBoxEventL(CEikListBox* listBox, TListBoxEvent eventType)
{
    //if (!_displayListBoxNotifications)
    //    return;
	switch (eventType)	
	{   
		case EEventEnterKeyPressed :  
			//iEikonEnv->InfoMsg(_L("EEventEnterKeyPressed")); 
			ShowDeatils();
			break;
		case EEventItemClicked:       
			//iEikonEnv->InfoMsg(_L("EEventItemClicked")); 
			break;
		case EEventItemDoubleClicked: 
			//iEikonEnv->InfoMsg(_L("EEventItemDoubleClicked")); 
			break;
		case EEventItemActioned:      
			//iEikonEnv->InfoMsg(_L("EEventItemActioned")); 
			break;
		case EEventEditingStarted:    
			//iEikonEnv->InfoMsg(_L("EEventEditingStarted")); 
			break;
		case EEventEditingStopped:    
			//iEikonEnv->InfoMsg(_L("EEventEditingStopped")); 
			break;
	};
}


TBool CPasswordAppView::isListBoxEmpty() const
{
	if (iDataList == 0)
		return ETrue;
	CTextListBoxModel* model = iDataList->Model();
	return model->NumberOfItems() == 0;
}

TInt CPasswordAppView::getCurrentListBoxItem() const
{
	if (iDataList == 0)
		return -1;
	return iDataList->CurrentItemIndex();
}

CDesCArray* CPasswordAppView::generateListBoxItemsL()
{
	CDesCArray* listBoxItems = new (ELeave) CDesCArrayFlat(10);	// initial num of items
	TBuf<100> item;
	CDesCArrayFlat* PWDs;
	if(iPasswordDb)
	{
		PWDs = iPasswordDb->GetAllPasswordL(aPasswordID);
		iNumOfLog = PWDs->Count();
	}
	for (TInt i=0; i<iNumOfLog; i++) 
	{
		//FormatItem(&item,i);
		item.Format(_L("\t%S\t\t"),&PWDs->MdcaPoint(i));
		listBoxItems->AppendL(item);
	}

	return listBoxItems;
}

CDesCArray* CPasswordAppView::generateListBoxItemsL(CDesCArrayFlat* aNewItems)
{
	CDesCArray* listBoxItems = aNewItems;	// initial num of items
	TBuf<100> item;
	iNumOfLog = aNewItems->Count();
	for (TInt i=0; i<iNumOfLog; i++) 
	{
		//FormatItem(&item,i);
		item.Format(_L("\t%s\t\t"),aNewItems->At(i));
		listBoxItems->AppendL(item);
	}

	return listBoxItems;
}


void CPasswordAppView::FormatItem(TDes16* Buff, TInt i)
{
	TBuf<255> f;	// format
	f.Copy(_L("\tMeeting\t\t"));
	Buff->Format(f);
}


void CPasswordAppView::UpdateList()
{
	activateListBoxL(true);
}

void CPasswordAppView::HandleResourceChange(TInt aType)
    {
    CCoeControl::HandleResourceChange(aType);

    // ADDED FOR SCALABLE UI SUPPORT
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        //DeviceScreenChanged(rect);
        }
        if(iDataList!=NULL)
        {
        	iDataList->HandleResourceChange(aType);
        }
    }

CDesCArrayFlat* CPasswordAppView::ShowDeatils()
{
//	CDesCArrayFlat* CurrentPassword;
//	CurrentPassword = 
	return iPasswordDb->GetPasswordByKeyL(aPasswordID[iDataList->CurrentItemIndex()]);
}

void CPasswordAppView::AppendLog(TInt aRecordTime)
{
	//Use FIFO to append the log in array;
	
	TInt index;
	
	if(iNumOfLog<MAXLOGREC)
	{
		index=iNumOfLog;
		iNumOfLog++;
	}
	else if(iNumOfLog==MAXLOGREC)
	{
		index=iFristLogIndex;
		iFristLogIndex++;
		if(iFristLogIndex>=MAXLOGREC) iFristLogIndex=0;
	}
	else return;
	
	iLogArrary[index]=aRecordTime;
}

void CPasswordAppView::SetCaptionL(const TDesC& aNewCaption)
    {
    //iLabel->SetTextL(aNewCaption);
    SizeChanged();
    }

void CPasswordAppView::DeletePassword()
{
	iPasswordDb->RemovePassword(aPasswordID[iDataList->CurrentItemIndex()]);
}

TInt CPasswordAppView::GetID()
{
	return aPasswordID[iDataList->CurrentItemIndex()];
}

TInt CPasswordAppView::GetIndex()
{
	return iDataList->CurrentItemIndex();
}

void CPasswordAppView::SetCurrentIndex(TInt index)
{
	iDataList->SetCurrentItemIndex(index);
}

TInt CPasswordAppView::GetNumberOfItems()
{
	return iDataList->Model()->NumberOfItems();
}

void CPasswordAppView::UpdatePassword(TInt aID,TDes& aTitle,TDes& aUsername,TDes& aPassword,TDes& aDescription)
{
	iPasswordDb->UpdatePasswordRec(aID,aTitle,aUsername,aPassword,aDescription);
}

void CPasswordAppView::AddPassword(TDes& aTitle,TDes& aUsername,TDes& aPassword,TDes& aDescription)
{
	iPasswordDb->AddPasswordWithCppApi(aTitle,aUsername,aPassword,aDescription);
}

void CPasswordAppView::NewLPassword()
{
	iPasswordDb = CPasswordDb::NewL();
}

void CPasswordAppView::CreatePassword(TFileName iDatabaseFile)
{
	iPasswordDb->CreateDb(iDatabaseFile);
}

void CPasswordAppView::OpenPassword(TFileName iDatabaseFile)
{
	iPasswordDb->OpenDb(iDatabaseFile);
    iPasswordDb->GetDb().Compact();
}

⌨️ 快捷键说明

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