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