|
1 /* |
|
2 * Copyright (c) 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 the License "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: Implementation of class CMessageDetail |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <badesca.h> |
|
22 #include <msvapi.h> |
|
23 |
|
24 #include <CMsvAttachment.h> |
|
25 #include <MMsvAttachmentManager.h> |
|
26 #include <txtrich.h> |
|
27 #include <MsvUids.h> |
|
28 #include <MTCLREG.H> |
|
29 #include <smsclnt.h> |
|
30 #include <smuthdr.h> |
|
31 #include <senduiconsts.h> |
|
32 #include <cmsvrecipientlist.h> |
|
33 #include <mmsclient.h> |
|
34 |
|
35 #include "messageheader.h" |
|
36 #include "messagedetail.h" |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Two-phased constructor. |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CMessageDetail* CMessageDetail::NewL( CMsvSession& aServerSession ) |
|
43 { |
|
44 CMessageDetail* self = new (ELeave) CMessageDetail( aServerSession ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Destructor |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CMessageDetail::~CMessageDetail() |
|
53 { |
|
54 delete iMessageDetail; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Constructor. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CMessageDetail::CMessageDetail( CMsvSession& aServerSession ): |
|
62 iServerSession( aServerSession ) |
|
63 |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Gets the message details |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CMessageDetail::GetMessageDetailL( TMsvId aMessageId, |
|
72 CMessageDetailInfo*& aMessageDetail ) |
|
73 { |
|
74 iMessageId = aMessageId; |
|
75 |
|
76 ProcessRequestL(); // Client can get the results by calling the functions |
|
77 aMessageDetail = iMessageDetail; |
|
78 iMessageDetail = NULL; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Extracts the message body and attachment information, if any. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CMessageDetail::ProcessRequestL() |
|
86 { |
|
87 CMsvEntry * messageEntry = iServerSession.GetEntryL( iMessageId ); |
|
88 CleanupStack::PushL(messageEntry); |
|
89 |
|
90 if ( messageEntry->Entry().iMtm != KSenduiMtmSmsUid && |
|
91 messageEntry->Entry().iMtm != KSenduiMtmMmsUid ) |
|
92 { |
|
93 User::Leave( KErrNotSupported ); |
|
94 } |
|
95 |
|
96 iMessageDetail = CMessageDetailInfo::NewL(); |
|
97 iMessageDetail->SetMessageId( iMessageId ); |
|
98 |
|
99 CMsvStore * messageStore = messageEntry->ReadStoreL(); |
|
100 CleanupStack::PushL( messageStore ); |
|
101 |
|
102 |
|
103 // Attachment ...... |
|
104 MMsvAttachmentManager& attachMgr = messageStore->AttachmentManagerL(); |
|
105 |
|
106 TInt count = attachMgr.AttachmentCount(); |
|
107 |
|
108 for ( TInt i=0;i<count;i++) |
|
109 { |
|
110 CMsvAttachment * attachment = attachMgr.GetAttachmentInfoL( i ); |
|
111 CleanupStack::PushL( attachment ); |
|
112 |
|
113 CMessageAttachInfo* element = CMessageAttachInfo::NewL(); |
|
114 CleanupStack::PushL( element ); |
|
115 |
|
116 element->SetFileHandle( attachMgr.GetAttachmentFileL( i ) ); |
|
117 element->SetNameL( attachment->AttachmentName() ); |
|
118 element->SetSize( attachment->Size() ); |
|
119 |
|
120 HBufC* tempMime = HBufC::NewLC( attachment->MimeType().Length() ); |
|
121 tempMime->Des().Copy( attachment->MimeType() ); |
|
122 element->SetMimeTypeL( *tempMime ); |
|
123 CleanupStack::PopAndDestroy( tempMime ); |
|
124 |
|
125 iMessageDetail->AddAttachmentInfoL( element ); |
|
126 CleanupStack::Pop( element ); |
|
127 CleanupStack::PopAndDestroy( attachment ); |
|
128 } |
|
129 |
|
130 // Bodytext |
|
131 if ( messageStore->HasBodyTextL() ) |
|
132 { |
|
133 // build a CRichText object to read in message body |
|
134 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
135 CleanupStack::PushL( paraFormatLayer ); |
|
136 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
137 CleanupStack::PushL( charFormatLayer ); |
|
138 CRichText* richText = CRichText::NewL( paraFormatLayer, charFormatLayer ); |
|
139 CleanupStack::PushL(richText); |
|
140 |
|
141 // Get the body text. |
|
142 messageStore->RestoreBodyTextL( *richText ); |
|
143 const TInt length = richText->DocumentLength(); |
|
144 iMessageDetail->SetBodyTextL( richText->Read( 0, length ) ); |
|
145 |
|
146 CleanupStack::PopAndDestroy( 3, paraFormatLayer ); |
|
147 } |
|
148 |
|
149 // Sender / Reciever info |
|
150 if ( messageEntry->Entry().iMtm == KSenduiMtmSmsUid ) |
|
151 { |
|
152 GetSmsSenderRecipientL(); |
|
153 } |
|
154 else if ( messageEntry->Entry().iMtm == KSenduiMtmMmsUid ) |
|
155 { |
|
156 GetMmsSenderRecipientL(); |
|
157 } |
|
158 |
|
159 CleanupStack::PopAndDestroy( 2, messageEntry ); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // Gets the Sender Recipient info for SMS |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CMessageDetail::GetSmsSenderRecipientL() |
|
167 { |
|
168 CClientMtmRegistry* clientMtmReg = NULL; |
|
169 clientMtmReg = CClientMtmRegistry::NewL( iServerSession ); |
|
170 CleanupStack::PushL( clientMtmReg ); |
|
171 |
|
172 CSmsClientMtm* smsMtm = NULL; |
|
173 smsMtm = static_cast<CSmsClientMtm*>( clientMtmReg->NewMtmL( KSenduiMtmSmsUid ) ); |
|
174 CleanupStack::PushL( smsMtm ); |
|
175 smsMtm->SwitchCurrentEntryL( iMessageId ); |
|
176 smsMtm->LoadMessageL(); |
|
177 const CMsvRecipientList &recipientList = smsMtm->AddresseeList(); |
|
178 |
|
179 TInt count = recipientList.Count(); |
|
180 for ( int pos = 0; pos < count; pos++ ) |
|
181 { |
|
182 iMessageDetail->AddRecipientL( recipientList[pos], recipientList.Type(pos) ); |
|
183 } |
|
184 |
|
185 const CSmsHeader& smsHeader = smsMtm->SmsHeader(); |
|
186 iMessageDetail->SetFromL( smsMtm->Entry().Entry().iDetails ); |
|
187 |
|
188 CleanupStack::PopAndDestroy( smsMtm ); |
|
189 CleanupStack::PopAndDestroy( clientMtmReg ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // Gets the Sender Recipient info for MMS |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CMessageDetail::GetMmsSenderRecipientL() |
|
197 { |
|
198 CClientMtmRegistry* clientMtmReg = NULL; |
|
199 clientMtmReg = CClientMtmRegistry::NewL( iServerSession ); |
|
200 CleanupStack::PushL( clientMtmReg ); |
|
201 |
|
202 CMmsClientMtm* mmsMtm = NULL; |
|
203 mmsMtm = static_cast<CMmsClientMtm*>( clientMtmReg->NewMtmL( KUidMsgTypeMultimedia ) ); |
|
204 CleanupStack::PushL( mmsMtm ); |
|
205 mmsMtm->SwitchCurrentEntryL( iMessageId ); |
|
206 mmsMtm->LoadMessageL(); |
|
207 const CMsvRecipientList &recipientList = mmsMtm->AddresseeList(); |
|
208 |
|
209 TInt count = recipientList.Count(); |
|
210 for ( int pos = 0; pos < count; pos++ ) |
|
211 { |
|
212 iMessageDetail->AddRecipientL( recipientList[pos], recipientList.Type(pos) ); |
|
213 } |
|
214 |
|
215 iMessageDetail->SetFromL( mmsMtm->Sender() ); |
|
216 |
|
217 CleanupStack::PopAndDestroy( mmsMtm ); |
|
218 CleanupStack::PopAndDestroy( clientMtmReg ); |
|
219 } |
|
220 |