idlehomescreen/widgetmanager/src/wmportalbutton.cpp
branchRCL_3
changeset 34 d05a55b217df
parent 30 b8fae6b8a148
child 38 79311d856354
--- a/idlehomescreen/widgetmanager/src/wmportalbutton.cpp	Wed Mar 31 21:17:19 2010 +0300
+++ b/idlehomescreen/widgetmanager/src/wmportalbutton.cpp	Wed Apr 14 15:47:59 2010 +0300
@@ -32,6 +32,8 @@
 #include <widgetregistryclient.h> // widgetreqistry
 #include <bacline.h>
 #include <escapeutils.h> 
+#include <browserlauncher.h>
+#include <centralrepository.h>
 
 #include "wmportalbutton.h"
 #include "wmcommon.h"
@@ -42,10 +44,7 @@
 #include "wmprocessmonitor.h"
 
 // CONSTANTS
-_LIT( KUrlPrefix, "4 ");
 
-
-const TUid KOSSBrowserUidValue = { 0x10008D39 };
 // MEMBER FUNCTIONS
 
 // ---------------------------------------------------------
@@ -78,7 +77,7 @@
 // ---------------------------------------------------------
 //
 CWmPortalButton::~CWmPortalButton()
-    {    
+    {
     delete iButtonIcon;
     delete iButtonIconMask;
     
@@ -87,6 +86,7 @@
     // for de-reference open file count, so it should be deleted last.
     delete iImageConverter;
     delete iProcessMonitor;
+    delete iBrowserLauncher;
     }
 
 // ---------------------------------------------------------
@@ -102,6 +102,7 @@
     iButtonIcon = NULL;
     iButtonIconMask = NULL;
 	iProcessMonitor = NULL;
+	iBrowserLauncher = NULL;
     }
 
 // ---------------------------------------------------------
@@ -160,18 +161,31 @@
     {
     if ( iPortalButtonIndex == 0 )
         {
+        // OVI button
         if ( !iProcessMonitor )
             {
             iProcessMonitor = CWmProcessMonitor::NewL();
             }
-		if ( !iProcessMonitor->IsActive() )
+        // if process monitor is active laucher was allready started.
+        // this is for ignoring multiple button presses
+        if ( !iProcessMonitor->IsActive() )
             {
             RunOviL( iWmMainContainer->Configuration() );
             }
         }
     else if ( iPortalButtonIndex == 1 )
         {
-        RunOperatorL( iWmMainContainer->Configuration() );
+        // OPERATOR button
+        // if this leaves it means we need to start browser
+        // becouse application info was not given
+        TRAPD( err, RunOperatorApplicationL( 
+                iWmMainContainer->Configuration() ) )
+        if ( err != KErrNone )        
+            {
+            StartBrowserL( 
+                    iWmMainContainer->Configuration().PortalButtonBrowserUrl( 
+                            iPortalButtonIndex ) );
+            }
         } 
     else
         {
@@ -186,8 +200,6 @@
 //
 void CWmPortalButton::RunOviL( CWmConfiguration& aConf )
     {
-    // param is: channel=homescreenwidgets 
-    // laucher uid: 0x2002D07F
     RApaLsSession session;
     User::LeaveIfError( session.Connect() );
     CleanupClosePushL( session );
@@ -197,13 +209,7 @@
     TUid launchUid;
     launchUid = aConf.PortalButtonClientUid( iPortalButtonIndex );
 
-    TInt err = session.GetAppInfo( appInfo, launchUid );
-    if ( err != KErrNone )
-        {
-        //This is temp until we have laucher in SDK
-        StartBrowserL( aConf );
-        }
-    else
+    if ( session.GetAppInfo( appInfo, launchUid ) == KErrNone )
         {
         // Form parameter
         HBufC* param = HBufC::NewLC( aConf.PortalButtonClientParam( iPortalButtonIndex ).Length() );
@@ -226,67 +232,39 @@
 // CWmPortalButton::StartBrowserL
 // ---------------------------------------------------------
 //
-void CWmPortalButton::StartBrowserL( CWmConfiguration& aConf )
+void CWmPortalButton::StartBrowserL( const TDesC& aUrl )
     {
-    RApaLsSession session;
-    User::LeaveIfError( session.Connect() );
-    CleanupClosePushL( session );
+    // already running/or request launch or url is empty
+    if ( iBrowserLauncher || !aUrl.Length() ) { return; } 
 
-    HBufC* param = NULL;
-    if ( iPortalButtonIndex == 1 )
-        {
-        // browser start parameter
-        param = HBufC::NewLC( 
-                aConf.PortalButtonBrowserUrl( iPortalButtonIndex ).Length() + 
-                        KUrlPrefix().Length() );
+    _LIT( KUrlPrefix, "4 ");
+    HBufC* param = HBufC::NewLC( aUrl.Length() + KUrlPrefix().Length() );
+    param->Des().Append( KUrlPrefix );
+    param->Des().Append( aUrl );
         
-        param->Des().Copy( KUrlPrefix );
-        param->Des().Append( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) );
-        }
-    else
-        {
-        // becouse launcher knows url we need to have it temp here
-        // until laucher is available
-        _LIT( KTempUrl, "4 https://store.ovi.com/applications/");
-        param = HBufC::NewLC( KTempUrl().Length() );
-        param->Des().Copy( KTempUrl );
-        }
+    // Create browser launcher
+    CBrowserLauncher* launcher = CBrowserLauncher::NewLC();
+
+    // Asynchronous operation to launch the browser with given URL
+    launcher->LaunchBrowserEmbeddedL( 
+            *param, NULL, this, NULL );
     
-    TUid id( KOSSBrowserUidValue );
-    TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
-    TApaTask task = taskList.FindApp( id );
-    if( task.Exists() )
-        {
-        task.BringToForeground();
-        HBufC8* param8 = HBufC8::NewLC(param->Length());
-        param8->Des().Append(*param);
-        task.SendMessage(TUid::Uid(0), *param8); // UID not used
-        CleanupStack::PopAndDestroy(param8);
-        }
-    else
-        {
-        if( !session.Handle() )
-            {
-            User::LeaveIfError( session.Connect() );
-            }
-        TThreadId thread;
-        User::LeaveIfError(
-                session.StartDocument(*param, KOSSBrowserUidValue, thread));
-        }
-    
+    CleanupStack::Pop( launcher ); 
+    iBrowserLauncher = launcher;
+    launcher = NULL;
+
     CleanupStack::PopAndDestroy( param );
-    CleanupStack::PopAndDestroy( &session );
     }
 
 // ---------------------------------------------------------
-// CWmPortalButton::RunOperatorL
+// CWmPortalButton::HandleServerAppExit
 // ---------------------------------------------------------
 //
-void CWmPortalButton::RunOperatorL( CWmConfiguration& aConf )
+void CWmPortalButton::HandleServerAppExit( TInt aReason )
     {
-    // Current info is that this will be a widget
-    // meanwhile we just start browser
-    StartBrowserL( aConf );
+    MAknServerAppExitObserver::HandleServerAppExit( aReason );
+    delete iBrowserLauncher;
+    iBrowserLauncher = NULL;
     }
 
 // ---------------------------------------------------------
@@ -573,4 +551,95 @@
             baselineOffset, layoutText.Align() );    
     }
 
+// ---------------------------------------------------------
+// CWmPortalButton::RunOperatorApplicationL
+// ---------------------------------------------------------
+//
+void CWmPortalButton::RunOperatorApplicationL( CWmConfiguration& aConf )
+    {
+    CWmConfiguration::TOpAppType type = aConf.PortalButtonApplicationType( 1 );
+    if ( type == CWmConfiguration::EUnknown ||
+        type >= CWmConfiguration::EReserved )
+        {
+        // Leave if not found
+        User::Leave( KErrArgument );
+        }
+    
+    switch( type )
+        {
+        case CWmConfiguration::ES60:
+        case CWmConfiguration::EQt:    
+            {
+            TUid uid = KNullUid;
+            aConf.PortalButtonApplicationId( 1, uid );
+            StartProcessL( uid, aConf.PortalButtonClientParam( 1 ) );
+            }
+            break;
+        case CWmConfiguration::ECwrt:
+            {
+            TUid uid = KNullUid;
+            aConf.PortalButtonApplicationId( 1, uid );
+            StartWidgetL( uid, aConf.PortalButtonClientParam( 1 ) );
+            }
+            break;
+        case CWmConfiguration::EWrt:
+            {
+            TUid uid = KNullUid;
+            aConf.PortalButtonApplicationId( 1, uid );
+            StartWidgetL( uid, KNullDesC );
+            }
+            break;
+        case CWmConfiguration::EJava:
+            {
+            TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> appId;
+            aConf.PortalButtonApplicationId( 1, appId );
+            //TODO:
+            }
+            break;
+        }
+    }
+
+// ---------------------------------------------------------
+// CWmPortalButton::StartProcessL
+// ---------------------------------------------------------
+//
+void CWmPortalButton::StartProcessL( TUid aUid, const TDesC& aParam )
+    {
+    RApaLsSession session;
+    User::LeaveIfError( session.Connect() );
+    CleanupClosePushL( session );
+    
+    //get app info
+    TApaAppInfo appInfo;
+    User::LeaveIfError( session.GetAppInfo( appInfo, aUid ) );
+    // do the launch
+    RProcess process;
+    User::LeaveIfError( process.Create( appInfo.iFullName, aParam ) );
+    process.Resume();
+    
+    CleanupStack::PopAndDestroy( &session );
+    }
+
+// ---------------------------------------------------------
+// CWmPortalButton::StartWidgetL
+// ---------------------------------------------------------
+//
+void CWmPortalButton::StartWidgetL( TUid aAppUid, const TDesC& aParams )
+    {
+    if ( aAppUid == KNullUid )
+        User::Leave( KErrArgument );
+    
+    HBufC* params = aParams.AllocLC();
+    
+    RApaLsSession appArc;
+    User::LeaveIfError( appArc.Connect() );
+    CleanupClosePushL( appArc );
+    
+    TThreadId threadId;
+    User::LeaveIfError( appArc.StartDocument( *params, aAppUid, threadId ) );
+    
+    CleanupStack::PopAndDestroy( &appArc );      
+    CleanupStack::PopAndDestroy( params );
+    }
+
 // End of file