idlehomescreen/widgetmanager/src/wmmaincontainer.cpp
changeset 2 08c6ee43b396
parent 1 5315654608de
child 4 4d54b72983ae
equal deleted inserted replaced
1:5315654608de 2:08c6ee43b396
    34 #include <layoutmetadata.cdl.h>
    34 #include <layoutmetadata.cdl.h>
    35 #include <aknlayoutscalable_avkon.cdl.h>
    35 #include <aknlayoutscalable_avkon.cdl.h>
    36 #include <aknlayoutscalable_apps.cdl.h>
    36 #include <aknlayoutscalable_apps.cdl.h>
    37 #include <AknLayout.lag>
    37 #include <AknLayout.lag>
    38 #include <AknsSkinInstance.h>
    38 #include <AknsSkinInstance.h>
    39 #include <apgicnfl.h>
       
    40 #include <AknIconUtils.h>
    39 #include <AknIconUtils.h>
    41 #include <AknsDrawUtils.h>
    40 #include <AknsDrawUtils.h>
    42 #include <aknenv.h>
    41 #include <aknenv.h>
    43 #include <aknlists.h>
    42 #include <aknlists.h>
    44 #include <eikclbd.h>
    43 #include <eikclbd.h>
    47 #include <apgcli.h>
    46 #include <apgcli.h>
    48 #include <widgetmanager.mbg>
    47 #include <widgetmanager.mbg>
    49 #include <avkon.rsg>
    48 #include <avkon.rsg>
    50 #include <coecobs.h>
    49 #include <coecobs.h>
    51 #include <coecntrl.h>
    50 #include <coecntrl.h>
    52 #include <SWInstApi.h> //installer
       
    53 #include <widgetregistryclient.h> // widgetreqistry
       
    54 #include <schemehandler.h> // for starting the OVI client
       
    55 #include <featmgr.h>     // FeatureManager
    51 #include <featmgr.h>     // FeatureManager
    56 #include <hlplch.h>      // HlpLauncher
    52 #include <hlplch.h>      // HlpLauncher
    57 #include <csxhelp/hmsc.hlp.hrh>
    53 #include <csxhelp/hmsc.hlp.hrh>
    58 #include <aisystemuids.hrh>
    54 #include <aisystemuids.hrh>
    59 #include <centralrepository.h>
    55 
    60 
       
    61 #include "wmcrkeys.h"
       
    62 #include "wmcommon.h"
    56 #include "wmcommon.h"
    63 #include "wmplugin.h"
    57 #include "wmplugin.h"
    64 #include "wmmaincontainer.h"
    58 #include "wmmaincontainer.h"
    65 #include "wmmaincontainerview.h"
    59 #include "wmmaincontainerview.h"
    66 #include "wmresourceloader.h"
    60 #include "wmresourceloader.h"
    68 #include "wmlistbox.h"
    62 #include "wmlistbox.h"
    69 #include "wmpersistentwidgetorder.h"
    63 #include "wmpersistentwidgetorder.h"
    70 #include "wmdetailsdlg.h"
    64 #include "wmdetailsdlg.h"
    71 #include "wmportalbutton.h"
    65 #include "wmportalbutton.h"
    72 #include "wmwidgetloaderao.h"
    66 #include "wmwidgetloaderao.h"
       
    67 #include "wmconfiguration.h"
    73 
    68 
    74 // CONSTANTS
    69 // CONSTANTS
    75 const TInt KTextLimit = 40; // Text-limit for find-field
    70 const TInt KTextLimit = 40; // Text-limit for find-field
    76 const TInt KMinWidgets = 1; // minimum number of widgets to show findpane
    71 const TInt KMinWidgets = 1; // minimum number of widgets to show findpane
    77 _LIT8( KWrtMime, "application/x-nokia-widget");
       
    78 _LIT( KBrowserPrefix, "4 ");
       
    79 
    72 
    80 // ---------------------------------------------------------
    73 // ---------------------------------------------------------
    81 // CWmMainContainer::CWmMainContainer()
    74 // CWmMainContainer::CWmMainContainer()
    82 // ---------------------------------------------------------
    75 // ---------------------------------------------------------
    83 //
    76 //
    96 // CWmMainContainer::~CWmMainContainer()
    89 // CWmMainContainer::~CWmMainContainer()
    97 // ---------------------------------------------------------
    90 // ---------------------------------------------------------
    98 //
    91 //
    99 CWmMainContainer::~CWmMainContainer()
    92 CWmMainContainer::~CWmMainContainer()
   100 	{
    93 	{
   101     delete iOviStoreUrl;
       
   102     delete iOviStoreClientBundleId;
       
   103     delete iOviStoreClientParam;
       
   104         
       
   105     RemoveCtrlsFromStack();
    94     RemoveCtrlsFromStack();
   106     Components().ResetAndDestroy();
    95     Components().ResetAndDestroy();
   107     delete iWidgetLoader;
    96     delete iWidgetLoader;
   108     iWidgetsList = NULL;
    97     iWidgetsList = NULL;
   109     iOviPortal = NULL;
    98     iPortalButtonOne = NULL;
       
    99     iPortalButtonTwo = NULL;
   110     iFindbox = NULL;
   100     iFindbox = NULL;
   111 	delete iBgContext;
   101 	delete iBgContext;
       
   102 	delete iConfiguration;
   112 	}
   103 	}
   113 
   104 
   114 // ---------------------------------------------------------
   105 // ---------------------------------------------------------
   115 // CWmMainContainer::NewL
   106 // CWmMainContainer::NewL
   116 // ---------------------------------------------------------
   107 // ---------------------------------------------------------
   174 
   165 
   175 	// background context
   166 	// background context
   176 	iBgContext = CAknsBasicBackgroundControlContext::NewL( 
   167 	iBgContext = CAknsBasicBackgroundControlContext::NewL( 
   177 	        KAknsIIDQsnBgScreen, ScreenRect() , ETrue);
   168 	        KAknsIIDQsnBgScreen, ScreenRect() , ETrue);
   178 
   169 
   179 	// Read needed values from cenrep
   170     // load configuration
   180 	TRAP_IGNORE( FetchRepositoryDataL(); );
   171     iConfiguration = CWmConfiguration::NewL( iWmPlugin.ResourceLoader() );
   181 	
   172     
   182 	// set up controls
   173 	// set up controls
   183 	InitializeControlsL( aRect );
   174 	InitializeControlsL( aRect );
   184 
   175 
   185 	// set size and activate
   176 	// set size and activate
   186 	SetRect( aRect );
   177 	SetRect( aRect );
   187     ActivateL();
   178     ActivateL();
   188 	
   179 	
   189 	}
   180 	}
   190 
   181 
   191 // ---------------------------------------------------------
       
   192 // CWmMainContainer::FetchRepositoryDataL
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 void CWmMainContainer::FetchRepositoryDataL()
       
   196     {
       
   197     iOviStoreUrl = NULL;
       
   198     iOviStoreClientBundleId = NULL;
       
   199     iOviStoreClientParam = NULL;
       
   200     
       
   201     CRepository *repository = CRepository::NewLC( 
       
   202             TUid::Uid( KCrWidgetManagerm ) );
       
   203     TInt err = KErrNone;
       
   204     
       
   205     //read localized data from cenrep
       
   206     TLanguage sysLang = User::Language();
       
   207     for( TUint32 i = KLangId0; i <= KLangId9; i+=4 )
       
   208         {
       
   209         TInt crLang = 0;
       
   210         err = repository->Get( i, crLang );
       
   211 
       
   212         if ( sysLang == crLang && err == KErrNone )
       
   213             {
       
   214             // system langauge matches langauge in cenrep
       
   215             iOviStoreUrl = HBufC::NewL( 
       
   216                     NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   217             TPtr ptr( iOviStoreUrl->Des() );
       
   218             
       
   219             // get localized ovi store url
       
   220             err = repository->Get( i + KOviStoreBrowserUrlOffset, ptr );
       
   221             if ( err != KErrNone )
       
   222                 {
       
   223                 delete iOviStoreUrl;
       
   224                 iOviStoreUrl = NULL;
       
   225                 }
       
   226             }
       
   227         }
       
   228     
       
   229     //read other data from cenrep
       
   230     iOviStoreClientBundleId = HBufC::NewL( 
       
   231             NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   232     TPtr ptr( iOviStoreClientBundleId->Des() );
       
   233     err = repository->Get( KOviStoreBunbleId, ptr );
       
   234     if ( err != KErrNone )
       
   235         {
       
   236         delete iOviStoreClientBundleId;
       
   237         iOviStoreClientBundleId = NULL;
       
   238         }
       
   239     
       
   240     iOviStoreClientParam = HBufC::NewL( 
       
   241             NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   242     ptr.Set( iOviStoreClientParam->Des() );
       
   243     err = repository->Get( KOviStoreClientParam, ptr );
       
   244     if ( err != KErrNone )
       
   245         {
       
   246         delete iOviStoreClientParam;
       
   247         iOviStoreClientParam = NULL;
       
   248         }
       
   249         
       
   250     CleanupStack::PopAndDestroy( repository );
       
   251     }
       
   252 	
       
   253 // ---------------------------------------------------------
   182 // ---------------------------------------------------------
   254 // CWmMainContainer::SizeChanged
   183 // CWmMainContainer::SizeChanged
   255 // ---------------------------------------------------------
   184 // ---------------------------------------------------------
   256 //
   185 //
   257 void CWmMainContainer::SizeChanged()
   186 void CWmMainContainer::SizeChanged()
   291 	else
   220 	else
   292 	    {
   221 	    {
   293         iLayout = EPortrait;
   222         iLayout = EPortrait;
   294 	    }
   223 	    }
   295 	
   224 	
   296     // layout Ovi button
   225     // portal button layout
   297     AknLayoutUtils::LayoutControl( iOviPortal, rect, btnPane );
   226 	// todo: 2-button layout
       
   227     AknLayoutUtils::LayoutControl( iPortalButtonOne, rect, btnPane );
   298     
   228     
   299     if( iFindbox && iFindPaneIsVisible )
   229     if( iFindbox && iFindPaneIsVisible )
   300         {
   230         {
   301 		TAknLayoutRect layoutRect;
   231 		TAknLayoutRect layoutRect;
   302         layoutRect.LayoutRect( rect, listPane );
   232         layoutRect.LayoutRect( rect, listPane );
   314 // ---------------------------------------------------------
   244 // ---------------------------------------------------------
   315 // CWmMainContainer::OfferKeyEventL
   245 // CWmMainContainer::OfferKeyEventL
   316 // ---------------------------------------------------------
   246 // ---------------------------------------------------------
   317 //
   247 //
   318 TKeyResponse CWmMainContainer::OfferKeyEventL( 
   248 TKeyResponse CWmMainContainer::OfferKeyEventL( 
   319 		const TKeyEvent& aKeyEvent, 
   249         const TKeyEvent& aKeyEvent, 
   320 		TEventCode aType )
   250         TEventCode aType )
   321 	{
   251     {
   322     TKeyResponse keyResponse( EKeyWasNotConsumed );
   252     TKeyResponse keyResponse( EKeyWasNotConsumed );
   323     
   253 
   324     if ( iFindbox )
   254     // This is a bug fix for ou1cimx1#217716 & ou1cimx1#217667.
   325         {
   255     // For some weird reason homescreen is genarating one extra EEventKey 
   326         // open search field with alpha digit numbers
   256     // when using Nokia SU-8W bluetooth keyboard & backspace key. This if is to 
   327         if ( aType == EEventKeyDown && !iFindPaneIsVisible && 
   257     // ignore that event. Extra event allways has iModifiers set to 
   328         aKeyEvent.iScanCode < EStdKeyF1 &&
   258     // EModifierAutorepeatable.
   329             TChar(aKeyEvent.iScanCode).IsAlphaDigit() )
   259     if ( aType == EEventKey && 
   330             {
   260              aKeyEvent.iScanCode == EStdKeyBackspace && 
   331             ActivateFindPaneL();
   261              aKeyEvent.iModifiers == EModifierAutorepeatable )
   332             
   262         {
   333             if ( iFindPaneIsVisible )
   263         return EKeyWasNotConsumed;
   334                 {
   264         }
   335                 return EKeyWasConsumed;
   265     
   336                 }
   266     // Handle search keyevent
   337             }
   267     keyResponse = HandleSearchKeyEventL( aKeyEvent, aType );
       
   268     
       
   269     // Move focus between controls
       
   270     if ( keyResponse == EKeyWasNotConsumed )
       
   271         {
       
   272         keyResponse = MoveFocusByKeys( aKeyEvent, aType );
       
   273         }
       
   274     
       
   275     // Handle list keyevent
       
   276     if ( keyResponse == EKeyWasNotConsumed )
       
   277         {
       
   278         keyResponse = HandleListKeyEventL( aKeyEvent, aType );
       
   279         }
       
   280     
       
   281     // Handle buttons keyevent
       
   282     if ( keyResponse == EKeyWasNotConsumed )
       
   283         {
       
   284         keyResponse = HandleButtonKeyEventL( aKeyEvent, aType );
       
   285         }
       
   286     
       
   287     // Update ui if needed 
       
   288     if ( keyResponse == EKeyWasConsumed )
       
   289         {
       
   290         DrawDeferred();
       
   291         }
       
   292     
       
   293     // Do not let UI framework forward the keys to child controls as
       
   294     // we have already done that.
       
   295     return EKeyWasConsumed;
       
   296     }
       
   297 
       
   298 TKeyResponse CWmMainContainer::HandleSearchKeyEventL( 
       
   299         const TKeyEvent& aKeyEvent, 
       
   300         TEventCode aType )
       
   301     {
       
   302     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   303     
       
   304     // open search field with alpha digit numbers
       
   305     if ( aType == EEventKeyDown && !iFindPaneIsVisible && 
       
   306             aKeyEvent.iScanCode < EStdKeyF1 &&
       
   307         TChar( aKeyEvent.iScanCode ).IsAlphaDigit() )
       
   308         {
       
   309         ActivateFindPaneL();
   338         
   310         
   339         if ( iFindPaneIsVisible )
   311         if ( iFindPaneIsVisible )
   340             {
   312             {
   341             // deactive the FindPane when Back has been pressed
   313             return EKeyWasConsumed;
   342             if ( aType == EEventKeyDown && 
   314             }
   343                 aKeyEvent.iScanCode == EStdKeyBackspace )
   315         }
   344                 {
   316     
   345                 TBuf<KTextLimit> searchText;
   317     if ( iFindPaneIsVisible && aType == EEventKey )
   346                 iFindbox->GetSearchText( searchText );
   318         {
   347                 if ( searchText == KNullDesC )
   319         if ( aKeyEvent.iScanCode == EStdKeyNo || aKeyEvent.iCode == EKeyNo )
   348                     {
   320             {
   349                     DeactivateFindPaneL();
   321             DeactivateFindPaneL();
   350                     return EKeyWasConsumed;
   322             return EKeyWasConsumed;
   351                     }
   323             }
   352                 }
   324         
   353             
   325         TBool needsRefresh( EFalse );
   354             // Cancel-selected need to unfocus findbox 
   326        
   355             // to receive event in ProcessCommand
   327         if ( iFindbox->TextLength() == 0 
   356             if ( aType == EEventKeyDown 
   328                 && aKeyEvent.iScanCode == EStdKeyBackspace )
   357             && aKeyEvent.iScanCode == EStdKeyDevice1 )
   329             {
   358                 {
   330             // if lenght is 0 and backspace is pressed AknFind will deactivate
   359                 iFindbox->SetFocus( EFalse );
   331             // searchbox so we don't want to pass this event to AknFind
   360                 UpdateFocusMode();
   332             keyResponse = EKeyWasConsumed;
   361                 return EKeyWasConsumed;
   333             }
   362                 }
   334         else
   363 
   335             {
   364             if ( aKeyEvent.iScanCode == EStdKeyNo ||
       
   365                 aKeyEvent.iCode == EKeyNo )
       
   366                 {
       
   367                 DeactivateFindPaneL();
       
   368                 return EKeyWasConsumed;
       
   369                 }
       
   370 
       
   371             // find items with all event codes (that's the reason why there is EEventKey instead of aType)
       
   372             TBool needsRefresh( EFalse );
       
   373             keyResponse = AknFind::HandleFindOfferKeyEventL( 
   336             keyResponse = AknFind::HandleFindOfferKeyEventL( 
   374                                                 aKeyEvent, EEventKey, this, 
   337                     aKeyEvent, aType, this, 
   375                                 iWidgetsList, iFindbox, ETrue, needsRefresh );            
   338                     iWidgetsList, iFindbox, ETrue, needsRefresh );
   376             if ( needsRefresh )
   339             }
   377                 {
   340         if ( needsRefresh )
   378                 DrawNow();
   341             {
   379                 }
   342             DrawNow();
   380             }
   343             }
   381         }
   344         }
   382 
   345 
   383     // check special cases for movement between controls
   346     return keyResponse;
   384     if ( keyResponse == EKeyWasNotConsumed && !iFindPaneIsVisible )
   347     }
   385          {
   348 
   386          keyResponse = MoveFocusByKeys( aKeyEvent, aType );
   349 TKeyResponse CWmMainContainer::HandleListKeyEventL( 
   387          }
   350         const TKeyEvent& aKeyEvent, 
   388 
   351         TEventCode aType )
       
   352     {
       
   353     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   354     
   389     // pass key event except backpace or delete key event to widgets list if focused
   355     // pass key event except backpace or delete key event to widgets list if focused
   390     if ( keyResponse == EKeyWasNotConsumed && iWidgetsList->IsFocused() )
   356     if ( iWidgetsList->IsFocused() )
   391         {
   357         {
   392         if ( (aType == EEventKey) && (aKeyEvent.iCode == EKeyBackspace || aKeyEvent.iCode == EKeyDelete))
   358         if ( ( aType == EEventKey ) && ( aKeyEvent.iCode == EKeyBackspace 
       
   359                 || aKeyEvent.iCode == EKeyDelete ) )
   393             {
   360             {
   394             if( CanDoUninstall() )
   361             if( CanDoUninstall() )
   395                 {
   362                 {
   396                 UninstallWidgetL();
   363                 UninstallWidgetL();
   397                 }
   364                 }
   400                 CWmWidgetData* data = iWidgetsList->WidgetData();
   367                 CWmWidgetData* data = iWidgetsList->WidgetData();
   401                 if( data != NULL )
   368                 if( data != NULL )
   402                     iWmPlugin.ResourceLoader().InfoPopupL(
   369                     iWmPlugin.ResourceLoader().InfoPopupL(
   403                          R_QTN_WM_UNINST_NOT_ALLOWED, data->Name() );
   370                          R_QTN_WM_UNINST_NOT_ALLOWED, data->Name() );
   404                 }
   371                 }
       
   372             keyResponse = EKeyWasConsumed;
   405             }
   373             }
   406         else 
   374         else 
   407             {
   375             {
   408 			//passing to listbox handler
   376             //passing to listbox handler
   409             keyResponse = iWidgetsList->OfferKeyEventL( 
   377             keyResponse = iWidgetsList->OfferKeyEventL( 
   410                     aKeyEvent, aType );
   378                     aKeyEvent, aType );
   411             }
   379             }
   412         }
   380         }
   413 
   381     
   414     // pass key event to OVI portal if focused
   382     return keyResponse;
   415     if ( keyResponse == EKeyWasNotConsumed && iOviPortal->IsFocused() )
   383     }
   416         {
   384 
   417         keyResponse = iOviPortal->OfferKeyEventL( 
   385 TKeyResponse CWmMainContainer::HandleButtonKeyEventL( 
       
   386         const TKeyEvent& aKeyEvent, 
       
   387         TEventCode aType )
       
   388     {
       
   389     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   390     
       
   391     // pass key event to portal button if focused
       
   392     if ( iPortalButtonOne->IsFocused() )
       
   393         {
       
   394         keyResponse = iPortalButtonOne->OfferKeyEventL(
   418                             aKeyEvent, aType );
   395                             aKeyEvent, aType );
   419         }
   396         }
   420 
   397 
   421     if ( keyResponse == EKeyWasConsumed )
   398     // pass key event to the other portal button if exists and focused
   422         DrawDeferred();
   399     if ( iPortalButtonTwo && iPortalButtonTwo->IsFocused() )
   423 
   400         {
   424 	// Do not let UI framework forward the keys to child controls as
   401         keyResponse = iPortalButtonTwo->OfferKeyEventL(
   425 	// we have already done that.
   402                             aKeyEvent, aType );
   426     return EKeyWasConsumed;
   403         }
   427 	}
   404     
   428 
   405     return keyResponse;
       
   406     }
   429 
   407 
   430 // ---------------------------------------------------------
   408 // ---------------------------------------------------------
   431 // CWmMainContainer::MoveFocusByKeys
   409 // CWmMainContainer::MoveFocusByKeys
   432 // ---------------------------------------------------------
   410 // ---------------------------------------------------------
   433 //
   411 //
   446                 aKeyEvent.iScanCode == EStdKeyUpArrow &&
   424                 aKeyEvent.iScanCode == EStdKeyUpArrow &&
   447                 iWidgetsList->CurrentItemIndex() == 0 )
   425                 iWidgetsList->CurrentItemIndex() == 0 )
   448             {
   426             {
   449             // widget list top -> up -> ovi button (portrait)
   427             // widget list top -> up -> ovi button (portrait)
   450             if ( aType == EEventKey )
   428             if ( aType == EEventKey )
   451                 SetFocusToOviButton();
   429                 SetFocusToPortalButton( 0 );
   452             keyResponse = EKeyWasConsumed;
   430             keyResponse = EKeyWasConsumed;
   453             }
   431             }
   454         else if ( iLayout == EPortrait &&
   432         else if ( iLayout == EPortrait &&
   455                 aKeyEvent.iScanCode == EStdKeyDownArrow &&
   433                 aKeyEvent.iScanCode == EStdKeyDownArrow &&
   456                 iWidgetsList->CurrentItemIndex() ==
   434                 iWidgetsList->CurrentItemIndex() ==
   457                    iWidgetsList->Model()->NumberOfItems() - 1 )
   435                    iWidgetsList->Model()->NumberOfItems() - 1 )
   458             {
   436             {
   459             // widget list bottom -> down -> ovi button (portrait)
   437             // widget list bottom -> down -> ovi button (portrait)
   460             if ( aType == EEventKey )
   438             if ( aType == EEventKey )
   461                 SetFocusToOviButton();
   439                 SetFocusToPortalButton( 0 );
   462             keyResponse = EKeyWasConsumed;
   440             keyResponse = EKeyWasConsumed;
   463             }
   441             }
   464         else if ( iLayout == ELandscape &&
   442         else if ( iLayout == ELandscape &&
   465                 aKeyEvent.iScanCode == EStdKeyRightArrow )
   443                 aKeyEvent.iScanCode == EStdKeyRightArrow )
   466             {
   444             {
   467             // widget list -> right -> ovi button (landscape)
   445             // widget list -> right -> ovi button (landscape)
   468             if ( aType == EEventKey )
   446             if ( aType == EEventKey )
   469                 SetFocusToOviButton();
   447                 SetFocusToPortalButton( 0 );
   470             keyResponse = EKeyWasConsumed;
   448             keyResponse = EKeyWasConsumed;
   471             }
   449             }
   472         else if ( iLayout == ELandscapeMirrored &&
   450         else if ( iLayout == ELandscapeMirrored &&
   473                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
   451                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
   474             {
   452             {
   475             // widget list -> left -> ovi button (landscape mirrored)
   453             // widget list -> left -> ovi button (landscape mirrored)
   476             if ( aType == EEventKey )
   454             if ( aType == EEventKey )
   477                 SetFocusToOviButton();
   455                 SetFocusToPortalButton( 0 );
   478             keyResponse = EKeyWasConsumed;
   456             keyResponse = EKeyWasConsumed;
   479             }
   457             }
   480         }
   458         }
   481     else if ( iOviPortal->IsFocused() )
   459     else if ( iPortalButtonOne->IsFocused() )
   482         {
   460         {
   483         // ------------------------------------
   461         // ------------------------------------
   484         // focus is in the OVI PORTAL BUTTON
   462         // focus is in the FIRST PORTAL BUTTON
   485         // ------------------------------------
   463         // ------------------------------------
   486         if ( iLayout == EPortrait &&
   464         if ( iLayout == EPortrait &&
   487                 aKeyEvent.iScanCode == EStdKeyDownArrow )
   465                 aKeyEvent.iScanCode == EStdKeyDownArrow )
   488             {
   466             {
   489             // ovi button -> down -> widget list top (portrait)
   467             // left portal -> down -> widget list top
   490             if ( aType == EEventKey )
   468             if ( aType == EEventKey )
   491                 SetFocusToWidgetList( 0 );
   469                 SetFocusToWidgetList( 0 );
   492             keyResponse = EKeyWasConsumed;
   470             keyResponse = EKeyWasConsumed;
   493             }
   471             }
   494         else if ( iLayout == EPortrait &&
   472         else if ( iLayout == EPortrait &&
   495                 aKeyEvent.iScanCode == EStdKeyUpArrow )
   473                 aKeyEvent.iScanCode == EStdKeyUpArrow )
   496             {
   474             {
   497             // obi button -> up -> widget list bottom (portrait)
   475             // left portal -> up -> widget list bottom
   498             if ( aType == EEventKey )
   476             if ( aType == EEventKey )
   499                 SetFocusToWidgetList( iWidgetsList->Model()->NumberOfItems()-1 );
   477                 SetFocusToWidgetList( iWidgetsList->Model()->NumberOfItems()-1 );
       
   478             keyResponse = EKeyWasConsumed;
       
   479             }
       
   480         else if ( iLayout == EPortrait &&
       
   481                 aKeyEvent.iScanCode == EStdKeyRightArrow &&
       
   482                 iConfiguration->PortalButtonCount() > 1 )
       
   483             {
       
   484             // left portal -> right -> right portal
       
   485             if ( aType == EEventKey )
       
   486                 SetFocusToPortalButton( 1 );
   500             keyResponse = EKeyWasConsumed;
   487             keyResponse = EKeyWasConsumed;
   501             }
   488             }
   502         else if ( iLayout == ELandscape &&
   489         else if ( iLayout == ELandscape &&
   503                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
   490                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
   504             {
   491             {
   505             // ovi button -> left -> widget list (landscape)
   492             // upper portal -> left -> widget list
   506             if ( aType == EEventKey )
   493             if ( aType == EEventKey )
   507                 SetFocusToWidgetList();
   494                 SetFocusToWidgetList();
   508             keyResponse = EKeyWasConsumed;
   495             keyResponse = EKeyWasConsumed;
   509             }
   496             }
   510         else if ( iLayout == ELandscapeMirrored &&
   497         else if ( iLayout == ELandscapeMirrored &&
   511                 aKeyEvent.iScanCode == EStdKeyRightArrow )
   498                 aKeyEvent.iScanCode == EStdKeyRightArrow )
   512             {
   499             {
   513             // ovi button -> right -> widget list (landscape mirrored)
   500             // upper portal -> right -> widget list (mirrored)
   514             if ( aType == EEventKey )
   501             if ( aType == EEventKey )
   515                 SetFocusToWidgetList();
   502                 SetFocusToWidgetList();
       
   503             keyResponse = EKeyWasConsumed;
       
   504             }
       
   505         else if ( ( iLayout == ELandscape ||
       
   506                 iLayout == ELandscapeMirrored ) &&
       
   507                 aKeyEvent.iScanCode == EStdKeyDownArrow &&
       
   508                 iConfiguration->PortalButtonCount() > 1 )
       
   509             {
       
   510             // upper portal -> down -> lower portal
       
   511             if ( aType == EEventKey )
       
   512                 SetFocusToPortalButton( 1 );
       
   513             keyResponse = EKeyWasConsumed;
       
   514             }
       
   515         }
       
   516     else if ( iPortalButtonTwo && iPortalButtonTwo->IsFocused() )
       
   517         {
       
   518         // ------------------------------------
       
   519         // focus is in the SECOND PORTAL BUTTON
       
   520         // ------------------------------------
       
   521         if ( iLayout == EPortrait &&
       
   522                 aKeyEvent.iScanCode == EStdKeyDownArrow )
       
   523             {
       
   524             // right portal -> down -> widget list top
       
   525             if ( aType == EEventKey )
       
   526                 SetFocusToWidgetList( 0 );
       
   527             keyResponse = EKeyWasConsumed;
       
   528             }
       
   529         else if ( iLayout == EPortrait &&
       
   530                 aKeyEvent.iScanCode == EStdKeyUpArrow )
       
   531             {
       
   532             // right portal -> up -> widget list bottom
       
   533             if ( aType == EEventKey )
       
   534                 SetFocusToWidgetList( iWidgetsList->Model()->NumberOfItems()-1 );
       
   535             keyResponse = EKeyWasConsumed;
       
   536             }
       
   537         else if ( iLayout == EPortrait &&
       
   538                 aKeyEvent.iScanCode == EStdKeyRightArrow &&
       
   539                 iConfiguration->PortalButtonCount() > 1 )
       
   540             {
       
   541             // right portal -> right -> left portal
       
   542             if ( aType == EEventKey )
       
   543                 SetFocusToPortalButton( 0 );
       
   544             keyResponse = EKeyWasConsumed;
       
   545             }
       
   546         else if ( iLayout == ELandscape &&
       
   547                 aKeyEvent.iScanCode == EStdKeyLeftArrow )
       
   548             {
       
   549             // lower portal -> left -> widget list
       
   550             if ( aType == EEventKey )
       
   551                 SetFocusToWidgetList();
       
   552             keyResponse = EKeyWasConsumed;
       
   553             }
       
   554         else if ( iLayout == ELandscapeMirrored &&
       
   555                 aKeyEvent.iScanCode == EStdKeyRightArrow )
       
   556             {
       
   557             // lower portal -> right -> widget list (mirrored)
       
   558             if ( aType == EEventKey )
       
   559                 SetFocusToWidgetList();
       
   560             keyResponse = EKeyWasConsumed;
       
   561             }
       
   562         else if ( ( iLayout == ELandscape ||
       
   563                 iLayout == ELandscapeMirrored ) &&
       
   564                 aKeyEvent.iScanCode == EStdKeyUpArrow )
       
   565             {
       
   566             // lower portal -> up -> upper portal
       
   567             if ( aType == EEventKey )
       
   568                 SetFocusToPortalButton( 0 );
   516             keyResponse = EKeyWasConsumed;
   569             keyResponse = EKeyWasConsumed;
   517             }
   570             }
   518         }
   571         }
   519     else
   572     else
   520         {
   573         {
   535 
   588 
   536     return keyResponse;
   589     return keyResponse;
   537     }
   590     }
   538 
   591 
   539 // ---------------------------------------------------------
   592 // ---------------------------------------------------------
   540 // CWmMainContainer::SetFocusToOviButton
   593 // CWmMainContainer::SetFocusToPortalButton
   541 // ---------------------------------------------------------
   594 // ---------------------------------------------------------
   542 //
   595 //
   543 void CWmMainContainer::SetFocusToOviButton()
   596 void CWmMainContainer::SetFocusToPortalButton( TInt aIndex )
   544     {
   597     {
   545     iWidgetsList->SetFocus(EFalse);
   598     if ( aIndex != 0 && iPortalButtonTwo )
   546     iOviPortal->SetFocus(ETrue);
   599         {
       
   600         iWidgetsList->SetFocus(EFalse);
       
   601         iPortalButtonOne->SetFocus(EFalse);
       
   602         iPortalButtonTwo->SetFocus(ETrue);
       
   603         }
       
   604     else
       
   605         {
       
   606         iWidgetsList->SetFocus(EFalse);
       
   607         if ( iPortalButtonTwo )
       
   608             iPortalButtonTwo->SetFocus(EFalse);
       
   609         iPortalButtonOne->SetFocus(ETrue);
       
   610         }
   547     DrawDeferred();
   611     DrawDeferred();
   548     UpdateFocusMode();
   612     UpdateFocusMode();
   549     }
   613     }
   550 
   614 
   551 // ---------------------------------------------------------
   615 // ---------------------------------------------------------
   552 // CWmMainContainer::SetFocusToWidgetList
   616 // CWmMainContainer::SetFocusToWidgetList
   553 // ---------------------------------------------------------
   617 // ---------------------------------------------------------
   554 //
   618 //
   555 void CWmMainContainer::SetFocusToWidgetList( TInt aIndex )
   619 void CWmMainContainer::SetFocusToWidgetList( TInt aIndex )
   556     {
   620     {
   557     iOviPortal->SetFocus(EFalse);
   621     iPortalButtonOne->SetFocus(EFalse);
       
   622     if ( iPortalButtonTwo )
       
   623         iPortalButtonTwo->SetFocus(EFalse);
       
   624     if ( aIndex >= 0 && aIndex < iWidgetsList->Model()->NumberOfItems() )
       
   625         {
       
   626         iWidgetsList->SetCurrentItemIndex( aIndex );
       
   627         }
   558     iWidgetsList->SetFocus(ETrue);
   628     iWidgetsList->SetFocus(ETrue);
   559     if ( aIndex >= 0 && aIndex < iWidgetsList->Model()->NumberOfItems() )
       
   560         {
       
   561         iWidgetsList->SetCurrentItemIndex( aIndex );
       
   562         }
       
   563     DrawDeferred();
   629     DrawDeferred();
   564     UpdateFocusMode();
   630     UpdateFocusMode();
   565     }
   631     }
   566 
   632 
   567 // ---------------------------------------------------------
   633 // ---------------------------------------------------------
   568 // CWmMainContainer::UpdateFocusMode
   634 // CWmMainContainer::UpdateFocusMode
   569 // ---------------------------------------------------------
   635 // ---------------------------------------------------------
   570 //
   636 //
   571 void CWmMainContainer::UpdateFocusMode()
   637 void CWmMainContainer::UpdateFocusMode()
   572     {
   638     {
   573     if ( iOviPortal->IsFocused() )
   639     if ( iPortalButtonOne->IsFocused() )
   574         {
   640         {
   575         // OVI BUTTON is focused 
   641         // PORTAL BUTTON is focused
   576         iFocusMode = EOvi;
   642         iFocusMode = EPortal;
       
   643         }
       
   644     else if ( iPortalButtonTwo && iPortalButtonTwo->IsFocused() )
       
   645         {
       
   646         // SECOND PORTAL BUTTON is focused
       
   647         iFocusMode = EPortal;
   577         }
   648         }
   578     else if( ( iFindPaneIsVisible ) && 
   649     else if( ( iFindPaneIsVisible ) && 
   579         ( iFindbox->IsFocused() || iWidgetsList->IsFocused() ) )
   650         ( iFindbox->IsFocused() || iWidgetsList->IsFocused() ) )
   580         {
   651         {
   581         // FIND MODE
   652         // FIND MODE
   667 // CWmMainContainer::InitializeControlsL
   738 // CWmMainContainer::InitializeControlsL
   668 // ---------------------------------------------------------
   739 // ---------------------------------------------------------
   669 //
   740 //
   670 void CWmMainContainer::InitializeControlsL( const TRect& /*aRect*/ )
   741 void CWmMainContainer::InitializeControlsL( const TRect& /*aRect*/ )
   671 	{
   742 	{
   672 	// Create OVI STORE button
   743 	// Create portal buttons
   673     HBufC* oviText = StringLoader::LoadLC( R_QTN_WM_GO_TO_OVI_STORE );    
   744     iPortalButtonOne = CWmPortalButton::NewL( this, 0 );
   674     iOviPortal = CWmPortalButton::NewL( this, *oviText );
   745     iPortalButtonOne->SetMopParent( this );    
   675     CleanupStack::PopAndDestroy( oviText );
   746     AddControlL( iPortalButtonOne, EPortalOne );
   676     
   747     if ( iConfiguration->PortalButtonCount() > 1 )
   677     iOviPortal->SetMopParent( this );    
   748         {
   678     AddControlL( iOviPortal, EOviPortal );
   749         iPortalButtonTwo = CWmPortalButton::NewL( this, 1 );
       
   750         iPortalButtonTwo->SetMopParent( this );    
       
   751         AddControlL( iPortalButtonTwo, EPortalTwo );
       
   752         }
   679     
   753     
   680     // Create widget list box
   754     // Create widget list box
   681     iWidgetsList = CWmListBox::NewL(
   755     iWidgetsList = CWmListBox::NewL(
   682             iWmPlugin,
   756             iWmPlugin,
   683             TRect(),
   757             TRect(),
   805 // CWmMainContainer::PortalSelected
   879 // CWmMainContainer::PortalSelected
   806 // ---------------------------------------------------------
   880 // ---------------------------------------------------------
   807 //
   881 //
   808 TBool CWmMainContainer::PortalSelected()
   882 TBool CWmMainContainer::PortalSelected()
   809     {    
   883     {    
   810     return ( iFocusMode == EOvi );
   884     return ( iFocusMode == EPortal );
   811     }
   885     }
   812 
   886 
   813 // ---------------------------------------------------------
   887 // ---------------------------------------------------------
   814 // CWmMainContainer::WidgetSelected
   888 // CWmMainContainer::WidgetSelected
   815 // ---------------------------------------------------------
   889 // ---------------------------------------------------------
   862     {
   936     {
   863     TBool retVal(EFalse);
   937     TBool retVal(EFalse);
   864     if ( WidgetSelected() )
   938     if ( WidgetSelected() )
   865         {
   939         {
   866         CWmWidgetData* data = iWidgetsList->WidgetData();        
   940         CWmWidgetData* data = iWidgetsList->WidgetData();        
   867         if ( data->WidgetType() == CWmWidgetData::ECps &&
   941         if ( data && data->WidgetType() == CWmWidgetData::ECps &&
   868             data->PublisherUid() != KNullUid )
   942             data->PublisherUid() != KNullUid )
   869             {
   943             {
   870             retVal = ETrue;
   944             retVal = ETrue;
   871             }
   945             }
   872         }
   946         }
   928             DeactivateFindPaneL();
  1002             DeactivateFindPaneL();
   929             }
  1003             }
   930 
  1004 
   931         // set add to homescreen to be executed later
  1005         // set add to homescreen to be executed later
   932         iWmPlugin.SetPostponedCommandL(
  1006         iWmPlugin.SetPostponedCommandL(
   933                 CWmPlugin::EAddToHomescreen, data->HsContentInfo() );
  1007             CWmPlugin::EAddToHomescreen,
   934 
  1008             data->HsContentInfo() );
   935         iWmPlugin.Deactivate();
  1009 
   936         }
  1010         // check if we can add any widgets to hs. 
   937     }
  1011         TBool hsContentFull = ETrue;
   938 	
  1012         for ( TInt i=0; i<iWidgetsList->WidgetDataCount(); i++ )
       
  1013             {
       
  1014             CHsContentInfo& info = iWidgetsList->WidgetData(i).HsContentInfo();
       
  1015             if ( info.CanBeAdded() ) 
       
  1016                 {
       
  1017                 hsContentFull = EFalse;
       
  1018                 break;
       
  1019                 }
       
  1020             }
       
  1021         
       
  1022         // do not deactivate wm if wrt widget already exists on hs,
       
  1023         // instead of that show popup info note.
       
  1024         if ( CWmWidgetData::ECps == data->WidgetType() &&
       
  1025             !data->HsContentInfo().CanBeAdded() &&
       
  1026             !hsContentFull )
       
  1027             {
       
  1028             iWmPlugin.ExecuteCommandL();
       
  1029             }
       
  1030         else
       
  1031             {
       
  1032             iWmPlugin.Deactivate();
       
  1033             }
       
  1034         }
       
  1035     }
       
  1036 
   939 // ---------------------------------------------------------------------------
  1037 // ---------------------------------------------------------------------------
   940 // CWmMainContainer::LaunchWidgetL
  1038 // CWmMainContainer::LaunchWidgetL
   941 // ---------------------------------------------------------------------------
  1039 // ---------------------------------------------------------------------------
   942 //
  1040 //
   943 void CWmMainContainer::LaunchWidgetL()
  1041 void CWmMainContainer::LaunchWidgetL()
  1074 //
  1172 //
  1075 void CWmMainContainer::UninstallWidgetL()
  1173 void CWmMainContainer::UninstallWidgetL()
  1076     {
  1174     {
  1077     if ( CanDoUninstall() )
  1175     if ( CanDoUninstall() )
  1078         {
  1176         {
  1079         CWmWidgetData* data = iWidgetsList->WidgetData();
  1177         iWidgetsList->WidgetData()->UnInstallL();
  1080         
  1178         }
  1081         SwiUI::RSWInstLauncher installer;
  1179     }
  1082         User::LeaveIfError( installer.Connect() );
  1180 
  1083         
  1181 // ---------------------------------------------------------------------------
  1084         installer.Uninstall( data->PublisherUid(), KWrtMime );
  1182 // CWmMainContainer::OpenPortalL
  1085         installer.Close();
  1183 // ---------------------------------------------------------------------------
  1086         }
  1184 //
  1087     }
  1185 void CWmMainContainer::OpenPortalL()
  1088 
       
  1089 // ---------------------------------------------------------------------------
       
  1090 // CWmMainContainer::OpenOviPortalL
       
  1091 // ---------------------------------------------------------------------------
       
  1092 //
       
  1093 void CWmMainContainer::OpenOviPortalL()
       
  1094     {
  1186     {
  1095     if ( !iClosingDown )
  1187     if ( !iClosingDown )
  1096         {
  1188         {
  1097         RApaLsSession session;
  1189         // execute whichever of the portal buttons happens to be active
  1098         User::LeaveIfError( session.Connect() );
  1190         if ( iPortalButtonOne->IsFocused() )
  1099         CleanupClosePushL( session );
  1191             iPortalButtonOne->ExecuteL();
  1100         TApaAppInfo appInfo;
  1192         else if ( iPortalButtonTwo && iPortalButtonTwo->IsFocused() )
  1101         TUid launchUid;
  1193             iPortalButtonTwo->ExecuteL();
  1102 
  1194         else if ( !iPortalButtonTwo )
  1103         // Get ovi store uid    
  1195             iPortalButtonOne->ExecuteL();
  1104         RWidgetRegistryClientSession widgetSession;
       
  1105         User::LeaveIfError( widgetSession.Connect() );    
       
  1106         CleanupClosePushL( widgetSession );
       
  1107         
       
  1108         launchUid.iUid = widgetSession.GetWidgetUidL( *iOviStoreClientBundleId );    
       
  1109         CleanupStack::PopAndDestroy( &widgetSession );
       
  1110 
       
  1111         TInt err = session.GetAppInfo( appInfo, launchUid );
       
  1112         if ( err == KErrNone )
       
  1113             {
       
  1114             CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
  1115             commandLine->SetExecutableNameL(appInfo.iFullName); 
       
  1116             HBufC8* buf8 = HBufC8::NewLC( iOviStoreClientParam->Des().Length() );
       
  1117             buf8->Des().Copy( *iOviStoreClientParam );
       
  1118                     
       
  1119             //cmdLine->SetOpaqueDataL( *buf8 );
       
  1120             commandLine->SetTailEndL( *buf8 );
       
  1121             err = session.StartApp( *commandLine );
       
  1122             CleanupStack::PopAndDestroy( buf8 );
       
  1123             CleanupStack::PopAndDestroy( commandLine );
       
  1124             }
       
  1125         else
       
  1126             {
       
  1127             if( iOviStoreUrl )
       
  1128                 {
       
  1129                 // Ovi store not found start browser
       
  1130                 const TUid KOSSBrowserUidValue = { 0x10008D39 };
       
  1131                 HBufC* param = HBufC::NewLC( iOviStoreUrl->Length() + 
       
  1132                         KBrowserPrefix().Length() );
       
  1133                 
       
  1134                 param->Des().Copy( KBrowserPrefix );
       
  1135                 param->Des().Append( *iOviStoreUrl );
       
  1136                 
       
  1137                 TUid id( KOSSBrowserUidValue );
       
  1138                 
       
  1139                 TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
  1140                 TApaTask task = taskList.FindApp(id);
       
  1141                 if( task.Exists() )
       
  1142                     {
       
  1143                     task.BringToForeground();
       
  1144                     HBufC8* param8 = HBufC8::NewLC(param->Length());
       
  1145                     param8->Des().Append(*param);
       
  1146                     task.SendMessage(TUid::Uid(0), *param8); // UID not used
       
  1147                     CleanupStack::PopAndDestroy(param8);
       
  1148                     }
       
  1149                 else
       
  1150                     {
       
  1151                     if( !session.Handle() )
       
  1152                         {
       
  1153                         User::LeaveIfError( session.Connect() );
       
  1154                         }
       
  1155                     TThreadId thread;
       
  1156                     User::LeaveIfError(session.StartDocument(*param, KOSSBrowserUidValue, thread));
       
  1157                       
       
  1158                     }
       
  1159                 CleanupStack::PopAndDestroy( param );
       
  1160                 }
       
  1161             }
       
  1162         CleanupStack::PopAndDestroy( &session );
       
  1163         }
  1196         }
  1164     }
  1197     }
  1165 
  1198 
  1166 // ---------------------------------------------------------------------------
  1199 // ---------------------------------------------------------------------------
  1167 // CWmMainContainer::SelectL
  1200 // CWmMainContainer::SelectL
  1170 void CWmMainContainer::SelectL()
  1203 void CWmMainContainer::SelectL()
  1171     {
  1204     {
  1172     if ( WidgetSelected() )
  1205     if ( WidgetSelected() )
  1173         AddWidgetToHomeScreenL();
  1206         AddWidgetToHomeScreenL();
  1174     else if ( PortalSelected() )
  1207     else if ( PortalSelected() )
  1175         OpenOviPortalL();
  1208         OpenPortalL();
  1176     else
  1209     else
  1177         SetFocusToWidgetList();
  1210         SetFocusToWidgetList();
  1178     }
  1211     }
  1179 
  1212 
  1180 // ---------------------------------------------------------------------------
  1213 // ---------------------------------------------------------------------------
  1243         const CFbsBitmap* logo = ( data->LogoImage() ) ? 
  1276         const CFbsBitmap* logo = ( data->LogoImage() ) ? 
  1244                     data->LogoImage() : iWidgetsList->DefaultLogo();
  1277                     data->LogoImage() : iWidgetsList->DefaultLogo();
  1245         const CFbsBitmap* mask = ( data->LogoImageMask() ) ? 
  1278         const CFbsBitmap* mask = ( data->LogoImageMask() ) ? 
  1246                     data->LogoImageMask() : iWidgetsList->DefaultMask();
  1279                     data->LogoImageMask() : iWidgetsList->DefaultMask();
  1247         
  1280         
  1248         TPtrC description = ( data->Description().Length() > 0 ) ? 
       
  1249             data->Description() : iWmPlugin.ResourceLoader().NoDescriptionText();
       
  1250         CWmDetailsDlg* dlg = CWmDetailsDlg::NewL(
  1281         CWmDetailsDlg* dlg = CWmDetailsDlg::NewL(
  1251                 data->Name(), description, 
  1282                 data->Name(), data->Description(), 
  1252                 data->HsContentInfo().CanBeAdded(),
  1283                 data->HsContentInfo().CanBeAdded(),
  1253                 logo, mask, iBgContext );
  1284                 logo, mask, iBgContext );
  1254 
  1285 
  1255         if ( dlg && dlg->ExecuteLD() == ECbaAddToHs )
  1286         if ( dlg && dlg->ExecuteLD() == ECbaAddToHs )
  1256             {
  1287             {
  1273 // ----------------------------------------------------
  1304 // ----------------------------------------------------
  1274 //
  1305 //
  1275 TBool CWmMainContainer::ClosingDown()
  1306 TBool CWmMainContainer::ClosingDown()
  1276     {
  1307     {
  1277     return iClosingDown;
  1308     return iClosingDown;
       
  1309     }
       
  1310 
       
  1311 // ----------------------------------------------------
       
  1312 // CWmMainContainer::Configuration
       
  1313 // ----------------------------------------------------
       
  1314 //
       
  1315 CWmConfiguration& CWmMainContainer::Configuration()
       
  1316     {
       
  1317     return *iConfiguration;
  1278     }
  1318     }
  1279 
  1319 
  1280 // ----------------------------------------------------
  1320 // ----------------------------------------------------
  1281 // CWmMainContainer::HandleFindSizeChanged
  1321 // CWmMainContainer::HandleFindSizeChanged
  1282 // ----------------------------------------------------
  1322 // ----------------------------------------------------