homesync/contentmanager/mediaservant/src/msmaincontainer.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  CMSMainContainer class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknIconArray.h>
       
    21 #include <mediaservant.rsg>
       
    22 #include <mediaservant.mbg>
       
    23 #include <StringLoader.h>
       
    24 #include <aknnotewrappers.h>
       
    25 
       
    26 #include "mserv.hlp.hrh"
       
    27 #include "cmfillrule.h"
       
    28 #include "msappui.h"
       
    29 #include "msmainview.h"
       
    30 #include "mediaservantuid.h"
       
    31 #include "msmaincontainer.h"
       
    32 #include "msengine.h"
       
    33 #include "msconstants.h"
       
    34 #include "msdebug.h"
       
    35 
       
    36 // Constants
       
    37 const TInt KTimerInterval = 60000000; // 1 min
       
    38 const TInt KNaviTimerInterval = 2000000; // 2 sec
       
    39 
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CMSMainContainer::CMSMainContainer()
       
    43 // --------------------------------------------------------------------------
       
    44 //
       
    45 CMSMainContainer::CMSMainContainer( CMSAppUi& aAppUi,
       
    46                                     CMSMainView& aView )
       
    47     {
       
    48     LOG(_L("[MediaServant]\t CMSMainContainer::CMSMainContainer"));
       
    49 
       
    50     iAppUi = &aAppUi;
       
    51     iView = &aView;
       
    52     iAppWizardRun = EFalse;
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CMSMainContainer::~CMSMainContainer()
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CMSMainContainer::~CMSMainContainer()
       
    60     {
       
    61     LOG(_L("[MediaServant]\t CMSMainContainer::~CMSMainContainer"));
       
    62 
       
    63     if( iPeriodic )
       
    64         {
       
    65         iPeriodic->Cancel();
       
    66         }
       
    67     delete iPeriodic;
       
    68 
       
    69     if( iNaviTimer )
       
    70         {
       
    71         iNaviTimer->Cancel();
       
    72         }    
       
    73     delete iNaviTimer;
       
    74     
       
    75     if( iUpdateList )
       
    76         {
       
    77         iUpdateList->Cancel();
       
    78         }
       
    79     delete iUpdateList;
       
    80 
       
    81     if( iMSPropertyWatcher )
       
    82         {
       
    83         iMSPropertyWatcher->Stop();
       
    84         }
       
    85     delete iMSPropertyWatcher;
       
    86 
       
    87     if( iMemoryCardMonitor )
       
    88         {
       
    89         iMemoryCardMonitor->Cancel();
       
    90         }
       
    91     delete iMemoryCardMonitor;
       
    92 
       
    93     delete iListBox; // Deletes listbox object.
       
    94     }
       
    95 
       
    96 
       
    97 // --------------------------------------------------------------------------
       
    98 // CMSMainContainer::ConstructL()
       
    99 // --------------------------------------------------------------------------
       
   100 //
       
   101 void CMSMainContainer::ConstructL( TRect aRect )
       
   102     {
       
   103     LOG(_L("[MediaServant]\t CMSMainContainer::ConstructL"));
       
   104 
       
   105     // Create property watcher for progress info
       
   106     iMSPropertyWatcher = CMSPropertyWatcher::NewL();
       
   107     // view will observe changes in property
       
   108     iMSPropertyWatcher->SetObserver(this);
       
   109 
       
   110     //create a mmc monitor to capture mmc event
       
   111     RFs& systemFs = CEikonEnv::Static()->FsSession();
       
   112     iMemoryCardMonitor = CMSMemoryCardMonitor::NewL( this, systemFs );
       
   113     iMemoryCardMonitor->StartMonitor();
       
   114 
       
   115     CreateWindowL();
       
   116 
       
   117     iListBox = new (ELeave) CAknDoubleLargeStyleListBox;
       
   118 
       
   119     SetListBoxFromResourceL(iListBox, R_MAIN_VIEW_LISTBOX);
       
   120 
       
   121     // Create icons
       
   122     CAknIconArray* icons = new (ELeave) CAknIconArray( EIconCount );
       
   123     CleanupStack::PushL( icons );
       
   124     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   125     TFileName iconsPath( AknIconUtils::AvkonIconFileName() );
       
   126 
       
   127     AppendIconToArrayL( icons, skin,
       
   128                         KMSMifFileName,
       
   129                         KAknsIIDDefault,
       
   130                         EMbmMediaservantQgn_mserv_sync,
       
   131                         EMbmMediaservantQgn_mserv_sync_mask );
       
   132 
       
   133     AppendIconToArrayL( icons, skin,
       
   134                         KMSMifFileName,
       
   135                         KAknsIIDDefault,
       
   136                         EMbmMediaservantQgn_mserv_sync_stop,
       
   137                         EMbmMediaservantQgn_mserv_sync_stop_mask );
       
   138 
       
   139     AppendIconToArrayL( icons, skin,
       
   140                         KMSMifFileName,
       
   141                         KAknsIIDDefault,
       
   142                         EMbmMediaservantQgn_mserv_to_home,
       
   143                         EMbmMediaservantQgn_mserv_to_home_mask );
       
   144 
       
   145     AppendIconToArrayL( icons, skin,
       
   146                         KMSMifFileName,
       
   147                         KAknsIIDDefault,
       
   148                         EMbmMediaservantQgn_mserv_to_home_inactive,
       
   149                         EMbmMediaservantQgn_mserv_to_home_inactive_mask );
       
   150 
       
   151     AppendIconToArrayL( icons, skin,
       
   152                         KMSMifFileName,
       
   153                         KAknsIIDDefault,
       
   154                         EMbmMediaservantQgn_mserv_from_home,
       
   155                         EMbmMediaservantQgn_mserv_from_home_mask );
       
   156 
       
   157     AppendIconToArrayL( icons, skin,
       
   158                         KMSMifFileName,
       
   159                         KAknsIIDDefault,
       
   160                         EMbmMediaservantQgn_mserv_from_home_inactive,
       
   161                         EMbmMediaservantQgn_mserv_from_home_inactive_mask );
       
   162 
       
   163     iListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons);
       
   164 
       
   165     CleanupStack::Pop(icons);
       
   166 
       
   167     // Container is listbox observer
       
   168     iListBox->SetListBoxObserver( this );
       
   169     // Set engine observer
       
   170     iAppUi->MSEngine()->SetObserver( this );
       
   171 
       
   172     SetRect(aRect);
       
   173 
       
   174     // Check if automatic sync/harvest is ongoing
       
   175     TCmServerState state;
       
   176     iAppUi->MSEngine()->ServerState( state );
       
   177     if ( state == ECmServerStateStoring ||
       
   178          state == ECmServerStateFilling ||
       
   179          state == ECmServerStateSearchingForServers )
       
   180         {
       
   181         iSyncRunning = ESyncRunning;
       
   182          }
       
   183 
       
   184     if ( state == ECmServerStateHarvesting )
       
   185         {
       
   186         iRefreshRunning = ETrue;
       
   187         }
       
   188 
       
   189     // From home secondary item text depends list selections
       
   190     iFillListSelected = CheckIfFillListSelected();
       
   191     
       
   192     // Add data to listbox
       
   193     UpdateListBoxDataL();
       
   194 
       
   195     if ( iSyncRunning != ESyncRunning &&
       
   196          iRefreshRunning == EFalse &&
       
   197          state != ECmServerStateDeleting )
       
   198         {
       
   199         // Set last sync time to navi pane
       
   200         SetNaviTextLastSyncL();
       
   201         }
       
   202 
       
   203     // Delete may be in progress so we have to inform user
       
   204     if ( state == ECmServerStateDeleting )
       
   205         {
       
   206         HBufC* naviText = StringLoader::LoadLC( R_MS_PREPROCESSING_TEXT );
       
   207         iView->SetNavigationPaneTextL( *naviText );
       
   208         CleanupStack::PopAndDestroy( naviText );
       
   209         }
       
   210 
       
   211     // start listening property
       
   212     iMSPropertyWatcher->StartL();
       
   213 
       
   214     //Set current item
       
   215     iListBox->SetCurrentItemIndex(
       
   216                         iAppUi->ParameterAgent()->MainViewFocusIndex() );
       
   217     
       
   218     // Start timer for last sync time reading
       
   219     iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle);
       
   220     iPeriodic->Start( 0, KTimerInterval, TCallBack(TimerCallbackL,this) );
       
   221 
       
   222     // create navi text timer - don't start
       
   223     iNaviTimer = CPeriodic::NewL( CActive::EPriorityIdle );
       
   224     
       
   225     iUpdateList = CIdle::NewL( CActive::EPriorityIdle );
       
   226     
       
   227     ActivateL(); // Activates window. ( Ready to draw )
       
   228     }
       
   229 
       
   230 // --------------------------------------------------------------------------
       
   231 // CMSMainContainer::CountComponentControls()
       
   232 // Returns number of components.
       
   233 // --------------------------------------------------------------------------
       
   234 //
       
   235 TInt CMSMainContainer::CountComponentControls() const
       
   236     {
       
   237     return 1; // return number of controls inside this container
       
   238     }
       
   239 
       
   240 
       
   241 // --------------------------------------------------------------------------
       
   242 // CMSMainContainer::ComponentControl()
       
   243 // Returns pointer to particular component.
       
   244 // --------------------------------------------------------------------------
       
   245 //
       
   246 CCoeControl* CMSMainContainer::ComponentControl( TInt aIndex ) const
       
   247 
       
   248     {
       
   249     CCoeControl* retval = NULL;
       
   250     switch ( aIndex )
       
   251         {
       
   252         case 0:
       
   253             {
       
   254             retval = iListBox; // return a pointer to the listbox
       
   255             break;
       
   256             }
       
   257         default:
       
   258             {
       
   259             retval = NULL;
       
   260             break;
       
   261             }
       
   262         }
       
   263     return retval;
       
   264     }
       
   265 
       
   266 // --------------------------------------------------------------------------
       
   267 // CMSMainContainer::OfferKeyEventL()
       
   268 // Handles the key events.
       
   269 // --------------------------------------------------------------------------
       
   270 //
       
   271 TKeyResponse CMSMainContainer::OfferKeyEventL(
       
   272     const TKeyEvent& aKeyEvent,
       
   273     TEventCode aType )
       
   274     {
       
   275     LOG(_L("[MediaServant]\t CMSMainContainer::OfferKeyEventL"));
       
   276 
       
   277     TKeyResponse response = EKeyWasNotConsumed;
       
   278 
       
   279     if ( aType != EEventKey )
       
   280         {
       
   281         response =  EKeyWasNotConsumed;
       
   282         }
       
   283 
       
   284     if ( iListBox )
       
   285         {
       
   286         response = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   287         }
       
   288 
       
   289     iView->SetCbaL( iListBox->CurrentItemIndex() );
       
   290 
       
   291     return response;
       
   292     }
       
   293 
       
   294 
       
   295 // --------------------------------------------------------------------------
       
   296 // CMSMainContainer::OpenSelectedListboxItemL
       
   297 // --------------------------------------------------------------------------
       
   298 //
       
   299 void CMSMainContainer::OpenSelectedListboxItemL()
       
   300     {
       
   301     LOG(_L("[MediaServant]\t CMSMainContainer::OpenSelectedListboxItemL"));
       
   302     
       
   303     HandleListBoxEventL( NULL, EEventEnterKeyPressed );
       
   304     }
       
   305 
       
   306 
       
   307 // --------------------------------------------------------------------------
       
   308 // CMSMainContainer::HandleListBoxEventL()
       
   309 // Handles listbox event.
       
   310 // --------------------------------------------------------------------------
       
   311 void CMSMainContainer::HandleListBoxEventL(
       
   312     CEikListBox* /*aListBox*/,
       
   313     TListBoxEvent aEventType )
       
   314     {
       
   315     LOG(_L("[MediaServant]\t CMSMainContainer::HandleListBoxEventL"));
       
   316 
       
   317     if ( ( aEventType == MEikListBoxObserver::EEventEnterKeyPressed ) ||
       
   318          ( aEventType == MEikListBoxObserver::EEventItemClicked ) )
       
   319         {
       
   320         TInt selected = iListBox->CurrentItemIndex();
       
   321 
       
   322         switch ( selected )
       
   323             {
       
   324             case EStoreAndFill:
       
   325                 {
       
   326                 // refresh is not active
       
   327                 if ( !iRefreshRunning )
       
   328                     {
       
   329                     if ( iSyncRunning == ESyncNotRunning )
       
   330                         {
       
   331                         StartSyncL();
       
   332                         }
       
   333                     else
       
   334                         {
       
   335                         // Cancel current asyncronous operation
       
   336                         iAppUi->MSEngine()->StopOperation();
       
   337                         iSyncRunning = ESyncNotRunning;
       
   338                         iView->ClearCurrentNaviPaneText();
       
   339                         UpdateListBoxDataL();
       
   340                         }
       
   341                     }
       
   342                  // refresh is ongoing
       
   343                  else
       
   344                     {
       
   345                     if ( iSyncRunning == ESyncWaiting )
       
   346                         {
       
   347                         iSyncRunning = ESyncNotRunning;
       
   348                         }
       
   349                     else
       
   350                         {
       
   351                         iSyncRunning = ESyncWaiting;
       
   352                         }
       
   353                     UpdateListBoxDataL();
       
   354                     }
       
   355 
       
   356                 break;
       
   357                 }
       
   358             case EStoreToNetwork:
       
   359                 {
       
   360                 if ( !iRefreshRunning && 
       
   361                      !iSyncRunning && 
       
   362                      !iPreprocessRunning )
       
   363                     {
       
   364                     iAppUi->ChangeViewL( KMSMainViewId,
       
   365                                          KMSStoreListViewId );
       
   366                     }
       
   367                 else
       
   368                     {
       
   369                     TInt noteId = ( iRefreshRunning || iPreprocessRunning ?
       
   370                                     R_MS_ACCESS_ERROR_NOTE : 
       
   371                                     R_MS_ACCESS_ERROR_NOTE_SYNC );
       
   372                     ShowErrorNoteL( noteId );
       
   373                     }
       
   374                 break;
       
   375                 }
       
   376             case EFillToPhone:
       
   377                 {
       
   378                 if ( iAppUi->DriveSelectedL() )
       
   379                     {
       
   380                     if ( !iRefreshRunning &&
       
   381                          !iSyncRunning &&
       
   382                          !iPreprocessRunning )
       
   383                         {
       
   384                         iAppUi->ChangeViewL( KMSMainViewId, KMSFillViewId );
       
   385                         }
       
   386                     else
       
   387                         {
       
   388                         TInt noteId = ( iRefreshRunning ||
       
   389                                         iPreprocessRunning ?
       
   390                                         R_MS_ACCESS_ERROR_NOTE : 
       
   391                                         R_MS_ACCESS_ERROR_NOTE_SYNC );
       
   392                         ShowErrorNoteL( noteId );
       
   393                         }
       
   394                     }
       
   395                 else
       
   396                     {
       
   397                     ShowErrorNoteL( R_MS_INSERT_MEMORY_CARD_TEXT );
       
   398                     }
       
   399                 break;
       
   400                 }
       
   401             default:
       
   402                 {
       
   403                 LOG(_L("[MediaServant]\t CMSMainContainer::\
       
   404                 HandleListBoxEventL no item selected"));
       
   405                 }
       
   406             }
       
   407         }
       
   408     }
       
   409 
       
   410 // --------------------------------------------------------------------------
       
   411 // CMSMainContainer::UpdateListBoxDataL()
       
   412 // Updates listbox texts
       
   413 // --------------------------------------------------------------------------
       
   414 //
       
   415 void CMSMainContainer::UpdateListBoxDataL()
       
   416     {
       
   417     LOG(_L("[MediaServant]\t CMSMainContainer::UpdateListBoxDataL"));
       
   418 
       
   419     TCmServerState state;
       
   420     iAppUi->MSEngine()->ServerState( state );
       
   421 
       
   422     CDesCArray* itemArray = static_cast<CDesCArray*>
       
   423                                         (iListBox->Model()->ItemTextArray());
       
   424 
       
   425     if ( itemArray->Count() )
       
   426         {
       
   427         // delete all listbox items
       
   428         itemArray->Reset();
       
   429         }
       
   430 
       
   431 
       
   432     // Get file counts and sync time
       
   433     TInt itemsToBeStored( 0 );
       
   434     TInt itemsToBeFilled( 0 );
       
   435     TInt syncTime( 0 );
       
   436     TInt syncTimeStore( 0 );
       
   437     TInt syncTimeFill( 0 );
       
   438 
       
   439     iAppUi->MSEngine()->GetTransferInfo( ECmServiceStore,
       
   440                                          itemsToBeStored,
       
   441                                          syncTimeStore );
       
   442 
       
   443     iAppUi->MSEngine()->GetTransferInfo( ECmServiceFill,
       
   444                                          itemsToBeFilled,
       
   445                                          syncTimeFill );
       
   446 
       
   447     syncTime = syncTimeStore + syncTimeFill;
       
   448 
       
   449     // Create item strings
       
   450     HBufC* primaryText = NULL;
       
   451     HBufC* secondaryText = NULL;
       
   452     TInt icon = EIconSync;
       
   453 
       
   454     switch ( iSyncRunning )
       
   455         {
       
   456         default:
       
   457         // fall trough
       
   458         case ESyncNotRunning:
       
   459             {
       
   460             primaryText = StringLoader::LoadLC( R_MAIN_SYNC_NOW_TEXT );
       
   461 
       
   462             if ( itemsToBeStored > 0 || itemsToBeFilled > 0)
       
   463                 {
       
   464                 if ( syncTime/60 > 1 ) // 1 minute
       
   465                     {
       
   466                     secondaryText = StringLoader::LoadLC(
       
   467                                                     R_MS_SYNC_TIME_TEXT,
       
   468                                                     syncTime/60 );
       
   469                     // do number conversion
       
   470                     TPtr ptr = secondaryText->Des();
       
   471                     AknTextUtils::
       
   472                         DisplayTextLanguageSpecificNumberConversion( ptr );
       
   473                     }
       
   474                 else
       
   475                     {
       
   476                     secondaryText = StringLoader::LoadLC(
       
   477                                                R_MS_SYNC_TIME_ONE_MIN_TEXT );
       
   478                     }
       
   479 
       
   480                 }
       
   481             break;
       
   482             }
       
   483         case ESyncRunning:
       
   484             {
       
   485             primaryText = StringLoader::LoadLC( R_MAIN_STOP_SYNC_TEXT );
       
   486             icon = EIconSyncStop;
       
   487             break;
       
   488             }
       
   489         case ESyncWaiting:
       
   490             {
       
   491             primaryText = StringLoader::LoadLC( R_MAIN_STOP_SYNC_TEXT );
       
   492             secondaryText = StringLoader::LoadLC( R_MS_SYNC_WAITING_TEXT );
       
   493             icon = EIconSyncStop;
       
   494             break;
       
   495             }
       
   496         }
       
   497 
       
   498     AppendItemToListBoxArrayL( iListBox,
       
   499                                iListBox->Model(),
       
   500                                icon,
       
   501                                *primaryText,
       
   502                                *secondaryText );
       
   503 
       
   504     if ( secondaryText )
       
   505         {
       
   506         CleanupStack::PopAndDestroy( secondaryText );
       
   507         secondaryText = NULL;
       
   508         }
       
   509 
       
   510     if ( primaryText )
       
   511         {
       
   512         CleanupStack::PopAndDestroy( primaryText );
       
   513         primaryText = NULL;
       
   514         }
       
   515 
       
   516 
       
   517     // From Home -item
       
   518     primaryText = StringLoader::LoadLC( R_MAIN_FROM_HOME_TEXT );
       
   519 
       
   520     TBool driveSelected = iAppUi->DriveSelectedL();
       
   521 
       
   522     if ( driveSelected == EFalse )
       
   523         {
       
   524         secondaryText = StringLoader::LoadLC( R_MS_MEMORY_CARD_NEEDED_TEXT );
       
   525         }
       
   526     else if ( !iFillListSelected )
       
   527         {
       
   528         secondaryText = StringLoader::LoadLC( R_MS_LIST_NOTHING_SELECTED );
       
   529         }        
       
   530     else if ( itemsToBeFilled <= 0 )
       
   531         {
       
   532         secondaryText = StringLoader::LoadLC( R_MS_ALL_IN_SYNC_TEXT );
       
   533         }
       
   534 
       
   535     if ( iRefreshRunning ||
       
   536          iPreprocessRunning ||
       
   537          iSyncRunning == ESyncRunning ||
       
   538          driveSelected == EFalse )
       
   539         {
       
   540         AppendItemToListBoxArrayL( iListBox,
       
   541                                    iListBox->Model(),
       
   542                                    EIconFromHomeInactive,
       
   543                                    *primaryText,
       
   544                                    *secondaryText );
       
   545         }
       
   546     else
       
   547         {
       
   548         AppendItemToListBoxArrayL( iListBox,
       
   549                                    iListBox->Model(),
       
   550                                    EIconFromHome,
       
   551                                    *primaryText,
       
   552                                    *secondaryText );
       
   553         }
       
   554 
       
   555     if ( secondaryText )
       
   556         {
       
   557         CleanupStack::PopAndDestroy( secondaryText );
       
   558         secondaryText = NULL;
       
   559         }
       
   560 
       
   561     CleanupStack::PopAndDestroy( primaryText );
       
   562     primaryText = NULL;
       
   563 
       
   564     // To Home -item
       
   565     primaryText = StringLoader::LoadLC( R_MAIN_TO_HOME_TEXT );
       
   566 
       
   567     if ( itemsToBeStored < 1 )
       
   568         {
       
   569         secondaryText = StringLoader::LoadLC( R_MS_ALL_IN_SYNC_TEXT );
       
   570         }
       
   571     else if ( itemsToBeStored == 1 )
       
   572         {
       
   573         secondaryText = StringLoader::LoadLC( R_MS_SYNC_ONE_NEW_ITEM_TEXT );
       
   574         }
       
   575     else // > 1      
       
   576         {
       
   577         secondaryText = StringLoader::LoadLC( R_MS_SYNC_NEW_ITEMS_TEXT,
       
   578                                               itemsToBeStored );
       
   579         // do number conversion
       
   580         TPtr ptr = secondaryText->Des();
       
   581         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   582         }
       
   583 
       
   584     if ( iRefreshRunning ||
       
   585          iPreprocessRunning ||
       
   586          iSyncRunning == ESyncRunning )
       
   587         {
       
   588         AppendItemToListBoxArrayL( iListBox,
       
   589                                    iListBox->Model(),
       
   590                                    EIconToHomeInactive,
       
   591                                    *primaryText,
       
   592                                    *secondaryText );
       
   593         }
       
   594     else
       
   595         {
       
   596         AppendItemToListBoxArrayL( iListBox,
       
   597                                    iListBox->Model(),
       
   598                                    EIconToHome,
       
   599                                    *primaryText,
       
   600                                    *secondaryText );
       
   601         }
       
   602 
       
   603     if ( secondaryText )
       
   604         {
       
   605         CleanupStack::PopAndDestroy( secondaryText );
       
   606         secondaryText = NULL;
       
   607         }
       
   608 
       
   609     CleanupStack::PopAndDestroy( primaryText );
       
   610     primaryText = NULL;
       
   611 
       
   612 
       
   613     iListBox->DrawNow();
       
   614     }
       
   615 
       
   616 // --------------------------------------------------------------------------
       
   617 // CMSMainContainer::ReadyL()
       
   618 // engine observer callback
       
   619 // --------------------------------------------------------------------------
       
   620 //
       
   621 void CMSMainContainer::ReadyL( TCmService aService, TInt aError )
       
   622     {
       
   623     LOG(_L("[MediaServant]\t CMSMainContainer::ReadyL"));
       
   624 
       
   625     // Clears navi pane
       
   626     iView->ClearCurrentNaviPaneText();
       
   627 
       
   628     if( aError == KErrNotFound )
       
   629         {
       
   630         ShowErrorNoteL( R_MS_ERROR_DEVICES_NOT_FOUND );
       
   631         }
       
   632     else if( aError == KErrGeneral )
       
   633         {
       
   634         ShowErrorNoteL( R_MS_ERROR_SYNC_INTERRUPTED );
       
   635         }
       
   636     else if( aError == KErrDiskFull )
       
   637         {
       
   638         ShowErrorNoteL( R_MS_ERROR_MEMORY_FULL );
       
   639         }		
       
   640     else if ( aError && aError != KErrCancel )
       
   641         {
       
   642 #ifdef __DEBUG
       
   643         ShowNoteL( R_ACTIVE_ERROR_NOTE_TEXT, aError );
       
   644 #endif        
       
   645         iRefreshRunning = EFalse;
       
   646         iSyncRunning = ESyncNotRunning;
       
   647         }
       
   648 
       
   649     switch ( aService )
       
   650         {
       
   651         case ECmServiceDeleteMetadata:
       
   652             {
       
   653             iAppUi->MSEngine()->DeleteDeletedMediaserversL();
       
   654             // start harvest
       
   655             iAppUi->MSEngine()->ScanMediaServersL();
       
   656             break;
       
   657             }
       
   658         case ECmServiceHarvest:
       
   659             {
       
   660             if( iAppWizardRun )
       
   661                 {
       
   662                 LOG(_L("[MediaServant]\t CMSMainContainer::\
       
   663                 ReadyL, HARVEST (Wizard)"));
       
   664 
       
   665                 // refreshes also fill rules
       
   666                 iAppUi->RefreshListsL();
       
   667                 
       
   668                 // "From home" secondary item text depends list selections
       
   669                 // must be read here again because list selections change
       
   670                 // after wizard run
       
   671                 iFillListSelected = CheckIfFillListSelected();
       
   672                 
       
   673                 if ( iRefreshRunning && iSyncRunning == ESyncWaiting )
       
   674                     {
       
   675                     StartSyncL();
       
   676                     iRefreshRunning = EFalse;
       
   677                     }
       
   678 
       
   679                 iRefreshRunning = EFalse;
       
   680                 iAppWizardRun = EFalse;
       
   681                 LOG(_L("[MediaServant]\t CMSMainContainer::ReadyL, \
       
   682                 START PRE PRO"));
       
   683                 
       
   684                 // show navi pane text for 2 seconds
       
   685                 ShowRefreshCompleteTextL();
       
   686                 iNaviTimer->Start( KNaviTimerInterval,
       
   687                                   KNaviTimerInterval,
       
   688                                   TCallBack( NaviTimerCallbackL, this ) );
       
   689                 break;
       
   690                 }
       
   691             else
       
   692                 {
       
   693                 if ( iRefreshRunning && iSyncRunning == ESyncWaiting )
       
   694                     {
       
   695                     StartSyncL();
       
   696                     iRefreshRunning = EFalse;
       
   697                     }
       
   698                 else
       
   699                     {
       
   700                     iRefreshRunning = EFalse;
       
   701                     // refreshes also fill rules and store item
       
   702                     iAppUi->RefreshListsL();
       
   703                     
       
   704                     // show navi pane text for 2 seconds
       
   705                     ShowRefreshCompleteTextL();
       
   706                     iNaviTimer->Start( KNaviTimerInterval,
       
   707                                      KNaviTimerInterval,
       
   708                                      TCallBack( NaviTimerCallbackL, this ) );
       
   709                     }
       
   710                 }
       
   711             break;
       
   712             }
       
   713 
       
   714         case ECmServiceFill:
       
   715         // fall trough
       
   716         case ECmServiceStore:
       
   717             {
       
   718             iSyncRunning = ESyncNotRunning;
       
   719             SetNaviTextLastSyncL();
       
   720             iAppUi->RefreshListsL();
       
   721             break;
       
   722             }
       
   723 
       
   724         case ECmServicePreProcessingStore:
       
   725             {
       
   726             LOG(_L("[MediaServant]\t CMSMainContainer::ReadyL, \
       
   727             PRE PRO STORE"));
       
   728 
       
   729             if ( iSyncRunning == ESyncWaiting )
       
   730                 {
       
   731                 StartSyncL();
       
   732                 }
       
   733 
       
   734             iPreprocessRunning = EFalse;
       
   735             iAppUi->RefreshListsL();
       
   736             break;
       
   737             }
       
   738         case ECmServicePreProcessingFill:
       
   739             {
       
   740             LOG(_L("[MediaServant]\t CMSMainContainer::ReadyL, \
       
   741             PRE PRO FILL"));
       
   742 
       
   743             // Set last sync time to navi pane
       
   744             SetNaviTextLastSyncL();
       
   745 
       
   746             iPreprocessRunning = EFalse;
       
   747             break;
       
   748             }
       
   749 
       
   750         case ECmServiceDeleteFilledFiles:
       
   751             {
       
   752             // Set last sync time to navi pane
       
   753             SetNaviTextLastSyncL();
       
   754             break;
       
   755             }
       
   756 
       
   757         default:
       
   758             {
       
   759             LOG(_L("[MediaServant]\t CMSMainContainer::ReadyL \
       
   760             service not found"));
       
   761             break;
       
   762             }
       
   763         }
       
   764 
       
   765     UpdateListBoxDataL();
       
   766     }
       
   767 
       
   768 // --------------------------------------------------------------------------
       
   769 // CMSMainContainer::PropertyChangedL
       
   770 // --------------------------------------------------------------------------
       
   771 //
       
   772 void CMSMainContainer::PropertyChangedL( TCmService aService,
       
   773                                     TInt aTotalItems,
       
   774                                     TInt aProcessedItems,
       
   775                                     TInt /*aItemsToBeProcessed*/ )
       
   776     {
       
   777     LOG(_L("[MediaServant]\t CMSMainContainer::PropertyChangedL"));
       
   778 
       
   779     switch ( aService )
       
   780         {
       
   781         case ECmServiceHarvest:
       
   782             {
       
   783             // Launching propertywatcher causes unwanted call of observer
       
   784             // (server previous state is returned
       
   785             // We want to show progress only when refresh is truly running
       
   786             if ( iRefreshRunning )
       
   787                 {
       
   788                 TInt value( 0 );
       
   789                 if ( aTotalItems > 0 )
       
   790                     {
       
   791                     value = (TReal(aProcessedItems)/TReal(aTotalItems))*100;
       
   792                     }
       
   793 
       
   794                 HBufC* progress = StringLoader::LoadLC(
       
   795                                    R_MS_NAVI_REFRESHING_TEXT, value );
       
   796 
       
   797                 // do number conversion
       
   798                 TPtr ptr = progress->Des();
       
   799                 AknTextUtils::
       
   800                     DisplayTextLanguageSpecificNumberConversion( ptr );
       
   801 
       
   802                 // update navi pane
       
   803                 iView->SetNavigationPaneTextL( *progress );
       
   804                 CleanupStack::PopAndDestroy( progress );
       
   805                 }
       
   806             break;
       
   807             }
       
   808         case ECmServiceStore:
       
   809         // fall through
       
   810         case ECmServiceFill:
       
   811             {
       
   812             if ( aTotalItems > 0 && aProcessedItems > 0 )
       
   813                 {
       
   814                 // calculate procentual value
       
   815                 TInt value = (TReal(aProcessedItems)/TReal(aTotalItems))*100;
       
   816                 HBufC* progress = StringLoader::LoadLC(
       
   817                                    R_MS_NAVI_SYNC_TEXT, value );
       
   818 
       
   819                 // do number conversion
       
   820                 TPtr ptr = progress->Des();
       
   821                 AknTextUtils::
       
   822                     DisplayTextLanguageSpecificNumberConversion( ptr );
       
   823 
       
   824                 // update navi pane
       
   825                 iView->SetNavigationPaneTextL( *progress );
       
   826                 CleanupStack::PopAndDestroy( progress );
       
   827                 }
       
   828             break;
       
   829             }
       
   830         case ECmServiceNone:
       
   831             {
       
   832             iSyncRunning = ESyncNotRunning;
       
   833             iRefreshRunning = EFalse;
       
   834             if ( iNaviTimer && !iNaviTimer->IsActive() )
       
   835                 {
       
   836                 SetNaviTextLastSyncL();    
       
   837                 }
       
   838             
       
   839             break;
       
   840             }
       
   841         default:
       
   842             {
       
   843             LOG(_L("[MediaServant]\t CMSMainContainer::PropertyChangedL \
       
   844             service not found"));
       
   845             }
       
   846         }
       
   847     
       
   848     if ( iUpdateList && !iUpdateList->IsActive() )
       
   849         {
       
   850         iCurStep = EFirstStep;
       
   851         iRequestCt = 1;
       
   852         iUpdateList->Start( TCallBack( BackgroundUpdateListL, this ) );
       
   853         }
       
   854     else
       
   855         {
       
   856         iRequestCt++;
       
   857         LOG(_L("[MediaServant]\t S.L add to queue"));
       
   858         }
       
   859     }
       
   860 
       
   861 // --------------------------------------------------------------------------
       
   862 // CMSMainContainer::SetManualWizardInfo
       
   863 // --------------------------------------------------------------------------
       
   864 //
       
   865 void CMSMainContainer::SetManualWizardInfo( TBool aAppWizardRun )
       
   866     {
       
   867     iAppWizardRun = aAppWizardRun;
       
   868     }
       
   869 
       
   870 
       
   871 // --------------------------------------------------------------------------
       
   872 // CMSMainContainer::ShowRefreshIndicationL
       
   873 // --------------------------------------------------------------------------
       
   874 //
       
   875 void CMSMainContainer::ShowRefreshIndicationL()
       
   876     {
       
   877     LOG(_L("[MediaServant]\t CMSMainContainer::ShowRefreshIndicationL"));
       
   878 
       
   879     iRefreshRunning = ETrue;
       
   880     // Start 0 %
       
   881     HBufC* naviText = StringLoader::LoadLC(
       
   882                                   R_MS_NAVI_REFRESHING_TEXT, 0 );
       
   883 
       
   884     // do number conversion
       
   885     TPtr ptr = naviText->Des();
       
   886     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   887 
       
   888     iView->SetNavigationPaneTextL( *naviText );
       
   889     CleanupStack::PopAndDestroy( naviText );
       
   890 
       
   891     UpdateListBoxDataL();
       
   892     }
       
   893 
       
   894 // --------------------------------------------------------------------------
       
   895 // CMSMainContainer::StopRefreshL
       
   896 // --------------------------------------------------------------------------
       
   897 //
       
   898 void CMSMainContainer::StopRefreshL()
       
   899     {
       
   900     LOG(_L("[MediaServant]\t CMSMainContainer::StopRefreshL"));
       
   901 
       
   902     iRefreshRunning = EFalse;
       
   903     iSyncRunning = ESyncNotRunning;
       
   904     iAppUi->FillRuleController()->UpdateArrayL();
       
   905     UpdateListBoxDataL();
       
   906     }
       
   907 
       
   908 // --------------------------------------------------------------------------
       
   909 // CMSMainContainer::StartSyncL
       
   910 // --------------------------------------------------------------------------
       
   911 //
       
   912 void CMSMainContainer::StartSyncL()
       
   913     {
       
   914     LOG(_L("[MediaServant]\t CMSMainContainer::StartSync"));
       
   915 
       
   916     iSyncRunning = ESyncRunning;
       
   917     TInt error = iAppUi->MSEngine()->ExecuteSyncL();
       
   918 
       
   919     if ( !error )
       
   920         {
       
   921         UpdateListBoxDataL();
       
   922 
       
   923         // set progress to 0%
       
   924         HBufC* progress = StringLoader::LoadLC(
       
   925                                        R_MS_NAVI_SYNC_TEXT, 0 );
       
   926 
       
   927         // do number conversion
       
   928         TPtr ptr = progress->Des();
       
   929         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   930 
       
   931         iView->SetNavigationPaneTextL( *progress );
       
   932         CleanupStack::PopAndDestroy( progress );
       
   933         }
       
   934     else
       
   935         {
       
   936         iSyncRunning = ESyncNotRunning;
       
   937         }
       
   938     }
       
   939 
       
   940 // --------------------------------------------------------------------------
       
   941 // CMSMainContainer::StartMetadataDeleteL
       
   942 // --------------------------------------------------------------------------
       
   943 //
       
   944 void CMSMainContainer::StartMetadataDeleteL()
       
   945     {
       
   946     LOG(_L("[MediaServant]\t CMSMainContainer::StartMetadataDeleteL"));
       
   947 
       
   948     iAppUi->MSEngine()->DeleteMetadataL();
       
   949     }
       
   950 
       
   951 // --------------------------------------------------------------------------
       
   952 // CMSMainContainer::SelectedItemIndex
       
   953 // returns current item index
       
   954 // --------------------------------------------------------------------------
       
   955 //
       
   956 TInt CMSMainContainer::SelectedItemIndex()
       
   957     {
       
   958     return iListBox->CurrentItemIndex();
       
   959     }
       
   960 
       
   961 // --------------------------------------------------------------------------
       
   962 // CMSMainContainer::ShowErrorNoteL
       
   963 // Shows error note
       
   964 // --------------------------------------------------------------------------
       
   965 //
       
   966 void CMSMainContainer::ShowErrorNoteL( TInt aTextResource )
       
   967     {
       
   968     LOG(_L("[MediaServant]\t CMSMainContainer::ShowErrorNoteL"));
       
   969     
       
   970     HBufC* errorText = StringLoader::LoadLC( aTextResource );
       
   971     CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote();
       
   972     dlg->ExecuteLD( *errorText );
       
   973     CleanupStack::PopAndDestroy( errorText );
       
   974     }
       
   975 
       
   976 // --------------------------------------------------------------------------
       
   977 // CMSMainContainer::SetNaviTextLastSyncL
       
   978 // Sets last synchronization time to navi pane
       
   979 // --------------------------------------------------------------------------
       
   980 //
       
   981 void CMSMainContainer::SetNaviTextLastSyncL()
       
   982     {
       
   983     LOG(_L("[MediaServant]\t CMSMainContainer::SetNaviTextLastSyncL"));
       
   984     
       
   985     TTimeIntervalMinutes syncMinutes;
       
   986     TTimeIntervalHours syncHours;
       
   987     TTimeIntervalDays syncDays;
       
   988 
       
   989     TTime lastSync = iAppUi->MSEngine()->LastSyncTime();
       
   990 
       
   991     if ( lastSync.Int64() > 0 )
       
   992         {
       
   993         // Get current time
       
   994         TTime time;
       
   995         time.HomeTime();
       
   996 
       
   997         time.MinutesFrom( lastSync, syncMinutes );
       
   998         time.HoursFrom( lastSync, syncHours );
       
   999         syncDays = time.DaysFrom( lastSync );
       
  1000 
       
  1001 
       
  1002         HBufC* naviText = NULL;
       
  1003 
       
  1004         TInt days = syncDays.Int();
       
  1005         TInt hours = syncHours.Int();            
       
  1006         TInt mins = syncMinutes.Int();            
       
  1007         if ( days > 0 )
       
  1008             {
       
  1009             naviText = ( days == 1 ? StringLoader::LoadLC(
       
  1010                                     R_MS_LAST_SYNC_DAY ) :
       
  1011                                      StringLoader::LoadLC(
       
  1012                                     R_MS_LAST_SYNC_DAYS, days ));
       
  1013             }        
       
  1014         else if ( hours > 0 )
       
  1015             {
       
  1016             naviText = ( hours == 1 ? StringLoader::LoadLC(
       
  1017                                     R_MS_LAST_SYNC_HOUR ) :
       
  1018                                      StringLoader::LoadLC(
       
  1019                                     R_MS_LAST_SYNC_HOURS, hours ));
       
  1020             }          
       
  1021         else if ( mins > 0 )
       
  1022             {
       
  1023             naviText = ( mins == 1 ? StringLoader::LoadLC(
       
  1024                                    R_MS_LAST_SYNC_MIN ) :
       
  1025                                      StringLoader::LoadLC(
       
  1026                                    R_MS_LAST_SYNC_MINS, mins ));
       
  1027             }
       
  1028         else
       
  1029             {
       
  1030             // do nothing - leave navi pane empty
       
  1031             }
       
  1032 
       
  1033         if ( naviText )
       
  1034             {
       
  1035             // do number conversion
       
  1036             TPtr ptr = naviText->Des();
       
  1037             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
  1038 
       
  1039             iView->SetNavigationPaneTextL( *naviText );
       
  1040             CleanupStack::PopAndDestroy( naviText );
       
  1041             }
       
  1042         }
       
  1043     }
       
  1044 
       
  1045 // --------------------------------------------------------------------------
       
  1046 // CMSMainContainer::SizeChanged()
       
  1047 // Called by framework when the view size is changed.
       
  1048 // --------------------------------------------------------------------------
       
  1049 //
       
  1050 void CMSMainContainer::SizeChanged()
       
  1051     {
       
  1052     // container control resize code.
       
  1053     if ( iListBox )
       
  1054         {
       
  1055         iListBox->SetRect( Rect() ); // Set rectangle of listbox.
       
  1056         }
       
  1057     }
       
  1058 
       
  1059 // --------------------------------------------------------------------------
       
  1060 // CMSMainContainer::HandleResourceChange
       
  1061 // Handles layout change
       
  1062 // --------------------------------------------------------------------------
       
  1063 //
       
  1064 void CMSMainContainer::HandleResourceChange( TInt aType )
       
  1065     {
       
  1066     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1067         {
       
  1068         SetRect( iView->ClientRect() );
       
  1069         }
       
  1070 
       
  1071     CCoeControl::HandleResourceChange( aType );
       
  1072     }
       
  1073 
       
  1074 // --------------------------------------------------------------------------
       
  1075 // CMSMainContainer::TimerCallbackL()
       
  1076 // Periodic timer callback
       
  1077 // --------------------------------------------------------------------------
       
  1078 //
       
  1079 TInt CMSMainContainer::TimerCallbackL(TAny* aObject)
       
  1080     {        
       
  1081     CMSMainContainer* mainContainer =
       
  1082                             static_cast<CMSMainContainer*>(aObject);
       
  1083     TCmServerState state;
       
  1084     mainContainer->iAppUi->MSEngine()->ServerState( state );
       
  1085     if ( state == ECmServerStateIdle )
       
  1086         {
       
  1087         mainContainer->SetNaviTextLastSyncL();
       
  1088         }
       
  1089     return 0;
       
  1090     }
       
  1091 
       
  1092 // --------------------------------------------------------------------------
       
  1093 // CMSMainContainer::NaviTimerCallbackL()
       
  1094 // --------------------------------------------------------------------------
       
  1095 //
       
  1096 TInt CMSMainContainer::NaviTimerCallbackL(TAny* aObject)
       
  1097     {        
       
  1098     CMSMainContainer* mainContainer =
       
  1099                             static_cast<CMSMainContainer*>(aObject);
       
  1100     TCmServerState state;
       
  1101     mainContainer->iAppUi->MSEngine()->ServerState( state );
       
  1102     
       
  1103     // Clear old text
       
  1104     mainContainer->iView->ClearCurrentNaviPaneText();
       
  1105     
       
  1106     if ( state == ECmServerStateIdle )
       
  1107         {
       
  1108         mainContainer->SetNaviTextLastSyncL();
       
  1109         }
       
  1110     
       
  1111     mainContainer->iNaviTimer->Cancel();
       
  1112     
       
  1113     return 0;
       
  1114     }
       
  1115     
       
  1116 // --------------------------------------------------------------------------
       
  1117 // CMSMainContainer::BackgroundUpdateListL
       
  1118 // Static callback method for update list box data
       
  1119 // --------------------------------------------------------------------------
       
  1120 //
       
  1121 TInt CMSMainContainer::BackgroundUpdateListL( TAny* aObject )
       
  1122     {
       
  1123     LOG(_L("[MediaServant]\t CMSMainContainer::BackgroundUpdateListL"));
       
  1124     TInt reslt = ( ( CMSMainContainer* )aObject )->UpdateListByStepL();
       
  1125     return reslt;
       
  1126     }
       
  1127 
       
  1128 // --------------------------------------------------------------------------
       
  1129 // CMSMainContainer::UpdateListByStepL
       
  1130 // Update list box data steps
       
  1131 // --------------------------------------------------------------------------
       
  1132 //
       
  1133 TInt CMSMainContainer::UpdateListByStepL()
       
  1134     {
       
  1135     TRACE(Print(_L("[MediaServant]\t CMSMainContainer:UpdateListByStepL \
       
  1136         step: %d %d"), iCurStep, iUpdateList->IsActive()));
       
  1137 
       
  1138     // Get file counts and sync time
       
  1139     static TInt staItemsToBeStored( 0 );
       
  1140     static TInt staItemsToBeFilled( 0 );
       
  1141     static TInt staSyncTime( 0 );
       
  1142     static TInt staSyncTimeStore( 0 );
       
  1143     static TInt staSyncTimeFill( 0 );
       
  1144     static TBool staDriveSelected( ETrue );
       
  1145 
       
  1146     switch ( iCurStep )
       
  1147         {
       
  1148         case EFirstStep:
       
  1149             {
       
  1150             iAppUi->MSEngine()->GetTransferInfo( ECmServiceStore,
       
  1151                                                  staItemsToBeStored,
       
  1152                                                  staSyncTimeStore );
       
  1153             break;
       
  1154             }
       
  1155         case ESecondStep:
       
  1156             {
       
  1157             iAppUi->MSEngine()->GetTransferInfo( ECmServiceFill,
       
  1158                                                  staItemsToBeFilled,
       
  1159                                                  staSyncTimeFill );
       
  1160             break;
       
  1161             }
       
  1162         case EThirdStep:
       
  1163             {
       
  1164             staDriveSelected = iAppUi->DriveSelectedL();
       
  1165             break;
       
  1166             }
       
  1167         case EForthStep:
       
  1168         //fall through
       
  1169         default:
       
  1170             {
       
  1171             TInt icon = EIconSync;
       
  1172             // Create item strings
       
  1173             HBufC* primaryText = NULL;
       
  1174             HBufC* secondaryText = NULL;
       
  1175             
       
  1176             CDesCArray* itemArray = static_cast<CDesCArray*>
       
  1177                                         (iListBox->Model()->ItemTextArray());
       
  1178             if ( itemArray->Count() )
       
  1179                 {
       
  1180                 // delete all listbox items
       
  1181                itemArray->Reset();
       
  1182                 }
       
  1183             staSyncTime = staSyncTimeStore + staSyncTimeFill;
       
  1184             //home-sync item
       
  1185             switch ( iSyncRunning )
       
  1186                 {
       
  1187                 default:
       
  1188                 // fall trough
       
  1189                 case ESyncNotRunning:
       
  1190                     {
       
  1191                     primaryText = StringLoader::LoadLC(
       
  1192                                       R_MAIN_SYNC_NOW_TEXT );
       
  1193                     if ( staItemsToBeStored > 0 || staItemsToBeFilled > 0 )
       
  1194                         {
       
  1195                         if ( staSyncTime/60 > 1 ) // 1 minute
       
  1196                             {
       
  1197                             secondaryText = StringLoader::LoadLC(
       
  1198                                                 R_MS_SYNC_TIME_TEXT,
       
  1199                                                 staSyncTime/60 );
       
  1200                             // do number conversion
       
  1201                             TPtr ptr = secondaryText->Des();
       
  1202                             AknTextUtils::
       
  1203                                DisplayTextLanguageSpecificNumberConversion( ptr );
       
  1204                             }
       
  1205                         else
       
  1206                             {
       
  1207                             secondaryText = StringLoader::LoadLC(
       
  1208                                                 R_MS_SYNC_TIME_ONE_MIN_TEXT );
       
  1209                             }
       
  1210                         }
       
  1211                     break;
       
  1212                     }
       
  1213                 case ESyncRunning:
       
  1214                     {
       
  1215                     primaryText = StringLoader::LoadLC(
       
  1216                                       R_MAIN_STOP_SYNC_TEXT );
       
  1217                     icon = EIconSyncStop;
       
  1218                     break;
       
  1219                     }
       
  1220                 case ESyncWaiting:
       
  1221                     {
       
  1222                     primaryText = StringLoader::LoadLC( 
       
  1223                                       R_MAIN_STOP_SYNC_TEXT );
       
  1224                     secondaryText = StringLoader::LoadLC(
       
  1225                                         R_MS_SYNC_WAITING_TEXT );
       
  1226                     icon = EIconSyncStop;
       
  1227                     break;
       
  1228                     }
       
  1229                 }
       
  1230             AppendItemToListBoxArrayL( iListBox,
       
  1231                                        iListBox->Model(),
       
  1232                                        icon,
       
  1233                                        *primaryText,
       
  1234                                        *secondaryText );
       
  1235 
       
  1236             if ( secondaryText )
       
  1237                 {
       
  1238                 CleanupStack::PopAndDestroy( secondaryText );
       
  1239                 secondaryText = NULL;
       
  1240                 }
       
  1241 
       
  1242             if ( primaryText )
       
  1243                 {
       
  1244                 CleanupStack::PopAndDestroy( primaryText );
       
  1245                 primaryText = NULL;
       
  1246                 }
       
  1247             
       
  1248             // From Home -item
       
  1249             primaryText = StringLoader::LoadLC( R_MAIN_FROM_HOME_TEXT );
       
  1250             
       
  1251             if ( staDriveSelected == EFalse )
       
  1252                 {
       
  1253                 secondaryText = StringLoader::LoadLC( 
       
  1254                                     R_MS_MEMORY_CARD_NEEDED_TEXT );
       
  1255                 }
       
  1256             else if ( !iFillListSelected )
       
  1257                 {
       
  1258                 secondaryText = StringLoader::LoadLC( 
       
  1259                                     R_MS_LIST_NOTHING_SELECTED );
       
  1260                 }
       
  1261             else if ( staItemsToBeFilled <= 0 )
       
  1262                 {
       
  1263                 secondaryText = StringLoader::LoadLC( 
       
  1264                                     R_MS_ALL_IN_SYNC_TEXT );
       
  1265                 }
       
  1266 
       
  1267             if ( iRefreshRunning ||
       
  1268                  iPreprocessRunning ||
       
  1269                  iSyncRunning == ESyncRunning ||
       
  1270                  staDriveSelected == EFalse )
       
  1271                 {
       
  1272                 AppendItemToListBoxArrayL( iListBox,
       
  1273                                            iListBox->Model(),
       
  1274                                            EIconFromHomeInactive,
       
  1275                                            *primaryText,
       
  1276                                            *secondaryText );
       
  1277                 }
       
  1278             else
       
  1279                 {
       
  1280                 AppendItemToListBoxArrayL( iListBox,
       
  1281                                            iListBox->Model(),
       
  1282                                            EIconFromHome,
       
  1283                                            *primaryText,
       
  1284                                            *secondaryText );
       
  1285                 }
       
  1286 
       
  1287             if ( secondaryText )
       
  1288                 {
       
  1289                 CleanupStack::PopAndDestroy( secondaryText );
       
  1290                 secondaryText = NULL;
       
  1291                 }
       
  1292 
       
  1293             CleanupStack::PopAndDestroy( primaryText );
       
  1294             primaryText = NULL;
       
  1295 
       
  1296             // To Home -item
       
  1297             primaryText = StringLoader::LoadLC( R_MAIN_TO_HOME_TEXT );
       
  1298           
       
  1299 
       
  1300             if ( staItemsToBeStored < 1 )
       
  1301                 {
       
  1302                 secondaryText = StringLoader::LoadLC(
       
  1303                                             R_MS_ALL_IN_SYNC_TEXT );
       
  1304                 }
       
  1305             else if ( staItemsToBeStored == 1 )
       
  1306                 {
       
  1307                 secondaryText = StringLoader::LoadLC(
       
  1308                                             R_MS_SYNC_ONE_NEW_ITEM_TEXT );
       
  1309                 }
       
  1310             else // > 1      
       
  1311                 {
       
  1312                 secondaryText = StringLoader::LoadLC(
       
  1313                                             R_MS_SYNC_NEW_ITEMS_TEXT,
       
  1314                                             staItemsToBeStored );
       
  1315                 // do number conversion
       
  1316                 TPtr ptr = secondaryText->Des();
       
  1317                 AknTextUtils::
       
  1318                     DisplayTextLanguageSpecificNumberConversion( ptr );
       
  1319                 }
       
  1320 
       
  1321             if ( iRefreshRunning ||
       
  1322                  iPreprocessRunning ||
       
  1323                  iSyncRunning == ESyncRunning )
       
  1324                 {
       
  1325                 AppendItemToListBoxArrayL( iListBox,
       
  1326                                            iListBox->Model(),
       
  1327                                            EIconToHomeInactive,
       
  1328                                            *primaryText,
       
  1329                                            *secondaryText );
       
  1330                 }
       
  1331             else
       
  1332                 {
       
  1333                 AppendItemToListBoxArrayL( iListBox,
       
  1334                                            iListBox->Model(),
       
  1335                                            EIconToHome,
       
  1336                                            *primaryText,
       
  1337                                            *secondaryText );
       
  1338                 }
       
  1339 
       
  1340             if ( secondaryText )
       
  1341                 {
       
  1342                 CleanupStack::PopAndDestroy( secondaryText );
       
  1343                 secondaryText = NULL;
       
  1344                 }
       
  1345             CleanupStack::PopAndDestroy( primaryText );
       
  1346             primaryText = NULL;
       
  1347             iListBox->DrawNow();
       
  1348             break;
       
  1349             }
       
  1350         }
       
  1351     TInt theValue = ( TInt )iCurStep;
       
  1352     theValue++;
       
  1353     iCurStep = ( TMSUpdateStep )theValue;
       
  1354     
       
  1355     //complete one refresh request
       
  1356     TInt reslt( 0 );
       
  1357     if( iCurStep == EEndStep )
       
  1358         {
       
  1359         iRequestCt--;
       
  1360         if( iRequestCt )
       
  1361             {
       
  1362             iCurStep = EFirstStep;
       
  1363             }
       
  1364         //if still have request,continue
       
  1365         reslt = iRequestCt;
       
  1366         }
       
  1367     //not the last step, contiue
       
  1368     else
       
  1369         {
       
  1370         reslt = ETrue;
       
  1371         }
       
  1372     return reslt;
       
  1373     }
       
  1374 
       
  1375 // ---------------------------------------------------------------------------
       
  1376 // CMSMainContainer::GetHelpContext
       
  1377 // ---------------------------------------------------------------------------
       
  1378 //
       
  1379 void CMSMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1380     {
       
  1381     LOG(_L("[MediaServant]\t CMSMainContainer::GetHelpContext"));
       
  1382 
       
  1383     aContext.iMajor = TUid::Uid(KMediaServantUID3);
       
  1384     aContext.iContext = KMSERV_HLP_MAIN_VIEW;
       
  1385     }
       
  1386 
       
  1387 // --------------------------------------------------------------------------
       
  1388 // CMSMainContainer::MemoryCardChangedL
       
  1389 // Callback to handle mmc insert
       
  1390 // --------------------------------------------------------------------------
       
  1391 //
       
  1392 void CMSMainContainer::MemoryCardChangedL( TMemoryCardEvent aEvent )
       
  1393     {
       
  1394     LOG(_L("[MediaServant]\t CMSMainContainer::MemoryCardChangedL start"));
       
  1395     switch ( aEvent )
       
  1396         {
       
  1397         case EMemoryCardInsert:
       
  1398             {
       
  1399             if( !iAppUi->DriveSelectedL() )
       
  1400                 {
       
  1401                 iView->CheckMemoryCardL();
       
  1402                 }
       
  1403             UpdateListBoxDataL();
       
  1404             break;
       
  1405             }
       
  1406         default:
       
  1407             {
       
  1408             LOG(_L("[MediaServant]\t CMSMainContainer::MemoryCardChangedL \
       
  1409             event not found"));
       
  1410             break;
       
  1411             }
       
  1412         }
       
  1413     LOG(_L("[MediaServant]\t CMSMainContainer::MemoryCardChangedL end"));
       
  1414     }
       
  1415 
       
  1416 // --------------------------------------------------------------------------
       
  1417 // CMSMainContainer::CheckIfFillListSelected
       
  1418 // --------------------------------------------------------------------------
       
  1419 //
       
  1420 TBool CMSMainContainer::CheckIfFillListSelected()
       
  1421     {
       
  1422     LOG(_L("[MediaServant]\t CMSMainContainer::CheckIfFillListSelected"));
       
  1423     
       
  1424     TBool listSelected( EFalse );
       
  1425     RPointerArray<CMSFillList>* listArray =
       
  1426                         iAppUi->FillRuleController()->FillListArray();
       
  1427     
       
  1428     for ( TInt i = 0; i < listArray->Count(); i++  )
       
  1429         {
       
  1430         CCmFillRule* list = (*listArray)[i]->List();
       
  1431         if ( list->Selected() == ECmSelected )
       
  1432             {
       
  1433             listSelected = ETrue;
       
  1434             i = listArray->Count(); // break loop
       
  1435             }
       
  1436         }
       
  1437     return listSelected;
       
  1438     }
       
  1439 
       
  1440 // --------------------------------------------------------------------------
       
  1441 // CMSMainContainer::ShowRefreshCompleteTextL
       
  1442 // --------------------------------------------------------------------------
       
  1443 //
       
  1444 void CMSMainContainer::ShowRefreshCompleteTextL()
       
  1445     {
       
  1446     LOG(_L("[MediaServant]\t CMSMainContainer::ShowRefreshCompleteTextL"));
       
  1447     
       
  1448     HBufC* naviText = StringLoader::LoadLC( R_MS_NAVI_CONTENT_REFRESHED );
       
  1449     iView->SetNavigationPaneTextL( *naviText );
       
  1450     CleanupStack::PopAndDestroy( naviText );    
       
  1451     }
       
  1452 // End of File
       
  1453