예제 #1
0
void CDummyCalendarApp::AddEntryL(TInt aNumToAdd, TBool isParent, TBool isRepeat)
	{
	test.Next(_L("Adding entries"));

	TBuf<50> summary;
	TBuf<50> location;
	TBuf<50> description;

    

	iEntries.ResetAndDestroy();
	for (TInt index=0; index<aNumToAdd; index++)
		{
		TBuf8<255> buf;
		buf.Append(_L("GuidId"));
		buf.AppendNum(index);
		HBufC8* guid = buf.AllocLC();   // need to be pushed to ...

		CCalEntry::TType entryType=(index%2==0)?CCalEntry::ETodo:CCalEntry::EAppt;

		CCalEntry* entry = NULL;
		if(isParent)
			{
			entry = CreateCalEntryL(entryType, guid);
			}
		else
			{
			TTime localTime(KRecurrIdLocalTime);
			TCalTime recurrenceId;
			recurrenceId.SetTimeLocalL(localTime);
			entry = CCalEntry::NewL(entryType, guid, CCalEntry::EMethodAdd, 1, recurrenceId, CalCommon::EThisAndFuture);
			}
		CleanupStack::Pop(guid);
		iEntries.AppendL(entry);

		TInt year = -1;
		TInt month = -1;
		TInt day = -1;
		
		if (isParent)
		    {
    		year = index % 5 + 2001;    // Any year in the range: 2001 - 2005
    		month = index % 12;         
    		day = index % 28;
		    }
        else
            {
            // if this is a child entry, use the recurrence local time as the entry start time 
            // so it won't be out of range
            TCalTime recurrId = entry->RecurrenceIdL(); 
            TDateTime localTime = recurrId.TimeLocalL().DateTime();               
            year = localTime.Year();
            month = localTime.Month();
            day = localTime.Day();    
            }
		
		TTime start(TDateTime(year, (TMonth)month, day, 0, 0, 0, 0));
		TTime end(TDateTime(year, (TMonth)month, day, 0, 0, 0, 0));
		end += TTimeIntervalDays(1);

		SetEntryStartAndEndTimeL(entry,start,end);
				
		RandomText(summary);
		entry->SetSummaryL(summary);
		
		RandomText(location);
		entry->SetLocationL(location);
		
		RandomText(description);
		entry->SetDescriptionL(description);

		if(isRepeat)
			{
			//create a daily repeat rule and make sure its repeat start\end date is within the deleting time range
			TCalRRule rpt(TCalRRule::EDaily);
			rpt.SetInterval(1);
			TCalTime repeatStart;
			TCalTime repeatend;
			if(isParent)
				{
				//make sure the repeat time is within the delete time range
				repeatStart.SetTimeLocalL(TDateTime(2000, EJune, 0, 0, 0, 0, 0));
				repeatend.SetTimeLocalL(TDateTime(2006, EJune, 0, 0, 0, 0, 0));
				}
			else if (index<aNumToAdd/2)
				{
                // if this is a child entry, use the entry's recurrance time as repeating rule
                // start time 
                TCalTime recurrId = entry->RecurrenceIdL(); 
				
				// make sure the repeat time is within the delete time range for the first half entries
				repeatStart.SetTimeLocalL(recurrId.TimeLocalL());	// June 1, 2003 00:00:00
				repeatend.SetTimeLocalL(recurrId.TimeLocalL() + TTimeIntervalMonths(1));  // July 1, 2003 00:00:00
				}
			else
				{
				//make sure the repeat time is out of the delete time range for the second half entries
				repeatStart.SetTimeLocalL(TDateTime(2003, EJune, 0, 0, 0, 0, 0));
				repeatend.SetTimeLocalL(TDateTime(2007, EJune, 0, 0, 0, 0, 0));
				}

			rpt.SetDtStart(repeatStart); 
			rpt.SetUntil(repeatend);
			entry->SetRRuleL(rpt);
			}
		}
	
	TInt entriesStored(0);
	iLocalEntryView->StoreL(iEntries, entriesStored); //temp
	test(entriesStored == iEntries.Count());
	}
예제 #2
0
void CDummyCalendarApp::Add3ReminderAnd1ApptL()
	{
	test.Next(_L("Create some entries including day note and delete them"));


//Create entries	
	iEntries.ResetAndDestroy();
	//create reminder 1
	TBuf8<255> buf;
	buf.Append(_L("GuidId_Reminder_1"));
	HBufC8* guid = buf.AllocLC();
	CCalEntry* reminder1 = CCalEntry::NewL(CCalEntry::EReminder, guid, CCalEntry::EMethodAdd, 0);
	CleanupStack::Pop(guid);
	iEntries.AppendL(reminder1);

	TCalTime starttime;
	starttime.SetTimeLocalL(TDateTime(2006, EMarch, 5, 0, 0, 0, 0));
	reminder1->SetStartAndEndTimeL(starttime, starttime);

	TBuf<50> summary;
	RandomText(summary);
	reminder1->SetSummaryL(summary);

	//create reminder 2
	buf.Delete(buf.Length()-1,1);
	buf.Append(2);
	guid = buf.AllocLC();
	CCalEntry* reminder2 = CCalEntry::NewL(CCalEntry::EReminder, guid, CCalEntry::EMethodAdd, 0);
	CleanupStack::Pop(guid);
	iEntries.AppendL(reminder2);
	starttime.SetTimeLocalL(TDateTime(2006, EMarch, 6, 0, 0, 0, 0));
	reminder2->SetStartAndEndTimeL(starttime, starttime);
	RandomText(summary);
	reminder2->SetSummaryL(summary);

	//create reminder 3
	buf.Delete(buf.Length()-1,1);
	buf.Append(3);
	guid = buf.AllocLC();
	CCalEntry* reminder3 = CCalEntry::NewL(CCalEntry::EReminder, guid, CCalEntry::EMethodAdd, 0);
	CleanupStack::Pop(guid);
	iEntries.AppendL(reminder3);
	starttime.SetTimeLocalL(TDateTime(2006, EMarch, 7, 0, 0, 0, 0));
	reminder3->SetStartAndEndTimeL(starttime, starttime);
	RandomText(summary);
	reminder3->SetSummaryL(summary);
	
	//Create appt
	buf.Zero();
	buf.Append(_L("GuidId_Appt"));
	guid = buf.AllocLC();
	CCalEntry* appt = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodAdd, 0);
	CleanupStack::Pop(guid);
	iEntries.AppendL(appt);
	
	starttime.SetTimeLocalL(TDateTime(2006, EMarch, 7, 14, 0, 0, 0));
	TTime endtimetime(TDateTime(2006, EMarch, 7, 14, 0, 0, 0));
	endtimetime +=TTimeIntervalHours(1);
	TCalTime endtime;
	endtime.SetTimeLocalL(endtimetime);
	appt->SetStartAndEndTimeL(starttime, endtime);

	RandomText(summary);
	appt->SetSummaryL(summary);

//store 4 entries
	TInt entriesStored(0);
	SynCGetEntryViewL().StoreL(iEntries, entriesStored); 
	test(entriesStored == 4);
	iEntries.ResetAndDestroy();
	}
CAgnEntry* CAgnCalendarConverter209::InternalizeEntryL(RReadStream& aStream, TBool& aHasExtended)
	{
	enum TAgnEntryTypeV9192 // the entry type enumeration in v9.1 and v9.2
		{
		EAgnAppt,
		EAgnTodo,
		EAgnEvent,
		EAgnAnniv
		};
	
	const TInt KAgnExtendedDataFlag = 0x80;
    // Remove 9.1's/9.2's KAgnExtendedDataFlag (0x80)
    // from the entry type
    //
    TUint8 typeData = aStream.ReadUint8L();
    
	if (typeData & KAgnExtendedDataFlag)
		{
		const TUint8 KVersion = aStream.ReadUint8L();
		__ASSERT_ALWAYS(KVersion !=0, User::Leave(KErrCorrupt));  //version mumbers started from 1
		if (KVersion > 1)
			{
			const TUint8 KLength = aStream.ReadUint8L();
			for (TInt i=0; i<KLength; ++i)
				{
				aStream.ReadUint8L(); //skip additional data becouse we don't support it yet
				}
			}
		typeData &= ~KAgnExtendedDataFlag;
		}
		
	const TAgnEntryTypeV9192 KV9192Type = static_cast<TAgnEntryTypeV9192>(typeData);
	
	CCalEntry::TType entryType = CCalEntry::EAppt;

	TAgnEntryId entryId;
	entryId.InternalizeL(aStream); //TUInt32 iId
	TUint16 attributes = aStream.ReadUint16L(); 
	
	switch (KV9192Type)
		{
		case EAgnAppt:
			if (attributes & EBit9)
				{
				entryType = CCalEntry::EReminder; // is a day note
				}
			else
				{
				entryType = CCalEntry::EAppt;
				}
			break;
		case EAgnAnniv:
			entryType = CCalEntry::EAnniv;
			break;
		case EAgnEvent:
			entryType = CCalEntry::EEvent;
			break;
		case EAgnTodo:
			entryType = CCalEntry::ETodo;
			break;
		default:
			User::Leave(KErrCorrupt);
		}
	
    if (attributes & EBit13)
    	{
    	aHasExtended = ETrue;
    	}
    else
    	{
    	aHasExtended = EFalse;
    	}
    	
    CCalEntry::TStatus status = CCalEntry::ENullStatus;
    // Get status from attributes' bits 
    //
    if (attributes & (EBit14 | EBit15 | EBit16))
    	{
    	// Bits 14,15,16 on.
    	status = CCalEntry::EVCalDelegated;
    	}
    else if (attributes & (EBit14 | EBit15))
    	{
    	// Bits 14, 15 on
    	if (entryType == CCalEntry::ETodo)
    		{
    		status = CCalEntry::ETodoCompleted;
    		}
    	}
    else if (attributes & (EBit14 | EBit16))
    	{
    	//Bits 14,16 on
    	status = CCalEntry::EVCalDeclined;
    	}
    else if (attributes & (EBit15 | EBit16))
    	{
    	// Bits 15, 16 on
    	status = CCalEntry::EVCalSent;
    	}
    else if (attributes & EBit14)
   	 	{
    	if (entryType != CCalEntry::ETodo)
    		{
    		status = CCalEntry::EConfirmed;
    		}
   	 	}
    else if (attributes & EBit15)
    	{
    	status = CCalEntry::EVCalNeedsAction;
    	}
    else if (attributes & EBit16)
    	{
    	status = CCalEntry::EVCalAccepted;
    	}
    else if(attributes & EBit11)
    	{
    	if (entryType != CCalEntry::ETodo)
    		{
    		status = CCalEntry::ETentative;
    		}
    	}
 
    // read GS data
   	enum TGsTypeV9192
		{
		/** Not a GS Entry (created using AgnModel APIs directly, not CalInterimAPI. */
		ENonGsEntry,
		/** Parent Entry. */
		EGsRootParent,
		/** Not used. */
		EGsParent,
		/** Child Entry. */
		EGsLeaf
		};
			
	CAgnEntry* entry = NULL;
	
	const TGsTypeV9192 KCalTypeV9192 = static_cast<TGsTypeV9192> (aStream.ReadInt8L());
	switch (KCalTypeV9192)
		{
		case EGsRootParent:
			{
		    aStream.ReadUint32L(); // ignore guid hash
		    HBufC8* guid = HBufC8::NewLC(aStream, KAgnEntryMaxGuidLength);   
		    
		    aStream.ReadInt8L(); // read other class type 
		    
		    entry = CAgnEntry::NewL(entryType, guid, CCalEntry::EMethodNone, 0); // dummy values for method and sequence number
			CleanupStack::Pop(guid);
			CleanupStack::PushL(entry);
			
		    TAgnCalendarTime recurId;

		    const TInt KCount = aStream.ReadInt32L(); 
		    for (TInt i = 0; i < KCount; ++i)
				{
				TCalLocalUid childId = aStream.ReadUint32L();	
				aStream >> recurId;
				
				TGsChildRefData childData(childId, recurId);
				entry->AddChildIdL(childData);
				}
		
			// set correct value for method and sequence number
			TInt32 seqNum = aStream.ReadInt32L();
			entry->SetSequenceNumber(seqNum);
			
			CCalEntry::TMethod method = static_cast<CCalEntry::TMethod> (aStream.ReadInt8L());
			entry->SetMethod(method);

			aStream.ReadUint32L(); // parent ID (Null for a parent)
			}
			break;
			
		case EGsLeaf:
			{
			TInt32 seqNum = aStream.ReadInt32L();
			CCalEntry::TMethod method = static_cast<CCalEntry::TMethod> (aStream.ReadInt8L());
			TCalLocalUid parentId = aStream.ReadUint32L(); 
			
		    entry = CAgnEntry::NewL(entryType, NULL, method, seqNum, TAgnCalendarTime(), CalCommon::EThisOnly);
		    CleanupStack::PushL(entry);
		    entry->SetParentId(parentId);
			}
			break;

		case EGsParent: // fall through
		case ENonGsEntry:
			// this is a non-GS entry, get the GUID from the unique ID, entry == NULL
			break;
		
		default:
			{
			User::Leave(KErrCorrupt);
			}
		}
    
    // Read in entry's unique Id
    //
   	TCalLocalUid localUid;
    aStream >> localUid;
    
    // create entry now we have all the information
	
	if (!entry) // create non-GS entry from unique ID
		{
    	TBuf8<32> uniqueIdBuf;
	    uniqueIdBuf.AppendNum(localUid);
	    HBufC8* guid = uniqueIdBuf.AllocLC();
		entry = CAgnEntry::NewL(entryType, guid, CCalEntry::EMethodNone, 0);
		CleanupStack::Pop(guid);
		CleanupStack::PushL(entry);
		}
		
    entry->SetStatus(status);
    entry->SetLocalUid(localUid);

    // TReplicationData was next in 9.1/9.2, with the following data:
    //            TStatus iStatus;
    //            TBool iHasBeenDeleted;
    //            TUint iCount;
    //            TAgnCalendarTime iLastChangedDateUtc
    //
	entry->SetReplicationStatusL(static_cast<CCalEntry::TReplicationStatus>(aStream.ReadInt8L()));

    TBool hasBeenDeleted = aStream.ReadUint8L();// Not used in 9.3 but checked later
    aStream.ReadUint8L();//skip iCount
    TAgnCalendarTime lastChangedDate;
	aStream >> lastChangedDate;
	entry->SetLastModifiedDateUtc(lastChangedDate.UtcL());
    
    // CAgnRptDef
    //
    // In 9.1/9.2, the second bit of the 'attributes' 
    // indicates presence/absence of a repeat definition
    // 
    CArrayFixFlat<TAgnCalendarTime>* exceptions = NULL;
    if (attributes & EBit2)
    	{
		exceptions = InternalizeRptDefL(aStream, *entry);
		}
	
	TInt32 alarmPreTime = InternalizeAlarmL(aStream, attributes, *entry);
	InternalizeSummaryL(aStream, hasBeenDeleted, *entry);
	InternalizeTypeSpecificDataL(aStream, attributes, *entry);
	AddExceptionsL(*entry, exceptions); // must add exceptions after start date has been set
	delete exceptions;
	
	// if the entry is floating, the until date must be converted to a floating TAgnCalendarTime
	if (entry->TimeMode() == MAgnCalendarTimeMode::EFloating)
		{
		if (entry->RptDef() && entry->RptDef()->RRule())
			{
			if (AgnDateTime::IsValidAgendaTTime(entry->RptDef()->RRule()->UntilTimeL().UtcL()))
				{
				TAgnCalendarTime agnUntilTime;
				agnUntilTime.SetFloatingL(entry->RptDef()->RRule()->UntilTimeL().UtcL());
				entry->RptDef()->SetUntilTime(agnUntilTime);
				}
			}
		}
	
	// if the entry has an alarm, calculate the offset from the pretime used in v9.1/v9.2
	if (alarmPreTime != KMaxTInt32)
		{
		if (KV9192Type == EAgnTodo)
			{
			entry->SetAlarmOffset(CalculateAlarmOffsetL(alarmPreTime, entry->EndTime().LocalL()));
			}
		else
			{
			entry->SetAlarmOffset(CalculateAlarmOffsetL(alarmPreTime, entry->StartTime().LocalL()));
			}
		}
	
	CleanupStack::Pop(entry);
	
	return entry;
	}