listview.cpp
来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 772 行 · 第 1/2 页
CPP
772 行
// Symbian Signed test criteria CON-03 requires we inform the user we might
// cause a billable event - quite why CQikSendAsDialog does not do this is a bit of
// an oversight... still its not that hard to add.
iEikonEnv->InfoWinL(R_STR_SENDAS_BILLABLE_EVENT_TITLE,R_STR_SENDAS_BILLABLE_EVENT_INFO);
CQikSendAsLogic* sendAs=CQikSendAsLogic::NewL();
CleanupStack::PushL(sendAs);
// If you wanted to have subject and body text they would be obtained and set here.. This simply
// supports sending a file
// _LIT(KSubjectText,"Subject text");
// _LIT(KBodyText,"Body text");
// sendAs->SetSubjectL(KSubjectText);
// sendAs->SetBodyTextL(KBodyText);
TFileName fullName;
iEngine->EntryFullName(fullName);
sendAs->AddAttachmentL(fullName);
CleanupStack::Pop(sendAs); // CQikSendAsDialog guarantees to take ownership
// KUidMtmQuerySupportAttachments = only display transports that support attachments, as thats
// what we are attempting to send. (e.g. SMS gets filtered out)
CQikSendAsDialog::RunDlgLD(sendAs,KUidMtmQuerySupportAttachments);
}
void CListView::DeleteCurrentEntryL()
//
// User may want to remove the current entry. Firstly request the user confirms they really want to
// do this. If confirmed then go ahead.
//
{
SetCurrentEntry();
const TFolderEntry& entry=iEngine->CurrentEntry();
TBuf<256>bb;
iEikonEnv->Format256(bb,R_STR_ABOUT_TO_DELETE,&entry.EntryName());
TBuf<64>bb2;
iEikonEnv->ReadResourceL(bb2,R_STR_ATTENTION);
if (iEikonEnv->QueryWinL(bb2,bb))
{
// before the entry is deleted use any properties
iEikonEnv->Format256(bb,R_STR_DELETED,&entry.EntryName());
// remove entry from disk
iEngine->DeleteCurrentEntryL();
// remove from the list view list display as its been deleted
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EListViewListId);
listbox->RemoveItemL(listbox->CurrentItemIndex());
// now ensure engine and listBox think the same entry is the current entry
TInt i=iEngine->CurrentEntryIndex();
if (i>=0)
listbox->SetCurrentItemIndexL(i,ETrue,EDrawNow);
// give some +ve feedback to the user that the delete has occured
iEikonEnv->InfoMsg(bb);
// e.g. if no more entries in the current list, make items unavailable.
UpdateCommandAvailability();
}
}
void CListView::TidyUpSoundPlayer()
//
// Tidy up sound player resources.
//
{
if (iSoundPlayer)
{
// cancel any playback, harmless if not playing back, but will panic if we have not
// completed the initialization yet.
if (iSoundInitialized)
iSoundPlayer->Stop();
iSoundInitialized=EFalse;
iSoundPlayer->Close();
delete(iSoundPlayer);
iSoundPlayer=NULL;
}
}
void CListView::MapcInitComplete(TInt aError,const TTimeIntervalMicroSeconds& aDuration)
//
// The sound we are attempting to play has been loaded.
//
{
if (aError)
{
TidyUpSoundPlayer();
TBuf<128>bb;
iEikonEnv->Format128(bb,R_STR_PLAY_SOUND_ERROR,aError);
iEikonEnv->InfoMsg(bb);
return;
}
iSoundInitialized=ETrue;
TInt vol=iSoundPlayer->MaxVolume();
if (iLevel==ESoundLevelMedium)
vol>>=1; // half
else if (iLevel==ESoundLevelLow)
vol>>=2; // quarter
iSoundPlayer->SetVolume(vol);
iSoundPlayer->Play(); // will call back MapcPlayComplete() when sound playing finished
iEikonEnv->InfoMsg(R_STR_OPEN_SOUND);
}
void CListView::MapcPlayComplete(TInt aError)
//
// The sound we were playing has finished, successfully or otherwise.
//
{
TidyUpSoundPlayer();
}
void CListView::PlayAudioEntryL()
//
// The entry has been classified as an audio entry. Play it back
//
{
// if any sound is currently playing we need to ensure we stop it in this application
// since we re-use the iSoundPlayer property for a different sound.
TidyUpSoundPlayer();
// Create a sound player to playback the currently selected file.
TFileName name;
iEngine->EntryFullName(name);
iLevel=ESoundLevelMedium;
iSoundInitialized=EFalse;
// calls back MapcInitComplete() when the sound is loaded.
iSoundPlayer=CMdaAudioPlayerUtility::NewFilePlayerL(name,*this);
}
void CListView::OpenEntryL()
//
// View/Open/Play the current entry
//
{
SetCurrentEntry();
switch (iEngine->CurrentEntry().EntryCategory())
{
case EAppCategorySound:
PlayAudioEntryL();
break;
case EAppCategoryImage:
iQikAppUi.ActivateViewL(KViewIdImageConversionView);
break;
case EAppCategoryVideo:
iQikAppUi.ActivateViewL(KViewIdVideoPlaybackView);
break;
default:
iEikonEnv->InfoWinL(R_STR_UNKNOWN_OPEN_TITLE,R_STR_UNKNOWN_OPEN_INFO);
break;
}
}
void CListView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
if (aCommand.Type()==EQikCommandTypeCategory)
{
if (aCommand.Id()==EAppCmdEditCategories)
CQikEditCategoriesDialog::RunDlgLD(CategoryModel(),this);
else
{ // one of the category entries has been chosen, update selected category...
iEngine->ChangeCategoryL(aCommand.CategoryHandle());
SelectCategoryL(aCommand.CategoryHandle());
UpdateListBoxL();
UpdateCommandAvailability();
}
}
else
{
switch (aCommand.Id())
{
case EAppCmdOpen:
OpenEntryL();
break;
case EAppCmdNew:
{
CCreateNewDialog* q=new(ELeave)CCreateNewDialog;
TInt type=q->ExecuteLD();
if (type==EQikCmdGoBack)
break; // cancelled via a back button (or app button etc)
if (!type)
iQikAppUi.ActivateViewL(KViewIdAudioRecordView);
else
{
// even if we cant goto view properly - e.g. no camera on device, UIQ will still leave
// us in the view, despite the CCameraView::ViewActivatedL() leaving - as its failed to
// implement sensible rollback.. e.g. to this view.
iQikAppUi.ActivateViewL(KViewIdCameraView);
}
// The following system dialog could be used to capture a photo. This app has chosen to
// perform the functionality at a more basic level to demo how that is also possible.
// {
// CFbsBitmap* image=NULL;
// CQikCameraCaptureDlg::RunDlgLD(image);
// delete(image);
// }
break;
}
case EAppCmdDelete:
case EAppCmdDelete2:
DeleteCurrentEntryL();
break;
case EAppCmdSortCascade:
break;
case EAppCmdSortByName:
SortListL(EFolderEntrySortByName,iEngine->SortOrder(),EAppCmdSortByName);
break;
case EAppCmdSortBySize:
SortListL(EFolderEntrySortBySize,iEngine->SortOrder(),EAppCmdSortBySize);
break;
case EAppCmdSortByDate:
SortListL(EFolderEntrySortByModified,iEngine->SortOrder(),EAppCmdSortByDate);
break;
case EAppCmdSortByType:
SortListL(EFolderEntrySortByType,iEngine->SortOrder(),EAppCmdSortByType);
break;
case EAppCmdSortOrder: // swap between ascending and descending
SortListL(iEngine->SortType(),(TFolderEntrySortOrder)(ESortOrderAscending+
ESortOrderDescending-iEngine->SortOrder()),EAppCmdSortOrder);
break;
case EAppCmdSendAs:
SendFileAsL();
break;
case EAppCmdZoom: // Launch the system std zoom dialog
CQikZoomDialog::RunDlgLD(iEngine->ListViewZoomState(),*this);
break;
case EQikCmdZoomLevel1: // delivered by the std system zoom dlg...
case EQikCmdZoomLevel2:
case EQikCmdZoomLevel3:
if (iEngine->SetListViewZoomState(aCommand.Id()))
{ // zoom state has changed
CQikViewBase::SetZoomFactorL(CQikAppUi::ZoomFactorL(aCommand.Id(),*iEikonEnv));
PerformLayout();
}
break;
case EAppCmdRegister:
iQikAppUi.HandleCommandL(EAppCmdRegister);
break;
case EAppCmdAbout:
iQikAppUi.HandleCommandL(EAppCmdAbout);
break;
case EEikCmdExit:
iQikAppUi.HandleCommandL(EEikCmdExit);
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
}
CQikCommand* CListView::DynInitOrDeleteCommandL(
//
// As commands are added to the view we get the opportunity to perform some actions.
// In this case we want to ensure the Radio buttons and SortOrder check item are correct.
//
CQikCommand* aCommand,
const CCoeControl& aControlAddingCommands)
{
TBool val=EFalse;
switch (aCommand->Id())
{
// determine which of the radio buttons should be checked
case EAppCmdSortByName:
if (iEngine->SortType()==EFolderEntrySortByName)
val=ETrue;
aCommand->SetChecked(val);
break;
case EAppCmdSortBySize:
if (iEngine->SortType()==EFolderEntrySortBySize)
val=ETrue;
aCommand->SetChecked(val);
break;
case EAppCmdSortByType:
if (iEngine->SortType()==EFolderEntrySortByType)
val=ETrue;
aCommand->SetChecked(val);
break;
case EAppCmdSortByDate:
if (iEngine->SortType()==EFolderEntrySortByModified)
val=ETrue;
aCommand->SetChecked(val);
break;
// determine whether the single check box type menu option should be checked
case EAppCmdSortOrder:
if (iEngine->SortOrder()==ESortOrderAscending)
val=ETrue;
aCommand->SetChecked(val);
break;
default:
break;
}
return(aCommand);
}
void CListView::ViewConstructL()
{
// Loads information about the UI configurations this view supports
// together with definition of each view.
ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);
// we want to HandleListBoxEventL() - so observe all the listboxes
LocateControlByUniqueHandle<CQikListBox>(EListViewListId)->SetListBoxObserver(this);
// Create the category list, this version creates it from the set within the engine
CQikCategoryModel* categories=CQikCategoryModel::NewLC();
const TInt count=iEngine->CategoryListCount();
for (TInt i=0;i<count;i++)
{
const TAppCategoryEntry& entry=iEngine->CategoryListAt(i);
TInt16 flags;
if (entry.iCategoryId==EAppCategoryAll)
flags=EQikCategoryCantBeRenamed | EQikCategoryCantBeDeleted | EQikCategoryAll;
else if (entry.iCategoryId==EAppCategoryUnfiled)
flags=EQikCategoryCantBeRenamed | EQikCategoryCantBeDeleted | EQikCategoryUnfiled;
else
flags=0;
categories->AddCategoryL(entry.iCategoryId,entry.iCategoryName,flags);
}
SetCategoryModel(categories); // takes ownership
CleanupStack::Pop(categories);
// by default we view the 'All' category
SelectCategoryL(EAppCategoryAll);
// Cause the category picker to be visible/softkey command group to exist.
SetCategoryModelAsCommandsL();
// set the line below app name to be "List title"
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_LIST_TITLE);
ViewContext()->AddTextL(1,bb);
}
void CListView::ViewDeactivated()
//
// The view is being de-activated.
//
{
// we always rebuild when come foreground so remove all items here
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EListViewListId);
TRAPD(junk,listbox->RemoveAllItemsL());
}
void CListView::ViewActivatedL(
//
// The view is being activated.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
UpdateListBoxL();
TInt i=iEngine->CurrentEntryIndex();
if (i>=0)
LocateControlByUniqueHandle<CQikListBox>(EListViewListId)->SetCurrentItemIndexL(i,ETrue,EDrawNow);
UpdateCommandAvailability();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?