phonebookui/Phonebook2/UIControls/src/cpbk2contacteditornewowncontact.cpp
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2009 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:  A contact editor strategy for the new own contact creation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cpbk2contacteditornewowncontact.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include <TPbk2ContactEditorParams.h>
       
    23 #include <CPbk2PresentationContact.h>
       
    24 #include "CPbk2InputAbsorber.h"
       
    25 #include <Pbk2Debug.h>
       
    26 #include <csxhelp/phob.hlp.hrh>
       
    27 #include <Pbk2UID.h>
       
    28 
       
    29 // Virtual Phonebook
       
    30 #include <MVPbkStoreContact.h>
       
    31 
       
    32 // System includes
       
    33 #include <avkon.rsg>
       
    34 
       
    35 
       
    36 #ifdef _DEBUG
       
    37 
       
    38 /// Unnamed namespace
       
    39 namespace {
       
    40 enum TPanicCode
       
    41     {
       
    42     EContactOperationCompleted_PreCond,
       
    43     EContactOperationFailed_PreCond,
       
    44     EDeleteContactL_PreCond
       
    45     };
       
    46 
       
    47 void Panic(TInt aReason)
       
    48     {
       
    49     _LIT(KPanicText, "EditorNewOwnContact");
       
    50     User::Panic(KPanicText, aReason);
       
    51     }
       
    52 } /// namespace
       
    53 
       
    54 #endif // _DEBUG
       
    55 
       
    56 // --------------------------------------------------------------------------
       
    57 // CPbk2ContactEditorNewOwnContact::CPbk2ContactEditorNewOwnContact
       
    58 // --------------------------------------------------------------------------
       
    59 //
       
    60 inline CPbk2ContactEditorNewOwnContact::CPbk2ContactEditorNewOwnContact(
       
    61     CPbk2PresentationContact* aContact ) :
       
    62         CActive( CActive::EPriorityStandard ),
       
    63         iContact( aContact )
       
    64     {
       
    65     CActiveScheduler::Add(this);
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CPbk2ContactEditorNewOwnContact::~CPbk2ContactEditorNewOwnContact
       
    70 // --------------------------------------------------------------------------
       
    71 //
       
    72 CPbk2ContactEditorNewOwnContact::~CPbk2ContactEditorNewOwnContact()
       
    73     {
       
    74     Cancel();
       
    75     delete iIdleDelete;
       
    76     delete iInputAbsorber;
       
    77     }
       
    78 
       
    79 // --------------------------------------------------------------------------
       
    80 // CPbk2ContactEditorNewOwnContact::NewL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 CPbk2ContactEditorNewOwnContact* CPbk2ContactEditorNewOwnContact::NewL(
       
    84     TPbk2ContactEditorParams& /*aParams*/,
       
    85     CPbk2PresentationContact* aContact )
       
    86     {
       
    87     CPbk2ContactEditorNewOwnContact* self =
       
    88         new(ELeave) CPbk2ContactEditorNewOwnContact(aContact);
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL();
       
    91     CleanupStack::Pop(self);
       
    92     return self;
       
    93     }
       
    94 
       
    95 // --------------------------------------------------------------------------
       
    96 // CPbk2ContactEditorNewOwnContact::ConstructL
       
    97 // --------------------------------------------------------------------------
       
    98 //
       
    99 inline void CPbk2ContactEditorNewOwnContact::ConstructL()
       
   100     {
       
   101     iContact->AddSupportedTemplateFieldsL();
       
   102     iInputAbsorber = CPbk2InputAbsorber::NewL(R_AVKON_SOFTKEYS_OPTIONS_DONE);
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CPbk2ContactEditorNewOwnContact::RunL
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 void CPbk2ContactEditorNewOwnContact::RunL()
       
   110     {
       
   111     MPbk2ContactEditorEventObserver* observer = iObserver;
       
   112     iObserver = NULL;
       
   113     observer->ContactEditorOperationCompleted(iLatestResult, iEditorParams);
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CPbk2ContactEditorNewOwnContact::DoCancel
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 void CPbk2ContactEditorNewOwnContact::DoCancel()
       
   121     {
       
   122     // Do nothing
       
   123     }
       
   124 
       
   125 // --------------------------------------------------------------------------
       
   126 // CPbk2ContactEditorNewOwnContact::SaveContactL
       
   127 // --------------------------------------------------------------------------
       
   128 //
       
   129 void CPbk2ContactEditorNewOwnContact::SaveContactL(
       
   130     MPbk2ContactEditorEventObserver& aObserver,
       
   131     MPbk2ContactEditorEventObserver::TParams& aParams)
       
   132     {
       
   133     // If observer is set there is process ongoing.
       
   134     // Might happen when user is quicker than should be.
       
   135     if ( !iObserver )
       
   136         {
       
   137         iObserver = &aObserver;
       
   138         iEditorParams = aParams;
       
   139         iContact->CommitL(*this);
       
   140         iInputAbsorber->Wait();        
       
   141         }
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CPbk2ContactEditorNewOwnContact::DeleteContactL
       
   146 // --------------------------------------------------------------------------
       
   147 //
       
   148 void CPbk2ContactEditorNewOwnContact::DeleteContactL(
       
   149     MPbk2ContactEditorEventObserver& aObserver,
       
   150 	MPbk2ContactEditorEventObserver::TParams& aParams)
       
   151     {
       
   152     __ASSERT_DEBUG(!iObserver, Panic(EDeleteContactL_PreCond));
       
   153 
       
   154     if (!iIdleDelete)
       
   155         {
       
   156         iIdleDelete = CIdle::NewL(CActive::EPriorityStandard);
       
   157         }
       
   158     else
       
   159         {
       
   160         iIdleDelete->Cancel();
       
   161         }
       
   162 
       
   163     iObserver = &aObserver;
       
   164     iEditorParams = aParams;
       
   165     iIdleDelete->Start(TCallBack(&IdleDeleteCallBack, this));
       
   166     iInputAbsorber->Wait();
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CPbk2ContactEditorNewOwnContact::DefaultTitle
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 const TDesC& CPbk2ContactEditorNewOwnContact::DefaultTitle() const
       
   174     {
       
   175     // not used
       
   176     return KNullDesC;
       
   177     }
       
   178 
       
   179 // --------------------------------------------------------------------------
       
   180 // CPbk2ContactEditorNewOwnContact::SwitchContactL
       
   181 // --------------------------------------------------------------------------
       
   182 //
       
   183 void CPbk2ContactEditorNewOwnContact::SwitchContactL(
       
   184     CPbk2PresentationContact* aContact)
       
   185     {
       
   186     iContact = aContact;
       
   187     }
       
   188 
       
   189 // --------------------------------------------------------------------------
       
   190 // CPbk2ContactEditorNewOwnContact::GetHelpContext
       
   191 // --------------------------------------------------------------------------
       
   192 //
       
   193 void CPbk2ContactEditorNewOwnContact::GetHelpContext(
       
   194     TCoeHelpContext &aContext) const
       
   195     {
       
   196     aContext.iMajor.iUid = KPbk2UID3;
       
   197     aContext.iContext = KHLP_CCA_EDITOR;
       
   198     }
       
   199 
       
   200 // --------------------------------------------------------------------------
       
   201 // CPbk2ContactEditorNewOwnContact::StopQuery
       
   202 // --------------------------------------------------------------------------
       
   203 //
       
   204 TBool CPbk2ContactEditorNewOwnContact::StopQuery()
       
   205     {
       
   206     return EFalse;
       
   207     }
       
   208 
       
   209 // --------------------------------------------------------------------------
       
   210 // CPbk2ContactEditorNewOwnContact::IdleDeleteCallBack
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 TInt CPbk2ContactEditorNewOwnContact::IdleDeleteCallBack( TAny* aSelf )
       
   214     {
       
   215     static_cast<CPbk2ContactEditorNewOwnContact*>(aSelf)->HandleIdleDelete();
       
   216     return EFalse;
       
   217     }
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CPbk2ContactEditorNewOwnContact::HandleIdleDelete
       
   221 // --------------------------------------------------------------------------
       
   222 //
       
   223 void CPbk2ContactEditorNewOwnContact::HandleIdleDelete()
       
   224     {
       
   225     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   226         ( "CPbk2ContactEditorNewOwnContact::HandleIdleDelete(0x%x)" ), this );
       
   227 
       
   228     iInputAbsorber->StopWait();
       
   229     MPbk2ContactEditorEventObserver* observer = iObserver;
       
   230     iObserver = NULL;
       
   231     MVPbkContactObserver::TContactOpResult result;
       
   232     // Disable warnings by nulling the data members
       
   233     result.iStoreContact = NULL;
       
   234     result.iExtension = NULL;
       
   235     result.iOpCode = MVPbkContactObserver::EContactDelete;
       
   236     observer->ContactEditorOperationCompleted( result, iEditorParams );
       
   237     }
       
   238 
       
   239 // --------------------------------------------------------------------------
       
   240 // CPbk2ContactEditorNewOwnContact::ContactOperationCompleted
       
   241 // --------------------------------------------------------------------------
       
   242 //
       
   243 void CPbk2ContactEditorNewOwnContact::ContactOperationCompleted(
       
   244     MVPbkContactObserver::TContactOpResult aResult )
       
   245     {
       
   246     __ASSERT_DEBUG(iObserver &&
       
   247         ( aResult.iOpCode == MVPbkContactObserver::EContactCommit ||
       
   248           aResult.iOpCode == MVPbkContactObserver::EContactSetOwn ),
       
   249         Panic(EContactOperationCompleted_PreCond));
       
   250 
       
   251     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   252         ("CPbk2ContactEditorNewOwnContact::ContactOperationCompleted(0x%x)"),
       
   253             this);
       
   254     if( aResult.iOpCode == MVPbkContactObserver::EContactCommit )
       
   255         {
       
   256         // Set contact as own contact
       
   257         TRAPD( err, iContact->SetAsOwnL( *this ) );
       
   258         if( err )
       
   259             {
       
   260             ContactOperationFailed( aResult.iOpCode, err, EFalse );
       
   261             }
       
   262         // store commit result
       
   263         iLatestResult = aResult;
       
   264         }
       
   265     else // MVPbkContactObserver::EContactSetOwn
       
   266         {
       
   267         iInputAbsorber->StopWait();
       
   268     
       
   269         // Notify client asynchronously to give some time for the all
       
   270         // contacts view to get ready. This might not be needed anymore
       
   271         // here in new contact strategy... In edit contact strategy
       
   272         // this however is a mandatory move.
       
   273         TRequestStatus* status = &iStatus;
       
   274         User::RequestComplete(status, KErrNone);
       
   275         SetActive();
       
   276         }
       
   277     }
       
   278 
       
   279 // --------------------------------------------------------------------------
       
   280 // CPbk2ContactEditorNewOwnContact::ContactOperationFailed
       
   281 // --------------------------------------------------------------------------
       
   282 //
       
   283 void CPbk2ContactEditorNewOwnContact::ContactOperationFailed(
       
   284     MVPbkContactObserver::TContactOp aOpCode,
       
   285     TInt aErrorCode, TBool aErrorNotified )
       
   286     {
       
   287     __ASSERT_DEBUG(iObserver, Panic(EContactOperationFailed_PreCond));
       
   288 
       
   289     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   290         ("CPbk2ContactEditorNewOwnContact::ContactOperationFailed(0x%x) aErrorCode(%d)"),
       
   291             this, aErrorCode);
       
   292     iInputAbsorber->StopWait();
       
   293     MPbk2ContactEditorEventObserver* observer = iObserver;
       
   294     iObserver = NULL;
       
   295 
       
   296     MPbk2ContactEditorEventObserver::TFailParams failParams;
       
   297     failParams.iCloseEditor = EFalse;
       
   298     failParams.iErrorNotified = aErrorNotified;
       
   299     failParams.iErrorCode = KErrNone;
       
   300 
       
   301     observer->ContactEditorOperationFailed(aOpCode, aErrorCode, iEditorParams,
       
   302         failParams );
       
   303     }
       
   304 
       
   305 //  End of File