idlehomescreen/xmluirendering/uiengine/src/xnbackgroundmanager.cpp
branchRCL_3
changeset 23 7be2816dbabd
parent 19 79311d856354
child 26 1b758917cafc
equal deleted inserted replaced
19:79311d856354 23:7be2816dbabd
    33 // SYSTEM INCLUDE FILES
    33 // SYSTEM INCLUDE FILES
    34 #include <gfxtranseffect/gfxtranseffect.h>
    34 #include <gfxtranseffect/gfxtranseffect.h>
    35 #include <akntransitionutils.h>
    35 #include <akntransitionutils.h>
    36 #include <aknlistquerydialog.h> 
    36 #include <aknlistquerydialog.h> 
    37 #include <xnuiengine.rsg>
    37 #include <xnuiengine.rsg>
       
    38 #include <xnwallpaperview.rsg>
    38 #include <AknSkinsInternalCRKeys.h>
    39 #include <AknSkinsInternalCRKeys.h>
    39 #include <activeidle2domaincrkeys.h>
    40 #include <activeidle2domaincrkeys.h>
    40 #include <AknsWallpaperUtils.h>
    41 #include <AknsWallpaperUtils.h>
    41 #include <imageconversion.h>
    42 #include <imageconversion.h>
    42 #include <bitmaptransforms.h>
    43 #include <bitmaptransforms.h>
       
    44 #include <StringLoader.h>
       
    45 #include <aknnotewrappers.h>
       
    46 #include <bautils.h>
    43 
    47 
    44 #include <AknsUtils.h>
    48 #include <AknsUtils.h>
    45 #include <AknsDrawUtils.h>
    49 #include <AknsDrawUtils.h>
    46 #include <AknsControlContext.h>
    50 #include <AknsControlContext.h>
    47 #include <AknsLayeredBackgroundControlContext.h>
    51 #include <AknsLayeredBackgroundControlContext.h>
    52 
    56 
    53 // Constants
    57 // Constants
    54 _LIT8( KSingle, "single" );
    58 _LIT8( KSingle, "single" );
    55 const TUid KDummyUid = { 0x0000000 };
    59 const TUid KDummyUid = { 0x0000000 };
    56 const TInt KSkinGfxInnerRectShrink( 5 );
    60 const TInt KSkinGfxInnerRectShrink( 5 );
    57 const TInt KCallbackDelay( 500000 ); // 500ms
    61 
       
    62 // ============================= LOCAL FUNCTIONS ===============================
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // ShowInfoNoteL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void ShowInfoNoteL( TInt aResourceId )
       
    69     {
       
    70     HBufC* msg( StringLoader::LoadLC( aResourceId ) ); 
       
    71 
       
    72     CAknInformationNote* note = new ( ELeave ) CAknInformationNote;    
       
    73     note->ExecuteLD( *msg );
       
    74                    
       
    75     CleanupStack::PopAndDestroy( msg );                 
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // HandleErrorL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void HandleErrorL( TInt aErr )
       
    83     {
       
    84     TInt resourceId( NULL );
       
    85     if ( aErr == KErrTooBig || aErr == KErrNoMemory )
       
    86         {
       
    87         resourceId = R_QTN_HS_TOO_BIG_IMAGE_NOTE;
       
    88         }
       
    89     else if ( aErr == KErrCancel || aErr == KErrCouldNotConnect || 
       
    90         aErr == KErrCANoRights )
       
    91         {
       
    92         // Ignore these
       
    93         }
       
    94     else if ( aErr != KErrNone )
       
    95         {
       
    96         resourceId = R_QTN_HS_CORRUPTED_IMAGE_NOTE;
       
    97         }
       
    98 
       
    99     if( resourceId )
       
   100         {
       
   101         ShowInfoNoteL( resourceId );
       
   102         }
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CreateSkinBitmapL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CFbsBitmap* CreateSkinBitmapL( TAknsItemID aId, TRect aRect )
       
   110     {
       
   111     CFbsBitmap* newBitmap = new ( ELeave ) CFbsBitmap;
       
   112     User::LeaveIfError( newBitmap->Create( aRect.Size(), EColor16M ) );
       
   113     CleanupStack::PushL( newBitmap );
       
   114             
       
   115     CFbsBitmapDevice* bitmapDev = CFbsBitmapDevice::NewL( newBitmap );
       
   116     CleanupStack::PushL( bitmapDev );
       
   117 
       
   118     CBitmapContext* bc( NULL );
       
   119     User::LeaveIfError( bitmapDev->CreateBitmapContext( bc ) );
       
   120     CleanupStack::PushL( bc );
       
   121 
       
   122     CAknsBasicBackgroundControlContext* context = 
       
   123         CAknsBasicBackgroundControlContext::NewL( aId, aRect, EFalse );
       
   124     CleanupStack::PushL( context );
       
   125 
       
   126     AknsDrawUtils::Background( AknsUtils::SkinInstance(),
       
   127         context, static_cast< CWindowGc& >( *bc ), aRect );
       
   128 
       
   129     CleanupStack::PopAndDestroy( 3, bitmapDev );
       
   130     CleanupStack::Pop( newBitmap );
       
   131     return newBitmap;
       
   132     }
    58 
   133 
    59 // ============================ MEMBER FUNCTIONS ===============================
   134 // ============================ MEMBER FUNCTIONS ===============================
    60 
   135 
    61 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
    62 // C++ default constructor.
   137 // C++ default constructor.
    63 // -----------------------------------------------------------------------------
   138 // -----------------------------------------------------------------------------
    64 //
   139 //
    65 CXnBackgroundManager::CXnBackgroundManager( CXnViewManager& aViewManager, CHspsWrapper& aWrapper )
   140 CXnBackgroundManager::CXnBackgroundManager( CXnViewManager& aViewManager, CHspsWrapper& aWrapper )
    66     : iViewManager( aViewManager ), 
   141     : iViewManager( aViewManager ), 
    67       iHspsWrapper( aWrapper )
   142       iHspsWrapper( aWrapper ),
       
   143       iStoreWallpaper( ETrue )
    68     {
   144     {
    69     }
   145     }
    70 
   146 
    71 // -----------------------------------------------------------------------------
   147 // -----------------------------------------------------------------------------
    72 // Symbian 2nd phase constructor.
   148 // Symbian 2nd phase constructor.
    87     Window().SetOrdinalPosition( -1 );
   163     Window().SetOrdinalPosition( -1 );
    88 
   164 
    89     MakeVisible( ETrue );
   165     MakeVisible( ETrue );
    90     ActivateL();
   166     ActivateL();
    91     iIntUpdate = 0;
   167     iIntUpdate = 0;
       
   168     
    92     User::LeaveIfError( iSkinSrv.Connect( this ) );
   169     User::LeaveIfError( iSkinSrv.Connect( this ) );
    93     iSkinSrv.EnableSkinChangeNotify();  
   170           
    94     
       
    95     // Start listening for drive events.
   171     // Start listening for drive events.
    96     User::LeaveIfError( iFsSession.Connect() );
   172     User::LeaveIfError( iFsSession.Connect() );
    97     
   173     
    98     // Start listening file server notifications.
   174     // Start listening file server notifications.
    99     iDiskNotifier = CDiskNotifyHandler::NewL( *this, iFsSession );
   175     iDiskNotifier = CDiskNotifyHandler::NewL( *this, iFsSession );
   100     User::LeaveIfError( iDiskNotifier->NotifyDisk() );
   176     User::LeaveIfError( iDiskNotifier->NotifyDisk() );
   101     
   177     
   102     // Reads from cenrep wheteher page specific wallpaper is enabled or not
   178     // Reads from cenrep wheteher page specific wallpaper is enabled or not
   103     CheckFeatureTypeL();   
   179     CheckFeatureTypeL();   
   104 
   180     
   105     iTimer = CPeriodic::NewL( CActive::EPriorityIdle );
   181     GfxTransEffect::Register( this, KGfxContextBgAppear );       
   106 
       
   107     GfxTransEffect::Register( this, KGfxContextBgAppear );    
       
   108 
       
   109     iOomSysHandler = CXnOomSysHandler::NewL();
       
   110     }
   182     }
   111 
   183 
   112 // -----------------------------------------------------------------------------
   184 // -----------------------------------------------------------------------------
   113 // Two-phased constructor.
   185 // Two-phased constructor.
   114 // -----------------------------------------------------------------------------
   186 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   130 //
   202 //
   131 CXnBackgroundManager::~CXnBackgroundManager()
   203 CXnBackgroundManager::~CXnBackgroundManager()
   132     {
   204     {
   133     GfxTransEffect::Deregister( this );
   205     GfxTransEffect::Deregister( this );
   134     
   206         
   135     delete iTimer;
   207     iSkinSrv.RemoveAllWallpapers();
   136     CleanCache();
       
   137     iSkinSrv.Close();
   208     iSkinSrv.Close();
   138     delete iDiskNotifier;
   209     delete iDiskNotifier;
   139     iFsSession.Close();
   210     iFsSession.Close();
   140     delete iBgContext;
   211     delete iBgContext;
   141     delete iBgImage;
   212     delete iBgImage;
   142     delete iBgImagePath;
   213     delete iBgImagePath;    
   143     delete iOomSysHandler;
   214     delete iSpBitmap;
   144     delete iSpMask;   
   215     delete iSpMask;   
   145     }
   216     }
   146 
   217 
   147 // -----------------------------------------------------------------------------
   218 // -----------------------------------------------------------------------------
   148 // CXnBackgroundManager::Draw
   219 // CXnBackgroundManager::Draw
   149 // -----------------------------------------------------------------------------
   220 // -----------------------------------------------------------------------------
   150 //    
   221 //    
   151 void CXnBackgroundManager::Draw(const TRect& aRect) const
   222 void CXnBackgroundManager::Draw(const TRect& aRect) const
   152     {
   223     {
   153     CFbsBitmap* wallpaper( NULL );
   224     CFbsBitmap* wallpaper( NULL );
       
   225     
   154     if( iType == EPageSpecific )
   226     if( iType == EPageSpecific )
   155         {
   227         {
   156         CXnViewData& viewData( iViewManager.ActiveViewData() );
   228         CXnViewData& viewData( iViewManager.ActiveViewData() );
   157         wallpaper = viewData.WallpaperImage();
   229         wallpaper = viewData.WallpaperImage();
   158         }
   230         }
   165     if( wallpaper )
   237     if( wallpaper )
   166         {   
   238         {   
   167         TSize bitmapSize = wallpaper->SizeInPixels();
   239         TSize bitmapSize = wallpaper->SizeInPixels();
   168         
   240         
   169         // If image is smaller that screen size it needs to be centralized
   241         // If image is smaller that screen size it needs to be centralized
   170         if( iRect.Height() > bitmapSize.iHeight && iRect.Width() > bitmapSize.iWidth )
   242         if( iRect.Height() > bitmapSize.iHeight && 
       
   243             iRect.Width() > bitmapSize.iWidth )
   171             {
   244             {
   172             TInt width = bitmapSize.iWidth / 2;
   245             TInt width = bitmapSize.iWidth / 2;
   173             TInt height = bitmapSize.iHeight / 2;
   246             TInt height = bitmapSize.iHeight / 2;
   174         
   247         
   175             TPoint point = iRect.Center();
   248             TPoint point = iRect.Center();
   181             }
   254             }
   182         else
   255         else
   183             {
   256             {
   184             SystemGc().DrawBitmap( iRect, wallpaper );
   257             SystemGc().DrawBitmap( iRect, wallpaper );
   185             }
   258             }
       
   259         
   186         DrawStatusPaneMask();
   260         DrawStatusPaneMask();
   187         }
   261         }
   188     
   262     
   189     // Skin bg is used by default
   263     // Skin bg is used by default
   190     else
   264     else
   205 // -----------------------------------------------------------------------------
   279 // -----------------------------------------------------------------------------
   206 // 
   280 // 
   207 void CXnBackgroundManager::SizeChanged()
   281 void CXnBackgroundManager::SizeChanged()
   208     {
   282     {
   209     iRect = Rect();
   283     iRect = Rect();
   210     if( iType == EPageSpecific )
   284     
       
   285     if ( iType == EPageSpecific )
   211         {
   286         {
   212         TRAP_IGNORE( UpdateWallpapersL() );
   287         TRAP_IGNORE( UpdateWallpapersL() );
   213         }
   288         }
   214     else if( iType == ECommon ) 
   289     else if ( iType == ECommon ) 
   215         {
   290         {
   216         if( iBgImagePath )
   291         if( iBgImagePath )
   217             {
   292             {
   218             delete iBgImage;
   293             delete iBgImage;
   219             iBgImage = NULL;
   294             iBgImage = NULL;
   220             TRAP_IGNORE( iBgImage = iSkinSrv.WallpaperImageL( *iBgImagePath ) );
   295             TRAP_IGNORE( iBgImage = iSkinSrv.WallpaperImageL( *iBgImagePath ) );
   221             }
   296             }
   222         }
   297         }
       
   298     
   223     iBgContext->SetRect( iRect );
   299     iBgContext->SetRect( iRect );
   224     
   300     
   225     // create status pane mask image and set size
   301     TRAPD( err, UpdateStatuspaneMaskL() );
   226     if( iSpMask )
   302     if( err )
   227         {
   303         {
       
   304         delete iSpBitmap;
       
   305         iSpBitmap = NULL;
   228         delete iSpMask;
   306         delete iSpMask;
   229         iSpMask = NULL;
   307         iSpMask = NULL;
   230         }
       
   231     
       
   232     TRect spRect;
       
   233     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, spRect );
       
   234     
       
   235     TInt err( KErrNone );    
       
   236     
       
   237     if( Layout_Meta_Data::IsLandscapeOrientation() )
       
   238         {
       
   239         TRAP( err, iSpMask = AknsUtils::CreateBitmapL( AknsUtils::SkinInstance(),
       
   240                 KAknsIIDQgnGrafBgLscTopMaskIcon ) );
       
   241         }
       
   242     else
       
   243         {
       
   244         TRAP( err, iSpMask = AknsUtils::CreateBitmapL( AknsUtils::SkinInstance(),
       
   245                 KAknsIIDQgnGrafBgPrtTopMaskIcon ) );        
       
   246         }
       
   247     
       
   248     if( iSpMask )
       
   249         {
       
   250         AknIconUtils::SetSize( iSpMask, spRect.Size(), EAspectRatioNotPreserved );
       
   251         }
   308         }
   252     }
   309     }
   253 
   310 
   254 // -----------------------------------------------------------------------------
   311 // -----------------------------------------------------------------------------
   255 // CXnBackgroundManager::MakeVisible
   312 // CXnBackgroundManager::MakeVisible
   256 // -----------------------------------------------------------------------------
   313 // -----------------------------------------------------------------------------
   257 // 
   314 // 
   258 void CXnBackgroundManager::MakeVisible( TBool aVisible )
   315 void CXnBackgroundManager::MakeVisible( TBool aVisible )
   259     {    
   316     {    
   260     CCoeControl::MakeVisible( aVisible );
   317     CCoeControl::MakeVisible( aVisible );      
   261     if ( aVisible && iScreenUpdateNeeded )
   318     
   262         {
   319     if ( aVisible )
   263         iScreenUpdateNeeded = EFalse;
   320         {
   264         DrawNow();
   321         DrawNow();
   265         }
   322         }
   266     }
   323     }
   267 
   324 
   268 
       
   269 // -----------------------------------------------------------------------------
   325 // -----------------------------------------------------------------------------
   270 // Handle disk drive notifications.
   326 // Handle disk drive notifications.
   271 // -----------------------------------------------------------------------------
   327 // -----------------------------------------------------------------------------
   272 //
   328 //
   273 void CXnBackgroundManager::HandleNotifyDisk(
   329 void CXnBackgroundManager::HandleNotifyDisk( TInt /*aError*/, 
   274         TInt /*aError*/,
   330     const TDiskEvent& aEvent )              
   275         const TDiskEvent& aEvent )
       
   276     {
   331     {
   277     if( aEvent.iType == MDiskNotifyHandlerCallback::EDiskStatusChanged )
   332     if( aEvent.iType == MDiskNotifyHandlerCallback::EDiskStatusChanged )
   278         {
   333         {
   279         if( !( aEvent.iInfo.iDriveAtt & KDriveAttInternal ) ) 
   334         if( !( aEvent.iInfo.iDriveAtt & KDriveAttInternal ) ) 
   280             {        
   335             {        
   281             TBool diskRemoved( aEvent.iInfo.iType == EMediaNotPresent );
   336             TBool diskRemoved( aEvent.iInfo.iType == EMediaNotPresent );
       
   337             
   282             if( diskRemoved )
   338             if( diskRemoved )
   283                 {
   339                 {
   284                 // TODO:
   340                 TRAP_IGNORE( RemovableDiskRemovedL() );        
   285                 //TRAP_IGNORE( RemovableDiskRemovedL() );
       
   286                 }
   341                 }
   287             else
   342             else
   288                 {
   343                 {
   289                 TRAP_IGNORE( RemovableDiskInsertedL() );        
   344                 TRAP_IGNORE( RemovableDiskInsertedL() );        
   290                 }
   345                 }
   291             }
   346             }
   292         }
   347         }
   293     }
   348     }
   294 
   349 
   295 // -----------------------------------------------------------------------------
   350 // -----------------------------------------------------------------------------
   296 // CXnBackgroundManager::CacheWallpaperL
   351 // CXnBackgroundManager::ConstructWallpaper
   297 // -----------------------------------------------------------------------------
   352 // -----------------------------------------------------------------------------
   298 //
   353 //
   299 TInt CXnBackgroundManager::CacheWallpaperL( const TDesC& aFileName, CXnViewData& aViewData )
   354 TInt CXnBackgroundManager::ConstructWallpaper( const TDesC& aFileName, 
   300     {
   355     CXnViewData& aViewData )
   301     if( aFileName == KNullDesC )
   356     {
   302         {
   357     TRAP_IGNORE( aViewData.SetWallpaperImagePathL( aFileName ) );
   303         return KErrArgument;
       
   304         }
       
   305 
       
   306     aViewData.SetWallpaperImagePathL( aFileName );
       
   307     aViewData.SetWallpaperImage( NULL );
   358     aViewData.SetWallpaperImage( NULL );
   308 
   359 
   309     TBool err( KErrNone );
   360     TRAPD( err, iSkinSrv.AddWallpaperL( aFileName, iRect.Size() ) );
   310     TRAP( err, iSkinSrv.AddWallpaperL( aFileName, iRect.Size() ) );
       
   311     if( err == KErrNone )
   361     if( err == KErrNone )
   312         {    
   362         {
   313         CFbsBitmap* bitmap( NULL );
   363         UpdateViewData( aFileName, aViewData );
   314         CleanupStack::PushL( bitmap );
   364         }  
   315         TRAP( err, bitmap = iSkinSrv.WallpaperImageL( aFileName ) );
   365     
   316         if( err == KErrNone && bitmap )
   366     return err;
   317             {
   367     }
   318             aViewData.SetWallpaperImage( bitmap ); // Ownership tranferred
   368 
   319             }        
   369 // ---------------------------------------------------------------------------
       
   370 // CXnBackgroundManager::SetWallpaperL
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 void CXnBackgroundManager::SetWallpaperL()
       
   374     {
       
   375     TInt selectedIndex( 0 );
       
   376 
       
   377     CAknListQueryDialog* query =
       
   378         new ( ELeave ) CAknListQueryDialog( &selectedIndex );   
       
   379     query->PrepareLC( R_LISTQUERY_CHANGE_WALLPAPER );
       
   380 
       
   381     if ( !query->RunLD() )
       
   382         {
       
   383         // Query canceled
       
   384         return;
       
   385         }
       
   386            
       
   387     CXnAppUiAdapter& appui( iViewManager.AppUiAdapter() );
       
   388     
       
   389     if ( selectedIndex == 0 )
       
   390         {
       
   391         // Set wallpaper to default skin
       
   392         SetWallpaper( KNullDesC );
       
   393         
       
   394         appui.EffectManager()->BgAppearEffect( this, ETrue );        
       
   395         }
       
   396     else if ( selectedIndex == 1 )
       
   397         {
       
   398         if ( CXnOomSysHandler::HeapAvailable( CXnOomSysHandler::EMem6MB ) )
       
   399             {                                      
       
   400             appui.ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KSingle );
       
   401             
       
   402             appui.EffectManager()->BeginFullscreenEffectL( KGfxContextOpenWallpaperView );            
       
   403             }
   320         else
   404         else
   321             {
   405             {
   322             iSkinSrv.RemoveWallpaper( aFileName );
   406             // Potentially not enough memory
   323             }
   407             iViewManager.OomSysHandler().HandlePotentialOomL();        
   324         CleanupStack::Pop();
   408             }
   325         }
   409         }        
   326     return err;
   410     }
   327     }
   411     
   328 
   412 // ---------------------------------------------------------------------------
   329 // ---------------------------------------------------------------------------
   413 // CXnBackgroundManager::SetWallpaper
   330 // CXnBackgroundManager::AddWallpaperL
   414 // ---------------------------------------------------------------------------
   331 // ---------------------------------------------------------------------------
   415 //
   332 //
   416 TBool CXnBackgroundManager::SetWallpaper( const TDesC& aFileName )
   333 TInt CXnBackgroundManager::AddWallpaperL( const TDesC& aFileName )
   417     {
   334     {
   418     TInt err( KErrNone );
   335     TInt retVal( KErrNone );
   419                          
   336     
       
   337     GfxTransEffect::Begin( this, KGfxControlActionAppear );
       
   338                    
       
   339     if ( iType == EPageSpecific )
   420     if ( iType == EPageSpecific )
   340         {
   421         {
   341         retVal = AddPageSpecificWallpaperL( aFileName );
   422         TRAP( err, SetPageSpecificWallpaperL( aFileName ) );
   342         }
   423         }
   343     else if ( iType == ECommon )
   424     else if ( iType == ECommon )
   344         {
   425         {
   345         retVal = AddCommonWallpaperL( aFileName );
   426         TRAP( err, SetCommonWallpaperL( aFileName ) );
   346         }
   427         }
   347     
   428     
   348     GfxTransEffect::SetDemarcation( this, Position() );    
   429     if( err )
   349     GfxTransEffect::End( this );
   430         {
   350     
   431         TRAP_IGNORE( HandleErrorL( err ) );
   351     return retVal;
   432         return EFalse;
       
   433         }
       
   434         
       
   435     return ETrue;
   352     }
   436     }
   353 
   437 
   354 // ---------------------------------------------------------------------------
   438 // ---------------------------------------------------------------------------
   355 // CXnBackgroundManager::DeleteWallpaper
   439 // CXnBackgroundManager::DeleteWallpaper
   356 // ---------------------------------------------------------------------------
   440 // ---------------------------------------------------------------------------
   377             }
   461             }
   378         delete iBgImage;
   462         delete iBgImage;
   379         iBgImage = NULL;
   463         iBgImage = NULL;
   380         }
   464         }
   381     }
   465     }
   382     
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CXnBackgroundManager::ChangeWallpaper
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void CXnBackgroundManager::ChangeWallpaper( const CXnViewData& aOldView, 
       
   472     const CXnViewData& aNewView, TBool aDrawNow )
       
   473     {
       
   474     if( iType == EPageSpecific )
       
   475         {
       
   476         const TDesC& oldwp( aOldView.WallpaperImagePath() );
       
   477         const TDesC& newwp( aNewView.WallpaperImagePath() ); 
       
   478             
       
   479         if ( oldwp.Compare( newwp ) ) 
       
   480             {
       
   481             iStoreWallpaper = ETrue;                    
       
   482             
       
   483             if ( aDrawNow )
       
   484                 {
       
   485                 DrawNow();
       
   486                 }
       
   487             }
       
   488         }
       
   489     }
       
   490 
   383 // ---------------------------------------------------------------------------
   491 // ---------------------------------------------------------------------------
   384 // CXnBackgroundManager::WallpaperType
   492 // CXnBackgroundManager::WallpaperType
   385 // ---------------------------------------------------------------------------
   493 // ---------------------------------------------------------------------------
   386 //
   494 //
   387 CXnBackgroundManager::WppType CXnBackgroundManager::WallpaperType()
   495 CXnBackgroundManager::WppType CXnBackgroundManager::WallpaperType()
   388     {
   496     {
   389     return iType;
   497     return iType;
   390     }
   498     }
   391 
   499 	
   392 // -----------------------------------------------------------------------------
   500 // ---------------------------------------------------------------------------
   393 // CXnBackgroundManager::WallpaperChanged
   501 // CXnBackgroundManager::UpdateViewData
   394 // -----------------------------------------------------------------------------
   502 // ---------------------------------------------------------------------------
   395 //
   503 //
   396 void CXnBackgroundManager::WallpaperChanged( const CXnViewData& aOldView, 
   504 void CXnBackgroundManager::UpdateViewData( const TDesC& aFileName,
   397     const CXnViewData& aNewView )
   505     CXnViewData& aViewData )
   398     {
   506     {
   399     if( iType == EPageSpecific && 
   507     TRAP_IGNORE( aViewData.SetWallpaperImagePathL( aFileName ) );
   400         aOldView.WallpaperImagePath().Compare( aNewView.WallpaperImagePath() ) )
   508     
   401         {
   509     if( aFileName == KNullDesC )
   402         UpdateScreen();
   510         {
   403 
   511         aViewData.SetWallpaperImage( NULL );
   404         // Since AknsWallpaperUtils::SetIdleWallpaper() call is slow, it is called
   512         }
   405         // asynchronously. In that way we can avoid it slowing down page switching.
   513     else
   406         if ( iTimer->IsActive() )
   514         {
   407             {
   515         CFbsBitmap* bitmap( NULL );
   408             iTimer->Cancel();
   516         TRAPD( err, bitmap = iSkinSrv.WallpaperImageL( aFileName ) );
   409             }
   517         if( err == KErrNone && bitmap )
   410         iTimer->Start(KCallbackDelay, KCallbackDelay, TCallBack( TimerCallback, this ) );
   518             {
       
   519             aViewData.SetWallpaperImage( bitmap ); // Ownership tranferred
       
   520             }        
   411         }
   521         }
   412     }
   522     }
   413 
   523 
   414 // ---------------------------------------------------------------------------
   524 // ---------------------------------------------------------------------------
   415 // CXnBackgroundManager::SaveWallpaperL
   525 // CXnBackgroundManager::SaveWallpaperL
   516     
   626     
   517     CleanupStack::PopAndDestroy( pluginConf );
   627     CleanupStack::PopAndDestroy( pluginConf );
   518     
   628     
   519     return ret;
   629     return ret;
   520     }
   630     }
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // CXnBackgroundManager::SetWallpaperL
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 void CXnBackgroundManager::SetWallpaperL()
       
   527     {
       
   528     TInt selectedIndex( 0 );
       
   529 
       
   530     CAknListQueryDialog* query =
       
   531         new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
   532     CleanupStack::PushL( query );
       
   533     query->PrepareLC( R_LISTQUERY_CHANGE_WALLPAPER );
       
   534 
       
   535     if ( query->RunLD() )
       
   536         {
       
   537         if ( selectedIndex == 0 )
       
   538             {
       
   539             AddWallpaperL( KNullDesC );
       
   540             }
       
   541         else if ( selectedIndex == 1 )
       
   542             {
       
   543             if ( CXnOomSysHandler::HeapAvailable( CXnOomSysHandler::EMem6MB ) )
       
   544                 {
       
   545             CXnAppUiAdapter& appui( iViewManager.AppUiAdapter() );
       
   546             
       
   547             appui.EffectManager()->BeginFullscreenEffectL(
       
   548                 KGfxContextOpenWallpaperView, iViewManager.ActiveViewData() );        
       
   549             
       
   550             appui.ActivateLocalViewL( KWallpaperViewUid, KDummyUid, KSingle );                                 
       
   551                 }
       
   552             else
       
   553             	{
       
   554             	OomSysHandler().HandlePotentialOomL();
       
   555             	}
       
   556             }
       
   557         }
       
   558     CleanupStack::Pop( query );
       
   559     }
       
   560     
   631     
   561 // ---------------------------------------------------------------------------
   632 // ---------------------------------------------------------------------------
   562 // CXnBackgroundManager::SkinContentChanged
   633 // CXnBackgroundManager::SkinContentChanged
   563 // ---------------------------------------------------------------------------
   634 // ---------------------------------------------------------------------------
   564 //
   635 //
   565 void CXnBackgroundManager::SkinContentChanged()
   636 void CXnBackgroundManager::SkinContentChanged()
   566     {    
   637     {   
       
   638     TRAPD( err, UpdateStatuspaneMaskL() );
       
   639     if( err )
       
   640         {
       
   641         delete iSpBitmap;
       
   642         iSpBitmap = NULL;
       
   643         delete iSpMask;
       
   644         iSpMask = NULL;
       
   645         }
   567     }
   646     }
   568     
   647     
   569 // ---------------------------------------------------------------------------
   648 // ---------------------------------------------------------------------------
   570 // CXnBackgroundManager::SkinConfigurationChanged
   649 // CXnBackgroundManager::SkinConfigurationChanged
   571 // ---------------------------------------------------------------------------
   650 // ---------------------------------------------------------------------------
   584             TRAP_IGNORE( ReadWallpaperFromCenrepL() );
   663             TRAP_IGNORE( ReadWallpaperFromCenrepL() );
   585             }
   664             }
   586         }
   665         }
   587     else if ( aReason == EAknsSkinStatusConfigurationDeployed )
   666     else if ( aReason == EAknsSkinStatusConfigurationDeployed )
   588         {
   667         {
   589         UpdateScreen();
   668         DrawNow();
   590         }
   669         }
   591     }
   670     }
   592     
   671     
   593 // ---------------------------------------------------------------------------
   672 // ---------------------------------------------------------------------------
   594 // CXnBackgroundManager::SkinPackageChanged
   673 // CXnBackgroundManager::SkinPackageChanged
   598         const TAknsSkinStatusPackageChangeReason /*aReason*/ )
   677         const TAknsSkinStatusPackageChangeReason /*aReason*/ )
   599     {
   678     {
   600     }
   679     }
   601 
   680 
   602 // -----------------------------------------------------------------------------
   681 // -----------------------------------------------------------------------------
   603 // CXnBackgroundManager::CleanCache
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 void CXnBackgroundManager::CleanCache()
       
   607     {
       
   608     iSkinSrv.RemoveAllWallpapers();
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CXnBackgroundManager::RemoveWallpaper
   682 // CXnBackgroundManager::RemoveWallpaper
   613 // -----------------------------------------------------------------------------
   683 // -----------------------------------------------------------------------------
   614 //
   684 //
   615 void CXnBackgroundManager::RemoveWallpaperFromCache( const TDesC& aFileName,
   685 void CXnBackgroundManager::RemoveWallpaperFromCache( const TDesC& aFileName,
   616     CXnViewData* aViewData )
   686     CXnViewData* aViewData )
   617     {
   687     {
       
   688     if( aFileName == KNullDesC )
       
   689         {
       
   690         return;
       
   691         }
       
   692     
   618     CXnViewData* currentViewData( aViewData );
   693     CXnViewData* currentViewData( aViewData );
   619     if( !currentViewData )
   694     if( !currentViewData )
   620         {
   695         {
   621         currentViewData = &iViewManager.ActiveViewData();
   696         currentViewData = &iViewManager.ActiveViewData();
   622         }
   697         }
   640     // Image is not needed anymore. Can be removed from the cache.
   715     // Image is not needed anymore. Can be removed from the cache.
   641     iSkinSrv.RemoveWallpaper( aFileName );  
   716     iSkinSrv.RemoveWallpaper( aFileName );  
   642     }
   717     }
   643 
   718 
   644 // -----------------------------------------------------------------------------
   719 // -----------------------------------------------------------------------------
   645 // CXnBackgroundManager::RemoveWallpaper
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 void CXnBackgroundManager::RemoveWallpaperL( CXnViewData& aViewData )
       
   649     {
       
   650     aViewData.SetWallpaperImagePathL( KNullDesC );
       
   651     aViewData.SetWallpaperImage( NULL );
       
   652     SetSettingPropertyL( aViewData.PluginId(), KWallpaper, KPath, KNullDesC8 );
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CXnBackgroundManager::UpdateWallpapersL
   720 // CXnBackgroundManager::UpdateWallpapersL
   657 // -----------------------------------------------------------------------------
   721 // -----------------------------------------------------------------------------
   658 //
   722 //
   659 void CXnBackgroundManager::UpdateWallpapersL()
   723 void CXnBackgroundManager::UpdateWallpapersL()
   660     {
   724     {
   679             }
   743             }
   680         }
   744         }
   681     }
   745     }
   682 
   746 
   683 // -----------------------------------------------------------------------------
   747 // -----------------------------------------------------------------------------
       
   748 // CXnBackgroundManager::RemovableDiskRemovedL
       
   749 // -----------------------------------------------------------------------------
       
   750 //
       
   751 void CXnBackgroundManager::RemovableDiskRemovedL()
       
   752     {
       
   753     TInt drawingNeeded( EFalse );
       
   754     RFs& fs( CEikonEnv::Static()->FsSession() );
       
   755 
       
   756     if( iType == EPageSpecific )
       
   757         {
       
   758         CXnRootData& rootData = iViewManager.ActiveAppData();
       
   759         if( !&rootData )
       
   760             {
       
   761             return;
       
   762             }
       
   763         RPointerArray<CXnPluginData>& rootDataArr = rootData.PluginData();
       
   764         for( TInt i = 0; i < rootDataArr.Count(); i++ )
       
   765             {
       
   766             CXnViewData* viewData = static_cast<CXnViewData*>( rootDataArr[i] );
       
   767             const TDesC& path = viewData->WallpaperImagePath();
       
   768             CFbsBitmap* bitmap = viewData->WallpaperImage();
       
   769             if( path != KNullDesC && bitmap )
       
   770                 {
       
   771                 if ( !BaflUtils::FileExists( fs, path ) )
       
   772                     {
       
   773                     viewData->SetWallpaperImage( NULL );
       
   774                     if( viewData == &iViewManager.ActiveViewData() )
       
   775                         {
       
   776                         drawingNeeded = ETrue;
       
   777                         }
       
   778                     }
       
   779                 }
       
   780             }
       
   781         }
       
   782     else
       
   783         {
       
   784         if( iBgImagePath && iBgImage )
       
   785             {
       
   786             if ( !BaflUtils::FileExists( fs, *iBgImagePath ) )
       
   787                 {
       
   788                 delete iBgImage;
       
   789                 iBgImage = NULL;
       
   790                 drawingNeeded = ETrue;
       
   791                 }
       
   792             }
       
   793         }
       
   794 
       
   795     if( drawingNeeded )
       
   796         {
       
   797         DrawNow();
       
   798         
       
   799         iIntUpdate++;
       
   800         TInt err = AknsWallpaperUtils::SetIdleWallpaper( KNullDesC , NULL );
       
   801         if( err )
       
   802             {
       
   803             iIntUpdate--;
       
   804             }  
       
   805         }    
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
   684 // CXnBackgroundManager::RemovableDiskInsertedL
   809 // CXnBackgroundManager::RemovableDiskInsertedL
   685 // -----------------------------------------------------------------------------
   810 // -----------------------------------------------------------------------------
   686 //
   811 //
   687 void CXnBackgroundManager::RemovableDiskInsertedL()
   812 void CXnBackgroundManager::RemovableDiskInsertedL()
   688     {
   813     {
       
   814     RFs& fs( CEikonEnv::Static()->FsSession() );
       
   815 
   689     if( iType == EPageSpecific )
   816     if( iType == EPageSpecific )
   690         {
   817         {
   691         CXnRootData& rootData = iViewManager.ActiveAppData();
   818         CXnRootData& rootData = iViewManager.ActiveAppData();
   692         if( !&rootData )
   819         if( !&rootData )
   693             {
   820             {
   700             CXnViewData* viewData = static_cast<CXnViewData*>( rootDataArr[i] );
   827             CXnViewData* viewData = static_cast<CXnViewData*>( rootDataArr[i] );
   701             const TDesC& path = viewData->WallpaperImagePath();
   828             const TDesC& path = viewData->WallpaperImagePath();
   702             CFbsBitmap* bitmap = viewData->WallpaperImage();
   829             CFbsBitmap* bitmap = viewData->WallpaperImage();
   703             if( path != KNullDesC && !bitmap )
   830             if( path != KNullDesC && !bitmap )
   704                 {
   831                 {
   705                 TInt err = CacheWallpaperL( path, *viewData );
   832                 if ( BaflUtils::FileExists( fs, path ) )
   706                 if( err == KErrNone && viewData == &iViewManager.ActiveViewData() )
       
   707                     {
   833                     {
   708                     drawingNeeded = ETrue;
   834                     TInt err = ConstructWallpaper( path, *viewData );
       
   835                     if( err == KErrNone && viewData == &iViewManager.ActiveViewData() )
       
   836                         {
       
   837                         drawingNeeded = ETrue;
       
   838                         }
   709                     }
   839                     }
   710                 }
   840                 }
   711             }
   841             }
   712         if( drawingNeeded )
   842         if( drawingNeeded )
   713             {
   843             {
   714             UpdateScreen();
   844             DrawNow();
   715             
   845             iStoreWallpaper = ETrue;
   716             TInt err = AknsWallpaperUtils::SetIdleWallpaper( 
   846             StoreWallpaperL();
   717                 iViewManager.ActiveViewData().WallpaperImagePath(), NULL );
       
   718             if( err == KErrNone )
       
   719                 {
       
   720                 iIntUpdate++;
       
   721                 }   
       
   722             }    
   847             }    
   723         }
   848         }
   724     else
   849     else
   725         {
   850         {
   726         if( iBgImagePath )
   851         if( iBgImagePath && !iBgImage )
   727             {
   852             {
   728             AddCommonWallpaperL( *iBgImagePath, EFalse );
   853             if ( BaflUtils::FileExists( fs, *iBgImagePath ) )
       
   854                 {
       
   855                 TRAPD( err, SetCommonWallpaperL( *iBgImagePath, EFalse ) );
       
   856                 if( err == KErrCANoRights )
       
   857                     {
       
   858                     ShowInfoNoteL( R_QTN_HS_DRM_PROTECTED_IMAGE_NOTE );
       
   859                     delete iBgImagePath;
       
   860                     iBgImagePath = NULL;
       
   861                     SaveWallpaperL();
       
   862                     }
       
   863                 }
   729             }
   864             }
   730         }
   865         }
   731     }
   866     }
   732 
   867 
   733 // ---------------------------------------------------------------------------
   868 // ---------------------------------------------------------------------------
   748             {
   883             {
   749             iType = EPageSpecific;
   884             iType = EPageSpecific;
   750             }
   885             }
   751         else
   886         else
   752             {
   887             {
       
   888             iStoreWallpaper = EFalse;
       
   889 
   753             TFileName path;
   890             TFileName path;
   754             err = repository->Get( KAIWallpaperPath, path );
   891             err = repository->Get( KAIWallpaperPath, path );
   755             if ( !err && path.Length())
   892             if ( !err && path.Length())
   756                 {
   893                 {
   757                 AddCommonWallpaperL( path, EFalse );
   894                 TRAP_IGNORE( SetCommonWallpaperL( path, EFalse, EFalse ) );
   758                 }
   895                 }
   759             }
   896             }
   760         }
   897         }
   761     CleanupStack::PopAndDestroy( repository );
   898     CleanupStack::PopAndDestroy( repository );
   762     }
   899     }
   763 
   900 
   764 // ---------------------------------------------------------------------------
   901 // ---------------------------------------------------------------------------
   765 // CXnBackgroundManager::AddPageSpecificWallpaperL
   902 // CXnBackgroundManager::SetPageSpecificWallpaperL
   766 // ---------------------------------------------------------------------------
   903 // ---------------------------------------------------------------------------
   767 //
   904 //
   768 TInt CXnBackgroundManager::AddPageSpecificWallpaperL( const TDesC& aFileName )
   905 void CXnBackgroundManager::SetPageSpecificWallpaperL( const TDesC& aFileName )
   769     {
   906     {
   770     TInt err = KErrNone;
       
   771     CXnViewData& viewData( iViewManager.ActiveViewData() );
   907     CXnViewData& viewData( iViewManager.ActiveViewData() );
   772     const TDesC& old = viewData.WallpaperImagePath();
   908 
   773 
   909     TInt err( KErrNone );
   774     // Remove old from the cache
   910     iIntUpdate++;
   775     if( old != KNullDesC )
   911 
   776         {
   912     if(  aFileName == KNullDesC )
   777         RemoveWallpaperFromCache( old );
   913         {
   778         }
   914         err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
   779 
   915         }
   780     // Add new to the cache
       
   781     if( aFileName != KNullDesC )
       
   782         {
       
   783         err = CacheWallpaperL( aFileName, viewData ); 
       
   784     
       
   785         if( err == KErrNone )
       
   786             {
       
   787             SaveWallpaperL(); // to HSPS
       
   788             }
       
   789         else
       
   790             {
       
   791             return err;
       
   792             }
       
   793         }
       
   794     // WallpaperImage changed back to default. Update view data.
       
   795     else
   916     else
   796         {
   917         {
   797         viewData.SetWallpaperImagePathL( KNullDesC );
   918         // Wallpaper is also added into the cache if it is not there already.
   798         viewData.SetWallpaperImage( NULL ); 
   919         err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, CCoeEnv::Static(),
       
   920             R_QTN_HS_PROCESSING_NOTE, R_CHANGE_WALLPAPER_WAIT_DIALOG );    
       
   921         }
       
   922     if( err == KErrNone )
       
   923         {
       
   924         // Remove old wallpaper from the cache
       
   925         const TDesC& oldPath = viewData.WallpaperImagePath();
       
   926         RemoveWallpaperFromCache( oldPath );
       
   927 
       
   928         UpdateViewData( aFileName, viewData );
       
   929 
   799         SaveWallpaperL(); // to HSPS
   930         SaveWallpaperL(); // to HSPS
   800         }
   931         }
   801 
   932     else
       
   933         {
       
   934         iIntUpdate--;
       
   935         User::Leave( err );
       
   936         }
       
   937     }
       
   938         
       
   939 // ---------------------------------------------------------------------------
       
   940 // CXnBackgroundManager::SetCommonWallpaperL
       
   941 // ---------------------------------------------------------------------------
       
   942 //
       
   943 void CXnBackgroundManager::SetCommonWallpaperL( const TDesC& aFileName, 
       
   944     TBool aSave, TBool aShowProgressBar )
       
   945     {
       
   946     TInt err( KErrNone );
       
   947     iIntUpdate++;
       
   948 
       
   949     if(  aFileName == KNullDesC || !aShowProgressBar )
       
   950         {
       
   951         err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
       
   952         }
       
   953     else
       
   954         {
       
   955         // Wallpaper is also added into the cache if it is not there already.
       
   956         err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, CCoeEnv::Static(),
       
   957             R_QTN_HS_PROCESSING_NOTE, R_CHANGE_WALLPAPER_WAIT_DIALOG );    
       
   958         }
       
   959 
       
   960     if( !err )
       
   961         {
       
   962         // Remove old from the cache
       
   963         if( iBgImagePath && iBgImagePath->Compare( aFileName ) )
       
   964             {
       
   965             iSkinSrv.RemoveWallpaper( *iBgImagePath );          
       
   966             delete iBgImagePath;
       
   967             iBgImagePath = NULL;
       
   968             }
       
   969         delete iBgImage;
       
   970         iBgImage = NULL;
       
   971 
       
   972         if( aFileName != KNullDesC )
       
   973             {
       
   974             iBgImagePath = aFileName.AllocL();
       
   975 
       
   976             TRAPD( err, iBgImage = iSkinSrv.WallpaperImageL( aFileName ) );
       
   977             if( err )
       
   978                 {
       
   979                 delete iBgImage;
       
   980                 iBgImage = NULL;
       
   981                 delete iBgImagePath;
       
   982                 iBgImagePath = NULL;
       
   983                 User::Leave( err );
       
   984                 }
       
   985             }    
       
   986         }
       
   987     else
       
   988         {
       
   989         iIntUpdate--;
       
   990         User::Leave( err );
       
   991         }
       
   992     
   802     // Update screen
   993     // Update screen
   803     UpdateScreen();
   994     DrawNow();        
   804     
       
   805     err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
       
   806     if( err == KErrNone )
       
   807         {
       
   808         iIntUpdate++;
       
   809         }
       
   810         
       
   811     return err;
       
   812     }
       
   813         
       
   814 // ---------------------------------------------------------------------------
       
   815 // CXnBackgroundManager::AddCommonWallpaperL
       
   816 // ---------------------------------------------------------------------------
       
   817 //
       
   818 TInt CXnBackgroundManager::AddCommonWallpaperL( const TDesC& aFileName, 
       
   819     TBool aSave )
       
   820     {
       
   821     TInt err = KErrNone;      
       
   822     // Remove old from the cache
       
   823     if( iBgImagePath )
       
   824         {
       
   825         iSkinSrv.RemoveWallpaper( *iBgImagePath );          
       
   826         delete iBgImagePath;
       
   827         iBgImagePath = NULL;
       
   828         }
       
   829     delete iBgImage;
       
   830     iBgImage = NULL;
       
   831 
       
   832     if( aFileName != KNullDesC )
       
   833         {
       
   834         iBgImagePath = aFileName.AllocL();
       
   835     
       
   836         err = KErrNone;
       
   837         TRAP( err, iSkinSrv.AddWallpaperL( aFileName, iRect.Size() ) );
       
   838         if( err != KErrNone )
       
   839             {
       
   840             return err;
       
   841             }
       
   842         
       
   843         TRAP( err, iBgImage = iSkinSrv.WallpaperImageL( aFileName ) );
       
   844         if( err )
       
   845             {
       
   846             iSkinSrv.RemoveWallpaper( aFileName );
       
   847             delete iBgImage;
       
   848             iBgImage = NULL;
       
   849             // image is corrupted or format is not supported
       
   850             return KErrCACorruptContent;
       
   851             }
       
   852         }
       
   853     
       
   854     // Update screen
       
   855     UpdateScreen();        
       
   856 
   995 
   857     // Save path to cenrep
   996     // Save path to cenrep
   858     if( aSave )
   997     if( aSave )
   859         {
   998         {
   860         SaveWallpaperL();
   999         SaveWallpaperL();
   861         }
  1000         }
   862 
       
   863     err = AknsWallpaperUtils::SetIdleWallpaper( aFileName, NULL );
       
   864     if( err == KErrNone )
       
   865         {
       
   866         iIntUpdate++;
       
   867         }
       
   868 
       
   869     return err;
       
   870     }
  1001     }
   871 
  1002 
   872 // ---------------------------------------------------------------------------
  1003 // ---------------------------------------------------------------------------
   873 // CXnBackgroundManager::ReadWallpaperFromCenrepL
  1004 // CXnBackgroundManager::ReadWallpaperFromCenrepL
   874 // ---------------------------------------------------------------------------
  1005 // ---------------------------------------------------------------------------
   881         // Get wallpaper type from cenrep
  1012         // Get wallpaper type from cenrep
   882         TInt wallpaperType;
  1013         TInt wallpaperType;
   883         TInt err = repository->Get( KPslnWallpaperType, wallpaperType );
  1014         TInt err = repository->Get( KPslnWallpaperType, wallpaperType );
   884         if ( err == KErrNone )
  1015         if ( err == KErrNone )
   885             {
  1016             {
   886             if ( wallpaperType == 0 )
  1017             TFileName wallpaper;            
   887                 {
  1018             
   888                 if( iType == EPageSpecific )
  1019             // WallpaperImage is image
       
  1020             // Get wallpaper image path from cenrep
       
  1021             if ( wallpaperType == 1 )
       
  1022                 {
       
  1023                 err = repository->Get( KPslnIdleBackgroundImagePath, wallpaper );
       
  1024                 if ( err != KErrNone )
   889                     {
  1025                     {
   890                     CXnViewData& viewData( iViewManager.ActiveViewData() );
  1026                     return;
   891                     RemoveWallpaperFromCache( viewData.WallpaperImagePath() );
  1027                     }
   892                     RemoveWallpaperL( viewData );                        
  1028                 }
   893                     } 
  1029                 
   894                 else if( iType == ECommon )
  1030             if( iType == EPageSpecific )
       
  1031                 {
       
  1032                 CXnViewData& viewData( iViewManager.ActiveViewData() );
       
  1033                 RemoveWallpaperFromCache( viewData.WallpaperImagePath() );
       
  1034                 viewData.SetWallpaperImagePathL( KNullDesC );
       
  1035                 viewData.SetWallpaperImage( NULL );
       
  1036                 if( wallpaperType == 1 )
   895                     {
  1037                     {
   896                     if( iBgImagePath )
  1038                     UpdateViewData( wallpaper, viewData );
   897                         {
       
   898                         iSkinSrv.RemoveWallpaper( *iBgImagePath );
       
   899                         delete iBgImagePath;
       
   900                         iBgImagePath = NULL;
       
   901                         }
       
   902                     delete iBgImage;
       
   903                     iBgImage = NULL;
       
   904                     SaveWallpaperL();
       
   905                     }
  1039                     }
   906                 }
  1040                 } 
   907             else if ( wallpaperType == 1 )
  1041             else if( iType == ECommon )
   908                 {
  1042                 {
   909                 // WallpaperImage is image
  1043                 if( iBgImagePath )
   910                 // Get wallpaper image path from cenrep and save it
       
   911                 TFileName wallpaper;            
       
   912                 err = repository->Get( KPslnIdleBackgroundImagePath, wallpaper );
       
   913                 if ( err == KErrNone )
       
   914                     {
  1044                     {
   915                     if( iType == EPageSpecific )
  1045                     iSkinSrv.RemoveWallpaper( *iBgImagePath );
   916                         {
  1046                     delete iBgImagePath;
   917                         AddPageSpecificWallpaperL( wallpaper );
  1047                     iBgImagePath = NULL;
   918                         }
  1048                     }
   919                     else if( iType == ECommon )
  1049                 delete iBgImage;
   920                         {
  1050                 iBgImage = NULL;
   921                         AddCommonWallpaperL( wallpaper, EFalse );
  1051                 if( wallpaperType == 1 )
   922                         }
  1052                     {
   923                     }                
  1053                     iBgImagePath = wallpaper.AllocL();                
   924                 }
  1054                     iBgImage = iSkinSrv.WallpaperImageL( wallpaper );
   925             UpdateScreen();
  1055                     }
   926             }
  1056                 }
   927 
  1057             }
   928         CleanupStack::PopAndDestroy( repository );
  1058 
       
  1059         SaveWallpaperL();
       
  1060         DrawNow();
   929         }    
  1061         }    
   930     }
  1062     CleanupStack::PopAndDestroy( repository );
   931 
       
   932 // ---------------------------------------------------------------------------
       
   933 // CXnBackgroundManager::UpdateScreen
       
   934 // ---------------------------------------------------------------------------
       
   935 //
       
   936 void CXnBackgroundManager::UpdateScreen()
       
   937     {
       
   938     if( !IsVisible() )
       
   939         {
       
   940         iScreenUpdateNeeded = ETrue;
       
   941         }
       
   942     else
       
   943         {
       
   944         DrawNow();  
       
   945         }
       
   946     }
  1063     }
   947 
  1064 
   948 // -----------------------------------------------------------------------------
  1065 // -----------------------------------------------------------------------------
   949 // CXnBackgroundManager::DrawEditModeBackgroundSkin
  1066 // CXnBackgroundManager::DrawEditModeBackgroundSkin
   950 // -----------------------------------------------------------------------------
  1067 // -----------------------------------------------------------------------------
   960     AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), SystemGc(), 
  1077     AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), SystemGc(), 
   961             iRect, shrunkRect, KAknsIIDQgnHomeEditBg, KAknsIIDDefault );
  1078             iRect, shrunkRect, KAknsIIDQgnHomeEditBg, KAknsIIDDefault );
   962     }
  1079     }
   963 
  1080 
   964 // -----------------------------------------------------------------------------
  1081 // -----------------------------------------------------------------------------
   965 // CXnBackgroundManager::TimerCallback
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 TInt CXnBackgroundManager::TimerCallback(TAny *aPtr)
       
   969     {
       
   970     CXnBackgroundManager* bgManager = reinterpret_cast<CXnBackgroundManager*>( aPtr );    
       
   971     bgManager->iTimer->Cancel();
       
   972     
       
   973     TInt err = AknsWallpaperUtils::SetIdleWallpaper( bgManager->
       
   974         iViewManager.ActiveViewData().WallpaperImagePath(), NULL );
       
   975     if( err == KErrNone )
       
   976         {
       
   977         bgManager->iIntUpdate++;
       
   978         }   
       
   979     return EFalse;
       
   980     }
       
   981 
       
   982 // -----------------------------------------------------------------------------
       
   983 // CXnBackgroundManager::DrawStatusPaneMask
  1082 // CXnBackgroundManager::DrawStatusPaneMask
   984 // -----------------------------------------------------------------------------
  1083 // -----------------------------------------------------------------------------
   985 //
  1084 //
   986 void CXnBackgroundManager::DrawStatusPaneMask() const
  1085 void CXnBackgroundManager::DrawStatusPaneMask() const
   987     {
  1086     {
   988     if( iSpMask )
  1087     if( iSpBitmap && iSpMask )
   989         {
  1088         {
   990         TSize bmpSize = iSpMask->SizeInPixels();
  1089         TSize bmpSize = iSpMask->SizeInPixels();
   991         TRect spRect( 0, 0, bmpSize.iWidth, bmpSize.iHeight );
  1090         TRect spRect( 0, 0, bmpSize.iWidth, bmpSize.iHeight );
   992         SystemGc().DrawBitmap( spRect, iSpMask );
  1091         SystemGc().DrawBitmapMasked( spRect, iSpBitmap, spRect, iSpMask, ETrue );
   993         }
  1092         }
   994     }
  1093     }
   995 
  1094 
   996 // -----------------------------------------------------------------------------
  1095 // -----------------------------------------------------------------------------
   997 // CXnBackgroundManager::OOMSysHandler
  1096 // CXnBackgroundManager::StoreWallpaperL
   998 // -----------------------------------------------------------------------------
  1097 // -----------------------------------------------------------------------------
   999 //
  1098 //
  1000 CXnOomSysHandler& CXnBackgroundManager::OomSysHandler() const
  1099 void CXnBackgroundManager::StoreWallpaperL()
  1001     {
  1100     {
  1002     __ASSERT_DEBUG( iOomSysHandler , User::Panic( _L("xnbackgroundmanager"), 0 ) );
  1101     if ( iStoreWallpaper )
  1003 
  1102         {   
  1004     return *iOomSysHandler;
  1103         iStoreWallpaper = EFalse;
       
  1104 
       
  1105         CXnViewData& activeView = iViewManager.ActiveViewData();
       
  1106         const TDesC& path( activeView.WallpaperImagePath() );
       
  1107         if( path != KNullDesC && activeView.WallpaperImage() )
       
  1108             {
       
  1109             iIntUpdate++;
       
  1110             TInt err( AknsWallpaperUtils::SetIdleWallpaper( path, NULL ) ); 
       
  1111                   
       
  1112             if( err )
       
  1113                 {
       
  1114                 iIntUpdate--;
       
  1115                 
       
  1116                 if ( err == KErrCANoRights )
       
  1117                     {
       
  1118                     ShowInfoNoteL( R_QTN_HS_DRM_PROTECTED_IMAGE_NOTE );
       
  1119 
       
  1120                     // Change wpp to default
       
  1121                     UpdateViewData( KNullDesC, iViewManager.ActiveViewData() );
       
  1122                     SaveWallpaperL();
       
  1123                     DrawNow();
       
  1124                     }            
       
  1125                 }        
       
  1126             }
       
  1127         else
       
  1128             {
       
  1129             iIntUpdate++;
       
  1130             TInt err( AknsWallpaperUtils::SetIdleWallpaper( KNullDesC, NULL ) ); 
       
  1131             if( err )
       
  1132                 {
       
  1133                 iIntUpdate--;
       
  1134                 }       
       
  1135             }
       
  1136         }       
       
  1137     }
       
  1138 
       
  1139 // -----------------------------------------------------------------------------
       
  1140 // CXnBackgroundManager::UpdateStatuspaneMaskL
       
  1141 // -----------------------------------------------------------------------------
       
  1142 //
       
  1143 void CXnBackgroundManager::UpdateStatuspaneMaskL()
       
  1144     {
       
  1145     if ( iSpBitmap )
       
  1146         {
       
  1147         delete iSpBitmap;
       
  1148         iSpBitmap = NULL;
       
  1149         }
       
  1150     if ( iSpMask )
       
  1151         {
       
  1152         delete iSpMask;
       
  1153         iSpMask = NULL;
       
  1154         }
       
  1155     
       
  1156     TRect spRect;
       
  1157     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EStatusPane, spRect );
       
  1158     
       
  1159     iSpBitmap = CreateSkinBitmapL( KAknsIIDQsnBgScreenIdle, spRect );
       
  1160     
       
  1161     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1162         {
       
  1163         iSpMask = AknsUtils::CreateBitmapL( AknsUtils::SkinInstance(),
       
  1164             KAknsIIDQgnGrafBgLscTopMaskIcon );
       
  1165         }
       
  1166     else
       
  1167         {
       
  1168         iSpMask = AknsUtils::CreateBitmapL( AknsUtils::SkinInstance(),
       
  1169             KAknsIIDQgnGrafBgPrtTopMaskIcon );        
       
  1170         }
       
  1171     
       
  1172     if ( iSpMask )
       
  1173         {
       
  1174         User::LeaveIfError( AknIconUtils::SetSize( 
       
  1175             iSpMask, spRect.Size(), EAspectRatioNotPreserved ) );
       
  1176         }
  1005     }
  1177     }
  1006 
  1178 
  1007 //  End of File
  1179 //  End of File