phoneapp/phoneuiview/src/cphonesingleitemfetch.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Fetch items from Contacts
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikenv.h>
       
    20 #include <cphcntsingleitemfetch.h>
       
    21 #include <cphcntcontactid.h>
       
    22 #include <PhCltUtils.h>
       
    23 #include <eikcmobs.h>
       
    24 #include <AknQueryDialog.h>
       
    25 
       
    26 #include "cphoneviewcontroller.h"
       
    27 #include "cphonecontactcontroller.h"
       
    28 #include "cphonesingleitemfetch.h"
       
    29 #include "tphonecommandparam.h"
       
    30 #include "tphonecmdparamboolean.h"
       
    31 #include "tphonecmdparaminteger.h"
       
    32 #include "tphonecmdparamsingleitemfetch.h"
       
    33 #include "cphonestatuspane.h"
       
    34 #include "cphonemainresourceresolver.h"
       
    35 #include "phonerssbase.h"
       
    36 #include "phonelogger.h"
       
    37 #include "cphoneview.h"
       
    38 
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CPhoneSingleItemFetch::CPhoneSingleItemFetch(
       
    49     CEikonEnv& aEikEnv,
       
    50     CPhoneViewController& aViewController,
       
    51     CPhoneContactController& aContactController,
       
    52     CPhoneStatusPane& aStatusPane )
       
    53     : CActive ( EPriorityStandard ),
       
    54     iEikEnv( aEikEnv ),
       
    55     iViewController( aViewController ),
       
    56     iContactController( aContactController ),
       
    57     iStatusPane( aStatusPane )
       
    58     {
       
    59     CActiveScheduler::Add( this );
       
    60     iViewController.PhoneView()->SetPhoneViewObserver( *this );
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CPhoneSingleItemFetch::NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C CPhoneSingleItemFetch* CPhoneSingleItemFetch::NewL(
       
    69     CEikonEnv& aEikEnv,
       
    70     CPhoneViewController& aViewController,
       
    71     CPhoneContactController& aContactController,
       
    72     CPhoneStatusPane& aStatusPane )
       
    73     {
       
    74     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneSingleItemFetch::NewL() ");
       
    75     CPhoneSingleItemFetch* self =
       
    76         new( ELeave ) CPhoneSingleItemFetch( aEikEnv,
       
    77                                              aViewController,
       
    78                                              aContactController,
       
    79                                              aStatusPane );
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CPhoneSingleItemFetch::RunL
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CPhoneSingleItemFetch::RunL()
       
    89     {
       
    90     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneSingleItemFetch::RunL()" );
       
    91 
       
    92     iButtonId = EPhoneViewYesSingleItemFetch;
       
    93 
       
    94     // First open the single item fetch dialog
       
    95     HBufC* fetchContent = HBufC::NewLC( KPhoneNumberEntryBufferSize );
       
    96     fetchContent->Des().Zero();
       
    97     TPtr ptr( fetchContent->Des() );
       
    98     TPhoneCmdParamSingleItemFetch singleItemFetchParam;
       
    99 
       
   100     if ( iResourceId == EPhoneNewCallFetchTitle )
       
   101         {
       
   102         singleItemFetchParam.SetType( CPhCntSingleItemFetch::EFetchNewCall );
       
   103         singleItemFetchParam.SetTitlePaneResourceId(
       
   104             CPhoneMainResourceResolver::Instance()->
       
   105                 ResolveResourceID( EPhoneNewCallFetchTitle ) );
       
   106         singleItemFetchParam.SetCbaResourceId(
       
   107             CPhoneMainResourceResolver::Instance()->
       
   108                 ResolveResourceID( EPhoneNewCallFetchCBA ) );
       
   109         singleItemFetchParam.SetString( &ptr );
       
   110         }
       
   111     else if ( iResourceId > EPhoneRssBaseLast )
       
   112         {
       
   113         singleItemFetchParam.SetType( CPhCntSingleItemFetch::EFetchNewPSCall );
       
   114         singleItemFetchParam.SetTitlePaneResourceId(
       
   115             CPhoneMainResourceResolver::Instance()->
       
   116                 ResolveResourceID( EPhoneNewCallFetchTitle ) );
       
   117         singleItemFetchParam.SetCbaResourceId(
       
   118         CPhoneMainResourceResolver::Instance()->
       
   119            ResolveResourceID( EPhoneNewCallFetchCBA ) );
       
   120         singleItemFetchParam.SetString( &ptr );
       
   121         }
       
   122     else // EPhoneDtmfFetchTitle & EPhoneDtmfNumberQuery
       
   123         {
       
   124         singleItemFetchParam.SetType( CPhCntSingleItemFetch::EFetchDtmf );
       
   125         singleItemFetchParam.SetTitlePaneResourceId(
       
   126             CPhoneMainResourceResolver::Instance()->
       
   127                 ResolveResourceID( EPhoneDtmfFetchTitle ) );
       
   128         singleItemFetchParam.SetCbaResourceId(
       
   129             CPhoneMainResourceResolver::Instance()->
       
   130                 ResolveResourceID( KPhoneDefaultFetchCBA ) );
       
   131         singleItemFetchParam.SetString( &ptr );
       
   132         }
       
   133 
       
   134     // Change title pane contents
       
   135     CBase* textTitlePane = iStatusPane.CreateTextTitlePaneLC(
       
   136     singleItemFetchParam.TitlePaneResourceId() );
       
   137 
       
   138     CPhCntSingleItemFetch::TFetchParams result;
       
   139     result.iType = singleItemFetchParam.Type();
       
   140     result.iString = singleItemFetchParam.String();
       
   141     result.iCbaResource = singleItemFetchParam.CbaResourceId();
       
   142     result.iNumberType = MPhCntMatch::ENone;
       
   143     result.iContactId = NULL;
       
   144 
       
   145     TInt retval = KErrNotFound;
       
   146     if( iSingleItemFetch )
       
   147         {
       
   148         retval = iSingleItemFetch->FetchLD( result );
       
   149         iFetchPerformed = ETrue;
       
   150         iSingleItemFetch = NULL; // destructed in FetchLD
       
   151         delete result.iContactId; // pointer which will leak otherwise
       
   152         result.iContactId = NULL;
       
   153         }
       
   154 
       
   155     // The contact operation may be cancelled if the END key
       
   156     // is pressed (res == KErrCancel).
       
   157     // If so, the blocking dialog will be removed.
       
   158     if ( !iViewController.BlockingDialogIsDisplayed() || ptr == KNullDesC )
       
   159         {
       
   160         // Indicate that the operation has been cancelled
       
   161         iButtonId = EPhoneViewNoSingleItemFetch;
       
   162         static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   163             ->ProcessCommandL( iButtonId );
       
   164         iFetchPerformed = EFalse;
       
   165         }
       
   166     else if ( retval == KErrNone )
       
   167         {
       
   168         if ( CPhCntSingleItemFetch::EFetchNewPSCall !=
       
   169                 singleItemFetchParam.Type() )
       
   170             {
       
   171             // Remove garbage from buffer.
       
   172             PhCltUtils::RemoveInvalidChars(
       
   173                 *( singleItemFetchParam.String() ) );
       
   174             }
       
   175         iViewController.SetFetchContent( ptr );
       
   176         }
       
   177 
       
   178     // restore title pane
       
   179     CleanupStack::PopAndDestroy( textTitlePane );
       
   180     CleanupStack::PopAndDestroy( fetchContent );
       
   181     // Reset the flag
       
   182     // ETrue if a blocking dialog is currently being displayed.
       
   183     TPhoneCmdParamBoolean booleanParam;
       
   184     booleanParam.SetBoolean( EFalse );
       
   185     iViewController.ExecuteCommandL(
       
   186         EPhoneViewSetBlockingDialogStatus,
       
   187         &booleanParam );
       
   188   }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // CPhoneSingleItemFetch::RunError
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 TInt CPhoneSingleItemFetch::RunError( TInt /*aError */ )
       
   195     {
       
   196     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneSingleItemFetch::RunError( ) ");
       
   197     Delete();
       
   198     TPhoneCmdParamBoolean booleanParam;
       
   199     booleanParam.SetBoolean( EFalse );
       
   200     TRAP_IGNORE( iViewController.ExecuteCommandL(
       
   201         EPhoneViewSetBlockingDialogStatus, &booleanParam ))
       
   202     return KErrNone;
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CPhoneSingleItemFetch::DoCancel
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 void CPhoneSingleItemFetch::DoCancel()
       
   210     {
       
   211     __LOGMETHODSTARTEND( EPhoneUIView, "CPhoneSingleItemFetch::DoCancel()" );
       
   212     Delete();
       
   213     }
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // Destructor
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CPhoneSingleItemFetch::~CPhoneSingleItemFetch()
       
   221     {
       
   222     __LOGMETHODSTARTEND( EPhoneUIView,
       
   223         "CPhoneSingleItemFetch::~CPhoneSingleItemFetch()" );
       
   224     Delete();
       
   225     }
       
   226 
       
   227 
       
   228 // ---------------------------------------------------------
       
   229 // CPhoneSingleItemFetch::OpenSingleItemFetchDialogL
       
   230 // ---------------------------------------------------------
       
   231 //
       
   232 void CPhoneSingleItemFetch::OpenSingleItemFetchDialogL(
       
   233     TPhoneCommandParam* aCommandParam )
       
   234     {
       
   235     __LOGMETHODSTARTEND( EPhoneUIView,
       
   236         "CPhoneSingleItemFetch::OpenSingleItemFetchDialogL()" );
       
   237    if( !IsActive() )
       
   238         {
       
   239         TPhoneCmdParamInteger* resourceId 
       
   240             = static_cast<TPhoneCmdParamInteger*>( aCommandParam );
       
   241         iResourceId = resourceId->Integer();
       
   242     
       
   243         // Create the contact dialog
       
   244         iSingleItemFetch = iContactController.CreateSingleItemFetchL();
       
   245         
       
   246         iViewController.SetSingleItemFetchType( iResourceId );
       
   247         
       
   248         SetActive();
       
   249         TRequestStatus* status = &iStatus;
       
   250         User::RequestComplete( status, KErrNone );
       
   251         }
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CPhoneSingleItemFetch::Delete
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CPhoneSingleItemFetch::Delete()
       
   259     {
       
   260     __LOGMETHODSTARTEND(EPhoneUIView, "CPhoneSingleItemFetch::Delete()" );
       
   261     if ( iSingleItemFetch )
       
   262         {
       
   263         iViewController.SetSingleItemFetchType( NULL );
       
   264         
       
   265         // Cancel request (FetchLD) by destroying the instance.
       
   266         delete iSingleItemFetch;
       
   267         iSingleItemFetch = NULL;
       
   268         }
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CPhoneSingleItemFetch::PhoneViewActivatedL
       
   273 // ---------------------------------------------------------
       
   274 //
       
   275 void CPhoneSingleItemFetch::PhoneViewActivatedL()
       
   276     {
       
   277     // Phone view is fully activated, now provide selection to states.
       
   278     if ( iFetchPerformed )
       
   279         {
       
   280         // reset flag
       
   281         iFetchPerformed = EFalse;
       
   282         static_cast<MEikCommandObserver*>( iEikEnv.EikAppUi() )
       
   283             ->ProcessCommandL( iButtonId );
       
   284         }
       
   285     }