idlehomescreen/xmluirendering/uiengine/src/xnwallpaperview.cpp
branchRCL_3
changeset 23 7be2816dbabd
parent 19 79311d856354
equal deleted inserted replaced
19:79311d856354 23:7be2816dbabd
    14 * Description:  Wallpaper view.
    14 * Description:  Wallpaper view.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <aknappui.h>
       
    20 #include <eikapp.h>
       
    21 #include <eikbtgpc.h>
    19 #include <eikbtgpc.h>
    22 #include <avkon.rsg>
    20 #include <avkon.rsg>
    23 #include <AknsWallpaperUtils.h>
    21 #include <MGFetch.h> 
    24 #include <MGFetch.h>
       
    25 #include <aknnotewrappers.h>
       
    26 #include <StringLoader.h> 
       
    27 #include <caf/caf.h>
       
    28 #include <bautils.h>
    22 #include <bautils.h>
    29 #include <AknWaitDialog.h>
       
    30 #include <data_caging_path_literals.hrh>
    23 #include <data_caging_path_literals.hrh>
    31 
    24 
    32 // User includes
    25 // User includes
    33 #include <xnwallpaperview.rsg>
    26 #include <xnwallpaperview.rsg>
    34 #include "xnwallpaperview.h"
    27 #include "xnwallpaperview.h"
    35 #include "xnwallpapercontainer.h"
    28 #include "xnwallpapercontainer.h"
    36 #include "xnuiengine.h"
    29 #include "xnuiengine.h"
    37 #include "xnappuiadapter.h"
    30 #include "xnappuiadapter.h"
    38 #include "xnviewadapter.h"
    31 #include "xnviewadapter.h"
    39 #include "xnbackgroundmanager.h"
    32 #include "xnviewmanager.h"
    40 #include "xneffectmanager.h"
    33 #include "xneffectmanager.h"
    41 #include "xnviewmanager.h"
       
    42 #include "xnspbgcleaner.h"
    34 #include "xnspbgcleaner.h"
    43 
    35 
    44 // Constants
    36 // Constants
    45 _LIT( KResourceDrive, "z:" );
    37 _LIT( KResourceDrive, "z:" );
    46 _LIT( KResourceFile, "xnwallpaperview.rsc" );
    38 _LIT( KResourceFile, "xnwallpaperview.rsc" );
    47 
    39 
    48 _LIT8( KMulti, "multi" );
    40 _LIT8( KMulti, "multi" );
       
    41 _LIT8( KSetWallpaper, "setwallpaper" );
    49 
    42 
    50 const TInt KFileArrayGranularity( 6 );
    43 const TInt KFileArrayGranularity( 6 );
    51 const TInt KShortDelay = 1000;
       
    52 const TInt KLongDelay = 1000 * 1000;
       
    53 
    44 
    54 // ============================ MEMBER FUNCTIONS ===============================
    45 // ============================ MEMBER FUNCTIONS ===============================
    55 
    46 
    56 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    57 // C++ default constructor.
    48 // C++ default constructor.
       
    49 //
    58 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    59 //
    51 //
    60 CXnWallpaperView::CXnWallpaperView( CXnUiEngine& aEngine ) 
    52 CXnWallpaperView::CXnWallpaperView( CXnUiEngine& aEngine ) 
    61     : iEngine( aEngine ), iAppUi( iEngine.AppUiAdapter() )    
    53     : iEngine( aEngine ), iAppUi( iEngine.AppUiAdapter() )    
    62     {
    54     {
    63     }
    55     }
    64 
    56 
    65 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    66 // Symbian 2nd phase constructor.
    58 // Symbian 2nd phase constructor.
       
    59 //
    67 // -----------------------------------------------------------------------------
    60 // -----------------------------------------------------------------------------
    68 //
    61 //
    69 void CXnWallpaperView::ConstructL()
    62 void CXnWallpaperView::ConstructL()
    70     {
    63     {
    71     TFileName resFile;
    64     TFileName resFile;
    79 
    72 
    80     iResourceOffset = env->AddResourceFileL( resFile );
    73     iResourceOffset = env->AddResourceFileL( resFile );
    81     
    74     
    82     BaseConstructL( R_WALLPAPER_VIEW );
    75     BaseConstructL( R_WALLPAPER_VIEW );
    83            
    76            
    84     iTimer = CPeriodic::NewL( CActive::EPriorityIdle );
    77     TCallBack cb( HandleCallback, this );
    85     iViewState = EIdle;
    78     
       
    79     iAsyncCb = new ( ELeave ) CAsyncCallBack( cb, CActive::EPriorityHigh );
       
    80     
       
    81     iFiles = new ( ELeave ) CDesCArrayFlat( KFileArrayGranularity );                
    86     }
    82     }
    87 
    83 
    88 // -----------------------------------------------------------------------------
    84 // -----------------------------------------------------------------------------
    89 // Two-phased constructor.
    85 // Two-phased constructor.
       
    86 //
    90 // -----------------------------------------------------------------------------
    87 // -----------------------------------------------------------------------------
    91 //
    88 //
    92 CXnWallpaperView* CXnWallpaperView::NewL( CXnUiEngine& aEngine )
    89 CXnWallpaperView* CXnWallpaperView::NewL( CXnUiEngine& aEngine )
    93     {
    90     {
    94     CXnWallpaperView* self = new (ELeave) CXnWallpaperView( aEngine );
    91     CXnWallpaperView* self = new (ELeave) CXnWallpaperView( aEngine );
    98     return self;
    95     return self;
    99     }
    96     }
   100 
    97 
   101 // -----------------------------------------------------------------------------
    98 // -----------------------------------------------------------------------------
   102 // Destructor.
    99 // Destructor.
       
   100 //
   103 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   104 //
   102 //
   105 CXnWallpaperView::~CXnWallpaperView()
   103 CXnWallpaperView::~CXnWallpaperView()
   106     {
   104     {        
   107     if ( iWaitDialog )
       
   108         {
       
   109         TRAP_IGNORE( iWaitDialog->ProcessFinishedL(); );
       
   110         }
       
   111     
       
   112     CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );    
   105     CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );    
   113     
   106     
       
   107     if ( iFiles )
       
   108         {
       
   109         iFiles->Reset();
       
   110         }
       
   111     
       
   112     delete iFiles;    
   114     delete iContainer;
   113     delete iContainer;
   115     delete iXnSpBgCleaner;
   114     delete iSpBgCleaner;
   116     delete iTimer;
   115     delete iAsyncCb;
   117     }
   116     }
   118 
   117 
   119 // -----------------------------------------------------------------------------
   118 // -----------------------------------------------------------------------------
   120 // CXnWallpaperView::Id
   119 // CXnWallpaperView::Id
       
   120 //
   121 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   122 //
   122 //
   123 TUid CXnWallpaperView::Id() const
   123 TUid CXnWallpaperView::Id() const
   124     {
   124     {
   125     return KWallpaperViewUid;
   125     return KWallpaperViewUid;
   126     }
   126     }
   127 
   127 
   128 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
   129 // CXnWallpaperView::DoActivateL
   129 // CXnWallpaperView::DoActivateL
   130 // -----------------------------------------------------------------------------
   130 //
   131 //
   131 // -----------------------------------------------------------------------------
   132 void CXnWallpaperView::DoActivateL( const TVwsViewId& aPrevViewId,           
   132 //
       
   133 void CXnWallpaperView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,           
   133     TUid /*aCustomMessageId*/, const TDesC8& aCustomMessage )            
   134     TUid /*aCustomMessageId*/, const TDesC8& aCustomMessage )            
   134     {
   135     {
   135     // switch layout 
   136     // switch layout 
   136     CEikStatusPane* sp( iAppUi.StatusPane() );
   137     CEikStatusPane* sp( iAppUi.StatusPane() );
   137     
   138     
   141     sp->ApplyCurrentSettingsL();
   142     sp->ApplyCurrentSettingsL();
   142     // disable transparancy
   143     // disable transparancy
   143     sp->EnableTransparent( EFalse );
   144     sp->EnableTransparent( EFalse );
   144     
   145     
   145     // create background cleaner for sp
   146     // create background cleaner for sp
   146     if ( !iXnSpBgCleaner )
   147     if ( !iSpBgCleaner )
   147         {
   148         {
   148         iXnSpBgCleaner = CXnSpBgCleaner::NewL();
   149         iSpBgCleaner = CXnSpBgCleaner::NewL();
   149         AppUi()->AddToStackL( *this, iXnSpBgCleaner );
   150         AppUi()->AddToStackL( *this, iSpBgCleaner );
   150         }
   151         }
   151 
   152 
   152     // update sp
   153     // update sp
   153     iXnSpBgCleaner->DrawNow();
   154     iSpBgCleaner->DrawNow();
   154     sp->DrawNow();
   155     sp->DrawNow();
   155     
   156     
   156     // update cba
   157     // update cba
   157     CEikButtonGroupContainer* bgc( Cba() );
   158     CEikButtonGroupContainer* bgc( Cba() );
   158     CEikCba* cba = static_cast< CEikCba* >( bgc->ButtonGroup() );
   159     CEikCba* cba = static_cast< CEikCba* >( bgc->ButtonGroup() );
   168         iContainer = CXnWallpaperContainer::NewL();
   169         iContainer = CXnWallpaperContainer::NewL();
   169         iAppUi.AddToStackL( *this, iContainer );
   170         iAppUi.AddToStackL( *this, iContainer );
   170         iContainer->ActivateL();
   171         iContainer->ActivateL();
   171         iContainer->DrawNow();
   172         iContainer->DrawNow();
   172         }
   173         }
   173     
   174       
   174     iPreviousViewUid = aPrevViewId;
   175     iAppUi.EffectManager()->EndFullscreenEffect( KGfxContextOpenWallpaperView );
   175     iMultiple = ( (aCustomMessage == KMulti) ? ETrue : EFalse );
   176     
   176 
   177     iMultiple = ( aCustomMessage == KMulti ) ? ETrue : EFalse;
   177     iAppUi.EffectManager()->UiRendered();
   178            
   178     
   179     // Run image selection dialog asynchronously    
   179     iWaitDialog = NULL;
   180     iAsyncCb->CallBack();
   180     iViewState = EImageSelection;
   181     }
   181 
   182 
   182     // Run image selection dialog asynchronously
   183 // -----------------------------------------------------------------------------
   183     iTimer->Cancel();
   184 // CXnWallpaperView::DoDeactivate
   184     iTimer->Start( KShortDelay, KLongDelay, TCallBack( TimerCallback, this ) );
   185 //
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CXnWallpaperView::DoActivateL
       
   189 // -----------------------------------------------------------------------------
   186 // -----------------------------------------------------------------------------
   190 //
   187 //
   191 void CXnWallpaperView::DoDeactivate()
   188 void CXnWallpaperView::DoDeactivate()
   192     {
   189     {       
   193     iTimer->Cancel(); // cancel timer
       
   194     
       
   195     if ( iWaitDialog )
       
   196         {
       
   197         TRAP_IGNORE( iWaitDialog->ProcessFinishedL(); );
       
   198         }
       
   199     
       
   200     if ( iContainer )
   190     if ( iContainer )
   201         {
   191         {
   202         iAppUi.RemoveFromStack( iContainer );
   192         iAppUi.RemoveFromStack( iContainer );
   203         delete iContainer;
   193         delete iContainer;
   204         iContainer = NULL;
   194         iContainer = NULL;
   205         }
   195         }
   206     
   196     
   207     if ( iXnSpBgCleaner )
   197     if ( iSpBgCleaner )
   208         {
   198         {
   209         AppUi()->RemoveFromStack( iXnSpBgCleaner );
   199         AppUi()->RemoveFromStack( iSpBgCleaner );
   210         delete iXnSpBgCleaner;
   200         delete iSpBgCleaner;
   211         iXnSpBgCleaner = NULL;
   201         iSpBgCleaner = NULL;
   212         }
   202         }
   213     
   203     
   214     iViewState = EIdle;
   204     iAppUi.EffectManager()->EndFullscreenEffect( KGfxContextCloseWallpaperView );
   215     iAppUi.EffectManager()->UiRendered();
   205     }
   216     }
   206 
   217 
   207 // -----------------------------------------------------------------------------
   218 // -----------------------------------------------------------------------------
   208 // CXnWallpaperView::SelectedWallpaper
   219 // CXnWallpaperView::TimerCallback
   209 //
   220 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   221 //
   211 //
   222 TInt CXnWallpaperView::TimerCallback( TAny *aPtr )
   212 void CXnWallpaperView::SelectedWallpaper( TFileName& aFileName ) const
       
   213     {
       
   214     aFileName.Copy( iFileName );       
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CXnWallpaperView::HandleCallback
       
   219 //
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TInt CXnWallpaperView::HandleCallback( TAny* aAny )
   223     {       
   223     {       
   224     CXnWallpaperView* self = reinterpret_cast< CXnWallpaperView* >( aPtr );
   224     CXnWallpaperView* self = static_cast< CXnWallpaperView* >( aAny );
   225     TRAPD( err, self->DoHandleCallBackL(); );    
   225           
   226     if ( KErrNone != err )
   226     TRAP_IGNORE( self->DoHandleCallbackL() );
   227         {
   227     
   228         // activate default view in case of any error
   228     return KErrNone;
   229         TVwsViewId defaultView;
   229     }
   230         if ( self->iAppUi.GetDefaultViewId( defaultView ) != KErrNone )
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CXnWallpaperView::DoHandleCallbackL
       
   233 //
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CXnWallpaperView::DoHandleCallbackL()
       
   237     {    
       
   238     // Reset 
       
   239     iFileName = KNullDesC();    
       
   240     iFiles->Reset();
       
   241         
       
   242     TBool selected( EFalse );
       
   243                    
       
   244     TRAP_IGNORE( selected = 
       
   245         MGFetch::RunL( *iFiles, EImageFile, iMultiple ) ); 
       
   246             
       
   247     if ( selected && iFiles->MdcaCount() > 0 )                 
       
   248         {
       
   249         // Reset
       
   250         selected = EFalse;
       
   251                 
       
   252         if( iFiles->MdcaCount() == 1 )
   231             {
   253             {
   232             // use default if we got wrong viewid as previous view
   254             TPtrC fileName( iFiles->MdcaPoint( 0 ) );
   233             defaultView.iAppUid = self->iAppUi.Application()->AppDllUid();
   255                             
   234             defaultView.iViewUid = TUid::Uid( 1 );
   256             RFs& fs( CEikonEnv::Static()->FsSession() );
   235             }        
   257             
   236         // try activating default view
   258             if ( BaflUtils::FileExists( fs, fileName ) )
   237         TRAP_IGNORE( self->iAppUi.ActivateViewL( defaultView ); );
       
   238         }
       
   239     return KErrNone;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CXnWallpaperView::DoHandleCallBackL
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CXnWallpaperView::DoHandleCallBackL()
       
   247     {
       
   248     iTimer->Cancel();
       
   249     
       
   250     if ( iViewState == EImageSelection )
       
   251         {
       
   252         CDesCArrayFlat* files = 
       
   253                 new (ELeave) CDesCArrayFlat( KFileArrayGranularity );    
       
   254         CleanupStack::PushL( files );
       
   255     
       
   256         TInt err( KErrNone );
       
   257         TBool selected( EFalse );
       
   258         
       
   259         CXnBackgroundManager& bg( iAppUi.ViewAdapter().BgManager() );
       
   260         
       
   261         selected = MGFetch::RunL( *files, EImageFile, iMultiple );
       
   262         
       
   263         if ( selected && files->MdcaCount() > 0 )                 
       
   264             {
       
   265             // set wallpaper
       
   266             if( files->MdcaCount() == 1 )
       
   267                 {
   259                 {
   268                 TFileName fileName( files->MdcaPoint( 0 ) );
   260                 // Accept the selected file
   269                 RFs& fs = CEikonEnv::Static()->FsSession();
   261                 selected = ETrue;
   270                 if ( BaflUtils::FileExists( fs, fileName ) )
   262                 iFileName.Copy( fileName );
   271                     {
       
   272                     // if wallpaper adding will take more than 1,5 sec waitdlg will appear
       
   273                     iWaitDialog = new( ELeave ) CAknWaitDialog(
       
   274                             reinterpret_cast<CEikDialog**>( &iWaitDialog ), EFalse );
       
   275                     iWaitDialog->ExecuteLD( R_CHANGE_WALLPAPER_WAIT_DIALOG );
       
   276                     
       
   277                     // add wallpaper
       
   278                     err = bg.AddWallpaperL( fileName );
       
   279     
       
   280                     // notify waitdlg we're done.     
       
   281                     iWaitDialog->ProcessFinishedL();
       
   282                     // ProcessFinishedL() will NULL iWaitDialog
       
   283                     }
       
   284                 }
   263                 }
   285             }
   264             }
   286         
   265         
   287         CleanupStack::PopAndDestroy( files );
   266         iFiles->Reset();
   288         
   267         }       
   289         if( err == KErrTooBig || err == KErrNoMemory )
   268     
   290             {
   269     // Default view
   291             ShowErrorDialogL( R_QTN_HS_TOO_BIG_IMAGE_NOTE );
   270     TVwsViewId xmlViewId( iAppUi.View().ViewId() );
   292             }
   271     
   293         else if( err == KErrCancel || err == KErrCouldNotConnect )
   272     const TDesC8& param( selected ? KSetWallpaper() : KNullDesC8() );
   294             {
   273     
   295             // Ignore these.
   274     iAppUi.EffectManager()->BeginFullscreenEffectL( KGfxContextCloseWallpaperView );
   296             }
   275     
   297         else if( err != KErrNone )
   276     iAppUi.ActivateLocalViewL( xmlViewId.iViewUid, TUid(), param );                         
   298             {
   277     }
   299             ShowErrorDialogL( R_QTN_HS_CORRUPTED_IMAGE_NOTE );        
       
   300             }
       
   301         
       
   302         // restart timer to deactivate view. View activation fails if
       
   303         // any dialog was shown just before calling iAppUi.ActivateViewL
       
   304         // specially when theme effects are on.
       
   305         iViewState = EViewDeactivation;
       
   306         iTimer->Start( KLongDelay, KLongDelay, TCallBack( TimerCallback, this ) );
       
   307         }
       
   308     else if ( iViewState == EViewDeactivation )
       
   309         {        
       
   310         iAppUi.EffectManager()->BeginFullscreenEffectL( 
       
   311                                     KGfxContextCloseWallpaperView, 
       
   312                                     iAppUi.ViewManager().ActiveViewData() );
       
   313         iAppUi.ActivateViewL( iPreviousViewUid );
       
   314         }
       
   315     else
       
   316         {
       
   317         iViewState = EIdle;
       
   318         User::Leave( KErrUnknown );
       
   319         }
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CXnWallpaperView::ShowErrorDialogL
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 void CXnWallpaperView::ShowErrorDialogL( const TInt aResourceId )
       
   327     {
       
   328     //load message text
       
   329     HBufC* msg = StringLoader::LoadLC( aResourceId );
       
   330     //ensure that dialog will not disappear immediatelly - by const. param
       
   331     CAknErrorNote* dialog = new (ELeave) CAknErrorNote( true );
       
   332     CleanupStack::PushL( dialog );
       
   333     //show dialog to user and destroy it
       
   334     dialog->ExecuteLD( *msg );
       
   335     CleanupStack::Pop( dialog );
       
   336     CleanupStack::PopAndDestroy( msg );
       
   337     }
       
   338 
       
   339 
   278 
   340 //  End of File
   279 //  End of File