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