📄 passwordinfoview.cpp
字号:
/* ====================================================================
* File: PasswordInfoView.cpp
* Created: 11/06/07
* Author:
* Copyright (c): , All rights reserved
* ==================================================================== */
#include <coemain.h>
#include <Password0x2936360A.rsg>
#include "PasswordInfoView.h"
#include <aknquerydialog.h>
#include <aknlists.h>
#include <barsread.h>
// Standard construction sequence
CPasswordInfoView* CPasswordInfoView::NewL(const TRect& aRect)
{
CPasswordInfoView* self = CPasswordInfoView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CPasswordInfoView* CPasswordInfoView::NewLC(const TRect& aRect)
{
CPasswordInfoView* self = new (ELeave) CPasswordInfoView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CPasswordInfoView::CPasswordInfoView()
{
// no implementation required
iFristLogIndex=0;
iNumOfLog=0;
iTitleChanged = false;
iOtherChanged = false;
isFirst = false;
isEdit = false;
}
CPasswordInfoView::~CPasswordInfoView()
{
// no implementation required
if(iDataList)
{
delete iDataList;
}
}
void CPasswordInfoView::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 CPasswordInfoView::SizeChanged()
{
TRect r;
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, r);
if (iDataList)
iDataList->SetExtent(TPoint(0,0), TSize(r.Width(), r.Height()));
}
TInt CPasswordInfoView::CountComponentControls() const
{
return 1;
}
CCoeControl* CPasswordInfoView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0: return iDataList;
default: return NULL;
}
}
TKeyResponse CPasswordInfoView::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 CPasswordInfoView::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 CPasswordInfoView::activateListBoxL(TBool redraw /*true*/)
{
delete iDataList;
iDataList = 0;
iDataList = new (ELeave) CAknSettingStyleListBox;
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 CPasswordInfoView::generateCurrentListBoxItemsL(CDesCArrayFlat * iCurrentPassword)
{
delete iDataList;
iDataList = 0;
iDataList = new (ELeave) CAknSettingStyleListBox;
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(iCurrentPassword);
CTextListBoxModel* model = iDataList->Model();
model->SetItemTextArray(listBoxItems);
model->SetOwnershipType(ELbmOwnsItemArray); // transfers ownership
SizeChanged();
iDataList->ActivateL();
DrawNow();
}
void CPasswordInfoView::HandleControlEventL(CCoeControl* control, TCoeEvent eventType)
{
}
void CPasswordInfoView::HandleListBoxEventL(CEikListBox* listBox, TListBoxEvent eventType)
{
//if (!_displayListBoxNotifications)
// return;
if(isFirst)
{
isFirst = false;
return;
}
switch (eventType)
{
case EEventEnterKeyPressed :
//iEikonEnv->InfoMsg(_L("EEventEnterKeyPressed"));
EditItemIndex();
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 CPasswordInfoView::isListBoxEmpty() const
{
if (iDataList == 0)
return ETrue;
CTextListBoxModel* model = iDataList->Model();
return model->NumberOfItems() == 0;
}
TInt CPasswordInfoView::getCurrentListBoxItem() const
{
if (iDataList == 0)
return -1;
return iDataList->CurrentItemIndex();
}
CDesCArray* CPasswordInfoView::generateListBoxItemsL()
{
CDesCArray* listBoxItems = new (ELeave) CDesCArrayFlat(4); // initial num of items
TBuf<100> item;
TBuf<255> f[4]; // format
//f.Copy(_L("\tInput text language\t\tAutomatic"));
iCoeEnv->ReadResource( f[0], L_TITLE);
iCoeEnv->ReadResource( f[1], L_USERNAME);
iCoeEnv->ReadResource( f[2], L_PASSWORD);
iCoeEnv->ReadResource( f[3], L_DESCRIPTION);
// f[0].Copy(_L("Title"));
// f[1].Copy(_L("Username"));
// f[2].Copy(_L("Password"));
// f[3].Copy(_L("Description"));
for (TInt i=0; i<4; i++)
{
item.Format(_L("\t%S\t\t"),&f[i]);
listBoxItems->AppendL(item);
}
return listBoxItems;
}
CDesCArray* CPasswordInfoView::generateListBoxItemsL(TDesC& text)
{
CDesCArray* listBoxItems = new (ELeave) CDesCArrayFlat(4); // initial num of items
TBuf<300> item;
TBuf<255> f[4]; // format
// f[0].Copy(_L("Title"));
// f[1].Copy(_L("Username"));
// f[2].Copy(_L("Password"));
// f[3].Copy(_L("Description"));
iCoeEnv->ReadResource( f[0], L_TITLE);
iCoeEnv->ReadResource( f[1], L_USERNAME);
iCoeEnv->ReadResource( f[2], L_PASSWORD);
iCoeEnv->ReadResource( f[3], L_DESCRIPTION);
for (TInt i=0; i<4; i++)
{
if(iDataList->CurrentItemIndex() == i)
{
item.Format(_L("\t%S\t\t%S"),&f[i],&text);
listBoxItems ->AppendL(item);
}
else
{
item=iDataList->Model()->ItemText(i);
if((item.Right((item.Length())-(item.LocateReverseF('\t'))-1)).Compare(_L("No data"))==0)
item = item.Left(item.LocateReverseF('\t'));
listBoxItems->AppendL(item);
}
}
return listBoxItems;
}
CDesCArray* CPasswordInfoView::generateListBoxItemsL(CDesCArrayFlat * iCurrentPassword)
{
CDesCArray* listBoxItems = new (ELeave) CDesCArrayFlat(4); // initial num of items
TBuf<300> item;
TBuf<255> f[6]; // format
//f.Copy(_L("\tInput text language\t\tAutomatic"));
// f[0].Copy(_L("Title"));
// f[1].Copy(_L("Username"));
// f[2].Copy(_L("Password"));
// f[3].Copy(_L("Description"));
iCoeEnv->ReadResource( f[0], L_TITLE);
iCoeEnv->ReadResource( f[1], L_USERNAME);
iCoeEnv->ReadResource( f[2], L_PASSWORD);
iCoeEnv->ReadResource( f[3], L_DESCRIPTION);
iCoeEnv->ReadResource( f[4], L_CREATEDATE);
iCoeEnv->ReadResource( f[5], L_MODIFYDATE);
// f[4].Copy(_L("Password"));
// f[5].Copy(_L("Description"));
for (TInt i=0; i<6; i++)
{
item.Format(_L("\t%S\t\t%S"),&f[i],&iCurrentPassword->MdcaPoint(i));
listBoxItems->AppendL(item);
}
return listBoxItems;
}
void CPasswordInfoView::FormatItem(TDes16* Buff, TInt i)
{
}
void CPasswordInfoView::UpdateList()
{
activateListBoxL(true);
}
void CPasswordInfoView::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);
}
}
void CPasswordInfoView::ShowDeatils()
{
}
void CPasswordInfoView::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 CPasswordInfoView::ShowTextDialog(TInt currenIndex)
{
// The descriptor used for the editor
TBuf<300> text;
TInt index;
index = currenIndex;
// if(isEdit)
// {
//text.Format(_L("%S"),&iCurrentPassword->MdcaPoint(index));
text.Copy(iDataList->Model()->ItemText(index));
text = text.Right((text.Length())-(text.LocateReverseF('\t'))-1);
// }
// The descriptor contained the prompt text for the query. The prompt // text can also be defined in the resource structure of the query
// if(text.Compare(_L("No data"))==0)
// text.Copy(_L(""));
TBuf<300> prompt;//(_L("Enter data:"));
// iCoeEnv->ReadResource( prompt, L_ENTERDATA);
prompt.Copy(iDataList->Model()->ItemText(index));
prompt = prompt.Left((prompt.LocateReverseF('\t')) - 1);
prompt = prompt.Right(prompt.Length() - 1);
// create dialog instance
CAknTextQueryDialog* dlg =
new( ELeave ) CAknTextQueryDialog( text, prompt );
// Prepares the dialog, constructing it from the specified resource
dlg->PrepareLC( R_DEMO_DATA_QUERY );
// Sets the maximum length of the text editor
if(index == 3)
dlg->SetMaxLength(255);
else
dlg->SetMaxLength(64);
// Launch the dialog
if (dlg->RunLD())
{
CDesCArray* listBoxItems = generateListBoxItemsL(text);
CTextListBoxModel* model = iDataList->Model();
model->SetItemTextArray(listBoxItems);
model->SetOwnershipType(ELbmOwnsItemArray); // transfers ownership
SizeChanged();
iDataList->ActivateL();
DrawNow();
if(index == 0)
{
iTitleChanged = true;
}
else iOtherChanged = true;
// ok pressed, text is the descriptor containing the entered text // in the editor.
}
}
/*void CPasswordInfoView::SetParms(CPasswordDb * iPasswordDb)
{
iPWDDb = iPasswordDb;
}*/
void CPasswordInfoView::Setparms(CDesCArrayFlat* CurrentPassword)
{
iCurrentPassword = CurrentPassword;
}
void CPasswordInfoView::EditItemIndex()
{
if(iDataList->CurrentItemIndex()==0 ||
iDataList->CurrentItemIndex()==1 ||
iDataList->CurrentItemIndex()==2 ||
iDataList->CurrentItemIndex()==3)
{
ShowTextDialog(iDataList->CurrentItemIndex());
}
}
void CPasswordInfoView::SetCurrentIndex(TInt index)
{
iDataList->SetCurrentItemIndex(index);
}
void CPasswordInfoView::SetTitleChanged(TBool isChanged)
{
iTitleChanged = isChanged;
}
void CPasswordInfoView::SetOtherChanged(TBool isChanged)
{
iOtherChanged = isChanged;
}
TBool CPasswordInfoView::GetTitleChanged()
{
return iTitleChanged;
}
TBool CPasswordInfoView::GetOtherChanged()
{
return iOtherChanged;
}
void CPasswordInfoView::GetInfo(TDes& aTitle,TDes& aUsername,TDes& aPassword,TDes& aDescription)
{
aTitle.Copy(iDataList->Model()->ItemText(0));
aTitle = aTitle.Right((aTitle.Length())-(aTitle.LocateReverseF('\t'))-1);
aUsername.Copy(iDataList->Model()->ItemText(1));
aUsername = aUsername.Right((aUsername.Length())-(aUsername.LocateReverseF('\t'))-1);
aPassword.Copy(iDataList->Model()->ItemText(2));
aPassword = aPassword.Right((aPassword.Length())-(aPassword.LocateReverseF('\t'))-1);
aDescription.Copy(iDataList->Model()->ItemText(3));
aDescription = aDescription.Right((aDescription.Length())-(aDescription.LocateReverseF('\t'))-1);
}
void CPasswordInfoView::SetIsEdit(TBool iBool)
{
isEdit = iBool;
}
void CPasswordInfoView::SetIsFirst(TBool iBool)
{
isFirst = iBool;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -