|
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: |
|
15 * Copies/Moves message store from source drive to target drive |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <eikenv.h> |
|
24 #include "MceSettingsMovemsgs.h" |
|
25 #include "MceSettingsUtils.h" |
|
26 |
|
27 #include <systemwarninglevels.hrh> |
|
28 |
|
29 #include <msvapi.h> |
|
30 #include <e32cmn.h> |
|
31 #include <msvipc.h> |
|
32 |
|
33 #include <StringLoader.h> |
|
34 #include <MceSettings.rsg> |
|
35 #include <aknnotewrappers.h> |
|
36 |
|
37 // CONSTANTS |
|
38 |
|
39 #ifdef _DEBUG |
|
40 _LIT( KPanicText, "MceSettings.dll" ); |
|
41 enum TMcesettingsPanic |
|
42 { |
|
43 EMceSingleOpWatcherAlreadyActive = 1, |
|
44 EMceSingleOpWatcherOperationAlreadySet, |
|
45 EMceSingleOpWatcherOperationNull |
|
46 }; |
|
47 #endif |
|
48 |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // ---------------------------------------------------- |
|
53 // CMceMessageTransHandler::Constructor |
|
54 // |
|
55 // |
|
56 // ---------------------------------------------------- |
|
57 CMceMessageTransHandler::CMceMessageTransHandler( |
|
58 MMceMsgTransHandlerObserver& aOwner, CMsvSession* aSession, TInt aTargetDrive, |
|
59 TInt aSourceDrive, TBool aDeleteCopiedStore ) |
|
60 : CActive( KMsgTransHndlrPriority ), iOwner( aOwner ), iSession( aSession ), |
|
61 iTargetDrive(aTargetDrive ), iSourceDrive( aSourceDrive ), |
|
62 iDeleteCopiedStore( aDeleteCopiedStore ), |
|
63 iState( EStateCopying ) |
|
64 { |
|
65 __DECLARE_NAME(_S("CMceMessageTransHandler") ); |
|
66 CActiveScheduler::Add( this ); |
|
67 } |
|
68 |
|
69 |
|
70 // ---------------------------------------------------- |
|
71 // CMceMessageTransHandler::Constructor |
|
72 // |
|
73 // |
|
74 // ---------------------------------------------------- |
|
75 CMceMessageTransHandler *CMceMessageTransHandler::NewL( |
|
76 MMceMsgTransHandlerObserver& aOwner, CMsvSession* aSession, |
|
77 TInt aTargetDrive, TInt aSourceDrive, TBool aDeleteCopiedStore ) |
|
78 { |
|
79 CMceMessageTransHandler* self=new ( ELeave ) CMceMessageTransHandler( |
|
80 aOwner,aSession,aTargetDrive,aSourceDrive,aDeleteCopiedStore); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); // should be consts in next release |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------- |
|
88 // CMceMessageTransHandler::ConstructL |
|
89 // Creates delete thread and transfer thread |
|
90 // |
|
91 // ---------------------------------------------------- |
|
92 void CMceMessageTransHandler::ConstructL() |
|
93 { |
|
94 /* Nothing */; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------- |
|
98 // CMceMessageTransHandler::Destructor |
|
99 // |
|
100 // |
|
101 // ---------------------------------------------------- |
|
102 CMceMessageTransHandler::~CMceMessageTransHandler() |
|
103 { |
|
104 Cancel(); |
|
105 delete iOperation; |
|
106 iOperation = NULL; |
|
107 } |
|
108 |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CMceMessageTransHandler::SetOperation |
|
112 // --- Setter --- |
|
113 // Must only be called once during the lifetime of a CMsvSingleOpWatcher object. |
|
114 // --------------------------------------------------------- |
|
115 void CMceMessageTransHandler::SetOperation( CMsvOperation* aOperation ) |
|
116 { |
|
117 __ASSERT_DEBUG( !IsActive(), User::Panic( KPanicText, EMceSingleOpWatcherAlreadyActive ) ); |
|
118 __ASSERT_DEBUG( !iOperation, User::Panic( KPanicText, EMceSingleOpWatcherOperationAlreadySet ) ); |
|
119 __ASSERT_DEBUG( aOperation, User::Panic( KPanicText, EMceSingleOpWatcherOperationNull ) ); |
|
120 |
|
121 // Delete the old operation |
|
122 delete iOperation; |
|
123 iOperation = NULL; |
|
124 |
|
125 // Take ownership of operation and set our active status so we're handled |
|
126 // by the active scheduler. |
|
127 iOperation = aOperation; |
|
128 SetActive(); |
|
129 } |
|
130 |
|
131 |
|
132 // --------------------------------------------------------- |
|
133 // CMsvSingleOpWatcher::Operation |
|
134 // --- Accessor --- |
|
135 // --------------------------------------------------------- |
|
136 // |
|
137 CMsvOperation& CMceMessageTransHandler::Operation() const |
|
138 { |
|
139 __ASSERT_DEBUG( iOperation, User::Panic( KPanicText, EMceSingleOpWatcherOperationNull ) ); |
|
140 return *iOperation; |
|
141 } |
|
142 |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CMceMessageTransHandler::DoCancel |
|
146 // --- From CActive --- |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CMceMessageTransHandler::DoCancel() |
|
150 { |
|
151 // Pass on cancel |
|
152 iOperation->Cancel(); |
|
153 } |
|
154 |
|
155 |
|
156 // ---------------------------------------------------- |
|
157 // CMceMessageTransHandler::RunL |
|
158 // Calls TransferCompleteL and |
|
159 // sets message store drive on the message server |
|
160 // ---------------------------------------------------- |
|
161 void CMceMessageTransHandler::RunL() |
|
162 { |
|
163 TInt err = iStatus.Int(); |
|
164 if (err == KErrNone) |
|
165 { |
|
166 err = ProgressErrorL(); |
|
167 } |
|
168 |
|
169 if ( err != KErrNone ) |
|
170 { |
|
171 // Copy operation did not succeed |
|
172 HBufC* text = StringLoader::LoadLC( R_MCE_SETTINGS_CANNOT_MOVE_STORE, |
|
173 CCoeEnv::Static() ); |
|
174 CAknErrorNote* note = new ( ELeave ) CAknErrorNote(); |
|
175 note->ExecuteLD( *text ); |
|
176 CleanupStack::PopAndDestroy( text ); |
|
177 } |
|
178 |
|
179 switch ( iState ) |
|
180 { |
|
181 case EStateCopying: |
|
182 // Inform client of watcher that the operation has completed |
|
183 iOwner.CopyCompleteL( err ); |
|
184 if ( err == KErrNone && iDeleteCopiedStore ) |
|
185 { |
|
186 // Only delete if there is no error copying |
|
187 delete iOperation; |
|
188 iOperation = NULL; |
|
189 // Delete the old store |
|
190 iOperation = iSession->DeleteStoreL( iSourceDrive, iStatus ); |
|
191 iState = EStateDeleting; |
|
192 SetActive(); |
|
193 } |
|
194 else |
|
195 iOwner.TransferCompleteL( err ); |
|
196 break; |
|
197 case EStateDeleting: |
|
198 // Check whether operation worked OK |
|
199 iOwner.TransferCompleteL( err ); |
|
200 break; |
|
201 default: |
|
202 break; |
|
203 } |
|
204 } |
|
205 |
|
206 |
|
207 // ---------------------------------------------------- |
|
208 // CMceMessageTransHandler::Progress |
|
209 // return % copied so far |
|
210 // |
|
211 // ---------------------------------------------------- |
|
212 TInt CMceMessageTransHandler::ProgressL() const |
|
213 { |
|
214 // Let's say everything up to the actual copy is the first 1%, |
|
215 // the copying is the next 98% and everything else the last 1%. |
|
216 const TInt KPreCopyPercentage = 1; |
|
217 const TInt KPostCopyPercentage = 1; |
|
218 const TInt KHundredPercentage = 100; |
|
219 const TInt KCopyPercentage = KHundredPercentage - KPreCopyPercentage - KPostCopyPercentage; |
|
220 |
|
221 if ( iState == EStateCopying ) |
|
222 { |
|
223 // Get the progress |
|
224 TMsvCopyProgress copyProgress; |
|
225 TPckgC<TMsvCopyProgress> progressPackage( copyProgress ); |
|
226 progressPackage.Set( iOperation->ProgressL() ); |
|
227 copyProgress = progressPackage(); |
|
228 if ( copyProgress.iError == KErrNone ) |
|
229 { |
|
230 if ( copyProgress.iState == TMsvCopyProgress::ENotYetStarted ) |
|
231 { |
|
232 return 0; // Nothing done yet |
|
233 } |
|
234 else if ( copyProgress.iState < TMsvCopyProgress::ECopyStore ) |
|
235 { |
|
236 return KPreCopyPercentage; // Started, but not yet copying |
|
237 } |
|
238 else if ( copyProgress.iState == TMsvCopyProgress::ECopyStore ) |
|
239 { |
|
240 // Copying, so return percentage of copy done + pre-copy percentage |
|
241 return ( ( ( copyProgress.iCurrent + 1 ) * KCopyPercentage ) |
|
242 / copyProgress.iTotal ) + KPreCopyPercentage; |
|
243 } |
|
244 else if ( copyProgress.iState == TMsvCopyProgress::ECompleted && !iDeleteCopiedStore ) |
|
245 { |
|
246 // Finished copying and no delete to do - All done! |
|
247 return KHundredPercentage; |
|
248 } |
|
249 else |
|
250 { |
|
251 // Copy is done but there's still more to do |
|
252 return KHundredPercentage - KPostCopyPercentage; |
|
253 } |
|
254 } |
|
255 else |
|
256 { |
|
257 return 0; // Error |
|
258 } |
|
259 } |
|
260 else // EStateDeleting |
|
261 { |
|
262 TMsvDeleteProgress deleteProgress; |
|
263 TPckgC<TMsvDeleteProgress> progressPackage( deleteProgress ); |
|
264 progressPackage.Set( iOperation->ProgressL() ); |
|
265 deleteProgress = progressPackage(); |
|
266 if ( deleteProgress.iError != KErrNone ) |
|
267 { |
|
268 if ( deleteProgress.iState == TMsvDeleteProgress::ECompleted ) |
|
269 { |
|
270 // Finsihed copying and deleting - All done! |
|
271 return KHundredPercentage; |
|
272 } |
|
273 else |
|
274 { |
|
275 // Still deleting |
|
276 return KHundredPercentage - KPostCopyPercentage; |
|
277 } |
|
278 } |
|
279 else |
|
280 { |
|
281 return 0; // Error |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------- |
|
287 // TInt CMceMessageTransHandler::ProgressErrorL() const |
|
288 // |
|
289 // ---------------------------------------------------- |
|
290 TInt CMceMessageTransHandler::ProgressErrorL() const |
|
291 { |
|
292 if ( iState == EStateCopying ) |
|
293 { |
|
294 TMsvCopyProgress copyProgress; |
|
295 TPckgC<TMsvCopyProgress> copyProgressPckg( copyProgress ); |
|
296 copyProgressPckg.Set( iOperation->ProgressL() ); |
|
297 return copyProgressPckg().iError; |
|
298 } |
|
299 else // EStateDeleting |
|
300 { |
|
301 TMsvDeleteProgress deleteProgress; |
|
302 TPckgC<TMsvDeleteProgress> deleteProgressPckg( deleteProgress ); |
|
303 deleteProgressPckg.Set( iOperation->ProgressL() ); |
|
304 return deleteProgressPckg().iError; |
|
305 } |
|
306 } |
|
307 |
|
308 |
|
309 // ---------------------------------------------------- |
|
310 // Called by the framework if RunL leaves |
|
311 // |
|
312 // ---------------------------------------------------- |
|
313 TInt CMceMessageTransHandler::RunError( TInt ) |
|
314 { |
|
315 return KErrNone; |
|
316 } |
|
317 |
|
318 // End of file |