apengine/apsettingshandlerui/src/ApSelectorDialog.cpp
changeset 66 ed07dcc72692
parent 47 cb7afde124a3
equal deleted inserted replaced
64:84c6623982f6 66:ed07dcc72692
    53 TInt CApSelectorDialog::ConstructAndRunLD( CApSettingsModel& aModel,
    53 TInt CApSelectorDialog::ConstructAndRunLD( CApSettingsModel& aModel,
    54                                           CApSettingsHandlerImpl& aHandler,
    54                                           CApSettingsHandlerImpl& aHandler,
    55                                           TUint32 aHighLight,
    55                                           TUint32 aHighLight,
    56                                           TUint32& aSelected )
    56                                           TUint32& aSelected )
    57     {
    57     {
    58     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::ConstructAndRunLD")
    58     return 0;
    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     }
    59     }
   172 
    60 
   173 
    61 
   174 
    62 
   175 
    63 
   178 // Destructor
    66 // Destructor
   179 // ---------------------------------------------------------
    67 // ---------------------------------------------------------
   180 //
    68 //
   181 CApSelectorDialog::~CApSelectorDialog()
    69 CApSelectorDialog::~CApSelectorDialog()
   182     {
    70     {
   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     }
    71     }
   218 
    72 
   219 
    73 
   220 
    74 
   221 // ---------------------------------------------------------
    75 // ---------------------------------------------------------
   232                                         TUint32& aEventStore,
    86                                         TUint32& aEventStore,
   233                                         TBool aNoEdit,
    87                                         TBool aNoEdit,
   234                                         TInt aReqIpvType
    88                                         TInt aReqIpvType
   235                                         )
    89                                         )
   236     {
    90     {
   237     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::NewL")
    91     return NULL;
   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     }
    92     }
   249 
    93 
   250 
    94 
   251 
    95 
   252 
    96 
   275 iExitReason( EExitNone ),
   119 iExitReason( EExitNone ),
   276 iReqIpvType( aReqIpvType ),
   120 iReqIpvType( aReqIpvType ),
   277 iInitialised( EFalse ),
   121 iInitialised( EFalse ),
   278 iNoEdit(aNoEdit)
   122 iNoEdit(aNoEdit)
   279     {
   123     {
   280 
       
   281     }
   124     }
   282 
   125 
   283 
   126 
   284 
   127 
   285 // ---------------------------------------------------------
   128 // ---------------------------------------------------------
   288 // to initialize localized textual data
   131 // to initialize localized textual data
   289 // ---------------------------------------------------------
   132 // ---------------------------------------------------------
   290 //
   133 //
   291 void CApSelectorDialog::InitTextsL()
   134 void CApSelectorDialog::InitTextsL()
   292     {
   135     {
   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     }
   136     }
   320 
   137 
   321 
   138 
   322 
   139 
   323 // ---------------------------------------------------------
   140 // ---------------------------------------------------------
   325 // called before the dialog is shown to initialize listbox data
   142 // called before the dialog is shown to initialize listbox data
   326 // ---------------------------------------------------------
   143 // ---------------------------------------------------------
   327 //
   144 //
   328 void CApSelectorDialog::HandleListboxDataChangeL()
   145 void CApSelectorDialog::HandleListboxDataChangeL()
   329     {
   146     {
   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     }
   147     }
   369 
   148 
   370 
   149 
   371 
   150 
   372 // ---------------------------------------------------------
   151 // ---------------------------------------------------------
   374 // called by framework before dialog is shown
   153 // called by framework before dialog is shown
   375 // ---------------------------------------------------------
   154 // ---------------------------------------------------------
   376 //
   155 //
   377 void CApSelectorDialog::SetTextOverrides( CTextOverrides *aOverrides )
   156 void CApSelectorDialog::SetTextOverrides( CTextOverrides *aOverrides )
   378     {
   157     {
   379     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::SetTextOverrides<->")
       
   380     
       
   381     __ASSERT_DEBUG( aOverrides, Panic( ENullPointer ) );
       
   382     iTextOverrides = aOverrides;
       
   383     }
   158     }
   384 
   159 
   385 
   160 
   386 
   161 
   387 
   162 
   391 // used to handle empty list - query
   166 // used to handle empty list - query
   392 // ---------------------------------------------------------
   167 // ---------------------------------------------------------
   393 //
   168 //
   394 void CApSelectorDialog::CheckIfEmptyL()
   169 void CApSelectorDialog::CheckIfEmptyL()
   395     {
   170     {
   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     }
   171     }
   406 
   172 
   407 
   173 
   408 // ---------------------------------------------------------
   174 // ---------------------------------------------------------
   409 // CApSelectorDialog::ActivateL()
   175 // CApSelectorDialog::ActivateL()
   411 // used to handle empty list - query
   177 // used to handle empty list - query
   412 // ---------------------------------------------------------
   178 // ---------------------------------------------------------
   413 //
   179 //
   414 void CApSelectorDialog::ActivateL()
   180 void CApSelectorDialog::ActivateL()
   415     {
   181     {
   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     }
   182     }
   424 
   183 
   425 
   184 
   426 
   185 
   427 // ---------------------------------------------------------
   186 // ---------------------------------------------------------
   428 // CApSelectorDialog::GetHelpContext()
   187 // CApSelectorDialog::GetHelpContext()
   429 // ---------------------------------------------------------
   188 // ---------------------------------------------------------
   430 //
   189 //
   431 void CApSelectorDialog::GetHelpContext(TCoeHelpContext& aContext) const
   190 void CApSelectorDialog::GetHelpContext(TCoeHelpContext& aContext) const
   432     {
   191     {
   433     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::GetHelpContext<->")
       
   434     
       
   435     aContext.iMajor = iHandler->iHelpMajor;
       
   436     }
   192     }
   437 
   193 
   438 
   194 
   439 
   195 
   440 // ---------------------------------------------------------
   196 // ---------------------------------------------------------
   442 // called by the active access point framework
   198 // called by the active access point framework
   443 // ---------------------------------------------------------
   199 // ---------------------------------------------------------
   444 //
   200 //
   445 void CApSelectorDialog::HandleApDbEventL( TEvent anEvent )
   201 void CApSelectorDialog::HandleApDbEventL( TEvent anEvent )
   446     {
   202     {
   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     }
   203     }
   477 
   204 
   478 
   205 
   479 
   206 
   480 // From MEikCommandObserver
   207 // From MEikCommandObserver
   481 void CApSelectorDialog::ProcessCommandL( TInt aCommandId )
   208 void CApSelectorDialog::ProcessCommandL( TInt aCommandId )
   482     {
   209     {
   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     }
   210     }
   493 
   211 
   494 
   212 
   495 
   213 
   496 
   214 
   497 // From MEikListBoxObserver
   215 // From MEikListBoxObserver
   498 void CApSelectorDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
   216 void CApSelectorDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
   499                                              TListBoxEvent aEventType )
   217                                              TListBoxEvent aEventType )
   500     {
   218     {
   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     }
   219     }
   532 
   220 
   533 
   221 
   534 
   222 
   535 //----------------------------------------------------------
   223 //----------------------------------------------------------
   537 //----------------------------------------------------------
   225 //----------------------------------------------------------
   538 //
   226 //
   539 SEikControlInfo CApSelectorDialog::CreateCustomControlL
   227 SEikControlInfo CApSelectorDialog::CreateCustomControlL
   540 ( TInt aControlType )
   228 ( TInt aControlType )
   541     {
   229     {
   542     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::CreateCustomControlL")
   230     User::Leave( KErrNotSupported );
   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     }
   231     }
   559 
   232 
   560 
   233 
   561 //----------------------------------------------------------
   234 //----------------------------------------------------------
   562 // CApSelectorDialog::DynInitMenuPaneL
   235 // CApSelectorDialog::DynInitMenuPaneL
   563 //----------------------------------------------------------
   236 //----------------------------------------------------------
   564 //
   237 //
   565 void CApSelectorDialog::DynInitMenuPaneL( TInt aResourceId,
   238 void CApSelectorDialog::DynInitMenuPaneL( TInt aResourceId,
   566                                          CEikMenuPane* aMenuPane )
   239                                          CEikMenuPane* aMenuPane )
   567     {
   240     {
   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     }
   241     }
   612 
   242 
   613 
   243 
   614 
   244 
   615 // ---------------------------------------------------------
   245 // ---------------------------------------------------------
   617 // ---------------------------------------------------------
   247 // ---------------------------------------------------------
   618 //
   248 //
   619 TKeyResponse CApSelectorDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
   249 TKeyResponse CApSelectorDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
   620                                                TEventCode aType)
   250                                                TEventCode aType)
   621     {
   251     {
   622     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::OfferKeyEventL")
   252     User::Leave( KErrNotSupported );
   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     }
   253     }
   673 
   254 
   674 
   255 
   675 // ---------------------------------------------------------
   256 // ---------------------------------------------------------
   676 // CApSelectorDialog::PreLayoutDynInitL();
   257 // CApSelectorDialog::PreLayoutDynInitL();
   677 // called by framework before dialog is shown
   258 // called by framework before dialog is shown
   678 // ---------------------------------------------------------
   259 // ---------------------------------------------------------
   679 //
   260 //
   680 void CApSelectorDialog::PreLayoutDynInitL()
   261 void CApSelectorDialog::PreLayoutDynInitL()
   681     {
   262     {
   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     }
   263     }
   700 
   264 
   701 
   265 
   702 // ---------------------------------------------------------
   266 // ---------------------------------------------------------
   703 // CApSelectorDialog::PreLayoutDynInitL();
   267 // CApSelectorDialog::PreLayoutDynInitL();
   704 // called by framework before dialog is shown
   268 // called by framework before dialog is shown
   705 // ---------------------------------------------------------
   269 // ---------------------------------------------------------
   706 //
   270 //
   707 void CApSelectorDialog::PostLayoutDynInitL()
   271 void CApSelectorDialog::PostLayoutDynInitL()
   708     {
   272     {
   709     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::PostLayoutDynInitL")
       
   710     
       
   711     iDataModel->Database()->AddObserverL( this );
       
   712     
       
   713     APSETUILOGGER_LEAVEFN( EDialog,"SelDIalog::PostLayoutDynInitL")
       
   714     }
   273     }
   715 
   274 
   716 
   275 
   717 // ---------------------------------------------------------
   276 // ---------------------------------------------------------
   718 // CApSelectorDialog::OkToExitL( TInt aButtonId )
   277 // CApSelectorDialog::OkToExitL( TInt aButtonId )
   719 // called by framework when the OK button is pressed
   278 // called by framework when the OK button is pressed
   720 // ---------------------------------------------------------
   279 // ---------------------------------------------------------
   721 //
   280 //
   722 TBool CApSelectorDialog::OkToExitL( TInt aButtonId )
   281 TBool CApSelectorDialog::OkToExitL( TInt aButtonId )
   723     {
   282     {
   724     APSETUILOGGER_ENTERFN( EDialog,"SelDIalog::OkToExitL")
   283     return EFalse;
   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     }
   284     }
   755 
   285 
   756 
   286 
   757 // ---------------------------------------------------------
   287 // ---------------------------------------------------------
   758 // CApSelectorDialog::SetHighlighted()
   288 // CApSelectorDialog::SetHighlighted()
   759 // called when needs to change the highlighting
   289 // called when needs to change the highlighting
   760 // ---------------------------------------------------------
   290 // ---------------------------------------------------------
   761 //
   291 //
   762 void CApSelectorDialog::SetHighlighted()
   292 void CApSelectorDialog::SetHighlighted()
   763     {
   293     {
   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     }
   294     }
   806 
   295 
   807 
   296 
   808 
   297 
   809 
   298 
   814 // called when needs to change the highlighting
   303 // called when needs to change the highlighting
   815 // ---------------------------------------------------------
   304 // ---------------------------------------------------------
   816 //
   305 //
   817 void CApSelectorDialog::DoProcessCommandL( TInt aCommandId )
   306 void CApSelectorDialog::DoProcessCommandL( TInt aCommandId )
   818     {
   307     {
   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     }
   308     }
   960 
   309 
   961 
   310 
   962 
   311 
   963 // End of File
   312 // End of File