XDMSettingsUI/src/XDMPlugin.cpp
branchRCL_3
changeset 35 fbd2e7cec7ef
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2005-2010 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:    XDMPlugin Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // Includes
       
    22 #include "XDMExternalInterface.h"
       
    23 
       
    24 #include <aknViewAppUi.h>
       
    25 #include <StringLoader.h>
       
    26 #include <gsprivatepluginproviderids.h>
       
    27 #include <eikmenub.h>
       
    28 #include <aknlists.h>
       
    29 #include <aknPopup.h>
       
    30 #include <XdmSettingsApi.h>
       
    31 #include <AknQueryDialog.h>
       
    32 #include <featmgr.h>
       
    33 #include <hlplch.h>
       
    34 #include <csxhelp/xdm.hlp.hrh>
       
    35 #include <gsxdmplugin.mbg>
       
    36 #include <bautils.h>
       
    37 
       
    38 #include "XDMPlugin.h"
       
    39 #include "XDMPluginContainer.h"
       
    40 #include "XDMPluginSLContainer.h"
       
    41 #include "XDMPlugin.hrh"
       
    42 
       
    43 
       
    44 // Constants
       
    45 
       
    46 const TInt KMaxNameLength = 255;
       
    47 
       
    48 _LIT( KGSXDMPluginResourceFileName, "z:\\resource\\XDMPluginRsc.rsc" );
       
    49 
       
    50 #ifdef __SCALABLE_ICONS
       
    51 // bitmap
       
    52 _LIT( KGSXDMPluginIconFileName, "\\resource\\apps\\GSXDMplugin.mif");
       
    53 #else //__SCALABLE_ICONS
       
    54 // svg file
       
    55 _LIT( KGSXDMPluginIconFileName, "\\resource\\apps\\GSXDMplugin.mbm");
       
    56 #endif //__SCALABLE_ICONS
       
    57 
       
    58 
       
    59 // ========================= MEMBER FUNCTIONS ================================
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CXDMPlugin::CXDMPlugin()
       
    63 // Constructor
       
    64 //
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CXDMPlugin::CXDMPlugin( )
       
    68     : iAppUi( CAknView::AppUi() ), iResources( *CCoeEnv::Static() )
       
    69     {
       
    70     
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CXDMPlugin::~CXDMPlugin()
       
    75 // Destructor
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CXDMPlugin::~CXDMPlugin()
       
    79     {
       
    80     if (iCurrentContainer)
       
    81         {
       
    82         if(iAppUi)
       
    83         iAppUi->RemoveFromViewStack( *this, iCurrentContainer );
       
    84         iCurrentContainer = NULL;
       
    85         }
       
    86 
       
    87     if( iMainListContainer )
       
    88         {
       
    89         delete iMainListContainer;
       
    90         iMainListContainer=NULL;
       
    91         }
       
    92         
       
    93     if (iSettingListContainer)
       
    94         {
       
    95         delete iSettingListContainer;
       
    96         iSettingListContainer=NULL;
       
    97         }
       
    98 
       
    99     iResources.Close();
       
   100     /** Nice to know when the plugin is cleaned up */
       
   101     #ifdef _DEBUG
       
   102     RDebug::Print( _L( "[CXDMPlugin] ~CXDMPlugin()" ) );
       
   103     #endif
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CXDMPlugin::ConstructL()
       
   108 // Symbian OS two-phased constructor
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CXDMPlugin::ConstructL()
       
   112     {
       
   113     // To know if the plugin is loaded (for debugging)
       
   114     #ifdef _DEBUG
       
   115     RDebug::Print(_L("[CXDMPlugin] ConstructL()" ));
       
   116     RDebug::Print( _L( "[CXDMPlugin] Loading resource from :" ) );
       
   117     RDebug::Print( KGSXDMPluginResourceFileName );
       
   118     #endif
       
   119     
       
   120     TFileName fileName( KGSXDMPluginResourceFileName );
       
   121     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   122     iResources.OpenL( fileName );
       
   123     BaseConstructL( R_GS_XDM_MAIN_VIEW );
       
   124         
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CXDMPlugin::NewL()
       
   129 // Static constructor
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 CXDMPlugin* CXDMPlugin::NewL( TAny* /*aInitParams*/ )
       
   133     {
       
   134     CXDMPlugin* self = new(ELeave) CXDMPlugin( );
       
   135     CleanupStack::PushL(self);
       
   136     self->ConstructL();
       
   137     CleanupStack::Pop(self);
       
   138     return self;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CXDMPlugin::Id() const
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TUid CXDMPlugin::Id() const
       
   146     {
       
   147     return KGSXDMPluginUid;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CXDMPlugin::HandleClientRectChange()
       
   152 // ---------------------------------------------------------------------------
       
   153 void CXDMPlugin::HandleViewRectChange()
       
   154     {
       
   155     if ( iMainListContainer->IsVisible() )
       
   156         {
       
   157         iMainListContainer->SetRect( ClientRect() );
       
   158         }
       
   159         
       
   160     if ( iSettingListContainer->IsVisible() )
       
   161         {
       
   162         iSettingListContainer->SetRect( ClientRect() );
       
   163         }
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CXDMPlugin::DoActivateL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CXDMPlugin::DoActivateL( const TVwsViewId& aPrevViewId,
       
   171                                   TUid /*aCustomMessageId*/,
       
   172                                   const TDesC8& /*aCustomMessage*/ )
       
   173     {
       
   174     iPrevViewId = aPrevViewId;
       
   175     if (iCurrentContainer)
       
   176         {
       
   177         iAppUi->RemoveFromViewStack( *this, iCurrentContainer );
       
   178         iCurrentContainer = NULL;
       
   179         }
       
   180         
       
   181 
       
   182     if( iMainListContainer )
       
   183         {
       
   184         delete iMainListContainer;
       
   185         iMainListContainer=NULL;
       
   186         }
       
   187 
       
   188     if( iSettingListContainer )
       
   189         {
       
   190         delete iSettingListContainer;
       
   191         iSettingListContainer = NULL;
       
   192         }
       
   193 
       
   194     iMainListContainer = new( ELeave ) CXDMPluginContainer(this);
       
   195     iMainListContainer->SetMopParent(this);
       
   196     TRAPD( error, iMainListContainer->ConstructL( ClientRect() ) );
       
   197     if (error)
       
   198         {
       
   199         delete iMainListContainer;
       
   200         iMainListContainer = NULL;
       
   201         User::Leave( error );
       
   202         }
       
   203         
       
   204     iSettingListContainer = new( ELeave ) CXDMPluginSLContainer(this);
       
   205     iSettingListContainer->SetMopParent(this);
       
   206     TRAPD( error1, iSettingListContainer->ConstructL( ClientRect()));
       
   207     if (error1)
       
   208         {
       
   209         delete iSettingListContainer;
       
   210         iSettingListContainer = NULL;
       
   211         User::Leave( error1 );
       
   212         }
       
   213 
       
   214     // switching control
       
   215     iSettingListContainer->MakeVisible(EFalse);    
       
   216     iCurrentContainer = iMainListContainer;
       
   217     iAppUi->AddToViewStackL( *this, iCurrentContainer );
       
   218     UpdateMskL();
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CXDMPlugin::DoDeactivate()
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CXDMPlugin::DoDeactivate()
       
   226     {
       
   227     // try to save settings if in settings list container
       
   228     TInt err;
       
   229     if (iCurrentContainer == iSettingListContainer)
       
   230         TRAP(err, iSettingListContainer->SaveSettingsIfPossibleL());
       
   231     if (iCurrentContainer)
       
   232         iAppUi->RemoveFromViewStack( *this, iCurrentContainer );
       
   233     iCurrentContainer = NULL;
       
   234 
       
   235     if( iMainListContainer )
       
   236         {
       
   237         delete iMainListContainer;
       
   238         iMainListContainer = NULL;
       
   239         }
       
   240         
       
   241     if( iSettingListContainer )
       
   242         {
       
   243         delete iSettingListContainer;
       
   244         iSettingListContainer = NULL;
       
   245         }
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CXDMPlugin::HandleCommandL()
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CXDMPlugin::HandleCommandL( TInt aCommand )
       
   253     {
       
   254     switch ( aCommand )
       
   255         {
       
   256         case EAknSoftkeyBack:
       
   257             if (iCurrentContainer == iSettingListContainer)
       
   258                 {
       
   259                 if (iSettingListContainer->IsExitProcessingOKL())
       
   260                     LoadMainViewL();    
       
   261                 }
       
   262             else 
       
   263                 iAppUi->ActivateLocalViewL( iPrevViewId.iViewUid );
       
   264             break;
       
   265         case EGSXDMPluginCmdChange:
       
   266             iSettingListContainer->EditCurrentItemL();                       
       
   267             break;
       
   268         case EGSXDMPluginCmdEdit:
       
   269             iMainListContainer->EditCurrentItemL();
       
   270             break;
       
   271         case EGSXDMPluginCmdNewExisting:
       
   272             if(iSettingListContainer->DisplayNewXDMSetOptionsL()) // if user ok
       
   273                 LoadSettingsViewL(ENewFromExisting, iSettingListContainer->GetCurrentSetName());
       
   274             break;
       
   275         case EGSXDMPluginCmdNewDefault:
       
   276             LoadSettingsViewL(ENewDefault, iSettingListContainer->GetCurrentSetName());
       
   277             break;
       
   278         case EGSXDMPluginCmdDelete:
       
   279             iMainListContainer->DeleteSetProcedureL();
       
   280             UpdateMskL();
       
   281             break;
       
   282         case EAknCmdHelp:
       
   283             HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), AppUi()->AppHelpContextL ());
       
   284             break;
       
   285         case EGSXDMPluginCmdExitFromSL:
       
   286             if (iCurrentContainer == iSettingListContainer)
       
   287                 {
       
   288                 if (iSettingListContainer->IsExitProcessingOKL())
       
   289                     iAppUi->HandleCommandL( EAknCmdExit ); 
       
   290                 }
       
   291             break;
       
   292         case EAknCmdExit:
       
   293         case EEikCmdExit:
       
   294             if (iCurrentContainer == iSettingListContainer)
       
   295                 iSettingListContainer->SaveSettingsIfPossibleL();
       
   296             iAppUi->HandleCommandL( EAknCmdExit );
       
   297             break;    
       
   298         default:
       
   299             iAppUi->HandleCommandL( aCommand );
       
   300             break;
       
   301         }
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CXDMPlugin::GetCaptionL()
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CXDMPlugin::GetCaptionL( TDes& aCaption ) const
       
   309     {
       
   310     StringLoader::Load( aCaption, R_STR_XDM_SETTINGS );
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // CXDMPlugin::PluginProviderCategory()
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 TInt CXDMPlugin::PluginProviderCategory() const
       
   318     {
       
   319     return KGSPluginProviderInternal;
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CXDMPlugin::LoadSettingsViewL()
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 void CXDMPlugin::LoadSettingsViewL(TXDMSettingsViewType aType, TDesC& aXDMSetName)
       
   327     {
       
   328     switch(aType)
       
   329         {
       
   330         case EEditExisting:
       
   331             iSettingListContainer->PrepareXDMSetForEditingL(aXDMSetName);
       
   332             break;
       
   333         case ENewDefault:
       
   334             iSettingListContainer->PrepareXDMSetNewDefaultL();
       
   335             break;
       
   336         case ENewFromExisting:
       
   337             iSettingListContainer->PrepareNewXDMSetFromExistingL(aXDMSetName);
       
   338             break;
       
   339         default:
       
   340             break;
       
   341         }
       
   342     if (iCurrentContainer)
       
   343         iAppUi->RemoveFromViewStack( *this, iCurrentContainer );
       
   344     iCurrentContainer = iSettingListContainer;
       
   345     iAppUi->AddToViewStackL( *this, iCurrentContainer );
       
   346     iMainListContainer->MakeVisible(EFalse);
       
   347     iSettingListContainer->MakeVisible(ETrue);
       
   348     UpdateMskL();
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CXDMPlugin::LoadMainViewL()
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CXDMPlugin::LoadMainViewL()
       
   356     {
       
   357     TInt err(KErrNone);
       
   358     TRAP(err,iMainListContainer->LoadSettingsListArrayL()); // update main container
       
   359     if (iCurrentContainer)
       
   360         iAppUi->RemoveFromViewStack( *this, iCurrentContainer );
       
   361     iCurrentContainer = iMainListContainer;
       
   362     iAppUi->AddToViewStackL( *this, iCurrentContainer );
       
   363     
       
   364     iMainListContainer->SetFocusIfExist(iSettingListContainer->GetCurrentSetName());
       
   365     
       
   366     iSettingListContainer->MakeVisible(EFalse);  
       
   367     iMainListContainer->MakeVisible(ETrue);
       
   368     UpdateMskL();
       
   369     }
       
   370     
       
   371 // ---------------------------------------------------------------------------
       
   372 // CXDMPlugin::DynInitMenuPaneL()
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CXDMPlugin::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
   376     {
       
   377     if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   378     	{
       
   379     	aMenuPane->SetItemDimmed(EAknCmdHelp, ETrue);
       
   380     	}
       
   381     
       
   382     if (aResourceId == R_GS_XDM_SETTINGS_MAIN_MENU)
       
   383         {
       
   384         if (iCurrentContainer == iMainListContainer)
       
   385             {
       
   386             aMenuPane->SetItemDimmed(EGSXDMPluginCmdChange, ETrue);
       
   387             aMenuPane->SetItemDimmed(EGSXDMPluginCmdExitFromSL, ETrue);
       
   388             if (iMainListContainer->IsListEmpty())
       
   389                 {
       
   390                 aMenuPane->SetItemDimmed(EGSXDMPluginCmdEdit, ETrue);
       
   391                 aMenuPane->SetItemDimmed(EGSXDMPluginCmdDelete, ETrue);
       
   392                 }
       
   393             }
       
   394         else
       
   395             {
       
   396             aMenuPane->SetItemDimmed(EGSXDMPluginCmdEdit, ETrue);
       
   397             aMenuPane->SetItemDimmed(EGSXDMPluginCmdDelete, ETrue);
       
   398             aMenuPane->SetItemDimmed(EGSXDMPluginCmdNewSettings, ETrue);
       
   399             aMenuPane->SetItemDimmed(EAknCmdExit, ETrue);
       
   400             }
       
   401         }
       
   402     
       
   403     if (aResourceId == R_GS_XDM_NEW_SETTINGS_MENU)
       
   404         {
       
   405         if (iMainListContainer->IsListEmpty())
       
   406             {
       
   407             aMenuPane->SetItemDimmed(EGSXDMPluginCmdNewExisting, ETrue);
       
   408             }
       
   409         }
       
   410     
       
   411     if ( iSettingListContainer && !iMainListContainer->IsListEmpty() )
       
   412         {
       
   413         TBool inUse( EFalse );
       
   414         HBufC* currentSetName = iMainListContainer->GetCurrentSetNameLC();
       
   415         TBuf<KMaxNameLength> setName;
       
   416         setName.Copy( currentSetName->Des() );
       
   417         TRAP_IGNORE( inUse = iSettingListContainer->SettingsApInUseL( setName ) );
       
   418         CleanupStack::PopAndDestroy( currentSetName );
       
   419     
       
   420         if ( inUse )
       
   421             {
       
   422             TInt pos( KErrNotFound );
       
   423             if ( aMenuPane->MenuItemExists( EGSXDMPluginCmdDelete, pos ) )
       
   424                 {
       
   425                 aMenuPane->SetItemSpecific( EGSXDMPluginCmdDelete, EFalse );
       
   426                 aMenuPane->SetItemDimmed(EGSXDMPluginCmdDelete, ETrue);
       
   427                 }
       
   428             }
       
   429         else
       
   430             {
       
   431             TInt pos( KErrNotFound );
       
   432             if ( aMenuPane->MenuItemExists( EGSXDMPluginCmdDelete, pos ) )
       
   433                 {
       
   434                 aMenuPane->SetItemSpecific( EGSXDMPluginCmdDelete, ETrue );
       
   435                 aMenuPane->SetItemDimmed(EGSXDMPluginCmdDelete, EFalse);
       
   436                 }
       
   437             }
       
   438         }
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------
       
   442 // CXDMPlugin::HandleResourceChangeManual()
       
   443 // ---------------------------------------------------------
       
   444 //
       
   445 void CXDMPlugin::HandleResourceChangeManual(TInt aType)
       
   446     {
       
   447     if ( iSettingListContainer )
       
   448         iSettingListContainer->HandleResourceChangeManual(aType);    
       
   449     if ( iMainListContainer )
       
   450         iMainListContainer->HandleResourceChangeManual(aType);
       
   451     }
       
   452     
       
   453 // ---------------------------------------------------------------------------
       
   454 // CXDMPlugin::CreateIconL
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 CGulIcon* CXDMPlugin::CreateIconL( const TUid aIconType )
       
   458     {
       
   459     CGulIcon* icon;
       
   460        
       
   461     if( aIconType == KGSIconTypeLbxItem )
       
   462         {
       
   463         icon = AknsUtils::CreateGulIconL(
       
   464         AknsUtils::SkinInstance(), 
       
   465         KAknsIIDQgnPropSetConnXdm, 
       
   466         KGSXDMPluginIconFileName,
       
   467         EMbmGsxdmpluginQgn_prop_set_conn_xdm,
       
   468         EMbmGsxdmpluginQgn_prop_set_conn_xdm_mask);
       
   469         }
       
   470      else
       
   471         {
       
   472         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   473         }
       
   474 
       
   475     return icon;
       
   476     }
       
   477     
       
   478 // ---------------------------------------------------------------------------
       
   479 // CXDMPlugin::UpdateMskL()
       
   480 // ---------------------------------------------------------------------------
       
   481 //
       
   482 void CXDMPlugin::UpdateMskL()
       
   483     {
       
   484     if ( !Cba() )
       
   485         {
       
   486         return;
       
   487         }
       
   488     
       
   489     CEikCba* cba = static_cast< CEikCba* >( Cba()->ButtonGroup() );
       
   490     if(iCurrentContainer==iMainListContainer)
       
   491         {
       
   492         TBool showEdit = !(iMainListContainer->IsListEmpty());
       
   493         cba->SetCommandSetL(R_XDMUI_MAINVIEW_SOFTKEYS);
       
   494         cba->MakeCommandVisible( EGSXDMPluginCmdEdit, showEdit );
       
   495         }
       
   496     else if(iCurrentContainer==iSettingListContainer)
       
   497         {
       
   498         cba->SetCommandSetL(R_XDMUI_MAINVIEW_SOFTKEYS_SL);
       
   499         cba->MakeCommandVisible( EGSXDMPluginCmdChange, ETrue);
       
   500         if ( iSettingListContainer->IsVisible() )
       
   501             {
       
   502             iCurrentContainer->DrawNow();
       
   503             }
       
   504         }
       
   505     cba->DrawNow();
       
   506     }
       
   507     
       
   508 // End of file
       
   509 
       
   510