91 or shortcut. |
93 or shortcut. |
92 \param contentService: service for adding widgets |
94 \param contentService: service for adding widgets |
93 \param shortcutService: service for adding shortcuts |
95 \param shortcutService: service for adding shortcuts |
94 \retval void |
96 \retval void |
95 */ |
97 */ |
96 #ifdef COVERAGE_MEASUREMENT |
|
97 #pragma CTC SKIP |
|
98 #endif //COVERAGE_MEASUREMENT |
|
99 void HsPreviewHSWidgetState::onEntry(QEvent *event) |
98 void HsPreviewHSWidgetState::onEntry(QEvent *event) |
100 { |
99 { |
101 HSMENUTEST_FUNC_ENTRY("HsPreviewHSWidgetState::onEntry"); |
100 HSMENUTEST_FUNC_ENTRY("HsPreviewHSWidgetState::onEntry"); |
102 HsMenuBaseState::onEntry(event); |
101 QState::onEntry(event); |
103 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
102 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
104 QVariantMap data = menuEvent->data(); |
103 QVariantMap data = menuEvent->data(); |
105 |
104 |
106 mEntryId = data.value(itemIdKey()).toInt(); |
105 mEntryId = data.value(itemIdKey()).toInt(); |
107 |
106 |
108 QVariantHash widgetData; |
107 QVariantHash widgetData; |
109 widgetData.insert(LIBRARY, data.value(widgetLibraryAttributeName()).toString()); |
108 widgetData.insert(LIBRARY, data.value(widgetLibraryAttributeName()).toString()); |
110 widgetData.insert(URI, data.value(widgetUriAttributeName()).toString()); |
109 widgetData.insert(URI, data.value(widgetUriAttributeName()).toString()); |
111 |
110 |
112 QScopedPointer<HsWidgetHost> widget(contentService()->createWidgetForPreview(widgetData)); |
111 mWidget.reset( |
113 |
112 HsContentService::instance()->createWidgetForPreview(widgetData)); |
114 if (widget) { |
113 |
115 widget->setMinimumSize(widget->preferredWidth(),widget->preferredHeight()); |
114 if (!mWidget.isNull()) { |
116 |
115 |
117 HbDocumentLoader loader; |
116 QSharedPointer<CaEntry> entry = |
118 |
117 CaService::instance()->getEntry(mEntryId); |
119 bool loadStatusOk = false; |
118 |
120 mObjectList = |
119 mPreviewDialog = buildPreviewDialog(*entry); |
121 loader.load(HS_WIDGET_PREVIEW_DIALOG_LAYOUT, &loadStatusOk); |
120 |
122 Q_ASSERT_X(loadStatusOk, |
121 if (mPreviewDialog != NULL) { |
123 HS_WIDGET_PREVIEW_DIALOG_LAYOUT, |
|
124 "Error while loading docml file."); |
|
125 |
|
126 mPopupDialog = |
|
127 qobject_cast<HbDialog*>( |
|
128 loader.findWidget(HS_WIDGET_PREVIEW_DIALOG_NAME)); |
|
129 |
|
130 mScrollArea = |
|
131 qobject_cast<HbScrollArea*>( |
|
132 loader.findWidget(HS_WIDGET_PREVIEW_SCROLL_AREA_NAME)); |
|
133 |
|
134 // set parent to actions to delete them together with dialog |
|
135 mPopupDialog->actions()[0]->setParent(mPopupDialog); |
|
136 mPopupDialog->actions()[1]->setParent(mPopupDialog); |
|
137 |
|
138 if (mPopupDialog != NULL && mScrollArea != NULL) { |
|
139 mPopupDialog->setContentWidget(mScrollArea); // ownership transferred |
|
140 mPopupDialog->setTimeout(HbPopup::NoTimeout); |
|
141 mPopupDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
142 mScrollArea->verticalScrollBar()->setInteractive(true); |
|
143 mScrollArea->horizontalScrollBar()->setInteractive(true); |
|
144 mWidget = widget.take(); // ownership transfered |
|
145 mScrollArea->setContentWidget(mWidget); // ownership transferred |
|
146 |
|
147 subscribeForMemoryCardRemove(); |
122 subscribeForMemoryCardRemove(); |
148 mWidget->startWidget(); |
|
149 // Launch popup asyncronously |
123 // Launch popup asyncronously |
150 mPopupDialog->open(this, SLOT(previewDialogFinished(HbAction*))); |
124 mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*))); |
151 } |
125 } |
152 |
|
153 } else { |
126 } else { |
154 subscribeForMemoryCardRemove(); |
127 subscribeForMemoryCardRemove(); |
155 showMessageWidgetCorrupted(); |
128 showMessageWidgetCorrupted(); |
156 } |
129 } |
157 |
130 |
158 HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry"); |
131 HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry"); |
159 } |
132 } |
160 #ifdef COVERAGE_MEASUREMENT |
|
161 #pragma CTC ENDSKIP |
|
162 #endif //COVERAGE_MEASUREMENT |
|
163 |
133 |
164 /*! |
134 /*! |
165 Slot launched after state has exited and in destructor. |
135 Slot launched after state has exited and in destructor. |
166 \retval void |
136 \retval void |
167 */ |
137 */ |
168 void HsPreviewHSWidgetState::cleanUp() |
138 void HsPreviewHSWidgetState::cleanUp() |
169 { |
139 { |
170 // Close popups if App key was pressed or memory card removed |
140 // Close popups if App key was pressed or memory card removed |
171 if (mPopupDialog) { |
141 if (mPreviewDialog) { |
172 disconnect(mPopupDialog, SIGNAL(finished(HbAction*)), this, SLOT(previewDialogFinished(HbAction*))); |
142 disconnect(mPreviewDialog, SIGNAL(finished(HbAction*)), |
173 mPopupDialog->close(); |
143 this, SLOT(previewDialogFinished(HbAction*))); |
174 mPopupDialog = NULL; |
144 mPreviewDialog->close(); |
|
145 mPreviewDialog = NULL; |
175 } |
146 } |
176 |
147 |
177 if (mCorruptedMessage) { |
148 if (mCorruptedMessage) { |
178 disconnect(mCorruptedMessage, SIGNAL(finished(HbAction*)), this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
149 disconnect(mCorruptedMessage, SIGNAL(finished(HbAction*)), |
|
150 this, SLOT(messageWidgetCorruptedFinished(HbAction*))); |
179 mCorruptedMessage->close(); |
151 mCorruptedMessage->close(); |
180 mCorruptedMessage = NULL; |
152 mCorruptedMessage = NULL; |
181 } |
153 } |
182 |
154 |
183 mScrollArea = NULL; |
155 mWidget.reset(); |
184 mWidget = NULL; |
|
185 |
156 |
186 disconnect(mNotifier, |
157 disconnect(mNotifier, |
187 SIGNAL(entryChanged(CaEntry,ChangeType)), |
158 SIGNAL(entryChanged(CaEntry,ChangeType)), |
188 this, SIGNAL(exit())); |
159 this, SIGNAL(exit())); |
189 |
160 |
195 Slot launched on dismissing the preview dialog |
166 Slot launched on dismissing the preview dialog |
196 \retval void |
167 \retval void |
197 */ |
168 */ |
198 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction) |
169 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction) |
199 { |
170 { |
200 if (finishedAction == mPopupDialog->actions().value(0)) { |
171 if (finishedAction == mPreviewDialog->actions().value(0)) { |
201 mWidget->hideWidget(); |
172 |
202 mScrollArea->takeContentWidget(); |
|
203 HsScene::instance()->activePage()->addNewWidget( |
173 HsScene::instance()->activePage()->addNewWidget( |
204 mWidget); // ownership transferred |
174 mWidget.take()); // ownership transferred |
205 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
175 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
206 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
176 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
207 notificationDialog->setTitle(hbTrId( |
177 notificationDialog->setTitle(hbTrId( |
208 "txt_applib_dpophead_added_to_homescreen") ); |
178 "txt_applib_dpophead_added_to_homescreen") ); |
209 notificationDialog->show(); |
179 notificationDialog->show(); |
210 } else { |
180 } else { |
211 mScrollArea->takeContentWidget(); |
|
212 mWidget->remove(); |
181 mWidget->remove(); |
213 mWidget = NULL; |
182 mWidget.take(); |
|
183 mWidget.reset(); |
214 } |
184 } |
215 emit exit(); |
185 emit exit(); |
216 } |
186 } |
217 |
187 |
218 /*! |
188 /*! |
272 if (finishedAction == mCorruptedMessage->actions().value(0)) { |
236 if (finishedAction == mCorruptedMessage->actions().value(0)) { |
273 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
237 HsMenuService::executeAction(mEntryId, removeActionIdentifier()); |
274 } |
238 } |
275 emit exit(); |
239 emit exit(); |
276 } |
240 } |
|
241 |
|
242 /*! |
|
243 \param entry The entry which is to be presented by the preview dialog. |
|
244 \return Preview popup for a given entry on success, NULL otherwise. |
|
245 Ownership is passed to the caller. |
|
246 */ |
|
247 HbDialog* HsPreviewHSWidgetState::buildPreviewDialog(const CaEntry& entry) const |
|
248 { |
|
249 HbDocumentLoader loader; |
|
250 |
|
251 bool loadStatusOk = false; |
|
252 loader.load(HS_WIDGET_PREVIEW_DIALOG_LAYOUT, &loadStatusOk); |
|
253 |
|
254 HbDialog *const previewDialog = |
|
255 qobject_cast<HbDialog*>( |
|
256 loader.findWidget(HS_WIDGET_PREVIEW_DIALOG_NAME)); |
|
257 HbLabel *const headingLabel = |
|
258 qobject_cast<HbLabel*>( |
|
259 loader.findWidget(HS_WIDGET_PREVIEW_LABEL_NAME)); |
|
260 HbLabel *const iconBox = |
|
261 qobject_cast<HbLabel*>( |
|
262 loader.findWidget(HS_WIDGET_PREVIEW_ICON_BOX_NAME)); |
|
263 |
|
264 loadStatusOk = loadStatusOk && (previewDialog != NULL) |
|
265 && (headingLabel != NULL) && (iconBox != NULL); |
|
266 |
|
267 Q_ASSERT_X(loadStatusOk, |
|
268 HS_WIDGET_PREVIEW_DIALOG_LAYOUT, |
|
269 "Cannot initialize widgets based on docml file."); |
|
270 |
|
271 if (loadStatusOk) { |
|
272 previewDialog->actions()[0]->setParent(previewDialog); |
|
273 previewDialog->actions()[1]->setParent(previewDialog); |
|
274 |
|
275 previewDialog->setTimeout(HbPopup::NoTimeout); |
|
276 previewDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
277 |
|
278 headingLabel->setPlainText(entry.text()); |
|
279 |
|
280 const QString previewImageName(entry.attribute( |
|
281 QLatin1String(HS_PREVIEW_ATTRIBUTE_NAME))); |
|
282 |
|
283 if (!previewImageName.isEmpty()) { |
|
284 const HbIcon previewImage(previewImageName); |
|
285 if (previewImage.size().isValid()) { |
|
286 iconBox->setIcon(previewImage); |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 return previewDialog; |
|
292 } |
|
293 |