9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: Helper class to monitor msg construction in unified editor |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 // INCLUDES |
18 // INCLUDES |
19 #include "debugtraces.h" |
19 #include "debugtraces.h" |
|
20 #include <HbNotificationDialog> |
|
21 #include <HbWidget> |
20 |
22 |
21 // USER INCLUDES |
23 // USER INCLUDES |
22 #include "msgmonitor.h" |
24 #include "msgmonitor.h" |
|
25 #include "msgunieditorview.h" |
|
26 #include "msgunieditoraddress.h" |
|
27 #include "msgunieditorsubject.h" |
23 #include "msgunieditorbody.h" |
28 #include "msgunieditorbody.h" |
24 #include "msgunieditorsubject.h" |
|
25 #include "msgattachmentcontainer.h" |
29 #include "msgattachmentcontainer.h" |
26 #include "UniEditorGenUtils.h" |
30 #include "UniEditorGenUtils.h" |
27 |
31 |
28 // Constants |
32 // Constants |
29 |
33 |
30 // Define static |
34 // Define static |
|
35 ConvergedMessage::MessageType MsgMonitor::mMessageType; |
31 int MsgMonitor::mBodySize; |
36 int MsgMonitor::mBodySize; |
32 int MsgMonitor::mContainerSize; |
37 int MsgMonitor::mContainerSize; |
33 int MsgMonitor::mSubjectSize; |
38 int MsgMonitor::mSubjectSize; |
34 int MsgMonitor::mMaxMmsSize; |
39 int MsgMonitor::mMaxMmsSize; |
|
40 int MsgMonitor::mMaxSmsRecipients; |
|
41 int MsgMonitor::mMaxMmsRecipients; |
|
42 |
|
43 //Localized strings |
|
44 #define LOC_POP_MESSAGE_CHANGE_MUL hbTrId("txt_messaging_dpopinfo_message_type_changed_to_mul") |
|
45 #define LOC_POP_MESSAGE_CHANGE_TEXT hbTrId("txt_messaging_dpopinfo_message_type_changed_to_tex") |
35 |
46 |
36 //--------------------------------------------------------------- |
47 //--------------------------------------------------------------- |
37 // MsgMonitor::MsgMonitor |
48 // MsgMonitor::MsgMonitor |
38 // @see header file |
49 // @see header file |
39 //--------------------------------------------------------------- |
50 //--------------------------------------------------------------- |
40 MsgMonitor::MsgMonitor(QObject* parent) : |
51 MsgMonitor::MsgMonitor(QObject* parent) : |
41 QObject(parent) |
52 QObject(parent), |
|
53 mSkipNote(false) |
42 { |
54 { |
43 init(); |
55 init(); |
|
56 mUniEditorGenUtils = new UniEditorGenUtils; |
|
57 } |
|
58 |
|
59 //--------------------------------------------------------------- |
|
60 // MsgMonitor::~MsgMonitor |
|
61 // @see header file |
|
62 //--------------------------------------------------------------- |
|
63 MsgMonitor::~MsgMonitor() |
|
64 { |
|
65 delete mUniEditorGenUtils; |
44 } |
66 } |
45 |
67 |
46 //--------------------------------------------------------------- |
68 //--------------------------------------------------------------- |
47 // MsgMonitor::init |
69 // MsgMonitor::init |
48 // @see header file |
70 // @see header file |
49 //--------------------------------------------------------------- |
71 //--------------------------------------------------------------- |
50 void MsgMonitor::init() |
72 void MsgMonitor::init() |
51 { |
73 { |
|
74 mMessageType = ConvergedMessage::Sms; |
52 mBodySize = 0; |
75 mBodySize = 0; |
53 mContainerSize = 0; |
76 mContainerSize = 0; |
54 mSubjectSize = 0; |
77 mSubjectSize = 0; |
55 |
78 |
56 mMaxMmsSize = 0; |
|
57 UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; |
79 UniEditorGenUtils* uniEditorGenUtils = new UniEditorGenUtils; |
|
80 |
58 mMaxMmsSize = KDefaultMaxSize; |
81 mMaxMmsSize = KDefaultMaxSize; |
59 TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL()); |
82 TRAP_IGNORE(mMaxMmsSize = uniEditorGenUtils->MaxMmsMsgSizeL()); |
60 } |
83 |
61 |
84 mMaxSmsRecipients = KDefaultSmsRecipients; |
62 //--------------------------------------------------------------- |
85 TRAP_IGNORE(mMaxSmsRecipients = uniEditorGenUtils->MaxSmsRecipientsL()); |
63 // MsgMonitor::~MsgMonitor |
86 |
64 // @see header file |
87 mMaxMmsRecipients = KDefaultMmsRecipients; |
65 //--------------------------------------------------------------- |
88 TRAP_IGNORE(mMaxMmsRecipients = uniEditorGenUtils->MaxMmsRecipientsL()); |
66 MsgMonitor::~MsgMonitor() |
89 |
67 { |
90 delete uniEditorGenUtils; |
68 } |
91 } |
69 |
92 |
70 //--------------------------------------------------------------- |
93 //--------------------------------------------------------------- |
71 // MsgMonitor::messageSize |
94 // MsgMonitor::checkMsgTypeChange |
72 // @see header file |
95 // @see header file |
73 //--------------------------------------------------------------- |
96 //--------------------------------------------------------------- |
74 int MsgMonitor::messageSize() |
97 void MsgMonitor::checkMsgTypeChange() |
75 { |
98 { |
76 return mBodySize + mContainerSize + mSubjectSize; |
99 // fetch editor's content |
77 } |
100 MsgUnifiedEditorBody* edBody = view()->mBody; |
78 |
101 QStringList objList = edBody->mediaContent(); |
79 //--------------------------------------------------------------- |
102 QString bodyText = edBody->text(); |
80 // MsgMonitor::bodySize |
103 |
81 // @see header file |
104 MsgUnifiedEditorSubject* edSubject = view()->mSubjectField; |
82 //--------------------------------------------------------------- |
105 ConvergedMessage::Priority priority = ConvergedMessage::Normal; |
83 int MsgMonitor::bodySize() |
106 QString subjectText; |
84 { |
107 if(edSubject) |
85 return mBodySize; |
108 { |
86 } |
109 priority = edSubject->priority(); |
87 |
110 subjectText = edSubject->text(); |
88 //--------------------------------------------------------------- |
111 } |
89 // MsgMonitor::containerSize |
112 |
90 // @see header file |
113 MsgUnifiedEditorAddress* edCc = view()->mCcField; |
91 //--------------------------------------------------------------- |
114 MsgUnifiedEditorAddress* edBcc = view()->mBccField; |
92 int MsgMonitor::containerSize() |
115 int ccCount = 0; |
93 { |
116 int bccCount = 0; |
94 return mContainerSize; |
117 if(edCc && edBcc) |
95 } |
118 { |
96 |
119 ccCount = edCc->addressCount(); |
97 //--------------------------------------------------------------- |
120 bccCount = edBcc->addressCount(); |
98 // MsgMonitor::subjectSize |
121 } |
99 // @see header file |
122 |
100 //--------------------------------------------------------------- |
123 MsgAttachmentContainer* edContainer = view()->mAttachmentContainer; |
101 int MsgMonitor::subjectSize() |
124 bool hasMMAttachmentContent = false; |
102 { |
125 int attachmentCount = 0; |
103 return mSubjectSize; |
126 if(edContainer) |
104 } |
127 { |
105 |
128 hasMMAttachmentContent = edContainer->hasMMContent(); |
106 //--------------------------------------------------------------- |
129 attachmentCount = edContainer->count(); |
107 // MsgMonitor::maxMmsSize |
130 } |
108 // @see header file |
131 |
109 //--------------------------------------------------------------- |
132 // find out the msgtype based on content |
110 int MsgMonitor::maxMmsSize() |
133 ConvergedMessage::MessageType projectedMsgType = ConvergedMessage::Sms; |
111 { |
134 |
112 return mMaxMmsSize; |
135 // check for presence of MMS content |
113 } |
136 // 1. If any media-object is present inside body |
114 |
137 // 2. If priority is set to other than Normal |
115 //--------------------------------------------------------------- |
138 // 3. If subject has some content |
116 // MsgMonitor::onSizeChanged |
139 // 4. If CC/BCC has some content |
117 // @see header file |
140 // 5. If MM attachments are present |
118 //--------------------------------------------------------------- |
141 // 6. If only one non-MM attachment is present e.g. vcf |
119 void MsgMonitor::onSizeChanged(int aSize) |
142 // and body text is also present |
120 { |
143 // 7. If body text size exceeds sms text-size limit |
121 // TODO: implement this correctly |
144 if( !objList.isEmpty() || |
|
145 (priority != ConvergedMessage::Normal) || |
|
146 !subjectText.isEmpty() || |
|
147 (ccCount || bccCount) || |
|
148 hasMMAttachmentContent || |
|
149 ((attachmentCount == 1) && !bodyText.isEmpty()) |
|
150 ) |
|
151 { |
|
152 projectedMsgType = ConvergedMessage::Mms; |
|
153 } |
|
154 else |
|
155 { |
|
156 projectedMsgType = ConvergedMessage::Sms; |
|
157 } |
|
158 |
|
159 // optimization 1: if projected type is still sms means |
|
160 // the message under composition has only plain text |
|
161 if(projectedMsgType == ConvergedMessage::Sms) |
|
162 { |
|
163 bool hasUnicodeText = edBody->isUnicode(); |
|
164 int bodyTextSize = mUniEditorGenUtils->UTF8Size(bodyText); |
|
165 int maxSmsSize = mUniEditorGenUtils->MaxSmsMsgSizeL(hasUnicodeText); |
|
166 if(bodyTextSize > maxSmsSize) |
|
167 { |
|
168 projectedMsgType = ConvergedMessage::Mms; |
|
169 } |
|
170 } |
|
171 |
|
172 // show type change note, if needed |
|
173 if(mMessageType != projectedMsgType) |
|
174 { |
|
175 mMessageType = projectedMsgType; |
|
176 QString noteStr; |
|
177 if(projectedMsgType == ConvergedMessage::Sms) |
|
178 { |
|
179 noteStr = LOC_POP_MESSAGE_CHANGE_TEXT; |
|
180 } |
|
181 else |
|
182 { |
|
183 noteStr = LOC_POP_MESSAGE_CHANGE_MUL; |
|
184 |
|
185 //Disable char counter |
|
186 edBody->disableCharCounter(); |
|
187 } |
|
188 showPopup(noteStr); |
|
189 } |
|
190 |
|
191 // update size of editor component |
122 HbWidget* senderWidget = qobject_cast<HbWidget*>(sender()); |
192 HbWidget* senderWidget = qobject_cast<HbWidget*>(sender()); |
123 |
193 updateSizeInfo(senderWidget); |
|
194 } |
|
195 |
|
196 //--------------------------------------------------------------- |
|
197 // MsgMonitor::updateSizeInfo |
|
198 // @see header file |
|
199 //--------------------------------------------------------------- |
|
200 void MsgMonitor::updateSizeInfo(HbWidget* aWidget) |
|
201 { |
124 // if sent by body widget |
202 // if sent by body widget |
125 MsgUnifiedEditorBody* body = NULL; |
203 MsgUnifiedEditorBody* body = NULL; |
126 body = qobject_cast<MsgUnifiedEditorBody*>(senderWidget); |
204 body = qobject_cast<MsgUnifiedEditorBody*>(aWidget); |
127 if(body) |
205 if(body) |
128 { |
206 { |
129 mBodySize = aSize; |
207 mBodySize = view()->mBody->bodySize(); |
130 return; |
208 return; |
131 } |
209 } |
132 |
210 |
133 // if sent by attachment container widget |
211 // if sent by attachment container widget |
134 MsgAttachmentContainer* container = NULL; |
212 MsgAttachmentContainer* container = NULL; |
135 container = qobject_cast<MsgAttachmentContainer*>(senderWidget); |
213 container = qobject_cast<MsgAttachmentContainer*>(aWidget); |
136 if(container) |
214 if(container) |
137 { |
215 { |
138 mContainerSize = aSize; |
216 mContainerSize = view()->mAttachmentContainer->containerSize(); |
139 return; |
217 return; |
140 } |
218 } |
141 |
219 |
142 // if sent by subject widget |
220 // if sent by subject widget |
143 MsgUnifiedEditorSubject* subject = NULL; |
221 MsgUnifiedEditorSubject* subject = NULL; |
144 subject = qobject_cast<MsgUnifiedEditorSubject*>(senderWidget); |
222 subject = qobject_cast<MsgUnifiedEditorSubject*>(aWidget); |
145 if(subject) |
223 if(subject) |
146 { |
224 { |
147 mSubjectSize = aSize; |
225 mSubjectSize = view()->mSubjectField->subjectSize(); |
148 } |
226 } |
|
227 } |
|
228 |
|
229 //--------------------------------------------------------------- |
|
230 // MsgMonitor::showPopup |
|
231 // @see header file |
|
232 //--------------------------------------------------------------- |
|
233 void MsgMonitor::showPopup(const QString& text) |
|
234 { |
|
235 if(!mSkipNote) |
|
236 { |
|
237 HbNotificationDialog* dlg = new HbNotificationDialog(); |
|
238 dlg->setFocusPolicy(Qt::NoFocus); |
|
239 dlg->setDismissPolicy(HbPopup::TapAnywhere); |
|
240 dlg->setAttribute(Qt::WA_DeleteOnClose, true); |
|
241 dlg->setText(text); |
|
242 dlg->show(); |
|
243 } |
|
244 // reset skip note flag |
|
245 mSkipNote = false; |
|
246 } |
|
247 |
|
248 //--------------------------------------------------------------- |
|
249 // MsgMonitor::view |
|
250 // @see header file |
|
251 //--------------------------------------------------------------- |
|
252 MsgUnifiedEditorView* MsgMonitor::view() |
|
253 { |
|
254 return static_cast<MsgUnifiedEditorView*>(this->parent()); |
149 } |
255 } |
150 |
256 |
151 //EOF |
257 //EOF |