// -----------------------------------------------------------------------------
// CPIMAgnToDoAdapter::ConvertStringToAgnL
// Makes string conversion from framework PIM item data field to To-do item field
// -----------------------------------------------------------------------------
//
void CPIMAgnToDoAdapter::ConvertStringToAgnL(TPIMToDoField aField, // String field to be converted
        TInt aIndex, // Index of the date field
        CCalEntry& aEntry, // The Agenda Model entry
        const MPIMItemData& aItem) // The PIM item to read the field from
{
    JELOG2(EPim);
    const TPIMFieldData fieldData = aItem.ValueL(aField, aIndex);
    const TDesC& string = fieldData.StringValue();

    // Check that string is not too long
    __ASSERT_ALWAYS(string.Length() <= KPIMToDoStringValueMaxLength,
                    User::Leave(KErrTooBig));

    switch (aField)
    {
    case EPIMToDoSummary:
    {
        aEntry.SetSummaryL(string);
        break;
    }
    case EPIMToDoNote:
    {
        aEntry.SetDescriptionL(string);
        break;
    }
    default:
    {
        // Should not happen
    }
    }

}
// -----------------------------------------------------------------------------
// CPIMAgnToDoAdapter::ExportItemL
// (other items were commented in a header)
// -----------------------------------------------------------------------------
//
void CPIMAgnToDoAdapter::ExportItemL(const MPIMToDoItem& aItem,
                                     CCalEntry& aEntry, TBool aResetEntry)
{
    JELOG2(EPim);
    if (aResetEntry)
    {
        // Reset native entry for exporting new data
        aEntry.SetSummaryL(KNullDesC());
        aEntry.SetDescriptionL(KNullDesC());
        aEntry.SetPriorityL(0);
        aEntry.SetCompletedL(EFalse, aEntry.CompletedTimeL());
    }

    // Export item data to the native ToDo calendar entry
    const MPIMItemData& itemData = aItem.ItemData();
    CArrayFix<TPIMField>* fields = itemData.FieldsLC();

    // Add default values to the calendar entry
    AddDefaultValuesToEntryL(itemData, aEntry);

    // Convert each field to the native ToDo calendar entry
    TInt count = fields->Count();
    for (TInt i = 0; i < count; i++)
    {
        TPIMToDoField field = static_cast<TPIMToDoField>(fields->At(i));
        ConvertToAgnL(field, aEntry, itemData);
    }
    CleanupStack::PopAndDestroy(fields);
}
void CMultiThreadTestApp::AddEntryL(CCalEntryView& aView, const TInt aNumToAdd)
	{
	// Add Entries for Test
	RTest test(KTestName);
	test.Next(_L("Adding entries"));

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


	RPointerArray<CCalEntry> entriesToStore;
	CleanupResetAndDestroyPushL(entriesToStore);
	
	for (TInt index = 0; index < aNumToAdd; ++index)
		{
		CCalEntry* entry;
		HBufC8*    guid = HBufC8::NewL(255);
		TPtr8      uidP = guid->Des();
		
		RandomText8(uidP);
		
		if( (index %2) == 0 )
			{
			entry = CreateCalEntryL(CCalEntry::ETodo, guid);
			}
		else
			{
			entry = CreateCalEntryL(CCalEntry::EAppt, guid);
			}
	
		TInt err = entriesToStore.Append(entry);
		test(err == KErrNone);
		
		SetEntryStartAndEndTimeL(entry);
				
		RandomText(summary);
		entry->SetSummaryL(summary);
		
		RandomText(location);
		entry->SetLocationL(location);
		
		RandomText(description);
		entry->SetDescriptionL(description);
		}

	TInt entriesStored(0);
	aView.StoreL(entriesToStore, entriesStored); //temp
	test(entriesStored == aNumToAdd);
	test.Close();
	
	CleanupStack::PopAndDestroy(&entriesToStore);
	}
Пример #4
0
void CDummyCalendarApp::RepeatExceptedEntryCreateL()
	{
	test.Next(_L("Add entry, repeat twice, set excepted and delete"));

	iEntries.ResetAndDestroy();	
	
	// Create new calendar entry.
	CCalEntry* entry = NULL;
	HBufC8* guid = KGUIDInc081869().AllocLC();	
	entry = CreateCalEntryL(CCalEntry::EAppt, guid);
	CleanupStack::Pop(guid);
	
	iEntries.AppendL(entry);	

    // Set start and end date.
	TTime start(TDateTime(2006, EMarch, 6, 10, 0, 0, 0));
	TTime end(TDateTime(2006, EMarch, 6, 14, 0, 0, 0));
	SetEntryStartAndEndTimeL(entry, start, end);
	
	TBuf<50> summary;			
	RandomText(summary);
	entry->SetSummaryL(summary);

	TBuf<50> location;
	RandomText(location);
	entry->SetLocationL(location);

	TBuf<50> description;		
	RandomText(description);
	entry->SetDescriptionL(description);	

	// Create a daily repeating rule that occurs for 2 days.
	TCalRRule rpt(TCalRRule::EDaily);
	rpt.SetInterval(1);
	rpt.SetCount(2);	
	
	// Make sure the repeat time is within the delete time range.
	TCalTime repeatStart;
	TCalTime repeatEnd;
	repeatStart.SetTimeLocalL(TDateTime(2006, EMarch, 6, 0, 0, 0, 0));
	repeatEnd.SetTimeLocalL(TDateTime(2006, EMarch, 8, 0, 0, 0, 0));
	rpt.SetDtStart(repeatStart); 
	rpt.SetUntil(repeatEnd);
	entry->SetRRuleL(rpt);

    // Store the entry. Because it repeats over 2 days, there will
    // be 2 entries.
	TInt entriesStored(0);
	SynCGetEntryViewL().StoreL(iEntries, entriesStored);
	test(entriesStored == iEntries.Count());
	}
// -----------------------------------------------------------------------------
// CNSmlNotepadDatabase::AddNoteL
// -----------------------------------------------------------------------------
//
void CNSmlNotepadDatabase::AddNoteL(CNpdItem& aNote, TInt &aKey)
    {
    _NOTEPAD_DBG_FILE("CNSmlNotepadDatabase::AddNoteL(): begin");   
   
    TInt successCount = 0;

    CCalenInterimUtils2* interimUtils = CCalenInterimUtils2::NewL();
    CleanupStack::PushL(interimUtils);
    
    HBufC8* guid = interimUtils->GlobalUidL();
    CleanupStack::PopAndDestroy(interimUtils);
    
    CleanupStack::PushL(guid);
    CCalEntry* entry = CCalEntry::NewL(CCalEntry::ENote, guid,
            CCalEntry::EMethodNone, 0);
    CleanupStack::Pop(guid);
    
    CleanupStack::PushL(entry);

    // set the description
    TDesC* noteContent(aNote.Content());
    entry->SetDescriptionL(*noteContent);

    // store the entry in to calendar file
    RPointerArray<CCalEntry> array;
    CleanupRPtrArrayPushL(array); 

    array.AppendL(entry);
    CleanupStack::Pop(entry);
    iEntryView->StoreL(array, successCount);
    
    if(successCount)
        {
        HBufC* content = HBufC::NewL(entry->DescriptionL().Length());
        content->Des().Copy(entry->DescriptionL());
        aNote.Set(entry->LocalUidL(),entry->LastModifiedDateL().TimeUtcL(), content);
        aKey = entry->LocalUidL();
        CleanupStack::PopAndDestroy(&array);
        _NOTEPAD_DBG_FILE("CNSmlNotepadDatabase::AddNoteL(): inside if(successCount) after array");
        }
    else
        {
        User::Leave(KErrGeneral);
        }
	
	_NOTEPAD_DBG_FILE("CNSmlNotepadDatabase::AddNoteL(): end");
	
	User::Leave(KErrNone);
    }
// -----------------------------------------------------------------------------
// CPIMAgnEventAdapter::ClearPIMFieldsL
// Clears the fields supported by PIM API from this Agenda Model entry.
// -----------------------------------------------------------------------------
//
void CPIMAgnEventAdapter::ClearPIMFieldsL(CCalEntry& aEntry,
        const TPIMField aSupportedFields[], // Array of supported field types
        TInt aSize) // Size of the array of supported fields
{
    JELOG2(EPim);
    for (int i = 0; i < aSize; i++)
    {
        switch (aSupportedFields[i])
        {
        case EPIMEventSummary:
        {
            aEntry.SetSummaryL(KNullDesC);
            break;
        }
        case EPIMEventLocation:
        {
            aEntry.SetLocationL(KNullDesC);
            break;
        }
        case EPIMEventNote:
        {
            aEntry.SetDescriptionL(KNullDesC);
            break;
        }
        case EPIMEventAlarm:
        {
            aEntry.SetAlarmL(NULL);
            break;
        }
        case EPIMEventStart: // Fallthrough
        case EPIMEventEnd: // Fallthrough
        case EPIMEventUid: // Fallthrough
        case EPIMEventClass: // Fallthrough
        case EPIMEventRevision:
        {
            break; // For these fields there is no need to do anything
        }
        default:
        {
            User::Leave(KErrArgument);
        }
        }
    }
}
CCalAlarm* CCalAlarmAttachTest::StoreEntryWithAlarmContentLC(const TDesC8& aUid)
    {
    test.Printf(_L("Store an alarmed entry with alarm content\n"));
    // Create an attachment to the alarm.
    CCalAlarm* alarm = CCalAlarm::NewL();
    CleanupStack::PushL(alarm);
    alarm->SetTimeOffset(1);
    
    CCalContent* almContent = CCalContent::NewL();
    CleanupStack::PushL(almContent);
    // Add content and mimetype for the alarm.
    HBufC8* content = KContent().AllocLC();
    HBufC8* mimetype = KMimeType().AllocLC();
    
    almContent->SetContentL(content, mimetype, CCalContent::EDispositionInline);
    CleanupStack::Pop(mimetype);
    CleanupStack::Pop(content);    
    alarm->SetAlarmAction(almContent); // Takes ownership of almContent.
    CleanupStack::Pop(almContent); 
  
    //Create the entry with the alarm and store it
    RPointerArray<CCalEntry> entries;
    CleanupResetAndDestroyPushL(entries);
    HBufC8* guid = aUid.AllocLC();
    CCalEntry* entry = CCalEntry::NewL(CCalEntry::EEvent, guid, CCalEntry::EMethodNone, 0);
    CleanupStack::Pop(guid);
    CleanupStack::PushL(entry);
    entries.AppendL(entry);
    CleanupStack::Pop(entry);

    TCalTime calTime;
    calTime.SetTimeUtcL(TDateTime(2007,EFebruary,15, 13, 30, 0, 0));
    entry->SetStartAndEndTimeL(calTime, calTime);
    entry->SetSummaryL(KSummary());
    
    entry->SetDescriptionL(KDescription());
    entry->SetAlarmL(alarm);
    TInt entriesStored = 0;
    iTestLib->SynCGetEntryViewL().StoreL(entries, entriesStored);
    CleanupStack::PopAndDestroy(&entries);
    return alarm;
    }
// -----------------------------------------------------------------------------
// CPIMAgnEventAdapter::ConvertStringFieldToAgnL
// Makes string conversion from framework PIM item data field to Appt item field
// -----------------------------------------------------------------------------
//
void CPIMAgnEventAdapter::ConvertStringFieldToAgnL(const MPIMEventItem& aItem,
        CCalEntry& aEntry, const TPIMEventField aField) const
{
    JELOG2(EPim);
    const MPIMItemData& itemData = aItem.ItemData();
    TInt amount = itemData.CountValues(aField);
    for (TInt i = 0; i < amount; i++)
    {
        const TPIMFieldData fieldData = itemData.ValueL(aField, i);
        const TDesC& stringValue = fieldData.StringValue();
        EnsureValidStringValueL(stringValue);
        // Add correct data to the field
        switch (aField)
        {
        case EPIMEventNote:
        {
            aEntry.SetDescriptionL(stringValue);
            break;
        }
        case EPIMEventSummary:
        {
            aEntry.SetSummaryL(stringValue);
            break;
        }
        case EPIMEventLocation:
        {
            aEntry.SetLocationL(stringValue);
            break;
        }
        default:
        {
            __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory,
                                               EPIMPanicUnsupportedStringField));
            break;
        }
        }

    }
}
Пример #9
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());
	}
void CTestCalIndexFileModifyEntryStep::ModifyEntryL()
	{
	TPtrC entryString;
	TBool readRes = EFalse;
	readRes = GetStringFromConfig(ConfigSection(), KModifyEntry, entryString);
	if (!readRes)
		{
		INFO_PRINTF1(_L("Error in CTestCalIndexFileModifyEntryStep::ModifyEntryL - entrytomodify not found in config file"));
		User::Leave(KErrNotFound);
		}
	CConfigTestEntryInfo* inf = new(ELeave)CConfigTestEntryInfo();
	CleanupStack::PushL(inf);
	ParseEntryStringL(*inf, entryString);
				
	//  see if we can find a match in the database using an instance view
		
		CCalProgress* progress = new(ELeave)CCalProgress;
		CleanupStack::PushL(progress);  
	
		CCalInstanceView* view = CCalInstanceView::NewL(*iSession, *progress);
		CleanupStack::PushL(view);
		
		CActiveScheduler::Start();
		
		CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts;
		switch (inf->iType)
			{
			case (CCalEntry::EAppt):
				filter = CalCommon::EIncludeAppts;
				break;
			case (CCalEntry::ETodo):
				filter = CalCommon::EIncludeCompletedTodos | CalCommon::EIncludeIncompletedTodos;
				break;
			case (CCalEntry::EEvent):
				filter = CalCommon::EIncludeEvents;
				break;
			case (CCalEntry::EReminder):
				filter = CalCommon::EIncludeReminder;
				break;
			case (CCalEntry::EAnniv):
				filter = CalCommon::EIncludeAnnivs;
				break;
			default:
				User::Leave(KErrCorrupt);
				break;
			}
		RPointerArray<CCalInstance> instances;
		CleanupClosePushL(instances);

		// look for instances between (startdate -1 day) and
		// (enddate + 1 day)
		TTimeIntervalDays oneDay(1);
		TTime beginTTime = (inf->iStartTime) - oneDay;
		TTime endTTime = (inf->iEndTime) + oneDay;
		TCalTime begin;
		begin.SetTimeUtcL(beginTTime);
		TCalTime end;
		end.SetTimeUtcL(endTTime);
		CalCommon::TCalTimeRange timerange(begin, end);	
		
		view->FindInstanceL(instances, filter, timerange);
		
		TInt counter = 0;
		TInt max = instances.Count();
		INFO_PRINTF2(_L("%d instances to compare against"),max);
		TBool found = EFalse;
		while ((found == EFalse) && (counter < max))
			{
			INFO_PRINTF2(_L("compare modify info to entry %d"), (counter+1));
			if (inf->CompareToEntryL((instances[counter])->Entry()))
				{
				INFO_PRINTF2(_L("Entry info matched instance %d"), (counter+1));
				found = ETrue;
				
				CCalProgress* progress1 = new(ELeave)CCalProgress;
				CleanupStack::PushL(progress1);  
				
				CCalEntryView* eView = CCalEntryView::NewL(*iSession, *progress);
				CleanupStack::PushL(eView);
				
				CActiveScheduler::Start();

				CCalEntry* eEntry = &((instances[counter])->Entry());
				eEntry->SetDescriptionL(KTCIModifiedText());
				RPointerArray<CCalEntry> eList;
				CleanupResetAndDestroyPushL(eList);
				eList.Reset();
				TInt numChanged = 0;
				eList.Append(eEntry);
				eView->UpdateL(eList, numChanged);
				if (numChanged != 1)
					{
					INFO_PRINTF1(_L("Error modifiying entry"));
					User::Leave(KErrGeneral);
					}
				CleanupStack::PopAndDestroy(&eList);
				CleanupStack::PopAndDestroy(2);
				}
			else
				{
				counter++;
				}
			}
		CleanupStack::PopAndDestroy(&instances);
		CleanupStack::PopAndDestroy(view);
		CleanupStack::PopAndDestroy(progress);
	
	CleanupStack::PopAndDestroy(inf);
	
	if (!found)
		{
		INFO_PRINTF1(_L("Could not find entrytomodify in database"));
		User::Leave(KErrNotFound);
		}
	}