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