browserui/browser/BrowserAppSrc/BrowserAppViewBase.cpp
branchRCL_3
changeset 65 8e6fa1719340
equal deleted inserted replaced
64:6385c4c93049 65:8e6fa1719340
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *      Declaration of class CBrowserAppViewBase.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include "BrowserAppViewBase.h"
       
    22 #include "BrowserAppUi.h"
       
    23 #include "ApiProvider.h"
       
    24 #include <BrowserNG.rsg>
       
    25 #include "CommonConstants.h"
       
    26 #include <aknviewappui.h>
       
    27 #include <eikbtgpc.h>
       
    28 #include <avkon.rsg>
       
    29 #include <LayoutMetaData.cdl.h> // check landscape/portrait modes
       
    30 #include <aknenv.h>
       
    31 #include <AknSgcc.h>
       
    32 #include <StringLoader.h>
       
    33 #include "BrowserUtil.h"
       
    34 #include <browseruisdkcrkeys.h>
       
    35 #include <UTF.h>
       
    36 #include <charconv.h>
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // TSKPair::TSKPair
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 TSKPair::TSKPair():
       
    44 	iCmdId(EWmlNoCmd),iQtnRsc(R_BROWSER_DYN_SK_NULL)
       
    45 {
       
    46 }	
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // TSKPair::TSKPair
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 TSKPair::TSKPair(TInt aId,TInt aRsc):
       
    53 	iCmdId(aId),iQtnRsc(aRsc)
       
    54 {
       
    55 }	
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // TSKPair::IsNotDefault
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 TBool TSKPair::IsAssigned()
       
    62 {
       
    63 	return ( (iCmdId != EWmlNoCmd) && (iQtnRsc != R_BROWSER_DYN_SK_NULL) );
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // TSKPair::operator==
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 TBool TSKPair::operator==(TSKPair aSkPair)
       
    71 {
       
    72 	return( (iCmdId == aSkPair.id()) && (iQtnRsc == aSkPair.qtn()) );
       
    73 }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // TSKPair::operator=
       
    77 // ---------------------------------------------------------
       
    78 //
       
    79 void TSKPair::operator=(TSKPair aSKPair)
       
    80 {
       
    81 	iCmdId = aSKPair.id();
       
    82 	iQtnRsc = aSKPair.qtn();
       
    83 }
       
    84 
       
    85 // ---------------------------------------------------------
       
    86 // TSKPair::set
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void TSKPair::setPair(TInt aId, TInt aRsc)
       
    90 {
       
    91 	iCmdId = aId;
       
    92 	iQtnRsc = aRsc;
       
    93 }
       
    94 
       
    95 
       
    96 // ================= MEMBER FUNCTIONS =======================
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CBrowserViewBase::CBrowserViewBase
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 CBrowserViewBase::CBrowserViewBase( MApiProvider& aApiProvider ):
       
   103     iApiProvider( aApiProvider ),
       
   104     iLastCommandSet( R_BROWSER_BUTTONS_CBA_NULL )
       
   105     {
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CBrowserViewBase::ApiProvider
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 MApiProvider& CBrowserViewBase::ApiProvider()
       
   113     {
       
   114     return iApiProvider;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CBrowserViewBase::UpdateCbaL
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 void CBrowserViewBase::UpdateCbaL()
       
   122 {
       
   123     if ( !iApiProvider.ExitInProgress() )
       
   124         {
       
   125         TInt commandSet = CommandSetResourceIdL();
       
   126         TUid currViewId = Id();
       
   127 
       
   128 		// Ask BrowserAppUi which view we were in when we last updated the CBA
       
   129 		// this will help decide if we should do it again
       
   130         TUid previousCBAUpdateViewId = iApiProvider.GetLastCBAUpdateView();
       
   131 
       
   132         if ( commandSet )
       
   133         	{
       
   134         	// Don't perform updates to the CBA when
       
   135         	//
       
   136         	// - We're still in the same view we were just in AND
       
   137         	// - We're not dynamically setting CBA (do more checking below) AND
       
   138         	// - The command set is the same as the one we just set last time
       
   139         	//   this was called
       
   140         	// - We're currently in the content view (the update-cba is more complex here
       
   141         	//   and we should just do it when asked by ContentView class)
       
   142         	//
       
   143         	// NOTE that we rely on CommandSetResource to set the commandSet to
       
   144         	//  R_BROWSER_BUTTONS_CBA_DYNAMIC to signal a desire to update the keys
       
   145         	//  dynamically. 
       
   146 			if(	currViewId == iPreviousViewID &&
       
   147 				commandSet != R_BROWSER_BUTTONS_CBA_DYNAMIC &&
       
   148 				currViewId == previousCBAUpdateViewId &&
       
   149 				currViewId != KUidBrowserContentViewId)
       
   150 				{
       
   151 				return;
       
   152 				}
       
   153         	
       
   154         	// If command set is our special dynamic cba set,
       
   155         	// now ask derived class for the resources dynamically.        	
       
   156         	if(commandSet == R_BROWSER_BUTTONS_CBA_DYNAMIC)
       
   157             	{
       
   158 				TSKPair lsk,rsk,msk;					
       
   159 				CommandSetResourceDynL(lsk,rsk,msk);
       
   160 
       
   161 				// Similar exclusion as above:
       
   162 				// Don't update the LSK, RSK, MSK dynamic assignments if:
       
   163 				//
       
   164 				// - We're still in the same view we were just in
       
   165 				// - The lsk, rsk, msk are all the same settings we set last time
       
   166 				if(currViewId == previousCBAUpdateViewId &&
       
   167 					lsk == iLastLSK && 
       
   168 					rsk == iLastRSK &&
       
   169 					msk == iLastMSK)
       
   170 				{
       
   171 					return;
       
   172 				}				
       
   173 				
       
   174 				// Save the settings
       
   175 				iLastLSK = lsk;
       
   176 				iLastRSK = rsk;
       
   177 				iLastMSK = msk;
       
   178 				
       
   179 				//
       
   180 				// Update each softkey in turn
       
   181 				// 
       
   182 				// If the CommandSetResourceDynL command assigned something to the key
       
   183 				// (in other words, it changed the key assignment from its default - it does have the option not to do so), 
       
   184 				// 
       
   185 				// Update each key now.
       
   186 				//
       
   187 				// Each derived-class view should update them as a general rule, even if it is to some default value
       
   188 				//	
       
   189 				if( lsk.IsAssigned() )
       
   190 					{
       
   191 					HBufC* txt = StringLoader::LoadLC( lsk.qtn() );
       
   192             		Cba()->SetCommandL(CEikButtonGroupContainer::ELeftSoftkeyPosition, lsk.id(), *txt);
       
   193 					CleanupStack::PopAndDestroy();  // txt
       
   194 					}
       
   195 				if( rsk.IsAssigned() )
       
   196 					{
       
   197 					HBufC* txt = StringLoader::LoadLC( rsk.qtn() );
       
   198             		Cba()->SetCommandL(CEikButtonGroupContainer::ERightSoftkeyPosition, rsk.id(), *txt);
       
   199 					CleanupStack::PopAndDestroy();  // txt
       
   200 					}
       
   201 				if( msk.IsAssigned() )
       
   202 					{
       
   203 					HBufC* txt = StringLoader::LoadLC( msk.qtn() );
       
   204             		Cba()->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition, msk.id(), *txt);
       
   205 					CleanupStack::PopAndDestroy();  // txt
       
   206 					}
       
   207 				}
       
   208 			else // Else - the exisiting case: set the softkeys as a block by assigning a pre-defined resource id
       
   209 				{
       
   210 	        	// The usual case is to set the command set to 
       
   211     	    	// whatever CommandSetResourceIdL has said
       
   212 	    	  	Cba()->SetCommandSetL( commandSet );				
       
   213 				}				
       
   214  			
       
   215  			// Save the last command set and set view id
       
   216  			iLastCommandSet = commandSet;
       
   217  			iApiProvider.SetLastCBAUpdateView(currViewId);
       
   218  			
       
   219 	   		// DrawNow() doesn't refresh MSK properly
       
   220            	Cba()->DrawDeferred();
       
   221 			}
       
   222         }    
       
   223 }
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 
       
   229 
       
   230 
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CBrowserViewBase::MakeCbaVisible
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 void CBrowserViewBase::MakeCbaVisible(TBool aVisible)
       
   237     {
       
   238     // don't turn off the cba in landscape mode since it will still be visible and
       
   239     // calling MakeVisible(EFalse) will just make it not update correctly
       
   240 
       
   241     TBool vis = aVisible;
       
   242     if (!vis)
       
   243         {
       
   244         CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
       
   245         TInt currentStatusPaneLayoutResId = 0;
       
   246         if (statusPane)
       
   247             {
       
   248             currentStatusPaneLayoutResId = statusPane->CurrentLayoutResId();
       
   249             }
       
   250         else
       
   251             {
       
   252             // If this CBA:s owner does not have statuspane, then we ask the layout from AknCapServer.
       
   253             currentStatusPaneLayoutResId = AVKONENV->StatusPaneResIdForCurrentLayout(CAknSgcClient::CurrentStatuspaneResource());
       
   254             }
       
   255 
       
   256         TBool staconPane = ((currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_RIGHT) ||
       
   257                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_USUAL_SOFTKEYS_LEFT)  ||
       
   258                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_RIGHT) ||
       
   259                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_EMPTY_SOFTKEYS_LEFT)  ||
       
   260                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_RIGHT) ||
       
   261                       (currentStatusPaneLayoutResId == R_AVKON_STACON_PANE_LAYOUT_IDLE_SOFTKEYS_LEFT));
       
   262         vis = staconPane;
       
   263         }
       
   264     Cba()->MakeVisible( vis );
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CBrowserViewBase::UpdateGotoPaneL
       
   269 // ---------------------------------------------------------
       
   270 //
       
   271 void CBrowserViewBase::UpdateGotoPaneL()
       
   272     {
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CBrowserViewBase::ClearCbaL
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 void CBrowserViewBase::ClearCbaL()
       
   280     {
       
   281     TInt commandSet = R_AVKON_SOFTKEYS_EMPTY;
       
   282     Cba()->SetCommandSetL( commandSet );
       
   283     Cba()->DrawNow();
       
   284     }
       
   285 	
       
   286 // -----------------------------------------------------------------------------
       
   287 // CBrowserContentView::LaunchSearchApplicationL
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CBrowserViewBase::LaunchSearchApplicationL( const TDesC& aSearchString )
       
   291     {
       
   292     TInt id = iApiProvider.Preferences().GetIntValue( KBrowserSearchAppUid );
       
   293     TUid searchAppId( TUid::Uid( id ) );
       
   294     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
   295     TApaTask task = taskList.FindApp( searchAppId );
       
   296     HBufC8* searchParam8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aSearchString );
       
   297     CleanupStack::PushL( searchParam8 );
       
   298     if ( task.Exists() )
       
   299         {
       
   300         User::LeaveIfError( task.SendMessage( TUid::Uid( 0 ), *searchParam8 ) );
       
   301         }
       
   302     else
       
   303         {
       
   304         RApaLsSession appArcSession;
       
   305         TApaAppInfo appInfo;
       
   306         User::LeaveIfError(appArcSession.Connect());
       
   307         CleanupClosePushL( appArcSession );
       
   308         TInt err  = appArcSession.GetAppInfo( appInfo, searchAppId );
       
   309         if( err == KErrNone )
       
   310             {
       
   311             CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   312             cmdLine->SetExecutableNameL( appInfo.iFullName );
       
   313             cmdLine->SetTailEndL( *searchParam8 );
       
   314             User::LeaveIfError( appArcSession.StartApp( *cmdLine ));
       
   315             CleanupStack::PopAndDestroy( cmdLine ); 
       
   316             }
       
   317         CleanupStack::PopAndDestroy( &appArcSession );
       
   318         }
       
   319     CleanupStack::PopAndDestroy( searchParam8 );
       
   320     } 
       
   321 // End of File