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