apengine/apsettingshandlerui/src/ApSelectorDialog.cpp
changeset 61 8b0c979bbe8c
parent 59 2709c04a4af5
child 70 ac5daea24fb0
equal deleted inserted replaced
59:2709c04a4af5 61:8b0c979bbe8c
     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 *     Defines dialog CApSelectorDialog for access point selection.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "APSettingsHandlerUIVariant.hrh"
       
    22 
       
    23 #include <aknnavide.h>
       
    24 #include <akntitle.h>
       
    25 #include <eikmenup.h>
       
    26 
       
    27 #include <ApListItem.h>
       
    28 #include <apsetui.rsg>
       
    29 
       
    30 #include <featmgr.h>
       
    31 
       
    32 #include "ApSelectorDialog.h"
       
    33 #include "ApSelectorListBoxModel.h"
       
    34 #include "ApSelectorListbox.h"
       
    35 #include "ApSettingsModel.h"
       
    36 #include "ApsettingshandleruiImpl.h"
       
    37 #include "ApSettingsHandlerUI.hrh"
       
    38 #include "TextOverrides.h"
       
    39 
       
    40 #include "ApSettingsHandlerLogger.h"
       
    41 
       
    42 #include <VpnApEngine.h>
       
    43 // CONSTANTS
       
    44 
       
    45 
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 // ---------------------------------------------------------
       
    49 // CApSelectorDialog::ConstructAndRunLD
       
    50 // Constructs the dialog and runs it.
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 TInt CApSelectorDialog::ConstructAndRunLD( CApSettingsModel& aModel,
       
    54                                           CApSettingsHandlerImpl& aHandler,
       
    55                                           TUint32 aHighLight,
       
    56                                           TUint32& aSelected )
       
    57     {
       
    58     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::ConstructAndRunLD")
       
    59     
       
    60     CleanupStack::PushL( this );
       
    61 
       
    62     FeatureManager::InitializeLibL();
       
    63     iHelpSupported = FeatureManager::FeatureSupported( KFeatureIdHelp );
       
    64     FeatureManager::UnInitializeLib();
       
    65 
       
    66 #ifdef __TEST_OOMDEBUG
       
    67     RFs fs;
       
    68     User::LeaveIfError( fs.Connect() );
       
    69     CleanupClosePushL<RFs>( fs );
       
    70     TUint att;
       
    71     if ( fs.Att( KTestFileName, att ) == KErrNone )
       
    72         {
       
    73         iMemTestOn = ETrue;
       
    74         }
       
    75     else
       
    76         {
       
    77         iMemTestOn = EFalse;
       
    78         }
       
    79     CleanupStack::PopAndDestroy(); // fs, will also close it
       
    80 #endif // __TEST_OOMDEBUG
       
    81 
       
    82 
       
    83     TInt retValue = KErrNone;
       
    84 
       
    85     iHighLight = aHighLight;
       
    86     iSelected = &aSelected;
       
    87 
       
    88     iDataModel = &aModel;
       
    89     iHandler = &aHandler;
       
    90     iVariant = iHandler->iExt->iVariant;
       
    91 
       
    92     TInt aMenuTitleResourceId;
       
    93     switch ( iSelMenuType )
       
    94         {
       
    95         case EApSettingsSelMenuSelectOnly:
       
    96             {
       
    97             aMenuTitleResourceId = R_APSETTINGSUI_SELECT_ONLY_MENUBAR;
       
    98             break;
       
    99             }
       
   100         case EApSettingsSelMenuSelectNormal:
       
   101             {
       
   102             aMenuTitleResourceId = R_APSETTINGSUI_SELECT_NORMAL_MENUBAR;
       
   103             break;
       
   104             }
       
   105         case EApSettingsSelMenuNormal:
       
   106         default: // defensive ! treat all error cases like normal!
       
   107             {
       
   108             aMenuTitleResourceId = R_APSETTINGSUI_NORMAL_MENUBAR;
       
   109             break;
       
   110             }
       
   111         }
       
   112     ConstructL( aMenuTitleResourceId );
       
   113 
       
   114     TInt aDlgResourceId;
       
   115     switch ( iListType )
       
   116         {
       
   117         case EApSettingsSelListIsPopUp:
       
   118         case EApSettingsSelListIsPopUpWithNone:
       
   119             {
       
   120             aDlgResourceId = R_APSELECTOR_POPUP_DIALOG;
       
   121             break;
       
   122             }
       
   123         case EApSettingsSelListIsListPane:
       
   124         default:// defensive ! treat all error cases like normal!
       
   125             {
       
   126             aDlgResourceId = R_APSELECTOR_PANE_DIALOG;
       
   127             break;
       
   128             }
       
   129         }
       
   130 
       
   131     iModel = new( ELeave )CApSelectorListboxModel;
       
   132     
       
   133     TBool islocked;
       
   134     iDataModel->AllListItemDataL( islocked, *iModel, iIspFilter,
       
   135                                   iBearerFilter, iSortType,
       
   136                                   iReqIpvType );
       
   137     
       
   138 
       
   139     if ( !iModel->Count() )
       
   140         {
       
   141         // no ap defined, ask query if editable,
       
   142         // show note if not
       
   143         if ( iNoEdit )
       
   144             {
       
   145             // show note first, 
       
   146             ShowNoteL( R_APUI_VIEW_NO_IAP_DEFINED_INFO );
       
   147             // then simply go back:
       
   148             User::Leave(KLeaveWithoutAlert);
       
   149             }
       
   150         else
       
   151             {        
       
   152             // no ap defined, ask query
       
   153             if ( !AskQueryL( R_APUI_IAP_CREATE_NEW ) )
       
   154                 { // do not create, simply go back
       
   155                 User::Leave(KLeaveWithoutAlert);
       
   156                 }
       
   157             else
       
   158                 { // create new AP
       
   159                 // just ket it pass, later in it will be handled in CheckIfEmptyL()
       
   160                 }
       
   161             }
       
   162         }
       
   163     
       
   164     CleanupStack::Pop();  // this, it will be PushL-d by executeLD...
       
   165 
       
   166     retValue = ExecuteLD( aDlgResourceId );
       
   167 
       
   168     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::ConstructAndRunLD")
       
   169 
       
   170     return retValue;
       
   171     }
       
   172 
       
   173 
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CApSelectorDialog::~CApSelectorDialog
       
   178 // Destructor
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 CApSelectorDialog::~CApSelectorDialog()
       
   182     {
       
   183     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::~CApSelectorDialog")
       
   184     
       
   185     if ( iDataModel )
       
   186         {
       
   187         if ( iDataModel->Database() )
       
   188             {
       
   189             iDataModel->Database()->RemoveObserver( this );
       
   190             }
       
   191         }
       
   192 
       
   193     // iModel is deleted by the ListBox because LB owns the model...
       
   194     // of course only after we passed ownership...
       
   195     if ( !iModelPassed )
       
   196         {
       
   197         delete iModel;
       
   198         }
       
   199     if ( iNaviDecorator )
       
   200         {
       
   201         delete iNaviDecorator;
       
   202         }
       
   203     if ( iTitlePane )
       
   204         {
       
   205         // set old text back, if we have it...
       
   206         if ( iOldTitleText )
       
   207             {
       
   208             if ( iExitReason != EShutDown )
       
   209                 {
       
   210                 TRAP_IGNORE( iTitlePane->SetTextL( *iOldTitleText ) );
       
   211                 }
       
   212             delete iOldTitleText;
       
   213             }
       
   214         }
       
   215     
       
   216     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::~CApSelectorDialog")
       
   217     }
       
   218 
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CApSelectorDialog::NewLC
       
   223 // Two-phase dconstructor, second phase is ConstructAndRunLD
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 CApSelectorDialog* CApSelectorDialog::NewL(
       
   227                                         TSelectionListType aListType,
       
   228                                         TSelectionMenuType aSelMenuType,
       
   229                                         TInt aIspFilter,
       
   230                                         TInt aBearerFilter,
       
   231                                         TInt aSortType,
       
   232                                         TUint32& aEventStore,
       
   233                                         TBool aNoEdit,
       
   234                                         TInt aReqIpvType
       
   235                                         )
       
   236     {
       
   237     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::NewL")
       
   238     
       
   239     CApSelectorDialog* db =
       
   240         new ( ELeave )CApSelectorDialog( aListType, aSelMenuType,
       
   241                                          aIspFilter, aBearerFilter,
       
   242                                          aSortType, aEventStore,
       
   243                                          aNoEdit,
       
   244                                          aReqIpvType );
       
   245 
       
   246     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::NewL")
       
   247     return db;
       
   248     }
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------
       
   254 // CApSelectorDialog::CApSelectorDialog
       
   255 // Constructor
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 CApSelectorDialog::CApSelectorDialog( TSelectionListType aListType,
       
   259                                       TSelectionMenuType aSelMenuType,
       
   260                                       TInt aIspFilter,
       
   261                                       TInt aBearerFilter,
       
   262                                       TInt aSortType,
       
   263                                       TUint32& aEventStore,
       
   264                                       TBool aNoEdit,
       
   265                                       TInt aReqIpvType
       
   266                                      )
       
   267 :iListType( aListType ),
       
   268 iSelMenuType( aSelMenuType ),
       
   269 iIspFilter( aIspFilter ),
       
   270 iBearerFilter( aBearerFilter ),
       
   271 iSortType( aSortType ),
       
   272 iEventStore( &aEventStore ),
       
   273 iNeedUnlock( EFalse ),
       
   274 iModelPassed( EFalse ),
       
   275 iExitReason( EExitNone ),
       
   276 iReqIpvType( aReqIpvType ),
       
   277 iInitialised( EFalse ),
       
   278 iNoEdit(aNoEdit)
       
   279     {
       
   280 
       
   281     }
       
   282 
       
   283 
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CApSelectorDialog::InitTextsL
       
   287 // called before the dialog is shown
       
   288 // to initialize localized textual data
       
   289 // ---------------------------------------------------------
       
   290 //
       
   291 void CApSelectorDialog::InitTextsL()
       
   292     {
       
   293     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::InitTextsL")
       
   294     
       
   295     // set pane text if neccessary...
       
   296     // pane text needed if not pop-up...
       
   297     __ASSERT_DEBUG( iTextOverrides, Panic( ENullPointer ) );
       
   298     if ( iListType == EApSettingsSelListIsListPane )
       
   299         {
       
   300         iStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   301         iTitlePane =
       
   302             ( CAknTitlePane* )iStatusPane->ControlL(
       
   303                                 TUid::Uid( EEikStatusPaneUidTitle ) );
       
   304 
       
   305         iOldTitleText = iTitlePane->Text()->AllocL();
       
   306         iTitlePane->SetTextL( 
       
   307                         *iEikonEnv->AllocReadResourceLC( R_APUI_NAVI_AP ) );
       
   308 
       
   309         CleanupStack::PopAndDestroy(); // resource R_APUI_NAVI_AP
       
   310 
       
   311         iNaviPane = ( CAknNavigationControlContainer* ) 
       
   312                         iStatusPane->ControlL( 
       
   313                                 TUid::Uid( EEikStatusPaneUidNavi ) );
       
   314         iNaviDecorator = iNaviPane->CreateNavigationLabelL( KEmpty );
       
   315         iNaviPane->PushL( *iNaviDecorator );
       
   316         }
       
   317         
       
   318     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::InitTextsL")
       
   319     }
       
   320 
       
   321 
       
   322 
       
   323 // ---------------------------------------------------------
       
   324 // CApSelectorDialog::HandleListboxDataChangeL
       
   325 // called before the dialog is shown to initialize listbox data
       
   326 // ---------------------------------------------------------
       
   327 //
       
   328 void CApSelectorDialog::HandleListboxDataChangeL()
       
   329     {
       
   330     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::HandleListboxDataChangeL")
       
   331     
       
   332     iPreferredLine = iList->CurrentItemIndex();
       
   333     if ( iPreferredLine < 0 )
       
   334         {
       
   335         iPreferredLine = 0;
       
   336         }
       
   337     if ( !iPreferredUid )
       
   338         { // if not specified explicitly, get current and use as 'preferred'
       
   339         if ( iPreferredLine >= 0 )
       
   340             {
       
   341             if ( iModel->Count() )
       
   342                 {
       
   343                 iPreferredUid = iModel->At( iPreferredLine )->Uid();
       
   344                 }
       
   345             }
       
   346         }
       
   347 
       
   348 
       
   349     TBool isLocked(EFalse);
       
   350     iNeedUnlock = EFalse;
       
   351     iDataModel->AllListItemDataL( isLocked, *iModel, iIspFilter,
       
   352                                   iBearerFilter, iSortType,
       
   353                                   iReqIpvType );
       
   354     if ( isLocked )
       
   355         {
       
   356         iNeedUnlock = ETrue;
       
   357         }
       
   358 
       
   359     iList->View()->SetDisableRedraw( ETrue );
       
   360     iList->HandleItemAdditionL();
       
   361 
       
   362     SetHighlighted();
       
   363 
       
   364     iList->View()->SetDisableRedraw( EFalse );
       
   365     iList->HandleItemAdditionL();
       
   366     
       
   367     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::HandleListboxDataChangeL")
       
   368     }
       
   369 
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------
       
   373 // CApSelectorDialog::SetTextOverrides
       
   374 // called by framework before dialog is shown
       
   375 // ---------------------------------------------------------
       
   376 //
       
   377 void CApSelectorDialog::SetTextOverrides( CTextOverrides *aOverrides )
       
   378     {
       
   379     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::SetTextOverrides<->")
       
   380     
       
   381     __ASSERT_DEBUG( aOverrides, Panic( ENullPointer ) );
       
   382     iTextOverrides = aOverrides;
       
   383     }
       
   384 
       
   385 
       
   386 
       
   387 
       
   388 // ---------------------------------------------------------
       
   389 // CApSelectorDialog::CheckIfEmptyL()
       
   390 // called on activation and after the db has changed
       
   391 // used to handle empty list - query
       
   392 // ---------------------------------------------------------
       
   393 //
       
   394 void CApSelectorDialog::CheckIfEmptyL()
       
   395     {
       
   396     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::CheckIfEmptyL")
       
   397     
       
   398     if ( !iModel->Count() )
       
   399         {
       
   400         ProcessCommandL( EApSelCmdNewBlank );
       
   401         }
       
   402     iInitialised = ETrue;
       
   403     
       
   404     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::CheckIfEmptyL")
       
   405     }
       
   406 
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CApSelectorDialog::ActivateL()
       
   410 // called after the dialog is shown
       
   411 // used to handle empty list - query
       
   412 // ---------------------------------------------------------
       
   413 //
       
   414 void CApSelectorDialog::ActivateL()
       
   415     {
       
   416     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::ActivateL")
       
   417     
       
   418     CAknDialog::ActivateL();
       
   419     // put empty list checking & required actions here.
       
   420     CheckIfEmptyL();
       
   421     
       
   422     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::ActivateL")
       
   423     }
       
   424 
       
   425 
       
   426 
       
   427 // ---------------------------------------------------------
       
   428 // CApSelectorDialog::GetHelpContext()
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 void CApSelectorDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   432     {
       
   433     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::GetHelpContext<->")
       
   434     
       
   435     aContext.iMajor = iHandler->iHelpMajor;
       
   436     }
       
   437 
       
   438 
       
   439 
       
   440 // ---------------------------------------------------------
       
   441 // CApSelectorDialog::HandleApDbEventLw
       
   442 // called by the active access point framework
       
   443 // ---------------------------------------------------------
       
   444 //
       
   445 void CApSelectorDialog::HandleApDbEventL( TEvent anEvent )
       
   446     {
       
   447     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::HandleApDbEventL")
       
   448     
       
   449     switch ( anEvent )
       
   450         {
       
   451         case EDbChanged:
       
   452             {
       
   453             HandleListboxDataChangeL();
       
   454             break;
       
   455             }
       
   456         case EDbClosing:
       
   457             {
       
   458             break;
       
   459             }
       
   460         case EDbAvailable:
       
   461             {
       
   462             if ( iNeedUnlock )
       
   463                 {
       
   464                 HandleListboxDataChangeL();
       
   465                 }
       
   466             break;
       
   467             }
       
   468         default:
       
   469             {
       
   470             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   471             break;
       
   472             }
       
   473         }
       
   474     
       
   475     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::HandleApDbEventL")
       
   476     }
       
   477 
       
   478 
       
   479 
       
   480 // From MEikCommandObserver
       
   481 void CApSelectorDialog::ProcessCommandL( TInt aCommandId )
       
   482     {
       
   483     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::ProcessCommandL")
       
   484     
       
   485     if ( MenuShowing() )
       
   486         {
       
   487         HideMenu();
       
   488         }
       
   489     DoProcessCommandL( aCommandId );
       
   490     
       
   491     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::ProcessCommandL")
       
   492     }
       
   493 
       
   494 
       
   495 
       
   496 
       
   497 // From MEikListBoxObserver
       
   498 void CApSelectorDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   499                                              TListBoxEvent aEventType )
       
   500     {
       
   501     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::HandleListBoxEventL")
       
   502     
       
   503     switch ( aEventType )
       
   504         {
       
   505         case EEventItemSingleClicked:            
       
   506         case EEventEnterKeyPressed:
       
   507             // both handled in the same way for now...
       
   508         case EEventItemDoubleClicked:
       
   509             {
       
   510             ProcessCommandL( EApSelCmdOpen );
       
   511             break;
       
   512             }
       
   513         case EEventItemClicked:
       
   514             {
       
   515             break;
       
   516             }
       
   517         case EEventEditingStarted:
       
   518             {
       
   519             break;
       
   520             }
       
   521         case EEventEditingStopped:
       
   522             {
       
   523             break;
       
   524             }
       
   525         default:
       
   526             {
       
   527             };
       
   528         };
       
   529     
       
   530     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::HandleListBoxEventL")
       
   531     }
       
   532 
       
   533 
       
   534 
       
   535 //----------------------------------------------------------
       
   536 // CApSelectorDialog::CreateCustomControlL
       
   537 //----------------------------------------------------------
       
   538 //
       
   539 SEikControlInfo CApSelectorDialog::CreateCustomControlL
       
   540 ( TInt aControlType )
       
   541     {
       
   542     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::CreateCustomControlL")
       
   543     
       
   544     SEikControlInfo controlInfo;
       
   545     controlInfo.iTrailerTextId = 0;
       
   546     controlInfo.iFlags = 0;
       
   547     if ( aControlType == KApSelectorListboxType )
       
   548         {
       
   549         controlInfo.iControl = new ( ELeave ) CApSelectorListbox;
       
   550         }
       
   551     else
       
   552         {
       
   553         controlInfo.iControl = NULL;
       
   554         }
       
   555     
       
   556     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::CreateCustomControlL")
       
   557     return controlInfo;
       
   558     }
       
   559 
       
   560 
       
   561 //----------------------------------------------------------
       
   562 // CApSelectorDialog::DynInitMenuPaneL
       
   563 //----------------------------------------------------------
       
   564 //
       
   565 void CApSelectorDialog::DynInitMenuPaneL( TInt aResourceId,
       
   566                                          CEikMenuPane* aMenuPane )
       
   567     {
       
   568     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::DynInitMenuPaneL")
       
   569     
       
   570     CAknDialog::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   571 
       
   572     TInt itemCount = iList->Model()->NumberOfItems();
       
   573 //    TUint32 itemUid = iModel->At( iList->CurrentItemIndex() )->Uid();
       
   574 
       
   575     TUint32 itemUid(0);
       
   576     if ( itemCount > 0 )
       
   577         {
       
   578         itemUid = iModel->At( iList->CurrentItemIndex() )->Uid();
       
   579         }
       
   580 
       
   581     if ( iHandler->iModel->Need2DeleteSelect( aResourceId, itemCount ) )
       
   582         {
       
   583         aMenuPane->DeleteMenuItem( EApSelCmdSelect );
       
   584         }
       
   585     if ( iHandler->iModel->Need2DeleteOpen( aResourceId, itemCount, 
       
   586                                             itemUid, EFalse ) )
       
   587         {
       
   588         aMenuPane->DeleteMenuItem( EApSelCmdOpen );
       
   589         }
       
   590     if ( iHandler->iModel->Need2DeleteDeleteL( aResourceId, itemCount, 
       
   591                                                itemUid, EFalse ) )
       
   592         {
       
   593         aMenuPane->DeleteMenuItem( EApSelCmdDelete );
       
   594         }
       
   595     if ( iHandler->iModel->Need2DeleteNewUseExisting( aResourceId, 
       
   596                                                       itemCount ) )
       
   597         {
       
   598         aMenuPane->DeleteMenuItem( EApSelCmdNewUseExisting );
       
   599         }
       
   600     if ( iHandler->iModel->Need2DeleteNewL( aResourceId ) )
       
   601         {
       
   602         aMenuPane->DeleteMenuItem( EApSelCmdNewBlank );
       
   603         }
       
   604 
       
   605     if ( iHandler->iModel->Need2DeleteHelp( aResourceId ) )
       
   606         {
       
   607         aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   608         }
       
   609     
       
   610     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::DynInitMenuPaneL")
       
   611     }
       
   612 
       
   613 
       
   614 
       
   615 // ---------------------------------------------------------
       
   616 // CApSelectorDialog::OfferKeyEventL();
       
   617 // ---------------------------------------------------------
       
   618 //
       
   619 TKeyResponse CApSelectorDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   620                                                TEventCode aType)
       
   621     {
       
   622     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::OfferKeyEventL")
       
   623     
       
   624     TKeyResponse retval( EKeyWasConsumed );
       
   625     if ( ( aType == EEventKey ) &&
       
   626          ( ( aKeyEvent.iCode == EKeyDelete ) ||
       
   627            ( aKeyEvent.iCode == EKeyBackspace ) ) )
       
   628         {
       
   629         if (!iNoEdit)
       
   630             {
       
   631             ProcessCommandL( EApSelCmdDelete );
       
   632             }
       
   633         }
       
   634     else
       
   635         {
       
   636         if ( ( aType == EEventKey ) && ( aKeyEvent.iCode == EKeyOK ) )
       
   637             { // process only if command is available...
       
   638             if ( iList->Model()->NumberOfItems() > 0)
       
   639                 {
       
   640                 if (!iNoEdit)
       
   641                     {
       
   642                     ProcessCommandL( EApSelCmdOpen );
       
   643                     }
       
   644                 }
       
   645             }
       
   646         else
       
   647             {
       
   648             if ( iList )
       
   649                 {
       
   650                 // as list IS consuming, must handle because
       
   651                 // it IS the SHUTDOWN...
       
   652                 // or, a view switch is shutting us down...
       
   653                 if ( aKeyEvent.iCode == EKeyEscape )
       
   654                     {
       
   655                     ProcessCommandL( EEikCmdExit );
       
   656                     retval = EKeyWasConsumed;
       
   657                     }
       
   658                 else
       
   659                     {
       
   660                     retval = iList->OfferKeyEventL( aKeyEvent, aType );
       
   661                     }
       
   662                 }
       
   663             else
       
   664                 {
       
   665                 retval = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   666                 }
       
   667             }
       
   668         }
       
   669     
       
   670     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::OfferKeyEventL")
       
   671     return retval;
       
   672     }
       
   673 
       
   674 
       
   675 // ---------------------------------------------------------
       
   676 // CApSelectorDialog::PreLayoutDynInitL();
       
   677 // called by framework before dialog is shown
       
   678 // ---------------------------------------------------------
       
   679 //
       
   680 void CApSelectorDialog::PreLayoutDynInitL()
       
   681     {
       
   682     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::PreLayoutDynInitL")
       
   683     
       
   684     iList =
       
   685         STATIC_CAST( CApSelectorListbox*, Control( KApSelectorListboxId ) );
       
   686     iList->CreateScrollBarFrameL( ETrue );
       
   687     iList->ScrollBarFrame()->SetScrollBarVisibilityL
       
   688         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   689     iList->SetListBoxObserver( this );
       
   690 
       
   691     iList->Model()->SetItemTextArray( iModel );
       
   692     iModelPassed = ETrue;
       
   693     iList->LoadIconsL();
       
   694     HandleListboxDataChangeL();
       
   695     iList->HandleItemAdditionL();
       
   696     InitTextsL();
       
   697     
       
   698     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::PreLayoutDynInitL")
       
   699     }
       
   700 
       
   701 
       
   702 // ---------------------------------------------------------
       
   703 // CApSelectorDialog::PreLayoutDynInitL();
       
   704 // called by framework before dialog is shown
       
   705 // ---------------------------------------------------------
       
   706 //
       
   707 void CApSelectorDialog::PostLayoutDynInitL()
       
   708     {
       
   709     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::PostLayoutDynInitL")
       
   710     
       
   711     iDataModel->Database()->AddObserverL( this );
       
   712     
       
   713     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::PostLayoutDynInitL")
       
   714     }
       
   715 
       
   716 
       
   717 // ---------------------------------------------------------
       
   718 // CApSelectorDialog::OkToExitL( TInt aButtonId )
       
   719 // called by framework when the OK button is pressed
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 TBool CApSelectorDialog::OkToExitL( TInt aButtonId )
       
   723     {
       
   724     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::OkToExitL")
       
   725     
       
   726     // Translate the button presses into commands for the appui & current
       
   727     // view to handle
       
   728     TBool retval( EFalse );
       
   729 
       
   730     if ( aButtonId == EAknSoftkeyOptions )
       
   731         {
       
   732         if ( iSelMenuType == EApSettingsSelMenuSelectOnly )
       
   733             {
       
   734             *iSelected = iList->CurrentItemUid();
       
   735             retval = ETrue;
       
   736             }
       
   737         else
       
   738             {
       
   739             DisplayMenuL();
       
   740             }
       
   741         }
       
   742     else if (aButtonId == EApSelCmdOpen)
       
   743         {
       
   744         ProcessCommandL(aButtonId);
       
   745         retval = EFalse; // don't exit the dialog
       
   746         }
       
   747     else
       
   748         {
       
   749         retval = ETrue;
       
   750         }
       
   751     
       
   752     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::OkToExitL")
       
   753     return retval;
       
   754     }
       
   755 
       
   756 
       
   757 // ---------------------------------------------------------
       
   758 // CApSelectorDialog::SetHighlighted()
       
   759 // called when needs to change the highlighting
       
   760 // ---------------------------------------------------------
       
   761 //
       
   762 void CApSelectorDialog::SetHighlighted()
       
   763     {
       
   764     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::SetHighlighted")
       
   765     
       
   766     TBool done( EFalse );
       
   767 
       
   768     if ( iPreferredUid )
       
   769         {
       
   770         TInt err( KErrNone );
       
   771         TInt idx = iModel->Item4Uid( iPreferredUid, err );
       
   772         // if UID exists, set as current, else set 0 as current.
       
   773         if ( err == KErrNone )
       
   774             {
       
   775             iList->SetCurrentItemIndexAndDraw( idx );
       
   776             iPreferredUid = 0;
       
   777             done = ETrue;
       
   778             }
       
   779         }
       
   780     if ( !done )
       
   781         { // try to use iPreferredLine, as previous selection had been deleted
       
   782         TInt count( iModel->Count() );
       
   783         if ( count <= iPreferredLine )
       
   784             {
       
   785             // less elements, preferred line is out of the screen, 
       
   786             // select last one
       
   787             if ( count )
       
   788                 {
       
   789                 iList->SetCurrentItemIndexAndDraw( count - 1 );
       
   790                 }
       
   791             else
       
   792                 {
       
   793                 iList->SetCurrentItemIndexAndDraw( 0 );
       
   794                 }
       
   795             done = ETrue;
       
   796             }
       
   797         else
       
   798             { // count > iPreferredLine, select preferred line
       
   799             iList->SetCurrentItemIndexAndDraw( iPreferredLine );
       
   800             done = ETrue;
       
   801             }
       
   802         }
       
   803     
       
   804     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::SetHighlighted")
       
   805     }
       
   806 
       
   807 
       
   808 
       
   809 
       
   810 
       
   811 
       
   812 // ---------------------------------------------------------
       
   813 // CApSelectorDialog::DoProcessCommandL
       
   814 // called when needs to change the highlighting
       
   815 // ---------------------------------------------------------
       
   816 //
       
   817 void CApSelectorDialog::DoProcessCommandL( TInt aCommandId )
       
   818     {
       
   819     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::DoProcessCommandL")
       
   820     
       
   821     switch ( aCommandId )
       
   822         {
       
   823         case EApSelCmdSelect:
       
   824             {
       
   825             *iSelected = iList->CurrentItemUid();
       
   826             *iEventStore |= KApUiEventSelected;
       
   827             iPreferredUid = iList->CurrentItemUid();
       
   828             SetHighlighted();
       
   829             // Can not exit here, as it would delete this,
       
   830             // Exit will be handled at the end of this function!
       
   831             // TryExitL( EAknSoftkeyBack );
       
   832             break;
       
   833             }
       
   834         case EApSelCmdOpen:
       
   835             {
       
   836             // when using __UHEAP_MARK;/MARKEND, TitlePane old text setback is
       
   837             // reported as a mem. leak, but it is not as the lifetime of 
       
   838             // the text is longer than this part.
       
   839             iPreferredUid = iList->CurrentItemUid();
       
   840             iHandler->DoRunViewerL( iPreferredUid );
       
   841             break;
       
   842             }
       
   843         case EApSelCmdNewBlank:
       
   844             { // put the new's UID into iPreferredUid to set highlight onto it
       
   845             // when using __UHEAP_MARK;/MARKEND, TitlePane old text setback is
       
   846             // reported as a mem. leak, but it is not as the lifetime of 
       
   847             // the text is longer than this part.
       
   848             iPreferredUid =
       
   849                     iHandler->HandleApBlankNewL( iBearerFilter, iIspFilter );
       
   850             SetHighlighted();
       
   851             break;
       
   852             }
       
   853         case EApSelCmdNewUseExisting:
       
   854             { // put the new's UID into iPreferredUid to set highlight onto it
       
   855             // when using __UHEAP_MARK;/MARKEND, TitlePane old text setback is
       
   856             // reported as a mem. leak, but it is not as the lifetime of 
       
   857             // the text is longer than this part.
       
   858             iPreferredUid = 
       
   859                     iHandler->HandleDuplicateL( iList->CurrentItemUid() );
       
   860             SetHighlighted();
       
   861             break;
       
   862             }
       
   863         case EApSelCmdDelete:
       
   864             { 
       
   865             // put the UID of the next Ap into iPreferredUid to set 
       
   866             // highlight onto it...
       
   867             // if next does not exists, put it onto prev.
       
   868             // if no next & no prev. exists, set it to 0 (don't care).
       
   869             // As it might have been started by the Clear key,
       
   870             // we must check if there is any...
       
   871             if ( iModel->Count() )
       
   872                 {
       
   873                 // As we must be standing on an item, it must exist...
       
   874                 // So no problem on iModel->At( ...)
       
   875                 if ( iList->CurrentItemIndex() < ( iModel->Count()-1 ) )
       
   876                     {
       
   877                     // move to next one if possible
       
   878                     iPreferredUid =
       
   879                         iList->Uid4Item( iList->CurrentItemIndex()+1 );
       
   880                     }
       
   881                 else
       
   882                     {
       
   883                     // if it is the last, move to previous if possible.
       
   884                     // if not, set to 0
       
   885                     if ( iModel->Count()> 1 )
       
   886                         {
       
   887                         // move to prev. one if possible
       
   888                         iPreferredUid =
       
   889                             iList->Uid4Item( iList->CurrentItemIndex()-1 );
       
   890                         }
       
   891                     else
       
   892                         {
       
   893                         iPreferredUid = 0;
       
   894                         }
       
   895                     }
       
   896                 iHandler->HandleApDeleteCmdL( iList->CurrentItemUid(),
       
   897                                               iModel->Count() == 1 );
       
   898                 }
       
   899             break;
       
   900             }
       
   901         case EAknCmdHelp:
       
   902             {
       
   903 			if ( iHelpSupported )
       
   904 				{
       
   905             	iDataModel->LaunchHelpL();
       
   906 				}
       
   907             break;
       
   908             }
       
   909         default:
       
   910             {
       
   911             // silently ignore it
       
   912             break;
       
   913             }
       
   914         }
       
   915     // check if user wants to exit...
       
   916     if ( *iEventStore & KApUiEventExitRequested )
       
   917         {
       
   918         if ( iInitialised )
       
   919             {                        
       
   920             TryExitL( EAknSoftkeyBack );
       
   921             }
       
   922         else
       
   923             {
       
   924             *iEventStore |= KApUiEventInternal;
       
   925             User::Leave(KLeaveWithoutAlert);
       
   926             }
       
   927         }
       
   928     else
       
   929         { // handle possible exit reasons/request here.
       
   930         switch ( aCommandId )
       
   931             {
       
   932             case EApSelCmdSelect:
       
   933                 {
       
   934                 TryExitL( EAknSoftkeyBack );
       
   935                 break;
       
   936                 }
       
   937             case EApSelCmdExit:
       
   938                 {
       
   939                 iExitReason = EExit;
       
   940                 *iEventStore |= KApUiEventExitRequested;
       
   941                 TryExitL( EAknSoftkeyBack );
       
   942                 break;
       
   943                 }
       
   944             case EEikCmdExit:
       
   945                 {
       
   946                 iExitReason = EShutDown;
       
   947                 *iEventStore |= KApUiEventShutDownRequested;
       
   948                 TryExitL( EAknSoftkeyBack );
       
   949                 break;
       
   950                 }
       
   951             default:
       
   952                 {
       
   953                 break;
       
   954                 }
       
   955             }
       
   956         }
       
   957     
       
   958     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::DoProcessCommandL")
       
   959     }
       
   960 
       
   961 
       
   962 
       
   963 // End of File
       
   964