12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
|
17 |
17 #include "msgindicator.h" |
18 #include "msgindicator.h" |
18 #include "msgindicator_p.h" |
19 #include "msgindicator_p.h" |
|
20 #include "msginfodefs.h" |
|
21 #include "debugtraces.h" |
19 |
22 |
20 #include <QThreadPool> |
23 #include <QThreadPool> |
21 #include <QRunnable> |
24 #include <QRunnable> |
22 #include <QByteArray> |
25 #include <QByteArray> |
23 #include <QProcess> |
26 #include <QProcess> |
24 #include "debugtraces.h" |
27 #include <QFileInfo> |
25 |
28 #include <qvariant.h> |
26 #include <xqservicerequest.h> |
29 #include <xqaiwrequest.h> |
|
30 #include <xqappmgr.h> |
|
31 #include <ccsdefs.h> |
|
32 |
27 |
33 |
28 //Localized Constants |
34 //Localized Constants |
29 #define LOC_UNREAD_MESSAGES hbTrId("txt_messaging_list_ln") |
35 #define LOC_UNREAD_MESSAGES hbTrId("txt_messaging_list_ln") |
30 #define LOC_NEW_MESSAGES hbTrId("txt_common_opt_ln_new_messages") |
36 #define LOC_NEW_MESSAGES hbTrId("txt_common_opt_ln_new_messages") |
31 |
37 #define LOC_RECEIVED_FILES hbTrId("Received files") |
32 //---------------------------------------------------------------------- |
38 #define LOC_UNREAD_SINGLE_MESSAGE hbTrId("Unread Message") |
33 class ServiceRequestSenderTask : public QRunnable |
39 #define LOC_UNREAD_MULTIPLE_MESSAGES hbTrId("Unread Messages") |
34 { |
40 #define LOC_FAILED_SINGLE_MESSAGE hbTrId("Failed Message") |
35 public: |
41 #define LOC_FAILED_MULTIPLE_MESSAGES hbTrId("Failed Messages") |
36 ServiceRequestSenderTask(qint64 conversationId):mConvId(conversationId) {} |
42 #define LOC_OUTGOING_SINGLE_MESSAGE hbTrId("Outgoing Message") |
37 |
43 #define LOC_OUTGOING_MULTIPLE_MESSAGES hbTrId("Outgoing Messages") |
38 void run() |
44 |
39 { |
45 /** |
40 XQServiceRequest snd( |
46 * The number of indicators. |
41 "com.nokia.services.hbserviceprovider.conversationview", |
47 */ |
42 "open(qint64)",false); |
48 static const int MsgIndicatorCount = 4; |
43 snd << mConvId; |
49 |
44 bool res=snd.send(); |
50 /** |
45 } |
51 * The attibutes of an indicator. |
46 |
52 */ |
47 ~ServiceRequestSenderTask() |
53 struct MsgIndicatorInfo |
|
54 { |
|
55 QString icon; |
|
56 QString primaryText; |
|
57 QString secondaryText; |
|
58 }; |
|
59 |
|
60 /** |
|
61 * Array of Indicator information elements |
|
62 */ |
|
63 |
|
64 //TODO: Localize |
|
65 |
|
66 |
|
67 // TODO: get regular icons, thes are placeholders.hanlde later |
|
68 static const MsgIndicatorInfo IndicatorInfo[MsgIndicatorCount] = { |
|
69 { "", "", "" }, |
|
70 { "qtg_large_new_message", "newindicatorplugin", "%1 unread messages" }, |
|
71 { "qtg_small_fail", "failedindicatorplugin", "%1 Failed message%2" }, |
|
72 { "qtg_small_outbox","pendingindicatorplugin", "%1 Outgoing message%2" } |
|
73 }; |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // ServiceRequestSenderTask::ServiceRequestSenderTask |
|
77 // @see msgindicator.h |
|
78 // ---------------------------------------------------------------------------- |
|
79 ServiceRequestSenderTask::ServiceRequestSenderTask(qint64 conversationId): |
|
80 mConvId(conversationId) |
48 { |
81 { |
49 } |
82 } |
50 |
83 |
51 private: |
84 // ---------------------------------------------------------------------------- |
52 qint64 mConvId; |
85 // ServiceRequestSenderTask::~ServiceRequestSenderTask |
53 }; |
86 // @see msgindicator.h |
54 |
87 // ---------------------------------------------------------------------------- |
55 //---------------------------------------------------------------------- |
88 ServiceRequestSenderTask::~ServiceRequestSenderTask() |
56 |
89 { |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // ServiceRequestSenderTask::run |
|
94 // @see msgindicator.h |
|
95 // ---------------------------------------------------------------------------- |
|
96 void ServiceRequestSenderTask::run() |
|
97 { |
|
98 QList<QVariant> args; |
|
99 QString serviceName("com.nokia.services.hbserviceprovider"); |
|
100 QString operation("open(qint64)"); |
|
101 XQAiwRequest* request; |
|
102 XQApplicationManager appManager; |
|
103 request = appManager.create(serviceName, "conversationview", operation, false); // embedded |
|
104 if ( request == NULL ) |
|
105 { |
|
106 return; |
|
107 } |
|
108 args << QVariant(mConvId); |
|
109 request->setArguments(args); |
|
110 request->send(); |
|
111 delete request; |
|
112 } |
57 |
113 |
58 // ---------------------------------------------------------------------------- |
114 // ---------------------------------------------------------------------------- |
59 // MsgIndicator::MsgIndicator |
115 // MsgIndicator::MsgIndicator |
60 // @see msgindicator.h |
116 // @see msgindicator.h |
61 // ---------------------------------------------------------------------------- |
117 // ---------------------------------------------------------------------------- |
62 MsgIndicator::MsgIndicator(const QString &indicatorType) : |
118 MsgIndicator::MsgIndicator(const QString &indicatorType) : |
63 HbIndicatorInterface(indicatorType, |
119 HbIndicatorInterface(indicatorType, HbIndicatorInterface::GroupPriorityHigh, |
64 HbIndicatorInterface::GroupPriorityHigh, |
120 InteractionActivated), |
65 InteractionActivated) |
121 mIndicatorType(NULL) |
66 { |
122 { |
67 d_ptr = new MsgIndicatorPrivate(this); |
123 d_ptr = new MsgIndicatorPrivate(this); |
68 } |
124 } |
69 |
125 |
70 // ---------------------------------------------------------------------------- |
126 // ---------------------------------------------------------------------------- |
71 // MsgIndicator::~MsgIndicator |
127 // MsgIndicator::~MsgIndicator |
72 // @see msgindicator.h |
128 // @see msgindicator.h |
73 // ---------------------------------------------------------------------------- |
129 // ---------------------------------------------------------------------------- |
74 MsgIndicator::~MsgIndicator() |
130 MsgIndicator::~MsgIndicator() |
75 { |
131 { |
76 delete d_ptr; |
132 delete d_ptr; |
77 } |
133 } |
78 |
134 |
79 // ---------------------------------------------------------------------------- |
135 // ---------------------------------------------------------------------------- |
80 // MsgIndicator::handleInteraction |
136 // MsgIndicator::handleInteraction |
81 // @see msgindicator.h |
137 // @see msgindicator.h |
82 // ---------------------------------------------------------------------------- |
138 // ---------------------------------------------------------------------------- |
83 bool MsgIndicator::handleInteraction(InteractionType type) |
139 bool MsgIndicator::handleInteraction(InteractionType type) |
84 { |
140 { |
85 bool handled = false; |
141 bool handled = false; |
86 if (type == InteractionActivated) |
142 if (type == InteractionActivated) |
87 { |
143 { |
88 QThreadPool::globalInstance()->start( |
144 QThreadPool::globalInstance()->start(new ServiceRequestSenderTask( |
89 new ServiceRequestSenderTask(mConversationId)); |
145 mConversationId)); |
90 handled = true; |
146 handled = true; |
91 } |
147 } |
92 return handled; |
148 return handled; |
93 } |
149 } |
94 |
150 |
95 // ---------------------------------------------------------------------------- |
151 // ---------------------------------------------------------------------------- |
96 // MsgIndicator::indicatorData |
152 // MsgIndicator::indicatorData |
97 // @see msgindicator.h |
153 // @see msgindicator.h |
98 // ---------------------------------------------------------------------------- |
154 // ---------------------------------------------------------------------------- |
99 QVariant MsgIndicator::indicatorData(int role) const |
155 QVariant MsgIndicator::indicatorData(int role) const |
100 { |
156 { |
101 switch(role) |
157 switch (role) { |
102 { |
158 case PrimaryTextRole: |
103 case TextRole: |
159 { |
104 { |
160 return mPrimaryText; |
105 mConversationId = -100; |
161 } |
106 |
|
107 IndicatorData data; |
|
108 d_ptr->getIndicatorInfo(data); |
|
109 |
|
110 mConversationFromSingleContact = data.mFromSingle; |
|
111 mBodyText = data.mDescription; |
|
112 |
|
113 if (mConversationFromSingleContact) |
|
114 { |
|
115 mConversationId = (int)data.mConversationId; |
|
116 QString name = prepareDisplayName(data); |
|
117 name.append(QString(" (%1)").arg(data.mUnreadMsgCount)); |
|
118 return name; |
|
119 } |
|
120 else |
|
121 { |
|
122 QString text = QString("%1 new messages").arg(data.mUnreadMsgCount); |
|
123 return text; |
|
124 } |
|
125 } |
|
126 case SecondaryTextRole: |
162 case SecondaryTextRole: |
127 { |
163 { |
128 if (mConversationFromSingleContact) |
164 return mSecondaryText; |
129 { |
165 } |
130 return mBodyText; |
166 case DecorationNameRole: |
131 } |
167 { |
132 else |
168 return IndicatorInfo[mIndicatorType].icon; |
133 { |
169 |
134 return QString(); |
170 } |
135 } |
171 default: |
136 } |
172 return QVariant(); |
137 case IconNameRole: |
|
138 { |
|
139 QString iconName("z:/resource/messaging/message.svg"); |
|
140 return iconName; |
|
141 } |
|
142 default: |
|
143 return QVariant(); |
|
144 } |
173 } |
145 } |
174 } |
146 |
175 |
147 // ---------------------------------------------------------------------------- |
176 // ---------------------------------------------------------------------------- |
148 // MsgIndicator::handleClientRequest |
177 // MsgIndicator::handleClientRequest |
149 // @see msgindicator.h |
178 // @see msgindicator.h |
150 // ---------------------------------------------------------------------------- |
179 // ---------------------------------------------------------------------------- |
151 bool MsgIndicator::handleClientRequest( RequestType type, |
180 bool MsgIndicator::handleClientRequest(RequestType type, const QVariant ¶meter) |
152 const QVariant ¶meter) |
181 { |
153 { |
182 |
154 Q_UNUSED(parameter); |
|
155 bool handled(false); |
183 bool handled(false); |
156 switch (type) { |
184 switch (type) { |
157 case RequestActivate: |
185 case RequestActivate: |
158 { |
186 { |
159 emit dataChanged(); |
187 QByteArray dataArray = parameter.toByteArray(); |
160 handled = true; |
188 QDataStream messageStream(&dataArray, QIODevice::ReadOnly); |
|
189 MsgInfo info; |
|
190 info.deserialize(messageStream); |
|
191 |
|
192 mCount = info.mMsgCount; |
|
193 mIndicatorType = info.mIndicatorType; |
|
194 mPrimaryText = getPrimaryText(info); |
|
195 mSecondaryText = getSecondaryText(info); |
|
196 mConversationId = info.mConversationId; |
|
197 emit |
|
198 dataChanged(); |
|
199 handled = true; |
|
200 } |
|
201 break; |
|
202 |
|
203 case RequestDeactivate: |
|
204 { |
|
205 // reset data |
|
206 mConversationId = -100; |
|
207 mBodyText = QString(); |
|
208 emit deactivate(); |
|
209 } |
|
210 break; |
|
211 default: |
|
212 break; |
|
213 } |
|
214 |
|
215 return handled; |
|
216 } |
|
217 |
|
218 // ---------------------------------------------------------------------------- |
|
219 // MsgIndicator::prepareDisplayName |
|
220 // @see msgindicator.h |
|
221 // ---------------------------------------------------------------------------- |
|
222 QString MsgIndicator::prepareDisplayName(MsgInfo& indicatorData) const |
|
223 { |
|
224 //Set the Contact Name/Number |
|
225 |
|
226 QString displayName; |
|
227 |
|
228 if (ECsBlueTooth == indicatorData.mMessageType) { |
|
229 displayName = LOC_RECEIVED_FILES; |
|
230 } |
|
231 else { |
|
232 indicatorData.mDisplayName.removeDuplicates(); |
|
233 indicatorData.mDisplayName.sort(); |
|
234 displayName = indicatorData.mDisplayName.at(0); |
|
235 |
|
236 for (int i = 1; i < indicatorData.mDisplayName.count(); ++i) { |
|
237 displayName += QString(", ") + indicatorData.mDisplayName.at(i); |
|
238 } |
|
239 } |
|
240 return displayName; |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // MsgIndicator::getPrimaryText |
|
245 // @see msgindicator.h |
|
246 // ---------------------------------------------------------------------------- |
|
247 QString MsgIndicator::getPrimaryText(MsgInfo& data) |
|
248 { |
|
249 if (data.mIndicatorType == NewIndicatorPlugin) { |
|
250 return getUnreadPrimaryText(data); |
|
251 } |
|
252 else { |
|
253 QString primaryText; |
|
254 if (mCount >= 1) { |
|
255 if (data.mIndicatorType == FailedIndicatorPlugin) { |
|
256 primaryText += QString("%1 ").arg(mCount); |
|
257 primaryText += (mCount > 1)? |
|
258 LOC_FAILED_MULTIPLE_MESSAGES : LOC_FAILED_SINGLE_MESSAGE; |
161 } |
259 } |
162 |
260 else { |
163 break; |
261 primaryText += QString("%1 ").arg(mCount); |
164 case RequestDeactivate: |
262 primaryText += (mCount > 1)? |
165 { |
263 LOC_OUTGOING_MULTIPLE_MESSAGES : LOC_OUTGOING_SINGLE_MESSAGE; |
166 // reset data |
|
167 mConversationId = -100; |
|
168 mBodyText = QString(); |
|
169 emit deactivate(); |
|
170 } |
264 } |
171 break; |
265 } |
172 default: |
266 return primaryText; |
173 break; |
267 } |
174 } |
268 } |
175 |
269 |
176 return handled; |
270 // ---------------------------------------------------------------------------- |
177 } |
271 // MsgIndicator::getUnreadPrimaryText |
178 |
272 // @see msgindicator.h |
179 // ---------------------------------------------------------------------------- |
273 // ---------------------------------------------------------------------------- |
180 // MsgIndicator::prepareDisplayName |
274 QString MsgIndicator::getUnreadPrimaryText(MsgInfo& data) |
181 // @see msgindicator.h |
275 { |
182 // ---------------------------------------------------------------------------- |
276 mConversationId = -100; |
183 QString MsgIndicator::prepareDisplayName(IndicatorData& indicatorData) const |
277 |
184 |
278 d_ptr->getIndicatorInfo(data); |
185 { |
279 |
186 //Set the Contact Name/Number |
280 mConversationFromSingleContact = data.mFromSingle; |
187 QString firstName(indicatorData.mFirstName); |
281 mBodyText = data.mDescription; |
188 QString lastName(indicatorData.mLastName); |
282 |
189 QString contactAddress(indicatorData.mContactNum); |
283 if (mConversationFromSingleContact) { |
190 QString nickName(indicatorData.mNickName); |
284 mConversationId = (int) data.mConversationId; |
191 |
285 QString name = data.mDisplayName.at(0); |
192 QString displayName; |
286 name.append(QString(" (%1)").arg(data.mMsgCount)); |
193 |
287 return name; |
194 if (!nickName.isEmpty()) |
288 } |
195 { |
289 else { |
196 displayName.append(nickName); |
290 QString text = QString("%1 ").arg(mCount) + LOC_UNREAD_MULTIPLE_MESSAGES; |
197 } |
291 return text; |
198 else if ( firstName.isEmpty() && lastName.isEmpty()) |
292 } |
199 { |
293 |
200 displayName.append(contactAddress); |
294 } |
201 } |
295 |
202 else if (lastName.isEmpty() && !firstName.isEmpty()) |
296 // ---------------------------------------------------------------------------- |
203 { |
297 // MsgIndicator::getSecondaryText |
204 displayName.append(firstName); |
298 // @see msgindicator.h |
205 } |
299 // ---------------------------------------------------------------------------- |
206 else if (firstName.isEmpty() && !lastName.isEmpty()) |
300 QString MsgIndicator::getSecondaryText(MsgInfo& info) |
207 { |
301 { |
208 displayName.append(lastName); |
302 QString secondaryText(""); |
209 } |
303 |
210 else |
304 if (info.mIndicatorType == NewIndicatorPlugin) { |
211 { |
305 secondaryText = info.mDescription; |
212 // If both first Name and last name are present |
306 |
213 displayName.append(firstName); |
307 if (info.mFromSingle) { |
214 displayName.append(" "); |
308 if (ECsBlueTooth == info.mMessageType) { |
215 displayName.append(lastName); |
309 QFileInfo fname(secondaryText); |
216 } |
310 secondaryText = fname.fileName(); |
217 return displayName; |
311 } |
218 } |
312 } |
|
313 else { |
|
314 info.mConversationId = -100; |
|
315 } |
|
316 } |
|
317 else { |
|
318 info.mDisplayName.removeDuplicates(); |
|
319 info.mDisplayName.sort(); |
|
320 int count = info.mDisplayName.count(); |
|
321 if (count > 1) { |
|
322 info.mConversationId = -100; |
|
323 } |
|
324 |
|
325 secondaryText.append(info.mDisplayName.at(0)); |
|
326 for (int i = 1; i < info.mDisplayName.count(); ++i) { |
|
327 secondaryText.append(", "); |
|
328 secondaryText.append(info.mDisplayName.at(i)); |
|
329 } |
|
330 } |
|
331 return secondaryText; |
|
332 } |