|
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 <QtDebug> |
|
27 #include <QIcon> |
|
28 #include <QVariant> |
|
29 #include <QList> |
|
30 #include <hbicon.h> |
|
31 #include <hbiconanimationmanager.h> |
|
32 #include <hbdevicedialogtrace_p.h> |
|
33 #include "hbdevicenotificationdialogwidget_p.h" |
|
34 #include "hbdevicenotificationdialogpluginerrors_p.h" |
|
35 |
|
36 #ifdef HB_EFFECTS |
|
37 #include "hbeffectinternal_p.h" |
|
38 #endif |
|
39 |
|
40 // Constructor |
|
41 HbDeviceNotificationDialogWidget::HbDeviceNotificationDialogWidget(const QVariantMap ¶meters) |
|
42 : HbNotificationDialog() |
|
43 { |
|
44 TRACE_ENTRY |
|
45 mLastError = NoError; |
|
46 mShowEventReceived = false; |
|
47 resetProperties(); |
|
48 constructDialog(parameters); |
|
49 |
|
50 #ifdef HB_EFFECTS |
|
51 HbEffectInternal::add(this, "devicenotificationdialog_appear", "appear"); |
|
52 HbEffectInternal::add(this, "devicenotificationdialog_disappear", "disappear"); |
|
53 #endif |
|
54 |
|
55 TRACE_EXIT |
|
56 } |
|
57 |
|
58 HbDeviceNotificationDialogWidget::~HbDeviceNotificationDialogWidget() |
|
59 { |
|
60 #ifdef HB_EFFECTS |
|
61 HbEffectInternal::remove(this); |
|
62 #endif |
|
63 } |
|
64 |
|
65 // Set parameters |
|
66 bool HbDeviceNotificationDialogWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
67 { |
|
68 TRACE_ENTRY |
|
69 bool ret(false); |
|
70 mLastError = NoError; |
|
71 if (checkProperties(parameters)) { |
|
72 setProperties(parameters); |
|
73 ret = true; |
|
74 } |
|
75 TRACE_EXIT |
|
76 return ret; |
|
77 } |
|
78 |
|
79 // Get error |
|
80 int HbDeviceNotificationDialogWidget::deviceDialogError() const |
|
81 { |
|
82 TRACE_ENTRY |
|
83 TRACE_EXIT |
|
84 return mLastError; |
|
85 } |
|
86 |
|
87 // Close device dialog |
|
88 void HbDeviceNotificationDialogWidget::closeDeviceDialog(bool byClient) |
|
89 { |
|
90 TRACE_ENTRY |
|
91 Q_UNUSED(byClient); |
|
92 close(); |
|
93 // If show event has been received, close is signalled from hide event. If not, |
|
94 // hide event does not come and close is signalled from here. |
|
95 if (!mShowEventReceived) { |
|
96 emit deviceDialogClosed(); |
|
97 } |
|
98 TRACE_EXIT |
|
99 } |
|
100 |
|
101 // Return display widget |
|
102 HbDialog *HbDeviceNotificationDialogWidget::deviceDialogWidget() const |
|
103 { |
|
104 TRACE_ENTRY |
|
105 TRACE_EXIT |
|
106 return const_cast<HbDeviceNotificationDialogWidget*>(this); |
|
107 } |
|
108 |
|
109 // Construct device dialog |
|
110 bool HbDeviceNotificationDialogWidget::constructDialog(const QVariantMap ¶meters) |
|
111 { |
|
112 TRACE_ENTRY |
|
113 mLastError = NoError; |
|
114 bool ret = checkProperties(parameters); |
|
115 |
|
116 if (ret) { |
|
117 connect(this, SIGNAL(activated()), this, SLOT(widgetActivated())); |
|
118 setProperties(parameters); |
|
119 } |
|
120 |
|
121 TRACE_EXIT |
|
122 return ret; |
|
123 } |
|
124 |
|
125 // Check that device dialog parameters are valid |
|
126 bool HbDeviceNotificationDialogWidget::checkProperties(const QVariantMap ¶meters) |
|
127 { |
|
128 TRACE_ENTRY |
|
129 bool ret(true); |
|
130 |
|
131 QVariantMap::const_iterator i = parameters.constBegin(); |
|
132 while (i != parameters.constEnd()) { |
|
133 QByteArray key = i.key().toAscii(); |
|
134 if (!property(key.constData()).isValid()) { |
|
135 TRACE_EXIT |
|
136 mLastError = ParameterError; |
|
137 ret = false; |
|
138 break; |
|
139 } |
|
140 ++i; |
|
141 } |
|
142 |
|
143 TRACE_EXIT |
|
144 return ret; |
|
145 } |
|
146 |
|
147 // Set properties |
|
148 void HbDeviceNotificationDialogWidget::setProperties(const QVariantMap ¶meters) |
|
149 { |
|
150 TRACE_ENTRY |
|
151 QVariantMap::const_iterator i = parameters.constBegin(); |
|
152 while (i != parameters.constEnd()) { |
|
153 QByteArray key = i.key().toAscii(); |
|
154 if (property(key.constData()).isValid()) { |
|
155 setProperty(key.constData(), i.value()); |
|
156 } |
|
157 ++i; |
|
158 } |
|
159 |
|
160 TRACE_EXIT |
|
161 } |
|
162 |
|
163 // Reset properties to default values |
|
164 void HbDeviceNotificationDialogWidget::resetProperties() |
|
165 { |
|
166 TRACE_ENTRY |
|
167 mIconFilename.clear(); |
|
168 TRACE_EXIT |
|
169 return; |
|
170 } |
|
171 |
|
172 QString HbDeviceNotificationDialogWidget::iconName() const |
|
173 { |
|
174 TRACE_ENTRY |
|
175 TRACE_EXIT |
|
176 return mIconFilename; |
|
177 } |
|
178 |
|
179 void HbDeviceNotificationDialogWidget::setIconName(QString iconName) |
|
180 { |
|
181 TRACE_ENTRY |
|
182 HbIcon hbicon(iconName); |
|
183 setIcon(hbicon); |
|
184 TRACE_EXIT |
|
185 } |
|
186 |
|
187 // Widget is about to hide. Closing effect has ended. |
|
188 void HbDeviceNotificationDialogWidget::hideEvent(QHideEvent *event) |
|
189 { |
|
190 HbNotificationDialog::hideEvent(event); |
|
191 emit deviceDialogClosed(); |
|
192 } |
|
193 |
|
194 // Widget is about to show |
|
195 void HbDeviceNotificationDialogWidget::showEvent(QShowEvent *event) |
|
196 { |
|
197 HbNotificationDialog::showEvent(event); |
|
198 mShowEventReceived = true; |
|
199 } |
|
200 |
|
201 QString HbDeviceNotificationDialogWidget::animationDefinition() const |
|
202 { |
|
203 TRACE_ENTRY |
|
204 TRACE_EXIT |
|
205 return mAnimationDefinition; |
|
206 } |
|
207 |
|
208 void HbDeviceNotificationDialogWidget::setAnimationDefinition(QString &animationDefinition) |
|
209 { |
|
210 TRACE_ENTRY |
|
211 HbIconAnimationManager *manager = HbIconAnimationManager::global(); |
|
212 manager->addDefinitionFile(animationDefinition); |
|
213 mAnimationDefinition = animationDefinition; |
|
214 TRACE_EXIT |
|
215 } |
|
216 |
|
217 void HbDeviceNotificationDialogWidget::widgetActivated() |
|
218 { |
|
219 TRACE_ENTRY |
|
220 QVariantMap map; |
|
221 map[QString("result")] = "activated"; |
|
222 emit deviceDialogData(map); |
|
223 TRACE_EXIT |
|
224 } |