25
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Freestyle Email application attachment download info mediator
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef FSEMAILDOWNLOADINFORMATIONMEDIATOR_H
|
|
19 |
#define FSEMAILDOWNLOADINFORMATIONMEDIATOR_H
|
|
20 |
|
|
21 |
// INCLUDES
|
|
22 |
#include <e32base.h>
|
|
23 |
//<cmail>
|
|
24 |
#include "mfsmailrequestobserver.h"
|
|
25 |
//</cmail>
|
|
26 |
#include <AknGlobalMsgQuery.h>
|
|
27 |
#include "FreestyleEmailUiConstants.h"
|
|
28 |
|
|
29 |
class CFSMailClient;
|
|
30 |
|
|
31 |
// CONSTANTS
|
|
32 |
|
|
33 |
class MFSEmailDownloadInformationObserver
|
|
34 |
{
|
|
35 |
/**
|
|
36 |
* RequestResposeL
|
|
37 |
* Download information callback
|
|
38 |
* @param aEvent event information
|
|
39 |
* @param aPart message part which the event belongs
|
|
40 |
*/
|
|
41 |
|
|
42 |
public:
|
|
43 |
virtual void RequestResponseL( const TFSProgress& aEvent, const TPartData& aPart ) = 0;
|
|
44 |
};
|
|
45 |
|
|
46 |
// CLASS DECLARATION
|
|
47 |
class CFSEmailDownloadInfoMediator : public CActive, public MFSMailRequestObserver
|
|
48 |
{
|
|
49 |
public:
|
|
50 |
/**
|
|
51 |
* Two-phased class constructor.
|
|
52 |
*/
|
|
53 |
static CFSEmailDownloadInfoMediator* NewL( CFSMailClient& aMailClient );
|
|
54 |
|
|
55 |
// destroys the instance
|
|
56 |
static void Destroy();
|
|
57 |
|
|
58 |
// from MFSMailRequestObserver
|
|
59 |
virtual void RequestResponseL( TFSProgress aEvent, TInt aRequestId );
|
|
60 |
|
|
61 |
/**
|
|
62 |
* AddObserver
|
|
63 |
* Adds observer to receive download information callbacks from one message
|
|
64 |
* @param aObserver observer, ownership is not transferred
|
|
65 |
* @param aMessageId message to observe
|
|
66 |
*/
|
|
67 |
void AddObserver( MFSEmailDownloadInformationObserver* aObserver, TFSMailMsgId aMessageId );
|
|
68 |
|
|
69 |
/**
|
|
70 |
* AddObserver
|
|
71 |
* Adds observer to receive download information callbacks from all messages
|
|
72 |
* @param aObserver observer, ownership is not transferred
|
|
73 |
*/
|
|
74 |
void AddObserver( MFSEmailDownloadInformationObserver* aObserver );
|
|
75 |
|
|
76 |
/**
|
|
77 |
* StopObserving
|
|
78 |
* Removes observer
|
|
79 |
* @param aObserver observer to be removed, ownership is not transferred
|
|
80 |
* @param aMessageId message which should not be observed anymore
|
|
81 |
*/
|
|
82 |
void StopObserving( MFSEmailDownloadInformationObserver* aObserver, TFSMailMsgId aMessageId );
|
|
83 |
|
|
84 |
/**
|
|
85 |
* StopObserving
|
|
86 |
* Removes observer
|
|
87 |
* @param aObserver observer to be removed, ownership is not transferred
|
|
88 |
*/
|
|
89 |
void StopObserving( MFSEmailDownloadInformationObserver* aObserver );
|
|
90 |
|
|
91 |
/**
|
|
92 |
* DownloadL
|
|
93 |
* Starts attachment download
|
|
94 |
* @param aPartData message part to download
|
|
95 |
* @param aCompleteNote show download compete note
|
|
96 |
*/
|
|
97 |
void DownloadL( TPartData aPart, TBool aCompleteNote=ETrue );
|
|
98 |
|
|
99 |
/**
|
|
100 |
* DownloadAndSaveL
|
|
101 |
* Starts attachment download and saves the file after download is complete
|
|
102 |
* @param aPart message part to download
|
|
103 |
* @param aSaveFileName file name to save
|
|
104 |
* @param aCompleteNote show download compete note
|
|
105 |
*/
|
|
106 |
void DownloadAndSaveL( TPartData aPart, const TDesC& aSaveFileName, TBool aCompleteNote = ETrue );
|
|
107 |
|
|
108 |
/**
|
|
109 |
* CancelDownloadL
|
|
110 |
* Cancels attachment download
|
|
111 |
* @param aMessagePartId message part id to cancel
|
|
112 |
*/
|
|
113 |
void CancelDownloadL( TFSMailMsgId aMessagePartId );
|
|
114 |
|
|
115 |
|
|
116 |
/**
|
|
117 |
* CancelAllDownloadsL
|
|
118 |
* Cancels all mailbox downloads
|
|
119 |
* @param aMailBoxId mailbox id of cancelled downloads
|
|
120 |
*/
|
|
121 |
void CancelAllDownloadsL( TFSMailMsgId aMailBoxId );
|
|
122 |
|
|
123 |
/**
|
|
124 |
* IsAnyAttachmentDownloads
|
|
125 |
* Checks if there has been at least one download since program has been started
|
|
126 |
* @return has there been a download status
|
|
127 |
*/
|
|
128 |
TBool IsAnyAttachmentDownloads();
|
|
129 |
|
|
130 |
/**
|
|
131 |
* IsAnyAttachmentDownloads
|
|
132 |
* Checks if there is at least one ongoing download for a message
|
|
133 |
* @param aMessageId message id
|
|
134 |
* @return current download status
|
|
135 |
*/
|
|
136 |
TBool IsAnyAttachmentDownloads( TFSMailMsgId aMessageId );
|
|
137 |
|
|
138 |
/**
|
|
139 |
* GetDownloadPercentage
|
|
140 |
* Checks if there is at least one ongoing download for a message
|
|
141 |
* @param aMessageId ID of the message for which downloads are checked
|
|
142 |
* @return Percentage (0...100) of downloaded content out of all content currently under downloading
|
|
143 |
* KErrNotFound if there are no ongoing downloads for the given message.
|
|
144 |
*/
|
|
145 |
TInt GetDownloadPercentageL( TFSMailMsgId aMessageId );
|
|
146 |
|
|
147 |
/**
|
|
148 |
* IsDownloadableL
|
|
149 |
* Checks if the message part is in "downloadable state" ( not downloaded and not downloading at the moment )
|
|
150 |
* @param aPart message information
|
|
151 |
* @return downloadable state
|
|
152 |
*/
|
|
153 |
TBool IsDownloadableL( TPartData aPart );
|
|
154 |
|
|
155 |
/**
|
|
156 |
* IsDownloading
|
|
157 |
* Checks if the message part is currently being downloaded
|
|
158 |
* @return download status
|
|
159 |
* @param aMessagePart message part
|
|
160 |
*/
|
|
161 |
TBool IsDownloading( TFSMailMsgId aMessagePart );
|
|
162 |
|
|
163 |
/**
|
|
164 |
* Check if attachments of a message have been fully downloaded and notify observers
|
|
165 |
* if they are. This is used to inform the observers about the completion of
|
|
166 |
* automatic attachment download which takes place with POP protocol.
|
|
167 |
* @param aMessageId The mailbox, folder, and message IDs identifying the message.
|
|
168 |
* Member aMessageId.messagePartId is ignored.
|
|
169 |
*/
|
|
170 |
void NotifyObserversIfAttachmentsDownloadedL( TPartData aMessageId );
|
|
171 |
|
|
172 |
public: // construction
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Destructor of CFSEmailDownloadInfoMediator class.
|
|
176 |
*/
|
|
177 |
|
|
178 |
CFSEmailDownloadInfoMediator( CFSMailClient& aMailClient );
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Second phase class constructor.
|
|
182 |
*/
|
|
183 |
void ConstructL();
|
|
184 |
|
|
185 |
public: // from CActive
|
|
186 |
/**
|
|
187 |
* @see CActive.
|
|
188 |
*/
|
|
189 |
void RunL();
|
|
190 |
|
|
191 |
/**
|
|
192 |
* @see CActive.
|
|
193 |
*/
|
|
194 |
void DoCancel();
|
|
195 |
|
|
196 |
/**
|
|
197 |
* @see CActive.
|
|
198 |
*/
|
|
199 |
TInt RunError( TInt aError );
|
|
200 |
|
|
201 |
/**
|
|
202 |
* Cancels querys.
|
|
203 |
*/
|
|
204 |
void Cancel();
|
|
205 |
|
|
206 |
private: // methods
|
|
207 |
|
|
208 |
struct TRequestObserver
|
|
209 |
{
|
|
210 |
MFSEmailDownloadInformationObserver* iObserver;
|
|
211 |
TFSMailMsgId iMessageId;
|
|
212 |
TBool iDeleted;
|
|
213 |
};
|
|
214 |
|
|
215 |
class TDownload
|
|
216 |
{
|
|
217 |
public: // members
|
|
218 |
TInt iRequestId;
|
|
219 |
TPartData iPartData;
|
|
220 |
TFileName iSaveFileName;
|
|
221 |
TBool iNotifyComplete;
|
|
222 |
TInt iCounter;
|
|
223 |
TInt iMaxCount;
|
|
224 |
|
|
225 |
public: // constructors
|
|
226 |
inline TDownload()
|
|
227 |
: iRequestId(0), iPartData(), iSaveFileName(), iNotifyComplete(EFalse), iCounter(0), iMaxCount(0) {}
|
|
228 |
inline TDownload( TInt aRequestId, TPartData aPartData, const TDesC& aFileName, TBool aNotifyComplete )
|
|
229 |
: iRequestId( aRequestId ), iPartData( aPartData ), iSaveFileName( aFileName ),
|
|
230 |
iNotifyComplete( aNotifyComplete ), iCounter( 0 ), iMaxCount( 0 ) {}
|
|
231 |
};
|
|
232 |
|
|
233 |
class TDownloadCount
|
|
234 |
{
|
|
235 |
public: // members
|
|
236 |
TFSMailMsgId iMessageId;
|
|
237 |
TInt iDownloadsStartedCount;
|
|
238 |
TInt iDownloadsCompletedCount;
|
|
239 |
TInt iSaveRequestedCount;
|
|
240 |
|
|
241 |
public: // constructors
|
|
242 |
inline TDownloadCount()
|
|
243 |
: iMessageId(), iDownloadsStartedCount(0), iDownloadsCompletedCount(0), iSaveRequestedCount(0) {}
|
|
244 |
inline TDownloadCount( TFSMailMsgId aMessageId )
|
|
245 |
: iMessageId( aMessageId ), iDownloadsStartedCount(0), iDownloadsCompletedCount(0), iSaveRequestedCount(0) {}
|
|
246 |
};
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Appends a new download to internal arrays iDownloadArray and iDonwloadCountArray.
|
|
250 |
* The function makes sure that there's no previous downloads with the same request ID.
|
|
251 |
*/
|
|
252 |
void AppendDownloadToInternalArraysL( const TDownload& aNewDownload );
|
|
253 |
|
|
254 |
/**
|
|
255 |
* Checks if download complete notification should be show for this message part
|
|
256 |
*/
|
|
257 |
TBool CompletionNotesInUseL() const;
|
|
258 |
|
|
259 |
/**
|
|
260 |
* Launches a global note about completed download(s).
|
|
261 |
* @param aPart A bundle of IDs identifying the message for which the note is shown.
|
|
262 |
* @param aCompletedCount How many attachments were succesfully downloaded.
|
|
263 |
*/
|
|
264 |
void LaunchDownloadCompleteNoteL( const TPartData& aPart, TInt aCompletedCount );
|
|
265 |
void OpenAttachmentL( const TPartData& aPart, const TInt aCompletedCount );
|
|
266 |
|
|
267 |
/**
|
|
268 |
* Notify all the registered observers about a download event.
|
|
269 |
*/
|
|
270 |
void NotifyObserversL( const TFSProgress& aEvent, const TPartData& aPart );
|
|
271 |
|
|
272 |
/**
|
|
273 |
* Notify all the registered observers for a particular message part about a download event.
|
|
274 |
*/
|
|
275 |
void NotifyPartObserversL( const TFSProgress& aEvent, const TPartData& aPart );
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Removes deleted observers from the observer array.
|
|
279 |
*/
|
|
280 |
void CleanUpObservers();
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Safely removes an entry from the observer array in case notifications
|
|
284 |
* are currently in process.
|
|
285 |
*/
|
|
286 |
void RemoveObserver( TInt aIdx );
|
|
287 |
|
|
288 |
/**
|
|
289 |
* Updates the entry in iDownloadCountArray according a progress event and gets a copy of
|
|
290 |
* its data. The original entry may be removed from the array as a result.
|
|
291 |
* @param aCountObject Input/output argument for the count array entry. The entries are matched by the iMessageId.
|
|
292 |
* @param aEvent The event which causes the entry to be updated.
|
|
293 |
*/
|
|
294 |
void GetAndUpdateDownloadCountL( TDownloadCount& aCountObject, const TFSProgress& aEvent );
|
|
295 |
|
|
296 |
/**
|
|
297 |
* Updates missing iMaxCount values to match the file sizes of the corresponding attachments.
|
|
298 |
* @param aMessageData Identifies the message for which the update is done. The member
|
|
299 |
* messagePartId is ignored.
|
|
300 |
*/
|
|
301 |
void UpdateAttachmentSizesL( const TPartData& aMessageData );
|
|
302 |
|
|
303 |
/**
|
|
304 |
* Identity relation which chekcs if two TDownloadCount objects have matchinng
|
|
305 |
* message ID.
|
|
306 |
*/
|
|
307 |
static TBool EqualMessageId( const TDownloadCount& aFirst, const TDownloadCount& aSecond );
|
|
308 |
|
|
309 |
/**
|
|
310 |
* Identity relation which chekcs if two TDownload objects have matchinng
|
|
311 |
* message part ID.
|
|
312 |
*/
|
|
313 |
static TBool EqualMessagePartId( const TDownload& aFirst, const TDownload& aSecond );
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Destructor of CFSEmailDownloadInfoMediator class.
|
|
317 |
*/
|
|
318 |
virtual ~CFSEmailDownloadInfoMediator();
|
|
319 |
|
|
320 |
private: // data
|
|
321 |
|
|
322 |
// mail client
|
|
323 |
CFSMailClient& iMailClient;
|
|
324 |
|
|
325 |
// download complete query
|
|
326 |
CAknGlobalMsgQuery* iGlobalMsgQuery;
|
|
327 |
|
|
328 |
// message view data or attachment data to launch from user query response
|
|
329 |
TPartData iPopupLaunchData;
|
|
330 |
|
|
331 |
// array of current downloads
|
|
332 |
RArray<TDownload> iDownloadArray;
|
|
333 |
|
|
334 |
// array of download counts of one message
|
|
335 |
RArray<TDownloadCount> iDownloadCountArray;
|
|
336 |
|
|
337 |
// array of download information observers (one message)
|
|
338 |
RArray<TRequestObserver> iObserverArray;
|
|
339 |
|
|
340 |
// array of download observers (all messages)
|
|
341 |
RPointerArray<MFSEmailDownloadInformationObserver> iAllObserverArray;
|
|
342 |
|
|
343 |
// has there been any downloads since program started
|
|
344 |
TBool iDownloadsStarted;
|
|
345 |
|
|
346 |
// counter indicating how many observer notification operations are
|
|
347 |
// currently in progress
|
|
348 |
TInt iNotificationsInProgress;
|
|
349 |
|
|
350 |
// have any observers been deleted during notification
|
|
351 |
TBool iObserverDeleted;
|
|
352 |
};
|
|
353 |
|
|
354 |
#endif // FSEMAILDOWNLOADINFORMATIONMEDIATOR_H
|
|
355 |
|
|
356 |
// end of file
|