phonebookui/Phonebook2/ServerApplication/src/CPbk2AssignSelectFieldDlg.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 select field dialog for assign service.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2AssignSelectFieldDlg.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2SelectFieldProperty.h"
       
    23 #include "CPbk2KeyEventDealer.h"
       
    24 #include <MPbk2ExitCallback.h>
       
    25 
       
    26 // System includes
       
    27 #include <avkon.hrh>
       
    28 #include <eikcmobs.h>
       
    29 #include <eikappui.h>
       
    30 
       
    31 /// Unnamed namespace for local definitions
       
    32 namespace {
       
    33 
       
    34 #ifdef _DEBUG
       
    35 enum TPanicCode
       
    36     {
       
    37     EPanicPreCond_ResetWhenDestroyed = 1
       
    38     };
       
    39 
       
    40 void Panic( TInt aReason )
       
    41     {
       
    42     _LIT( KPanicText, "CPbk2AssignSelectFieldDlg" );
       
    43     User::Panic( KPanicText, aReason );
       
    44     }
       
    45 
       
    46 #endif // _DEBUG
       
    47 
       
    48 } /// namespace
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // CPbk2AssignSelectFieldDlg::CPbk2AssignSelectFieldDlg
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CPbk2AssignSelectFieldDlg::CPbk2AssignSelectFieldDlg
       
    55         ( MPbk2ExitCallback& aExitCallback ):
       
    56             iExitCallback( aExitCallback )
       
    57     {
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CPbk2AssignSelectFieldDlg::~CPbk2AssignSelectFieldDlg
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 CPbk2AssignSelectFieldDlg::~CPbk2AssignSelectFieldDlg()
       
    65     {
       
    66     // Tells ExecuteLD this object has been destroyed
       
    67     if ( iDestroyedPtr )
       
    68         {
       
    69         *iDestroyedPtr = ETrue;
       
    70         }
       
    71 
       
    72     if ( iSelfPtr )
       
    73         {
       
    74         *iSelfPtr = NULL;
       
    75         }
       
    76 
       
    77     delete iDealer;
       
    78     }
       
    79 
       
    80 // --------------------------------------------------------------------------
       
    81 // CPbk2AssignSelectFieldDlg::ConstructL
       
    82 // --------------------------------------------------------------------------
       
    83 //
       
    84 inline void CPbk2AssignSelectFieldDlg::ConstructL()
       
    85     {
       
    86     iDealer = CPbk2KeyEventDealer::NewL( *this );
       
    87     }
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CPbk2AssignSelectFieldDlg::NewL
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 CPbk2AssignSelectFieldDlg* CPbk2AssignSelectFieldDlg::NewL
       
    94         ( MPbk2ExitCallback& aExitCallback )
       
    95     {
       
    96     CPbk2AssignSelectFieldDlg* self =
       
    97         new ( ELeave ) CPbk2AssignSelectFieldDlg( aExitCallback );
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop( self );
       
   101     return self;
       
   102     }
       
   103 
       
   104 // --------------------------------------------------------------------------
       
   105 // CPbk2AssignSelectFieldDlg::ExecuteLD
       
   106 // --------------------------------------------------------------------------
       
   107 //
       
   108 TInt CPbk2AssignSelectFieldDlg::ExecuteLD
       
   109         ( MPbk2SelectFieldProperty& aProperty )
       
   110     {
       
   111     CleanupStack::PushL( this );
       
   112 
       
   113     iProperty = &aProperty;
       
   114 
       
   115     aProperty.PrepareL();
       
   116 
       
   117     TBool thisDestroyed = EFalse;
       
   118     iDestroyedPtr = &thisDestroyed;
       
   119 
       
   120     TInt result = aProperty.ExecuteL();
       
   121 
       
   122     if ( thisDestroyed )
       
   123         {
       
   124         // This object has been destroyed
       
   125         CleanupStack::Pop( this );
       
   126         }
       
   127     else
       
   128         {
       
   129         iProperty = NULL;
       
   130         // If end key has been pressed the property dialog
       
   131         // returns with KErrCancel. If also abort is ordered we
       
   132         // must change the return value to KErrAbort
       
   133         if ( iExitRecord.IsSet( EAbortOrdered ) && result == KErrCancel )
       
   134             {
       
   135             result = KErrAbort;
       
   136             }
       
   137 
       
   138         CleanupStack::PopAndDestroy( this );
       
   139         }
       
   140 
       
   141     return result;
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CPbk2AssignSelectFieldDlg::RequestExitL
       
   146 // --------------------------------------------------------------------------
       
   147 //
       
   148 void CPbk2AssignSelectFieldDlg::RequestExitL( TInt aCommandId )
       
   149     {
       
   150     if ( iProperty )
       
   151         {
       
   152         iProperty->Cancel( aCommandId );
       
   153         iProperty = NULL;
       
   154         }
       
   155 
       
   156     if ( aCommandId == EEikBidCancel )
       
   157         {
       
   158         // End key exit
       
   159         iExitRecord.Set( EAbortApproved );
       
   160         ExitApplication( EAknCmdExit );
       
   161         }
       
   162     else
       
   163         {
       
   164         delete this;
       
   165         }
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CPbk2AssignSelectFieldDlg::ForceExit
       
   170 // --------------------------------------------------------------------------
       
   171 //
       
   172 void CPbk2AssignSelectFieldDlg::ForceExit()
       
   173     {
       
   174     if ( iProperty )
       
   175         {
       
   176         // Command id does not matter much, it shouldn't however be
       
   177         // EEikBidCancel since that indicates end key and causes
       
   178         // application exit
       
   179         iProperty->Cancel( EAknSoftkeyClose );
       
   180         iProperty = NULL;
       
   181         }
       
   182 
       
   183     delete this;
       
   184     }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CPbk2AssignSelectFieldDlg::ResetWhenDestroyed
       
   188 // --------------------------------------------------------------------------
       
   189 //
       
   190 void CPbk2AssignSelectFieldDlg::ResetWhenDestroyed
       
   191         ( MPbk2DialogEliminator** aSelfPtr )
       
   192     {
       
   193     __ASSERT_DEBUG( !aSelfPtr || *aSelfPtr == this,
       
   194         Panic( EPanicPreCond_ResetWhenDestroyed ) );
       
   195 
       
   196     iSelfPtr = aSelfPtr;
       
   197     }
       
   198 
       
   199 // --------------------------------------------------------------------------
       
   200 // CPbk2AssignSelectFieldDlg::Pbk2ProcessKeyEventL
       
   201 // --------------------------------------------------------------------------
       
   202 //
       
   203 TBool CPbk2AssignSelectFieldDlg::Pbk2ProcessKeyEventL
       
   204         ( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   205     {
       
   206     TBool ret = EFalse;
       
   207 
       
   208     if ( aType == EEventKey && aKeyEvent.iCode == EKeyEscape )
       
   209         {
       
   210         // We need to catch end key pressed events for quering
       
   211         // the client is it ok to exit
       
   212         iExitRecord.Set( EAbortOrdered );
       
   213 
       
   214         // If exit callback returned EFalse, the exit is cancelled
       
   215         if ( !iExitCallback.OkToExitL( EEikBidCancel ) )
       
   216             {
       
   217             iExitRecord.Clear( EAbortApproved );
       
   218             }
       
   219 
       
   220         ret = ETrue;
       
   221         }
       
   222 
       
   223     return ret;
       
   224     }
       
   225 
       
   226 // --------------------------------------------------------------------------
       
   227 // CPbk2AssignSelectFieldDlg::ExitApplication
       
   228 // --------------------------------------------------------------------------
       
   229 //
       
   230 void CPbk2AssignSelectFieldDlg::ExitApplication( TInt aCommandId )
       
   231     {
       
   232     if ( iExitRecord.IsSet( EAbortOrdered ) &&
       
   233          iExitRecord.IsSet( EAbortApproved ) )
       
   234         {
       
   235         CEikAppUi* appUi = static_cast<CEikAppUi*>
       
   236             ( CCoeEnv::Static()->AppUi() );
       
   237         MEikCommandObserver* cmdObs =
       
   238             static_cast<MEikCommandObserver*>( appUi );
       
   239 
       
   240         // Dialog is closed so there is nothing to do if
       
   241         // ProcessCommandL leaves. Of course it shouldn't leave in
       
   242         // practice because it's exit command.
       
   243         TRAP_IGNORE( cmdObs->ProcessCommandL( aCommandId ) );
       
   244         }
       
   245     }
       
   246 
       
   247 // End of File