omads/omadsappui/AiwSyncProvider/src/AiwSyncProvider.cpp
changeset 0 dab8a81a92de
child 26 3e6957da2ff8
equal deleted inserted replaced
-1:000000000000 0:dab8a81a92de
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 
       
    20 #include <AiwMenu.h>
       
    21 #include <AiwGenericParam.hrh>
       
    22 #include <AiwCommon.hrh>
       
    23 
       
    24 #include <implementationproxy.h>
       
    25 
       
    26 #include <data_caging_path_literals.hrh>  // for resource and bitmap directories
       
    27 
       
    28 #include <AiwSyncProvider.rsg>
       
    29 #include "AiwSyncProvider.h"
       
    30 #include "AiwSyncProviderUids.hrh"
       
    31 #include "AiwSyncProvider.rh"
       
    32 #include "AiwSyncProviderDebug.h"
       
    33 
       
    34 #include <aknnotewrappers.h>    // CAknInformationNote
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 _LIT( KResFileName, "z:AiwSyncProvider.rsc" );
       
    40 
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAspSyncProvider::NewL
       
    45 //
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CAspSyncProvider* CAspSyncProvider::NewL()
       
    49 	{
       
    50     FLOG( _L("CAspSyncProvider::NewL START") );
       
    51 
       
    52 	CAspSyncProvider* self = new (ELeave) CAspSyncProvider();
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop(self);
       
    56     
       
    57     FLOG( _L("CAspSyncProvider::NewL END") );
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CAspSyncProvider::Constructor
       
    64 //
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CAspSyncProvider::CAspSyncProvider()
       
    68 	{
       
    69 	}
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CAspSyncProvider::Destructor
       
    74 //
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CAspSyncProvider::~CAspSyncProvider()
       
    78 	{
       
    79 	FLOG( _L("~CAspSyncProvider START") );
       
    80 	
       
    81 	delete iSyncUtilApi;
       
    82 	
       
    83 	FLOG( _L("~CAspSyncProvider END") );
       
    84 	}
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CAspSyncProvider::ConstructL
       
    89 //
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CAspSyncProvider::ConstructL()
       
    93     {
       
    94     FLOG( _L("CAspSyncProvider::ConstructL START") );
       
    95  
       
    96 	iSyncUtilApi = CSyncUtilApi::NewL();
       
    97 
       
    98     FLOG( _L("CAspSyncProvider::ConstructL END") );
       
    99     } 
       
   100 
       
   101 
       
   102  
       
   103 // -----------------------------------------------------------------------------
       
   104 // CAspSyncProvider::InitialiseL (from CAiwServiceIfBase)
       
   105 //
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CAspSyncProvider::InitialiseL(MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   109 	    						   const RCriteriaArray& /*aInterest*/)
       
   110 	{
       
   111 	// Not implemented
       
   112 	}
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CAspSyncProvider::HandleServiceCmdL (from CAiwServiceIfBase)
       
   117 //
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CAspSyncProvider::HandleServiceCmdL(const TInt& aCmdId,
       
   121                                          const CAiwGenericParamList& aInParamList,
       
   122                                          CAiwGenericParamList& /*aOutParamList*/,
       
   123                                          TUint /*aCmdOptions*/,
       
   124                                          const MAiwNotifyCallback* /*aCallback*/)
       
   125 	{
       
   126 	TInt jobId = KErrNotFound;
       
   127 	TInt info1 = KErrNotFound;
       
   128 	TBuf<KBufSize> info2(KNullDesC);
       
   129 	TInt applicationId = GetApplicationId(aInParamList);
       
   130 
       
   131 	if (aCmdId != KAiwCmdSynchronize)
       
   132 		{
       
   133 		return;
       
   134 		}
       
   135 		
       
   136    	if (applicationId == EGenericParamMessageItemEMail)
       
   137 		{
       
   138 	    GetFileName(aInParamList, info2);
       
   139 	    if (info2.Length() == 0)
       
   140 	    	{
       
   141 	    	FLOG( _L("### mailbox name not found ###") );
       
   142 	    	return; // email sync requires mailbox name
       
   143 	    	}
       
   144 	    info1 = EGenericParamMessageItemEMail;
       
   145 		}
       
   146 		
       
   147 	iSyncUtilApi->SynchronizeL(applicationId, jobId, info1, info2); 
       
   148 		
       
   149     
       
   150         
       
   151     // R&D solution: Remove constness.
       
   152     //MAiwNotifyCallback* callback = 
       
   153     //    const_cast< MAiwNotifyCallback* >(aCallback);
       
   154 
       
   155 	//CAiwGenericParamList* dummyParamList = NULL;
       
   156 	
       
   157 	//callback->HandleNotifyL(0, 0, *dummyParamList, *dummyParamList);
       
   158 	}
       
   159 
       
   160 
       
   161 
       
   162  
       
   163 // -----------------------------------------------------------------------------
       
   164 // CAspSyncProvider::InitializeMenuPaneL (from CAiwServiceIfMenu)
       
   165 //
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CAspSyncProvider::InitializeMenuPaneL(CAiwMenuPane& aMenuPane,
       
   169 											  TInt aIndex,
       
   170 											  TInt /*aCascadeId*/,
       
   171 											  const CAiwGenericParamList& aInParamList)
       
   172 	{
       
   173 	FLOG( _L("CAspSyncProvider::InitializeMenuPaneL START") );
       
   174 	
       
   175 	
       
   176 	TFileName resFile;
       
   177 	GetResFileName(resFile);
       
   178 	
       
   179 	FTRACE( RDebug::Print(_L("resfile= '%S'  index= %d"), &resFile, aIndex) );
       
   180 
       
   181     TInt serviceCommand = GetServiceCommandId(aInParamList);
       
   182     
       
   183     if (serviceCommand == KErrNotFound)
       
   184     	{
       
   185     	FLOG( _L("### service command not found ###") );
       
   186     	FLOG( _L("CAspSyncProvider::InitializeMenuPaneL END") );
       
   187     	return;
       
   188     	}
       
   189     
       
   190     if (serviceCommand == KAiwCmdSynchronizeSelected)
       
   191     	{
       
   192         TRAPD(ignoreError, aMenuPane.AddMenuItemsL(resFile, R_ASPSYNCPROVIDER_MENU_4, KAiwCmdSynchronizeSelected, aIndex));
       
   193         if (ignoreError != KErrNone)
       
   194         	{
       
   195         	FTRACE( RDebug::Print(_L("### CAiwMenuPane::AddMenuItemsL failed (%d) ###"), ignoreError) );
       
   196         	}
       
   197        	}
       
   198        	
       
   199     if (serviceCommand == KAiwCmdSynchronize)
       
   200     	{
       
   201     	TRAPD(ignoreError, aMenuPane.AddMenuItemsL(resFile, R_ASPSYNCPROVIDER_SUBMENU, KAiwCmdSynchronize, aIndex));
       
   202         if (ignoreError != KErrNone)
       
   203         	{
       
   204         	FTRACE( RDebug::Print(_L("### CAiwMenuPane::AddMenuItemsL failed (%d) ###"), ignoreError) );
       
   205         	}
       
   206     	}
       
   207     	
       
   208     FLOG( _L("CAspSyncProvider::InitializeMenuPaneL END") );
       
   209 	}
       
   210 
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CAspSyncProvider::HandleMenuCmdL (from CAiwServiceIfMenu)
       
   214 //
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CAspSyncProvider::HandleMenuCmdL(TInt aMenuCmdId, 
       
   218                                       const CAiwGenericParamList& aInParamList,
       
   219                                       CAiwGenericParamList& /*aOutParamList*/,
       
   220                                       TUint /*aCmdOptions*/,
       
   221                                       const MAiwNotifyCallback* /*aCallback*/)
       
   222 	{
       
   223 	FLOG( _L("CAspSyncProvider::HandleMenuCmdL START") );
       
   224     
       
   225 	TInt jobId = KErrNotFound;
       
   226 	TInt info1 = KErrNotFound;
       
   227 	TBuf<KBufSize> info2(KNullDesC);
       
   228 	TInt applicationId = GetApplicationId(aInParamList);
       
   229 	
       
   230 	if (applicationId == KErrNotFound)
       
   231 		{
       
   232     	FLOG(_L("### application id not found ###"));
       
   233 		return; // must have consumer app id
       
   234 		}
       
   235 	
       
   236 	switch (aMenuCmdId)
       
   237 		{
       
   238 		case EAspSyncProviderCmdStart:
       
   239 			if (applicationId == EGenericParamMessageItemEMail)
       
   240 				{
       
   241 			    GetFileName(aInParamList, info2);
       
   242 			    if (info2.Length() == 0)
       
   243 			    	{
       
   244 			    	FLOG( _L("### mailbox name not found ###") );
       
   245 			    	return; // email sync requires mailbox name
       
   246 			    	}
       
   247 				}
       
   248 		
       
   249 			iSyncUtilApi->SynchronizeL(applicationId, jobId, info1, info2); 
       
   250             break;
       
   251 
       
   252 		case EAspSyncProviderCmdSettings:
       
   253 		    iSyncUtilApi->ShowSettingsL(applicationId, info1, info2);
       
   254             break;
       
   255             
       
   256 		case EAspSyncProviderCmdRetrieve:
       
   257 		    applicationId = EGenericParamMessageItemEMail;
       
   258 		    info1 = KAiwCmdSynchronizeSelected;
       
   259 		    GetFileName(aInParamList, info2);
       
   260 		    if (info2.Length() == 0)
       
   261 		    	{
       
   262 		    	FLOG( _L("### mailbox name not found ###") );
       
   263 		    	return; // email sync requires mailbox name
       
   264 		    	}
       
   265 		    
       
   266 		    iSyncUtilApi->SynchronizeL(applicationId, jobId, info1, info2);
       
   267             break; 
       
   268             
       
   269 		default:
       
   270 		    FTRACE( RDebug::Print(_L("### unknown menu command (%d) ###"), aMenuCmdId) );
       
   271 			break;
       
   272 		}
       
   273 		
       
   274 	FLOG( _L("CAspSyncProvider::HandleMenuCmdL END") );
       
   275 	}
       
   276 
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CAspSyncProvider::GetApplicationIdL
       
   280 //
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TInt CAspSyncProvider::GetApplicationId(const CAiwGenericParamList& aInParamList)
       
   284 	{
       
   285 	_LIT(KSyncApplicationName, "sync");
       
   286 	
       
   287 	TInt index = 0;
       
   288 	
       
   289 	const TAiwGenericParam* param = aInParamList.FindFirst(index, EGenericParamContactItem);
       
   290 	if (index >= 0)
       
   291 		{
       
   292     	return EGenericParamContactItem;
       
   293 		}
       
   294 		
       
   295 	index = 0;
       
   296 	param = aInParamList.FindFirst(index, EGenericParamCalendarItem);
       
   297 	if (index >= 0)
       
   298 		{
       
   299     	return EGenericParamCalendarItem;
       
   300 		}
       
   301 
       
   302     index = 0;
       
   303 	param = aInParamList.FindFirst(index, EGenericParamMessageItemEMail);
       
   304 	if (index >= 0)
       
   305 		{
       
   306     	return EGenericParamMessageItemEMail;
       
   307 		}
       
   308 		
       
   309 	index = 0;
       
   310 	param = aInParamList.FindFirst(index, EGenericParamNoteItem);
       
   311 	if (index >= 0)
       
   312 		{
       
   313     	return EGenericParamNoteItem;
       
   314 		}
       
   315    
       
   316     index = 0;
       
   317 	param = aInParamList.FindFirst(index, EGenericParamMessageItemMMS);
       
   318 	if (index >= 0)
       
   319 		{
       
   320     	return EGenericParamMessageItemMMS;
       
   321 		}
       
   322 
       
   323     index = 0;
       
   324 	param = aInParamList.FindFirst(index, EGenericParamEmailAddress);
       
   325 	if (index >= 0)
       
   326 		{
       
   327     	return EGenericParamEmailAddress;
       
   328 		}
       
   329 
       
   330 	// this is for starting Sync application - not used at the moment
       
   331 	index = 0;
       
   332 	param = aInParamList.FindFirst(index, EGenericParamApplication);
       
   333 	if (index >= 0)
       
   334 		{
       
   335    	    TPtrC ptr;
       
   336     	const TAiwVariant& val = param->Value();
       
   337 	    if (val.Get(ptr))
       
   338 		    {
       
   339 		    if (ptr.Compare(KSyncApplicationName) == 0)
       
   340 		    	{
       
   341 		    	return KSyncApplicationId;
       
   342 		    	}
       
   343 		    }
       
   344 		}
       
   345 
       
   346 	return KErrNotFound;
       
   347 	}
       
   348 
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CAspSyncProvider::GetFileName
       
   352 //
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 void CAspSyncProvider::GetFileName(const CAiwGenericParamList& aInParamList, TDes& aText)
       
   356 	{
       
   357 	aText = KNullDesC;
       
   358 	TInt index = 0;
       
   359 	const TAiwGenericParam* param = aInParamList.FindFirst(index, EGenericParamMessageItemMbox);
       
   360 	if (index < 0)
       
   361 		{
       
   362 		return;
       
   363 		}
       
   364 
       
   365     TPtrC ptr;
       
   366 	const TAiwVariant& val = param->Value();
       
   367 	if (!val.Get(ptr))
       
   368 		{
       
   369 		FLOG(_L("### CAspSyncProvider::GetFileName: param value not found ###"));
       
   370 		return;
       
   371 		}
       
   372 	
       
   373 	StrCopy(aText, ptr);
       
   374 	}
       
   375 
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CAspSyncProvider::GetServiceCommandId
       
   379 //
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 TInt CAspSyncProvider::GetServiceCommandId(const CAiwGenericParamList& aInParamList)
       
   383 	{
       
   384 	TInt index = 0;
       
   385 	const TAiwGenericParam* param = aInParamList.FindFirst(index, EGenericParamServiceCommand);
       
   386 	if (index < 0)
       
   387 		{
       
   388     	return KErrNotFound;
       
   389 		}
       
   390 
       
   391     TInt32 num = 0;
       
   392 	const TAiwVariant& val = param->Value();
       
   393 	if (!val.Get(num))
       
   394 		{
       
   395 		FLOG(_L("CAspSyncProvider::GetServiceCommandId: param value not found"));
       
   396 		return KErrNotFound;
       
   397 		}
       
   398 	return num;
       
   399 	}
       
   400 
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CAspSyncProvider::GetResFileName
       
   404 //
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CAspSyncProvider::GetResFileName(TDes& aText)
       
   408 	{
       
   409 	TParse parse;
       
   410 	parse.Set(KResFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   411 	StrCopy(aText, parse.FullName());
       
   412 	}
       
   413 
       
   414 
       
   415 // -------------------------------------------------------------------------------
       
   416 // CAspSyncProvider::StrCopy
       
   417 //
       
   418 // String copy with lenght check.
       
   419 // -------------------------------------------------------------------------------
       
   420 //
       
   421 void CAspSyncProvider::StrCopy(TDes& aTarget, const TDesC& aSource)
       
   422     {
       
   423 	TInt len = aTarget.MaxLength();
       
   424     if(len < aSource.Length()) 
       
   425 	    {
       
   426 		aTarget.Copy(aSource.Left(len));
       
   427 		return;
       
   428 	    }
       
   429 	aTarget.Copy(aSource);
       
   430     }
       
   431 
       
   432 
       
   433 //------------------------------------------------------------------------------
       
   434 // TDialogUtil::ShowInformationNoteL
       
   435 //
       
   436 //------------------------------------------------------------------------------
       
   437 //
       
   438 void CAspSyncProvider::ShowInformationNoteL(const TDesC& aText)
       
   439 	{
       
   440 	CAknInformationNote* queryDialog = new (ELeave) CAknInformationNote(ETrue);
       
   441 	queryDialog->ExecuteLD(aText);
       
   442 	}
       
   443 
       
   444 
       
   445 
       
   446 
       
   447 
       
   448 //
       
   449 // Rest of the file is for ECom initialization. 
       
   450 //
       
   451 
       
   452 
       
   453 
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // Map the interface UIDs to implementation factory functions
       
   457 //
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 const TImplementationProxy ImplementationTable[] =
       
   461     {
       
   462     IMPLEMENTATION_PROXY_ENTRY(KAspSyncProviderImplUid,	CAspSyncProvider::NewL)
       
   463     };
       
   464 
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // Exported proxy for instantiation method resolution
       
   468 //
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   472 {
       
   473     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   474 
       
   475     return ImplementationTable;
       
   476 }
       
   477 
       
   478 
       
   479 
       
   480 
       
   481 
       
   482 
       
   483 // End of file