idlehomescreen/widgetmanager/src/wminstaller.cpp
changeset 5 c743ef5928ba
child 15 ff572dfe6d86
equal deleted inserted replaced
4:4d54b72983ae 5:c743ef5928ba
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 * widget manager plugin implementation
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "wminstaller.h"
       
    22 #include "wmwidgetdata.h"
       
    23 
       
    24 
       
    25 // CONSTANTS
       
    26 _LIT8( KWrtMime, "application/x-nokia-widget");
       
    27 
       
    28 // ---------------------------------------------------------
       
    29 // CWmInstaller::NewL
       
    30 // ---------------------------------------------------------
       
    31 //
       
    32 CWmInstaller* CWmInstaller::NewL()
       
    33     {
       
    34     CWmInstaller* self = CWmInstaller::NewLC();
       
    35     CleanupStack::Pop(); // self;
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CWmInstaller::NewLC
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CWmInstaller* CWmInstaller::NewLC()
       
    44     {
       
    45     CWmInstaller* self = new ( ELeave ) CWmInstaller();
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CWmInstaller::CWmInstaller
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CWmInstaller::CWmInstaller() : CActive( EPriorityStandard )
       
    56     {
       
    57     iUid = KNullUid;
       
    58     iIdle = NULL;
       
    59     CActiveScheduler::Add( this );
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CWmInstaller::ConstructL
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 void CWmInstaller::ConstructL()
       
    67     {
       
    68     iIdle = CIdle::NewL( CActive::EPriorityStandard );
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CWmInstaller::~CWmInstaller
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 CWmInstaller::~CWmInstaller()
       
    76     {
       
    77     Cancel();
       
    78 
       
    79     if ( iIdle && iIdle->IsActive() )
       
    80         {
       
    81         iIdle->Cancel();
       
    82         }
       
    83     delete iIdle;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CWmInstaller::DoCancel
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 void CWmInstaller::DoCancel()
       
    91     {
       
    92     if ( IsActive() )
       
    93         {
       
    94         iInstaller.CancelAsyncRequest( 
       
    95                 SwiUI::ERequestSilentUninstall );
       
    96 
       
    97         // close session
       
    98         iInstaller.Close();
       
    99         }
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // CWmInstaller::RunL
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 void CWmInstaller::RunL()
       
   107     {
       
   108     // close SWI session
       
   109     if ( iIdle && iIdle->IsActive() )
       
   110         {
       
   111         iIdle->Cancel();
       
   112         }
       
   113     iIdle->Start( TCallBack( CloseSwiSession, this ) );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CWmInstaller::CloseSwiSession
       
   118 // ---------------------------------------------------------
       
   119 //
       
   120 TInt CWmInstaller::CloseSwiSession( TAny* aPtr )
       
   121     {
       
   122     CWmInstaller* self = static_cast< CWmInstaller* >( aPtr );
       
   123     if ( self->iIdle->IsActive() )
       
   124       {
       
   125       self->iIdle->Cancel(); 
       
   126       }
       
   127     
       
   128     self->iUid = KNullUid;
       
   129     
       
   130     self->iInstaller.Close();
       
   131     return KErrNone;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CWmInstaller::RunError
       
   136 // ---------------------------------------------------------
       
   137 //
       
   138 TInt CWmInstaller::RunError(TInt /*aError*/)
       
   139     {   
       
   140     // close SWI session
       
   141     if ( iIdle && iIdle->IsActive() )
       
   142         {
       
   143         iIdle->Cancel();
       
   144         }
       
   145     iIdle->Start( TCallBack( CloseSwiSession, this ) );
       
   146 
       
   147     return KErrNone;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // CWmInstaller::UninstallL
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 void CWmInstaller::UninstallL( CWmWidgetData* aData )
       
   155     {
       
   156     if ( IsActive() )
       
   157         {
       
   158         User::Leave( KErrInUse );
       
   159         }
       
   160     else
       
   161         {
       
   162         User::LeaveIfError( iInstaller.Connect() );
       
   163         iUid = aData->PublisherUid();
       
   164         SwiUI::TUninstallOptions optionsUninstall;
       
   165         optionsUninstall.iBreakDependency = SwiUI::EPolicyAllowed;
       
   166         optionsUninstall.iKillApp = SwiUI::EPolicyAllowed;
       
   167         SwiUI::TUninstallOptionsPckg uninstallOptionsPkg( optionsUninstall );
       
   168         iInstaller.SilentUninstall( iStatus, iUid, 
       
   169                                 uninstallOptionsPkg, KWrtMime );
       
   170         
       
   171         aData->VisualizeUninstallL();
       
   172         SetActive();
       
   173         }
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CWmInstaller::Uid
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 TUid CWmInstaller::UninstallUid()
       
   181     {
       
   182     if ( IsActive() )
       
   183         {
       
   184         return iUid;
       
   185         }
       
   186     else
       
   187         {
       
   188         return KNullUid;
       
   189         }
       
   190     }