|
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: Widget class for Notificaiton Dialog Plugin |
|
15 * |
|
16 */ |
|
17 #include <QThreadPool> |
|
18 #include <QRunnable> |
|
19 #include "debugtraces.h" |
|
20 |
|
21 #include <ccsdefs.h> |
|
22 #include <QIcon> |
|
23 #include <QVariant> |
|
24 #include <QList> |
|
25 #include <hbicon.h> |
|
26 #include <hbpopup.h> |
|
27 #include <xqservicerequest.h> |
|
28 #include <xqaiwrequest.h> |
|
29 #include <xqappmgr.h> |
|
30 |
|
31 #include "convergedmessage.h" |
|
32 |
|
33 #include "msgnotificationdialogpluginkeys.h" |
|
34 #include "msgnotificationdialogwidget.h" |
|
35 |
|
36 const int NoError = 0; |
|
37 const int ParameterError = 10000; |
|
38 |
|
39 const QString BT_ICON("qtg_large_bluetooth"); |
|
40 const QString SMS_ICON("qtg_large_new_message"); |
|
41 const QString MMS_ICON("qtg_large_new_message"); |
|
42 const QString RINGTONE_ICON("qtg_large_tone"); |
|
43 const QString VCARD_ICON("qtg_large_new_message"); |
|
44 // ---------------------------------------------------------------------------- |
|
45 // ServiceRequestSenderTask::ServiceRequestSenderTask |
|
46 // @see msgnotificationdialogwidget.h |
|
47 // ---------------------------------------------------------------------------- |
|
48 ServiceRequestSenderTask::ServiceRequestSenderTask(qint64 conversationId): |
|
49 mConvId(conversationId) |
|
50 { |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // ServiceRequestSenderTask::~ServiceRequestSenderTask |
|
55 // @see msgnotificationdialogwidget.h |
|
56 // ---------------------------------------------------------------------------- |
|
57 ServiceRequestSenderTask::~ServiceRequestSenderTask() |
|
58 { |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // ServiceRequestSenderTask::run |
|
63 // @see msgnotificationdialogwidget.h |
|
64 // ---------------------------------------------------------------------------- |
|
65 void ServiceRequestSenderTask::run() |
|
66 { |
|
67 QList<QVariant> args; |
|
68 QString serviceName("com.nokia.services.hbserviceprovider"); |
|
69 QString operation("open(qint64)"); |
|
70 XQAiwRequest* request; |
|
71 XQApplicationManager appManager; |
|
72 request = appManager.create(serviceName, "conversationview", operation, false); // not embedded |
|
73 if ( request == NULL ) |
|
74 { |
|
75 return; |
|
76 } |
|
77 args << QVariant(mConvId); |
|
78 request->setArguments(args); |
|
79 request->send(); |
|
80 delete request; |
|
81 } |
|
82 |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // MsgNotificationDialogWidget::MsgNotificationDialogWidget |
|
86 // @see msgnotificationdialogwidget.h |
|
87 // ---------------------------------------------------------------------------- |
|
88 MsgNotificationDialogWidget::MsgNotificationDialogWidget( |
|
89 const QVariantMap ¶meters) |
|
90 : HbNotificationDialog(), |
|
91 mLastError(NoError), |
|
92 mShowEventReceived(false), |
|
93 mConversationId(-1) |
|
94 { |
|
95 constructDialog(parameters); |
|
96 } |
|
97 |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // MsgNotificationDialogWidget::setDeviceDialogParameters |
|
101 // @see msgnotificationdialogwidget.h |
|
102 // ---------------------------------------------------------------------------- |
|
103 bool MsgNotificationDialogWidget::setDeviceDialogParameters( |
|
104 const QVariantMap ¶meters) |
|
105 { |
|
106 return constructDialog(parameters); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // MsgNotificationDialogWidget::constructDialog |
|
111 // @see msgnotificationdialogwidget.h |
|
112 // ---------------------------------------------------------------------------- |
|
113 bool MsgNotificationDialogWidget::constructDialog( |
|
114 const QVariantMap ¶meters) |
|
115 { |
|
116 // Set parameters |
|
117 mLastError = NoError; |
|
118 |
|
119 // if conversation id is not proper return false |
|
120 mConversationId = parameters.value(KConversationIdKey).toLongLong(); |
|
121 if( mConversationId <= 0) |
|
122 { |
|
123 mLastError = ParameterError; |
|
124 return false; |
|
125 } |
|
126 |
|
127 prepareDisplayName(parameters); |
|
128 |
|
129 int messageType = parameters.value(KMessageTypeKey).toInt(); |
|
130 if( messageType == ECsSMS) |
|
131 { |
|
132 HbIcon icon(SMS_ICON); |
|
133 setIcon(icon); |
|
134 QString messageBody; |
|
135 messageBody = parameters.value(KMessageBodyKey).toString(); |
|
136 messageBody.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
137 messageBody.replace('\r', QChar::LineSeparator); |
|
138 setText(messageBody); |
|
139 } |
|
140 else if(messageType == ECsMMS) |
|
141 { |
|
142 HbIcon icon(MMS_ICON); |
|
143 setIcon(icon); |
|
144 setText(parameters.value(KMessageSubjectKey).toString()); |
|
145 } |
|
146 else if(messageType == ECsMmsNotification) |
|
147 { |
|
148 HbIcon icon(MMS_ICON); |
|
149 setIcon(icon); |
|
150 setText(parameters.value(KMessageSubjectKey).toString()); |
|
151 } |
|
152 else if(messageType == ECsRingingTone) |
|
153 { |
|
154 HbIcon icon(RINGTONE_ICON); |
|
155 setIcon(icon); |
|
156 setText(parameters.value(KMessageBodyKey).toString()); |
|
157 } |
|
158 else if(messageType == ECsBlueTooth) |
|
159 { |
|
160 HbIcon icon(BT_ICON); // show default for other message types |
|
161 setIcon(icon); |
|
162 setText(parameters.value(KMessageBodyKey).toString()); |
|
163 } |
|
164 else if(messageType == ECsBioMsg_VCard) |
|
165 { |
|
166 HbIcon icon(VCARD_ICON); // show default for other message types |
|
167 setIcon(icon); |
|
168 setText(parameters.value(KMessageBodyKey).toString()); |
|
169 } |
|
170 else |
|
171 { |
|
172 setText(parameters.value(KMessageBodyKey).toString()); |
|
173 } |
|
174 |
|
175 // enable touch activation and connect to slot |
|
176 enableTouchActivation(true); |
|
177 connect(this, SIGNAL(activated()), this, SLOT(widgetActivated())); |
|
178 |
|
179 // set the standard timeout value, that is used by default notificaitons dialogs |
|
180 setTimeout(HbPopup::StandardTimeout); |
|
181 |
|
182 return true; |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // MsgNotificationDialogWidget::deviceDialogError |
|
187 // @see msgnotificationdialogwidget.h |
|
188 // ---------------------------------------------------------------------------- |
|
189 int MsgNotificationDialogWidget::deviceDialogError() const |
|
190 { |
|
191 // Get error |
|
192 return mLastError; |
|
193 } |
|
194 |
|
195 // ---------------------------------------------------------------------------- |
|
196 // MsgNotificationDialogWidget::closeDeviceDialog |
|
197 // @see msgnotificationdialogwidget.h |
|
198 // ---------------------------------------------------------------------------- |
|
199 void MsgNotificationDialogWidget::closeDeviceDialog(bool byClient) |
|
200 { |
|
201 // Close device dialog |
|
202 Q_UNUSED(byClient); |
|
203 close(); |
|
204 // If show event has been received, close is signalled from hide event. If not, |
|
205 // hide event does not come and close is signalled from here. |
|
206 if (!mShowEventReceived) { |
|
207 emit deviceDialogClosed(); |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------------------------------- |
|
213 // MsgNotificationDialogWidget::deviceDialogWidget |
|
214 // @see msgnotificationdialogwidget.h |
|
215 // ---------------------------------------------------------------------------- |
|
216 HbDialog *MsgNotificationDialogWidget::deviceDialogWidget() const |
|
217 { |
|
218 // Return display widget |
|
219 return const_cast<MsgNotificationDialogWidget*>(this); |
|
220 } |
|
221 |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // MsgNotificationDialogWidget::hideEvent |
|
225 // @see msgnotificationdialogwidget.h |
|
226 // ---------------------------------------------------------------------------- |
|
227 void MsgNotificationDialogWidget::hideEvent(QHideEvent *event) |
|
228 { |
|
229 HbNotificationDialog::hideEvent(event); |
|
230 emit deviceDialogClosed(); |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // MsgNotificationDialogWidget::showEvent |
|
235 // @see msgnotificationdialogwidget.h |
|
236 // ---------------------------------------------------------------------------- |
|
237 void MsgNotificationDialogWidget::showEvent(QShowEvent *event) |
|
238 { |
|
239 HbNotificationDialog::showEvent(event); |
|
240 mShowEventReceived = true; |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // MsgNotificationDialogWidget::widgetActivated |
|
245 // @see msgnotificationdialogwidget.h |
|
246 // ---------------------------------------------------------------------------- |
|
247 void MsgNotificationDialogWidget::widgetActivated() |
|
248 { |
|
249 QThreadPool::globalInstance()->start( |
|
250 new ServiceRequestSenderTask(mConversationId)); |
|
251 enableTouchActivation(false); |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------------------------- |
|
255 // MsgNotificationDialogWidget::prepareDisplayName |
|
256 // @see msgnotificationdialogwidget.h |
|
257 // ---------------------------------------------------------------------------- |
|
258 void MsgNotificationDialogWidget::prepareDisplayName( |
|
259 const QVariantMap ¶meters) |
|
260 { |
|
261 //Set the Contact Name/Number |
|
262 QString displayName = parameters.value(KDisplayNameKey).toString(); |
|
263 QString contactAddress = parameters.value(KContactAddressKey).toString(); |
|
264 |
|
265 if (displayName.isEmpty()) |
|
266 { |
|
267 setTitle(contactAddress); |
|
268 } |
|
269 else |
|
270 { |
|
271 setTitle(displayName); |
|
272 } |
|
273 } |