widgets/widgetapp/src/WidgetUiPSNotifier.cpp
branchRCL_3
changeset 47 e1bea15f9a39
equal deleted inserted replaced
46:30342f40acbf 47:e1bea15f9a39
       
     1 /*
       
     2 * Copyright (c) 2007 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:  
       
    15 *
       
    16 */
       
    17  
       
    18 #include "WidgetUiPSNotifier.h"
       
    19 #include "WidgetUiWindowManager.h"
       
    20 #include <widgetregistryclient.h>
       
    21 #include "WidgetUiWindow.h"
       
    22 #include "WidgetAppDefs.rh"
       
    23 #include <e32debug.h>
       
    24 CWidgetUiPSNotifier::CWidgetUiPSNotifier(CWidgetUiWindowManager& aWindowManager, TPropertyKeyValues aKey) :iWindowManager(aWindowManager), iKey(aKey),  CActive( EPriorityNormal )
       
    25     {
       
    26     }
       
    27 CWidgetUiPSNotifier::~CWidgetUiPSNotifier()
       
    28     {
       
    29     Cancel();
       
    30     iProperty.Close();
       
    31     }
       
    32 
       
    33 CWidgetUiPSNotifier* CWidgetUiPSNotifier::NewL(CWidgetUiWindowManager& aWindowManager, TPropertyKeyValues aKey )
       
    34     { 
       
    35     CWidgetUiPSNotifier* self = new (ELeave) CWidgetUiPSNotifier(aWindowManager, aKey);
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );    
       
    39     return self;
       
    40     }
       
    41 
       
    42 void CWidgetUiPSNotifier::ConstructL()
       
    43     { 
       
    44     CActiveScheduler::Add(this);    
       
    45     TInt r(KErrNone);
       
    46     
       
    47     if ( iKey != EWidgetRegAltered)
       
    48         {
       
    49         r = RProperty::Define( KPropertyWidgetUI, iKey, RProperty::EInt );
       
    50         if ( r != KErrAlreadyExists && r != KErrNone )
       
    51             {
       
    52             User::LeaveIfError( r );
       
    53             }
       
    54         User::LeaveIfError( iProperty.Attach( KPropertyWidgetUI,iKey));         
       
    55         }
       
    56       // Attach the key
       
    57     
       
    58     if ( iKey == EWidgetRegAltered )
       
    59         User::LeaveIfError( iProperty.Attach( KMyPropertyCat,iKey));         
       
    60     // initial subscription
       
    61     iProperty.Subscribe( iStatus );
       
    62     SetActive();
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CWrtHarvesterPSNotifier::DoCancel
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CWidgetUiPSNotifier::DoCancel()
       
    71     {
       
    72     iProperty.Cancel();
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CWidgetUiPSNotifier::RunL()
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CWidgetUiPSNotifier::RunL()
       
    80     {
       
    81     
       
    82     // resubscribe before processing new value to prevent missing updates
       
    83     iProperty.Subscribe( iStatus );
       
    84     SetActive();
       
    85     
       
    86     if (iKey == EWidgetRegAltered)
       
    87         {
       
    88         UpdateWindowList();
       
    89         }
       
    90     else if( iKey == ESapiPrompt || iKey == ESapiPromptCleared)
       
    91         {
       
    92         UpdateSapiPromptState();
       
    93         }
       
    94 
       
    95     }
       
    96 // ---------------------------------------------------------------------------
       
    97 // CWrtHarvesterPSNotifier::UpdateSapiPromptState
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CWidgetUiPSNotifier::UpdateSapiPromptState()
       
   101     {
       
   102     TInt value( 0 );
       
   103     iProperty.Get( value  );
       
   104 
       
   105     if( value != 0)
       
   106         {
       
   107         RPointerArray<CWidgetUiWindow>      windowList;
       
   108         iWindowManager.WindowList( windowList );
       
   109         for(TInt i=windowList.Count()-1;i>=0;i--)
       
   110             {
       
   111             if( value == windowList[i]->Uid().iUid)
       
   112                 {
       
   113                 if(iKey == ESapiPrompt )
       
   114                     {
       
   115                 	  if( !windowList[i]->getSapiPromptCleared() )
       
   116                 	  	   windowList[i]->setNeedToIgnoreSapiClearNtfn(EIncrement);
       
   117                 	  else if( windowList[i]->getNeedToIgnoreSapiNtfn() == 0)
       
   118                         windowList[i]->setSapiPromptCleared(EFalse);
       
   119                     else if(windowList[i]->getNeedToIgnoreSapiNtfn() > 0 )
       
   120                         	  windowList[i]->setNeedToIgnoreSapiNtfn(EDecrement);
       
   121 
       
   122                     }
       
   123                 else if(iKey == ESapiPromptCleared )
       
   124                     {
       
   125                 	  if( windowList[i]->getSapiPromptCleared() )
       
   126                 	      windowList[i]->setNeedToIgnoreSapiNtfn(EIncrement);
       
   127                 	  else if ( windowList[i]->getNeedToIgnoreSapiClearNtfn() == 0)
       
   128                         windowList[i]->setSapiPromptCleared(ETrue);
       
   129                     else if(windowList[i]->getNeedToIgnoreSapiClearNtfn() > 0)
       
   130                   	    windowList[i]->setNeedToIgnoreSapiClearNtfn(EDecrement);
       
   131                     }
       
   132                 break;
       
   133                 }
       
   134             }
       
   135         }	
       
   136     
       
   137     }
       
   138 // ---------------------------------------------------------------------------
       
   139 // CWrtHarvesterPSNotifier::UpdateWindowList
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CWidgetUiPSNotifier::UpdateWindowList()
       
   143     {
       
   144     RPointerArray<CWidgetUiWindow>      iWindowList;
       
   145     RWidgetRegistryClientSession        iClientSession;
       
   146     RPointerArray<CWidgetInfo>          iWidgetInfoArray;
       
   147         
       
   148     iWindowManager.WindowList( iWindowList );
       
   149     User::LeaveIfError( iClientSession.Connect());
       
   150     iClientSession.InstalledWidgetsL(iWidgetInfoArray); 
       
   151     TInt j=0;
       
   152     for(TInt i=iWindowList.Count()-1;i>=0;i--){
       
   153         for(j=0;j<iWidgetInfoArray.Count();j++) {
       
   154             if( iWindowList[i]->Uid().iUid == iWidgetInfoArray[j]->iUid.iUid )
       
   155                 {
       
   156                 break;
       
   157                 }
       
   158             }
       
   159             //present.... so break, go to the next element in iWindowList array
       
   160             if (j == iWidgetInfoArray.Count())
       
   161                 iWindowManager.HandleWidgetCommandL(iWindowList[i]->Uid(), Deactivate);
       
   162                                                
       
   163         }
       
   164     }
       
   165