~michael-sheldon/content-hub/peer_picker_ui_weaved

« back to all changes in this revision

Viewing changes to examples/import-qml/import.qml

  • Committer: Michael Sheldon
  • Date: 2014-03-20 21:17:18 UTC
  • mfrom: (71.4.71 peer_picker_ui)
  • Revision ID: michael.sheldon@canonical.com-20140320211718-4n2yjluhq7xh5b7q
Weave merge peer_picker_ui

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import QtQuick 2.0
2
2
import Ubuntu.Components 0.1
3
3
import Ubuntu.Components.ListItems 0.1 as ListItem
4
 
 
5
4
import Ubuntu.Content 0.1
6
5
 
7
6
MainView {
12
11
 
13
12
    property list<ContentItem> importItems
14
13
    property var activeTransfer
15
 
    property list<ContentPeer> peers
16
 
 
17
 
 
18
 
    function _importFromPeer(peer) {
19
 
        /* if peer is null, choose default */
20
 
        if (peer === null)
21
 
            peer = ContentHub.defaultSourceForType(ContentType.Pictures);
22
 
        var transfer = ContentHub.importContent(ContentType.Pictures, peer);
23
 
        var store = ContentHub.defaultStoreForType(ContentType.Pictures);
24
 
        console.log("Store is: " + store.uri);
25
 
        if (transfer !== null) {
26
 
            transfer.selectionType = ContentTransfer.Multiple;
27
 
            transfer.setStore(store);
28
 
            activeTransfer = transfer;
29
 
            activeTransfer.start();
30
 
        }
31
 
    }
32
 
 
33
 
    Component.onCompleted: {
34
 
        peers = ContentHub.knownSourcesForType(ContentType.Pictures);
 
14
 
 
15
 
 
16
    ContentPeer {
 
17
        id: picSource
 
18
        // well know content type
 
19
        contentType: ContentType.Pictures
 
20
        // Type of handler: Source, Destination, or Share
 
21
        handler: ContentHandler.Source
 
22
        // Optional appId, if this isn't specified the hub will use the default
 
23
        //appId: ""
 
24
    }
 
25
        
 
26
    // Optional store to use for persistent storage of content
 
27
    ContentStore {
 
28
        id: appStore
 
29
        scope: ContentScope.App
 
30
    }
 
31
 
 
32
    // Provides a list<ContentPeer> suitable for use as a model
 
33
    ContentPeerModel {
 
34
        id: picSources
 
35
        // Type of handler: Source, Destination, or Share
 
36
        handler: ContentHandler.Source
 
37
        // well know content type
 
38
        contentType: ContentType.Pictures
35
39
    }
36
40
 
37
41
    ListView {
42
46
            top: importButtons.bottom
43
47
        }
44
48
        height: childrenRect.height
45
 
        model: peers
 
49
        model: picSources.peers
46
50
 
47
51
        delegate: ListItem.Standard {
48
52
            text: modelData.name
49
53
            control: Button {
50
54
                text: "Import"
51
55
                onClicked: {
52
 
                    _importFromPeer(modelData);
 
56
                    // Request the transfer, it needs to be created and dispatched from the hub
 
57
                    activeTransfer = modelData.request();
53
58
                }
54
59
            }
55
60
        }
64
69
            }
65
70
            text: "Import from default"
66
71
            onClicked: {
67
 
                _importFromPeer(null);
 
72
                // Request the transfer, it needs to be created and dispatched from the hub
 
73
                // Specify a location to use for permanent storage
 
74
                activeTransfer = picSource.request(appStore);
68
75
            }
69
76
        }
70
77
 
79
86
        }
80
87
    }
81
88
 
82
 
 
83
89
    ListView {
84
90
        id: resultList
85
91
        anchors {
108
114
            }
109
115
    }
110
116
 
111
 
    ContentImportHint {
 
117
    // Provides overlay showing another app is being used to complete the request
 
118
    // formerly named ContentImportHint
 
119
    ContentTransferHint {
112
120
        anchors.fill: parent
113
 
        activeTransfer: root.activeTransfer
 
121
        activeTransfer: activeTransfer
114
122
    }
115
123
 
116
124
    Connections {
117
 
        target: root.activeTransfer
 
125
        target: activeTransfer
118
126
        onStateChanged: {
119
127
            console.log("StateChanged: " + activeTransfer.state);
120
128
            if (activeTransfer.state === ContentTransfer.Charged)