psln/Src/PslnScreenSaverView.cpp
changeset 0 2f259fa3e83a
child 14 3320e4e6e8bb
child 18 0aa5fbdfbc30
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Screen saver view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // RProperty keys.
       
    22 #include <e32cmn.h>
       
    23 #include <e32def.h>
       
    24 #include <ScreensaverInternalPSKeys.h>
       
    25 #include <ScreensaverInternalCRKeys.h>
       
    26 
       
    27 // Central repository.
       
    28 #include <centralrepository.h>
       
    29 #include <cenrepnotifyhandler.h>
       
    30 
       
    31 // AVKON services.
       
    32 #include <AknWaitDialog.h>
       
    33 #include <aknnotewrappers.h>
       
    34 #include <avkon.hrh>
       
    35 #include <StringLoader.h>
       
    36 #include <eikmenup.h>
       
    37 
       
    38 // Power save mode setting
       
    39 #include <psmsettings.h>
       
    40 
       
    41 // Psln specific.
       
    42 #include <psln.rsg>
       
    43 #include "PslnModel.h"
       
    44 #include "PslnScreenSaverView.h"
       
    45 #include "PslnScreenSaverContainer.h"
       
    46 #include "PslnConst.h"
       
    47 #include "PslnUi.h"
       
    48 
       
    49 // CONSTANTS
       
    50 // Number of default system screensavers.
       
    51 const TInt KPslnSystemScreenSavers = 2;
       
    52 // Value in PubSub when screensaver preview is off.
       
    53 const TInt KPslnScreenSaverPreviewOff = 0;
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // C++ default constructor can NOT contain any code, that might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CPslnScreenSaverView::CPslnScreenSaverView()
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // Symbian 2nd phase constructor can leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CPslnScreenSaverView::ConstructL()
       
    70     {
       
    71     BaseConstructL( R_PSLN_SCREENSAVER_VIEW );
       
    72 
       
    73     iNaviPaneContext = iPslnUi->PslnTabGroup();
       
    74 
       
    75     iScreenSaverRepository = CRepository::NewL( KCRUidScreenSaver );
       
    76     iScreenSaverNotifier = CCenRepNotifyHandler::NewL(
       
    77         *this,
       
    78         *iScreenSaverRepository,
       
    79         CCenRepNotifyHandler::EIntKey,
       
    80         KScreenSaverObject );
       
    81 
       
    82     // Load screensavers.
       
    83     iModel->LoadScreensaverArrayL();
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // Two-phased constructor.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CPslnScreenSaverView* CPslnScreenSaverView::NewLC()
       
    91     {
       
    92     CPslnScreenSaverView* self = new (ELeave) CPslnScreenSaverView();
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL();
       
    95     return self;
       
    96     }
       
    97 
       
    98 // Destructor
       
    99 CPslnScreenSaverView::~CPslnScreenSaverView()
       
   100     {
       
   101     if ( iPreviewModeSubscriber )
       
   102         {
       
   103         iPreviewModeSubscriber->Cancel();
       
   104         }
       
   105     iPreviewModeProperty.Close();
       
   106     delete iPreviewModeSubscriber;
       
   107     if ( iPreviewStateSubscriber )
       
   108         {
       
   109         iPreviewStateSubscriber->Cancel();
       
   110         }
       
   111     iPreviewStateProperty.Close();
       
   112     delete iPreviewStateSubscriber;
       
   113     
       
   114     if(iPsmClient)
       
   115     	{
       
   116     	iPsmClient->CancelPowerSaveModeNotificationRequest();
       
   117     	delete iPsmClient;
       
   118     	}
       
   119     
       
   120     if ( iWaitDlg )
       
   121         {
       
   122         delete iWaitDlg;
       
   123         }
       
   124 
       
   125     if ( iScreenSaverNotifier->IsActive() )
       
   126         {
       
   127         iScreenSaverNotifier->StopListening();
       
   128         }
       
   129     delete iScreenSaverNotifier;
       
   130     delete iScreenSaverRepository;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CPslnScreenSaverView::Id
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TUid CPslnScreenSaverView::Id() const
       
   138     {
       
   139     return KPslnScreenSaverView;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CPslnScreenSaverView::HandleCommandL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CPslnScreenSaverView::HandleCommandL( TInt aCommand )
       
   147     {
       
   148     TInt currentItem = 0;
       
   149     if ( iContainer )
       
   150         {
       
   151         currentItem = iContainer->CurrentItemIndex();
       
   152         }
       
   153     switch ( aCommand )
       
   154         {
       
   155         case EPslnCmdAppChangeScreenSaver:
       
   156             if ( iModel->ScreensaverHasCapability( currentItem, EScpCapsConfigure ) )
       
   157                 {
       
   158                 HandleScreenSaverSettingsL( currentItem );
       
   159                 }
       
   160             else
       
   161                 {
       
   162                 HandleScreenSaverActivationL( currentItem );
       
   163                 }
       
   164             break;
       
   165         case EPslnCmdAppSetScreenSaver:
       
   166 #ifdef __WINS__
       
   167             // Trap in wins => unhandled leave propagated to UI level.
       
   168             TRAP_IGNORE( HandleScreenSaverActivationL( currentItem ) );
       
   169 #else
       
   170             HandleScreenSaverActivationL( currentItem );
       
   171 #endif //__WINS__
       
   172             break;
       
   173 
       
   174         case EPslnCmdPreviewScreenSaver:
       
   175             HandleScreenSaverPreviewL( currentItem );
       
   176             break;
       
   177 
       
   178         case EPslnCmdAppSettings:
       
   179             HandleScreenSaverSettingsL( currentItem );
       
   180             break;
       
   181 
       
   182         case EAknSoftkeyExit:
       
   183             aCommand = EAknCmdExit;
       
   184             //lint -fallthrough
       
   185         default:
       
   186             iPslnUi->HandleCommandL( aCommand );
       
   187             break;
       
   188         }
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // When screensaver list is updated due to install/uninstall of screensaver,
       
   193 // this method is called.
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CPslnScreenSaverView::HandlePluginListChangeL()
       
   197     {
       
   198     // Set highlight to selected item.
       
   199     if ( iContainer )
       
   200         {
       
   201         static_cast<CPslnScreenSaverContainer*> (iContainer)->UpdateListBoxL();
       
   202 
       
   203         TInt newDefault = iModel->CurrentPropertyIndexL( KPslnScreenSettingId );
       
   204         if ( newDefault == KErrNotFound )
       
   205             {
       
   206             // If no default found, assume that date is default.
       
   207             newDefault = 0;
       
   208             iModel->SetCurrentPropertyTypeL(
       
   209                 KPslnScreenSettingId,
       
   210                 newDefault );
       
   211             }
       
   212         iContainer->SetCurrentItemIndexAndDraw( newDefault );
       
   213         CheckMiddleSoftkeyLabelL();
       
   214         }
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // When this method is called, view checks based on highlight focus, if the MSK
       
   219 // label is correct.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CPslnScreenSaverView::CheckMiddleSoftkeyLabelL()
       
   223     {
       
   224     // First remove any prevous commands.
       
   225     RemoveCommandFromMSK();
       
   226 
       
   227     if ( IsChangeCommandVisibleL() )
       
   228         {
       
   229         // Set middle softkey as Change.
       
   230         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   231             R_PSLN_MSK_CHANGE,
       
   232             EPslnCmdAppChangeScreenSaver );
       
   233         }
       
   234     else if(IsApplyCommandVisibleL())
       
   235         {
       
   236         // For "Date" and for inactive screensavers MSK Label is Apply.
       
   237         // Apply is also used for simple installed screensavers that do not have settings.
       
   238         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   239             R_PSLN_MSK_ACTIVATE,
       
   240             EPslnCmdAppSetScreenSaver );
       
   241        
       
   242         }
       
   243     else
       
   244         {
       
   245         // when current focus and ticked item is Date.
       
   246         // Do not show MSK.
       
   247         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   248             R_PSLN_MSK_DUMMY,
       
   249             EPslnCmdAppSetScreenSaver );
       
   250         }
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // This is callback method for iPreviewModeSubscriber.
       
   255 // This method is not allowed to leave - if it leaves, subscription is not
       
   256 // activated.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 TInt CPslnScreenSaverView::HandlePreviewModeChanged( TAny *aPtr )
       
   260     {
       
   261     CPslnScreenSaverView* self =
       
   262         static_cast<CPslnScreenSaverView*>(aPtr);
       
   263     TInt value = KErrNone;
       
   264     if ( self->iPreviewModeSubscriber )
       
   265         {
       
   266         self->iPreviewModeProperty.Get( value );
       
   267         }
       
   268 
       
   269     if ( value == KPslnScreenSaverPreviewOff )
       
   270         {
       
   271 
       
   272         // Stop listening for preview mode changes.
       
   273         if ( self->iPreviewModeSubscriber )
       
   274             {
       
   275             self->iPreviewModeSubscriber->Cancel();
       
   276             }
       
   277 
       
   278         // Restore the original screen saver
       
   279         self->iModel->ActivateScreenSaver(
       
   280             KErrNotFound,
       
   281             EPslnScreenSaverPreviewDeactivation );
       
   282 
       
   283         if ( self->iContainer )
       
   284             {
       
   285             // Update container.
       
   286             TRAP_IGNORE(
       
   287                 static_cast<CPslnScreenSaverContainer*>
       
   288                     (self->iContainer)->UpdateListBoxL() );
       
   289             }
       
   290         }
       
   291     return KErrNone;
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // This is callback method for iPreviewStateSubscriber.
       
   296 // This method is not allowed to leave - if it leaves, subscription is not
       
   297 // activated.
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 TInt CPslnScreenSaverView::HandlePreviewStateChanged( TAny* aPtr )
       
   301     {
       
   302     CPslnScreenSaverView* self =
       
   303         static_cast<CPslnScreenSaverView*>(aPtr);
       
   304     TInt value = KErrNone;
       
   305     if ( self->iPreviewStateSubscriber )
       
   306         {
       
   307         self->iPreviewStateProperty.Get( value );
       
   308         }
       
   309 
       
   310     if ( value == EScreenSaverPreviewNone ||
       
   311          value == EScreenSaverPreviewEnd ||
       
   312          value == EScreenSaverPreviewCancel ||
       
   313          value == EScreenSaverPreviewError ||
       
   314          value == EScreenSaverPreviewInvalid )
       
   315         {
       
   316 
       
   317         // Stop listening for preview mode changes.
       
   318         if ( self->iPreviewStateSubscriber )
       
   319             {
       
   320             self->iPreviewStateSubscriber->Cancel();
       
   321             }
       
   322         }
       
   323     else
       
   324         {
       
   325         switch ( value )
       
   326             {
       
   327             case EScreenSaverPreviewLoading:
       
   328                 self->LaunchNote();
       
   329                 break;
       
   330             case EScreenSaverPreviewLoaded:
       
   331             case EScreenSaverPreviewStart:
       
   332                 self->RemoveNote();
       
   333                 break;
       
   334             default:
       
   335                 break;
       
   336             }
       
   337         }
       
   338     return KErrNone;
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // Screensaver array needs to be loaded before activating the view.
       
   343 // It is done from UI class.
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CPslnScreenSaverView::DoActivateL(
       
   347             const TVwsViewId& aPrevViewId,
       
   348             TUid aCustomMessageId,
       
   349             const TDesC8& aCustomMessage )
       
   350     {
       
   351     CPslnBaseView::DoActivateL(
       
   352         aPrevViewId,
       
   353         aCustomMessageId,
       
   354         aCustomMessage );
       
   355 
       
   356     // If view is directly activated (not through main view), update
       
   357     // tab group (and main view's active folder). The static views
       
   358     // have same UID as their tab index.
       
   359     if ( aPrevViewId.iAppUid != KUidPsln )
       
   360         {
       
   361         iPslnUi->UpdateTabIndex(
       
   362             KPslnScreenSaverView.iUid,
       
   363             KPslnScreenSaverView.iUid );
       
   364         }
       
   365 
       
   366     // Notify model that we are ready to receive changes in screensavers.
       
   367     iModel->EnableScreenSaverNotifications( ETrue, *this );
       
   368 
       
   369     if ( !iScreenSaverNotifier->IsActive() )
       
   370         {
       
   371         iScreenSaverNotifier->StartListeningL();
       
   372         }
       
   373 
       
   374     iPsmClient = CPsmClient::NewL(*this);
       
   375     iPsmClient->RequestPowerSaveModeNotification();
       
   376 
       
   377     // Set highlight to selected item.
       
   378     if ( iContainer )
       
   379         {
       
   380         iContainer->SetCurrentItemIndexAndDraw(
       
   381             iModel->CurrentPropertyIndexL( KPslnScreenSettingId ) );
       
   382         }
       
   383     CheckMiddleSoftkeyLabelL();
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // This is called when view is deactivated (when another view has been activated),
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void CPslnScreenSaverView::DoDeactivate()
       
   391     {
       
   392     CPslnBaseView::DoDeactivate();
       
   393 
       
   394     // Notify model that we are no longer active.
       
   395     // Get the pointer to model from UI class (even though base view also has it)
       
   396     // because, the model might have been deleted at this point and base class is
       
   397     // not aware of the deletion.
       
   398     if ( iPslnUi->Model() )
       
   399         {
       
   400         iPslnUi->Model()->EnableScreenSaverNotifications( EFalse, *this );
       
   401         }
       
   402         
       
   403     if(iPsmClient)
       
   404     	{
       
   405     	iPsmClient->CancelPowerSaveModeNotificationRequest();
       
   406         delete iPsmClient;
       
   407         iPsmClient = NULL;
       
   408     	}
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CPslnScreenSaverView::DynInitMenuPaneL
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CPslnScreenSaverView::DynInitMenuPaneL(
       
   416     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   417     {
       
   418     if ( aResourceId == R_PSLN_SS_VIEW_MENUPANE )
       
   419         {
       
   420         if ( iContainer )
       
   421             {
       
   422             iCurrentItem = iContainer->CurrentItemIndex();
       
   423             }
       
   424 
       
   425         if ( IsChangeCommandVisibleL() )
       
   426             {
       
   427             // Remove Set screensaver, if current selection is already active.
       
   428             aMenuPane->SetItemDimmed( EPslnCmdAppSetScreenSaver, ETrue );
       
   429             }
       
   430         else if ( IsApplyCommandVisibleL() )
       
   431             {
       
   432             // Remove Change screensaver if
       
   433             //  a) not active screensaver
       
   434             //  b) not of Date type
       
   435             //  c) installed screensaver is such that it does not have settings.
       
   436             aMenuPane->SetItemDimmed( EPslnCmdAppChangeScreenSaver, ETrue );
       
   437             }
       
   438         else
       
   439             {
       
   440             // when current focus and ticked item is Date.
       
   441             // a) do not show apply
       
   442             // b) do not show change
       
   443             aMenuPane->SetItemDimmed( EPslnCmdAppSetScreenSaver, ETrue );
       
   444             aMenuPane->SetItemDimmed( EPslnCmdAppChangeScreenSaver, ETrue );
       
   445             }
       
   446 
       
   447         // If it is System screen saver, or the plug-in doesn't allow editing
       
   448         // of settings, remove 'Settings' item.
       
   449         if ( ( iCurrentItem < KPslnSystemScreenSavers ) ||
       
   450              ( !iModel->ScreensaverHasCapability(
       
   451                    iCurrentItem, EScpCapsConfigure ) ) )
       
   452             {
       
   453             // Set Settings off.
       
   454             aMenuPane->SetItemDimmed( EPslnCmdAppSettings, ETrue );
       
   455             }
       
   456         }
       
   457     CPslnBaseView::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CPslnScreenSaverView::HandleListBoxSelectionL
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 void CPslnScreenSaverView::HandleListBoxSelectionL()
       
   465     {
       
   466     if ( iContainer )
       
   467         {
       
   468         iCurrentItem = iContainer->CurrentItemIndex();
       
   469         }
       
   470     if ( IsChangeCommandVisibleL() )
       
   471         {
       
   472         HandleCommandL( EPslnCmdAppChangeScreenSaver );
       
   473         }
       
   474     else
       
   475         {    
       
   476         HandleCommandL( EPslnCmdAppSetScreenSaver );
       
   477         }
       
   478     }
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CPslnScreenSaverView::HandleListBoxItemHighlightL
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CPslnScreenSaverView::HandleListBoxItemHighlightL()
       
   485     {    
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CPslnScreenSaverView::NewContainerL
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CPslnScreenSaverView::NewContainerL()
       
   493     {
       
   494     iContainer = new (ELeave) CPslnScreenSaverContainer();
       
   495     iContainer->SetMiddleSoftkeyObserver( this );
       
   496     }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CPslnScreenSaverView::SetTitlePaneL
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 void CPslnScreenSaverView::SetTitlePaneL( TInt& aResourceId )
       
   503     {
       
   504 #ifdef RD_CONTROL_PANEL
       
   505     aResourceId = R_PSLN_TITLE_PANE_SCREENSAVER;
       
   506 #endif //RD_CONTROL_PANEL
       
   507     }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // If wallpaper image has changed, update container.
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 void CPslnScreenSaverView::HandleNotifyInt( TUint32 aId, TInt /*aNewValue*/ )
       
   514     {
       
   515     if ( aId != KScreenSaverObject )
       
   516         {
       
   517         return;
       
   518         }
       
   519 
       
   520     TInt value = KErrNone;
       
   521     if ( iPreviewModeSubscriber )
       
   522         {
       
   523         iPreviewModeProperty.Get( value );
       
   524         }
       
   525 
       
   526     if( iContainer && ( value == KPslnScreenSaverPreviewOff ) )
       
   527         {
       
   528         // Update container.
       
   529         TRAP_IGNORE(
       
   530             static_cast<CPslnScreenSaverContainer*>
       
   531                 (iContainer)->UpdateListBoxL() );
       
   532         }
       
   533     }
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // If the whole repository changes, update container.
       
   537 // -----------------------------------------------------------------------------
       
   538 //
       
   539 void CPslnScreenSaverView::HandleNotifyGeneric( TUint32 aId )
       
   540     {
       
   541     if ( ( aId == NCentralRepositoryConstants::KInvalidNotificationId ||
       
   542            aId == KScreenSaverObject ) && iContainer )
       
   543         {
       
   544         // Update container.
       
   545         TRAP_IGNORE(
       
   546             static_cast<CPslnScreenSaverContainer*>
       
   547                 (iContainer)->UpdateListBoxL() );
       
   548         }
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // In case of error, try to re-start listening.
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 void CPslnScreenSaverView::HandleNotifyError(
       
   556     TUint32 /*aId*/,
       
   557     TInt aError,
       
   558     CCenRepNotifyHandler* aHandler )
       
   559     {
       
   560     if ( ( aError != KErrNone ) && aHandler )
       
   561         {
       
   562         TRAP_IGNORE( aHandler->StartListeningL() );
       
   563         }
       
   564     }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // CPslnScreenSaverView::HandleScreenSaverActivationL
       
   568 // -----------------------------------------------------------------------------
       
   569 //
       
   570 void CPslnScreenSaverView::HandleScreenSaverActivationL( TInt aCurrentItem )
       
   571     {
       
   572     TInt PsmMode = 0; 
       
   573     iPsmClient->PsmSettings().GetCurrentMode( PsmMode );
       
   574     if ( PsmMode == EPsmsrvModePowerSave ) // PSM on, setting is protected
       
   575         {
       
   576         HBufC* buf = StringLoader::LoadLC( R_PSLN_QTN_PSM_INFONOTE );
       
   577         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   578         note->ExecuteLD( *buf );
       
   579         CleanupStack::PopAndDestroy( buf );
       
   580         return;
       
   581         }
       
   582     
       
   583     TRAPD( err, DoInvokeScreenSaverFunctionL(
       
   584         aCurrentItem,
       
   585         EScpCapsSelectionNotification ) );
       
   586 
       
   587     if ( err == KErrNone )
       
   588         {        
       
   589         TRAPD( seterr,iModel->SetCurrentPropertyTypeL(
       
   590             KPslnScreenSettingId,
       
   591             aCurrentItem ) );
       
   592         if( seterr == KErrCancel )
       
   593             {
       
   594             return;
       
   595             }
       
   596         else
       
   597             {
       
   598             User::LeaveIfError( seterr );
       
   599             }
       
   600 
       
   601         if ( iContainer )
       
   602             {
       
   603             // Update container.
       
   604             static_cast<CPslnScreenSaverContainer*>
       
   605                 (iContainer)->UpdateListBoxL();
       
   606             }
       
   607         CheckMiddleSoftkeyLabelL();
       
   608         }
       
   609     
       
   610     return;
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CPslnScreenSaverView::HandleScreenSaverPreviewL
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CPslnScreenSaverView::HandleScreenSaverPreviewL( TInt aCurrentItem )
       
   618     {
       
   619     TRAPD( err, DoInvokeScreenSaverFunctionL(
       
   620         aCurrentItem,
       
   621         EScpCapsPreviewNotification ) );
       
   622 
       
   623     if ( err == KErrNone )
       
   624         {        
       
   625         // Start listening for screensaver preview mode key changes.
       
   626         CreatePreviewModeSubscriberL();
       
   627         CreatePreviewStateSubscriberL();
       
   628         
       
   629         User::LeaveIfError(
       
   630             iModel->ActivateScreenSaver(
       
   631                 aCurrentItem,
       
   632                 EPslnScreenSaverPreviewActivation ) );       
       
   633         }
       
   634     
       
   635     return;
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CPslnScreenSaverView::HandleScreenSaverSettingsL
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CPslnScreenSaverView::HandleScreenSaverSettingsL( TInt aCurrentItem )
       
   643     {
       
   644     // Indicate to the plugin that active screensaver is possibly modified.
       
   645     TInt selectedItem = iModel->CurrentPropertyIndexL( KPslnScreenSettingId );
       
   646     if ( selectedItem == aCurrentItem )
       
   647         {
       
   648         User::LeaveIfError(
       
   649             RProperty::Set(
       
   650                 KPSUidScreenSaver,
       
   651                 KScreenSaverPluginSettingsChanged,
       
   652                 EScreenSaverPluginSettingsChanging ) );
       
   653         }
       
   654     // Configure plugin.
       
   655     TRAP_IGNORE( DoInvokeScreenSaverFunctionL(
       
   656         aCurrentItem,
       
   657         EScpCapsConfigure ) );
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // Non-Leaving version of wait note launching.
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CPslnScreenSaverView::LaunchNote()
       
   665     {
       
   666     TRAP_IGNORE( LaunchNoteL() );
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // Launches wait note.
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CPslnScreenSaverView::LaunchNoteL()
       
   674     {
       
   675     HBufC* noteText = StringLoader::LoadLC( R_PSLN_QTN_GEN_NOTE_OPENING  );
       
   676 
       
   677     if ( !iWaitDlg )
       
   678         {
       
   679         // Create note and launch it.
       
   680         CAknWaitDialog* requestingNote = new(ELeave) CAknWaitDialog(
       
   681             (REINTERPRET_CAST( CEikDialog**, &iWaitDlg ) ), ETrue );
       
   682         iWaitDlg = requestingNote;
       
   683         requestingNote->PrepareLC( R_PSLN_GENERAL_WAIT_NOTE );
       
   684         if ( noteText )
       
   685             {
       
   686             requestingNote->SetTextL( noteText->Des() );
       
   687             }
       
   688         requestingNote->RunLD();
       
   689         }
       
   690 
       
   691     CleanupStack::PopAndDestroy( noteText );
       
   692     }
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // Non-Leaving version of wait note removal.
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 void CPslnScreenSaverView::RemoveNote()
       
   699     {
       
   700     TRAP_IGNORE( RemoveNoteL() );
       
   701     }
       
   702 
       
   703 // -----------------------------------------------------------------------------
       
   704 // Removes opening note and stops listening for preview state changes.
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 void CPslnScreenSaverView::RemoveNoteL()
       
   708     {
       
   709     // Stop listening for preview mode changes.
       
   710     if ( iPreviewStateSubscriber )
       
   711         {
       
   712         iPreviewStateSubscriber->Cancel();
       
   713         }
       
   714     // Remove wait note.
       
   715     if ( iWaitDlg )
       
   716         {
       
   717         iWaitDlg->ProcessFinishedL();
       
   718         iWaitDlg = NULL;
       
   719         }
       
   720     }
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // Invokes screensaver function.
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CPslnScreenSaverView::DoInvokeScreenSaverFunctionL(
       
   727     const TInt aCurrentItem, const TScPluginCaps aType )
       
   728     {
       
   729     // Offer selection notification, if requested by the saver
       
   730     if( iModel && iModel->ScreensaverHasCapability(
       
   731         aCurrentItem,
       
   732         aType ) )
       
   733         {
       
   734         iModel->InvokeSSPluginFunctionL(
       
   735             aCurrentItem,
       
   736             aType );
       
   737         }
       
   738     }
       
   739 
       
   740 // -----------------------------------------------------------------------------
       
   741 // Creates subscriber and starts to listen.
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CPslnScreenSaverView::CreatePreviewModeSubscriberL()
       
   745     {
       
   746     if ( !iPreviewModeSubscriber )
       
   747         {
       
   748         User::LeaveIfError(
       
   749             iPreviewModeProperty.Attach(
       
   750                 KPSUidScreenSaver,
       
   751                 KScreenSaverPreviewMode ) );
       
   752         iPreviewModeSubscriber =
       
   753             new (ELeave) CPslnPropertySubscriber(
       
   754                 TCallBack( HandlePreviewModeChanged, this ),
       
   755                 iPreviewModeProperty );
       
   756         }
       
   757     iPreviewModeSubscriber->Subscribe();
       
   758     }
       
   759 
       
   760 void CPslnScreenSaverView::CreatePreviewStateSubscriberL()
       
   761     {
       
   762     if ( !iPreviewStateSubscriber )
       
   763         {
       
   764         User::LeaveIfError(
       
   765                 iPreviewStateProperty.Attach(
       
   766                 KPSUidScreenSaver,
       
   767                 KScreenSaverPreviewState ) );
       
   768         iPreviewStateSubscriber =
       
   769             new (ELeave) CPslnPropertySubscriber(
       
   770                 TCallBack( HandlePreviewStateChanged, this ),
       
   771                 iPreviewStateProperty );
       
   772         }
       
   773     iPreviewStateSubscriber->Subscribe();
       
   774     }
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // Remove unnecessary commands from Middle softkey.
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 void CPslnScreenSaverView::RemoveCommandFromMSK()
       
   781     {
       
   782     CEikButtonGroupContainer* cbaGroup = Cba();
       
   783     if ( cbaGroup )
       
   784         {
       
   785         cbaGroup->RemoveCommandFromStack( KPslnMSKControlID, EPslnCmdAppSetScreenSaver );
       
   786         }
       
   787     }
       
   788 
       
   789 // -----------------------------------------------------------------------------
       
   790 // Is 'Change' command visible or not.
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 TBool CPslnScreenSaverView::IsChangeCommandVisibleL() const
       
   794     {
       
   795     if ( !iContainer )
       
   796         {
       
   797         return EFalse;
       
   798         }
       
   799 
       
   800     TInt currentItem = KErrNotFound;
       
   801     currentItem = iContainer->CurrentItemIndex();
       
   802 
       
   803     // Remove Change screensaver if
       
   804     //  a) not active screensaver
       
   805     //  b) not of Date type
       
   806     //  c) installed screensaver is such that it does not have settings.
       
   807     if ( currentItem == iModel->CurrentPropertyIndexL( KPslnScreenSettingId ) &&
       
   808        iModel->ScreensaverHasCapability( currentItem, EScpCapsConfigure ) )
       
   809         {
       
   810         return ETrue;
       
   811         }
       
   812 
       
   813     return EFalse;
       
   814     }
       
   815 
       
   816 
       
   817 // -----------------------------------------------------------------------------
       
   818 // Is the focus item the same as the setting
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 TBool CPslnScreenSaverView::IsApplyCommandVisibleL() const
       
   822     {
       
   823     if ( !iContainer )
       
   824         {
       
   825         return EFalse;
       
   826         }
       
   827 
       
   828     TInt currentItem = KErrNotFound;
       
   829     currentItem = iContainer->CurrentItemIndex();
       
   830 
       
   831     // Remove Apply screensaver if
       
   832     //  a) the focused item is the same as ticked 
       
   833     //  c) 
       
   834 
       
   835     TBool retVal = ETrue;
       
   836     if ( currentItem == iModel->CurrentPropertyIndexL( KPslnScreenSettingId ))
       
   837         {
       
   838         retVal = EFalse;
       
   839         }
       
   840     return retVal;
       
   841     }
       
   842 
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // Called when the power save mode is changed.
       
   846 // -----------------------------------------------------------------------------
       
   847 //
       
   848 void CPslnScreenSaverView::PowerSaveModeChanged( const TPsmsrvMode /*aMode*/ )
       
   849 	{
       
   850 	TRAP_IGNORE( iContainer->SetCurrentItemIndexAndDraw(
       
   851         iModel->CurrentPropertyIndexL( KPslnScreenSettingId ) ) );
       
   852 	TRAP_IGNORE( CheckMiddleSoftkeyLabelL() );	
       
   853 	
       
   854 	if ( iPsmClient )
       
   855 		{
       
   856 	    iPsmClient->RequestPowerSaveModeNotification();	
       
   857 		}    
       
   858 	}
       
   859 
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // Called when some wrong with the power save mode change.
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 void CPslnScreenSaverView::PowerSaveModeChangeError( const TInt /*aError*/ )
       
   866 	{
       
   867 	}
       
   868 
       
   869 
       
   870 //  End of File