Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_cal_example_8cpp-source.html
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Tue, 30 Mar 2010 11:42:04 +0100
changeset 4 4816d766a08a
parent 1 25a17d01db0c
permissions -rw-r--r--
Week 12 contribution of SDK documentation_content. See release notes for details. Fixes Bug 1892, Bug 1522, Bug 1520, Bug 394, Bug 1319, Bug 344, Bug 1897

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/AppEngine/CalInterimApi/CalExample.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/AppEngine/CalInterimApi/CalExample.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">//</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include "CalExample.h"</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;calinstance.h&gt;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 CCalExample::CCalExample()
<a name="l00021"></a>00021         {
<a name="l00022"></a>00022         }
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="class_c_cal_example.html#9f6aac09024aec8f53080d949937afbe">00024</a> <a class="code" href="class_c_cal_example.html#9f6aac09024aec8f53080d949937afbe">CCalExample::~CCalExample</a>()
<a name="l00025"></a>00025         {
<a name="l00026"></a>00026         _LIT(KExitMsg,<span class="stringliteral">"\n\nPress any key to exit the application "</span>);
<a name="l00027"></a>00027         iConsole-&gt;Printf(KExitMsg); 
<a name="l00028"></a>00028         iConsole-&gt;Getch();
<a name="l00029"></a>00029         
<a name="l00030"></a>00030         <span class="keyword">delete</span> iCalEntryView;
<a name="l00031"></a>00031         <span class="keyword">delete</span> iCalSession;     
<a name="l00032"></a>00032         <span class="keyword">delete</span> iConsole; 
<a name="l00033"></a>00033         }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="class_c_cal_example.html#db58fbf73337500d5bc8162ad2229336">00035</a> <a class="code" href="class_c_cal_example.html">CCalExample</a>* <a class="code" href="class_c_cal_example.html#db58fbf73337500d5bc8162ad2229336">CCalExample::NewL</a>()
<a name="l00036"></a>00036         {
<a name="l00037"></a>00037         <a class="code" href="class_c_cal_example.html">CCalExample</a>* <span class="keyword">self</span>= <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_cal_example.html">CCalExample</a>();
<a name="l00038"></a>00038         CleanupStack::PushL(<span class="keyword">self</span>);
<a name="l00039"></a>00039         <span class="keyword">self</span>-&gt;ConstructL();
<a name="l00040"></a>00040         CleanupStack::Pop();    
<a name="l00041"></a>00041         <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00042"></a>00042         }
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="keywordtype">void</span> CCalExample::ConstructL()
<a name="l00045"></a>00045         {
<a name="l00046"></a>00046         _LIT(KTitle, <span class="stringliteral">"calexample"</span> );
<a name="l00047"></a>00047         iConsole = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
<a name="l00048"></a>00048 
<a name="l00049"></a>00049         _LIT(KPressAKeyMsg, <span class="stringliteral">"\n\nPress any key to step through the example"</span>);
<a name="l00050"></a>00050         iConsole-&gt;Printf ( KPressAKeyMsg );
<a name="l00051"></a>00051         iConsole-&gt;Getch ();
<a name="l00052"></a>00052         
<a name="l00053"></a>00053         iCalSession = CCalSession::NewL();
<a name="l00054"></a>00054         <span class="comment">// Create and open a calendar file</span>
<a name="l00055"></a>00055         _LIT(KFileName,<span class="stringliteral">"calendarfile"</span>);
<a name="l00056"></a>00056         TRAPD(err, iCalSession-&gt;CreateCalFileL(KFileName));
<a name="l00057"></a>00057         <span class="comment">// ignore KErrAlreadyExists leave code</span>
<a name="l00058"></a>00058         <span class="keywordflow">if</span> (err != KErrAlreadyExists)
<a name="l00059"></a>00059                 {
<a name="l00060"></a>00060                 User::LeaveIfError(err);
<a name="l00061"></a>00061                 }
<a name="l00062"></a>00062         <span class="comment">// Open the calendar file</span>
<a name="l00063"></a>00063         iCalSession-&gt;OpenL(KFileName);
<a name="l00064"></a>00064         
<a name="l00065"></a>00065         _LIT(KProgressMsg, <span class="stringliteral">"\nCalendar entry view creation is in progress..."</span>);
<a name="l00066"></a>00066         iConsole-&gt;Printf(KProgressMsg); 
<a name="l00067"></a>00067         <span class="comment">// Create a calendar entry view to view the entries</span>
<a name="l00068"></a>00068         iCalEntryView = CCalEntryView::NewL(*iCalSession,*<span class="keyword">this</span>);
<a name="l00069"></a>00069         CActiveScheduler::Start();              
<a name="l00070"></a>00070         }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="comment">// Called during calendar entry view creation</span>
<a name="l00073"></a><a class="code" href="class_c_cal_example.html#1ccce3cfbd215268e2210d9f67ff4aef">00073</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#1ccce3cfbd215268e2210d9f67ff4aef">CCalExample::Progress</a>(TInt aProgress)
<a name="l00074"></a>00074         {
<a name="l00075"></a>00075         _LIT(KProgressVal,<span class="stringliteral">"\n%d%% complete"</span>);
<a name="l00076"></a>00076         iConsole-&gt;Printf(KProgressVal,aProgress);
<a name="l00077"></a>00077         }
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 <span class="comment">// Called on completion of calendar entry view creation</span>
<a name="l00080"></a><a class="code" href="class_c_cal_example.html#f5a6cde3a8ccb269b8662ca73d7b371b">00080</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#f5a6cde3a8ccb269b8662ca73d7b371b">CCalExample::Completed</a>(TInt <span class="comment">/*aError*/</span>)
<a name="l00081"></a>00081         {
<a name="l00082"></a>00082         CActiveScheduler::Stop();
<a name="l00083"></a>00083         }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 <span class="comment">// Returns whether or not progress notification is required</span>
<a name="l00086"></a><a class="code" href="class_c_cal_example.html#1fdf9918d6d05fadb6d382ea1c0d0f7b">00086</a> TBool <a class="code" href="class_c_cal_example.html#1fdf9918d6d05fadb6d382ea1c0d0f7b">CCalExample::NotifyProgress</a>()
<a name="l00087"></a>00087         {
<a name="l00088"></a>00088         <span class="comment">// Progress notification is required</span>
<a name="l00089"></a>00089         <span class="keywordflow">return</span> ETrue;
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091                 
<a name="l00092"></a>00092 <span class="comment">// Sets some entry details - start and end date/time, description, categories and attendees</span>
<a name="l00093"></a>00093 <span class="keywordtype">void</span> CCalExample::SetEntryDetailsL(CCalEntry* aEntry,<span class="keyword">const</span> TDesC&amp; aDescription, TDateTime&amp; aStartTime,TDateTime&amp; aEndTime)
<a name="l00094"></a>00094         {
<a name="l00095"></a>00095         TCalTime startTime;
<a name="l00096"></a>00096         TCalTime endTime;
<a name="l00097"></a>00097         
<a name="l00098"></a>00098         <span class="comment">// Set the start and end times using time values local to the current system time zone</span>
<a name="l00099"></a>00099         startTime.SetTimeLocalL(aStartTime);
<a name="l00100"></a>00100         endTime.SetTimeLocalL(aEndTime);
<a name="l00101"></a>00101         aEntry-&gt;SetStartAndEndTimeL(startTime, endTime);        
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <span class="comment">// Set the description text</span>
<a name="l00104"></a>00104         aEntry-&gt;SetDescriptionL(aDescription);  
<a name="l00105"></a>00105         
<a name="l00106"></a>00106         <span class="comment">// Add a category</span>
<a name="l00107"></a>00107         <span class="keyword">const</span> RPointerArray&lt;CCalCategory&gt; categoryList = aEntry-&gt;CategoryListL();
<a name="l00108"></a>00108         <span class="keywordflow">if</span>(categoryList.Count() == 0)
<a name="l00109"></a>00109                 {
<a name="l00110"></a>00110                 TBuf&lt;32&gt; buf;
<a name="l00111"></a>00111                 _LIT(KCategoryName, <span class="stringliteral">"Dummy Category"</span>);
<a name="l00112"></a>00112                 buf.Copy(KCategoryName);
<a name="l00113"></a>00113                 
<a name="l00114"></a>00114                 CCalCategory* category = CCalCategory::NewL(buf);
<a name="l00115"></a>00115                 CleanupStack::PushL(category);
<a name="l00116"></a>00116                 aEntry-&gt;AddCategoryL(category);
<a name="l00117"></a>00117                 CleanupStack::Pop(category);
<a name="l00118"></a>00118                 } 
<a name="l00119"></a>00119                 
<a name="l00120"></a>00120         <span class="comment">// Add some attendees</span>
<a name="l00121"></a>00121         <span class="keyword">const</span> RPointerArray&lt;CCalAttendee&gt;attendeeList = aEntry-&gt;AttendeesL();
<a name="l00122"></a>00122         <span class="keywordflow">if</span>(attendeeList.Count() == 0)
<a name="l00123"></a>00123                 {
<a name="l00124"></a>00124                 _LIT(KAttendeeOne, <span class="stringliteral">"nokiauk@nokia.com"</span>);
<a name="l00125"></a>00125                 _LIT(KAttendeeTwo, <span class="stringliteral">"nokiaindia@nokia.com"</span>);
<a name="l00126"></a>00126 
<a name="l00127"></a>00127                 CCalAttendee* attendeeOne = CCalAttendee::NewL(KAttendeeOne);
<a name="l00128"></a>00128                 CleanupStack::PushL(attendeeOne);       
<a name="l00129"></a>00129                 aEntry-&gt;AddAttendeeL(attendeeOne);      
<a name="l00130"></a>00130                 CleanupStack::Pop(attendeeOne);
<a name="l00131"></a>00131         
<a name="l00132"></a>00132                 CCalAttendee* attendeeTwo = CCalAttendee::NewL(KAttendeeTwo);
<a name="l00133"></a>00133                 CleanupStack::PushL(attendeeTwo);       
<a name="l00134"></a>00134                 aEntry-&gt;AddAttendeeL(attendeeTwo);
<a name="l00135"></a>00135                 CleanupStack::Pop(attendeeTwo);
<a name="l00136"></a>00136                 }
<a name="l00137"></a>00137         }
<a name="l00138"></a>00138         
<a name="l00139"></a>00139 <span class="comment">// Add a non-repeating appointment to the calendar file</span>
<a name="l00140"></a><a class="code" href="class_c_cal_example.html#d89edab97029a30027346db3773ec5d0">00140</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#d89edab97029a30027346db3773ec5d0">CCalExample::AddEntryL</a>()
<a name="l00141"></a>00141         { 
<a name="l00142"></a>00142         <span class="keyword">const</span> TDesC8&amp; guidDes = KGuid;
<a name="l00143"></a>00143         HBufC8* guid = guidDes.AllocL();
<a name="l00144"></a>00144         
<a name="l00145"></a>00145         CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
<a name="l00146"></a>00146         CleanupStack::PushL(entry);
<a name="l00147"></a>00147                 
<a name="l00148"></a>00148         <span class="comment">// For an appointment, the time as well as the date is relevant</span>
<a name="l00149"></a>00149         TDateTime startTime(2006, EJanuary, 04, 10, 0, 0, 0);
<a name="l00150"></a>00150         TDateTime endTime(2006, EJanuary, 05, 16, 0, 0, 0);
<a name="l00151"></a>00151         
<a name="l00152"></a>00152         _LIT(KAddingMsg, <span class="stringliteral">"\n\nAdding an entry..."</span>);
<a name="l00153"></a>00153         iConsole-&gt;Printf ( KAddingMsg );
<a name="l00154"></a>00154                 
<a name="l00155"></a>00155         _LIT(KDescription,<span class="stringliteral">"Meeting is scheduled in 1st week of January"</span>);
<a name="l00156"></a>00156         SetEntryDetailsL(entry,KDescription, startTime, endTime);
<a name="l00157"></a>00157                 
<a name="l00158"></a>00158         RPointerArray&lt;CCalEntry&gt; array;
<a name="l00159"></a>00159         CleanupClosePushL(array);
<a name="l00160"></a>00160         array.AppendL(entry);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162         TInt success(0);
<a name="l00163"></a>00163         <span class="comment">// If StoreL() leaves, 'success' contains the number of entries that were</span>
<a name="l00164"></a>00164         <span class="comment">// stored before it failed</span>
<a name="l00165"></a>00165         iCalEntryView-&gt;StoreL(array, success);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         CleanupStack::PopAndDestroy(&amp;array);
<a name="l00168"></a>00168         CleanupStack::PopAndDestroy(entry);
<a name="l00169"></a>00169         }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171 <span class="comment">// Destroy the RPointerArray</span>
<a name="l00172"></a>00172 <span class="keywordtype">void</span> DestroyRPointerArray(TAny* aPtr)
<a name="l00173"></a>00173         {
<a name="l00174"></a>00174         RPointerArray&lt;CCalEntry&gt;* <span class="keyword">self</span> = <span class="keyword">static_cast&lt;</span>RPointerArray&lt;CCalEntry&gt;*<span class="keyword">&gt;</span> (aPtr);
<a name="l00175"></a>00175         <span class="keyword">self</span>-&gt;ResetAndDestroy();
<a name="l00176"></a>00176         }
<a name="l00177"></a>00177 
<a name="l00178"></a>00178 <span class="comment">// Fetch the entry and update some of its details</span>
<a name="l00179"></a><a class="code" href="class_c_cal_example.html#4de85d476d3f6f24657e81da3280d80c">00179</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#4de85d476d3f6f24657e81da3280d80c">CCalExample::UpdateEntryL</a>()
<a name="l00180"></a>00180         {
<a name="l00181"></a>00181         RPointerArray&lt;CCalEntry&gt; array;
<a name="l00182"></a>00182         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;array));
<a name="l00183"></a>00183         iCalEntryView-&gt;FetchL(KGuid, array);
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="comment">//Fetch the first entry in the list</span>
<a name="l00186"></a>00186         _LIT(KUpdatingMsg,<span class="stringliteral">"\n\nUpdating the entry..."</span>);
<a name="l00187"></a>00187         iConsole-&gt;Printf(KUpdatingMsg);
<a name="l00188"></a>00188         CCalEntry* entry = array[0];
<a name="l00189"></a>00189         
<a name="l00190"></a>00190         _LIT(KNewDescription,<span class="stringliteral">"Meeting rescheduled to 2nd week of January"</span>);
<a name="l00191"></a>00191         TDateTime startTime(2006, EJanuary, 11, 10, 0, 0, 0); 
<a name="l00192"></a>00192         TDateTime endTime(2006, EJanuary, 12, 16, 0, 0, 0);
<a name="l00193"></a>00193         SetEntryDetailsL(entry,KNewDescription, startTime, endTime);    
<a name="l00194"></a>00194                         
<a name="l00195"></a>00195         TInt numberOfEntries(0);
<a name="l00196"></a>00196         <span class="comment">// If UpdateL() leaves, 'numberOfEntries' contains the number of entries that were</span>
<a name="l00197"></a>00197         <span class="comment">// updated before it failed</span>
<a name="l00198"></a>00198         iCalEntryView-&gt;UpdateL(array,numberOfEntries);
<a name="l00199"></a>00199         CleanupStack::PopAndDestroy(&amp;array);
<a name="l00200"></a>00200         }
<a name="l00201"></a>00201         
<a name="l00202"></a>00202 <span class="comment">// Add a repeating appointment. This is called the originating entry.</span>
<a name="l00203"></a><a class="code" href="class_c_cal_example.html#7c1da41338976354f45e8873f4343790">00203</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#7c1da41338976354f45e8873f4343790">CCalExample::AddOriginatingEntryL</a>()
<a name="l00204"></a>00204         {
<a name="l00205"></a>00205         _LIT(KAddingMsg, <span class="stringliteral">"\n\nAdding a repeating entry..."</span>);
<a name="l00206"></a>00206         iConsole-&gt;Printf ( KAddingMsg );
<a name="l00207"></a>00207         
<a name="l00208"></a>00208         TTime startTime(TDateTime(2006, EJanuary, 0, 14, 0, 0, 0)); <span class="comment">// January 1st 2pm</span>
<a name="l00209"></a>00209         TTime endTime(startTime + TTimeIntervalHours(1)); <span class="comment">// January 1st 3pm    </span>
<a name="l00210"></a>00210         
<a name="l00211"></a>00211         <span class="keyword">const</span> TDesC8&amp; guidDes = KGuid;
<a name="l00212"></a>00212         HBufC8* guid = guidDes.AllocL();
<a name="l00213"></a>00213         CCalEntry* originatingEntry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
<a name="l00214"></a>00214         CleanupStack::PushL(originatingEntry);
<a name="l00215"></a>00215         
<a name="l00216"></a>00216         _LIT(KDescription,<span class="stringliteral">"An originating entry"</span>);
<a name="l00217"></a>00217         originatingEntry-&gt;SetDescriptionL(KDescription);
<a name="l00218"></a>00218         
<a name="l00219"></a>00219         TCalTime entryStartTime;
<a name="l00220"></a>00220         entryStartTime.SetTimeLocalL(startTime);
<a name="l00221"></a>00221         TCalTime entryEndTime;
<a name="l00222"></a>00222         entryEndTime.SetTimeLocalL(endTime);
<a name="l00223"></a>00223         originatingEntry-&gt;SetStartAndEndTimeL(entryStartTime, entryEndTime);
<a name="l00224"></a>00224         
<a name="l00225"></a>00225         <span class="comment">// Set the repeat rule</span>
<a name="l00226"></a>00226         <span class="comment">// The entry repeats weekly with 3 instances being created</span>
<a name="l00227"></a>00227         TCalRRule weeklyRptRule(TCalRRule::EWeekly);
<a name="l00228"></a>00228         weeklyRptRule.SetDtStart(entryStartTime);       
<a name="l00229"></a>00229         weeklyRptRule.SetCount(3); 
<a name="l00230"></a>00230         weeklyRptRule.SetInterval(1);
<a name="l00231"></a>00231         <span class="comment">// Also need to set the day that the entry repeats on</span>
<a name="l00232"></a>00232         RArray&lt;TDay&gt; days;
<a name="l00233"></a>00233         CleanupClosePushL(days);
<a name="l00234"></a>00234         days.AppendL(ESunday);
<a name="l00235"></a>00235         weeklyRptRule.SetByDay(days);
<a name="l00236"></a>00236         CleanupStack::PopAndDestroy(&amp;days);
<a name="l00237"></a>00237         originatingEntry-&gt;SetRRuleL(weeklyRptRule);
<a name="l00238"></a>00238 
<a name="l00239"></a>00239         <span class="comment">// Now write the entry to the view</span>
<a name="l00240"></a>00240         RPointerArray&lt;CCalEntry&gt; array;
<a name="l00241"></a>00241         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;array));
<a name="l00242"></a>00242         array.AppendL(originatingEntry);
<a name="l00243"></a>00243         TInt success(0);
<a name="l00244"></a>00244         <span class="comment">// If StoreL() leaves, 'success' contains the number of entries that were</span>
<a name="l00245"></a>00245         <span class="comment">// stored before it failed</span>
<a name="l00246"></a>00246         iCalEntryView-&gt;StoreL(array, success);
<a name="l00247"></a>00247         
<a name="l00248"></a>00248         <span class="comment">// clean up     </span>
<a name="l00249"></a>00249         array.Close();
<a name="l00250"></a>00250         CleanupStack::PopAndDestroy(&amp;array);
<a name="l00251"></a>00251         CleanupStack::PopAndDestroy(originatingEntry);  
<a name="l00252"></a>00252         }
<a name="l00253"></a>00253         
<a name="l00254"></a>00254 <span class="comment">// Adds a modifying, or "child" entry.</span>
<a name="l00255"></a>00255 <span class="comment">// A modifying entry modifies one or more instances of the "originating" repeating entry. </span>
<a name="l00256"></a>00256 <span class="comment">// It has the same UID, and is deleted when the originating entry is deleted.</span>
<a name="l00257"></a><a class="code" href="class_c_cal_example.html#0d965ba3fe5db4687c36b3288b9766d7">00257</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#0d965ba3fe5db4687c36b3288b9766d7">CCalExample::AddmodifyingEntryL</a>()
<a name="l00258"></a>00258         {
<a name="l00259"></a>00259         RPointerArray&lt;CCalEntry&gt; modifyingArray;
<a name="l00260"></a>00260         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;modifyingArray));
<a name="l00261"></a>00261         
<a name="l00262"></a>00262         _LIT(KAddingMsg, <span class="stringliteral">"\n\nAdding a modifying entry..."</span>);
<a name="l00263"></a>00263         iConsole-&gt;Printf ( KAddingMsg );
<a name="l00264"></a>00264         <span class="comment">// Create repeating modifying entry</span>
<a name="l00265"></a>00265         <span class="comment">// Has the same recurrence Id as the second instance of the originating and</span>
<a name="l00266"></a>00266         <span class="comment">// this and all future instances are modified.</span>
<a name="l00267"></a>00267         TTime recurrenceId(TDateTime(2006, EJanuary, 7, 14, 0, 0, 0)); <span class="comment">// January 8th 2pm</span>
<a name="l00268"></a>00268         TCalTime recurrenceIdCal;
<a name="l00269"></a>00269         recurrenceIdCal.SetTimeLocalL(recurrenceId);
<a name="l00270"></a>00270         
<a name="l00271"></a>00271         <span class="keyword">const</span> TDesC8&amp; guidDes = KGuid;
<a name="l00272"></a>00272         HBufC8* guid = guidDes.AllocL();
<a name="l00273"></a>00273 
<a name="l00274"></a>00274         <span class="comment">// Entry type is appointment, group scheduling method none and modifying this and all future instances </span>
<a name="l00275"></a>00275         CCalEntry* modifyingEntry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 1, recurrenceIdCal, CalCommon::EThisAndFuture);
<a name="l00276"></a>00276         CleanupStack::PushL(modifyingEntry);
<a name="l00277"></a>00277 
<a name="l00278"></a>00278         <span class="comment">// The modifying entry has a different description to the originating entry</span>
<a name="l00279"></a>00279         _LIT(KChildDescription,<span class="stringliteral">"A modifying entry"</span>);
<a name="l00280"></a>00280         modifyingEntry-&gt;SetDescriptionL(KChildDescription);
<a name="l00281"></a>00281         <span class="comment">// The modifying entry modifies the originating entry's date by one day</span>
<a name="l00282"></a>00282         TTime childStartTime(TDateTime(2006, EJanuary, 8, 14, 0, 0, 0)); <span class="comment">// January 9th 2pm</span>
<a name="l00283"></a>00283         TTime childEndTime(childStartTime + TTimeIntervalHours(1)); <span class="comment">// January 9th 3pm</span>
<a name="l00284"></a>00284         
<a name="l00285"></a>00285         TCalTime childEntryStartTime;
<a name="l00286"></a>00286         childEntryStartTime.SetTimeLocalL(childStartTime);
<a name="l00287"></a>00287         TCalTime childEntryEndTime;
<a name="l00288"></a>00288         childEntryEndTime.SetTimeLocalL(childEndTime);
<a name="l00289"></a>00289         modifyingEntry-&gt;SetStartAndEndTimeL(childEntryStartTime, childEntryEndTime);
<a name="l00290"></a>00290         <span class="comment">// Target instance for recurrence range in the modifying entry is second instance</span>
<a name="l00291"></a>00291         TCalRRule childRptRule(TCalRRule::EWeekly);
<a name="l00292"></a>00292         childRptRule.SetDtStart(childEntryStartTime);
<a name="l00293"></a>00293         childRptRule.SetCount(2); 
<a name="l00294"></a>00294         childRptRule.SetInterval(1);
<a name="l00295"></a>00295         
<a name="l00296"></a>00296         <span class="comment">// The modifying entry modifies the originating entry by occurring on Mondays</span>
<a name="l00297"></a>00297         RArray&lt;TDay&gt; days;
<a name="l00298"></a>00298         CleanupClosePushL(days);
<a name="l00299"></a>00299         days.AppendL(EMonday);
<a name="l00300"></a>00300         childRptRule.SetByDay(days);
<a name="l00301"></a>00301         CleanupStack::PopAndDestroy(&amp;days);
<a name="l00302"></a>00302         modifyingEntry-&gt;SetRRuleL(childRptRule);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304         <span class="comment">// add the modifying entry to the entry view.</span>
<a name="l00305"></a>00305         modifyingArray.AppendL(modifyingEntry);
<a name="l00306"></a>00306 
<a name="l00307"></a>00307         TInt success(0);
<a name="l00308"></a>00308         <span class="comment">// If StoreL() leaves, 'success' contains the number of entries that were</span>
<a name="l00309"></a>00309         <span class="comment">// stored before it failed</span>
<a name="l00310"></a>00310         iCalEntryView-&gt;StoreL(modifyingArray, success); 
<a name="l00311"></a>00311 
<a name="l00312"></a>00312         <span class="comment">// clean up     </span>
<a name="l00313"></a>00313         CleanupStack::PopAndDestroy(modifyingEntry);
<a name="l00314"></a>00314         modifyingArray.Reset();
<a name="l00315"></a>00315         CleanupStack::PopAndDestroy(&amp;modifyingArray);   
<a name="l00316"></a>00316         }
<a name="l00317"></a>00317         
<a name="l00318"></a>00318 <span class="comment">// Searches for all instances in January, then prints out their details.</span>
<a name="l00319"></a>00319 <span class="comment">// Creates an instance view to display the instances. </span>
<a name="l00320"></a><a class="code" href="class_c_cal_example.html#b2e18bfdafe7adb1e1d7cd100d5e383e">00320</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#b2e18bfdafe7adb1e1d7cd100d5e383e">CCalExample::FindInstanceL</a>()
<a name="l00321"></a>00321         { 
<a name="l00322"></a>00322         _LIT(KPressAKeyMsg, <span class="stringliteral">"\n\nPress any key to view the instances"</span>);
<a name="l00323"></a>00323         iConsole-&gt;Printf(KPressAKeyMsg);
<a name="l00324"></a>00324         iConsole-&gt;Getch ();
<a name="l00325"></a>00325         _LIT(KProgressMsg, <span class="stringliteral">"\nCalendar instance view creation is in progress..."</span>);
<a name="l00326"></a>00326         iConsole-&gt;Printf(KProgressMsg);         
<a name="l00327"></a>00327         CCalInstanceView* instanceView = CCalInstanceView::NewL(*iCalSession, *<span class="keyword">this</span>);
<a name="l00328"></a>00328         CleanupStack::PushL(instanceView);
<a name="l00329"></a>00329         CActiveScheduler::Start();
<a name="l00330"></a>00330         
<a name="l00331"></a>00331         RPointerArray&lt;CCalInstance&gt; instanceList;
<a name="l00332"></a>00332         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;instanceList));
<a name="l00333"></a>00333         CalCommon::TCalViewFilter filter = CalCommon::EIncludeAll;
<a name="l00334"></a>00334         TCalTime startDateForInstanceSearch;
<a name="l00335"></a>00335         TCalTime endDateForInstanceSearch;
<a name="l00336"></a>00336         
<a name="l00337"></a>00337         <span class="comment">// Set date and time range for searching for instances</span>
<a name="l00338"></a>00338         startDateForInstanceSearch.SetTimeLocalL(TDateTime( 2006, EJanuary, 0, 12, 0, 0, 0));  <span class="comment">// 1st January 12 pm</span>
<a name="l00339"></a>00339         endDateForInstanceSearch.SetTimeLocalL(TDateTime( 2006, EJanuary, 30, 10, 0, 0, 0)); <span class="comment">//  31st January 10 am</span>
<a name="l00340"></a>00340         CalCommon::TCalTimeRange searchTimeRange(startDateForInstanceSearch, endDateForInstanceSearch);
<a name="l00341"></a>00341         
<a name="l00342"></a>00342         <span class="comment">// Searches for instances within the specified date range</span>
<a name="l00343"></a>00343         instanceView-&gt;FindInstanceL(instanceList, filter, searchTimeRange);
<a name="l00344"></a>00344         
<a name="l00345"></a>00345         _LIT(KInstancesFound,<span class="stringliteral">"\n\nFound %d instances:"</span>);
<a name="l00346"></a>00346         iConsole-&gt;Printf(KInstancesFound,instanceList.Count());
<a name="l00347"></a>00347                 
<a name="l00348"></a>00348         TDateTime date; 
<a name="l00349"></a>00349         <span class="keywordflow">for</span>(TInt i = 0; i&lt;instanceList.Count(); i++) 
<a name="l00350"></a>00350                 {
<a name="l00351"></a>00351                 TPtrC des = instanceList[i]-&gt;Entry().DescriptionL();
<a name="l00352"></a>00352                 _LIT(KEntryDesc,<span class="stringliteral">"\nDescription: %S"</span>);
<a name="l00353"></a>00353                 iConsole-&gt;Printf(KEntryDesc,&amp;des); 
<a name="l00354"></a>00354 
<a name="l00355"></a>00355                 TTime time = instanceList[i]-&gt;StartTimeL().TimeLocalL();
<a name="l00356"></a>00356                 TBuf&lt;40&gt; datetimeStr;           
<a name="l00357"></a>00357                 _LIT(KFormat,<span class="stringliteral">"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S"</span>);
<a name="l00358"></a>00358                 time.FormatL(datetimeStr,KFormat);
<a name="l00359"></a>00359                 
<a name="l00360"></a>00360                 <span class="comment">// Print out the start date/time</span>
<a name="l00361"></a>00361                 _LIT(KStartDate,<span class="stringliteral">"\nLocal instance start date/time: %S "</span>);
<a name="l00362"></a>00362                 iConsole-&gt;Printf(KStartDate,&amp;datetimeStr);
<a name="l00363"></a>00363                 }
<a name="l00364"></a>00364                 
<a name="l00365"></a>00365         CleanupStack::PopAndDestroy(&amp;instanceList);     
<a name="l00366"></a>00366         CleanupStack::PopAndDestroy(instanceView);      
<a name="l00367"></a>00367         }       
<a name="l00368"></a>00368 
<a name="l00369"></a>00369 <span class="comment">// Fetch and print the entry details</span>
<a name="l00370"></a><a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">00370</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">CCalExample::PrintEntryDetailsL</a>()
<a name="l00371"></a>00371         {
<a name="l00372"></a>00372         _LIT(KPressAKeyMsg, <span class="stringliteral">"\nPress any key to view entry details"</span>);
<a name="l00373"></a>00373         iConsole-&gt;Printf ( KPressAKeyMsg );
<a name="l00374"></a>00374         iConsole-&gt;Getch ();
<a name="l00375"></a>00375 
<a name="l00376"></a>00376         RPointerArray&lt;CCalEntry&gt; array;
<a name="l00377"></a>00377         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;array));
<a name="l00378"></a>00378         iCalEntryView-&gt;FetchL(KGuid, array);
<a name="l00379"></a>00379         <span class="keywordflow">for</span>(TInt i=0; i&lt;array.Count(); i++)
<a name="l00380"></a>00380                 {
<a name="l00381"></a>00381                 CCalEntry* entry = array[i];
<a name="l00382"></a>00382                 CleanupStack::PushL(entry);
<a name="l00383"></a>00383                 
<a name="l00384"></a>00384                 TPtrC des = entry-&gt;DescriptionL();
<a name="l00385"></a>00385                 _LIT(KEntryDesc,<span class="stringliteral">" \n\nDescription: %S"</span>);
<a name="l00386"></a>00386                 iConsole-&gt;Printf(KEntryDesc,&amp;des); 
<a name="l00387"></a>00387 
<a name="l00388"></a>00388                 TCalTime startTime = entry-&gt;StartTimeL();
<a name="l00389"></a>00389                 TCalTime endTime = entry-&gt;EndTimeL();
<a name="l00390"></a>00390                 TTime time = startTime.TimeLocalL();
<a name="l00391"></a>00391                 
<a name="l00392"></a>00392                 TBuf&lt;40&gt; datetimeStr;           
<a name="l00393"></a>00393                 _LIT(KFormat,<span class="stringliteral">"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S"</span>);
<a name="l00394"></a>00394                 time.FormatL(datetimeStr,KFormat);
<a name="l00395"></a>00395                 
<a name="l00396"></a>00396                 <span class="comment">// Print out the start date/time</span>
<a name="l00397"></a>00397                 _LIT(KStartDate,<span class="stringliteral">"\nStart date/time: %S "</span>);
<a name="l00398"></a>00398                 iConsole-&gt;Printf(KStartDate,&amp;datetimeStr);
<a name="l00399"></a>00399                 
<a name="l00400"></a>00400                 <span class="comment">// Now, print out the end date/time</span>
<a name="l00401"></a>00401                 time = endTime.TimeLocalL();
<a name="l00402"></a>00402                 time.FormatL(datetimeStr,KFormat);
<a name="l00403"></a>00403                 _LIT(KEndDate,<span class="stringliteral">"\nEnd date/time: %S"</span>);
<a name="l00404"></a>00404                 iConsole-&gt;Printf(KEndDate,&amp;datetimeStr);
<a name="l00405"></a>00405                 CleanupStack::Pop(entry);
<a name="l00406"></a>00406                 
<a name="l00407"></a>00407                 <span class="comment">// Fetch category</span>
<a name="l00408"></a>00408                 RPointerArray&lt;CCalCategory&gt; categoryList = entry-&gt;CategoryListL();
<a name="l00409"></a>00409                 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> j=0; j&lt;categoryList.Count(); j++)
<a name="l00410"></a>00410                         {
<a name="l00411"></a>00411                         <span class="keyword">const</span> TDesC&amp; category = categoryList[j]-&gt;ExtendedCategoryName();
<a name="l00412"></a>00412                         HBufC* catbuf = category.AllocL();
<a name="l00413"></a>00413                         _LIT(KCatType,<span class="stringliteral">"\nCategory type: %S"</span>);
<a name="l00414"></a>00414                         iConsole-&gt;Printf(KCatType,catbuf);
<a name="l00415"></a>00415                         <span class="keyword">delete</span> catbuf;
<a name="l00416"></a>00416                         } 
<a name="l00417"></a>00417                                 
<a name="l00418"></a>00418                 <span class="comment">// Fetch attendee</span>
<a name="l00419"></a>00419                 RPointerArray&lt;CCalAttendee&gt; attendeeList;
<a name="l00420"></a>00420                 attendeeList = entry-&gt;AttendeesL();
<a name="l00421"></a>00421                 <span class="keywordflow">for</span>( <span class="keywordtype">int</span> k=0; k&lt;attendeeList.Count(); k++)
<a name="l00422"></a>00422                         {
<a name="l00423"></a>00423                         <span class="keyword">const</span> TDesC16&amp; address = attendeeList[k]-&gt;Address();
<a name="l00424"></a>00424                         HBufC16* addr = address.AllocL();
<a name="l00425"></a>00425                         _LIT(KAttendee,<span class="stringliteral">"\nAttendee %d: %S"</span>);
<a name="l00426"></a>00426                         iConsole-&gt;Printf(KAttendee,k+1, addr);
<a name="l00427"></a>00427                         <span class="keyword">delete</span> addr;            
<a name="l00428"></a>00428                         }
<a name="l00429"></a>00429                 }
<a name="l00430"></a>00430         CleanupStack::PopAndDestroy(&amp;array);
<a name="l00431"></a>00431         }
<a name="l00432"></a>00432 
<a name="l00433"></a>00433 <span class="comment">// Delete the originating entry </span>
<a name="l00434"></a><a class="code" href="class_c_cal_example.html#cbc67752acc71548a176ede8c8790c1e">00434</a> <span class="keywordtype">void</span> <a class="code" href="class_c_cal_example.html#cbc67752acc71548a176ede8c8790c1e">CCalExample::DeleteEntryL</a>()
<a name="l00435"></a>00435         {
<a name="l00436"></a>00436         _LIT(KPressAKeyMsg, <span class="stringliteral">"\n\nPress any key to delete the originating entry, (also deletes the modifying entry)"</span>);
<a name="l00437"></a>00437         iConsole-&gt;Printf ( KPressAKeyMsg );
<a name="l00438"></a>00438         iConsole-&gt;Getch ();
<a name="l00439"></a>00439         
<a name="l00440"></a>00440         RPointerArray&lt;CCalEntry&gt; entryArray;
<a name="l00441"></a>00441         CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &amp;entryArray));
<a name="l00442"></a>00442         
<a name="l00443"></a>00443         <span class="comment">// Fetch the entry to be deleted</span>
<a name="l00444"></a>00444         iCalEntryView-&gt;FetchL(KGuid, entryArray);
<a name="l00445"></a>00445         CCalEntry* entry = entryArray[0];
<a name="l00446"></a>00446 
<a name="l00447"></a>00447         <span class="comment">// Delete originating entry, thereby also deleting the modifying entry</span>
<a name="l00448"></a>00448         iCalEntryView-&gt;DeleteL(*entry);
<a name="l00449"></a>00449         CleanupStack::PopAndDestroy(&amp;entryArray);                       
<a name="l00450"></a>00450         }
<a name="l00451"></a>00451 
<a name="l00452"></a>00452 LOCAL_C <span class="keywordtype">void</span> <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>()
<a name="l00453"></a>00453         {
<a name="l00454"></a>00454         <a class="code" href="class_c_cal_example.html">CCalExample</a>* app = <a class="code" href="class_c_cal_example.html#db58fbf73337500d5bc8162ad2229336">CCalExample::NewL</a>();
<a name="l00455"></a>00455         CleanupStack::PushL(app);
<a name="l00456"></a>00456         
<a name="l00457"></a>00457         <span class="comment">// Add an entry and display the entry details</span>
<a name="l00458"></a>00458         app-&gt;<a class="code" href="class_c_cal_example.html#d89edab97029a30027346db3773ec5d0">AddEntryL</a>();
<a name="l00459"></a>00459         app-&gt;<a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">PrintEntryDetailsL</a>();      
<a name="l00460"></a>00460 
<a name="l00461"></a>00461         <span class="comment">// Update an entry and display the updated entry details</span>
<a name="l00462"></a>00462         app-&gt;<a class="code" href="class_c_cal_example.html#4de85d476d3f6f24657e81da3280d80c">UpdateEntryL</a>();
<a name="l00463"></a>00463         app-&gt;<a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">PrintEntryDetailsL</a>();
<a name="l00464"></a>00464         
<a name="l00465"></a>00465         <span class="comment">// Create a repeating entry and display the entry details</span>
<a name="l00466"></a>00466         app-&gt;<a class="code" href="class_c_cal_example.html#7c1da41338976354f45e8873f4343790">AddOriginatingEntryL</a>();
<a name="l00467"></a>00467         app-&gt;<a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">PrintEntryDetailsL</a>(); 
<a name="l00468"></a>00468         
<a name="l00469"></a>00469         <span class="comment">// Display the repeat instances</span>
<a name="l00470"></a>00470         app-&gt;<a class="code" href="class_c_cal_example.html#b2e18bfdafe7adb1e1d7cd100d5e383e">FindInstanceL</a>();           
<a name="l00471"></a>00471         
<a name="l00472"></a>00472         <span class="comment">// Create a modifying entry and display the entry details</span>
<a name="l00473"></a>00473         app-&gt;<a class="code" href="class_c_cal_example.html#0d965ba3fe5db4687c36b3288b9766d7">AddmodifyingEntryL</a>();
<a name="l00474"></a>00474         app-&gt;<a class="code" href="class_c_cal_example.html#3f297c124bb7751e7ca1d15eb12c17b9">PrintEntryDetailsL</a>(); 
<a name="l00475"></a>00475         
<a name="l00476"></a>00476         <span class="comment">// Display the repeat instances</span>
<a name="l00477"></a>00477         app-&gt;<a class="code" href="class_c_cal_example.html#b2e18bfdafe7adb1e1d7cd100d5e383e">FindInstanceL</a>();
<a name="l00478"></a>00478         
<a name="l00479"></a>00479         <span class="comment">// Delete the originating thereby deleting the modifying entry and all repeat instances</span>
<a name="l00480"></a>00480         app-&gt;<a class="code" href="class_c_cal_example.html#cbc67752acc71548a176ede8c8790c1e">DeleteEntryL</a>();             
<a name="l00481"></a>00481         
<a name="l00482"></a>00482         CleanupStack::PopAndDestroy(app);
<a name="l00483"></a>00483         }
<a name="l00484"></a>00484 
<a name="l00485"></a><a class="code" href="globals_8h.html#0f358e9c4355138f629b8c4f37310295">00485</a> GLDEF_C TInt <a class="code" href="dbllist_8cpp.html#0f358e9c4355138f629b8c4f37310295">E32Main</a>()
<a name="l00486"></a>00486         {
<a name="l00487"></a>00487         __UHEAP_MARK;
<a name="l00488"></a>00488         <span class="comment">// Active scheduler required as this is a console app</span>
<a name="l00489"></a>00489         CActiveScheduler* scheduler=<span class="keyword">new</span> CActiveScheduler;
<a name="l00490"></a>00490         
<a name="l00491"></a>00491         <span class="comment">// If active scheduler has been created, install it.</span>
<a name="l00492"></a>00492         <span class="keywordflow">if</span> (scheduler)
<a name="l00493"></a>00493                 {
<a name="l00494"></a>00494                 CActiveScheduler::Install(scheduler); 
<a name="l00495"></a>00495                 
<a name="l00496"></a>00496                 <span class="comment">// Cleanup stack needed</span>
<a name="l00497"></a>00497                 CTrapCleanup* cleanup = CTrapCleanup::New();
<a name="l00498"></a>00498                 <span class="keywordflow">if</span>(cleanup)
<a name="l00499"></a>00499                         {
<a name="l00500"></a>00500                         TRAPD(err, <a class="code" href="circularbuffer_8cpp.html#5fb473d4ee18739183215b04dcad6e12">MainL</a>());
<a name="l00501"></a>00501                         <span class="keywordflow">if</span>(err != KErrNone)
<a name="l00502"></a>00502                                 {
<a name="l00503"></a>00503                                 _LIT(KUserPanic,<span class="stringliteral">"Failed to complete"</span>);  
<a name="l00504"></a>00504                                 User::Panic(KUserPanic, err);
<a name="l00505"></a>00505                                 }
<a name="l00506"></a>00506                         <span class="keyword">delete</span> cleanup;
<a name="l00507"></a>00507                         }
<a name="l00508"></a>00508                 }
<a name="l00509"></a>00509         <span class="keyword">delete</span> scheduler;
<a name="l00510"></a>00510 
<a name="l00511"></a>00511         __UHEAP_MARKEND;
<a name="l00512"></a>00512         <span class="keywordflow">return</span> KErrNone;
<a name="l00513"></a>00513         }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:54 2010 for TB10.1 Example Applications by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>