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

📄 agendaview.cpp

📁 手机文件浏览器 Here are the sources to SMan v1.2c 1.2 is a major jump from v1.1. You will see this from the
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "sman.h"
#include "agendaview.h"
#include <SMan.rsg>
#include <eikhlbv.h>
#include <gulicon.h>
#include <eikon.mbg>
#include <agenda.mbg>

/*************************************************************
*
* View
*
**************************************************************/

CSMan2AgendaView::CSMan2AgendaView(CConfig *cData) : CViewBase(cData)
{
	reader = new (ELeave) CAgendaFileReader(configData);
}

TBool CSMan2AgendaView::ViewScreenModeCompatible(TInt aScreenMode)
{
	return (aScreenMode == 0);
}

TVwsViewIdAndMessage CSMan2AgendaView::ViewScreenDeviceChangedL()
{
	return TVwsViewIdAndMessage(TVwsViewId(KUidSMan2App, KUidFlipclosedView));
}

void CSMan2AgendaView::ViewDeactivated()
{
	activateCount--;
	if (activateCount <= 0)
	{
		MakeVisible(EFalse);
		static_cast<CEikAppUi*>(iEikonEnv->AppUi())->RemoveFromStack(this);
		reader->CloseAgendaFile();
	}
}

void CSMan2AgendaView::ViewActivatedL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
{
	doViewActivated();
}

TVwsViewId CSMan2AgendaView::ViewId() const
{
	return TVwsViewId(KUidSMan2App, KUidAgendaView);
}

CSMan2AgendaView::~CSMan2AgendaView()
{
	// Don't need to delete these as the hierarchical list box owns them
	//delete hierModel;
	//delete hierDrawer;
	delete reader;
	delete internalHierModel;
}

void CSMan2AgendaView::ConstructL(const TRect& aRect)
{
	CreateWindowL();
	SetExtent(aRect.iTl, aRect.Size());

	// Initialize model
	hierModel = new (ELeave) CHierModel();
	hierModel->ConstructL();
	
	internalHierModel = new (ELeave) CHierModel();
	internalHierModel->ConstructL();
	
	hierModel->fullHierModel = internalHierModel;

	// Initialize item drawer
	CArrayPtrFlat<CGulIcon>* bitmaps = new (ELeave) CArrayPtrFlat<CGulIcon>(2);
	CleanupStack::PushL(bitmaps);
	// Level 0 and 1 icons
	bitmaps->AppendL(iEikonEnv->CreateIconL(_L("*"), EMbmMyheaderTodayviewclosed, EMbmMyheaderTodayviewclosedmask));
	bitmaps->AppendL(iEikonEnv->CreateIconL(_L("*"), EMbmMyheaderTodayviewopen, EMbmMyheaderTodayviewopenmask));
	_LIT(KMBMPath, "Z:\\SYSTEM\\APPS\\AGENDA\\AGENDA.MBM");

	// Level 2 icon for outstanding items
	bitmaps->AppendL(iEikonEnv->CreateIconL(KMBMPath, EMbmAgendaAgnuntimedappointment, EMbmAgendaAgnuntimedappointmentmask));

	// Level 2 icon for completed items
	bitmaps->AppendL(iEikonEnv->CreateIconL(KMBMPath, EMbmAgendaAgndoubleuntimedappointment, EMbmAgendaAgndoubleuntimedappointmentmask));
	
	CleanupStack::Pop();
	hierDrawer = new (ELeave) CHierItemDrawer(hierModel, iEikonEnv->NormalFont(), bitmaps);
	hierDrawer->fullHierModel = internalHierModel;

	cHierListBox = new (ELeave) CEikHierarchicalListBox();
	cHierListBox->ConstructL(hierModel, hierDrawer, this, 0);
	cHierListBox->CreateScrollBarFrameL();
	cHierListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	cHierListBox->SetExtent(TPoint(0, 0), TSize(Size().iWidth, Size().iHeight - 10 - EQikToolbarHeight));
	cHierListBox->SetFocus(ETrue, EDrawNow);
	controlsArray->AppendL(cHierListBox);

	viewId = CSMan2AppUi::EViewAgenda;
	bjackIconPosition = TPoint(2, cHierListBox->Position().iY + cHierListBox->Size().iHeight);
	initBJackIcon();
	SetZoomLevel(configData->zoomAgenda);
	
	MakeVisible(EFalse);
	ActivateL();
}

void CSMan2AgendaView::FixSynchTimeZone()
{
	EikFileUtils::DeleteFile(_L("C:\\SYSTEM\\DATA\\GMTOFFSET.INI"));
	EikFileUtils::DeleteFile(_L("C:\\SYSTEM\\DATA\\DAYLIGHT.INI"));
	EikFileUtils::DeleteFile(_L("C:\\SYSTEM\\APPS\\AGENDA\\AGENDA.INI"));
	CEikonEnv::Static()->InfoMsg(R_TBUF_MISC_DONE);
}

void CSMan2AgendaView::ReadAgenda(TBool dateIsSet)
{	
	if (reader->activeSchedulerStarted)
		return;

	TBuf<50> rootEntry;
	
	CEikonEnv::Static()->BusyMsgL(R_TBUF_AGENDA_BUSY, 0);	
	
	cHierListBox->SetCurrentItemIndex(0);
	internalHierModel->RemoveAllItems();

	TTime tTime;		
	if (!dateIsSet)
	{
		tTime.HomeTime();
		reader->iDay = TDateTime(tTime.DateTime().Year(), tTime.DateTime().Month(), tTime.DateTime().Day(), 0, 0, 0, 0);
	}
	else
		tTime = reader->iDay;
	
	tTime.FormatL(rootEntry, _L("%/0%1%/1%2%/2%3%/3"));
	
	tTime.HomeTime();
	if (IsSameDate(&tTime, &(reader->iDay)))
		rootEntry.Insert(0, _L("Today "));
	else
		rootEntry.Insert(0, _L("On "));

	//CHierListItem *listItem = new (ELeave) CHierListItem(0);
	CHListItem *listItem = new (ELeave) CHListItem(0);
	listItem->SetTextL(rootEntry);
	internalHierModel->AddItemL(listItem, -1, -1);

	listItem = new (ELeave) CHListItem(0);
	listItem->SetTextL(_L("Calendar"));
	internalHierModel->AddItemL(listItem, 0, KEikHierListInsertAsFirstSibling);
	
	listItem = new (ELeave) CHListItem(0);
	listItem->SetTextL(_L("Todo"));
	internalHierModel->AddItemL(listItem, 0, 1);

	/*
	Read calendar items. This class destroys itself when it's done.
	My approach to handling ExpandItemL is this:
	- create another model (data model) that will hold the COMPLETE expanded list of agenda entries 
	- based on the previous model, populate the display model as appropriate
	I also subclass CHierListItem by adding in 3 additional bits of information as explained below.
	
	TInt iFullHierListModelIndex 
	Is used in the display list to cross reference the item back to the complete list of agenda entries. By
	doing so, i can handle ExpandItemL properly since i can then obtain a list of child items for the correct
	node being expanded.
	
	TBool iComplete
	Indicates if the item was completed or not. This is done by checking against the current home time
	and also whether the item is crossed out
	
	TInt iDayListIndex
	This is cross referenced to iDayList. iDayList maintains an array of TAgnInstanceId. This is used when
	tapping on an individual item and we want to query the agenda to obtain the detailed information about
	that particular instance
	*/
	reader->ExecuteL(internalHierModel);
	
	// Populate the display model with the first item
	hierModel->RemoveAllItems();
	listItem = new (ELeave) CHListItem(0);
	listItem->SetTextL(internalHierModel->ItemText(0));
	listItem->iFullHierListModelIndex = 0;
	cHierListBox->HlModel()->AddItemL(listItem, -1, -1);

	CEikonEnv::Static()->BusyMsgCancel();

	cHierListBox->HlModel()->ExpandItemL(0);
	// If you think about it, u'll realize these need to be expanded in reverse order else i can't hard-code
	// the itemindex numbers :)
	if (configData->agendaAutoExpandTodo)
		cHierListBox->HlModel()->ExpandItemL(2);
	if (configData->agendaAutoExpandCalendar)
		cHierListBox->HlModel()->ExpandItemL(1);
	
	cHierListBox->HandleItemAdditionL();
}

TBool CSMan2AgendaView::IsSameDate(TTime *aDate1, TTime *aDate2)
{
	TInt retVal = EFalse;
	if ((aDate1->DateTime().Day() == aDate2->DateTime().Day()) &&
		(aDate1->DateTime().Month() == aDate2->DateTime().Month()) &&
		(aDate1->DateTime().Year() == aDate2->DateTime().Year()))
			retVal = ETrue;
	return retVal;
}

void CSMan2AgendaView::FetchEntry()
{
	CAgnEntry *theEntry = reader->GetOneEntry(cHierListBox->CurrentItemIndex());
	if (theEntry != NULL)
	{
		HBufC *noneText = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_AGENDA_NONE);
		HBufC *notImplementedText = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_AGENDA_NOTIMPLEMENTED);
		if (theEntry->Type() == CAgnEntry::EAppt)
		{
			CAgnAppt* calEntry = theEntry->CastToAppt();
			CAgendaDetail *detailDialog = new (ELeave) CAgendaDetail;

			TBuf<40> startDTText;
			TTime startDT = calEntry->InstanceStartDate();
			startDT.FormatL(startDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
			detailDialog->startDateTime = &startDTText;

			TBuf<40> endDTText;
			TTime endDT = calEntry->InstanceEndDate();
			if (!IsSameDate(&startDT, &endDT))
				endDT.FormatL(endDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
			else
				endDT.FormatL(endDTText, _L("%J%:1%T%+B  "));
			detailDialog->endDateTime = &endDTText;
			
			TBuf<40> alarmDTText;
			alarmDTText.Copy(*noneText);
			if (calEntry->HasAlarm())
			{
				TTime alarmDT = calEntry->AlarmInstanceDateTime();
				if (!IsSameDate(&startDT, &alarmDT))
					alarmDT.FormatL(alarmDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
				else
					alarmDT.FormatL(alarmDTText, _L("%J%:1%T%+B  "));
			}
			detailDialog->alarmDateTime = &alarmDTText;
		
			TBuf<50> locationText;
			if (calEntry->Location().Length() == 0)
				locationText.Copy(*noneText);
			else
				locationText.Copy(calEntry->Location());
			detailDialog->location = &locationText;
			
			calEntry->LoadAllComponentsL(CEikonEnv::Static()->PictureFactory());
			calEntry->NotesTextL();
			detailDialog->notes.Set(calEntry->NotesTextL());

			detailDialog->ExecuteLD(R_DIALOG_AGENDA_CALENDAR_DETAILED);
		}
		else if (theEntry->Type() == CAgnEntry::ETodo)
		{
			CAgnTodo* todoEntry = theEntry->CastToTodo();
			CTodoDetail *detailDialog = new (ELeave) CTodoDetail;

			TBuf<40> dueDTText;
			TTime dueDT = TTime(0);
			if (todoEntry->IsDated())
			{
				dueDT = todoEntry->DueDate();
				dueDT.FormatL(dueDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
			}
			else
				dueDTText.Copy(*noneText);
			detailDialog->dueDateTime = &dueDTText;

			TBuf<40> alarmDTText;
			alarmDTText.Copy(*noneText);
			if (todoEntry->HasAlarm())
			{
				TTime alarmDT = todoEntry->AlarmInstanceDateTime();
				if (!IsSameDate(&dueDT, &alarmDT))
					alarmDT.FormatL(alarmDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
				else
					alarmDT.FormatL(alarmDTText, _L("%J%:1%T%+B  "));

				//TTime alarmDT = todoEntry->AlarmInstanceDateTime();
				//alarmDT.FormatL(alarmDTText, _L("%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%+B  "));
			}
			detailDialog->alarmDateTime = &alarmDTText;
		
			TBuf<6> priorityText;
			if (todoEntry->Priority() != 0)
				priorityText.Format(_L("%d"), todoEntry->Priority());
			else
				priorityText.Copy(*noneText);
			detailDialog->priority = &priorityText;
			
			todoEntry->LoadAllComponentsL(CEikonEnv::Static()->PictureFactory());
			todoEntry->NotesTextL();
			detailDialog->notes.Set(todoEntry->NotesTextL());

			detailDialog->ExecuteLD(R_DIALOG_AGENDA_TODO_DETAILED);
		}
		delete noneText;
		delete notImplementedText;
		delete theEntry;
	}
	else
		CEikonEnv::Static()->InfoMsg(R_TBUF_AGENDA_NOTFOUND_OR_ERROR);
}

void CSMan2AgendaView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
	TInt theItem;
	TBool pointValid = cHierListBox->View()->XYPosToItemIndex(aPointerEvent.iPosition, theItem);
	
	if (!(reader->activeSchedulerStarted))
	{
		cHierListBox->HandlePointerEventL(aPointerEvent);
		if (aPointerEvent.iType == TPointerEvent::EButton1Up)
		{
			if (pointValid)
			{
				CHierListItem *itemToBeExpanded = cHierListBox->HlModel()->Item(cHierListBox->CurrentItemIndex());
				if (itemToBeExpanded->Level() == 2)
					FetchEntry();
			}
		}
	}
}

TKeyResponse CSMan2AgendaView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if (aType == EEventKey)
	{
		TBool consumed = EFalse;
		if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)
		{
			cHierListBox->View()->MoveCursorL(CListBoxView::ECursorNextItem, CListBoxView::ENoSelection);
			consumed = ETrue;
		}
		else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)
		{
			cHierListBox->View()->MoveCursorL(CListBoxView::ECursorPreviousItem, CListBoxView::ENoSelection);
			consumed = ETrue;
		}
		else	if ((aKeyEvent.iCode == EQuartzKeyConfirm) && (!(reader->activeSchedulerStarted)))
		{
			CHierListItem *itemToBeExpanded = cHierListBox->HlModel()->Item(cHierListBox->CurrentItemIndex());
			if (itemToBeExpanded->Level() < 2)
			{
				if (!itemToBeExpanded->IsExpanded())
					cHierListBox->HlModel()->ExpandItemL(cHierListBox->CurrentItemIndex());
				else
					cHierListBox->HlModel()->CollapseItem(cHierListBox->CurrentItemIndex());
				// For some god forsaken reason, HandleItemRemovalL() doesn't work when I
				// collapse the node. Sheesh... :(
				cHierListBox->HandleItemAdditionL();
			}
			else
				FetchEntry();
			consumed = ETrue;
		}
		if (consumed)
		{
			cHierListBox->UpdateScrollBarsL();
			return EKeyWasConsumed;
		}
	}
	return cHierListBox->OfferKeyEventL(aKeyEvent, aType);
}

void CSMan2AgendaView::SetDateFromCalendarAndDrawNow(const TTime& aDate)
{
	reader->iDay = TDateTime(aDate.DateTime().Year(), aDate.DateTime().Month(), aDate.DateTime().Day(), 0, 0, 0, 0);
}

void CSMan2AgendaView::GetMinimumAndMaximumAndInitialDatesForCalendarL(TTime& aMinimumDate, TTime& aMaximumDate, TTime& aInitialDate) const
{
	aMinimumDate = TTime(_L("19000101:000000.000000"));
	aMaximumDate = TTime(_L("20990101:000000.000000"));
	aInitialDate = reader->iDay;
}

void CSMan2AgendaView::ViewOtherDate()
{
	TTime now;
	now.HomeTime();

	CEikCalendar *calendar = new (ELeave) CEikCalendar;
	calendar->SetCalendarObserver(this);
	

⌨️ 快捷键说明

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