psln/PslnFramework/src/PslnFWAppThemeHandler.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2005-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 "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:  Handles interface towards XUIKON, sets and gets theme information.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 // Psln Framework
       
    23 #include    <PslnFWAppThemeHandler.h>
       
    24 #include    <MPslnFWAppThemeObserver.h>
       
    25 #include    "PslnXNClientLoader.h"
       
    26 
       
    27 // Constants
       
    28 #include    "PslnConst.h"
       
    29 #include    "PslnDebug.h"
       
    30 
       
    31 // Xuikon
       
    32 #include    <XnODT.h>
       
    33 
       
    34 #include    <AknEnv.h>
       
    35 
       
    36 // CONTANTS
       
    37 // Path to wrapper dll for XnClient.
       
    38 _LIT( KPslnXuikonClientLoaderName, 
       
    39      "\\system\\libs\\PslnXNClientLoader.dll");
       
    40 
       
    41 // TYPE DEFINITIONS
       
    42 // Xuikon client loader.
       
    43 typedef TAny* (*NewXuikonClientL)();
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // C++ constructor can NOT contain any code, that might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CPslnFWAppThemeHandler::CPslnFWAppThemeHandler( 
       
    50     MPslnFWAppThemeObserver& aObserver,
       
    51     CArrayPtrFlat<CXnODT>& aApplicationSkinList ) : 
       
    52     iObserver( aObserver ), iAppThemeList( &aApplicationSkinList )
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CPslnFWAppThemeHandler::ConstructL()
       
    61     {
       
    62     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::ConstructL BEGIN");
       
    63     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::ConstructL END");
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CPslnFWAppThemeHandler* CPslnFWAppThemeHandler::NewL
       
    71     ( MPslnFWAppThemeObserver& aObserver,
       
    72       CArrayPtrFlat<CXnODT>& aApplicationSkinList )
       
    73     {
       
    74     CPslnFWAppThemeHandler* self = 
       
    75         new( ELeave ) CPslnFWAppThemeHandler( aObserver, aApplicationSkinList );
       
    76 
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     CleanupStack::Pop( self );
       
    80 
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 // Destructor
       
    86 CPslnFWAppThemeHandler::~CPslnFWAppThemeHandler()
       
    87     {
       
    88     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler destructor BEGIN");
       
    89     // deleting iXnClientLoader automatically cancels all existing fetches.
       
    90     delete iXnClientLoader;
       
    91     if( iXnClientDllLoaded )
       
    92         {
       
    93         iXnClientDll.Close();
       
    94         }
       
    95     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler destructor END");
       
    96     // do not destroy iAppThemeList - it is owned by application.
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // Collect application specific themes from server.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C TXnServiceCompletedMessage CPslnFWAppThemeHandler::GetApplicationSkinsL( 
       
   104     TUid aUid )
       
   105     {
       
   106     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::GetApplicationSkinsL BEGIN");
       
   107     if ( !iXnClientLoader )
       
   108         {
       
   109         CreateXnClientL();
       
   110         }    
       
   111     // Remember to cancel first. CPslnFWAppThemeHandler only supports one 
       
   112     // active request per application.
       
   113     if ( iFetchOngoing )
       
   114         {
       
   115         return EXnServiceRequestError;
       
   116         }
       
   117 
       
   118     // Clear previous fetch first.
       
   119     iFetchOngoing = ETrue;
       
   120     if ( iAppThemeList )
       
   121         {
       
   122         iAppThemeList->ResetAndDestroy();
       
   123         }
       
   124 
       
   125     // Start looking for application skins.
       
   126     CXnODT* odt = CreateODTFromAppUidLC( aUid );
       
   127     TXnServiceCompletedMessage ret =
       
   128         iXnClientLoader->GetListHeaders( *odt, *iAppThemeList ); 
       
   129 
       
   130     if ( ret == EXnGetListHeadersSuccess )
       
   131         {
       
   132         // There are existing application specific skins. 
       
   133         // Let's start looking for these.
       
   134         iXnClientLoader->GetNextHeader();
       
   135         }
       
   136     else if ( ret == EXnGetListHeadersEmpty )
       
   137         {
       
   138         // There are no application specific skins now, but
       
   139         // let's start to wait if some would appear later.
       
   140         iXnClientLoader->GetNextHeader();
       
   141         }
       
   142     else if ( ret == EXnGetListHeadersFailed || ret == EXnServiceRequestError )
       
   143         {
       
   144         // Error.
       
   145         PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::GetApplicationSkinsL Error");
       
   146         }
       
   147     else
       
   148         {
       
   149         PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::GetApplicationSkinsL Empty else");
       
   150         }
       
   151 
       
   152     CleanupStack::PopAndDestroy( odt );
       
   153     return ret;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // Sets application specific theme.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TXnServiceCompletedMessage CPslnFWAppThemeHandler::SetApplicationSkinL( 
       
   161     CXnODT& aThemeODT )
       
   162     {
       
   163     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::SetApplicationSkinL BEGIN");
       
   164     if ( !iXnClientLoader )
       
   165         {
       
   166         CreateXnClientL();
       
   167         }
       
   168 
       
   169     CXnODT* odt = CXnODT::NewL();
       
   170     CleanupStack::PushL( odt );
       
   171 
       
   172     TXnServiceCompletedMessage ret = 
       
   173         iXnClientLoader->SetActiveTheme( aThemeODT, *odt );
       
   174 
       
   175     CleanupStack::PopAndDestroy( odt );
       
   176     return ret;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CPslnFWAppThemeHandler::CancelGetApplicationSkins
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C void CPslnFWAppThemeHandler::CancelGetApplicationSkins()
       
   185     {
       
   186     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::CancelGetApplicationSkins BEGIN");
       
   187     iFetchOngoing = EFalse;
       
   188     if ( iXnClientLoader )
       
   189         {
       
   190         iXnClientLoader->CancelGetListHeaders(); 
       
   191         }   
       
   192     }
       
   193 
       
   194 EXPORT_C TXnServiceCompletedMessage CPslnFWAppThemeHandler::SetApplicationSkinAndExitL( 
       
   195     CXnODT& aThemeODT )
       
   196     {
       
   197     TXnServiceCompletedMessage ret = SetApplicationSkinL( aThemeODT );
       
   198     if ( ret ==  EXnSetActiveThemeSuccess )
       
   199         {
       
   200         CAknEnv::RunAppShutter();
       
   201         }    
       
   202     return ret;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // Xuikon theme manager callback.
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CPslnFWAppThemeHandler::HandleXnClientMessage( 
       
   210     TXnServiceCompletedMessage aMessage )
       
   211     {
       
   212     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::HandleXnClientMessage BEGIN");   
       
   213     switch ( aMessage )
       
   214         {
       
   215         case EXnGetListHeadersEmpty:
       
   216             // notify client that there are no themes available. 
       
   217             // Destroy possible previously available skins
       
   218             iObserver.HandleMessage( aMessage );
       
   219             if ( iAppThemeList )
       
   220                 {
       
   221                 iAppThemeList->ResetAndDestroy();
       
   222                 }
       
   223             break;
       
   224         case EXnGetListHeadersFailed:
       
   225             // notify client that observation has been stopped
       
   226             iObserver.HandleMessage( aMessage );
       
   227             CancelGetApplicationSkins();
       
   228             break;
       
   229         case EXnServiceRequestCanceled:
       
   230         case EXnServiceRequestError:
       
   231             // notify client about possible error cause.
       
   232             iObserver.HandleMessage( aMessage );
       
   233             break;
       
   234         case EXnGetListHeadersUpdate:
       
   235             // give the client the new list.
       
   236             // Fall through
       
   237         case EXnGetListHeadersRestart:
       
   238             // notify client that old list is now not valid, and the new list needs to
       
   239             // be used.
       
   240             // Fall through
       
   241         default:
       
   242             iObserver.HandleMessage( aMessage, *iAppThemeList );
       
   243             break;
       
   244         }
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // Creates ODT based on application UID. 
       
   249 // 
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 CXnODT* CPslnFWAppThemeHandler::CreateODTFromAppUidLC( TUid aUid )
       
   253     {
       
   254     PSLN_TRACE_DEBUG("CPslnFWAppThemeHandler::CreateODTFromAppUidLC BEGIN");
       
   255     CXnODT* odt = CXnODT::NewL();
       
   256     CleanupStack::PushL( odt );
       
   257     odt->SetAppUid( aUid.iUid ); // the UID of the application
       
   258     odt->SetProviderUid( Nokia_VID ); // all provided by Nokia
       
   259     return odt;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // Creates XUIKON Client interface.
       
   264 // 
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 void CPslnFWAppThemeHandler::CreateXnClientL()
       
   268     {    
       
   269     // Xuikon Client dll loading.
       
   270     if( !iXnClientDllLoaded )
       
   271         {
       
   272         if( iXnClientDll.Load( KPslnXuikonClientLoaderName ) == KErrNone )
       
   273             {
       
   274             iXnClientDllLoaded = ETrue;
       
   275             // Request the entry function
       
   276             NewXuikonClientL xuikonClient = 
       
   277                 (NewXuikonClientL) iXnClientDll.Lookup( KPslnDllEntryPoint );
       
   278             if( xuikonClient )
       
   279                 {
       
   280                 // Create the class
       
   281                 iXnClientLoader = 
       
   282                     (CPslnXNClientLoader*) (*xuikonClient)();
       
   283                 }
       
   284             }
       
   285         }
       
   286     // The wrapper failed to load.
       
   287     if ( !iXnClientLoader )
       
   288         {
       
   289         User::Leave( KErrNotFound );
       
   290         }
       
   291     iXnClientLoader->CreateClientL( *this );
       
   292     }
       
   293 //  End of File