|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "csendaseditwatcher.h" |
|
17 |
|
18 #include <msvids.h> |
|
19 #include <mtclbase.h> |
|
20 #include <csendaseditutils.h> |
|
21 |
|
22 #include "msendaseditobserver.h" |
|
23 #include "tsendasserverpanic.h" |
|
24 |
|
25 CSendAsEditWatcher* CSendAsEditWatcher::NewL(MSendAsEditObserver& aObserver, TUid aUid) |
|
26 { |
|
27 CSendAsEditWatcher* self = new (ELeave) CSendAsEditWatcher(aObserver); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(aUid); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CSendAsEditWatcher::~CSendAsEditWatcher() |
|
35 { |
|
36 // do not notify observer during deletion. |
|
37 iObserver = NULL; |
|
38 Cancel(); |
|
39 |
|
40 delete iUtils; |
|
41 } |
|
42 |
|
43 CSendAsEditWatcher::CSendAsEditWatcher(MSendAsEditObserver& aObserver) |
|
44 : CActive(CActive::EPriorityStandard), iObserver(&aObserver) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 void CSendAsEditWatcher::ConstructL(TUid aUid) |
|
50 { |
|
51 // Create the edit utils (loads Ecom plugin specified by aUId) |
|
52 iUtils = CSendAsEditUtils::NewL(aUid); |
|
53 } |
|
54 |
|
55 void CSendAsEditWatcher::LaunchEditorL(TMsvId aEntryId) |
|
56 { |
|
57 __ASSERT_ALWAYS( iState == EEditWatcherIdle, User::Invariant() ); |
|
58 |
|
59 // launch the editor |
|
60 iUtils->LaunchEditorL(aEntryId, iStatus); |
|
61 SetActive(); |
|
62 |
|
63 iState = EEditWatcherEditing; |
|
64 } |
|
65 |
|
66 void CSendAsEditWatcher::Complete(TInt aError) |
|
67 { |
|
68 iState = EEditWatcherDone; // This must be set before notifying observer |
|
69 if( iObserver != NULL ) |
|
70 { |
|
71 // notify observer that the editor thread has closed. |
|
72 iObserver->EditComplete(aError); |
|
73 } |
|
74 } |
|
75 |
|
76 /* |
|
77 * Methods from CActive |
|
78 */ |
|
79 |
|
80 void CSendAsEditWatcher::RunL() |
|
81 { |
|
82 User::LeaveIfError(iStatus.Int()); |
|
83 |
|
84 switch( iState ) |
|
85 { |
|
86 case EEditWatcherEditing: |
|
87 { |
|
88 Complete(KErrNone); |
|
89 } break; |
|
90 case EEditWatcherIdle: |
|
91 case EEditWatcherDone: |
|
92 default: |
|
93 User::Invariant(); |
|
94 } |
|
95 } |
|
96 |
|
97 void CSendAsEditWatcher::DoCancel() |
|
98 { |
|
99 switch( iState ) |
|
100 { |
|
101 case EEditWatcherEditing: |
|
102 { |
|
103 iUtils->Cancel(); |
|
104 } |
|
105 case EEditWatcherIdle: |
|
106 case EEditWatcherDone: |
|
107 default: |
|
108 // do nothing... |
|
109 break; |
|
110 } |
|
111 Complete(KErrCancel); |
|
112 } |
|
113 |
|
114 TInt CSendAsEditWatcher::RunError(TInt aError) |
|
115 { |
|
116 Complete(aError); |
|
117 return KErrNone; |
|
118 } |