Merge lp:~ken-vandine/content-hub/lp1236932 into lp:~content-hub-team/content-hub/trunk

Proposed by Ken VanDine on 2013-10-22
Status: Merged
Approved by: Ken VanDine on 2013-10-23
Approved revision: 70
Merged at revision: 62
Proposed branch: lp:~ken-vandine/content-hub/lp1236932
Merge into: lp:~content-hub-team/content-hub/trunk
Diff against target: 264 lines (+96/-54)
5 files modified
examples/import-qml/import.qml (+78/-34)
import/Ubuntu/Content/contenthub.cpp (+3/-4)
import/Ubuntu/Content/contenthub.h (+1/-1)
import/Ubuntu/Content/contentpeer.cpp (+10/-11)
import/Ubuntu/Content/contentpeer.h (+4/-4)
To merge this branch: bzr merge lp:~ken-vandine/content-hub/lp1236932
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2013-10-23
Günter Schwann (community) 2013-10-22 Approve on 2013-10-23
Review via email: mp+192207@code.launchpad.net

Commit message

return a QVariantList from knownSourcesForType so the QML bindings can
expose a list of peers, fixes (LP: #1236932)

Description of the change

* return a QVariantList from knownSourcesForType so the QML bindings can
  expose a list of peers, fixes (LP: #1236932)

* Added id() and return name for name() instead of id

* Removed type property from ContentPeer, it isn't used and the cpp API doesn't provide it.

To post a comment you must log in.
66. By Ken VanDine on 2013-10-22

removed FIXME

67. By Ken VanDine on 2013-10-22

emit idChanged on setPeer

68. By Ken VanDine on 2013-10-22

removed the "type" property from ContentPeer, it isn't used and
com::ubuntu::content::Peer doesn't provide a type either.

Günter Schwann (schwann) wrote :

218 + Q_PROPERTY(QString id READ id NOTIFY idChanged)

Having a property called "id" is not the best idea, as it collides with QML "id"

review: Needs Fixing
69. By Ken VanDine on 2013-10-23

Renamed id to appId to avoid colliding with QML's id property

70. By Ken VanDine on 2013-10-23

revert changelog entry

Günter Schwann (schwann) wrote :

looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/import-qml/import.qml'
2--- examples/import-qml/import.qml 2013-10-01 16:55:39 +0000
3+++ examples/import-qml/import.qml 2013-10-23 12:08:41 +0000
4@@ -1,6 +1,6 @@
5 import QtQuick 2.0
6 import Ubuntu.Components 0.1
7-import Ubuntu.Components.ListItems 0.1
8+import Ubuntu.Components.ListItems 0.1 as ListItem
9
10 import Ubuntu.Content 0.1
11
12@@ -12,41 +12,85 @@
13
14 property list<ContentItem> importItems
15 property var activeTransfer
16-
17- Button {
18- id: importButton
19- text: "Import from default"
20- onClicked: {
21- var 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-
34- Button {
35- anchors.left: importButton.right
36- text: "Finalize import"
37- enabled: activeTransfer.state === ContentTransfer.Collected
38- onClicked: activeTransfer.finalize()
39- }
40-
41- ListView {
42- anchors {
43- left: parent.left
44- right: parent.right
45- bottom: parent.bottom
46- top: importButton.bottom
47- }
48+ property var peers
49+
50+
51+ function _importFromPeer(peer) {
52+ /* if peer is null, choose default */
53+ if (peer === null)
54+ peer = ContentHub.defaultSourceForType(ContentType.Pictures);
55+ var transfer = ContentHub.importContent(ContentType.Pictures, peer);
56+ var store = ContentHub.defaultStoreForType(ContentType.Pictures);
57+ console.log("Store is: " + store.uri);
58+ if (transfer !== null) {
59+ transfer.selectionType = ContentTransfer.Multiple;
60+ transfer.setStore(store);
61+ activeTransfer = transfer;
62+ activeTransfer.start();
63+ }
64+ }
65+
66+ Component.onCompleted: {
67+ peers = ContentHub.knownSourcesForType(ContentType.Pictures);
68+ }
69+
70+ ListView {
71+ id: peerList
72+ anchors {
73+ left: parent.left
74+ right: parent.right
75+ top: importButtons.bottom
76+ }
77+ height: childrenRect.height
78+ model: peers
79+
80+ delegate: ListItem.Standard {
81+ text: modelData.name
82+ control: Button {
83+ text: "Import"
84+ onClicked: {
85+ _importFromPeer(modelData);
86+ }
87+ }
88+ }
89+ }
90+
91+ ListItem.Empty {
92+ id: importButtons
93+ Button {
94+ anchors {
95+ left: parent.left
96+ margins: units.gu(2)
97+ }
98+ text: "Import from default"
99+ onClicked: {
100+ _importFromPeer(null);
101+ }
102+ }
103+
104+ Button {
105+ anchors {
106+ right: parent.right
107+ margins: units.gu(2)
108+ }
109+ text: "Finalize import"
110+ enabled: activeTransfer.state === ContentTransfer.Collected
111+ onClicked: activeTransfer.finalize()
112+ }
113+ }
114+
115+
116+ ListView {
117+ id: resultList
118+ anchors {
119+ left: parent.left
120+ right: parent.right
121+ top: peerList.bottom
122+ }
123+ height: childrenRect.height
124
125 model: importItems
126- delegate: Empty {
127+ delegate: ListItem.Empty {
128 id: result
129 height: 128
130 UbuntuShape {
131
132=== modified file 'import/Ubuntu/Content/contenthub.cpp'
133--- import/Ubuntu/Content/contenthub.cpp 2013-10-01 16:55:39 +0000
134+++ import/Ubuntu/Content/contenthub.cpp 2013-10-23 12:08:41 +0000
135@@ -148,20 +148,19 @@
136 *
137 * Returns all possible peers for the given content \a type
138 */
139-QList<ContentPeer *> ContentHub::knownSourcesForType(int type)
140+QVariantList ContentHub::knownSourcesForType(int type)
141 {
142 qDebug() << Q_FUNC_INFO;
143
144 const cuc::Type &hubType = ContentType::contentType2HubType(type);
145 QVector<cuc::Peer> hubPeers = m_hub->known_peers_for_type(hubType);
146
147- QList<ContentPeer *> qmlPeers;
148+ QVariantList qmlPeers;
149 foreach (const cuc::Peer &hubPeer, hubPeers) {
150 ContentPeer *qmlPeer = new ContentPeer(this);
151 qmlPeer->setPeer(hubPeer);
152- qmlPeers.append(qmlPeer);
153+ qmlPeers.append(QVariant::fromValue(qmlPeer));
154 }
155-
156 return qmlPeers;
157 }
158
159
160=== modified file 'import/Ubuntu/Content/contenthub.h'
161--- import/Ubuntu/Content/contenthub.h 2013-10-01 16:55:39 +0000
162+++ import/Ubuntu/Content/contenthub.h 2013-10-23 12:08:41 +0000
163@@ -48,7 +48,7 @@
164 ContentHub(QObject *parent = nullptr);
165
166 Q_INVOKABLE ContentPeer *defaultSourceForType(int type);
167- Q_INVOKABLE QList<ContentPeer *> knownSourcesForType(int type);
168+ Q_INVOKABLE QVariantList knownSourcesForType(int type);
169
170 Q_INVOKABLE ContentStore *defaultStoreForType(int type);
171
172
173=== modified file 'import/Ubuntu/Content/contentpeer.cpp'
174--- import/Ubuntu/Content/contentpeer.cpp 2013-08-23 10:05:50 +0000
175+++ import/Ubuntu/Content/contentpeer.cpp 2013-10-23 12:08:41 +0000
176@@ -28,7 +28,7 @@
177 *
178 * FIXME add documentation
179 *
180- * See documentation for \ContentHub
181+ * See documentation for ContentHub
182 */
183
184 namespace cuc = com::ubuntu::content;
185@@ -43,29 +43,28 @@
186 /*!
187 * \qmlproperty string ContentPeer::name
188 *
189- * FIXME add documentation
190+ * Returns user friendly name of the peer
191 */
192-const QString &ContentPeer::name() const
193+QString ContentPeer::name()
194 {
195 qDebug() << Q_FUNC_INFO;
196- return m_peer.id();
197+ return m_peer.name();
198 }
199
200 /*!
201- * \qmlproperty string ContentPeer::type
202+ * \qmlproperty string ContentPeer::appId
203 *
204- * FIXME add documentation
205+ * Returns the Application id
206 */
207-const QString &ContentPeer::type() const
208+const QString &ContentPeer::appId() const
209 {
210 qDebug() << Q_FUNC_INFO;
211- // FIXME return the type
212 return m_peer.id();
213 }
214
215 /*!
216 * \brief ContentPeer::peer
217- * \return
218+ * \internal
219 */
220 const com::ubuntu::content::Peer &ContentPeer::peer() const
221 {
222@@ -74,11 +73,11 @@
223
224 /*!
225 * \brief ContentPeer::setPeer
226- * \param peer
227+ * \internal
228 */
229 void ContentPeer::setPeer(const cuc::Peer &peer)
230 {
231 m_peer = peer;
232 Q_EMIT nameChanged();
233- Q_EMIT typeChanged();
234+ Q_EMIT appIdChanged();
235 }
236
237=== modified file 'import/Ubuntu/Content/contentpeer.h'
238--- import/Ubuntu/Content/contentpeer.h 2013-08-23 07:48:15 +0000
239+++ import/Ubuntu/Content/contentpeer.h 2013-10-23 12:08:41 +0000
240@@ -26,20 +26,20 @@
241 {
242 Q_OBJECT
243 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
244- Q_PROPERTY(QString type READ type NOTIFY typeChanged)
245+ Q_PROPERTY(QString appId READ appId NOTIFY appIdChanged)
246
247 public:
248 ContentPeer(QObject *parent = nullptr);
249
250- const QString &name() const;
251- const QString &type() const;
252+ QString name();
253+ const QString &appId() const;
254
255 const com::ubuntu::content::Peer &peer() const;
256 void setPeer(const com::ubuntu::content::Peer &peer);
257
258 Q_SIGNALS:
259 void nameChanged();
260- void typeChanged();
261+ void appIdChanged();
262
263 private:
264 com::ubuntu::content::Peer m_peer;

Subscribers

People subscribed via source and target branches