omads/omadsappui/AspSyncUtil/src/AspContentListDialog.cpp
changeset 0 dab8a81a92de
equal deleted inserted replaced
-1:000000000000 0:dab8a81a92de
       
     1 /*
       
     2 * Copyright (c) 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 FILES
       
    21 #include "AspContentListDialog.h"
       
    22 #include "AspContentDialog.h"
       
    23 #include "AspDialogUtil.h"
       
    24 #include "AspSyncUtil.rh"  // for menu command ids
       
    25 #include "AspUtil.h"
       
    26 #include "AspDebug.h"
       
    27 #include "AspDefines.h"
       
    28 #include "AspResHandler.h"
       
    29 #include <csxhelp/ds.hlp.hrh>
       
    30 
       
    31 
       
    32 #include <AspSyncUtil.mbg>  // for bitmap enumerations
       
    33 #include <akniconarray.h>  // GulArray
       
    34 #include <FeatMgr.h>   // FeatureManager
       
    35 
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CAspContentListDialog::ShowDialogL
       
    44 // 
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 TBool CAspContentListDialog::ShowDialogL(const TAspParam& aParam)
       
    48 	{
       
    49     CAspContentListDialog* dialog = CAspContentListDialog::NewL(aParam);
       
    50 
       
    51 	TBool ret = dialog->ExecuteLD(R_ASP_CONTENT_LIST_DIALOG);
       
    52 
       
    53 	return ret;
       
    54 	}
       
    55 
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CAspContentListDialog::NewL
       
    59 //
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CAspContentListDialog* CAspContentListDialog::NewL(const TAspParam& aParam)
       
    63     {
       
    64     FLOG( _L("CAspContentListDialog::NewL START") );
       
    65 
       
    66     CAspContentListDialog* self = new (ELeave) CAspContentListDialog(aParam);
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop(self);
       
    70 
       
    71     FLOG( _L("CAspContentListDialog::NewL END") );
       
    72     return(self);
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CAspContentListDialog::CAspContentListDialog
       
    78 // 
       
    79 // -----------------------------------------------------------------------------
       
    80 CAspContentListDialog::CAspContentListDialog(const TAspParam& aParam) 
       
    81     {
       
    82 	iApplicationId = aParam.iApplicationId;
       
    83 	iProfile = aParam.iProfile;
       
    84 	iSyncSession = aParam.iSyncSession;
       
    85 	
       
    86 	__ASSERT_ALWAYS(iProfile, TUtil::Panic(KErrGeneral));
       
    87 	__ASSERT_ALWAYS(iSyncSession, TUtil::Panic(KErrGeneral));		
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CAspContentListDialog::ConstructL
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 void CAspContentListDialog::ConstructL()
       
    96     {
       
    97     FLOG( _L("CAspContentListDialog::ConstructL START" ) );
       
    98 
       
    99 	// contruct menu for our dialog
       
   100 	CAknDialog::ConstructL(R_ASP_CONTENT_LIST_DIALOG_MENU);
       
   101 
       
   102 	// get previous title so it can be restored
       
   103 	iStatusPaneHandler = CStatusPaneHandler::NewL(iAvkonAppUi);
       
   104 	iStatusPaneHandler->StoreOriginalTitleL();
       
   105 
       
   106 
       
   107     TAspParam param(iApplicationId, iSyncSession);
       
   108 	param.iProfile = iProfile;
       
   109 	param.iMode = CAspContentList::EInitAll;
       
   110 
       
   111 	iContentList = CAspContentList::NewL(param);
       
   112 
       
   113     iStatusPaneHandler->SetTitleL(R_ASP_CONTENT_LIST_DIALOG_TITLE);
       
   114 
       
   115 	FLOG( _L("CAspContentListDialog::ConstructL END") );
       
   116     } 
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // Destructor
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 CAspContentListDialog::~CAspContentListDialog()
       
   124     {
       
   125     FLOG( _L("CAspContentListDialog::~CAspContentListDialog START") );
       
   126     
       
   127     if (iAvkonAppUi)
       
   128     	{
       
   129     	iAvkonAppUi->RemoveFromStack(this);
       
   130     	}
       
   131 
       
   132 	delete iStatusPaneHandler;
       
   133 	delete iContentList;
       
   134 	
       
   135 	FLOG( _L("CAspContentListDialog::~CAspContentListDialog END") );
       
   136     }
       
   137 
       
   138 
       
   139 //------------------------------------------------------------------------------
       
   140 // CAspContentListDialog::ActivateL (from CCoeControl)
       
   141 //
       
   142 // Called by system when dialog is activated.
       
   143 //------------------------------------------------------------------------------
       
   144 //
       
   145 void CAspContentListDialog::ActivateL()
       
   146 	{
       
   147     CAknDialog::ActivateL();
       
   148 
       
   149 	// this cannot be in ConstructL which is executed before dialog is launched
       
   150 	iAvkonAppUi->AddToStackL(this);
       
   151     }
       
   152 
       
   153 
       
   154 //------------------------------------------------------------------------------
       
   155 // CAspContentListDialog::GetHelpContext
       
   156 //
       
   157 //------------------------------------------------------------------------------
       
   158 //
       
   159 void CAspContentListDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   160 	{
       
   161 	aContext.iMajor = KUidSmlSyncApp;
       
   162 	//aContext.iContext = KDS_HLP_APPS_VIEW;    
       
   163 	}
       
   164 
       
   165 
       
   166 //------------------------------------------------------------------------------
       
   167 // CAspContentListDialog::ProcessCommandL
       
   168 //
       
   169 // Handle commands from menu.
       
   170 //------------------------------------------------------------------------------
       
   171 //
       
   172 void CAspContentListDialog::ProcessCommandL(TInt aCommandId)
       
   173 	{
       
   174 	HideMenu();
       
   175 
       
   176 	switch (aCommandId)
       
   177 		{
       
   178         case EAspMenuCmdEdit:
       
   179 			{
       
   180 			ShowContentL();
       
   181 			break;
       
   182 			}
       
   183         
       
   184         case EAspMenuCmdHelp:
       
   185 			{
       
   186 			TUtil::LaunchHelpAppL(iEikonEnv);
       
   187 			break;
       
   188 			}
       
   189 
       
   190         case EAspMenuCmdExit:
       
   191         case EAknCmdExit:
       
   192         case EEikCmdExit:
       
   193 			{
       
   194 			// close dialog and exit calling application
       
   195 			iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   196 			break;
       
   197 			}
       
   198 
       
   199 		default:
       
   200 			{
       
   201 			break;
       
   202 			}
       
   203 		}
       
   204 	}
       
   205 
       
   206 
       
   207 //------------------------------------------------------------------------------
       
   208 // CAspContentListDialog::OkToExitL
       
   209 //
       
   210 //------------------------------------------------------------------------------
       
   211 //
       
   212 TBool CAspContentListDialog::OkToExitL(TInt aButtonId)
       
   213 	{
       
   214 	if (aButtonId == EEikBidCancel)
       
   215 		{
       
   216 		// exit going on - must return true.
       
   217 		return ETrue;
       
   218 		}
       
   219 
       
   220 	if (aButtonId == EAknSoftkeyBack)
       
   221         {
       
   222 		return ETrue;
       
   223 		}
       
   224 
       
   225 	return CAknDialog::OkToExitL(aButtonId);
       
   226 	}
       
   227 
       
   228 
       
   229 // ----------------------------------------------------------------------------
       
   230 // CAspContentListDialog::OfferKeyEventL
       
   231 // 
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 TKeyResponse CAspContentListDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   235 	{
       
   236 	if (aType == EEventKey)
       
   237 		{
       
   238 		switch (aKeyEvent.iCode)
       
   239 			{
       
   240 			case EKeyOK:
       
   241 				{
       
   242 				ShowContentL();
       
   243 				return EKeyWasConsumed;
       
   244 				}
       
   245     		
       
   246 			case EKeyEscape:  // framework calls this when dialog must shut down
       
   247 				{
       
   248 			    return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   249 				}
       
   250  
       
   251 			default:
       
   252 				{
       
   253 			    break;
       
   254 				}
       
   255 			}
       
   256 		}
       
   257 
       
   258 	return CAknDialog::OfferKeyEventL( aKeyEvent, aType);
       
   259 	}
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CAspContentListDialog::PreLayoutDynInitL
       
   264 //
       
   265 // Called by framework before dialog is shown.
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CAspContentListDialog::PreLayoutDynInitL()
       
   269     {
       
   270     iSettingListBox = (CAknDoubleLargeStyleListBox*) ControlOrNull (EAspContentListDialogList);
       
   271     
       
   272    	__ASSERT_ALWAYS(iSettingListBox, TUtil::Panic(KErrGeneral));
       
   273 	
       
   274 	iSettingListBox->SetListBoxObserver(this);
       
   275 	iSettingListBox->CreateScrollBarFrameL(ETrue);
       
   276 	iSettingListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   277 
       
   278 	TFileName bitmapName;
       
   279 	CAspResHandler::GetBitmapFileName(bitmapName);
       
   280 
       
   281 	CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(KDefaultArraySize);
       
   282 	CleanupStack::PushL(icons);
       
   283 
       
   284  	// NOTE: icons must be appended in correct order (TAspContentListDialogIconIndex)
       
   285  	icons->AppendL(IconL(KAknsIIDQgnPropSmlSyncServer, bitmapName, EMbmAspsyncutilQgn_prop_sml_sync_server, EMbmAspsyncutilQgn_prop_sml_sync_server_mask));
       
   286 	icons->AppendL(IconL(KAknsIIDQgnPropSmlSyncToServer, bitmapName, EMbmAspsyncutilQgn_prop_sml_sync_to_server, EMbmAspsyncutilQgn_prop_sml_sync_to_server_mask));
       
   287 	icons->AppendL(IconL(KAknsIIDQgnPropSmlSyncFromServer, bitmapName, EMbmAspsyncutilQgn_prop_sml_sync_from_server, EMbmAspsyncutilQgn_prop_sml_sync_from_server_mask));
       
   288 	icons->AppendL(IconL(KAknsIIDQgnPropSmlSyncOff, bitmapName, EMbmAspsyncutilQgn_prop_sml_sync_off, EMbmAspsyncutilQgn_prop_sml_sync_off_mask));
       
   289 
       
   290 	iSettingListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   291 	CleanupStack::Pop(icons);
       
   292 
       
   293 	UpdateListBoxL();
       
   294 	
       
   295 	iSettingListBox->UpdateScrollBarsL();
       
   296 	iSettingListBox->ScrollBarFrame()->MoveVertThumbTo(0);
       
   297 	}
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CAspContentListDialog::IconL
       
   302 // 
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 CGulIcon* CAspContentListDialog::IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex, TInt aFileMaskIndex)
       
   306 	{
       
   307     return TDialogUtil::CreateIconL(aId, aFileName, aFileIndex, aFileMaskIndex);
       
   308 	}
       
   309 
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CAspContentListDialog::DynInitMenuPaneL
       
   313 //
       
   314 // Called by framework before menu is shown.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CAspContentListDialog::DynInitMenuPaneL(TInt aResourceID, 	CEikMenuPane* /*aMenuPane*/)
       
   318 	{
       
   319     if (aResourceID != R_ASP_CONTENT_LIST_DIALOG_MENU_PANE)
       
   320 		{
       
   321 		return;
       
   322 		}
       
   323 
       
   324 	if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   325 		{
       
   326 		TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdHelp);
       
   327 		}
       
   328 
       
   329     }
       
   330 
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CAspContentListDialog::HandleListBoxEventL (from MEikListBoxObserver)
       
   334 // 
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 void CAspContentListDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent /*aEventType*/)
       
   338 	{
       
   339 	}
       
   340 
       
   341 
       
   342 // ----------------------------------------------------------------------------
       
   343 // CAspContentListDialog::HandleResourceChange
       
   344 // 
       
   345 // ----------------------------------------------------------------------------
       
   346 //
       
   347 void CAspContentListDialog::HandleResourceChange(TInt aType)
       
   348     {   
       
   349     if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation
       
   350         {
       
   351         TRect mainPaneRect;
       
   352         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   353         SetRect(mainPaneRect);
       
   354         iSettingListBox->SetSize(mainPaneRect.Size());
       
   355         CCoeControl::HandleResourceChange(aType);
       
   356 		DrawDeferred();
       
   357 	    return;
       
   358 		}
       
   359 		
       
   360     CCoeControl::HandleResourceChange(aType);
       
   361     }
       
   362 
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CAspContentListDialog::UpdateListBoxL
       
   366 //	
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CAspContentListDialog::UpdateListBoxL()
       
   370 	{
       
   371 	TInt iconIndex = EIconNotDefined;
       
   372 	
       
   373 	CAknDoubleLargeStyleListBox* listBox = ListBox();
       
   374 	CDesCArray* items = (CDesCArray*) listBox->Model()->ItemTextArray();
       
   375 	items->Reset();
       
   376     listBox->ItemDrawer()->ClearAllPropertiesL();
       
   377 	
       
   378 	TInt count = iContentList->ProviderCount();
       
   379 
       
   380 	for (TInt i=0; i<count; i++)
       
   381 		{
       
   382 		HBufC* firstLine = NULL;
       
   383 		HBufC* secondLine = NULL;
       
   384 				
       
   385 		iconIndex = EIconNotDefined;
       
   386 		TAspProviderItem& providerItem = iContentList->ProviderItem(i);
       
   387 		
       
   388 		firstLine = CAspResHandler::GetContentNameLC(providerItem.iDataProviderId, providerItem.iDisplayName);
       
   389 		
       
   390 		TInt index = iContentList->FindTaskIndexForProvider(providerItem.iDataProviderId);
       
   391 		
       
   392 		if (index != KErrNotFound)
       
   393 			{
       
   394 			TAspTaskItem& task = iContentList->TaskItem(index);
       
   395 			TInt status = iContentList->CheckMandatoryTaskDataL(task.iTaskId);
       
   396 	        if (status == EMandatoryOk)
       
   397 			    {
       
   398 			    secondLine = CAspResHandler::ReadLC(R_ASP_DEFINED);
       
   399                 if (task.iSyncDirection == ESyncDirectionTwoWay)
       
   400 				    {
       
   401 				    iconIndex = EIconBothDirections;
       
   402 				    }
       
   403 			    if (task.iSyncDirection == ESyncDirectionOneWayFromDevice)
       
   404 				    {
       
   405 				    iconIndex = EIconDeviceToServer;
       
   406 				    }
       
   407 			    if (task.iSyncDirection == ESyncDirectionOneWayIntoDevice)
       
   408 				    {
       
   409 				    iconIndex = EIconServerToDevice;
       
   410 				    }
       
   411 			    }
       
   412 			else
       
   413 				{
       
   414 				secondLine = CAspResHandler::ReadLC(R_ASP_NOT_DEFINED);
       
   415 				}
       
   416 			}
       
   417 		else
       
   418 			{
       
   419 			secondLine = CAspResHandler::ReadLC(R_ASP_NOT_DEFINED);
       
   420 			}
       
   421 		
       
   422 		TPtr ptr1 = firstLine->Des();
       
   423 		AknTextUtils::DisplayTextLanguageSpecificNumberConversion(ptr1);
       
   424 		TPtr ptr2 = secondLine->Des();
       
   425         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(ptr2);
       
   426 
       
   427 		HBufC* hBuf = NULL;
       
   428 		hBuf = TDialogUtil::ConstructListBoxItemLC(firstLine->Des(), secondLine->Des(), iconIndex);
       
   429 
       
   430 		items->AppendL(hBuf->Des());
       
   431 		
       
   432 		CleanupStack::PopAndDestroy(hBuf);
       
   433 		CleanupStack::PopAndDestroy(secondLine);
       
   434 		CleanupStack::PopAndDestroy(firstLine);
       
   435 		}
       
   436 
       
   437 	listBox->HandleItemAdditionL();
       
   438 
       
   439 	if (listBox->Model()->NumberOfItems() == 0)
       
   440 		{
       
   441 		User::Leave(KErrNotFound);
       
   442 		}
       
   443 	}
       
   444 
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CAspContentListDialog::ShowContentL
       
   448 //
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 void CAspContentListDialog::ShowContentL()
       
   452 	{
       
   453  	TAspParam param(iApplicationId, iSyncSession);
       
   454     param.iProfile = iProfile;
       
   455     param.iDataProviderId = SelectedProvider().iDataProviderId;
       
   456     param.iSyncTaskId = KErrNotFound;
       
   457 
       
   458     CAspContentDialog::ShowDialogL(param);
       
   459      
       
   460     iContentList->InitAllTasksL();
       
   461     
       
   462 	UpdateListBoxL();
       
   463 	}
       
   464 
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // CAspContentListDialog::ListBox
       
   468 //
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 CAknDoubleLargeStyleListBox* CAspContentListDialog::ListBox()
       
   472 	{
       
   473 	__ASSERT_DEBUG(iSettingListBox, TUtil::Panic(KErrGeneral));
       
   474 
       
   475 	return iSettingListBox;
       
   476 	}
       
   477 
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CAspContentListDialog::SelectedProvider
       
   481 //
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 TAspProviderItem& CAspContentListDialog::SelectedProvider()
       
   485 	{
       
   486 	TInt index = ListBox()->CurrentItemIndex();
       
   487 
       
   488 	return iContentList->ProviderItem(index);
       
   489 	}
       
   490 
       
   491 
       
   492 
       
   493 //  End of File