idlehomescreen/widgetmanager/src/wmportalbutton.cpp
branchRCL_3
changeset 11 ff572dfe6d86
parent 9 f966699dea19
child 17 b8fae6b8a148
equal deleted inserted replaced
9:f966699dea19 11:ff572dfe6d86
    29 #include <widgetmanager.mbg>
    29 #include <widgetmanager.mbg>
    30 #include <apgcli.h>
    30 #include <apgcli.h>
    31 #include <apgtask.h>
    31 #include <apgtask.h>
    32 #include <widgetregistryclient.h> // widgetreqistry
    32 #include <widgetregistryclient.h> // widgetreqistry
    33 #include <bacline.h>
    33 #include <bacline.h>
    34 #include <EscapeUtils.h> 
    34 #include <escapeutils.h> 
    35 
    35 
    36 #include "wmportalbutton.h"
    36 #include "wmportalbutton.h"
    37 #include "wmcommon.h"
    37 #include "wmcommon.h"
    38 #include "wmplugin.h"
    38 #include "wmplugin.h"
    39 #include "wmresourceloader.h"
    39 #include "wmresourceloader.h"
    40 #include "wmmaincontainer.h"
    40 #include "wmmaincontainer.h"
    41 #include "wmconfiguration.h"
    41 #include "wmconfiguration.h"
    42 #include "wmprocessmonitor.h"
    42 #include "wmprocessmonitor.h"
    43 
    43 
    44 // CONSTANTS
    44 // CONSTANTS
    45 _LIT( KOviUrlPrefix, "oviurl ");
    45 _LIT( KUrlPrefix, "4 ");
    46 _LIT( KBrowserUrlPrefix, "browserurl ");
    46 
    47 _LIT( KSpace, " ");
       
    48 _LIT( Kurlprefix, "4 ");
       
    49 
    47 
    50 const TUid KOSSBrowserUidValue = { 0x10008D39 };
    48 const TUid KOSSBrowserUidValue = { 0x10008D39 };
    51 const TInt KMaxParam = 512;
       
    52 // MEMBER FUNCTIONS
    49 // MEMBER FUNCTIONS
    53 
    50 
    54 // ---------------------------------------------------------
    51 // ---------------------------------------------------------
    55 // CWmPortalButton::NewL
    52 // CWmPortalButton::NewL
    56 // ---------------------------------------------------------
    53 // ---------------------------------------------------------
   126     iWmMainContainer = aParent;
   123     iWmMainContainer = aParent;
   127     
   124     
   128     // construct the button
   125     // construct the button
   129     CAknButton::ConstructL( NULL, NULL, NULL, NULL, aText, KNullDesC, 0 );
   126     CAknButton::ConstructL( NULL, NULL, NULL, NULL, aText, KNullDesC, 0 );
   130 
   127 
   131     TAknsItemID frameId = KAknsIIDQgnHomeWmButton;
       
   132     TAknsItemID frameCenterId = KAknsIIDQgnHomeWmButtonCenter;
       
   133     TAknsItemID framePressedId = KAknsIIDQgnHomeWmButtonPressed;
       
   134     TAknsItemID framePressedCenterId = KAknsIIDQgnHomeWmButtonPressedCenter;
       
   135 
       
   136     SetFocusing( ETrue );
       
   137     SetBackgroundIds( frameId,
       
   138                       framePressedId,
       
   139                       KAknsIIDQsnFrButtonInactive,
       
   140                       framePressedId,
       
   141                       KAknsIIDQsnFrButtonInactive );
       
   142     SetFrameAndCenterIds( 
   128     SetFrameAndCenterIds( 
   143                         frameId,
   129             KAknsIIDQsnFrButtonNormal,
   144 						frameCenterId,
   130             KAknsIIDQsnFrButtonCenterNormal,
   145 						KAknsIIDDefault,
   131             KAknsIIDQsnFrButtonPressed,
   146 						KAknsIIDDefault,
   132             KAknsIIDQsnFrButtonCenterPressed,
   147 						KAknsIIDDefault,
   133             KAknsIIDQsnFrButtonInactive,
   148 						KAknsIIDDefault,
   134             KAknsIIDQsnFrButtonCenterInactive,
   149 						framePressedId,
   135             KAknsIIDQsnFrButtonPressed,
   150 						framePressedCenterId,
   136             KAknsIIDQsnFrButtonCenterPressed,
   151 						KAknsIIDDefault,
   137             KAknsIIDQsnFrButtonInactive,
   152 						KAknsIIDDefault );
   138             KAknsIIDQsnFrButtonCenterInactive );
   153     
   139     
   154     // start image converter for the icon
   140     // start image converter for the icon
   155     iImageConverter = CWmImageConverter::NewL( this );
   141     iImageConverter = CWmImageConverter::NewL( this );
   156     TSize iconsize( LayoutIconSize() );
   142     TSize iconsize( LayoutIconSize() );
   157     iImageConverter->HandleIconString(
   143     iImageConverter->HandleIconString(
   158             iconsize.iWidth, iconsize.iHeight, aIcon );
   144             iconsize.iWidth, iconsize.iHeight, aIcon );
   159     // observe our own press events
   145     // observe our own press events
   160     SetObserver( this );
   146     SetObserver( this );
   161     
   147     
       
   148     SetFocusing( ETrue );
       
   149     SetRequestExit( ETrue ); // notification request for button up event
       
   150     
   162     // ready to be drawn
   151     // ready to be drawn
   163     ActivateL();
   152     ActivateL();
   164     }
   153     }
   165 
   154 
   166 // ---------------------------------------------------------
   155 // ---------------------------------------------------------
   175             {
   164             {
   176             iProcessMonitor = CWmProcessMonitor::NewL();
   165             iProcessMonitor = CWmProcessMonitor::NewL();
   177             }
   166             }
   178 		if ( !iProcessMonitor->IsActive() )
   167 		if ( !iProcessMonitor->IsActive() )
   179             {
   168             {
   180             // We will have laucher for starting ovi store but until
   169             RunOviL( iWmMainContainer->Configuration() );
   181             // it's added to SDK we need to start browser to ovi url
       
   182             if ( 0 )
       
   183                 RunOviL( iWmMainContainer->Configuration() );
       
   184             else
       
   185                 StartBrowserL( iWmMainContainer->Configuration() );
       
   186             }
   170             }
   187         }
   171         }
   188     else if ( iPortalButtonIndex == 1 )
   172     else if ( iPortalButtonIndex == 1 )
   189         {
   173         {
   190         RunOperatorL( iWmMainContainer->Configuration() );
   174         RunOperatorL( iWmMainContainer->Configuration() );
   200 // CWmPortalButton::RunOviL
   184 // CWmPortalButton::RunOviL
   201 // ---------------------------------------------------------
   185 // ---------------------------------------------------------
   202 //
   186 //
   203 void CWmPortalButton::RunOviL( CWmConfiguration& aConf )
   187 void CWmPortalButton::RunOviL( CWmConfiguration& aConf )
   204     {
   188     {
       
   189     // param is: channel=homescreenwidgets 
       
   190     // laucher uid: 0x2002D07F
   205     RApaLsSession session;
   191     RApaLsSession session;
   206     User::LeaveIfError( session.Connect() );
   192     User::LeaveIfError( session.Connect() );
   207     CleanupClosePushL( session );
   193     CleanupClosePushL( session );
   208     
   194     
   209     //get app info
   195     //get app info
   210     TApaAppInfo appInfo;
   196     TApaAppInfo appInfo;
   211     TUid launchUid; //plan was to save uid in cenrep and fetch it from there
   197     TUid launchUid;
   212     launchUid = aConf.PortalButtonClientUid( iPortalButtonIndex );
   198     launchUid = aConf.PortalButtonClientUid( iPortalButtonIndex );
   213     User::LeaveIfError( session.GetAppInfo( appInfo, launchUid ) );
   199 
   214    
   200     TInt err = session.GetAppInfo( appInfo, launchUid );
   215     // Form parameter
   201     if ( err != KErrNone )
   216     // it should look like this "oviurl url1 browserurl url2"  
   202         {
   217     HBufC* param = HBufC::NewLC( KMaxParam );
   203         //This is temp until we have laucher in SDK
   218     param->Des().Copy( KOviUrlPrefix );
   204         StartBrowserL( aConf );
   219     HBufC* decodedParam = EscapeUtils::EscapeEncodeL( aConf.PortalButtonClientParam( iPortalButtonIndex ), EscapeUtils::EEscapeUrlEncoded );
   205         }
   220     CleanupStack::PushL( decodedParam );
   206     else
   221     param->Des().Append( *decodedParam );
   207         {
   222     param->Des().Append( KSpace );
   208         // Form parameter
   223     param->Des().Append( KBrowserUrlPrefix );
   209         HBufC* param = HBufC::NewLC( aConf.PortalButtonClientParam( iPortalButtonIndex ).Length() );
   224     decodedParam->Des().Copy( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) );
   210         param->Des().Copy( aConf.PortalButtonClientParam( iPortalButtonIndex ) );
   225     param->Des().Append( *decodedParam );
   211         
   226 
   212         // do the launch
   227     // do the launch
   213         RProcess process;
   228     RProcess process;
   214         User::LeaveIfError( process.Create( appInfo.iFullName, *param ) );
   229     User::LeaveIfError( process.Create( appInfo.iFullName, *param ) );
   215     
   230     iProcessMonitor->Monitor( process );
   216         iProcessMonitor->Monitor( process );
   231     process.Resume();
   217         process.Resume();
   232 
   218     
   233     CleanupStack::PopAndDestroy( decodedParam );
   219         CleanupStack::PopAndDestroy( param );
   234     CleanupStack::PopAndDestroy( param );
   220         }
       
   221     
   235     CleanupStack::PopAndDestroy( &session );
   222     CleanupStack::PopAndDestroy( &session );
   236     }
   223     }
   237 
   224 
   238 // ---------------------------------------------------------
   225 // ---------------------------------------------------------
   239 // CWmPortalButton::StartBrowserL
   226 // CWmPortalButton::StartBrowserL
   243     {
   230     {
   244     RApaLsSession session;
   231     RApaLsSession session;
   245     User::LeaveIfError( session.Connect() );
   232     User::LeaveIfError( session.Connect() );
   246     CleanupClosePushL( session );
   233     CleanupClosePushL( session );
   247 
   234 
   248     // browser start parameters
   235     HBufC* param = NULL;
   249     HBufC* param = HBufC::NewLC( 
   236     if ( iPortalButtonIndex == 1 )
   250             aConf.PortalButtonBrowserUrl( iPortalButtonIndex ).Length() + 
   237         {
   251             Kurlprefix().Length() );
   238         // browser start parameter
   252     
   239         param = HBufC::NewLC( 
   253     param->Des().Copy( Kurlprefix );
   240                 aConf.PortalButtonBrowserUrl( iPortalButtonIndex ).Length() + 
   254     param->Des().Append( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) );
   241                         KUrlPrefix().Length() );
       
   242         
       
   243         param->Des().Copy( KUrlPrefix );
       
   244         param->Des().Append( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) );
       
   245         }
       
   246     else
       
   247         {
       
   248         // becouse launcher knows url we need to have it temp here
       
   249         // until laucher is available
       
   250         _LIT( KTempUrl, "4 https://store.ovi.com/applications/");
       
   251         param = HBufC::NewLC( KTempUrl().Length() );
       
   252         param->Des().Copy( KTempUrl );
       
   253         }
   255     
   254     
   256     TUid id( KOSSBrowserUidValue );
   255     TUid id( KOSSBrowserUidValue );
   257     
       
   258     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
   256     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
   259     TApaTask task = taskList.FindApp( id );
   257     TApaTask task = taskList.FindApp( id );
   260     if( task.Exists() )
   258     if( task.Exists() )
   261         {
   259         {
   262         task.BringToForeground();
   260         task.BringToForeground();
   282 
   280 
   283 // ---------------------------------------------------------
   281 // ---------------------------------------------------------
   284 // CWmPortalButton::RunOperatorL
   282 // CWmPortalButton::RunOperatorL
   285 // ---------------------------------------------------------
   283 // ---------------------------------------------------------
   286 //
   284 //
   287 void CWmPortalButton::RunOperatorL( CWmConfiguration& /*aConf*/ )
   285 void CWmPortalButton::RunOperatorL( CWmConfiguration& aConf )
   288     {
   286     {
   289     //TODO: current info is that this will be a widget
   287     // Current info is that this will be a widget
       
   288     // meanwhile we just start browser
       
   289     StartBrowserL( aConf );
   290     }
   290     }
   291 
   291 
   292 // ---------------------------------------------------------
   292 // ---------------------------------------------------------
   293 // CWmPortalButton::HandleControlEventL
   293 // CWmPortalButton::HandleControlEventL
   294 // ---------------------------------------------------------
   294 // ---------------------------------------------------------
   295 //
   295 //
   296 void CWmPortalButton::HandleControlEventL( CCoeControl* /*aControl*/,
   296 void CWmPortalButton::HandleControlEventL( CCoeControl* aControl,
   297         TCoeEvent aEventType )
   297         TCoeEvent aEventType )
   298     {
   298     {
   299     // execute portal action when button pressed (short or long press)
   299     if ( aControl == this )
   300     if ( aEventType == EEventStateChanged ||
   300         {
   301         aEventType == ELongPressEndedEvent )
   301         if ( aEventType == EEventStateChanged ||
   302         {
   302             aEventType == ELongPressEndedEvent ||
   303         ExecuteL();
   303             aEventType == EEventRequestCancel )
   304         }
   304             {
   305     }
   305             DrawDeferred();
       
   306             }
       
   307         // execute portal action when button pressed (short or long press)
       
   308         if ( aEventType == EEventRequestExit )
       
   309             {
       
   310             SetFocus( EFalse );
       
   311             DrawNow();
       
   312             ExecuteL();
       
   313             }
       
   314         }
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------
       
   318 // CWmPortalButton::HandlePointerEventL
       
   319 // ---------------------------------------------------------
       
   320 //
       
   321 void CWmPortalButton::HandlePointerEventL( 
       
   322         const TPointerEvent& aPointerEvent )
       
   323     {
       
   324     CAknButton::HandlePointerEventL( aPointerEvent );
       
   325     
       
   326     // remove focus from button if button is released outside rect 
       
   327     if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   328         {
       
   329         TBool wasFoucused( IsFocused() );
       
   330         SetFocus( Rect().Contains( aPointerEvent.iPosition ) );
       
   331         if ( wasFoucused != IsFocused() ){ DrawNow(); }
       
   332         }
       
   333     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   334         {
       
   335         SetFocus( EFalse ); // remove focus when button released.
       
   336         }
       
   337     }
       
   338 
   306 
   339 
   307 // ---------------------------------------------------------
   340 // ---------------------------------------------------------
   308 // CWmPortalButton::LayoutIconSize
   341 // CWmPortalButton::LayoutIconSize
   309 // ---------------------------------------------------------
   342 // ---------------------------------------------------------
   310 //
   343 //
   368         iButtonIconMask = NULL;
   401         iButtonIconMask = NULL;
   369         iButtonIconMask = iImageConverter->Mask();
   402         iButtonIconMask = iImageConverter->Mask();
   370         if ( iButtonIcon && iButtonIconMask )
   403         if ( iButtonIcon && iButtonIconMask )
   371             {
   404             {
   372             TSize size = LayoutIconSize();
   405             TSize size = LayoutIconSize();
   373             AknIconUtils::SetSize( 
   406             if ( iButtonIcon->SizeInPixels() != size )
       
   407                 {
       
   408                 AknIconUtils::SetSize( 
   374                     iButtonIcon, size, EAspectRatioPreserved );
   409                     iButtonIcon, size, EAspectRatioPreserved );
   375             AknIconUtils::SetSize( 
   410                 }
       
   411             if ( iButtonIconMask->SizeInPixels() != size )
       
   412                 {
       
   413                 AknIconUtils::SetSize( 
   376                     iButtonIconMask, size, EAspectRatioPreserved );
   414                     iButtonIconMask, size, EAspectRatioPreserved );
   377             DrawDeferred();            
   415                 }
       
   416             DrawDeferred();
   378             }
   417             }
   379         }
   418         }
   380     else
   419     else
   381         {
   420         {
   382         // no image available. Do nothing.
   421         // no image available. Do nothing.
   397     TRect innerRect = centerLayout.Rect();
   436     TRect innerRect = centerLayout.Rect();
   398 
   437 
   399     CWindowGc& gc = SystemGc();
   438     CWindowGc& gc = SystemGc();
   400     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   439     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   401 
   440 
   402  	TAknsItemID frameId = ( KAknsIIDQgnHomeWmButton );
   441  	TAknsItemID frameId = ( KAknsIIDQsnFrButtonNormal );
   403     TAknsItemID frameCenterId = ( KAknsIIDQgnHomeWmButtonCenter );
   442     TAknsItemID frameCenterId = ( KAknsIIDQsnFrButtonCenterNormal );
   404  	
   443  	
   405     if ( iButtonPressed )
   444     if ( iButtonPressed )
   406     	{
   445     	{
   407         frameId = ( KAknsIIDQgnHomeWmButtonPressed );
   446         frameId = ( KAknsIIDQsnFrButtonPressed );
   408         frameCenterId = ( KAknsIIDQgnHomeWmButtonPressedCenter );
   447         frameCenterId = ( KAknsIIDQsnFrButtonCenterPressed );
   409     	}
   448     	}
   410     else if ( IsDimmed() )
   449     else if ( IsDimmed() )
   411         {
   450         {
   412     	frameId = KAknsIIDQsnFrButtonInactive;
   451     	frameId = KAknsIIDQsnFrButtonInactive;
   413     	frameCenterId = KAknsIIDQsnFrButtonCenterInactive;
   452     	frameCenterId = KAknsIIDQsnFrButtonCenterInactive;
   414         }
   453         }
   415     else if ( IsFocused() )
   454     else if ( IsFocused() )
   416         {
   455         {
   417         frameId = KAknsIIDQsnFrList;
   456         frameId = KAknsIIDQsnFrButtonHighlight;
   418         frameCenterId = KAknsIIDQsnFrListCenter;
   457         frameCenterId = KAknsIIDQsnFrButtonHighlightCenter;
   419         }
   458         }
   420     
   459     
   421     iBgContext->SetFrame( frameId );
   460     iBgContext->SetFrame( frameId );
   422     iBgContext->SetCenter( frameCenterId );
   461     iBgContext->SetCenter( frameCenterId );
   423     iBgContext->SetFrameRects( rect, innerRect );
   462     iBgContext->SetFrameRects( rect, innerRect );
   424 
   463 
   425     if ( !AknsDrawUtils::Background( skin, iBgContext, NULL, 
   464     if ( !AknsDrawUtils::Background( skin, iBgContext, NULL, 
   426                     gc, rect, KAknsDrawParamNoClearUnderImage ) )
   465         gc, rect, KAknsDrawParamNoClearUnderImage ) )
   427         {
   466         {
   428         gc.SetBrushColor( KRgbRed );
   467         gc.SetBrushColor( KRgbRed );
   429         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
   468         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
   430         gc.DrawRect( rect );
   469         gc.DrawRect( rect );
   431         }
   470         }
   509         textColor = iEikonEnv->ControlColor( EColorButtonText, *this );
   548         textColor = iEikonEnv->ControlColor( EColorButtonText, *this );
   510         // try over-writing color from theme, ignore error.
   549         // try over-writing color from theme, ignore error.
   511         AknsUtils::GetCachedColor( 
   550         AknsUtils::GetCachedColor( 
   512                 skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );        
   551                 skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );        
   513         }
   552         }
       
   553     else
       
   554         {
       
   555         // default for button
       
   556         AknsUtils::GetCachedColor( 
       
   557                 skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG80 ); 
       
   558         }
   514     aGc.SetPenColor( textColor);
   559     aGc.SetPenColor( textColor);
   515     
   560     
   516     // Layout data not correct, add some space for text
   561     // Layout data not correct, add some space for text
   517     textRect.iBr.iX += aMargin;
   562     textRect.iBr.iX += aMargin;
   518     textRect.iTl.iX -= aMargin;
   563     textRect.iTl.iX -= aMargin;