|
1 /* |
|
2 * Copyright (c) 2006 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: MPX asynchronour save helper API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "mpxsavehelper.h" |
|
22 |
|
23 #include <eikenv.h> |
|
24 #include <pathinfo.h> |
|
25 #include <sysutil.h> |
|
26 #include <mpxlog.h> |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CMPXSaveHelper::CMPXSaveHelper |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CMPXSaveHelper::CMPXSaveHelper( MMPXSaveHelperObserver* aObserver ) |
|
37 : CActive( EPriorityStandard ) |
|
38 { |
|
39 iObserver = aObserver; |
|
40 } |
|
41 |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CMPXSaveHelper::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CMPXSaveHelper::ConstructL(MFileManObserver* aFMObserver ) |
|
49 { |
|
50 iFileMan = CFileMan::NewL( CEikonEnv::Static()->FsSession(), aFMObserver ); |
|
51 |
|
52 // Add this active object to the scheduler. |
|
53 CActiveScheduler::Add( this ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CMPXSaveHelper::NewL |
|
58 // Two-phased constructor. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C CMPXSaveHelper* CMPXSaveHelper::NewL( MMPXSaveHelperObserver* aObserver, MFileManObserver* aFMObserver ) |
|
62 { |
|
63 CMPXSaveHelper* self = new( ELeave ) CMPXSaveHelper( aObserver ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL( aFMObserver ); |
|
66 CleanupStack::Pop(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMPXSaveHelper::~CMPXSaveHelper |
|
72 // Destructor |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CMPXSaveHelper::~CMPXSaveHelper() |
|
76 { |
|
77 delete iFileMan; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMPXSaveHelper::StartCopyOperationL |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C void CMPXSaveHelper::StartCopyOperationL( |
|
85 const TDesC& anOld, |
|
86 const TDesC& aNew, |
|
87 TBool aMove /*=EFalse*/ ) |
|
88 { |
|
89 if (!IsActive()) |
|
90 { |
|
91 if ( aMove ) |
|
92 { |
|
93 iFileMan->Move( anOld, aNew, CFileMan::EOverWrite, iStatus ); |
|
94 } |
|
95 else |
|
96 { |
|
97 iFileMan->Copy( anOld, aNew, CFileMan::EOverWrite, iStatus ); |
|
98 } |
|
99 SetActive(); |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CMPXSaveHelper::StartCopyOperationL |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C void CMPXSaveHelper::StartCopyOperationL( |
|
108 RFile& anOldFile, |
|
109 const TDesC& aNew, |
|
110 TBool aMove /*=EFalse*/, |
|
111 TBool aSync ) |
|
112 { |
|
113 if ( !aSync ) |
|
114 { |
|
115 if ( !IsActive()) |
|
116 { |
|
117 if ( aMove ) |
|
118 { |
|
119 TFileName filename; |
|
120 anOldFile.FullName( filename ); |
|
121 User::LeaveIfError( iFileMan->Move( filename, aNew, CFileMan::EOverWrite, iStatus )); |
|
122 } |
|
123 else |
|
124 { |
|
125 User::LeaveIfError( iFileMan->Copy( anOldFile, aNew, CFileMan::EOverWrite, iStatus )); |
|
126 } |
|
127 |
|
128 SetActive(); |
|
129 } |
|
130 } |
|
131 else |
|
132 { |
|
133 TInt err = iFileMan->Copy( anOldFile, aNew, CFileMan::EOverWrite); |
|
134 if ( !err && iObserver ) |
|
135 { |
|
136 iObserver->HandleSaveComplete( iStatus.Int() ); |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CMPXSaveHelper::RunL |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CMPXSaveHelper::RunL() |
|
146 { |
|
147 MPX_DEBUG1("CMPXSaveHelper::RunL(): entering"); |
|
148 if ( iObserver ) |
|
149 { |
|
150 iObserver->HandleSaveComplete( iStatus.Int() ); |
|
151 } |
|
152 MPX_DEBUG1("CMPXSaveHelper::RunL(): exiting"); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CMPXSaveHelper::DoCancel |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CMPXSaveHelper::DoCancel() |
|
160 { |
|
161 MPX_DEBUG1("CMPXSaveHelper::DoCancel(): entering"); |
|
162 |
|
163 if ( iObserver ) |
|
164 { |
|
165 iObserver->HandleSaveComplete( KErrCancel ); |
|
166 } |
|
167 |
|
168 MPX_DEBUG1("CMPXSaveHelper::DoCancel(): exiting"); |
|
169 } |
|
170 |
|
171 // End of File |