psln/Src/PslnWallpaperView.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:  Wallpaper view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // Psln specific
       
    21 #include <psln.rsg>
       
    22 #include "PslnModel.h"
       
    23 #include "PslnWallpaperView.h"
       
    24 #include "PslnWallpaperContainer.h"
       
    25 #include "PslnConst.h"
       
    26 #include "PslnUi.h"
       
    27 #include "PslnDRMImplementation.h"
       
    28 #include "PslnDebug.h"
       
    29 
       
    30 // General services
       
    31 #include <MGFetch.h>
       
    32 #include <AknSkinsInternalCRKeys.h>
       
    33 #include <centralrepository.h>
       
    34 #include <StringLoader.h>
       
    35 #include <AknGlobalNote.h>
       
    36 
       
    37 #ifdef RD_SLIDESHOW_WALLPAPER
       
    38 // Slide set wallpaper.
       
    39 #include <pslnslidesetwallpaperdialog.h>
       
    40 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    41 #include <ecom/resolver.h>
       
    42 #endif // RD_SLIDESHOW_WALLPAPER
       
    43 
       
    44 // CONSTANTS
       
    45 // Granularity for wallpaper items.
       
    46 const TInt KPslnFileArrayGranularity = 4;
       
    47 // Index of selected file item from MGFetch.
       
    48 const TInt KPslnSelectedFile = 0;
       
    49 
       
    50 // Index of current wallpaper item selection.
       
    51 enum TPslnWallpaperSelection
       
    52     {
       
    53     EPslnNoneWP = 0,
       
    54     EPslnUserDefinedWP,
       
    55     EPslnSlideSetWP
       
    56     };
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // C++ default constructor can NOT contain any code, that might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPslnWallpaperView::CPslnWallpaperView()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CPslnWallpaperView::ConstructL()
       
    73     {
       
    74     PSLN_TRACE_DEBUG("CPslnWallpaperView::ConstructL BEGIN");
       
    75     BaseConstructL( R_PSLN_WALLPAPER_VIEW );
       
    76 
       
    77     iNaviPaneContext = iPslnUi->PslnTabGroup();
       
    78 
       
    79     iWallpaperRepository = CRepository::NewL( KCRUidPersonalisation );
       
    80     iWallpaperNotifier = CCenRepNotifyHandler::NewL(
       
    81         *this,
       
    82         *iWallpaperRepository,
       
    83         CCenRepNotifyHandler::EIntKey,
       
    84         KPslnWallpaperType );
       
    85     iWpDlgRunnig = EFalse;
       
    86     PSLN_TRACE_DEBUG("CPslnWallpaperView::ConstructL END");
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Two-phased constructor.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CPslnWallpaperView* CPslnWallpaperView::NewLC()
       
    94     {
       
    95     CPslnWallpaperView* self = new (ELeave) CPslnWallpaperView();
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     return self;
       
    99     }
       
   100 
       
   101 // Destructor
       
   102 CPslnWallpaperView::~CPslnWallpaperView()
       
   103     {
       
   104     if ( iWallpaperNotifier )
       
   105         {
       
   106         iWallpaperNotifier->StopListening();
       
   107         }
       
   108     delete iWallpaperNotifier;
       
   109     delete iWallpaperRepository;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPslnWallpaperView::Id
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TUid CPslnWallpaperView::Id() const
       
   117     {
       
   118     return KPslnWallpaperView;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CPslnWallpaperView::HandleCommandL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void CPslnWallpaperView::HandleCommandL( TInt aCommand )
       
   126     {
       
   127     if ( aCommand == EAknSoftkeyOk ||
       
   128          aCommand == EPslnCmdAppSetWallpaper ||
       
   129          aCommand == EPslnCmdAppChangeWallpaper ||
       
   130          aCommand == EPslnCmdWallpaperConfigure )
       
   131         {
       
   132         if ( iContainer )
       
   133             {
       
   134             TInt setBgImage = KErrNone;
       
   135             // If User specified is selected.
       
   136             switch ( iContainer->CurrentItemIndex() )
       
   137                 {
       
   138                 case EPslnUserDefinedWP:
       
   139                     {
       
   140                     if ( iWpDlgRunnig )
       
   141                         {
       
   142                         return;
       
   143                         }
       
   144                     if ( !ShowBackgroundImageListL() )
       
   145                         {
       
   146                         return;
       
   147                         }
       
   148                     iModel->SetCurrentPropertyTypeL(
       
   149                         KPslnBgIdleSettingId,
       
   150                         EPslnUserDefinedWP );
       
   151                     }
       
   152                     break;
       
   153                 case EPslnNoneWP:
       
   154                     if ( iActiveWallpaper != EPslnNoneWP )
       
   155                         {
       
   156                         iModel->SetCurrentPropertyTypeL(
       
   157                             KPslnBgIdleSettingId,
       
   158                             EPslnNoneWP );
       
   159                         setBgImage = iModel->SetBackgroundImagePath( KNullDesC );
       
   160                         if ( setBgImage != KErrNone )
       
   161                             {
       
   162                             iPslnUi->HandleImageErrorsL( setBgImage );
       
   163                             }
       
   164                         }
       
   165                     else
       
   166                         {
       
   167                         // No need to do anything.
       
   168                         return;
       
   169                         }
       
   170                     break;
       
   171                 case EPslnSlideSetWP:
       
   172                     {
       
   173 #ifdef RD_SLIDESHOW_WALLPAPER
       
   174                     if ( iWpDlgRunnig )
       
   175                         {
       
   176                         //Try not run slideset dialog more than once.
       
   177                         return;
       
   178                         }
       
   179                     RImplInfoPtrArray array;
       
   180                     const TUid wallpaperUid = { 0x102823AD };
       
   181                     const TEComResolverParams emptyParams;
       
   182                     REComSession::ListImplementationsL(
       
   183                         wallpaperUid,
       
   184                         emptyParams,
       
   185                         KRomOnlyResolverUid,
       
   186                         array );
       
   187                     CleanupResetAndDestroyPushL( array );
       
   188 
       
   189                     CImplementationInformation* info = array[ KPslnWallpaperSlideSettingDialog ];
       
   190                     TUid implUid = info->ImplementationUid();
       
   191 
       
   192                     CPslnSlidesetDialogInterface* plugin =
       
   193                         CPslnSlidesetDialogInterface::NewL( implUid );
       
   194                     if ( aCommand == EPslnCmdWallpaperConfigure )
       
   195                         {
       
   196                         plugin->SetDialogFlag(
       
   197                             CPslnSlidesetDialogInterface::EPslnLaunchMode,
       
   198                             CPslnSlidesetDialogInterface::EPslnConfigureOnly );
       
   199                         }
       
   200                     if ( aCommand == EPslnCmdAppSetWallpaper &&
       
   201                          plugin->GetDialogFlag(
       
   202                             CPslnSlidesetDialogInterface::EPslnConfigurability ) ==
       
   203                                 CPslnSlidesetDialogInterface::EPslnDirectActivationPossible )
       
   204                         {
       
   205                         delete plugin; // just delete the plugin as it is not needed.
       
   206                         iWallpaperRepository->Set( KPslnWallpaperType, EPslnSlideSetWP );
       
   207                         UpdateCurrentItem();
       
   208                         }
       
   209                     else
       
   210                         {
       
   211                         iWpDlgRunnig = ETrue;
       
   212                         plugin->ExecuteDialogLD();
       
   213                         iWpDlgRunnig = EFalse;
       
   214                         }
       
   215 
       
   216                     plugin = NULL;
       
   217                     CleanupStack::PopAndDestroy(); // array
       
   218 
       
   219                     // Plugin stores wallpaper type, if it deems that the user selection is valid.
       
   220 
       
   221 #endif // RD_SLIDESHOW_WALLPAPER
       
   222                     }
       
   223                     break;
       
   224                 default:
       
   225                     break;
       
   226                 }
       
   227 
       
   228             // Update container.
       
   229             static_cast<CPslnWallpaperContainer*>
       
   230                 (iContainer)->UpdateListBoxL();
       
   231             CheckMiddleSoftkeyLabelL();
       
   232             }
       
   233         }
       
   234     else
       
   235         {
       
   236     	if ( ( aCommand == EAknSoftkeyBack ) && iWpDlgRunnig )
       
   237     		{
       
   238     		return;
       
   239     		}
       
   240         iPslnUi->HandleCommandL( aCommand );
       
   241         }
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // When this method is called, view checks based on highlight focus, if the MSK
       
   246 // label is correct.
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 void CPslnWallpaperView::CheckMiddleSoftkeyLabelL()
       
   250     {
       
   251     // First remove any prevous commands.
       
   252     RemoveCommandFromMSK();
       
   253 
       
   254     if ( iContainer )
       
   255         {
       
   256         iCurrentItem = iContainer->CurrentItemIndex();
       
   257         }
       
   258 
       
   259     // Set MSK label.
       
   260     if ( iActiveWallpaper != iCurrentItem )
       
   261         {
       
   262         // Set middle softkey as Apply, if:
       
   263         // a) 'None' is selected
       
   264         // b) highlight is on inactive selection
       
   265         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   266             R_PSLN_MSK_ACTIVATE,
       
   267             EPslnCmdAppSetWallpaper );
       
   268         }
       
   269      else if (  iActiveWallpaper == 0 )
       
   270         {
       
   271         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   272                 R_PSLN_MSK_DUMMY,
       
   273                 EPslnCmdEmptyCommand );
       
   274         }
       
   275     else
       
   276         {
       
   277         // Otherwise set middle softkey as Change.
       
   278         CPslnBaseView::SetMiddleSoftKeyLabelL(
       
   279             R_PSLN_MSK_CHANGE,
       
   280             EPslnCmdAppChangeWallpaper );
       
   281         }
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // If wallpaper image has changed, update container.
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CPslnWallpaperView::HandleNotifyInt( TUint32 aId, TInt /*aNewValue*/ )
       
   289     {
       
   290     if ( ( aId == KPslnWallpaperType ) && iContainer )
       
   291         {
       
   292         TInt previousValue = UpdateCurrentItem();
       
   293         if ( iActiveWallpaper != previousValue )
       
   294             {
       
   295             UpdateContainer();
       
   296             }
       
   297         }
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // If the whole repository changes, update container.
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CPslnWallpaperView::HandleNotifyGeneric( TUint32 aId )
       
   305     {
       
   306     if ( ( aId == NCentralRepositoryConstants::KInvalidNotificationId ||
       
   307            aId == KPslnWallpaperType ) && iContainer )
       
   308         {
       
   309         TInt previousValue = UpdateCurrentItem();
       
   310         if ( iActiveWallpaper != previousValue )
       
   311             {
       
   312             UpdateContainer();
       
   313             }
       
   314         }
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // In case of error, try to re-start listening.
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CPslnWallpaperView::HandleNotifyError(
       
   322     TUint32 /*aId*/,
       
   323     TInt aError,
       
   324     CCenRepNotifyHandler* aHandler )
       
   325     {
       
   326     if ( ( aError != KErrNone ) && aHandler )
       
   327         {
       
   328         TRAP_IGNORE( aHandler->StartListeningL() );
       
   329         }
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CPslnWallpaperView::DoActivateL
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CPslnWallpaperView::DoActivateL(
       
   337             const TVwsViewId& aPrevViewId,
       
   338             TUid aCustomMessageId,
       
   339             const TDesC8& aCustomMessage )
       
   340     {
       
   341     PSLN_TRACE_DEBUG("CPslnWallpaperView::DoActivateL START");
       
   342     CPslnBaseView::DoActivateL(
       
   343         aPrevViewId,
       
   344         aCustomMessageId,
       
   345         aCustomMessage );
       
   346 
       
   347     // If view is directly activated (not through main view), update
       
   348     // tab group (and main view's active folder). The static views
       
   349     // have same UID as their tab index.
       
   350     if ( aPrevViewId.iAppUid != KUidPsln )
       
   351         {
       
   352         iPslnUi->UpdateTabIndex(
       
   353             KPslnWallpaperView.iUid,
       
   354             KPslnWallpaperView.iUid );
       
   355         }
       
   356 
       
   357     if ( iContainer )
       
   358         {
       
   359         UpdateCurrentItem();
       
   360         // Set highlight to selected item.
       
   361         iContainer->SetCurrentItemIndexAndDraw( iActiveWallpaper );
       
   362         }
       
   363     if ( iWallpaperNotifier )
       
   364         {
       
   365         iWallpaperNotifier->StartListeningL();
       
   366         }
       
   367     CheckMiddleSoftkeyLabelL();
       
   368     iWpDlgRunnig = EFalse;
       
   369     PSLN_TRACE_DEBUG("CPslnWallpaperView::DoActivateL END");
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CPslnWallpaperView::DynInitMenuPaneL
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CPslnWallpaperView::DynInitMenuPaneL(
       
   377     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   378     {
       
   379     if ( aResourceId == R_PSLN_WALLPAPER_MENUPANE )
       
   380         {
       
   381         if ( iContainer )
       
   382             {
       
   383             iCurrentItem = iContainer->CurrentItemIndex();
       
   384             }
       
   385         // Remove change if none is selected, or highlight is not in active item.
       
   386         if ( iActiveWallpaper != iCurrentItem )
       
   387             {
       
   388             aMenuPane->SetItemDimmed( EPslnCmdAppChangeWallpaper, ETrue );
       
   389             }
       
   390         else if ( iActiveWallpaper == 0 )
       
   391             {
       
   392                 aMenuPane->SetItemDimmed( EPslnCmdAppSetWallpaper, ETrue );
       
   393                 aMenuPane->SetItemDimmed( EPslnCmdAppChangeWallpaper, ETrue );
       
   394             }
       
   395         else
       
   396             {
       
   397             aMenuPane->SetItemDimmed( EPslnCmdAppSetWallpaper, ETrue );
       
   398             }
       
   399           
       
   400 #ifdef RD_SLIDESHOW_WALLPAPER
       
   401 
       
   402         if ( iCurrentItem != EPslnSlideSetWP )
       
   403             {
       
   404             aMenuPane->SetItemDimmed( EPslnCmdWallpaperConfigure, ETrue );
       
   405             }
       
   406 #endif // RD_SLIDESET_WALLPAPER
       
   407         }
       
   408     CPslnBaseView::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CPslnWallpaperView::HandleListBoxSelectionL
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CPslnWallpaperView::HandleListBoxSelectionL()
       
   416     {
       
   417     if ( iContainer )
       
   418         {
       
   419         iCurrentItem = iContainer->CurrentItemIndex();
       
   420         }
       
   421     HandleCommandL( EAknSoftkeyOk );
       
   422     }
       
   423     
       
   424 // -----------------------------------------------------------------------------
       
   425 // CPslnWallpaperView::HandleListBoxItemHighlightL
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 void CPslnWallpaperView::HandleListBoxItemHighlightL()
       
   429     {    
       
   430     }    
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // CPslnWallpaperView::NewContainerL
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 void CPslnWallpaperView::NewContainerL()
       
   437     {
       
   438     iContainer = new(ELeave) CPslnWallpaperContainer();
       
   439     iContainer->SetMiddleSoftkeyObserver( this );
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CPslnWallpaperView::SetTitlePaneL
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CPslnWallpaperView::SetTitlePaneL( TInt& aResourceId )
       
   447     {
       
   448 #ifdef RD_CONTROL_PANEL
       
   449     aResourceId = R_PSLN_TITLE_PANE_WALLPAPER;
       
   450 #endif //RD_CONTROL_PANEL
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CPslnWallpaperView::CbaExitEnabled
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 TInt CPslnWallpaperView::CbaResourceId( const TVwsViewId& /*aPrevViewId*/,TUid aCustomMessageId )
       
   458     {
       
   459     return aCustomMessageId.iUid ?
       
   460         R_AVKON_SOFTKEYS_OPTIONS_EXIT : R_AVKON_SOFTKEYS_OPTIONS_BACK;
       
   461     }
       
   462     
       
   463 // ---------------------------------------------------------------------------
       
   464 // CPslnWallpaperView::ShowBackgroundImageListL
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 TBool CPslnWallpaperView::ShowBackgroundImageListL()
       
   468     {
       
   469     PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL");
       
   470     TBool retVal = EFalse;
       
   471     CDesCArrayFlat* files =
       
   472         new (ELeave) CDesCArrayFlat( KPslnFileArrayGranularity );
       
   473     CleanupStack::PushL( files );
       
   474     CPslnDRMImplementation* verifier = NULL;
       
   475     verifier = CPslnDRMImplementation::NewL();
       
   476     CleanupStack::PushL( verifier );
       
   477 
       
   478     PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL MGFetch");
       
   479     iWpDlgRunnig = ETrue;
       
   480     TBool selected = EFalse;
       
   481     TRAPD( err,selected = MGFetch::RunL( *files, EImageFile, EFalse, verifier ) );
       
   482     iWpDlgRunnig = EFalse;
       
   483     User::LeaveIfError( err );
       
   484     if ( !verifier )
       
   485         {
       
   486         PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL DRM Error");
       
   487         }
       
   488 
       
   489     else if( selected && ( files->MdcaCount() > 0 ) )
       
   490         {
       
   491         PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL Fetch successful");
       
   492         TInt setBgImage = iModel->SetBackgroundImagePath(
       
   493                 files->MdcaPoint( KPslnSelectedFile ) );
       
   494         if ( setBgImage != KErrNone )
       
   495             {
       
   496             if ( setBgImage == KLeaveExit )
       
   497                 {
       
   498                 User::Leave( KLeaveExit );
       
   499                 }
       
   500             else
       
   501                 {    
       
   502                 iPslnUi->HandleImageErrorsL( setBgImage );
       
   503                 }
       
   504             }
       
   505         else
       
   506             {
       
   507             // Image selected, no DRM issues.
       
   508             retVal = ETrue;
       
   509             }
       
   510         CheckMiddleSoftkeyLabelL();
       
   511         }
       
   512     else
       
   513         {
       
   514         PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL Fetch cancelled");
       
   515         }
       
   516 
       
   517     CleanupStack::PopAndDestroy( 2, files ); // verifier, files
       
   518 
       
   519     PSLN_TRACE_DEBUG("CPslnWallpaperView::ShowBackgroundImageListL METHOD COMPLETED");
       
   520     return retVal;
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // Updates the container.
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 void CPslnWallpaperView::UpdateContainer()
       
   528     {
       
   529     PSLN_TRACE_DEBUG("CPslnWallpaperView::UpdateContainer START");
       
   530     if ( iContainer )
       
   531         {
       
   532         TRAP_IGNORE( static_cast<CPslnWallpaperContainer*>
       
   533                 (iContainer)->UpdateListBoxL();
       
   534             CheckMiddleSoftkeyLabelL();
       
   535             );
       
   536         }
       
   537     PSLN_TRACE_DEBUG("CPslnWallpaperView::UpdateContainer END");
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // Removes unnecessary commands from Middle softkey.
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CPslnWallpaperView::RemoveCommandFromMSK()
       
   545     {
       
   546     CEikButtonGroupContainer* cbaGroup = Cba();
       
   547     if ( cbaGroup )
       
   548         {
       
   549         cbaGroup->RemoveCommandFromStack( KPslnMSKControlID, EPslnCmdAppSetWallpaper );
       
   550         cbaGroup->RemoveCommandFromStack( KPslnMSKControlID, EPslnCmdAppChangeWallpaper );
       
   551         }
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // Updates current item.
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 TInt CPslnWallpaperView::UpdateCurrentItem()
       
   559     {
       
   560     TInt previousValue = iActiveWallpaper;
       
   561     iActiveWallpaper = iModel->CurrentPropertyIndex( KPslnBgIdleSettingId );
       
   562     return previousValue;
       
   563     }
       
   564 
       
   565 //  End of File