homesync/contentmanager/mediaservant/src/msappui.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2007 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:  CMediaServantAppUi class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <StringLoader.h>
       
    20 #include <mediaservant.rsg>
       
    21 #include <f32file.h>
       
    22 #include <driveinfo.h>
       
    23 
       
    24 #include "cmsettingsfactory.h"
       
    25 #include "cmsettings.h"
       
    26 #include "cmdriveinfo.h"
       
    27 #include "msappui.h"
       
    28 #include "msstorelistcontroller.h"
       
    29 #include "msmainview.h"
       
    30 #include "msfillview.h"
       
    31 #include "msfillruleeditview.h"
       
    32 #include "msstorelistview.h"
       
    33 #include "msstoresettingsview.h"
       
    34 #include "msbrowseview.h"
       
    35 #include "msfillbrowseview.h"
       
    36 #include "msconstants.h"
       
    37 #include "msengine.h"
       
    38 #include "msparameteragent.h"
       
    39 #include "cmsappwizard.h"
       
    40 #include "msgsinterface.h"
       
    41 #include "msgspluginuids.h"
       
    42 
       
    43 #include "msdebug.h"
       
    44 
       
    45 // --------------------------------------------------------------------------
       
    46 // CMSAppUi::ConstructL()
       
    47 // --------------------------------------------------------------------------
       
    48 //
       
    49 void CMSAppUi::ConstructL()
       
    50     {
       
    51     LOG(_L("[MediaServant]\t CMSAppUi::ConstructL"));
       
    52 
       
    53 #ifndef __SERIES60_31__
       
    54     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
       
    55 #else
       
    56     BaseConstructL( EAknEnableSkin );
       
    57 #endif
       
    58     
       
    59     // Create engine
       
    60     iMSEngine = CMSEngine::NewL();
       
    61 
       
    62     // Create parameter agent for message passing between views
       
    63     iParameterAgent = new ( ELeave ) CMSParameterAgent();
       
    64 
       
    65     // Create fill list controller
       
    66     iFillRuleController = CMSFillRuleController::NewL( *iMSEngine );
       
    67 
       
    68     // Create store list controller
       
    69     iStoreListController = CMSStoreListController::NewL( *iMSEngine );
       
    70 
       
    71     LoadSettingsPluginL(); // loads gs plugin
       
    72 
       
    73     // main view is created
       
    74     CMSMainView* mainView = new ( ELeave )CMSMainView( *this );
       
    75     CleanupStack::PushL( mainView );
       
    76     mainView->ConstructL();
       
    77     AddViewL( mainView );           // transfer ownership to CAknViewAppUi
       
    78     CleanupStack::Pop( mainView);
       
    79 
       
    80     CMSFillView* fillView = new ( ELeave ) CMSFillView( *this );
       
    81     CleanupStack::PushL( fillView );
       
    82     fillView->ConstructL();
       
    83     AddViewL( fillView );           // transfer ownership to CAknViewAppUi
       
    84     CleanupStack::Pop( fillView );
       
    85 
       
    86     CMSFillRuleEditView* ruleEditView = new ( ELeave )
       
    87                                             CMSFillRuleEditView( *this );
       
    88     CleanupStack::PushL( ruleEditView );
       
    89     ruleEditView->ConstructL();
       
    90     AddViewL( ruleEditView );       // transfer ownership to CAknViewAppUi
       
    91     CleanupStack::Pop( ruleEditView );
       
    92 
       
    93     CMSStoreListView* storelistView = new ( ELeave )
       
    94                                 CMSStoreListView( *this );
       
    95     CleanupStack::PushL( storelistView );
       
    96     storelistView->ConstructL();
       
    97     AddViewL( storelistView );      // transfer ownership to CAknViewAppUi
       
    98     CleanupStack::Pop( storelistView);
       
    99 
       
   100     CMSStoreSettingsView* storesettingView = new ( ELeave )
       
   101                                 CMSStoreSettingsView( *this );
       
   102     CleanupStack::PushL( storesettingView );
       
   103     storesettingView->ConstructL();
       
   104     AddViewL( storesettingView );   // transfer ownership to CAknViewAppUi
       
   105     CleanupStack::Pop( storesettingView );
       
   106 
       
   107     CMSBrowseView* browseView = new ( ELeave )
       
   108                                 CMSBrowseView( *this );
       
   109     CleanupStack::PushL( browseView );
       
   110     browseView->ConstructL();
       
   111     AddViewL( browseView );   // transfer ownership to CAknViewAppUi
       
   112     CleanupStack::Pop( browseView );
       
   113 
       
   114     CMSFillBrowseView* fillBrowseView =
       
   115                     new ( ELeave ) CMSFillBrowseView( *this );
       
   116     CleanupStack::PushL( fillBrowseView );
       
   117     fillBrowseView->ConstructL();
       
   118     AddViewL( fillBrowseView );   // transfer ownership to CAknViewAppUi
       
   119     CleanupStack::Pop( fillBrowseView );
       
   120 
       
   121 
       
   122     // default view is now main view
       
   123     SetDefaultViewL( *mainView );
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // CMSAppUi::~CMSAppUi()
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 CMSAppUi::~CMSAppUi()
       
   131     {
       
   132     LOG(_L("[MediaServant]\t CMSAppUi::~CMSAppUi"));
       
   133     
       
   134     if( iPlugin )
       
   135         {
       
   136         // Destroy Ecom plugin
       
   137         iPlugin->DestroyPlugin();
       
   138         }
       
   139 
       
   140     delete iMSEngine;
       
   141     delete iParameterAgent;
       
   142     delete iFillRuleController;
       
   143     delete iStoreListController;
       
   144     }
       
   145 
       
   146 // --------------------------------------------------------------------------
       
   147 // CMSAppUi::HandleCommandL(TInt aCommand)
       
   148 // --------------------------------------------------------------------------
       
   149 //
       
   150 void CMSAppUi::HandleCommandL(TInt aCommand)
       
   151     {
       
   152     LOG(_L("[MediaServant]\t CMSAppUi::HandleCommandL"));
       
   153 
       
   154     switch ( aCommand )
       
   155         {
       
   156         case EAknSoftkeyBack:
       
   157         // fall trough
       
   158         case EEikCmdExit:
       
   159             {
       
   160             // program is exited
       
   161             Exit();
       
   162             break;
       
   163             }
       
   164         default:
       
   165             {
       
   166             LOG(_L("[MediaServant]\t CMSAppUi::HandleCommandL \
       
   167             invalid command"));
       
   168             break;
       
   169             }
       
   170         }
       
   171     }
       
   172 
       
   173 // --------------------------------------------------------------------------
       
   174 // CMSAppUi::ChangeViewL()
       
   175 //
       
   176 // Changes active view according to input parameter.
       
   177 // --------------------------------------------------------------------------
       
   178 //
       
   179 void CMSAppUi::ChangeViewL(const TUid& aOldView, const TUid& aNewView)
       
   180     {
       
   181     LOG(_L("[MediaServant]\t CMSAppUi::ChangeViewL"));
       
   182 
       
   183     iParameterAgent->SetPreviousViewId( aOldView );
       
   184 
       
   185     if ( aOldView.iUid == KMSMainViewId.iUid )
       
   186         {
       
   187         // store focus index of main view
       
   188         iParameterAgent->SetMainViewFocusIndex(
       
   189                     static_cast<CMSMainView*> (iView)->FocusIndex());
       
   190         
       
   191         }
       
   192     else if ( aOldView.iUid == KMSFillViewId.iUid )
       
   193         {
       
   194         // store focus index of main view
       
   195         iParameterAgent->SetFillViewFocusIndex(
       
   196                     static_cast<CMSFillView*> (iView)->FocusIndex());
       
   197         
       
   198         }
       
   199     else if ( aOldView.iUid == KMSStoreListViewId.iUid )
       
   200         {
       
   201         // store focus index of fill view
       
   202         iParameterAgent->SetStoreViewFocusIndex(
       
   203                     static_cast<CMSStoreListView*> (iView)->FocusIndex());
       
   204         }        
       
   205     else
       
   206         {
       
   207         // no need to change view
       
   208         }
       
   209 
       
   210     // new view is activated
       
   211     ActivateViewL(TVwsViewId(KUidMediaServant, aNewView));
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CMSAppUi::StoreListController()
       
   216 // Returns fill rule container
       
   217 // --------------------------------------------------------------------------
       
   218 //
       
   219 CMSStoreListController* CMSAppUi::StoreListController()
       
   220     {
       
   221     LOG(_L("[MediaServant]\t CMSAppUi::StoreListController"));
       
   222 
       
   223     return iStoreListController;
       
   224     }
       
   225 
       
   226 // --------------------------------------------------------------------------
       
   227 // CMSAppUi::MSEngine()
       
   228 // Returns msengine pointer
       
   229 // --------------------------------------------------------------------------
       
   230 //
       
   231 CMSEngine* CMSAppUi::MSEngine()
       
   232     {
       
   233     return iMSEngine;
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CMSAppUi::RefreshListsL()
       
   238 // Refresh store and fill lists
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CMSAppUi::RefreshListsL()    
       
   242     {
       
   243     LOG(_L("[MediaServant]\t CMSAppUi::RefreshListsL"));
       
   244     
       
   245     iStoreListController->UpdateListsL();
       
   246     iFillRuleController->UpdateArrayL();
       
   247     }
       
   248 
       
   249 // --------------------------------------------------------------------------
       
   250 // CMSFillView::ReadMMCInfoL
       
   251 // Reads mmc capasity
       
   252 // --------------------------------------------------------------------------
       
   253 //
       
   254 TInt CMSAppUi::ReadMMCInfoL( TInt64& aCapasity, TInt64& aFreeSpace )
       
   255     {
       
   256     LOG(_L("[MediaServant]\t CMSAppUi::ReadMMCInfoL"));
       
   257     RFs& sysFs = FsSession();
       
   258     RPointerArray<CCmDriveInfo> storedDrives;
       
   259     RPointerArray<CCmDriveInfo> driveArray;
       
   260     TInt error = KErrNone;
       
   261     aCapasity = 0;
       
   262     aFreeSpace = 0;
       
   263     MCmSettings* settings = CCmSettingsFactory::NewCmSettingsEngineLC();
       
   264 
       
   265     // read stored info of stored drives
       
   266     MSEngine()->GetDrivesL( storedDrives );
       
   267     // get system drive info
       
   268     settings->DriveListL( sysFs, driveArray );
       
   269 
       
   270     TInt count = storedDrives.Count();
       
   271 
       
   272     for ( TInt i = 0; i < count; i++ )
       
   273         {
       
   274         TIdentityRelation<CCmDriveInfo> relation( CMSAppUi::CompareIds );
       
   275         TInt index = driveArray.Find( storedDrives[i], relation );
       
   276         if ( index != KErrNotFound )
       
   277             {
       
   278             TVolumeInfo volInfo;
       
   279             error = sysFs.Volume( volInfo, storedDrives[i]->DriveNumber() );
       
   280             if ( error == KErrNone )
       
   281                 {
       
   282                 TRACE(Print(_L("[MediaServant]\t CMSAppUi::ReadMMCInfoL %ld\n"),
       
   283                             volInfo.iSize ));
       
   284                 aCapasity += volInfo.iSize;
       
   285                 aFreeSpace += volInfo.iFree;
       
   286                 }
       
   287             }
       
   288         }
       
   289 
       
   290     storedDrives.ResetAndDestroy();
       
   291     storedDrives.Close();
       
   292 
       
   293     driveArray.ResetAndDestroy();
       
   294     driveArray.Close();
       
   295 
       
   296 	settings->Close();
       
   297     CleanupStack::Pop(); // settings
       
   298     return error;
       
   299     }
       
   300 
       
   301 // --------------------------------------------------------------------------
       
   302 // CMSAppUi::GetFilledFilesSize
       
   303 // Get filled files size
       
   304 // --------------------------------------------------------------------------
       
   305 //
       
   306 void CMSAppUi::GetFilledFilesSize( TInt64& aSize, const TInt aID )
       
   307     {
       
   308     iMSEngine->GetFilledFilesSize( aSize, aID );
       
   309     }
       
   310 
       
   311 
       
   312 // CMSAppUi::ParameterAgent
       
   313 // returns pointer to parameter agent
       
   314 // --------------------------------------------------------------------------
       
   315 //
       
   316 CMSParameterAgent* CMSAppUi::ParameterAgent()
       
   317     {
       
   318     return iParameterAgent;
       
   319     }
       
   320 
       
   321 // --------------------------------------------------------------------------
       
   322 // CMSAppUi::FillRuleController
       
   323 // returns pointer to rule controller
       
   324 // --------------------------------------------------------------------------
       
   325 //
       
   326 CMSFillRuleController* CMSAppUi::FillRuleController()
       
   327     {
       
   328     return iFillRuleController;
       
   329     }
       
   330 
       
   331 // --------------------------------------------------------------------------
       
   332 // CMSAppUi::FsSession
       
   333 // returns file server session
       
   334 // --------------------------------------------------------------------------
       
   335 //
       
   336 RFs& CMSAppUi::FsSession()
       
   337     {
       
   338     return iEikonEnv->FsSession();
       
   339     }
       
   340 
       
   341 // --------------------------------------------------------------------------
       
   342 // CMSAppUi::DriveSelectedL
       
   343 // returns drive selection status
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 TBool CMSAppUi::DriveSelectedL()
       
   347     {
       
   348     TBool status( EFalse );
       
   349 
       
   350     if ( iMSEngine->DriveSelectionStatus() && MemoryAttachedL() )
       
   351         {
       
   352         status = ETrue;
       
   353         }
       
   354     return status;
       
   355     }
       
   356 
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CMSAppUi::MemoryAttachedL
       
   360 // Returns ETrue if selected memory is on the device
       
   361 // --------------------------------------------------------------------------
       
   362 //
       
   363 TBool CMSAppUi::MemoryAttachedL()
       
   364     {
       
   365     LOG(_L("[MediaServant]\t CMSAppUi::MemoryAttachedL"));
       
   366     
       
   367     TBool status( EFalse );
       
   368     RFs& fileServer = FsSession();
       
   369     RPointerArray<CCmDriveInfo> storedDrives;
       
   370     RPointerArray<CCmDriveInfo> driveArray;
       
   371     MCmSettings* settings = CCmSettingsFactory::NewCmSettingsEngineLC();
       
   372 
       
   373     // read stored info of stored drives
       
   374     MSEngine()->GetDrivesL( storedDrives );
       
   375     // get system drive info
       
   376     settings->DriveListL( fileServer, driveArray );
       
   377 
       
   378     TInt count = storedDrives.Count();
       
   379 
       
   380     for ( TInt i = 0; i < count; i++ )
       
   381         {
       
   382         TIdentityRelation<CCmDriveInfo> relation(CMSAppUi::CompareIds );
       
   383         TInt index = driveArray.Find( storedDrives[i], relation );
       
   384         if ( index != KErrNotFound )
       
   385             {
       
   386             status = ETrue;
       
   387             i = count; // break loop
       
   388             }
       
   389         }
       
   390 
       
   391     storedDrives.ResetAndDestroy();
       
   392     storedDrives.Close();
       
   393 
       
   394     driveArray.ResetAndDestroy();
       
   395     driveArray.Close();
       
   396 
       
   397 	settings->Close();
       
   398     CleanupStack::Pop(); // settings
       
   399 
       
   400     return status;
       
   401     }
       
   402 
       
   403 // --------------------------------------------------------------------------
       
   404 // CMSAppUi::CompareIds
       
   405 // Compares drive ids
       
   406 // --------------------------------------------------------------------------
       
   407 //
       
   408 TBool CMSAppUi::CompareIds( const CCmDriveInfo& aStoredDrive,
       
   409                             const CCmDriveInfo& aDrive )
       
   410     {
       
   411     TBool retval = EFalse;
       
   412     if ( aStoredDrive.DriveId() == aDrive.DriveId() )
       
   413         {
       
   414         retval = ETrue;
       
   415         }
       
   416 
       
   417     return retval;
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // CMSAppUi::LoadSettingsPluginL
       
   422 // ---------------------------------------------------------------------------
       
   423 //    
       
   424 void CMSAppUi::LoadSettingsPluginL()
       
   425     {
       
   426     LOG(_L("[MediaServant]\t CMSAppUi::LoadSettingsPluginL start"));
       
   427    
       
   428     TRAPD( error, iPlugin = CMSGSInterface::NewL( KMSGSImplementationUid ) );
       
   429     if ( !error )
       
   430         {
       
   431         AddViewL( iPlugin ); // transfer ownership to CAknViewAppUi    
       
   432         }    
       
   433     
       
   434     LOG(_L("[MediaServant]\t CMSAppUi::LoadSettingsPluginL end"));
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CMSAppUi::SettingsPlugin
       
   439 // ---------------------------------------------------------------------------
       
   440 // 
       
   441 CMSGSInterface* CMSAppUi::SettingsPlugin()
       
   442     {
       
   443     return iPlugin;
       
   444     }
       
   445     
       
   446 // ---------------------------------------------------------------------------
       
   447 // CMSAppUi::CheckDrivesSelectedL
       
   448 // ---------------------------------------------------------------------------
       
   449 // 
       
   450 void CMSAppUi::CheckDrivesSelectedL()
       
   451     {
       
   452     LOG(_L("[MediaServant]\t CMSAppUi::CheckDrivesSelectedL"));
       
   453     
       
   454     TBool status( EFalse );
       
   455     RFs& fileServer = FsSession();
       
   456     MCmSettings* settings = CCmSettingsFactory::NewCmSettingsEngineLC();
       
   457     RPointerArray<CCmDriveInfo> storedDrives;
       
   458     RPointerArray<CCmDriveInfo> driveArray;
       
   459     CleanupClosePushL( storedDrives );
       
   460     CleanupClosePushL( driveArray );
       
   461 
       
   462     // read stored info of stored drives
       
   463     MSEngine()->GetDrivesL( storedDrives );
       
   464     // get system drive info
       
   465     settings->DriveListL( fileServer, driveArray );
       
   466 
       
   467     TInt count = storedDrives.Count();
       
   468 
       
   469     for ( TInt i = 0; i < count; i++ )
       
   470         {
       
   471         TIdentityRelation<CCmDriveInfo> relation(CMSAppUi::CompareIds );
       
   472         TInt index = driveArray.Find( storedDrives[i], relation );
       
   473         if ( index != KErrNotFound )
       
   474             {
       
   475             status = ETrue;
       
   476             i = count; // break loop
       
   477             }
       
   478         }
       
   479     
       
   480     // none of drives have been selected
       
   481     if( !status )
       
   482         {
       
   483         for ( TInt j = 0; j < driveArray.Count(); j++ )
       
   484             {
       
   485             // mass memory
       
   486             if ( driveArray[j]->DriveType() != DriveInfo::EDriveRemovable )
       
   487                 {
       
   488                 RPointerArray<CCmDriveInfo> massDrives;
       
   489                 CleanupClosePushL( massDrives );
       
   490                 TInt64 quota =
       
   491                 ( driveArray[j]->DriveSize() * KHDDefaultQuota ) / 100;
       
   492                 driveArray[j]->SetDriveQuota( quota );
       
   493                 driveArray[j]->SetStatus( ETrue );
       
   494                 
       
   495                 massDrives.AppendL( driveArray[j] );
       
   496                 MSEngine()->SetDrivesL( massDrives );
       
   497                 CleanupStack::PopAndDestroy(  );// &massDrives
       
   498                 //break, for only one mass memory exist
       
   499                 j = driveArray.Count();
       
   500                 }
       
   501             }
       
   502         }
       
   503     storedDrives.ResetAndDestroy();
       
   504     driveArray.ResetAndDestroy();
       
   505     
       
   506     CleanupStack::PopAndDestroy( 2 ); // &storedDrives, &driveArray
       
   507 	settings->Close();
       
   508     CleanupStack::Pop(); // settings
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------------------------
       
   512 // CMSAppUi::RunWizard
       
   513 // ---------------------------------------------------------------------------
       
   514 // 
       
   515 TInt CMSAppUi::RunWizardL()
       
   516 	{
       
   517 	LOG(_L("[MediaServant]\t CMSAppUi::RunWizardL Launch Wizard"));
       
   518 	
       
   519 	TInt wizRetVal(KErrNone);
       
   520 
       
   521     // Check drives selection status
       
   522     CheckDrivesSelectedL();
       
   523         
       
   524     CMSAppWizard* appWizard = CMSAppWizard::NewL( *iMSEngine );
       
   525     CleanupStack::PushL( appWizard );
       
   526     wizRetVal = appWizard->StartL();
       
   527     CleanupStack::PopAndDestroy( appWizard );
       
   528 
       
   529     if( wizRetVal != KErrNone)
       
   530         {
       
   531         LOG(_L("[MediaServant]\t CMSAppUi::RunWizardL Wizard Run OK"));        
       
   532         }
       
   533     else
       
   534         {
       
   535         TRACE(Print(_L("[MediaServant]\t RunWizardL::\
       
   536         wizard return value: %d"), wizRetVal));
       
   537         RefreshListsL();
       
   538         }
       
   539     iMSEngine->SetAppWizardState();
       
   540 
       
   541     return wizRetVal;
       
   542 	}
       
   543 // End of File