localisation/apparchitecture/apfile/apuninstallmonitor.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "apuninstallmonitor.h"
       
    17 
       
    18 // This active object has lower priority than CApaAppListServer but higher than file scanning periodic timer.
       
    19 const TInt KAppUninstallPriority=CActive::EPriorityStandard-10; 
       
    20 
       
    21 //
       
    22 // CApaAppUnInstallMonitor class
       
    23 //
       
    24 EXPORT_C CApaAppUnInstallMonitor* CApaAppUnInstallMonitor::NewL(CApaAppListServer* aApaServer)
       
    25 	{
       
    26 	CApaAppUnInstallMonitor* self = new(ELeave) CApaAppUnInstallMonitor(aApaServer);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CApaAppUnInstallMonitor::CApaAppUnInstallMonitor(CApaAppListServer* aApaServer) :
       
    34 		CActive(KAppUninstallPriority),
       
    35 		iApaServer(aApaServer),
       
    36 		iWaitingForStartUninstall(ETrue)
       
    37 	{
       
    38 	CActiveScheduler::Add(this);
       
    39 	}
       
    40 
       
    41 void CApaAppUnInstallMonitor::ConstructL()
       
    42 	{
       
    43 	User::LeaveIfError(iSwisProperty.Attach(KUidSystemCategory, Swi::KUidSoftwareInstallKey));
       
    44 	}
       
    45 
       
    46 EXPORT_C CApaAppUnInstallMonitor::~CApaAppUnInstallMonitor()
       
    47 	{
       
    48 	Cancel();
       
    49 	iSwisProperty.Close();
       
    50 	}
       
    51 
       
    52 EXPORT_C void CApaAppUnInstallMonitor::Start()
       
    53 	{
       
    54 	DoStart();
       
    55 	}
       
    56 
       
    57 TBool CApaAppUnInstallMonitor::UnInstallInProgress() const
       
    58 	{
       
    59 	return ((iSwisState & Swi::KSwisOperationMask) & Swi::ESwisUninstall)
       
    60 			&& ((iSwisState & Swi::KSwisOperationStatusMask) == Swi::ESwisStatusNone);
       
    61 	}
       
    62 
       
    63 void CApaAppUnInstallMonitor::RunL()
       
    64 	{
       
    65 	if(iStatus.Int() == KErrNone)
       
    66 		{
       
    67 		DoStart();
       
    68 		
       
    69 		if (iWaitingForStartUninstall)
       
    70 			{
       
    71 			if (UnInstallInProgress())
       
    72 				{
       
    73 				iWaitingForStartUninstall = EFalse;
       
    74 				iApaServer->HandleStartUninstallEvent();
       
    75 				}
       
    76 			}
       
    77 		else
       
    78 			{ // waiting for end uninstall
       
    79 			if (!UnInstallInProgress())
       
    80 				{
       
    81 				iWaitingForStartUninstall = ETrue;
       
    82 				TRAP_IGNORE(iApaServer->HandleEndUninstallEventL()); // let user try again if OOM
       
    83 				}
       
    84 			
       
    85 			}
       
    86 		}
       
    87 	}
       
    88 	
       
    89 void CApaAppUnInstallMonitor::DoStart()
       
    90 	{
       
    91 	iSwisProperty.Subscribe(iStatus);
       
    92 	TInt err = iSwisProperty.Get(KUidSystemCategory, Swi::KUidSoftwareInstallKey, iSwisState);
       
    93 	if(err == KErrNone)
       
    94 		{
       
    95 		SetActive();
       
    96 		}
       
    97 	else
       
    98 		{
       
    99 		iSwisProperty.Cancel();
       
   100 		}
       
   101 	}
       
   102 
       
   103 void CApaAppUnInstallMonitor::DoCancel()
       
   104 	{
       
   105 	iSwisProperty.Cancel();
       
   106 	}
       
   107 	
       
   108 
       
   109 // End of file