|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "csendasattachment.h" |
|
17 |
|
18 #include <mtclbase.h> |
|
19 |
|
20 #include "msendasattachmentobserver.h" |
|
21 #include "tsendasserverpanic.h" |
|
22 |
|
23 CSendAsAttachment* CSendAsAttachment::NewL(MSendAsAttachmentObserver& aObserver, CBaseMtm& aClientMtm) |
|
24 { |
|
25 CSendAsAttachment* self = new(ELeave) CSendAsAttachment(aObserver, aClientMtm); |
|
26 return self; |
|
27 } |
|
28 |
|
29 CSendAsAttachment::~CSendAsAttachment() |
|
30 { |
|
31 // do not notify observer during deletion. |
|
32 iObserver = NULL; |
|
33 Cancel(); |
|
34 } |
|
35 |
|
36 CSendAsAttachment::CSendAsAttachment(MSendAsAttachmentObserver& aObserver, CBaseMtm& aClientMtm) |
|
37 : CActive(CActive::EPriorityStandard), iObserver(&aObserver), iClientMtm(aClientMtm) |
|
38 { |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 |
|
42 void CSendAsAttachment::AddExistingFileAttachmentL(RFile& aAttachment) |
|
43 { |
|
44 AddExistingFileAttachmentWithMimeTypeL(aAttachment, KNullDesC8, 0); |
|
45 } |
|
46 |
|
47 void CSendAsAttachment::AddExistingFileAttachmentWithMimeTypeL(RFile& aAttachment, const TDesC8& aMimeType, TUint aCharset) |
|
48 { |
|
49 __ASSERT_ALWAYS( iState == EIdle, TSendAsServerPanic::Panic(TSendAsServerPanic::ESendAsAttachmentBadState) ); |
|
50 |
|
51 iClientMtm.AddAttachmentL(aAttachment, aMimeType, aCharset, iStatus); |
|
52 SetActive(); |
|
53 |
|
54 iState = EAddingAttachment; |
|
55 } |
|
56 |
|
57 void CSendAsAttachment::AddFileLinkAttachmentL(const TDesC& aFileName) |
|
58 { |
|
59 AddFileLinkAttachmentWithMimeTypeL(aFileName, KNullDesC8, 0); |
|
60 } |
|
61 |
|
62 void CSendAsAttachment::AddFileLinkAttachmentWithMimeTypeL(const TDesC& aFileName, const TDesC8& aMimeType, TUint aCharset) |
|
63 { |
|
64 __ASSERT_ALWAYS( iState == EIdle, TSendAsServerPanic::Panic(TSendAsServerPanic::ESendAsAttachmentBadState) ); |
|
65 |
|
66 iClientMtm.AddLinkedAttachmentL(aFileName, aMimeType, aCharset, iStatus); |
|
67 SetActive(); |
|
68 |
|
69 iState = EAddingAttachment; |
|
70 } |
|
71 |
|
72 void CSendAsAttachment::CreateNewFileAttachmentL(RFile& aAttachment, const TDesC& aFileName) |
|
73 { |
|
74 CreateNewFileAttachmentWithMimeTypeL(aAttachment, aFileName, KNullDesC8, 0); |
|
75 } |
|
76 |
|
77 void CSendAsAttachment::CreateNewFileAttachmentWithMimeTypeL(RFile& aAttachment, const TDesC& aFileName, const TDesC8& aMimeType, TUint aCharset) |
|
78 { |
|
79 __ASSERT_ALWAYS( iState == EIdle, TSendAsServerPanic::Panic(TSendAsServerPanic::ESendAsAttachmentBadState) ); |
|
80 |
|
81 iClientMtm.CreateAttachmentL(aFileName, aAttachment, aMimeType, aCharset, iStatus); |
|
82 SetActive(); |
|
83 |
|
84 iState = ECreatingAttachment; |
|
85 } |
|
86 |
|
87 void CSendAsAttachment::CompleteL(TInt aError) |
|
88 { |
|
89 if( iObserver != NULL ) |
|
90 { |
|
91 // notify observer that the attachment has completed. |
|
92 // transference of the attachment file to the client on create |
|
93 // attachment completes the RMessage2. |
|
94 iObserver->AttachmentCompleteL(aError, (iState != ECreatingAttachment)); |
|
95 } |
|
96 } |
|
97 |
|
98 /* |
|
99 * Methods from CActive |
|
100 */ |
|
101 |
|
102 void CSendAsAttachment::RunL() |
|
103 { |
|
104 User::LeaveIfError(iStatus.Int()); |
|
105 |
|
106 switch( iState ) |
|
107 { |
|
108 case ECreatingAttachment: |
|
109 // drop through to next case... |
|
110 case EAddingAttachment: |
|
111 { |
|
112 CompleteL(KErrNone); |
|
113 } break; |
|
114 case EIdle: |
|
115 case EAttachmentComplete: |
|
116 default: |
|
117 User::Invariant(); |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 void CSendAsAttachment::DoCancel() |
|
123 { |
|
124 iClientMtm.CancelAttachmentOperation(); |
|
125 TRAP_IGNORE(CompleteL(KErrCancel)); |
|
126 } |
|
127 |
|
128 TInt CSendAsAttachment::RunError(TInt aError) |
|
129 { |
|
130 TInt error = KErrNone; |
|
131 TRAP(error,CompleteL(aError)); |
|
132 return error; |
|
133 } |