javaextensions/pim/cntadapter/src.s60/cpimcmadapteraccess.cpp
branchRCL_3
changeset 14 04becd199f91
child 17 0fd27995241b
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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:  Provides access to Contacts Model adapter
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE files
       
    20 #include "cpimcmadapteraccess.h"
       
    21 #include "cpimcmadaptermanager.h"
       
    22 #include "cpimcontactlistadapter.h"
       
    23 #include "mpimlocalizationmanager.h"
       
    24 #include "mpimlocalizationdata.h"
       
    25 #include "pimlocalizationids.h"
       
    26 #include "logger.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 const CDesCArray& CPIMCMAdapterAccess::ListNamesL(const TPIMListType aListType)
       
    31 {
       
    32     JELOG2(EPim);
       
    33     if (aListType == EPIMContactList)
       
    34     {
       
    35         return *iContactListNames;
       
    36     }
       
    37     else
       
    38     {
       
    39         // no Event or ToDo lists
       
    40         return *iNoListNames;
       
    41     }
       
    42 }
       
    43 
       
    44 TBool CPIMCMAdapterAccess::OpenContactListL(const TDesC* aListName,
       
    45         MPIMContactAdapterManager** aRetAdapterManager,
       
    46         MPIMContactListAdapter** aRetListAdapter,
       
    47         MPIMLocalizationData** aRetLocalizationData)
       
    48 {
       
    49     JELOG2(EPim);
       
    50     // There is exactly one Contact list, which is the default contact list.
       
    51 
       
    52     // If name is given, check that it matches the existing list name
       
    53     if (aListName && (*aListName != (*iContactListNames)[0]))
       
    54     {
       
    55         // Not found
       
    56         return EFalse;
       
    57     }
       
    58 
       
    59     // OK, got this far - Open the Contact list
       
    60 
       
    61     CPIMCMAdapterManager* adapterManager = CPIMCMAdapterManager::NewL(
       
    62                                                (*iContactListNames)[0]);
       
    63 
       
    64     CleanupStack::PushL(adapterManager);
       
    65 
       
    66     CPIMContactListAdapter* listAdapter = CPIMContactListAdapter::NewL(
       
    67                                               iFuncServer);
       
    68 
       
    69     CleanupStack::Pop(adapterManager);
       
    70 
       
    71     *aRetAdapterManager = adapterManager;
       
    72     *aRetListAdapter = listAdapter;
       
    73     *aRetLocalizationData = iContactLocalizationData;
       
    74 
       
    75     return ETrue;
       
    76 }
       
    77 
       
    78 TBool CPIMCMAdapterAccess::OpenEventListL(const TDesC* /*aListName*/,
       
    79         MPIMEventAdapterManager** /*aRetAdapterManager*/,
       
    80         MPIMEventListAdapter** /*aRetListAdapter*/, MPIMLocalizationData** /*aRetLocalizationData */)
       
    81 {
       
    82     JELOG2(EPim);
       
    83     // no Event lists
       
    84     return EFalse;
       
    85 }
       
    86 
       
    87 TBool CPIMCMAdapterAccess::OpenToDoListL(const TDesC* /*aListName*/,
       
    88         MPIMToDoAdapterManager** /*aRetAdapterManager*/,
       
    89         MPIMToDoListAdapter** /*aRetListAdapter*/, MPIMLocalizationData** /*aRetLocalizationData */)
       
    90 {
       
    91     JELOG2(EPim);
       
    92     // no ToDo lists
       
    93     return EFalse;
       
    94 }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CPIMCMAdapterAccess::NewL
       
    98 // Two-phased constructor.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CPIMCMAdapterAccess* CPIMCMAdapterAccess::NewL(
       
   102     MPIMLocalizationManager* aLocalizationManager,
       
   103     java::util::FunctionServer* aFuncServer)
       
   104 {
       
   105     JELOG2(EPim);
       
   106     CPIMCMAdapterAccess* self =
       
   107         new(ELeave) CPIMCMAdapterAccess(aLocalizationManager, aFuncServer);
       
   108 
       
   109     CleanupStack::PushL(self);
       
   110     self->ConstructL();
       
   111     CleanupStack::Pop(self);
       
   112 
       
   113     return self;
       
   114 }
       
   115 
       
   116 // destructor
       
   117 CPIMCMAdapterAccess::~CPIMCMAdapterAccess()
       
   118 {
       
   119     JELOG2(EPim);
       
   120     delete iContactListNames;
       
   121     delete iNoListNames;
       
   122     delete iContactLocalizationData;
       
   123 }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CPIMCMAdapterAccess::CPIMCMAdapterAccess
       
   127 // C++ default constructor can NOT contain any code, that
       
   128 // might leave.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 CPIMCMAdapterAccess::CPIMCMAdapterAccess(
       
   132     MPIMLocalizationManager* aLocalizationManager,
       
   133     java::util::FunctionServer* aFuncServer) :
       
   134         iLocalizationManager(aLocalizationManager), iFuncServer(aFuncServer)
       
   135 {
       
   136     JELOG2(EPim);
       
   137 }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CPIMCMAdapterAccess::ConstructL
       
   141 // Symbian 2nd phase constructor can leave.
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CPIMCMAdapterAccess::ConstructL()
       
   145 {
       
   146     JELOG2(EPim);
       
   147     // there will be one Contact list name
       
   148     iContactListNames = new(ELeave) CDesCArrayFlat(1);
       
   149 
       
   150     // will be left empty
       
   151     iNoListNames = new(ELeave) CDesCArrayFlat(1);
       
   152 
       
   153     iContactLocalizationData = iLocalizationManager->GetPIMLocalizationDataL(
       
   154                                    KPIMLocalizationIdContacts);
       
   155 
       
   156     HBufC* listName = iContactLocalizationData->GetListNameL();
       
   157     CleanupStack::PushL(listName);
       
   158     iContactListNames->AppendL(*listName);
       
   159     CleanupStack::PopAndDestroy(listName);
       
   160 }