Merge lp:~abreu-alexandre/unity-webapps-qml/fail-safe-content-hub-bindings into lp:unity-webapps-qml

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 139
Merged at revision: 140
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/fail-safe-content-hub-bindings
Merge into: lp:unity-webapps-qml
Diff against target: 49 lines (+19/-4)
2 files modified
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+2/-1)
src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js (+17/-3)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/fail-safe-content-hub-bindings
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Mardegan (community) Approve
Review via email: mp+242834@code.launchpad.net

Commit message

Make sure that the content hub bindings are fail safe since the content hub package is a suggests (which is fine since it is not there by default on desktop).

Description of the change

Make sure that the content hub bindings are fail safe since the content hub package is a suggests (which is fine since it is not there by default on desktop).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alberto Mardegan (mardy) wrote :

I don't think that you need to import the QtQuick 2.0 module.
Also, I'm not sure if the exception will always be thrown, or if it's possible for Qt.createQmlObject() to return null without raising the exception; if so, you should check for its return value != null as well.

But I'm not sure of either points, so if you have already tested this and this is the correct solution, +1 from me.

review: Approve
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> I don't think that you need to import the QtQuick 2.0 module.

I didn't initially, but it seems to be required to known about QtObject,

> Also, I'm not sure if the exception will always be thrown, or if it's possible
> for Qt.createQmlObject() to return null without raising the exception; if so,
> you should check for its return value != null as well.

+1

> But I'm not sure of either points, so if you have already tested this and this
> is the correct solution, +1 from me.

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> I don't think that you need to import the QtQuick 2.0 module.

I didn't initially, but it seems to be required to known about QtObject,

> Also, I'm not sure if the exception will always be thrown, or if it's possible
> for Qt.createQmlObject() to return null without raising the exception; if so,
> you should check for its return value != null as well.

+1

> But I'm not sure of either points, so if you have already tested this and this
> is the correct solution, +1 from me.

139. By Alexandre Abreu

updates

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
140. By Alexandre Abreu

revert change

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
2--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-11-21 21:12:26 +0000
3+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-12-01 15:44:28 +0000
4@@ -784,7 +784,8 @@
5 return AlarmApiBackend.createAlarmApi(UnityBackends.backendDelegate)
6 }),
7
8- ContentHub: ContentHubApiBackend.createContentHubApi(UnityBackends.backendDelegate),
9+ ContentHub: ContentHubApiBackend.createContentHubApi(
10+ UnityBackends.backendDelegate, webapps),
11
12 RuntimeApi: __injectResourceIfExtraApisAreEnabled(function() {
13 return RuntimeApiBackend.createRuntimeApi(UnityBackends.backendDelegate)
14
15=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js'
16--- src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-06-17 13:53:49 +0000
17+++ src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-12-01 15:44:28 +0000
18@@ -16,15 +16,29 @@
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22-.import Ubuntu.Content 0.1 as ContentHubBridge
23-
24 /**
25 *
26 * ContentHub API backend binding
27 *
28 */
29
30-function createContentHubApi(backendDelegate, accessPolicy) {
31+function createContentHubApi(backendDelegate, parent) {
32+
33+ var bridge = null
34+ try {
35+ bridge = Qt.createQmlObject(
36+ 'import QtQuick 2.0; import Ubuntu.Content 0.1 as ContentHubBridge; \
37+ QtObject { property var hub: ContentHubBridge }', parent)
38+ }
39+ catch(e) { }
40+
41+ if (!bridge) {
42+ console.log('Could not create ContentHub backend (does not appear to be installed)')
43+ return {};
44+ }
45+
46+ var ContentHubBridge = bridge.hub;
47+
48 var PLUGIN_URI = 'Ubuntu.Content';
49 var VERSION = 0.1;
50

Subscribers

People subscribed via source and target branches

to all changes: