presencesettingsui/src/psuigspluginsettingview.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     1 /*
       
     2 * Copyright (c) 2006 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:    Presence Settings UI setting view implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <bautils.h>
       
    23 #include <psuigspluginrsc.rsg>
       
    24 #include <StringLoader.h>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <aknnotewrappers.h>
       
    27 #include <aknViewAppUi.h>
       
    28 #include <featmgr.h>
       
    29 #include <hlplch.h>
       
    30 #include "psuigsplugin.h"
       
    31 #include "psuigspluginsettingview.h"
       
    32 #include "psuigspluginmodel.h"
       
    33 #include "psuigspluginsettingviewcontainer.h"
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 // ========================= MEMBER FUNCTIONS ================================
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CPSUIGSPluginSettingView::CPSUIGSPluginSettingView()
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CPSUIGSPluginSettingView::CPSUIGSPluginSettingView( CPSUIGSPlugin* aMainView )
       
    46     : iMainView ( aMainView )
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CPSUIGSPluginSettingView::~CPSUIGSPluginSettingView()
       
    52 // Destructor
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CPSUIGSPluginSettingView::~CPSUIGSPluginSettingView()
       
    56     {
       
    57     // iAppUi, iMainView deleted elsewhere
       
    58     if ( iPSUIContainer && iAppUi )
       
    59         {
       
    60         iAppUi->RemoveFromViewStack( *this, iPSUIContainer );
       
    61         delete iPSUIContainer;
       
    62         iPSUIContainer = NULL;
       
    63         }
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CPSUIGSPluginSettingView::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CPSUIGSPluginSettingView::ConstructL()
       
    72     {
       
    73     // base construct
       
    74     BaseConstructL( R_PSUI_SETTING_VIEW );
       
    75     iAppUi = AppUi();
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CPSUIGSPluginSettingView::NewL()
       
    80 // Two-phased constructor.
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CPSUIGSPluginSettingView* CPSUIGSPluginSettingView::NewL( CPSUIGSPlugin* aMainView )
       
    84     {
       
    85     CPSUIGSPluginSettingView* self = new( ELeave ) CPSUIGSPluginSettingView( aMainView );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop( self );
       
    89     return self;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CPSUIGSPluginSettingView::Id()
       
    94 // See header for details.
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 TUid CPSUIGSPluginSettingView::Id() const
       
    98     {
       
    99     return KPreSettingViewId;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CPSUIGSPluginSettingView::HandleViewRectChange()
       
   104 // See header for details.
       
   105 // ---------------------------------------------------------------------------
       
   106 //  
       
   107 void CPSUIGSPluginSettingView::HandleViewRectChange()
       
   108     {
       
   109     if ( iPSUIContainer && iPSUIContainer->ListBox() )
       
   110         {
       
   111         iPSUIContainer->SetRect( ClientRect() );
       
   112         }
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CPSUIGSPluginSettingView::DoActivateL()
       
   117 // See header for details.
       
   118 // ---------------------------------------------------------------------------
       
   119 //  
       
   120 void CPSUIGSPluginSettingView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   121                                   TUid /*aCustomMessageId*/,
       
   122                                   const TDesC8& /*aCustomMessage*/ )
       
   123     {
       
   124     iPrevViewId = aPrevViewId;
       
   125 
       
   126     CreateContainerL();
       
   127     iAppUi->AddToViewStackL( *this, iPSUIContainer );
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CPSUIGSPluginSettingView::DoDeactivate()
       
   132 // See header for details.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CPSUIGSPluginSettingView::DoDeactivate()
       
   136     {
       
   137     if ( iPSUIContainer )
       
   138         {
       
   139         iAppUi->RemoveFromViewStack( *this, iPSUIContainer );
       
   140         delete iPSUIContainer;
       
   141         iPSUIContainer = NULL;
       
   142         }
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CPSUIGSPluginSettingView::HandleCommandL()
       
   147 // See header for details.
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CPSUIGSPluginSettingView::HandleCommandL( TInt aCommand )
       
   151     {
       
   152     switch ( aCommand )
       
   153         {
       
   154         case EAknSoftkeyBack:
       
   155             {
       
   156             HandleBackKeyL();
       
   157             break;
       
   158             }
       
   159         case EPSUICmdChange:
       
   160             {
       
   161             iPSUIContainer->EditCurrentItemL();
       
   162             break;
       
   163             }
       
   164         case EAknCmdHelp:
       
   165             {
       
   166             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   167                 {
       
   168                 HlpLauncher::LaunchHelpApplicationL(
       
   169                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   170                 }
       
   171             break;
       
   172             }              
       
   173         default:
       
   174             {
       
   175             if ( EEikCmdExit == aCommand )
       
   176                 {
       
   177                 HandleMenuExitL();
       
   178                 }            
       
   179             
       
   180             iAppUi->HandleCommandL( aCommand );
       
   181             break;
       
   182             }
       
   183         }
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CPSUIGSPluginSettingView::CreateContainerL()
       
   188 // See header for details.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CPSUIGSPluginSettingView::CreateContainerL()
       
   192     {
       
   193     // delete container if present
       
   194     if( iPSUIContainer )
       
   195         {
       
   196         iAppUi->RemoveFromViewStack( *this, iPSUIContainer );
       
   197         delete iPSUIContainer;
       
   198         iPSUIContainer = NULL;
       
   199         }
       
   200     
       
   201     // check the data    
       
   202     iMainView->PSModel()->ClearInvalidSIPAndXDMSettingsL();  
       
   203     
       
   204     // create container
       
   205     iPSUIContainer = new ( ELeave ) CPSUIGSPluginSettingViewContainer( this );
       
   206     iPSUIContainer->SetMopParent( this );
       
   207     iPSUIContainer->ConstructL( ClientRect() );
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CPSUIGSPluginSettingView::HandleBackKeyL()
       
   212 // See header for details.
       
   213 // ---------------------------------------------------------------------------
       
   214 //    
       
   215 void CPSUIGSPluginSettingView::HandleBackKeyL()
       
   216     {
       
   217     CPSUIGSPluginModel* psModel = iMainView->PSModel();// not owned
       
   218     
       
   219     TBool okToGoBack = ETrue;
       
   220     TBool okToSave = ETrue;
       
   221     psModel->ClearInvalidSIPAndXDMSettingsL();
       
   222     const TInt id = psModel->SettingsId();
       
   223     
       
   224     // compulsory-field handling
       
   225     if ( !psModel->AllCompulsoryFieldsFilled())
       
   226         {// empty compulsory fields found
       
   227         okToSave = EFalse;
       
   228         HBufC* string = StringLoader::LoadLC( 
       
   229             R_QTN_PRESENCE_SETTINGS_NOT_FILLED );
       
   230         CAknQueryDialog* query = CAknQueryDialog::NewL( 
       
   231             CAknQueryDialog::EConfirmationTone );        
       
   232         if ( !query->ExecuteLD( R_PSUI_CONF_QUERY,  *string ))
       
   233             {
       
   234             okToGoBack = EFalse;
       
   235             }
       
   236         CleanupStack::PopAndDestroy( string );// string         
       
   237         }
       
   238         
       
   239     // same name checking        
       
   240     if ( okToSave && HandleDuplicatePSNamesL() )
       
   241         {// same name found
       
   242         okToGoBack = EFalse;
       
   243         okToSave = EFalse;
       
   244         iPSUIContainer->EditItemL( EPSUIServerNameId, ETrue );
       
   245         }
       
   246      
       
   247     if ( okToSave )
       
   248         {// save settings
       
   249         psModel->SaveSettingsL();
       
   250         }
       
   251     else if ( !okToSave && okToGoBack && id )
       
   252         {// old settings, delete and go back
       
   253         psModel->DeleteSettingsL( id, EFalse );
       
   254         }
       
   255     if ( okToGoBack )
       
   256         {// go back, no save or delete
       
   257         iAppUi->ActivateLocalViewL( iPrevViewId.iViewUid );
       
   258         }
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CPSUIGSPluginSettingView::HandleMenuExitL()
       
   263 // See header for details.
       
   264 // ---------------------------------------------------------------------------
       
   265 //  
       
   266 void CPSUIGSPluginSettingView::HandleMenuExitL()
       
   267     {
       
   268     CPSUIGSPluginModel* psModel = iMainView->PSModel();// not owned
       
   269     if ( !psModel )
       
   270         {// no model, can't do anything
       
   271         // (leaving would stop exiting, so just return)
       
   272         return;
       
   273         }
       
   274     
       
   275     if ( psModel->AllCompulsoryFieldsFilled() )
       
   276         {// needed fields filled, proceed saving
       
   277         if ( psModel->IsItDuplicatePSName() )
       
   278             {// a dupe name -> change name
       
   279             HBufC* newName = psModel->CreateSettingNameLC( 
       
   280                 psModel->SettingsSet().iSetName.AllocL() );
       
   281             psModel->SettingsSet().iSetName.Copy( newName->Des() );
       
   282             CleanupStack::PopAndDestroy( newName );            
       
   283             }
       
   284         // save settings
       
   285         psModel->SaveSettingsL();            
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CPSUIGSPluginSettingView::HandleDuplicatePSNamesL()
       
   291 // See header for details.
       
   292 // ---------------------------------------------------------------------------
       
   293 // 
       
   294 TBool CPSUIGSPluginSettingView::HandleDuplicatePSNamesL()
       
   295     {
       
   296     TBool found = iMainView->PSModel()->IsItDuplicatePSName();
       
   297     if ( found )
       
   298         {
       
   299         HBufC* fullText = StringLoader::LoadLC( 
       
   300             R_QTN_PRESENCE_SETTINGS_NAME_EXISTS, 
       
   301             iMainView->PSModel()->SettingsSet().iSetName );
       
   302         CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue ); //wait-flag on
       
   303         note->ExecuteLD( *fullText );
       
   304         CleanupStack::PopAndDestroy( fullText );
       
   305         }
       
   306     return found;
       
   307     }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CPSUIGSPluginSettingView::MainView()
       
   311 // See header for details.
       
   312 // ---------------------------------------------------------------------------
       
   313 //    
       
   314 CPSUIGSPlugin* CPSUIGSPluginSettingView::MainView()
       
   315     {
       
   316     return iMainView;
       
   317     }
       
   318 
       
   319 // End of file