filebrowser/src/FBToolbar.cpp
branchRCL_3
changeset 20 fad26422216a
parent 0 d6fe6244b863
equal deleted inserted replaced
19:b3cee849fa46 20:fad26422216a
       
     1 /*
       
     2 * Copyright (c) 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "FBToolbar.h"
       
    21 
       
    22 #include <aknappui.h>
       
    23 #include <akntoolbar.h>
       
    24 #include <AknsUtils.h>
       
    25 #include <aknbutton.h>
       
    26 #include <akntouchpane.h>
       
    27 #include <gulicon.h>
       
    28 #include <eikapp.h>
       
    29 #include <StringLoader.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include <layoutmetadata.cdl.h>
       
    32 #include <aknlayoutscalable_avkon.cdl.h>
       
    33 #include <aknlayoutscalable_apps.cdl.h>
       
    34 #include <filebrowser.rsg>
       
    35 #include <AknInfoPopupNoteController.h>
       
    36 
       
    37 #include "FB.hrh"
       
    38 #include "FBDocument.h"
       
    39 #include "FBModel.h"
       
    40 #include "FBFileUtils.h"
       
    41 #include "FBFileListContainer.h"
       
    42 
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CFileBrowserToolbar::NewL(const TRect& aRect)
       
    48 // EPOC two-phased constructor
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CFileBrowserToolbar* CFileBrowserToolbar::NewL(/* CAknView& aView*/ )
       
    52     {
       
    53     CFileBrowserToolbar* self = CFileBrowserToolbar::NewLC();
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CFileBrowserToolbar::NewLC()
       
    60 // Creates and leaves on failure. 
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CFileBrowserToolbar* CFileBrowserToolbar::NewLC()
       
    64     {
       
    65     CFileBrowserToolbar* self = new ( ELeave )CFileBrowserToolbar();
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();               
       
    68     return self;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CFileBrowserToolbar::~CFileBrowserToolbar()
       
    73 // removes the toolbar items when it leaves Editor/viewer plugin.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CFileBrowserToolbar::~CFileBrowserToolbar()
       
    77     {
       
    78     delete iInfoPopup;
       
    79     if ( AknLayoutUtils::PenEnabled() )
       
    80         {
       
    81         if ( iViewerToolbar )
       
    82             {
       
    83             iViewerToolbar->SetToolbarVisibility( EFalse );
       
    84             TRAP_IGNORE( iViewerToolbar->DisableToolbarL(ETrue) );
       
    85             }
       
    86         }
       
    87 
       
    88     if ( iViewerToolbar )
       
    89         {
       
    90         iViewerToolbar->HideItem( EFileBrowserCmdFileBack, ETrue, EFalse );
       
    91         iViewerToolbar->HideItem( EFileBrowserCmdFileSearch, ETrue, EFalse );
       
    92         iViewerToolbar->HideItem( EFileBrowserCmdEditSelect, ETrue, EFalse );
       
    93         }
       
    94     }
       
    95 // -----------------------------------------------------------------------------
       
    96 // CFileBrowserToolbar::CFileBrowserToolbar()
       
    97 // C++ construct function add items the toolbar.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CFileBrowserToolbar::CFileBrowserToolbar() :
       
   101     iFirstSelectionIndex( KErrNotFound ),
       
   102     iLastSelectionIndex( KErrNotFound )
       
   103     {
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CFileBrowserToolbar::ConstructL()
       
   108 // C++ construct function add items the toolbar.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CFileBrowserToolbar::ConstructL()
       
   112     {
       
   113     CAknAppUi* appUi = (CAknAppUi*)CEikonEnv::Static()->EikAppUi();
       
   114     iModel = static_cast<CFileBrowserDocument*>(appUi->Document())->Model();
       
   115 
       
   116     iViewerToolbar = appUi->CurrentFixedToolbar();
       
   117     iSelectbutton = static_cast<CAknButton*>( iViewerToolbar->ControlOrNull( EFileBrowserCmdEditSelect ) );
       
   118 
       
   119     if ( iViewerToolbar )
       
   120         {
       
   121         iShown = ETrue;
       
   122         iViewerToolbar->SetObserver( this );
       
   123         iViewerToolbar->SetToolbarObserver( this );
       
   124         iViewerToolbar->SetWithSliding( ETrue );
       
   125         iViewerToolbar->SetCloseOnAllCommands( EFalse );
       
   126         iViewerToolbar->SetFocusing( EFalse );
       
   127         }
       
   128     iInfoPopup = CAknInfoPopupNoteController::NewL();
       
   129     iInfoPopup->SetTimePopupInView(5000);
       
   130     iInfoPopup->SetTimeDelayBeforeShow(500);
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CFileBrowserToolbar::ResetState
       
   135 // Updates the toolbar 
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CFileBrowserToolbar::ResetState()
       
   139     {
       
   140     if ( AknLayoutUtils::PenEnabled() )
       
   141         {
       
   142         iSelectbutton->SetCurrentState( 0, ETrue );
       
   143         iFirstSelectionIndex = KErrNotFound;
       
   144         iLastSelectionIndex = KErrNotFound;
       
   145         }
       
   146     if ( iInfoPopup )
       
   147         {
       
   148         iInfoPopup->HideInfoPopupNote();
       
   149         }
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CFileBrowserToolbar::DynInitToolbarL
       
   154 // Initialise before the display of the toolbar
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CFileBrowserToolbar::DynInitToolbarL( TInt /*aResourceId*/, CAknToolbar* /*aToolbar*/ )
       
   158     {
       
   159     ResetState();
       
   160     iViewerToolbar->SetFocusing(EFalse);
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CFileBrowserToolbar::ShowToolbar
       
   165 // Shows the toolbar
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CFileBrowserToolbar::ShowToolbarL()
       
   169     {
       
   170     if(AknLayoutUtils::PenEnabled() )
       
   171         {
       
   172         TRAP_IGNORE( iViewerToolbar->DisableToolbarL(EFalse) );
       
   173         iViewerToolbar->SetToolbarVisibility(ETrue);
       
   174         }
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CFileBrowserToolbar::ShowToolbar
       
   179 // Hides the Toolbar
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void  CFileBrowserToolbar::HideToolbarL()
       
   183     {
       
   184     // Undim the toolbar if dimmed
       
   185     if(AknLayoutUtils::PenEnabled() )
       
   186         {
       
   187         TRAP_IGNORE( iViewerToolbar->DisableToolbarL(ETrue) );
       
   188         iViewerToolbar->SetToolbarVisibility(EFalse);
       
   189         }
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CFileBrowserToolbar::OfferToolbarEventL
       
   194 // Handling toolbar key events
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CFileBrowserToolbar::OfferToolbarEventL( TInt aCommand )
       
   198     {
       
   199     switch ( aCommand )
       
   200         {
       
   201         case EFileBrowserCmdFileBack:
       
   202             {
       
   203             iModel->FileUtils()->MoveUpOneLevelL();
       
   204             break;
       
   205             }
       
   206         case EFileBrowserCmdFileSearch:
       
   207             {
       
   208             TBool emptyListBox = iModel->FileListContainer()->ListBoxNumberOfVisibleItems() == 0;
       
   209             TBool searchFieldEnabled = iModel->FileListContainer()->IsSearchFieldEnabled();
       
   210             if ( !emptyListBox && !searchFieldEnabled )
       
   211                 {
       
   212                 iModel->FileListContainer()->EnableSearchFieldL();
       
   213                 }
       
   214             else if ( searchFieldEnabled )
       
   215                 {
       
   216                 iModel->FileListContainer()->DisableSearchFieldL();
       
   217                 }
       
   218             break;
       
   219             }
       
   220         case EFileBrowserCmdEditSelect:
       
   221             {
       
   222             TBool emptyListBox = iModel->FileListContainer()->ListBoxNumberOfVisibleItems() == 0;
       
   223             TBool driveListActive = iModel->FileUtils()->IsDriveListViewActive();
       
   224             TBool allSelected = iModel->FileListContainer()->ListBox()->SelectionIndexes()->Count() == iModel->FileListContainer()->ListBox()->Model()->NumberOfItems();
       
   225             TBool noneSelected = iModel->FileListContainer()->ListBox()->SelectionIndexes()->Count() == 0;
       
   226             
       
   227             if ( iViewerToolbar->EventModifiers() == CAknToolbar::ELongPressEnded )
       
   228                 {                
       
   229                 // handle long tap event 
       
   230                 iFirstSelectionIndex = KErrNotFound;
       
   231                 iLastSelectionIndex = KErrNotFound;
       
   232                 iSelectbutton->SetCurrentState( 0, ETrue );
       
   233 
       
   234                 if ( !( driveListActive || allSelected || emptyListBox ) )
       
   235                     {
       
   236                     AknSelectionService::HandleMarkableListProcessCommandL( EAknMarkAll, iModel->FileListContainer()->ListBox() );
       
   237                     }
       
   238                 else if ( !( driveListActive || noneSelected || emptyListBox ) )
       
   239                     {
       
   240                     AknSelectionService::HandleMarkableListProcessCommandL( EAknUnmarkAll, iModel->FileListContainer()->ListBox() );
       
   241                     }
       
   242                 }
       
   243             else if ( iViewerToolbar->EventModifiers() != CAknToolbar::ELongPress )
       
   244                 {
       
   245                 // handle single tap event
       
   246                 TBool currentSelected = iModel->FileListContainer()->ListBox()->View()->ItemIsSelected(iModel->FileListContainer()->ListBox()->View()->CurrentItemIndex());                
       
   247                 
       
   248                 if ( !( driveListActive || emptyListBox ) )
       
   249                     {
       
   250                     if ( noneSelected && iFirstSelectionIndex == KErrNotFound )
       
   251                         {
       
   252                         iLastSelectionIndex = KErrNotFound;
       
   253                         }
       
   254                     
       
   255                     if ( iFirstSelectionIndex == KErrNotFound )
       
   256                         {
       
   257                         // first item selected
       
   258                         iFirstSelectionIndex = iModel->FileListContainer()->ListBox()->CurrentItemIndex();
       
   259                         if ( currentSelected )
       
   260                             {
       
   261                             AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark, iModel->FileListContainer()->ListBox() );
       
   262                             }
       
   263                         else
       
   264                             {
       
   265                             AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iModel->FileListContainer()->ListBox() );
       
   266                             }
       
   267                         // Toolbar button updates its state (icon)
       
   268                         iInfoPopup->SetTextL( _L("Select the last item.") );
       
   269                         iInfoPopup->ShowInfoPopupNote();
       
   270                         }
       
   271                     else
       
   272                         {
       
   273                         iInfoPopup->HideInfoPopupNote();
       
   274                         iLastSelectionIndex = iModel->FileListContainer()->ListBox()->CurrentItemIndex();
       
   275                         if ( iLastSelectionIndex == iFirstSelectionIndex )
       
   276                             {
       
   277                             // the same item selected second time
       
   278                             iFirstSelectionIndex = KErrNotFound;
       
   279                             iLastSelectionIndex = KErrNotFound;
       
   280                             if ( currentSelected )
       
   281                                 {
       
   282                                 AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark, iModel->FileListContainer()->ListBox() );
       
   283                                 }
       
   284                             else
       
   285                                 {
       
   286                                 AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iModel->FileListContainer()->ListBox() );
       
   287                                 }
       
   288                             // Toolbar button updates its state (icon)
       
   289                             }
       
   290                         else
       
   291                             {
       
   292                             // the last item selected, toggle the item selection between first and last 
       
   293                             TInt skipFirstToggle(1);
       
   294                             TInt skipLastToggle(0);
       
   295                             TInt finalFocus = iLastSelectionIndex;
       
   296                             if ( iFirstSelectionIndex > iLastSelectionIndex )
       
   297                                 {
       
   298                                 TInt tmp = iFirstSelectionIndex;
       
   299                                 iFirstSelectionIndex = iLastSelectionIndex;
       
   300                                 iLastSelectionIndex = tmp;
       
   301                                 skipFirstToggle = 0;
       
   302                                 skipLastToggle = 1;
       
   303                                 }
       
   304                             for ( TInt i = iFirstSelectionIndex+skipFirstToggle; i <= iLastSelectionIndex-skipLastToggle ; i++ )
       
   305                                 {
       
   306                                 iModel->FileListContainer()->ListBox()->SetCurrentItemIndexAndDraw( i );
       
   307                                 TBool itemSelected = iModel->FileListContainer()->ListBox()->View()->ItemIsSelected(iModel->FileListContainer()->ListBox()->View()->CurrentItemIndex());
       
   308                                 if ( itemSelected )
       
   309                                     {
       
   310                                     TRAP_IGNORE( AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdUnmark, iModel->FileListContainer()->ListBox() ) );
       
   311                                     }
       
   312                                 else
       
   313                                     {
       
   314                                     TRAP_IGNORE( AknSelectionService::HandleMarkableListProcessCommandL( EAknCmdMark, iModel->FileListContainer()->ListBox() ) );
       
   315                                     }
       
   316                                 }
       
   317                             iFirstSelectionIndex = KErrNotFound;
       
   318                             iLastSelectionIndex = KErrNotFound;
       
   319                             iModel->FileListContainer()->ListBox()->SetCurrentItemIndexAndDraw( finalFocus );
       
   320                             // Toolbar button updates its state (icon)
       
   321                             }
       
   322                         }
       
   323                     }
       
   324                 else
       
   325                     {
       
   326                     iSelectbutton->SetCurrentState( 0, ETrue );
       
   327                     }
       
   328                 }
       
   329             break;
       
   330             }
       
   331         default:
       
   332             {
       
   333             break;
       
   334             }
       
   335         }
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CFileBrowserToolbar::HandleControlEventL
       
   340 // Handles toolbar event cannot contain any code
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CFileBrowserToolbar::HandleControlEventL( CCoeControl* /*aControl*/,
       
   344                                                TCoeEvent /*aEventType*/ )
       
   345     {
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CFileBrowserToolbar::IsShown
       
   350 // Returns whether the toolbar is shown or not
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 TBool CFileBrowserToolbar::IsShown()
       
   354     {
       
   355     return iShown;
       
   356     }   
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // CFileBrowserToolbar::Rect
       
   360 // 
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 const TRect CFileBrowserToolbar::Rect() const
       
   364     {
       
   365     return iViewerToolbar->Rect();
       
   366     }
       
   367 
       
   368 // End of File
       
   369