psln/pslnengine/src/PslnModel.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2002-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:  Model class for Psln application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Psln specific.
       
    20 #include "PslnModel.h"
       
    21 #include "PslnDiskUtil.h"
       
    22 #include "PslnFeatures.h"
       
    23 #include "PslnSkinEntry.h"
       
    24 #include "PslnSkinStore.h"
       
    25 #include "PslnEcomListener.h"
       
    26 #include "PslnDebug.h"
       
    27 #include "PslnConst.h"
       
    28 
       
    29 // Wrapper for wallpaper utils.
       
    30 #include "pslnwallpaperutilsloader.h"
       
    31 #include "pslnbrowserlaunchloader.h"
       
    32 
       
    33 // Resources
       
    34 #include <psln.rsg>
       
    35 #include <pslnskinnames.rsg>
       
    36 
       
    37 // Generic
       
    38 #include <StringLoader.h>
       
    39 #include <data_caging_path_literals.hrh>
       
    40 #include <f32file.h>
       
    41 #include <hal.h>
       
    42 
       
    43 // UI libraries
       
    44 #include <AknsSkinUID.h>
       
    45 #include <AknsConstants.h>
       
    46 #include <eikenv.h>
       
    47 #include <AknQueryDialog.h>
       
    48 
       
    49 // Misc
       
    50 #include <bautils.h>
       
    51 #include <mmf/common/mmfcontrollerpluginresolver.h> // For CleanupResetAndDestroyPushL
       
    52 
       
    53 // Central Repository and Publish&Subscribe keys.
       
    54 #include <centralrepository.h>
       
    55 #include <e32property.h>
       
    56 #include "pslninternalcrkeys.h"
       
    57 #include <AknSkinsInternalCRKeys.h>             // wallpaper, screen saver
       
    58 #include <cenrepnotifyhandler.h>
       
    59 
       
    60 // For enabling first component transition effect
       
    61 #include <gfxtranseffect/gfxtranseffect.h>
       
    62 #include <akntranseffect.h>
       
    63 #ifdef RD_MULTIPLE_DRIVE
       
    64 #include <driveinfo.h>
       
    65 #endif //RD_MULTIPLE_DRIVE
       
    66 
       
    67 
       
    68 // CONSTANTS
       
    69 // Path of skin files.
       
    70 _LIT( KPslnSkinNamesFile,"z:PslnSkinNames.rsc" );
       
    71 
       
    72 // Default item index.
       
    73 const TInt KPslnDefaultItemIndex = 0;
       
    74 
       
    75 // Screen saver type: user defined text
       
    76 const TInt KPslnSsText = 0;
       
    77 // Screen saver type: date & time
       
    78 const TInt KPslnSsDate = 1;
       
    79 // Screen saver type: object
       
    80 const TInt KPslnSsObject = 3;
       
    81 // Screen saver type: none
       
    82 const TInt KPslnSsNone = 4;
       
    83 
       
    84 // Granularity of screen saver array.
       
    85 const TInt KPslnSsArrayGranularity = 5;
       
    86 // Length of drive number descriptor.
       
    87 const TInt KPslnDriveNumberLength = 2;
       
    88 // Free RAM required when activating transition effects.
       
    89 const TInt KPslnTransitionEffectRAMThreshold = 2000000;
       
    90 // Maximum of text length in text screensaver for APAC.
       
    91 // For western variant, value is taken directly from resources.
       
    92 const TInt KPslnSsTextDialogAPACMaxLength = 7;
       
    93 // Path to wallpaper utils.
       
    94 _LIT( KPslnWallpaperUtilsLoaderName, 
       
    95      "\\system\\libs\\PslnWallpaperUtilsLoader.dll");
       
    96 _LIT( KPslnBrowserLaunchLoaderName, 
       
    97      "\\system\\libs\\PslnBrowserLaunchLoader.dll");
       
    98 // Screen saver UID is stored like [ss_uid]. This is the end mark.
       
    99 _LIT( KPslnScreenSaverUidEndMark, "]" );
       
   100 
       
   101 // CLASS DECLARATIONS
       
   102 
       
   103 class CPslnActivationGuard : public CBase
       
   104     {
       
   105     public:
       
   106         virtual ~CPslnActivationGuard()
       
   107             {
       
   108             PSLN_TRACE_DEBUG("CPslnActivationGuard::destructor");
       
   109             iModel->SkinSrvSession().EnableSkinChangeNotify();
       
   110             }
       
   111 
       
   112         static CPslnActivationGuard* NewL( CPslnModel* aModel )
       
   113             {
       
   114             PSLN_TRACE_DEBUG("CPslnActivationGuard::NewL");
       
   115             CPslnActivationGuard* self = new (ELeave) CPslnActivationGuard();
       
   116             self->iModel = aModel;
       
   117             PSLN_TRACE_DEBUG("CPslnActivationGuard DisableSkinChangeNotify");
       
   118             aModel->SkinSrvSession().DisableSkinChangeNotify();
       
   119             return self;
       
   120             }
       
   121 
       
   122     private:
       
   123         CPslnModel* iModel;
       
   124     };
       
   125 
       
   126 // TYPE DEFINITIONS
       
   127 // Wallpaper Utils entry.
       
   128 typedef TAny* (*NewWallpaperUtilsL)();
       
   129 
       
   130 // Browser Launcher entry.
       
   131 typedef TAny* (*NewBrowserLauncherL)();
       
   132 
       
   133 
       
   134 // ============================ MEMBER FUNCTIONS ===============================
       
   135 // -----------------------------------------------------------------------------
       
   136 // Two-phased constructor.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C CPslnModel* CPslnModel::NewL( MAknsSkinChangeObserver* aObserver )
       
   140     {
       
   141     PSLN_TRACE_DEBUG("CPslnModel::NewL");
       
   142     CPslnModel* self = new(ELeave) CPslnModel;
       
   143 
       
   144     CleanupStack::PushL( self );
       
   145     self->ConstructL( aObserver );
       
   146     CleanupStack::Pop( self );
       
   147 
       
   148     PSLN_TRACE_DEBUG("CPslnModel::NewL OK");
       
   149     return self;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // Two-phased constructor. Simpler version for PslnFramework use.
       
   154 // Deprecated.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C CPslnModel* CPslnModel::NewL()
       
   158     {
       
   159     CPslnModel* self = new(ELeave) CPslnModel;
       
   160     return self;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // Destructor
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 EXPORT_C CPslnModel::~CPslnModel()
       
   168     {
       
   169     PSLN_TRACE_DEBUG("CPslnModel::destructor");
       
   170 
       
   171     delete iSkinsRepository;
       
   172     delete iScreenSaverRepository;
       
   173     iSkinSrvSession.Close();
       
   174 
       
   175     while( iSkinNames.Count() )
       
   176         {
       
   177         delete iSkinNames[0].iListName;
       
   178         delete iSkinNames[0].iTitleName;
       
   179         iSkinNames.Remove(0);
       
   180         }
       
   181     iSkinNames.Close();
       
   182 
       
   183     delete iScreensaverFilenameArr;
       
   184     delete iScreensaverNameArr;
       
   185     iScreensaverCapsArr.Reset();
       
   186 
       
   187     delete iSkinStore;
       
   188     if( iVisibleSkinArr )
       
   189         {
       
   190         iVisibleSkinArr->ResetAndDestroy();
       
   191         delete iVisibleSkinArr;
       
   192         }
       
   193     delete iScreenSaverInfo;
       
   194 
       
   195     delete iWallpaperSetter;
       
   196     if( iInternalState.IsSet( EPslnModelStateWallpaperDllLoaded  ) )
       
   197         {
       
   198         iWallpaperDll.Close();
       
   199         }
       
   200 
       
   201     delete iBrowserLauncher;
       
   202     if( iInternalState.IsSet( EPslnModelStateBrowserLaunchDllLoaded ) )
       
   203         {
       
   204         iBrowserLaunchDll.Close();
       
   205         }
       
   206 
       
   207     // If client is bad-behaving and has not cancelled listening, 
       
   208     // cancel itself.
       
   209     if ( iScreenSaverListener )
       
   210         {
       
   211         if ( iScreenSaverListener->IsActive() )
       
   212             {
       
   213             iScreenSaverListener->Cancel();
       
   214             }
       
   215         delete iScreenSaverListener;
       
   216         // NUllified here, just in case if client later decides to try and
       
   217         // destroy this.
       
   218         iScreenSaverListener = NULL;
       
   219         }
       
   220         
       
   221     if(iThemesAppCenRepNotifyHandler)
       
   222         {
       
   223         iThemesAppCenRepNotifyHandler->StopListening();
       
   224         delete iThemesAppCenRepNotifyHandler;
       
   225         }
       
   226     delete iThemesAppRepository;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // Activate a Skin.
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C TBool CPslnModel::ActivateSkinL(
       
   234     const TDesC8& /*aPreviewType*/,
       
   235     const TInt /*aActiveSkinIndex*/ )
       
   236     {
       
   237     PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL -- depricated!!");
       
   238     User::Leave( KErrNotSupported );
       
   239     return EFalse;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // Activate a screen saver.
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C TInt CPslnModel::ActivateScreenSaver( const TInt aItemIndex, 
       
   247     TPslnScreenSaverActivation aActivationType )
       
   248     {
       
   249     PSLN_TRACE_DEBUG("CPslnModel::ActivateScreenSaver");
       
   250     TRAPD( err, ActivateScreenSaverL( aItemIndex, aActivationType ) );
       
   251     PSLN_TRACE_DEBUG1("CPslnModel::ActivateScreenSaver %d", err );
       
   252     return err;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CPslnModel::GuardActivationLC
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C void  CPslnModel::GuardActivationLC()
       
   260     {
       
   261     PSLN_TRACE_DEBUG("CPslnModel::GuardActivationLC");
       
   262     CleanupStack::PushL( CPslnActivationGuard::NewL( this ) );
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // Download a skin.
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C void CPslnModel::DownloadSkinL()
       
   270     {
       
   271     PSLN_TRACE_DEBUG("CPslnModel::DownloadSkinL BEGIN");
       
   272     PSLN_TRACE_DEBUG("CPslnModel::DownloadSkinL Load DLL");
       
   273     LoadBrowserLaunchL();
       
   274     if ( iBrowserLauncher )
       
   275         {
       
   276         PSLN_TRACE_DEBUG("CPslnModel::DownloadSkinL Launch embedded browser");
       
   277         TRAPD( error, 
       
   278                iBrowserLauncher->LaunchBrowserStandaloneL( ) );
       
   279         if ( error != KErrNone )
       
   280             {
       
   281             PSLN_TRACE_DEBUG1("CPslnModel::DownloadSkinL Handle exit: %d", error );
       
   282             }
       
   283         if ( error == KErrNoMemory )
       
   284             {
       
   285             PSLN_TRACE_DEBUG("CPslnModel::DownloadSkinL OOM");
       
   286             User::Leave( error );
       
   287             }
       
   288         }
       
   289     PSLN_TRACE_DEBUG("CPslnModel::DownloadSkinL END");
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // Set Background image path name.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C TInt CPslnModel::SetBackgroundImagePath( const TDesC& aImagePath )
       
   297     {
       
   298     PSLN_TRACE_DEBUG("CPslnModel::SetBackgroundImagePath");
       
   299 
       
   300     TRAP_IGNORE( LoadWallpaperUtilsL() );
       
   301     TInt retVal = KErrNone;
       
   302     if ( iWallpaperSetter )
       
   303         {
       
   304         if( aImagePath.Length() > 0 )
       
   305             {
       
   306             retVal = iWallpaperSetter->SetIdleWallpaper(
       
   307                 aImagePath, 
       
   308                 CCoeEnv::Static(),
       
   309                 R_PSLN_SKINS_LOADING_IMAGE,
       
   310                 R_PSLN_GENERAL_WAIT_NOTE );
       
   311             }
       
   312         else
       
   313             {
       
   314             retVal = iWallpaperSetter->SetIdleWallpaper( KNullDesC, NULL );
       
   315             }
       
   316         }
       
   317     else
       
   318         {
       
   319         retVal = KErrNoMemory;
       
   320         }
       
   321     return retVal;
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CPslnModel::InvokeSSPluginFunctionL
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 EXPORT_C void CPslnModel::InvokeSSPluginFunctionL(
       
   329     TInt aIndex,
       
   330     TScPluginCaps aFunction )
       
   331     {
       
   332     PSLN_TRACE_DEBUG("CPslnModel::InvokeSSPluginFunctionL");
       
   333     if ( !iScreensaverFilenameArr || iScreensaverFilenameArr->Count() == 0 )
       
   334         {
       
   335         User::Leave( KErrNotFound );
       
   336         }
       
   337 
       
   338     if( aIndex >= iScreensaverFilenameArr->MdcaCount() )
       
   339         {
       
   340         User::Leave( KErrArgument );
       
   341         }
       
   342         
       
   343     if(aFunction == EScpCapsConfigure &&
       
   344        aIndex == GetScreenSaverIndexByFileName(KPslnScreenSaverTypeText))
       
   345         {
       
   346         TBool ret = QueryAndSetScreensaverTextL();
       
   347         if ( !ret )
       
   348             {
       
   349             User::Leave( KErrCancel );
       
   350             }
       
   351         return;
       
   352         }
       
   353 
       
   354     // Convert the UID of the given screensaver plugin from text to integer
       
   355     // The string format of the UID: [12345678]
       
   356     // The number inside the brackets in hexadecimal format
       
   357     TLex lex( iScreensaverFilenameArr->MdcaPoint( aIndex ) );
       
   358     // Skip the first character: '['
       
   359     lex.Get();
       
   360     TUint screenSaverPluginImpUid;
       
   361     // Get the UID
       
   362     TInt err = lex.Val( screenSaverPluginImpUid, EHex );
       
   363     PSLN_TRACE_DEBUG1("CPslnModel::InvokeSSPluginFunctionL lexed: %d", err );
       
   364     User::LeaveIfError( err );
       
   365 
       
   366     if( err == KErrCancel && aIndex == CurrentPropertyIndexL( KPslnScreenSettingId ) )
       
   367         {
       
   368         SetScreenSaverToDefault();
       
   369         }
       
   370     
       
   371     User::LeaveIfError( err );
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CPslnModel::PerformCompleteUpdateL
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 EXPORT_C void CPslnModel::PerformCompleteUpdateL()
       
   379     {
       
   380     PSLN_TRACE_DEBUG("CPslnModel::PerformCompleteUpdateL");
       
   381 
       
   382     if ( iInternalState.IsClear( EPslnModelStateSkinNamesLoaded ) )
       
   383         {
       
   384         LoadSkinNamesResourceL();
       
   385         }
       
   386     UpdateFromServerL();
       
   387     SetActiveSkinL();
       
   388 
       
   389     PSLN_TRACE_DEBUG("CPslnModel::PerformCompleteUpdateL COMPLETED");
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // CPslnModel::LoadScreensaverArrayL
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 EXPORT_C void CPslnModel::LoadScreensaverArrayL()
       
   397     {
       
   398     PSLN_TRACE_DEBUG("CPslnModel::LoadScreensaverArrayL");
       
   399 
       
   400     // Destroy old arrays, if any
       
   401     delete iScreensaverNameArr;
       
   402     iScreensaverNameArr = NULL;
       
   403     delete iScreensaverFilenameArr;
       
   404     iScreensaverFilenameArr = NULL;
       
   405     iScreensaverCapsArr.Reset();
       
   406 
       
   407     // Load default items
       
   408     iScreensaverNameArr = iEikEnv->ReadDesC16ArrayResourceL(
       
   409         R_SCREEN_SAVER_SETTING_PAGE_LBX );
       
   410 
       
   411     // Add descriptors for system screensavers
       
   412     iScreensaverFilenameArr =
       
   413         new (ELeave) CDesC16ArrayFlat( KPslnSsArrayGranularity );
       
   414     iScreensaverFilenameArr->AppendL( KPslnScreenSaverTypeDateTime );
       
   415     iScreensaverFilenameArr->AppendL( KPslnScreenSaverTypeText );
       
   416 
       
   417     // System screensavers have no capabilities
       
   418     User::LeaveIfError( iScreensaverCapsArr.Append( EFalse ) );
       
   419 
       
   420     if ( IsSupportScreenSaverNoneOption() )
       
   421         {
       
   422         iScreensaverFilenameArr->InsertL(0, KPslnScreenSaverTypeNone ); 
       
   423         User::LeaveIfError( iScreensaverCapsArr.Insert( 0, EFalse ) );
       
   424         }
       
   425     else
       
   426         {
       
   427         iScreensaverNameArr->Delete(0);
       
   428         }
       
   429 
       
   430     FindAndAppendScreensaversL();
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CPslnModel::VisibleSkin
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C CPslnSkinEntry* CPslnModel::VisibleSkin( const TInt aIndex )
       
   438     {
       
   439     PSLN_TRACE_DEBUG("CPslnModel::VisibleSkin");
       
   440     if ( !iSkinStore )
       
   441         {
       
   442         TRAPD( err, iSkinStore = CPslnSkinStore::NewL( this ) );
       
   443         if ( err != KErrNone )
       
   444             {
       
   445             return NULL;
       
   446             }
       
   447         }
       
   448     CPslnSkinEntry* visibleSkin = NULL;
       
   449     if ( iVisibleSkinArr )
       
   450         {
       
   451         if( ( aIndex >= 0 ) && ( aIndex < iVisibleSkinArr->Count() ) )
       
   452             {
       
   453             CPslnSkinNameEntry* nameEntry = (*iVisibleSkinArr)[aIndex];
       
   454             visibleSkin = iSkinStore->Find(
       
   455                 nameEntry->PkgID(), nameEntry->Location() );
       
   456             }
       
   457         }
       
   458     return visibleSkin;
       
   459     }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // Get a skin's name by index.
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 EXPORT_C void CPslnModel::GetSkinNameByIndex( const TInt aIndex, TDes& aSkinName,
       
   466     const TPslnSkinNameType aType ) const
       
   467     {
       
   468     PSLN_TRACE_DEBUG("CPslnModel::GetSkinNameByIndex");
       
   469 
       
   470     TAknsPkgID pid = KAknsNullPkgID;
       
   471     if ( iVisibleSkinArr )
       
   472         {
       
   473         if( ( aIndex >= 0 ) && ( aIndex < iVisibleSkinArr->Count() ) )
       
   474             {
       
   475             pid = (*iVisibleSkinArr)[aIndex]->PkgID();
       
   476             }
       
   477         }
       
   478 
       
   479     GetSkinNameByPID( pid, aSkinName, aType );
       
   480     }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // Return if the selected skin is activated.
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 EXPORT_C TBool CPslnModel::IsActiveSkinSelected( TInt aSkinIndex ) const
       
   487     {
       
   488     PSLN_TRACE_DEBUG("CPslnModel::IsActiveOfSkinSelected");
       
   489 
       
   490     TInt skinIndex = iCurrentSkinIndex;
       
   491     if ( aSkinIndex >= 0 )
       
   492         {
       
   493         skinIndex = aSkinIndex;
       
   494         }
       
   495     return ( iActiveSkinIndex == skinIndex );
       
   496     }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CPslnModel::LocationOfSkin
       
   500 // Deprecated.
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 EXPORT_C TAknSkinSrvSkinPackageLocation CPslnModel::LocationOfSkin(
       
   504     const TInt aIndex )
       
   505     {
       
   506     PSLN_TRACE_DEBUG("CPslnModel::LocationOfSkin");
       
   507     TAknSkinSrvSkinPackageLocation skinLocation = EAknsSrvPhone;
       
   508     CPslnSkinEntry* entry = VisibleSkin( aIndex );
       
   509     if( entry )
       
   510         {
       
   511         skinLocation = entry->Location();
       
   512         }
       
   513     return skinLocation;
       
   514     }
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // Return the active skin index.
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 EXPORT_C TInt CPslnModel::ActiveSkinIndex () const
       
   521     {
       
   522     PSLN_TRACE_DEBUG("CPslnModel::ActiveSkinIndex");
       
   523     return iActiveSkinIndex;
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // Return the skin index of the selection currently active.
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 EXPORT_C TInt CPslnModel::CurrentSelectedSkinIndex () const
       
   531     {
       
   532     PSLN_TRACE_DEBUG("CPslnModel::CurrentSelectedSkinIndex");
       
   533     return iCurrentSkinIndex;
       
   534     }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // Get number of skins.
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 EXPORT_C TInt CPslnModel::NumberOfSkins() const
       
   541     {
       
   542     PSLN_TRACE_DEBUG("CPslnModel::NumberOfSkins");
       
   543     TInt numberOfSkins = 0;
       
   544     if ( iVisibleSkinArr )
       
   545         {
       
   546         numberOfSkins = iVisibleSkinArr->Count();
       
   547         }
       
   548     return numberOfSkins;
       
   549     }
       
   550 
       
   551 // ---------------------------------------------------------------------------
       
   552 // CPslnModel::ScreensaverNames
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 EXPORT_C const MDesC16Array& CPslnModel::ScreensaverNames() const
       
   556     {
       
   557     PSLN_TRACE_DEBUG("CPslnModel::ScreensaverNames");
       
   558     return *iScreensaverNameArr;
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // CPslnModel::ScreensaverHasCapability
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 EXPORT_C TBool CPslnModel::ScreensaverHasCapability(
       
   566     const TInt aIndex,
       
   567     const TScPluginCaps aCapability ) const
       
   568     {
       
   569     PSLN_TRACE_DEBUG("CPslnModel::ScreensaverHasCapability");
       
   570     if( ( aIndex < 0 ) || ( aIndex >= iScreensaverCapsArr.Count() ) )
       
   571         {
       
   572         return EFalse;
       
   573         }
       
   574 
       
   575     return ( iScreensaverCapsArr[ aIndex ] & aCapability );
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // CPslnModel::ProtectionOfSkin
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 EXPORT_C TAknsSkinSrvSkinProtectionType CPslnModel::ProtectionOfSkin(
       
   583     const TInt aIndex )
       
   584     {
       
   585     PSLN_TRACE_DEBUG("CPslnModel::ProtectionOfSkin");
       
   586     TAknsSkinSrvSkinProtectionType skinProtectionType = EAknsSrvNoProtection;
       
   587     CPslnSkinEntry* entry = VisibleSkin( aIndex );
       
   588     if( entry )
       
   589         {
       
   590         skinProtectionType = entry->Protection();
       
   591         }
       
   592     return skinProtectionType;
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CPslnModel::IsValidForActivation
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 EXPORT_C TBool CPslnModel::IsValidForActivation( const TInt aItemIndex )
       
   600     {
       
   601     PSLN_TRACE_DEBUG("CPslnModel::IsValidForActivation");
       
   602     CPslnSkinEntry* skinEntry = VisibleSkin( aItemIndex );
       
   603     return ( skinEntry && !skinEntry->IsCorrupted() );
       
   604     }
       
   605 
       
   606 // -----------------------------------------------------------------------------
       
   607 // CPslnModel::IsValidForPreview
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 EXPORT_C TBool CPslnModel::IsValidForPreview( const TInt aItemIndex )
       
   611     {
       
   612     PSLN_TRACE_DEBUG("CPslnModel::IsValidForPreview");
       
   613     CPslnSkinEntry* skinEntry = VisibleSkin( aItemIndex );
       
   614     if( !skinEntry )
       
   615         {
       
   616         return EFalse;
       
   617         }
       
   618         
       
   619     if( skinEntry->IsCorrupted() )
       
   620         {
       
   621         return EFalse;
       
   622         }
       
   623     TInt type = skinEntry->Protection();
       
   624     if( type != EAknsSrvNoProtection && type != EAknsSrvProtected )
       
   625         {
       
   626         return EFalse;
       
   627         }
       
   628         
       
   629     TBool skinFileExist = SkinFileExist( aItemIndex );
       
   630     if( !skinFileExist )
       
   631         {
       
   632         return EFalse;
       
   633         }
       
   634 
       
   635     return ETrue;
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // Checks if the skin support animated background.
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 EXPORT_C TBool CPslnModel::IsSupportAnimBg( TInt aItemIndex )
       
   643     {
       
   644     CPslnSkinEntry* skinEntry = VisibleSkin( aItemIndex );
       
   645     return skinEntry && skinEntry->IsSupportAnimBg();
       
   646     }
       
   647 	
       
   648 // -----------------------------------------------------------------------------
       
   649 // Set current selected skin index.
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 EXPORT_C void CPslnModel::SetCurrentSelectedSkinIndex(
       
   653     const TInt aCurrentSkinIndex )
       
   654     {
       
   655     PSLN_TRACE_DEBUG1("CPslnModel::SetCurrentSelectedSkinIndex:%d", aCurrentSkinIndex );
       
   656     if ( aCurrentSkinIndex >= 0 )
       
   657         {
       
   658         iCurrentSkinIndex = aCurrentSkinIndex;
       
   659         }
       
   660     // If given index is negative, assume that first skin is selected.
       
   661     else
       
   662         {
       
   663         iCurrentSkinIndex = 0;
       
   664         }
       
   665     }
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // CPslnModel::SetCurrentPropertyType
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 EXPORT_C TInt CPslnModel::SetCurrentPropertyType(
       
   672     const TInt /*aProperty*/, const TInt /*aCurItemIndex*/ )
       
   673     {
       
   674     // deprecated.
       
   675     return KErrNotSupported;
       
   676     }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // Get a Skin's Properties Type index.
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 EXPORT_C TInt CPslnModel::CurrentPropertyIndex( const TInt aProperty )
       
   683     {
       
   684     PSLN_TRACE_DEBUG1("CPslnModel::CurrentPropertyIndex:%d", aProperty );
       
   685     TInt currentIndex = KErrNotFound;
       
   686     TRAP_IGNORE( currentIndex = CurrentPropertyIndexL( aProperty ) );
       
   687     PSLN_TRACE_DEBUG1("CPslnModel::CurrentPropertyIndex return:%d", currentIndex );
       
   688     return currentIndex;
       
   689     }
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // Starts to listen for ECOM screensaver changes.
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 EXPORT_C void CPslnModel::EnableScreenSaverNotifications(
       
   696     const TBool& aActive, MPslnScreenSaverECOMObserver& aObserver )
       
   697     {
       
   698     PSLN_TRACE_DEBUG("CPslnModel::EnableScreenSaverNotifications" );
       
   699     if ( aActive )
       
   700         {
       
   701         // Create listening class (active object)
       
   702         TRAP_IGNORE(
       
   703             iScreenSaverListener = CPslnEcomListener::NewL( *this, aObserver ) );
       
   704         }
       
   705     else
       
   706         {
       
   707         // Check if model has already destroyed this.
       
   708         if ( iScreenSaverListener )
       
   709             {
       
   710             if ( iScreenSaverListener->IsActive() )
       
   711                 {
       
   712                 iScreenSaverListener->Cancel();
       
   713                 }
       
   714             delete iScreenSaverListener;
       
   715             iScreenSaverListener = NULL;
       
   716             }
       
   717         }
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // Activates skin. This overloaded version knows in which state the activation 
       
   722 // is requested.
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 EXPORT_C TBool CPslnModel::ActivateSkinL(
       
   726     const TDesC8& /*aPreviewType*/,
       
   727     const TInt /*aActiveSkinIndex*/,
       
   728     const TBool& /*aActivateFromPreview*/ )
       
   729     {
       
   730     PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL -- depricated!!");
       
   731     User::Leave( KErrNotSupported );
       
   732     return EFalse;
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // Activates skin. 
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 EXPORT_C TBool CPslnModel::ActivateSkinL(
       
   740     const TInt aActiveSkinIndex )
       
   741     {
       
   742     PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL");
       
   743 
       
   744     TInt indexToActivate = aActiveSkinIndex;
       
   745     if( aActiveSkinIndex == KErrNotFound )
       
   746         {
       
   747         indexToActivate = iActiveSkinIndex;
       
   748         }
       
   749     PSLN_TRACE_DEBUG1("CPslnModel::ActivateSkinL activate skin index=%d", indexToActivate );
       
   750     // Get skin's full name.
       
   751     HBufC* fullName = HBufC::NewLC( KMaxFileName );
       
   752     TPtr fullNamePtr = fullName->Des();
       
   753     fullNamePtr = GetSkinFullName( indexToActivate );
       
   754 
       
   755     if ( !PslnDiskUtil::QueryAndSetAutomatedL( iSkinSrvSession, fullNamePtr ) )
       
   756         {
       
   757         CleanupStack::PopAndDestroy( fullName );
       
   758         PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL set autom. not ok");
       
   759         return EFalse;
       
   760         }
       
   761     CleanupStack::PopAndDestroy( fullName );
       
   762 
       
   763     // Find out the skin package ID
       
   764     CPslnSkinEntry* activeEntry = VisibleSkin( indexToActivate );
       
   765     if ( !activeEntry )
       
   766         {
       
   767         PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL NULL entry");
       
   768         User::Leave( KErrGeneral );
       
   769         }
       
   770 
       
   771     if ( !activeEntry->IsSupportAnimBg() )
       
   772         {
       
   773         //Stop animated background
       
   774         SetAnimBackground( EPslnDisableAllEffects );
       
   775         }
       
   776     TAknsPkgID activeSkinPid = activeEntry->PkgID();
       
   777     // Activate whole skin
       
   778     PSLN_TRACE_DEBUG("CPslnModel::ActivateSkinL set all definition sets");
       
   779     TInt error = iSkinSrvSession.SetAllDefinitionSets( activeSkinPid );
       
   780     
       
   781     // For enabling first component transition effect
       
   782     GfxTransEffect::Enable();
       
   783     
       
   784     if ( error != KErrNone )
       
   785         {
       
   786         PSLN_TRACE_DEBUG1("CPslnModel::ActivateSkinL error when setting definition sets: %d", error );
       
   787         User::LeaveIfError( error );
       
   788         }
       
   789         
       
   790     // Otherwise, save to shareddata
       
   791     TAknsPkgIDBuf pidBuf;
       
   792     activeSkinPid.CopyToDes( pidBuf );
       
   793 
       
   794     iSkinsRepository->Set(
       
   795         KPslnActiveSkinUid,
       
   796         pidBuf );
       
   797     iSkinsRepository->Set(
       
   798         KPslnActiveSkinLocation,
       
   799         activeEntry->Location() );
       
   800         
       
   801     iActiveSkinIndex = indexToActivate;
       
   802     return ETrue;
       
   803     }
       
   804 
       
   805 // -----------------------------------------------------------------------------
       
   806 // Leaving version of CurrentPropertyIndex.
       
   807 // -----------------------------------------------------------------------------
       
   808 //
       
   809 EXPORT_C TInt CPslnModel::CurrentPropertyIndexL( const TInt aProperty )
       
   810     {
       
   811     PSLN_TRACE_DEBUG1("CPslnModel::CurrentPropertyIndex prop=%d", aProperty );
       
   812 
       
   813     TInt itemIndex = KErrNotFound;
       
   814 
       
   815     switch( aProperty )
       
   816         {
       
   817         case KPslnBgIdleSettingId:
       
   818             {
       
   819             itemIndex = GetWallPaperItemIndex();
       
   820             break;
       
   821             }
       
   822         case KPslnScreenSettingId:
       
   823             {
       
   824             itemIndex = GetScreenSaverItemIndexL();
       
   825             break;
       
   826             }
       
   827         default:
       
   828             break;
       
   829         }
       
   830     return itemIndex;
       
   831     }
       
   832 
       
   833 // -----------------------------------------------------------------------------
       
   834 // Sets transition effects.
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 EXPORT_C TInt CPslnModel::SetTransitionEffectsL( const TInt aEffectValue )
       
   838     {
       
   839     PSLN_TRACE_DEBUG("CPslnModel::SetTransitionEffectsL");
       
   840     TInt retVal = KErrNone;
       
   841 
       
   842     // For the first time only, read default enable mask.
       
   843     if ( iInternalState.IsClear( EPslnModelStateTransitionEnableCRKeyRead ) )
       
   844         {
       
   845         // Initialize to enable all.
       
   846         iEffectsDefaultEnableMask = EPslnEnableAllEffects;
       
   847 
       
   848         retVal = iThemesAppRepository->Get( 
       
   849             KThemesDefaultTransitionEffects, 
       
   850             iEffectsDefaultEnableMask );
       
   851         if ( retVal == KErrNone )
       
   852             {            
       
   853             iInternalState.Set( EPslnModelStateTransitionEnableCRKeyRead );
       
   854             }
       
   855         }
       
   856 
       
   857     // Only accept default mask, zero or max value.
       
   858     if ( aEffectValue != iEffectsDefaultEnableMask && 
       
   859          aEffectValue != EPslnEnableAllEffects &&
       
   860          aEffectValue != EPslnDisableAllEffects )
       
   861         {
       
   862         retVal = KErrArgument;
       
   863         }
       
   864     else
       
   865         {
       
   866         if ( aEffectValue == EPslnEnableAllEffects ||
       
   867              aEffectValue == iEffectsDefaultEnableMask )
       
   868             {
       
   869             TInt freeRAM = 0;
       
   870             HAL::Get( HALData::EMemoryRAMFree, freeRAM );
       
   871             if ( freeRAM < KPslnTransitionEffectRAMThreshold )
       
   872                 {
       
   873                 return KErrNoMemory;
       
   874                 }
       
   875             }
       
   876 
       
   877         // Use mask, if activating effects.
       
   878         TInt effectValue = aEffectValue;
       
   879         if ( aEffectValue != EPslnDisableAllEffects )
       
   880             {
       
   881             effectValue = iEffectsDefaultEnableMask;
       
   882             }
       
   883 
       
   884         iThemesAppRepository->Set( 
       
   885             KThemesTransitionEffects, 
       
   886             effectValue );
       
   887         }
       
   888         
       
   889     // Need to have TFXSrv running before calling enable
       
   890     const TInt KWaitForTFXServerStart( 100000 );
       
   891     User::After( KWaitForTFXServerStart );
       
   892     // For enabling first component transition effect
       
   893     GfxTransEffect::Enable();
       
   894     
       
   895     PSLN_TRACE_DEBUG1("CPslnModel::SetTransitionEffectsL %d", retVal );
       
   896     return retVal;
       
   897     }
       
   898 
       
   899 // -----------------------------------------------------------------------------
       
   900 // Gets current value of transition effects.
       
   901 // -----------------------------------------------------------------------------
       
   902 //
       
   903 EXPORT_C TInt CPslnModel::GetTransitionEffectStateL()
       
   904     {
       
   905     if( PslnFeatures::IsSupported( KPslnSupportFastPreviewTheme ) )
       
   906         {
       
   907         return iTransitionEffectValue;
       
   908         }
       
   909     
       
   910 
       
   911     PSLN_TRACE_DEBUG("CPslnModel::GetTransitionEffectStateL");
       
   912     TInt effectsValue = KErrNone;
       
   913 
       
   914     TInt error = iThemesAppRepository->Get( KThemesTransitionEffects, effectsValue );
       
   915     if ( error != KErrNone || effectsValue < 0 )
       
   916         {
       
   917         PSLN_TRACE_DEBUG2("CPslnModel::GetTransitionEffectStateL Error: %d %d", error, effectsValue );
       
   918         effectsValue = KErrNotFound;
       
   919         }
       
   920 
       
   921     PSLN_TRACE_DEBUG1("CPslnModel::GetTransitionEffectStateL return %d", effectsValue );
       
   922     return effectsValue;
       
   923     }
       
   924 
       
   925 // -----------------------------------------------------------------------------
       
   926 // Get Animated Background state
       
   927 // -----------------------------------------------------------------------------
       
   928 //
       
   929 EXPORT_C TInt CPslnModel::AnimBackgroundState() const
       
   930     {   
       
   931     TInt value = KErrNone;
       
   932     TInt error = iThemesAppRepository->Get( KThemesAnimBackgroundSupport, value );
       
   933     if ( error != KErrNone || value < 0 )
       
   934         {
       
   935         value = KMaxTInt;
       
   936         }
       
   937 
       
   938     return value;
       
   939     }
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // Set Animated Background state
       
   943 // -----------------------------------------------------------------------------
       
   944 //
       
   945 EXPORT_C TInt CPslnModel::SetAnimBackground( TInt aValue )
       
   946     {
       
   947     ASSERT( aValue == EPslnEnableAllEffects ||
       
   948             aValue == EPslnDisableAllEffects );
       
   949     
       
   950     TInt retVal = KErrNone;
       
   951     if ( aValue == EPslnEnableAllEffects )
       
   952         {
       
   953         TInt freeRAM = 0;
       
   954         HAL::Get( HALData::EMemoryRAMFree, freeRAM );
       
   955         if ( freeRAM < KPslnTransitionEffectRAMThreshold )
       
   956             {
       
   957             return KErrNoMemory;
       
   958             }
       
   959         }
       
   960     iThemesAppRepository->Set( KThemesAnimBackgroundSupport, aValue );
       
   961         
       
   962     return retVal;
       
   963     }
       
   964 	
       
   965 // -----------------------------------------------------------------------------
       
   966 // Checks if screensaver is on memory card.
       
   967 // -----------------------------------------------------------------------------
       
   968 //
       
   969 EXPORT_C TBool CPslnModel::IsScreenSaverOnMemoryCard( const TInt aIndex ) const
       
   970     {
       
   971     if ( !iScreensaverFilenameArr || iScreensaverFilenameArr->Count() == 0 )
       
   972         {
       
   973         return EFalse;
       
   974         }
       
   975 
       
   976     TLex lex( iScreensaverFilenameArr->MdcaPoint( aIndex ) );
       
   977     // Skip the first character: '['
       
   978     lex.Get();
       
   979     TUint screenSaverPluginImpUid;
       
   980     TInt currentDrive = EDriveC;
       
   981     // Get the UID
       
   982     lex.Val( screenSaverPluginImpUid, EHex );
       
   983     // Skip character: ']'
       
   984     lex.Get();
       
   985     // Get the drive
       
   986     if ( !lex.Eos() )
       
   987         {
       
   988         // Find out which drive the plugin is on
       
   989         if ( lex.Val( currentDrive ) != KErrNone )
       
   990             {
       
   991             return EFalse;
       
   992             }
       
   993         }
       
   994 #ifndef RD_MULTIPLE_DRIVE
       
   995     if ( currentDrive == EDriveE )
       
   996         {
       
   997         return ETrue;
       
   998         }
       
   999     return EFalse;
       
  1000 #else
       
  1001     RFs& fs = iEikEnv->FsSession();
       
  1002 
       
  1003     TUint driveStatus = 0;
       
  1004     TBool retVal = EFalse;
       
  1005     TInt err = DriveInfo::GetDriveStatus( fs, currentDrive, driveStatus );
       
  1006     if ( driveStatus & DriveInfo::EDriveExternallyMountable &&
       
  1007          driveStatus & DriveInfo::EDriveRemovable )
       
  1008         {
       
  1009         retVal = ETrue;
       
  1010         }
       
  1011     return retVal;
       
  1012 #endif // RD_MULTIPLE_DRIVE
       
  1013     }
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // Sets currently active content (screensaver/wallpaper) index.
       
  1017 // -----------------------------------------------------------------------------
       
  1018 //
       
  1019 EXPORT_C void CPslnModel::SetCurrentPropertyTypeL(
       
  1020     const TInt aProperty, const TInt aCurItemIndex )
       
  1021     {
       
  1022     PSLN_TRACE_DEBUG2("CPslnModel::SetCurrentPropertyTypeL prop=%d index=%d", 
       
  1023         aProperty, aCurItemIndex );
       
  1024 
       
  1025     if( aCurItemIndex < KPslnDefaultItemIndex )
       
  1026         {
       
  1027         User::Leave( KErrArgument );
       
  1028         }
       
  1029 
       
  1030     TInt retVal = KErrNone;
       
  1031     switch( aProperty )
       
  1032         {
       
  1033         case KPslnBgIdleSettingId:
       
  1034             retVal = iSkinsRepository->Set( KPslnWallpaperType, aCurItemIndex );
       
  1035             break;
       
  1036         case KPslnScreenSettingId:
       
  1037             {
       
  1038             TInt screensaverType = GetScreensaverTypeByIndex(aCurItemIndex);
       
  1039             if ( screensaverType == KPslnSsText )
       
  1040                 {
       
  1041                 // Query text if necessary
       
  1042                 TBool ret = QueryAndSetScreensaverTextL();
       
  1043                 if ( !ret )
       
  1044                     {
       
  1045                     User::Leave( KErrCancel );
       
  1046                     }
       
  1047                 }
       
  1048             
       
  1049             break;
       
  1050             }
       
  1051         default:
       
  1052             break;
       
  1053         }
       
  1054     User::LeaveIfError( retVal );
       
  1055     }
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 // Checks if the theme is on memory card.
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 EXPORT_C TBool CPslnModel::IsThemeOnMemoryCard( const TInt& aIndex )
       
  1062     {
       
  1063 #ifndef RD_MULTIPLE_DRIVE
       
  1064     return EFalse;
       
  1065 #else
       
  1066     PSLN_TRACE_DEBUG("CPslnModel::IsThemeOnMemoryCard");
       
  1067     TBool isThemeOnMemoryCard = EFalse;
       
  1068     CPslnSkinEntry* entry = VisibleSkin( aIndex );
       
  1069     if( entry )
       
  1070         {
       
  1071         isThemeOnMemoryCard = entry->IsOnMemoryCard();
       
  1072         }
       
  1073     return isThemeOnMemoryCard;
       
  1074 #endif //RD_MULTIPLE_DRIVE
       
  1075     }
       
  1076 
       
  1077 // -----------------------------------------------------------------------------
       
  1078 // Checks if the theme is on mass memory.
       
  1079 // -----------------------------------------------------------------------------
       
  1080 //
       
  1081 EXPORT_C TBool CPslnModel::IsThemeOnMassDrive( const TInt& aIndex  )
       
  1082     {
       
  1083 #ifndef RD_MULTIPLE_DRIVE
       
  1084     return EFalse;
       
  1085 #else
       
  1086     PSLN_TRACE_DEBUG("CPslnModel::IsThemeOnMassDrive");
       
  1087     TBool isThemeOnMemoryCard = EFalse;
       
  1088     CPslnSkinEntry* entry = VisibleSkin( aIndex );
       
  1089     if( entry )
       
  1090         {
       
  1091         isThemeOnMemoryCard = entry->IsOnMassDrive();
       
  1092         }
       
  1093     return isThemeOnMemoryCard;
       
  1094 #endif //RD_MULTIPLE_DRIVE
       
  1095     }
       
  1096 
       
  1097 // -----------------------------------------------------------------------------
       
  1098 // Checks if the screensaver is on mass memory.
       
  1099 // -----------------------------------------------------------------------------
       
  1100 //
       
  1101 EXPORT_C TBool CPslnModel::IsScreenSaverOnMassDrive( const TInt& aIndex ) const
       
  1102     {
       
  1103 #ifndef RD_MULTIPLE_DRIVE
       
  1104     return EFalse;
       
  1105 #else
       
  1106 
       
  1107     if ( !iScreensaverFilenameArr || iScreensaverFilenameArr->Count() == 0 )
       
  1108         {
       
  1109         return EFalse;
       
  1110         }
       
  1111 
       
  1112     TLex lex( iScreensaverFilenameArr->MdcaPoint( aIndex ) );
       
  1113     // Skip the first character: '['
       
  1114     lex.Get();
       
  1115     TUint screenSaverPluginImpUid;
       
  1116     TInt currentDrive = EDriveC;
       
  1117     // Get the UID
       
  1118     lex.Val( screenSaverPluginImpUid, EHex );
       
  1119     // Skip character: ']'
       
  1120     lex.Get();
       
  1121     // Get the drive
       
  1122     if ( !lex.Eos() )
       
  1123         {
       
  1124         // Find out which drive the plugin is on
       
  1125         if ( lex.Val( currentDrive ) != KErrNone )
       
  1126             {
       
  1127             return EFalse;
       
  1128             }
       
  1129         }
       
  1130 
       
  1131     RFs& fs = iEikEnv->FsSession();
       
  1132 
       
  1133     TUint driveStatus = 0;
       
  1134     TBool retVal = EFalse;
       
  1135     TInt err = DriveInfo::GetDriveStatus( fs, currentDrive, driveStatus );
       
  1136     
       
  1137     // It is mass memory, if it is externally mountable, but not removable.
       
  1138     if ( driveStatus & DriveInfo::EDriveExternallyMountable &&
       
  1139          !( driveStatus & DriveInfo::EDriveRemovable ) )
       
  1140         {
       
  1141         retVal = ETrue;
       
  1142         }
       
  1143     return retVal;
       
  1144 #endif // RD_MULTIPLE_DRIVE
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // Shares skin server session.
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 EXPORT_C RAknsSrvSession CPslnModel::SkinSrvSession() const
       
  1152     { 
       
  1153     return iSkinSrvSession;
       
  1154     }
       
  1155     
       
  1156 // -----------------------------------------------------------------------------
       
  1157 // Starts or stops transition effects.
       
  1158 // -----------------------------------------------------------------------------
       
  1159 //    
       
  1160 EXPORT_C void CPslnModel::TransEffect(TInt aAction) const
       
  1161     {
       
  1162     __ASSERT_DEBUG( EPslnTransitionEffectDummyFirst < aAction && 
       
  1163                     aAction < EPslnTransitionEffectDummyLast,
       
  1164                     User::Panic(_L("Invalid action for CPslnModel::TransEffect"), 1) );
       
  1165                     
       
  1166     switch (aAction)
       
  1167         {
       
  1168         case EPslnTransitionEffectStartPreview:
       
  1169              GfxTransEffect::BeginFullScreen( /*AknTransEffect::EApplicationExit*/1500, TRect(), 
       
  1170                                       AknTransEffect::EParameterType,
       
  1171                                       AknTransEffect::GfxTransParam( KUidPsln ) );    
       
  1172              break;                                               
       
  1173         case EPslnTransitionEffectStartThemeActivation:
       
  1174              GfxTransEffect::BeginFullScreen( /*AknTransEffect::EApplicationExit*/1501, TRect(), 
       
  1175                                       AknTransEffect::EParameterType,
       
  1176                                       AknTransEffect::GfxTransParam( KUidPsln ) );             
       
  1177              break;                                      
       
  1178         
       
  1179         case EPslnTransitionEffectStop:
       
  1180              GfxTransEffect::EndFullScreen(); 
       
  1181              break;            
       
  1182         }
       
  1183     }
       
  1184     
       
  1185 // ---------------------------------------------------------------------------
       
  1186 // Set current screensaver to default screensaver.
       
  1187 // ---------------------------------------------------------------------------
       
  1188 //
       
  1189 EXPORT_C void CPslnModel::SetScreenSaverToDefault()
       
  1190     {
       
  1191     }
       
  1192 
       
  1193 // -----------------------------------------------------------------------------
       
  1194 // CPslnModel::GetSeparatelyLocalizedSkinName
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 TBool CPslnModel::GetSeparatelyLocalizedSkinName(
       
  1198     const TAknsPkgID aPID, TDes& aSkinName,
       
  1199     const TPslnSkinNameType aType ) const
       
  1200     {
       
  1201     PSLN_TRACE_DEBUG("CPslnModel::GetSeparatelyLocalizedSkinName");
       
  1202     TBool retValue = EFalse;
       
  1203     TInt i = KErrNone;
       
  1204     for( ; i < iSkinNames.Count(); i++ )
       
  1205         {
       
  1206         if( iSkinNames[i].iPid == aPID )
       
  1207             {
       
  1208             switch( aType )
       
  1209                 {
       
  1210                 case EPslnSkinNameTypeList:
       
  1211                     aSkinName = *iSkinNames[i].iListName;
       
  1212                     break;
       
  1213                 case EPslnSkinNameTypeTitle:
       
  1214                     aSkinName = *iSkinNames[i].iTitleName;
       
  1215                     break;
       
  1216                 }
       
  1217             retValue = ETrue;
       
  1218             break; // break the for loop
       
  1219             }
       
  1220         }
       
  1221     return retValue;
       
  1222     }
       
  1223 
       
  1224 
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // C++ constructor can NOT contain any code, that might leave.
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 CPslnModel::CPslnModel()
       
  1230     {
       
  1231     PSLN_TRACE_DEBUG("CPslnModel::constructor");
       
  1232     iEikEnv = CEikonEnv::Static();
       
  1233     iActiveSkinIndex = KErrNotFound;
       
  1234     iCurrentSkinIndex = KErrNotFound;
       
  1235     iInternalState.ClearAll();
       
  1236     }
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // Symbian 2nd phase constructor can leave.
       
  1240 // -----------------------------------------------------------------------------
       
  1241 //
       
  1242 void CPslnModel::ConstructL( MAknsSkinChangeObserver* aObserver )
       
  1243     {
       
  1244     PSLN_TRACE_DEBUG("CPslnModel::ConstructL");
       
  1245 
       
  1246     PSLN_TRACE_DEBUG("CPslnModel::ConstructL CenRep");
       
  1247     iSkinsRepository = CRepository::NewL( KCRUidPersonalisation );
       
  1248     iScreenSaverRepository = NULL;
       
  1249     iThemesAppRepository = CRepository::NewL( KCRUidThemes );
       
  1250 
       
  1251     // Connect to skin server.
       
  1252     User::LeaveIfError( iSkinSrvSession.Connect( aObserver ) );
       
  1253     
       
  1254     if( PslnFeatures::IsSupported( KPslnSupportFastPreviewTheme ) )
       
  1255         {
       
  1256         InitTransitionEffectVauleL();
       
  1257         }
       
  1258 
       
  1259     PSLN_TRACE_DEBUG("CPslnModel::ConstructL OK");
       
  1260     }
       
  1261 
       
  1262 // -----------------------------------------------------------------------------
       
  1263 // Loads the skin name resource file
       
  1264 // -----------------------------------------------------------------------------
       
  1265 //
       
  1266 void CPslnModel::LoadSkinNamesResourceL()
       
  1267     {
       
  1268     PSLN_TRACE_DEBUG("CPslnModel::LoadSkinNamesResourceL");
       
  1269     TParse* fp = new (ELeave) TParse;
       
  1270     fp->Set( KPslnSkinNamesFile, &KDC_APP_RESOURCE_DIR, NULL );
       
  1271     TFileName filename = fp->FullName();
       
  1272     delete fp;
       
  1273 
       
  1274     BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), filename );
       
  1275     TResourceReader reader;
       
  1276     TInt resourceFileOffset = iEikEnv->AddResourceFileL( filename );
       
  1277     iEikEnv->CreateResourceReaderLC( reader, R_PSLN_SKINNAME_LIST );
       
  1278 
       
  1279     TInt items = reader.ReadInt16();
       
  1280     for( TInt i = 0; i < items; i++ )
       
  1281         {
       
  1282         TInt pid1 = reader.ReadInt32();
       
  1283         TInt pid2 = reader.ReadInt32();
       
  1284         HBufC16* listname = reader.ReadHBufC16L();
       
  1285         CleanupStack::PushL( listname );
       
  1286         HBufC16* titlename = reader.ReadHBufC16L();
       
  1287         CleanupStack::PushL( titlename );
       
  1288 
       
  1289         TPslnSkinNameEntry entry;
       
  1290         entry.iPid.Set( pid2, pid1 );
       
  1291         entry.iListName = listname;
       
  1292         entry.iTitleName = titlename;
       
  1293         User::LeaveIfError( iSkinNames.Append( entry ) );
       
  1294 
       
  1295         // Title and list name are deleted in the model's destructor.
       
  1296         CleanupStack::Pop( 2, listname ); // titlename, listname
       
  1297         }
       
  1298     CleanupStack::PopAndDestroy(); // reader
       
  1299 
       
  1300     if( resourceFileOffset )
       
  1301         {
       
  1302         iEikEnv->DeleteResourceFile( resourceFileOffset );
       
  1303         }
       
  1304 
       
  1305     iInternalState.Set( EPslnModelStateSkinNamesLoaded );
       
  1306     PSLN_TRACE_DEBUG("CPslnModel::LoadSkinNamesResourceL DONE");
       
  1307     }
       
  1308 
       
  1309 // ---------------------------------------------------------------------------
       
  1310 // CPslnModel::FindAndAppendScreensaversL
       
  1311 // ---------------------------------------------------------------------------
       
  1312 //
       
  1313 TBool CPslnModel::FindAndAppendScreensaversL()
       
  1314     {
       
  1315     PSLN_TRACE_DEBUG("CPslnModel::FindAndAppendScreensaversL");
       
  1316 
       
  1317     TBool found = EFalse;
       
  1318 
       
  1319     RImplInfoPtrArray screenSaverList;
       
  1320     CleanupResetAndDestroyPushL( screenSaverList );
       
  1321 
       
  1322     const TInt ssCount = screenSaverList.Count();
       
  1323 
       
  1324     for( TInt i = 0; i < ssCount; i++ )
       
  1325         {
       
  1326         PSLN_TRACE_DEBUG("CPslnModel::FindAndAppendScreensaversL Plugin found");
       
  1327 
       
  1328         CImplementationInformation* implInfo = screenSaverList[i];
       
  1329 
       
  1330         // The the screensaver ecom plugin implementation UID will be used in place of
       
  1331         // screensaver file name
       
  1332         // The string format of the UID: [12345678]
       
  1333         // The number inside the brackets in hexadecimal format
       
  1334         TUid impUid = implInfo->ImplementationUid();
       
  1335 
       
  1336         // Stash plugin drive number after the UID.
       
  1337         HBufC* ssName = HBufC::NewLC( KMaxUidName + KPslnDriveNumberLength );
       
  1338         TPtr ssNamePtr = ssName->Des();
       
  1339         ssNamePtr = impUid.Name();
       
  1340         ssNamePtr.AppendNum( implInfo->Drive() );
       
  1341 
       
  1342         PSLN_TRACE_DEBUG("CPslnModel::FindAndAppendScreensaversL Getting caps");
       
  1343                 }
       
  1344 
       
  1345     PSLN_TRACE_DEBUG("CPslnModel::FindAndAppendScreensaversL COMPLETED");
       
  1346     CleanupStack::PopAndDestroy( &screenSaverList );
       
  1347     return found;
       
  1348     }
       
  1349 
       
  1350 // ---------------------------------------------------------------------------
       
  1351 // CPslnModel::UpdateFromServerL
       
  1352 // ---------------------------------------------------------------------------
       
  1353 //
       
  1354 void CPslnModel::UpdateFromServerL()
       
  1355     {
       
  1356     PSLN_TRACE_DEBUG("CPslnModel::UpdateFromServerL");
       
  1357     if ( !iSkinStore )
       
  1358         {        
       
  1359         iSkinStore = CPslnSkinStore::NewL( this );
       
  1360         }
       
  1361     iSkinStore->UpdateAllSkinsL( iEikEnv->FsSession() );
       
  1362     UpdateVisibleSkinListL();
       
  1363     }
       
  1364 
       
  1365 // ---------------------------------------------------------------------------
       
  1366 // CPslnModel::UpdateVisibleSkinListL
       
  1367 // ---------------------------------------------------------------------------
       
  1368 //
       
  1369 void CPslnModel::UpdateVisibleSkinListL()
       
  1370     {
       
  1371     PSLN_TRACE_DEBUG("CPslnModel::UpdateVisibleSkinListL");
       
  1372     if( iVisibleSkinArr )
       
  1373         {
       
  1374         iVisibleSkinArr->ResetAndDestroy();
       
  1375         delete iVisibleSkinArr;
       
  1376         iVisibleSkinArr = NULL;
       
  1377         }
       
  1378 
       
  1379     if ( iSkinStore )
       
  1380         {
       
  1381         iVisibleSkinArr = iSkinStore->CreateNameArrayL();
       
  1382         }    
       
  1383     }
       
  1384 
       
  1385 // -----------------------------------------------------------------------------
       
  1386 // CPslnModel::SetActiveSkinL
       
  1387 // -----------------------------------------------------------------------------
       
  1388 //
       
  1389 void CPslnModel::SetActiveSkinL()
       
  1390     {
       
  1391     PSLN_TRACE_DEBUG("CPslnModel::SetActiveSkinL");
       
  1392 
       
  1393     TInt activeSkinLocation = KErrNotFound;
       
  1394 
       
  1395     iSkinsRepository->Get(
       
  1396         KPslnActiveSkinLocation,
       
  1397         activeSkinLocation );
       
  1398 
       
  1399     // If skin is from memory card, check memory card status.
       
  1400     if( activeSkinLocation == EAknsSrvMMC )
       
  1401         {
       
  1402         if( PslnDiskUtil::MmcStatus() < 0 )
       
  1403             {
       
  1404             // If skin is on memory card, and there is access error, 
       
  1405             // activate default skin.
       
  1406             ActivateDefaultSkinL();
       
  1407             return;
       
  1408             }
       
  1409         }
       
  1410 
       
  1411     TAknsPkgIDBuf pidBuf;
       
  1412     iSkinsRepository->Get(
       
  1413         KPslnActiveSkinUid,
       
  1414         pidBuf );
       
  1415 
       
  1416     TAknsPkgID activeSkinPid;
       
  1417     activeSkinPid.SetFromDesL( pidBuf );
       
  1418 
       
  1419     if ( !iVisibleSkinArr )
       
  1420         {
       
  1421         User::Leave( KErrGeneral );
       
  1422         }
       
  1423     TInt activeSkinIndex = KErrNotFound;
       
  1424     for( TInt i = 0; i < iVisibleSkinArr->Count(); i++ )
       
  1425         {
       
  1426         CPslnSkinNameEntry* nameEntry = (*iVisibleSkinArr)[i];
       
  1427         if ( !nameEntry )
       
  1428             {
       
  1429             User::Leave( KErrGeneral );
       
  1430             }
       
  1431         if( ( activeSkinPid == nameEntry->PkgID() ) &&
       
  1432             ( activeSkinLocation == nameEntry->Location() ) )
       
  1433             {
       
  1434             activeSkinIndex = i;
       
  1435             break;
       
  1436             }
       
  1437         }
       
  1438 
       
  1439     if( activeSkinIndex == KErrNotFound )
       
  1440         {
       
  1441         // If the currently active skin no longer exists, activate the default.
       
  1442         ActivateDefaultSkinL();
       
  1443         return;
       
  1444         }
       
  1445 
       
  1446     iActiveSkinIndex = activeSkinIndex;
       
  1447     }
       
  1448 
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // Screen saver text query
       
  1451 // -----------------------------------------------------------------------------
       
  1452 //
       
  1453 TBool CPslnModel::QueryAndSetScreensaverTextL()
       
  1454     {
       
  1455     PSLN_TRACE_DEBUG("CPslnModel::QueryAndSetScreensaverTextL");
       
  1456 
       
  1457     HBufC* displayText = HBufC::NewLC( KPslnMaxNumberOfScreenSaverText );
       
  1458     TPtr txtPtr = displayText->Des();
       
  1459 
       
  1460 
       
  1461     // Just load the default text if nothing was set in the skin settings.
       
  1462     if ( txtPtr.Length() == 0 )
       
  1463         {
       
  1464         GetDefaultTextToScreensaverL( txtPtr );
       
  1465         }
       
  1466 
       
  1467     // Set text to query.
       
  1468     CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(
       
  1469         txtPtr,
       
  1470         CAknQueryDialog::ENoTone );
       
  1471     dlg->SetPredictiveTextInputPermitted( ETrue );
       
  1472 
       
  1473     // If in APAC region, set dialog length dynamically.
       
  1474     if ( PslnFeatures::IsAPACSupported() )
       
  1475         {        
       
  1476         dlg->SetMaxLength( KPslnSsTextDialogAPACMaxLength );
       
  1477         }
       
  1478 
       
  1479     TBool retValue = EFalse;
       
  1480     // Show query for Screen saver txt.
       
  1481     if( dlg->ExecuteLD( R_PSLN_SCREEN_SAVER_TEXT_QUERY_DIALOG ) )
       
  1482         {
       
  1483             retValue = ETrue;
       
  1484         }
       
  1485     CleanupStack::PopAndDestroy( displayText );
       
  1486     return retValue;
       
  1487     }
       
  1488 
       
  1489 
       
  1490 // ---------------------------------------------------------------------------
       
  1491 // CPslnModel::GetSkinFullName
       
  1492 // ---------------------------------------------------------------------------
       
  1493 //
       
  1494 const TDesC& CPslnModel::GetSkinFullName( const TInt aItemIndex )
       
  1495     {
       
  1496     PSLN_TRACE_DEBUG("CPslnModel::GetSkinFullName");
       
  1497     CPslnSkinEntry* skinEntry = VisibleSkin( aItemIndex );
       
  1498     if ( skinEntry )
       
  1499         {
       
  1500         return skinEntry->FullName();
       
  1501         }
       
  1502     return KNullDesC;
       
  1503     }
       
  1504 
       
  1505 // -----------------------------------------------------------------------------
       
  1506 // CPslnModel::GetSkinNameByPID
       
  1507 // -----------------------------------------------------------------------------
       
  1508 //
       
  1509 void CPslnModel::GetSkinNameByPID( const TAknsPkgID aPID, TDes& aSkinName,
       
  1510     const TPslnSkinNameType aType ) const
       
  1511     {
       
  1512     PSLN_TRACE_DEBUG("CPslnModel::GetSkinNameByPID");
       
  1513 
       
  1514     aSkinName = KNullDesC;
       
  1515 
       
  1516     if( GetSeparatelyLocalizedSkinName( aPID, aSkinName, aType ) )
       
  1517         {
       
  1518         return;
       
  1519         }
       
  1520 
       
  1521     if ( iSkinStore )
       
  1522         {
       
  1523         CPslnSkinEntry* entry = iSkinStore->Find( aPID, EAknsSrvAll );
       
  1524         if ( entry )
       
  1525             {
       
  1526             entry->GetName( aSkinName );
       
  1527             }
       
  1528         }
       
  1529     }
       
  1530 
       
  1531 // ---------------------------------------------------------------------------
       
  1532 // CPslnModel::ActivateDefaultSkinL
       
  1533 // ---------------------------------------------------------------------------
       
  1534 //    
       
  1535 void CPslnModel::ActivateDefaultSkinL()
       
  1536     {
       
  1537     PSLN_TRACE_DEBUG("CPslnModel::ActivateDefaultSkinL");
       
  1538     GuardActivationLC();
       
  1539     ActivateSkinL( KPslnSeries60SkinIndex );
       
  1540     CleanupStack::PopAndDestroy(); // activation guard
       
  1541     }
       
  1542 
       
  1543 // ---------------------------------------------------------------------------
       
  1544 // Sets default text to parameter.
       
  1545 // ---------------------------------------------------------------------------
       
  1546 //
       
  1547 void CPslnModel::GetDefaultTextToScreensaverL( TDes& aDisplayText )
       
  1548     {
       
  1549     PSLN_TRACE_DEBUG("CPslnModel::GetDefaultTextToScreensaverL");
       
  1550     HBufC* strBuffer = NULL;
       
  1551     strBuffer = StringLoader::LoadLC( R_PSLN_SCREEN_SAVER_DEFAULT_TEXT );
       
  1552     if ( strBuffer )
       
  1553         {
       
  1554         aDisplayText = strBuffer->Des();
       
  1555         }
       
  1556     CleanupStack::PopAndDestroy( strBuffer );
       
  1557     }
       
  1558 
       
  1559 // ---------------------------------------------------------------------------
       
  1560 // Gets wallpaper item index. Same as above, but can leave.
       
  1561 // ---------------------------------------------------------------------------
       
  1562 //    
       
  1563 TInt CPslnModel::GetWallPaperItemIndex()
       
  1564     {
       
  1565     PSLN_TRACE_DEBUG("CPslnModel::GetWallPaperItemIndexL");
       
  1566     TInt itemIndex = KErrNotFound;
       
  1567 
       
  1568     TInt error = iSkinsRepository->Get( KPslnWallpaperType, itemIndex );
       
  1569     if ( error != KErrNone )
       
  1570         {
       
  1571         itemIndex = KPslnDefaultItemIndex;
       
  1572         }
       
  1573     if ( itemIndex == KPslnDefaultItemIndex )
       
  1574         {
       
  1575         // Verify that key values are coherent.
       
  1576         TFileName wallpaperPath;
       
  1577         error = iSkinsRepository->Get( KPslnIdleBackgroundImagePath, wallpaperPath );
       
  1578         if ( wallpaperPath.Length() > 0 )
       
  1579             {
       
  1580             // Wallpaper image is defined, but type is claimed as None.
       
  1581             // Assume that image is desired.
       
  1582             itemIndex = 1;
       
  1583             }
       
  1584         }
       
  1585 
       
  1586     return itemIndex;
       
  1587     }
       
  1588 
       
  1589 // ---------------------------------------------------------------------------
       
  1590 // Gets screensaver item index. Same as above, but can leave.
       
  1591 // ---------------------------------------------------------------------------
       
  1592 //     
       
  1593 TInt CPslnModel::GetScreenSaverItemIndexL()
       
  1594     {
       
  1595     PSLN_TRACE_DEBUG("CPslnModel::GetScreenSaverItemIndexL");
       
  1596     TInt screenObjectType = KErrNotFound;
       
  1597     TInt error = KErrNone;
       
  1598     
       
  1599     if ( error != KErrNone )
       
  1600         {
       
  1601         return KErrNotFound;
       
  1602         }
       
  1603 
       
  1604     if ( screenObjectType == KPslnSsNone && !IsSupportScreenSaverNoneOption() )
       
  1605         {
       
  1606         //if "none" option is not supported and the settings of cenrep is none
       
  1607         //then change it to the default screen saver - "date".
       
  1608         screenObjectType = KPslnSsDate;
       
  1609         }
       
  1610         
       
  1611     switch ( screenObjectType )
       
  1612         {
       
  1613         case KPslnSsNone:
       
  1614             return GetScreenSaverIndexByFileName(KPslnScreenSaverTypeNone);
       
  1615         case KPslnSsDate:
       
  1616             return GetScreenSaverIndexByFileName(KPslnScreenSaverTypeDateTime);
       
  1617         case KPslnSsText:
       
  1618             return GetScreenSaverIndexByFileName(KPslnScreenSaverTypeText);
       
  1619         case KPslnSsObject:
       
  1620             break;
       
  1621         default:
       
  1622             return KErrNotFound;
       
  1623         }
       
  1624 
       
  1625     TInt itemIndex = KErrNotFound;
       
  1626     HBufC* screenSaverFileName = HBufC::NewLC( KMaxFileName );
       
  1627     TPtr ssFilePtr = screenSaverFileName->Des();
       
  1628 
       
  1629     // Try to look for ']'.
       
  1630     TInt eqPos = ssFilePtr.Find( KPslnScreenSaverUidEndMark );
       
  1631 
       
  1632     // If not found, use the whole string.
       
  1633     if( eqPos == KErrNotFound )
       
  1634         {
       
  1635         eqPos = ssFilePtr.Length();
       
  1636         }
       
  1637     // strip all characters right of it.
       
  1638     ssFilePtr = ssFilePtr.Left( eqPos + 1 );
       
  1639 
       
  1640     if ( error == KErrNone && iScreensaverFilenameArr )
       
  1641         {
       
  1642         // Loop through all the screensavers.
       
  1643         for( TInt i = 0; i < iScreensaverFilenameArr->MdcaCount(); i++ )
       
  1644             {
       
  1645             TPtrC ssNamePtr = GetRealScreenSaverUid( i );
       
  1646             if( ssNamePtr.CompareF( ssFilePtr ) == 0 )
       
  1647                 {
       
  1648                 itemIndex = i;
       
  1649                 break;
       
  1650                 }
       
  1651             }
       
  1652         }
       
  1653     CleanupStack::PopAndDestroy( screenSaverFileName );
       
  1654     return itemIndex;
       
  1655     }
       
  1656 
       
  1657 // ---------------------------------------------------------------------------
       
  1658 // Dynamically loads AknsWallpaperUtils to memory.
       
  1659 // ---------------------------------------------------------------------------
       
  1660 //
       
  1661 void CPslnModel::LoadWallpaperUtilsL()
       
  1662     {
       
  1663     // Wallpaper utils dll loading.
       
  1664     if( iInternalState.IsClear( EPslnModelStateWallpaperDllLoaded ) )
       
  1665         {
       
  1666         PSLN_TRACE_DEBUG("CPslnModel::LoadWallpaperUtilsL about load");
       
  1667         if( iWallpaperDll.Load( KPslnWallpaperUtilsLoaderName ) == KErrNone )
       
  1668             {
       
  1669             PSLN_TRACE_DEBUG("CPslnModel::LoadWallpaperUtilsL loaded");
       
  1670             iInternalState.Set( EPslnModelStateWallpaperDllLoaded );
       
  1671             // Request the entry function
       
  1672             NewWallpaperUtilsL wallpaperUtils =
       
  1673                 (NewWallpaperUtilsL) iWallpaperDll.Lookup( KPslnDllEntryPoint );
       
  1674             if( wallpaperUtils )
       
  1675                 {
       
  1676                 PSLN_TRACE_DEBUG("CPslnModel::LoadWallpaperUtilsL create");
       
  1677                 // Create the class
       
  1678                 iWallpaperSetter =
       
  1679                     (CPslnWallpaperUtilsLoader*) (*wallpaperUtils)();
       
  1680                 }
       
  1681             }
       
  1682         }
       
  1683     if ( !iWallpaperSetter )
       
  1684         {
       
  1685         User::Leave( KErrNotFound );
       
  1686         }
       
  1687     }
       
  1688 
       
  1689 // -----------------------------------------------------------------------------
       
  1690 // This function removes file information from ScreenSaver UID.
       
  1691 // -----------------------------------------------------------------------------
       
  1692 //
       
  1693 TPtrC CPslnModel::GetRealScreenSaverUid( const TInt aIndex )
       
  1694     {
       
  1695     PSLN_TRACE_DEBUG("CPslnModel::GetRealScreenSaverUid");
       
  1696     // Look for ']' - this indicates the end of screensaver UID. 
       
  1697     TInt eqPos = 
       
  1698         iScreensaverFilenameArr->MdcaPoint( aIndex ).Find( 
       
  1699             KPslnScreenSaverUidEndMark );
       
  1700     // If not found, use the whole string.
       
  1701     if( eqPos == KErrNotFound )
       
  1702         {
       
  1703         eqPos = iScreensaverFilenameArr->MdcaPoint( aIndex ).Length();
       
  1704         }
       
  1705     // strip all characters right of it.
       
  1706     return iScreensaverFilenameArr->MdcaPoint( aIndex ).Left( eqPos + 1 );
       
  1707     }
       
  1708 
       
  1709 // -----------------------------------------------------------------------------
       
  1710 // This is leaving version of ActivateScreenSaver.
       
  1711 // -----------------------------------------------------------------------------
       
  1712 //
       
  1713 void CPslnModel::ActivateScreenSaverL( const TInt aItemIndex, 
       
  1714     TPslnScreenSaverActivation aActivationType )
       
  1715     {
       
  1716     PSLN_TRACE_DEBUG("CPslnModel::ActivateScreenSaver");
       
  1717     
       
  1718     if ( aActivationType == EPslnScreenSaverPreviewActivation )
       
  1719         {
       
  1720         // get screen saver type to be previewed
       
  1721         TInt previewSsType = GetScreensaverTypeByIndex( aItemIndex );
       
  1722         if ( previewSsType == KErrNotFound )
       
  1723             {
       
  1724             User::Leave( KErrNotFound );
       
  1725             }
       
  1726 
       
  1727         // create CScreenSaverInfo object to backup the current screensaver settings
       
  1728         if ( !iScreenSaverInfo )
       
  1729             {
       
  1730             iScreenSaverInfo = CPslnScreenSaverInfo::NewL();
       
  1731             }
       
  1732             
       
  1733         //set values to screen saver needed to preview
       
  1734         if ( previewSsType == KPslnSsText )
       
  1735             {
       
  1736             // Load the default text.
       
  1737             if ( iScreenSaverInfo->iScreenSaverTxt->Length() == 0 )
       
  1738                 {
       
  1739                 HBufC* screensaverText = HBufC::NewLC( KPslnMaxNumberOfScreenSaverText );
       
  1740                 TPtr ptr = screensaverText->Des();
       
  1741 
       
  1742                 GetDefaultTextToScreensaverL( ptr );
       
  1743                 CleanupStack::PopAndDestroy(screensaverText);
       
  1744                 }
       
  1745             }
       
  1746         }
       
  1747     else
       
  1748         {
       
  1749         User::Leave( KErrNotSupported );      
       
  1750         }   
       
  1751     }
       
  1752 
       
  1753 // ---------------------------------------------------------------------------
       
  1754 // Dynamically loads browser launcher dll to memory.
       
  1755 // ---------------------------------------------------------------------------
       
  1756 //
       
  1757 void CPslnModel::LoadBrowserLaunchL()
       
  1758     {
       
  1759     // Browser launch dll loading.
       
  1760     if( iInternalState.IsClear( EPslnModelStateBrowserLaunchDllLoaded ) )
       
  1761         {
       
  1762         PSLN_TRACE_DEBUG("CPslnModel::LoadBrowserLaunchL about load");
       
  1763         if( iBrowserLaunchDll.Load( KPslnBrowserLaunchLoaderName ) == KErrNone )
       
  1764             {
       
  1765             PSLN_TRACE_DEBUG("CPslnModel::LoadBrowserLaunchL loaded");
       
  1766             iInternalState.Set( EPslnModelStateBrowserLaunchDllLoaded );
       
  1767             // Request the entry function
       
  1768             NewBrowserLauncherL browserLaucnher =
       
  1769                 (NewBrowserLauncherL) iBrowserLaunchDll.Lookup( KPslnDllEntryPoint );
       
  1770             if( browserLaucnher )
       
  1771                 {
       
  1772                 PSLN_TRACE_DEBUG("CPslnModel::LoadBrowserLaunchL create");
       
  1773                 // Create the class
       
  1774                 iBrowserLauncher =
       
  1775                     (CPslnBrowserLaunchLoader*) (*browserLaucnher)();
       
  1776                 }
       
  1777             }
       
  1778         }
       
  1779     if ( !iBrowserLauncher )
       
  1780         {
       
  1781         User::Leave( KErrNotFound );
       
  1782         }
       
  1783     }
       
  1784     
       
  1785 // -----------------------------------------------------------------------------
       
  1786 // CPslnModel::SkinFileExist
       
  1787 // -----------------------------------------------------------------------------
       
  1788 //
       
  1789 TBool CPslnModel::SkinFileExist( const TInt& aIndex  )
       
  1790     {
       
  1791     if( !IsThemeOnMemoryCard(aIndex) )
       
  1792         {
       
  1793         return ETrue;
       
  1794         }
       
  1795     
       
  1796     TFileName fullname;
       
  1797     fullname = GetSkinFullName( aIndex );
       
  1798     
       
  1799     TInt filehandle = 0;
       
  1800     TInt fileserverhandle = iSkinSrvSession.OpenBitmapFile( fullname, filehandle );
       
  1801 
       
  1802     RFile file;
       
  1803     TInt errorcode = file.AdoptFromServer( fileserverhandle, filehandle );
       
  1804     file.Close();
       
  1805     
       
  1806     if ( errorcode == KErrNone )
       
  1807         {
       
  1808         return ETrue;
       
  1809         }
       
  1810     
       
  1811     return EFalse;
       
  1812     }
       
  1813         
       
  1814 // ---------------------------------------------------------------------------
       
  1815 // Used to notify the client about changes for integer value keys.
       
  1816 // ---------------------------------------------------------------------------
       
  1817 //
       
  1818 void CPslnModel::HandleNotifyInt(TUint32 aId, TInt aNewValue)
       
  1819     {
       
  1820     if( aId == KThemesTransitionEffects )
       
  1821         {
       
  1822         iTransitionEffectValue = aNewValue;
       
  1823         }
       
  1824     }
       
  1825     
       
  1826 // ---------------------------------------------------------------------------
       
  1827 // Gets transition effect value and initialize CenRep notify handler.
       
  1828 // ---------------------------------------------------------------------------
       
  1829 //
       
  1830 void CPslnModel::InitTransitionEffectVauleL()
       
  1831     {
       
  1832     iTransitionEffectValue = KErrNone;
       
  1833 
       
  1834     TInt error = iThemesAppRepository->Get( KThemesTransitionEffects, iTransitionEffectValue );
       
  1835     if ( error != KErrNone || iTransitionEffectValue < 0 )
       
  1836         {
       
  1837         iTransitionEffectValue = KErrNotFound;
       
  1838         }
       
  1839     
       
  1840     iThemesAppCenRepNotifyHandler = 
       
  1841          CCenRepNotifyHandler::NewL(*this, *iThemesAppRepository,
       
  1842             CCenRepNotifyHandler::EIntKey, KThemesTransitionEffects);
       
  1843     iThemesAppCenRepNotifyHandler->StartListeningL();
       
  1844 
       
  1845     }
       
  1846 
       
  1847 // -----------------------------------------------------------------------------
       
  1848 // Get screen saver object type from index.
       
  1849 // -----------------------------------------------------------------------------
       
  1850 //
       
  1851 TInt CPslnModel::GetScreensaverTypeByIndex(TInt aIndex)
       
  1852     {
       
  1853     if(aIndex < 0 || aIndex >= iScreensaverFilenameArr->MdcaCount())
       
  1854         {
       
  1855         return KErrNotFound;
       
  1856         }
       
  1857         
       
  1858     TPtrC ptr = iScreensaverFilenameArr->MdcaPoint(aIndex);
       
  1859     if(ptr.Compare(KPslnScreenSaverTypeNone) == 0)
       
  1860         {
       
  1861         return KPslnSsNone;
       
  1862         }
       
  1863     if(ptr.Compare(KPslnScreenSaverTypeDateTime) == 0)
       
  1864         {
       
  1865         return KPslnSsDate;
       
  1866         }
       
  1867     if(ptr.Compare(KPslnScreenSaverTypeText) == 0)
       
  1868         {
       
  1869         return KPslnSsText;
       
  1870         }
       
  1871     
       
  1872     return KPslnSsObject;
       
  1873     }
       
  1874 
       
  1875 // ---------------------------------------------------------------------------
       
  1876 // Get screensaver item index from filename
       
  1877 // ---------------------------------------------------------------------------
       
  1878 //  
       
  1879 TInt CPslnModel::GetScreenSaverIndexByFileName(const TDesC &aFileName) const
       
  1880     {
       
  1881     for( TInt i = 0; i < iScreensaverFilenameArr->MdcaCount(); i++ )
       
  1882         {
       
  1883         if( aFileName.Compare((*iScreensaverFilenameArr)[i]) == 0 )
       
  1884             {
       
  1885             return i;
       
  1886             }
       
  1887         }
       
  1888     return KErrNotFound;
       
  1889     }
       
  1890 
       
  1891 // ---------------------------------------------------------------------------
       
  1892 // Get if the "None" screen saver is supported.
       
  1893 // ---------------------------------------------------------------------------
       
  1894 //      
       
  1895 TBool CPslnModel::IsSupportScreenSaverNoneOption() const
       
  1896     {
       
  1897     return PslnFeatures::IsSupported( KPslnSupportScreenSaverSupportNoneOption );
       
  1898     }
       
  1899     
       
  1900     
       
  1901 
       
  1902 //  End of File
       
  1903