photosgallery/commonui/src/glxnavigationalstate.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Navigational state of the app
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxnavigationalstate.h"
       
    22 
       
    23 #include <glxassert.h>
       
    24 #include <glxsingletonstore.h>
       
    25 #include <mpxcollectionobserver.h>
       
    26 #include <mpxcollectionmessage.h>
       
    27 #include <mpxcollectionpath.h>
       
    28 #include <mpxcollectionutility.h>
       
    29 #include <mpxmessagegeneraldefs.h>
       
    30 #include <mpxviewutility.h> // MMPXViewUtility
       
    31 #include "mglxnavigationalstateobserver.h"
       
    32 #include <eikappui.h>
       
    33 #include <eikenv.h>
       
    34 
       
    35 #include <glxtracer.h>
       
    36 
       
    37 #include <glxlog.h>
       
    38 
       
    39  /**
       
    40  * CGlxNavigationalStateImp
       
    41  *
       
    42  * Implementation of navigational state
       
    43  * Note: function entry-exit logging is in CGlxNavigationalState, 
       
    44  * not in CGlxNavigationalStateImp.
       
    45  *
       
    46  * @author Aki Vanhatalo
       
    47  */
       
    48 class CGlxNavigationalStateImp : public CBase, public MMPXCollectionObserver
       
    49     {
       
    50 public:
       
    51     /** 
       
    52      * Second-phase constructor 
       
    53      * inlined since used only once from CGlxNavigationalState
       
    54      */
       
    55     inline void ConstructL()
       
    56         {
       
    57         iCollectionUtility = MMPXCollectionUtility::NewL( this );
       
    58         iViewUtility = MMPXViewUtility::UtilityL(); 
       
    59         iViewingMode = NGlxNavigationalState::EBrowse;
       
    60         }
       
    61         
       
    62     /** Destructor */
       
    63     ~CGlxNavigationalStateImp()
       
    64         {
       
    65         GLX_LOG_ENTRY_EXIT( "CGlxNavigationalStateImp::~CGlxNavigationalStateImp");
       
    66         if ( iCollectionUtility )
       
    67             {
       
    68             iCollectionUtility->Close();
       
    69             }
       
    70         
       
    71         if ( iViewUtility )
       
    72             {
       
    73             iViewUtility->Close();
       
    74             }
       
    75         // Log a warning if observers remaining; they should have been removed by the client
       
    76         __ASSERT_DEBUG( !iObservers.Count(), 
       
    77             GLX_LOG_WARNING1( "CGlxNavigationalStateImp - %d observers not removed", iObservers.Count() ) );
       
    78 
       
    79         iObservers.Close();
       
    80         }
       
    81     
       
    82     /**
       
    83      * Add an observer
       
    84      * inlined since used only once from CGlxNavigationalState
       
    85      * @param aObserver Observer of changes to state
       
    86      */
       
    87     inline void AddObserverL( MGlxNavigationalStateObserver& aObserver )
       
    88         {
       
    89         GLX_LOG_INFO1("CGlxNavigationalStateImp::AddObserverL %x", &aObserver);
       
    90         __ASSERT_DEBUG( KErrNotFound == iObservers.Find( &aObserver ), 
       
    91             GLX_LOG_WARNING( "CGlxNavigationalStateImp - Observer already added" ) );
       
    92 
       
    93         // Add the observer, unless already added
       
    94         if ( KErrNotFound == iObservers.Find( &aObserver ) )
       
    95             {
       
    96             iObservers.AppendL( &aObserver );
       
    97             }
       
    98         }
       
    99     
       
   100     /**
       
   101      * Remove an observer
       
   102      * inlined since used only once from CGlxNavigationalState
       
   103      * @param aObserver Observer to remove
       
   104      */
       
   105     inline void RemoveObserver( MGlxNavigationalStateObserver& aObserver )
       
   106         {
       
   107         GLX_LOG_INFO1("CGlxNavigationalStateImp::RemoveObserver %x", &aObserver);
       
   108 
       
   109         // Remove the observer if exists
       
   110         TInt index = iObservers.Find( &aObserver );
       
   111         if ( KErrNotFound != index )
       
   112             {
       
   113             iObservers.Remove( index );
       
   114             }
       
   115 
       
   116         __ASSERT_DEBUG( KErrNotFound != index, 
       
   117             GLX_LOG_WARNING( "CGlxNavigationalStateImp - No such observer to remove" ) );
       
   118         }
       
   119 
       
   120     /**
       
   121      * @return the current navigational state. Caller gets ownership.
       
   122      */
       
   123     CMPXCollectionPath* StateLC() const 
       
   124         {
       
   125         GLX_LOG_ENTRY_EXIT("CGlxNavigationalStateImp::StateLC");
       
   126         
       
   127         // state is stored in the collection utility as a collection path
       
   128         CMPXCollectionPath* state = Collection().PathL();
       
   129         CleanupStack::PushL( state );
       
   130         
       
   131         // go up one level in hierarchy, since the path contains also the 
       
   132         // currently open level, not only the nodes to the level
       
   133         state->Back();
       
   134         
       
   135         return state;
       
   136         }
       
   137     
       
   138     /**
       
   139      * Navigate back in the UI hierarchy
       
   140      * Does nothing, if currently at root.
       
   141      */
       
   142     inline void NavigateToParentL()
       
   143         {
       
   144         if ( ViewingMode()== NGlxNavigationalState::EView )
       
   145             {
       
   146             iViewingMode = NGlxNavigationalState::EBrowse;
       
   147             //Collection().BackL(); // added by gopakumar
       
   148             NotifyObserversOfStateChange();
       
   149             }
       
   150         else 
       
   151             {
       
   152             Collection().BackL();
       
   153             }
       
   154         }
       
   155     
       
   156     /**
       
   157      * Navigate forward to provided item
       
   158      * @param aItemToOpen Id of item to navigate to
       
   159      */
       
   160     void NavigateToChildL( const TGlxMediaId& aItemIdToOpen )
       
   161         {
       
   162         // there is no way to open MPX collection utility's current state with 
       
   163         // and id of a child item, so create a full path object and add the 
       
   164         // requested item's id as the new level
       
   165         iViewingMode = NGlxNavigationalState::EBrowse;
       
   166         CMPXCollectionPath* state = StateLC();
       
   167         state->AppendL( aItemIdToOpen.Value() );
       
   168         
       
   169         NavigateToL( *state );
       
   170         
       
   171         CleanupStack::PopAndDestroy( state );      
       
   172         }
       
   173     
       
   174     /**
       
   175      * Navigate to provided position in hierarchy
       
   176      * @param aNewState Path object which describes the new position in hierarchy
       
   177      */
       
   178     inline void NavigateToL( const CMPXCollectionPath& aNewState )
       
   179         {
       
   180         // (it does not matter that the root level is opened without 
       
   181         // gallery plugin filter (EGlxCollectionPluginGallery), as long as 
       
   182         // the root level is *rendered* with something that uses the filter, 
       
   183         // such as a media list)
       
   184         if(!iIsNavigating)
       
   185             {
       
   186         iViewingMode = NGlxNavigationalState::EBrowse;
       
   187         Collection().OpenL( aNewState );
       
   188             iIsNavigating = ETrue;
       
   189             }
       
   190         }
       
   191        
       
   192     // commented off by gopakumar , as this is no longer needed .    
       
   193     /**
       
   194     * Set the ID of the view that will be activated if there are no other
       
   195     * view's in the view history
       
   196     */
       
   197     /*inline void SetFirstViewId( TVwsViewId aViewId )
       
   198         {
       
   199         // Save the view Id
       
   200         iViewId = aViewId;
       
   201         }*/
       
   202 
       
   203     /**
       
   204     * Activate previous view
       
   205     */
       
   206     inline void ActivatePreviousViewL()
       
   207         {
       
   208         iViewingMode = NGlxNavigationalState::EBrowse;
       
   209         //go back one view
       
   210         if ( iViewUtility->ViewHistoryDepth() > 1 )
       
   211             {
       
   212             iViewUtility->ActivatePreviousViewL();
       
   213             
       
   214             }
       
   215         }
       
   216      
       
   217 
       
   218     // From MMPXCollectionObserver
       
   219     void HandleCollectionMessageL( const CMPXMessage& aMessage )
       
   220         {
       
   221         TRACER( "CGlxNavigationalStateImp::HandleCollectionMessageL" );
       
   222         
       
   223         if ( IsPathChangedMessage( aMessage ) )
       
   224             {
       
   225             NotifyObserversOfStateChange();
       
   226             iIsNavigating = EFalse;
       
   227             }
       
   228         }
       
   229         
       
   230     // From MMPXCollectionObserver
       
   231     void HandleOpenL( const CMPXMedia& /*aEntries*/, TInt /*aIndex*/, 
       
   232             TBool /*aComplete*/, TInt /*aError*/ )
       
   233         {
       
   234         // do nothing
       
   235         }
       
   236         
       
   237     // From MMPXCollectionObserver
       
   238     void HandleOpenL( const CMPXCollectionPlaylist& /*aPlaylist*/, TInt /*aError*/ )    
       
   239         {
       
   240         // do nothing
       
   241         }
       
   242         
       
   243     // From MMPXCollectionObserver
       
   244     void HandleCollectionMediaL( const CMPXMedia& /*aMedia*/, TInt /*aError*/ )
       
   245         {
       
   246         // do nothing
       
   247         }
       
   248     void SetToViewMode()
       
   249         {
       
   250          iViewingMode = NGlxNavigationalState::EView;
       
   251          // inform the observers( only appui!! ) that the mode is view
       
   252          NotifyObserversOfStateChange();
       
   253          
       
   254         }
       
   255     NGlxNavigationalState::TViewingMode ViewingMode()
       
   256         {
       
   257          return iViewingMode;
       
   258         }
       
   259 
       
   260 private:
       
   261     /** Notify observers of state change */
       
   262     inline void NotifyObserversOfStateChange()
       
   263         {
       
   264         GLX_LOG_ENTRY_EXIT( "CGlxNavigationalStateImp::NotifyObserversOfStateChange" );
       
   265         // iObservers::Count() used in loop: ok, since unlikely to have many observers
       
   266         for ( TInt i = 0; i < iObservers.Count(); i++ ) 
       
   267             {
       
   268             iObservers[ i ]->HandleNavigationalStateChangedL();
       
   269             }
       
   270         }
       
   271         
       
   272     /** @return MPX collection */
       
   273     inline MMPXCollection& Collection() const
       
   274         {
       
   275         return iCollectionUtility->Collection();
       
   276         }
       
   277 
       
   278     /**
       
   279      * @param aMessage message to test
       
   280      * @return ETrue if the message is a "path changed" message 
       
   281      */
       
   282     inline TBool IsPathChangedMessage( const CMPXMessage& aMessage )
       
   283         {
       
   284         // message is a "path changed" message if message id is KMPXMessageGeneral
       
   285         // and KMPXMessageGeneralEvent attribute is EPathChanged
       
   286         return ( aMessage.IsSupported(KMPXMessageGeneralId ) 
       
   287               && KMPXMessageGeneral == aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralId ) 
       
   288               && aMessage.IsSupported( KMPXMessageGeneralEvent )
       
   289               && TMPXCollectionMessage::EPathChanged == aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
   290         }
       
   291     
       
   292 private:
       
   293     /// Collection utility that stores the path to represent current navigational
       
   294     /// state
       
   295     MMPXCollectionUtility* iCollectionUtility;
       
   296     MMPXViewUtility*        iViewUtility; 
       
   297     NGlxNavigationalState::TViewingMode  iViewingMode; 
       
   298     // commented off by gopakumar as this is not used anymore
       
   299    // TVwsViewId   iViewId;
       
   300     /// List of observers
       
   301     RPointerArray< MGlxNavigationalStateObserver > iObservers;
       
   302     
       
   303     TBool iIsNavigating; // If ETrue it means Navigating is already happening, so not allowed to navigate before current navigation Completes.
       
   304                          // If EFalse it means Navigation can happen   
       
   305     
       
   306     };
       
   307     
       
   308 // -----------------------------------------------------------------------------
       
   309 // InstanceL
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 EXPORT_C CGlxNavigationalState* CGlxNavigationalState::InstanceL()
       
   313     {
       
   314     GLX_LOG_INFO( "CGlxNavigationalState::InstanceL" );
       
   315     return CGlxSingletonStore::InstanceL( &NewL );
       
   316     }
       
   317     
       
   318 // -----------------------------------------------------------------------------
       
   319 // NewL
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 CGlxNavigationalState* CGlxNavigationalState::NewL()
       
   323     {
       
   324     GLX_LOG_INFO( "CGlxNavigationalState::NewL" );
       
   325     CGlxNavigationalState* self = new ( ELeave ) CGlxNavigationalState;
       
   326     CleanupStack::PushL( self );
       
   327 
       
   328     // Construct implementation object
       
   329     self->iImp = new ( ELeave ) CGlxNavigationalStateImp;
       
   330     self->iImp->ConstructL();
       
   331 
       
   332     CleanupStack::Pop( self );
       
   333     return self;
       
   334     }
       
   335     
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // Destructor
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 CGlxNavigationalState::~CGlxNavigationalState()
       
   342     {
       
   343     delete iImp;
       
   344     }
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // Close a reference
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 EXPORT_C void CGlxNavigationalState::Close()
       
   351     {
       
   352     GLX_LOG_ENTRY_EXIT( "CGlxNavigationalState::Close");
       
   353 
       
   354     // Decrease reference count, and delete if last one
       
   355     CGlxSingletonStore::Close( this );
       
   356     // Member variable access not safe after CGlxSingletonStore::Close()
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // Close a reference
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 EXPORT_C void CGlxNavigationalState::AddObserverL(  
       
   364         MGlxNavigationalStateObserver& aObserver )
       
   365     {
       
   366     GLX_LOG_INFO1( "CGlxNavigationalState::AddObserverL %x", &aObserver );
       
   367     iImp->AddObserverL( aObserver );
       
   368     }
       
   369     
       
   370 // -----------------------------------------------------------------------------
       
   371 // Close a reference
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 EXPORT_C void CGlxNavigationalState::RemoveObserver( 
       
   375         MGlxNavigationalStateObserver& aObserver )
       
   376     {
       
   377     GLX_LOG_INFO1( "CGlxNavigationalState::RemoveObserver %x", &aObserver );
       
   378     iImp->RemoveObserver( aObserver );
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // Close a reference
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 EXPORT_C CMPXCollectionPath* CGlxNavigationalState::StateLC() const
       
   386     {
       
   387     GLX_LOG_ENTRY_EXIT( "CGlxNavigationalState::StateLC" );
       
   388     return iImp->StateLC();
       
   389     }
       
   390     
       
   391 // -----------------------------------------------------------------------------
       
   392 // Navigate to parent item
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 EXPORT_C void CGlxNavigationalState::NavigateToParentL()
       
   396     {
       
   397     GLX_LOG_ENTRY_EXIT( "CGlxNavigationalState::NavigateToParentL" );
       
   398     iImp->NavigateToParentL();
       
   399     }
       
   400     
       
   401 // -----------------------------------------------------------------------------
       
   402 // Navigate to a child item
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 EXPORT_C void CGlxNavigationalState::NavigateToChildL( 
       
   406         const TGlxMediaId& aItemIdToOpen )
       
   407     {
       
   408    // GLX_LOG_INFO1( "CGlxNavigationalState::NavigateToChildL %d", aItemIdToOpen.Value() );
       
   409     iImp->NavigateToChildL( aItemIdToOpen );
       
   410     }
       
   411     
       
   412 // -----------------------------------------------------------------------------
       
   413 // Navigate to a path
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 EXPORT_C void CGlxNavigationalState::NavigateToL( const CMPXCollectionPath& aState )
       
   417     {
       
   418     GLX_LOG_ENTRY_EXIT( "CGlxNavigationalState::NavigateToL");
       
   419     iImp->NavigateToL( aState );
       
   420     }
       
   421     
       
   422 // -----------------------------------------------------------------------------
       
   423 // Activate previous view
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 EXPORT_C void CGlxNavigationalState::ActivatePreviousViewL() 
       
   427     {
       
   428     GLX_LOG_ENTRY_EXIT( "CGlxNavigationalState::ActivatePreviousViewL");
       
   429     iImp->ActivatePreviousViewL();
       
   430     }
       
   431     
       
   432 EXPORT_C void CGlxNavigationalState::SetToViewMode()
       
   433     {
       
   434      iImp->SetToViewMode();
       
   435      // inform the observers( only appui!! ) that the mode is view
       
   436     }
       
   437     
       
   438 EXPORT_C  NGlxNavigationalState::TViewingMode CGlxNavigationalState::ViewingMode()
       
   439     {
       
   440      return iImp->ViewingMode();
       
   441     }
       
   442 
       
   443  
       
   444 EXPORT_C void CGlxNavigationalState::SetBackExitStatus(TBool aStatus)
       
   445     {
       
   446     iBackExitStatus = aStatus;
       
   447     }
       
   448 
       
   449 EXPORT_C TBool CGlxNavigationalState::BackExitStatus()
       
   450     {
       
   451     return iBackExitStatus;
       
   452     }
       
   453 
       
   454 // EOF