|
1 /* |
|
2 * Copyright (c) 2002-2007 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: MMsgMailOpObserver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CMSGMAILBASEOP_H |
|
21 #define CMSGMAILBASEOP_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <AknWaitDialog.h> |
|
26 |
|
27 // DATA TYPES |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CMsgMailEditorDocument; |
|
31 class CMsgMailBaseOp; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * Observer interface for operations. |
|
37 */ |
|
38 NONSHARABLE_CLASS( MMsgMailOpObserver ) |
|
39 { |
|
40 public: |
|
41 /** |
|
42 * Method for observing operation completion. Intentionally |
|
43 * non-leaving since any problem in observer should not affect the |
|
44 * operation. |
|
45 * @param aOp operation instance reference |
|
46 * @param aResult result code |
|
47 */ |
|
48 virtual void HandleOpCompleted( const CMsgMailBaseOp& aOp, |
|
49 TInt aResult ) = 0; |
|
50 }; |
|
51 |
|
52 /** |
|
53 * Base class for state machine -based long-running operations. |
|
54 * Operations are divided to steps by the implementing subclass, and |
|
55 * these steps are performed as individual CActive requests. The requests |
|
56 * may either be truly asynchronous, or self-completing synchronous steps. |
|
57 * |
|
58 * Due to existing tight coupling with MsgMailEditorAppUi and UI |
|
59 * in general the subclass may need to delegate some tasks to the UI via |
|
60 * MMsgMailOpDelegate interface. |
|
61 * |
|
62 * Two alternative observation mechanisms for operations are available: |
|
63 * either via MMsgMailOpObserver interface or using TRequestStatus completion. |
|
64 * |
|
65 * The base class does not cancel the operation in it's destructor |
|
66 * since subclass destructors are called before base class destructor |
|
67 * and that would lead to access violations. Subclasses must call Cancel() |
|
68 * by themselves in their destructors if they want to cancel in destruction. |
|
69 */ |
|
70 NONSHARABLE_CLASS( CMsgMailBaseOp ) : public CActive, |
|
71 public MProgressDialogCallback |
|
72 { |
|
73 protected: |
|
74 |
|
75 // subclasses add their own states |
|
76 enum TState |
|
77 { |
|
78 EIdleState, // initial and final state of operation |
|
79 EFirstFreeState // a marker for subclasses, not a real state |
|
80 }; |
|
81 |
|
82 public: // Constructors and destructor |
|
83 |
|
84 /** |
|
85 * Destructor. |
|
86 */ |
|
87 ~CMsgMailBaseOp(); |
|
88 |
|
89 public: // API |
|
90 |
|
91 /** |
|
92 * Method for the class user to start the entire operation. Possibly |
|
93 * already ongoing operation is cancelled. |
|
94 * @param aObserver observer which is notified when operation completes |
|
95 */ |
|
96 void StartOp( MMsgMailOpObserver& aObserver ); |
|
97 |
|
98 /** |
|
99 * Method for the class user to start the entire operation. Possibly |
|
100 * already ongoing operation is cancelled. |
|
101 * @param aStatus request status, completed along with the operation |
|
102 */ |
|
103 void StartOp( TRequestStatus& aStatus ); |
|
104 |
|
105 protected: // From CActive |
|
106 |
|
107 // From CActive |
|
108 void DoCancel(); |
|
109 void RunL(); |
|
110 TInt RunError( TInt aError ); |
|
111 |
|
112 protected: // From MProgressDialogCallback |
|
113 /** |
|
114 * Callback method is called when a dialog is dismissed. |
|
115 * @param aButtonId Cancel button id. |
|
116 */ |
|
117 void DialogDismissedL( TInt aButtonId ); |
|
118 |
|
119 protected: // Implementation |
|
120 |
|
121 /** |
|
122 * Template method for implementing state switching logic. |
|
123 */ |
|
124 virtual void SetNextState() = 0; |
|
125 |
|
126 /** |
|
127 * Template method for handling action for latest state transition. |
|
128 */ |
|
129 virtual void HandleStateActionL() = 0; |
|
130 |
|
131 /** |
|
132 * Template method for handling operation cancellation. This is called |
|
133 * from DoCancel to allow subclass to cancel any outstanding request. |
|
134 */ |
|
135 virtual void HandleOperationCancel() = 0; |
|
136 |
|
137 /** |
|
138 * Optional template method for handling an error occurred during |
|
139 * current state action. This method is called from RunError(). |
|
140 * Return value determines whether the entire operation is continued |
|
141 * (ETrue returned) or stopped (EFalse returned). The base class |
|
142 * implementation always returns EFalse. |
|
143 * @param aError error code |
|
144 * @retval ETrue if error was handled and operation can continue |
|
145 */ |
|
146 virtual TBool HandleStateActionError( TInt aError ); |
|
147 |
|
148 /** |
|
149 * Helper method for completing non-asynchronous steps and |
|
150 * continuing with next iteration. If action is completed with an |
|
151 * error code, then RunError will get executed. |
|
152 * @param aError completion code, by default KErrNone |
|
153 */ |
|
154 void CompleteStateAction( TInt aError = KErrNone ); |
|
155 |
|
156 /** |
|
157 * Helper method for starting a wait note. |
|
158 * @param aTextResourceId wait note text |
|
159 * @param aDelayOff wait note delay on/off |
|
160 * @param aResourceId wait dialog resource |
|
161 */ |
|
162 void StartWaitNoteL( TInt aTextResourceId, |
|
163 TBool aDelayOff, |
|
164 TInt aResouceID ); |
|
165 |
|
166 /** |
|
167 * Helper method for stopping a wait note. If not called, then |
|
168 * wait note will be closed when operation is stopped. |
|
169 */ |
|
170 void StopWaitNote(); |
|
171 |
|
172 private: // Implementation |
|
173 |
|
174 /** |
|
175 * Resets state machine, closes and waits possibly open wait note. |
|
176 * Calls NotifyObservers if wait note is not visible, otherwise the |
|
177 * operation handling continues in DialogDismissedL. |
|
178 * @param aError error code |
|
179 */ |
|
180 void CompleteOperation( TInt aError ); |
|
181 |
|
182 /** |
|
183 * Notifies observer with the given error code |
|
184 * @param aError error code |
|
185 */ |
|
186 void NotifyObservers( TInt aError ); |
|
187 |
|
188 protected: |
|
189 |
|
190 /** |
|
191 * Constructor. |
|
192 * @param aDocument Editor's document reference |
|
193 */ |
|
194 CMsgMailBaseOp( CMsgMailEditorDocument& aDocument ); |
|
195 |
|
196 protected: // Data |
|
197 |
|
198 // Wait dialog, own |
|
199 CAknWaitDialog* iWaitDialog; |
|
200 |
|
201 // Editor's document, not own |
|
202 CMsgMailEditorDocument& iDocument; |
|
203 |
|
204 // Operation observer, not own |
|
205 MMsgMailOpObserver* iObserver; |
|
206 |
|
207 // Operation obeserver's request status, not own |
|
208 TRequestStatus* iExtRequestStatus; |
|
209 |
|
210 // Current state |
|
211 TInt iState; |
|
212 |
|
213 // Pending operation result (waiting wait dialog). |
|
214 TInt iWaitingError; |
|
215 }; |
|
216 |
|
217 #endif // CMSGMAILBASEOP_H |
|
218 |
|
219 // End of File |