homesync/contentmanager/mediaservant/src/msmainview.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:  CMSMainView class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <mediaservant.rsg>
       
    21 #include <StringLoader.h>
       
    22 #include <hlplch.h>
       
    23 #include <driveinfo.h>
       
    24 
       
    25 #include "msgspluginuids.h"
       
    26 #include "msstorelistcontroller.h"
       
    27 #include "cmsettingsfactory.h"
       
    28 #include "cmsettings.h"
       
    29 #include "cmdriveinfo.h"
       
    30 #include "msmaincontainer.h"
       
    31 #include "mediaservant.hrh"
       
    32 #include "msgsinterface.h"
       
    33 #include "msengine.h"
       
    34 #include "msconstants.h"
       
    35 #include "msmainview.h"
       
    36 #include "msappui.h"
       
    37 #include "msdebug.h"
       
    38 #include "cmsappwizard.h"
       
    39 
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CMSMainView::CMSMainView()
       
    43 // --------------------------------------------------------------------------
       
    44 //
       
    45 CMSMainView::CMSMainView(CMSAppUi& aAppUi )
       
    46     {
       
    47     LOG(_L("[MediaServant]\t CMSMainView::CMSMainView"));
       
    48 
       
    49     iAppUi = &aAppUi;
       
    50     iCheckMMC = ETrue;
       
    51 
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // CMSMainView::ConstructL()
       
    56 // --------------------------------------------------------------------------
       
    57 //
       
    58 void CMSMainView::ConstructL()
       
    59     {
       
    60     LOG(_L("[MediaServant]\t CMSMainView::ConstructL"));
       
    61 
       
    62     BaseConstructL( R_MS_MAIN_VIEW );
       
    63 
       
    64     TInt error( KErrNone );
       
    65     TBool runWizard( EFalse );
       
    66 
       
    67     // Check if wizard has been executed:
       
    68     runWizard = iAppUi->MSEngine()->GetAppWizardState( error );
       
    69 
       
    70     TRACE( Print(_L("[MediaServant]\t CMSMainView::ConstructL \
       
    71                     wizard state error = %d"), error ));
       
    72 
       
    73     if ( error == KErrNone && !runWizard )
       
    74         {
       
    75         // prevent user events handling
       
    76         iWizardInitialization = ETrue;
       
    77         iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
    78         TCallBack cb( InitializeWizardL, this );
       
    79         iIdle->Start( cb );
       
    80         }
       
    81     else
       
    82         {
       
    83         iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
    84         TCallBack cb( InitializeMemoryCardL, this );
       
    85         iIdle->Start( cb );
       
    86         }
       
    87     }
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CMSMainView::~CMSMainView()
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 CMSMainView::~CMSMainView()
       
    94     {
       
    95     LOG(_L("[MediaServant]\t CMSMainView::~CMSMainView"));
       
    96 
       
    97     delete iIdle;
       
    98 
       
    99     DoDeactivate();
       
   100     }
       
   101 // --------------------------------------------------------------------------
       
   102 // TUid CMSMainView::Id()
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 TUid CMSMainView::Id() const
       
   106     {
       
   107     LOG(_L("[MediaServant]\t CMSMainView::Id"));
       
   108 
       
   109     return KMSMainViewId;
       
   110     }
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // CMSFillView::FocusIndex()
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 TInt CMSMainView::FocusIndex() const
       
   117     {
       
   118     return iContainer->SelectedItemIndex();
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CMSMainView::HandleCommandL(TInt aCommand)
       
   123 // --------------------------------------------------------------------------
       
   124 //
       
   125 void CMSMainView::HandleCommandL( TInt aCommand )
       
   126     {
       
   127     LOG(_L("[MediaServant]\t CMSMainView::HandleCommandL"));
       
   128 
       
   129     if ( !iWizardInitialization )
       
   130         {
       
   131         switch ( aCommand )
       
   132             {
       
   133             case EMSCmdSelect:
       
   134             // fall through
       
   135             case EAknCmdOpen:
       
   136             // fall through:
       
   137             case EAknSoftkeyOpen:
       
   138             // fall through:
       
   139             case EAknSoftkeySelect:
       
   140                 {
       
   141                 iContainer->OpenSelectedListboxItemL();
       
   142                 break;
       
   143                 }
       
   144 
       
   145             case EMSCmdStartHarvest:
       
   146                 {
       
   147                 iAppUi->MSEngine()->ScanMediaServersL();
       
   148                 iContainer->ShowRefreshIndicationL();
       
   149                 break;
       
   150                 }
       
   151 
       
   152             case EMSCmdStopHarvest:
       
   153                 {
       
   154                 // clear navi pane
       
   155                 ClearCurrentNaviPaneText();
       
   156 
       
   157                 iAppUi->MSEngine()->StopOperation();
       
   158                 iContainer->StopRefreshL();
       
   159                 break;
       
   160                 }
       
   161 
       
   162             case EMSCmdSettings:
       
   163                 {
       
   164                 if ( iAppUi->SettingsPlugin() )
       
   165                     {
       
   166                     // activate plugin
       
   167                     iAppUi->ActivateLocalViewL(
       
   168                                 iAppUi->SettingsPlugin()->Id() );
       
   169                     }
       
   170                 break;
       
   171                 }
       
   172             case EMSCmdRunWizard:
       
   173                 {
       
   174                 LOG(_L("[MediaServant]\t CMSMainView::\
       
   175                         HandleCommandL WIZARD"));
       
   176                 TBool wizRetVal(KErrNone);
       
   177                 CMSAppWizard* wiz =
       
   178                     CMSAppWizard::NewL( *iAppUi->MSEngine() );
       
   179                 CleanupStack::PushL( wiz );
       
   180                 wizRetVal = wiz->StartL();
       
   181 
       
   182                 iAppUi->RefreshListsL();
       
   183                 CleanupStack::PopAndDestroy( wiz );
       
   184 
       
   185                 if( wizRetVal != KErrNone )
       
   186                     {
       
   187                     // Start harvest:
       
   188                     LOG(_L("[MediaServant]\t CMSMainView::\
       
   189                             HandleCommandL WIZARD, Start Harvest"));
       
   190                     iContainer->SetManualWizardInfo( ETrue );
       
   191                     iContainer->StartMetadataDeleteL();
       
   192                     iContainer->ShowRefreshIndicationL();
       
   193                     }
       
   194 
       
   195                 break;
       
   196                 }
       
   197 
       
   198             case EAknCmdHelp :
       
   199                 {
       
   200 
       
   201                 TRAP_IGNORE( HlpLauncher::LaunchHelpApplicationL(
       
   202                             iEikonEnv->WsSession(),
       
   203                 iEikonEnv->EikAppUi()->AppHelpContextL() ));
       
   204                 break;
       
   205                 }
       
   206 
       
   207             default:
       
   208                 {
       
   209                 AppUi()->HandleCommandL( aCommand );
       
   210                 break;
       
   211                 }
       
   212             }
       
   213         }
       
   214     }
       
   215 
       
   216 
       
   217 
       
   218 // --------------------------------------------------------------------------
       
   219 // CMSMainView::DoActivateL(...)
       
   220 // --------------------------------------------------------------------------
       
   221 //
       
   222 void CMSMainView::DoActivateL(
       
   223    const TVwsViewId& aPrevViewId, TUid /*aCustomMessageId*/,
       
   224    const TDesC8& /*aCustomMessage*/)
       
   225     {
       
   226     LOG(_L("[MediaServant]\t CMSMainView::DoActivateL"));
       
   227     if( KMSGSImplementationUid == aPrevViewId.iViewUid )
       
   228         {
       
   229         // Refresh store and fill rules array from server.
       
   230         iAppUi->RefreshListsL();
       
   231 
       
   232         CCmStoreRuleContainer* container =
       
   233                     ( iAppUi->StoreListController() )->StoreListContainer();
       
   234         // update the Table transferInfo
       
   235         iAppUi->MSEngine()->SetStoreRulesL( container );
       
   236         }
       
   237 
       
   238     // Set title pane text to default
       
   239     SetTitlePaneTextL( KMSDefaultTitleId );
       
   240 
       
   241     if ( !iContainer )
       
   242         {
       
   243         iContainer = new (ELeave) CMSMainContainer( *iAppUi,
       
   244                                                     *this );
       
   245         iContainer->ConstructL( ClientRect() );
       
   246         iContainer->SetMopParent( this );
       
   247         AppUi()->AddToViewStackL( *this, iContainer );
       
   248         }
       
   249    }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // CMSMainView::DoDeactivate()
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 void CMSMainView::DoDeactivate()
       
   256     {
       
   257     LOG(_L("[MediaServant]\t CMSMainView::DoDeactivate"));
       
   258 
       
   259     if ( iContainer )
       
   260         {
       
   261         AppUi()->RemoveFromStack( iContainer );
       
   262         }
       
   263 
       
   264     delete iContainer; // Deletes the container class object.
       
   265     iContainer = NULL;
       
   266 
       
   267     ClearCurrentNaviPaneText();
       
   268     }
       
   269 
       
   270 // --------------------------------------------------------------------------
       
   271 // CMSMainView::DynInitMenuPaneL
       
   272 // --------------------------------------------------------------------------
       
   273 //
       
   274 void CMSMainView::DynInitMenuPaneL( TInt aResourceId,
       
   275                                          CEikMenuPane* aMenuPane)
       
   276     {
       
   277     LOG(_L("[MediaServant]\t CMSMainView::DynInitMenuPaneL"));
       
   278 
       
   279     TCmServerState state;
       
   280 
       
   281     if (aResourceId == R_MAIN_VIEW_MENU )
       
   282         {
       
   283         iAppUi->MSEngine()->ServerState( state );
       
   284 
       
   285         switch ( state )
       
   286             {
       
   287             case ECmServerStateHarvesting:
       
   288                 {
       
   289                 aMenuPane->SetItemDimmed(EMSCmdStartHarvest, ETrue);
       
   290                 aMenuPane->SetItemDimmed(EMSCmdSettings, ETrue);
       
   291                 aMenuPane->SetItemDimmed(EMSCmdRunWizard, ETrue);
       
   292                 break;
       
   293                 }
       
   294             case ECmServerStateDeleting:
       
   295             // fall through
       
   296             case ECmServerStateFilling:
       
   297             // fall through
       
   298             case ECmServerStateStoring:
       
   299             // fall through
       
   300             case ECmServicePreProcessingStore:
       
   301             // fall through
       
   302             case ECmServicePreProcessingFill:
       
   303                 {
       
   304                 aMenuPane->SetItemDimmed(EMSCmdStartHarvest, ETrue);
       
   305                 aMenuPane->SetItemDimmed(EMSCmdStopHarvest, ETrue);
       
   306                 aMenuPane->SetItemDimmed(EMSCmdSettings, ETrue);
       
   307                 aMenuPane->SetItemDimmed(EMSCmdRunWizard, ETrue);
       
   308                 break;
       
   309                 }
       
   310             default:
       
   311                 {
       
   312                 aMenuPane->SetItemDimmed(EMSCmdStopHarvest, ETrue);
       
   313                 }
       
   314             }
       
   315 
       
   316         // sync item highlighted
       
   317         if ( iContainer->SelectedItemIndex() == 0 )
       
   318             {
       
   319             aMenuPane->SetItemDimmed( EAknCmdOpen, ETrue );
       
   320             }
       
   321         else
       
   322             {
       
   323             aMenuPane->SetItemDimmed( EMSCmdSelect, ETrue );
       
   324             }
       
   325 
       
   326         }
       
   327     }
       
   328 
       
   329 // --------------------------------------------------------------------------
       
   330 // CMSMainView::SetCbaL()
       
   331 // Changes softkeys
       
   332 // --------------------------------------------------------------------------
       
   333 //
       
   334 void CMSMainView::SetCbaL( TBool aHighlightedIndex )
       
   335     {
       
   336     CEikButtonGroupContainer* cba = Cba();
       
   337 
       
   338     if ( aHighlightedIndex == EStoreAndFill )
       
   339         {
       
   340         cba->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK__SELECT );
       
   341         }
       
   342     else
       
   343         {
       
   344         cba->SetCommandSetL( R_MS_SOFTKEYS_OPTIONS_BACK__OPEN );
       
   345         }
       
   346     cba->DrawDeferred();
       
   347     }
       
   348 
       
   349 // --------------------------------------------------------------------------
       
   350 // CMSMainView::CheckMemoryCardL
       
   351 // Checks if memory card has been changed
       
   352 // --------------------------------------------------------------------------
       
   353 //
       
   354 void CMSMainView::CheckMemoryCardL()
       
   355     {
       
   356     LOG(_L("[MediaServant]\t CMSMainView::CheckMemoryCardL"));
       
   357 
       
   358     RFs& fileServer = iAppUi->FsSession();
       
   359     RPointerArray<CCmDriveInfo> storedDrives;
       
   360     CleanupClosePushL( storedDrives );
       
   361     RPointerArray<CCmDriveInfo> driveArray;
       
   362     CleanupClosePushL( driveArray );
       
   363 
       
   364     MCmSettings* settings = CCmSettingsFactory::NewCmSettingsEngineLC();
       
   365 
       
   366     // read stored info of stored drives
       
   367     iAppUi->MSEngine()->GetDrivesL( storedDrives );
       
   368 
       
   369     // get system drive info
       
   370     settings->DriveListL( fileServer, driveArray );
       
   371 
       
   372     TInt count = driveArray.Count();
       
   373 
       
   374     for ( TInt i = 0; i < count; i++ )
       
   375         {
       
   376         TRACE(
       
   377             Print(_L("[MediaServant]\t CMSMainView::drivearray type = %d"), \
       
   378             driveArray[i]->DriveType()));
       
   379 
       
   380         // check if mmc card is found
       
   381         if ( driveArray[i]->DriveType() == DriveInfo::EDriveRemovable )
       
   382             {
       
   383             // check if memory card is used before
       
   384             TIdentityRelation<CCmDriveInfo> relation(CMSAppUi::CompareIds );
       
   385             TInt index = storedDrives.Find( driveArray[i], relation );
       
   386             if ( index == KErrNotFound )
       
   387                 {
       
   388                 ShowAndHandleMMCQueryL( *&storedDrives,
       
   389                                         *&driveArray,
       
   390                                         i );
       
   391 
       
   392                 iAppUi->MSEngine()->ExecuteStorePreProcessingL();
       
   393 
       
   394                 i = count; // break loop
       
   395                 }
       
   396             }
       
   397         }
       
   398 
       
   399     settings->Close();
       
   400     CleanupStack::Pop(); // settings
       
   401     driveArray.ResetAndDestroy();
       
   402     storedDrives.ResetAndDestroy();
       
   403     CleanupStack::PopAndDestroy( 2, &storedDrives );
       
   404     }
       
   405 
       
   406 // --------------------------------------------------------------------------
       
   407 // CMSMainView::ShowAndHandleMMCQueryL
       
   408 // Shows mmc query and handles selection
       
   409 // --------------------------------------------------------------------------
       
   410 //
       
   411 void CMSMainView::ShowAndHandleMMCQueryL(
       
   412                                 RPointerArray<CCmDriveInfo>& aStoredArray,
       
   413                                 RPointerArray<CCmDriveInfo>& aDriveArray,
       
   414                                 TInt index )
       
   415     {
       
   416     LOG(_L("[MediaServant]\t CMSMainView::ShowAndHandleMMCQueryL"));
       
   417 
       
   418     // Show delete files query
       
   419     CAknQueryDialog* query= CAknQueryDialog::NewL(
       
   420                                      CAknQueryDialog::ENoTone );
       
   421 
       
   422     if ( query->ExecuteLD( R_MSERV_MMC_QUERY ) )
       
   423         {
       
   424         TInt driveCount = aStoredArray.Count();
       
   425         // search and delete existing mmc card info
       
   426         for ( TInt i = driveCount - 1 ; i >= 0 ; i-- )
       
   427             {
       
   428           TRACE( Print( _L("[MediaServant]\t CMSAppUi::storedarray \
       
   429                   type = %d"), aStoredArray[i]->DriveType() ) );
       
   430             if ( aStoredArray[i]->DriveType() == DriveInfo::EDriveRemovable )
       
   431                 {
       
   432                 delete aStoredArray[i];
       
   433                 aStoredArray[i] = NULL;
       
   434                 aStoredArray.Remove(i);
       
   435                 LOG(_L("[MediaServant]\t CMSMainView::CheckMemoryCardL \
       
   436                 old mmc info removed"));
       
   437                 }
       
   438             }
       
   439         TInt64 quota =
       
   440                ( aDriveArray[index]->DriveSize() * KMMCDefaultQuota ) / 100;
       
   441         aDriveArray[index]->SetDriveQuota( quota );
       
   442         aDriveArray[index]->SetStatus( ETrue );
       
   443         // then append new one
       
   444         aStoredArray.Append( aDriveArray[index] );
       
   445         // ownership transferred->remove pointer from drivearray
       
   446         aDriveArray.Remove(index);
       
   447 
       
   448         // store drives
       
   449         iAppUi->MSEngine()->SetDrivesL( aStoredArray );
       
   450         }
       
   451     }
       
   452 
       
   453 // --------------------------------------------------------------------------
       
   454 // CMSMainView::InitializeWizardL
       
   455 // Starts the wizard when run first time
       
   456 // --------------------------------------------------------------------------
       
   457 //
       
   458 TBool CMSMainView::InitializeWizardL( TAny* aPtr )
       
   459     {
       
   460     CMSMainView* main = static_cast< CMSMainView* >( aPtr );
       
   461 
       
   462     return main->DoInitializeWizardL();
       
   463     }
       
   464 
       
   465 // --------------------------------------------------------------------------
       
   466 // CMSMainView::InitializeMemoryCardL
       
   467 // Starts the new memroy card when new memory card inserted
       
   468 // --------------------------------------------------------------------------
       
   469 //
       
   470 TInt CMSMainView::InitializeMemoryCardL( TAny* aPtr )
       
   471     {
       
   472     CMSMainView* main = static_cast< CMSMainView* >( aPtr );
       
   473 
       
   474     main->DoInitializeMemoryCardL();
       
   475 
       
   476     return KErrNone;
       
   477     }
       
   478 
       
   479 // --------------------------------------------------------------------------
       
   480 // CMSMainView::DoInitializeWizardL
       
   481 // Do starts the wizard when run first time
       
   482 // --------------------------------------------------------------------------
       
   483 //
       
   484 TBool CMSMainView::DoInitializeWizardL()
       
   485     {
       
   486     LOG(_L("[MediaServant]\t CMSAppUi::DoInitializeWizardL"));
       
   487         TInt wizRetVal(KErrNone);
       
   488 
       
   489     TRAPD( error, wizRetVal = iAppUi->RunWizardL() );
       
   490 
       
   491     if ( error )
       
   492         {
       
   493         TRACE(Print(_L("[MediaServant]\t DoInitializeWizardL::\
       
   494         wizard error value: %d"), error));
       
   495         }
       
   496 
       
   497     if( wizRetVal != KErrNone)
       
   498         {
       
   499         iContainer->SetManualWizardInfo( ETrue );
       
   500         iAppUi->RefreshListsL();
       
   501         iContainer->StartMetadataDeleteL();
       
   502         iContainer->ShowRefreshIndicationL();
       
   503         }
       
   504     else
       
   505         {
       
   506         TRACE(Print(_L("[MediaServant]\t DoInitializeWizardL::\
       
   507         wizard return value: %d"), wizRetVal));
       
   508         // wizard cancelled. Check memory card
       
   509         iContainer->MemoryCardChangedL(EMemoryCardInsert);
       
   510         }
       
   511 
       
   512     // let view to respond user events again
       
   513     iWizardInitialization = EFalse;
       
   514 
       
   515     // must return EFalse because this is not called anymore
       
   516     return EFalse;
       
   517     }
       
   518 
       
   519 // --------------------------------------------------------------------------
       
   520 // CMSMainView::DoInitializeMemoryCardL
       
   521 // Do Starts the new memroy card when new memory card dialog inserted
       
   522 // --------------------------------------------------------------------------
       
   523 //
       
   524 void CMSMainView::DoInitializeMemoryCardL()
       
   525     {
       
   526     CheckMemoryCardL();
       
   527     }
       
   528 
       
   529 // End of File