|         |      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 *     Messaging Centre application "Delivery Reports" view class | 
|         |     16 *     implementation. | 
|         |     17 * | 
|         |     18 */ | 
|         |     19  | 
|         |     20  | 
|         |     21  | 
|         |     22 // INCLUDE FILES | 
|         |     23  | 
|         |     24  | 
|         |     25 #include    <eikmenub.h> | 
|         |     26 #include    <aknappui.h> | 
|         |     27 #include    <AknQueryDialog.h> | 
|         |     28 #include    <featmgr.h> | 
|         |     29  | 
|         |     30 #include    <avkon.hrh> | 
|         |     31 #include    <avkon.rsg> | 
|         |     32 #include    <Sendnorm.rsg> | 
|         |     33 #include    <eikdialg.h> | 
|         |     34 #include    <eikenv.h> | 
|         |     35 #include    <f32file.h> | 
|         |     36 #include    <StringLoader.h> | 
|         |     37 #include    <akntitle.h> | 
|         |     38 //#include    <CPhCltDialer.h> | 
|         |     39 #include    <mce.rsg> | 
|         |     40  | 
|         |     41 #include    "MceDeliveryReportView.h" | 
|         |     42 #include    "MceDeliveryReportControlContainer.h" | 
|         |     43 #include    "MceApplication.h" | 
|         |     44 #include    "MceDocument.h" | 
|         |     45 #include    "mceui.h" | 
|         |     46 #include    "MceCommands.hrh"       // UID enumeration. | 
|         |     47 #include    "MceLogEngine.h" | 
|         |     48  | 
|         |     49 #include	<commonphoneparser.h> | 
|         |     50 #include	<PhCltTypes.h> | 
|         |     51 #include	<MuiuMsvUiServiceUtilities.h> | 
|         |     52 #include	<e32cmn.h> | 
|         |     53 #include	<msvapi.h> | 
|         |     54 #include	"MceSessionHolder.h" | 
|         |     55  | 
|         |     56 // For Muiu split | 
|         |     57 #include <muiumsvuiserviceutilitiesinternal.h> | 
|         |     58  | 
|         |     59 // The position of the middle soft key | 
|         |     60 const TInt KMSKPosition = 3; | 
|         |     61  | 
|         |     62  | 
|         |     63 // ================= MEMBER FUNCTIONS ======================= | 
|         |     64  | 
|         |     65 CMceDeliveryReportView* CMceDeliveryReportView::NewL( CMceSessionHolder& aSessionHolder ) | 
|         |     66     { | 
|         |     67     CMceDeliveryReportView* self = new(ELeave) CMceDeliveryReportView(aSessionHolder); | 
|         |     68     CleanupStack::PushL(self); | 
|         |     69     self->ConstructL(); | 
|         |     70     CleanupStack::Pop( self ); | 
|         |     71     return self; | 
|         |     72     } | 
|         |     73  | 
|         |     74 CMceDeliveryReportView::CMceDeliveryReportView( CMceSessionHolder& aSessionHolder ) :  | 
|         |     75 	iSessionHolder(aSessionHolder) | 
|         |     76 	{ | 
|         |     77 	iSessionHolder.AddClient(); | 
|         |     78 	} | 
|         |     79  | 
|         |     80 CMceDeliveryReportView::~CMceDeliveryReportView() | 
|         |     81     { | 
|         |     82     iCoeEnv->RemoveForegroundObserver( *this ); | 
|         |     83  | 
|         |     84     if (iContainer) | 
|         |     85         { | 
|         |     86         AppUi()->RemoveFromViewStack(*this,iContainer); | 
|         |     87  | 
|         |     88         // Destroy the control container | 
|         |     89         delete iContainer; | 
|         |     90         } | 
|         |     91  | 
|         |     92      | 
|         |     93     ClosePopup(); | 
|         |     94  | 
|         |     95     FeatureManager::UnInitializeLib(); | 
|         |     96     iSessionHolder.RemoveClient(); | 
|         |     97     } | 
|         |     98  | 
|         |     99 CMceUi* CMceDeliveryReportView::MceAppUi() | 
|         |    100     { | 
|         |    101     // Explicit cast: the app ui must always be of type CMceUi. | 
|         |    102     return STATIC_CAST( CMceUi*, CAknView::AppUi() ); | 
|         |    103     } | 
|         |    104  | 
|         |    105  | 
|         |    106 void CMceDeliveryReportView::HandleCommandL( TInt aCommandId ) | 
|         |    107     { | 
|         |    108     switch (aCommandId ) | 
|         |    109         { | 
|         |    110         case EMceCmdCall: | 
|         |    111             { | 
|         |    112             if( iPopup ) | 
|         |    113                 { | 
|         |    114                 iPopup->StopDisplayingMenuBar(); | 
|         |    115                 ClosePopup(); | 
|         |    116                 } | 
|         |    117             TInt index( 0 ); | 
|         |    118             index = iContainer->ListBox()->CurrentItemIndex(); | 
|         |    119             TPhCltTelephoneNumber tel; | 
|         |    120             tel = MceAppUi()->LogEngine()->Event( index )->Number(); | 
|         |    121  | 
|         |    122 			// Check the validity of the phone number and initiate the call | 
|         |    123             TBool validNumber = CommonPhoneParser::ParsePhoneNumber( tel, CommonPhoneParser::EPlainPhoneNumber );             | 
|         |    124 			if ( validNumber ) | 
|         |    125             	{ | 
|         |    126             	TPhCltNameBuffer recipientstring( KNullDesC ); | 
|         |    127             	iAvkonAppUi->SetKeyEventFlags( CAknAppUiBase::EDisableSendKeyShort | CAknAppUiBase::EDisableSendKeyLong ); | 
|         |    128 			        MsvUiServiceUtilitiesInternal::CallToSenderQueryL( tel, recipientstring, EFalse ); | 
|         |    129 			        iAvkonAppUi->SetKeyEventFlags( 0x00 ); | 
|         |    130               } | 
|         |    131             } | 
|         |    132             break; | 
|         |    133         case EMceClearDrList: | 
|         |    134             { | 
|         |    135             CAknQueryDialog* queryDlg = CAknQueryDialog::NewL(); | 
|         |    136             if( queryDlg->ExecuteLD( R_MCE_CLEAR_LIST_CONFIRMATION_QUERY ) ) | 
|         |    137                 { | 
|         |    138                 MceAppUi()->LogEngine()->ClearDrListL(); | 
|         |    139                 } | 
|         |    140             SetMSKButtonL(); | 
|         |    141             } | 
|         |    142             break; | 
|         |    143         case EAknCmdHideInBackground: | 
|         |    144             // handled by app ui and sent directly to appui by avkon framework so ignore this by view. | 
|         |    145             break; | 
|         |    146         default: | 
|         |    147             MceAppUi()->HandleCommandL( aCommandId ); | 
|         |    148             break; | 
|         |    149         }     | 
|         |    150     } | 
|         |    151  | 
|         |    152  | 
|         |    153 TUid CMceDeliveryReportView::Id() const | 
|         |    154     { | 
|         |    155     return KMceDeliveryReportViewId; | 
|         |    156     } | 
|         |    157  | 
|         |    158  | 
|         |    159 void CMceDeliveryReportView::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane ) | 
|         |    160     { | 
|         |    161     TInt aPosition = -1; | 
|         |    162  | 
|         |    163     if( aMenuPane->MenuItemExists( EAknCmdHelp, aPosition ) ) | 
|         |    164         { | 
|         |    165         // KFeatureIdHelp is used by Feature Mgr to check if help is supported | 
|         |    166         if( FeatureManager::FeatureSupported( KFeatureIdHelp ) ) | 
|         |    167             { | 
|         |    168             aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse ); | 
|         |    169             } | 
|         |    170         else | 
|         |    171             { | 
|         |    172             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue ); | 
|         |    173             } | 
|         |    174         } | 
|         |    175  | 
|         |    176     switch( aResourceId ) | 
|         |    177         { | 
|         |    178         case R_MCE_DELIVERY_REPORT_SYSTEM_MENU: | 
|         |    179  | 
|         |    180             if(  ! MceAppUi()->LogEngine()-> | 
|         |    181                     IsNumberAvailable( iContainer->ListBox()->CurrentItemIndex() ) ) | 
|         |    182                 { | 
|         |    183                 aMenuPane->DeleteMenuItem( EMceCmdCall ); | 
|         |    184                 } | 
|         |    185  | 
|         |    186             if ( iContainer->ListBox()->Model()->NumberOfItems() == 0 ) | 
|         |    187                 { | 
|         |    188                 aMenuPane->DeleteMenuItem( EMceClearDrList ); | 
|         |    189                 } | 
|         |    190             break; | 
|         |    191  | 
|         |    192         default: | 
|         |    193             break; | 
|         |    194         } | 
|         |    195     } | 
|         |    196  | 
|         |    197  | 
|         |    198 void CMceDeliveryReportView::HandleClientRectChange() | 
|         |    199     { | 
|         |    200     iContainer->SetRect(ClientRect()); | 
|         |    201     } | 
|         |    202  | 
|         |    203 void CMceDeliveryReportView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, | 
|         |    204     TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/) | 
|         |    205     { | 
|         |    206     if ( iContainer == NULL ) | 
|         |    207         { | 
|         |    208         // Create the control container | 
|         |    209         iContainer = CMceDeliveryReportControlContainer::NewL(this, iSessionHolder, ClientRect() ); | 
|         |    210         AppUi()->AddToViewStackL(*this,iContainer); | 
|         |    211         } | 
|         |    212     iContainer->ListBox()->SetListBoxObserver(this); | 
|         |    213  | 
|         |    214  | 
|         |    215     // Fetch pointer to the default title pane control | 
|         |    216     CAknTitlePane* title=(CAknTitlePane *)StatusPane()->ControlL( | 
|         |    217         TUid::Uid(EEikStatusPaneUidTitle)); | 
|         |    218     HBufC* text = StringLoader::LoadLC( R_MCE_DELIVERY_REPORTS_VIEW_TITLE ); | 
|         |    219     title->SetTextL( *text ); | 
|         |    220     CleanupStack::PopAndDestroy(); // text | 
|         |    221      | 
|         |    222     MceAppUi()->SetMceViewActive( EMceDeliveryReportsViewActive ); | 
|         |    223      | 
|         |    224     // Just ignore if this leaves. Worst thing happens here is that user sees empty delivery reports view. | 
|         |    225     TRAP_IGNORE( MceAppUi()->LogEngine()->ForegroundGainedL() ); | 
|         |    226     if( iContainer->LogDisabledL() == KMceDRLogingOff ) | 
|         |    227         { | 
|         |    228         iContainer->PopUpNoteL(); | 
|         |    229         } | 
|         |    230     } | 
|         |    231  | 
|         |    232 void CMceDeliveryReportView::DoDeactivate() | 
|         |    233     { | 
|         |    234     if (iContainer) | 
|         |    235         { | 
|         |    236         // Remove view and its control from the view stack | 
|         |    237         AppUi()->RemoveFromViewStack(*this, iContainer); | 
|         |    238  | 
|         |    239         // Destroy the container control | 
|         |    240         delete iContainer; | 
|         |    241         iContainer = NULL; | 
|         |    242         } | 
|         |    243     } | 
|         |    244  | 
|         |    245 void CMceDeliveryReportView::ConstructL() | 
|         |    246     { | 
|         |    247     // Sets up TLS, must be done before FeatureManager is used. | 
|         |    248     FeatureManager::InitializeLibL(); | 
|         |    249  | 
|         |    250     // Init base class | 
|         |    251     BaseConstructL( R_MCE_DELIVERY_REPORT_VIEW ); | 
|         |    252     iCoeEnv->AddForegroundObserverL( *this ); | 
|         |    253     } | 
|         |    254  | 
|         |    255 void CMceDeliveryReportView::HandleListBoxEventL( | 
|         |    256     CEikListBox* /*aListBox*/, | 
|         |    257     TListBoxEvent aEventType) | 
|         |    258     { | 
|         |    259     if ( aEventType == EEventItemSingleClicked ) | 
|         |    260     	{ | 
|         |    261     	ProcessCommandL( EAknSoftkeyContextOptions ); | 
|         |    262     	} | 
|         |    263     } | 
|         |    264  | 
|         |    265 void CMceDeliveryReportView::LaunchPopupMenuL( TInt aResourceId ) | 
|         |    266     { | 
|         |    267     ClosePopup(); | 
|         |    268     iPopup = new ( ELeave ) CEikMenuBar; | 
|         |    269     TRAPD( err, DoLaunchPopupL( aResourceId ) ); | 
|         |    270     if( err ) | 
|         |    271         { | 
|         |    272         ClosePopup(); | 
|         |    273         User::Leave( err ); | 
|         |    274         } | 
|         |    275     } | 
|         |    276  | 
|         |    277 void CMceDeliveryReportView::ClosePopup() | 
|         |    278     { | 
|         |    279     if( iPopup ) | 
|         |    280         { | 
|         |    281         AppUi()->RemoveFromViewStack( *this, iPopup ); | 
|         |    282         delete( iPopup ); | 
|         |    283         iPopup = NULL; | 
|         |    284         } | 
|         |    285     } | 
|         |    286  | 
|         |    287 void CMceDeliveryReportView::DoLaunchPopupL( TInt aResourceId ) | 
|         |    288     { | 
|         |    289     iPopup->ConstructL( this, 0, aResourceId ); | 
|         |    290     AppUi()->AddToViewStackL( *this, iPopup, ECoeStackPriorityMenu, | 
|         |    291                                              ECoeStackFlagRefusesFocus ); | 
|         |    292     iPopup->SetMenuType(CEikMenuBar::EMenuContext); | 
|         |    293     iPopup->TryDisplayMenuBarL(); | 
|         |    294     } | 
|         |    295  | 
|         |    296  | 
|         |    297 void CMceDeliveryReportView::HandleGainingForeground() | 
|         |    298     { | 
|         |    299      if ( MceAppUi()->MceViewActive( EMceDeliveryReportsViewActive ) ) | 
|         |    300         { | 
|         |    301         // Just ignore if this leaves. Worst thing happens here is that user sees empty delivery reports view. | 
|         |    302         TRAP_IGNORE( MceAppUi()->LogEngine()->ForegroundGainedL() ); | 
|         |    303         }     | 
|         |    304     } | 
|         |    305  | 
|         |    306 void CMceDeliveryReportView::HandleLosingForeground() | 
|         |    307     { | 
|         |    308     MceAppUi()->LogEngine()->ForegroundLost(); | 
|         |    309     } | 
|         |    310  | 
|         |    311 void CMceDeliveryReportView::ProcessCommandL( TInt aCommand ) | 
|         |    312     { | 
|         |    313 	TInt index( 0 ); | 
|         |    314 	TBool validNumber = EFalse ; | 
|         |    315 	index = iContainer->ListBox()->CurrentItemIndex(); | 
|         |    316 	if ( index >= 0 ) | 
|         |    317 		{ | 
|         |    318 		TPhCltTelephoneNumber tel; | 
|         |    319 		tel = MceAppUi()->LogEngine()->Event( index )->Number(); | 
|         |    320 		// Check the validity of the phone number and initiate the call | 
|         |    321 		validNumber = CommonPhoneParser::ParsePhoneNumber( tel, CommonPhoneParser::EPlainPhoneNumber );             | 
|         |    322 		} | 
|         |    323     if ( validNumber && aCommand == EAknSoftkeyContextOptions ) | 
|         |    324         { | 
|         |    325         aCommand = EAknSoftkeyOptions; | 
|         |    326         MenuBar()->SetMenuTitleResourceId( R_MCE_DELIVERY_REPORT_OK_MENUBAR ); | 
|         |    327         MenuBar()->SetMenuType(CEikMenuBar::EMenuContext); | 
|         |    328         } | 
|         |    329     else | 
|         |    330         { | 
|         |    331         MenuBar()->SetMenuTitleResourceId( R_MCE_DELIVERY_REPORT_MENUBAR ); | 
|         |    332         MenuBar()->SetMenuType(CEikMenuBar::EMenuOptions); | 
|         |    333         } | 
|         |    334 	     | 
|         |    335     CAknView::ProcessCommandL( aCommand ); | 
|         |    336     } | 
|         |    337  | 
|         |    338 void CMceDeliveryReportView::SetMSKButtonL() | 
|         |    339     { | 
|         |    340     TInt resourceId = R_MCE_MSK_BUTTON_CONTEXT_OPTIONS; | 
|         |    341     if ( iContainer->ListBox()->Model()->NumberOfItems() == 0 || | 
|         |    342 		!MceAppUi()->LogEngine()-> | 
|         |    343 			IsNumberAvailable( iContainer->ListBox()->CurrentItemIndex() ) ) | 
|         |    344         { | 
|         |    345         resourceId = R_MCE_MSK_BUTTON_EMPTY; | 
|         |    346         } | 
|         |    347     CEikButtonGroupContainer* cba = Cba(); | 
|         |    348     cba->SetCommandL( KMSKPosition, resourceId ); | 
|         |    349     cba->DrawDeferred(); | 
|         |    350     } | 
|         |    351  | 
|         |    352 //  End of File |