19 #include "hsdatabase.h" |
19 #include "hsdatabase.h" |
20 #include "hsscene.h" |
20 #include "hsscene.h" |
21 #include "hspage.h" |
21 #include "hspage.h" |
22 #include "hsdomainmodeldatastructures.h" |
22 #include "hsdomainmodeldatastructures.h" |
23 #include "hswidgethost.h" |
23 #include "hswidgethost.h" |
|
24 #include "hsapp_defs.h" |
24 |
25 |
25 |
26 |
26 /*! |
27 /*! |
27 \class HsContentService |
28 \class HsContentService |
28 \ingroup group_hsdomainmodel |
29 \ingroup group_hsdomainmodel |
29 \brief |
30 \brief Service for creating widget to Home Screen and make query for widget instances. |
|
31 |
30 */ |
32 */ |
31 |
33 |
32 /*! |
34 /*! |
33 |
35 Constructor. |
|
36 |
|
37 \a parent Owner. |
34 */ |
38 */ |
35 HsContentService::HsContentService(QObject *parent) |
39 HsContentService::HsContentService(QObject *parent) |
36 : QObject(parent),mWidgetStartFaulted(false) |
40 : QObject(parent), mWidgetStartFaulted(false) |
37 { |
41 { |
38 |
42 |
39 } |
43 } |
40 |
44 |
41 /*! |
45 /*! |
42 |
46 Destructor. |
43 */ |
47 */ |
44 HsContentService::~HsContentService() |
48 HsContentService::~HsContentService() |
45 { |
49 { |
46 } |
50 } |
47 |
51 |
48 /*! |
52 /*! |
49 |
53 Creates widget. \a params must include 'uri' for the desired widget type. |
|
54 'preferences' is optional. |
50 */ |
55 */ |
51 bool HsContentService::createWidget(const QVariantHash ¶ms) |
56 bool HsContentService::createWidget(const QVariantHash ¶ms) |
52 { |
57 { |
53 return addWidget(params.value("uri").toString(),params.value("preferences").toHash()); |
58 return addWidget(params.value(URI).toString(), |
|
59 params.value(PREFERENCES).toHash(), |
|
60 params.value(HOMESCREENDATA)); |
54 } |
61 } |
55 |
62 |
56 // This method will be removed. |
63 // This method will be removed. |
57 #ifdef COVERAGE_MEASUREMENT |
64 #ifdef COVERAGE_MEASUREMENT |
58 #pragma CTC SKIP |
65 #pragma CTC SKIP |
59 #endif //COVERAGE_MEASUREMENT |
66 #endif //COVERAGE_MEASUREMENT |
60 HsWidgetHost *HsContentService::createWidgetForPreview(const QVariantHash ¶ms) |
67 HsWidgetHost *HsContentService::createWidgetForPreview(const QVariantHash ¶ms) |
61 { |
68 { |
62 HsWidgetData widgetData; |
69 HsWidgetData widgetData; |
63 widgetData.uri = params.value("uri").toString(); |
70 widgetData.uri = params.value(URI).toString(); |
64 |
71 |
65 return HsWidgetHost::createInstance( |
72 return HsWidgetHost::createInstance( |
66 widgetData, params.value("preferences").toHash()); |
73 widgetData, params.value(PREFERENCES).toHash()); |
67 } |
74 } |
68 #ifdef COVERAGE_MEASUREMENT |
75 #ifdef COVERAGE_MEASUREMENT |
69 #pragma CTC ENDSKIP |
76 #pragma CTC ENDSKIP |
70 #endif //COVERAGE_MEASUREMENT |
77 #endif //COVERAGE_MEASUREMENT |
71 |
78 |
72 /*! |
79 /*! |
73 |
80 |
74 */ |
81 */ |
75 bool HsContentService::addWidget(const QString &uri, const QVariantHash &preferences) |
82 bool HsContentService::addWidget(const QString &uri, const QVariantHash &preferences, |
|
83 const QVariant &homescreenData) |
76 { |
84 { |
77 HsWidgetData data; |
85 HsWidgetData data; |
78 data.uri = uri; |
86 data.uri = uri; |
79 |
87 |
80 HsWidgetHost *widget = HsWidgetHost::createInstance(data, preferences); |
88 HsWidgetHost *widget = HsWidgetHost::createInstance(data, preferences); |
81 if (!widget) { |
89 if (!widget) { |
82 return false; |
90 return false; |
83 } |
91 } |
84 |
92 |
85 HsPage *page = HsScene::instance()->activePage(); |
93 HsPage *page = HsScene::instance()->activePage(); |
86 if (!page->addNewWidget(widget)) { |
94 QPointF touchPoint = homescreenData.toPointF(); |
|
95 if (!page->addNewWidget(widget, touchPoint)) { |
87 widget->remove(); |
96 widget->remove(); |
88 return false; |
97 return false; |
89 } |
98 } |
90 connect(widget,SIGNAL(event_faulted()),SLOT(widgetStartFaulted())); |
99 connect(widget,SIGNAL(event_faulted()),SLOT(widgetStartFaulted())); |
91 mWidgetStartFaulted = false; |
100 mWidgetStartFaulted = false; |
93 if (mWidgetStartFaulted) { |
102 if (mWidgetStartFaulted) { |
94 // page will destroy widget instance |
103 // page will destroy widget instance |
95 return false; |
104 return false; |
96 } |
105 } |
97 widget->disconnect(this); |
106 widget->disconnect(this); |
98 |
107 emit widgetAdded(uri, preferences); |
99 return true; |
108 return true; |
100 } |
109 } |
101 |
110 |
102 /*! |
111 /*! |
|
112 Returns false if database query fails. If returns true then |
|
113 number of widget instances of the given \a uri and \a preferences is stored to \a count. |
|
114 If \a preferences is empty then returns number of widget instances with given uri. |
|
115 */ |
|
116 bool HsContentService::widgets(const QString &uri, const QVariantHash &preferences, int &count) |
|
117 { |
|
118 return HsDatabase::instance()->widgets(uri, preferences, count); |
|
119 } |
103 |
120 |
|
121 /*! |
104 */ |
122 */ |
105 HsContentService *HsContentService::instance() |
123 HsContentService *HsContentService::instance() |
106 { |
124 { |
107 if (!mInstance) { |
125 if (!mInstance) { |
108 mInstance = new HsContentService(); |
126 mInstance = new HsContentService(); |
109 } |
127 } |
110 return mInstance; |
128 return mInstance; |
|
129 } |
|
130 |
|
131 /*! |
|
132 |
|
133 */ |
|
134 void HsContentService::emitWidgetRemoved(const QString &uri, const QVariantHash &preferences) |
|
135 { |
|
136 emit widgetRemoved(uri, preferences); |
111 } |
137 } |
112 |
138 |
113 /*! |
139 /*! |
114 |
140 |
115 */ |
141 */ |