79
|
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: MsgAttachmentModel implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// ========== INCLUDE FILES ================================
|
|
21 |
#include <eikenv.h>
|
|
22 |
#include <gulicon.h>
|
|
23 |
#include <apgicnfl.h> // apamasked bitmaps
|
|
24 |
#include <coeutils.h> // for ConeUtils::FileExists
|
|
25 |
#include <DocumentHandler.h> // for KGameMimeType
|
|
26 |
#include <data_caging_path_literals.hrh>
|
|
27 |
#include <msvids.h> // KMsvNullIndexEntryId
|
|
28 |
|
|
29 |
#include <AknUtils.h>
|
|
30 |
#include <AknsUtils.h> // skinned icons
|
|
31 |
#include <AknsConstants.h> // skinned icon ids
|
|
32 |
#include <aknlayout.cdl.h> // LAF
|
|
33 |
|
|
34 |
#include <msgeditor.mbg>
|
|
35 |
#include <msgeditor_ah.mbg>
|
|
36 |
|
|
37 |
#include "MsgEditorCommon.h"
|
|
38 |
#include "MsgAttachmentModel.h"
|
|
39 |
#include "MsgAttachmentModelObserver.h"
|
|
40 |
#include "MsgAttachmentInfo.h"
|
|
41 |
#include "MsgAttachmentUtils.h"
|
|
42 |
|
|
43 |
#include "MsgEditorLogging.h"
|
|
44 |
|
|
45 |
// ========== EXTERNAL DATA STRUCTURES =====================
|
|
46 |
|
|
47 |
// ========== EXTERNAL FUNCTION PROTOTYPES =================
|
|
48 |
|
|
49 |
// ========== CONSTANTS ====================================
|
|
50 |
|
|
51 |
const TUint KAttachArrayGranularity = 16;
|
|
52 |
|
|
53 |
const TInt32 KMaxGameEngineDataID = 1000;
|
|
54 |
const TInt KGameEngineUID = 0x101F5EDA;
|
|
55 |
|
|
56 |
/**
|
|
57 |
* UID of the messaging centre to show correct icon for email
|
|
58 |
* attachments
|
|
59 |
*/
|
|
60 |
const TInt KMceUID = 0x100058C5;
|
|
61 |
_LIT8( KEMailMessageMimeType, "message/rfc822" );
|
|
62 |
|
|
63 |
_LIT8( KTextDataType, "text/plain" );
|
|
64 |
const TInt KNotepadUID3 = 0x1000599d;
|
|
65 |
|
|
66 |
|
|
67 |
// ========== MACROS =======================================
|
|
68 |
|
|
69 |
// ========== LOCAL CONSTANTS AND MACROS ===================
|
|
70 |
|
|
71 |
// ========== MODULE DATA STRUCTURES =======================
|
|
72 |
|
|
73 |
// ========== LOCAL FUNCTION PROTOTYPES ====================
|
|
74 |
|
|
75 |
// ========== LOCAL FUNCTIONS ==============================
|
|
76 |
|
|
77 |
// ========== MEMBER FUNCTIONS =============================
|
|
78 |
|
|
79 |
// ---------------------------------------------------------
|
|
80 |
// CMsgAttachmentModel::NewL
|
|
81 |
//
|
|
82 |
// Factory method.
|
|
83 |
// ---------------------------------------------------------
|
|
84 |
//
|
|
85 |
EXPORT_C CMsgAttachmentModel* CMsgAttachmentModel::NewL( TBool aReadOnly )
|
|
86 |
{
|
|
87 |
CMsgAttachmentModel* self = new ( ELeave ) CMsgAttachmentModel( aReadOnly );
|
|
88 |
|
|
89 |
CleanupStack::PushL( self );
|
|
90 |
self->ConstructL();
|
|
91 |
CleanupStack::Pop();
|
|
92 |
|
|
93 |
return self;
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------
|
|
97 |
// CMsgAttachmentModel::~CMsgAttachmentModel
|
|
98 |
//
|
|
99 |
// Destructor.
|
|
100 |
// ---------------------------------------------------------
|
|
101 |
//
|
|
102 |
EXPORT_C CMsgAttachmentModel::~CMsgAttachmentModel()
|
|
103 |
{
|
|
104 |
delete iDRMFWDLockIcon;
|
|
105 |
delete iDRMSDIconRightsValid;
|
|
106 |
delete iDRMFWDLockIconNoRights;
|
|
107 |
delete iDRMSDIconNoRights;
|
|
108 |
|
|
109 |
if ( iAttachInfoArray )
|
|
110 |
{
|
|
111 |
iAttachInfoArray->ResetAndDestroy();
|
|
112 |
}
|
|
113 |
delete iAttachInfoArray;
|
|
114 |
|
|
115 |
iAppList.Close();
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------
|
|
119 |
// CMsgAttachmentModel::SetObserver
|
|
120 |
//
|
|
121 |
// Sets attachment model observer.
|
|
122 |
// ---------------------------------------------------------
|
|
123 |
//
|
|
124 |
EXPORT_C void CMsgAttachmentModel::SetObserver(
|
|
125 |
MMsgAttachmentModelObserver* aObserver )
|
|
126 |
{
|
|
127 |
iAttachmentModelObserver = aObserver;
|
|
128 |
}
|
|
129 |
|
|
130 |
// ---------------------------------------------------------
|
|
131 |
// CMsgAttachmentModel::NumberOfItems
|
|
132 |
//
|
|
133 |
// Returns number of attachments.
|
|
134 |
// ---------------------------------------------------------
|
|
135 |
//
|
|
136 |
EXPORT_C TInt CMsgAttachmentModel::NumberOfItems() const
|
|
137 |
{
|
|
138 |
return iAttachInfoArray->Count();
|
|
139 |
}
|
|
140 |
|
|
141 |
// ---------------------------------------------------------
|
|
142 |
// CMsgAttachmentModel::AttachmentInfoAt
|
|
143 |
//
|
|
144 |
// Returns reference to attachment info at given index.
|
|
145 |
// ---------------------------------------------------------
|
|
146 |
//
|
|
147 |
EXPORT_C CMsgAttachmentInfo& CMsgAttachmentModel::AttachmentInfoAt(
|
|
148 |
TInt aIndex ) const
|
|
149 |
{
|
|
150 |
return *iAttachInfoArray->At( aIndex );
|
|
151 |
}
|
|
152 |
|
|
153 |
// ---------------------------------------------------------
|
|
154 |
// CMsgAttachmentModel::BitmapForFileL
|
|
155 |
//
|
|
156 |
// Returns pointer to bitmap of the application that handles given file.
|
|
157 |
// If application not found returns default bitmap and sets supported flag
|
|
158 |
// of the aAttaInfo to EFalse.
|
|
159 |
// ---------------------------------------------------------
|
|
160 |
//
|
|
161 |
EXPORT_C CGulIcon* CMsgAttachmentModel::BitmapForFileL(
|
|
162 |
CMsgAttachmentInfo& aAttaInfo )
|
|
163 |
{
|
|
164 |
MEBLOGGER_ENTERFN( "BitmapForFileL" );
|
|
165 |
|
|
166 |
TUid appUid( KNullUid );
|
|
167 |
// Get bitmap based on datatype:
|
|
168 |
TInt err = iAppList.AppForDataType( aAttaInfo.DataType(), appUid );
|
|
169 |
/*
|
|
170 |
// Get bitmap based on recognition:
|
|
171 |
// How to handle this with file handles?!
|
|
172 |
TDataType dataType;
|
|
173 |
TInt err = iAppList.AppForDocument( aAttaInfo.FileName(), appUid, dataType );
|
|
174 |
TInt err = iAppList.AppForDocumentAndService(
|
|
175 |
const TDesC& aFileName,
|
|
176 |
RFs& aFSession,
|
|
177 |
RFile& aFile,
|
|
178 |
TUid aServiceUid,
|
|
179 |
TUid& aAppUid,
|
|
180 |
TDataType& aDataType);
|
|
181 |
|
|
182 |
if ( dataType.Des8().FindF( KGameMimeType ) != KErrNotFound )
|
|
183 |
{
|
|
184 |
appUid = AppUidFromGameFileL( dataType, aAttaInfo.FileName() );
|
|
185 |
}
|
|
186 |
*/
|
|
187 |
if ( aAttaInfo.DataType().Des8().Compare( KEMailMessageMimeType ) == 0 )
|
|
188 |
{
|
|
189 |
appUid.iUid = KMceUID;
|
|
190 |
err = KErrNone;
|
|
191 |
}
|
|
192 |
else if ( aAttaInfo.DataType().Des8().Compare( KTextDataType ) == 0 )
|
|
193 |
{
|
|
194 |
appUid.iUid = KNotepadUID3;
|
|
195 |
err = KErrNone;
|
|
196 |
}
|
|
197 |
|
|
198 |
TBool supported( ( err == KErrNone ) && ( appUid.iUid != 0 ) );
|
|
199 |
|
|
200 |
// Case Imelody: content type text/x-imelody. AppForDataType() returns 'no-app'.
|
|
201 |
// But Imelody should be opened into text editor.
|
|
202 |
// AppForDocument resolves correct application icon.
|
|
203 |
// Content type length check removed from if()
|
|
204 |
if ( !supported )
|
|
205 |
{
|
|
206 |
TDataType dataType;
|
|
207 |
TMsvAttachmentId attachmentId = aAttaInfo.AttachmentId();
|
|
208 |
// OPEN: is there need to handle attachmentId == 0 differently?
|
|
209 |
RFile attachmentFile;
|
|
210 |
TRAP( err, attachmentFile = iAttachmentModelObserver->GetAttachmentFileL( attachmentId ) );
|
|
211 |
if ( err == KErrNone && attachmentFile.SubSessionHandle() != KNullHandle )
|
|
212 |
{
|
|
213 |
err = iAppList.AppForDocument( attachmentFile, appUid, dataType );
|
|
214 |
attachmentFile.Close();
|
|
215 |
}
|
|
216 |
supported = ( ( err == KErrNone ) && ( appUid.iUid != 0 ) );
|
|
217 |
}
|
|
218 |
|
|
219 |
aAttaInfo.SetSupported( supported );
|
|
220 |
|
|
221 |
CGulIcon* addIcon = NULL;
|
|
222 |
CGulIcon* icon = NULL;
|
|
223 |
if ( aAttaInfo.DRMDataType() )
|
|
224 |
{
|
|
225 |
MAknsSkinInstance* skins = AknsUtils::SkinInstance();
|
|
226 |
switch ( aAttaInfo.DRMDataType() )
|
|
227 |
{
|
|
228 |
case CMsgAttachmentInfo::ECombinedDeliveryInvalidRights:
|
|
229 |
{
|
|
230 |
if ( !iDRMFWDLockIconNoRights )
|
|
231 |
{
|
|
232 |
iDRMFWDLockIconNoRights = AknsUtils::CreateGulIconL(
|
|
233 |
skins,
|
|
234 |
KAknsIIDQgnPropDrmExpForbidSuper,
|
|
235 |
KMsgEditorMbm,
|
|
236 |
EMbmMsgeditorQgn_prop_drm_exp_forbid_super,
|
|
237 |
EMbmMsgeditorQgn_prop_drm_exp_forbid_super_mask );
|
|
238 |
AknIconUtils::SetSize( iDRMFWDLockIconNoRights->Bitmap(), iAddIconSize );
|
|
239 |
}
|
|
240 |
addIcon = iDRMFWDLockIconNoRights;
|
|
241 |
}
|
|
242 |
break;
|
|
243 |
|
|
244 |
case CMsgAttachmentInfo::ESeparateDeliveryInvalidRights:
|
|
245 |
{
|
|
246 |
if ( !iDRMSDIconNoRights )
|
|
247 |
{
|
|
248 |
iDRMSDIconNoRights = AknsUtils::CreateGulIconL(
|
|
249 |
skins,
|
|
250 |
KAknsIIDQgnPropDrmRightsExpSuper,
|
|
251 |
KMsgEditorMbm,
|
|
252 |
EMbmMsgeditorQgn_prop_drm_rights_exp_super,
|
|
253 |
EMbmMsgeditorQgn_prop_drm_rights_exp_super_mask );
|
|
254 |
AknIconUtils::SetSize( iDRMSDIconNoRights->Bitmap(), iAddIconSize );
|
|
255 |
}
|
|
256 |
addIcon = iDRMSDIconNoRights;
|
|
257 |
}
|
|
258 |
break;
|
|
259 |
|
|
260 |
case CMsgAttachmentInfo::EForwardLockedOrCombinedDelivery:
|
|
261 |
{
|
|
262 |
// OPEN: What should the addIcon be if file is not supported?
|
|
263 |
// Now it will be "iDRMFWDLockIcon"
|
|
264 |
if ( !iDRMFWDLockIcon )
|
|
265 |
{
|
|
266 |
iDRMFWDLockIcon = AknsUtils::CreateGulIconL(
|
|
267 |
skins,
|
|
268 |
KAknsIIDQgnPropDrmSendForbidSuper,
|
|
269 |
KMsgEditorMbm,
|
|
270 |
EMbmMsgeditorQgn_prop_drm_send_forbid_super,
|
|
271 |
EMbmMsgeditorQgn_prop_drm_send_forbid_super_mask );
|
|
272 |
AknIconUtils::SetSize( iDRMFWDLockIcon->Bitmap(), iAddIconSize );
|
|
273 |
}
|
|
274 |
|
|
275 |
addIcon = iDRMFWDLockIcon;
|
|
276 |
}
|
|
277 |
break;
|
|
278 |
|
|
279 |
case CMsgAttachmentInfo::ESeparateDeliveryValidRights:
|
|
280 |
{
|
|
281 |
if ( !iDRMSDIconRightsValid )
|
|
282 |
{
|
|
283 |
iDRMSDIconRightsValid = AknsUtils::CreateGulIconL(
|
|
284 |
skins,
|
|
285 |
KAknsIIDQgnPropDrmRightsValidSuper,
|
|
286 |
KMsgEditorMbm,
|
|
287 |
EMbmMsgeditorQgn_prop_drm_rights_valid_super,
|
|
288 |
EMbmMsgeditorQgn_prop_drm_rights_valid_super );
|
|
289 |
AknIconUtils::SetSize( iDRMSDIconRightsValid->Bitmap(), iAddIconSize );
|
|
290 |
}
|
|
291 |
|
|
292 |
addIcon = iDRMSDIconRightsValid;
|
|
293 |
}
|
|
294 |
break;
|
|
295 |
|
|
296 |
default:
|
|
297 |
break;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
if ( !icon )
|
|
301 |
{
|
|
302 |
icon = supported
|
|
303 |
? BitmapForAppL( appUid )
|
|
304 |
: LoadDefaultBitmapL( EFalse );
|
|
305 |
}
|
|
306 |
|
|
307 |
CleanupStack::PushL( icon );
|
|
308 |
AknIconUtils::SetSize( icon->Bitmap(), iIconSize );
|
|
309 |
|
|
310 |
CGulIcon* finalIcon = NULL;
|
|
311 |
|
|
312 |
if ( addIcon )
|
|
313 |
{
|
|
314 |
// Create two new bitmaps (app icon and mask) that have document
|
|
315 |
// icon drawn on top.
|
|
316 |
CFbsBitmap* newMask = MsgAttachmentUtils::CombineIconsL(
|
|
317 |
icon->Mask(),
|
|
318 |
addIcon->Mask(),
|
|
319 |
addIcon->Mask() );
|
|
320 |
CleanupStack::PushL( newMask );
|
|
321 |
CFbsBitmap* newBitmap = MsgAttachmentUtils::CombineIconsL(
|
|
322 |
icon->Bitmap(),
|
|
323 |
addIcon->Bitmap(),
|
|
324 |
addIcon->Mask() );
|
|
325 |
CleanupStack::PushL( newBitmap );
|
|
326 |
|
|
327 |
finalIcon = CGulIcon::NewL( newBitmap, newMask );
|
|
328 |
CleanupStack::Pop( 2 ); //newBitmap, mask
|
|
329 |
CleanupStack::PopAndDestroy(); //icon
|
|
330 |
CleanupStack::PushL( finalIcon );
|
|
331 |
}
|
|
332 |
else
|
|
333 |
{
|
|
334 |
finalIcon = icon;
|
|
335 |
}
|
|
336 |
|
|
337 |
// fade icon if not fetched.
|
|
338 |
if ( !aAttaInfo.IsFetched() )
|
|
339 |
{
|
|
340 |
// Create copy of the original application icon bitmap & mask
|
|
341 |
// so that original data is not modified.
|
|
342 |
CFbsBitmap* newMask = CopyBitmapL( finalIcon->Mask() );
|
|
343 |
CleanupStack::PushL( newMask );
|
|
344 |
CFbsBitmap* newBitmap = CopyBitmapL( finalIcon->Bitmap() );
|
|
345 |
CleanupStack::PushL( newBitmap );
|
|
346 |
|
|
347 |
CGulIcon* tempIcon = CGulIcon::NewL( newBitmap, newMask );
|
|
348 |
|
|
349 |
CleanupStack::Pop( 2, newMask );
|
|
350 |
CleanupStack::PopAndDestroy( addIcon ? finalIcon : icon );
|
|
351 |
finalIcon = tempIcon;
|
|
352 |
CleanupStack::PushL( finalIcon );
|
|
353 |
|
|
354 |
FadeBitmapL( finalIcon->Bitmap() );
|
|
355 |
}
|
|
356 |
CleanupStack::Pop( finalIcon );
|
|
357 |
|
|
358 |
MEBLOGGER_LEAVEFN( "BitmapForFileL" );
|
|
359 |
|
|
360 |
return finalIcon;
|
|
361 |
}
|
|
362 |
|
|
363 |
|
|
364 |
// ---------------------------------------------------------
|
|
365 |
// CMsgAttachmentModel::FadeBitmapL
|
|
366 |
// ---------------------------------------------------------
|
|
367 |
//
|
|
368 |
void CMsgAttachmentModel::FadeBitmapL( CFbsBitmap* aBitmap )
|
|
369 |
{
|
|
370 |
TRegionFix<1> area( aBitmap->SizeInPixels() );
|
|
371 |
|
|
372 |
CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( aBitmap );
|
|
373 |
|
|
374 |
CFbsBitGc* bitGc = NULL;
|
|
375 |
bmpDevice->CreateContext( bitGc );
|
|
376 |
|
|
377 |
if ( bitGc )
|
|
378 |
{
|
|
379 |
// TODO: Magic numbers here to stay?
|
|
380 |
TUint8 blackMap = 128;
|
|
381 |
TUint8 whiteMap = 255;
|
|
382 |
bitGc->SetFadingParameters( blackMap, whiteMap );
|
|
383 |
bitGc->FadeArea( &area );
|
|
384 |
|
|
385 |
delete bitGc;
|
|
386 |
}
|
|
387 |
delete bmpDevice;
|
|
388 |
}
|
|
389 |
|
|
390 |
// ---------------------------------------------------------
|
|
391 |
// CMsgAttachmentModel::CopyBitmapL
|
|
392 |
// ---------------------------------------------------------
|
|
393 |
//
|
|
394 |
CFbsBitmap* CMsgAttachmentModel::CopyBitmapL( const CFbsBitmap* aBitmap )
|
|
395 |
{
|
|
396 |
if ( !aBitmap )
|
|
397 |
{
|
|
398 |
User::Leave( KErrArgument );
|
|
399 |
}
|
|
400 |
|
|
401 |
CFbsBitmap* newBitmap = new( ELeave ) CFbsBitmap();
|
|
402 |
CleanupStack::PushL( newBitmap );
|
|
403 |
|
|
404 |
User::LeaveIfError( newBitmap->Create( aBitmap->SizeInPixels(), aBitmap->DisplayMode() ) );
|
|
405 |
|
|
406 |
CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( newBitmap );
|
|
407 |
|
|
408 |
CleanupStack::Pop( newBitmap );
|
|
409 |
CleanupStack::PushL( bitmapDevice );
|
|
410 |
|
|
411 |
CBitmapContext* bitmapContext = NULL;
|
|
412 |
User::LeaveIfError( bitmapDevice->CreateBitmapContext( bitmapContext ) );
|
|
413 |
CleanupStack::PushL( bitmapContext );
|
|
414 |
|
|
415 |
bitmapContext->BitBlt( TPoint(), aBitmap );
|
|
416 |
|
|
417 |
CleanupStack::PopAndDestroy( 2, bitmapDevice );
|
|
418 |
return newBitmap;
|
|
419 |
}
|
|
420 |
|
|
421 |
// ---------------------------------------------------------
|
|
422 |
// CMsgAttachmentModel::AddAttachmentL
|
|
423 |
//
|
|
424 |
// Adds attachment to the internal array. Notifies attachment model
|
|
425 |
// observer with EMsgAttachmentAdded parameter.
|
|
426 |
// ---------------------------------------------------------
|
|
427 |
//
|
|
428 |
EXPORT_C CMsgAttachmentInfo* CMsgAttachmentModel::AddAttachmentL(
|
|
429 |
const TDesC& aFullName,
|
|
430 |
TInt aSize,
|
|
431 |
TMsvAttachmentId aAttachmentEntryId,
|
|
432 |
TBool aFetched,
|
|
433 |
TInt aIndex /*= -1*/ )
|
|
434 |
{
|
|
435 |
TDataType dataType;
|
|
436 |
|
|
437 |
if ( ConeUtils::FileExists( aFullName ) )
|
|
438 |
{
|
|
439 |
TUid appUid( KNullUid );
|
|
440 |
iAppList.AppForDocument( aFullName, appUid, dataType );
|
|
441 |
}
|
|
442 |
|
|
443 |
return AddAttachmentL(
|
|
444 |
aFullName, aSize, aAttachmentEntryId, aFetched, dataType, aIndex );
|
|
445 |
}
|
|
446 |
|
|
447 |
// ---------------------------------------------------------
|
|
448 |
// CMsgAttachmentModel::AddAttachmentL
|
|
449 |
//
|
|
450 |
// Adds attachment to the internal array. Notifies attachment model
|
|
451 |
// observer with EMsgAttachmentAdded parameter.
|
|
452 |
// ---------------------------------------------------------
|
|
453 |
//
|
|
454 |
EXPORT_C CMsgAttachmentInfo* CMsgAttachmentModel::AddAttachmentL(
|
|
455 |
const TDesC& aFullName,
|
|
456 |
TInt aSize,
|
|
457 |
TMsvAttachmentId aAttachmentEntryId,
|
|
458 |
TBool aFetched,
|
|
459 |
const TDataType& aDataType,
|
|
460 |
TInt aIndex )
|
|
461 |
{
|
|
462 |
return AddAttachmentL( aFullName,
|
|
463 |
aSize,
|
|
464 |
aAttachmentEntryId,
|
|
465 |
aFetched,
|
|
466 |
aDataType,
|
|
467 |
CMsgAttachmentInfo::ENoLimitations,
|
|
468 |
aIndex);
|
|
469 |
}
|
|
470 |
|
|
471 |
// ---------------------------------------------------------
|
|
472 |
// CMsgAttachmentModel::AddAttachmentL
|
|
473 |
//
|
|
474 |
// Adds attachment to the internal array. Notifies attachment model
|
|
475 |
// observer with EMsgAttachmentAdded parameter.
|
|
476 |
// ---------------------------------------------------------
|
|
477 |
//
|
|
478 |
EXPORT_C CMsgAttachmentInfo* CMsgAttachmentModel::AddAttachmentL(
|
|
479 |
const TDesC& aFullName,
|
|
480 |
TInt aSize,
|
|
481 |
TMsvAttachmentId aAttachmentEntryId,
|
|
482 |
TBool aFetched,
|
|
483 |
const TDataType& aDataType,
|
|
484 |
CMsgAttachmentInfo::TDRMDataType aDRMDataType,
|
|
485 |
TInt aIndex /*= -1*/ )
|
|
486 |
{
|
|
487 |
CMsgAttachmentInfo* info = CreateNewInfoL( aFullName,
|
|
488 |
aSize,
|
|
489 |
aFetched,
|
|
490 |
ETrue,
|
|
491 |
aAttachmentEntryId,
|
|
492 |
aDataType,
|
|
493 |
aDRMDataType );
|
|
494 |
|
|
495 |
CleanupStack::PushL( info );
|
|
496 |
|
|
497 |
info->SetAttachmentId( aAttachmentEntryId );
|
|
498 |
|
|
499 |
if ( aIndex == -1 )
|
|
500 |
{
|
|
501 |
iAttachInfoArray->AppendL( info );
|
|
502 |
}
|
|
503 |
else
|
|
504 |
{
|
|
505 |
iAttachInfoArray->InsertL( aIndex, info );
|
|
506 |
}
|
|
507 |
|
|
508 |
iModified = ETrue;
|
|
509 |
|
|
510 |
if ( ( iAttachmentModelObserver != NULL ) && ( NumberOfItems() > 0 ) )
|
|
511 |
{
|
|
512 |
iAttachmentModelObserver->NotifyChanges(
|
|
513 |
MMsgAttachmentModelObserver::EMsgAttachmentAdded, info );
|
|
514 |
}
|
|
515 |
|
|
516 |
CleanupStack::Pop(); // info
|
|
517 |
|
|
518 |
return info;
|
|
519 |
}
|
|
520 |
|
|
521 |
// ---------------------------------------------------------
|
|
522 |
// CMsgAttachmentModel::DeleteAttachment
|
|
523 |
//
|
|
524 |
// Deletes attachment from internal array. Notifies attachment model
|
|
525 |
// observer with EMsgAttachmentRemoved parameter.
|
|
526 |
// ---------------------------------------------------------
|
|
527 |
//
|
|
528 |
EXPORT_C void CMsgAttachmentModel::DeleteAttachment( TInt aIndex )
|
|
529 |
{
|
|
530 |
TRAP_IGNORE( DoDeleteAttachmentL( aIndex ) );
|
|
531 |
}
|
|
532 |
|
|
533 |
// ---------------------------------------------------------
|
|
534 |
// CMsgAttachmentModel::DoDeleteAttachmentL
|
|
535 |
//
|
|
536 |
// Deletes attachment from internal array. Notifies attachment model
|
|
537 |
// observer with EMsgAttachmentRemoved parameter.
|
|
538 |
// ---------------------------------------------------------
|
|
539 |
//
|
|
540 |
void CMsgAttachmentModel::DoDeleteAttachmentL( TInt aIndex )
|
|
541 |
{
|
|
542 |
if ( aIndex >= 0 && aIndex < iAttachInfoArray->Count() )
|
|
543 |
{
|
|
544 |
CEikonEnv* eikonEnv = CEikonEnv::Static();
|
|
545 |
|
|
546 |
CFileMan* fileMan = CFileMan::NewL( eikonEnv->FsSession() );
|
|
547 |
CleanupStack::PushL( fileMan );
|
|
548 |
|
|
549 |
CMsgAttachmentInfo* info = iAttachInfoArray->At( aIndex );
|
|
550 |
|
|
551 |
if ( iAttachmentModelObserver )
|
|
552 |
{
|
|
553 |
iAttachmentModelObserver->NotifyChanges(
|
|
554 |
MMsgAttachmentModelObserver::EMsgAttachmentRemoved, info );
|
|
555 |
}
|
|
556 |
|
|
557 |
// delete the information block.
|
|
558 |
delete info;
|
|
559 |
|
|
560 |
// delete the array entry.
|
|
561 |
iAttachInfoArray->Delete( aIndex );
|
|
562 |
// delete files from our temp directory.
|
|
563 |
|
|
564 |
TFileName temppath;
|
|
565 |
MsgAttachmentUtils::GetMsgEditorTempPath( temppath );
|
|
566 |
fileMan->Delete( temppath );
|
|
567 |
|
|
568 |
CleanupStack::PopAndDestroy( fileMan );
|
|
569 |
|
|
570 |
iModified = ETrue;
|
|
571 |
}
|
|
572 |
}
|
|
573 |
|
|
574 |
// ---------------------------------------------------------
|
|
575 |
// CMsgAttachmentModel::IsModified
|
|
576 |
//
|
|
577 |
// Returns true if stored info about attachments is modified.
|
|
578 |
// ---------------------------------------------------------
|
|
579 |
//
|
|
580 |
EXPORT_C TBool CMsgAttachmentModel::IsModified() const
|
|
581 |
{
|
|
582 |
return iModified;
|
|
583 |
}
|
|
584 |
|
|
585 |
// ---------------------------------------------------------
|
|
586 |
// CMsgAttachmentModel::SetModified
|
|
587 |
//
|
|
588 |
// Sets the modified flag.
|
|
589 |
// ---------------------------------------------------------
|
|
590 |
//
|
|
591 |
EXPORT_C void CMsgAttachmentModel::SetModified( TBool aModified )
|
|
592 |
{
|
|
593 |
iModified = aModified;
|
|
594 |
}
|
|
595 |
|
|
596 |
// ---------------------------------------------------------
|
|
597 |
// CMsgAttachmentModel::IsReadOnly
|
|
598 |
//
|
|
599 |
// Returns ETrue if attachment model was created to be read-only.
|
|
600 |
// ---------------------------------------------------------
|
|
601 |
//
|
|
602 |
EXPORT_C TBool CMsgAttachmentModel::IsReadOnly()
|
|
603 |
{
|
|
604 |
return iReadOnly;
|
|
605 |
}
|
|
606 |
|
|
607 |
// ---------------------------------------------------------
|
|
608 |
// CMsgAttachmentModel::IsFileAttached
|
|
609 |
//
|
|
610 |
// Returns ETrue if given file is found from the internal array.
|
|
611 |
// ---------------------------------------------------------
|
|
612 |
//
|
|
613 |
EXPORT_C TBool CMsgAttachmentModel::IsFileAttached( const TDesC& aFileName ) const
|
|
614 |
{
|
|
615 |
TInt cc = iAttachInfoArray->Count() - 1;
|
|
616 |
|
|
617 |
// TODO: Make this understandable!
|
|
618 |
for ( ; ( cc >= 0 ) && ( iAttachInfoArray->At( cc )->FileName().CompareF( aFileName ) != 0 ); --cc )
|
|
619 |
;
|
|
620 |
|
|
621 |
return cc >= 0;
|
|
622 |
}
|
|
623 |
|
|
624 |
// ---------------------------------------------------------
|
|
625 |
// CMsgAttachmentModel::IsIdAttached
|
|
626 |
//
|
|
627 |
// Returns ETrue if given attachment id is found from the internal array.
|
|
628 |
// ---------------------------------------------------------
|
|
629 |
//
|
|
630 |
EXPORT_C TBool CMsgAttachmentModel::IsIdAttached( TMsvAttachmentId aId ) const
|
|
631 |
{
|
|
632 |
TInt cc = iAttachInfoArray->Count() - 1;
|
|
633 |
|
|
634 |
// TODO: Make this understandable!
|
|
635 |
for (; ( cc >= 0 ) && ( iAttachInfoArray->At( cc )->AttachmentId() != aId ); --cc )
|
|
636 |
;
|
|
637 |
|
|
638 |
return cc >= 0;
|
|
639 |
}
|
|
640 |
|
|
641 |
// ---------------------------------------------------------
|
|
642 |
// CMsgAttachmentModel::ViewAttachmentL
|
|
643 |
//
|
|
644 |
// Opens seleceted attachment in corresponding target application.
|
|
645 |
// ---------------------------------------------------------
|
|
646 |
//
|
|
647 |
EXPORT_C void CMsgAttachmentModel::ViewAttachmentL( TInt aIndex )
|
|
648 |
{
|
|
649 |
CMsgAttachmentInfo& attInfo = AttachmentInfoAt( aIndex );
|
|
650 |
TFileName filename = attInfo.FileName();
|
|
651 |
TThreadId id;
|
|
652 |
User::LeaveIfError( iAppList.StartDocument( filename, id ) );
|
|
653 |
}
|
|
654 |
|
|
655 |
// ---------------------------------------------------------
|
|
656 |
// CMsgAttachmentModel::Reset
|
|
657 |
//
|
|
658 |
// Reset the attachment model (empties the internal array).
|
|
659 |
// ---------------------------------------------------------
|
|
660 |
//
|
|
661 |
EXPORT_C void CMsgAttachmentModel::Reset()
|
|
662 |
{
|
|
663 |
if ( iAttachInfoArray )
|
|
664 |
{
|
|
665 |
iAttachInfoArray->ResetAndDestroy();
|
|
666 |
}
|
|
667 |
}
|
|
668 |
|
|
669 |
// ---------------------------------------------------------
|
|
670 |
// CMsgAttachmentModel::CMsgAttachmentModel
|
|
671 |
//
|
|
672 |
// Constructor.
|
|
673 |
// ---------------------------------------------------------
|
|
674 |
//
|
|
675 |
EXPORT_C CMsgAttachmentModel::CMsgAttachmentModel( TBool aReadOnly )
|
|
676 |
: iReadOnly( aReadOnly )
|
|
677 |
{
|
|
678 |
}
|
|
679 |
|
|
680 |
// ---------------------------------------------------------
|
|
681 |
// CMsgAttachmentModel::ConstructL
|
|
682 |
//
|
|
683 |
// 2nd phase constructor. Creates attachment info array.
|
|
684 |
// ---------------------------------------------------------
|
|
685 |
//
|
|
686 |
EXPORT_C void CMsgAttachmentModel::ConstructL()
|
|
687 |
{
|
|
688 |
iAttachInfoArray = new ( ELeave ) CAttInfoArray( KAttachArrayGranularity );
|
|
689 |
User::LeaveIfError( iAppList.Connect() );
|
|
690 |
LoadResourcesL();
|
|
691 |
}
|
|
692 |
|
|
693 |
EXPORT_C void CMsgAttachmentModel::LoadResourcesL()
|
|
694 |
{
|
|
695 |
// Resolve icon layout
|
|
696 |
TRect mainPane;
|
|
697 |
AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
|
|
698 |
TAknLayoutRect listPaneLayout;
|
|
699 |
listPaneLayout.LayoutRect(
|
|
700 |
mainPane,
|
|
701 |
AknLayout::list_gen_pane( 0 ) );
|
|
702 |
TAknLayoutRect doubleGraphicLayout;
|
|
703 |
doubleGraphicLayout.LayoutRect(
|
|
704 |
listPaneLayout.Rect(),
|
|
705 |
AknLayout::list_double_large_graphic_pane_list_double2_large_graphic_pane_list_single_big_large_graphic_pane( 0 ) );
|
|
706 |
TAknLayoutRect iconLayout;
|
|
707 |
iconLayout.LayoutRect(
|
|
708 |
doubleGraphicLayout.Rect(),
|
|
709 |
AknLayout::List_pane_elements__double_large_graphic__Line_8() );
|
|
710 |
TAknLayoutRect addIconLayout;
|
|
711 |
addIconLayout.LayoutRect(
|
|
712 |
doubleGraphicLayout.Rect(),
|
|
713 |
AknLayout::List_pane_elements__double_large_graphic__Line_9( 0 ) );
|
|
714 |
|
|
715 |
iIconSize = iconLayout.Rect().Size();
|
|
716 |
iAddIconSize = addIconLayout.Rect().Size();
|
|
717 |
|
|
718 |
MAknsSkinInstance* skins = AknsUtils::SkinInstance();
|
|
719 |
|
|
720 |
delete iDRMFWDLockIcon;
|
|
721 |
iDRMFWDLockIcon = NULL;
|
|
722 |
delete iDRMSDIconRightsValid;
|
|
723 |
iDRMSDIconRightsValid = NULL;
|
|
724 |
delete iDRMFWDLockIconNoRights;
|
|
725 |
iDRMFWDLockIconNoRights = NULL;
|
|
726 |
delete iDRMSDIconNoRights;
|
|
727 |
iDRMSDIconNoRights = NULL;
|
|
728 |
|
|
729 |
TInt count = iAttachInfoArray
|
|
730 |
? iAttachInfoArray->Count()
|
|
731 |
: 0;
|
|
732 |
while ( count-- )
|
|
733 |
{
|
|
734 |
// Update possibly already existing icons
|
|
735 |
iAttachInfoArray->At( count )->ChangeSizeAndIconL();
|
|
736 |
}
|
|
737 |
}
|
|
738 |
|
|
739 |
|
|
740 |
// ---------------------------------------------------------
|
|
741 |
// CMsgAttachmentModel::GetAttachmentFileL
|
|
742 |
// ---------------------------------------------------------
|
|
743 |
//
|
|
744 |
EXPORT_C RFile CMsgAttachmentModel::GetAttachmentFileL( TInt aIndex )
|
|
745 |
{
|
|
746 |
CMsgAttachmentInfo* attInfo = iAttachInfoArray->At( aIndex );
|
|
747 |
|
|
748 |
if ( !attInfo )
|
|
749 |
{
|
|
750 |
User::Leave( KErrNotFound );
|
|
751 |
}
|
|
752 |
|
|
753 |
TMsvAttachmentId attachmentId = attInfo->AttachmentId();
|
|
754 |
RFile file;
|
|
755 |
if ( attachmentId == KMsvNullIndexEntryId )
|
|
756 |
{
|
|
757 |
RFs& fs = CEikonEnv::Static()->FsSession();
|
|
758 |
TInt err = file.Open( fs, attInfo->FileName(), EFileRead | EFileShareAny );
|
|
759 |
if ( err )
|
|
760 |
{
|
|
761 |
User::LeaveIfError( file.Open( fs, attInfo->FileName(), EFileRead | EFileShareReadersOnly ) );
|
|
762 |
}
|
|
763 |
}
|
|
764 |
else
|
|
765 |
{
|
|
766 |
file = iAttachmentModelObserver->GetAttachmentFileL( attachmentId );
|
|
767 |
}
|
|
768 |
return file;
|
|
769 |
}
|
|
770 |
|
|
771 |
// ---------------------------------------------------------
|
|
772 |
// CMsgAttachmentModel::LoadDefaultBitmapL
|
|
773 |
//
|
|
774 |
// Loads system default bitmap.
|
|
775 |
// ---------------------------------------------------------
|
|
776 |
//
|
|
777 |
CGulIcon* CMsgAttachmentModel::LoadDefaultBitmapL( TBool /*aSupported*/ )
|
|
778 |
{
|
|
779 |
MEBLOGGER_ENTERFN( "LoadDefaultBitmapL" );
|
|
780 |
if( AknLayoutUtils::LayoutMirrored() )
|
|
781 |
{
|
|
782 |
return AknsUtils::CreateGulIconL(
|
|
783 |
AknsUtils::SkinInstance(),
|
|
784 |
KAknsIIDQgnPropUnknown,
|
|
785 |
KMsgEditorMbm_AH,
|
|
786 |
EMbmMsgeditor_ahQgn_prop_unknown,
|
|
787 |
EMbmMsgeditor_ahQgn_prop_unknown_mask );
|
|
788 |
}
|
|
789 |
else
|
|
790 |
{
|
|
791 |
return AknsUtils::CreateGulIconL(
|
|
792 |
AknsUtils::SkinInstance(),
|
|
793 |
KAknsIIDQgnPropUnknown,
|
|
794 |
KMsgEditorMbm,
|
|
795 |
EMbmMsgeditorQgn_prop_unknown,
|
|
796 |
EMbmMsgeditorQgn_prop_unknown_mask );
|
|
797 |
}
|
|
798 |
}
|
|
799 |
|
|
800 |
// ---------------------------------------------------------
|
|
801 |
// CMsgAttachmentModel::AppUidForFileL
|
|
802 |
//
|
|
803 |
// Returns app ui of application that handles given file.
|
|
804 |
// ---------------------------------------------------------
|
|
805 |
//
|
|
806 |
TUid CMsgAttachmentModel::AppUidForFileL( const TFileName& aFileName )
|
|
807 |
{
|
|
808 |
TUid appUid( KNullUid );
|
|
809 |
TDataType dataType;
|
|
810 |
|
|
811 |
User::LeaveIfError( iAppList.AppForDocument( aFileName, appUid, dataType ) );
|
|
812 |
|
|
813 |
if ( appUid.iUid == 0 )
|
|
814 |
{
|
|
815 |
User::LeaveIfError( iAppList.AppForDataType( dataType, appUid ) );
|
|
816 |
}
|
|
817 |
|
|
818 |
return appUid;
|
|
819 |
}
|
|
820 |
|
|
821 |
// ---------------------------------------------------------
|
|
822 |
// CMsgAttachmentModel::AppUidForDataTypeL
|
|
823 |
//
|
|
824 |
// Returns app ui of application that handles given data type.
|
|
825 |
// ---------------------------------------------------------
|
|
826 |
//
|
|
827 |
TUid CMsgAttachmentModel::AppUidForDataTypeL( const TDataType& aDataType )
|
|
828 |
{
|
|
829 |
TUid appUid( KNullUid );
|
|
830 |
|
|
831 |
User::LeaveIfError( iAppList.AppForDataType( aDataType, appUid ) );
|
|
832 |
|
|
833 |
return appUid;
|
|
834 |
}
|
|
835 |
|
|
836 |
// ---------------------------------------------------------
|
|
837 |
// CMsgAttachmentModel::AppUidFromGameFileL
|
|
838 |
//
|
|
839 |
// Returns app uid of application that handles given game data.
|
|
840 |
// ---------------------------------------------------------
|
|
841 |
TUid CMsgAttachmentModel::AppUidFromGameFileL(
|
|
842 |
TDataType& aDataType, const TDesC& aFileName )
|
|
843 |
{
|
|
844 |
TUid appUid( KNullUid );
|
|
845 |
RFile file;
|
|
846 |
RFs& fs = CEikonEnv::Static()->FsSession();
|
|
847 |
|
|
848 |
User::LeaveIfError( file.Open( fs, aFileName, EFileRead ) );
|
|
849 |
CleanupClosePushL(file);
|
|
850 |
RFileReadStream reader( file );
|
|
851 |
CleanupClosePushL(reader);
|
|
852 |
TInt32 gameId = reader.ReadInt32L();
|
|
853 |
|
|
854 |
CleanupStack::PopAndDestroy(2,&file); //reader , file
|
|
855 |
|
|
856 |
if ( gameId > KMaxGameEngineDataID )
|
|
857 |
{
|
|
858 |
TBuf8<256> completedType = aDataType.Des8();
|
|
859 |
completedType.Append(_L("-"));
|
|
860 |
completedType.AppendNumFixedWidth( gameId, EHex, 8 );
|
|
861 |
aDataType = TDataType( completedType );
|
|
862 |
}
|
|
863 |
|
|
864 |
iAppList.AppForDataType( aDataType, appUid );
|
|
865 |
|
|
866 |
if ( appUid.iUid == 0 )
|
|
867 |
{
|
|
868 |
appUid.iUid = KGameEngineUID;
|
|
869 |
}
|
|
870 |
|
|
871 |
return appUid;
|
|
872 |
}
|
|
873 |
|
|
874 |
// ---------------------------------------------------------
|
|
875 |
// CMsgAttachmentModel::BitmapForAppL
|
|
876 |
//
|
|
877 |
// Returns pointer to bitmap of given application.
|
|
878 |
// ---------------------------------------------------------
|
|
879 |
//
|
|
880 |
CGulIcon* CMsgAttachmentModel::BitmapForAppL( const TUid &aAppUid )
|
|
881 |
{
|
|
882 |
MEBLOGGER_ENTERFN("BitmapForAppL");
|
|
883 |
|
|
884 |
CFbsBitmap* tempBitmap = NULL;
|
|
885 |
CFbsBitmap* tempMask = NULL;
|
|
886 |
|
|
887 |
AknsUtils::CreateAppIconLC(
|
|
888 |
AknsUtils::SkinInstance(),
|
|
889 |
aAppUid,
|
|
890 |
EAknsAppIconTypeList,
|
|
891 |
tempBitmap,
|
|
892 |
tempMask );
|
|
893 |
|
|
894 |
CGulIcon* bitmap = CGulIcon::NewL( tempBitmap, tempMask );
|
|
895 |
CleanupStack::Pop( 2 ); // tempBitmap, tempMask
|
|
896 |
|
|
897 |
MEBLOGGER_LEAVEFN( "BitmapForAppL" );
|
|
898 |
|
|
899 |
return bitmap;
|
|
900 |
}
|
|
901 |
|
|
902 |
// ---------------------------------------------------------
|
|
903 |
// CMsgAttachmentModel::CreateNewInfoL
|
|
904 |
//
|
|
905 |
// Creates new attachment info object.
|
|
906 |
// ---------------------------------------------------------
|
|
907 |
//
|
|
908 |
CMsgAttachmentInfo* CMsgAttachmentModel::CreateNewInfoL(
|
|
909 |
const TDesC& aFileName,
|
|
910 |
TInt aSize,
|
|
911 |
TBool aFetched,
|
|
912 |
TBool aAttachedThisSession,
|
|
913 |
TMsvAttachmentId aAttachmentId,
|
|
914 |
const TDataType& aDataType,
|
|
915 |
CMsgAttachmentInfo::TDRMDataType aDRMDataType )
|
|
916 |
{
|
|
917 |
return CMsgAttachmentInfo::NewL(
|
|
918 |
*this,
|
|
919 |
aFileName,
|
|
920 |
aSize,
|
|
921 |
aFetched,
|
|
922 |
aAttachedThisSession,
|
|
923 |
aAttachmentId,
|
|
924 |
aDataType,
|
|
925 |
aDRMDataType );
|
|
926 |
}
|
|
927 |
|
|
928 |
// ========== OTHER EXPORTED FUNCTIONS =====================
|
|
929 |
|
|
930 |
// End of File
|