webengine/widgetinstaller/Src/WidgetRegistrationManager.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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 is defines CWidgetRegistrationManager which handles
       
    15 *                registration of widgets
       
    16 *
       
    17 */
       
    18 
       
    19 #include "WidgetRegistrationManager.h"
       
    20 #include "WidgetInstaller.h"
       
    21 #include <apgcli.h>
       
    22 #include <APGICNFL.h>
       
    23 #include <S32MEM.H>
       
    24 #include <WidgetRegistryData.h>
       
    25 
       
    26 // CONSTANTS
       
    27 _LIT(KMBMExt, ".mbm");
       
    28 
       
    29 
       
    30 // MEMBER FUNCTION DECLARATIONS
       
    31 
       
    32 // ============================================================================
       
    33 // CWidgetRegistrationManager::NewL()
       
    34 // two-phase constructor
       
    35 //
       
    36 // @since 3.1
       
    37 // ============================================================================
       
    38 //
       
    39 CWidgetRegistrationManager* CWidgetRegistrationManager::NewL( RFs& aFs )
       
    40     {
       
    41     CWidgetRegistrationManager *self =
       
    42         new ( ELeave ) CWidgetRegistrationManager( aFs );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ============================================================================
       
    50 // CWidgetRegistrationManager::CWidgetRegistrationManager()
       
    51 // C++ constructor
       
    52 //
       
    53 // @since 3.1
       
    54 // ============================================================================
       
    55 //
       
    56 CWidgetRegistrationManager::CWidgetRegistrationManager(
       
    57     RFs& aFs )
       
    58     : iFs( aFs )
       
    59     {
       
    60     }
       
    61 
       
    62 // ============================================================================
       
    63 // CWidgetRegistrationManager::~CWidgetRegistrationManager()
       
    64 // destructor
       
    65 //
       
    66 // @since 3.1
       
    67 // ============================================================================
       
    68 //
       
    69 CWidgetRegistrationManager::~CWidgetRegistrationManager()
       
    70     {
       
    71     }
       
    72 
       
    73 // ============================================================================
       
    74 // CWidgetRegistrationManager::CWidgetRegistrationManager()
       
    75 // Symbian second phase constructor
       
    76 //
       
    77 // @since 3.1
       
    78 // ============================================================================
       
    79 //
       
    80 void CWidgetRegistrationManager::ConstructL()
       
    81     {
       
    82     }
       
    83 
       
    84 // ============================================================================
       
    85 // CWidgetRegistrationManager::DeregisterWidgetL()
       
    86 // Deregister installed widget as non native app
       
    87 //
       
    88 // @since 3.1
       
    89 // ============================================================================
       
    90 //
       
    91 void CWidgetRegistrationManager::DeregisterWidgetL( const TUid& aUid )
       
    92     {
       
    93     RApaLsSession apparcSession;
       
    94     User::LeaveIfError( apparcSession.Connect() );
       
    95 
       
    96     apparcSession.PrepareNonNativeApplicationsUpdatesL();
       
    97     apparcSession.DeregisterNonNativeApplicationL( aUid );
       
    98     apparcSession.DeregisterNonNativeApplicationTypeL( aUid );
       
    99     apparcSession.CommitNonNativeApplicationsUpdatesL();
       
   100     apparcSession.Close();
       
   101     }
       
   102 
       
   103 // ============================================================================
       
   104 // CWidgetRegistrationManager::RegisterWidgetL()
       
   105 // Register installed widget as non native app
       
   106 //
       
   107 // It will leave if registration is impossible or fails.  It will not
       
   108 // leave if icon path is KNullDesC or unusable since a default icon
       
   109 // will be used.
       
   110 //
       
   111 // @since 3.1
       
   112 // ============================================================================
       
   113 //
       
   114 void CWidgetRegistrationManager::RegisterWidgetL(
       
   115     const TDesC& aMainHTML,
       
   116     const TDesC& aBundleDisplayName,
       
   117     const TDesC& aIconPath,
       
   118     const TDesC& aDriveName,
       
   119     const TUid& aUid )
       
   120     {
       
   121     RApaLsSession apparcSession;
       
   122     CleanupClosePushL( apparcSession );
       
   123     User::LeaveIfError( apparcSession.Connect() );
       
   124     // TODO move this where it is only done once
       
   125     apparcSession.PrepareNonNativeApplicationsUpdatesL();
       
   126     apparcSession.DeregisterNonNativeApplicationL( KUidWidgetLauncher );
       
   127     apparcSession.DeregisterNonNativeApplicationTypeL( KUidWidgetLauncher );
       
   128     apparcSession.CommitNonNativeApplicationsUpdatesL();
       
   129     // TODO end
       
   130 
       
   131     // reasonably like an acceptable file name
       
   132     TBuf<KWidgetRegistryVal> appName;
       
   133     appName.Append( aMainHTML );
       
   134 
       
   135     CApaRegistrationResourceFileWriter* writer =
       
   136         CApaRegistrationResourceFileWriter::NewL(
       
   137             aUid,
       
   138             appName,
       
   139             TApaAppCapability::ENonNative );
       
   140     CleanupStack::PushL( writer );
       
   141 
       
   142     TBuf8<KWidgetRegistryVal> opaqueData;
       
   143     RDesWriteStream writeStream( opaqueData );
       
   144 
       
   145     // le data opaque
       
   146     writeStream.WriteUint32L( aUid.iUid );
       
   147     writeStream.WriteUint32L( aMainHTML.Length() );
       
   148     writeStream.WriteL( aMainHTML );
       
   149 
       
   150     writeStream.CommitL();
       
   151     writer->SetOpaqueDataL( opaqueData );
       
   152 
       
   153     // avec nom de plume
       
   154     CApaLocalisableResourceFileWriter* lWriter =
       
   155         CApaLocalisableResourceFileWriter::NewL(
       
   156             KNullDesC,
       
   157             aBundleDisplayName,
       
   158             1 ,
       
   159             KNullDesC );
       
   160     CleanupStack::PushL( lWriter );
       
   161 
       
   162     // This call deletes any pending registrations which are not commited
       
   163     // in previous installations (ex: power off case).
       
   164     // This must be the first call after session connect,
       
   165     // and before Prepare... call.
       
   166     // This function returns with no effect, if no pending registrations in
       
   167     // previous install.
       
   168     apparcSession.RollbackNonNativeApplicationsUpdates();
       
   169 
       
   170     // Prepare for Registration & Deregistration.
       
   171     // Actual Registration & Deregistration will be done at Commit call
       
   172     // CommitNonNativeApplicationsUpdatesL.
       
   173     apparcSession.PrepareNonNativeApplicationsUpdatesL();
       
   174 
       
   175     RFile appArcIconFile;
       
   176     CleanupClosePushL( appArcIconFile );
       
   177     RFile* toIconFile = NULL;
       
   178 
       
   179     // la petit image (ou non)
       
   180     if ( aIconPath.Length() )
       
   181         {
       
   182         TFileName mbmIcon;
       
   183         mbmIcon.Append( aIconPath );
       
   184         mbmIcon.Append( aUid.Name() );
       
   185         mbmIcon.Append( KMBMExt() );
       
   186         TInt error =
       
   187             appArcIconFile.Open(
       
   188                 iFs, mbmIcon,
       
   189                 EFileShareReadersOrWriters|EFileWrite );
       
   190         if ( KErrNone == error )
       
   191             {
       
   192             toIconFile = &appArcIconFile;
       
   193             }
       
   194         }
       
   195 
       
   196     apparcSession.RegisterNonNativeApplicationL(
       
   197         KUidWidgetLauncher,
       
   198         aDriveName,
       
   199         *writer,
       
   200         lWriter,
       
   201         toIconFile );
       
   202 
       
   203     // TODO move this where it is only done once
       
   204     TRAP_IGNORE( apparcSession.RegisterNonNativeApplicationTypeL(
       
   205                      KUidWidgetLauncher,
       
   206                      KLauncherApp() ) );
       
   207     // TODO end
       
   208 
       
   209     apparcSession.CommitNonNativeApplicationsUpdatesL();
       
   210 
       
   211     // appArcIconFile, writer, lWriter, apparcSession
       
   212     CleanupStack::PopAndDestroy( 4 );
       
   213     }
       
   214 
       
   215 //  End of File