|
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 Agenda Model event adapters |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cpimeventadapteraccess.h" |
|
21 #include "cpimapptadaptermanager.h" |
|
22 #include "cpimmemoadaptermanager.h" |
|
23 #include "cpimannivadaptermanager.h" |
|
24 #include "cpimagnapptadapter.h" |
|
25 #include "cpimagnmemoadapter.h" |
|
26 #include "cpimagnannivadapter.h" |
|
27 #include "mpimlocalizationmanager.h" |
|
28 #include "mpimlocalizationdata.h" |
|
29 #include "pimlocalizationids.h" |
|
30 #include "logger.h" |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CPIMEventAdapterAccess::CPIMEventAdapterAccess |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CPIMEventAdapterAccess::CPIMEventAdapterAccess( |
|
39 MPIMLocalizationManager* aLocalizationManager, |
|
40 java::util::FunctionServer* aFuncServer) // not owned |
|
41 : |
|
42 iLocalizationManager(aLocalizationManager), iFuncServer(aFuncServer) |
|
43 { |
|
44 JELOG2(EPim); |
|
45 } |
|
46 |
|
47 void CPIMEventAdapterAccess::ConstructL() |
|
48 { |
|
49 JELOG2(EPim); |
|
50 iEventListNames = new(ELeave) CDesCArrayFlat(KPIMNumberOfEventLists); |
|
51 |
|
52 // will be left empty |
|
53 iNoListNames = new(ELeave) CDesCArrayFlat(1); |
|
54 |
|
55 // Order of lists matters: |
|
56 // Appointments - Events (Memos) - Anniversaries |
|
57 // See OpenEventListL(). |
|
58 |
|
59 iApptLocalizationData = iLocalizationManager->GetPIMLocalizationDataL( |
|
60 KPIMLocalizationIdEvent, KPIMListNameIdAppointment); |
|
61 |
|
62 iMemoLocalizationData = iLocalizationManager->GetPIMLocalizationDataL( |
|
63 KPIMLocalizationIdEvent, KPIMListNameIdEvent); |
|
64 |
|
65 iAnnivLocalizationData = iLocalizationManager->GetPIMLocalizationDataL( |
|
66 KPIMLocalizationIdEvent, KPIMListNameIdAnniversary); |
|
67 |
|
68 HBufC* listName = NULL; // reused |
|
69 |
|
70 // Order of lists matters, see above. |
|
71 |
|
72 listName = iApptLocalizationData->GetListNameL(); |
|
73 CleanupStack::PushL(listName); |
|
74 iEventListNames->AppendL(*listName); |
|
75 CleanupStack::PopAndDestroy(listName); |
|
76 |
|
77 listName = iMemoLocalizationData->GetListNameL(); |
|
78 CleanupStack::PushL(listName); |
|
79 iEventListNames->AppendL(*listName); |
|
80 CleanupStack::PopAndDestroy(listName); |
|
81 |
|
82 listName = iAnnivLocalizationData->GetListNameL(); |
|
83 CleanupStack::PushL(listName); |
|
84 iEventListNames->AppendL(*listName); |
|
85 CleanupStack::PopAndDestroy(listName); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CPIMEventAdapterAccess::NewL |
|
90 // Two-phased constructor. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CPIMEventAdapterAccess* CPIMEventAdapterAccess::NewL( |
|
94 MPIMLocalizationManager* aLocalizationManager, |
|
95 java::util::FunctionServer* aFuncServer) // not owned |
|
96 { |
|
97 JELOG2(EPim); |
|
98 CPIMEventAdapterAccess * self = |
|
99 new(ELeave) CPIMEventAdapterAccess(aLocalizationManager, aFuncServer); |
|
100 |
|
101 CleanupStack::PushL(self); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop(self); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // destructor |
|
108 CPIMEventAdapterAccess::~CPIMEventAdapterAccess() |
|
109 { |
|
110 JELOG2(EPim); |
|
111 delete iEventListNames; |
|
112 delete iNoListNames; |
|
113 delete iApptLocalizationData; |
|
114 delete iMemoLocalizationData; |
|
115 delete iAnnivLocalizationData; |
|
116 } |
|
117 |
|
118 const CDesCArray& CPIMEventAdapterAccess::ListNamesL( |
|
119 const TPIMListType aListType) |
|
120 { |
|
121 JELOG2(EPim); |
|
122 if (aListType == EPIMEventList) |
|
123 { |
|
124 return *iEventListNames; |
|
125 } |
|
126 else |
|
127 { |
|
128 // no Event or ToDo lists |
|
129 return *iNoListNames; |
|
130 } |
|
131 } |
|
132 |
|
133 TBool CPIMEventAdapterAccess::OpenContactListL(const TDesC* /*aListName*/, |
|
134 MPIMContactAdapterManager** /*aRetAdapterManager*/, |
|
135 MPIMContactListAdapter** /*aRetListAdapter*/, MPIMLocalizationData** /*aRetLocalizationData*/) |
|
136 { |
|
137 JELOG2(EPim); |
|
138 // no Contact lists |
|
139 return EFalse; |
|
140 } |
|
141 |
|
142 TBool CPIMEventAdapterAccess::OpenEventListL(const TDesC* aListName, |
|
143 MPIMEventAdapterManager** aRetAdapterManager, |
|
144 MPIMEventListAdapter** aRetListAdapter, |
|
145 MPIMLocalizationData** aRetLocalizationData) |
|
146 { |
|
147 JELOG2(EPim); |
|
148 // Open named Event list or the default list if no name given |
|
149 TPIMLocalizationDataID listId = KPIMListNameIdAppointment; // default |
|
150 |
|
151 // Order of lists is Appointments - Memos - Anniversaries |
|
152 |
|
153 if (aListName) |
|
154 { |
|
155 TInt listNamePos(0); |
|
156 if (0 == iEventListNames->Find(*aListName, listNamePos)) |
|
157 { |
|
158 listId = TPIMLocalizationDataID(listNamePos); |
|
159 } |
|
160 else |
|
161 { |
|
162 // List not found |
|
163 return EFalse; |
|
164 } |
|
165 } |
|
166 |
|
167 // OK, we have now identified the list - open it |
|
168 |
|
169 MPIMEventAdapterManager* adapterManager = NULL; |
|
170 MPIMEventListAdapter* listAdapter = NULL; |
|
171 MPIMLocalizationData* localizationData = NULL; |
|
172 |
|
173 switch (listId) |
|
174 { |
|
175 case EPIMEventListAppointment: |
|
176 { |
|
177 adapterManager = CPIMApptAdapterManager::NewL( |
|
178 (*iEventListNames)[listId]); |
|
179 CleanupDeletePushL(adapterManager); |
|
180 |
|
181 CPIMAgnApptAdapter* adapter = CPIMAgnApptAdapter::NewL(iFuncServer); |
|
182 CleanupStack::PushL(adapter); |
|
183 |
|
184 listAdapter = CPIMEventListAdapter::NewL(CCalEntry::EAppt, adapter, |
|
185 iFuncServer); |
|
186 |
|
187 CleanupStack::Pop(adapter); |
|
188 CleanupStack::Pop(adapterManager); |
|
189 |
|
190 localizationData = iApptLocalizationData; |
|
191 |
|
192 break; |
|
193 } |
|
194 case EPIMEventListEvent: |
|
195 { |
|
196 adapterManager = CPIMMemoAdapterManager::NewL( |
|
197 (*iEventListNames)[listId]); |
|
198 CleanupDeletePushL(adapterManager); |
|
199 |
|
200 CPIMAgnMemoAdapter* adapter = CPIMAgnMemoAdapter::NewL(iFuncServer); |
|
201 CleanupStack::PushL(adapter); |
|
202 |
|
203 listAdapter = CPIMEventListAdapter::NewL(CCalEntry::EEvent, adapter, |
|
204 iFuncServer); |
|
205 |
|
206 CleanupStack::Pop(adapter); |
|
207 CleanupStack::Pop(adapterManager); |
|
208 |
|
209 localizationData = iMemoLocalizationData; |
|
210 |
|
211 break; |
|
212 } |
|
213 case EPIMEventListAnniversary: |
|
214 { |
|
215 adapterManager = CPIMAnnivAdapterManager::NewL( |
|
216 (*iEventListNames)[listId]); |
|
217 CleanupDeletePushL(adapterManager); |
|
218 |
|
219 CPIMAgnAnnivAdapter* adapter = CPIMAgnAnnivAdapter::NewL(iFuncServer); |
|
220 CleanupStack::PushL(adapter); |
|
221 |
|
222 listAdapter = CPIMEventListAdapter::NewL(CCalEntry::EAnniv, adapter, |
|
223 iFuncServer); |
|
224 |
|
225 CleanupStack::Pop(adapter); |
|
226 CleanupStack::Pop(adapterManager); |
|
227 |
|
228 localizationData = iAnnivLocalizationData; |
|
229 |
|
230 break; |
|
231 } |
|
232 default: |
|
233 { |
|
234 // We should never end up here (but if we do, the list name |
|
235 // mappings are not OK) |
|
236 User::Leave(KErrCorrupt); |
|
237 } |
|
238 } |
|
239 |
|
240 *aRetAdapterManager = adapterManager; |
|
241 *aRetListAdapter = listAdapter; |
|
242 *aRetLocalizationData = localizationData; |
|
243 |
|
244 return ETrue; |
|
245 } |
|
246 |
|
247 TBool CPIMEventAdapterAccess::OpenToDoListL(const TDesC* /*aListName*/, |
|
248 MPIMToDoAdapterManager** /*aRetAdapterManager*/, |
|
249 MPIMToDoListAdapter** /*aRetListAdapter*/, MPIMLocalizationData** /*aRetLocalizationData*/) |
|
250 { |
|
251 JELOG2(EPim); |
|
252 // no ToDo lists |
|
253 return EFalse; |
|
254 } |
|
255 |
|
256 // End of File |