psln/Src/PslnUi.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2002-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:  UI class of Psln.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "PslnUi.h"
       
    22 
       
    23 #include <barsread.h>
       
    24 #include <StringLoader.h>
       
    25 
       
    26 // Navi pane, Title Pane & Tab groups
       
    27 #include <aknnavi.h>
       
    28 #include <aknnavide.h>
       
    29 #include <akntitle.h>
       
    30 
       
    31 // Notes & Dialogs
       
    32 #include <AknGlobalNote.h>
       
    33 #include <aknnotewrappers.h>
       
    34 
       
    35 // DRM.
       
    36 #include <DRMHelper.h>
       
    37 #include <DRMRights.h>
       
    38 
       
    39 // Psln specific.
       
    40 #include <psln.rsg>
       
    41 #include "PslnModel.h"
       
    42 #include "PslnSkinEntry.h"
       
    43 #include "PslnFeatures.h"
       
    44 #include "PslnSoundActivator.h"
       
    45 #include "pslntaskactivatesounds.h"
       
    46 #include "pslntaskgenericupdate.h"
       
    47 #include "pslnidletaskcreateviews.h"
       
    48 #include "PslnConst.h"
       
    49 #include "PslnDebug.h"
       
    50 #include "PslnModel.h"
       
    51 #include "PslnPropertySubscriber.h"
       
    52 
       
    53 // Views
       
    54 #include "PslnMainView.h"
       
    55 #include "PslnGeneralThemeView.h"
       
    56 #include "PslnScreenSaverView.h"
       
    57 #include "PslnWallpaperView.h"
       
    58 
       
    59 // Framework
       
    60 #include "PslnPluginHandler.h"
       
    61 #include <pslnfwplugininterface.h>
       
    62 #include <pslnfwbaseview.h>
       
    63 
       
    64 // Help texts
       
    65 #include <hlplch.h>
       
    66 #include <csxhelp/skins.hlp.hrh>
       
    67 #include <UsbWatcherInternalPSKeys.h>           // KPSUidUsbWatcher
       
    68 #include <usbpersonalityids.h>                  // Usb Personality Ids
       
    69 
       
    70 // Sets internal state correctly when leave occurs in skin changing.
       
    71 
       
    72 // Handles application exit correctly when leave occurs in exiting.
       
    73 void HandleExitLeave( TAny* aPtr )
       
    74     {
       
    75     CPslnUi* psln = static_cast<CPslnUi*>(aPtr);
       
    76     psln->HandleCmdExitLeave();
       
    77     }
       
    78 
       
    79 // ========================= MEMBER FUNCTIONS ================================
       
    80 // ---------------------------------------------------------------------------
       
    81 // C++ constructor can NOT contain any code, that might leave.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CPslnUi::CPslnUi() : iPslnUiStatus ( EPslnCreated )
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Symbian two-phased constructor.
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CPslnUi::ConstructL()
       
    93     {
       
    94     PSLN_TRACE_DEBUG1("CPslnUi::ConstructL, Start:%d", User::NTickCount() );
       
    95 
       
    96     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
    97     EnableExternalViewSwitches(ETrue);
       
    98 
       
    99     // Create ECOM plugin loader.
       
   100     PSLN_TRACE_DEBUG("CPslnUi::ConstructL PluginHandler");
       
   101     iPluginHandler = CPslnPluginHandler::NewL( this );
       
   102 
       
   103     PSLN_TRACE_DEBUG("CPslnUi::ConstructL Model");
       
   104     // Force creation of model, since it is anyway created when ANY view is
       
   105     // activated.
       
   106     CreateModelL();
       
   107 
       
   108     PSLN_TRACE_DEBUG("CPslnUi::ConstructL StatusPane");
       
   109     // Show tabs for main views from resources
       
   110     CEikStatusPane* sp = StatusPane();
       
   111     if ( sp )
       
   112         {
       
   113         // Fetch pointer to the default navi pane control
       
   114         iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(
       
   115             TUid::Uid(EEikStatusPaneUidNavi));
       
   116         }
       
   117 
       
   118     // New main view
       
   119     PSLN_TRACE_DEBUG("CPslnUi::ConstructL View-Main");
       
   120     CPslnMainView* view = CPslnMainView::NewLC();
       
   121     AddViewL( view );          // transfer ownership to CAknViewAppUi
       
   122     CleanupStack::Pop( view ); // the view has to be popped from cleanupstack here
       
   123     iMainView = view;
       
   124     SetDefaultViewL( *view );
       
   125 
       
   126     iIdleActivateSkin = CIdle::NewL( CActive::EPriorityIdle );
       
   127     iIdleUpdateSkin = CIdle::NewL( CActive::EPriorityIdle );
       
   128     
       
   129     PSLN_TRACE_DEBUG("CPslnUi::ConstructL OK");
       
   130     User::LeaveIfError( iEnableUSBWatchProperty.Attach(
       
   131           KPSUidUsbWatcher, KUsbWatcherSelectedPersonality) );
       
   132     iUSBWatchSubscriber = new (ELeave) CPslnPropertySubscriber(
       
   133         TCallBack(USBCallBackL, this), iEnableUSBWatchProperty );
       
   134     iUSBWatchSubscriber->Subscribe();
       
   135     
       
   136     
       
   137     TInt value = KErrNone;
       
   138     iEnableUSBWatchProperty.Get(value);
       
   139     if (value == KUsbPersonalityIdMS)
       
   140         {
       
   141         iUSBAttached = ETrue;
       
   142         }
       
   143     else
       
   144         {
       
   145         iUSBAttached = EFalse;
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Destructor
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 CPslnUi::~CPslnUi()
       
   154     {
       
   155     PSLN_TRACE_DEBUG("CPslnUi::Destructor");
       
   156 
       
   157     // Reset skin info when exiting normally. This prevents model class
       
   158     // from trying to revert back to previous skin.
       
   159     if ( iView && iView->Id().iUid == KPslnMainView2.iUid )
       
   160         {
       
   161         // It is possible that Model is not created, if exiting immediately after
       
   162         // application launch. So first check that Model is created.
       
   163         if ( iModel )
       
   164             {
       
   165             TInt currentlySelected = iModel->ActiveSkinIndex();
       
   166             iModel->SetCurrentSelectedSkinIndex( currentlySelected );
       
   167             }
       
   168         }
       
   169     delete iModel;
       
   170     // This nullification is needed, since external DLL's may try to access
       
   171     // model through view framework and it might succeed even if model and UI
       
   172     // classes are already deleted, but external DLLs aren't.
       
   173     // This is due to that model reference is passed as a pointer due to delayed
       
   174     // construction - it is not available at the time when view is constructed.
       
   175     iModel = NULL;
       
   176     delete iDecoratedTabGroup;
       
   177 
       
   178     if ( iPluginHandler )
       
   179         {
       
   180         delete iPluginHandler;
       
   181         }
       
   182 
       
   183     delete iIdleTask;
       
   184     delete iIdleActivateSkin;
       
   185     delete iIdleUpdateSkin;
       
   186     
       
   187     
       
   188     if( iUSBWatchSubscriber )
       
   189         {
       
   190         iUSBWatchSubscriber->Cancel();
       
   191         }
       
   192     iEnableUSBWatchProperty.Close();
       
   193     delete iUSBWatchSubscriber;
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // Handles event when focus loss or gain.
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CPslnUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination )
       
   201     {
       
   202     PSLN_TRACE_DEBUG("CPslnUi::HandlwWSEvent");
       
   203     if ( iView )
       
   204         {
       
   205         TInt eventType = aEvent.Type();
       
   206         TUid currentView = iView->Id();
       
   207 
       
   208         // do this everytime when foreground gained.
       
   209         if ( ( currentView.iUid == KPslnGeneralView.iUid ) &&
       
   210              ( eventType == EEventFocusGained ) &&
       
   211              ( GetStatus( EPslnListUpdateNeeded )  ||
       
   212                GetStatus( EPslnProtectedSkinInList ) ) && IsForeground() )
       
   213             {
       
   214             PSLN_TRACE_DEBUG("CPslnUi::HandlwWSEvent Update list");
       
   215             SetStateOff( EPslnListUpdateNeeded );
       
   216             DoCreateWaitNoteL();
       
   217             }
       
   218         }
       
   219     CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Handles commands directed to this class.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CPslnUi::HandleCommandL( TInt aCommand )
       
   227     {
       
   228     PSLN_TRACE_DEBUG1("CPslnUi::HandleCommand %d", aCommand );
       
   229     switch ( aCommand )
       
   230         {
       
   231         //both exit commands should do the same thing
       
   232         case EEikCmdExit:
       
   233         case EAknCmdExit:
       
   234         case EAknSoftkeyExit:
       
   235             HandleCmdExitL();
       
   236             break;
       
   237 
       
   238         case EPslnCmdAppActivate:
       
   239             {
       
   240             if (!iIdleActivateSkin->IsActive())
       
   241                 {
       
   242                 iIdleActivateSkin->Start(TCallBack( DoActivateSkinL, this ));
       
   243                 }
       
   244             }
       
   245             break;
       
   246         case EPslnCmdAppDownload:
       
   247             DownloadSkinL();
       
   248             break;
       
   249         case EAknCmdHelp:
       
   250         case EPslnCmdAppHelp:
       
   251             {
       
   252             HlpLauncher::LaunchHelpApplicationL(
       
   253                 iEikonEnv->WsSession(), AppHelpContextL());
       
   254             }
       
   255             break;
       
   256         case EAknSoftkeyBack:
       
   257             // If General view is active and Back key is
       
   258             // pressed and there is skin activation ongoing
       
   259             // set internal state off.
       
   260             if ( iView && GetStatus( EPslnSkinChangeRequested ) &&
       
   261                    ( iView->Id().iUid == KPslnGeneralView.iUid )  )
       
   262                 {
       
   263                 SetStateOff( EPslnSkinChangeRequested );
       
   264                 }
       
   265             ActivateLocalViewL( KPslnMainView2 );
       
   266             break;
       
   267         default:
       
   268             CAknViewAppUi::HandleCommandL( aCommand );
       
   269             break;
       
   270         }
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CPslnUi::HandleResourceChangeL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CPslnUi::HandleResourceChangeL( TInt aType )
       
   278     {
       
   279     PSLN_TRACE_DEBUG("CPslnUi::HandleResourceChangeL");
       
   280     if (  iView && !GetStatus( EPslnSkinChangeRequested ) &&
       
   281           iView->Id().iUid == KPslnGeneralView.iUid &&
       
   282           aType == KAknsMessageSkinChange )
       
   283         {
       
   284         iGeneralThemeView->UpdateSkinListItemsDColumnOnlyL();
       
   285         }
       
   286     CAknViewAppUi::HandleResourceChangeL( aType );
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CPslnUi::ActivateLocalViewL
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CPslnUi::ActivateLocalViewL( TUid aViewId )
       
   294     {
       
   295     if ( GetStatus( EPslnListUpdateNeeded ) &&
       
   296          ( aViewId.iUid == KPslnGeneralView.iUid ) )
       
   297         {
       
   298         PSLN_TRACE_DEBUG("CPslnUi::ActivateLocalViewL update list");
       
   299         SetStateOff( EPslnListUpdateNeeded );
       
   300         DoCreateWaitNoteL();
       
   301         }
       
   302     CAknViewAppUi::ActivateLocalViewL( aViewId );
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CPslnUi::SkinContentChanged
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CPslnUi::SkinContentChanged()
       
   310     {
       
   311     PSLN_TRACE_DEBUG("CPslnUi::SkinContentChanged");
       
   312     if ( !iView || iView->Id().iUid != KPslnGeneralView.iUid  )
       
   313         {
       
   314         SetStateOn( EPslnListUpdateNeeded );
       
   315         }
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CPslnUi::SkinConfigurationChanged
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CPslnUi::SkinConfigurationChanged(
       
   323     const TAknsSkinStatusConfigurationChangeReason aReason )
       
   324     {
       
   325     PSLN_TRACE_DEBUG("CPslnUi::SkinConfigurationChanged");
       
   326     TRAPD( err, SkinConfigurationChangedL( aReason ) );
       
   327     if ( err != KErrNone )
       
   328         {
       
   329         TRAP_IGNORE( iGeneralThemeView->UpdateSkinListItemsL() );
       
   330         TRAP_IGNORE( ToggleScreenBlankerL( EFalse, EFalse ) );
       
   331         }
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CPslnUi::SkinPackageChanged
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CPslnUi::SkinPackageChanged(
       
   339     const TAknsSkinStatusPackageChangeReason aReason )
       
   340     {
       
   341     PSLN_TRACE_DEBUG("CPslnUi::SkinPackageChanged");
       
   342     if ( aReason == EAknsSkinStatusPackageListUpdate )
       
   343         {
       
   344         if ( !iView || iView->Id().iUid != KPslnGeneralView.iUid )
       
   345             {
       
   346             SetStateOn( EPslnListUpdateNeeded );
       
   347             }
       
   348         else
       
   349             {
       
   350             PSLN_TRACE_DEBUG("CPslnUi::SkinPackageChanged update list");
       
   351             //To Fix Defect:ESNN-7CXCT2:Themes: Layout is incorrect 
       
   352             //when removing memory card which the active theme is installed in.
       
   353             //DoCreateWaitNoteL take too much time and stop the skin refresh.
       
   354             //Need to wait for the Skin Server finish its work,so we use CIdle.
       
   355             //Also we need User::After to delay some time to make sure 
       
   356             //iIdleUpdateSkin start late enough.
       
   357             User::After(KPslnUpdateSkinDelay);
       
   358             if (!iIdleUpdateSkin->IsActive())
       
   359                 {
       
   360                 iIdleUpdateSkin->Start(TCallBack( DoCreateWaitNoteL, this ));
       
   361                 }
       
   362             SetStateOff( EPslnListUpdateNeeded );
       
   363             }
       
   364         }
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // Return model pointer.
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 CPslnModel* CPslnUi::Model() const
       
   372     {
       
   373     return iModel;
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // Updates tab group to current tab index
       
   378 // The parameters are optional.
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 #ifdef RD_CONTROL_PANEL
       
   382 void CPslnUi::UpdateTabIndex( const TInt aMyId, const TInt /*aMyTabIndex*/ )
       
   383 #else
       
   384 void CPslnUi::UpdateTabIndex( const TInt /*aMyId*/, const TInt aMyTabIndex )
       
   385 #endif // RD_CONTROL_PANEL
       
   386     {
       
   387 #ifdef RD_CONTROL_PANEL
       
   388     if ( aMyId != KErrNotFound )
       
   389         {
       
   390         if ( iMainView )
       
   391             {
       
   392             iMainView->SetActiveFolder( TUid::Uid( aMyId ) );
       
   393             }
       
   394         }
       
   395 #else
       
   396     if ( aMyTabIndex != KErrNotFound )
       
   397         {
       
   398         if ( iTabGroup )
       
   399             {
       
   400             iTabGroup->SetActiveTabById( aMyTabIndex );
       
   401             }
       
   402         }
       
   403     if ( ( iView == iMainView ) && iTabGroup && iMainView )
       
   404         {
       
   405         iTabGroup->SetActiveTabByIndex( iMainView->ActiveView() );
       
   406         }
       
   407 #endif //RD_CONTROL_PANEL
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // Creates given view.
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 void CPslnUi::CreateViewL( TUid aViewUid )
       
   415     {
       
   416     PSLN_TRACE_DEBUG1("CPslnUi::CreateViewL, Start:%d", User::NTickCount() );
       
   417     TBitFlags views = ViewSupport();
       
   418 
       
   419 if ( aViewUid == KPslnWallpaperView &&
       
   420               !GetStatus( EPslnWallpaperViewCreated ) )
       
   421         {
       
   422 
       
   423         if ( views.IsSet( EPslnWallpaperView ) )
       
   424             {
       
   425             CAknView* view = CPslnWallpaperView::NewLC();
       
   426             AddViewL( view );          // transfer ownership to CAknViewAppUi
       
   427             CleanupStack::Pop( view );
       
   428 
       
   429             SetStateOn( EPslnWallpaperViewCreated );
       
   430 
       
   431             PSLN_TRACE_DEBUG("CPslnUi::CreateViewL - Wallpaper");
       
   432             PSLN_TRACE_DEBUG1("CPslnUi::CreateViewL, End:%d", User::NTickCount() );
       
   433             }
       
   434         }
       
   435     // Screensaver view.
       
   436     else if ( aViewUid == KPslnScreenSaverView &&
       
   437               !GetStatus( EPslnScreenSaverViewCreated ) )
       
   438         {
       
   439         if ( views.IsSet( EPslnScreensaverView ) )
       
   440             {
       
   441             CAknView* view = CPslnScreenSaverView::NewLC();
       
   442             AddViewL( view );          // transfer ownership to CAknViewAppUi
       
   443             CleanupStack::Pop( view );
       
   444 
       
   445             SetStateOn( EPslnScreenSaverViewCreated );
       
   446 
       
   447             PSLN_TRACE_DEBUG("CPslnUi::CreateViewL - ScreenSaver");
       
   448             PSLN_TRACE_DEBUG1("CPslnUi::CreateViewL, End:%d", User::NTickCount() );
       
   449             }
       
   450         }
       
   451     // General view.
       
   452     else if ( aViewUid.iUid == KPslnGeneralView.iUid &&
       
   453               !GetStatus( EPslnGeneralViewCreated ) )
       
   454         {
       
   455         CAknView* view = CPslnGeneralThemeView::NewLC();
       
   456         AddViewL( view );          // transfer ownership to CAknViewAppUi
       
   457         iGeneralThemeView = static_cast< CPslnGeneralThemeView* >( view );
       
   458         CleanupStack::Pop( view );
       
   459 
       
   460         SetStateOn( EPslnGeneralViewCreated );
       
   461 
       
   462         PSLN_TRACE_DEBUG("CPslnUi::CreateViewL - General");
       
   463         PSLN_TRACE_DEBUG1("CPslnUi::CreateViewL, End:%d", User::NTickCount() );
       
   464         }
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // Return navi control container pointer.
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 CAknNavigationControlContainer* CPslnUi::NaviContainer() const
       
   472     {
       
   473     return iNaviPane;
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // Return tab group pointer.
       
   478 // ---------------------------------------------------------------------------
       
   479 //
       
   480 CAknNavigationDecorator* CPslnUi::PslnTabGroup()
       
   481     {
       
   482      if ( !GetStatus( EPslnTabGroupCreated ) )
       
   483          {
       
   484          TRAP_IGNORE( ConstructTabGroupL() );
       
   485          }
       
   486     return iDecoratedTabGroup;
       
   487     }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // Return plugin handler pointer.
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 CPslnPluginHandler* CPslnUi::PluginHandler() const
       
   494     {
       
   495     return iPluginHandler;
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // Adds new view to UI class, if the UI class is not already completed.
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 void CPslnUi::AddNewViewL( CAknView* aNewView )
       
   503     {
       
   504     if ( GetStatus( EPslnCreated ) )
       
   505         {
       
   506         if ( aNewView && !View( aNewView->Id() ) )
       
   507             {
       
   508             AddViewL( aNewView );
       
   509             }
       
   510         }
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // When this method is called, UI class considers itself to be complete.
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 void CPslnUi::AllViewsDone()
       
   518     {
       
   519     SetStateOff( EPslnCreated );
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // Handles errors that occur when handling images.
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 void CPslnUi::HandleImageErrorsL( TInt aError )
       
   527     {
       
   528     PSLN_TRACE_DEBUG1("CPslnUi::HandleImageError %d", aError );
       
   529     if ( aError == KErrNoMemory || aError == KErrTooBig )
       
   530         {
       
   531         // Show information note
       
   532         HBufC* prompt = iCoeEnv->AllocReadResourceLC( R_PSLN_IMAGE_TOO_LARGE );
       
   533         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   534         note->ExecuteLD( *prompt );
       
   535         CleanupStack::PopAndDestroy( prompt );
       
   536         }
       
   537     else if ( aError == KErrCancel || aError == KErrCouldNotConnect )
       
   538         {
       
   539         // Other error codes are ignored; as not real errors (i.e. KErrCancel),
       
   540         // or such errors that Psln cannot react to them (KErrCouldNotConnect)
       
   541         }
       
   542     else
       
   543         {
       
   544         // Show information note
       
   545         HBufC* prompt = iCoeEnv->AllocReadResourceLC( R_PSLN_IMAGE_CORRUPTED );
       
   546         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   547         note->ExecuteLD( *prompt );
       
   548         CleanupStack::PopAndDestroy( prompt );
       
   549         }
       
   550     }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // Indicate that tab group has been changed.
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 #ifndef RD_CONTROL_PANEL
       
   557 void CPslnUi::TabChangedL( TInt aIndex )
       
   558     {
       
   559     PSLN_TRACE_DEBUG("CPslnUi::TabChangedL 1" );
       
   560     // If it is one of the dynamically created views, check if the view is
       
   561     // already created. If view is not created, create it.
       
   562     if ( aIndex == KPslnGeneralView.iUid )
       
   563         {
       
   564         if ( !GetStatus( EPslnGeneralViewCreated ) )
       
   565             {
       
   566             CreateViewL( KPslnGeneralView );
       
   567             }
       
   568         }
       
   569     else if ( aIndex == KPslnWallpaperView.iUid )
       
   570         {
       
   571         if ( !GetStatus( EPslnWallpaperViewCreated ) )
       
   572             {
       
   573             CreateViewL( KPslnWallpaperView );
       
   574             }
       
   575         }
       
   576     else if ( aIndex == KPslnScreenSaverView.iUid )
       
   577         {
       
   578         if ( !GetStatus( EPslnScreenSaverViewCreated ) )
       
   579             {
       
   580             CreateViewL( KPslnScreenSaverView );
       
   581             }
       
   582         }
       
   583     if ( iMainView )
       
   584         {
       
   585         iMainView->SetActiveFolder( aIndex );
       
   586         ActivateLocalViewL( TUid::Uid( iMainView->ActiveFolderUid() ) );
       
   587         }
       
   588     }
       
   589 #endif //RD_CONTROL_PANEL
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // Loads views when application is idle.
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 void CPslnUi::LoadViewsWhenIdleL()
       
   596     {
       
   597     if ( !iIdleTask )
       
   598         {
       
   599         iIdleTask = CPslnIdleTaskCreateViews::NewL( this );
       
   600         }
       
   601     }
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // Constructs the Tab group.
       
   605 // ---------------------------------------------------------------------------
       
   606 void CPslnUi::ConstructTabGroupL()
       
   607     {
       
   608 #ifdef RD_CONTROL_PANEL
       
   609     return;
       
   610 #else
       
   611     if ( GetStatus( EPslnTabGroupCreated ) )
       
   612         {
       
   613         // Tabgroup has already been created.
       
   614         return;
       
   615         }
       
   616     // Tabgroup has been read from resource and it were pushed to the navi pane.
       
   617     // Get pointer to the navigation decorator
       
   618     // and set this to be a MAknTabObserver.
       
   619     if ( iNaviPane )
       
   620         {
       
   621         iDecoratedTabGroup = iNaviPane->ResourceDecorator();
       
   622         }
       
   623     if ( iDecoratedTabGroup )
       
   624         {
       
   625         PSLN_TRACE_DEBUG("CPslnUi::ConstructTabGroupL DecoTabGrp");
       
   626         iTabGroup = static_cast <CAknTabGroup*>
       
   627             ( iDecoratedTabGroup->DecoratedControl() );
       
   628         iTabGroup->SetObserver( this );
       
   629         }
       
   630     TInt tabCount = 1; // index 0 = general view
       
   631     TBitFlags views = ViewSupport();
       
   632 
       
   633     // Update Tab group to contain default plugins.
       
   634     if ( iPluginHandler )
       
   635         {
       
   636         CPslnFWPluginInterface* plugin =
       
   637             iPluginHandler->GetPlugin( KPslnASPluginUid );
       
   638         if ( plugin )
       
   639             {
       
   640             AddPluginToTab( *plugin );
       
   641             static_cast <CPslnFWBaseView*>
       
   642                 (plugin)->SetNaviPaneDecorator( iDecoratedTabGroup );
       
   643             tabCount++; // index 1 = AS plugin
       
   644             }
       
   645         plugin = iPluginHandler->GetPlugin( KPslnAIPluginUid );
       
   646         if ( plugin )
       
   647             {
       
   648             AddPluginToTab( *plugin );
       
   649             static_cast <CPslnFWBaseView*>
       
   650                 (plugin)->SetNaviPaneDecorator( iDecoratedTabGroup );
       
   651             tabCount++; // index 2 = AI plugin
       
   652             }
       
   653         }
       
   654 
       
   655     // Add tabs for screen saver and wallpaper.
       
   656     if ( iTabGroup )
       
   657         {
       
   658         if ( views.IsSet( EPslnWallpaperView ) )
       
   659             {
       
   660             TResourceReader reader;
       
   661             iCoeEnv->CreateResourceReaderLC( reader, R_PSLN_WALLPAPER_TAB );
       
   662             iTabGroup->AddTabL( reader );
       
   663             CleanupStack::PopAndDestroy(); // reader - AppUi now owns this tab,
       
   664             tabCount++; // index 3 = Wallpaper view
       
   665             }
       
   666 
       
   667         if ( views.IsSet( EPslnScreensaverView ) )
       
   668             {
       
   669             TResourceReader reader2;
       
   670             iCoeEnv->CreateResourceReaderLC( reader2, R_PSLN_SCREENSAVER_TAB );
       
   671             iTabGroup->AddTabL( reader2 );
       
   672             CleanupStack::PopAndDestroy(); // reader2  - AppUi now owns this tab,
       
   673             tabCount++; // index 4 = Screensaver view
       
   674             }
       
   675         PSLN_TRACE_DEBUG("CPslnUi::ConstructTabGroupL Default Tabs added to TabGrp");
       
   676         }
       
   677 
       
   678     // Add rest of the plugins to tabs.
       
   679     if ( iPluginHandler )
       
   680         {
       
   681         // Fetch the plugin array.
       
   682         CArrayPtrFlat<CPslnFWPluginInterface>* pluginArray =
       
   683             iPluginHandler->GetPluginArray();
       
   684         CleanupStack::PushL( pluginArray );
       
   685         TInt pluginCount = pluginArray->Count();
       
   686         PSLN_TRACE_DEBUG1("CPslnUi::ConstructTabGroupL Plugin count=%d", pluginCount );
       
   687 
       
   688         // Go through all the plugins and add plugins to tab group.
       
   689         for ( TInt i = 0; i < pluginCount; i++ )
       
   690             {
       
   691             CPslnFWPluginInterface* plugin = pluginArray->operator[]( i );
       
   692 
       
   693             if ( !plugin )
       
   694                 {
       
   695                 PSLN_TRACE_DEBUG("CPslnUi::ConstructTabGroupL Plugin fails");
       
   696                 }
       
   697             // Default plugins can be skipped.
       
   698             else if ( plugin->Id().iUid == KPslnASPluginUid.iUid ||
       
   699                       plugin->Id().iUid == KPslnAIPluginUid.iUid )
       
   700                 {
       
   701                 PSLN_TRACE_DEBUG("CPslnUi::ConstructTabGroupL Plugin skipped");
       
   702                 }
       
   703             else
       
   704                 {
       
   705                 PSLN_TRACE_DEBUG1("CPslnUi::ConstructTabGroupL Plugin Id=%d", plugin->Id().iUid );
       
   706                 AddPluginToTab( *plugin );
       
   707                 static_cast <CPslnFWBaseView*>
       
   708                     (plugin)->SetNaviPaneDecorator( iDecoratedTabGroup );
       
   709                 // Inform to the plugin which tab index it is using.
       
   710                 static_cast <CPslnFWBaseView*>
       
   711                     (plugin)->SetTabIndex( tabCount++ );
       
   712                 PSLN_TRACE_DEBUG("CPslnUi::ConstructTabGroupL Plugin added to tab");
       
   713                 }
       
   714             }
       
   715         CleanupStack::Pop( pluginArray ); // plugin handler owns plugin array
       
   716         }
       
   717     // Push empty navi pane, so that tab group is not shown with default item (first),
       
   718     // if other than main view is activated externally.
       
   719     iNaviPane->PushDefaultL();
       
   720     SetStateOn( EPslnTabGroupCreated );
       
   721 #endif //RD_CONTROL_PANEL
       
   722     }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // Activates screen blanker. Note that second parameter is only used when
       
   726 // enabling blanker (i.e. first parameter is ETrue ).
       
   727 // ---------------------------------------------------------------------------
       
   728 void CPslnUi::ToggleScreenBlankerL( 
       
   729     const TBool& aToggleValue, const TBool& /*aStatusPaneVisible*/, const TBool& aRealAct )
       
   730     {
       
   731     TInt transitionEffectsValue = iModel->GetTransitionEffectStateL();
       
   732     if ( aToggleValue )
       
   733         {
       
   734         // Effects are enabled if value is NOT KMaxTInt.
       
   735         if( transitionEffectsValue != KMaxTInt )
       
   736             {
       
   737             if ( aRealAct )
       
   738                 {
       
   739                 iModel->TransEffect(EPslnTransitionEffectStartThemeActivation);
       
   740                 }
       
   741             else
       
   742                 {
       
   743                 iModel->TransEffect(EPslnTransitionEffectStartPreview);
       
   744                 }
       
   745             }
       
   746 //        else if ( iView && iView->MenuBar()->IsDisplayed() )
       
   747 //            {
       
   748 //            iView->MenuBar()->StopDisplayingMenuBar();
       
   749 //            }
       
   750         }
       
   751     else
       
   752         {
       
   753         // Effects are enabled if value is NOT KMaxTInt.
       
   754         if( transitionEffectsValue != KMaxTInt )
       
   755             {
       
   756             iModel->TransEffect(EPslnTransitionEffectStop);
       
   757             }
       
   758 //        else if ( iView && iView->MenuBar()->IsDisplayed() )
       
   759 //            {
       
   760 //            iView->MenuBar()->MenuPane()->DrawNow();
       
   761 //            }
       
   762         }
       
   763     }
       
   764 
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // Is this class able to handle a new skin activation related command.
       
   768 // ---------------------------------------------------------------------------
       
   769 TBool CPslnUi::IsReadyToHandleCommands()
       
   770     {
       
   771     return !GetStatus( EPslnSkinChangeRequested );
       
   772     }
       
   773 
       
   774 // ---------------------------------------------------------------------------
       
   775 // Ensure that Exit() is called when trying to exit and leave occurs.
       
   776 // ---------------------------------------------------------------------------
       
   777 void CPslnUi::HandleCmdExitLeave()
       
   778     {
       
   779     Exit();
       
   780     }
       
   781 
       
   782 // ---------------------------------------------------------------------------
       
   783 // Sets title pane back to default text.
       
   784 // ---------------------------------------------------------------------------
       
   785 void CPslnUi::SetTitleToDefaultL()
       
   786     {
       
   787     // Set default title back. But do not change title when application is about
       
   788     // to die.
       
   789     if ( iCoeEnv && Model() )
       
   790         {
       
   791         TResourceReader rReader;
       
   792         iCoeEnv->CreateResourceReaderLC( rReader, R_PSLN_SKIN_LIST_VIEW_TITLE );
       
   793         if ( iAvkonAppUi )
       
   794             {
       
   795             CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   796             if ( sp )
       
   797                 {
       
   798                 CAknTitlePane* title = static_cast<CAknTitlePane*>(
       
   799                     sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   800 
       
   801                 if ( title )
       
   802                     {
       
   803                     title->SetFromResourceL( rReader );
       
   804                     }
       
   805                 }
       
   806             }
       
   807         CleanupStack::PopAndDestroy(); // rReader
       
   808         }
       
   809     }
       
   810 
       
   811 // ---------------------------------------------------------------------------
       
   812 // Checks if a view has been created.
       
   813 // ---------------------------------------------------------------------------
       
   814 TBitFlags CPslnUi::ViewSupport()
       
   815     {
       
   816     // Initially all views are 'on'.
       
   817     TBitFlags viewFlags;
       
   818     viewFlags.SetAll();
       
   819     if ( GetStatus( EPslnViewSupportChecked ) )
       
   820         {
       
   821         if ( GetStatus( EPslnNoScreenSaverView ) )
       
   822             {
       
   823             viewFlags.Clear( EPslnScreensaverView );
       
   824             }
       
   825         if ( GetStatus( EPslnNoWallpaperView ) )
       
   826             {
       
   827             viewFlags.Clear( EPslnWallpaperView );
       
   828             }
       
   829         }
       
   830     else
       
   831         {
       
   832         TBool noWallpaperView = PslnFeatures::IsSupported( KPslnRemoveWallpaper );
       
   833         TBool noScreenSaverView = PslnFeatures::IsSupported( KPslnRemoveScreensaver );
       
   834         if ( noWallpaperView )
       
   835             {
       
   836             SetStateOn( EPslnNoWallpaperView );
       
   837             viewFlags.Clear( EPslnWallpaperView );
       
   838             }
       
   839         if ( noScreenSaverView )
       
   840             {
       
   841             SetStateOn( EPslnNoScreenSaverView );
       
   842             viewFlags.Clear( EPslnScreensaverView );
       
   843             }
       
   844         SetStateOn( EPslnViewSupportChecked );
       
   845         }
       
   846     return viewFlags;
       
   847     }
       
   848 
       
   849 // ---------------------------------------------------------------------------
       
   850 //
       
   851 // ---------------------------------------------------------------------------
       
   852 void CPslnUi::SetDRMProtectedSkinInSkinList(
       
   853     const TBool& aProtectedSkinInList )
       
   854     {
       
   855     if ( aProtectedSkinInList )
       
   856         {
       
   857         SetStateOn( EPslnProtectedSkinInList );
       
   858         }
       
   859     else
       
   860         {
       
   861         SetStateOff( EPslnProtectedSkinInList );
       
   862         }
       
   863     }
       
   864 
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 // Callback - USB status change.
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 TInt CPslnUi::USBCallBackL(TAny* aPtr)
       
   871     {
       
   872     CPslnUi* self = static_cast<CPslnUi*>(aPtr);
       
   873     if ( self )
       
   874         {
       
   875         self->HandleUSBCallBackL();
       
   876         }
       
   877     return KErrNone;
       
   878     }
       
   879     
       
   880     
       
   881     /**
       
   882     * USB Attach State.
       
   883     * @return ETrue when USB already attached, otherwise EFalse,
       
   884     */
       
   885 // ---------------------------------------------------------------------------
       
   886 // USB Attach State.
       
   887 // ---------------------------------------------------------------------------
       
   888 TBool CPslnUi::USBAttachState()
       
   889     {
       
   890     return iUSBAttached;
       
   891     }
       
   892 
       
   893 // ---------------------------------------------------------------------------
       
   894 // Called when a key is pressed and no other class has catched the event.
       
   895 // Handles only key events that are meant to control the tab group.
       
   896 // ---------------------------------------------------------------------------
       
   897 #ifdef RD_CONTROL_PANEL
       
   898 TKeyResponse CPslnUi::HandleKeyEventL(
       
   899     const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ )
       
   900 #else
       
   901 TKeyResponse CPslnUi::HandleKeyEventL(
       
   902     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   903 #endif // RD_CONTROL_PANEL
       
   904     {
       
   905     PSLN_TRACE_DEBUG("CPslnUi::HandleKeyEventL");
       
   906 
       
   907 #ifndef RD_CONTROL_PANEL
       
   908     // If tab group is not yet created, create it.
       
   909     if ( !GetStatus( EPslnTabGroupCreated ) )
       
   910         {
       
   911         ConstructTabGroupL();
       
   912         }
       
   913     iTabGroup = static_cast<CAknTabGroup*>
       
   914         ( iDecoratedTabGroup->DecoratedControl() );
       
   915 
       
   916     // Only forward key events to tabgroup when:
       
   917     //     1) TabGroup has been created (and is not NULL)
       
   918     //     2) Active view is not MainView (there is no tab group in Main)
       
   919     //     3) key event is either left key or right key
       
   920     if ( iTabGroup && iView && iView->Id().iUid != KPslnMainView2.iUid &&
       
   921          ( aKeyEvent.iScanCode == EStdKeyLeftArrow ||
       
   922            aKeyEvent.iScanCode == EStdKeyRightArrow ) )
       
   923         {
       
   924         PSLN_TRACE_DEBUG("CPslnUi::HandleKeyEventL forward event to Tab");
       
   925         // If preview is about to activate, cancel it.
       
   926         if ( GetStatus( EPslnSkinChangeRequested ) &&
       
   927              iView->Id().iUid == KPslnGeneralView.iUid )
       
   928             {
       
   929             SetStateOff( EPslnSkinChangeRequested );
       
   930             }
       
   931 
       
   932         return iTabGroup->OfferKeyEventL( aKeyEvent, aType );
       
   933         }
       
   934 #endif // !RD_CONTROL_PANEL
       
   935     return EKeyWasNotConsumed;
       
   936     }
       
   937 
       
   938 // ---------------------------------------------------------------------------
       
   939 // CPslnUi::SkinConfigurationChangedL
       
   940 // ---------------------------------------------------------------------------
       
   941 //
       
   942 void CPslnUi::SkinConfigurationChangedL(
       
   943     const TAknsSkinStatusConfigurationChangeReason aReason )
       
   944     {
       
   945     PSLN_TRACE_DEBUG1("CPslnUi::SkinConfigurationChangedL internal state before: %d", iPslnUiStatus );
       
   946     HBufC* errorBuf = NULL;
       
   947 
       
   948     switch( aReason )
       
   949         {
       
   950         // Skin activation failed due to OOM.
       
   951         // Set skin activation user activity off, so that subsequent attempts can be made.
       
   952         // Also, set error note text.
       
   953         // Finally, set skin activation attempt off and update skin list.
       
   954         case EAknsSkinStatusConfigurationFailedOOM:
       
   955             SetStateOff( EPslnSkinChangeRequested );
       
   956             errorBuf = StringLoader::LoadLC( R_PSLN_QTN_MEMLO_RAM_OUT_OF_MEM );
       
   957             if ( GetStatus( EPslnSkinActivated ) )
       
   958                 {
       
   959                 SetStateOff( EPslnSkinActivated );
       
   960                 DoCreateWaitNoteL();
       
   961                 }
       
   962             break;
       
   963         // Skin activation failed due to skin being corrupted.
       
   964         // Set skin activation user activity off, so that subsequent attempts can be made.
       
   965         // Also, set error note text.
       
   966         // Then set skin activation attempt off and update skin list.
       
   967         // Finally, activate default skin.
       
   968         case EAknsSkinStatusConfigurationFailedCorrupt:
       
   969             SetStateOff( EPslnSkinChangeRequested );
       
   970             iGeneralThemeView->HightlightDefaultSkin();
       
   971             errorBuf = StringLoader::LoadLC( R_PSLN_QTN_SKINS_ERROR_CORRUPTED );
       
   972             if ( GetStatus( EPslnSkinActivated ) )
       
   973                 {
       
   974                 SetStateOff( EPslnSkinActivated );
       
   975                 DoCreateWaitNoteL();
       
   976                 }
       
   977             SetStateOn( EPslnListUpdateNeeded );
       
   978             break;
       
   979         // Skin activation was success.
       
   980         // Set skin activation user activity off.
       
   981         // Show confirmation note about the skin change and set activation
       
   982         // request state off. Finally, check if there are sounds in the skin.
       
   983         case EAknsSkinStatusConfigurationDeployed:
       
   984             SetStateOff( EPslnSkinChangeRequested );
       
   985             if ( GetStatus( EPslnSkinActivated ) )
       
   986                 {
       
   987                 SetStateOff( EPslnSkinActivated );
       
   988                 SkinDeployedL();
       
   989                 }
       
   990             else // Theme changed by other app, update view.
       
   991                 {
       
   992                 iModel->PerformCompleteUpdateL();             
       
   993                 iGeneralThemeView->UpdateSkinListItemsL( iModel->ActiveSkinIndex() + 
       
   994                                 PslnFeatures::IsEnhancedEmbeddedLinksSupported() );
       
   995                 iGeneralThemeView->RemoveLocalSkinItems();
       
   996                 }
       
   997             
       
   998             if ( GetStatus( EPslnSoundActivationPending ) )
       
   999                 {
       
  1000                 SetStateOff( EPslnSoundActivationPending );
       
  1001                 ActivateSoundsL();
       
  1002                 }
       
  1003             ToggleScreenBlankerL( EFalse, EFalse );
       
  1004             break;
       
  1005         default:
       
  1006             break;
       
  1007         }
       
  1008 
       
  1009     if( errorBuf )
       
  1010         {
       
  1011         ShowErrorNoteL( *errorBuf );
       
  1012         CleanupStack::PopAndDestroy( errorBuf );
       
  1013         }
       
  1014     PSLN_TRACE_DEBUG1("CPslnUi::SkinConfigurationChangedL internal state after: %d", iPslnUiStatus );
       
  1015     }
       
  1016 
       
  1017 // ---------------------------------------------------------------------------
       
  1018 // Activate a Skin.
       
  1019 // ---------------------------------------------------------------------------
       
  1020 //
       
  1021 void CPslnUi::ActivateSkinL()
       
  1022     {
       
  1023     PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL");
       
  1024     TInt skinIndex = iModel->CurrentSelectedSkinIndex();
       
  1025 
       
  1026     CPslnSkinEntry* entry = iModel->VisibleSkin( skinIndex );
       
  1027     if( !entry )
       
  1028         {
       
  1029         SetStateOff( EPslnSkinChangeRequested );
       
  1030         return;
       
  1031         }
       
  1032 
       
  1033     TBool showWaitNote = EFalse;
       
  1034     TInt drmError = KErrNone;
       
  1035     HBufC* errorBuf = NULL;
       
  1036 
       
  1037     PSLN_TRACE_DEBUG1("CPslnUi::ActivateSkinL entry->Protection: %d", entry->Protection() );
       
  1038     switch ( entry->Protection() )
       
  1039         {
       
  1040         case EAknsSrvNoRights:
       
  1041             drmError = CDRMRights::ENoRights;
       
  1042             showWaitNote = ETrue;
       
  1043             break;
       
  1044         case EAknsSrvFutureRights:
       
  1045             drmError = CDRMRights::ERightsExpired;
       
  1046             break;
       
  1047         case EAknsSrvExpiredRights:
       
  1048             drmError = CDRMRights::ERightsExpired;
       
  1049             showWaitNote = ETrue;
       
  1050             break;
       
  1051         default :
       
  1052             break;
       
  1053         }
       
  1054 
       
  1055     // DRMHelper handles the error.
       
  1056     if ( drmError )
       
  1057         {
       
  1058         RAknsSrvSession skinsrv;
       
  1059         User::LeaveIfError( skinsrv.Connect() );
       
  1060         CleanupClosePushL( skinsrv );
       
  1061 
       
  1062         TInt fileserverhandle;
       
  1063         TInt filehandle;
       
  1064         fileserverhandle = skinsrv.OpenBitmapFile( entry->FullName(), filehandle );
       
  1065         RFile file;
       
  1066         User::LeaveIfError( file.AdoptFromServer( fileserverhandle, filehandle ) );
       
  1067         CleanupClosePushL( file );
       
  1068 
       
  1069         TInt returnCode = KErrNone;
       
  1070         PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL use DRMHelper to show the error note");
       
  1071         CDRMHelper* drmhelper = CDRMHelper::NewLC( *CCoeEnv::Static() );
       
  1072         returnCode = drmhelper->HandleErrorL(
       
  1073             drmError,
       
  1074             file );
       
  1075 
       
  1076         PSLN_TRACE_DEBUG1("CPslnUi::ActivateSkinL DRMHelper returns: %d", returnCode );
       
  1077         if ( returnCode && showWaitNote )
       
  1078             {
       
  1079             if ( GetStatus( EPslnListUpdateNeeded ) )
       
  1080                 {
       
  1081                 SetStateOff( EPslnListUpdateNeeded );
       
  1082                 DoCreateWaitNoteL();
       
  1083                 }
       
  1084             }
       
  1085         SetStateOff( EPslnSkinChangeRequested );
       
  1086         CleanupStack::PopAndDestroy( 3 ); // drmHelper, skinsrv, file
       
  1087         }
       
  1088     else
       
  1089         {
       
  1090         if ( entry->Protection() == EAknsSrvCountBased )
       
  1091             {
       
  1092             errorBuf = StringLoader::LoadLC( R_PSLN_QTN_DRM_PREV_RIGHTS_SET );
       
  1093             }
       
  1094         // Check for corruption.
       
  1095         if ( entry->IsCorrupted() )
       
  1096             {
       
  1097             PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL corrupt skin!");
       
  1098             errorBuf = StringLoader::LoadLC( R_PSLN_QTN_SKINS_ERROR_CORRUPTED );
       
  1099             }
       
  1100 
       
  1101         // Non-DRMHelper error handling.
       
  1102         if ( errorBuf )
       
  1103             {
       
  1104             SetStateOff( EPslnSkinChangeRequested );
       
  1105             ShowErrorNoteL( *errorBuf );
       
  1106             CleanupStack::PopAndDestroy( errorBuf );
       
  1107             }
       
  1108         // No errors, activate the skin.
       
  1109         else
       
  1110             {
       
  1111             PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL 2");
       
  1112             // Start changing active skin.
       
  1113             iModel->GuardActivationLC();
       
  1114             TBool shownote = EFalse;
       
  1115 
       
  1116             // Show screen clearer when skin is changing.
       
  1117             ToggleScreenBlankerL( ETrue, ETrue );
       
  1118 
       
  1119             PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL directly");
       
  1120             shownote = iModel->ActivateSkinL( skinIndex );
       
  1121 
       
  1122             if ( shownote )
       
  1123                 {
       
  1124                 PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL skin activated");
       
  1125                 SetStateOn( EPslnSkinActivated );
       
  1126                 }
       
  1127             else
       
  1128                 {
       
  1129                 // If user declined to activate protected skin, re-initialize status
       
  1130                 // flag.
       
  1131                 if ( GetStatus( EPslnSkinChangeRequested ) )
       
  1132                     {
       
  1133                     PSLN_TRACE_DEBUG("CPslnUi::ActivateSkinL decline DRM activation");
       
  1134                     SetStateOff( EPslnSkinChangeRequested );
       
  1135                     // Remove screen clearer.
       
  1136                     ToggleScreenBlankerL( EFalse, EFalse );
       
  1137                     }
       
  1138                 }
       
  1139             CleanupStack::PopAndDestroy(); // activation guard
       
  1140             }
       
  1141         }
       
  1142     }
       
  1143 
       
  1144 // ---------------------------------------------------------------------------
       
  1145 // CPslnUi::ActivateSoundsL
       
  1146 // ---------------------------------------------------------------------------
       
  1147 //
       
  1148 void CPslnUi::ActivateSoundsL()
       
  1149     {
       
  1150     PSLN_TRACE_DEBUG("CPslnUi::ActivateSoundsL");
       
  1151 
       
  1152     // Is sounds are not supperted, ignore.
       
  1153     if ( !PslnFeatures::IsSoundsInSkinsSupported()
       
  1154 
       
  1155     // If sounds are supported, but general view is not active, ignore.
       
  1156         || iView && iView->Id().iUid != KPslnGeneralView.iUid  )
       
  1157         {
       
  1158         return;
       
  1159         }
       
  1160 
       
  1161     TPath skinPath;
       
  1162     CPslnSkinEntry* entry = iModel->VisibleSkin( iModel->ActiveSkinIndex() );
       
  1163     if( entry )
       
  1164         {
       
  1165         entry->GetSkinPath( skinPath );
       
  1166         skinPath.Append( KPslnPathSeparator );
       
  1167         }
       
  1168     else
       
  1169         {
       
  1170         User::Leave( KErrUnknown );
       
  1171         }
       
  1172 
       
  1173     // Find sound files.
       
  1174     CPslnSoundActivator* activator = CPslnSoundActivator::NewLC();
       
  1175     TInt numberOfSounds = 0;
       
  1176     activator->CollectSoundsL( skinPath, numberOfSounds );
       
  1177 
       
  1178     PSLN_TRACE_DEBUG1("CPslnUi::ActivateSoundsL num of tunes %d", numberOfSounds );
       
  1179 
       
  1180     if ( numberOfSounds <= 0 )
       
  1181         {
       
  1182         CleanupStack::PopAndDestroy( activator );
       
  1183         return;
       
  1184         }
       
  1185 
       
  1186     // Launch profile settings loader.
       
  1187     CPslnTaskActivateSounds* activateTask = new (ELeave)
       
  1188         CPslnTaskActivateSounds( *activator );
       
  1189     CleanupStack::PushL( activateTask );
       
  1190 
       
  1191     CreateAndShowWaitWrapperL(
       
  1192         *activateTask,
       
  1193         R_PSLN_QTN_GEN_NOTE_OPENING,
       
  1194         KNullDesC() );
       
  1195 
       
  1196     HBufC* noteText = NULL;
       
  1197 
       
  1198     PSLN_TRACE_DEBUG1("CPslnUi::ActivateSoundsL error %d", activateTask->iActivationErr );
       
  1199 
       
  1200     if( activateTask->iActivationErr == KErrNone )
       
  1201         {
       
  1202         if ( numberOfSounds == 1 )
       
  1203             {
       
  1204             noteText = StringLoader::LoadLC(
       
  1205                 R_PSLN_QTN_SKINS_NOTE_TONE_ACTIVATED );
       
  1206             }
       
  1207         else
       
  1208             {
       
  1209             noteText = StringLoader::LoadLC(
       
  1210                 R_PSLN_QTN_SKINS_NOTE_TONES_ACTIVATED );
       
  1211             }
       
  1212 
       
  1213         CAknConfirmationNote* note =
       
  1214             new (ELeave) CAknConfirmationNote( ETrue );
       
  1215         note->ExecuteLD( *noteText );
       
  1216         }
       
  1217     else
       
  1218         {
       
  1219         if( activateTask->iActivationErr == KErrPermissionDenied )
       
  1220             {
       
  1221             noteText = StringLoader::LoadLC(
       
  1222                 R_PSLN_QTN_PROFILES_INFO_TONE_NO_DRM );
       
  1223             }
       
  1224         else
       
  1225             {
       
  1226             noteText = StringLoader::LoadLC(
       
  1227                 R_PSLN_QTN_FILE_FORMAT_ERROR );
       
  1228             }
       
  1229         CAknErrorNote* note =
       
  1230             new (ELeave) CAknErrorNote( ETrue );
       
  1231         note->ExecuteLD( *noteText );
       
  1232         }
       
  1233     
       
  1234     CleanupStack::PopAndDestroy( 3, activator );
       
  1235     }
       
  1236 
       
  1237 // ---------------------------------------------------------------------------
       
  1238 // CPslnUi::DownloadSkinL
       
  1239 // ---------------------------------------------------------------------------
       
  1240 //
       
  1241 void CPslnUi::DownloadSkinL()
       
  1242     {
       
  1243     PSLN_TRACE_DEBUG("CPslnUi::DownloadSkinL");
       
  1244     iModel->DownloadSkinL();
       
  1245     }
       
  1246 
       
  1247 // ---------------------------------------------------------------------------
       
  1248 // CPslnUi::CreateAndShowWaitWrapperL
       
  1249 // ---------------------------------------------------------------------------
       
  1250 //
       
  1251 void CPslnUi::CreateAndShowWaitWrapperL( MAknBackgroundProcess& aTask,
       
  1252     const TInt aResourceID, const TDesC& aString,
       
  1253     const TBool aShowImmediately )
       
  1254     {
       
  1255     HBufC* noteText = NULL;
       
  1256     if ( aString.Length() == 0 )
       
  1257         {
       
  1258         noteText = StringLoader::LoadLC( aResourceID, iEikonEnv );
       
  1259         }
       
  1260     else
       
  1261         {
       
  1262         noteText = StringLoader::LoadLC( aResourceID, aString, iEikonEnv );
       
  1263         }
       
  1264 
       
  1265     CAknWaitNoteWrapper* wrapper = CAknWaitNoteWrapper::NewL();
       
  1266     CleanupDeletePushL( wrapper );
       
  1267     if ( wrapper )
       
  1268         {
       
  1269         wrapper->ExecuteL(
       
  1270             R_PSLN_GENERAL_WAIT_NOTE, aTask, *noteText, aShowImmediately );
       
  1271         }
       
  1272 
       
  1273     CleanupStack::PopAndDestroy( 2, noteText ); // noteText, wrapper
       
  1274     }
       
  1275 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 // CPslnUi::AddPluginToTabL
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //
       
  1280 #ifndef RD_CONTROL_PANEL
       
  1281 void CPslnUi::AddPluginToTabL( CPslnFWPluginInterface& aPlugin )
       
  1282     {
       
  1283     PSLN_TRACE_DEBUG("CPslnUi::AddPluginToTabL Start");
       
  1284     HBufC* buf = HBufC::NewLC( KPslnItemLength );
       
  1285     TPtr ptrBuf = buf->Des();
       
  1286     aPlugin.GetTabTextL( ptrBuf );
       
  1287     TInt pluginUid = aPlugin.Id().iUid;
       
  1288     if ( iTabGroup )
       
  1289         {
       
  1290         iTabGroup->AddTabL( pluginUid, ptrBuf );
       
  1291         }
       
  1292     PSLN_TRACE_DEBUG("CPslnUi::AddPluginToTabL Default Plugin added to tab");
       
  1293     CleanupStack::PopAndDestroy( buf );
       
  1294     }
       
  1295 #endif //!RD_CONTROL_PANEL
       
  1296 
       
  1297 // ---------------------------------------------------------------------------
       
  1298 // Handles Exit command.
       
  1299 // ---------------------------------------------------------------------------
       
  1300 //
       
  1301 void CPslnUi::HandleCmdExitL()
       
  1302     {
       
  1303     Exit();
       
  1304     }
       
  1305 
       
  1306 // ---------------------------------------------------------------------------
       
  1307 // Shows error note.
       
  1308 // ---------------------------------------------------------------------------
       
  1309 //
       
  1310 void CPslnUi::ShowErrorNoteL( HBufC& aErrorBuf ) const
       
  1311     {
       
  1312     // Display global note.
       
  1313     CAknGlobalNote* errorNote = CAknGlobalNote::NewLC();
       
  1314     errorNote->ShowNoteL( EAknGlobalErrorNote, aErrorBuf );
       
  1315     CleanupStack::PopAndDestroy( errorNote );
       
  1316     }
       
  1317 // ---------------------------------------------------------------------------
       
  1318 // Callback when idle time occurs for skin update.
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 TInt CPslnUi::DoCreateWaitNoteL( TAny* aAny )
       
  1322     {
       
  1323     static_cast< CPslnUi* >( aAny )->DoCreateWaitNoteL();
       
  1324     return EFalse;
       
  1325     }
       
  1326 // ---------------------------------------------------------------------------
       
  1327 // CPslnUi::DoCreateWaitNoteL
       
  1328 // ---------------------------------------------------------------------------
       
  1329 //
       
  1330 void CPslnUi::DoCreateWaitNoteL()
       
  1331     {
       
  1332     CPslnTaskGenericUpdate* updateTask =
       
  1333         new (ELeave) CPslnTaskGenericUpdate(
       
  1334         *this, &CPslnModel::PerformCompleteUpdateL, ETrue );
       
  1335     CleanupStack::PushL( updateTask );
       
  1336 
       
  1337     CreateAndShowWaitWrapperL( *updateTask,
       
  1338         R_PSLN_QTN_GEN_NOTE_OPENING, KNullDesC(), EFalse );
       
  1339 
       
  1340     User::LeaveIfError( updateTask->iCallErr );
       
  1341 
       
  1342     CleanupStack::PopAndDestroy( updateTask );
       
  1343     }
       
  1344 
       
  1345 // ---------------------------------------------------------------------------
       
  1346 // This operation needs to be atomic. If it leaves, set state back to previous.
       
  1347 // ---------------------------------------------------------------------------
       
  1348 //
       
  1349 TInt CPslnUi::ActivateSkin( const TInt aPslnStatus )
       
  1350     {
       
  1351     TInt error = KErrNone;
       
  1352     if ( !GetStatus( aPslnStatus ) )
       
  1353         {
       
  1354         SetStateOn( aPslnStatus );
       
  1355         TRAPD( err, ActivateSkinL() );
       
  1356         if ( err != KErrNone )
       
  1357             {
       
  1358             SetStateOff( aPslnStatus );
       
  1359             error = err;
       
  1360             }
       
  1361         }
       
  1362     iGeneralThemeView->RemoveLocalSkinItems();
       
  1363     return error;
       
  1364     }
       
  1365 
       
  1366 // ---------------------------------------------------------------------------
       
  1367 // Non-leaving version of AddPluginToTabL.
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 #ifndef RD_CONTROL_PANEL
       
  1371 TInt CPslnUi::AddPluginToTab( CPslnFWPluginInterface& aPlugin )
       
  1372     {
       
  1373     TRAPD( err, AddPluginToTabL( aPlugin ) );
       
  1374     if ( err )
       
  1375         {
       
  1376         PSLN_TRACE_DEBUG1("CPslnUi::AddPluginToTab plugin fails: ", aPlugin.Id().iUid );
       
  1377         }
       
  1378     return err;
       
  1379     }
       
  1380 #endif //!RD_CONTROL_PANEL
       
  1381 
       
  1382 // ---------------------------------------------------------------------------
       
  1383 // Show skin activated note.
       
  1384 // ---------------------------------------------------------------------------
       
  1385 //
       
  1386 void CPslnUi::SkinDeployedL()
       
  1387     {
       
  1388 #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2
       
  1389     // Only set sound state - no conf note anymore.
       
  1390     SetStateOn( EPslnSoundActivationPending );
       
  1391 #else
       
  1392     HBufC* skinName = HBufC::NewLC( KMaxName );
       
  1393     TPtr skinNamePtr = skinName->Des();
       
  1394     TInt skinIndex = iModel->ActiveSkinIndex();
       
  1395 
       
  1396     iModel->GetSkinNameByIndex(
       
  1397         skinIndex,
       
  1398         skinNamePtr,
       
  1399         EPslnSkinNameTypeTitle );
       
  1400 
       
  1401     // Show confirmation note about skin change.
       
  1402     HBufC* noteTxt = StringLoader::LoadL(
       
  1403         R_PSLN_CONFIRM_ACTIVE_SKIN_STRING,
       
  1404         skinNamePtr,
       
  1405         iEikonEnv );
       
  1406     CleanupStack::PushL( noteTxt );
       
  1407 
       
  1408     SetStateOn( EPslnSoundActivationPending );
       
  1409     CAknConfirmationNote* note =
       
  1410         new (ELeave) CAknConfirmationNote( ETrue );
       
  1411     note->ExecuteLD( *noteTxt );
       
  1412     CleanupStack::PopAndDestroy( 2, skinName ); // skinName, noteTxt
       
  1413 
       
  1414 #endif
       
  1415     iGeneralThemeView->UpdateSkinListItemsL();
       
  1416     }
       
  1417 
       
  1418 // ---------------------------------------------------------------------------
       
  1419 // Creates model class.
       
  1420 // ---------------------------------------------------------------------------
       
  1421 //
       
  1422 void CPslnUi::CreateModelL()
       
  1423     {
       
  1424     if ( !GetStatus( EPslnModelCreated ) )
       
  1425         {
       
  1426         iModel = CPslnModel::NewL( this );
       
  1427         SetStateOn( EPslnModelCreated );
       
  1428         }
       
  1429     }
       
  1430 
       
  1431 // ---------------------------------------------------------------------------
       
  1432 // Callback when idle time occurs for skin activation.
       
  1433 // ---------------------------------------------------------------------------
       
  1434 //
       
  1435 TInt CPslnUi::DoActivateSkinL( TAny* aAny )
       
  1436     {
       
  1437     static_cast< CPslnUi* >( aAny )->DoActivateSkinL();
       
  1438     return EFalse;
       
  1439     }
       
  1440 
       
  1441 // ---------------------------------------------------------------------------
       
  1442 // Callback when idle time occurs for skin activation.
       
  1443 // ---------------------------------------------------------------------------
       
  1444 //
       
  1445 void CPslnUi::DoActivateSkinL()
       
  1446     {
       
  1447     TInt error = ActivateSkin( EPslnSkinChangeRequested );
       
  1448     if ( error == KErrNoMemory )
       
  1449         {
       
  1450         HBufC* errorBuf = StringLoader::LoadLC(
       
  1451             R_PSLN_QTN_MEMLO_RAM_OUT_OF_MEM );
       
  1452         // Display global note.
       
  1453         CAknGlobalNote* errorNote = CAknGlobalNote::NewLC();
       
  1454         errorNote->ShowNoteL( EAknGlobalErrorNote, *errorBuf );
       
  1455         CleanupStack::PopAndDestroy( 2 ); // errorNote & errorBuf
       
  1456         }
       
  1457     }
       
  1458 
       
  1459 
       
  1460 /**
       
  1461 * Handle USB Callback.
       
  1462 */
       
  1463 void CPslnUi::HandleUSBCallBackL()
       
  1464     {
       
  1465     if ( iView && iView->Id().iUid == KPslnGeneralView.iUid )
       
  1466         {
       
  1467         TInt value = KErrNone;
       
  1468         iEnableUSBWatchProperty.Get(value);
       
  1469         
       
  1470         if (value == KUsbPersonalityIdMS )
       
  1471             {
       
  1472             iUSBAttached = ETrue;
       
  1473             }
       
  1474         else
       
  1475             {
       
  1476             iUSBAttached = EFalse;
       
  1477             }
       
  1478         static_cast< CPslnGeneralThemeView* >( iView )->RestartQuickPreviewL();
       
  1479         }
       
  1480     }
       
  1481 // End of File
       
  1482