webengine/wrtharvester/src/wrtharvesterregistryaccess.cpp
changeset 0 dd21522fd290
child 16 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2007, 2008 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:  Handle communications to Widget Registry.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "wrtharvesterregistryaccess.h"
       
    22 
       
    23 _LIT( KSeparator, ":" );
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ==============================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // Constructor
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 WrtHarvesterRegistryAccess::WrtHarvesterRegistryAccess()
       
    33 	{
       
    34 	}
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Destructor
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 WrtHarvesterRegistryAccess::~WrtHarvesterRegistryAccess()
       
    41     {
       
    42     iWidgetInfoArray.ResetAll();
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Collect bundle names of widgets supporting miniviews.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void WrtHarvesterRegistryAccess::WidgetBundleNamesL( 
       
    50     RPointerArray< HBufC >& aArray )
       
    51     {
       
    52     RWrtArray< CWidgetInfo > widgetInfoArr;
       
    53     RWidgetRegistryClientSession session;
       
    54     
       
    55     CleanupClosePushL( session );
       
    56     widgetInfoArr.PushL();
       
    57     
       
    58     User::LeaveIfError( session.Connect() );
       
    59     
       
    60     aArray.Reset();
       
    61     // Reset previously appended widget infos
       
    62     iWidgetInfoArray.ResetAll();
       
    63     
       
    64     TInt err = session.InstalledWidgetsL( widgetInfoArr );
       
    65     
       
    66     for( TInt i( widgetInfoArr.Count() - 1 ); i >= 0; --i )
       
    67         {
       
    68         CWidgetInfo* widgetInfo( widgetInfoArr[i] );
       
    69         
       
    70         if ( SupportsMiniviewL( session, widgetInfo->iUid ) )
       
    71             {
       
    72             aArray.AppendL( ConstructWidgetNameL( session, *widgetInfo ) );
       
    73             iWidgetInfoArray.AppendL( widgetInfo );
       
    74             }
       
    75         else
       
    76             {
       
    77             delete widgetInfo;
       
    78             }
       
    79             
       
    80         widgetInfoArr.Remove( i );
       
    81         }
       
    82         
       
    83     CleanupStack::PopAndDestroy( 2, &session ); 
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // Find widget by UID.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 TUid WrtHarvesterRegistryAccess::WidgetUid( TPtrC aBundleName )
       
    91     {
       
    92     TUid uid={0};
       
    93     TInt pos = aBundleName.Find( KSeparator );
       
    94     if( pos != KErrNotFound )
       
    95         {
       
    96         aBundleName.Set( aBundleName.Right( aBundleName.Length()-pos-1 ));
       
    97         }
       
    98                    
       
    99     for( TInt i = 0; i < iWidgetInfoArray.Count(); i++ )
       
   100         {
       
   101         if( aBundleName == *iWidgetInfoArray[i]->iBundleName )
       
   102             {
       
   103             uid = iWidgetInfoArray[i]->iUid;
       
   104             break;
       
   105             }
       
   106         }
       
   107     return uid;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Check if widget supports miniview.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TBool WrtHarvesterRegistryAccess::SupportsMiniviewL( 
       
   115     RWidgetRegistryClientSession& aSession,
       
   116     const TUid& aUid )
       
   117     {
       
   118     TBool res( EFalse );
       
   119     
       
   120     CWidgetPropertyValue* value( NULL );
       
   121     value = aSession.GetWidgetPropertyValueL( aUid, EMiniViewEnable );
       
   122     
       
   123     res = value && *value;
       
   124     
       
   125     delete value;
       
   126     return res;
       
   127     }
       
   128     
       
   129 // ---------------------------------------------------------------------------
       
   130 // Get the Bundle identifier.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 HBufC* WrtHarvesterRegistryAccess::ConstructWidgetNameL( 
       
   134     RWidgetRegistryClientSession& aSession,
       
   135     CWidgetInfo& aInfo )
       
   136     {   
       
   137     CWidgetPropertyValue* value( NULL );
       
   138     value = aSession.GetWidgetPropertyValueL( aInfo.iUid, EBundleIdentifier );
       
   139     CleanupStack::PushL( value );
       
   140     
       
   141     const TDesC& identifier = *value;    
       
   142     HBufC* bundle = aInfo.iBundleName;
       
   143 
       
   144     HBufC* name = HBufC::NewL( identifier.Length() + KSeparator().Length() + bundle->Length());
       
   145     TPtr ptr = name->Des();
       
   146     ptr.Append( identifier );
       
   147     ptr.Append( KSeparator );
       
   148     ptr.Append( *bundle);
       
   149     CleanupStack::PopAndDestroy( value );
       
   150     return name;
       
   151     }
       
   152     
       
   153  //  End of File
       
   154