psln/Src/PslnMainView.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Main state view for Psln application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <psln.rsg>
       
    22 
       
    23 #include <eikbtgpc.h>
       
    24 #include <avkon.rsg>
       
    25 
       
    26 #include "PslnMainView.h"
       
    27 #include "PslnMainViewContainer.h"
       
    28 #include "PslnUi.h"
       
    29 
       
    30 // Framework
       
    31 #include <pslnfwplugininterface.h>
       
    32 #include "PslnPluginHandler.h"
       
    33 
       
    34 // CONSTANTS
       
    35 // Main view indexes of default plugins.
       
    36 const TInt KPslnASPluginLoc = 1;
       
    37 const TInt KPslnAIPluginLoc = 2;
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 // ---------------------------------------------------------------------------
       
    41 // Two-phased constructor.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CPslnMainView* CPslnMainView::NewLC()
       
    45     {
       
    46     CPslnMainView* self = new (ELeave) CPslnMainView();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CPslnMainView::ConstructL()
       
    57     {
       
    58     BaseConstructL( R_PSLN_MAIN_VIEW );
       
    59 
       
    60     ConstructViewArrayL();
       
    61     // Start background operation and create tabgroup.
       
    62     iPslnUi->LoadViewsWhenIdleL();
       
    63     iPslnUi->ConstructTabGroupL();
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // C++ default constructor can NOT contain any code, that might leave.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CPslnMainView::CPslnMainView()
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Destructor.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CPslnMainView::~CPslnMainView()
       
    79     {
       
    80     iViewIds.Close();
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // TUid CPslnMainView::Id()
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 TUid CPslnMainView::Id() const
       
    88     {
       
    89     return KPslnMainView2;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CPslnMainView::HandleCommandL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CPslnMainView::HandleCommandL( TInt aCommand )
       
    97     {
       
    98     switch ( aCommand )
       
    99         {
       
   100         case EPslnCmdAppOpen:
       
   101             DoActivateLocalViewL();
       
   102             break;
       
   103         // If view was launched externally, handle back as exit.
       
   104         case EAknSoftkeyBack:
       
   105         case EAknSoftkeyExit:
       
   106             aCommand = EAknCmdExit;
       
   107             //lint -fallthrough
       
   108         default:
       
   109             iPslnUi->HandleCommandL( aCommand );
       
   110             break;
       
   111         }
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CPslnMainView::ActiveView
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt CPslnMainView::ActiveView() const
       
   119     {
       
   120     return iCurrentItem;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CPslnMainView::SetActiveFolder
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CPslnMainView::SetActiveFolder( TInt aIndex )
       
   128     {
       
   129     iCurrentItem = aIndex;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CPslnMainView::ActiveFolderUid
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 TInt CPslnMainView::ActiveFolderUid()
       
   137     {
       
   138     if ( ( iCurrentItem > iViewIds.Count() )||
       
   139          ( iCurrentItem < 0 ) )
       
   140         {
       
   141         // If index is out-of-bounds, set first item active.
       
   142         iCurrentItem = 0;
       
   143         return 0;
       
   144         }
       
   145     return iViewIds[ iCurrentItem ].iUid;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CPslnMainView::SetActiveFolder
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CPslnMainView::SetActiveFolder( TUid aUid )
       
   153     {
       
   154     for ( TInt idx = 0; idx < iViewIds.Count(); idx++ )
       
   155         {
       
   156         if ( iViewIds[ idx ].iUid == aUid.iUid )
       
   157             {
       
   158             iCurrentItem = idx;
       
   159             }
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CPslnMainView::DoActivateL
       
   165 // ---------------------------------------------------------------------------
       
   166 void CPslnMainView::DoActivateL(
       
   167     const TVwsViewId& aPrevViewId,
       
   168     TUid aCustomMessageId,
       
   169     const TDesC8& aCustomMessage )
       
   170     {
       
   171     // If application is launched through NULL thread, it means that it is
       
   172     // launched as embedded application
       
   173     if ( aPrevViewId.iAppUid.iUid == KUidPsln.iUid &&
       
   174          aPrevViewId.iViewUid.iUid == KPslnGeneralView.iUid )
       
   175         {        
       
   176         MAknsSkinInstance* si = AknsUtils::SkinInstance();
       
   177         si->SetChangeEventsEnabled( EFalse );
       
   178         si->RemoveLocalItemDefs();
       
   179         si->SetChangeEventsEnabled( ETrue );
       
   180         }
       
   181 
       
   182     CPslnBaseView::DoActivateL(
       
   183         aPrevViewId,
       
   184         aCustomMessageId,
       
   185         aCustomMessage );
       
   186 
       
   187     // Set middle softkey label.
       
   188     CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   189         R_PSLN_MSK_OPEN,
       
   190         EPslnCmdAppOpen );
       
   191 
       
   192     //set highlight ,if returning from other view
       
   193     if(iContainer && aPrevViewId.iAppUid.iUid == KUidPsln.iUid)
       
   194         {
       
   195         //search which item should be highlighted
       
   196         TInt activateItem = GetListboxItemIndexByViewId(aPrevViewId);
       
   197         if(activateItem != KErrNotFound)
       
   198             {
       
   199             iContainer->SetCurrentItemIndex( activateItem );
       
   200             }
       
   201         else
       
   202             {
       
   203             iContainer->SetCurrentItemIndex( iCurrentItem );
       
   204             }
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CPslnMainView::DynInitMenuPaneL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CPslnMainView::DynInitMenuPaneL(
       
   213     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   214     {
       
   215     CPslnBaseView::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CPslnMainView::HandleListBoxSelectionL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CPslnMainView::HandleListBoxSelectionL()
       
   223     {
       
   224     HandleCommandL( EPslnCmdAppOpen );
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CPslnMainView::HandleListBoxItemHighlightL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CPslnMainView::HandleListBoxItemHighlightL()
       
   232     {    
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CPslnMainView::NewContainerL
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CPslnMainView::NewContainerL()
       
   240     {
       
   241     iContainer = new(ELeave) CPslnMainViewContainer( iPslnUi );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CPslnMainView::ConstructViewArrayL
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CPslnMainView::ConstructViewArrayL()
       
   249     {
       
   250     // First add static views.
       
   251     iViewIds.AppendL( KPslnGeneralView );
       
   252 
       
   253     TBitFlags views = iPslnUi->ViewSupport();
       
   254     if ( views.IsSet( CPslnUi::EPslnWallpaperView ) )
       
   255         {
       
   256         iViewIds.AppendL( KPslnWallpaperView );
       
   257         }
       
   258 
       
   259     if ( views.IsSet ( CPslnUi::EPslnScreensaverView ) )
       
   260         {
       
   261         iViewIds.AppendL( KPslnScreenSaverView );
       
   262         }
       
   263 
       
   264     // Then start looking for plugins.
       
   265     CArrayPtrFlat<CPslnFWPluginInterface>* array =
       
   266         iPslnUi->PluginHandler()->GetPluginArray();
       
   267     CleanupStack::PushL ( array );
       
   268     if ( array )
       
   269         {
       
   270         TBool appShellPluginInserted = EFalse;
       
   271         for ( TInt i = 0; i < array->Count(); i++ )
       
   272             {
       
   273             CAknView* view = array->At( i );
       
   274 
       
   275             // If plugin is either AS or AI, insert between static views.
       
   276             if ( view->Id().iUid == KPslnASPluginUid.iUid )
       
   277                 {
       
   278                 iViewIds.InsertL( view->Id(), KPslnASPluginLoc );
       
   279                 appShellPluginInserted = ETrue;
       
   280                 }
       
   281             else if ( view->Id().iUid == KPslnAIPluginUid.iUid )
       
   282                 {
       
   283                 if ( appShellPluginInserted )
       
   284                     {
       
   285                     iViewIds.InsertL( view->Id(), KPslnAIPluginLoc );
       
   286                     }
       
   287                 else
       
   288                     {
       
   289                     // If there is ASplugin - claim it's place.
       
   290                     // note that ASplugin maybe later inserted to this place.
       
   291                     iViewIds.InsertL( view->Id(), KPslnASPluginLoc );
       
   292                     }
       
   293                 }
       
   294             // Other plugins are just appended in order from plugin array.
       
   295             // Plugins are already ordered in PluginHandler.
       
   296             else
       
   297                 {
       
   298                 iViewIds.AppendL( view->Id() );
       
   299                 }
       
   300             }
       
   301         }
       
   302     CleanupStack::Pop( array );
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CPslnMainView::CbaExitEnabled
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 TInt CPslnMainView::CbaResourceId( const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/ )
       
   310     {
       
   311     TBool value =  iEikonEnv->StartedAsServerApp();
       
   312     return   value ? R_AVKON_SOFTKEYS_OPTIONS_BACK
       
   313         : R_AVKON_SOFTKEYS_OPTIONS_EXIT;
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // Tries to activate local view from UI class. If class is not yet
       
   318 // created, instructs UI class to create the view first.
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CPslnMainView::DoActivateLocalViewL()
       
   322     {
       
   323     if ( iContainer )
       
   324         {
       
   325         iCurrentItem = iContainer->CurrentItemIndex();
       
   326         }
       
   327     if ( iCurrentItem > iViewIds.Count() )
       
   328         {
       
   329         User::Leave( KErrOverflow );
       
   330         }
       
   331     // These views are possibly done dynamically. It is possible that due to
       
   332     // idle time, they have already been created.
       
   333     if ( iCurrentItem == KPslnGeneralView.iUid ||
       
   334          iCurrentItem == KPslnWallpaperView.iUid ||
       
   335          iCurrentItem == KPslnScreenSaverView.iUid )
       
   336         {
       
   337         iPslnUi->CreateViewL( iViewIds[ iCurrentItem ] );
       
   338         }
       
   339     iPslnUi->ActivateLocalViewL( iViewIds[ iCurrentItem ] );
       
   340     }
       
   341     
       
   342 // ---------------------------------------------------------------------------
       
   343 // Return given view's index by searching the view id
       
   344 // ---------------------------------------------------------------------------
       
   345 //
       
   346 TInt CPslnMainView::GetListboxItemIndexByViewId(const TVwsViewId& aViewId) const
       
   347     {
       
   348     TInt listBoxItemIndex = KErrNotFound;
       
   349     
       
   350     for( int i=0; i<iViewIds.Count(); i++ )
       
   351         {
       
   352         if( iViewIds[i] == aViewId.iViewUid )
       
   353             {
       
   354             listBoxItemIndex = i;
       
   355             }
       
   356         }
       
   357         
       
   358     return listBoxItemIndex;
       
   359     };
       
   360     
       
   361 //  End of File