19 #include <hblabel.h> |
19 #include <hblabel.h> |
20 //#include <hsiwidgetprovider.h> |
20 //#include <hsiwidgetprovider.h> |
21 #include <hbmessagebox.h> |
21 #include <hbmessagebox.h> |
22 #include <qstatemachine.h> |
22 #include <qstatemachine.h> |
23 #include <hbaction.h> |
23 #include <hbaction.h> |
|
24 #include <HbDocumentLoader> |
24 #include <hbdialog.h> |
25 #include <hbdialog.h> |
25 #include <hbwidget.h> |
26 #include <hbwidget.h> |
26 #include <hbscrollarea.h> |
27 #include <hbscrollarea.h> |
27 #include <hbscrollbar.h> |
28 #include <hbscrollbar.h> |
|
29 #include <QtAlgorithms> |
28 |
30 |
29 #include "hsmenueventfactory.h" |
31 #include "hsmenueventfactory.h" |
30 #include "hsmenuservice.h" |
32 #include "hsmenuservice.h" |
31 #include "hswidgetdata.h" |
|
32 #include "hswidgethost.h" |
33 #include "hswidgethost.h" |
33 #include "hspreviewhswidgetstate.h" |
34 #include "hspreviewhswidgetstate.h" |
34 #include "hsmenuevent.h" |
35 #include "hsmenuevent.h" |
35 #include "hsapp_defs.h" |
36 #include "hsapp_defs.h" |
36 #include "hsscene.h" |
37 #include "hsscene.h" |
41 #include "caservice.h" |
42 #include "caservice.h" |
42 |
43 |
43 #include "hsdomainmodel_global.h" |
44 #include "hsdomainmodel_global.h" |
44 #include <hscontentservice.h> |
45 #include <hscontentservice.h> |
45 |
46 |
|
47 |
|
48 const char HS_PREVIEW_HS_WIDGET_STATE[] = "HsPreviewHSWidgetState"; |
|
49 |
46 /*! |
50 /*! |
47 Constructor |
51 Constructor |
48 \param parent: parent state |
52 \param parent: parent state |
49 \retval void |
53 \retval void |
50 */ |
54 */ |
51 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) : |
55 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) : |
52 HsMenuBaseState("HsPreviewHSWidgetState", parent), |
56 HsMenuBaseState(HS_PREVIEW_HS_WIDGET_STATE, parent), |
53 mPopupDialog(0), |
57 mPopupDialog(0), |
54 mNotifier(0) |
58 mNotifier(0) |
55 { |
59 { |
56 requestServices(QList<QVariant> () << CONTENT_SERVICE_KEY); |
60 requestServices(QList<QVariant> () << CONTENT_SERVICE_KEY); |
57 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
61 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
92 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
93 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
93 QVariantMap data = menuEvent->data(); |
94 QVariantMap data = menuEvent->data(); |
94 |
95 |
95 const int entryId = data.value(itemIdKey()).toInt(); |
96 const int entryId = data.value(itemIdKey()).toInt(); |
96 |
97 |
97 QVariantMap widgetData; |
98 QVariantHash widgetData; |
98 widgetData.insert("library", data.value(widgetLibraryAttributeName()).toString()); |
99 widgetData.insert(LIBRARY, data.value(widgetLibraryAttributeName()).toString()); |
99 widgetData.insert("uri", data.value(widgetUriAttributeName()).toString()); |
100 widgetData.insert(URI, data.value(widgetUriAttributeName()).toString()); |
100 HsWidgetHost *widget = contentService()->createWidgetForPreview(widgetData); |
101 QScopedPointer<HsWidgetHost> widget( |
|
102 contentService()->createWidgetForPreview(widgetData)); |
101 |
103 |
102 if (widget) { |
104 if (widget) { |
103 widget->setMinimumSize(widget->preferredWidth(),widget->preferredHeight()); |
105 widget->setMinimumSize(widget->preferredWidth(),widget->preferredHeight()); |
104 HbScrollArea *scrollArea = new HbScrollArea(); |
106 |
105 scrollArea->setClampingStyle(HbScrollArea::StrictClamping); |
107 HbDocumentLoader loader; |
106 scrollArea->setScrollingStyle(HbScrollArea::Pan); |
108 |
107 scrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
109 bool loadStatusOk = false; |
108 scrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);// |
110 mObjectList = |
109 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
111 loader.load(HS_WIDGET_PREVIEW_DIALOG_LAYOUT, &loadStatusOk); |
110 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);// |
112 Q_ASSERT_X(loadStatusOk, |
111 scrollArea->verticalScrollBar()->setInteractive(true); |
113 HS_WIDGET_PREVIEW_DIALOG_LAYOUT, |
112 scrollArea->horizontalScrollBar()->setInteractive(true); |
114 "Error while loading docml file."); |
113 // this sets up the scroll area to scroll in both directions |
115 |
114 scrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal); |
116 mPopupDialog = |
115 scrollArea->setContentWidget(widget); //ownership transferred |
117 qobject_cast<HbDialog*>( |
116 scrollArea->setAlignment(Qt::AlignCenter); |
118 loader.findWidget(HS_WIDGET_PREVIEW_DIALOG_NAME)); |
117 |
119 |
118 // Instantiate a popup |
120 HbScrollArea *const scrollArea( |
119 mPopupDialog = new HbDialog(); |
121 qobject_cast<HbScrollArea*>( |
120 |
122 loader.findWidget(HS_WIDGET_PREVIEW_SCROLL_AREA_NAME))); |
121 // Set dismiss policy that determines what tap events will cause the dialog |
123 |
122 // to be dismissed |
124 if (mPopupDialog != NULL && scrollArea != NULL) { |
123 mPopupDialog->setDismissPolicy(HbDialog::NoDismiss); |
125 mPopupDialog->setContentWidget(scrollArea); //ownership transferred |
124 mPopupDialog->setTimeout(HbDialog::NoTimeout); |
126 mPopupDialog->setTimeout(HbPopup::NoTimeout); |
125 |
127 scrollArea->verticalScrollBar()->setInteractive(true); |
126 // Set content widget |
128 scrollArea->horizontalScrollBar()->setInteractive(true); |
127 mPopupDialog->setContentWidget(scrollArea); //ownership transferred |
129 scrollArea->setContentWidget(widget.data()); |
128 |
|
129 // Sets the primary action and secondary action |
|
130 mPopupDialog->setPrimaryAction(new HbAction(hbTrId("txt_applib_button_add_to_homescreen"),mPopupDialog)); |
|
131 mPopupDialog->setSecondaryAction(new HbAction(hbTrId("txt_common_button_close"),mPopupDialog)); |
|
132 |
|
133 subscribeForMemoryCardRemove(entryId); |
|
134 widget->initializeWidget(); |
|
135 widget->showWidget(); |
|
136 // Launch popup syncronously |
|
137 HbAction *result = mPopupDialog->exec(); |
|
138 |
|
139 disconnect(mNotifier, |
|
140 SIGNAL(entryChanged(const CaEntry &, ChangeType)), |
|
141 this, SLOT(memoryCardRemoved())); |
|
142 |
|
143 if (result == mPopupDialog->primaryAction()) { |
|
144 // take it back from scrollarea |
|
145 scrollArea->takeContentWidget(); |
130 scrollArea->takeContentWidget(); |
146 widget->hideWidget(); |
131 |
147 widget->uninitializeWidget(); |
132 subscribeForMemoryCardRemove(entryId); |
148 HsScene::instance()->activePage()->addNewWidget(widget); |
133 widget->initializeWidget(); |
149 } else { |
134 widget->showWidget(); |
150 widget->deleteFromDatabase(); |
135 // Launch popup syncronously |
|
136 const HbAction *const action(mPopupDialog->exec()); |
|
137 |
|
138 disconnect(mNotifier, |
|
139 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
140 this, SLOT(memoryCardRemoved())); |
|
141 |
|
142 if (action == mPopupDialog->primaryAction()) { |
|
143 widget->hideWidget(); |
|
144 HsScene::instance()->activePage()->addNewWidget( |
|
145 widget.take()); // ownership transferred |
|
146 } else { |
|
147 widget->uninitializeWidget(); |
|
148 widget->deleteFromDatabase(); |
|
149 } |
151 } |
150 } |
152 |
|
153 delete result; |
|
154 result = NULL; |
|
155 |
151 |
156 } else { |
152 } else { |
157 showMessageWidgetCorrupted(entryId); |
153 showMessageWidgetCorrupted(entryId); |
158 } |
154 } |
159 |
155 |