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