psln/pslnslidesetdialog/src/pslnslidesetwallpaperdialog.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:  Wallpaper slide set setting dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // General
       
    20 #include <e32std.h>
       
    21 #include <StringLoader.h>
       
    22 #include <csxhelp/skins.hlp.hrh>
       
    23 
       
    24 // Central repository.
       
    25 #include <centralrepository.h>
       
    26 #include <AknSkinsInternalCRKeys.h>
       
    27 #include <pslninternalcrkeys.h>
       
    28 
       
    29 // From AVKON
       
    30 #include <avkon.hrh>
       
    31 #include <aknappui.h>
       
    32 #include <aknradiobuttonsettingpage.h>
       
    33 #include <AknsSrvClient.h>
       
    34 
       
    35 // Psln Slide set specific.
       
    36 #include "pslnslidesetwallpaperdialog.h"
       
    37 #include "pslnslidesetdialog.hrh"
       
    38 #include "pslnslidesetmodel.h"
       
    39 #include "pslnslidesetconst.h"
       
    40 
       
    41 // Resources
       
    42 #include <pslnslidesetdialogrsc.rsg>
       
    43 
       
    44 const TInt KPslnSsSettingsItemArray = 6;
       
    45 const TInt KPslnSsSlideSetType = 2;
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // C++ default constructor can NOT contain any code, that might leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPslnWallpaperSlidesetDialog::CPslnWallpaperSlidesetDialog()
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CPslnWallpaperSlidesetDialog::ConstructL()
       
    62     {
       
    63 #ifndef RD_SLIDESHOW_WALLPAPER
       
    64     User::Leave( KErrNotSupported );
       
    65 #endif // RD_SLIDESHOW_WALLPAPER
       
    66     BaseConstructL(
       
    67         GetDialogFlag( CPslnSlidesetDialogInterface::EPslnDialogType ) );
       
    68 
       
    69     iSlideSetTypeItems = iCoeEnv->ReadDesC16ArrayResourceL(
       
    70         R_PSLN_SLIDESET_TYPE_WP_SETTING_PAGE_LBX );
       
    71 
       
    72     // Add each line separately, since it needs language-dependant conversion.
       
    73     iIntervalItems = new( ELeave ) CDesCArrayFlat( KPslnSsSettingsItemArray );
       
    74     AppendIntervalItemL( R_PSLN_SLIDESET_INTERVAL_1_MINUTE );
       
    75     AppendIntervalItemL( R_PSLN_SLIDESET_INTERVAL_10_MINUTE );
       
    76     AppendIntervalItemL( R_PSLN_SLIDESET_INTERVAL_30_MINUTE );
       
    77     AppendIntervalItemL( R_PSLN_SLIDESET_INTERVAL_1_HOUR );
       
    78     AppendIntervalItemL( R_PSLN_SLIDESET_INTERVAL_1_DAY );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CPslnWallpaperSlidesetDialog* CPslnWallpaperSlidesetDialog::NewL()
       
    86     {
       
    87     CPslnWallpaperSlidesetDialog* self = NewLC();
       
    88     CleanupStack::Pop(); // Self
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CPslnWallpaperSlidesetDialog* CPslnWallpaperSlidesetDialog::NewLC()
       
    97     {
       
    98     CPslnWallpaperSlidesetDialog* self =
       
    99         new ( ELeave ) CPslnWallpaperSlidesetDialog();
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     return self;
       
   103     }
       
   104 
       
   105 // Destructor
       
   106 CPslnWallpaperSlidesetDialog::~CPslnWallpaperSlidesetDialog()
       
   107     {
       
   108     // base class destroys iSlideSetTypeItems.
       
   109     delete iIntervalItems;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // Executes dialog.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CPslnWallpaperSlidesetDialog::ExecuteDialogLD()
       
   117     {
       
   118     return CAknDialog::ExecuteLD( R_PSLN_SETTINGS_DIALOG );
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // Configures dialog.
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CPslnWallpaperSlidesetDialog::SetDialogFlag(
       
   126     const TInt aFlag, const TInt aValue )
       
   127     {
       
   128     switch( aFlag )
       
   129         {
       
   130         case CPslnSlidesetDialogInterface::EPslnDialogType:
       
   131             // Cannot be changed.
       
   132             break;
       
   133         case CPslnSlidesetDialogInterface::EPslnLaunchMode:
       
   134             if ( aValue == CPslnSlidesetDialogInterface::EPslnNormal ||
       
   135                  aValue == CPslnSlidesetDialogInterface::EPslnConfigureOnly )
       
   136                 {
       
   137                 iLaunchMode = aValue;
       
   138                 }
       
   139             break;
       
   140         default:
       
   141             break;
       
   142         }
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // Queries for dialog parameters.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TInt CPslnWallpaperSlidesetDialog::GetDialogFlag( const TInt aFlag )
       
   150     {
       
   151     TInt flagValue = KErrNotFound;
       
   152     switch( aFlag )
       
   153         {
       
   154         case CPslnSlidesetDialogInterface::EPslnDialogType:
       
   155             flagValue = EPslnWallpaperDialog;
       
   156             break;
       
   157         case CPslnSlidesetDialogInterface::EPslnLaunchMode:
       
   158             flagValue = iLaunchMode;
       
   159             break;
       
   160         case CPslnSlidesetDialogInterface::EPslnConfigurability:
       
   161             TRAP_IGNORE( flagValue = DeduceActivationModeL() );
       
   162             break;
       
   163         default:
       
   164             break;
       
   165         }
       
   166     return flagValue;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // Layouts dialog before showing it.
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CPslnWallpaperSlidesetDialog::PreLayoutDynInitL()
       
   174     {
       
   175     // Set title pane text.
       
   176     SetTitlePaneL( R_PSLN_SLIDESET_WALLPAPER_DIALOG_TITLE );
       
   177     // Set middle softkey as Change.
       
   178     CPslnSlidesetDialog::SetMiddleSoftKeyLabelL(
       
   179         R_PSLN_MSK_CHANGE,
       
   180         EPslnCmdAppSetWallpaper );
       
   181     CPslnSlidesetDialog::PreLayoutDynInitL();
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // Process command.
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CPslnWallpaperSlidesetDialog::ProcessCommandL( TInt aCommandId )
       
   189     {
       
   190     CPslnSlidesetDialog::ProcessCommandL( aCommandId );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // Reimplements CAknDialog::OkToExitL.
       
   195 // Possibly stores wallpaper type to cenrep.
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CPslnWallpaperSlidesetDialog::OkToExitL( TInt aButtonId )
       
   199     {
       
   200     if ( CPslnSlidesetDialog::IsFeatureSupported( EPslnSlideSetFeatureRandom ) )
       
   201         {
       
   202         CRepository* repository = CRepository::NewL( KCRUidThemes );
       
   203         TInt slideSetType = KErrNotFound;
       
   204         repository->Get( KThemesWallpaperSlideSetType, slideSetType );
       
   205         delete repository;
       
   206         // If Random is selected, then set slide type wallpaper active.
       
   207         if ( ( slideSetType == KPslnSlideSetRandomIndex ) &&
       
   208              ( iLaunchMode == CPslnSlidesetDialogInterface::EPslnNormal ) )
       
   209             {
       
   210             CRepository* repository2 =
       
   211                 CRepository::NewL( KCRUidPersonalisation );
       
   212             repository2->Set(
       
   213                 KPslnWallpaperType,
       
   214                 KPslnSsSlideSetType );
       
   215             delete repository2;
       
   216             }
       
   217         }
       
   218     return CPslnSlidesetDialog::OkToExitL( aButtonId );
       
   219     }
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // Adds setting list items to listbox.
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CPslnWallpaperSlidesetDialog::CreateListBoxItemsL()
       
   227     {
       
   228     iItems = iCoeEnv->ReadDesC16ArrayResourceL(
       
   229         R_PSLN_WALLPAPER_SLIDE_SETTING_LBX_ITEMS );
       
   230     CPslnSlidesetDialog::MakeItemL( EPslnSlideSetImagesId );
       
   231     CPslnSlidesetDialog::MakeItemL( EPslnSlideSetDurationId ); // regard as interval
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Gets help context for Help application.
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CPslnWallpaperSlidesetDialog::GetHelpContext(
       
   239     TCoeHelpContext& aContext ) const
       
   240     {
       
   241     aContext.iMajor = KUidPsln;
       
   242     aContext.iContext = KSCREENSAVER_HLP_WP_SETTINGS;
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // Show slide set image interval peridod setting page.
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CPslnWallpaperSlidesetDialog::ShowIntervalListL()
       
   250     {
       
   251     // Retrieve title txt.
       
   252     TInt titleResourceID = R_PSLN_INTERVAL_SLIDE_PAGE_TITLE;
       
   253     HBufC* titleText = StringLoader::LoadLC( titleResourceID );
       
   254 
       
   255     // Retrieve current setting page value.
       
   256     TInt currentValue = iModel->GetSlideSetInterval();
       
   257 
       
   258     // Create & show the setting page.
       
   259     CAknRadioButtonSettingPage* dlg =
       
   260         new( ELeave ) CAknRadioButtonSettingPage(
       
   261             titleText,
       
   262             EAknSettingPageNoOrdinalDisplayed,
       
   263             EAknCtSettingPage,
       
   264             0,
       
   265             R_PSLN_IMAGE_SELECTION_SETTING_PAGE,
       
   266             currentValue,
       
   267             iIntervalItems );
       
   268     dlg->SetSettingId( EPslnSlideSetIntervalId );
       
   269     dlg->SetSettingPageObserver( this );
       
   270     dlg->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted );
       
   271     // Base class stores new value to CenRep.
       
   272 
       
   273     CleanupStack::PopAndDestroy( titleText );
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // Deduce if the slide set can be activated without showing the dialog.
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TInt CPslnWallpaperSlidesetDialog::DeduceActivationModeL()
       
   281     {
       
   282     TInt retValue = CPslnSlidesetDialogInterface::EPslnNeedsToBeConfigured;
       
   283     if ( CPslnSlidesetDialog::IsFeatureSupported( EPslnSlideSetFeatureRandom ) )
       
   284         {
       
   285         CRepository* repository = CRepository::NewL( KCRUidThemes );
       
   286         TInt slideSetType = KErrNotFound;
       
   287         repository->Get( KThemesWallpaperSlideSetType, slideSetType );
       
   288         delete repository;
       
   289         // If selection type is set to random, then direct activation
       
   290         // is possible.
       
   291         if ( slideSetType == KPslnSlideSetRandomIndex )
       
   292             {
       
   293             return CPslnSlidesetDialogInterface::EPslnDirectActivationPossible;
       
   294             }
       
   295         }
       
   296     // If slide set image list file exists, direct activation is allowed.
       
   297     if ( iModel->SlideSetImageFileExistsL( EAknsSrvInifileSSWP ) &&
       
   298          iModel->GetImageCountInSlideSetL( EAknsSrvInifileSSWP ) > 1 )
       
   299         {
       
   300         retValue = CPslnSlidesetDialogInterface::EPslnDirectActivationPossible;
       
   301         }
       
   302     return retValue;
       
   303     }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // Append one line to interval setting list - make language dependant conversion.
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CPslnWallpaperSlidesetDialog::AppendIntervalItemL( TInt aResourceText )
       
   310     {
       
   311     HBufC* text = iCoeEnv->AllocReadResourceLC( aResourceText );
       
   312     TPtr ptr = text->Des();
       
   313     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
   314     iIntervalItems->AppendL( ptr  );
       
   315     CleanupStack::PopAndDestroy();  // textFromResourceFile
       
   316     }
       
   317 
       
   318 // End of File