appinstaller/AppinstUi/Daemon/Src/dialogwatcher.cpp
changeset 0 ba25891c3a9e
child 37 6e7b00453237
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "dialogwatcher.h"
       
    20 #include "DialogWrapper.h"
       
    21 #include "SWInstDebug.h"
       
    22 
       
    23 using namespace Swi;
       
    24 
       
    25 CDialogWatcher* CDialogWatcher::NewL( CDialogWrapper* aDialog )
       
    26     {
       
    27     CDialogWatcher* self = CDialogWatcher::NewLC( aDialog );
       
    28     CleanupStack::Pop( self );
       
    29     return self;
       
    30     }
       
    31 
       
    32 CDialogWatcher* CDialogWatcher::NewLC( CDialogWrapper* aDialog )
       
    33     {
       
    34     CDialogWatcher* self = new(ELeave) CDialogWatcher();
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL( aDialog );
       
    37     return self;    
       
    38     }
       
    39 
       
    40 void CDialogWatcher::ConstructL( CDialogWrapper* aDialog )
       
    41     {
       
    42     iDialogWrapper = aDialog;
       
    43     iNoteActive = EFalse;
       
    44     iRequestToDisplayNote = EFalse;
       
    45     
       
    46     FLOG( _L("[CDialogWatcher] ConstructL: iProperty.Attach") );     
       
    47     User::LeaveIfError( iProperty.Attach(            
       
    48         KPSUidSWInstallerUiNotification, 
       
    49         KSWInstallerDisableDaemonNotes ) );
       
    50     
       
    51     FLOG( _L("[CDialogWatcher] ConstructL: CActiveScheduler::Add") );  
       
    52     CActiveScheduler::Add( this );
       
    53     }
       
    54 
       
    55 CDialogWatcher::~CDialogWatcher()
       
    56     {
       
    57     FLOG( _L("[CDialogWatcher] ~CDialogWatcher") ); 
       
    58     FLOG( _L("[CDialogWatcher] ~CDialogWatcher: Cancel subscribe") ); 
       
    59     iProperty.Cancel();
       
    60     FLOG( _L("[CDialogWatcher] ~CDialogWatcher: Close property") ); 
       
    61     iProperty.Close();
       
    62 
       
    63     if( IsAdded() ) 
       
    64          { 
       
    65          FLOG( _L("[CDialogWatcher] ~CDialogWatcher: CActive Deque()") ); 
       
    66          // Cancel outstanding request and remove from active scheduler.
       
    67          Deque();         
       
    68          }                            
       
    69     }
       
    70  
       
    71 CDialogWatcher::CDialogWatcher() : CActive( CActive::EPriorityStandard )   
       
    72     {
       
    73     }
       
    74 
       
    75 void CDialogWatcher::CancelNoteRequest()
       
    76     {
       
    77     FLOG( _L("[CDialogWatcher] CancelNoteRequest") ); 
       
    78     iRequestToDisplayNote = EFalse;
       
    79     }
       
    80  
       
    81 void CDialogWatcher::RequestToDisplayNote()
       
    82     {
       
    83     FLOG( _L("[CDialogWatcher] RequestToDisplayNote") ); 
       
    84     iRequestToDisplayNote = ETrue;
       
    85     }
       
    86 
       
    87 void CDialogWatcher::StartWatcher()
       
    88     {
       
    89     FLOG( _L("[CDialogWatcher] StartWatcher") );  
       
    90     if( !IsActive() )
       
    91         {         
       
    92         FLOG( _L("[CDialogWatcher] StartWatcher: Start subscribe") );
       
    93         // Request PS key change event.
       
    94         iProperty.Subscribe( iStatus );
       
    95         FLOG( _L("[CDialogWatcher] StartWatcher: SetActive") );
       
    96         SetActive();        
       
    97         }
       
    98     }
       
    99 
       
   100 void CDialogWatcher::StopWatcher()
       
   101     {
       
   102     FLOG( _L("[CDialogWatcher] StopWatcher: Cancel subscribe ") );  
       
   103     iProperty.Cancel();      
       
   104     Cancel();
       
   105     iRequestToDisplayNote = EFalse;  
       
   106     }
       
   107 
       
   108 TInt CDialogWatcher::GetPSKeyForUI( TInt& aPSKeyValue )
       
   109     {   
       
   110     FLOG( _L("[CDialogWatcher] GetPSKeyForUI") ); 
       
   111     TInt err = RProperty::Get( 
       
   112         KPSUidSWInstallerUiNotification, 
       
   113         KSWInstallerDisableDaemonNotes,
       
   114         aPSKeyValue );  
       
   115     
       
   116     FLOG_1( _L("[CDialogWatcher] RProperty::Get error = %d "), err );
       
   117     FLOG_1( _L("[CDialogWatcher] PS Key value = %d "), aPSKeyValue );   
       
   118     return err;
       
   119     }
       
   120 
       
   121 void CDialogWatcher::DoCancel()
       
   122     {
       
   123     FLOG( _L("[CDialogWatcher] DoCancel ") ); 
       
   124     iProperty.Cancel();
       
   125     }
       
   126 
       
   127 void CDialogWatcher::RunL()
       
   128     {
       
   129     FLOG( _L("[CDialogWatcher] RunL ") ); 
       
   130     TInt psKey = KErrNotFound;
       
   131     
       
   132     // Get the current PS key.
       
   133     TInt err = GetPSKeyForUI( psKey );
       
   134     if ( err )
       
   135         {
       
   136         // If error, let's try ones more.
       
   137         err = GetPSKeyForUI( psKey );
       
   138         }
       
   139     if ( err == KErrNone )
       
   140         {        
       
   141         if ( psKey )
       
   142             {
       
   143             FLOG( _L("[CDialogWatcher] RunL: PSKey true -> Cancel notes ") ); 
       
   144             // If key is true, cancel all dialogs.
       
   145             iDialogWrapper->CancelWaitingNoteL(); 
       
   146             iDialogWrapper->SetUIFlag( psKey );
       
   147             // Issue new request.
       
   148             StartWatcher();
       
   149             }
       
   150         else if ( !psKey && iRequestToDisplayNote )
       
   151             {
       
   152             FLOG( _L("[CDialogWatcher] RunL: PSKey false -> Show note") ); 
       
   153             // If key is false and note should be displayed, 
       
   154             // start showing the waiting note.
       
   155             iDialogWrapper->SetUIFlag( psKey );
       
   156             iDialogWrapper->ShowWaitingNoteL(); 
       
   157             iRequestToDisplayNote = EFalse;
       
   158             // Issue new request.
       
   159             StartWatcher();
       
   160             }
       
   161         else if ( !psKey )
       
   162             {
       
   163             FLOG( _L("[CDialogWatcher] RunL: PSKey false -> Set UI flag") ); 
       
   164             // If key is true, set UI flag to true and let 
       
   165             // dialog wrapper show notes/warnings if needed.
       
   166             iDialogWrapper->SetUIFlag( psKey );
       
   167             StartWatcher();
       
   168             }
       
   169         }
       
   170     else
       
   171         {
       
   172         FLOG_1( _L("[CDialogWatcher] RunL: PSKey get error = %d"), err ); 
       
   173         FLOG( _L("[CDialogWatcher] RunL: Cancel notes") ); 
       
   174         // If we can not read the the PS Key, let's close dialogs, 
       
   175         // so we do not block the start applications.
       
   176         iDialogWrapper->CancelWaitingNoteL(); 
       
   177         iDialogWrapper->SetUIFlag( ETrue );
       
   178         // Issue new request.
       
   179         StartWatcher();
       
   180         }            
       
   181     }
       
   182 
       
   183 TInt CDialogWatcher::RunError( TInt aError )
       
   184     {
       
   185     FLOG_1( _L("[CDialogWatcher] RunError error = %d "), aError );
       
   186     return aError;
       
   187     }
       
   188 
       
   189 //EOF
       
   190