|
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: |
|
15 * Operation to delete mail messages locally i.e. just remove body and |
|
16 * attachments from the flash but leave header. So don't delete message |
|
17 * from mail server. After operation user is able to fetch message again |
|
18 |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <MTMStore.h> |
|
25 #include <msvstd.hrh> |
|
26 #include <mtmuibas.h> |
|
27 #include <msvuids.h> |
|
28 #include <imum.rsg> |
|
29 #include <coemain.h> |
|
30 #include <StringLoader.h> |
|
31 #include <eikenv.h> |
|
32 |
|
33 #include "ImumDeleteMessagesLocally.h" |
|
34 #include "EmailUtils.H" |
|
35 #include "ImumMtmLogging.h" |
|
36 |
|
37 // EXTERNAL DATA STRUCTURES |
|
38 // EXTERNAL FUNCTION PROTOTYPES |
|
39 // CONSTANTS |
|
40 // minimum disk space needed when deleting messages locally |
|
41 const TInt KImumDiskSpaceForDelete = (2*1024); |
|
42 |
|
43 // LOCAL CONSTANTS AND MACROS |
|
44 const TInt KImumEntriesDoneReplaceIndex = 0; |
|
45 const TInt KImumTotalEntriesReplaceIndex = 1; |
|
46 |
|
47 // MODULE DATA STRUCTURES |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CImumDeleteMessagesLocally::CImumDeleteMessagesLocally() |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CImumDeleteMessagesLocally::CImumDeleteMessagesLocally( |
|
56 CImumInternalApi& aMailboxApi, |
|
57 TRequestStatus& aObserverRequestStatus, |
|
58 TBool aDiskSpaceRequest ) |
|
59 : |
|
60 CImCacheManager(aMailboxApi.MsvSession(), aObserverRequestStatus), |
|
61 iDiskSpaceRequest( aDiskSpaceRequest ) |
|
62 { |
|
63 IMUM_CONTEXT( CImumDeleteMessagesLocally::CImumDeleteMessagesLocally, 0, KImumMtmLog ); |
|
64 IMUM_IN(); |
|
65 IMUM_OUT(); |
|
66 |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CImumDeleteMessagesLocally::ConstructL() |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 void CImumDeleteMessagesLocally::ConstructL( |
|
74 CMsvEntrySelection& aMessageSelection ) |
|
75 { |
|
76 IMUM_CONTEXT( CImumDeleteMessagesLocally::ConstructL, 0, KImumMtmLog ); |
|
77 IMUM_IN(); |
|
78 |
|
79 CImCacheManager::ConstructL(); |
|
80 iMessageSelection = aMessageSelection.CopyL(); |
|
81 if ( iDiskSpaceRequest ) |
|
82 { |
|
83 CEikonEnv* env = CEikonEnv::Static(); |
|
84 |
|
85 // Create the file session and get access to current drive |
|
86 iFileSession = env->FsSession(); |
|
87 iDriveNo = iMsvSession.CurrentDriveL(); |
|
88 |
|
89 // Try to reserve disk space and leave if it fails |
|
90 User::LeaveIfError( MsvEmailMtmUiUtils::AcquireDiskSpace( |
|
91 iFileSession, |
|
92 iDriveNo, |
|
93 KImumDiskSpaceForDelete ) ); |
|
94 } |
|
95 |
|
96 TInt resourceId = (iMessageSelection->Count()>1) ? |
|
97 R_IMAP4_PROGRESS_DELETING_LOCALLY_MANY : R_IMAP4_PROGRESS_DELETING_LOCALLY; |
|
98 |
|
99 iProgressText = StringLoader::LoadL( resourceId ); |
|
100 |
|
101 StartL( *iMessageSelection, iObserverRequestStatus ); |
|
102 IMUM_OUT(); |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------------------------------- |
|
106 // CImumDeleteMessagesLocally::NewL() |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 CImumDeleteMessagesLocally* CImumDeleteMessagesLocally::NewL( |
|
110 CMsvEntrySelection& aMessageSelection, |
|
111 CImumInternalApi& aMailboxApi, |
|
112 TRequestStatus& aObserverRequestStatus, |
|
113 TBool aDiskSpaceRequest /* = ETrue */) |
|
114 { |
|
115 IMUM_STATIC_CONTEXT( CImumDeleteMessagesLocally::NewL, 0, mtm, KImumMtmLog ); |
|
116 IMUM_IN(); |
|
117 |
|
118 CImumDeleteMessagesLocally* self = |
|
119 new ( ELeave ) CImumDeleteMessagesLocally( |
|
120 aMailboxApi, |
|
121 aObserverRequestStatus, |
|
122 aDiskSpaceRequest ); |
|
123 |
|
124 CleanupStack::PushL(self); |
|
125 self->ConstructL( aMessageSelection ); |
|
126 CleanupStack::Pop(); // self |
|
127 IMUM_OUT(); |
|
128 |
|
129 return self; |
|
130 }; |
|
131 |
|
132 |
|
133 // Destructor |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CImumDeleteMessagesLocally::~CImumDeleteMessagesLocally() |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 CImumDeleteMessagesLocally::~CImumDeleteMessagesLocally() |
|
139 { |
|
140 IMUM_CONTEXT( CImumDeleteMessagesLocally::~CImumDeleteMessagesLocally, 0, KImumMtmLog ); |
|
141 IMUM_IN(); |
|
142 |
|
143 delete iProgressText; |
|
144 delete iMessageSelection; |
|
145 |
|
146 if ( iDiskSpaceRequest ) |
|
147 { |
|
148 iFileSession.ReleaseReserveAccess( iDriveNo ); |
|
149 } |
|
150 IMUM_OUT(); |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CImumDeleteMessagesLocally::Filter() |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CImumDeleteMessagesLocally::Filter() const |
|
158 { |
|
159 IMUM_CONTEXT( CImumDeleteMessagesLocally::Filter, 0, KImumMtmLog ); |
|
160 IMUM_IN(); |
|
161 |
|
162 if ( iMessageSelection->Find( iCurrentEntry->Entry().Id() ) |
|
163 > KErrNotFound ) |
|
164 { |
|
165 IMUM_OUT(); |
|
166 return ETrue; |
|
167 } |
|
168 IMUM_OUT(); |
|
169 return EFalse; |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // CImumDeleteMessagesLocally::DecodeProgress() |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 TInt CImumDeleteMessagesLocally::DecodeProgress(const TDesC8& aProgress, |
|
177 TBuf<CBaseMtmUi::EProgressStringMaxLen>& aReturnString, |
|
178 TInt& aTotalEntryCount, TInt& aEntriesDone, |
|
179 TInt& aCurrentEntrySize, TInt& aCurrentBytesTrans, TBool /*aInternal*/) |
|
180 { |
|
181 IMUM_CONTEXT( CImumDeleteMessagesLocally::DecodeProgress, 0, KImumMtmLog ); |
|
182 IMUM_IN(); |
|
183 |
|
184 if( !aProgress.Length()) |
|
185 { |
|
186 return KErrNone; |
|
187 } |
|
188 |
|
189 TPckgBuf<TImCacheManagerProgress> paramPack; |
|
190 paramPack.Copy(aProgress); |
|
191 const TImCacheManagerProgress& progress=paramPack(); |
|
192 |
|
193 aEntriesDone=progress.iMessagesProcessed; |
|
194 aTotalEntryCount=iMessageSelection->Count(); |
|
195 aCurrentEntrySize=progress.iTotalMessages; |
|
196 aCurrentBytesTrans=progress.iMessagesProcessed; |
|
197 |
|
198 aReturnString.Copy( *iProgressText ); |
|
199 if ( iMessageSelection->Count()>1 ) |
|
200 { |
|
201 TBuf<CBaseMtmUi::EProgressStringMaxLen> tempBuffer; |
|
202 StringLoader::Format( |
|
203 tempBuffer, |
|
204 aReturnString, |
|
205 KImumEntriesDoneReplaceIndex, |
|
206 aEntriesDone ); |
|
207 StringLoader::Format( |
|
208 aReturnString, |
|
209 tempBuffer, |
|
210 KImumTotalEntriesReplaceIndex, |
|
211 aTotalEntryCount ); |
|
212 } |
|
213 IMUM_OUT(); |
|
214 return KErrNone; |
|
215 } |
|
216 |
|
217 |
|
218 // End of File |
|
219 |
|
220 |