categories.cpp

来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 623 行 · 第 1/2 页

CPP
623
字号
//
	{
	if (aCommand.Type()==EQikCommandTypeCategory)
		{
		if (aCommand.Id()==EAppCmdEditCategories)
			CQikEditCategoriesDialog::RunDlgLD(CategoryModel(),this);
		else
			{
			// one of the category entries has been chosen, update selected category...
			SelectCategoryL(aCommand.CategoryHandle());

			// and update the items displayed 
			UpdateListBoxL();
			}
		}
	else
		{
		switch (aCommand.Id())
			{
		case EAppCmdAbout:
			(new(ELeave)CAboutDialog)->ExecuteLD(R_ABOUT_DIALOG);
			break;
	
		default: // e.g. the back button...
			CQikViewBase::HandleCommandL(aCommand);
			break;
			}
		}
	}

void CAppSpecificListView::HandleListBoxEventL(
//
// List box event occured - its reporting back what that might be.
//
	CQikListBox* aListBox,
	TQikListBoxEvent aEventType,
	TInt aItemIndex,
	TInt aSlotId)
	{
	switch (aEventType)
		{
	case EEventItemConfirmed:
	case EEventItemTapped:
		break;
	default:
		break;
		}
	}

void CAppSpecificListView::UpdateListBoxL()
//
// Update the listbox to contain those entries filtered by the selected category
//
	{
	// In this example we choose to remove all entries before checking whether the entries we 
	// have in the engine should belong to the list or not. 
	// An alternative approach is to only add/remove entries from the listbox which do not
	// exist and should, or do exist and should not. Either way some sensible rollback
	// should be implemented. In this example if the lbData->AddTextL() leaves then we will
	// have an empty list box. This is probably preferable to having some entries added, some
	// missing and the list not actually reflecting the chosen category closely. 
	CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1);
	listbox->RemoveAllItemsL();

	TInt handle=CurrentCategoryHandle();
	MQikListBoxModel& model(listbox->Model());
	model.ModelBeginUpdateLC();
	TInt count=iEngine->EntryListCount();
	for (TInt i=0;i<count;i++)
		{
		TAppListEntry& entry=iEngine->EntryListAt(i);
		if (handle==EAppCategoryAll || handle==entry.iCategoryId)
			{
			MQikListBoxData* lbData=model.NewDataL(MQikListBoxModel::EDataNormal);
			CleanupClosePushL(*lbData);
			lbData->AddTextL(entry.iName,EQikListBoxSlotText1);
			lbData->SetItemId(i);
			CleanupStack::PopAndDestroy(lbData);
			}
		}
	model.ModelEndUpdateL();
	}

void CAppSpecificListView::ViewConstructL()
	{
	ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);

	// we want to HandleListBoxEventL() - so observe the listboxes
	LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId1)->SetListBoxObserver(this); 

	// Create the category list, display the All category by default
	CQikCategoryModel* categories=QikCategoryUtils::ConstructCategoriesLC(R_APP_CATEGORIES);
	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();
	
	// cause listbox to display the items associated with the current category
	UpdateListBoxL();

	// 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 CAppSpecificListView::ViewDeactivated()
//
// The view is being de-activated.
//
	{
	}

void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated.
//
	const TVwsViewId& aPrevViewId,
	const TUid aCustomMessageId,
	const TDesC8& aCustomMessage)
	{
	}
	
TBool CAppSpecificListView::OkToAddCategory() const
//
// Report whether it is acceptable to add a category.
//
	{
	return(ETrue); // ok to add a category
	}

TBool CAppSpecificListView::DoAddCategoryL(TInt& aHandle)
//
// Called when the user added a new category. aHandle can be updated if the model has a preferred 
// way of linking handles to categories.
//
	{
	TQikCategoryName name(CategoryModel()->CategoryNameByHandle(aHandle));
	iEngine->AddCategoryL(aHandle,name);
	return(ETrue); // added ok
	}

TBool CAppSpecificListView::OkToRenameCategory(TInt aHandle,const TDesC& aNewName) const
//
// Report whether it is acceptable to rename a category.This is not called for 
// entries marked as EQikCategoryCantBeRenamed within the resource. It already knows the category
// cannot be renamed.
//
	{
	return(ETrue); // ok to rename a category
	}

TBool CAppSpecificListView::DoRenameCategoryL(TInt aHandle,const TDesC& aNewName)
//
// The indicated category has been renamed. We need to store the updated category name.
//
	{
	iEngine->UpdateCategoryName(aHandle,aNewName);
	return(ETrue);
	}

TBool CAppSpecificListView::OkToMergeCategories(TInt aSourceHandle,TInt aTargetHandle) const
//
// Report whether it is reasonable to merge the two categories indicated.
//
	{
	return(EFalse); // not ok to merge.
	}

TBool CAppSpecificListView::DoMergeCategoriesL(TInt aSourceHandle,TInt aTargetHandle)
//
// Merge the indicated categories. The UI does not actually support this so we dont actually 
// need to support this
//
	{
	return(EFalse);
	}

TBool CAppSpecificListView::OkToDeleteCategory(TInt aHandle) const
//
// Report whether it is reasonable to delete the category indicated. This is not called for 
// entries marked as EQikCategoryCantBeDeleted within the resource. It already knows the category
// cannot be deleted.
//
	{
	return(ETrue); // ok to delete the category
	}

TBool CAppSpecificListView::DoDeleteCategoryL(TInt aHandle)
//
// Delete the indicated category.
//
	{
	iEngine->DeleteCategory(aHandle);
	
	// Determine if we are deleting the current category, if so we need to do something sensible
	if (aHandle==CurrentCategoryHandle())
		{ // we choose to display the 'All' category - which is defined as not being deletable
		  // in this app.
		SelectCategoryL(EAppCategoryAll);

		// to display those items in EAppCategoryAll since weve deleted the previosuly displayed category
		UpdateListBoxL();
		}
	return(ETrue);
	}

TBool CAppSpecificListView::IsCategoryEmpty(TInt aHandle) const
//
// Report if the category is empty or not. If we lie and claim it is empty this enables deletion
// of categories that contain items. Items within a category that gets deleted are set to belong to 
// the Unfiled category.
//
	{
	return(ETrue); // allow deletion of category even if still contains items
	}

//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
	{
	delete(iEngine);
	}

CAppEngine* CAppSpecificUi::AppEngine() const
	{
	return(iEngine);
	}

void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
	{
	CQikAppUi::ConstructL();

	// an engine, implements any category data/model support 
	iEngine=new(ELeave)CAppEngine();
	iEngine->ConstructL();

	// Our view
	CAppSpecificListView* q=new(ELeave)CAppSpecificListView(*this,iEngine);
	CleanupStack::PushL(q);
	q->ConstructL();
	AddViewL(*q);	// takes ownership
	CleanupStack::Pop(q);
	}

/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
	{
protected:
	CQikAppUi* CreateAppUiL();
public:
    CAppSpecificDocument(CQikApplication& aApp);
	static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
	};

CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
	CQikDocument(aApp)
	{
	__DECLARE_NAME(_S("CAppSpecificDocument"));
	}

CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
	{
	return(new(ELeave)CAppSpecificDocument(aApp));
	}

CQikAppUi* CAppSpecificDocument::CreateAppUiL()
	{
	return(new(ELeave)CAppSpecificUi);
	}

//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
	{
protected:
	TUid AppDllUid() const;
	CApaDocument* CreateDocumentL();
	}; 

TUid CAppSpecificApplication::AppDllUid() const
    {
    return(KAppSpecificUid);
    }

CApaDocument* CAppSpecificApplication::CreateDocumentL()
    {
    return(CAppSpecificDocument::NewL(*this));
    }

//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
    {
    return(new CAppSpecificApplication);
    }

GLDEF_C TInt E32Main()
	{
	return(EikStart::RunApplication(NewApplication));
	}

⌨️ 快捷键说明

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