|
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: Helper class to monitor msg construction in unified editor |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "debugtraces.h" |
|
20 #include <HbNotificationDialog> |
|
21 #include <HbWidget> |
|
22 |
|
23 // USER INCLUDES |
|
24 #include "msgmonitor.h" |
|
25 #include "msgunieditorview.h" |
|
26 #include "msgunieditoraddress.h" |
|
27 #include "msgunieditorsubject.h" |
|
28 #include "msgunieditorbody.h" |
|
29 #include "msgattachmentcontainer.h" |
|
30 #include "UniEditorGenUtils.h" |
|
31 |
|
32 // Constants |
|
33 |
|
34 // Define static |
|
35 ConvergedMessage::MessageType MsgMonitor::mMessageType; |
|
36 int MsgMonitor::mBodySize; |
|
37 int MsgMonitor::mContainerSize; |
|
38 int MsgMonitor::mSubjectSize; |
|
39 int MsgMonitor::mMaxMmsSize; |
|
40 int MsgMonitor::mMaxSmsRecipients; |
|
41 int MsgMonitor::mMaxMmsRecipients; |
|
42 int MsgMonitor::mMsgCurrAddressCount; |
|
43 |
|
44 //Localized strings |
|
45 #define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul") |
|
46 #define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex") |
|
47 |
|
48 //--------------------------------------------------------------- |
|
49 // MsgMonitor::MsgMonitor |
|
50 // @see header file |
|
51 //--------------------------------------------------------------- |
|
52 MsgMonitor::MsgMonitor(QObject* parent) : |
|
53 QObject(parent), |
|
54 mSkipNote(false) |
|
55 { |
|
56 init(); |
|
57 mUniEditorGenUtils = new UniEditorGenUtils; |
|
58 } |
|
59 |
|
60 //--------------------------------------------------------------- |
|
61 // MsgMonitor::~MsgMonitor |
|
62 // @see header file |
|
63 //--------------------------------------------------------------- |
|
64 MsgMonitor::~MsgMonitor() |
|
65 { |
|
66 delete mUniEditorGenUtils; |
|
67 } |
|
68 |
|
69 //--------------------------------------------------------------- |
|
70 // MsgMonitor::init |
|
71 // @see header file |
|
72 //--------------------------------------------------------------- |
|
73 void MsgMonitor::init() |
|
74 { |
|
75 mMessageType = ConvergedMessage::Sms; |
|
76 mBodySize = 0; |
|
77 mContainerSize = 0; |
|
78 mSubjectSize = 0; |
|
79 mMsgCurrAddressCount = 0; |
|
80 |
|
81 UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; |
|
82 |
|
83 mMaxMmsSize = KDefaultMaxSize; |
|
84 TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL()); |
|
85 |
|
86 mMaxSmsRecipients = KDefaultSmsRecipients; |
|
87 TRAP_IGNORE(mMaxSmsRecipients = uniEditorGenUtils->MaxSmsRecipientsL()); |
|
88 |
|
89 mMaxMmsRecipients = KDefaultMmsRecipients; |
|
90 TRAP_IGNORE(mMaxMmsRecipients = uniEditorGenUtils->MaxMmsRecipientsL()); |
|
91 |
|
92 delete uniEditorGenUtils; |
|
93 } |
|
94 |
|
95 //--------------------------------------------------------------- |
|
96 // MsgMonitor::handleContentChange |
|
97 // @see header file |
|
98 //--------------------------------------------------------------- |
|
99 void MsgMonitor::handleContentChange() |
|
100 { |
|
101 // get the projected message type & show the type change note |
|
102 ConvergedMessage::MessageType newMsgType = projectedMsgType(); |
|
103 if(mMessageType != newMsgType) |
|
104 { |
|
105 mMessageType = newMsgType; |
|
106 QString noteStr; |
|
107 if(newMsgType == ConvergedMessage::Sms) |
|
108 { |
|
109 noteStr = LOC_POP_MESSAGE_CHANGE_TEXT; |
|
110 } |
|
111 else |
|
112 { |
|
113 noteStr = LOC_POP_MESSAGE_CHANGE_MUL; |
|
114 } |
|
115 showPopup(noteStr); |
|
116 } |
|
117 |
|
118 HbWidget* senderWidget = qobject_cast<HbWidget*>(sender()); |
|
119 updateMsgInfo(senderWidget); |
|
120 } |
|
121 |
|
122 //--------------------------------------------------------------- |
|
123 // MsgMonitor::projectedMsgType |
|
124 // @see header file |
|
125 //--------------------------------------------------------------- |
|
126 ConvergedMessage::MessageType MsgMonitor::projectedMsgType() |
|
127 { |
|
128 ConvergedMessage::MessageType newMsgType = ConvergedMessage::Sms; |
|
129 |
|
130 // check if MMS content is present in any of the editor component |
|
131 if( bodyHasMMSContent() || |
|
132 subjectHasMMSContent() || |
|
133 containerHasMMSContent() || |
|
134 otherMMSCriteriaMet() ) |
|
135 { |
|
136 newMsgType = ConvergedMessage::Mms; |
|
137 } |
|
138 return newMsgType; |
|
139 } |
|
140 |
|
141 //--------------------------------------------------------------- |
|
142 // MsgMonitor::updateMsgInfo |
|
143 // @see header file |
|
144 //--------------------------------------------------------------- |
|
145 void MsgMonitor::updateMsgInfo(HbWidget* senderWidget) |
|
146 { |
|
147 if(mMessageType == ConvergedMessage::Mms) |
|
148 { |
|
149 //Disable char counter & add subject |
|
150 view()->mBody->disableCharCounter(); |
|
151 view()->addSubject(); |
|
152 } |
|
153 |
|
154 // check if sent by body widget |
|
155 MsgUnifiedEditorBody* body = NULL; |
|
156 body = qobject_cast<MsgUnifiedEditorBody*>(senderWidget); |
|
157 if(body) |
|
158 { |
|
159 mBodySize = view()->mBody->bodySize(); |
|
160 view()->setAttachOptionEnabled( |
|
161 MsgUnifiedEditorView::TBE_PHOTO, !view()->mBody->hasImage()); |
|
162 view()->setAttachOptionEnabled( |
|
163 MsgUnifiedEditorView::TBE_SOUND, !view()->mBody->hasAudio()); |
|
164 return; |
|
165 } |
|
166 |
|
167 // check if sent by subject widget |
|
168 MsgUnifiedEditorSubject* subject = NULL; |
|
169 subject = qobject_cast<MsgUnifiedEditorSubject*>(senderWidget); |
|
170 if(subject) |
|
171 { |
|
172 mSubjectSize = view()->mSubjectField->subjectSize(); |
|
173 return; |
|
174 } |
|
175 |
|
176 // check if sent by attachment container widget |
|
177 MsgAttachmentContainer* container = NULL; |
|
178 container = qobject_cast<MsgAttachmentContainer*>(senderWidget); |
|
179 if(container) |
|
180 { |
|
181 mContainerSize = view()->mAttachmentContainer->containerSize(); |
|
182 return; |
|
183 } |
|
184 |
|
185 // handle content change from other widgets e.g. To, Cc, Bcc address field |
|
186 int totalAddressCount = view()->mToField->addressCount(); |
|
187 if(view()->mCcField && view()->mBccField) |
|
188 { |
|
189 totalAddressCount += view()->mCcField->addressCount() + |
|
190 view()->mBccField->addressCount(); |
|
191 } |
|
192 mMsgCurrAddressCount = totalAddressCount; |
|
193 return; |
|
194 } |
|
195 |
|
196 //--------------------------------------------------------------- |
|
197 // MsgMonitor::showPopup |
|
198 // @see header file |
|
199 //--------------------------------------------------------------- |
|
200 void MsgMonitor::showPopup(const QString& text) |
|
201 { |
|
202 if(!mSkipNote) |
|
203 { |
|
204 HbNotificationDialog* dlg = new HbNotificationDialog(); |
|
205 dlg->setFocusPolicy(Qt::NoFocus); |
|
206 dlg->setDismissPolicy(HbPopup::TapAnywhere); |
|
207 dlg->setAttribute(Qt::WA_DeleteOnClose, true); |
|
208 dlg->setText(text); |
|
209 dlg->show(); |
|
210 } |
|
211 // reset skip note flag |
|
212 mSkipNote = false; |
|
213 } |
|
214 |
|
215 //--------------------------------------------------------------- |
|
216 // MsgMonitor::view |
|
217 // @see header file |
|
218 //--------------------------------------------------------------- |
|
219 MsgUnifiedEditorView* MsgMonitor::view() |
|
220 { |
|
221 return static_cast<MsgUnifiedEditorView*>(this->parent()); |
|
222 } |
|
223 |
|
224 //--------------------------------------------------------------- |
|
225 // MsgMonitor::bodyHasMMSContent |
|
226 // @see header file |
|
227 //--------------------------------------------------------------- |
|
228 bool MsgMonitor::bodyHasMMSContent() |
|
229 { |
|
230 MsgUnifiedEditorBody* edBody = view()->mBody; |
|
231 // If any media-object is present inside body |
|
232 if(!edBody->mediaContent().isEmpty()) |
|
233 { |
|
234 return true; |
|
235 } |
|
236 |
|
237 int bodyTextSize = mUniEditorGenUtils->UTF8Size(edBody->text()); |
|
238 int maxSmsSize = 0; |
|
239 TRAP_IGNORE(maxSmsSize = |
|
240 mUniEditorGenUtils->MaxSmsMsgSizeL(edBody->isUnicode())); |
|
241 // If body text size exceeds sms text-size limit |
|
242 if(bodyTextSize > maxSmsSize) |
|
243 { |
|
244 return true; |
|
245 } |
|
246 return false; |
|
247 } |
|
248 |
|
249 //--------------------------------------------------------------- |
|
250 // MsgMonitor::subjectHasMMSContent |
|
251 // @see header file |
|
252 //--------------------------------------------------------------- |
|
253 bool MsgMonitor::subjectHasMMSContent() |
|
254 { |
|
255 MsgUnifiedEditorSubject* edSubject = view()->mSubjectField; |
|
256 ConvergedMessage::Priority priority = ConvergedMessage::Normal; |
|
257 QString subjectText; |
|
258 if(edSubject) |
|
259 { |
|
260 priority = edSubject->priority(); |
|
261 subjectText = edSubject->text(); |
|
262 } |
|
263 // If priority is set to other than Normal or |
|
264 // If subject has some content |
|
265 if( (priority != ConvergedMessage::Normal) || |
|
266 !subjectText.isEmpty() ) |
|
267 { |
|
268 return true; |
|
269 } |
|
270 return false; |
|
271 } |
|
272 |
|
273 //--------------------------------------------------------------- |
|
274 // MsgMonitor::containerHasMMSContent |
|
275 // @see header file |
|
276 //--------------------------------------------------------------- |
|
277 bool MsgMonitor::containerHasMMSContent() |
|
278 { |
|
279 QString bodyText = view()->mBody->text(); |
|
280 MsgAttachmentContainer* edContainer = view()->mAttachmentContainer; |
|
281 bool hasMMAttachmentContent = false; |
|
282 int attachmentCount = 0; |
|
283 if(edContainer) |
|
284 { |
|
285 hasMMAttachmentContent = edContainer->hasMMContent(); |
|
286 attachmentCount = edContainer->count(); |
|
287 } |
|
288 // If MM attachments are present or |
|
289 // If only one non-MM attachment is present e.g. vcf along with body text |
|
290 if( hasMMAttachmentContent || |
|
291 ((attachmentCount == 1) && !bodyText.isEmpty()) ) |
|
292 { |
|
293 return true; |
|
294 } |
|
295 return false; |
|
296 } |
|
297 |
|
298 //--------------------------------------------------------------- |
|
299 // MsgMonitor::otherMMSCriteriaMet |
|
300 // @see header file |
|
301 //--------------------------------------------------------------- |
|
302 bool MsgMonitor::otherMMSCriteriaMet() |
|
303 { |
|
304 MsgUnifiedEditorAddress* edCc = view()->mCcField; |
|
305 MsgUnifiedEditorAddress* edBcc = view()->mBccField; |
|
306 int ccCount = 0; |
|
307 int bccCount = 0; |
|
308 if(edCc && edBcc) |
|
309 { |
|
310 ccCount = edCc->addressCount(); |
|
311 bccCount = edBcc->addressCount(); |
|
312 } |
|
313 // If CC/BCC has some content or |
|
314 // If to-recipients count exceeds max sms recipient count |
|
315 if( ccCount || bccCount || |
|
316 (view()->mToField->addressCount() > mMaxSmsRecipients) ) |
|
317 { |
|
318 return true; |
|
319 } |
|
320 |
|
321 // If to-field contains an email address |
|
322 bool isEmailPresent = false; |
|
323 ConvergedMessageAddressList addrList = view()->mToField->addresses(); |
|
324 TRAP_IGNORE(isEmailPresent = mUniEditorGenUtils->VerifyEmailAddressesL(addrList)); |
|
325 if(isEmailPresent) |
|
326 { |
|
327 return true; |
|
328 } |
|
329 return false; |
|
330 } |
|
331 |
|
332 //EOF |