emailuis/emailui/src/FreestyleEmailUiGlobalSettingsList.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Freestyle Email source file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include "emailtrace.h"
       
    21 #include <avkon.hrh>
       
    22 #include <avkon.rsg>
       
    23 #include <eikmenup.h>
       
    24 #include <aknappui.h>
       
    25 #include <eikcmobs.h>
       
    26 #include <barsread.h>
       
    27 #include <StringLoader.h>
       
    28 #include <AknPopupFieldText.h>
       
    29 #include <eikenv.h>
       
    30 #include <eikappui.h>
       
    31 #include <aknViewAppUi.h>
       
    32 #include <apgcli.h>
       
    33 #include <FreestyleEmailUi.rsg>
       
    34 
       
    35 // LOCAL INCLUDES
       
    36 #include "FreestyleEmailUiGlobalSettingsData.h"
       
    37 #include "FreestyleEmailUiGlobalSettings.hrh"
       
    38 #include "FreestyleEmailUiGlobalSettingsListView.h"
       
    39 #include "FreestyleEmailUiGlobalSettingsList.h"
       
    40 #include "FreestyleEmailUiAppui.h"
       
    41 #include "FreestyleEmailCenRepHandler.h"
       
    42 #include "FreestyleEmailUiShortcutBinding.h"
       
    43 #include "FreestyleEmailUiConstants.h"
       
    44 
       
    45 /**
       
    46  * Constructor
       
    47  * @param aCommandObserver command observer
       
    48  */ 
       
    49 CFsEmailUiGlobalSettingsList::CFsEmailUiGlobalSettingsList( 
       
    50 		CFsEmailUiGlobalSettingsData& aSettings, 
       
    51 		MEikCommandObserver* aCommandObserver )
       
    52 	: iSettings( aSettings ), iCommandObserver( aCommandObserver )
       
    53 	{
       
    54     FUNC_LOG;
       
    55 	}
       
    56 
       
    57 /** 
       
    58  * Destructor
       
    59  * Destroy any instance variables
       
    60  */
       
    61 CFsEmailUiGlobalSettingsList::~CFsEmailUiGlobalSettingsList()
       
    62 	{
       
    63     FUNC_LOG;
       
    64 	}
       
    65 
       
    66 /**
       
    67  * Handle system notification that the container's size has changed.
       
    68  */
       
    69 void CFsEmailUiGlobalSettingsList::SizeChanged()
       
    70 	{
       
    71     FUNC_LOG;
       
    72 
       
    73 	if ( ListBox() ) 
       
    74 		{
       
    75 		ListBox()->SetRect( Rect() );
       
    76 		}
       
    77 
       
    78 	}
       
    79 
       
    80 /**
       
    81  * Create one setting item at a time, identified by id.
       
    82  * CAknSettingItemList calls this method and takes ownership
       
    83  * of the returned value.  The CAknSettingItem object owns
       
    84  * a reference to the underlying data, which EditItemL() uses
       
    85  * to edit and store the value.
       
    86  */
       
    87 CAknSettingItem* CFsEmailUiGlobalSettingsList::CreateSettingItemL( TInt aId )
       
    88 	{
       
    89     FUNC_LOG;
       
    90 
       
    91 	switch ( aId )
       
    92 		{
       
    93 		case EGlobalSettingsTitleDividers:
       
    94 			{
       
    95 			CAknBinaryPopupSettingItem* item = new ( ELeave ) 
       
    96 				CAknBinaryPopupSettingItem( 
       
    97 					aId,
       
    98 					iSettings.TitleDividers() );
       
    99 			return item;
       
   100 			}
       
   101 		case EGlobalSettingsDownloadNotifications:
       
   102 			{			
       
   103 			CAknBinaryPopupSettingItem* item = new ( ELeave ) 
       
   104 				CAknBinaryPopupSettingItem( 
       
   105 					aId,
       
   106 					iSettings.DownloadNotifications() );
       
   107 			return item;
       
   108 			}
       
   109 		case EGlobalSettingsWarnBeforeDelete:
       
   110 		    {         
       
   111 		    CAknBinaryPopupSettingItem* item = new ( ELeave ) 
       
   112 		        CAknBinaryPopupSettingItem( 
       
   113                     aId,
       
   114                     iSettings.WarnBeforeDelete() );
       
   115             return item;
       
   116             }/*
       
   117 		case EGlobalSettingsDownloadHTMLImages:
       
   118             {         
       
   119             CAknBinaryPopupSettingItem* item = new ( ELeave ) 
       
   120                 CAknBinaryPopupSettingItem( 
       
   121                     aId,
       
   122                     iSettings.DownloadHTMLImages() );
       
   123             return item;
       
   124             }*/
       
   125         case EGlobalSettingsActiveIdle:
       
   126             {           
       
   127             CAknBigSettingItemBase* item = new ( ELeave )
       
   128                 CAknBigSettingItemBase( aId );
       
   129             TBool hideHsSetting = !IsHsModesAppAvailable(); // handling other HS types to be added later
       
   130             item->SetHidden( hideHsSetting );
       
   131             return item;
       
   132             }
       
   133 		}
       
   134 		
       
   135 	return NULL;
       
   136 	}
       
   137 	
       
   138 /**
       
   139  * Edit the setting item identified by the given id and store
       
   140  * the changes into the store.
       
   141  * @param aIndex the index of the setting item in SettingItemArray()
       
   142  * @param aCalledFromMenu true: a menu item invoked editing, thus
       
   143  *	always show the edit page and interactively edit the item;
       
   144  *	false: change the item in place if possible, else show the edit page
       
   145  */
       
   146 void CFsEmailUiGlobalSettingsList::EditItemL ( TInt aIndex, TBool aCalledFromMenu )
       
   147     {
       
   148     FUNC_LOG;
       
   149 
       
   150     CAknSettingItem* item = ( *SettingItemArray() )[aIndex];
       
   151     CAknSettingItemList::EditItemL( aIndex, aCalledFromMenu );	
       
   152 
       
   153     item->StoreL();
       
   154     SaveSettingValuesL();
       
   155     }
       
   156 
       
   157 /**
       
   158  * Handle the "Change" option on the Options menu or on the MSK.
       
   159  * The argument tells which one is the case.
       
   160  */
       
   161 void CFsEmailUiGlobalSettingsList::ChangeSelectedItemL( TBool aCalledFromMenu )
       
   162 	{
       
   163     FUNC_LOG;
       
   164 
       
   165   	TInt idx = ListBox()->CurrentItemIndex(); 
       
   166 	if ( idx >= 0 )
       
   167 		{
       
   168 		CAknSettingItem* item = ( *SettingItemArray() )[idx];
       
   169 		    
       
   170 		if ( item->Identifier() == EGlobalSettingsActiveIdle )
       
   171 		    {
       
   172 		    if ( IsHsModesAppAvailable() )
       
   173 		        {
       
   174 		        ActivateHsModesEmailViewL();
       
   175 		        }
       
   176 		    else
       
   177 		        {
       
   178 		        // opening of Email widget settings or settings of non-Eseries
       
   179 		        // S60 3.2 home screen plugin to be added here later
       
   180 		        }
       
   181 		    }
       
   182 		else
       
   183 		    {
       
   184 	        EditItemL( idx, aCalledFromMenu );
       
   185 		    }
       
   186 		}
       
   187 	}
       
   188 
       
   189 /**
       
   190  *	Load the initial contents of the setting items.  By default,
       
   191  *	the setting items are populated with the default values from
       
   192  * 	the design.  You can override those values here.
       
   193  *	
       
   194  */
       
   195 void CFsEmailUiGlobalSettingsList::LoadSettingValuesL()
       
   196 	{
       
   197     FUNC_LOG;
       
   198 
       
   199 	CFSEmailCRHandler *crHandler = CFSEmailCRHandler::InstanceL();
       
   200 	
       
   201     // Layout setting item has values 1 (1 line) and 0 (2 lines) because no other values are allowed in binary items.
       
   202     // CenRep, on the other hand, uses values 1 (1 line) and 2 (2 lines).
       
   203 	iSettings.SetMessageListLayout( crHandler->MessageListLayout() == 1 ? 1 : 0 );
       
   204 	
       
   205 	iSettings.SetBodyPreview( crHandler->BodyPreview() );
       
   206 	iSettings.SetTitleDividers( crHandler->TitleDividers() );
       
   207 	iSettings.SetDownloadNotifications( crHandler->DownloadNotifications() );
       
   208 	iSettings.SetActiveIdle( crHandler->ActiveIdle() );
       
   209 	iSettings.SetWarnBeforeDelete( crHandler->WarnBeforeDelete() );
       
   210 	//iSettings.SetDownloadHTMLImages( crHandler->DownloadHTMLImages() );
       
   211 	}
       
   212 	
       
   213 /**
       
   214  *	Save the contents of the setting items.  Note, this is called
       
   215  *	whenever an item is changed and stored to the model, so it
       
   216  *	may be called multiple times or not at all.
       
   217  */
       
   218 void CFsEmailUiGlobalSettingsList::SaveSettingValuesL()
       
   219 	{
       
   220     FUNC_LOG;
       
   221 
       
   222 	CFSEmailCRHandler *crHandler = CFSEmailCRHandler::InstanceL();
       
   223 	
       
   224 	// Layout setting item has values 1 (1 line) and 0 (2 lines) because no other values are allowed in binary items.
       
   225 	// CenRep, on the other hand, uses values 1 (1 line) and 2 (2 lines).
       
   226 	crHandler->SetMessageListLayout( iSettings.MessageListLayout() ? 1 : 2 );
       
   227 	
       
   228 	crHandler->SetBodyPreview( iSettings.BodyPreview() );
       
   229 	crHandler->SetTitleDividers( iSettings.TitleDividers() );
       
   230 	crHandler->SetDownloadNotifications( iSettings.DownloadNotifications() );
       
   231 	crHandler->SetActiveIdle( iSettings.ActiveIdle() );
       
   232 	crHandler->SetWarnBeforeDelete( iSettings.WarnBeforeDelete() );
       
   233 	//crHandler->SetDownloadHTMLImages( iSettings.DownloadHTMLImages() );
       
   234 	}
       
   235 
       
   236 /**
       
   237  * Get ID of the focused setting list item
       
   238  */
       
   239 TInt CFsEmailUiGlobalSettingsList::FocusedItemId()
       
   240     {
       
   241     FUNC_LOG;
       
   242     TInt id = KErrNotFound;
       
   243     
       
   244     if ( ListBox() && SettingItemArray() )
       
   245         {
       
   246         TInt curIdx = ListBox()->CurrentItemIndex();
       
   247         CAknSettingItem* item = ( *SettingItemArray() )[curIdx];
       
   248         id = item->Identifier();
       
   249         }
       
   250     
       
   251     return id;
       
   252     }
       
   253 
       
   254 /** 
       
   255  * Handle global resource changes, such as scalable UI or skin events (override)
       
   256  */
       
   257 void CFsEmailUiGlobalSettingsList::HandleResourceChange( TInt aType )
       
   258 	{
       
   259     FUNC_LOG;
       
   260 
       
   261 	CAknSettingItemList::HandleResourceChange( aType );
       
   262 	SetRect( iAvkonViewAppUi->View( GlobalSettingsViewId )->ClientRect() );
       
   263 
       
   264 	}
       
   265 				
       
   266 /** 
       
   267  * Handle key event (override)
       
   268  * @param aKeyEvent key event
       
   269  * @param aType event code
       
   270  * @return EKeyWasConsumed if the event was handled, else EKeyWasNotConsumed
       
   271  */
       
   272 TKeyResponse CFsEmailUiGlobalSettingsList::OfferKeyEventL( 
       
   273 		const TKeyEvent& aKeyEvent, 
       
   274 		TEventCode aType )
       
   275 	{
       
   276     FUNC_LOG;
       
   277   	TKeyResponse retVal = EKeyWasNotConsumed;
       
   278 
       
   279     // Check keyboard shortcuts.
       
   280     if ( aType == EEventKey )
       
   281         {
       
   282         CFreestyleEmailUiAppUi* appUi = static_cast<CFreestyleEmailUiAppUi*>(iAvkonViewAppUi);
       
   283         TInt shortcutCommand = 
       
   284             appUi->ShortcutBinding().CommandForShortcutKey( aKeyEvent,
       
   285                                                             CFSEmailUiShortcutBinding::EContextSettings );
       
   286         if ( shortcutCommand != KErrNotFound )
       
   287             {
       
   288             appUi->View( GlobalSettingsViewId )->HandleCommandL( shortcutCommand );
       
   289             retVal = EKeyWasConsumed;
       
   290             }
       
   291         }
       
   292 
       
   293     if ( retVal == EKeyWasNotConsumed )
       
   294         {
       
   295         retVal = CAknSettingItemList::OfferKeyEventL( aKeyEvent, aType );
       
   296         }
       
   297     
       
   298     // Update MSK label after key has been consumed
       
   299     if ( retVal == EKeyWasConsumed )
       
   300         {
       
   301         CFsEmailUiGlobalSettingsListView* view =
       
   302             static_cast<CFsEmailUiGlobalSettingsListView*>( 
       
   303                     iAvkonViewAppUi->View(GlobalSettingsViewId) );
       
   304         view->SetMskL();
       
   305         }
       
   306     
       
   307 	return retVal; 
       
   308 	}
       
   309 	
       
   310 // ---------------------------------------------------------------------------
       
   311 // Move list focus to top
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CFsEmailUiGlobalSettingsList::GoToTop()
       
   315     {
       
   316     FUNC_LOG;
       
   317     TInt count = ListBox()->Model()->NumberOfItems();
       
   318     if ( count )
       
   319         {
       
   320         ListBox()->SetCurrentItemIndexAndDraw( 0 );
       
   321         }
       
   322     }
       
   323     
       
   324 // ---------------------------------------------------------------------------
       
   325 // Move list focus to bottom
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CFsEmailUiGlobalSettingsList::GoToBottom()
       
   329     {
       
   330     FUNC_LOG;
       
   331     TInt count = ListBox()->Model()->NumberOfItems();
       
   332     if ( count )
       
   333         {
       
   334         ListBox()->SetCurrentItemIndexAndDraw( count-1 );
       
   335         }
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // Move selector one page up
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CFsEmailUiGlobalSettingsList::PageUp()
       
   343     {
       
   344     FUNC_LOG;
       
   345     TInt itemsOnPage = ListBox()->BottomItemIndex() - ListBox()->TopItemIndex();
       
   346     TInt currentIdx = ListBox()->CurrentItemIndex();
       
   347     TInt newIdx = Max( 0, currentIdx - itemsOnPage );
       
   348     ListBox()->SetCurrentItemIndexAndDraw( newIdx );
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // Move selector one page down
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CFsEmailUiGlobalSettingsList::PageDown()
       
   356     {
       
   357     FUNC_LOG;
       
   358     TInt count = ListBox()->Model()->NumberOfItems();
       
   359     TInt itemsOnPage = ListBox()->BottomItemIndex() - ListBox()->TopItemIndex();
       
   360     TInt currentIdx = ListBox()->CurrentItemIndex();
       
   361     TInt newIdx = Min( count-1, currentIdx + itemsOnPage );
       
   362     ListBox()->SetCurrentItemIndexAndDraw( newIdx );
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // Checks if the Homescreen Modes application is available on the device
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 TBool CFsEmailUiGlobalSettingsList::IsHsModesAppAvailable() const
       
   370     {
       
   371     FUNC_LOG;
       
   372     TBool available = EFalse;
       
   373     RApaLsSession apaSession;
       
   374     TInt err = apaSession.Connect();
       
   375     if ( !err )
       
   376         {
       
   377         TApaAppInfo appInfo;
       
   378         err = apaSession.GetAppInfo( appInfo, KHsModesAppUid );
       
   379         apaSession.Close();
       
   380         if ( !err )
       
   381             {
       
   382             available = ETrue;
       
   383             }
       
   384         }
       
   385     return available;
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // Activates the email view of the Homescreen Modes application
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CFsEmailUiGlobalSettingsList::ActivateHsModesEmailViewL()
       
   393     {
       
   394     FUNC_LOG;
       
   395     const TVwsViewId KModesEmailView( KHsModesAppUid, KHsModesPrimaryEmailViewId );
       
   396     iAvkonViewAppUi->ActivateViewL( KModesEmailView );
       
   397     }
       
   398