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