menufw/hierarchynavigator/hnengine/src/hnengine.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <uri8.h>
       
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    21 #include <sacls.h>
       
    22 #include <apgtask.h>
       
    23 #include <centralrepository.h>
       
    24 #include <AknUtils.h>
       
    25 
       
    26 #include "hnengine.h"
       
    27 #include "hnconvutils.h"
       
    28 #include "hncontrollerinterface.h"
       
    29 #include "hnfilter.h"
       
    30 #include "hnsuitemodelcontainer.h"
       
    31 #include "hnsuitemodel.h"
       
    32 #include "hnserviceglobals.h"
       
    33 #include "hnglobals.h"
       
    34 #include "hnmdsuite.h"
       
    35 #include "hnitemid.h"
       
    36 #include "hnliwutils.h"
       
    37 #include "hnrepositorymanager.h"
       
    38 #include "menudebug.h"
       
    39 #include "hnrepositorymanager.h"
       
    40 #include "hnsuiteobserver.h"
       
    41 #include "hnmdbasekey.h"
       
    42 #include "hnitemsorder.h"
       
    43 
       
    44 _LIT8(  KAnd8,                      "&" );
       
    45 _LIT8(  KEquals8,                   "=" );
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void CHnEngine::ConstructL()
       
    54     {
       
    55     iEEnv = CEikonEnv::Static();
       
    56     iSuiteContainer = CHnSuiteModelContainer::NewL( *this , iControllerInterface );
       
    57     iMetaDataModel = CHnMdModel::NewL( this, iSuiteContainer );
       
    58     iLight = CHWRMLight::NewL(this);
       
    59     iInstObserver = CHnInstallNotifier::NewL( this,
       
    60             KUidSystemCategory, KSAUidSoftwareInstallKeyValue  );
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CHnEngine* CHnEngine::NewL( MHnControllerInterface& aController )
       
    68     {
       
    69     CHnEngine* self = CHnEngine::NewLC( aController );
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CHnEngine* CHnEngine::NewLC( MHnControllerInterface& aController )
       
    79     {
       
    80     CHnEngine* self = new( ELeave ) CHnEngine( aController );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     return self;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CHnEngine::CHnEngine( MHnControllerInterface& aController ):
       
    91     iControllerInterface( aController )
       
    92     {
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CHnEngine::~CHnEngine()
       
   100     {
       
   101     delete iInstObserver;
       
   102     delete iLight;
       
   103     if( iSuiteContainer )
       
   104         {
       
   105         iSuiteContainer->RemoveLiwObjects();
       
   106         }
       
   107     delete iMetaDataModel;
       
   108     delete iSuiteContainer;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TInt CHnEngine::GetSuiteModelsCountL()
       
   116     {
       
   117     return iSuiteContainer->GetSuiteModelCount();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TBool CHnEngine::SuiteModelLoadedL( TInt aId )
       
   125     {
       
   126     TBool ret( EFalse );
       
   127     TInt count( iSuiteContainer->GetSuiteModelCount() );
       
   128     for( int i=0; i<count; i++ )
       
   129         {
       
   130         CHnSuiteModel* suite = iSuiteContainer->GetSuiteModel( i );
       
   131         if( suite->GetItemsOrder()->GetSuiteId() == aId )
       
   132             {
       
   133             ret = ETrue;
       
   134             break;
       
   135             }
       
   136         }
       
   137     return ret;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 CHnSuiteModel* CHnEngine::GetLastSuiteModelL()
       
   145     {
       
   146     return iSuiteContainer->GetLastSuiteModel();
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 CHnSuiteModel* CHnEngine::GetParentSuiteModelL()
       
   154     {
       
   155     return iSuiteContainer->GetParentSuiteModel();
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C TInt CHnEngine::TriggerHnEventL( const TInt aHnEventId,
       
   163         const TInt aRecipientId, CLiwGenericParamList* aEventParameters )
       
   164     {
       
   165     TInt ret = iSuiteContainer->OfferHnEventL( aHnEventId, aRecipientId,
       
   166             aEventParameters);
       
   167     return ret;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CHnEngine::HighlightPlacementFromUriL( const TDesC8& aUriFragment )
       
   175     {
       
   176     TLex8 lexFrag( aUriFragment );
       
   177     TInt highLight( 0 );
       
   178     if( !( lexFrag.Val( highLight ) ) )
       
   179         {
       
   180         iSuiteContainer->GetLastSuiteModel()->SetSuiteHighlightL( highLight );
       
   181         iControllerInterface.HandleSuiteEventL( ESuiteHighlightChanged,
       
   182                 iSuiteContainer->GetLastSuiteModel() );
       
   183         }
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TInt CHnEngine::LoadSuiteFromUriL( const TDesC8& aSuiteName,
       
   191         const TDesC8& aUriQuery, const TDesC8& aUriFragment )
       
   192     {
       
   193     TInt error( KErrNone );
       
   194 
       
   195     if( !( aSuiteName.Compare( KRoot8 ) ) )
       
   196         {
       
   197         CLiwGenericParamList* uriParams =
       
   198 			UriQueryToLiwListLC( aUriQuery, aUriFragment, aSuiteName );
       
   199         CLiwGenericParamList* params = CLiwGenericParamList::NewLC();
       
   200         params->AppendL( iMetaDataModel->GetSuiteParameters( 0 ) );
       
   201         params->AppendL( *uriParams );
       
   202         ResetModelsL();
       
   203         iMetaDataModel->QueueForeground( CHnMdModel::EWhenAnySuiteIsEvaluated );
       
   204         error = InitializeL( *params );
       
   205         CleanupStack::PopAndDestroy( params );
       
   206         CleanupStack::PopAndDestroy( uriParams );
       
   207         }
       
   208     else
       
   209         {
       
   210         CLiwGenericParamList* params =
       
   211 			UriQueryToLiwListLC( aUriQuery, aUriFragment, aSuiteName );
       
   212 
       
   213         HBufC* suiteName = HnConvUtils::Str8ToStrLC( aSuiteName );
       
   214         params->AppendL( TLiwGenericParam( KNewSuiteParamNameEn,
       
   215             TLiwVariant( *suiteName ) ) );
       
   216 
       
   217         error = HandleNewSuiteLoadedEventL( *params );
       
   218 
       
   219         CleanupStack::PopAndDestroy( suiteName );
       
   220         CleanupStack::PopAndDestroy( params );
       
   221         }
       
   222 
       
   223     return error;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 TBool CHnEngine::SuitesAreTheSameL( const TDesC& aLastSuiteName,
       
   231     const TDesC8& aFirstSuiteName )
       
   232     {
       
   233     RBuf8 lastSuiteName;
       
   234     CleanupClosePushL( lastSuiteName );
       
   235     lastSuiteName.CreateL( aLastSuiteName.Length() );
       
   236     lastSuiteName.Copy( aLastSuiteName );
       
   237     TBool suitesAreTheSame( !lastSuiteName.Compare( aFirstSuiteName ) );
       
   238     CleanupStack::PopAndDestroy( &lastSuiteName );
       
   239     return suitesAreTheSame;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CHnEngine::HandleTheSameSuitesL( TBool aNextExists, const TDesC8& aParams )
       
   247     {
       
   248     RBuf exitMode;
       
   249     CleanupClosePushL( exitMode );
       
   250     CLiwGenericParamList* params = UriQueryToLiwListLC( aParams, KNullDesC8, KNullDesC8 );
       
   251     HnLiwUtils::GetStringL( *params, KExitModeParams, exitMode );
       
   252 
       
   253     if ( !exitMode.Compare( KExitModeHide ) )
       
   254         {
       
   255         // set parameters
       
   256         iSuiteContainer->GetLastSuiteModel()->SetExitMode( EExitModeHide );
       
   257         }
       
   258 
       
   259     CleanupStack::PopAndDestroy( params );
       
   260     CleanupStack::PopAndDestroy( &exitMode );
       
   261 
       
   262     if ( !aNextExists )
       
   263         {
       
   264         // refresh if necessary
       
   265         iControllerInterface.NotifyUiRefreshL( ERefreshSuite );
       
   266         }
       
   267     }
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C void CHnEngine::LoadSuitesFromUriL( const TDesC8& aUri )
       
   273 	{
       
   274 	DEBUG(("_MM_:CHnEngine::LoadSuitesFromUriL IN"));
       
   275 	DEBUG8(("_MM_:\tURI: %S",&aUri));
       
   276 
       
   277 	TBool consumed(EFalse);
       
   278 
       
   279     if ( aUri.Find( KSetFocusWithPref ) != KErrNotFound )
       
   280 	    {
       
   281 	    LoadFromCrL( aUri );
       
   282 	    consumed = ETrue;
       
   283 	    }
       
   284 
       
   285     if ( !consumed )
       
   286     	{
       
   287     	consumed = HandleActionL( aUri );
       
   288     	}
       
   289 
       
   290     if ( !consumed )
       
   291     	{
       
   292     	LoadSuitesL( aUri );
       
   293     	}
       
   294 
       
   295     DEBUG(("_MM_:CHnEngine::LoadSuitesFromUriL OUT"));
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 TInt CHnEngine::HandleModelEventL( const TDesC& aEventName,
       
   303                                 CLiwGenericParamList& aParams )
       
   304     {
       
   305     TInt ret(KErrNotFound);
       
   306 
       
   307     if ( aEventName == KNewSuiteLoadedMdEvent )
       
   308         {
       
   309         // This handles new suite creation, putting its visual model
       
   310         // onto the stack eventually.
       
   311         ret = HandleNewSuiteLoadedEventL( aParams );
       
   312         }
       
   313     else if ( aEventName == KBackMdEvent )
       
   314         {
       
   315         const TDesC& suiteName = iSuiteContainer->GetLastSuiteModel()->SuiteName();
       
   316         ret = HandleBackEventL( suiteName );
       
   317         }
       
   318     else if (aEventName == KReevaluateMdEvent )
       
   319         {
       
   320         // This event triggers reevaluate on the model.
       
   321         // aParams holds liw packed filter.
       
   322         ret = HandleReevaluateEventL( aParams );
       
   323         }
       
   324     else if (aEventName == KSwitchWidgetMdEvent )
       
   325         {
       
   326         // Widget change is requested.
       
   327         ret = HandleWidgetChangeL( aParams );
       
   328         }
       
   329     else if (aEventName == KRefreshUiMdEvent )
       
   330         {
       
   331         // Refresh of the whole of the UI is refreshed
       
   332         iControllerInterface.NotifyUiRefreshL( ERefreshSuite );
       
   333         ret = KErrNone;
       
   334         }
       
   335     else if (aEventName == KRefreshToolbarMdEvent )
       
   336         {
       
   337         // Just the toolbar in UI is refreshed
       
   338         iControllerInterface.NotifyUiRefreshL( ERefreshToolbar );
       
   339         ret = KErrNone;
       
   340         }
       
   341     else if (aEventName == KStartEditModeMdEvent )
       
   342         {
       
   343         // Starting edit mode
       
   344         iControllerInterface.NotifyUiRefreshL( EStartEditMode );
       
   345         ret = KErrNone;
       
   346         }
       
   347     else if (aEventName == KStopEditModeMdEvent )
       
   348         {
       
   349         // Stopping edit mode
       
   350         iControllerInterface.NotifyUiRefreshL( EStopEditMode );
       
   351         ret = KErrNone;
       
   352         }
       
   353     else if (aEventName == KSetFocusEvent )
       
   354         {
       
   355         // SetFocus
       
   356         ret = HandleSetFocusEventL( aParams );
       
   357         }
       
   358     else if (aEventName == KAppGainForeground )
       
   359     	{
       
   360     	//force matrix gain foreground
       
   361         DEBUG(("_MM_:CHnEngine::HandleModelEventL EForegroundGain"));
       
   362         iControllerInterface.NotifyUiRefreshL( EForegroundGain );
       
   363         ret = KErrNone;
       
   364     	}
       
   365     else if (aEventName == KAppGainBackground )
       
   366     	{
       
   367     	//force matrix gain background
       
   368         DEBUG(("_MM_:CHnEngine::HandleModelEventL EBackgroundGain"));
       
   369         iControllerInterface.NotifyUiRefreshL( EBackgroundGain );
       
   370         ret = KErrNone;
       
   371     	}
       
   372 
       
   373     return ret;
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 TInt CHnEngine::HandleWidgetChangeL(
       
   381         CLiwGenericParamList& aParams )
       
   382     {
       
   383     THnSuiteWidgetType type = EChangeWidget;
       
   384     TInt pos( 0 );
       
   385     const TLiwGenericParam* param = NULL;
       
   386     param = aParams.FindFirst( pos,  KWidgetTypeAttrName8 );
       
   387     if ( pos != KErrNotFound )
       
   388         {
       
   389         TPtrC widgetType( KNullDesC );
       
   390         param->Value().Get( widgetType );
       
   391         if ( widgetType.Compare( KWidgetTypeList ) == 0 )
       
   392             type = EListWidget;
       
   393         else if ( widgetType.Compare( KWidgetTypeGrid ) == 0 )
       
   394             type = EGridWidget;
       
   395         else if ( widgetType.Compare( KWidgetTypeCoverFlow ) == 0 )
       
   396             type = ECoverFlowWidget;
       
   397         }
       
   398 
       
   399     CHnSuiteModel* model  = iSuiteContainer->GetLastSuiteModel();
       
   400     return HandleWidgetChangeL( model->SuiteName(), type );
       
   401     }
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 TInt CHnEngine::HandleWidgetChangeL( const TDesC& aSuiteName,
       
   408         THnSuiteWidgetType aType )
       
   409     {
       
   410     DEBUG(("_MM_:CMatrixMenuAppUi::HandleWidgetChangeL IN"));
       
   411     TInt ret( KErrGeneral );
       
   412 
       
   413     CHnRepositoryManager* rep = CHnRepositoryManager::NewLC();
       
   414     THnSuiteWidgetType type( EUnspecified );
       
   415     TInt err( rep->ReadSuiteWidgetTypeL( aSuiteName, type ) );
       
   416 
       
   417     if( ( !err || err == KErrNotFound ) && type != EUnspecified )
       
   418         {
       
   419         ret = rep->StoreSuiteWidgetTypeL( aSuiteName, aType );
       
   420         }
       
   421     CleanupStack::PopAndDestroy( rep );
       
   422     DEBUG(("_MM_:CMatrixMenuAppUi::HandleWidgetChangeL OUT"));
       
   423     return ret;
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 TInt CHnEngine::HandleReevaluateEventL(
       
   431         CLiwGenericParamList& aParams )
       
   432     {
       
   433     TInt ret(KErrNone);
       
   434     // Paths to retrieve filter values
       
   435     _LIT8( KGenreGlobalPath, "filter:genre");
       
   436     _LIT8( KIdGlobalPath, "filter:id");
       
   437     _LIT8( KGenrePath, "filter:[%d]/genre");
       
   438     _LIT8( KItemPath, "filter:[%d]/item");
       
   439 
       
   440     CHnFilter* filter = CHnFilter::NewLC();
       
   441 
       
   442     TLiwGenericParam param;
       
   443     param.PushL();
       
   444     aParams.AtL(0, param);
       
   445     ASSERT( !param.Name().Compare( KFilterElementItem8 ) );
       
   446 
       
   447     TLiwVariant suiteIdVariant;
       
   448     suiteIdVariant.PushL();
       
   449     TLiwVariant genreVariant;
       
   450     genreVariant.PushL();
       
   451     TInt idFound =
       
   452         HnLiwUtils::GetVariantL( aParams, KIdGlobalPath(), suiteIdVariant );
       
   453     TInt found =
       
   454         HnLiwUtils::GetVariantL(aParams, KGenreGlobalPath(), genreVariant );
       
   455     if (idFound != KErrNotFound)
       
   456         {
       
   457         filter->SetSuiteId( suiteIdVariant.AsTInt32() );
       
   458         filter->SetEvaluateSuiteL( ETrue );
       
   459         }
       
   460     else if (found != KErrNotFound && found != KErrBadDescriptor)
       
   461         {
       
   462         filter->SetSuiteNameL( genreVariant.AsDes() );
       
   463         filter->SetEvaluateSuiteL( ETrue );
       
   464         }
       
   465     else
       
   466         {
       
   467         filter->SetEvaluateSuiteL( EFalse );
       
   468         // For each entry in the fitler list....
       
   469         for ( int i=0; i< param.Value().AsList()->Count(); i++ )
       
   470             {
       
   471             RBuf8 path;
       
   472             CleanupClosePushL( path );
       
   473             path.CreateL( KGenrePath().Length() );
       
   474             path.Format( KGenrePath, i );
       
   475             TLiwVariant genreVariant;
       
   476             HnLiwUtils::GetVariantL(aParams, path, genreVariant );
       
   477             path.Close();
       
   478             path.CreateL( KItemPath().Length() );
       
   479             path.Format( KItemPath, i );
       
   480             TLiwVariant itemVariant;
       
   481             HnLiwUtils::GetVariantL(aParams, path, itemVariant );
       
   482             CleanupStack::PopAndDestroy( &path );
       
   483 
       
   484             TPtrC suiteName;
       
   485             TPtrC itemId;
       
   486             genreVariant.Get(suiteName);
       
   487             itemVariant.Get(itemId);
       
   488 
       
   489             CHnItemId* itemIdObject = CHnItemId::NewLC(suiteName, itemId);
       
   490             filter->AppendItemIdL( itemIdObject );
       
   491             CleanupStack::Pop( itemIdObject );
       
   492 
       
   493             genreVariant.Reset();
       
   494             itemVariant.Reset();
       
   495             }
       
   496         }
       
   497     CleanupStack::PopAndDestroy( &genreVariant );
       
   498     CleanupStack::PopAndDestroy( &suiteIdVariant );
       
   499     CleanupStack::PopAndDestroy( &param );
       
   500     iMetaDataModel->EvaluateL( *filter );
       
   501     CleanupStack::PopAndDestroy( filter );
       
   502     return ret;
       
   503     }
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 // ---------------------------------------------------------------------------
       
   508 //
       
   509 TInt CHnEngine::HandleBackEventL( const TDesC& aGenre, TInt aIterations )
       
   510     {
       
   511     return iMetaDataModel->HandleBackEventL(
       
   512             iSuiteContainer, aGenre, aIterations );
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 // ---------------------------------------------------------------------------
       
   518 //
       
   519 TInt CHnEngine::HandleNewSuiteLoadedEventL(
       
   520         CLiwGenericParamList& aParams )
       
   521     {
       
   522     DEBUG(("_MM_:CHnEngine::HandleNewSuiteLoadedEventL IN"));
       
   523     TInt err( KErrNone );
       
   524     const TLiwGenericParam* param =
       
   525         aParams.FindFirst( err, KNewSuiteParamNameEn );
       
   526     if( err != KErrNotFound )
       
   527         {
       
   528         TPtrC genre;
       
   529         param->Value().Get( genre );
       
   530         DEBUG16(("_MM_:\tSuite genre name: %S",&genre));
       
   531         // load and evaluate the suite
       
   532         err = iMetaDataModel->LoadSuiteL( genre, &aParams );
       
   533         if ( !err )
       
   534             {
       
   535             GetLastSuiteModelL()->RegisterSuiteObserverL( &iControllerInterface, EPriorityNull );
       
   536             CHnFilter* filter = CHnFilter::NewLC();
       
   537             filter->SetSuiteNameL( genre );
       
   538             filter->SetEvaluateSuiteL( ETrue );
       
   539             if ( iEditMode )
       
   540                 {
       
   541                 iMetaDataModel->SetModeL( EMdModeEdit );
       
   542                 }
       
   543             else
       
   544                 {
       
   545                 iMetaDataModel->SetModeL( EMdModeNormal );
       
   546                 }
       
   547 
       
   548             TRAP( err, iMetaDataModel->EvaluateL( *filter ) );
       
   549 
       
   550             CleanupStack::PopAndDestroy( filter );
       
   551             if ( err )
       
   552                 {
       
   553                 iMetaDataModel->DeleteLastSuite();
       
   554                 iSuiteContainer->PopSuiteModelL( genre );
       
   555                 }
       
   556             }
       
   557         else
       
   558             {
       
   559             // show error note to User
       
   560             HBufC* message( NULL );
       
   561             switch ( err )
       
   562                 {
       
   563                 case KErrPathNotFound :
       
   564                     {
       
   565                     message = KDebugNoteDirNotFound().AllocL();
       
   566                     }
       
   567                     break;
       
   568                 case KErrNotFound :
       
   569                     {
       
   570                     message = KDebugNoteFileNotFound().AllocL();
       
   571                     }
       
   572                     break;
       
   573                 default :
       
   574                     {
       
   575                     message = HBufC::NewL( KDebugNoteOtherError().Length() +
       
   576                                             KMaxLength );
       
   577                     message->Des().AppendFormat( KDebugNoteOtherError, err );
       
   578                     }
       
   579                     break;
       
   580                 }
       
   581             iEEnv->AlertWin( *message );
       
   582             delete message;
       
   583             }
       
   584         }
       
   585     DEBUG(("_MM_:\tReturned error code: %d",err));
       
   586     DEBUG(("_MM_:CHnEngine::HandleNewSuiteLoadedEventL OUT"));
       
   587 
       
   588     return err;
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 TInt CHnEngine::HandleSetFocusEventL( const CLiwGenericParamList& aParams  )
       
   596     {
       
   597     // Triggering event in hierarchy navigator, specifying
       
   598     // that suite given by the name genre has been
       
   599     DEBUG(("_MM_:CHnEngine::HandleSetFocusEventL IN"));
       
   600 
       
   601     TInt posSuite( 0 );
       
   602     TInt posItem( 0 );
       
   603 	TInt64 suiteCustomId( KErrNotFound );
       
   604 	TInt64 itemCustomId( KErrNotFound );
       
   605 
       
   606 	// Get suite's and item's custom ids.
       
   607 	const TLiwGenericParam* paramSuiteId = aParams.FindFirst( posSuite,  KSuiteCustomId8 );
       
   608 	const TLiwGenericParam* paramItemId = aParams.FindFirst( posItem,  KItemCustomId8 );
       
   609 
       
   610 
       
   611 	if ( posSuite >= 0 && posItem >= 0 )
       
   612     	{
       
   613     	suiteCustomId = paramSuiteId->Value().AsTInt64();
       
   614     	itemCustomId = paramItemId->Value().AsTInt64();
       
   615 
       
   616     	// Get matching suite.
       
   617     	CHnSuiteModel* suiteModel = iSuiteContainer->GetMatchingSuiteModel( suiteCustomId );
       
   618 
       
   619     	if ( suiteModel )
       
   620     		{
       
   621     		// If suite is not null, then find matching item model.
       
   622     		TInt index( KErrNotFound );
       
   623     		CHnItemModel* itemModel = suiteModel->GetMatchingItemModelL( itemCustomId, index );
       
   624 
       
   625     		if ( itemModel )
       
   626     			{
       
   627     			// If itemModel is not null then set highlight and set highligh
       
   628     			// on matching item.
       
   629     			suiteModel->SetSuiteHighlightL( index );
       
   630         		iControllerInterface.HandleSuiteEventL( ESuiteHighlightChanged, suiteModel );
       
   631     			}
       
   632     		else
       
   633     			{
       
   634     			suiteModel->QueueFocus( itemCustomId );
       
   635     			}
       
   636     		}
       
   637     	}
       
   638 
       
   639     DEBUG(("_MM_:CHnEngine::HandleSetFocusEventL OUT"));
       
   640     return KErrNone;
       
   641     }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 TInt CHnEngine::HandleMoveFocusBeforeDeleteEventL(
       
   648         const CLiwGenericParamList& /* aParams */  )
       
   649     {
       
   650     // Triggering event in hierarchy navigator, specifying
       
   651     // that suite given by the name genre has been
       
   652     DEBUG(("_MM_:CHnEngine::HandleMoveFocusBeforeDeleteEventL IN"));
       
   653 
       
   654     TInt currentHighlight( GetLastSuiteModelL()->GetSuiteHighlight() );
       
   655     TInt itemsCount( GetLastSuiteModelL()->GetItemModelsCount() );
       
   656 
       
   657     TInt shift( 0 );
       
   658     if( AknLayoutUtils::PenEnabled() && iEditMode )
       
   659         {
       
   660         // add empty item
       
   661         shift = 1;
       
   662         }
       
   663     if( currentHighlight == itemsCount - shift - 1 )
       
   664         {
       
   665         GetLastSuiteModelL()->SetSuiteHighlightL( currentHighlight - 1 );
       
   666         }
       
   667     else
       
   668         {
       
   669         GetLastSuiteModelL()->SetSuiteHighlightL( currentHighlight + 1 );
       
   670         }
       
   671     iControllerInterface.HandleSuiteEventL(
       
   672             ESuiteHighlightChanged, GetLastSuiteModelL() );
       
   673 
       
   674     DEBUG(("_MM_:CHnEngine::HandleMoveFocusBeforeDeleteEventL OUT"));
       
   675     return KErrNone;
       
   676     }
       
   677 
       
   678 // ---------------------------------------------------------------------------
       
   679 //
       
   680 // ---------------------------------------------------------------------------
       
   681 //
       
   682 TInt CHnEngine::HandleRefreshIconsEventL( const CLiwGenericParamList& /* aParams */ )
       
   683     {
       
   684     iMetaDataModel->EvaluateL();
       
   685     return KErrNone;
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 // ---------------------------------------------------------------------------
       
   691 //
       
   692 TInt CHnEngine::HandleDisableActionsForItemL( const CLiwGenericParamList& aParams )
       
   693     {
       
   694     TInt pos( 0 );
       
   695     aParams.FindFirst( pos, KItemCustomId8 );
       
   696     if ( pos != KErrNotFound )
       
   697         {
       
   698         TInt itemCustomId = aParams[pos].Value().AsTInt32();
       
   699         TInt itemId = 0;
       
   700         CHnItemModel* itemModel =
       
   701                 iSuiteContainer->GetLastSuiteModel()->GetMatchingItemModelL(
       
   702                         itemCustomId, itemId );
       
   703         if ( itemModel )
       
   704             {
       
   705             itemModel->DeleteAllActionModels();
       
   706             }
       
   707         }
       
   708     return KErrNone;
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 // ---------------------------------------------------------------------------
       
   714 //
       
   715 void CHnEngine::InstallChangeL( TInt aStatus )
       
   716     {
       
   717     switch ( aStatus)
       
   718         {
       
   719         case EInstOpNone:
       
   720             {
       
   721             iMetaDataModel->HandleSisInstallationEventL( iSuiteContainer );
       
   722             break;
       
   723             }
       
   724         case EInstOpInstall:
       
   725         case EInstOpUninstall:
       
   726             {
       
   727             iMetaDataModel->ReleaseLocalization();
       
   728             break;
       
   729             }
       
   730         }
       
   731     }
       
   732 // ---------------------------------------------------------------------------
       
   733 //
       
   734 // ---------------------------------------------------------------------------
       
   735 //
       
   736 EXPORT_C TInt CHnEngine::InitializeL( CLiwGenericParamList& aParam )
       
   737     {
       
   738     DEBUG(("_MM_:CMatrixMenuAppUi::InitializeL IN"));
       
   739     User::LeaveIfError( HandleNewSuiteLoadedEventL( aParam ) );
       
   740     DEBUG(("_MM_:CMatrixMenuAppUi::InitializeL OUT"));
       
   741     // This is an interface method so some value has to be returned.
       
   742     return KErrNone;
       
   743     }
       
   744 
       
   745 // ---------------------------------------------------------------------------
       
   746 //
       
   747 // ---------------------------------------------------------------------------
       
   748 //
       
   749 void CHnEngine::ParseSuiteUriPathL( const TDesC8& aUriPath,
       
   750         CDesC8ArrayFlat& aOutput )
       
   751     {
       
   752     DEBUG(("_MM_:CHnEngine::ParseSuiteUriPathL IN"));
       
   753     DEBUG(("_MM_:\tURI path: %S",&aUriPath));
       
   754     if ( aUriPath.Length() )
       
   755         {
       
   756         // copy the path so we can freely trim already parsed chunks
       
   757         RBuf8 buf( aUriPath.AllocL() );
       
   758         CleanupClosePushL( buf );
       
   759 
       
   760         // get rid of the initial slash
       
   761         if ( buf[0] == KSlash8()[0] )
       
   762             {
       
   763             buf.Delete( 0, 1 );
       
   764             DEBUG(("_MM_:\tDeleted leading slash"));
       
   765             }
       
   766 
       
   767         // get the first chunk
       
   768         TInt slashPos = buf.Find( KSlash8 );
       
   769         TPtrC8 chunkPtr;
       
   770         if ( slashPos != KErrNotFound )
       
   771             {
       
   772             chunkPtr.Set( buf.Left( slashPos ) );
       
   773             }
       
   774         else
       
   775             {
       
   776             // no slash - one chunk path
       
   777             chunkPtr.Set( buf );
       
   778             }
       
   779 
       
   780         while ( chunkPtr.Length() )
       
   781             {
       
   782             aOutput.AppendL( chunkPtr );
       
   783             DEBUG8(( "_MM_:\t\tParsed segment: %S", &chunkPtr ));
       
   784 
       
   785             // get rid of the parsed chunk and get a new one
       
   786             if ( slashPos != KErrNotFound )
       
   787                 {
       
   788                 // also remove the trailing slash
       
   789                 buf.Delete( 0, chunkPtr.Length() + 1 );
       
   790                 slashPos = buf.Find( KSlash8 );
       
   791                 if ( slashPos != KErrNotFound )
       
   792                     {
       
   793                     chunkPtr.Set( buf.Left( slashPos ) );
       
   794                     }
       
   795                 else
       
   796                     {
       
   797                     // last chunk
       
   798                     chunkPtr.Set( buf );
       
   799                     }
       
   800                 }
       
   801             else
       
   802                 {
       
   803                 // no slashes found, this was the last one
       
   804                 break;
       
   805                 }
       
   806             }
       
   807 
       
   808         CleanupStack::PopAndDestroy( &buf );
       
   809         }
       
   810     DEBUG(("_MM_:CHnEngine::ParseSuiteUriPathL OUT"));
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 //
       
   815 // ---------------------------------------------------------------------------
       
   816 //
       
   817 EXPORT_C void CHnEngine::ResetModelsL()
       
   818     {
       
   819     MMPERF(("CHnEngine::ResetModelsL - START"));
       
   820 
       
   821     iControllerInterface.NotifyUiRefreshL( ERemoveLiwObjects );
       
   822 
       
   823     if( iSuiteContainer )
       
   824         {
       
   825         iSuiteContainer->RemoveLiwObjects();
       
   826         }
       
   827     delete iMetaDataModel;
       
   828     iMetaDataModel = NULL;
       
   829     delete iSuiteContainer;
       
   830     iSuiteContainer = NULL;
       
   831 
       
   832     iSuiteContainer = CHnSuiteModelContainer::NewL( *this , iControllerInterface );
       
   833     MMPERF(("CHnEngine::ResetModelsL - suite container ready"));
       
   834 
       
   835     iMetaDataModel = CHnMdModel::NewL( this, iSuiteContainer );
       
   836 
       
   837     MMPERF(("CHnEngine::ResetModelsL - DONE"));
       
   838     }
       
   839 
       
   840 // ---------------------------------------------------------------------------
       
   841 //
       
   842 // ---------------------------------------------------------------------------
       
   843 //
       
   844 CLiwGenericParamList* CHnEngine::UriQueryToLiwListLC(
       
   845         const TDesC8& aUriQuery, const TDesC8& aUriFragment, const TDesC8& aSuiteName )
       
   846     {
       
   847     CLiwGenericParamList* list = CLiwGenericParamList::NewLC();
       
   848 
       
   849     CLiwDefaultMap* map = CLiwDefaultMap::NewL();
       
   850     map->PushL();
       
   851 
       
   852     RPointerArray< HBufC8 > params = SplitL( aUriQuery, KAnd8 );
       
   853 
       
   854     for( TInt i = 0; i < params.Count(); i++ )
       
   855         {
       
   856         RPointerArray< HBufC8 > paramValue = SplitL( *params[ i ], KEquals8 );
       
   857         CleanupResetAndDestroyPushL( paramValue );
       
   858         ASSERT( paramValue.Count() == 2 );
       
   859         map->InsertL( *paramValue[ 0 ], TLiwVariant( *paramValue[ 1 ] ) );
       
   860         CleanupStack::PopAndDestroy( &paramValue );
       
   861         }
       
   862 
       
   863     if ( aUriFragment.Length() > 0 && aSuiteName.Length() > 0 )
       
   864         {
       
   865         map->InsertL( KUriHighlight, TLiwVariant( aUriFragment ) );
       
   866         map->InsertL( KUriHighlightSuite, TLiwVariant( aSuiteName ) );
       
   867         }
       
   868 
       
   869     list->AppendL( TLiwGenericParam(  KParams8, TLiwVariant( map )));
       
   870 
       
   871     params.ResetAndDestroy();
       
   872     CleanupStack::PopAndDestroy( map );
       
   873 
       
   874     return list;
       
   875     }
       
   876 
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 // ---------------------------------------------------------------------------
       
   880 //
       
   881 RPointerArray< HBufC8 > CHnEngine::SplitL( const TDesC8& aSource,
       
   882         const TDesC8& aSeparator )
       
   883     {
       
   884     RPointerArray< HBufC8 > tokens;
       
   885     CleanupResetAndDestroyPushL( tokens );
       
   886 
       
   887     if ( aSource.Length() > 0 && aSeparator.Length() > 0 )
       
   888         {
       
   889         TPtrC8 tmpSource = aSource;
       
   890 
       
   891         TPtrC8 token( KNullDesC8 );
       
   892 
       
   893         while( ETrue )
       
   894             {
       
   895             TInt length = tmpSource.Find( aSeparator );
       
   896 
       
   897             if ( length >= 0 )
       
   898                 {
       
   899                 token.Set( tmpSource.Mid( 0, length ) );
       
   900                 tokens.AppendL( token.AllocL() );
       
   901                 tmpSource.Set( tmpSource.Mid( length + 1 ) );
       
   902                 }
       
   903             else
       
   904                 {
       
   905                 token.Set( tmpSource );
       
   906                 tokens.AppendL( token.AllocL() );
       
   907                 break;
       
   908                 }
       
   909             }
       
   910         }
       
   911     CleanupStack::Pop( &tokens );
       
   912     return tokens;
       
   913     }
       
   914 
       
   915 // ---------------------------------------------------------------------------
       
   916 //
       
   917 // ---------------------------------------------------------------------------
       
   918 //
       
   919 void CHnEngine::SetEditModeL( TBool aEditMode )
       
   920     {
       
   921     iEditMode = aEditMode;
       
   922     if ( aEditMode )
       
   923         {
       
   924         iMetaDataModel->SetModeL( EMdModeEdit );
       
   925         }
       
   926     else
       
   927         {
       
   928         iMetaDataModel->SetModeL( EMdModeNormal );
       
   929         }
       
   930     //The suite on top of the stack is probably displayed.
       
   931     //Switching to edit mode has some dramatic ui impact,
       
   932     //thus when parts of the suite will get displayed
       
   933     //it may look awkward thus the suite on top of the stack
       
   934     //is marked as uninitialized, therefore ui will be able to
       
   935     //react only to the ready suite model.
       
   936     if (AknLayoutUtils::PenEnabled() || (!AknLayoutUtils::PenEnabled() && iEditMode))
       
   937         {
       
   938         GetLastSuiteModelL()->GetItemsOrder()->MarkSuiteUninitialized();
       
   939         iMetaDataModel->EvaluateL();
       
   940         }
       
   941     }
       
   942 
       
   943 // ---------------------------------------------------------------------------
       
   944 //
       
   945 // ---------------------------------------------------------------------------
       
   946 //
       
   947 TBool CHnEngine::IsOnlyRootConfLoaded()
       
   948     {
       
   949     return ( iSuiteContainer &&
       
   950             iSuiteContainer->GetSuiteModelCount() == KModelCountForRoot );
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------------------------
       
   954 //
       
   955 // ---------------------------------------------------------------------------
       
   956 //
       
   957 
       
   958 EXPORT_C void CHnEngine::HandleRequestL( const CLiwGenericParamList& aParam,
       
   959                                 CLiwGenericParamList* /*aOutput*/ )
       
   960     {
       
   961     TInt pos( 0 );
       
   962     aParam.FindFirst( pos, KHnRequest );
       
   963     if (pos != KErrNotFound)
       
   964         {
       
   965         TPtrC8 command = aParam[pos].Value().AsData();
       
   966         if( command == KSetFocus )
       
   967             {
       
   968             HandleSetFocusEventL( aParam );
       
   969             }
       
   970         else if( command == KMoveFocusBeforeDelete )
       
   971             {
       
   972             HandleMoveFocusBeforeDeleteEventL( aParam );
       
   973             }
       
   974         else if( command == KRefreshIcons )
       
   975             {
       
   976             HandleRefreshIconsEventL( aParam );
       
   977             }
       
   978         else if (command == KEvaluateMdModel)
       
   979             {
       
   980             GetLastSuiteModelL()->GetItemsOrder()->MarkSuiteUninitialized();
       
   981             iMetaDataModel->EvaluateL();
       
   982             }
       
   983         else if ( command == KDisableActionsForItem )
       
   984             {
       
   985             HandleDisableActionsForItemL( aParam );
       
   986             }
       
   987         }
       
   988     }
       
   989 
       
   990 // ---------------------------------------------------------------------------
       
   991 //
       
   992 // ---------------------------------------------------------------------------
       
   993 //
       
   994 void CHnEngine::LoadFromCrL( const TDesC8& aUri )
       
   995 	{
       
   996 	HBufC8* uriBuf = HBufC8::NewLC( aUri.Length() );
       
   997 	uriBuf->Des().Copy( aUri );
       
   998 
       
   999 	TUriParser8 parser;
       
  1000 	parser.Parse( *uriBuf );
       
  1001 	User::LeaveIfError( parser.IsSchemeValid() ? KErrNone : KErrPathNotFound );
       
  1002 
       
  1003 	const TDesC8& query = parser.Extract( EUriQuery );
       
  1004     RPointerArray< HBufC8 > params = SplitL( query, HnLogicalRelations::KLogicalAnd8);
       
  1005 
       
  1006     TBuf8<KApaMaxAppGroupName + KTimeStampBufferLength + KUidStringLength + 2> item;
       
  1007 
       
  1008     for( TInt i = 0; i < params.Count(); i++ )
       
  1009         {
       
  1010         RPointerArray< HBufC8 > paramValue = SplitL( *params[ i ], HnLogicalRelations::KLogicalEqual8 );
       
  1011         CleanupResetAndDestroyPushL( paramValue );
       
  1012         ASSERT( paramValue.Count() == 2 );
       
  1013 
       
  1014         if ( !paramValue[0]->Compare(KMcsAppGroupName8) )
       
  1015         	{
       
  1016         	TBuf8<KApaMaxAppGroupName> appgrname;
       
  1017         	if( paramValue[1]->Length()<=KApaMaxAppGroupName )
       
  1018         	    {
       
  1019         	    appgrname.Append( *paramValue[1] );
       
  1020         	    }
       
  1021 
       
  1022         	//get current time
       
  1023         	TTime currentTime;
       
  1024         	currentTime.HomeTime();
       
  1025         	TDateTime date(currentTime.DateTime());
       
  1026         	item.Format(KCRepTimeFormat, &appgrname , date.Year(), date.Month(),
       
  1027         		date.Day(), date.Hour(), date.Minute(), date.Second(), date.MicroSecond());
       
  1028         	}
       
  1029         else if ( !paramValue[0]->Compare( KKeyTypeUid ) )
       
  1030         	{
       
  1031         	item.Append( KComma8 );
       
  1032             if( paramValue[1]->Length()<=KUidStringLength )
       
  1033                 {
       
  1034                 item.Append( *paramValue[1] );
       
  1035                 }
       
  1036         	}
       
  1037         CleanupStack::PopAndDestroy( &paramValue );
       
  1038         }
       
  1039 
       
  1040     TBuf<KApaMaxAppGroupName + KTimeStampBufferLength + KUidStringLength + 2> item1;
       
  1041     item1.Copy(item);
       
  1042 	CRepository *cenRep = CRepository::NewLC( KCRUidMenu );
       
  1043 	cenRep->Set(KMenuShowFolder, item1);
       
  1044 	CleanupStack::PopAndDestroy( cenRep );
       
  1045 
       
  1046     params.ResetAndDestroy();
       
  1047     CleanupStack::PopAndDestroy( uriBuf );
       
  1048 
       
  1049 	}
       
  1050 // ---------------------------------------------------------------------------
       
  1051 //
       
  1052 // ---------------------------------------------------------------------------
       
  1053 //
       
  1054 void CHnEngine::LightStatusChanged(TInt aTarget,
       
  1055         CHWRMLight::TLightStatus aStatus)
       
  1056     {
       
  1057         DEBUG(("_Mm_:CHnEngine::LightStatusChanged: target %d, status %d - IN", aTarget, aStatus));
       
  1058     if (CHWRMLight::EPrimaryDisplay == aTarget
       
  1059             || CHWRMLight::EPrimaryDisplayAndKeyboard == aTarget)
       
  1060         {
       
  1061         switch (aStatus)
       
  1062             {
       
  1063             case CHWRMLight::ELightOn:
       
  1064                 {
       
  1065                 TRAP_IGNORE( iControllerInterface.NotifyUiRefreshL(ELightOn) );
       
  1066                 break;
       
  1067                 }
       
  1068             case CHWRMLight::ELightOff:
       
  1069                 {
       
  1070                 TRAP_IGNORE( iControllerInterface.NotifyUiRefreshL(ELightOff) );
       
  1071                 break;
       
  1072                 }
       
  1073             }
       
  1074         }
       
  1075         DEBUG(("_Mm_:CMmAppUi::LightStatusChanged - OUT"));
       
  1076     }
       
  1077 
       
  1078 // ---------------------------------------------------------------------------
       
  1079 //
       
  1080 // ---------------------------------------------------------------------------
       
  1081 //
       
  1082 TBool CHnEngine::HandleActionL( const TDesC8& aUri )
       
  1083 	{
       
  1084 	TBool exitActionConsumed(EFalse);
       
  1085 
       
  1086 	HBufC8* uriBuf = HBufC8::NewLC( aUri.Length() );
       
  1087 	uriBuf->Des().Copy( aUri );
       
  1088 
       
  1089 	TUriParser8 parser;
       
  1090     parser.Parse( *uriBuf );
       
  1091     User::LeaveIfError( parser.IsSchemeValid() ? KErrNone : KErrPathNotFound );
       
  1092 
       
  1093     const TDesC8& host8 = parser.Extract( EUriHost );
       
  1094     const TDesC8& query = parser.Extract( EUriQuery );
       
  1095 
       
  1096 	RBuf action;
       
  1097     CleanupClosePushL( action );
       
  1098     CLiwGenericParamList* paramsUri = UriQueryToLiwListLC( query, KNullDesC8, KNullDesC8 );
       
  1099     HnLiwUtils::GetStringL( *paramsUri, KActionParams, action );
       
  1100 
       
  1101     if ( !action.Compare( KActionExit ) )
       
  1102     	{
       
  1103     	RBuf host;
       
  1104 		host.CreateL( host8.Length() );
       
  1105 		CleanupClosePushL( host );
       
  1106 		host.Copy(host8);
       
  1107     	CHnSuiteModel* suiteModel = iSuiteContainer->GetSuiteModel( host );
       
  1108     	TBool exitHideHostNotFound( ETrue  );
       
  1109     	if( suiteModel  && suiteModel->ExitMode() == EExitModeHide )
       
  1110     	    {
       
  1111     	    exitHideHostNotFound = EFalse;
       
  1112     	    }
       
  1113 
       
  1114 		if ( exitHideHostNotFound )
       
  1115 			{
       
  1116 			//send to foreground
       
  1117 			CLiwGenericParamList* pl = CLiwGenericParamList::NewL();
       
  1118 			CleanupStack::PushL( pl );
       
  1119 			HandleModelEventL( KAppGainForeground, *pl );
       
  1120 			CleanupStack::PopAndDestroy( pl );
       
  1121 			}
       
  1122 		else
       
  1123 			{
       
  1124 			//send to background
       
  1125 			CLiwGenericParamList* pl = CLiwGenericParamList::NewL();
       
  1126 			CleanupStack::PushL( pl );
       
  1127 			HandleModelEventL( KAppGainBackground, *pl );
       
  1128 			CleanupStack::PopAndDestroy( pl );
       
  1129 			}
       
  1130 
       
  1131     	if ( exitHideHostNotFound && iSuiteContainer->GetLastSuiteModel() == suiteModel  )
       
  1132     		{
       
  1133             HandleBackEventL( host,  1 );
       
  1134     		}
       
  1135     	else
       
  1136     		{
       
  1137         	//reset to root
       
  1138             CLiwGenericParamList* params = CLiwGenericParamList::NewLC();
       
  1139             params->AppendL( iMetaDataModel->GetSuiteParameters( 0 ) );
       
  1140         	ResetModelsL();
       
  1141             InitializeL( *params );
       
  1142             CleanupStack::PopAndDestroy( params );
       
  1143     		}
       
  1144 
       
  1145     	CleanupStack::PopAndDestroy( &host );
       
  1146     	exitActionConsumed = ETrue;
       
  1147     	}
       
  1148 
       
  1149     CleanupStack::PopAndDestroy( paramsUri );
       
  1150     CleanupStack::PopAndDestroy( &action );
       
  1151     CleanupStack::PopAndDestroy( uriBuf );
       
  1152     return exitActionConsumed;
       
  1153 	}
       
  1154 
       
  1155 // ---------------------------------------------------------------------------
       
  1156 //
       
  1157 // ---------------------------------------------------------------------------
       
  1158 //
       
  1159 void CHnEngine::LoadSuitesL( const TDesC8& aUri )
       
  1160 	{
       
  1161 	TBool sendToForeground(EFalse);
       
  1162 	HBufC8* uriBuf = HBufC8::NewLC( aUri.Length() );
       
  1163 	uriBuf->Des().Copy( aUri );
       
  1164 
       
  1165 	TUriParser8 parser;
       
  1166 	parser.Parse( *uriBuf );
       
  1167 	User::LeaveIfError( parser.IsSchemeValid() ? KErrNone : KErrPathNotFound );
       
  1168 
       
  1169 	CDesC8ArrayFlat* suiteNameArray = new( ELeave ) CDesC8ArrayFlat( KDefaultGranularity ) ;
       
  1170 	CleanupStack::PushL( suiteNameArray );
       
  1171 
       
  1172 	const TDesC8& host = parser.Extract( EUriHost );
       
  1173     RBuf8 host8;
       
  1174     CleanupClosePushL( host8 );
       
  1175     if (host.Compare( KNullDesC8 ))
       
  1176         {
       
  1177         host8.CreateL( host );
       
  1178         host8.LowerCase();
       
  1179         suiteNameArray->AppendL( host8 );
       
  1180         DEBUG8(( "_MM_:\tURI host part: %S", &host8 ));
       
  1181         }
       
  1182 
       
  1183 	const TDesC8& path = parser.Extract( EUriPath );
       
  1184 	if (path.Compare( KNullDesC8 ))
       
  1185 		{
       
  1186 		HBufC8* path8 = HBufC8::NewLC( path.Length() );
       
  1187 		path8->Des().Copy( path );
       
  1188 		path8->Des().LowerCase();
       
  1189 		ParseSuiteUriPathL( *path8, *suiteNameArray );
       
  1190 		CleanupStack::PopAndDestroy( path8 );
       
  1191 		}
       
  1192 
       
  1193 	TBool suiteExists( EFalse );
       
  1194 	iMetaDataModel->IgnoreEvaluations( ETrue );
       
  1195 	iMetaDataModel->QueueForeground( CHnMdModel::EWhenAnySuiteIsEvaluated );
       
  1196 
       
  1197     if( host8.Length() == 0 || ( host8.Length() > 0 &&
       
  1198             !iMetaDataModel->SuiteModelExistsL( host8 ) ) )
       
  1199         {
       
  1200         suiteNameArray->Reset();
       
  1201         suiteNameArray->AppendL( KRoot8 );
       
  1202         }
       
  1203 
       
  1204 	for( TInt i = 0; i < suiteNameArray->Count(); ++i )
       
  1205 		{
       
  1206 		suiteExists = iMetaDataModel->SuiteModelExistsL(
       
  1207 			( *suiteNameArray )[i] );
       
  1208 		TBool nextExists = i < suiteNameArray->Count() - 1 &&
       
  1209 			iMetaDataModel->SuiteModelExistsL( ( *suiteNameArray )[i + 1] );
       
  1210 		TBool isLast = ( i == ( suiteNameArray->Count() - 1 ) );
       
  1211 
       
  1212 		TBool turnOnEvaluation = ( suiteExists && ( !nextExists || isLast ) );
       
  1213 		if( turnOnEvaluation || !suiteExists )
       
  1214 			{
       
  1215 			iMetaDataModel->IgnoreEvaluations( EFalse );
       
  1216 			}
       
  1217 
       
  1218 		TInt err( KErrNone );
       
  1219 
       
  1220 		// Ignore loading new suite if the last suite in model is the same
       
  1221 		// as first one in the uri.
       
  1222 		if ( i == 0 )
       
  1223 			{
       
  1224 			if ( SuitesAreTheSameL( iMetaDataModel->GetLastSuite()->SuiteName(), (*suiteNameArray)[i] ) )
       
  1225 				{
       
  1226 				HandleTheSameSuitesL( nextExists, parser.Extract( EUriQuery ) );
       
  1227 				sendToForeground = ETrue;
       
  1228 				continue;
       
  1229 				}
       
  1230 			}
       
  1231 
       
  1232 		if( suiteExists )
       
  1233 			{
       
  1234 			if (!nextExists)
       
  1235 			    {
       
  1236 			    // Tricky: queue foreground so that if the suite is evaluated synchronously
       
  1237 			    // the foreground will be gained.
       
  1238 			    iMetaDataModel->QueueForeground( CHnMdModel::EWhenAnySuiteIsEvaluated );
       
  1239 			    }
       
  1240 			err = LoadSuiteFromUriL(
       
  1241 				( *suiteNameArray )[i], parser.Extract( EUriQuery ), parser.Extract( EUriFragment ) );
       
  1242 			if ( KErrNone == err && !nextExists && iMetaDataModel->IsForegroundQueued() )
       
  1243 			    {
       
  1244 			    // Tricky: if foreground is still queued it means that the suite is evaluated
       
  1245 			    // asynchronously. Override the previos foreground queue setting with one
       
  1246 			    // that will be effective only if the last loaded suite is evaluated.
       
  1247 			    iMetaDataModel->QueueForeground( CHnMdModel::EWhenCurrentTopSuiteIsEvaluated );
       
  1248 			    }
       
  1249 			if ( err != KErrNone )
       
  1250 				{
       
  1251 				sendToForeground = ETrue;
       
  1252 				}
       
  1253 			}
       
  1254 
       
  1255 		if( !suiteExists || err != KErrNone || !nextExists )
       
  1256 			{
       
  1257 			CHnFilter* filter = CHnFilter::NewLC();
       
  1258 
       
  1259 			filter->SetSuiteId(
       
  1260 				iSuiteContainer->GetLastSuiteModel()->CustomId() );
       
  1261 
       
  1262 			filter->SetEvaluateSuiteL( ETrue );
       
  1263 			iMetaDataModel->IgnoreEvaluations( EFalse );
       
  1264 
       
  1265 			TRAPD( err, iMetaDataModel->EvaluateL( *filter ) );
       
  1266 
       
  1267 			CleanupStack::PopAndDestroy( filter );
       
  1268 			if( err )
       
  1269 				{
       
  1270 				iMetaDataModel->DeleteLastSuite();
       
  1271 				iSuiteContainer->PopSuiteModelL(
       
  1272 					 HnConvUtils::Str8ToStr( ( *suiteNameArray )[i] )->Des() );
       
  1273 				sendToForeground = ETrue;
       
  1274 				}
       
  1275 			break;
       
  1276 			}
       
  1277 		}
       
  1278 
       
  1279 	// set highlight only when path is valid!
       
  1280 	if( suiteExists )
       
  1281 		{
       
  1282 		HighlightPlacementFromUriL( parser.Extract( EUriFragment ) );
       
  1283 		}
       
  1284 
       
  1285     CleanupStack::PopAndDestroy( &host8 );
       
  1286 	CleanupStack::PopAndDestroy( suiteNameArray );
       
  1287 	CleanupStack::PopAndDestroy( uriBuf );
       
  1288 
       
  1289 //    send to foreground
       
  1290 	if ( sendToForeground )
       
  1291 		{
       
  1292 		CLiwGenericParamList* pl = CLiwGenericParamList::NewL();
       
  1293 		CleanupStack::PushL( pl );
       
  1294 		HandleModelEventL( KAppGainForeground, *pl );
       
  1295 		CleanupStack::PopAndDestroy( pl );
       
  1296 		iMetaDataModel->QueueForeground( CHnMdModel::ENever );
       
  1297 		}
       
  1298 
       
  1299 	}
       
  1300 
       
  1301 // End of file