calendarengines/caldav/src/caldavenginemgr.cpp
changeset 1 4927282092b4
child 6 5a04f2ceabfe
equal deleted inserted replaced
0:f979ecb2b13e 1:4927282092b4
       
     1 /*
       
     2 * Copyright (c) 2010 Sun Microsystems, Inc. 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 Contributor:
       
    10 * Maximilian Odendahl
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: provides a manager to keep track of all available engines
       
    15 *
       
    16 */
       
    17 
       
    18 #include "caldavenginemgr.h"
       
    19 #include "caldavengine.h"
       
    20 
       
    21 #include <calsession.h>
       
    22 #include <calcalendarinfo.h>
       
    23 #include "calenglobaldata.h"
       
    24 
       
    25 /**
       
    26  * CCalDavEngineMgr::CCalDavEngineMgr()
       
    27  * default constructor
       
    28  */
       
    29 CCalDavEngineMgr::CCalDavEngineMgr()
       
    30 	{
       
    31 	}
       
    32 
       
    33 /**
       
    34  * CCalDavEngineMgr::~CCalDavEngineMgr()
       
    35  * default destructor
       
    36  */
       
    37 CCalDavEngineMgr::~CCalDavEngineMgr()
       
    38 	{
       
    39 	for (TInt i = iEngines.Count() - 1; i >= 0; --i)
       
    40 		delete iEngines[i];
       
    41 	iEngines.Close();
       
    42 	}
       
    43 
       
    44 /**
       
    45  * CCalDavEngineMgr::NewLC()
       
    46  * first phase construction
       
    47  */
       
    48 CCalDavEngineMgr* CCalDavEngineMgr::NewLC()
       
    49 	{
       
    50 	CCalDavEngineMgr* self = new (ELeave) CCalDavEngineMgr();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 /**
       
    57  * CCalDavEngineMgr::NewL()
       
    58  * first phase construction
       
    59  */
       
    60 CCalDavEngineMgr* CCalDavEngineMgr::NewL()
       
    61 	{
       
    62 	CCalDavEngineMgr* self = CCalDavEngineMgr::NewLC();
       
    63 	CleanupStack::Pop(); // self;
       
    64 	return self;
       
    65 	}
       
    66 
       
    67 /**
       
    68  * CCalDavEngineMgr::Progress()
       
    69  * progress callback
       
    70  */
       
    71 void CCalDavEngineMgr::Progress(TInt /*aPercentageCompleted*/)
       
    72 	{
       
    73 	}
       
    74 
       
    75 /**
       
    76  * CCalDavEngineMgr::Completed()
       
    77  * completed callback
       
    78  */
       
    79 void CCalDavEngineMgr::Completed(TInt /*aError*/)
       
    80 	{
       
    81 	}
       
    82 
       
    83 /**
       
    84  * CCalDavEngineMgr::NotifyProgress()
       
    85  * NotifyProgress callback
       
    86  */
       
    87 TBool CCalDavEngineMgr::NotifyProgress()
       
    88 	{
       
    89 	return EFalse;
       
    90 	}
       
    91 
       
    92 /**
       
    93  * CCalDavEngineMgr::ConstructL()
       
    94  * second phase construction
       
    95  * check all calendar files, for each one which has caldav sync enabled, 
       
    96  * create a CCalDavengine and enable sync
       
    97  */
       
    98 void CCalDavEngineMgr::ConstructL()
       
    99 	{
       
   100 	RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   101 	CCalenGlobalData* data = CCalenGlobalData::NewL(*this);
       
   102 	data->InitializeGlobalDataL();
       
   103 	CleanupStack::PushL(data);
       
   104 	data->GetAllCalendarInfoL(calendarInfoList);
       
   105 	CleanupClosePushL(calendarInfoList);
       
   106 
       
   107 	for (TInt i = 0; i < calendarInfoList.Count(); i++)
       
   108 		{
       
   109 		CDesC8Array* propertyKeys = calendarInfoList[i]->PropertyKeysL();
       
   110 		CleanupStack::PushL(propertyKeys);
       
   111 		TInt pos = 0;
       
   112 		if (propertyKeys->Find(KCaldavEnabled, pos, ECmpNormal) == KErrNone)
       
   113 			{
       
   114 			CCalDavEngine* engine = CCalDavEngine::NewL(
       
   115 					calendarInfoList[i]->FileNameL());
       
   116 			iEngines.Append(engine);
       
   117 			if (engine->EnabledSync())
       
   118 				engine->EnableL();
       
   119 			}
       
   120 		CleanupStack::PopAndDestroy(propertyKeys);
       
   121 		}
       
   122 	CleanupStack::PopAndDestroy(&calendarInfoList);
       
   123 	CleanupStack::PopAndDestroy(data);
       
   124 	}
       
   125 
       
   126 /**
       
   127  * CCalDavEngineMgr::FindEngineL()
       
   128  * find engines inside engine array, create if neccessary
       
   129  */
       
   130 TInt CCalDavEngineMgr::FindEngineL(const TDesC &aName, TBool aCreate)
       
   131 	{
       
   132 	CCalSession* session = CCalSession::NewL();
       
   133 	TRAPD(error,session->OpenL(aName));
       
   134 	delete session;
       
   135 	if (error != KErrNone)
       
   136 		return KErrNotFound;
       
   137 		
       
   138 	for (TInt i = 0; i <= iEngines.Count() - 1; i++)
       
   139 		{
       
   140 		if (iEngines[i]->CalendarName() == aName)
       
   141 			return i;
       
   142 		}
       
   143 
       
   144 	if (aCreate)
       
   145 		{
       
   146 		iEngines.Append(CCalDavEngine::NewL(aName));
       
   147 		return iEngines.Count() - 1;
       
   148 		}
       
   149 	else
       
   150 		return KErrNotFound;
       
   151 	}
       
   152 
       
   153 /**
       
   154  * CCalDavEngineMgr::SyncL()
       
   155  * sync specific calendar
       
   156  */
       
   157 TInt CCalDavEngineMgr::SyncL(const TDesC &aCalendar)
       
   158 	{
       
   159 	TInt pos = FindEngineL(aCalendar);
       
   160 	if (pos != KErrNotFound)
       
   161 		return iEngines[pos]->SyncL();
       
   162 	else
       
   163 		return KErrNotFound;
       
   164 	}
       
   165 
       
   166 /**
       
   167  * CCalDavEngineMgr::SyncAllL()
       
   168  * sync all calendars
       
   169  */
       
   170 TInt CCalDavEngineMgr::SyncAllL()
       
   171 	{
       
   172 	// sync all caldav enabled calendars
       
   173 	for (TInt i = 0; i <= iEngines.Count() - 1; i++)
       
   174 		iEngines[i]->SyncL();
       
   175 	return KErrNone;
       
   176 	}
       
   177 
       
   178 /**
       
   179  * CCalDavEngineMgr::DisableL()
       
   180  * 
       
   181  */
       
   182 TInt CCalDavEngineMgr::DisableL(const TDesC &aCalendar)
       
   183 	{
       
   184 	TInt pos = FindEngineL(aCalendar);
       
   185 
       
   186 	if (pos != KErrNotFound)
       
   187 		iEngines[pos]->DisableL();
       
   188 
       
   189 	return pos == KErrNotFound ? KErrNotFound : KErrNone;
       
   190 	}
       
   191 
       
   192 /**
       
   193  * CCalDavEngineMgr::EnableL()
       
   194  * 
       
   195  */
       
   196 TInt CCalDavEngineMgr::EnableL(const TDesC &aCalendar)
       
   197 	{
       
   198 	TInt pos = FindEngineL(aCalendar);
       
   199 	if (pos != KErrNotFound)
       
   200 		{
       
   201 		return iEngines[pos]->EnableL();
       
   202 		}
       
   203 
       
   204 	return KErrArgument;
       
   205 	}
       
   206 
       
   207 /**
       
   208  * CCalDavEngineMgr::UrlL()
       
   209  * 
       
   210  */
       
   211 TPtrC8 CCalDavEngineMgr::UrlL(const TDesC &aCalendar)
       
   212 	{
       
   213 	TInt pos = FindEngineL(aCalendar);
       
   214 	return (pos != KErrNotFound) ? iEngines[pos]->Url() : KNullDesC8();
       
   215 	}
       
   216 
       
   217 /**
       
   218  * CCalDavEngineMgr::SetUrlL()
       
   219  * 
       
   220  */
       
   221 void CCalDavEngineMgr::SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl)
       
   222 	{
       
   223 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   224 	if (pos != KErrNotFound)
       
   225 		iEngines[pos]->SetUrlL(aUrl);
       
   226 	}
       
   227 
       
   228 /**
       
   229  * CCalDavEngineMgr::UsernameL()
       
   230  * 
       
   231  */
       
   232 TPtrC8 CCalDavEngineMgr::UsernameL(const TDesC &aCalendar)
       
   233 	{
       
   234 	TInt pos = FindEngineL(aCalendar);
       
   235 	return (pos != KErrNotFound) ? iEngines[pos]->User() : KNullDesC8();
       
   236 	}
       
   237 
       
   238 /**
       
   239  * CCalDavEngineMgr::SetUsernameL()
       
   240  * 
       
   241  */
       
   242 void CCalDavEngineMgr::SetUsernameL(const TDesC &aCalendar,
       
   243 		const TDesC8 &aUsername)
       
   244 	{
       
   245 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   246 	if (pos != KErrNotFound)
       
   247 		iEngines[pos]->SetUserL(aUsername);
       
   248 	}
       
   249 
       
   250 /**
       
   251  * CCalDavEngineMgr::PasswordL()
       
   252  * 
       
   253  */
       
   254 TPtrC8 CCalDavEngineMgr::PasswordL(const TDesC &aCalendar)
       
   255 	{
       
   256 	TInt pos = FindEngineL(aCalendar);
       
   257 	return (pos != KErrNotFound) ? iEngines[pos]->Password() : KNullDesC8();
       
   258 	}
       
   259 
       
   260 /**
       
   261  * CCalDavEngineMgr::SetPasswordL()
       
   262  * 
       
   263  */
       
   264 void CCalDavEngineMgr::SetPasswordL(const TDesC &aCalendar,
       
   265 		const TDesC8 &aPassword)
       
   266 	{
       
   267 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   268 	if (pos != KErrNotFound)
       
   269 		iEngines[pos]->SetPasswordL(aPassword);
       
   270 	}
       
   271 
       
   272 /**
       
   273  * CCalDavEngineMgr::SyncIntervalL()
       
   274  * 
       
   275  */
       
   276 TTimeIntervalMinutes CCalDavEngineMgr::SyncIntervalL(const TDesC &aCalendar)
       
   277 	{
       
   278 	TInt pos = FindEngineL(aCalendar);
       
   279 	return (pos != KErrNotFound) ? iEngines[pos]->SyncInterval()
       
   280 			: TTimeIntervalMinutes(DEFAULT_SYNC_MINUTES);
       
   281 	}
       
   282 
       
   283 /**
       
   284  * CCalDavEngineMgr::SetSyncIntervalL()
       
   285  * 
       
   286  */
       
   287 void CCalDavEngineMgr::SetSyncIntervalL(const TDesC &aCalendar,
       
   288 		TTimeIntervalMinutes aSyncInterval)
       
   289 	{
       
   290 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   291 	if (pos != KErrNotFound)
       
   292 		iEngines[pos]->SetSyncIntervalL(aSyncInterval);
       
   293 	}
       
   294 
       
   295 /**
       
   296  * CCalDavEngineMgr::PastDaysL()
       
   297  * 
       
   298  */
       
   299 TTimeIntervalDays CCalDavEngineMgr::PastDaysL(const TDesC &aCalendar)
       
   300 	{
       
   301 	TInt pos = FindEngineL(aCalendar);
       
   302 	return (pos != KErrNotFound) ? iEngines[pos]->PastDays()
       
   303 			: TTimeIntervalDays(DEFAULT_PAST_DAYS);
       
   304 	}
       
   305 
       
   306 /**
       
   307  * CCalDavEngineMgr::SetPastDaysL()
       
   308  * 
       
   309  */
       
   310 void CCalDavEngineMgr::SetPastDaysL(const TDesC &aCalendar,
       
   311 		TTimeIntervalDays aDays)
       
   312 	{
       
   313 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   314 	if (pos != KErrNotFound)
       
   315 		iEngines[pos]->SetPastDaysL(aDays);
       
   316 	}
       
   317 
       
   318 /**
       
   319  * CCalDavEngineMgr::ImmediateSyncL()
       
   320  * 
       
   321  */
       
   322 TBool CCalDavEngineMgr::ImmediateSyncL(const TDesC &aCalendar)
       
   323 	{
       
   324 	TInt pos = FindEngineL(aCalendar);
       
   325 	return pos != KErrNotFound ? iEngines[pos]->ImmediateSync()
       
   326 			: DEFAULT_IMMEDIATE_SYNC;
       
   327 	}
       
   328 
       
   329 /**
       
   330  * CCalDavEngineMgr::SetImmediateSyncL()
       
   331  * 
       
   332  */
       
   333 void CCalDavEngineMgr::SetImmediateSyncL(const TDesC &aCalendar,
       
   334 		TBool aImmediateSyc)
       
   335 	{
       
   336 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   337 	if (pos != KErrNotFound)
       
   338 		iEngines[pos]->SetImmediateSyncL(aImmediateSyc);
       
   339 	}
       
   340 
       
   341 /**
       
   342  * CCalDavEngineMgr::KeepServerEntryL()
       
   343  * 
       
   344  */
       
   345 TBool CCalDavEngineMgr::KeepServerEntryL(const TDesC &aCalendar)
       
   346 	{
       
   347 	TInt pos = FindEngineL(aCalendar);
       
   348 	return pos != KErrNotFound ? iEngines[pos]->KeepServerEntry()
       
   349 			: DEFAULT_KEEP_SERVER_ENTRY;
       
   350 	}
       
   351 
       
   352 /**
       
   353  * CCalDavEngineMgr::SetKeepServerEntryL()
       
   354  * 
       
   355  */
       
   356 void CCalDavEngineMgr::SetKeepServerEntryL(const TDesC &aCalendar,
       
   357 		TBool aKeepServerEntry)
       
   358 	{
       
   359 	TInt pos = FindEngineL(aCalendar, ETrue);
       
   360 	if (pos != KErrNotFound)
       
   361 		iEngines[pos]->SetKeepServerEntryL(aKeepServerEntry);
       
   362 	}
       
   363 
       
   364 /**
       
   365  * CCalDavEngineMgr::EnabledSyncL()
       
   366  * 
       
   367  */
       
   368 TBool CCalDavEngineMgr::EnabledSyncL(const TDesC &aCalendar)
       
   369 	{
       
   370 	TInt pos = FindEngineL(aCalendar);
       
   371 	return (pos != KErrNotFound) ? iEngines[pos]->EnabledSync() : EFalse;
       
   372 	}