19 #include <xqconversions.h> |
19 #include <xqconversions.h> |
20 #include "msgnotifier_p.h" |
20 #include "msgnotifier_p.h" |
21 #include <ccsrequesthandler.h> |
21 #include <ccsrequesthandler.h> |
22 #include <ccsconversationentry.h> |
22 #include <ccsconversationentry.h> |
23 #include <ccsclientconversation.h> |
23 #include <ccsclientconversation.h> |
24 |
24 #include "msgcontacthandler.h" |
25 #include <msvids.h> |
25 #include <msvids.h> |
26 #include <mmsconst.h> |
26 #include <mmsconst.h> |
|
27 #include <smuthdr.h> |
27 #include <SendUiConsts.h> |
28 #include <SendUiConsts.h> |
28 #include <msvsearchsortquery.h> |
29 #include <msvsearchsortquery.h> |
29 #include <msvsearchsortoperation.h> |
30 #include <msvsearchsortoperation.h> |
|
31 #include <tmsvsmsentry.h> |
|
32 #include <txtrich.h> |
|
33 #include <ssm/ssmdomaindefs.h> |
|
34 #include "debugtraces.h" |
30 |
35 |
31 // CONSTANTS |
36 // CONSTANTS |
|
37 _LIT(KUnixEpoch, "19700000:000000.000000"); |
32 |
38 |
33 // ================= MEMBER FUNCTIONS ======================= |
39 // ================= MEMBER FUNCTIONS ======================= |
34 |
40 |
35 // --------------------------------------------------------- |
41 // --------------------------------------------------------- |
36 // Default constructor. |
42 // Default constructor. |
37 // --------------------------------------------------------- |
43 // --------------------------------------------------------- |
38 // |
44 // |
39 MsgStoreHandler::MsgStoreHandler(MsgNotifierPrivate* notifier, CCSRequestHandler* aCvServer) : |
45 MsgStoreHandler::MsgStoreHandler(MsgNotifierPrivate* notifier, CCSRequestHandler* aCvServer) : |
40 iMsvSession(NULL), iNotifier(notifier), iRequestHandler(aCvServer) |
46 CActive(EPriorityStandard), iMsvSession(NULL), iNotifier(notifier), iRequestHandler(aCvServer) |
41 { |
47 { |
42 InitL(); |
48 InitL(); |
43 } |
49 } |
44 |
50 |
45 // --------------------------------------------------------- |
51 // --------------------------------------------------------- |
46 // Destructor. |
52 // Destructor. |
47 // --------------------------------------------------------- |
53 // --------------------------------------------------------- |
48 // |
54 // |
49 MsgStoreHandler::~MsgStoreHandler() |
55 MsgStoreHandler::~MsgStoreHandler() |
50 { |
56 { |
|
57 Cancel(); |
|
58 iStateAwareSession.Close(); |
|
59 |
51 if (iMsvEntry) { |
60 if (iMsvEntry) { |
52 delete iMsvEntry; |
61 delete iMsvEntry; |
53 iMsvEntry = NULL; |
62 iMsvEntry = NULL; |
54 } |
63 } |
55 |
64 |
74 iMsvSession = CMsvSession::OpenSyncL(*this); |
83 iMsvSession = CMsvSession::OpenSyncL(*this); |
75 iMsvEntry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
84 iMsvEntry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
76 iMsvEntry->AddObserverL(*this); |
85 iMsvEntry->AddObserverL(*this); |
77 |
86 |
78 iFailedMessages = new (ELeave) CMsvEntrySelection; |
87 iFailedMessages = new (ELeave) CMsvEntrySelection; |
79 } |
88 |
80 |
89 User::LeaveIfError(iStateAwareSession.Connect(KSM2GenMiddlewareDomain3)); |
|
90 CActiveScheduler::Add(this); |
|
91 |
|
92 TSsmState ssmState = iStateAwareSession.State(); |
|
93 |
|
94 if (ssmState.MainState() != ESsmNormal) |
|
95 { |
|
96 iStateAwareSession.RequestStateNotification(iStatus); |
|
97 SetActive(); |
|
98 } |
|
99 else |
|
100 { |
|
101 RunL(); |
|
102 } |
|
103 |
|
104 } |
|
105 |
|
106 void MsgStoreHandler::RunL() |
|
107 { |
|
108 TSsmState ssmState = iStateAwareSession.State(); |
|
109 if (ssmState.MainState() != ESsmNormal) |
|
110 { |
|
111 iStateAwareSession.RequestStateNotification(iStatus); |
|
112 SetActive(); |
|
113 } |
|
114 else |
|
115 { |
|
116 //Create the query/operation object |
|
117 CMsvSearchSortOperation *operation = CMsvSearchSortOperation::NewL(*iMsvSession); |
|
118 CleanupStack::PushL(operation); |
|
119 CMsvSearchSortQuery *query = CMsvSearchSortQuery::NewL(); |
|
120 CleanupStack::PushL(query); |
|
121 |
|
122 //set the query options |
|
123 query->SetParentId(KMsvGlobalInBoxIndexEntryId); |
|
124 query->SetResultType(EMsvResultAsTMsvId); |
|
125 query->AddSearchOptionL(EMsvMtmTypeUID, KSenduiMtmSmsUidValue, EMsvEqual); |
|
126 query->AddSearchOptionL(EMsvUnreadMessages, ETrue); |
|
127 CleanupStack::Pop(query); |
|
128 |
|
129 CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC(); |
|
130 //ownership of Query transferred to Operation |
|
131 operation->RequestL(query, EFalse, wait->iStatus); |
|
132 wait->Start(); |
|
133 |
|
134 //Get No of entries |
|
135 RArray<TMsvId> messageArray; |
|
136 operation->GetResultsL(messageArray); |
|
137 |
|
138 CMsvEntry* entry = NULL; |
|
139 for (TInt i = 0; i < messageArray.Count(); ++i) |
|
140 { |
|
141 entry = iMsvSession->GetEntryL(messageArray[i]); |
|
142 TMsvSmsEntry smsEntry = entry->Entry(); |
|
143 TSmsDataCodingScheme::TSmsClass classType(TSmsDataCodingScheme::ESmsClass0); |
|
144 if (smsEntry.Class(classType)) |
|
145 { |
|
146 HandleClass0SmsL(entry, smsEntry.Id()); |
|
147 } |
|
148 else |
|
149 { |
|
150 delete entry; |
|
151 entry = NULL; |
|
152 } |
|
153 } |
|
154 messageArray.Close(); |
|
155 CleanupStack::PopAndDestroy(2, operation); |
|
156 } |
|
157 |
|
158 } |
|
159 |
|
160 void MsgStoreHandler::DoCancel() |
|
161 { |
|
162 iStateAwareSession.RequestStateNotificationCancel(); |
|
163 } |
81 // --------------------------------------------------------- |
164 // --------------------------------------------------------- |
82 // MsgStoreHandler::HandleSessionEventL() |
165 // MsgStoreHandler::HandleSessionEventL() |
83 // --------------------------------------------------------- |
166 // --------------------------------------------------------- |
84 // |
167 // |
85 void MsgStoreHandler::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) |
168 void MsgStoreHandler::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) |
100 if (!(parent == KMsvGlobalOutBoxIndexEntryIdValue || parent == KMsvGlobalInBoxIndexEntryIdValue) |
183 if (!(parent == KMsvGlobalOutBoxIndexEntryIdValue || parent == KMsvGlobalInBoxIndexEntryIdValue) |
101 && aEvent != EMsvEntriesChanged) { |
184 && aEvent != EMsvEntriesChanged) { |
102 return; |
185 return; |
103 } |
186 } |
104 |
187 |
|
188 // check for incoming class 0 sms |
|
189 if (parent == KMsvGlobalInBoxIndexEntryIdValue && aEvent == EMsvEntriesChanged) { |
|
190 CMsvEntry* inboxEntry = iMsvSession->GetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
191 for (TInt i = 0; i < selection->Count(); ++i) { |
|
192 TMsvEntry entry = inboxEntry->ChildDataL(selection->At(i)); |
|
193 if (KSenduiMtmSmsUidValue == entry.iMtm.iUid) { |
|
194 CMsvEntry* msgEntry = iMsvSession->GetEntryL(entry.Id()); |
|
195 TMsvSmsEntry smsEntry = msgEntry->Entry(); |
|
196 TSmsDataCodingScheme::TSmsClass classType(TSmsDataCodingScheme::ESmsClass0); |
|
197 |
|
198 if (smsEntry.Class(classType) && smsEntry.Unread()) |
|
199 { |
|
200 HandleClass0SmsL(msgEntry, smsEntry.Id()); |
|
201 } |
|
202 else |
|
203 { |
|
204 delete msgEntry; |
|
205 msgEntry = NULL; |
|
206 } |
|
207 } |
|
208 |
|
209 } // for (TInt i = 0; i < selection->Count(); ++i) |
|
210 delete inboxEntry; |
|
211 } |
105 //Handling for outbox entries |
212 //Handling for outbox entries |
106 if (parent == KMsvGlobalOutBoxIndexEntryIdValue) { |
213 else if (parent == KMsvGlobalOutBoxIndexEntryIdValue) { |
107 CMsvEntry* rootEntry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
214 CMsvEntry* rootEntry = iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
108 |
215 |
109 for (TInt i = 0; i < selection->Count(); ++i) { |
216 for (TInt i = 0; i < selection->Count(); ++i) { |
110 TMsvEntry entry = rootEntry->ChildDataL(selection->At(i)); |
217 TMsvEntry entry = rootEntry->ChildDataL(selection->At(i)); |
111 |
218 |
164 } |
271 } |
165 |
272 |
166 } |
273 } |
167 |
274 |
168 // --------------------------------------------------------- |
275 // --------------------------------------------------------- |
|
276 // MsgStoreHandler::HandleClass0SmsL() |
|
277 // --------------------------------------------------------- |
|
278 // |
|
279 void MsgStoreHandler::HandleClass0SmsL(CMsvEntry* aMsgEntry, TMsvId aMsgId) |
|
280 { |
|
281 CleanupStack::PushL(aMsgEntry); |
|
282 |
|
283 CMsvStore* store = aMsgEntry->ReadStoreL(); |
|
284 CleanupStack::PushL(store); |
|
285 |
|
286 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
287 CleanupStack::PushL(paraFormatLayer); |
|
288 |
|
289 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
290 CleanupStack::PushL(charFormatLayer); |
|
291 |
|
292 CRichText* richText = CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
293 CleanupStack::PushL(richText); |
|
294 |
|
295 store->RestoreBodyTextL(*richText); |
|
296 |
|
297 TInt len = richText->DocumentLength(); |
|
298 HBufC* bufBody = HBufC::NewLC(len * 2); |
|
299 |
|
300 // Get Body content of SMS message |
|
301 TPtr bufBodyPtr = bufBody->Des(); |
|
302 richText->Extract(bufBodyPtr, 0, len); |
|
303 |
|
304 //convert bufbody to qstring.. |
|
305 QString body = XQConversions::s60DescToQString(*bufBody); |
|
306 |
|
307 Class0Info class0Info; |
|
308 |
|
309 class0Info.body = body; |
|
310 CleanupStack::PopAndDestroy(bufBody); |
|
311 |
|
312 // Get From address of SMS message |
|
313 CPlainText* nullString = CPlainText::NewL(); |
|
314 CleanupStack::PushL(nullString); |
|
315 |
|
316 CSmsHeader* smsheader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *nullString); |
|
317 CleanupStack::PushL(smsheader); |
|
318 smsheader->RestoreL(*store); |
|
319 |
|
320 QString address = XQConversions::s60DescToQString(smsheader->FromAddress()); |
|
321 class0Info.address = address; |
|
322 |
|
323 // Get alias of SMS message |
|
324 QString alias; |
|
325 int count; |
|
326 MsgContactHandler::resolveContactDisplayName(address, alias, count); |
|
327 class0Info.alias = alias; |
|
328 |
|
329 // Get timestamp of SMS message |
|
330 QDateTime timeStamp; |
|
331 TTime time = aMsgEntry->Entry().iDate; |
|
332 TTime unixEpoch(KUnixEpoch); |
|
333 TTimeIntervalSeconds seconds; |
|
334 time.SecondsFrom(unixEpoch, seconds); |
|
335 timeStamp.setTime_t(seconds.Int()); |
|
336 |
|
337 const QString times = timeStamp.toString("dd/MM/yy hh:mm ap"); |
|
338 class0Info.time = times; |
|
339 |
|
340 class0Info.messageId = aMsgId; |
|
341 CleanupStack::PopAndDestroy(7); |
|
342 aMsgEntry = NULL; |
|
343 |
|
344 // Show the SMS message.. |
|
345 iNotifier->ShowClass0Message(class0Info); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------- |
169 // MsgStoreHandler::HandleEntryEventL() |
349 // MsgStoreHandler::HandleEntryEventL() |
170 // --------------------------------------------------------- |
350 // --------------------------------------------------------- |
171 |
351 |
172 void MsgStoreHandler::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, |
352 void MsgStoreHandler::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, |
173 TAny* /*aArg3*/) |
353 TAny* /*aArg3*/) |