|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <hbaction.h> |
|
27 #include <hbdialog.h> |
|
28 #include <hbdevicedialogtrace_p.h> |
|
29 #include <hbiconanimationmanager.h> |
|
30 #include "hbdevicemessageboxwidget_p.h" |
|
31 #include "hbdevicemessageboxpluginerrors_p.h" |
|
32 |
|
33 // Constructor |
|
34 HbDeviceMessageBoxWidget::HbDeviceMessageBoxWidget( |
|
35 HbMessageBox::MessageBoxType type, const QVariantMap ¶meters) : HbMessageBox(type) |
|
36 { |
|
37 TRACE_ENTRY |
|
38 mLastError = NoError; |
|
39 mShowEventReceived = false; |
|
40 mPrimaryAction = 0; |
|
41 mSecondaryAction = 0; |
|
42 resetProperties(); |
|
43 constructDialog(parameters); |
|
44 if (!mPrimaryAction) { |
|
45 // If default button provided by HbMessageBox is used, connect into its triggered signal. |
|
46 HbAction *action = primaryAction(); |
|
47 if (action) { |
|
48 connect(action, SIGNAL(triggered()), SLOT(primaryActionTriggered())); |
|
49 } |
|
50 } |
|
51 if (!mSecondaryAction) { |
|
52 // If default button provided by HbMessageBox is used, connect into its triggered signal. |
|
53 HbAction *action = secondaryAction(); |
|
54 if (action) { |
|
55 connect(action, SIGNAL(triggered()), SLOT(secondaryActionTriggered())); |
|
56 } |
|
57 } |
|
58 |
|
59 TRACE_EXIT |
|
60 } |
|
61 |
|
62 // Destructor |
|
63 HbDeviceMessageBoxWidget::~HbDeviceMessageBoxWidget() |
|
64 { |
|
65 delete mPrimaryAction; |
|
66 delete mSecondaryAction; |
|
67 } |
|
68 |
|
69 // Set parameters |
|
70 bool HbDeviceMessageBoxWidget::setDeviceDialogParameters( |
|
71 const QVariantMap ¶meters) |
|
72 { |
|
73 TRACE_ENTRY |
|
74 mLastError = NoError; |
|
75 bool ret(false); |
|
76 if (checkProperties(parameters)) { |
|
77 setProperties(parameters); |
|
78 ret = true; |
|
79 } |
|
80 else { |
|
81 mLastError = ParameterError; |
|
82 ret = false; |
|
83 } |
|
84 TRACE_EXIT |
|
85 return ret; |
|
86 } |
|
87 |
|
88 // Get error |
|
89 int HbDeviceMessageBoxWidget::deviceDialogError() const |
|
90 { |
|
91 TRACE_ENTRY |
|
92 TRACE_EXIT |
|
93 return mLastError; |
|
94 } |
|
95 |
|
96 // Close device dialog |
|
97 void HbDeviceMessageBoxWidget::closeDeviceDialog(bool byClient) |
|
98 { |
|
99 TRACE_ENTRY |
|
100 Q_UNUSED(byClient); |
|
101 // Closed by client or internally by server -> no action to be transmitted. |
|
102 mSendAction = false; |
|
103 close(); |
|
104 // If show event has been received, close is signalled from hide event. If not, |
|
105 // hide event does not come and close is signalled from here. |
|
106 if (!mShowEventReceived) { |
|
107 emit deviceDialogClosed(); |
|
108 } |
|
109 TRACE_EXIT |
|
110 } |
|
111 |
|
112 // Return display widget |
|
113 HbDialog *HbDeviceMessageBoxWidget::deviceDialogWidget() const |
|
114 { |
|
115 TRACE_ENTRY |
|
116 TRACE_EXIT |
|
117 return const_cast<HbDeviceMessageBoxWidget*>(this); |
|
118 } |
|
119 |
|
120 // Construct dialog |
|
121 bool HbDeviceMessageBoxWidget::constructDialog(const QVariantMap ¶meters) |
|
122 { |
|
123 TRACE_ENTRY |
|
124 bool ret(false); |
|
125 // Check that parameters are valid |
|
126 if (!checkProperties(parameters)) { |
|
127 mLastError = ParameterError; |
|
128 ret = false; |
|
129 } |
|
130 else { |
|
131 setProperties(parameters); |
|
132 ret = true; |
|
133 } |
|
134 TRACE_EXIT |
|
135 return ret; |
|
136 } |
|
137 |
|
138 // Check that device dialog parameters are valid |
|
139 bool HbDeviceMessageBoxWidget::checkProperties(const QVariantMap ¶meters) |
|
140 { |
|
141 TRACE_ENTRY |
|
142 QVariantMap::const_iterator i = parameters.constBegin(); |
|
143 while (i != parameters.constEnd()) { |
|
144 QByteArray key = i.key().toAscii(); |
|
145 if (!property(key.constData()).isValid()) { |
|
146 TRACE_EXIT |
|
147 return false; |
|
148 } |
|
149 ++i; |
|
150 } |
|
151 TRACE_EXIT |
|
152 return true; |
|
153 } |
|
154 |
|
155 // Set properties |
|
156 void HbDeviceMessageBoxWidget::setProperties(const QVariantMap ¶meters) |
|
157 { |
|
158 TRACE_ENTRY |
|
159 QVariantMap::const_iterator i = parameters.constBegin(); |
|
160 while (i != parameters.constEnd()) { |
|
161 QByteArray key = i.key().toAscii(); |
|
162 if (property(key.constData()).isValid()) { |
|
163 setProperty(key.constData(), i.value()); |
|
164 } |
|
165 ++i; |
|
166 } |
|
167 TRACE_EXIT |
|
168 return; |
|
169 } |
|
170 |
|
171 // Reset properties to default values |
|
172 void HbDeviceMessageBoxWidget::resetProperties() |
|
173 { |
|
174 TRACE_ENTRY |
|
175 mIconName.clear(); |
|
176 setModal(true); |
|
177 setTimeout(HbPopup::NoTimeout); |
|
178 setDismissPolicy(HbPopup::NoDismiss); |
|
179 mSendAction = true; |
|
180 TRACE_EXIT |
|
181 return; |
|
182 } |
|
183 |
|
184 QString HbDeviceMessageBoxWidget::iconName() const |
|
185 { |
|
186 TRACE_ENTRY |
|
187 TRACE_EXIT |
|
188 return mIconName; |
|
189 } |
|
190 |
|
191 void HbDeviceMessageBoxWidget::setIconName(QString &iconName) |
|
192 { |
|
193 TRACE_ENTRY |
|
194 if (mIconName != iconName) { |
|
195 mIconName = iconName; |
|
196 setIcon(HbIcon(mIconName)); |
|
197 } |
|
198 TRACE_EXIT |
|
199 return; |
|
200 } |
|
201 |
|
202 QString HbDeviceMessageBoxWidget::primaryActionText() const |
|
203 { |
|
204 HbAction *action = primaryAction(); |
|
205 return action ? action->text() : QString(); |
|
206 } |
|
207 |
|
208 void HbDeviceMessageBoxWidget::setPrimaryActionText(QString &actionText) |
|
209 { |
|
210 TRACE_ENTRY |
|
211 HbAction *action = primaryAction(); |
|
212 if (action) { |
|
213 action->setText(actionText); |
|
214 } else { |
|
215 if (!mPrimaryAction) { |
|
216 mPrimaryAction = new HbAction(actionText); |
|
217 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggered())); |
|
218 } else { |
|
219 mPrimaryAction->setText(actionText); |
|
220 } |
|
221 setPrimaryAction(mPrimaryAction); |
|
222 } |
|
223 TRACE_EXIT |
|
224 } |
|
225 |
|
226 QString HbDeviceMessageBoxWidget::secondaryActionText() const |
|
227 { |
|
228 HbAction *action = secondaryAction(); |
|
229 return action ? action->text() : QString(); |
|
230 } |
|
231 |
|
232 void HbDeviceMessageBoxWidget::setSecondaryActionText(QString &actionText) |
|
233 { |
|
234 TRACE_ENTRY |
|
235 HbAction *action = secondaryAction(); |
|
236 if (action) { |
|
237 action->setText(actionText); |
|
238 } else { |
|
239 if (!mSecondaryAction) { |
|
240 mSecondaryAction = new HbAction(actionText); |
|
241 connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(secondaryActionTriggered())); |
|
242 } else { |
|
243 mSecondaryAction->setText(actionText); |
|
244 } |
|
245 setSecondaryAction(mSecondaryAction); |
|
246 } |
|
247 TRACE_EXIT |
|
248 } |
|
249 |
|
250 bool HbDeviceMessageBoxWidget::primaryActionNull() const |
|
251 { |
|
252 return primaryAction() == 0; |
|
253 } |
|
254 |
|
255 void HbDeviceMessageBoxWidget::setPrimaryActionNull(bool isNull) |
|
256 { |
|
257 TRACE_ENTRY |
|
258 if (isNull) { |
|
259 // If there is a message box's default action, disconnect from it. |
|
260 HbAction *action = primaryAction(); |
|
261 if (action && mPrimaryAction == 0) { |
|
262 action->disconnect(SIGNAL(triggered()), this, SLOT(primaryActionTriggered())); |
|
263 } |
|
264 setPrimaryAction(0); |
|
265 } else { |
|
266 QString text = mPrimaryAction ? mPrimaryAction->text() : QString(); |
|
267 setPrimaryActionText(text); |
|
268 } |
|
269 TRACE_EXIT |
|
270 } |
|
271 |
|
272 bool HbDeviceMessageBoxWidget::secondaryActionNull() const |
|
273 { |
|
274 return secondaryAction() == 0; |
|
275 } |
|
276 |
|
277 void HbDeviceMessageBoxWidget::setSecondaryActionNull(bool isNull) |
|
278 { |
|
279 TRACE_ENTRY |
|
280 if (isNull) { |
|
281 // If there is a message box's default action, disconnect from it. |
|
282 HbAction *action = secondaryAction(); |
|
283 if (action && mSecondaryAction == 0) { |
|
284 action->disconnect(SIGNAL(triggered()), this, SLOT(secondaryActionTriggered())); |
|
285 } |
|
286 setSecondaryAction(0); |
|
287 } else { |
|
288 QString text = mSecondaryAction ? mSecondaryAction->text() : QString(); |
|
289 setSecondaryActionText(text); |
|
290 } |
|
291 TRACE_EXIT |
|
292 } |
|
293 |
|
294 // Widget is about to hide. Closing effect has ended. |
|
295 void HbDeviceMessageBoxWidget::hideEvent(QHideEvent *event) |
|
296 { |
|
297 HbMessageBox::hideEvent(event); |
|
298 emit deviceDialogClosed(); |
|
299 } |
|
300 |
|
301 // Widget is about to show |
|
302 void HbDeviceMessageBoxWidget::showEvent(QShowEvent *event) |
|
303 { |
|
304 HbMessageBox::showEvent(event); |
|
305 mShowEventReceived = true; |
|
306 } |
|
307 |
|
308 void HbDeviceMessageBoxWidget::setAnimationDefinition(QString &animationDefinition) |
|
309 { |
|
310 // Load animation definition |
|
311 HbIconAnimationManager *manager = HbIconAnimationManager::global(); |
|
312 manager->addDefinitionFile(animationDefinition); |
|
313 mAnimationDefinition = animationDefinition; |
|
314 } |
|
315 |
|
316 QString HbDeviceMessageBoxWidget::animationDefinition() const |
|
317 { |
|
318 return mAnimationDefinition; |
|
319 } |
|
320 |
|
321 // Primary action triggered |
|
322 void HbDeviceMessageBoxWidget::primaryActionTriggered() |
|
323 { |
|
324 TRACE_ENTRY |
|
325 QVariantMap data; |
|
326 data.insert("act", "p"); |
|
327 emit deviceDialogData(data); |
|
328 mSendAction = false; |
|
329 TRACE_EXIT |
|
330 } |
|
331 |
|
332 // Secondary action triggered |
|
333 void HbDeviceMessageBoxWidget::secondaryActionTriggered() |
|
334 { |
|
335 TRACE_ENTRY |
|
336 QVariantMap data; |
|
337 data.insert("act", "s"); |
|
338 emit deviceDialogData(data); |
|
339 mSendAction = false; |
|
340 TRACE_EXIT |
|
341 } |