phonebookui/Phonebook/View/src/CPbkSingleEntryFetchDlg.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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 *       Provides methods for Phonebook Single Entry Fetch dialog API.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkSingleEntryFetchDlg.h"  // This class
       
    22 #include <PbkView.rsg>
       
    23 #include "CPbkFetchDlg.h"
       
    24 #include <CPbkContactEngine.h>
       
    25 
       
    26 // LOCAL CONSTANTS AND MACROS
       
    27 enum TPanicCode
       
    28     {
       
    29     EPanicPostCond_Constructor = 1,
       
    30     EPanicPreCond_ConstructL,
       
    31     EPanicPreCond_ExecuteLD,
       
    32     EPanicPreCond_ResetWhenDestroyed,
       
    33     EPanicPostCond_ConstructL
       
    34     };
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 EXPORT_C CPbkSingleEntryFetchDlg::TParams::TParams() :
       
    39     iPbkEngine(NULL),
       
    40     iContactView(NULL),
       
    41     iFetchKeyCallback(NULL),
       
    42     iFetchDlgAccept(NULL),
       
    43     iSelectedEntry(KNullContactId),
       
    44     iCbaId(0)
       
    45     {
       
    46     }
       
    47 
       
    48 inline CPbkSingleEntryFetchDlg::CPbkSingleEntryFetchDlg(TParams& aParams) :
       
    49     iParams(aParams), 
       
    50     iPbkEngine(iParams.iPbkEngine),
       
    51     iContactView(iParams.iContactView)
       
    52     {
       
    53     // PostCond
       
    54     __ASSERT_DEBUG(!iFetchDlg && !iDestroyedPtr, 
       
    55         Panic(EPanicPostCond_Constructor));
       
    56     }
       
    57 
       
    58 EXPORT_C CPbkSingleEntryFetchDlg* CPbkSingleEntryFetchDlg::NewL(TParams& aParams)
       
    59     {
       
    60     CPbkSingleEntryFetchDlg* self = new(ELeave) CPbkSingleEntryFetchDlg(aParams);
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65     }
       
    66 
       
    67 EXPORT_C void CPbkSingleEntryFetchDlg::SetMopParent(MObjectProvider* aParent)
       
    68     {
       
    69     iObjectProvider = aParent;
       
    70     }
       
    71 
       
    72 EXPORT_C void CPbkSingleEntryFetchDlg::ResetWhenDestroyed
       
    73         (CPbkSingleEntryFetchDlg** aSelfPtr)
       
    74     {
       
    75     __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr==this, 
       
    76             Panic(EPanicPreCond_ResetWhenDestroyed));
       
    77 
       
    78     iSelfPtr = aSelfPtr;
       
    79     }
       
    80 
       
    81 EXPORT_C TInt CPbkSingleEntryFetchDlg::ExecuteLD()
       
    82     {
       
    83     // PreCond
       
    84     __ASSERT_DEBUG(iContactView && !iFetchDlg && iPbkEngine, 
       
    85             Panic(EPanicPreCond_ExecuteLD));
       
    86 
       
    87     // "D" function semantics
       
    88     CleanupStack::PushL(this);
       
    89     TBool thisDestroyed = EFalse;
       
    90     // Destructor sets thisDestroyed to ETrue
       
    91     iDestroyedPtr = &thisDestroyed;
       
    92 
       
    93     // Convert iParams for input to CPbkFetchDlg
       
    94     CPbkFetchDlg::TParams params;
       
    95     params.iResId = R_PBK_SINGLE_ENTRY_FETCH_DLG;
       
    96     params.iFlags = CPbkFetchDlg::FETCH_FOCUSED;
       
    97     params.iContactView = iContactView;
       
    98     params.iFocusedEntry = iParams.iSelectedEntry;
       
    99     params.iKeyCallback = iParams.iFetchKeyCallback;
       
   100     params.iAcceptCallback = iParams.iFetchDlgAccept;
       
   101     params.iCbaId = iParams.iCbaId;
       
   102 
       
   103     iFetchDlg = CPbkFetchDlg::NewL(params, *iPbkEngine);
       
   104     iFetchDlg->SetMopParent(iObjectProvider);
       
   105     iFetchDlg->ResetWhenDestroyed(&iFetchDlg);
       
   106     TInt result = 0;
       
   107     result = iFetchDlg->ExecuteLD();
       
   108     
       
   109     if (thisDestroyed)
       
   110         {
       
   111         CleanupStack::Pop(this);
       
   112         }
       
   113     else
       
   114         {
       
   115         if (result && params.iFocusedEntry != KNullContactId)
       
   116             {
       
   117             // Convert params back to our format
       
   118             iParams.iSelectedEntry = params.iFocusedEntry;
       
   119             }
       
   120         CleanupStack::PopAndDestroy(this);
       
   121         }
       
   122 
       
   123     return result;
       
   124     }
       
   125 
       
   126 CPbkSingleEntryFetchDlg::~CPbkSingleEntryFetchDlg()
       
   127     {
       
   128     if (iSelfPtr) 
       
   129         {
       
   130         *iSelfPtr = NULL;
       
   131         }
       
   132     if (iDestroyedPtr) 
       
   133         {
       
   134         *iDestroyedPtr = ETrue;
       
   135         }
       
   136     // Close the dialog
       
   137     delete iFetchDlg;
       
   138     // Delete engine if this object owns one
       
   139     delete iOwnPbkEngine;
       
   140     }
       
   141 
       
   142 void CPbkSingleEntryFetchDlg::ConstructL()
       
   143     {
       
   144     // PreCond
       
   145     __ASSERT_DEBUG(!iFetchDlg && !iDestroyedPtr && !iOwnPbkEngine, 
       
   146         Panic(EPanicPreCond_ConstructL));
       
   147 
       
   148     if (!iPbkEngine)
       
   149         {
       
   150         CPbkContactEngine* engine = CPbkContactEngine::Static();
       
   151         if (engine)
       
   152             {
       
   153             iPbkEngine = engine;
       
   154             }
       
   155         else
       
   156             {
       
   157             iOwnPbkEngine = CPbkContactEngine::NewL();
       
   158             iPbkEngine = iOwnPbkEngine;
       
   159             }
       
   160         }
       
   161 
       
   162     // Set up contact view if needed
       
   163     if (!iContactView)
       
   164         {
       
   165         iContactView = &iPbkEngine->AllContactsView();
       
   166         }
       
   167 
       
   168     // PostCond
       
   169     __ASSERT_DEBUG(iPbkEngine, Panic(EPanicPostCond_ConstructL));
       
   170     }
       
   171 
       
   172 void CPbkSingleEntryFetchDlg::Panic(TInt aReason)
       
   173     {
       
   174     _LIT(KPanicText, "CPbkSingleEntryFetchDlg");
       
   175     User::Panic(KPanicText, aReason);
       
   176     }
       
   177 
       
   178 //  End of File