1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 |
|
18 //SYSTEM INCLUDES |
|
19 #include <e32cmn.h> |
|
20 #include <mtclreg.h> |
|
21 #include <mtclbase.h> |
|
22 #include <msvids.h> |
|
23 #include <txtetext.h> |
|
24 #include <txtrich.h> |
|
25 #include <txtfmlyr.h> |
|
26 |
|
27 #include <smsclnt.h> |
|
28 #include "debugtraces.h" |
|
29 |
|
30 #include <QDateTime> |
|
31 |
|
32 #include <csmsemailfields.h> |
|
33 //USER INCLUDES |
|
34 #include "s60qconversions.h" |
|
35 #include "convergedmessageaddress.h" |
|
36 #include "convergedmessage.h" |
|
37 |
|
38 #include "unismsdataplugin_p.h" |
|
39 #include "sessioneventhandler.h" |
|
40 |
|
41 #define KSmsMtmUidValue 0x1000102C |
|
42 const TUid KSmsMtmUid = |
|
43 {KSmsMtmUidValue}; |
|
44 _LIT(KUnixEpoch, "19700000:000000.000000"); |
|
45 |
|
46 //--------------------------------------------------------------- |
|
47 // UniSMSDataPluginPrivate::~UniSMSDataPluginPrivate |
|
48 // @see header |
|
49 //--------------------------------------------------------------- |
|
50 UniSMSDataPluginPrivate::~UniSMSDataPluginPrivate() |
|
51 { |
|
52 q_ptr = NULL; |
|
53 delete iSmsClient; |
|
54 delete iMtmReg; |
|
55 delete iSessionHandler; |
|
56 delete iMSession; |
|
57 } |
|
58 |
|
59 //--------------------------------------------------------------- |
|
60 // UniSMSDataPluginPrivate::UniSMSDataPluginPrivate |
|
61 // @see header |
|
62 //--------------------------------------------------------------- |
|
63 UniSMSDataPluginPrivate::UniSMSDataPluginPrivate(UniSMSDataPlugin* plugin) : |
|
64 iMSession(NULL), |
|
65 iMtmReg(NULL), |
|
66 iSmsClient(NULL), |
|
67 q_ptr(plugin), |
|
68 iSessionHandler(NULL) |
|
69 { |
|
70 iSessionHandler = new SessionEventHandler(); |
|
71 iMSession = CMsvSession::OpenSyncL(*iSessionHandler); |
|
72 iSessionHandler->start(); |
|
73 done = EFalse; |
|
74 } |
|
75 |
|
76 void UniSMSDataPluginPrivate::initL() |
|
77 { |
|
78 |
|
79 iMtmReg = CClientMtmRegistry::NewL(*iMSession); |
|
80 TMsvSelectionOrdering ordering; |
|
81 |
|
82 CMsvEntry* root = CMsvEntry::NewL(*iMSession, |
|
83 KMsvRootIndexEntryId, |
|
84 ordering); |
|
85 CleanupStack::PushL(root); |
|
86 |
|
87 TMsvId firstId; |
|
88 TRAPD(err, TSmsUtilities::ServiceIdL(*root,firstId)); |
|
89 |
|
90 if (err == KErrNotFound) |
|
91 { |
|
92 TMsvEntry entry; |
|
93 entry.iMtm = KUidMsgTypeSMS; |
|
94 entry.iType = KUidMsvServiceEntry; |
|
95 entry.SetReadOnly(EFalse); |
|
96 entry.SetVisible(EFalse); |
|
97 entry.iDate.UniversalTime(); |
|
98 entry.iDetails.Set(_L("SMS Service")); |
|
99 |
|
100 root->SetEntryL(KMsvRootIndexEntryId); |
|
101 root->CreateL(entry); |
|
102 } |
|
103 |
|
104 CleanupStack::PopAndDestroy(root); |
|
105 iSmsClient = static_cast<CSmsClientMtm*> (iMtmReg->NewMtmL(KSmsMtmUid)); |
|
106 done = ETrue; |
|
107 iMessageId = 0; |
|
108 } |
|
109 |
|
110 //--------------------------------------------------------------- |
|
111 // UniSMSDataPluginPrivate::reset |
|
112 // @see header |
|
113 //--------------------------------------------------------------- |
|
114 void UniSMSDataPluginPrivate::reset() |
|
115 { |
|
116 } |
|
117 |
|
118 //--------------------------------------------------------------- |
|
119 // UniSMSDataPluginPrivate::setMessageId |
|
120 // @see header |
|
121 //--------------------------------------------------------------- |
|
122 int UniSMSDataPluginPrivate::setMessageId(int mId) |
|
123 { |
|
124 TInt error = KErrNone; |
|
125 TRAP(error, setMessageIdL(mId)); |
|
126 return error; |
|
127 |
|
128 } |
|
129 |
|
130 void UniSMSDataPluginPrivate::setMessageIdL(int mId) |
|
131 { |
|
132 if (done == EFalse) |
|
133 { |
|
134 initL(); |
|
135 } |
|
136 if (iMessageId != mId) |
|
137 { |
|
138 iMessageId = (TMsvId) mId; |
|
139 iSmsClient->SwitchCurrentEntryL(iMessageId); |
|
140 iSmsClient->LoadMessageL(); |
|
141 } |
|
142 |
|
143 } |
|
144 |
|
145 //--------------------------------------------------------------- |
|
146 // UniSMSDataPluginPrivate::body |
|
147 // @see header |
|
148 //--------------------------------------------------------------- |
|
149 void UniSMSDataPluginPrivate::body(QString& aBodyText) |
|
150 { |
|
151 CRichText& textBody = iSmsClient->Body(); |
|
152 TInt len = textBody.DocumentLength(); |
|
153 HBufC* buf = HBufC::NewL(len); |
|
154 TPtr bufPtr = buf->Des(); |
|
155 textBody.ExtractSelectively(bufPtr, 0, len, CPlainText::EExtractAll); |
|
156 aBodyText = S60QConversions::s60DescToQString(*buf); |
|
157 delete buf; |
|
158 } |
|
159 |
|
160 //--------------------------------------------------------------- |
|
161 // UniSMSDataPluginPrivate::messageSize |
|
162 // @see header |
|
163 //--------------------------------------------------------------- |
|
164 qint32 UniSMSDataPluginPrivate::messageSize() |
|
165 { |
|
166 return iSmsClient->Entry().Entry().iSize; |
|
167 } |
|
168 |
|
169 //--------------------------------------------------------------- |
|
170 // UniSMSDataPluginPrivate::toRecipientList |
|
171 // @see header |
|
172 //--------------------------------------------------------------- |
|
173 void UniSMSDataPluginPrivate::toRecipientList( |
|
174 ConvergedMessageAddressList& mAddressList) |
|
175 { |
|
176 TPtrC name; |
|
177 TPtrC address; |
|
178 // Get the recipient list from the client mtm |
|
179 const CMsvRecipientList& smsRecipients = iSmsClient->AddresseeList(); |
|
180 |
|
181 for (TInt id = 0; id < smsRecipients.Count(); ++id) |
|
182 { |
|
183 extractNameAndAddress(smsRecipients[id], name, address); |
|
184 // populate address |
|
185 ConvergedMessageAddress |
|
186 * messageAddress = |
|
187 new ConvergedMessageAddress(S60QConversions::s60DescToQString(address), |
|
188 S60QConversions::s60DescToQString(name)); |
|
189 mAddressList.append(messageAddress); |
|
190 } |
|
191 |
|
192 const CSmsEmailFields& emailFields = iSmsClient->SmsHeader().EmailFields(); |
|
193 // check if it is a EOS |
|
194 if (emailFields.HasAddress()) |
|
195 { |
|
196 const MDesCArray& emailRecipients = emailFields.Addresses(); |
|
197 for (TInt id = 0; id < emailRecipients.MdcaCount(); ++id) |
|
198 { |
|
199 extractNameAndAddress(emailRecipients.MdcaPoint(id), name, address); |
|
200 ConvergedMessageAddress |
|
201 * messageAddress = |
|
202 new ConvergedMessageAddress(S60QConversions::s60DescToQString(address), |
|
203 S60QConversions::s60DescToQString(name)); |
|
204 mAddressList.append(messageAddress); |
|
205 } |
|
206 } |
|
207 |
|
208 } |
|
209 |
|
210 //--------------------------------------------------------------- |
|
211 // UniSMSDataPluginPrivate::fromAddress |
|
212 // @see header |
|
213 //--------------------------------------------------------------- |
|
214 void UniSMSDataPluginPrivate::fromAddress(QString& messageAddress) |
|
215 { |
|
216 CPlainText* pText = CPlainText::NewL(); |
|
217 CleanupStack::PushL(pText); |
|
218 |
|
219 CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *pText); |
|
220 CleanupStack::PushL(smsHeader); |
|
221 |
|
222 CMsvEntry *cEntry = CMsvEntry::NewL(iSmsClient->Session(), |
|
223 iMessageId, |
|
224 TMsvSelectionOrdering()); |
|
225 CleanupStack::PushL(cEntry); |
|
226 |
|
227 CMsvStore* store = cEntry->ReadStoreL(); |
|
228 CleanupStack::PushL(store); |
|
229 |
|
230 smsHeader->RestoreL(*store); |
|
231 |
|
232 messageAddress |
|
233 = S60QConversions::s60DescToQString(smsHeader->FromAddress()); |
|
234 CleanupStack::PopAndDestroy(4, pText); |
|
235 } |
|
236 |
|
237 //--------------------------------------------------------------- |
|
238 // UniSMSDataPluginPrivate::timeStamp |
|
239 // @see header |
|
240 //--------------------------------------------------------------- |
|
241 int UniSMSDataPluginPrivate::timeStamp() |
|
242 { |
|
243 QDateTime retTimeStamp; |
|
244 TTime timeStamp = iSmsClient->Entry().Entry().iDate; |
|
245 TTime unixEpoch(KUnixEpoch); |
|
246 TTimeIntervalSeconds seconds; |
|
247 timeStamp.SecondsFrom(unixEpoch, seconds); |
|
248 return seconds.Int(); |
|
249 } |
|
250 |
|
251 //--------------------------------------------------------------- |
|
252 // UniSMSDataPluginPrivate::session |
|
253 // @see header |
|
254 //--------------------------------------------------------------- |
|
255 CMsvSession* UniSMSDataPluginPrivate::session() |
|
256 { |
|
257 return iMSession; |
|
258 } |
|
259 |
|
260 //--------------------------------------------------------------- |
|
261 // UniSMSDataPluginPrivate::extractNameAndAddress |
|
262 // @see header |
|
263 //--------------------------------------------------------------- |
|
264 void UniSMSDataPluginPrivate::extractNameAndAddress(const TDesC& aMsvAddress, |
|
265 TPtrC& aName, |
|
266 TPtrC& aAddress) |
|
267 { |
|
268 // For address information separation (start) |
|
269 const TUint KMsgSmsAddressStartChar('<'); |
|
270 |
|
271 // For address information separation (end) |
|
272 const TUint KMsgSmsAddressEndChar('>'); |
|
273 |
|
274 TInt addressStart = aMsvAddress.LocateReverse(KMsgSmsAddressStartChar); |
|
275 TInt addressEnd = aMsvAddress.LocateReverse(KMsgSmsAddressEndChar); |
|
276 |
|
277 if (addressStart != KErrNotFound && addressEnd != KErrNotFound |
|
278 && addressEnd > addressStart) |
|
279 { |
|
280 // verified address, will be used as selected from contacts manager |
|
281 aName.Set(aMsvAddress.Ptr(), addressStart); |
|
282 aAddress.Set(aMsvAddress.Mid(addressStart + 1).Ptr(), (addressEnd |
|
283 - addressStart) - 1); |
|
284 if (!aAddress.Length()) |
|
285 { |
|
286 aAddress.Set(aName); |
|
287 aName.Set(KNullDesC); // empty string |
|
288 } |
|
289 } |
|
290 else |
|
291 { |
|
292 // unverified string, will be used as entered in the header field |
|
293 aName.Set(KNullDesC); // empty string |
|
294 aAddress.Set(aMsvAddress.Ptr(), aMsvAddress.Length()); // a whole string to address |
|
295 } |
|
296 |
|
297 if (aName.CompareF(aAddress) == 0) |
|
298 { |
|
299 aName.Set(KNullDesC); // empty string |
|
300 } |
|
301 } |
|
302 |
|