Merge lp:~mzanetti/unity-api/launcher-api-pinning into lp:unity-api

Proposed by Michael Zanetti on 2013-07-04
Status: Merged
Approved by: Michael Zanetti on 2013-07-08
Approved revision: 97
Merged at revision: 76
Proposed branch: lp:~mzanetti/unity-api/launcher-api-pinning
Merge into: lp:unity-api
Diff against target: 831 lines (+396/-101)
14 files modified
debian/changelog (+6/-0)
include/unity/shell/launcher/CMakeLists.txt (+1/-1)
include/unity/shell/launcher/LauncherItemInterface.h (+26/-19)
include/unity/shell/launcher/LauncherModelInterface.h (+56/-13)
include/unity/shell/launcher/QuickListModelInterface.h (+84/-0)
test/qmltest/mocks/plugins/Unity/Launcher/CMakeLists.txt (+2/-0)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.cpp (+24/-11)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.h (+9/-5)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.cpp (+42/-24)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.h (+11/-2)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.cpp (+46/-0)
test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.h (+38/-0)
test/qmltest/mocks/plugins/Unity/Launcher/TestLauncherPlugin.cpp (+3/-0)
test/qmltest/unity/shell/launcher/tst_Launcher.qml (+48/-26)
To merge this branch: bzr merge lp:~mzanetti/unity-api/launcher-api-pinning
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-07-08
Michał Sawicz 2013-07-04 Approve on 2013-07-08
Review via email: mp+173064@code.launchpad.net

Commit message

more work on launcher API

- Remove WRITE properties from LauncherItemInterface's API. QML should use operations on LauncherModelInterface for manipulating the model.
- Introduced QuickListModelInterface as a property of LauncherItems. Will hold quick list menus.
- Introduces pin(), remove() and triggerQuickListAction() methods for LauncherModel.
- Renamed LauncherItem's "favorite" property to "pinned" in order to align naming with LauncherModel's API.
- Updated mocks and tests to reflect the above changes.

To post a comment you must log in.
Michał Sawicz (saviq) wrote :

116 Q_INVOKABLE virtual void move(int oldIndex, int newIndex) = 0;

131 + Q_INVOKABLE virtual void pin(int index) = 0;

142 + Q_INVOKABLE virtual void remove(int index) = 0;

151 + Q_INVOKABLE virtual void triggerQuickListAction(int itemIndex, int quickListIndex) = 0;

I wonder if we should instead identify the items by their ids and not indexes? Maybe not for the move(), but for pin() / unpin() and trigger() I would.

pin() should also take the index at which to pin the item (when you drag an item onto the launcher from the dash). Not sure if remove should not be "unpin", exactly because it might not actually result in the removal of the item - it's the backend model that decides what happens.

=====

206 + * - RoleLabel: The text entry in the QuickList menu (QString).
207 + * - RoleIcon: The icon to be shown for this entry (QString).
208 + * - RoleCheckable: Wether the item is checkable or not (bool).
209 + * - RoleGroup: A group this item is in. Items in the same group are exclusive (int). -1 for no group.

220 + enum Roles {
221 + RoleLabel,
222 + RoleIcon
223 + };

Hmm does it?

Shouldn't that be "label", "icon", "checkable", "group", too, instead?

Wether → Whether.

"The icon" - should that be full URL or only a themed icon name?

"checkable" - can you reword?

=====

253 -add_subdirectory(copyright)
254 -add_subdirectory(whitespace)
255 +#add_subdirectory(copyright)
256 +#add_subdirectory(whitespace)

Oh no you don't! ;P

=====

Please put Authors: consistently below the copyright.

=====

Maybe put the SignalSpy at the top?

review: Needs Fixing
Michael Zanetti (mzanetti) wrote :

> 116 Q_INVOKABLE virtual void move(int oldIndex, int newIndex) = 0;
>
> 131 + Q_INVOKABLE virtual void pin(int index) = 0;
>
> 142 + Q_INVOKABLE virtual void remove(int index) = 0;
>
> 151 + Q_INVOKABLE virtual void triggerQuickListAction(int itemIndex, int
> quickListIndex) = 0;
>
> I wonder if we should instead identify the items by their ids and not indexes?
> Maybe not for the move(), but for pin() / unpin() and trigger() I would.

So far this API does not know anything about id's. Identifying items by ID would require to introduce some ID in QML which I intended not to do so far.

> pin() should also take the index at which to pin the item (when you drag an
> item onto the launcher from the dash).

Would be a possibility too I guess. I did like the idea of not having to deal with app ids in QML but I'm not strongly against it either.

Still think I should change it? If yes, I'll do.

> Not sure if remove should not be
> "unpin", exactly because it might not actually result in the removal of the
> item - it's the backend model that decides what happens.

which would then require another remove() method because recent apps are not pinned. I for one would prefer keeping this single method that works for all items instead of 2 different ones that only work for some items.

> =====
>
> 206 + * - RoleLabel: The text entry in the QuickList menu (QString).
> 207 + * - RoleIcon: The icon to be shown for this entry (QString).
> 208 + * - RoleCheckable: Wether the item is checkable or not (bool).
> 209 + * - RoleGroup: A group this item is in. Items in the same group are
> exclusive (int). -1 for no group.
>
> 220 + enum Roles {
> 221 + RoleLabel,
> 222 + RoleIcon
> 223 + };
>
> Hmm does it?
>
> Shouldn't that be "label", "icon", "checkable", "group", too, instead?

Right... my draft had that stuff already in, but Antti asked me to leave it away because grouping and checking is not planned for the October deadline. I removed it from the comments too now.

> "The icon" - should that be full URL or only a themed icon name?

I don't know yet... depends a bit on what the backend will deliver. However, the API doesn't really care. In the end its a string that must be resolvable. I guess if the backend decides to mix them for some reason it should be fine for us too.

>
> "checkable" - can you reword?

I used checkable because that's what Qt uses for everything that is checkable. Anyways, its gone from the API for now.

> =====
>
> 253 -add_subdirectory(copyright)
> 254 -add_subdirectory(whitespace)
> 255 +#add_subdirectory(copyright)
> 256 +#add_subdirectory(whitespace)
>
> Oh no you don't! ;P

Ooops. Fixed. :D

Btw. those are failing in pbuilder because they parse the the build directory. I wonder actually how they build in Jenkins...

> =====
>
> Please put Authors: consistently below the copyright.

fixed.

>
> =====
>
> Maybe put the SignalSpy at the top?

Done.

Michał Sawicz (saviq) wrote :
Download full text (3.5 KiB)

W dniu 05.07.2013 17:23, Michael Zanetti pisze:
>> 116 Q_INVOKABLE virtual void move(int oldIndex, int newIndex) = 0;
>>
>> 131 + Q_INVOKABLE virtual void pin(int index) = 0;
>>
>> 142 + Q_INVOKABLE virtual void remove(int index) = 0;
>>
>> 151 + Q_INVOKABLE virtual void triggerQuickListAction(int itemIndex, int
>> quickListIndex) = 0;
>>
>> I wonder if we should instead identify the items by their ids and not indexes?
>> Maybe not for the move(), but for pin() / unpin() and trigger() I would.
>
> So far this API does not know anything about id's. Identifying items by ID would require to introduce some ID in QML which I intended not to do so far.
>
>> pin() should also take the index at which to pin the item (when you drag an
>> item onto the launcher from the dash).
>
> Would be a possibility too I guess. I did like the idea of not having to deal with app ids in QML but I'm not strongly against it either.
>
> Still think I should change it? If yes, I'll do.

I just think that that _is_ the identifier. The index is not, not
really. So yeah, I'd rather deal with app IDs I think.

>> Not sure if remove should not be
>> "unpin", exactly because it might not actually result in the removal of the
>> item - it's the backend model that decides what happens.
>
> which would then require another remove() method because recent apps are not pinned. I for one would prefer keeping this single method that works for all items instead of 2 different ones that only work for some items.

Do we even support removing recent apps? But ok, I'm good with that.
Just make it explicit in the comment (and maybe rename the method to
something suggesting that - requestRemove()) that this is just a request
that isn't necessarily executed straight away.

>> 206 + * - RoleLabel: The text entry in the QuickList menu (QString).
>> 207 + * - RoleIcon: The icon to be shown for this entry (QString).
>> 208 + * - RoleCheckable: Wether the item is checkable or not (bool).
>> 209 + * - RoleGroup: A group this item is in. Items in the same group are
>> exclusive (int). -1 for no group.
>>
>> 220 + enum Roles {
>> 221 + RoleLabel,
>> 222 + RoleIcon
>> 223 + };
>>
>> Hmm does it?
>>
>> Shouldn't that be "label", "icon", "checkable", "group", too, instead?
>
> Right... my draft had that stuff already in, but Antti asked me to leave it away because grouping and checking is not planned for the October deadline. I removed it from the comments too now.
>
>> "The icon" - should that be full URL or only a themed icon name?
>
> I don't know yet... depends a bit on what the backend will deliver. However, the API doesn't really care. In the end its a string that must be resolvable. I guess if the backend decides to mix them for some reason it should be fine for us too.
>
>>
>> "checkable" - can you reword?
>
> I used checkable because that's what Qt uses for everything that is checkable. Anyways, its gone from the API for now.

OK.

>> 253 -add_subdirectory(copyright)
>> 254 -add_subdirectory(whitespace)
>> 255 +#add_subdirectory(copyright)
>> 256 +#add_subdirectory(whitespace)
>>
>> Oh no you don't! ;P
>
> Ooops. Fixed....

Read more...

Michael Zanetti (mzanetti) wrote :

W dniu 05.07.2013, Michał (Saviq) Sawicz <email address hidden> pisze wiele uwag:
> [...]

All done.

Michał Sawicz (saviq) wrote :

201 + Q_INVOKABLE virtual void quickListActionInvoked(const QString &appId, int quickListIndex) = 0;

s/quickListIndex/actionIndex/ maybe?

review: Needs Information
Michael Zanetti (mzanetti) wrote :

> 201 + Q_INVOKABLE virtual void quickListActionInvoked(const QString
> &appId, int quickListIndex) = 0;
>
> s/quickListIndex/actionIndex/ maybe?

Sounds reasonable => Done

Michał Sawicz (saviq) :
review: Approve
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-07-03 02:35:04 +0000
3+++ debian/changelog 2013-07-08 16:43:36 +0000
4@@ -1,3 +1,9 @@
5+unity-api (7.80.3-0ubuntu1) UNRELEASED; urgency=low
6+
7+ * added quicklist support to launcher api
8+
9+ -- Michael Zanetti <michael.zanetti@canonical.com> Fri, 05 Jul 2013 17:29:44 +0200
10+
11 unity-api (7.80.2+13.10.20130703ubuntu.unity.next-0ubuntu1) saucy; urgency=low
12
13 [ Michał Sawicz ]
14
15=== modified file 'include/unity/shell/launcher/CMakeLists.txt'
16--- include/unity/shell/launcher/CMakeLists.txt 2013-05-17 10:10:20 +0000
17+++ include/unity/shell/launcher/CMakeLists.txt 2013-07-08 16:43:36 +0000
18@@ -7,7 +7,7 @@
19
20 set(UNITY_API_LIB_HDRS ${UNITY_API_LIB_HDRS} ${headers} ${internal_headers} PARENT_SCOPE)
21
22-set(VERSION 1)
23+set(VERSION 2)
24 set(PKGCONFIG_NAME "unity-shell-launcher")
25 set(PKGCONFIG_DESCRIPTION "Unity shell Launcher APIs")
26 set(PKGCONFIG_REQUIRES "Qt5Core")
27
28=== modified file 'include/unity/shell/launcher/LauncherItemInterface.h'
29--- include/unity/shell/launcher/LauncherItemInterface.h 2013-06-19 14:45:12 +0000
30+++ include/unity/shell/launcher/LauncherItemInterface.h 2013-07-08 16:43:36 +0000
31@@ -31,6 +31,8 @@
32 namespace launcher
33 {
34
35+class QuickListModelInterface;
36+
37 /**
38 * @brief An item presented in the launcher
39 *
40@@ -43,6 +45,11 @@
41 Q_OBJECT
42
43 /**
44+ * @brief The appId of the application associated with the item.
45+ */
46+ Q_PROPERTY(QString appId READ appId CONSTANT)
47+
48+ /**
49 * @brief The full path to the .desktop file.
50 */
51 Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
52@@ -58,19 +65,19 @@
53 Q_PROPERTY(QString icon READ icon CONSTANT)
54
55 /**
56- * @brief A flag whether the item is marked as favorite (aka. pinned) or not
57+ * @brief A flag whether the item is pinned or not
58 */
59- Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged)
60+ Q_PROPERTY(bool pinned READ pinned NOTIFY pinnedChanged)
61
62 /**
63 * @brief A flag whether the application belonging to the icon is currently running or not
64 */
65- Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
66+ Q_PROPERTY(bool running READ running NOTIFY runningChanged)
67
68 /**
69 * @brief A flag wheter the application is in the recently used applications list
70 */
71- Q_PROPERTY(bool recent READ recent WRITE setRecent NOTIFY recentChanged)
72+ Q_PROPERTY(bool recent READ recent NOTIFY recentChanged)
73
74 /**
75 * @brief The percentage of the progress bar shown on the item.
76@@ -78,7 +85,7 @@
77 * For values from 0 and 100 this will present a progress bar on the item.
78 * For values outside this range, no progress bar will be drawn.
79 */
80- Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged)
81+ Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
82
83 /**
84 * @brief The number for the count emblem on the item
85@@ -86,7 +93,16 @@
86 * For values >0 this will paint an emblem containing the number.
87 * For 0 and negative values, no count emblem will be drawn.
88 */
89- Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
90+ Q_PROPERTY(int count READ count NOTIFY countChanged)
91+
92+ /**
93+ * @brief The quick list menu contents for the item
94+ *
95+ * Items can have a quick list menu. This property holds a model for
96+ * the contents of that menu. The pointer to the model will be
97+ * constant, but of course the contents of the model can change.
98+ */
99+ Q_PROPERTY(unity::shell::launcher::QuickListModelInterface* quickList READ quickList CONSTANT)
100
101 protected:
102 /// @cond
103@@ -95,28 +111,19 @@
104 public:
105 virtual ~LauncherItemInterface() {}
106
107+ virtual QString appId() const = 0;
108 virtual QString desktopFile() const = 0;
109-
110 virtual QString name() const = 0;
111 virtual QString icon() const = 0;
112-
113- virtual bool favorite() const = 0;
114- virtual void setFavorite(bool favorite) = 0;
115-
116+ virtual bool pinned() const = 0;
117 virtual bool running() const = 0;
118- virtual void setRunning(bool running) = 0;
119-
120 virtual bool recent() const = 0;
121- virtual void setRecent(bool recent) = 0;
122-
123 virtual int progress() const = 0;
124- virtual void setProgress(int progress) = 0;
125-
126 virtual int count() const = 0;
127- virtual void setCount(int count) = 0;
128+ virtual unity::shell::launcher::QuickListModelInterface *quickList() const = 0;
129
130 Q_SIGNALS:
131- void favoriteChanged(bool favorite);
132+ void pinnedChanged(bool pinned);
133 void runningChanged(bool running);
134 void recentChanged(bool running);
135 void progressChanged(int progress);
136
137=== modified file 'include/unity/shell/launcher/LauncherModelInterface.h'
138--- include/unity/shell/launcher/LauncherModelInterface.h 2013-06-19 14:59:50 +0000
139+++ include/unity/shell/launcher/LauncherModelInterface.h 2013-07-08 16:43:36 +0000
140@@ -44,7 +44,17 @@
141
142 protected:
143 /// @cond
144- LauncherModelInterface(QObject *parent = 0): QAbstractListModel(parent) {}
145+ LauncherModelInterface(QObject *parent = 0): QAbstractListModel(parent) {
146+ m_roleNames.insert(RoleAppId, "appId");
147+ m_roleNames.insert(RoleDesktopFile, "desktopFile");
148+ m_roleNames.insert(RoleName, "name");
149+ m_roleNames.insert(RoleIcon, "icon");
150+ m_roleNames.insert(RolePinned, "pinned");
151+ m_roleNames.insert(RoleRunning, "running");
152+ m_roleNames.insert(RoleRecent, "recent");
153+ m_roleNames.insert(RoleProgress, "progress");
154+ m_roleNames.insert(RoleCount, "count");
155+ }
156 /// @endcond
157
158 public:
159@@ -54,10 +64,11 @@
160 * See LauncherItemInterface properties for details.
161 */
162 enum Roles {
163- RoleDesktopFile = Qt::UserRole,
164+ RoleAppId = Qt::UserRole,
165+ RoleDesktopFile,
166 RoleName,
167 RoleIcon,
168- RoleFavorite,
169+ RolePinned,
170 RoleRunning,
171 RoleRecent,
172 RoleProgress,
173@@ -68,6 +79,9 @@
174
175 /**
176 * @brief Move an item in the model.
177+ *
178+ * @param oldIndex The current (old) index of the item to be moved.
179+ * @param newIndex The new index where the item should be moved to.
180 */
181 Q_INVOKABLE virtual void move(int oldIndex, int newIndex) = 0;
182
183@@ -81,22 +95,51 @@
184 */
185 Q_INVOKABLE virtual unity::shell::launcher::LauncherItemInterface *get(int index) const = 0;
186
187+ /**
188+ * @brief Pin an item to the launcher.
189+ *
190+ * Recent and running applications will eventually disappear from the model
191+ * as the application is closed or new recent items appear. Pinning an item
192+ * to the launcher makes it persist until remove is called on it.
193+ *
194+ * @param appId The appId of the item to be pinned.
195+ * @param index The index where the item should be pinned to. This parameter is optional
196+ * and if not supplied, the item will be pinned to the current position.
197+ * Note: If an item is not contained in the launcher yet, calling this without an index
198+ * will pin the item to the end of the list.
199+ */
200+ Q_INVOKABLE virtual void pin(const QString &appId, int index = -1) = 0;
201+
202+ /**
203+ * @brief Request removal of an item from the model.
204+ *
205+ * Note: The actual removal of the item might be delayed in certain circumstances.
206+ *
207+ * @param appId The appId of the item to be removed.
208+ */
209+ Q_INVOKABLE virtual void requestRemove(const QString &appId) = 0;
210+
211+
212+ /**
213+ * @brief Trigger an action from the QuickList
214+ *
215+ * @param appId The appId of the LauncherItem.
216+ * @param actionIndex The index of the triggered entry in the QuickListModel.
217+ */
218+ Q_INVOKABLE virtual void quickListActionInvoked(const QString &appId, int actionIndex) = 0;
219+
220 /// @cond
221 virtual QHash<int, QByteArray> roleNames() const
222 {
223- QHash<int, QByteArray> roles;
224- roles.insert(RoleDesktopFile, "desktopFile");
225- roles.insert(RoleName, "name");
226- roles.insert(RoleIcon, "icon");
227- roles.insert(RoleFavorite, "favorite");
228- roles.insert(RoleRunning, "running");
229- roles.insert(RoleRecent, "recent");
230- roles.insert(RoleProgress, "progress");
231- roles.insert(RoleCount, "count");
232- return roles;
233+ return m_roleNames;
234 }
235 /// @endcond
236
237+protected:
238+ /// @cond
239+ QHash<int, QByteArray> m_roleNames;
240+ /// @endcond
241+
242 };
243
244 } // namespace launcher
245
246=== added file 'include/unity/shell/launcher/QuickListModelInterface.h'
247--- include/unity/shell/launcher/QuickListModelInterface.h 1970-01-01 00:00:00 +0000
248+++ include/unity/shell/launcher/QuickListModelInterface.h 2013-07-08 16:43:36 +0000
249@@ -0,0 +1,84 @@
250+/*
251+ * Copyright 2013 Canonical Ltd.
252+ *
253+ * This program is free software; you can redistribute it and/or modify
254+ * it under the terms of the GNU Lesser General Public License as published by
255+ * the Free Software Foundation; version 3.
256+ *
257+ * This program is distributed in the hope that it will be useful,
258+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
259+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
260+ * GNU Lesser General Public License for more details.
261+ *
262+ * You should have received a copy of the GNU Lesser General Public License
263+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
264+ *
265+ * Authors:
266+ * Michael Zanetti <michael.zanetti@canonical.com>
267+ */
268+
269+#ifndef UNITY_SHELL_LAUNCHER_QUICKLISTMODELINTERFACE_H
270+#define UNITY_SHELL_LAUNCHER_QUICKLISTMODELINTERFACE_H
271+
272+#include <unity/SymbolExport.h>
273+
274+#include <QtCore/QAbstractListModel>
275+
276+namespace unity
277+{
278+namespace shell
279+{
280+namespace launcher
281+{
282+
283+/**
284+ * @brief A model containing QuickList actions for an application in the launcher.
285+ *
286+ * The model has the following roles:
287+ * - RoleLabel (label): The text entry in the QuickList menu (QString).
288+ * - RoleIcon (icon): The icon to be shown for this entry (QString).
289+ */
290+class UNITY_API QuickListModelInterface: public QAbstractListModel
291+{
292+ Q_OBJECT
293+
294+protected:
295+ /// @cond
296+ explicit QuickListModelInterface(QObject *parent = 0) : QAbstractListModel(parent) {
297+ m_roleNames.insert(RoleLabel, "label");
298+ m_roleNames.insert(RoleIcon, "icon");
299+ }
300+ /// @endcond
301+public:
302+ /**
303+ * @brief The Roles supported by the model
304+ *
305+ * See class description for details.
306+ */
307+ enum Roles {
308+ RoleLabel,
309+ RoleIcon
310+ };
311+
312+ /// @cond
313+ virtual ~QuickListModelInterface() {}
314+ /// @endcond
315+
316+ /// @cond
317+ QHash<int, QByteArray> roleNames() const {
318+ return m_roleNames;
319+ }
320+ /// @endcond
321+
322+protected:
323+ /// @cond
324+ QHash<int, QByteArray> m_roleNames;
325+ /// @endcond
326+
327+};
328+
329+} // launcher
330+} // shell
331+} // unity
332+
333+#endif // UNITY_SHELL_LAUNCHER_QUICKLISTMODELINTERFACE_H
334
335=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/CMakeLists.txt'
336--- test/qmltest/mocks/plugins/Unity/Launcher/CMakeLists.txt 2013-06-19 13:28:46 +0000
337+++ test/qmltest/mocks/plugins/Unity/Launcher/CMakeLists.txt 2013-07-08 16:43:36 +0000
338@@ -13,8 +13,10 @@
339 set(LauncherMocks_SOURCES
340 ${CMAKE_SOURCE_DIR}/include/unity/shell/launcher/LauncherModelInterface.h
341 ${CMAKE_SOURCE_DIR}/include/unity/shell/launcher/LauncherItemInterface.h
342+ ${CMAKE_SOURCE_DIR}/include/unity/shell/launcher/QuickListModelInterface.h
343 Mocks/MockLauncherModel.cpp
344 Mocks/MockLauncherItem.cpp
345+ Mocks/MockQuickListModel.cpp
346 )
347
348 add_library(LauncherMocks SHARED ${LauncherMocks_SOURCES})
349
350=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.cpp'
351--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.cpp 2013-06-11 10:42:07 +0000
352+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.cpp 2013-07-08 16:43:36 +0000
353@@ -18,21 +18,29 @@
354 */
355
356 #include <Mocks/MockLauncherItem.h>
357+#include <Mocks/MockQuickListModel.h>
358
359 using namespace unity::shell::launcher;
360
361-MockLauncherItem::MockLauncherItem(const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
362+MockLauncherItem::MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
363 LauncherItemInterface(parent),
364+ m_appId(appId),
365 m_desktopFile(desktopFile),
366 m_name(name),
367 m_icon(icon),
368- m_favorite(false),
369+ m_pinned(false),
370 m_running(false),
371 m_recent(false),
372 m_progress(8),
373- m_count(8)
374-{
375-
376+ m_count(8),
377+ m_quickListModel(new MockQuickListModel(this))
378+{
379+
380+}
381+
382+QString MockLauncherItem::appId() const
383+{
384+ return m_appId;
385 }
386
387 QString MockLauncherItem::desktopFile() const
388@@ -50,17 +58,17 @@
389 return m_icon;
390 }
391
392-bool MockLauncherItem::favorite() const
393+bool MockLauncherItem::pinned() const
394 {
395- return m_favorite;
396+ return m_pinned;
397 }
398
399-void MockLauncherItem::setFavorite(bool favorite)
400+void MockLauncherItem::setPinned(bool pinned)
401 {
402- if (m_favorite != favorite)
403+ if (m_pinned != pinned)
404 {
405- m_favorite = favorite;
406- Q_EMIT favoriteChanged(m_favorite);
407+ m_pinned = pinned;
408+ Q_EMIT pinnedChanged(m_pinned);
409 }
410 }
411
412@@ -119,3 +127,8 @@
413 Q_EMIT countChanged(count);
414 }
415 }
416+
417+QuickListModelInterface *MockLauncherItem::quickList() const
418+{
419+ return m_quickListModel;
420+}
421
422=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.h'
423--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.h 2013-06-19 13:28:46 +0000
424+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherItem.h 2013-07-08 16:43:36 +0000
425@@ -28,15 +28,15 @@
426 {
427 Q_OBJECT
428 public:
429- MockLauncherItem(const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
430+ MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
431
432+ QString appId() const;
433 QString desktopFile() const;
434-
435 QString name() const;
436 QString icon() const;
437
438- bool favorite() const;
439- void setFavorite(bool favorite);
440+ bool pinned() const;
441+ void setPinned(bool pinned);
442
443 bool running() const;
444 void setRunning(bool running);
445@@ -50,15 +50,19 @@
446 int count() const;
447 void setCount(int count);
448
449+ unity::shell::launcher::QuickListModelInterface *quickList() const;
450+
451 private:
452+ QString m_appId;
453 QString m_desktopFile;
454 QString m_name;
455 QString m_icon;
456- bool m_favorite;
457+ bool m_pinned;
458 bool m_running;
459 bool m_recent;
460 int m_progress;
461 int m_count;
462+ QuickListModelInterface *m_quickListModel;
463 };
464
465 #endif // MOCKLAUNCHERITEM_H
466
467=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.cpp'
468--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.cpp 2013-06-11 10:42:07 +0000
469+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.cpp 2013-07-08 16:43:36 +0000
470@@ -24,25 +24,25 @@
471
472 MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
473 {
474- LauncherItemInterface *item = new MockLauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
475- m_list.append(item);
476- item = new MockLauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
477- m_list.append(item);
478- item = new MockLauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
479- m_list.append(item);
480- item = new MockLauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
481- m_list.append(item);
482- item = new MockLauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
483- m_list.append(item);
484- item = new MockLauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
485- m_list.append(item);
486- item = new MockLauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
487- m_list.append(item);
488- item = new MockLauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
489- m_list.append(item);
490- item = new MockLauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
491- m_list.append(item);
492- item = new MockLauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
493+ MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
494+ m_list.append(item);
495+ item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera");
496+ m_list.append(item);
497+ item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
498+ m_list.append(item);
499+ item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
500+ m_list.append(item);
501+ item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
502+ m_list.append(item);
503+ item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
504+ m_list.append(item);
505+ item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
506+ m_list.append(item);
507+ item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
508+ m_list.append(item);
509+ item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
510+ m_list.append(item);
511+ item = new MockLauncherItem("ubuntu-calendar-app", "/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
512 m_list.append(item);
513 }
514
515@@ -66,14 +66,16 @@
516 LauncherItemInterface *item = m_list.at(index.row());
517 switch(role)
518 {
519+ case RoleAppId:
520+ return item->appId();
521 case RoleDesktopFile:
522 return item->desktopFile();
523 case RoleName:
524 return item->name();
525 case RoleIcon:
526 return item->icon();
527- case RoleFavorite:
528- return item->favorite();
529+ case RolePinned:
530+ return item->pinned();
531 case RoleRunning:
532 return item->running();
533 case RoleRecent:
534@@ -98,7 +100,23 @@
535
536 void MockLauncherModel::move(int oldIndex, int newIndex)
537 {
538- beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
539- m_list.move(oldIndex, newIndex);
540- endMoveRows();
541+ Q_UNUSED(oldIndex)
542+ Q_UNUSED(newIndex)
543+}
544+
545+void MockLauncherModel::pin(const QString &appId, int index)
546+{
547+ Q_UNUSED(appId)
548+ Q_UNUSED(index)
549+}
550+
551+void MockLauncherModel::requestRemove(const QString &appId)
552+{
553+ Q_UNUSED(appId)
554+}
555+
556+void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
557+{
558+ Q_UNUSED(appId)
559+ Q_UNUSED(actionIndex)
560 }
561
562=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.h'
563--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.h 2013-06-19 13:28:46 +0000
564+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockLauncherModel.h 2013-07-08 16:43:36 +0000
565@@ -22,6 +22,8 @@
566
567 #include <LauncherModelInterface.h>
568
569+class MockLauncherItem;
570+
571 using namespace unity::shell::launcher;
572
573 class UNITY_API MockLauncherModel: public LauncherModelInterface
574@@ -38,8 +40,15 @@
575
576 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
577 Q_INVOKABLE void move(int oldIndex, int newIndex);
578-private:
579- QList<LauncherItemInterface*> m_list;
580+ Q_INVOKABLE void pin(const QString &appId, int index = -1);
581+ Q_INVOKABLE void requestRemove(const QString &appId);
582+ Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
583+
584+private:
585+ int findApp(const QString &appId);
586+
587+private:
588+ QList<MockLauncherItem*> m_list;
589 };
590
591 #endif // MOCKLAUNCHERMODEL_H
592
593=== added file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.cpp'
594--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.cpp 1970-01-01 00:00:00 +0000
595+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.cpp 2013-07-08 16:43:36 +0000
596@@ -0,0 +1,46 @@
597+/*
598+ * Copyright 2013 Canonical Ltd.
599+ *
600+ * This program is free software; you can redistribute it and/or modify
601+ * it under the terms of the GNU Lesser General Public License as published by
602+ * the Free Software Foundation; version 3.
603+ *
604+ * This program is distributed in the hope that it will be useful,
605+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
606+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
607+ * GNU Lesser General Public License for more details.
608+ *
609+ * You should have received a copy of the GNU Lesser General Public License
610+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
611+ *
612+ * Authors:
613+ * Michael Zanetti <michael.zanetti@canonical.com>
614+ */
615+
616+#include <Mocks/MockQuickListModel.h>
617+
618+using namespace unity::shell::launcher;
619+
620+MockQuickListModel::MockQuickListModel(QObject *parent) :
621+ QuickListModelInterface(parent)
622+{
623+
624+}
625+
626+QVariant MockQuickListModel::data(const QModelIndex &index, int role) const
627+{
628+ switch (role)
629+ {
630+ case RoleLabel:
631+ return QLatin1String("test menu entry ") + QString::number(index.row());
632+ case RoleIcon:
633+ return QLatin1String("copy.png");
634+ }
635+ return QVariant();
636+}
637+
638+int MockQuickListModel::rowCount(const QModelIndex &parent) const
639+{
640+ Q_UNUSED(parent)
641+ return 4;
642+}
643
644=== added file 'test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.h'
645--- test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.h 1970-01-01 00:00:00 +0000
646+++ test/qmltest/mocks/plugins/Unity/Launcher/Mocks/MockQuickListModel.h 2013-07-08 16:43:36 +0000
647@@ -0,0 +1,38 @@
648+/*
649+ * Copyright 2013 Canonical Ltd.
650+ *
651+ * This program is free software; you can redistribute it and/or modify
652+ * it under the terms of the GNU Lesser General Public License as published by
653+ * the Free Software Foundation; version 3.
654+ *
655+ * This program is distributed in the hope that it will be useful,
656+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
657+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
658+ * GNU Lesser General Public License for more details.
659+ *
660+ * You should have received a copy of the GNU Lesser General Public License
661+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
662+ *
663+ * Authors:
664+ * Michael Zanetti <michael.zanetti@canonical.com>
665+ */
666+
667+#ifndef MOCKQUICKLISTMODEL_H
668+#define MOCKQUICKLISTMODEL_H
669+
670+#include <QuickListModelInterface.h>
671+
672+using namespace unity::shell::launcher;
673+
674+class UNITY_API MockQuickListModel: public QuickListModelInterface
675+{
676+ Q_OBJECT
677+public:
678+ MockQuickListModel(QObject *parent = 0);
679+
680+ QVariant data(const QModelIndex &index, int role) const;
681+
682+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
683+};
684+
685+#endif // MOCKQUICKLISTMODEL_H
686
687=== modified file 'test/qmltest/mocks/plugins/Unity/Launcher/TestLauncherPlugin.cpp'
688--- test/qmltest/mocks/plugins/Unity/Launcher/TestLauncherPlugin.cpp 2013-06-19 13:28:46 +0000
689+++ test/qmltest/mocks/plugins/Unity/Launcher/TestLauncherPlugin.cpp 2013-07-08 16:43:36 +0000
690@@ -20,6 +20,7 @@
691 #include <TestLauncherPlugin.h>
692 #include <Mocks/MockLauncherModel.h>
693 #include <Mocks/MockLauncherItem.h>
694+#include <Mocks/MockQuickListModel.h>
695
696 #include <LauncherModelInterface.h>
697 #include <LauncherItemInterface.h>
698@@ -39,7 +40,9 @@
699 // @uri Unity.Launcher
700 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Interface for the LauncherModel");
701 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Interface for the LauncherItem");
702+ qmlRegisterUncreatableType<QuickListModelInterface>(uri, 0, 1, "QuickListModelInterface", "Interface for the QuickListModel");
703
704 qmlRegisterSingletonType<MockLauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
705 qmlRegisterUncreatableType<MockLauncherItem>(uri, 0, 1, "LauncherItem", "Can't create LauncherItems in QML. Get them from the LauncherModel");
706+ qmlRegisterUncreatableType<MockQuickListModel>(uri, 0, 1, "QuickListModel", "Can't create QuickListModels in QML. Get them from the LauncherItems");
707 }
708
709=== modified file 'test/qmltest/unity/shell/launcher/tst_Launcher.qml'
710--- test/qmltest/unity/shell/launcher/tst_Launcher.qml 2013-06-19 14:59:50 +0000
711+++ test/qmltest/unity/shell/launcher/tst_Launcher.qml 2013-07-08 16:43:36 +0000
712@@ -24,6 +24,10 @@
713
714 Item {
715
716+ SignalSpy {
717+ id: signalSpy
718+ }
719+
720 Verifier {
721 id: checkModelVerifier
722
723@@ -55,9 +59,17 @@
724 }
725 }
726
727+ Repeater {
728+ id: quickListRepeater
729+ model: LauncherModel.get(0).quickList
730+ delegate: Item {
731+ property var roles: model
732+ }
733+ }
734+
735 function initTestCase() {
736- if (repeater.count < 4) {
737- print("This Test Suite requires at least 4 items in the model.")
738+ if (repeater.count < 5) {
739+ print("This Test Suite requires at least 5 items in the model.")
740 fail()
741 }
742 }
743@@ -65,10 +77,11 @@
744 /* make sure all the required roles are exposed on Model */
745 function test_model_roles_data() {
746 return [
747+ { tag: "Model.roles[appId]", role: "appId", type: "string" },
748 { tag: "Model.roles[desktopFile]", role: "desktopFile", type: "string" },
749 { tag: "Model.roles[name]", role: "name", type: "string" },
750 { tag: "Model.roles[icon]", role: "icon", type: "string" },
751- { tag: "Model.roles[favorite]", role: "favorite", type: "boolean" },
752+ { tag: "Model.roles[pinned]", role: "pinned", type: "boolean" },
753 { tag: "Model.roles[running]", role: "running", type: "boolean" },
754 { tag: "Model.roles[recent]", role: "recent", type: "boolean" },
755 { tag: "Model.roles[progress]", role: "progress", type: "number" },
756@@ -89,8 +102,11 @@
757
758 function test_model_methods_data() {
759 return [
760- { tag: "Model.methods[get]", method: "get" },
761- { tag: "Model.methods[move]", method: "move" }
762+ { tag: "Model.methods[get]", method: "get" },
763+ { tag: "Model.methods[move]", method: "move" },
764+ { tag: "Model.methods[pin]", method: "pin" },
765+ { tag: "Model.methods[requestRemove]", method: "requestRemove" },
766+ { tag: "Model.methods[quickListActionInvoked]", method: "quickListActionInvoked" }
767 ];
768 }
769
770@@ -102,15 +118,17 @@
771
772 function test_item_properties_data() {
773 return [
774- { tag: "Item.properties[desktopFile]", constant: "desktopFile", type: "string" },
775- { tag: "Item.properties[name]", constant: "name", type: "string" },
776- { tag: "Item.properties[icon]", constant: "icon", type: "string" },
777- { tag: "Item.properties[favorite]", property: "favorite", type: "boolean" },
778- { tag: "Item.properties[recent]", property: "recent", type: "boolean" },
779- { tag: "Item.properties[running]", property: "running", type: "boolean" },
780- { tag: "Item.properties[progress]", property: "progress", type: "number" },
781- { tag: "Item.properties[count]", property: "count", type: "number" },
782- ];
783+ { tag: "Item.properties[appId]", constant: "appId", type: "string" },
784+ { tag: "Item.properties[desktopFile]", constant: "desktopFile", type: "string" },
785+ { tag: "Item.properties[name]", constant: "name", type: "string" },
786+ { tag: "Item.properties[icon]", constant: "icon", type: "string" },
787+ { tag: "Item.properties[pinned]", property: "pinned", type: "boolean" },
788+ { tag: "Item.properties[recent]", property: "recent", type: "boolean" },
789+ { tag: "Item.properties[running]", property: "running", type: "boolean" },
790+ { tag: "Item.properties[progress]", property: "progress", type: "number" },
791+ { tag: "Item.properties[count]", property: "count", type: "number" },
792+ { tag: "Item.properties[quickList]", constant: "quickList", type: "object" },
793+ ];
794 }
795
796 function test_item_properties(data) {
797@@ -125,18 +143,22 @@
798 verifyData(data)
799 }
800
801- function test_move() {
802- var item0 = LauncherModel.get(0)
803- var item1 = LauncherModel.get(1)
804- var item2 = LauncherModel.get(2)
805- var item3 = LauncherModel.get(3)
806-
807- LauncherModel.move(2, 0);
808-
809- compare(item2, LauncherModel.get(0), "Error moving Items im model")
810- compare(item0, LauncherModel.get(1), "Error moving Items im model")
811- compare(item1, LauncherModel.get(2), "Error moving Items im model")
812- compare(item3, LauncherModel.get(3), "Error moving Items im model")
813+ function test_quicklist_model_roles_data() {
814+ return [
815+ { tag: "Model.roles[label]", role: "label", type: "string" },
816+ { tag: "Model.roles[icon]", role: "icon", type: "string" },
817+ ];
818+ }
819+
820+ function test_quicklist_model_roles(data) {
821+ name = "QuickListModel"
822+ try {
823+ object = quickListRepeater.itemAt(0).roles;
824+ } catch(err) {
825+ object = undefined;
826+ }
827+
828+ verifyData(data);
829 }
830 }
831 }

Subscribers

People subscribed via source and target branches

to all changes: