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