idlehomescreen/widgetmanager/src/wmplugin.cpp
changeset 1 5315654608de
child 2 08c6ee43b396
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 * widget manager plugin implementation
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <bautils.h>
       
    21 #include <coemain.h>
       
    22 #include <aknViewAppUi.h>
       
    23 
       
    24 #include "wmcommon.h"
       
    25 #include "widgetmanager.hrh"
       
    26 #include "wmmaincontainer.h"
       
    27 #include "wmmaincontainerview.h"
       
    28 #include "wmresourceloader.h"
       
    29 #include "wmplugin.h"
       
    30 #include "wmeffectmanager.h"
       
    31 #include <widgetmanagerview.rsg>
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CWmPlugin::NewL
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CWmPlugin* CWmPlugin::NewL()
       
    38     {
       
    39     CWmPlugin* self=new(ELeave) CWmPlugin();
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop(self);
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CWmPlugin::~CWmPlugin
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 CWmPlugin::~CWmPlugin()
       
    51     {
       
    52     if ( iViewAppUi )
       
    53         {
       
    54         Deactivate();
       
    55         iViewAppUi->RemoveView( TUid::Uid( EWmMainContainerViewId ) );
       
    56         }
       
    57     iWmMainContainer = NULL;
       
    58     delete iResourceLoader;
       
    59     delete iEffectManager;
       
    60     delete iPostponedContent;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CWmPlugin::CWmPlugin
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CWmPlugin::CWmPlugin()
       
    68     {
       
    69     iPreviousViewUid.iViewUid = KNullUid;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CWmPlugin::ConstructL
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CWmPlugin::ConstructL()
       
    77     {
       
    78     iWmMainContainer = NULL;
       
    79 
       
    80     // store static view app ui
       
    81     CEikonEnv* eikonEnv = CEikonEnv::Static();
       
    82     if ( !eikonEnv ) User::Leave( KErrUnknown );
       
    83     iViewAppUi = (CAknViewAppUi*)eikonEnv->EikAppUi();
       
    84     if ( !iViewAppUi ) User::Leave( KErrUnknown );
       
    85 
       
    86     // create resource loader
       
    87     iFs = &eikonEnv->FsSession();
       
    88     iResourceLoader = CWmResourceLoader::NewL( *eikonEnv );
       
    89     iEffectManager = CWmEffectManager::NewL( *eikonEnv );
       
    90     
       
    91     // main view
       
    92     CWmMainContainerView* mainView =
       
    93             CWmMainContainerView::NewL( *this );
       
    94     CleanupStack::PushL( mainView );
       
    95 	iViewAppUi->AddViewL( mainView );	
       
    96 	CleanupStack::Pop( mainView );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CWmPlugin::Activate
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 void CWmPlugin::Activate()
       
   104     {
       
   105     if ( !IsActive() && iHsContentController )
       
   106         {
       
   107         TRAP_IGNORE( 
       
   108             iEffectManager->BeginFullscreenEffectL( 
       
   109                 KAppStartCommonDefaultStyle );
       
   110             iViewAppUi->ActivateLocalViewL( 
       
   111                 TUid::Uid( EWmMainContainerViewId ) ); 
       
   112             );
       
   113         }
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CWmPlugin::IsActive
       
   118 // ---------------------------------------------------------
       
   119 //
       
   120 TBool CWmPlugin::IsActive()
       
   121     {
       
   122     return ( iPreviousViewUid.iViewUid != KNullUid );
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------
       
   126 // CWmPlugin::Deactivate
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 void CWmPlugin::Deactivate()
       
   130     {
       
   131     if ( IsActive() )
       
   132         {
       
   133         iWmMainContainer->SetClosingDown( ETrue );
       
   134         TRAP_IGNORE( 
       
   135             iEffectManager->BeginFullscreenEffectL(
       
   136                 KAppExitCommonDefaultStyle );
       
   137             iViewAppUi->ActivateLocalViewL(
       
   138                 iPreviousViewUid.iViewUid ); 
       
   139             );
       
   140         }
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // CWmPlugin::MainViewActivated
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 void CWmPlugin::MainViewActivated( 
       
   148                     const TVwsViewId& aViewId,
       
   149                     CWmMainContainer* aWmMainContainer )
       
   150     {
       
   151     iPreviousViewUid = aViewId;
       
   152     iWmMainContainer = aWmMainContainer;
       
   153     iEffectManager->UiRendered();
       
   154     iWmMainContainer->SetClosingDown( EFalse );
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CWmPlugin::MainViewDeactivated
       
   159 // ---------------------------------------------------------
       
   160 //
       
   161 void CWmPlugin::MainViewDeactivated()
       
   162     {
       
   163     iPreviousViewUid.iViewUid = KNullUid;
       
   164     iWmMainContainer = NULL;
       
   165     iEffectManager->UiRendered();
       
   166 
       
   167     TRAP_IGNORE( ExecutePostponedCommandL(); );
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CWmPlugin::SetPostponedCommandL
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CWmPlugin::SetPostponedCommandL(
       
   175         TCommand aCommand, CHsContentInfo& aContentInfo )
       
   176     {
       
   177     iPostponedCommand = aCommand;
       
   178     delete iPostponedContent;
       
   179     iPostponedContent = NULL;
       
   180     iPostponedContent = aContentInfo.CloneL();
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------
       
   184 // CWmPlugin::ExecutePostponedCommandL
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CWmPlugin::ExecutePostponedCommandL()
       
   188     {
       
   189     if ( iPostponedCommand == EAddToHomescreen )
       
   190         {
       
   191         TInt err = ContentController().AddWidgetL( *iPostponedContent );
       
   192         if ( err == KHsErrorViewFull ||
       
   193                 err == KHsErrorDoesNotFit )
       
   194             {
       
   195             ResourceLoader().InfoPopupL(
       
   196                 R_QTN_HS_ADD_WIDGET_NO_SPACE_NOTE, KNullDesC );
       
   197             }
       
   198         else if ( err == KHsErrorMaxInstanceCountExceeded )
       
   199             {
       
   200             ResourceLoader().InfoPopupL(
       
   201                 R_QTN_HS_ADD_WIDGET_MAX_COUNT_NOTE, KNullDesC );
       
   202             }
       
   203         else if ( err == KErrNoMemory )
       
   204             {
       
   205             ResourceLoader().InfoPopupL(
       
   206                 R_QTN_HS_HS_MEMORY_FULL, KNullDesC );
       
   207             }
       
   208         else if ( err != KErrNone )
       
   209             {
       
   210             ResourceLoader().ErrorPopup( err );
       
   211             }
       
   212         }
       
   213     iPostponedCommand = ENone;
       
   214     delete iPostponedContent;
       
   215     iPostponedContent = NULL;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------
       
   219 // CWmPlugin::MainViewDeactivated
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 CAknViewAppUi& CWmPlugin::ViewAppUi()
       
   223     {
       
   224     return *iViewAppUi;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CWmPlugin::MainViewDeactivated
       
   229 // ---------------------------------------------------------
       
   230 //
       
   231 CWmResourceLoader& CWmPlugin::ResourceLoader()
       
   232     {
       
   233     return *iResourceLoader;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CWmPlugin::MainViewDeactivated
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 MHsContentController& CWmPlugin::ContentController()
       
   241     {
       
   242     return *iHsContentController;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CWmPlugin::MainViewDeactivated
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 RFs& CWmPlugin::FileServer()
       
   250     {
       
   251     return *iFs;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CWmPlugin::NotifyWidgetListChanged
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CWmPlugin::NotifyWidgetListChanged()
       
   259     {
       
   260     if ( iWmMainContainer )
       
   261         {
       
   262         iWmMainContainer->HandleWidgetListChanged();
       
   263         }
       
   264     }
       
   265 
       
   266 // End of file