author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 00:13:15 +0300 | |
changeset 72 | 6f657153cbc5 |
parent 52 | 12db4185673b |
permissions | -rw-r--r-- |
31 | 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:Message send functionality handler. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include "msgsendutil.h" |
|
19 |
#include "debugtraces.h" |
|
20 |
// plugin loader and plugin interface |
|
21 |
#include "unieditorpluginloader.h" |
|
22 |
#include "unieditorplugininterface.h" |
|
23 |
// general editor utilities |
|
24 |
#include "UniEditorGenUtils.h" |
|
25 |
||
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
26 |
#include <xqconversions.h> |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
27 |
#include <commonphoneparser.h> // commonengine |
31 | 28 |
|
29 |
//--------------------------------------------------------------- |
|
30 |
// MsgSendUtil::MsgSendUtil |
|
31 |
// Constructor |
|
32 |
//-------------------------------------------------------------- |
|
33 |
MsgSendUtil::MsgSendUtil(QObject* parentObject) : |
|
34 |
QObject(parentObject), mPluginLoader(0), mUniEditorGenUtils(0) |
|
35 |
{ |
|
36 |
// Load Plugins for send |
|
37 |
mPluginLoader = new UniEditorPluginLoader(this); |
|
52
12db4185673b
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
38 |
mUniEditorGenUtils = q_check_ptr(new UniEditorGenUtils()); |
31 | 39 |
} |
40 |
||
41 |
//--------------------------------------------------------------- |
|
42 |
// MsgSendUtil::~MsgSendUtil |
|
43 |
// Desctructor |
|
44 |
//-------------------------------------------------------------- |
|
45 |
MsgSendUtil::~MsgSendUtil() |
|
46 |
{ |
|
47 |
if( mUniEditorGenUtils) |
|
48 |
{ |
|
49 |
delete mUniEditorGenUtils; |
|
50 |
mUniEditorGenUtils = NULL; |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
//--------------------------------------------------------------- |
|
55 |
// MsgSendUtil::saveToDrafts |
|
56 |
// @see header file |
|
57 |
//-------------------------------------------------------------- |
|
58 |
TMsvId MsgSendUtil::saveToDrafts(ConvergedMessage& msg) |
|
59 |
{ |
|
60 |
QDEBUG_WRITE("START MsgSendUtil::saveToDraft"); |
|
61 |
bool emailOverSmsSupported = false; |
|
62 |
TMsvId id = -1; |
|
63 |
||
64 |
if( checkEmailOverSms(msg, emailOverSmsSupported) |
|
65 |
&& checkMaxRecipientCount(msg) |
|
66 |
&& checkMaxMsgSizeLimit(msg) ) |
|
67 |
{ |
|
68 |
UniEditorPluginInterface* pluginInterface = |
|
69 |
mPluginLoader->getUniEditorPlugin(msg.messageType()); |
|
70 |
id = pluginInterface->convertTo(&msg); |
|
71 |
} |
|
72 |
QDEBUG_WRITE("END MsgSendUtil::saveToDraft"); |
|
73 |
return id; |
|
74 |
} |
|
75 |
||
76 |
//--------------------------------------------------------------- |
|
77 |
// MsgSendUtil::send |
|
78 |
// @see header file |
|
79 |
//-------------------------------------------------------------- |
|
80 |
int MsgSendUtil::send(ConvergedMessage& msg) |
|
81 |
{ |
|
82 |
QDEBUG_WRITE("START MsgSendUtil::send"); |
|
83 |
int retValue = KErrGeneral; |
|
84 |
bool emailOverSmsSupported = false; |
|
85 |
long int id = saveToDrafts(msg); |
|
86 |
if(id != -1) |
|
87 |
{ |
|
88 |
checkEmailOverSms(msg, emailOverSmsSupported); |
|
89 |
UniEditorPluginInterface* pluginInterface = |
|
90 |
mPluginLoader->getUniEditorPlugin(msg.messageType()); |
|
91 |
if( validateService(pluginInterface, emailOverSmsSupported) ) |
|
92 |
{ |
|
93 |
pluginInterface->send(id); |
|
94 |
retValue = KErrNone; |
|
95 |
} |
|
96 |
else |
|
97 |
{ |
|
98 |
//Delete the entry created in drafts as we are switching to settings |
|
99 |
pluginInterface->deleteDraftsEntry(id); |
|
100 |
retValue = KErrNotFound; |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
QDEBUG_WRITE("END MsgSendUtil::send"); |
|
105 |
return retValue; |
|
106 |
} |
|
107 |
||
108 |
//--------------------------------------------------------------- |
|
72
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
109 |
// MsgSendUtil::isValidAddress |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
110 |
// @see header file |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
111 |
//-------------------------------------------------------------- |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
112 |
bool MsgSendUtil::isValidAddress(const QString &address) |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
113 |
{ |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
114 |
bool isValid = false; |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
115 |
if (!address.isEmpty()) { |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
116 |
|
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
117 |
HBufC *tempAddr = XQConversions::qStringToS60Desc(address); |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
118 |
|
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
119 |
// 1. perform number validation |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
120 |
isValid = CommonPhoneParser::IsValidPhoneNumber(*tempAddr, CommonPhoneParser::ESMSNumber); |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
121 |
|
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
122 |
// 2. if number validity fails, then perform email addr validation |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
123 |
if (!isValid) { |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
124 |
// additional check for MMS only |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
125 |
UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils); |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
126 |
isValid = genUtils->IsValidEmailAddress(*tempAddr); |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
127 |
delete genUtils; |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
128 |
} |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
129 |
delete tempAddr; |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
130 |
} |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
131 |
return isValid; |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
132 |
} |
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
133 |
|
6f657153cbc5
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
52
diff
changeset
|
134 |
//--------------------------------------------------------------- |
31 | 135 |
// MsgSendUtil::checkEmailOverSms |
136 |
// @see header file |
|
137 |
//-------------------------------------------------------------- |
|
138 |
bool MsgSendUtil::checkEmailOverSms(ConvergedMessage& msg, bool& emailOverSmsSupported) |
|
139 |
{ |
|
140 |
QDEBUG_WRITE("START MsgSendUtil::checkEmailOverSms"); |
|
141 |
if (msg.messageType() == ConvergedMessage::Sms) |
|
142 |
{ |
|
143 |
bool emailAddrPresent = false; |
|
144 |
TRAPD(err,emailAddrPresent = |
|
145 |
mUniEditorGenUtils->VerifyEmailAddressesL(msg.toAddressList())); |
|
146 |
if (err == KErrNone && emailAddrPresent) |
|
147 |
{ |
|
148 |
TRAPD(err, emailOverSmsSupported = mUniEditorGenUtils->AcceptEmailAddressesL()); |
|
149 |
if (err == KErrNone && !emailOverSmsSupported) |
|
150 |
{ |
|
151 |
//TODO if the note is to be shown or if we have to convert the msg type |
|
152 |
msg.setMessageType(ConvergedMessage::Mms); |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
// if control is here, then checks are ok |
|
157 |
QDEBUG_WRITE("END MsgSendUtil::checkEmailOverSms"); |
|
158 |
return true; |
|
159 |
} |
|
160 |
||
161 |
//--------------------------------------------------------------- |
|
162 |
// MsgSendUtil::checkMaxRecipientCount |
|
163 |
// @see header file |
|
164 |
//-------------------------------------------------------------- |
|
165 |
bool MsgSendUtil::checkMaxRecipientCount(ConvergedMessage& msg) |
|
166 |
{ |
|
167 |
QDEBUG_WRITE("START MsgSendUtil::checkMaxRecipientCount"); |
|
168 |
bool result = true; |
|
169 |
// max recipient count check for sms |
|
170 |
if (msg.messageType() == ConvergedMessage::Sms) |
|
171 |
{ |
|
172 |
int maxSmsRecipientsCount = KDefaultSmsRecipients; |
|
173 |
TRAP_IGNORE(maxSmsRecipientsCount = mUniEditorGenUtils->MaxSmsRecipientsL()); |
|
174 |
if (msg.toAddressList().count() > maxSmsRecipientsCount) |
|
175 |
{ |
|
176 |
//TODO show a note to user to delete some recipients |
|
177 |
//TODO or convert msg to MMS ?? |
|
178 |
result = false; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
// max recipient count check for mms |
|
183 |
if (msg.messageType() == ConvergedMessage::Mms) |
|
184 |
{ |
|
185 |
int maxMmsRecipientsCount = KDefaultMmsRecipients; |
|
186 |
TRAP_IGNORE(maxMmsRecipientsCount = mUniEditorGenUtils->MaxMmsRecipientsL()); |
|
187 |
if ( ( msg.toAddressList().count() |
|
188 |
+ msg.ccAddressList().count() |
|
189 |
+ msg.bccAddressList().count() ) > maxMmsRecipientsCount ) |
|
190 |
{ |
|
191 |
//TODO show a note to user to delete some recipients |
|
192 |
result = false; |
|
193 |
} |
|
194 |
} |
|
195 |
// if control is here, then all checks are ok |
|
196 |
QDEBUG_WRITE("END MsgSendUtil::checkMaxRecipientCount"); |
|
197 |
return result; |
|
198 |
} |
|
199 |
||
200 |
//--------------------------------------------------------------- |
|
201 |
// MsgSendUtil::checkMaxMsgSizeLimit |
|
202 |
// @see header file |
|
203 |
//-------------------------------------------------------------- |
|
204 |
bool MsgSendUtil::checkMaxMsgSizeLimit(ConvergedMessage& msg) |
|
205 |
{ |
|
206 |
QDEBUG_WRITE("START MsgSendUtil::checkMaxMsgSizeLimit"); |
|
207 |
bool result = true; |
|
208 |
// msg size limit check for sms |
|
209 |
if (msg.messageType() == ConvergedMessage::Sms) |
|
210 |
{ |
|
211 |
int maxSmsMsgSize = KFirstNormalSmsLength; |
|
212 |
TRAP_IGNORE(maxSmsMsgSize = mUniEditorGenUtils->MaxSmsMsgSizeL()); |
|
213 |
if (getSmsMsgSize(msg) > maxSmsMsgSize) |
|
214 |
{ |
|
215 |
// TODO: Msg size exceeded. Either convert to MMS?? or stall. |
|
216 |
result = false; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
// msg size limit check for mms |
|
221 |
if (msg.messageType() == ConvergedMessage::Mms) |
|
222 |
{ |
|
223 |
int maxMmsMsgSize = KDefaultMaxSize; |
|
224 |
TRAP_IGNORE(maxMmsMsgSize = mUniEditorGenUtils->MaxMmsMsgSizeL()); |
|
225 |
if (getMmsMsgSize(msg) > maxMmsMsgSize) |
|
226 |
{ |
|
227 |
// TODO: Show note and then give chance to user to delete content |
|
228 |
result = false; |
|
229 |
} |
|
230 |
} |
|
231 |
// if control is here, then all checks are ok |
|
232 |
QDEBUG_WRITE("END MsgSendUtil::checkMaxMsgSizeLimit"); |
|
233 |
return result; |
|
234 |
} |
|
235 |
||
236 |
//--------------------------------------------------------------- |
|
237 |
// MsgSendUtil::getSmsMsgSize |
|
238 |
// @see header file |
|
239 |
//-------------------------------------------------------------- |
|
240 |
int MsgSendUtil::getSmsMsgSize(ConvergedMessage& msg) |
|
241 |
{ |
|
242 |
QDEBUG_WRITE("START MsgSendUtil::getSmsMsgSize"); |
|
243 |
int totalMsgSize = 0; |
|
244 |
totalMsgSize += mUniEditorGenUtils->UTF8Size(msg.bodyText()) + |
|
245 |
mUniEditorGenUtils->UTF8Size(msg.subject()); |
|
246 |
bool ret = false; |
|
247 |
TRAP_IGNORE(ret = mUniEditorGenUtils->AcceptEmailAddressesL()); |
|
248 |
if (ret) |
|
249 |
{ |
|
250 |
int emailAddrLen = longestEmailAddressSize(msg.toAddressList()); |
|
251 |
if (emailAddrLen > 0) |
|
252 |
{ |
|
253 |
// 1 char is needed by recipient and subject separator |
|
254 |
totalMsgSize += emailAddrLen + 1; |
|
255 |
} |
|
256 |
} |
|
257 |
//TODO: attachment size calculation are missing (e.g vCard/vCal etc) |
|
258 |
||
259 |
QDEBUG_WRITE("END MsgSendUtil::getSmsMsgSize"); |
|
260 |
return totalMsgSize; |
|
261 |
} |
|
262 |
||
263 |
//--------------------------------------------------------------- |
|
264 |
// MsgSendUtil::longestEmailAddressSize |
|
265 |
// @see header file |
|
266 |
//-------------------------------------------------------------- |
|
267 |
int MsgSendUtil::longestEmailAddressSize(ConvergedMessageAddressList addrList) |
|
268 |
{ |
|
269 |
int count = addrList.count(); |
|
270 |
int longestEmailSize = 0; |
|
271 |
for(int i=0; i<count; i++) |
|
272 |
{ |
|
273 |
longestEmailSize = qMax(longestEmailSize, addrList.at(i)->address().length()); |
|
274 |
} |
|
275 |
return longestEmailSize; |
|
276 |
} |
|
277 |
||
278 |
//--------------------------------------------------------------- |
|
279 |
// MsgSendUtil::getMmsMsgSize |
|
280 |
// @see header file |
|
281 |
//-------------------------------------------------------------- |
|
282 |
int MsgSendUtil::getMmsMsgSize(ConvergedMessage& msg) |
|
283 |
{ |
|
284 |
QDEBUG_WRITE("START MsgSendUtil::getMmsMsgSize"); |
|
285 |
int totalMsgSize = 0; |
|
286 |
int textSize = mUniEditorGenUtils->UTF8Size(msg.bodyText()); |
|
287 |
totalMsgSize += textSize + |
|
288 |
mUniEditorGenUtils->UTF8Size(msg.subject()); |
|
289 |
ConvergedMessageAttachmentList attList = msg.attachments(); |
|
290 |
int attCount = attList.count(); |
|
291 |
bool hasInlineContent = false; |
|
292 |
||
293 |
for (int i=0; i<attCount; i++) |
|
294 |
{ |
|
295 |
if(attList.at(i)->attachmentType() == |
|
296 |
ConvergedMessageAttachment::EInline) |
|
297 |
{ |
|
298 |
hasInlineContent = true; |
|
299 |
} |
|
300 |
int attSize; |
|
301 |
QString mimeType; |
|
302 |
TMsgMediaType mediaType = EMsgMediaUnknown; |
|
303 |
||
304 |
attSize = 0; |
|
305 |
TRAP_IGNORE(mUniEditorGenUtils->getFileInfoL( |
|
306 |
attList.at(i)->filePath(), |
|
307 |
attSize, mimeType, mediaType)); |
|
308 |
totalMsgSize += attSize; |
|
309 |
} |
|
310 |
||
311 |
if( hasInlineContent && textSize > 0 ) |
|
312 |
{ |
|
313 |
// attachments are present, so we add our estimates |
|
314 |
totalMsgSize += KEstimatedMmsSmilHeaderSize + KEstimatedMimeHeaderSize; |
|
315 |
} |
|
316 |
QDEBUG_WRITE("END MsgSendUtil::getMmsMsgSize"); |
|
317 |
return totalMsgSize; |
|
318 |
} |
|
319 |
||
320 |
//--------------------------------------------------------------- |
|
321 |
// MsgSendUtil::validateService |
|
322 |
// @see header file |
|
323 |
//-------------------------------------------------------------- |
|
324 |
bool MsgSendUtil::validateService( |
|
325 |
UniEditorPluginInterface* pluginInterface, |
|
326 |
bool emailOverSmsSupported) |
|
327 |
{ |
|
328 |
QDEBUG_WRITE("START MsgSendUtil::validateService"); |
|
329 |
bool result = true; |
|
330 |
//If settings are missed then show a note and launch settings dialog |
|
331 |
if (!pluginInterface->validateService(emailOverSmsSupported)) |
|
332 |
{ |
|
333 |
//TODO: show note and launch settings dialog |
|
334 |
||
335 |
result = false; |
|
336 |
} |
|
337 |
// if control is here, then check is ok |
|
338 |
QDEBUG_WRITE("END MsgSendUtil::validateService"); |
|
339 |
return result; |
|
340 |
} |
|
341 |
||
342 |
// EOF |