upnpsharing/applicationengine/src/upnpiconconfigurator.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 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 "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:      Configurator class for mediaserver icons
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 // System
       
    25 #include <centralrepository.h>
       
    26 
       
    27 // upnp stack
       
    28 #include <upnpmediaserverclient.h>
       
    29 
       
    30 // upnp framework internal API's
       
    31 #include "upnpfileutilitytypes.h" // utilities / mime type definitions
       
    32 
       
    33 // app.engine internal
       
    34 #include "upnpapplicationcrkeys.h" //KUPnPAppMediaServerIcon
       
    35 #include "upnpfilesharingengineao.h"
       
    36 #include "upnpiconconfigurator.h"
       
    37 
       
    38 
       
    39 // constants
       
    40 _LIT( KIcon1Path, "\\system\\apps\\upnp\\upnp_ms_jpeg_sm.jpg");
       
    41 const TInt KIcon1Width( 48 );
       
    42 const TInt KIcon1Height( 48 );
       
    43 const TInt KIcon1Depth( 24 );
       
    44 
       
    45 _LIT( KIcon2Path, "\\system\\apps\\upnp\\upnp_ms_jpeg_lrg.jpg");
       
    46 const TInt KIcon2Width( 120 );
       
    47 const TInt KIcon2Height( 120 );
       
    48 const TInt KIcon2Depth( 24 );
       
    49 
       
    50 _LIT( KIcon3Path, "\\system\\apps\\upnp\\upnp_ms_png_sm.png");
       
    51 const TInt KIcon3Width( 48 );
       
    52 const TInt KIcon3Height( 48 );
       
    53 const TInt KIcon3Depth( 24 );
       
    54 
       
    55 _LIT( KIcon4Path, "\\system\\apps\\upnp\\upnp_ms_png_lrg.png");
       
    56 const TInt KIcon4Width( 120 );
       
    57 const TInt KIcon4Height( 120 );
       
    58 const TInt KIcon4Depth( 24 );
       
    59 
       
    60 _LIT(KComponentLogfile, "applicationengine.txt");
       
    61 #include "upnplog.h"
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ============================
       
    64 
       
    65 // --------------------------------------------------------------------------
       
    66 // CUPnPIconConfigurator::CUPnPIconConfigurator
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 CUPnPIconConfigurator::CUPnPIconConfigurator(
       
    70     RUpnpMediaServerClient& aMediaServer, 
       
    71     CUPnPFileSharingEngineAO& aFileShareingAO )
       
    72     : CActive(CActive::EPriorityStandard),
       
    73       iMediaServer( aMediaServer ),
       
    74       iFileShareEngineAO( aFileShareingAO )
       
    75     {
       
    76     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::CUPnPIconConfigurator" );
       
    77     CActiveScheduler::Add( this );
       
    78     }
       
    79 
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CUPnPIconConfigurator::~CUPnPIconConfigurator()
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CUPnPIconConfigurator::~CUPnPIconConfigurator()
       
    86     {
       
    87 
       
    88     if ( IsActive() )
       
    89         {
       
    90         iState = EStateIdle;
       
    91         TRequestStatus* stat = &iStatus;
       
    92         User::RequestComplete( stat, KErrNone );
       
    93         }
       
    94     Cancel();
       
    95     }
       
    96 
       
    97 // --------------------------------------------------------------------------
       
    98 // CUPnPIconConfigurator::NeedToConfigureIcons()
       
    99 // --------------------------------------------------------------------------
       
   100 //
       
   101 TBool CUPnPIconConfigurator::NeedToConfigureIcons()
       
   102     {
       
   103 #ifdef _DEBUG
       
   104     // in debug mode ALWAYS add new icons
       
   105     return ETrue;
       
   106 #else
       
   107     // in normal mode only add icons if they DO NOT exist
       
   108     TBool iconsExist = EFalse;
       
   109     TRAP_IGNORE( iconsExist = CheckIconsAddedL() );
       
   110     __LOG1( "[UPNP_ENGINE] CUPnPIconConfigurator: iconsExist %d",
       
   111         iconsExist );
       
   112     return !iconsExist;
       
   113 #endif
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CUPnPIconConfigurator::ConfigureIconsL()
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 void CUPnPIconConfigurator::ConfigureIconsL()
       
   121     {
       
   122     RemoveIcons();
       
   123     }
       
   124 
       
   125 // --------------------------------------------------------------------------
       
   126 // CUPnPFileSharingEngineAO::RunL
       
   127 // Called when asyncronous request is ready
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 void CUPnPIconConfigurator::RunL()
       
   131     {
       
   132     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::RunL" );
       
   133 
       
   134     TInt err( iStatus.Int() );
       
   135 
       
   136     if ( ( err != KErrNone ) && ( err != KErrNotFound ) )
       
   137         {       
       
   138         iFileShareEngineAO.SetIconComplete( err );
       
   139         }
       
   140     else
       
   141         {
       
   142         switch ( iState )
       
   143             {
       
   144             case EStateRemoving:
       
   145                 {
       
   146                 AddIcon1L();
       
   147                 iState = EStateAdding1;
       
   148                 }
       
   149                 break;
       
   150             case EStateAdding1:
       
   151                 {
       
   152                 delete iIcon1;
       
   153                 iIcon1 = NULL;
       
   154                 AddIcon2L();
       
   155                 iState = EStateAdding2;
       
   156                 }
       
   157                 break;
       
   158             case EStateAdding2:
       
   159                 {
       
   160                 delete iIcon2;
       
   161                 iIcon2 = NULL;
       
   162                 AddIcon3L();
       
   163                 iState = EStateAdding3;
       
   164                 }
       
   165                 break;
       
   166             case EStateAdding3:
       
   167                 {
       
   168                 delete iIcon3;
       
   169                 iIcon3 = NULL;
       
   170                 AddIcon4L();
       
   171                 iState = EStateAdding4;
       
   172                 }
       
   173                 break;
       
   174             case EStateAdding4:
       
   175                 {
       
   176                 delete iIcon4;
       
   177                 iIcon4 = NULL;
       
   178                 // operation complete.
       
   179                 MarkIconsAddedL( ETrue );
       
   180                 Cancel();
       
   181                 iFileShareEngineAO.SetIconComplete( KErrNone );
       
   182                 }
       
   183                 break;
       
   184             default:
       
   185                 {
       
   186                 __PANICD( __FILE__, __LINE__ );
       
   187                 }
       
   188                 break;
       
   189             }
       
   190         }
       
   191     }
       
   192 
       
   193 // --------------------------------------------------------------------------
       
   194 // CUPnPIconConfigurator::RunError
       
   195 // RunL error handler
       
   196 // --------------------------------------------------------------------------
       
   197 //
       
   198 TInt CUPnPIconConfigurator::RunError( TInt aError )
       
   199     {
       
   200     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::RunError begin" );
       
   201 
       
   202     iFileShareEngineAO.SetIconComplete( aError );
       
   203     return KErrNone;
       
   204     }
       
   205 
       
   206 // --------------------------------------------------------------------------
       
   207 // CUPnPIconConfigurator::DoCancel
       
   208 // Cancels active object
       
   209 // --------------------------------------------------------------------------
       
   210 //
       
   211 void CUPnPIconConfigurator::DoCancel()
       
   212     {
       
   213     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::DoCancel" );
       
   214     }
       
   215     
       
   216 // --------------------------------------------------------------------------
       
   217 // CUPnPIconConfigurator::RemoveIconsL
       
   218 // --------------------------------------------------------------------------
       
   219 //
       
   220 void CUPnPIconConfigurator::RemoveIcons()
       
   221     {
       
   222     __LOG( "[UPNP_ENGINE]\t CUPnPIconConfigurator::RemoveIconsL" );
       
   223     iState = EStateRemoving;
       
   224     iMediaServer.RemoveIcons( iStatus );
       
   225     if ( !IsActive() )
       
   226         {
       
   227         SetActive();
       
   228         }
       
   229     else
       
   230         {
       
   231         __LOG("[UPNP_ENGINE]\t CUPnPIconConfigurator::RemoveIconsL Error :\
       
   232                 Already active");
       
   233         }
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CUPnPIconConfigurator::AddIcon1
       
   238 // --------------------------------------------------------------------------
       
   239 //
       
   240 void CUPnPIconConfigurator::AddIcon1L()
       
   241     {
       
   242     __LOG( "[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon1" );
       
   243     TFileName iconPath;
       
   244     ResolveIconPath( KIcon1Path, iconPath );
       
   245     iIcon1 = CUpnpIcon::NewL( iconPath,
       
   246             KIcon1Width, KIcon1Height, KIcon1Depth, KJpegMime );
       
   247     iMediaServer.AddIcon( iIcon1, iStatus );
       
   248     if ( !IsActive() )
       
   249         {
       
   250         SetActive();
       
   251         }
       
   252     else
       
   253         {
       
   254         __LOG("[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon1L Error :\
       
   255                 Already active");
       
   256         }
       
   257     }
       
   258 
       
   259 // --------------------------------------------------------------------------
       
   260 // CUPnPIconConfigurator::AddIcon2
       
   261 // --------------------------------------------------------------------------
       
   262 //
       
   263 void CUPnPIconConfigurator::AddIcon2L()
       
   264     {
       
   265     __LOG( "[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon2" );
       
   266     TFileName iconPath;
       
   267     ResolveIconPath( KIcon2Path, iconPath );
       
   268     iIcon2 = CUpnpIcon::NewL( iconPath,
       
   269         KIcon2Width, KIcon2Height, KIcon2Depth, KJpegMime );
       
   270     iMediaServer.AddIcon( iIcon2, iStatus );
       
   271     if ( !IsActive() )
       
   272         {
       
   273         SetActive();
       
   274         }
       
   275     else
       
   276         {
       
   277         __LOG("[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon2L Error :\
       
   278                 Already active");
       
   279         }
       
   280     }
       
   281 
       
   282 // --------------------------------------------------------------------------
       
   283 // CUPnPIconConfigurator::AddIcon3
       
   284 // --------------------------------------------------------------------------
       
   285 //
       
   286 void CUPnPIconConfigurator::AddIcon3L()
       
   287     {
       
   288     __LOG( "[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon3" );
       
   289     TFileName iconPath;
       
   290     ResolveIconPath( KIcon3Path, iconPath );
       
   291     iIcon3 = CUpnpIcon::NewL( iconPath,
       
   292         KIcon3Width, KIcon3Height, KIcon3Depth, KPngMime );
       
   293     iMediaServer.AddIcon( iIcon3, iStatus );
       
   294     if ( !IsActive() )
       
   295         {
       
   296         SetActive();
       
   297         }
       
   298     else
       
   299         {
       
   300         __LOG("[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon3L Error :\
       
   301                 Already active");
       
   302         }
       
   303     }
       
   304 
       
   305 // --------------------------------------------------------------------------
       
   306 // CUPnPIconConfigurator::AddIcon4
       
   307 // --------------------------------------------------------------------------
       
   308 //
       
   309 void CUPnPIconConfigurator::AddIcon4L()
       
   310     {
       
   311     __LOG( "[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon4" );
       
   312     TFileName iconPath;
       
   313     ResolveIconPath( KIcon4Path, iconPath );
       
   314     iIcon4 = CUpnpIcon::NewL( iconPath,
       
   315         KIcon4Width, KIcon4Height, KIcon4Depth, KPngMime );
       
   316     iMediaServer.AddIcon( iIcon4, iStatus );
       
   317     if ( !IsActive() )
       
   318         {
       
   319         SetActive();
       
   320         }
       
   321     else
       
   322         {
       
   323         __LOG("[UPNP_ENGINE]\t CUPnPIconConfigurator::AddIcon4L Error :\
       
   324                 Already active");
       
   325         }
       
   326     }
       
   327 
       
   328 // --------------------------------------------------------------------------
       
   329 // CUPnPIconConfigurator::ResolveIconPath
       
   330 // Resolves absolute icon path
       
   331 // --------------------------------------------------------------------------
       
   332 //
       
   333 void CUPnPIconConfigurator::ResolveIconPath(
       
   334     const TDesC& relativePath, TFileName& iconPath )
       
   335     {
       
   336     iconPath = relativePath;
       
   337     TFileName dllName;
       
   338     Dll::FileName( dllName );
       
   339     TBuf<2> drive = dllName.Left(2); // Drive letter followed by ':' 
       
   340     iconPath.Insert( 0, drive );
       
   341     }
       
   342         
       
   343 // --------------------------------------------------------------------------
       
   344 // CUPnPIconConfigurator::CheckIconsAddedL
       
   345 // Set the mediaserver icon if it is needed
       
   346 // --------------------------------------------------------------------------
       
   347 //
       
   348 TBool CUPnPIconConfigurator::CheckIconsAddedL()
       
   349     {
       
   350     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::CheckIconsAddedL" );
       
   351 
       
   352     TInt iconSet ( EFalse );
       
   353     CRepository *repository = CRepository::NewL( KCRUidUPnPApplication );
       
   354     repository->Get( KUPnPAppMediaServerIcon, iconSet );
       
   355     delete repository;
       
   356     repository = NULL;
       
   357     return iconSet;
       
   358     }
       
   359 
       
   360 // --------------------------------------------------------------------------
       
   361 // CUPnPIconConfigurator::MarkIconsAddedL
       
   362 // store the cenrep value
       
   363 // --------------------------------------------------------------------------
       
   364 //
       
   365 void CUPnPIconConfigurator::MarkIconsAddedL( TBool aMark )
       
   366     {
       
   367     __LOG( "[UPNP_ENGINE] CUPnPIconConfigurator::MarkIconsAddedL" );
       
   368     
       
   369     CRepository *repository = CRepository::NewL( KCRUidUPnPApplication );
       
   370     repository->Set( KUPnPAppMediaServerIcon, aMark );
       
   371     delete repository;
       
   372     repository = NULL;
       
   373     }
       
   374 
       
   375 
       
   376 // End of file