|
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: MsgEditorModel implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ========== INCLUDE FILES ================================ |
|
21 |
|
22 #include <mtuireg.h> // MTM UI registery |
|
23 #include <mtmuibas.h> // MTM UI base |
|
24 #include <mtudreg.h> // MTM UI data registry |
|
25 #include <mtudcbas.h> // MTM UI data base |
|
26 #include <msvids.h> // NullEntryId |
|
27 |
|
28 #include "MsgEditorCommon.h" |
|
29 #include "MsgEditorModel.h" // Module Header |
|
30 #include "MsgEditorModelPanic.h" // panic codes for model |
|
31 #include "MsgEditorModelObserver.h" // MMsgEditorModelObserver |
|
32 |
|
33 #include "MsgEditorLogging.h" |
|
34 |
|
35 |
|
36 //#define ASYNC_CONST |
|
37 |
|
38 |
|
39 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
40 |
|
41 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
42 |
|
43 // ========== CONSTANTS ==================================== |
|
44 |
|
45 const TInt KThingsToWaitBeforeLaunch = 2; |
|
46 |
|
47 // ========== MACROS ======================================= |
|
48 |
|
49 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
50 |
|
51 // ========== MODULE DATA STRUCTURES ======================= |
|
52 |
|
53 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
54 |
|
55 // ========== LOCAL FUNCTIONS ============================== |
|
56 |
|
57 // ========== MEMBER FUNCTIONS ============================= |
|
58 |
|
59 // --------------------------------------------------------- |
|
60 // CMsgEditorModel::CMsgEditorModel |
|
61 // |
|
62 // Constructor. |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 CMsgEditorModel::CMsgEditorModel() : iLaunchWait(KThingsToWaitBeforeLaunch) |
|
66 { |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CMsgEditorModel::ConstructL |
|
71 // |
|
72 // 2nd phase constructor. |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 void CMsgEditorModel::ConstructL() |
|
76 { |
|
77 MEBLOGGER_ENTERFN("CMsgEditorModel::ConstructL"); |
|
78 |
|
79 #ifdef ASYNC_CONST |
|
80 |
|
81 MEBLOGGER_WRITE("OpenAsyncL"); |
|
82 MEBLOGGER_WRITE_TIMESTAMP(""); |
|
83 |
|
84 iSession = CMsvSession::OpenAsyncL(*this); |
|
85 |
|
86 #else |
|
87 |
|
88 MEBLOGGER_WRITE("OpenSyncL"); |
|
89 MEBLOGGER_WRITE_TIMESTAMP(""); |
|
90 |
|
91 TRAPD(err, iSession = CMsvSession::OpenSyncL(*this)); |
|
92 |
|
93 if (err != KErrNone) |
|
94 { |
|
95 iMediaAvailable = EFalse; |
|
96 if (iModelObserver) |
|
97 { |
|
98 // exits. |
|
99 iModelObserver->HandleServerFailedToStartL(); |
|
100 } |
|
101 else |
|
102 { |
|
103 User::Leave(err); |
|
104 } |
|
105 } |
|
106 |
|
107 __ASSERT_DEBUG(iSession, Panic(ENoSession)); |
|
108 |
|
109 iMediaAvailable = ETrue; |
|
110 |
|
111 CompleteConstructL(); |
|
112 |
|
113 #endif |
|
114 |
|
115 MEBLOGGER_LEAVEFN("CMsgEditorModel::ConstructL"); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // CMsgEditorModel::Wait |
|
120 // |
|
121 // Starts active scheduler to complete construction, if necessary. |
|
122 // --------------------------------------------------------- |
|
123 // |
|
124 void CMsgEditorModel::Wait() |
|
125 { |
|
126 #ifdef ASYNC_CONST |
|
127 |
|
128 MEBLOGGER_ENTERFN("CMsgEditorModel::Wait"); |
|
129 |
|
130 if (!iMediaAvailable) |
|
131 { |
|
132 iWait = ETrue; |
|
133 CActiveScheduler::Start(); |
|
134 } |
|
135 iWait = EFalse; |
|
136 |
|
137 MEBLOGGER_LEAVEFN("CMsgEditorModel::Wait"); |
|
138 |
|
139 #endif |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CMsgEditorModel::CompleteConstructL |
|
144 // |
|
145 // Creates client MTM registry and MTM UI registry when session is ready |
|
146 // for use. This completes model construction and is called after 'server |
|
147 // ready' event is received after async opening of CMsvSession. |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 void CMsgEditorModel::CompleteConstructL() |
|
151 { |
|
152 MEBLOGGER_ENTERFN("CMsgEditorModel::CompleteConstructL"); |
|
153 MEBLOGGER_WRITE_TIMESTAMP(""); |
|
154 |
|
155 __ASSERT_DEBUG(iMtmUiReg == NULL, Panic(ENullPointer)); |
|
156 |
|
157 iMtmReg = CClientMtmRegistry::NewL(*iSession); |
|
158 //delay the construction of iMtmUiReg and iMtmUiDataReg until needed |
|
159 |
|
160 __ASSERT_DEBUG(iMtmReg, Panic(ENullPointer)); |
|
161 |
|
162 |
|
163 MEBLOGGER_LEAVEFN("CMsgEditorModel::CompleteConstructL"); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------- |
|
167 // CMsgEditorModel::~CMsgEditorModel |
|
168 // |
|
169 // Destructor. |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 CMsgEditorModel::~CMsgEditorModel() |
|
173 { |
|
174 // note that iMtmReg can be deleted only after iMtm is deleted first |
|
175 delete iMtmUiData; |
|
176 delete iMtmUiDataReg; |
|
177 |
|
178 delete iMtmUi; |
|
179 delete iMtmUiReg; |
|
180 |
|
181 delete iMtm; |
|
182 delete iMtmReg; |
|
183 |
|
184 delete iSession; |
|
185 iModelObserver = NULL; // not owned |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CMsgEditorModel::SetEntryL |
|
190 // |
|
191 // Set up current message entry, creates a real connection between current |
|
192 // editor/viewer session and an message entryy to be displayed or edited. |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 void CMsgEditorModel::SetEntryL(TMsvId aEntryId) |
|
196 { |
|
197 MEBLOGGER_ENTERFN( "CMsgEditorModel::SetEntryL" ); |
|
198 MEBLOGGER_WRITE_TIMESTAMP(""); |
|
199 |
|
200 TMsvId service; |
|
201 TMsvEntry entry; |
|
202 User::LeaveIfError( Session().GetEntry( aEntryId, service, entry ) ); |
|
203 |
|
204 if ( iMtm == NULL || iMtm->Type() != entry.iMtm ) |
|
205 { |
|
206 delete iMtm; |
|
207 delete iMtmUi; |
|
208 delete iMtmUiData; |
|
209 |
|
210 iMtm = NULL; |
|
211 iMtmUi = NULL; |
|
212 iMtmUiData = NULL; |
|
213 |
|
214 iMtm = iMtmReg->NewMtmL( entry.iMtm ); |
|
215 // delay the construction of iMtmUi and iMtmUiData until needed |
|
216 } |
|
217 |
|
218 if ( !iMtm->HasContext() || iMtm->Entry().EntryId() != aEntryId ) |
|
219 { |
|
220 iMtm->SwitchCurrentEntryL( aEntryId ); |
|
221 } |
|
222 |
|
223 MEBLOGGER_LEAVEFN( "CMsgEditorModel::SetEntryL" ); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------- |
|
227 // CMsgEditorModel::PrepareMtmL |
|
228 // |
|
229 // Loads client and ui mtm's according to given message type. |
|
230 // clientmtm context is set also (this prepares |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CMsgEditorModel::PrepareMtmL(const TUid aMtmType) |
|
234 { |
|
235 if (iMtm == NULL) |
|
236 { |
|
237 //delete iMtm; |
|
238 delete iMtmUi; |
|
239 delete iMtmUiData; |
|
240 |
|
241 //iMtm = NULL; |
|
242 iMtmUi = NULL; |
|
243 iMtmUiData = NULL; |
|
244 |
|
245 iMtm = iMtmReg->NewMtmL(aMtmType); |
|
246 //delay the construction of iMtmUi and iMtmUiData until needed |
|
247 |
|
248 // ClientMtm needs some context before CreateMessageL can be called. |
|
249 CMsvEntry* entry = Session().GetEntryL(KMsvRootIndexEntryId); |
|
250 |
|
251 CleanupStack::PushL(entry); |
|
252 |
|
253 // Note: Switch... makes copy of the given entry. |
|
254 // Don't use SetCurrentEntry, because it does ownership transfer |
|
255 // delete moves out of model. |
|
256 iMtm->SwitchCurrentEntryL(entry->EntryId()); |
|
257 |
|
258 CleanupStack::PopAndDestroy(); // entry |
|
259 } |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------- |
|
263 // CMsgEditorModel::MtmUiL |
|
264 // --------------------------------------------------------- |
|
265 // |
|
266 CBaseMtmUi& CMsgEditorModel::MtmUiL() |
|
267 { |
|
268 __ASSERT_DEBUG(iMtm, Panic(ENullPointer)); |
|
269 if ( !iMtmUiReg ) |
|
270 { |
|
271 iMtmUiReg = CMtmUiRegistry::NewL(*iSession); |
|
272 } |
|
273 if ( !iMtmUi ) |
|
274 { |
|
275 iMtmUi = iMtmUiReg->NewMtmUiL(*iMtm); |
|
276 } |
|
277 return *iMtmUi; |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------- |
|
281 // CMsgEditorModel::MtmUiDataL |
|
282 // --------------------------------------------------------- |
|
283 // |
|
284 CBaseMtmUiData& CMsgEditorModel::MtmUiDataL() |
|
285 { |
|
286 __ASSERT_DEBUG(iMtm, Panic(ENullPointer)); |
|
287 if ( !iMtmUiDataReg ) |
|
288 { |
|
289 iMtmUiDataReg = CMtmUiDataRegistry::NewL(*iSession); |
|
290 } |
|
291 if ( !iMtmUi )//incase MtmUi was not initialized |
|
292 { |
|
293 MtmUiL(); |
|
294 } |
|
295 if ( !iMtmUiData ) |
|
296 { |
|
297 iMtmUiData = iMtmUiDataReg->NewMtmUiDataLayerL(iMtmUi->Type()); |
|
298 } |
|
299 return *iMtmUiData; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------- |
|
303 // CMsgEditorModel::HandleSessionEventL |
|
304 // |
|
305 // Handles session event observer, and call event handling functions in observer. |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 void CMsgEditorModel::HandleSessionEventL( |
|
309 TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3) |
|
310 { |
|
311 MEBLOGGER_ENTERFN("CMsgEditorModel::HandleSessionEventL"); |
|
312 MEBLOGGER_WRITE_TIMESTAMP(""); |
|
313 |
|
314 switch (aEvent) |
|
315 { |
|
316 case EMsvEntriesCreated: |
|
317 MEBLOGGER_WRITE("EMsvEntriesCreated"); |
|
318 // no action |
|
319 break; |
|
320 |
|
321 case EMsvEntriesChanged: |
|
322 { |
|
323 MEBLOGGER_WRITE("EMsvEntriesChanged"); |
|
324 |
|
325 if (iMtm == NULL || !(iMtm->HasContext())) |
|
326 break; // no entry => ignore event |
|
327 |
|
328 // check if the current entry has been changed |
|
329 const CMsvEntrySelection* sel = static_cast<CMsvEntrySelection*>(aArg1); |
|
330 |
|
331 __ASSERT_DEBUG(sel, Panic(ENullPointer)); |
|
332 |
|
333 const TInt index = sel->Find(Entry().Id()); |
|
334 |
|
335 // if it has (and if there is model observer defined) ... |
|
336 if ((index != KErrNotFound) && iModelObserver) |
|
337 { |
|
338 iModelObserver->HandleEntryChangeL(); |
|
339 } |
|
340 } |
|
341 break; |
|
342 |
|
343 case EMsvEntriesDeleted: |
|
344 { |
|
345 MEBLOGGER_WRITE("EMsvEntriesDeleted"); |
|
346 |
|
347 if (iMtm == NULL || !(iMtm->HasContext())) |
|
348 break; // no entry => ignore event |
|
349 |
|
350 // check if the current entry has been deleted |
|
351 const CMsvEntrySelection* sel = static_cast<CMsvEntrySelection*>(aArg1); |
|
352 |
|
353 __ASSERT_DEBUG(sel, Panic(ENullPointer)); |
|
354 |
|
355 const TInt index = sel->Find(Entry().Id()); |
|
356 |
|
357 // notify the application, if necessary |
|
358 if ((index != KErrNotFound) && iModelObserver) |
|
359 { |
|
360 iModelObserver->HandleEntryDeletedL(); |
|
361 } |
|
362 } |
|
363 break; |
|
364 |
|
365 case EMsvEntriesMoved: |
|
366 { |
|
367 MEBLOGGER_WRITE("EMsvEntriesMoved"); |
|
368 |
|
369 if (iMtm == NULL || !(iMtm->HasContext())) |
|
370 break; // no entry => ignore event |
|
371 |
|
372 // check if the current entry has been moved |
|
373 const CMsvEntrySelection* sel = static_cast<CMsvEntrySelection*>(aArg1); |
|
374 const TMsvId newParent = reinterpret_cast<TMsvId>(aArg2); |
|
375 const TMsvId oldParent = reinterpret_cast<TMsvId>(aArg3); |
|
376 |
|
377 __ASSERT_DEBUG(sel, Panic(ENullPointer)); |
|
378 __ASSERT_DEBUG(newParent, Panic(ENullPointer)); |
|
379 __ASSERT_DEBUG(oldParent, Panic(ENullPointer)); |
|
380 |
|
381 const TInt index = sel->Find(Entry().Id()); |
|
382 |
|
383 // notify the application, if necessary |
|
384 if ((index != KErrNotFound) && iModelObserver) |
|
385 { |
|
386 iModelObserver->HandleEntryMovedL(oldParent, newParent); |
|
387 } |
|
388 } |
|
389 break; |
|
390 |
|
391 case EMsvMtmGroupInstalled: |
|
392 MEBLOGGER_WRITE("EMsvMtmGroupInstalled"); |
|
393 // no action |
|
394 break; |
|
395 |
|
396 case EMsvMtmGroupDeInstalled: |
|
397 { |
|
398 MEBLOGGER_WRITE("EMsvMtmGroupDeInstalled"); |
|
399 |
|
400 if (iMtm == NULL || !(iMtm->HasContext())) |
|
401 break; // no entry => ignore event |
|
402 |
|
403 const TUid mtmId = TUid::Uid(reinterpret_cast<TInt>(aArg2)); |
|
404 |
|
405 if (mtmId == Mtm().Type() && iModelObserver) |
|
406 { |
|
407 iModelObserver->HandleMtmGroupDeinstalledL(); |
|
408 } |
|
409 } |
|
410 break; |
|
411 |
|
412 case EMsvGeneralError: |
|
413 { |
|
414 MEBLOGGER_WRITE("EMsvGeneralError"); |
|
415 |
|
416 const TInt errorCode = reinterpret_cast<TInt>(aArg1); |
|
417 |
|
418 if (iModelObserver) |
|
419 { |
|
420 iModelObserver->HandleGeneralErrorL(errorCode); |
|
421 } |
|
422 } |
|
423 break; |
|
424 |
|
425 case EMsvCloseSession: |
|
426 MEBLOGGER_WRITE("EMsvCloseSession"); |
|
427 |
|
428 if (iModelObserver) |
|
429 { |
|
430 iModelObserver->HandleCloseSessionL(); |
|
431 } |
|
432 break; |
|
433 |
|
434 case EMsvServerReady: |
|
435 MEBLOGGER_WRITE("EMsvServerReady"); |
|
436 |
|
437 iMediaAvailable = ETrue; |
|
438 #ifdef ASYNC_CONST |
|
439 CompleteConstructL(); |
|
440 if (iWait) |
|
441 { |
|
442 CActiveScheduler::Stop(); |
|
443 } |
|
444 #endif |
|
445 break; |
|
446 |
|
447 case EMsvServerFailedToStart: |
|
448 MEBLOGGER_WRITE("EMsvServerFailedToStart"); |
|
449 |
|
450 iMediaAvailable = EFalse; |
|
451 if (iModelObserver) |
|
452 { |
|
453 iModelObserver->HandleServerFailedToStartL(); |
|
454 } |
|
455 break; |
|
456 |
|
457 case EMsvServerTerminated: |
|
458 MEBLOGGER_WRITE("EMsvServerTerminated"); |
|
459 |
|
460 iMediaAvailable = EFalse; |
|
461 if (iModelObserver) |
|
462 { |
|
463 iModelObserver->HandleServerTerminatedL(); |
|
464 } |
|
465 break; |
|
466 |
|
467 case EMsvMediaChanged: |
|
468 MEBLOGGER_WRITE("EMsvMediaChanged"); |
|
469 |
|
470 // media is available, although it may not be the same one any more |
|
471 iMediaAvailable = ETrue; |
|
472 if (iModelObserver) |
|
473 { |
|
474 iModelObserver->HandleMediaChangedL(); |
|
475 } |
|
476 break; |
|
477 |
|
478 case EMsvMediaUnavailable: |
|
479 MEBLOGGER_WRITE("EMsvMediaUnavailable"); |
|
480 |
|
481 iMediaAvailable = EFalse; |
|
482 if (iModelObserver) |
|
483 { |
|
484 iModelObserver->HandleMediaUnavailableL(); |
|
485 } |
|
486 break; |
|
487 |
|
488 case EMsvMediaAvailable: |
|
489 MEBLOGGER_WRITE("EMsvMediaAvailable"); |
|
490 |
|
491 iMediaAvailable = ETrue; |
|
492 if (iModelObserver) |
|
493 { |
|
494 iModelObserver->HandleMediaAvailableL(); |
|
495 } |
|
496 break; |
|
497 |
|
498 case EMsvMediaIncorrect: |
|
499 MEBLOGGER_WRITE("EMsvMediaIncorrect"); |
|
500 |
|
501 iMediaAvailable = EFalse; |
|
502 if (iModelObserver) |
|
503 { |
|
504 iModelObserver->HandleMediaIncorrectL(); |
|
505 } |
|
506 break; |
|
507 |
|
508 case EMsvCorruptedIndexRebuilding: |
|
509 MEBLOGGER_WRITE("EMsvCorruptedIndexRebuilding"); |
|
510 |
|
511 iMediaAvailable = EFalse; |
|
512 if (iModelObserver) |
|
513 { |
|
514 iModelObserver->HandleCorruptedIndexRebuildingL(); |
|
515 } |
|
516 break; |
|
517 |
|
518 case EMsvCorruptedIndexRebuilt: |
|
519 MEBLOGGER_WRITE("EMsvCorruptedIndexRebuilt"); |
|
520 |
|
521 // iMediaAvailable will be updated by EMsvServerReady event |
|
522 if (iModelObserver) |
|
523 { |
|
524 iModelObserver->HandleCorruptedIndexRebuiltL(); |
|
525 } |
|
526 break; |
|
527 |
|
528 default: |
|
529 __ASSERT_DEBUG(EFalse, Panic(EUnknownSessionEvent)); |
|
530 break; |
|
531 } |
|
532 |
|
533 MEBLOGGER_LEAVEFN("CMsgEditorModel::HandleSessionEventL"); |
|
534 } |
|
535 |
|
536 // ========== OTHER EXPORTED FUNCTIONS ===================== |
|
537 |
|
538 // End of File |