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