contextengine/plugins/calendarplugin/src/CalendarContextPlugin.cpp
changeset 0 c53acadfccc6
child 19 82c0024438c8
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <mdeobject.h>
       
    21 
       
    22 #include <calinstance.h>
       
    23 #include <calinstanceview.h>
       
    24 #include <calsession.h>
       
    25 #include <caldataexchange.h>
       
    26 #include <caldataformat.h>
       
    27 
       
    28 #include <s32mem.h>
       
    29 
       
    30 #include "CalendarContextPlugin.h"
       
    31 #include "harvesterlog.h"
       
    32 #include "mdeconstants.h"
       
    33 #include "mdenamespacedef.h"
       
    34 #include "mdeobjectdef.h"
       
    35 #include "harvesterdata.h"
       
    36 #include "mdsutils.h"
       
    37 
       
    38 using namespace MdeConstants;
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CCalendarContextPlugin::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CCalendarContextPlugin* CCalendarContextPlugin::NewL()
       
    47 	{
       
    48 	WRITELOG( "CCalendarContextPlugin::NewL -- ENTER" );
       
    49 
       
    50 	CCalendarContextPlugin* self = new(ELeave) CCalendarContextPlugin();
       
    51 	CleanupStack::PushL( self );
       
    52 	self->ConstructL();
       
    53 	CleanupStack::Pop( self );
       
    54 
       
    55 	WRITELOG( "CCalendarContextPlugin::NewL -- RETURN" );
       
    56 
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCalendarContextPlugin::CCalendarContextPlugin
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CCalendarContextPlugin::CCalendarContextPlugin() :
       
    65     iCalInstanceView( NULL ), iMdeSession( NULL ),
       
    66     iCalSession( NULL ), iCalInstanceViewCompleted( EFalse ), 
       
    67     iRetryCount( 0 )
       
    68 	{
       
    69 	}
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CCalendarContextPlugin::ConstructL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CCalendarContextPlugin::ConstructL() // second-phase constructor
       
    76 	{
       
    77 	WRITELOG( "CCalendarContextPlugin::ConstructL -- ENTER" );
       
    78 
       
    79 	OpenViewL();
       
    80 	
       
    81 	WRITELOG( "CCalendarContextPlugin::ConstructL  -- RETURN" );
       
    82 	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCalendarContextPlugin::~CCalendarContextPlugin
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CCalendarContextPlugin::~CCalendarContextPlugin() // destruct
       
    89 	{
       
    90 	WRITELOG( "CCalendarContextPlugin::~CCalendarContextPlugin -- ENTER" );
       
    91 	delete iCalInstanceView;
       
    92 	delete iCalSession;
       
    93 	
       
    94 	if( iInitTimer )
       
    95 	    {
       
    96 	    iInitTimer->Cancel();
       
    97 	    delete iInitTimer;
       
    98 	    }
       
    99 		
       
   100 	WRITELOG( "CCalendarContextPlugin::~CCalendarContextPlugin -- RETURN" );
       
   101 	}
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CCalendarContextPlugin::InitL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CCalendarContextPlugin::Init( MContextPluginObserver& aObserver )
       
   108 	{
       
   109 	WRITELOG( "CCalendarContextPlugin::InitL  -- ENTER" );
       
   110 
       
   111 	// Notification to context framework
       
   112 	aObserver.PluginInitializationStatus( KErrNone );
       
   113 
       
   114 	WRITELOG( "CCalendarContextPlugin::InitL -- RETURN" );
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CCalendarContextPlugin::ContextSnapshot
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CCalendarContextPlugin::ContextSnapshot( MContextPluginObserver& aObserver,
       
   122 		CHarvesterData& aHD )
       
   123 	{
       
   124 	WRITELOG( "CCalendarContextPlugin::ContextSnapshotL, 1 obj. --ENTER" );
       
   125 
       
   126 	CMdEObject& mdeObject = aHD.MdeObject();
       
   127 	TRAPD( error, AddMetaDataL( mdeObject ) )	;
       
   128 	// Notification to context framework
       
   129 	aHD.SetErrorCode( error );
       
   130 	aObserver.PluginSnapshotStatus( &aHD );
       
   131 
       
   132 	WRITELOG( "CCalendarContextPlugin::ContextSnapshotL, 1 obj. --RETURN" );
       
   133 	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CCalendarContextPlugin::ContextSnapshot
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CCalendarContextPlugin::ContextSnapshot(MContextPluginObserver& aObserver,
       
   140 		RPointerArray< CHarvesterData >& aHDArray)
       
   141 	{
       
   142 #ifdef _DEBUG
       
   143 	WRITELOG( "CCalendarContextPlugin::ContextSnapshotL, array -- ENTER" );
       
   144 	WRITELOG1("Size of array: %d", aHDArray.Count() );
       
   145 #endif
       
   146 	
       
   147 	TInt err = KErrNone;
       
   148 	const TInt count( aHDArray.Count() );
       
   149 	for( TInt i = 0; i < count; ++i )
       
   150 		{
       
   151 		CHarvesterData* hd = aHDArray[i];
       
   152 		CMdEObject& mdeObject = hd->MdeObject();
       
   153 		TRAP( err,AddMetaDataL( mdeObject ) );
       
   154 		hd->SetErrorCode( err );
       
   155 		// Notification to context framework
       
   156 		aObserver.PluginSnapshotStatus( hd );
       
   157 		}
       
   158 
       
   159 	WRITELOG( "CCalendarContextPlugin::ContextSnapshotL, array -- RETURN" );
       
   160 	}
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CCalendarContextPlugin::GetTimeMdEPropL
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 #ifdef _DEBUG
       
   167 TTime CCalendarContextPlugin::GetTimeMdEPropL( const TDesC& aNameSpace,
       
   168     const TDesC& aProp, CMdEObject& aMdEObject) const
       
   169 #else
       
   170 TTime CCalendarContextPlugin::GetTimeMdEPropL( const TDesC&,
       
   171     const TDesC& aProp, CMdEObject& aMdEObject) const
       
   172 #endif
       
   173 	{
       
   174 	WRITELOG( "CCalendarContextPlugin::GetTimeMdEPropL -- ENTER" );
       
   175 	WRITELOG1("aNameSpace: %S", &aNameSpace );
       
   176 	WRITELOG1("aProp: %S", &aProp );
       
   177 
       
   178 	CMdEPropertyDef& timeDef = aMdEObject.Def().GetPropertyDefL( aProp );
       
   179 
       
   180 	CMdEProperty* timeProp = NULL;
       
   181 	aMdEObject.Property( timeDef, timeProp );
       
   182 
       
   183 	if ( !timeProp )
       
   184 		{
       
   185 		User::Leave( KErrNotFound );
       
   186 		}
       
   187 
       
   188 	WRITELOG( "CCalendarContextPlugin::GetTimeMdEPropL  -- RETURN" );
       
   189 
       
   190 	return timeProp->TimeValueL();
       
   191 	}
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CCalendarContextPlugin::AddMetaDataL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CCalendarContextPlugin::AddMetaDataL( CMdEObject& aMdEObject ) const
       
   198 	{
       
   199 	if ( aMdEObject.Id() == KNoId )
       
   200 		return;
       
   201 
       
   202 	WRITELOG( "CCalendarContextPlugin::AddMetaDataL -- ENTER" );
       
   203 
       
   204 	if ( !iCalInstanceViewCompleted )
       
   205 		{
       
   206 		// The CalendarInstanceView has not yet reported completion by calling
       
   207 		// the callback routine, so no calendar information can be looked up.
       
   208 		WRITELOG( "iCalInstanceViewCompleted==EFalse, returning." );
       
   209 		WRITELOG( "CCalendarContextPlugin::AddMetaDataL -- RETURN" );
       
   210 		return;
       
   211 		}
       
   212 
       
   213 	RPointerArray<CCalInstance> instances;
       
   214 	TCleanupItem cleanupItem( MdsUtils::CleanupPtrArray<CCalInstance>, &instances );
       
   215 	CleanupStack::PushL( cleanupItem );
       
   216 
       
   217 	// From the mdsAddTime find the start of the day and the end of the day
       
   218 	// in order to set the time range for the search in the calendar database
       
   219 	TTime mdsAddTime = GetTimeMdEPropL(
       
   220 		KMdEDefaultNameSpace, Object::KCreationDateProperty, aMdEObject );
       
   221 
       
   222 	TDateTime dateTime = mdsAddTime.DateTime();
       
   223 	dateTime.SetHour( 0 );
       
   224 	dateTime.SetMinute( 0 );
       
   225 	dateTime.SetSecond( 0 );
       
   226 	dateTime.SetMicroSecond( 0 );
       
   227 	TTime dayBeginTime( dateTime );
       
   228 	TCalTime startCalTime;
       
   229 	TCalTime stopCalTime;
       
   230 	startCalTime.SetTimeLocalL( dayBeginTime );
       
   231 	stopCalTime.SetTimeLocalL( dayBeginTime + 
       
   232 			TTimeIntervalDays ( 1 ) - TTimeIntervalMicroSeconds( 1 ) );
       
   233 
       
   234 	// Get a list of the all instances in the calendar database associated
       
   235 	// with this day
       
   236 	iCalInstanceView->FindInstanceL( instances, CalCommon::EIncludeAll,
       
   237 									 CalCommon::TCalTimeRange( startCalTime, stopCalTime) );
       
   238 
       
   239 	const TInt instanceCount = instances.Count();
       
   240 
       
   241 	WRITELOG1( "CCalendarContextPlugin::AddMetaDataL -- instanceCount: %d", instanceCount );
       
   242 
       
   243 	// required object properties
       
   244 	WRITELOG( "CCalendarContextPlugin::AddMetaDataL" );
       
   245 	User::LeaveIfNull( iMdeSession );
       
   246 	CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL();
       
   247 	WRITELOG( "CCalendarContextPlugin::AddMetaDataL" );
       
   248 
       
   249 	CMdERelationDef& containsRelDef = namespaceDef.GetRelationDefL(
       
   250 		Relations::KContains );
       
   251 	CMdEObjectDef& calendarObjectDef = namespaceDef.GetObjectDefL(
       
   252 		Calendar::KCalendarObject );
       
   253 
       
   254 	CMdEPropertyDef& creationDef = calendarObjectDef.GetPropertyDefL(
       
   255 		Object::KCreationDateProperty );
       
   256 	CMdEPropertyDef& modifiedDef = calendarObjectDef.GetPropertyDefL(
       
   257 		Object::KLastModifiedDateProperty );
       
   258 	CMdEPropertyDef& sizeDef = calendarObjectDef.GetPropertyDefL(
       
   259 		Object::KSizeProperty );
       
   260 	CMdEPropertyDef& itemTypeDef = calendarObjectDef.GetPropertyDefL(
       
   261 		Object::KItemTypeProperty );
       
   262 	CMdEPropertyDef& titleDef = calendarObjectDef.GetPropertyDefL(
       
   263 			Object::KTitleProperty );
       
   264 	CMdEPropertyDef& offSetDef = calendarObjectDef.GetPropertyDefL( 
       
   265 			Object::KTimeOffsetProperty );
       
   266 
       
   267 	// calendar properties
       
   268 	CMdEPropertyDef& startDef    = calendarObjectDef.GetPropertyDefL(
       
   269 		Calendar::KStartTimeProperty );
       
   270 	CMdEPropertyDef& endDef      = calendarObjectDef.GetPropertyDefL(
       
   271 		Calendar::KEndTimeProperty );
       
   272 	CMdEPropertyDef& caltypeDef  = calendarObjectDef.GetPropertyDefL(
       
   273 		Calendar::KCalendarTypeProperty );
       
   274 	CMdEPropertyDef& locationDef = calendarObjectDef.GetPropertyDefL(
       
   275 		Calendar::KLocationProperty );
       
   276 	CMdEPropertyDef& localUidDef = calendarObjectDef.GetPropertyDefL(
       
   277 			Calendar::KLocalUidProperty );
       
   278 
       
   279 	TTime curtime( 0 );
       
   280 	curtime.UniversalTime();
       
   281 
       
   282 	const TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
       
   283 	TTime localTime = curtime + timeOffsetSeconds;
       
   284 
       
   285 	TInt timeOffset = timeOffsetSeconds.Int() / 60;
       
   286 
       
   287 	for ( TInt i = 0; i < instanceCount; ++i )
       
   288 		{
       
   289 		WRITELOG1( "CCalendarContextPlugin::AddMetaDataL - loop index: %d", i );
       
   290 
       
   291 		CCalInstance* instance = instances[i];
       
   292 		CCalEntry& entry = instance->Entry();
       
   293 
       
   294 		const TDesC& location = entry.LocationL();
       
   295 		const TDesC& title = entry.SummaryL();
       
   296 		TTime beginTime = entry.StartTimeL().TimeLocalL();
       
   297 		TTime endTime = entry.EndTimeL().TimeLocalL();
       
   298 		TUint32 localUid = entry.LocalUidL();
       
   299 
       
   300 		CCalEntry::TType type = entry.EntryTypeL();
       
   301 
       
   302 		// Anniversaries and such are whole day events
       
   303 		if ( type == CCalEntry::EAnniv || type == CCalEntry::ETodo )
       
   304 			{
       
   305 			// Set end time to the end of the day
       
   306 			endTime += TTimeIntervalDays ( 1 );
       
   307 			endTime -= TTimeIntervalMicroSeconds( 1 );
       
   308 			}
       
   309 		// Other type entry must be currently active
       
   310 		else if ( ( mdsAddTime < beginTime ) || ( endTime < mdsAddTime ) )
       
   311 			{
       
   312 			WRITELOG( "CCalendarContextPlugin::AddMetaDataL - Calendar event not active - SKIP" );
       
   313 			continue;
       
   314 			}
       
   315 
       
   316 		WRITELOG( "CCalendarContextPlugin::AddMetaDataL - Create calendar item" );
       
   317 		CMdEObject* calendarObject=  NULL;
       
   318 		calendarObject = iMdeSession->NewObjectLC(
       
   319 			calendarObjectDef, Object::KAutomaticUri );
       
   320 		calendarObject->AddTimePropertyL( creationDef, localTime );
       
   321 		calendarObject->AddTimePropertyL( modifiedDef, curtime );
       
   322 		calendarObject->AddUint32PropertyL( sizeDef, 0 ); // always zero size for calendar objects
       
   323 		calendarObject->AddTextPropertyL( itemTypeDef, Calendar::KCalendarItemType );
       
   324 		calendarObject->AddInt16PropertyL( offSetDef, timeOffset );
       
   325 
       
   326 		//Calendar properties
       
   327 		calendarObject->AddTimePropertyL( startDef, beginTime );
       
   328 		calendarObject->AddTimePropertyL( endDef, endTime );
       
   329 		calendarObject->AddUint8PropertyL( caltypeDef, type );
       
   330 		calendarObject->AddUint32PropertyL( localUidDef, localUid );
       
   331 		if ( location.Length() > 0 )
       
   332 			{
       
   333 			calendarObject->AddTextPropertyL( locationDef, location );
       
   334 			}
       
   335 		if ( title.Length() > 0 )
       
   336 			{
       
   337 			calendarObject->AddTextPropertyL( titleDef, title );
       
   338 			}
       
   339 
       
   340 		WRITELOG( "CCalendarContextPlugin::AddMetaDataL - Add calendar item to MDE" );
       
   341 		TRAPD( addError, iMdeSession->AddObjectL( *calendarObject ) );
       
   342 		if ( addError != KErrNone )
       
   343 			{
       
   344 			WRITELOG1( "CCalendarContextPlugin::AddMetaDataL - Add calendar item to MDE error: %d", addError );
       
   345 			CleanupStack::PopAndDestroy( calendarObject );
       
   346 			continue;
       
   347 			}
       
   348 
       
   349 		const TItemId calid = calendarObject->Id();
       
   350 		const TItemId objid = aMdEObject.Id();
       
   351 
       
   352 		CMdERelation* relationObject = iMdeSession->NewRelationLC(
       
   353 			containsRelDef, objid, calid, 0 );
       
   354 		if ( !relationObject )
       
   355 			{
       
   356 			WRITELOG( "CCalendarContextPlugin::AddMetaDataL - Couldn't create relation object!" );
       
   357 			User::Leave( KErrBadHandle );
       
   358 			}
       
   359 
       
   360 		WRITELOG( "CCalendarContextPlugin::AddMetaDataL - Add calendar relation to MDE" );
       
   361 		TRAP( addError, iMdeSession->AddRelationL( *relationObject ) );
       
   362 		if ( addError != KErrNone)
       
   363 			{
       
   364 			WRITELOG1( "CCalendarContextPlugin::AddMetaDataL - Add calendar relation to MDE error: %d", addError );
       
   365 			}
       
   366 
       
   367 		CleanupStack::PopAndDestroy( relationObject );
       
   368 		CleanupStack::PopAndDestroy( calendarObject );
       
   369 		}
       
   370 
       
   371 	CleanupStack::PopAndDestroy( &instances );
       
   372 
       
   373 	WRITELOG( "CCalendarContextPlugin::AddMetaDataL -- RETURN" );
       
   374 	}
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CCalendarContextPlugin::HandleSessionOpened
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void CCalendarContextPlugin::HandleSessionOpened( CMdESession& /*aSession*/,
       
   381 		TInt /*aError*/ )
       
   382 	{
       
   383 	WRITELOG( "CCalendarContextPlugin::HandleSessionOpened -- ENTER" );
       
   384 	WRITELOG( "CCalendarContextPlugin::HandleSessionOpened -- RETURN" );
       
   385 	}
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CCalendarContextPlugin::HandleSessionError
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CCalendarContextPlugin::HandleSessionError( CMdESession& /*aSession*/,
       
   392 	TInt /*aError*/ )
       
   393 	{
       
   394 	WRITELOG( "CCalendarContextPlugin::HandleSessionError -- ENTER" );
       
   395 	WRITELOG( "CCalendarContextPlugin::HandleSessionError -- RETURN" );
       
   396 	}
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CCalendarContextPlugin::Progress
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 void CCalendarContextPlugin::Progress( TInt /*aPercentageCompleted*/ )
       
   403 	{
       
   404 	WRITELOG( "CCalendarContextPlugin::Progress -- ENTER" );
       
   405 	WRITELOG( "CCalendarContextPlugin::Progress -- RETURN" );
       
   406 	}
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // CCalendarContextPlugin::Completed
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CCalendarContextPlugin::Completed( TInt aError )
       
   413 	{
       
   414 	WRITELOG( "CCalendarContextPlugin::Completed -- ENTER" );
       
   415 
       
   416 	if ( aError != KErrNone )
       
   417 		{
       
   418 		iCalInstanceViewCompleted = EFalse;
       
   419 		WRITELOG1( "aError: %d", aError );
       
   420 		TRAP_IGNORE( StartRetryL() );
       
   421 		}
       
   422 	else
       
   423 		{
       
   424 		iCalInstanceViewCompleted = ETrue;
       
   425 		}
       
   426 
       
   427 	WRITELOG( "CCalendarContextPlugin::Completed -- RETURN" );
       
   428 	}
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CCalendarContextPlugin::NotifyProgress
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 TBool CCalendarContextPlugin::NotifyProgress()
       
   435 	{
       
   436 	WRITELOG( "CCalendarContextPlugin::NotifyProgress -- ENTER" );
       
   437 	WRITELOG( "CCalendarContextPlugin::NotifyProgress -- RETURN" );
       
   438 
       
   439 	return EFalse;
       
   440 	}
       
   441 
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // CCalendarContextPlugin::SetMdeSession
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CCalendarContextPlugin::SetMdeSession( CMdESession& aSession )
       
   448 	{
       
   449 	iMdeSession = &aSession;
       
   450 	}
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CCalendarContextPlugin::OpenView
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 void CCalendarContextPlugin::OpenViewL(TBool aRetry)
       
   457     {
       
   458     WRITELOG( "CCalendarContextPlugin::OpenViewL() ENTER" );
       
   459     TInt err(KErrNone);
       
   460     
       
   461     if(aRetry)
       
   462         {
       
   463         WRITELOG( "CCalendarContextPlugin::OpenViewL() retry" );
       
   464         iInitTimer->Cancel();
       
   465         delete iInitTimer;
       
   466         iInitTimer = NULL;
       
   467         }
       
   468     
       
   469     if(!iCalSession)
       
   470         {
       
   471         WRITELOG( "CCalendarContextPlugin::OpenViewL() new calsession");
       
   472         TRAP(err, iCalSession = CCalSession::NewL());
       
   473         
       
   474         if( err != KErrNone)
       
   475             {
       
   476             WRITELOG1( "CCalendarContextPlugin::OpenViewL() CCalSession::NewL() err = %d", err );
       
   477             iCalSession = NULL;
       
   478             StartRetryL();
       
   479             return;
       
   480             }
       
   481         }
       
   482 
       
   483     WRITELOG( "CCalendarContextPlugin::OpenViewL() open calsession");
       
   484     TRAP(err, iCalSession->OpenL( KNullDesC ));
       
   485 
       
   486     if(err != KErrNone )
       
   487         {
       
   488         WRITELOG1( "CCalendarContextPlugin::OpenViewL() iCalSession->OpenL() err = %d", err );
       
   489         StartRetryL();
       
   490         return;
       
   491         }
       
   492 
       
   493     WRITELOG( "CCalendarContextPlugin::OpenViewL() open view");
       
   494     TRAP( err, iCalInstanceView = CCalInstanceView::NewL( *iCalSession, *this ) );
       
   495         
       
   496     if(err != KErrNone )
       
   497         {
       
   498         WRITELOG1( "CCalendarContextPlugin::OpenViewL() CCalInstanceView::NewL() err = %d", err );
       
   499         iCalInstanceView = NULL;
       
   500         StartRetryL();
       
   501         return;
       
   502         }
       
   503 
       
   504     WRITELOG( "CCalendarContextPlugin::OpenViewL() RETURN" );
       
   505     }
       
   506 
       
   507 
       
   508 void CCalendarContextPlugin::StartRetryL()
       
   509     {
       
   510     WRITELOG( "CCalendarContextPlugin::StartRetryL() ENTER" );
       
   511     TInt err(KErrNone);
       
   512     
       
   513     if(iRetryCount++ > KMaxRetryCount)
       
   514         {
       
   515         delete iCalInstanceView;
       
   516         iCalInstanceView = NULL;
       
   517         delete iCalSession;
       
   518         iCalSession = NULL;
       
   519         
       
   520         if( iInitTimer )
       
   521             {
       
   522             iInitTimer->Cancel();
       
   523             delete iInitTimer;
       
   524             iInitTimer = NULL;
       
   525             }
       
   526         
       
   527 		return; 
       
   528         }
       
   529     
       
   530     
       
   531     if(!iInitTimer)
       
   532         {
       
   533         TRAP(err, iInitTimer = CPeriodic::NewL(CActive::EPriorityStandard) );
       
   534         }
       
   535                 
       
   536     if( err != KErrNone )
       
   537         {
       
   538         WRITELOG1( "CCalendarContextPlugin::OpenViewL() iInitTimer->Start failed %d", err );
       
   539         User::Leave( err );
       
   540         }
       
   541         
       
   542     WRITELOG( "CCalendarContextPlugin::OpenViewL() iInitTimer->Start" );
       
   543     iInitTimer->Start( KInitRetryTimeout, KInitRetryTimeout, TCallBack(InitRetryCallback, this));
       
   544     WRITELOG( "CCalendarContextPlugin::StartRetryL() RETURN" );
       
   545     }
       
   546 	
       
   547 // ---------------------------------------------------------------------------
       
   548 // CCalendarContextPlugin::InitRetryCallback()
       
   549 // ---------------------------------------------------------------------------
       
   550 //
       
   551 TInt CCalendarContextPlugin::InitRetryCallback(TAny* aAny)
       
   552     {
       
   553     WRITELOG( "CCalendarContextPlugin::InitRetryCallback() ENTER");
       
   554     CCalendarContextPlugin* self = static_cast<CCalendarContextPlugin*>( aAny );
       
   555 
       
   556     TRAP_IGNORE( self->OpenViewL(ETrue) );
       
   557     
       
   558     WRITELOG( "CCalendarContextPlugin::InitRetryCallback() RETURN");
       
   559     return KErrNone;
       
   560     }
       
   561