psln/pslnslidesetdialog/src/pslnslidesetdialog.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2006-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:  Slide set dialog base class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // General.
       
    20 #include <e32std.h>
       
    21 #include <barsread.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <hlplch.h>
       
    24 
       
    25 // UI components.
       
    26 #include <avkon.hrh>
       
    27 #include <AknUtils.h>
       
    28 #include <aknappui.h>
       
    29 #include <aknnavi.h>
       
    30 #include <akntitle.h>
       
    31 #include <aknlists.h>
       
    32 #include <aknradiobuttonsettingpage.h>
       
    33 #include <aknslidersettingpage.h>
       
    34 #include <AknsSrvClient.h>
       
    35 
       
    36 #include <AknsWallpaperUtils.h>
       
    37 #include <centralrepository.h>
       
    38 #include <AknSkinsInternalCRKeys.h>
       
    39 
       
    40 // Other services.
       
    41 #include <MGFetch.h>
       
    42 #include <StringLoader.h>
       
    43 #include <featmgr.h>
       
    44 
       
    45 // Psln slide set specific.
       
    46 #include "pslnslidesetdialog.h"
       
    47 #include "pslnslidesetmodel.h"
       
    48 #include "pslnslidesetdrmverifier.h"
       
    49 #include "pslnslidesetconst.h"
       
    50 
       
    51 // Local resources and definitions.
       
    52 #include "pslnslidesetdialog.hrh"
       
    53 #include <pslnslidesetdialogrsc.rsg>
       
    54 #include <bautils.h>
       
    55 
       
    56 // CONSTANTS
       
    57 // Image fetch granularity.
       
    58 const TInt KPslnSlideSetImagesGranualarity = 6;
       
    59 // Middle softkey command ID
       
    60 const TInt KPslnMSKControlID = 3;
       
    61 // Size of ending '\t' in string.
       
    62 const TInt KPslnStringEndMarkSize = 2;
       
    63 // Length of setting item value.
       
    64 const TInt KPslnSettingItemLength = 64;
       
    65 
       
    66 // Path to compiled resource file.
       
    67 _LIT( KPslnSlideSetDialogResourceFileName,
       
    68      "z:pslnslidesetdialogrsc.rsc" );
       
    69 
       
    70 // ============================ MEMBER FUNCTIONS ===============================
       
    71 
       
    72 void CPslnSlidesetDialog::BaseConstructL( const TInt aType )
       
    73     {
       
    74     FeatureManager::InitializeLibL();
       
    75 
       
    76     // Validate type parameter.
       
    77     if ( aType != EPslnScreensaverDialog &&
       
    78          aType != EPslnWallpaperDialog )
       
    79         {
       
    80         User::Leave( KErrArgument );
       
    81         }
       
    82     iType = aType;
       
    83 
       
    84     iModel = CPslnSlideSetModel::NewL();
       
    85     // Feature support should only be read once. It should not change run-time.
       
    86     iModel->GetFeatureSupportL( iFeaturesSupport );
       
    87 
       
    88     // Find the resource file:
       
    89     TParse* parse = new (ELeave) TParse;
       
    90     CleanupStack::PushL( parse );
       
    91     parse->Set(
       
    92         KPslnSlideSetDialogResourceFileName,
       
    93         &KDC_RESOURCE_FILES_DIR, NULL );
       
    94 
       
    95     TFileName* fileName = new (ELeave) TFileName( parse->FullName() );
       
    96     CleanupStack::PushL( fileName );
       
    97 
       
    98     // Open resource file:
       
    99     RFs& fs = iEikonEnv->FsSession();
       
   100     BaflUtils::NearestLanguageFile( fs, *fileName );
       
   101     iResourceOffset = iEikonEnv->AddResourceFileL( *fileName );
       
   102 
       
   103     CleanupStack::PopAndDestroy( 2, parse );
       
   104 
       
   105     CAknDialog::ConstructL( R_PSLN_SLIDE_DIALOG_MENUBAR );
       
   106 
       
   107     // Remove tab group (if applicable).
       
   108     ToggleDefaultNaviPaneL( ETrue );
       
   109 
       
   110     // Retrieve previous title so that we can set it back when
       
   111     // dialog exits.
       
   112     if ( iAvkonAppUi )
       
   113         {
       
   114         CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   115         if ( sp )
       
   116             {
       
   117             CAknTitlePane* title = static_cast<CAknTitlePane*>(
       
   118                 sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   119 
       
   120             if ( title )
       
   121                 {
       
   122                 const TDesC* prevTitle = title->Text();
       
   123                 iPreviousTitleTxt = prevTitle->AllocL();
       
   124                 }
       
   125             }
       
   126         }
       
   127     iMGFetchRunning = EFalse;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // C++ default constructor can NOT contain any code, that might leave.
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 CPslnSlidesetDialog::CPslnSlidesetDialog()
       
   135     {
       
   136     }
       
   137 
       
   138 // Destructor
       
   139 CPslnSlidesetDialog::~CPslnSlidesetDialog()
       
   140     {
       
   141     if ( this->IsFocused() )
       
   142         {
       
   143         CEikDialog::ButtonGroupContainer().RemoveCommandObserver( KPslnMSKControlID );
       
   144         }
       
   145 
       
   146     // Remove empty navi pane.
       
   147     TRAP_IGNORE( ToggleDefaultNaviPaneL( EFalse ) );
       
   148 
       
   149     iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   150 
       
   151     delete iListBox;
       
   152     delete iItems;
       
   153     delete iModel;
       
   154     delete iPreviousTitleTxt;
       
   155     delete iSlideSetTypeItems;
       
   156 
       
   157     if ( iResourceOffset != 0 )
       
   158         {
       
   159         iEikonEnv->DeleteResourceFile( iResourceOffset );
       
   160         }
       
   161 
       
   162     FeatureManager::UnInitializeLib();
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // Gets current item.
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 TInt CPslnSlidesetDialog::CurrentItemIndex() const
       
   170     {
       
   171     return iListBox->CurrentItemIndex();
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Sets current item and re-draws the listbox.
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CPslnSlidesetDialog::SetCurrentItemIndexAndDraw( TInt aNewIndex )
       
   179     {
       
   180     if( ( aNewIndex >= 0 ) &&
       
   181         ( aNewIndex < iListBox->Model()->NumberOfItems() ) )
       
   182         {
       
   183         iListBox->SetCurrentItemIndexAndDraw( aNewIndex );
       
   184         }
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // Checks if feature is supported.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TBool CPslnSlidesetDialog::IsFeatureSupported( TInt aFeatureID )
       
   192     {
       
   193     if ( ( aFeatureID >= 0 ) && ( aFeatureID < KPslnMaxFeatureID ) )
       
   194         {
       
   195         return iFeaturesSupport.IsSet( aFeatureID );
       
   196         }
       
   197     else
       
   198         {
       
   199         // invalid feature value.
       
   200         return EFalse;
       
   201         }
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Sets title pane text.
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CPslnSlidesetDialog::SetTitlePaneL( const TInt aResourceId )
       
   209     {
       
   210     CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   211     CAknTitlePane* titlePane =
       
   212         static_cast<CAknTitlePane*> (
       
   213         sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   214     if ( titlePane )
       
   215         {
       
   216         HBufC* titleBuf = StringLoader::LoadLC( aResourceId );
       
   217         titlePane->SetTextL( *titleBuf );
       
   218         CleanupStack::PopAndDestroy( titleBuf );
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Creates a specific setting item.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CPslnSlidesetDialog::MakeItemL( const TInt aIndex )
       
   227     {
       
   228     // Check that parameter is valid.
       
   229     if ( aIndex > iItems->Count() || aIndex < 0 )
       
   230         {
       
   231         User::Leave( KErrArgument );
       
   232         }
       
   233     TInt currentValue = KErrNotFound;
       
   234     switch( aIndex )
       
   235         {
       
   236         case EPslnSlideSetImagesId:
       
   237             {
       
   238             if ( IsFeatureSupported( EPslnSlideSetFeatureRandom ) &&
       
   239                  ( iType == EPslnScreensaverDialog ) )
       
   240                 {
       
   241                 currentValue = iModel->GetSlideSetType( iType );
       
   242                 SetSettingPageValueToListL(
       
   243                     *iSlideSetTypeItems,
       
   244                     aIndex,
       
   245                     currentValue,
       
   246                     EFalse );
       
   247                 }
       
   248             else
       
   249                 {
       
   250                 // Get number of images.
       
   251                 HBufC* item = (*iItems)[aIndex].AllocL();
       
   252                 TInt slideSetFileType = EAknsSrvInifileSSWP;
       
   253                 if ( iType == EPslnScreensaverDialog )
       
   254                     {
       
   255                     slideSetFileType = EAknsSrvInifileSSSS;
       
   256                     }
       
   257                 currentValue =
       
   258                     iModel->GetImageCountInSlideSetL( slideSetFileType );
       
   259 
       
   260                 // If there are images already selected, the number of images
       
   261                 // needs to be shown in the setting page.
       
   262                 if ( currentValue > 0 )
       
   263                     {
       
   264                     TInt resourceId =
       
   265                         SelectResourceStringForImages( currentValue );
       
   266                     HBufC* valueStr = NULL;
       
   267                 // Use singular form, if only one image.
       
   268                     if ( currentValue == 1 )
       
   269                         {
       
   270                         valueStr = StringLoader::LoadLC( resourceId );
       
   271                         }
       
   272                 // Otherwise plural.
       
   273                     else
       
   274                         {
       
   275                         valueStr = StringLoader::LoadLC(
       
   276                             resourceId,
       
   277                             currentValue );
       
   278                         }
       
   279                     // for A&H number conversion
       
   280                     TPtr bufPtr = valueStr->Des();
       
   281                     if( AknTextUtils::DigitModeQuery(
       
   282                         AknTextUtils::EDigitModeShownToUser ) )
       
   283                         {
       
   284                         AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   285                         }
       
   286                     // make room for value and end mark.
       
   287                     item = item->ReAllocL(
       
   288                         item->Length() +
       
   289                         bufPtr.Length() +
       
   290                         KPslnStringEndMarkSize );
       
   291                     TPtr expandedPtr = item->Des();
       
   292                     expandedPtr.Insert( item->Length(), bufPtr );
       
   293                     CleanupStack::PopAndDestroy( valueStr );
       
   294                     }
       
   295                 else
       
   296                 	{
       
   297                 	if ( iType == EPslnWallpaperDialog )
       
   298                 		{
       
   299                 		TInt type = KErrNone;
       
   300 						CRepository* rep = CRepository::NewL( KCRUidPersonalisation );
       
   301 						rep->Get( KPslnWallpaperType,type );
       
   302 						const TInt SlideSetWPType = 2;
       
   303 						if ( type == SlideSetWPType )
       
   304 							{
       
   305 							AknsWallpaperUtils::SetIdleWallpaper( KNullDesC, NULL );
       
   306 							}
       
   307 						delete rep;
       
   308                 		}
       
   309                 	}
       
   310                 CleanupStack::PushL( item );
       
   311                 TPtr ptr = item->Des();
       
   312                 iItemArray->InsertL( aIndex, ptr );
       
   313                 CleanupStack::PopAndDestroy( item );
       
   314                 }
       
   315             }
       
   316             break;
       
   317         case EPslnSlideSetDurationId:
       
   318             {
       
   319             if ( iType == EPslnScreensaverDialog )
       
   320                 {
       
   321                 currentValue = iModel->GetSlideSetDuration();
       
   322 
       
   323                 SetSliderValueToListL(
       
   324                     aIndex,
       
   325                     currentValue,
       
   326                     R_PSLN_DURATION_SLIDER );
       
   327                 }
       
   328             else
       
   329                 {
       
   330                 currentValue = iModel->GetSlideSetInterval();
       
   331 
       
   332                 // Last parameter is whether or not A&H numeric conversion should be done.
       
   333                 SetSettingPageValueToListL(
       
   334                     *iIntervalItems,
       
   335                     aIndex,
       
   336                     currentValue,
       
   337                     ETrue );
       
   338                 }
       
   339             }
       
   340             break;
       
   341         case EPslnSlideSetBacklightId:
       
   342             {
       
   343             currentValue = iModel->GetSlideSetBacklight();
       
   344 
       
   345             SetSliderValueToListL(
       
   346                 aIndex,
       
   347                 currentValue,
       
   348                 R_PSLN_BACKLIGHT_SLIDER );
       
   349             }
       
   350             break;
       
   351         default:
       
   352             break;
       
   353         }
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // Sets middle softkey label.
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CPslnSlidesetDialog::SetMiddleSoftKeyLabelL(
       
   361     const TInt aResourceId, const TInt aCommandId )
       
   362     {
       
   363     HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
   364     TPtr mskPtr = middleSKText->Des();
       
   365     CEikDialog::ButtonGroupContainer().AddCommandToStackL(
       
   366         KPslnMSKControlID,
       
   367         aCommandId,
       
   368         mskPtr );
       
   369     CEikDialog::ButtonGroupContainer().UpdateCommandObserverL(
       
   370         KPslnMSKControlID,
       
   371         *this );
       
   372     CleanupStack::PopAndDestroy( middleSKText );
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // Layouts dialog before it is visible.
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CPslnSlidesetDialog::PreLayoutDynInitL()
       
   380     {
       
   381     iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityDialog );
       
   382     CreateSettingsListL();
       
   383     CEikDialog::PreLayoutDynInitL();
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // Reimplements CAknDialog::ProcessCommandL inorder to handle dialog menu
       
   388 // commands.
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CPslnSlidesetDialog::ProcessCommandL( TInt aCommandId )
       
   392     {
       
   393     CAknDialog::ProcessCommandL( aCommandId );
       
   394     switch ( aCommandId )
       
   395         {
       
   396         case EPslnCmdAppSetWallpaper: // Fallthrough
       
   397         case EPslnCmdAppSetScreenSaver: // Fallthrough
       
   398         case EPslnSlideSetCmdChange:
       
   399             if ( iListBox )
       
   400                 {
       
   401                 HandleListBoxSelectionL();
       
   402                 }
       
   403             break;
       
   404         case EAknCmdHelp:
       
   405             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   406                 iAvkonAppUi->AppHelpContextL() );
       
   407             break;
       
   408         case EAknSoftkeyBack: // -Fallthrough
       
   409             // Remove empty navi pane.
       
   410             ToggleDefaultNaviPaneL( EFalse );
       
   411         case EEikCmdExit: // -Fallthrough
       
   412         case EAknCmdExit:
       
   413             // Close this dialog
       
   414             TryExitL( aCommandId );
       
   415             iAvkonAppUi->ProcessCommandL( aCommandId );
       
   416             break;
       
   417         default:
       
   418             break;
       
   419         }
       
   420     }
       
   421 
       
   422 // -----------------------------------------------------------------------------
       
   423 // Reimplements CAknDialog::OkToExitL.
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 TBool CPslnSlidesetDialog::OkToExitL( TInt aButtonId )
       
   427     {
       
   428     //Check if MGFetch is running.
       
   429     if( iMGFetchRunning )
       
   430         {
       
   431         return EFalse;
       
   432         }
       
   433 
       
   434     if ( iPreviousTitleTxt &&
       
   435          iPreviousTitleTxt->Length() > 0 &&
       
   436          aButtonId != EAknSoftkeyOptions )
       
   437         {
       
   438         if ( iAvkonAppUi )
       
   439             {
       
   440             CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   441             if ( sp )
       
   442                 {
       
   443                 CAknTitlePane* title = static_cast<CAknTitlePane*>(
       
   444                     sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   445 
       
   446                 if ( title )
       
   447                     {
       
   448                     title->SetTextL( *iPreviousTitleTxt );
       
   449                     }
       
   450                 }
       
   451             }
       
   452         }
       
   453     return CAknDialog::OkToExitL( aButtonId );
       
   454     }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // Reimplements CAknDialog::DynInitMenuPaneL inorder to support dynamic hiding
       
   458 // of menu items based on current state of the viewer.
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 void CPslnSlidesetDialog::DynInitMenuPaneL(
       
   462     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   463     {
       
   464     if ( aResourceId == R_PSLN_SLIDE_DIALOG_MENU &&
       
   465          !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   466         {
       
   467         // Disable help if not supported
       
   468         aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   469         }
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // Reimplements CAknDialog::SizeChanged inorder to support the resize of the
       
   474 // dialog when functions such as SetRect, SetExtent are called on the dialog.
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CPslnSlidesetDialog::SizeChanged()
       
   478     {
       
   479     CAknDialog::SizeChanged();
       
   480     if ( iListBox )
       
   481         {
       
   482         // Get size from main pane, place from this rect
       
   483         TRect mainPaneRect;
       
   484         AknLayoutUtils::LayoutMetricsRect(
       
   485             AknLayoutUtils::EMainPane,
       
   486             mainPaneRect );
       
   487 
       
   488         iListBox->SetExtent( Rect().iTl, mainPaneRect.Size() );
       
   489         }
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // Handles Key events by reimplementing CCoeControl::OfferKeyEventL.
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 TKeyResponse CPslnSlidesetDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   497     TEventCode aType )
       
   498     {
       
   499     switch ( aKeyEvent.iCode )
       
   500         {
       
   501         case EKeyLeftArrow: // -Fallthrough
       
   502         case EKeyRightArrow:
       
   503             // Listbox takes all event even if it doesn't use them
       
   504             if ( !iMGFetchRunning )
       
   505                 {
       
   506                 return EKeyWasConsumed;
       
   507                 }
       
   508             break;
       
   509         default:
       
   510             break;
       
   511         }
       
   512     // If MGFetch is running, do not give key events to listbox.
       
   513     if ( iListBox && !iMGFetchRunning )
       
   514         {
       
   515         iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   516         }
       
   517     return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   518     }
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // Handles setting page events.
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 void CPslnSlidesetDialog::HandleSettingPageEventL(
       
   525         CAknSettingPage* aSettingPage,
       
   526         TAknSettingPageEvent aEventType )
       
   527     {
       
   528     TInt settingPageId = aSettingPage->SettingId();
       
   529     TInt current = KErrNotFound;
       
   530     if ( aEventType == EEventSettingOked )
       
   531         {
       
   532         switch( settingPageId )
       
   533             {
       
   534             case EPslnSlideSetImagesId:
       
   535                 if ( IsFeatureSupported( EPslnSlideSetFeatureRandom ) )
       
   536                     {
       
   537                     current = static_cast<CAknRadioButtonSettingPage*>(
       
   538                         aSettingPage)->ListBoxControl()->CurrentItemIndex();
       
   539                     // If images is selected, start MGFetch.
       
   540                     if ( current != KPslnSlideSetRandomIndex )
       
   541                         {
       
   542                         HandleLaunchMGFetchL();
       
   543                         }
       
   544                     else
       
   545                         {
       
   546                         iModel->SetSlideSetType( iType, current );
       
   547                         }
       
   548                     }
       
   549                 break;
       
   550 
       
   551             case EPslnSlideSetDurationId:
       
   552                 current = static_cast<CAknSliderSettingPage*>
       
   553                     (aSettingPage)->SliderControl()->Value();
       
   554                 iModel->SetSlideSetDuration( current );
       
   555                 break;
       
   556             case EPslnSlideSetBacklightId:
       
   557                 current = static_cast<CAknSliderSettingPage*>
       
   558                     (aSettingPage)->SliderControl()->Value();
       
   559                 iModel->SetSlideSetBacklight( current );
       
   560                 break;
       
   561             case EPslnSlideSetIntervalId:
       
   562                 current = static_cast<CAknRadioButtonSettingPage*>(
       
   563                     aSettingPage)->ListBoxControl()->CurrentItemIndex();
       
   564                 iModel->SetSlideSetInterval( current );
       
   565                 // interval is regarded as duration
       
   566                 settingPageId = EPslnSlideSetDurationId;
       
   567                 break;
       
   568             default:
       
   569                 break;
       
   570             }
       
   571         UpdateDialogL( settingPageId );
       
   572         }
       
   573     }
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // Handles change of skin/Layout
       
   577 // -----------------------------------------------------------------------------
       
   578 //
       
   579 void CPslnSlidesetDialog::HandleResourceChange( TInt aType )
       
   580     {
       
   581     CAknDialog::HandleResourceChange( aType );
       
   582     if ( iListBox )
       
   583         {
       
   584         iListBox->HandleResourceChange( aType );
       
   585         }
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // Handles list animation events.
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 void CPslnSlidesetDialog::FocusChanged( TDrawNow aDrawNow )
       
   593     {
       
   594     CAknDialog::FocusChanged( aDrawNow );
       
   595     if( iListBox )
       
   596         {
       
   597         iListBox->SetFocus( IsFocused(), aDrawNow );
       
   598         }
       
   599     }
       
   600 
       
   601 // ---------------------------------------------------------------------------
       
   602 // Count components.
       
   603 // ---------------------------------------------------------------------------
       
   604 //
       
   605 TInt CPslnSlidesetDialog::CountComponentControls() const
       
   606     {
       
   607     return iListBox ? 1 : 0;
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------------------------
       
   611 // Give pointer to component matching to the index.
       
   612 // ---------------------------------------------------------------------------
       
   613 //
       
   614 CCoeControl* CPslnSlidesetDialog::ComponentControl( TInt aIndex ) const
       
   615     {
       
   616     return ( aIndex == 0 ) ? iListBox : NULL;
       
   617     }
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 // Handle listbox event.
       
   621 // ---------------------------------------------------------------------------
       
   622 //
       
   623 void CPslnSlidesetDialog::HandleListBoxEventL(
       
   624     CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
       
   625     {
       
   626     switch ( aEventType )
       
   627         {
       
   628         case EEventEnterKeyPressed: // Fallthrough
       
   629         case EEventItemDoubleClicked:
       
   630         case EEventItemSingleClicked:
       
   631             HandleListBoxSelectionL();
       
   632             break;
       
   633         default:
       
   634            break;
       
   635         }
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // Create setting items.
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CPslnSlidesetDialog::CreateSettingsListL()
       
   643     {
       
   644     // Create settings listbox.
       
   645     iListBox = new (ELeave) CAknSettingStyleListBox;
       
   646     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   647 
       
   648     // Create listbox items.
       
   649     iItemArray = static_cast<CDesCArray*>
       
   650         ( iListBox->Model()->ItemTextArray() );
       
   651     iListBox->SetContainerWindowL( *this );
       
   652     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   653 
       
   654     iListBox->CreateScrollBarFrameL( ETrue );
       
   655     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   656         CEikScrollBarFrame::EOff,
       
   657         CEikScrollBarFrame::EAuto );
       
   658     iListBox->SetListBoxObserver( this );
       
   659     iListBox->SetMopParent( this );
       
   660     iListBox->MakeVisible( ETrue );
       
   661 
       
   662     CreateListBoxItemsL();
       
   663     iListBox->HandleItemAdditionL();
       
   664 
       
   665     SetRect( iAvkonAppUi->ClientRect() );
       
   666     ActivateL();
       
   667     }
       
   668 
       
   669 // ---------------------------------------------------------------------------
       
   670 // CPslnSlidesetDialog::HandleListBoxSelectionL()
       
   671 // ---------------------------------------------------------------------------
       
   672 //
       
   673 void CPslnSlidesetDialog::HandleListBoxSelectionL()
       
   674     {
       
   675      TInt index = iListBox->CurrentItemIndex();
       
   676 
       
   677      switch ( index )
       
   678         {
       
   679         case EPslnSlideSetImagesId:
       
   680             if( iMGFetchRunning )
       
   681                 {
       
   682                 return;
       
   683                 }
       
   684             if ( IsFeatureSupported( EPslnSlideSetFeatureRandom ) 
       
   685                 && ( iType == EPslnScreensaverDialog ) )
       
   686                 {
       
   687                 ShowSlideSetTypeSelectionL();
       
   688                 }
       
   689             else
       
   690                 {
       
   691                 ShowSlideSetImageListL();
       
   692                 }
       
   693             break;
       
   694         case EPslnSlideSetDurationId:
       
   695             if ( iType == EPslnScreensaverDialog )
       
   696                 {
       
   697                 ShowDurationSliderL();
       
   698                 }
       
   699             else
       
   700                 {
       
   701                 ShowIntervalListL();
       
   702                 }
       
   703             break;
       
   704         case EPslnSlideSetBacklightId:
       
   705             ShowBacklightSliderL();
       
   706             break;
       
   707         default:
       
   708             break;
       
   709         }
       
   710     }
       
   711 
       
   712 // ---------------------------------------------------------------------------
       
   713 // Show slide set type setting page. Since it is used by both slide sets
       
   714 // (wallpaper and screen saver), the default implementation is in the base
       
   715 // class.
       
   716 // ---------------------------------------------------------------------------
       
   717 //
       
   718 void CPslnSlidesetDialog::ShowSlideSetTypeSelectionL()
       
   719     {
       
   720     // Retrieve title txt.
       
   721     TInt titleResourceID = R_PSLN_IMAGES_SLIDE_SS_PAGE_TITLE;
       
   722     if ( iType != EPslnScreensaverDialog )
       
   723         {
       
   724         titleResourceID = R_PSLN_IMAGES_SLIDE_WP_PAGE_TITLE;
       
   725         }
       
   726     HBufC* titleText = StringLoader::LoadLC( titleResourceID );
       
   727 
       
   728     // Retrieve current setting page value.
       
   729     TInt currentValue = iModel->GetSlideSetType( iType );
       
   730 
       
   731     // Create & show the setting page.
       
   732     CAknRadioButtonSettingPage* dlg =
       
   733         new( ELeave ) CAknRadioButtonSettingPage(
       
   734             titleText,
       
   735             EAknSettingPageNoOrdinalDisplayed,
       
   736             EAknCtSettingPage,
       
   737             0,
       
   738             R_PSLN_IMAGE_SELECTION_SETTING_PAGE,
       
   739             currentValue,
       
   740             iSlideSetTypeItems );
       
   741     dlg->SetSettingId( EPslnSlideSetImagesId );
       
   742     dlg->SetSettingPageObserver( this );
       
   743     dlg->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted );
       
   744 
       
   745     CleanupStack::PopAndDestroy( titleText );
       
   746     }
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // Shows backlight slider setting page.
       
   750 // ---------------------------------------------------------------------------
       
   751 //
       
   752 void CPslnSlidesetDialog::ShowBacklightSliderL()
       
   753     {
       
   754     // Empty implementation to be overloaded.
       
   755     }
       
   756 
       
   757 // ---------------------------------------------------------------------------
       
   758 // Shows duration slider setting page.
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 void CPslnSlidesetDialog::ShowDurationSliderL()
       
   762     {
       
   763     // Empty implementation to be overloaded.
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // Show wallpaper slide set's interval selection.
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 void CPslnSlidesetDialog::ShowIntervalListL()
       
   771     {
       
   772     // Empty implementation to be overloaded.
       
   773     }
       
   774 
       
   775 // ---------------------------------------------------------------------------
       
   776 // Starts image fetch.
       
   777 // ---------------------------------------------------------------------------
       
   778 //
       
   779 TBool CPslnSlidesetDialog::ShowSlideSetImageListL()
       
   780     {
       
   781     CDesCArrayFlat* files =
       
   782         new (ELeave) CDesCArrayFlat( KPslnSlideSetImagesGranualarity );
       
   783     CleanupStack::PushL( files );
       
   784 
       
   785     CPslnSlideSetDRMVerifier* verifier = CPslnSlideSetDRMVerifier::NewL( iType );
       
   786     CleanupStack::PushL( verifier );
       
   787 
       
   788     iMGFetchRunning = ETrue;
       
   789     TBool selected = EFalse;
       
   790     TRAPD( err,selected = MGFetch::RunL( *files, EImageFile, ETrue, verifier ) );
       
   791     iMGFetchRunning = EFalse;
       
   792     User::LeaveIfError( err );
       
   793     CleanupStack::PopAndDestroy( verifier );
       
   794 
       
   795     // Handle selection
       
   796     if ( selected && ( files->MdcaCount() > 0 ) )
       
   797         {
       
   798         iModel->SetImageListL( iType, *files, iLaunchMode );
       
   799         iModel->SetSlideSetType( iType, 0 );
       
   800         UpdateDialogL( EPslnSlideSetImagesId );
       
   801         }
       
   802     // else - either: User made a selection, but all the images had issues with DRM.
       
   803     // or: MGFetch was cancelled
       
   804     else
       
   805         {
       
   806         selected = EFalse;
       
   807         }
       
   808 
       
   809     CleanupStack::PopAndDestroy( files );
       
   810     return selected;
       
   811     }
       
   812 
       
   813 // ---------------------------------------------------------------------------
       
   814 // Toggles navi pane to default and back.
       
   815 // ---------------------------------------------------------------------------
       
   816 //
       
   817 #ifdef RD_CONTROL_PANEL
       
   818 void CPslnSlidesetDialog::ToggleDefaultNaviPaneL( const TBool /*aNaviPaneToggle*/ )
       
   819 #else
       
   820 void CPslnSlidesetDialog::ToggleDefaultNaviPaneL( const TBool aNaviPaneToggle )
       
   821 #endif // RD_CONTROL_PANEL
       
   822     {
       
   823     // Remove tab group (if applicable).
       
   824     CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   825     // Fetch pointer to the default navi pane control
       
   826     CAknNavigationControlContainer* naviPane =
       
   827         (CAknNavigationControlContainer*)sp->ControlL(
       
   828             TUid::Uid(EEikStatusPaneUidNavi));
       
   829     // Show again previous navipane
       
   830     if ( naviPane )
       
   831         {
       
   832 #ifndef RD_CONTROL_PANEL
       
   833         if ( !aNaviPaneToggle )
       
   834             {
       
   835             naviPane->Pop();
       
   836             }
       
   837         // Show default navi pane.
       
   838         else
       
   839 #endif // !RD_CONTROL_PANEL
       
   840             {
       
   841             naviPane->PushDefaultL();
       
   842             }
       
   843         }
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // Updates dialog based on new value of setting item.
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 void CPslnSlidesetDialog::UpdateDialogL( const TInt aSettingId )
       
   851     {
       
   852     if ( aSettingId >= 0 &&
       
   853          aSettingId < iItemArray->Count() )
       
   854         {
       
   855         iItemArray->Delete( aSettingId );
       
   856         MakeItemL( aSettingId );
       
   857         iListBox->HandleItemAdditionL();
       
   858         }
       
   859     }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // Updates dialog based on new value of setting item.
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 void CPslnSlidesetDialog::SetSettingPageValueToListL(
       
   866         const CDesCArrayFlat& aArray,
       
   867         const TInt aCurrentIndex,
       
   868         const TInt aCurrentValue,
       
   869         const TBool aNumericConversionNeeded )
       
   870     {
       
   871     if ( aCurrentIndex >= iItems->Count() )
       
   872         {
       
   873         User::Leave( KErrArgument );
       
   874         }
       
   875     HBufC* item = (*iItems)[aCurrentIndex].AllocL();
       
   876     HBufC* settingItemValue = HBufC::NewLC( KPslnSettingItemLength );
       
   877     TPtr valuePtr ( settingItemValue->Des() );
       
   878     valuePtr = aArray[ aCurrentValue ];
       
   879 
       
   880     // A&H conversion.
       
   881     if( aNumericConversionNeeded &&
       
   882         AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
   883         {
       
   884         AknTextUtils::LanguageSpecificNumberConversion( valuePtr );
       
   885         }
       
   886 
       
   887     // Re-allocate string, so that setting item name and current value fit.
       
   888     item = item->ReAllocL(
       
   889         item->Length() + valuePtr.Length() + KPslnStringEndMarkSize );
       
   890     TPtr expandedPtr = item->Des();
       
   891 
       
   892     expandedPtr.Insert( item->Length(), valuePtr );
       
   893     CleanupStack::PopAndDestroy( settingItemValue );
       
   894     CleanupStack::PushL( item );
       
   895 
       
   896     TPtr ptr = item->Des();
       
   897     iItemArray->InsertL( aCurrentIndex, ptr );
       
   898     CleanupStack::PopAndDestroy( item );
       
   899     }
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // Updates dialog based on new value of setting item.
       
   903 // -----------------------------------------------------------------------------
       
   904 //
       
   905 void CPslnSlidesetDialog::SetSliderValueToListL(
       
   906         const TInt aCurrentIndex,
       
   907         const TInt aCurrentValue,
       
   908         const TInt aResourceID )
       
   909     {
       
   910     if ( aCurrentIndex >= iItems->Count() )
       
   911         {
       
   912         User::Leave( KErrArgument );
       
   913         }
       
   914 
       
   915     HBufC* item = (*iItems)[aCurrentIndex].AllocL();
       
   916     // If minimum value for backlight, use "Off".
       
   917     if ( aResourceID == R_PSLN_BACKLIGHT_SLIDER && aCurrentValue == 0 )
       
   918         {
       
   919         HBufC* settingItem = StringLoader::LoadLC( R_PSLN_SANIM_SLIDER_OFF );
       
   920         TPtr bufPtr = settingItem->Des();
       
   921         item = item->ReAllocL(
       
   922             item->Length() + bufPtr.Length() + KPslnStringEndMarkSize );
       
   923         TPtr expandedPtr = item->Des();
       
   924 
       
   925         expandedPtr.Insert( item->Length(), bufPtr );
       
   926         CleanupStack::PopAndDestroy( settingItem );
       
   927 
       
   928         }
       
   929     else
       
   930         {
       
   931         HBufC* settingItem = CAknSlider::CreateValueTextInHBufCL(
       
   932                       aCurrentValue,
       
   933                       aResourceID );
       
   934         CleanupStack::PushL( settingItem );
       
   935 
       
   936         // for A&H number conversion
       
   937         TPtr bufPtr = settingItem->Des();
       
   938         if( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
   939             {
       
   940             AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   941             }
       
   942         item = item->ReAllocL(
       
   943             item->Length() + bufPtr.Length() + KPslnStringEndMarkSize );
       
   944         TPtr expandedPtr = item->Des();
       
   945 
       
   946         expandedPtr.Insert( item->Length(), bufPtr );
       
   947         CleanupStack::PopAndDestroy( settingItem );
       
   948         }
       
   949     CleanupStack::PushL( item );
       
   950     TPtr ptr = item->Des();
       
   951     iItemArray->InsertL( aCurrentIndex, ptr );
       
   952     CleanupStack::PopAndDestroy( item );
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // Select appropriate resource text for setting item value.
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 TInt CPslnSlidesetDialog::SelectResourceStringForImages( TInt aCurrentValue )
       
   960     {
       
   961     TInt resourceId = R_PSLN_SLIDE_SET_WP_IMAGES;
       
   962     if ( aCurrentValue == 1 )
       
   963         {
       
   964         if ( iType == EPslnScreensaverDialog )
       
   965             {
       
   966             resourceId = R_PSLN_SLIDE_SET_SS_IMAGE;
       
   967             }
       
   968         else
       
   969             {
       
   970             resourceId = R_PSLN_SLIDE_SET_WP_IMAGE;
       
   971             }
       
   972         }
       
   973     else
       
   974         {
       
   975         if ( iType == EPslnScreensaverDialog )
       
   976             {
       
   977             resourceId = R_PSLN_SLIDE_SET_SS_IMAGES;
       
   978             }
       
   979         }
       
   980     return resourceId;
       
   981     }
       
   982 
       
   983 // -----------------------------------------------------------------------------
       
   984 // Handles idle time. Starts MGFetch.
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 void CPslnSlidesetDialog::HandleLaunchMGFetchL()
       
   988     {
       
   989     TBool selected = ShowSlideSetImageListL();
       
   990     if ( !selected )
       
   991         {
       
   992         ShowSlideSetTypeSelectionL();
       
   993         }
       
   994     }
       
   995 
       
   996 // End of File