15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <qstatemachine.h> |
18 #include <qstatemachine.h> |
19 #include <hblabel.h> |
19 #include <hblabel.h> |
20 #include <hsiwidgetprovider.h> |
|
21 #include <hsshortcutservice.h> |
20 #include <hsshortcutservice.h> |
22 #include <hscontentservice.h> |
21 #include <hscontentservice.h> |
23 #include <hbmessagebox.h> |
22 #include <hbmessagebox.h> |
24 #include <hbaction.h> |
23 #include <hbaction.h> |
25 #include <hbnotificationdialog.h> |
24 #include <hbnotificationdialog.h> |
26 #include <hsmenueventfactory.h> |
25 #include <hsmenueventfactory.h> |
|
26 #include "hsmenudialogfactory.h" |
|
27 #include "hsmenuentryremovedhandler.h" |
27 |
28 |
28 #include "hsaddtohomescreenstate.h" |
29 #include "hsaddtohomescreenstate.h" |
29 #include "hsmenuevent.h" |
30 #include "hsmenuevent.h" |
30 #include "canotifier.h" |
31 #include "canotifier.h" |
31 #include "canotifierfilter.h" |
32 #include "canotifierfilter.h" |
54 \retval void |
55 \retval void |
55 */ |
56 */ |
56 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) : |
57 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) : |
57 QState(parent), |
58 QState(parent), |
58 mCorruptedMessage(NULL), mConfirmAction(NULL), |
59 mCorruptedMessage(NULL), mConfirmAction(NULL), |
59 mMenuMode(NormalHsMenuMode), |
60 mMenuMode(NormalHsMenuMode) |
60 mNotifier(0) |
|
61 { |
61 { |
62 setObjectName("/AddToHomeScreenState"); |
62 setObjectName("/AddToHomeScreenState"); |
63 |
63 |
64 if (this->parent()) { |
64 if (this->parent()) { |
65 setObjectName(this->parent()->objectName() + objectName()); |
65 setObjectName(this->parent()->objectName() + objectName()); |
138 QVariantHash params; |
138 QVariantHash params; |
139 params[URI] = uri; |
139 params[URI] = uri; |
140 params[HOMESCREENDATA] = mToken; |
140 params[HOMESCREENDATA] = mToken; |
141 bool success = contentService.createWidget(params); |
141 bool success = contentService.createWidget(params); |
142 if (!success) { |
142 if (!success) { |
143 subscribeForMemoryCardRemove(); |
|
144 showMessageWidgetCorrupted(); |
143 showMessageWidgetCorrupted(); |
145 } else { |
144 } else { |
146 emit exit(); |
145 emit exit(); |
147 if (mMenuMode == AddHsMenuMode) { |
146 if (mMenuMode == AddHsMenuMode) { |
148 machine()->postEvent( |
147 machine()->postEvent( |
161 */ |
160 */ |
162 void HsAddToHomeScreenState::showMessageWidgetCorrupted() |
161 void HsAddToHomeScreenState::showMessageWidgetCorrupted() |
163 { |
162 { |
164 HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted"); |
163 HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted"); |
165 |
164 |
166 mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
165 mCorruptedMessage = HsMenuDialogFactory().create( |
167 mCorruptedMessage->setAttribute(Qt::WA_DeleteOnClose); |
166 hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi")); |
168 |
167 mConfirmAction = mCorruptedMessage->actions().value(0); |
169 QString message(hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi")); |
168 |
170 mCorruptedMessage->setText(message); |
169 QScopedPointer<HsMenuEntryRemovedHandler> entryObserver( |
171 |
170 new HsMenuEntryRemovedHandler(mEntryId, |
172 mCorruptedMessage->clearActions(); |
171 mCorruptedMessage, SLOT(close()))); |
173 mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"), |
172 |
174 mCorruptedMessage); |
173 entryObserver.take()->setParent(mCorruptedMessage); |
175 mCorruptedMessage->addAction(mConfirmAction); |
174 |
176 |
|
177 HbAction *secondaryAction = new HbAction( |
|
178 hbTrId("txt_common_button_cancel"), mCorruptedMessage); |
|
179 mCorruptedMessage->addAction(secondaryAction); |
|
180 |
|
181 mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
175 mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
182 |
176 |
183 HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted"); |
177 HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted"); |
184 } |
178 } |
185 |
179 |
188 \retval void |
182 \retval void |
189 */ |
183 */ |
190 void HsAddToHomeScreenState::messageWidgetCorruptedFinished |
184 void HsAddToHomeScreenState::messageWidgetCorruptedFinished |
191 (HbAction* finishedAction) |
185 (HbAction* finishedAction) |
192 { |
186 { |
193 if (finishedAction == mConfirmAction) { |
187 if (static_cast<QAction*>(finishedAction) == mConfirmAction) { |
194 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
188 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
195 } |
189 } |
196 emit exit(); |
190 emit exit(); |
197 if (mMenuMode == AddHsMenuMode) { |
191 if (mMenuMode == AddHsMenuMode) { |
198 machine()->postEvent( |
192 machine()->postEvent( |
199 HsMenuEventFactory::createOpenHomeScreenEvent()); |
193 HsMenuEventFactory::createOpenHomeScreenEvent()); |
200 } |
194 } |
|
195 mConfirmAction = NULL; |
201 } |
196 } |
202 |
197 |
203 |
198 |
204 /*! |
199 /*! |
205 Slot launched after state has exited and in destructor. |
200 Slot launched after state has exited and in destructor. |
206 \retval void |
201 \retval void |
207 */ |
202 */ |
208 void HsAddToHomeScreenState::cleanUp() |
203 void HsAddToHomeScreenState::cleanUp() |
209 { |
204 { |
210 // Close popups if App key was pressed |
205 // Close popups if App key was pressed |
211 if (mCorruptedMessage) { |
206 if (mCorruptedMessage != NULL) { |
212 disconnect(mCorruptedMessage, SIGNAL(finished(HbAction*)), |
|
213 this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
|
214 mCorruptedMessage->close(); |
207 mCorruptedMessage->close(); |
215 mCorruptedMessage = NULL; |
208 mCorruptedMessage = NULL; |
216 } |
209 } |
217 |
210 |
218 disconnect(mNotifier, |
|
219 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
220 this, SLOT(memoryCardRemoved())); |
|
221 |
|
222 delete mNotifier; |
|
223 mNotifier = NULL; |
|
224 mToken = NULL; |
211 mToken = NULL; |
225 } |
212 } |
226 |
213 |
227 |
214 |
228 /*! |
215 /*! |
315 } else { |
302 } else { |
316 qWarning() << message; |
303 qWarning() << message; |
317 } |
304 } |
318 } |
305 } |
319 |
306 |
320 /*! |
307 |
321 Subscribe for memory card remove. |
308 |
322 \retval void |
309 |
323 */ |
|
324 void HsAddToHomeScreenState::subscribeForMemoryCardRemove() |
|
325 { |
|
326 CaNotifierFilter filter; |
|
327 QList<int> entryIds; |
|
328 entryIds.append(mEntryId); |
|
329 filter.setIds(entryIds); |
|
330 mNotifier = CaService::instance()->createNotifier(filter); |
|
331 mNotifier->setParent(this); |
|
332 connect(mNotifier, |
|
333 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
334 SLOT(memoryCardRemoved())); |
|
335 } |
|
336 |
|
337 /*! |
|
338 Memory card with instaled widget was removed. |
|
339 \retval void |
|
340 */ |
|
341 void HsAddToHomeScreenState::memoryCardRemoved() |
|
342 { |
|
343 if (mCorruptedMessage) { |
|
344 mCorruptedMessage->close(); |
|
345 mCorruptedMessage = NULL; |
|
346 } |
|
347 // exit not needed, it is called after dialog closed |
|
348 } |
|