filemanager/aiwprovider/src/filemanageraiwprovider.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38:491b3ed49290
     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:  This class offers AIW services
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <ecom/implementationproxy.h>
       
    21 #include <w32std.h>
       
    22 #include <apgtask.h>
       
    23 #include <apgcli.h>
       
    24 #include <apgwgnam.h>
       
    25 #include <apacmdln.h>
       
    26 #include <centralrepository.h>
       
    27 #include "FileManagerDebug.h"
       
    28 #include "FileManagerPrivateCRKeys.h"
       
    29 #include "filemanageraiwprovider.h"
       
    30 #include "FileManagerUID.h"
       
    31 
       
    32 const TImplementationProxy ImplementationTable[] =
       
    33     {
       
    34     IMPLEMENTATION_PROXY_ENTRY( 0x200110F9, CFileManagerAiwProvider::NewL )
       
    35     };
       
    36 const TUid KUidDefaultFileManager = { KFileManagerUID3 };
       
    37 const TInt KMaxSortMethodStr = 20;
       
    38 _LIT( KRootMatch, "?:\\" );
       
    39 
       
    40 
       
    41 // ======== LOCAL FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // FindStandaloneAppL
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 static TBool FindStandaloneAppL(
       
    48         RWsSession& aWs, const TUid& aUid, TInt& aWgId )
       
    49     {
       
    50     FUNC_LOG;
       
    51 
       
    52     aWgId = 0; // Used window group id is always greater than zero
       
    53     RArray< RWsSession::TWindowGroupChainInfo > windowChain;
       
    54     User::LeaveIfError( aWs.WindowGroupList( &windowChain ) );
       
    55     CleanupClosePushL( windowChain );
       
    56     TInt count( windowChain.Count() );
       
    57     for( TInt i( 0 ); i < count; ++i )
       
    58         {
       
    59         const RWsSession::TWindowGroupChainInfo& entry( windowChain[ i ] );
       
    60         CApaWindowGroupName* app = CApaWindowGroupName::NewLC(
       
    61             aWs, entry.iId );
       
    62         TUid appUid( app->AppUid() );
       
    63         CleanupStack::PopAndDestroy( app );
       
    64         // Match the app's UID and the embedded status.
       
    65         // The app is standalone when there is no parent window group.
       
    66         if ( appUid == aUid && entry.iParentId <= 0 )
       
    67             {
       
    68             // Standalone application found
       
    69             aWgId = entry.iId;
       
    70             break;
       
    71             }
       
    72         }
       
    73     CleanupStack::PopAndDestroy( &windowChain );
       
    74     return aWgId > 0;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // IsValidFolderToOpenPath
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 static TBool IsValidFolderToOpenPath( const TDesC& aFullPath )
       
    82     {
       
    83     FUNC_LOG;
       
    84 
       
    85     TInt len( aFullPath.Length() );
       
    86     if ( !len )
       
    87         {
       
    88         return ETrue; // Allow empty to open main view
       
    89         }
       
    90     // Check that at least root folder exists
       
    91     if ( aFullPath.Left( KRootMatch().Length() ).MatchF(
       
    92             KRootMatch ) == KErrNotFound )
       
    93         {
       
    94         return EFalse;
       
    95         }
       
    96     return ETrue;
       
    97     }
       
    98 
       
    99 // ======== MEMBER FUNCTIONS ========
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CFileManagerAiwProvider::CFileManagerAiwProvider
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CFileManagerAiwProvider::CFileManagerAiwProvider()
       
   106     {
       
   107     FUNC_LOG;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CFileManagerAiwProvider::NewL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 CFileManagerAiwProvider* CFileManagerAiwProvider::NewL()
       
   115     {
       
   116     FUNC_LOG;
       
   117 
       
   118     return new ( ELeave ) CFileManagerAiwProvider();
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CFileManagerAiwProvider::~CFileManagerAiwProvider
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CFileManagerAiwProvider::~CFileManagerAiwProvider()
       
   126     {
       
   127     FUNC_LOG;
       
   128 
       
   129     delete iService;
       
   130     delete iInParamList;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CFileManagerAiwProvider::InitialiseL
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CFileManagerAiwProvider::InitialiseL(
       
   138         MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   139         const RCriteriaArray& /*aInterest*/ )
       
   140     {
       
   141     FUNC_LOG;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CFileManagerAiwProvider::HandleServiceCmdL
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CFileManagerAiwProvider::HandleServiceCmdL(
       
   149         const TInt& aCmdId,
       
   150         const CAiwGenericParamList& aInParamList,
       
   151         CAiwGenericParamList& /*aOutParamList*/,
       
   152         TUint /*aCmdOptions*/,
       
   153         const MAiwNotifyCallback* aCallback )
       
   154     {
       
   155     FUNC_LOG;
       
   156 
       
   157     INFO_LOG2(
       
   158         "CFileManagerAiwProvider::HandleServiceCmdL-aCmdId=%d,aCallback=0x%x",
       
   159         aCmdId, aCallback );
       
   160 
       
   161     TInt err( KErrNone );
       
   162     switch ( aCmdId )
       
   163         {
       
   164         case KAiwCmdEdit:
       
   165             {
       
   166             TRAP( err, CmdEditL( aInParamList, aCallback ) );
       
   167             break;
       
   168             }
       
   169         default:
       
   170             {
       
   171             ERROR_LOG1(
       
   172                 "CFileManagerAiwProvider::HandleServiceCmdL-InvalidCmd=%d",
       
   173                 aCmdId );
       
   174             break;
       
   175             }
       
   176         }
       
   177     LOG_IF_ERROR2(
       
   178         err,
       
   179         "CFileManagerAiwProvider::HandleServiceCmdL-aCmdId=%d-err=%d",
       
   180         aCmdId, err );
       
   181     User::LeaveIfError( err );
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CFileManagerAiwProvider::HandleServerAppExit
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CFileManagerAiwProvider::HandleServerAppExit( TInt /*aReason*/ )
       
   189     {
       
   190     FUNC_LOG;
       
   191 
       
   192     TRAP_IGNORE( NotifyL( KAiwEventCompleted ) );
       
   193     iCallback = NULL; // No notifications are needed after app exit
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CFileManagerAiwProvider::CmdEditL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CFileManagerAiwProvider::CmdEditL(
       
   201         const CAiwGenericParamList& aInParamList,
       
   202         const MAiwNotifyCallback* aCallback )
       
   203     {
       
   204     FUNC_LOG;
       
   205 
       
   206     iCmd = KAiwCmdEdit;
       
   207     if ( IsFolderToOpenPathGiven( aInParamList ) )
       
   208         {
       
   209         if ( IsStandaloneLaunch( aInParamList ) )
       
   210             {
       
   211             LaunchStandaloneL( aInParamList );
       
   212             }
       
   213         else
       
   214             {
       
   215             LaunchEmbeddedL( aInParamList, aCallback );
       
   216             }
       
   217         }
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CFileManagerAiwProvider::NotifyL
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CFileManagerAiwProvider::NotifyL( TInt aEvent )
       
   225     {
       
   226     FUNC_LOG;
       
   227 
       
   228     if ( iCallback && iInParamList )
       
   229         {
       
   230         CAiwGenericParamList* eventParamList = CAiwGenericParamList::NewL();
       
   231         CleanupStack::PushL( eventParamList );
       
   232         // Must cast this because of AIW design error
       
   233         const_cast< MAiwNotifyCallback* >( iCallback )->HandleNotifyL(
       
   234     	    iCmd, aEvent, *eventParamList, *iInParamList );
       
   235         CleanupStack::PopAndDestroy( eventParamList );
       
   236         }
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CFileManagerAiwProvider::GetAppUidL
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 TUid CFileManagerAiwProvider::GetAppUidL()
       
   244     {
       
   245     FUNC_LOG;
       
   246 
       
   247     CRepository* cenRep = CRepository::NewLC( KCRUidFileManagerSettings );
       
   248     TInt uid( 0 );
       
   249     User::LeaveIfError( cenRep->Get( KFileManagerAppUidForAiwService, uid ) );
       
   250     CleanupStack::PopAndDestroy( cenRep );
       
   251     return TUid::Uid( uid );
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CFileManagerAiwProvider::GetAppUid
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 TUid CFileManagerAiwProvider::GetAppUid()
       
   259     {
       
   260     FUNC_LOG;
       
   261 
       
   262     if ( !iAppUid.iUid )
       
   263         {
       
   264         // Read the application to start from CenRep
       
   265         TRAPD( err, iAppUid = GetAppUidL() );
       
   266         if ( err != KErrNone || !iAppUid.iUid )
       
   267             {
       
   268             // Use the default application
       
   269             iAppUid = KUidDefaultFileManager;
       
   270             }
       
   271         ERROR_LOG1(
       
   272             "CFileManagerAiwProvider::GetAppUid-Uid=0x%x", iAppUid.iUid );
       
   273         }
       
   274     return iAppUid;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CFileManagerAiwProvider::LaunchEmbeddedL
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CFileManagerAiwProvider::LaunchEmbeddedL(
       
   282         const CAiwGenericParamList& aInParamList,
       
   283         const MAiwNotifyCallback* aCallback )
       
   284     {
       
   285     FUNC_LOG;
       
   286 
       
   287     delete iService;
       
   288     iService = NULL;
       
   289     delete iInParamList;
       
   290     iInParamList = NULL;
       
   291     iCallback = NULL;
       
   292 
       
   293     // Copy the input params for the launcher and then do the launch
       
   294     iInParamList = CAiwGenericParamList::NewL();
       
   295     TInt count( aInParamList.Count() );
       
   296     for( TInt i( 0 ); i < count; ++i )
       
   297         {
       
   298         iInParamList->AppendL( aInParamList[ i ] );
       
   299         }
       
   300     iService = CAknLaunchAppService::NewL( GetAppUid(), this, iInParamList );
       
   301     iCallback = aCallback;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CFileManagerAiwProvider::IsStandaloneLaunch
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TBool CFileManagerAiwProvider::IsStandaloneLaunch(
       
   309         const CAiwGenericParamList& aInParamList )
       
   310     {
       
   311     FUNC_LOG;
       
   312 
       
   313     TBool ret( EFalse );
       
   314     TInt i( 0 );
       
   315     // Get sort method first
       
   316     const TAiwGenericParam* param = aInParamList.FindFirst(
       
   317         i, EGenericParamDir, EVariantTypeTInt32 );
       
   318     if ( i != KErrNotFound && param )
       
   319         {
       
   320         // Then, check if standalone is requested
       
   321         param = aInParamList.FindNext( i, EGenericParamDir, EVariantTypeTInt32 );
       
   322         if ( i != KErrNotFound && param )
       
   323             {
       
   324             ret = param->Value().AsTInt32();
       
   325             }
       
   326         }
       
   327     return ret;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CFileManagerAiwProvider::LaunchStandaloneL
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CFileManagerAiwProvider::LaunchStandaloneL(
       
   335         const CAiwGenericParamList& aInParamList )
       
   336     {
       
   337     FUNC_LOG;
       
   338 
       
   339     TPtrC folderToOpen( KNullDesC );
       
   340     TInt sortMethod( KErrNotFound );
       
   341     TInt i( 0 );
       
   342     // Get folder path
       
   343     const TAiwGenericParam* param = aInParamList.FindFirst(
       
   344         i, EGenericParamDir, EVariantTypeDesC );
       
   345     if ( i != KErrNotFound && param )
       
   346         {
       
   347         folderToOpen.Set( param->Value().AsDes() );
       
   348         }
       
   349     // Get sort method
       
   350     param = aInParamList.FindFirst( i, EGenericParamDir, EVariantTypeTInt32 );
       
   351     if ( i != KErrNotFound && param )
       
   352         {
       
   353         sortMethod = param->Value().AsTInt32();
       
   354         }
       
   355 
       
   356     RWsSession wsSession;
       
   357     User::LeaveIfError( wsSession.Connect() );
       
   358     CleanupClosePushL( wsSession );
       
   359     TInt wgId( 0 );
       
   360     TUid appUid( GetAppUid() );
       
   361     if ( FindStandaloneAppL( wsSession, appUid, wgId ) )
       
   362         {
       
   363         // Bring the existing standalone app to foreground
       
   364         TApaTask apaTask( wsSession );
       
   365         apaTask.SetWgId( wgId );
       
   366         apaTask.BringToForeground();
       
   367         }
       
   368     else
       
   369         {
       
   370         // Start new standalone app
       
   371         TApaAppInfo appInfo;
       
   372         RApaLsSession apaLsSession;
       
   373         User::LeaveIfError( apaLsSession.Connect() );
       
   374         CleanupClosePushL( apaLsSession );
       
   375         User::LeaveIfError( apaLsSession.GetAppInfo( appInfo, appUid ) );
       
   376         CApaCommandLine* apaCmdLine = CApaCommandLine::NewLC();
       
   377         apaCmdLine->SetExecutableNameL( appInfo.iFullName );
       
   378         apaCmdLine->SetCommandL( EApaCommandOpen );
       
   379         apaCmdLine->SetDocumentNameL( folderToOpen );
       
   380         if ( sortMethod != KErrNotFound )
       
   381             {
       
   382             TBuf8< KMaxSortMethodStr > sortMethodStr;
       
   383             sortMethodStr.AppendNum( sortMethod );
       
   384             apaCmdLine->SetTailEndL( sortMethodStr );
       
   385             }
       
   386         TThreadId dummy;
       
   387         User::LeaveIfError( apaLsSession.StartApp( *apaCmdLine, dummy ) );
       
   388         CleanupStack::PopAndDestroy( apaCmdLine );
       
   389         CleanupStack::PopAndDestroy( &apaLsSession );
       
   390         }
       
   391     CleanupStack::PopAndDestroy( &wsSession );
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CFileManagerAiwProvider::IsFolderToOpenPathGiven
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 TBool CFileManagerAiwProvider::IsFolderToOpenPathGiven(
       
   399         const CAiwGenericParamList& aInParamList )
       
   400     {
       
   401     FUNC_LOG;
       
   402 
       
   403     TBool ret( EFalse );
       
   404     TPtrC folderToOpen( KNullDesC );
       
   405     TInt i( 0 );
       
   406     // Ensure first that no files are defined, because only folder service
       
   407     // is offered by this provider
       
   408     const TAiwGenericParam* param = aInParamList.FindFirst(
       
   409         i, EGenericParamFile, EVariantTypeAny );
       
   410     if ( i == KErrNotFound )
       
   411         {
       
   412         // Get folder path and check it
       
   413         i = 0;
       
   414         param = aInParamList.FindFirst(
       
   415             i, EGenericParamDir, EVariantTypeDesC );
       
   416         if ( i != KErrNotFound && param )
       
   417             {
       
   418             folderToOpen.Set( param->Value().AsDes() );
       
   419             ret = IsValidFolderToOpenPath( folderToOpen );
       
   420             }
       
   421         }
       
   422     if ( !ret )
       
   423         {
       
   424         ERROR_LOG2(
       
   425             "CFileManagerAiwProvider::IsFolderToOpenPathGiven-ret=%d,given=%S",
       
   426             ret, &folderToOpen );
       
   427         }
       
   428     return ret;
       
   429     }
       
   430 
       
   431 // ======== GLOBAL FUNCTIONS ========
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // ImplementationGroupProxy.
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   438     {
       
   439     FUNC_LOG;
       
   440 
       
   441     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   442     return ImplementationTable;
       
   443     }