|
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 static const char NEW_MSG_ICON[] = "qtg_large_new_message"; |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // ServiceRequestSenderTask::ServiceRequestSenderTask |
|
43 // @see msgnotificationdialogwidget.h |
|
44 // ---------------------------------------------------------------------------- |
|
45 ServiceRequestSenderTask::ServiceRequestSenderTask(qint64 conversationId): |
|
46 mConvId(conversationId) |
|
47 { |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // ServiceRequestSenderTask::~ServiceRequestSenderTask |
|
52 // @see msgnotificationdialogwidget.h |
|
53 // ---------------------------------------------------------------------------- |
|
54 ServiceRequestSenderTask::~ServiceRequestSenderTask() |
|
55 { |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // ServiceRequestSenderTask::run |
|
60 // @see msgnotificationdialogwidget.h |
|
61 // ---------------------------------------------------------------------------- |
|
62 void ServiceRequestSenderTask::run() |
|
63 { |
|
64 QList<QVariant> args; |
|
65 QString serviceName("com.nokia.services.hbserviceprovider"); |
|
66 QString operation("open(qint64)"); |
|
67 XQAiwRequest* request; |
|
68 XQApplicationManager appManager; |
|
69 request = appManager.create(serviceName, "conversationview", operation, false); // not embedded |
|
70 if ( request == NULL ) |
|
71 { |
|
72 return; |
|
73 } |
|
74 args << QVariant(mConvId); |
|
75 request->setArguments(args); |
|
76 request->send(); |
|
77 delete request; |
|
78 } |
|
79 |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // MsgNotificationDialogWidget::MsgNotificationDialogWidget |
|
83 // @see msgnotificationdialogwidget.h |
|
84 // ---------------------------------------------------------------------------- |
|
85 MsgNotificationDialogWidget::MsgNotificationDialogWidget( |
|
86 const QVariantMap ¶meters) |
|
87 : HbNotificationDialog(), |
|
88 mLastError(NoError), |
|
89 mShowEventReceived(false), |
|
90 mConversationId(-1) |
|
91 { |
|
92 constructDialog(parameters); |
|
93 } |
|
94 |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // MsgNotificationDialogWidget::setDeviceDialogParameters |
|
98 // @see msgnotificationdialogwidget.h |
|
99 // ---------------------------------------------------------------------------- |
|
100 bool MsgNotificationDialogWidget::setDeviceDialogParameters( |
|
101 const QVariantMap ¶meters) |
|
102 { |
|
103 return constructDialog(parameters); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // MsgNotificationDialogWidget::constructDialog |
|
108 // @see msgnotificationdialogwidget.h |
|
109 // ---------------------------------------------------------------------------- |
|
110 bool MsgNotificationDialogWidget::constructDialog( |
|
111 const QVariantMap ¶meters) |
|
112 { |
|
113 // Set parameters |
|
114 mLastError = NoError; |
|
115 |
|
116 // if conversation id is not proper return false |
|
117 mConversationId = parameters.value(KConversationIdKey).toLongLong(); |
|
118 if( mConversationId <= 0) |
|
119 { |
|
120 mLastError = ParameterError; |
|
121 return false; |
|
122 } |
|
123 |
|
124 prepareDisplayName(parameters); |
|
125 |
|
126 setIcon(HbIcon(NEW_MSG_ICON)); |
|
127 |
|
128 int messageType = parameters.value(KMessageTypeKey).toInt(); |
|
129 if( messageType == ECsSMS) |
|
130 { |
|
131 QString messageBody; |
|
132 messageBody = parameters.value(KMessageBodyKey).toString(); |
|
133 messageBody.replace(QChar::ParagraphSeparator, QChar::LineSeparator); |
|
134 messageBody.replace('\r', QChar::LineSeparator); |
|
135 setText(messageBody); |
|
136 } |
|
137 else |
|
138 { |
|
139 // No special handling required for other message types. |
|
140 // Subject & Body text are both set to description in msgnotifier. |
|
141 setText(parameters.value(KMessageSubjectKey).toString()); |
|
142 } |
|
143 |
|
144 // enable touch activation and connect to slot |
|
145 enableTouchActivation(true); |
|
146 connect(this, SIGNAL(activated()), this, SLOT(widgetActivated())); |
|
147 |
|
148 // set the standard timeout value, that is used by default notificaitons dialogs |
|
149 setTimeout(HbPopup::StandardTimeout); |
|
150 |
|
151 return true; |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // MsgNotificationDialogWidget::deviceDialogError |
|
156 // @see msgnotificationdialogwidget.h |
|
157 // ---------------------------------------------------------------------------- |
|
158 int MsgNotificationDialogWidget::deviceDialogError() const |
|
159 { |
|
160 // Get error |
|
161 return mLastError; |
|
162 } |
|
163 |
|
164 // ---------------------------------------------------------------------------- |
|
165 // MsgNotificationDialogWidget::closeDeviceDialog |
|
166 // @see msgnotificationdialogwidget.h |
|
167 // ---------------------------------------------------------------------------- |
|
168 void MsgNotificationDialogWidget::closeDeviceDialog(bool byClient) |
|
169 { |
|
170 // Close device dialog |
|
171 Q_UNUSED(byClient); |
|
172 close(); |
|
173 // If show event has been received, close is signalled from hide event. If not, |
|
174 // hide event does not come and close is signalled from here. |
|
175 if (!mShowEventReceived) { |
|
176 emit deviceDialogClosed(); |
|
177 } |
|
178 |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // MsgNotificationDialogWidget::deviceDialogWidget |
|
183 // @see msgnotificationdialogwidget.h |
|
184 // ---------------------------------------------------------------------------- |
|
185 HbDialog *MsgNotificationDialogWidget::deviceDialogWidget() const |
|
186 { |
|
187 // Return display widget |
|
188 return const_cast<MsgNotificationDialogWidget*>(this); |
|
189 } |
|
190 |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // MsgNotificationDialogWidget::hideEvent |
|
194 // @see msgnotificationdialogwidget.h |
|
195 // ---------------------------------------------------------------------------- |
|
196 void MsgNotificationDialogWidget::hideEvent(QHideEvent *event) |
|
197 { |
|
198 HbNotificationDialog::hideEvent(event); |
|
199 emit deviceDialogClosed(); |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // MsgNotificationDialogWidget::showEvent |
|
204 // @see msgnotificationdialogwidget.h |
|
205 // ---------------------------------------------------------------------------- |
|
206 void MsgNotificationDialogWidget::showEvent(QShowEvent *event) |
|
207 { |
|
208 HbNotificationDialog::showEvent(event); |
|
209 mShowEventReceived = true; |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------------------------------- |
|
213 // MsgNotificationDialogWidget::widgetActivated |
|
214 // @see msgnotificationdialogwidget.h |
|
215 // ---------------------------------------------------------------------------- |
|
216 void MsgNotificationDialogWidget::widgetActivated() |
|
217 { |
|
218 QThreadPool::globalInstance()->start( |
|
219 new ServiceRequestSenderTask(mConversationId)); |
|
220 enableTouchActivation(false); |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // MsgNotificationDialogWidget::prepareDisplayName |
|
225 // @see msgnotificationdialogwidget.h |
|
226 // ---------------------------------------------------------------------------- |
|
227 void MsgNotificationDialogWidget::prepareDisplayName( |
|
228 const QVariantMap ¶meters) |
|
229 { |
|
230 //Set the Contact Name/Number |
|
231 QString displayName = parameters.value(KDisplayNameKey).toString(); |
|
232 QString contactAddress = parameters.value(KContactAddressKey).toString(); |
|
233 |
|
234 if (displayName.isEmpty()) |
|
235 { |
|
236 setTitle(contactAddress); |
|
237 } |
|
238 else |
|
239 { |
|
240 setTitle(displayName); |
|
241 } |
|
242 } |