mobilemessaging/smum/src/SmumEmailServiceCentreItemDialog.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     A dialog for adding new and editing old service centres.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <SMUM.rsg>                     // resource identifiers
       
    23 #include <smutset.h>                    // CSmsSettings
       
    24 #include <aknappui.h>                   // CEikStatusPane
       
    25 #include <akntitle.h>                   // CAknTitlePane
       
    26 #include <StringLoader.h>               // StringLoader
       
    27 #include <commonphoneparser.h>          // CommonPhoneParser
       
    28 #include <aknnotewrappers.h>
       
    29 #include <eikmenup.h>                   // CEikMenuPane
       
    30 #include <hlplch.h>                     // For HlpLauncher
       
    31 #include <csxhelp/mce.hlp.hrh>
       
    32 // locals
       
    33 #include "SmumSettingsDialogGSM.h"         // KStringLength
       
    34 #include "SmumEmailServiceCentreItemDialog.h"// CSmumEmailServiceCentreDialog 
       
    35 #include "SMSU.HRH"                     // resource header
       
    36 #include "SmumServiceCentresDialog.h"   // CSmsServiceCentresDialog
       
    37 #include "smsui.pan"
       
    38 
       
    39 // CONSTANTS
       
    40 const TInt KSCNameLength = 100;
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 // C++ constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 CSmumEmailServiceCentreDialog::CSmumEmailServiceCentreDialog (
       
    45     TDes&           aGateway, 
       
    46     TDes&           aSC,
       
    47     const TBool&    aModifiable,
       
    48     TInt&           aExitCode,
       
    49     TBool           aHelpFeatureSupported ) 
       
    50         :iGateway               ( aGateway ), 
       
    51         iSC                     ( aSC ),
       
    52         iModifiable             ( aModifiable ),
       
    53         iExitCode               ( aExitCode ),
       
    54         iHelpFeatureSupported   ( aHelpFeatureSupported ),
       
    55         iLaunchDialog           ( EFalse )
       
    56     {
       
    57     }
       
    58 
       
    59 // Destructor
       
    60 CSmumEmailServiceCentreDialog::~CSmumEmailServiceCentreDialog ()
       
    61     {
       
    62     if ( iListBox )
       
    63         {
       
    64         iListBox->SetScrollBarFrame( NULL, CEikListBox::EOwnedExternally );
       
    65         }
       
    66     delete iPreviousTitleText;
       
    67     // iSettingsArray, iListBox, iTitlePane are
       
    68     // plain pointers to objects owned by other classes which take
       
    69     // care also about deletion.
       
    70     // Set to NULL to satisfy Lint
       
    71     iSettingsArray = NULL;
       
    72     iListBox = NULL;
       
    73     iTitlePane = NULL;
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------
       
    77 // CSmumEmailServiceCentreDialog::OkToExitL
       
    78 //
       
    79 // ----------------------------------------------------
       
    80 TInt CSmumEmailServiceCentreDialog::OkToExitL( TInt aButtonId )
       
    81     {
       
    82     TInt returnValue;
       
    83 
       
    84     switch( aButtonId )
       
    85         {
       
    86         case ESmsSettingsChoiceMenuChange:
       
    87 	        {
       
    88 	        ProcessCommandL( aButtonId );
       
    89 	        returnValue = EFalse; // Cannot exit, since MSK was pressed
       
    90 	        }     
       
    91 	        break;
       
    92         // menu / system exit
       
    93         case EAknSoftkeyCancel: 
       
    94             {
       
    95             if ( iExitCode != ESmumSmsSettingsMenuExit &&
       
    96                 iExitCode != ESmumSmsSettingsSystemExit )
       
    97                 {
       
    98                 // system exit
       
    99                 iExitCode = ESmumSmsSettingsSystemExit;
       
   100                 }
       
   101             // Special handling for menu exit
       
   102             if ( iExitCode == ESmumSmsSettingsMenuExit )
       
   103                 {
       
   104                 returnValue = ClosingEmailSettingsItemDialogL();
       
   105                 }
       
   106             else
       
   107                 {
       
   108                 TRAP_IGNORE( ClosingEmailSettingsItemDialogL() ); 
       
   109                 returnValue = ETrue; // to be sure of not leaving and exiting
       
   110                 }
       
   111             }
       
   112             break;
       
   113         case EAknSoftkeyBack:
       
   114             {
       
   115             iExitCode = ESmumSmsSettingsBack;
       
   116             returnValue = ClosingEmailSettingsItemDialogL();
       
   117             }
       
   118             break;
       
   119         default :
       
   120             returnValue = CAknDialog::OkToExitL( aButtonId );
       
   121             break;
       
   122         }
       
   123 
       
   124     return returnValue;
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------
       
   128 // CSmumEmailServiceCentreDialog::HandleListBoxEventL
       
   129 //
       
   130 // ----------------------------------------------------
       
   131 void CSmumEmailServiceCentreDialog::HandleListBoxEventL(
       
   132     CEikListBox* /*aListBox*/, 
       
   133     TListBoxEvent aEventType )
       
   134     {
       
   135     switch( aEventType )
       
   136         {
       
   137         case EEventEnterKeyPressed:
       
   138         case EEventItemSingleClicked:
       
   139             OpenSettingPageL( ETrue );
       
   140             break;
       
   141         default :
       
   142             // panic
       
   143             break;
       
   144         }
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------
       
   148 // CSmumEmailServiceCentreDialog::OfferKeyEventL
       
   149 //
       
   150 // ----------------------------------------------------
       
   151 TKeyResponse CSmumEmailServiceCentreDialog::OfferKeyEventL(
       
   152     const TKeyEvent& aKeyEvent,
       
   153     TEventCode aType )
       
   154     {
       
   155     TKeyResponse returnValue = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   156     return returnValue;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------
       
   160 // CSmumEmailServiceCentreDialog::ProcessCommandL
       
   161 //
       
   162 // ----------------------------------------------------
       
   163 void CSmumEmailServiceCentreDialog::ProcessCommandL(
       
   164     TInt aCommandId )
       
   165     {
       
   166     CAknDialog::ProcessCommandL( aCommandId ) ;
       
   167     switch ( aCommandId )
       
   168         {
       
   169         case ESmsSettingsChoiceMenuChange:
       
   170             OpenSettingPageL( EFalse );
       
   171         break;
       
   172         case EAknCmdHelp:           
       
   173             LaunchHelpL();            
       
   174             break;
       
   175         case ESmsSettingsChoiceMenuExit:
       
   176             { 
       
   177             iExitCode = ESmumSmsSettingsMenuExit;
       
   178             TryExitL( EAknSoftkeyCancel );
       
   179             }
       
   180             break;
       
   181         default :
       
   182             break;
       
   183         }
       
   184     }
       
   185 
       
   186 // ----------------------------------------------------
       
   187 // CSmumEmailServiceCentreDialog::OpenSettingPageL
       
   188 //
       
   189 // ----------------------------------------------------
       
   190 void CSmumEmailServiceCentreDialog::OpenSettingPageL(
       
   191     TBool aEnterPressed )
       
   192     {
       
   193     TInt index = iListBox->CurrentItemIndex();
       
   194     __ASSERT_DEBUG( index >= 0 , Panic( ESmsetdlgInvalidIndex ));
       
   195     
       
   196     if ( KErrNotFound != index )//check we have something in listbox
       
   197         {
       
   198         if ( iModifiable ) // Permisson to edit
       
   199             { // Edit the selected setting
       
   200             ModifySettingNumberL( aEnterPressed, index );
       
   201             }
       
   202         else // Show note
       
   203             {
       
   204             ShowInformationNoteL( R_QTN_SMS_EMAIL_SETT_CANNOT_CHANGE );
       
   205             }
       
   206         }
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CSmumEmailServiceCentreDialog::DynInitMenuPaneL
       
   211 //
       
   212 // ---------------------------------------------------------
       
   213 void CSmumEmailServiceCentreDialog::DynInitMenuPaneL(
       
   214     TInt aMenuId, 
       
   215     CEikMenuPane* aMenuPane)
       
   216     {
       
   217     if ( aMenuPane )
       
   218         {
       
   219         switch ( aMenuId )
       
   220             {
       
   221             case R_SMS_SERVICECENTRE_ITEM_CHOICE_MENUPANE:
       
   222                 // Help handling
       
   223                 aMenuPane->SetItemDimmed( EAknCmdHelp, !iHelpFeatureSupported );
       
   224                 break;
       
   225             default :
       
   226                 // panic
       
   227                 break;
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 // ----------------------------------------------------
       
   233 // CSmumEmailServiceCentreDialog::ModifySettingNumberL
       
   234 //
       
   235 // ----------------------------------------------------
       
   236 void CSmumEmailServiceCentreDialog::ModifySettingNumberL( TBool aEnterPressed, TInt aIndex )
       
   237     {
       
   238     TBool validNumber = EFalse;
       
   239     TBool canExit = EFalse;
       
   240     // Take the original number safe
       
   241     TBuf<KSCNameLength> origNumber = iSettingsArray->At( aIndex ).iUserText;
       
   242     // Check validity
       
   243     while ( !canExit )
       
   244         {
       
   245         // Did user press ok in setting page ?
       
   246         if ( iSettingsArray->EditItemL( aIndex, aEnterPressed ))
       
   247             {
       
   248             // yes, ok pressed
       
   249             // Check number with commonphoneparser
       
   250             validNumber = CommonPhoneParser::ParsePhoneNumber( 
       
   251                 iSettingsArray->At( aIndex ).iUserText,
       
   252                 CommonPhoneParser::ESMSNumber );
       
   253             if ( validNumber )
       
   254                 {                
       
   255                 canExit = ETrue;
       
   256                 // Update the ListView accordingly
       
   257 		    	iListBox->DrawNow();    
       
   258                 }
       
   259             else 
       
   260                 {
       
   261                 // Show "invalid number"-note
       
   262                 ShowInformationNoteL( R_QTN_INFO_INVALID_NUMBER );
       
   263                 canExit = EFalse;
       
   264                 }            
       
   265             }
       
   266         else
       
   267             {
       
   268             // no, cancel pressed
       
   269             // In case of cancel, restore the value
       
   270             iSettingsArray->At( aIndex ).iUserText = origNumber;
       
   271             canExit = ETrue;
       
   272             }
       
   273         }
       
   274     }
       
   275 
       
   276 // ----------------------------------------------------
       
   277 // CSmumEmailServiceCentreDialog::PreLayoutDynInitL
       
   278 //
       
   279 // ----------------------------------------------------
       
   280 void CSmumEmailServiceCentreDialog::PreLayoutDynInitL()
       
   281     {
       
   282     // Setting arrays in order
       
   283     iListBox = static_cast<CEikTextListBox*> ( Control( ESmsSCAddEditId ) );
       
   284     iSettingsArray = CMuiuSettingsArray::NewL( R_EMAIL_SERVICECENTRE_ITEMS );
       
   285 
       
   286     iSettingsArray->At( ESmumEmailServiceCentreNumber ).iUserText.Copy( iSC );
       
   287     iSettingsArray->At( ESmumEmailGateway ).iUserText.Copy( iGateway );
       
   288 
       
   289     iListBox->SetListBoxObserver( this );
       
   290 
       
   291     CTextListBoxModel* model = iListBox->Model();
       
   292     model->SetItemTextArray( iSettingsArray );
       
   293 
       
   294     // Fetch pointer to titlepane
       
   295     CEikStatusPane *sp =  static_cast<CAknAppUi*> 
       
   296         ( CEikonEnv::Static()->EikAppUi())->StatusPane();
       
   297     iTitlePane = static_cast<CAknTitlePane*> 
       
   298         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle )) );
       
   299     // Take old titlepane text safe
       
   300     iPreviousTitleText = ( *iTitlePane->Text() ).Alloc();
       
   301     HBufC* text = StringLoader::LoadLC( R_QTN_MCE_SETT_TITLE_SMS_MAIL );
       
   302     iTitlePane->SetTextL( *text );
       
   303     CleanupStack::PopAndDestroy(); // text
       
   304     }
       
   305 
       
   306 // ----------------------------------------------------
       
   307 // CSmumEmailServiceCentreDialog::ClosingEmailSettingsItemDialogL
       
   308 //
       
   309 // ----------------------------------------------------
       
   310 TBool CSmumEmailServiceCentreDialog::ClosingEmailSettingsItemDialogL()
       
   311     {
       
   312     TBool retValue = EFalse;
       
   313     TInt scSize( 
       
   314         iSettingsArray->At( ESmumEmailServiceCentreNumber ).iUserText.Size() );
       
   315     TInt gatewaySize( 
       
   316         iSettingsArray->At( ESmumEmailGateway ).iUserText.Size() );
       
   317     // Did user left empty fields?
       
   318     if ( !scSize || !gatewaySize )
       
   319         { // Yes, we have empty fields
       
   320         if ( iExitCode == ESmumSmsSettingsSystemExit ) // Are we exiting?
       
   321             { // Exiting fast without any queries or titlepane updates
       
   322             iSC.Zero();
       
   323             iGateway.Zero();
       
   324             retValue = ETrue;
       
   325             }
       
   326         else 
       
   327             {
       
   328             // do we exit without valid settings?
       
   329             CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   330             if ( dlg->ExecuteLD( R_EMAIL_SETTINGS_INCOMPLETE_QUERY ) )
       
   331                 {// Yes
       
   332                 // reset values
       
   333                 iSC.Zero();
       
   334                 iGateway.Zero();
       
   335                 retValue = ETrue;
       
   336                 }
       
   337             else
       
   338                 {// No
       
   339                 // Set the focus accordingly
       
   340                 if ( !gatewaySize )
       
   341                     {
       
   342                     iListBox->SetCurrentItemIndexAndDraw( 
       
   343                         ESmumEmailGateway );
       
   344                     }
       
   345                 else
       
   346                     {
       
   347                     iListBox->SetCurrentItemIndexAndDraw( 
       
   348                         ESmumEmailServiceCentreNumber );
       
   349                     }
       
   350                 }
       
   351             }
       
   352         }
       
   353     else{ // no empty fields
       
   354         iSC.Copy( iSettingsArray->At( 
       
   355             ESmumEmailServiceCentreNumber ).iUserText );
       
   356         iGateway.Copy( 
       
   357             iSettingsArray->At( ESmumEmailGateway ).iUserText );
       
   358         retValue = ETrue;
       
   359         }
       
   360     
       
   361     if ( retValue && iExitCode == ESmumSmsSettingsBack )
       
   362         {
       
   363         // Replace title with old title text
       
   364         iTitlePane->SetTextL( *iPreviousTitleText );
       
   365         }
       
   366 
       
   367     return retValue;
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------
       
   371 // CSmumEmailServiceCentreDialog::LaunchHelpL
       
   372 // launch help using context
       
   373 //
       
   374 // ----------------------------------------------------
       
   375 void CSmumEmailServiceCentreDialog::LaunchHelpL() const
       
   376     {
       
   377     if ( iHelpFeatureSupported )
       
   378         {
       
   379         CCoeAppUi* editorAppUi = static_cast<CCoeAppUi*>
       
   380             ( ControlEnv()->AppUi() );
       
   381         CArrayFix<TCoeHelpContext>* helpContext = editorAppUi->AppHelpContextL();
       
   382         HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
   383         }
       
   384     }
       
   385 
       
   386 // ----------------------------------------------------
       
   387 // CSmumEmailServiceCentreDialog::GetHelpContext
       
   388 // returns helpcontext as aContext
       
   389 //
       
   390 // ----------------------------------------------------
       
   391 void CSmumEmailServiceCentreDialog::GetHelpContext
       
   392         (TCoeHelpContext& aContext) const
       
   393     {    
       
   394     const TUid KUidMce ={0x100058C5};      
       
   395     aContext.iMajor = KUidMce;
       
   396     aContext.iContext = KSMS_HLP_SETTINGS_SMS_EMAIL;
       
   397     }
       
   398 
       
   399 // ----------------------------------------------------
       
   400 // CSmumEmailServiceCentreDialog::ShowInformationNoteL
       
   401 //
       
   402 // ----------------------------------------------------
       
   403 void CSmumEmailServiceCentreDialog::ShowInformationNoteL( TInt aResource )
       
   404     {
       
   405     HBufC* text = StringLoader::LoadLC( aResource, iCoeEnv );
       
   406     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   407     note->ExecuteLD( *text );
       
   408     CleanupStack::PopAndDestroy(); // text
       
   409     }
       
   410 //  End of File  
       
   411