homesync/contentmanager/mediaservant/src/msfillcontainer.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 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:  CMSFillContainer class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknIconArray.h>
       
    20 #include <aknlists.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <eikclbd.h>
       
    23 #include <mediaservant.rsg>
       
    24 #include <mediaservant.mbg>
       
    25 #include <StringLoader.h>
       
    26 #include <avkon.mbg>
       
    27 #include <aknlistquerydialog.h>
       
    28 #include "upnpstring.h"
       
    29 #include <e32math.h>
       
    30 
       
    31 #include "cmdriveinfo.h"
       
    32 #include "mserv.hlp.hrh"
       
    33 #include "cmfillrule.h"
       
    34 #include "msfillview.h"
       
    35 #include "msappui.h"
       
    36 #include "mediaservantuid.h"
       
    37 #include "msengine.h"
       
    38 #include "msfillcontainer.h"
       
    39 #include "msconstants.h"
       
    40 #include "msdebug.h"
       
    41 
       
    42 // CONSTANTS
       
    43 
       
    44 // Listbox granularity
       
    45 const TInt KListGranularity = 5;
       
    46 
       
    47 // --------------------------------------------------------------------------
       
    48 // CMSFillContainer::CMSFillContainer()
       
    49 // --------------------------------------------------------------------------
       
    50 //
       
    51 CMSFillContainer::CMSFillContainer( CMSAppUi& aAppUi, CMSFillView& aView ) :
       
    52     iMSAppUi( aAppUi ),
       
    53     iView( aView )
       
    54     {
       
    55     LOG(_L("[MediaServant]\t CMSFillContainer::CMSFillContainer"));
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CMSFillContainer::~CMSFillContainer()
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 CMSFillContainer::~CMSFillContainer()
       
    63     {
       
    64     LOG(_L("[MediaServant]\t CMSFillContainer::~CMSFillContainer"));
       
    65 
       
    66     iSelectedLists.Close();
       
    67 
       
    68     iView.ClearCurrentNaviPaneText();
       
    69 
       
    70     delete iListBox; // Deletes listbox object.
       
    71 
       
    72     }
       
    73 
       
    74 // --------------------------------------------------------------------------
       
    75 // CMSFillContainer::ConstructL()
       
    76 // --------------------------------------------------------------------------
       
    77 //
       
    78 void CMSFillContainer::ConstructL( TRect aRect )
       
    79     {
       
    80     LOG(_L("[MediaServant]\t CMSFillContainer::ConstructL"));
       
    81 
       
    82     // fill quota size
       
    83     CalculateFillQuotaL();
       
    84 
       
    85     CreateWindowL();
       
    86 
       
    87     iListBox = new (ELeave) CAknSingleGraphicStyleListBox;
       
    88 
       
    89     // This is multiselection listbox but resource defines it as SELECTION
       
    90     // LIST because we don't want to let framework handle icon changes.
       
    91     // Framework toggles between two icons whereas we have to show multiple
       
    92     // icons.
       
    93     // Special icons are changed every time item selection or priority
       
    94     // changes. Calculations for icons are made in SetIcon()
       
    95     SetListBoxFromResourceL(iListBox, R_FILL_VIEW_LISTBOX);
       
    96 
       
    97     // Create icons
       
    98     CAknIconArray* icons = new (ELeave) CAknIconArray( EIconCount );
       
    99     CleanupStack::PushL( icons );
       
   100     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   101 
       
   102     // selected and fits icon
       
   103     AppendIconToArrayL( icons, skin,
       
   104                         KMSMifFileName,
       
   105                         KAknsIIDDefault,
       
   106                         EMbmMediaservantQgn_mserv_white_check,
       
   107                         EMbmMediaservantQgn_mserv_white_check_mask );
       
   108 
       
   109     // unselected and fits icon
       
   110     AppendIconToArrayL( icons, skin,
       
   111                         KMSMifFileName,
       
   112                         KAknsIIDDefault,
       
   113                         EMbmMediaservantQgn_mserv_white_uncheck,
       
   114                         EMbmMediaservantQgn_mserv_white_uncheck_mask );
       
   115 
       
   116     // selected and partially fits icon
       
   117     AppendIconToArrayL( icons, skin,
       
   118                         KMSMifFileName,
       
   119                         KAknsIIDDefault,
       
   120                         EMbmMediaservantQgn_mserv_yellow_check,
       
   121                         EMbmMediaservantQgn_mserv_yellow_check_mask );
       
   122 
       
   123     // unselected and partially fits icon
       
   124     AppendIconToArrayL( icons, skin,
       
   125                         KMSMifFileName,
       
   126                         KAknsIIDDefault,
       
   127                         EMbmMediaservantQgn_mserv_yellow_uncheck,
       
   128                         EMbmMediaservantQgn_mserv_yellow_uncheck_mask );
       
   129 
       
   130     // selected and doesn't fit icon
       
   131     AppendIconToArrayL( icons, skin,
       
   132                         KMSMifFileName,
       
   133                         KAknsIIDDefault,
       
   134                         EMbmMediaservantQgn_mserv_red_check,
       
   135                         EMbmMediaservantQgn_mserv_red_check_mask );
       
   136 
       
   137     // unselected and doesn't fit icon
       
   138     AppendIconToArrayL( icons, skin,
       
   139                         KMSMifFileName,
       
   140                         KAknsIIDDefault,
       
   141                         EMbmMediaservantQgn_mserv_red_uncheck,
       
   142                         EMbmMediaservantQgn_mserv_red_uncheck_mask );
       
   143     // video type -icon
       
   144     AppendIconToArrayL( icons, skin,
       
   145                         KMSMifFileName,
       
   146                         KAknsIIDDefault,
       
   147                         EMbmMediaservantQgn_mserv_video_list_small,
       
   148                         EMbmMediaservantQgn_mserv_video_list_small_mask );
       
   149 
       
   150     // image type -icon
       
   151     AppendIconToArrayL( icons, skin,
       
   152                         KMSMifFileName,
       
   153                         KAknsIIDDefault,
       
   154                         EMbmMediaservantQgn_mserv_image_list_small,
       
   155                         EMbmMediaservantQgn_mserv_image_list_small_mask );
       
   156 
       
   157     // music type -icon
       
   158     AppendIconToArrayL( icons, skin,
       
   159                         KMSMifFileName,
       
   160                         KAknsIIDDefault,
       
   161                         EMbmMediaservantQgn_mserv_music_list_small,
       
   162                         EMbmMediaservantQgn_mserv_music_list_small_mask );
       
   163 
       
   164     // mark icon for reordering mode -icon
       
   165     AppendIconToArrayL( icons, skin,
       
   166                         KAvkonMifFileName,
       
   167                         KAknsIIDDefault,
       
   168                         EMbmAvkonQgn_indi_marked_add,
       
   169                         EMbmAvkonQgn_indi_marked_add_mask );
       
   170 
       
   171     iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   172     CleanupStack::Pop(icons);
       
   173 
       
   174 
       
   175     // Create icon for context pane
       
   176     AknsUtils::CreateIconL( skin,
       
   177                             KAknsIIDDefault,
       
   178                             iIcon,
       
   179                             iIconMask,
       
   180                             KMSMifFileName,
       
   181                             EMbmMediaservantQgn_mserv_from_home,
       
   182                             EMbmMediaservantQgn_mserv_from_home_mask);
       
   183     // change context icon
       
   184     SetContextPaneIconL( iIcon, iIconMask );
       
   185 
       
   186     SetRect(aRect);
       
   187 
       
   188     // Get rule controller
       
   189     iFillRuleController = iMSAppUi.FillRuleController();
       
   190     // Update array
       
   191     iFillRuleController->UpdateArrayL();
       
   192     // get fill lists
       
   193     iFillListArray = iFillRuleController->FillListArray();
       
   194     // keep selections safe
       
   195     iSelectedIndexes = iListBox->SelectionIndexes();
       
   196 
       
   197     TInt64 capasity;
       
   198     TInt64 free;
       
   199     iMSAppUi.ReadMMCInfoL( capasity, free );
       
   200     iFreeMemory = Min( free, iQuota );
       
   201 
       
   202     if ( iFillListArray->Count() > 0 )
       
   203         {
       
   204         // Add data to listbox
       
   205         UpdateListBoxDataL();
       
   206 
       
   207         // Enable text scrolling
       
   208         iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   209 
       
   210         // get item array
       
   211         CDesCArray* itemArray = static_cast<CDesCArray*>
       
   212                                 (iListBox->Model()->ItemTextArray());
       
   213 
       
   214         iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
   215         }
       
   216 
       
   217     // keep selections safe
       
   218     const CListBoxView::CSelectionIndexArray* selected =
       
   219                                             iListBox->SelectionIndexes();
       
   220 
       
   221     for ( TInt index = 0; index < selected->Count(); index++ )
       
   222         {
       
   223         iSelectedLists.AppendL( (*selected)[index] );
       
   224         }
       
   225 
       
   226     // Set highlighted item
       
   227     TInt currentItem = iMSAppUi.ParameterAgent()->FillViewFocusIndex();
       
   228     if ( currentItem >= 0 )
       
   229         {
       
   230         //Set current item
       
   231         iListBox->SetCurrentItemIndex( currentItem );
       
   232         }
       
   233     else
       
   234         {
       
   235         // first item
       
   236         // This is set when new list is created without existing lists
       
   237         iListBox->SetCurrentItemIndex( 0 );
       
   238         }
       
   239 
       
   240     UpdateNaviTextL();
       
   241 
       
   242 	iPreviousItemIndex = 0;
       
   243 	iDragItemIndex = 0;
       
   244 
       
   245     // Change middle softkey according to selection
       
   246     TBool listSelected = IsCurrentListItemActive();
       
   247     iView.SetCbaL( listSelected );
       
   248 
       
   249     ActivateL(); // Activates window. ( Ready to draw )
       
   250     }
       
   251 
       
   252 // --------------------------------------------------------------------------
       
   253 // CMSFillContainer::CountComponentControls()
       
   254 // Returns number of components.
       
   255 // --------------------------------------------------------------------------
       
   256 //
       
   257 TInt CMSFillContainer::CountComponentControls() const
       
   258     {
       
   259     LOG(_L("[MediaServant]\t CMSFillContainer::CountComponentControls"));
       
   260 
       
   261     return 1; // return number of controls inside this container
       
   262     }
       
   263 
       
   264 
       
   265 // --------------------------------------------------------------------------
       
   266 // CMSFillContainer::ComponentControl()
       
   267 // Returns pointer to particular component.
       
   268 // --------------------------------------------------------------------------
       
   269 //
       
   270 CCoeControl* CMSFillContainer::ComponentControl(TInt /*aIndex*/) const
       
   271 
       
   272     {
       
   273     return iListBox; // return a pointer to the listbox
       
   274     }
       
   275 
       
   276 // --------------------------------------------------------------------------
       
   277 // CMSFillContainer::OfferKeyEventL()
       
   278 // Handles the key events.
       
   279 // --------------------------------------------------------------------------
       
   280 //
       
   281 TKeyResponse CMSFillContainer::OfferKeyEventL(
       
   282     const TKeyEvent& aKeyEvent,
       
   283     TEventCode aType )
       
   284     {
       
   285     LOG(_L("[MediaServant]\t CMSFillContainer::OfferKeyEventL"));
       
   286 
       
   287     TKeyResponse response = EKeyWasNotConsumed;
       
   288 
       
   289     if ( aType != EEventKey )
       
   290         {
       
   291         response =  EKeyWasNotConsumed;
       
   292         }
       
   293 
       
   294     else if ( iListBox && iListBox->CurrentItemIndex() >= 0 )
       
   295         {
       
   296         // check if reordering mode is activated
       
   297         if ( iReorderState == EMSFillReorderActive ||
       
   298              aKeyEvent.iCode == EKeyLeftArrow ||
       
   299              aKeyEvent.iCode == EKeyRightArrow )
       
   300             {
       
   301             response = HandleReorderKeyEventL( aKeyEvent, aType );
       
   302             }
       
   303 
       
   304         // delete list
       
   305         else if ( aKeyEvent.iCode == EKeyBackspace )
       
   306             {
       
   307             DeleteRuleL();
       
   308             response = EKeyWasConsumed;
       
   309             }
       
   310 
       
   311         // activate/deactivate list
       
   312         else if ( aKeyEvent.iCode == EKeyOK )
       
   313             {
       
   314             CCmFillRule* rule =
       
   315                 (*iFillListArray)[iListBox->CurrentItemIndex()]->List();
       
   316             if ( rule->Selected() == ECmSelected )
       
   317                 {
       
   318                 rule->SetSelected( ECmUnSelected );
       
   319                 }
       
   320             else
       
   321                 {
       
   322                 rule->SetSelected( ECmSelected );
       
   323                 }
       
   324             iView.SetListUnselected();
       
   325             UpdateListBoxDataL();
       
   326             response = EKeyWasConsumed;
       
   327             }
       
   328 
       
   329         // default
       
   330         else
       
   331             {
       
   332             response = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   333             }
       
   334 
       
   335 
       
   336         TCmServerState state;
       
   337         iMSAppUi.MSEngine()->ServerState( state );
       
   338         if ( ( aKeyEvent.iCode == EKeyUpArrow ||
       
   339              ( aKeyEvent.iCode == EKeyDownArrow )))
       
   340             {
       
   341             // change navi pane text to match highlighted list size
       
   342             UpdateNaviTextL();
       
   343             }
       
   344         }
       
   345 
       
   346 #ifndef __SERIES60_31__
       
   347     if ( iReorderState == EMSFillNormal )
       
   348         {
       
   349         // Change middle softkey according to selection
       
   350         TBool listSelected = IsCurrentListItemActive();
       
   351         iView.SetCbaL( listSelected );
       
   352         }
       
   353 #endif
       
   354 
       
   355     return response;
       
   356     }
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CMSFillContainer::HandleDragAndDropEventsL()
       
   360 // Handles drag and drop events on touch screen
       
   361 // --------------------------------------------------------------------------
       
   362 //
       
   363 void CMSFillContainer::HandleDragAndDropEventsL( const TPointerEvent& aPointerEvent )
       
   364 	{
       
   365 	if ( aPointerEvent.iType == TPointerEvent::EButton1Down &&
       
   366 	     iReorderState != EMSFillNormal )
       
   367 		{
       
   368 		iReorderState = EMSFillReorderActive;
       
   369 	   	iDragItemIndex = iListBox->CurrentItemIndex();
       
   370 		}
       
   371 	else if ( aPointerEvent.iType == TPointerEvent::EButton1Up &&
       
   372 	     iReorderState == EMSFillReorderActive )
       
   373 		{
       
   374 		iView.HandleCommandL( EMSCmdDrop );
       
   375 		TInt listBoxItem = iListBox->CurrentItemIndex();
       
   376 		iListBox->SetCurrentItemIndex( iDragItemIndex );
       
   377 
       
   378 		TKeyEvent keyEvent;
       
   379 		// Move dragged item downwards
       
   380 		if ( listBoxItem >= iDragItemIndex )
       
   381 			{
       
   382 			keyEvent.iCode = EKeyDownArrow;
       
   383         	for( TInt c = 0; listBoxItem > iDragItemIndex + c; c++ )
       
   384 	        	{
       
   385 	        	HandleReorderKeyEventL( keyEvent, EEventKey );
       
   386 	        	}
       
   387 			}
       
   388 		// Move dragged item upwards
       
   389 		else
       
   390 			{
       
   391 			keyEvent.iCode = EKeyUpArrow;
       
   392         	for( TInt c = 0; listBoxItem < iDragItemIndex - c; c++ )
       
   393 	        	{
       
   394 	        	HandleReorderKeyEventL( keyEvent, EEventKey );
       
   395 	        	}
       
   396 			}
       
   397         	
       
   398 		iListBox->SetCurrentItemIndex( listBoxItem );
       
   399 		}
       
   400 	}
       
   401 
       
   402 // --------------------------------------------------------------------------
       
   403 // CMSFillContainer::UpdateListBoxDataL()
       
   404 // Creates listbox items
       
   405 // --------------------------------------------------------------------------
       
   406 //
       
   407 void CMSFillContainer::UpdateListBoxDataL()
       
   408     {
       
   409     LOG(_L("[MediaServant]\t CMSFillContainer::UpdateListBoxDataL"));
       
   410     TInt64 freeSpace = iFreeMemory;
       
   411 
       
   412     TCmServerState state;
       
   413     iMSAppUi.MSEngine()->ServerState( state );
       
   414 
       
   415     // Keep item index safe for reordering mode because we reset the list
       
   416     TInt currentItemIndex = iListBox->CurrentItemIndex();
       
   417 
       
   418     // reset list size
       
   419     iSizeOfSelectedLists = 0;
       
   420 
       
   421     TBuf<KMaxFileName> item;
       
   422     HBufC* primary_text = HBufC::NewL( KMaxFileName );
       
   423     CleanupStack::PushL( primary_text );
       
   424 
       
   425     // Listbox items
       
   426     CDesCArray* itemArray = static_cast<CDesCArray*>
       
   427                                    (iListBox->Model()->ItemTextArray());
       
   428     itemArray->Reset();
       
   429 
       
   430     // Marked listbox item indexes
       
   431     CArrayFix<TInt>* selectionArray = new (ELeave )
       
   432                                    CArrayFixFlat<TInt>(KListGranularity);
       
   433 
       
   434     CleanupStack::PushL( selectionArray );
       
   435 
       
   436     TInt ruleCount = iFillListArray->Count();
       
   437 
       
   438     for ( TInt index = 0; index < ruleCount; index++ )
       
   439         {
       
   440         // Get fill rule name and put it to the listbox
       
   441         CCmFillRule* rule = (*iFillListArray)[index]->List();
       
   442         HBufC* listName = UpnpString::ToUnicodeL( rule->Name() );
       
   443         CleanupStack::PushL( listName );
       
   444         primary_text->Des().Copy( *listName );
       
   445         CleanupStack::PopAndDestroy( listName );
       
   446 
       
   447 
       
   448         // Check if rule is active and mark it in the list
       
   449         TCmFillRuleStatus status = rule->Selected();
       
   450 
       
   451         TInt64 listSize = (*iFillListArray)[index]->ListSize();
       
   452 
       
   453         if ( status == ECmSelected )
       
   454             {
       
   455             selectionArray->AppendL( index );
       
   456 
       
   457             TInt id = rule->ListId();
       
   458             TInt64 size = 0;
       
   459             iMSAppUi.GetFilledFilesSize( size, id );
       
   460             
       
   461             // list selected - add used memory size
       
   462             iSizeOfSelectedLists += ( listSize - size );
       
   463             }
       
   464         // calculate icon index
       
   465         TInt iconIndex = ListItemIconIndex( index,
       
   466                                             listSize,
       
   467                                             freeSpace );
       
   468 
       
   469 
       
   470         switch ( rule->MediaType() )
       
   471             {
       
   472             case ECmVideo:
       
   473                 {
       
   474                 item.Format( KSingleGraphicStyleFormatString,
       
   475                              iconIndex, primary_text, EVideoType );
       
   476                 break;
       
   477                 }
       
   478             case ECmImage:
       
   479                 {
       
   480                 item.Format( KSingleGraphicStyleFormatString,
       
   481                              iconIndex, primary_text, EImageType );
       
   482                 break;
       
   483                 }
       
   484             case ECmAudio:
       
   485                 {
       
   486                 item.Format( KSingleGraphicStyleFormatString,
       
   487                              iconIndex, primary_text, EAudioType );
       
   488                 break;
       
   489                 }
       
   490             default:
       
   491                 {
       
   492                 item.Format( KSingleGraphicStyleFormatStringNoTrailIcons,
       
   493                              iconIndex, primary_text);
       
   494                 break;
       
   495                 }
       
   496             }
       
   497 
       
   498         // Check if reorder mode is active and mark current item
       
   499         if ( iReorderState == EMSFillReorderActive &&
       
   500              index == currentItemIndex )
       
   501             {
       
   502             TBuf<2> markIconStr; // Magic: 2 characters reserverd for icon
       
   503             markIconStr.AppendNum( EMark );
       
   504             item.Append(markIconStr);
       
   505             }
       
   506         itemArray->AppendL( item );
       
   507         }
       
   508 
       
   509     iListBox->SetSelectionIndexesL( selectionArray );
       
   510 
       
   511     CleanupStack::PopAndDestroy( selectionArray );
       
   512     CleanupStack::PopAndDestroy( primary_text );
       
   513 
       
   514     UpdateNaviTextL();
       
   515     if( currentItemIndex > KErrNotFound && currentItemIndex < ruleCount )
       
   516         {
       
   517         iListBox->SetCurrentItemIndex( currentItemIndex );
       
   518         }
       
   519     iListBox->HandleItemAdditionL();
       
   520     }
       
   521 
       
   522 // --------------------------------------------------------------------------
       
   523 // CMSFillContainer::SetFillRules()
       
   524 // Sends fill rules to server
       
   525 // --------------------------------------------------------------------------
       
   526 //
       
   527 void CMSFillContainer::SetFillRules()
       
   528     {
       
   529     LOG(_L("[MediaServant]\t CMSFillContainer::SetFillRules"));
       
   530 
       
   531     // Get marked items indexes
       
   532     const CListBoxView::CSelectionIndexArray* selected =
       
   533             iListBox->SelectionIndexes();
       
   534 
       
   535     // Listbox item count
       
   536     TInt itemCount = iFillListArray->Count();
       
   537 
       
   538     // Selected item index
       
   539     TInt itemIdx = 0;
       
   540 
       
   541     // Sort criteria, offset = 0
       
   542     TKeyArrayFix sortKey( 0, ECmpTUint );
       
   543 
       
   544     // count selected items
       
   545     TInt count = selected->Count();
       
   546 
       
   547     for ( TInt index = 0; index < itemCount; index++ )
       
   548         {
       
   549         // check if listbox item is found from selected item list
       
   550         TInt found = selected->Find( index, sortKey, itemIdx );
       
   551 
       
   552         CCmFillRule* rule = (*iFillListArray)[index]->List();
       
   553 
       
   554         // FOUND
       
   555         if ( found == 0 )
       
   556             {
       
   557             // set rule selected
       
   558             rule->SetSelected( ECmSelected );
       
   559             }
       
   560         // NOT FOUND
       
   561         else
       
   562             {
       
   563             // set rule unselected
       
   564             rule->SetSelected( ECmUnSelected );
       
   565             }
       
   566         }
       
   567     }
       
   568 
       
   569 // --------------------------------------------------------------------------
       
   570 // CMSFillContainer::SelectedItemIndex()
       
   571 // Highlighted item index
       
   572 // --------------------------------------------------------------------------
       
   573 //
       
   574 TInt CMSFillContainer::SelectedItemIndex()
       
   575     {
       
   576     LOG(_L("[MediaServant]\t CMSFillContainer::SelectedItemIndex"));
       
   577 
       
   578     return iListBox->CurrentItemIndex();
       
   579     }
       
   580 
       
   581 // --------------------------------------------------------------------------
       
   582 // CMSFillContainer::ListItemCount()
       
   583 // coun of list items
       
   584 // --------------------------------------------------------------------------
       
   585 //
       
   586 TInt CMSFillContainer::ListItemCount()
       
   587     {
       
   588     LOG(_L("[MediaServant]\t CMSFillContainer::ListItemCount"));
       
   589 
       
   590     return iListBox->Model()->NumberOfItems();
       
   591     }
       
   592 
       
   593 // --------------------------------------------------------------------------
       
   594 // CMSFillContainer::SetReorderStateL()
       
   595 // Sets reorder state
       
   596 // --------------------------------------------------------------------------
       
   597 //
       
   598 void CMSFillContainer::SetReorderStateL( TMSReorderState aState )
       
   599     {
       
   600     LOG(_L("[MediaServant]\t CMSFillContainer::SetReorderStateL"));
       
   601 
       
   602     switch ( aState )
       
   603         {
       
   604         case EMSFillNormal:
       
   605             {
       
   606             iReorderState = EMSFillNormal;
       
   607             break;
       
   608             }
       
   609         case EMSFillReorderActive:
       
   610             {
       
   611             iReorderState = EMSFillReorderActive;
       
   612             UpdateListBoxDataL();
       
   613             break;
       
   614             }
       
   615         case EMSFillGrabActive:
       
   616             {
       
   617             iReorderState = EMSFillGrabActive;
       
   618             UpdateListBoxDataL();
       
   619             break;
       
   620             }
       
   621         default:
       
   622             {
       
   623             iReorderState = EMSFillNormal;
       
   624             break;
       
   625             }
       
   626         }
       
   627     }
       
   628 
       
   629 // --------------------------------------------------------------------------
       
   630 // CMSFillContainer::MoveItem()
       
   631 // moves item up/down on the list
       
   632 // --------------------------------------------------------------------------
       
   633 //
       
   634 void CMSFillContainer::MoveItem( TInt aDirection )
       
   635     {
       
   636     LOG(_L("[MediaServant]\t CMSFillContainer::MoveItem"));
       
   637 
       
   638     TInt currentIdx = iListBox->CurrentItemIndex();
       
   639     TInt totalItem = iListBox->Model()->NumberOfItems();
       
   640 
       
   641     // store selection status of all rules
       
   642     StoreSelectionStatus();
       
   643 
       
   644     // up
       
   645     if (aDirection == -1 && currentIdx)
       
   646         {
       
   647         iFillRuleController->ChangePriority( totalItem,
       
   648                                              currentIdx,
       
   649                                              aDirection );
       
   650         }
       
   651     // down
       
   652     else if ( aDirection == 1 && currentIdx < totalItem - 1 )
       
   653         {
       
   654         iFillRuleController->ChangePriority( totalItem,
       
   655                                              currentIdx,
       
   656                                              aDirection );
       
   657         }
       
   658     else
       
   659         {
       
   660         // Do nothing
       
   661         }
       
   662     }
       
   663 
       
   664 
       
   665 // --------------------------------------------------------------------------
       
   666 // CMSFillContainer::HandleReorderKeyEventL
       
   667 // Handle key events in reordering mode.
       
   668 // (other items were commented in a header).
       
   669 // --------------------------------------------------------------------------
       
   670 //
       
   671 TKeyResponse CMSFillContainer::HandleReorderKeyEventL(
       
   672     const TKeyEvent& aKeyEvent,
       
   673     TEventCode aType )
       
   674     {
       
   675     LOG(_L("[MediaServant]\t CMSFillContainer::HandleReorderKeyEventL"));
       
   676 
       
   677     TKeyResponse keyResponse = EKeyWasConsumed;
       
   678 
       
   679     TInt currentIdx = iListBox->CurrentItemIndex();
       
   680     TInt totalItems = iListBox->Model()->NumberOfItems();
       
   681 
       
   682     TBool reqToRedraw = EFalse;
       
   683     if ( aType == EEventKey )
       
   684         {
       
   685         switch ( aKeyEvent.iCode )
       
   686             {
       
   687             case EKeyUpArrow:
       
   688             // fall through
       
   689             case EKeyLeftArrow:
       
   690                 {
       
   691                 if ( currentIdx > 0 )
       
   692                     {
       
   693                     MoveItem(-1);
       
   694                     iListBox->SetCurrentItemIndex( currentIdx - 1 );
       
   695                     reqToRedraw = ETrue;
       
   696                     }
       
   697                 break;
       
   698                 }
       
   699             case EKeyDownArrow:
       
   700             // fall through
       
   701             case EKeyRightArrow:
       
   702                 {
       
   703                 if ( currentIdx < totalItems-1 ) // because index is 0 based
       
   704                     {
       
   705                     MoveItem(1);
       
   706                     iListBox->SetCurrentItemIndex( currentIdx + 1 );
       
   707                     reqToRedraw = ETrue;
       
   708                     }
       
   709                 break;
       
   710                 }
       
   711             default:
       
   712                 {
       
   713                 LOG(_L("[MediaServant]\t CMSFillContainer::\
       
   714                 HandleReorderKeyEventL invalid keycode"));
       
   715                 break;
       
   716                 }
       
   717             }
       
   718         }
       
   719 
       
   720     if( reqToRedraw )
       
   721         {
       
   722         // update selected item indexes
       
   723         const CListBoxView::CSelectionIndexArray* selected =
       
   724                                                 iListBox->SelectionIndexes();
       
   725         UpdateListBoxDataL();
       
   726         iSelectedLists.Reset();
       
   727         for ( TInt index = 0; index < selected->Count(); index++ )
       
   728             {
       
   729             TInt a = (*selected)[index];
       
   730             iSelectedLists.AppendL( (*selected)[index] );
       
   731             }
       
   732         }
       
   733 
       
   734     return keyResponse;
       
   735     }
       
   736 
       
   737 // --------------------------------------------------------------------------
       
   738 // CMSFillContainer::StoreSelectionStatus()
       
   739 // stores fill rule selection status to rule container
       
   740 // --------------------------------------------------------------------------
       
   741 //
       
   742 void CMSFillContainer::StoreSelectionStatus()
       
   743     {
       
   744     LOG(_L("[MediaServant]\t CMSFillContainer::StoreSelectionStatusL"));
       
   745 
       
   746     // index of selected item
       
   747     TInt itemIdx = 0;
       
   748     // Sort criteria, offset = 0
       
   749     TKeyArrayFix sortKey( 0, ECmpTUint );
       
   750 
       
   751     // Listbox array
       
   752     CDesCArray* itemArray = static_cast<CDesCArray*>
       
   753                                     (iListBox->Model()->ItemTextArray());
       
   754 
       
   755     // Listbox item count
       
   756     TInt itemCount = itemArray->Count();
       
   757 
       
   758     const CListBoxView::CSelectionIndexArray* selected =
       
   759             iListBox->SelectionIndexes();
       
   760 
       
   761     // count selected items
       
   762     TInt count = selected->Count();
       
   763 
       
   764     for ( TInt index = 0; index < itemCount; index++ )
       
   765         {
       
   766         // check if listbox item is found from selected item list
       
   767         TInt found = selected->Find( index, sortKey, itemIdx );
       
   768 
       
   769         if ( found == 0 )
       
   770             {
       
   771             // found - get correcponding index for rule table with At()
       
   772             CCmFillRule* rule =
       
   773                 (*iFillListArray)[selected->At( itemIdx )]->List();
       
   774             // set rule selected
       
   775             rule->SetSelected( ECmSelected );
       
   776             }
       
   777         else
       
   778             {
       
   779             // not found
       
   780             CCmFillRule* rule = (*iFillListArray)[index]->List();
       
   781             // set rule unselected
       
   782             rule->SetSelected( ECmUnSelected );
       
   783             }
       
   784         }
       
   785     }
       
   786 
       
   787 // --------------------------------------------------------------------------
       
   788 // CMSFillContainer::DeleteRuleL()
       
   789 // Deletes highlighted rule
       
   790 // --------------------------------------------------------------------------
       
   791 //
       
   792 void CMSFillContainer::DeleteRuleL()
       
   793     {
       
   794     LOG(_L("[MediaServant]\t CMSFillContainer::DeleteRuleL"));
       
   795 
       
   796     // Show delete files query
       
   797     CAknQueryDialog* query= CAknQueryDialog::NewL(
       
   798                                    CAknQueryDialog::ENoTone );
       
   799 
       
   800     if ( query->ExecuteLD( R_MSERV_DELETE_LIST_QUERY ) )
       
   801         {
       
   802         TInt currentItemIndex = iListBox->CurrentItemIndex();
       
   803         // delete rule
       
   804         iFillRuleController->DeleteRuleL( currentItemIndex );
       
   805 
       
   806         // Listbox items
       
   807         CDesCArray* itemArray = static_cast<CDesCArray*>
       
   808                                        (iListBox->Model()->ItemTextArray());
       
   809 
       
   810         // delete list item
       
   811         itemArray->Delete( currentItemIndex );
       
   812         iListBox->HandleItemRemovalL();
       
   813         iListDeleted = ETrue;
       
   814 
       
   815         if ( currentItemIndex > 0 )
       
   816             {
       
   817             // highligth previous
       
   818             iListBox->SetCurrentItemIndexAndDraw( currentItemIndex - 1 );
       
   819             }
       
   820         iMSAppUi.MSEngine()->DeleteFilledFilesL();
       
   821         iView.ShowNaviTextL();
       
   822         }
       
   823     }
       
   824 
       
   825 // --------------------------------------------------------------------------
       
   826 // CMSFillContainer::IsListDeleted()
       
   827 // Returns list delete status
       
   828 // --------------------------------------------------------------------------
       
   829 //
       
   830 TBool CMSFillContainer::IsListDeleted()
       
   831     {
       
   832     return iListDeleted;
       
   833     }
       
   834 
       
   835 // --------------------------------------------------------------------------
       
   836 // CMSFillContainer::HandlePointerEventL()
       
   837 // Handles touchscreen event
       
   838 // --------------------------------------------------------------------------
       
   839 //
       
   840 void CMSFillContainer::HandlePointerEventL ( const TPointerEvent& aPointerEvent )
       
   841     {
       
   842 	CCoeControl::HandlePointerEventL( aPointerEvent );
       
   843     
       
   844     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   845     	{
       
   846     	// Do not change listbox item state, when highlighting an item or,
       
   847 	    // when reordering state is active
       
   848     	if ( iListBox->CurrentItemIndex() == iPreviousItemIndex &&
       
   849              iReorderState == EMSFillNormal )
       
   850 	    	{	
       
   851 			TKeyEvent keyEvent;
       
   852 			keyEvent.iCode = EKeyOK;
       
   853 			OfferKeyEventL( keyEvent, EEventKey );
       
   854     		}
       
   855     	else
       
   856     		{
       
   857     		UpdateListBoxDataL();
       
   858     		}
       
   859 	   	iPreviousItemIndex = iListBox->CurrentItemIndex();
       
   860 		}
       
   861 		
       
   862 	// Handle Drag and drop events, when reorder state is active
       
   863     if ( iReorderState != EMSFillNormal )
       
   864     	{
       
   865     	HandleDragAndDropEventsL( aPointerEvent );
       
   866     	}
       
   867     }
       
   868 
       
   869 // --------------------------------------------------------------------------
       
   870 // CMSFillContainer::CheckIfDublicateName()
       
   871 // Checks how many dublicate items is on the fill list
       
   872 // --------------------------------------------------------------------------
       
   873 //
       
   874 TInt CMSFillContainer::CheckIfDublicateNames( const TDesC& aName )
       
   875     {
       
   876     CDesCArray* itemArray = static_cast<CDesCArray*>
       
   877                                    (iListBox->Model()->ItemTextArray());
       
   878     TInt count(0);
       
   879 
       
   880     for ( TInt index = 0; index < itemArray->MdcaCount(); index++ )
       
   881         {
       
   882         if ( KErrNotFound != itemArray->MdcaPoint( index ).Match( aName ) )
       
   883             {
       
   884             count++;
       
   885             }
       
   886         }
       
   887     return count;
       
   888     }
       
   889 
       
   890 // --------------------------------------------------------------------------
       
   891 // CMSFillContainer::UpdateNaviTextL()
       
   892 // updates list size on navi pane
       
   893 // --------------------------------------------------------------------------
       
   894 //
       
   895 void CMSFillContainer::UpdateNaviTextL()
       
   896     {
       
   897     LOG(_L("[MediaServant]\t CMSFillContainer::UpdateNaviTextL"));
       
   898 
       
   899     TInt currentItemIndex = iListBox->CurrentItemIndex();
       
   900 
       
   901     if ( currentItemIndex != KErrNotFound )
       
   902         {
       
   903         CArrayFix<TInt>* infoArray = new ( ELeave ) CArrayFixFlat<TInt>(2);
       
   904         CleanupStack::PushL( infoArray );
       
   905 
       
   906         CMSFillList* fillList = (*iFillListArray)[currentItemIndex];
       
   907         CCmFillRule* rule = fillList->List();
       
   908 
       
   909         HBufC* naviText = NULL;
       
   910 
       
   911         TInt64 freeMemory = iFreeMemory - iSizeOfSelectedLists;
       
   912 
       
   913         // round values
       
   914         TReal size(0);
       
   915         Math::Round( size, TReal(fillList->ListSize()) / KMega, 0 );
       
   916 
       
   917         TReal freeSize(0);
       
   918         Math::Round( freeSize, TReal(freeMemory) / KMega, 0 );
       
   919 
       
   920         infoArray->AppendL( size );
       
   921         infoArray->AppendL( freeSize );
       
   922 
       
   923         naviText = StringLoader::LoadLC( R_MS_NAVI_LIST_SIZE,
       
   924                                          *infoArray );
       
   925         // do number conversion
       
   926         TPtr ptr = naviText->Des();
       
   927         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   928 
       
   929         iView.SetNavigationPaneTextL( *naviText );
       
   930         CleanupStack::PopAndDestroy( naviText );
       
   931         CleanupStack::PopAndDestroy( infoArray );
       
   932         }
       
   933     else
       
   934         {
       
   935         iView.ClearCurrentNaviPaneText();
       
   936         }
       
   937     }
       
   938 
       
   939 // --------------------------------------------------------------------------
       
   940 // CMSFillContainer::ChangeListActivityL()
       
   941 // Toggles list item
       
   942 // --------------------------------------------------------------------------
       
   943 //
       
   944 void CMSFillContainer::ChangeListActivityL()
       
   945     {
       
   946     CCmFillRule* rule =
       
   947         (*iFillListArray)[iListBox->CurrentItemIndex()]->List();
       
   948     if ( rule->Selected() == ECmSelected )
       
   949         {
       
   950         rule->SetSelected( ECmUnSelected );
       
   951         }
       
   952     else
       
   953         {
       
   954         rule->SetSelected( ECmSelected );
       
   955         }
       
   956     UpdateListBoxDataL();
       
   957     }
       
   958 
       
   959 // --------------------------------------------------------------------------
       
   960 // CMSFillContainer::IsCurrentListItemActive()
       
   961 // Checks if item is selected
       
   962 // --------------------------------------------------------------------------
       
   963 //
       
   964 TBool CMSFillContainer::IsCurrentListItemActive()
       
   965     {
       
   966     return iListBox->View()->ItemIsSelected( iListBox->CurrentItemIndex() );
       
   967     }
       
   968 
       
   969 // --------------------------------------------------------------------------
       
   970 // CMSFillContainer::HasListSelectionsChanged
       
   971 // Checks if item is selected
       
   972 // --------------------------------------------------------------------------
       
   973 //
       
   974 TBool CMSFillContainer::HasListSelectionsChanged()
       
   975     {
       
   976     LOG(_L("[MediaServant]\t CMSFillContainer::HasListSelectionsChanged"));
       
   977 
       
   978     TBool status = EFalse;
       
   979 
       
   980     TInt originalCount = iSelectedLists.Count();
       
   981 
       
   982     const CListBoxView::CSelectionIndexArray* selected =
       
   983                                                 iListBox->SelectionIndexes();
       
   984 
       
   985     TKeyArrayFix sortKey( 0, ECmpTUint );
       
   986     // dummy index - not interested of this
       
   987     TInt dummy = 0;
       
   988 
       
   989     for ( TInt index = 0; index < originalCount; index++ )
       
   990         {
       
   991         // check if listbox item is found from selected item list
       
   992         TInt found = selected->Find(
       
   993                              iSelectedLists[index], sortKey, dummy );
       
   994         if ( found != 0 )
       
   995             {
       
   996             // something has changed on the list
       
   997             status = ETrue;
       
   998             index = originalCount; // break loop
       
   999             }
       
  1000         }
       
  1001 
       
  1002     return status;
       
  1003     }
       
  1004 
       
  1005 // --------------------------------------------------------------------------
       
  1006 // CMSFillContainer::ListItemIconIndex
       
  1007 // Returns icon index based on list size and free space
       
  1008 // --------------------------------------------------------------------------
       
  1009 //
       
  1010 TInt CMSFillContainer::ListItemIconIndex( TInt aIndex,
       
  1011                                           TInt64 aListSize,
       
  1012                                           TInt64& aFreeSpace )
       
  1013     {
       
  1014     LOG(_L("[MediaServant]\t CMSFillContainer::ListItemIconIndex"));
       
  1015 
       
  1016     TInt iconIndex( 0 );
       
  1017     // check if item is selected
       
  1018     CCmFillRule* rule = (*iFillListArray)[aIndex]->List();
       
  1019     if(  ECmSelected == rule->Selected() )
       
  1020         {
       
  1021         // doesn't fit
       
  1022         if ( aFreeSpace <= 0 )
       
  1023             {
       
  1024             iconIndex = EMSSelectedDoesntFit;
       
  1025             aFreeSpace = 0;
       
  1026             }
       
  1027         // fits
       
  1028         else if ( aFreeSpace - aListSize > 0 )
       
  1029             {
       
  1030             iconIndex = EMSSelectedFits;
       
  1031             aFreeSpace -= aListSize;
       
  1032             }
       
  1033         // fits partially
       
  1034         else
       
  1035             {
       
  1036             iconIndex = EMSSelectedPartiallyFits;
       
  1037             aFreeSpace = 0;
       
  1038             }
       
  1039         }
       
  1040     else
       
  1041         {
       
  1042         // doesn't fit
       
  1043         if ( aFreeSpace <= 0)
       
  1044             {
       
  1045             iconIndex = EMSUnSelectedDoesntFit;
       
  1046             aFreeSpace = 0;
       
  1047             }
       
  1048         // fits
       
  1049         else if ( aFreeSpace - aListSize > 0 )
       
  1050             {
       
  1051             iconIndex = EMSUnselectedFits;
       
  1052             aFreeSpace -= aListSize;
       
  1053             }
       
  1054         // fits partially
       
  1055         else
       
  1056             {
       
  1057             iconIndex = EMSUnselectedPartiallyFits;
       
  1058             aFreeSpace = 0;
       
  1059             }
       
  1060         }
       
  1061     return iconIndex;
       
  1062     }
       
  1063 
       
  1064 // --------------------------------------------------------------------------
       
  1065 // CMSFillContainer::CalculateFillQuotaL()
       
  1066 // Gets selected drives and calculates quota size
       
  1067 // --------------------------------------------------------------------------
       
  1068 //
       
  1069 void CMSFillContainer::CalculateFillQuotaL()
       
  1070     {
       
  1071     RPointerArray<CCmDriveInfo> drives;
       
  1072 
       
  1073     iMSAppUi.MSEngine()->GetDrivesL( drives );
       
  1074     for ( TInt i = 0; i < drives.Count(); i++ )
       
  1075         {
       
  1076         iQuota += drives[i]->DriveQuota();
       
  1077         iQuota -= drives[i]->UsedDriveQuota();
       
  1078         }
       
  1079     drives.ResetAndDestroy();
       
  1080     drives.Close();
       
  1081     }
       
  1082 
       
  1083 // --------------------------------------------------------------------------
       
  1084 // CMSFillContainer::SizeChanged()
       
  1085 // Called by framework when the view size is changed.
       
  1086 // --------------------------------------------------------------------------
       
  1087 //
       
  1088 void CMSFillContainer::SizeChanged()
       
  1089     {
       
  1090     // container control resize code.
       
  1091     if ( iListBox )
       
  1092         {
       
  1093         iListBox->SetRect( Rect() ); // Set rectangle of listbox.
       
  1094         }
       
  1095     }
       
  1096 
       
  1097 // --------------------------------------------------------------------------
       
  1098 // CMSFillContainer::HandleResourceChange
       
  1099 // Handles layout change
       
  1100 // --------------------------------------------------------------------------
       
  1101 //
       
  1102 void CMSFillContainer::HandleResourceChange( TInt aType )
       
  1103     {
       
  1104     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1105         {
       
  1106         SetRect( iView.ClientRect() );
       
  1107         }
       
  1108 
       
  1109     CCoeControl::HandleResourceChange( aType );
       
  1110     }
       
  1111 
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // CMSFillContainer::GetHelpContext
       
  1114 // ---------------------------------------------------------------------------
       
  1115 //
       
  1116 void CMSFillContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1117     {
       
  1118     LOG(_L("[MediaServant]\t CMSFillContainer::GetHelpContext"));
       
  1119 
       
  1120     aContext.iMajor = TUid::Uid(KMediaServantUID3);
       
  1121     aContext.iContext = KMSERV_HLP_FILL_LIST;
       
  1122     }
       
  1123 
       
  1124 // End of File
       
  1125