presencesettingsui/src/psuigsplugin.cpp
changeset 13 b7e70c0792e6
parent 12 e6a66db4e9d0
equal deleted inserted replaced
12:e6a66db4e9d0 13:b7e70c0792e6
    18 
    18 
    19 
    19 
    20 
    20 
    21 // INCLUDE FILES
    21 // INCLUDE FILES
    22 #include <bautils.h>
    22 #include <bautils.h>
    23 #include <gsprivatepluginproviderids.h>
       
    24 #include <GSFWViewUIDs.h>
       
    25 #include <psuigspluginrsc.rsg>
    23 #include <psuigspluginrsc.rsg>
    26 #include <psuigsplugin.mbg>
    24 #include <psuigsplugin.mbg>
    27 #include <GSBaseView.h>
       
    28 #include <eiktxlbx.h>
    25 #include <eiktxlbx.h>
    29 #include <eikmenup.h>
    26 #include <eikmenup.h>
    30 #include <eiktxlbm.h>
    27 #include <eiktxlbm.h>
    31 #include <featmgr.h>
    28 #include <featmgr.h>
    32 #include <hlplch.h>
    29 #include <hlplch.h>
    42 #include "psuigspluginids.hrh"
    39 #include "psuigspluginids.hrh"
    43 #include "psuigspluginmodel.h"
    40 #include "psuigspluginmodel.h"
    44 #include "psuigspluginsettingview.h"
    41 #include "psuigspluginsettingview.h"
    45 
    42 
    46 // CONSTANTS
    43 // CONSTANTS
    47 _LIT( KPSUIGSPluginResourceFileName, "z:\\resource\\psuigspluginrsc.rsc" );
       
    48 
    44 
    49 #ifdef __SCALABLE_ICONS
    45 #ifdef __SCALABLE_ICONS
    50 // bitmap
    46 // bitmap
    51 _LIT( KPSUIGSPluginIconFileName, "\\resource\\apps\\psuigsplugin.mif");
       
    52 #else //__SCALABLE_ICONS
    47 #else //__SCALABLE_ICONS
    53 // svg file
    48 // svg file
    54 _LIT( KPSUIGSPluginIconFileName, "\\resource\\apps\\psuigsplugin.mbm");
    49 _LIT( KPSUIGSPluginIconFileName, "\\resource\\apps\\psuigsplugin.mbm");
    55 #endif //__SCALABLE_ICONS
    50 #endif //__SCALABLE_ICONS
    56 
    51 
    83 // Symbian 2nd phase constructor can leave.
    78 // Symbian 2nd phase constructor can leave.
    84 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    85 //
    80 //
    86 void CPSUIGSPlugin::ConstructL()
    81 void CPSUIGSPlugin::ConstructL()
    87     {
    82     {
    88     // preparing resources for use
       
    89     TFileName fileName( KPSUIGSPluginResourceFileName );
       
    90     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
    91     iResourceLoader.OpenL( fileName );
       
    92     // base construct (base needs the resources to be loaded 1st)
       
    93     BaseConstructL( R_PSUI_MAIN_VIEW );
       
    94     FeatureManager::InitializeLibL();
       
    95     }
    83     }
    96 
    84 
    97 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    98 // CPSUIGSPlugin::NewL()
    86 // CPSUIGSPlugin::NewL()
    99 // Two-phased constructor.
    87 // Two-phased constructor.
   117     {
   105     {
   118     return TUid::Uid( PSUIGSPluginImplUid );
   106     return TUid::Uid( PSUIGSPluginImplUid );
   119     }
   107     }
   120    
   108    
   121 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   122 // CPSUIGSPlugin::NewContainerL()
       
   123 // See header for details.
       
   124 // ---------------------------------------------------------------------------
       
   125 //  
       
   126 void CPSUIGSPlugin::NewContainerL()
       
   127     {
       
   128     iContainer = new ( ELeave ) CPSUIGSPluginContainer( this );
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CPSUIGSPlugin::DoActivateL()
   110 // CPSUIGSPlugin::DoActivateL()
   133 // See header for details.
   111 // See header for details.
   134 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   135 //  
   113 //  
   136 void CPSUIGSPlugin::DoActivateL( const TVwsViewId& aPrevViewId,
   114 void CPSUIGSPlugin::DoActivateL( const TVwsViewId& aPrevViewId,
   137                                   TUid aCustomMessageId,
   115                                   TUid /*aCustomMessageId*/,
   138                                   const TDesC8& aCustomMessage )
   116                                   const TDesC8& /*aCustomMessage*/ )
   139     {
   117     {
   140     if ( KPreSettingViewId != aPrevViewId.iViewUid )
   118     if ( KPreSettingViewId != aPrevViewId.iViewUid )
   141         {        
   119         {        
   142         iPSUIGSPrevViewId = aPrevViewId;
   120         iPSUIGSPrevViewId = aPrevViewId;
   143         }
   121         }
   144     
   122     
   145     // model & observer constructed only when needed
   123     // model & observer constructed only when needed
   146     if ( !iPSModel )
   124     if ( !iPSModel )
   147         {
   125         {
   148         iPSModel = CPSUIGSPluginModel::NewL();
   126         iPSModel = CPSUIGSPluginModel::NewL();   
   149         iAppUi->AddViewDeactivationObserverL( this );        
       
   150         }
   127         }
   151 
   128 
   152     const TInt id = iPSModel->SettingsId();
   129     const TInt id = iPSModel->SettingsId();
   153     if ( id )
   130     if ( id )
   154         {// readjust the focus
   131         {// readjust the focus
   155         SetCurrentItem( iPSModel->SettingsIDArray().Find( id ));
       
   156         }
   132         }
   157 
   133 
   158     iClosing = EFalse;
   134     iClosing = EFalse;
   159     CGSBaseView::DoActivateL( aPrevViewId, aCustomMessageId, aCustomMessage );
       
   160     UpdateMSK();
   135     UpdateMSK();
   161     }
   136     }
   162 
   137 
   163 // ---------------------------------------------------------------------------
   138 // ---------------------------------------------------------------------------
   164 // CPSUIGSPlugin::DoDeactivate()
   139 // CPSUIGSPlugin::DoDeactivate()
   165 // See header for details.
   140 // See header for details.
   166 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
   167 //
   142 //
   168 void CPSUIGSPlugin::DoDeactivate()
   143 void CPSUIGSPlugin::DoDeactivate()
   169     {
   144     {
   170     CGSBaseView::DoDeactivate();
       
   171     if ( iClosing )
   145     if ( iClosing )
   172         {// PSUI plugin is going to be closed so it is safe to free some memory
   146         {// PSUI plugin is going to be closed so it is safe to free some memory
   173         delete iPSModel;
   147         delete iPSModel;
   174         iPSModel = NULL;
   148         iPSModel = NULL;
   175         delete iSettingView;
       
   176         iSettingView = NULL;        
       
   177         }    
   149         }    
   178     }
   150     }
   179 
   151 
   180 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------
   181 // CPSUIGSPlugin::HandleViewDeactivation()
   153 // CPSUIGSPlugin::HandleViewDeactivation()
   188     {
   160     {
   189     if ( TUid::Uid( PSUIGSPluginImplUid ) == aViewIdToBeDeactivated.iViewUid && 
   161     if ( TUid::Uid( PSUIGSPluginImplUid ) == aViewIdToBeDeactivated.iViewUid && 
   190         iPSUIGSPrevViewId.iViewUid == aNewlyActivatedViewId.iViewUid )
   162         iPSUIGSPrevViewId.iViewUid == aNewlyActivatedViewId.iViewUid )
   191         {
   163         {
   192         iClosing = ETrue;
   164         iClosing = ETrue;
   193         iAppUi->RemoveViewDeactivationObserver( this );
       
   194         }
   165         }
   195     }
   166     }
   196 
   167 
   197 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   198 // CPSUIGSPlugin::HandleCommandL()
   169 // CPSUIGSPlugin::HandleCommandL()
   204     switch ( aCommand )
   175     switch ( aCommand )
   205         {
   176         {
   206         case EAknSoftkeyBack:
   177         case EAknSoftkeyBack:
   207             {
   178             {
   208             RemoveSettingView();
   179             RemoveSettingView();
   209             iAppUi->ActivateLocalViewL( iPSUIGSPrevViewId.iViewUid );
       
   210             break;
   180             break;
   211             }
   181             }
   212         case EPSUICmdEdit:
   182         case EPSUICmdEdit:
   213             {
   183             {
   214             HandleListBoxSelectionL();
       
   215             break;
   184             break;
   216             }
   185             }
   217         case EPSUICmdDelete:
   186         case EPSUICmdDelete:
   218             {
   187             {
   219             DeleteSettingsL();
   188             DeleteSettingsL();
   231             }
   200             }
   232         case EAknCmdHelp:
   201         case EAknCmdHelp:
   233             {
   202             {
   234             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
   203             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
   235                 {
   204                 {
   236                 HlpLauncher::LaunchHelpApplicationL(
       
   237                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   238                 }
   205                 }
   239             break;
   206             break;
   240             }                       
   207             }                       
   241         default:
   208         default:
   242             {
   209             {
   243             iAppUi->HandleCommandL( aCommand );
       
   244             break;
   210             break;
   245             }
   211             }
   246         }
   212         }
   247     }
   213     }
   248 
   214 
   249 // ---------------------------------------------------------------------------
   215 // ---------------------------------------------------------------------------
   250 // CPSUIGSPlugin::SettingCountAndIndex()
   216 // CPSUIGSPlugin::SettingCountAndIndex()
   251 // See header for details.
   217 // See header for details.
   252 // ---------------------------------------------------------------------------
   218 // ---------------------------------------------------------------------------
   253 //
   219 //
   254 TInt CPSUIGSPlugin::SettingCountAndIndex( TInt& aIndex )
   220 TInt CPSUIGSPlugin::SettingCountAndIndex( TInt& /*aIndex*/ )
   255     {
   221     {
   256     CEikTextListBox* listbox = Container()->iListBox;// not owned
   222     return KErrNone;        
   257     TInt count = listbox->Model()->NumberOfItems();
       
   258     aIndex = count ? listbox->CurrentItemIndex() : KErrNotFound;
       
   259         
       
   260     return count;        
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CPSUIGSPlugin::HandleListBoxSelectionL()
       
   265 // See header for details.
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 void CPSUIGSPlugin::HandleListBoxSelectionL()
       
   269     {
       
   270     TInt index = KErrNotFound;
       
   271     if ( SettingCountAndIndex( index ))
       
   272         {
       
   273         iPSModel->EditSettingsL( index );
       
   274 
       
   275         ConstructSettingViewL();    
       
   276         iAppUi->ActivateLocalViewL( KPreSettingViewId );
       
   277         }
       
   278     }
   223     }
   279 
   224 
   280 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   281 // CPSUIGSPlugin::DeleteSettingsL()
   226 // CPSUIGSPlugin::DeleteSettingsL()
   282 // See header for details.
   227 // See header for details.
   289     if ( count )
   234     if ( count )
   290         {
   235         {
   291         if ( AcceptDeletionL( count, index ))
   236         if ( AcceptDeletionL( count, index ))
   292             {
   237             {
   293             iPSModel->DeleteSettingsL( index, ETrue );
   238             iPSModel->DeleteSettingsL( index, ETrue );
   294             CEikTextListBox* listbox = Container()->iListBox;// not owned
       
   295             AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   296                 listbox, index, ETrue );
       
   297             listbox->DrawNow();
       
   298             UpdateMSK();    
   239             UpdateMSK();    
   299             }
   240             }
   300         }
   241         }
   301     }
   242     }
   302 
   243 
   306 // ---------------------------------------------------------------------------
   247 // ---------------------------------------------------------------------------
   307 //
   248 //
   308 TBool CPSUIGSPlugin::AcceptDeletionL( TInt aCount, TInt aIndex )
   249 TBool CPSUIGSPlugin::AcceptDeletionL( TInt aCount, TInt aIndex )
   309     {
   250     {
   310     HBufC* currentName = iPSModel->SettingNameLC( aIndex );
   251     HBufC* currentName = iPSModel->SettingNameLC( aIndex );
   311     HBufC* string = NULL;
       
   312     if ( aCount == 1 )
   252     if ( aCount == 1 )
   313         {
   253         {
   314         string = StringLoader::LoadLC( R_QTN_PRESENCE_SETTINGS_DELETE_LAST, *currentName );
       
   315         }
   254         }
   316     else
   255     else
   317         {
   256         {
   318         string = StringLoader::LoadLC( R_QTN_QUERY_COMMON_CONF_DELETE, *currentName );
       
   319         }
   257         }
   320 
   258 
   321     CAknQueryDialog* query = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );        
   259     CAknQueryDialog* query = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );        
   322     TInt ok = query->ExecuteLD( R_PSUI_CONF_QUERY,  *string );
   260     TInt ok = KErrNone;
   323     
   261     
   324     CleanupStack::PopAndDestroy( 2, currentName );//currentName, string       
   262     CleanupStack::PopAndDestroy( 2, currentName );//currentName, string       
   325         
   263         
   326     return ( ok );    
   264     return ( ok );    
   327     }
   265     }
   328 
   266 
   329 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   330 // CPSUIGSPlugin::GetCaptionL()
       
   331 // See header for details.
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CPSUIGSPlugin::GetCaptionL( TDes& aCaption ) const
       
   335     {
       
   336     StringLoader::Load( aCaption, R_QTN_SET_FOLDER_PRESENCE );
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CPSUIGSPlugin::PluginProviderCategory()
       
   341 // See header for details.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 TInt CPSUIGSPlugin::PluginProviderCategory() const
       
   345     {
       
   346     return KGSPluginProviderInternal;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // CPSUIGSPlugin::CreateIconL()
       
   351 // See header for details.
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 CGulIcon* CPSUIGSPlugin::CreateIconL( const TUid aIconType )
       
   355     {
       
   356     CGulIcon* icon = NULL;
       
   357     if( aIconType == KGSIconTypeLbxItem )
       
   358         {
       
   359         icon = AknsUtils::CreateGulIconL(
       
   360             AknsUtils::SkinInstance(), 
       
   361             KAknsIIDQgnPropSetConnPresence,
       
   362             KPSUIGSPluginIconFileName,
       
   363             EMbmPsuigspluginQgn_prop_set_conn_presence,
       
   364             EMbmPsuigspluginQgn_prop_set_conn_presence_mask );
       
   365         }
       
   366      else
       
   367         {
       
   368         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   369         }
       
   370     
       
   371     return icon;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CPSUIGSPlugin::DynInitMenuPaneL()
   268 // CPSUIGSPlugin::DynInitMenuPaneL()
   376 // See header for details.
   269 // See header for details.
   377 // ---------------------------------------------------------------------------
   270 // ---------------------------------------------------------------------------
   378 //
   271 //
   379 void CPSUIGSPlugin::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane *aMenuPane )
   272 void CPSUIGSPlugin::DynInitMenuPaneL( TInt /*aResourceId*/, CEikMenuPane */*aMenuPane*/ )
   380     {
   273     {
   381     // remove some of the items if no settings available
       
   382     const TInt count = Container()->iListBox->Model()->NumberOfItems();
       
   383     if ( aResourceId == R_PSUI_MAINVIEW_MENUPANE && 
       
   384         0 == count )
       
   385         {
       
   386         aMenuPane->DeleteMenuItem( EPSUICmdEdit );
       
   387         aMenuPane->DeleteMenuItem( EPSUICmdDelete );
       
   388         }
       
   389     if ( aResourceId == R_PSUI_NEWSETTINGS_MENU && 
       
   390         0 == count )
       
   391         {
       
   392         aMenuPane->DeleteMenuItem( EPSUICmdNewSettingsExisting );
       
   393         }
       
   394     
       
   395     // help-item handling
       
   396     if ( aResourceId == R_PSUI_MAINVIEW_MENUPANE && 
       
   397         !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   398         {
       
   399         aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   400         }
       
   401     }
   274     }
   402 
   275 
   403 // ---------------------------------------------------------------------------
   276 // ---------------------------------------------------------------------------
   404 // CPSUIGSPlugin::PSModel()
   277 // CPSUIGSPlugin::PSModel()
   405 // See header for details.
   278 // See header for details.
   416 // See header for details.
   289 // See header for details.
   417 // ---------------------------------------------------------------------------
   290 // ---------------------------------------------------------------------------
   418 //    
   291 //    
   419 void CPSUIGSPlugin::ConstructSettingViewL()
   292 void CPSUIGSPlugin::ConstructSettingViewL()
   420     {
   293     {
   421     if ( !iSettingView )
       
   422         {// no view yet, construct it
       
   423         CAknView* view = CPSUIGSPluginSettingView::NewL( this );
       
   424         CleanupStack::PushL( view );
       
   425         iAppUi->AddViewL( view );
       
   426         CleanupStack::Pop( view );
       
   427         iSettingView = view;
       
   428         }
       
   429     }
   294     }
   430     
   295     
   431 // ---------------------------------------------------------------------------
   296 // ---------------------------------------------------------------------------
   432 // CPSUIGSPlugin::RemoveSettingView()
   297 // CPSUIGSPlugin::RemoveSettingView()
   433 // See header for details.
   298 // See header for details.
   434 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   435 //    
   300 //    
   436 void CPSUIGSPlugin::RemoveSettingView()
   301 void CPSUIGSPlugin::RemoveSettingView()
   437     {
   302     {
   438     // Remove view from iAppUi -> View is deleted by iAppUi automatically.
       
   439     if ( iSettingView )
       
   440         {
       
   441         iAppUi->RemoveView( KPreSettingViewId );
       
   442         iSettingView = NULL;
       
   443         }
       
   444     }
   303     }
   445     
   304     
   446 // ---------------------------------------------------------------------------
   305 // ---------------------------------------------------------------------------
   447 // CPSUIGSPlugin::CreateNewDefaultSettingsL()
   306 // CPSUIGSPlugin::CreateNewDefaultSettingsL()
   448 // See header for details.
   307 // See header for details.
   450 // 
   309 // 
   451 void CPSUIGSPlugin::CreateNewDefaultSettingsL()
   310 void CPSUIGSPlugin::CreateNewDefaultSettingsL()
   452     {
   311     {
   453     iPSModel->CreateDefaultSettingsL();
   312     iPSModel->CreateDefaultSettingsL();
   454     ConstructSettingViewL();
   313     ConstructSettingViewL();
   455     iAppUi->ActivateLocalViewL( KPreSettingViewId );
       
   456     }
   314     }
   457 
   315 
   458 // ---------------------------------------------------------------------------
   316 // ---------------------------------------------------------------------------
   459 // CPSUIGSPlugin::CreateCopyOfExistingSettingsL()
   317 // CPSUIGSPlugin::CreateCopyOfExistingSettingsL()
   460 // See header for details.
   318 // See header for details.
   468 
   326 
   469     CAknPopupList* popupList = 
   327     CAknPopupList* popupList = 
   470         CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL );
   328         CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL );
   471     CleanupStack::PushL( popupList );    
   329     CleanupStack::PushL( popupList );    
   472     
   330     
   473     HBufC* title = StringLoader::LoadLC( R_QTN_PRESENCE_PROPMT_USE_EXIST );
       
   474     popupList->SetTitleL( *title );
       
   475     CleanupStack::PopAndDestroy( title );
       
   476 
   331 
   477     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
   332     list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
   478     list->CreateScrollBarFrameL( ETrue );
   333     list->CreateScrollBarFrameL( ETrue );
   479     list->ScrollBarFrame()->SetScrollBarVisibilityL( 
   334     list->ScrollBarFrame()->SetScrollBarVisibilityL( 
   480         CEikScrollBarFrame::EOff, 
   335         CEikScrollBarFrame::EOff, 
   490     
   345     
   491     if ( keyPress )
   346     if ( keyPress )
   492         {
   347         {
   493         iPSModel->DuplicateExistingSettingsL( list->CurrentItemIndex() );
   348         iPSModel->DuplicateExistingSettingsL( list->CurrentItemIndex() );
   494         ConstructSettingViewL();
   349         ConstructSettingViewL();
   495         iAppUi->ActivateLocalViewL( KPreSettingViewId );        
       
   496         }
   350         }
   497     
   351     
   498     CleanupStack::PopAndDestroy( list );
   352     CleanupStack::PopAndDestroy( list );
   499     }   
   353     }   
   500 
   354 
   503 // See header for details.
   357 // See header for details.
   504 // ---------------------------------------------------------------------------
   358 // ---------------------------------------------------------------------------
   505 // 
   359 // 
   506 void CPSUIGSPlugin::UpdateMSK()
   360 void CPSUIGSPlugin::UpdateMSK()
   507     {
   361     {
   508     TBool showEdit = ( 0 < Container()->iListBox->Model()->NumberOfItems());
       
   509     CEikCba* cba = static_cast< CEikCba* >( Cba()->ButtonGroup() );
       
   510     cba->MakeCommandVisible( EPSUICmdEdit, showEdit );
       
   511     cba->DrawNow();
       
   512     }
   362     }
   513 
   363 
   514 // End of file
   364 // End of file