33 #include "hsmenueventfactory.h" |
33 #include "hsmenueventfactory.h" |
34 #include "hsmenuservice.h" |
34 #include "hsmenuservice.h" |
35 #include "hswidgethost.h" |
35 #include "hswidgethost.h" |
36 #include "hspreviewhswidgetstate.h" |
36 #include "hspreviewhswidgetstate.h" |
37 #include "hsmenuevent.h" |
37 #include "hsmenuevent.h" |
|
38 #include "hsmenudialogfactory.h" |
38 #include "hsapp_defs.h" |
39 #include "hsapp_defs.h" |
39 #include "hsscene.h" |
40 #include "hsscene.h" |
40 #include "hspage.h" |
41 #include "hspage.h" |
41 |
42 |
42 #include "canotifier.h" |
43 #include "canotifier.h" |
98 void HsPreviewHSWidgetState::onEntry(QEvent *event) |
100 void HsPreviewHSWidgetState::onEntry(QEvent *event) |
99 { |
101 { |
100 HSMENUTEST_FUNC_ENTRY("HsPreviewHSWidgetState::onEntry"); |
102 HSMENUTEST_FUNC_ENTRY("HsPreviewHSWidgetState::onEntry"); |
101 QState::onEntry(event); |
103 QState::onEntry(event); |
102 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
104 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
|
105 |
103 QVariantMap data = menuEvent->data(); |
106 QVariantMap data = menuEvent->data(); |
104 |
|
105 mEntryId = data.value(itemIdKey()).toInt(); |
107 mEntryId = data.value(itemIdKey()).toInt(); |
106 |
108 mToken = data.value(HOMESCREENDATA); |
107 QVariantHash widgetData; |
109 |
108 widgetData.insert(LIBRARY, data.value(widgetLibraryAttributeName()).toString()); |
110 |
109 widgetData.insert(URI, data.value(widgetUriAttributeName()).toString()); |
111 QSharedPointer<CaEntry> entry = |
110 |
112 CaService::instance()->getEntry(mEntryId); |
111 mWidget.reset( |
113 mUri = entry->attribute(widgetUriAttributeName()); |
112 HsContentService::instance()->createWidgetForPreview(widgetData)); |
114 mPreviewDialog = buildPreviewDialog(*entry); |
113 |
115 |
114 if (!mWidget.isNull()) { |
116 if (mPreviewDialog != NULL) { |
115 |
|
116 QSharedPointer<CaEntry> entry = |
|
117 CaService::instance()->getEntry(mEntryId); |
|
118 |
|
119 mPreviewDialog = buildPreviewDialog(*entry); |
|
120 |
|
121 if (mPreviewDialog != NULL) { |
|
122 subscribeForMemoryCardRemove(); |
|
123 // Launch popup asyncronously |
|
124 mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*))); |
|
125 } |
|
126 } else { |
|
127 subscribeForMemoryCardRemove(); |
117 subscribeForMemoryCardRemove(); |
128 showMessageWidgetCorrupted(); |
118 // Launch popup asyncronously |
|
119 mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*))); |
129 } |
120 } |
130 |
121 |
131 HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry"); |
122 HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry"); |
132 } |
123 } |
133 |
124 |
150 this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
141 this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
151 mCorruptedMessage->close(); |
142 mCorruptedMessage->close(); |
152 mCorruptedMessage = NULL; |
143 mCorruptedMessage = NULL; |
153 } |
144 } |
154 |
145 |
155 mWidget.reset(); |
146 mToken = NULL; |
156 |
147 |
157 disconnect(mNotifier, |
148 disconnect(mNotifier, |
158 SIGNAL(entryChanged(CaEntry,ChangeType)), |
149 SIGNAL(entryChanged(CaEntry,ChangeType)), |
159 this, SIGNAL(exit())); |
150 this, SIGNAL(exit())); |
160 |
151 |
166 Slot launched on dismissing the preview dialog |
157 Slot launched on dismissing the preview dialog |
167 \retval void |
158 \retval void |
168 */ |
159 */ |
169 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction) |
160 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction) |
170 { |
161 { |
171 if (finishedAction == mPreviewDialog->actions().value(0)) { |
162 if (static_cast<QAction*>(finishedAction) == mPreviewDialog->actions().value(0)) { |
172 |
163 |
173 HsScene::instance()->activePage()->addNewWidget( |
164 QVariantHash widgetData; |
174 mWidget.take()); // ownership transferred |
165 widgetData[URI] = mUri; |
175 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
166 widgetData[HOMESCREENDATA] = mToken; |
176 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
167 |
177 notificationDialog->setTitle(hbTrId( |
168 bool success = HsContentService::instance()->createWidget(widgetData); |
178 "txt_applib_dpophead_added_to_homescreen") ); |
169 |
179 notificationDialog->show(); |
170 if (success) { |
|
171 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
|
172 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
|
173 notificationDialog->setTitle(hbTrId("txt_applib_dpophead_added_to_homescreen")); |
|
174 notificationDialog->show(); |
|
175 emit exit(); |
|
176 } |
|
177 else { |
|
178 mPreviewDialog = NULL; |
|
179 showMessageWidgetCorrupted(); |
|
180 } |
180 } else { |
181 } else { |
181 mWidget->remove(); |
182 emit exit(); |
182 mWidget.take(); |
183 } |
183 mWidget.reset(); |
|
184 } |
|
185 emit exit(); |
|
186 } |
184 } |
187 |
185 |
188 /*! |
186 /*! |
189 Subscribe for memory card remove. |
187 Subscribe for memory card remove. |
190 \retval void |
188 \retval void |
208 */ |
206 */ |
209 void HsPreviewHSWidgetState::showMessageWidgetCorrupted() |
207 void HsPreviewHSWidgetState::showMessageWidgetCorrupted() |
210 { |
208 { |
211 HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted"); |
209 HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted"); |
212 |
210 |
213 mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
211 mCorruptedMessage = HsMenuDialogFactory().create( |
214 mCorruptedMessage->setAttribute(Qt::WA_DeleteOnClose); |
212 hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi")); |
215 |
|
216 QString message(hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi")); |
|
217 mCorruptedMessage->setText(message); |
|
218 |
|
219 mCorruptedMessage->clearActions(); |
|
220 HbAction *primaryAction = new HbAction(hbTrId("txt_common_button_ok"), mCorruptedMessage); |
|
221 mCorruptedMessage->addAction(primaryAction); |
|
222 |
|
223 HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mCorruptedMessage); |
|
224 mCorruptedMessage->addAction(secondaryAction); |
|
225 |
213 |
226 mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
214 mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
|
215 |
227 HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted"); |
216 HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted"); |
228 } |
217 } |
229 |
218 |
230 /*! |
219 /*! |
231 Slot launched on dismissing the corrupted widget error note |
220 Slot launched on dismissing the corrupted widget error note |
232 \retval void |
221 \retval void |
233 */ |
222 */ |
234 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction) |
223 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction) |
235 { |
224 { |
236 if (finishedAction == mCorruptedMessage->actions().value(0)) { |
225 if (static_cast<QAction*>(finishedAction) == mCorruptedMessage->actions().value(0)) { |
237 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
226 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
238 } |
227 } |
239 emit exit(); |
228 emit exit(); |
240 } |
229 } |
241 |
230 |
281 QLatin1String(HS_PREVIEW_ATTRIBUTE_NAME))); |
270 QLatin1String(HS_PREVIEW_ATTRIBUTE_NAME))); |
282 |
271 |
283 if (!previewImageName.isEmpty()) { |
272 if (!previewImageName.isEmpty()) { |
284 const HbIcon previewImage(previewImageName); |
273 const HbIcon previewImage(previewImageName); |
285 if (previewImage.size().isValid()) { |
274 if (previewImage.size().isValid()) { |
|
275 iconBox->setMinimumHeight(previewImage.height()); |
|
276 iconBox->setMaximumHeight(previewImage.height()); |
286 iconBox->setIcon(previewImage); |
277 iconBox->setIcon(previewImage); |
287 } |
278 } |
288 } |
279 } |
289 } |
280 } |
290 |
281 |