Merge lp:~unity-team/unity8/launcher-backend into lp:unity8

Proposed by Michael Zanetti on 2013-07-05
Status: Merged
Approved by: Michał Sawicz on 2013-07-11
Approved revision: 99
Merged at revision: 100
Proposed branch: lp:~unity-team/unity8/launcher-backend
Merge into: lp:unity8
Diff against target: 2436 lines (+1644/-492)
36 files modified
CMakeLists.txt (+1/-2)
Launcher/Launcher.qml (+2/-5)
Launcher/LauncherPanel.qml (+3/-2)
debian/control (+5/-0)
plugins/Unity/CMakeLists.txt (+2/-1)
plugins/Unity/Launcher/CMakeLists.txt (+27/-0)
plugins/Unity/Launcher/backend/launcherbackend.cpp (+145/-0)
plugins/Unity/Launcher/backend/launcherbackend.h (+132/-0)
plugins/Unity/Launcher/common/quicklistentry.cpp (+54/-0)
plugins/Unity/Launcher/common/quicklistentry.h (+44/-0)
plugins/Unity/Launcher/launcheritem.cpp (+127/-0)
plugins/Unity/Launcher/launcheritem.h (+76/-0)
plugins/Unity/Launcher/launchermodel.cpp (+170/-0)
plugins/Unity/Launcher/launchermodel.h (+61/-0)
plugins/Unity/Launcher/plugin.cpp (+47/-0)
plugins/Unity/Launcher/plugin.h (+34/-0)
plugins/Unity/Launcher/qmldir (+2/-0)
plugins/Unity/Launcher/quicklistmodel.cpp (+60/-0)
plugins/Unity/Launcher/quicklistmodel.h (+48/-0)
plugins/Unity/launchermodel.cpp (+0/-153)
plugins/Unity/launchermodel.h (+0/-86)
plugins/Unity/plugin.cpp (+0/-3)
tests/mocks/Unity/CMakeLists.txt (+2/-1)
tests/mocks/Unity/Launcher/CMakeLists.txt (+26/-0)
tests/mocks/Unity/Launcher/MockLauncherItem.cpp (+134/-0)
tests/mocks/Unity/Launcher/MockLauncherItem.h (+70/-0)
tests/mocks/Unity/Launcher/MockLauncherModel.cpp (+152/-0)
tests/mocks/Unity/Launcher/MockLauncherModel.h (+54/-0)
tests/mocks/Unity/Launcher/MockQuickListModel.cpp (+46/-0)
tests/mocks/Unity/Launcher/MockQuickListModel.h (+38/-0)
tests/mocks/Unity/Launcher/plugin.cpp (+45/-0)
tests/mocks/Unity/Launcher/plugin.h (+35/-0)
tests/mocks/Unity/Launcher/qmldir (+2/-0)
tests/mocks/Unity/fake_launchermodel.cpp (+0/-150)
tests/mocks/Unity/fake_launchermodel.h (+0/-86)
tests/mocks/Unity/fake_unity_plugin.cpp (+0/-3)
To merge this branch: bzr merge lp:~unity-team/unity8/launcher-backend
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration 2013-07-05 Approve on 2013-07-11
Michał Sawicz 2013-07-05 Approve on 2013-07-10
Review via email: mp+173189@code.launchpad.net

Commit message

Make use of the launcher API defined in unity-api and separate the model from the backend.

Description of the change

This moves the fake data yet another step towards the bottom.

The LauncherModel itself is now responsible for ordering and managing the launcheritems while the actual contents come from the LauncherBackend class. Still sample data in there but real code to store/load stuff from configs is the next step.

To post a comment you must log in.
Michał Sawicz (saviq) wrote :
Download full text (3.7 KiB)

  78 + unity8-private | unity8-launcher-impl,
  79 + unity8-launcher-impl-0.2,

  87 +Provides: unity-launcher-impl,
  88 + unity-launcher-impl-0.2

As mentioned on IRC: unity-launcher-impl, not unity8, and -0.2 should be what you set to VERSION in the unity-api MP.

=====

 123 + ${CMAKE_CURRENT_BINARY_DIR}
 124 + ${LAUNCHER_API_INCLUDEDIR}

Is this required?

=====

# copy qmldir file into build directory for shadow builds
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
    )

See in Ubuntu.Gestures for a better approach to this (using a custom target depending on the files to update when changed - I'll later go through our current codebase and fix it across the board; we should also use ${CMAKE_COMMAND} -E copy... etc.)

=====

Please put Authors below copyright.

=====

 205 +LauncherBackend::~LauncherBackend()
 206 +{
 207 +
 208 +}

Is it just a template thing, or do we want empty destructors as a rule?

=====

 227 +QString LauncherBackend::displayName(const QString &appId) const
 228 +{
 229 + // TODO: get stuff from desktop files instead this hardcoded map
 230 + QHash<QString, QString> map;
 231 + map.insert("phone-app.desktop", "Phone");
 232 + map.insert("camera-app.desktop", "Camera");
 233 + map.insert("gallery-app.desktop", "Gallery");
 234 + map.insert("facebook-webapp.desktop", "Facebook");
 235 + map.insert("webbrowser-app.desktop", "Browser");
 236 + map.insert("twitter-webapp.desktop", "Twitter");
 237 + map.insert("gmail-webapp.desktop", "GMail");
 238 + map.insert("ubuntu-weather-app.desktop", "Weather");
 239 + map.insert("notes-app.desktop", "Notes");
 240 + map.insert("ubuntu-calendar-app.desktop", "Calendar");
 241 + return map.value(appId);
 242 +}
 243 +
 244 +QString LauncherBackend::icon(const QString &appId) const
 245 +{
 246 + // TODO: get stuff from desktop files instead this hardcoded map
 247 + QHash<QString, QString> map;
 248 + map.insert("phone-app.desktop", "phone-app");
 249 + map.insert("camera-app.desktop", "camera");
 250 + map.insert("gallery-app.desktop", "gallery");
 251 + map.insert("facebook-webapp.desktop", "facebook");
 252 + map.insert("webbrowser-app.desktop", "browser");
 253 + map.insert("twitter-webapp.desktop", "twitter");
 254 + map.insert("gmail-webapp.desktop", "gmail");
 255 + map.insert("ubuntu-weather-app.desktop", "weather");
 256 + map.insert("notes-app.desktop", "notepad");
 257 + map.insert("ubuntu-calendar-app.desktop", "calendar");
 258 + return map.value(appId);

I know that's temporary code, but making those static and only filling it once would save us some CPU cycles.

=====

 301 +void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)

s/quickListId/actionId/ maybe?

Hmm, from https://code.launchpad.net/~mzanetti/unity-api/launcher-api-pinning/+merge/173064

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

=====

Hmm hmm... Why doesn't LauncherBackend have an API definition in lp:unity-api? Or is it just a stop-gap? ...

Read more...

review: Needs Fixing
Michael Zanetti (mzanetti) wrote :
Download full text (5.0 KiB)

> 78 + unity8-private | unity8-launcher-impl,
> 79 + unity8-launcher-impl-0.2,
>
> 87 +Provides: unity-launcher-impl,
> 88 + unity-launcher-impl-0.2
>
>
> As mentioned on IRC: unity-launcher-impl, not unity8, and -0.2 should be what
> you set to VERSION in the unity-api MP.

Done

> =====
>
> 123 + ${CMAKE_CURRENT_BINARY_DIR}
> 124 + ${LAUNCHER_API_INCLUDEDIR}
>
> Is this required?

Not any more as the header files need to be added to sources anyways... => removed

> =====
>
> # copy qmldir file into build directory for shadow builds
> file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
> DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
> )
>
> See in Ubuntu.Gestures for a better approach to this (using a custom target
> depending on the files to update when changed - I'll later go through our
> current codebase and fix it across the board; we should also use
> ${CMAKE_COMMAND} -E copy... etc.)
>

Nice one, done.

> =====
>
> Please put Authors below copyright.

Hopefully now all the wrong ones are gone so I won't copy paste a wrong one again.

> =====
>
> 205 +LauncherBackend::~LauncherBackend()
> 206 +{
> 207 +
> 208 +}
>
> Is it just a template thing, or do we want empty destructors as a rule?

It's mostly just a template thing... Can remove it if you want, but I'm quite sure Antti will need it again.

> =====
>
> 227 +QString LauncherBackend::displayName(const QString &appId) const
> 228 +{
> 229 + // TODO: get stuff from desktop files instead this hardcoded map
> 230 + QHash<QString, QString> map;
> 231 + map.insert("phone-app.desktop", "Phone");
> 232 + map.insert("camera-app.desktop", "Camera");
> 233 + map.insert("gallery-app.desktop", "Gallery");
> 234 + map.insert("facebook-webapp.desktop", "Facebook");
> 235 + map.insert("webbrowser-app.desktop", "Browser");
> 236 + map.insert("twitter-webapp.desktop", "Twitter");
> 237 + map.insert("gmail-webapp.desktop", "GMail");
> 238 + map.insert("ubuntu-weather-app.desktop", "Weather");
> 239 + map.insert("notes-app.desktop", "Notes");
> 240 + map.insert("ubuntu-calendar-app.desktop", "Calendar");
> 241 + return map.value(appId);
> 242 +}
> 243 +
> 244 +QString LauncherBackend::icon(const QString &appId) const
> 245 +{
> 246 + // TODO: get stuff from desktop files instead this hardcoded map
> 247 + QHash<QString, QString> map;
> 248 + map.insert("phone-app.desktop", "phone-app");
> 249 + map.insert("camera-app.desktop", "camera");
> 250 + map.insert("gallery-app.desktop", "gallery");
> 251 + map.insert("facebook-webapp.desktop", "facebook");
> 252 + map.insert("webbrowser-app.desktop", "browser");
> 253 + map.insert("twitter-webapp.desktop", "twitter");
> 254 + map.insert("gmail-webapp.desktop", "gmail");
> 255 + map.insert("ubuntu-weather-app.desktop", "weather");
> 256 + map.insert("notes-app.desktop", "notepad");
> 257 + map.insert("ubuntu-calendar-app.desktop", "calendar");
> 258 + return map.value(appId);
>
> I know that's temporary code, but making those static and only filling it once
> would save us some CPU cycle...

Read more...

Michał Sawicz (saviq) wrote :

W dniu 08.07.2013 16:11, Michael Zanetti pisze:

>> 205 +LauncherBackend::~LauncherBackend()
>> 206 +{
>> 207 +
>> 208 +}
>>
>> Is it just a template thing, or do we want empty destructors as a rule?
>
> It's mostly just a template thing... Can remove it if you want, but I'm quite sure Antti will need it again.

OK.

>> Hmm hmm... Why doesn't LauncherBackend have an API definition in lp:unity-api?
>> Or is it just a stop-gap? Same for QuikcListEntry? Or is it even just a thing
>> that the shell won't ever see?
>
> Exactly... Thats the idea. Both are an implementation detail of me and Antti but never show up in the public QML api.

Yeah, but then... If we wanted to mock one or the other... Will all of
that later get away into a separate "unity-launcher" project for the
backend?

>> 355 + QStringList storedApplications() const;
>>
>> Shouldn't this be "pinnedApplications"?
>
> No, because this does not only contain pinned apps. It also contains recent ones. So if you look at it from the backend perspective, this is whant needs to be stored into the settings. The decision if its pinned, running, recent, whatever happens one layer above in LauncherModel.

Why should recent be stored? Info about recent apps should come from
Zeitgeist, and be volatile, no?

>> 401 + //TODO: Fill in getters for all the other things needed from the
>> .desktop file.
>>
>> I'm not sure that's needed, we should have a generic "AppData" component or
>> similar that would take an appId and expose all the data read from .desktop
>> and potentially other places.
>
> Yeah... Not really sure how the desktop file parser will work yet. In general I would leave that to Antti to finish up the backend API as he sees fit.

Let's just make sure we don't need to learn different APIs wherever
we're looking at an app.

>> One think we're missing is the Gettext domain to use to translate the strings.
>> It could be considered a backend task, though.
>
> yeah. I expect the backend to deliver translated app names so far. It would be quite easy to change it turns out to be a bad idea... But thats it for now and both, me and Antti where happy with it.

Yeah, I think that's common with what we do/expect in the other backends.

--
Michał (Saviq) Sawicz <email address hidden>
Canonical Services Ltd.

Michael Zanetti (mzanetti) wrote :

On Monday 08 July 2013 17:02:59 you wrote:
> W dniu 08.07.2013 16:11, Michael Zanetti pisze:
> >> 205 +LauncherBackend::~LauncherBackend()
> >> 206 +{
> >> 207 +
> >> 208 +}
> >>
> >> Is it just a template thing, or do we want empty destructors as a rule?
> >
> > It's mostly just a template thing... Can remove it if you want, but I'm
> > quite sure Antti will need it again.
> OK.
>
> >> Hmm hmm... Why doesn't LauncherBackend have an API definition in
> >> lp:unity-api? Or is it just a stop-gap? Same for QuikcListEntry? Or is
> >> it even just a thing that the shell won't ever see?
> >
> > Exactly... Thats the idea. Both are an implementation detail of me and
> > Antti but never show up in the public QML api.
> Yeah, but then... If we wanted to mock one or the other... Will all of
> that later get away into a separate "unity-launcher" project for the
> backend?

yes. Thats how I understand it... basically the complete folder
plugins/Unity/Launcher moves away to a different projects.

In there we can mock it for unit tests, but so far I'm following the idea of
pointing the backend to a directory with some desktopFile entries (instead of
/usr/share/application/) so we would test the whole thing at once. Anyways,
thats not totally planned through yet.

From a shell POV there's no need to mock the backend only because we will mock
the laucher plugin at the API. Because the backend is not exposed through the
api we wouldn't mock it.

> >> 355 + QStringList storedApplications() const;
> >>
> >> Shouldn't this be "pinnedApplications"?
> >
> > No, because this does not only contain pinned apps. It also contains
> > recent ones. So if you look at it from the backend perspective, this is
> > whant needs to be stored into the settings. The decision if its pinned,
> > running, recent, whatever happens one layer above in LauncherModel.
> Why should recent be stored? Info about recent apps should come from
> Zeitgeist, and be volatile, no?

Ah... hmm... didn't know the zeitgeist thing. In that case I would rename it
to pinnedApps indeed and have a second method for recent ones. However, this
is really stuff where Antti needs to jump in and it will evolve as he starts
working on it.

> >> 401 + //TODO: Fill in getters for all the other things needed from
> >> the
> >>
> >> .desktop file.
> >>
> >> I'm not sure that's needed, we should have a generic "AppData" component
> >> or
> >> similar that would take an appId and expose all the data read from
> >> .desktop
> >> and potentially other places.
> >
> > Yeah... Not really sure how the desktop file parser will work yet. In
> > general I would leave that to Antti to finish up the backend API as he
> > sees fit.
> Let's just make sure we don't need to learn different APIs wherever
> we're looking at an app.

Note that the Backend is an internal class and will not be exposed to anybody
else in form of an API. The only reason I commented it like an API is because
its the "internal interface" between me and Antti and I wanted to make it as
easy as possible for him to get started.

Michał Sawicz (saviq) wrote :

 811 + case RoleAppId:
 812 + return item->desktopFile();
 813 + case RoleDesktopFile:
 814 + return item->desktopFile();
 815 + case RoleName:
 816 + return item->name();
 817 + case RoleIcon:
 818 + return item->icon();
 819 + case RolePinned:
 820 + return item->pinned();

Please indent the cases

=====

1025 +}
1026 +void UnityLauncherPlugin::registerTypes(const char *uri)

Newline, please.

=====

That's it.

review: Needs Fixing
Michał Sawicz (saviq) wrote :

Would be nice to actually fail with pkgconfig version different than 2, that's the last thing here.

review: Needs Fixing
Michał Sawicz (saviq) wrote :

I say yes!

review: Approve
review: Approve (continuous-integration)
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-06-26 09:52:31 +0000
3+++ CMakeLists.txt 2013-07-10 17:15:31 +0000
4@@ -93,8 +93,6 @@
5 include(autopilot)
6 declare_autopilot_test(unity8 ${CMAKE_SOURCE_DIR}/tests/autopilot/)
7
8-add_subdirectory(tests)
9-
10 set(SHELL_APP unity8)
11
12 set(shell_app_HDRS
13@@ -132,6 +130,7 @@
14 )
15
16 # add subdirectories to build
17+add_subdirectory(tests)
18 add_subdirectory(plugins)
19
20 # install subdirectories
21
22=== modified file 'Launcher/Launcher.qml'
23--- Launcher/Launcher.qml 2013-07-02 19:24:33 +0000
24+++ Launcher/Launcher.qml 2013-07-10 17:15:31 +0000
25@@ -19,6 +19,7 @@
26 import Ubuntu.Components 0.1
27 import Ubuntu.Gestures 0.1
28 import Unity 0.1
29+import Unity.Launcher 0.1
30
31 Item {
32 id: root
33@@ -96,10 +97,6 @@
34 }
35 }
36
37- LauncherModel {
38- id: launcherModel
39- }
40-
41 MouseArea {
42 id: launcherDragArea
43 enabled: root.state == "visible"
44@@ -152,7 +149,7 @@
45 bottom: parent.bottom
46 }
47 x: -width
48- model: launcherModel
49+ model: LauncherModel
50
51 property bool animate: true
52
53
54=== modified file 'Launcher/LauncherPanel.qml'
55--- Launcher/LauncherPanel.qml 2013-07-10 08:51:12 +0000
56+++ Launcher/LauncherPanel.qml 2013-07-10 17:15:31 +0000
57@@ -17,6 +17,7 @@
58 import QtQuick 2.0
59 import Ubuntu.Components 0.1
60 import Unity 0.1
61+import Unity.Launcher 0.1
62 import "../Components/ListItems"
63
64 Item {
65@@ -140,7 +141,7 @@
66 } else if (angle < -12) {
67 launcherListView.flick(0, launcherListView.clickFlickSpeed);
68 } else {
69- root.applicationSelected(launcherModel.get(index).desktopFile);
70+ root.applicationSelected(LauncherModel.get(index).desktopFile);
71 }
72 return;
73 }
74@@ -151,7 +152,7 @@
75 } else if (angle < -30) {
76 launcherListView.flick(0, launcherListView.clickFlickSpeed);
77 } else {
78- root.applicationSelected(launcherModel.get(index).desktopFile);
79+ root.applicationSelected(LauncherModel.get(index).desktopFile);
80 }
81 }
82 }
83
84=== modified file 'debian/control'
85--- debian/control 2013-07-04 10:34:48 +0000
86+++ debian/control 2013-07-10 17:15:31 +0000
87@@ -13,6 +13,7 @@
88 libpulse-dev,
89 libqt5v8-5-private-dev,
90 libunity-core-6.0-dev (<< 7.80),
91+ libunity-api-dev (>= 7.80.3),
92 libunity-dev (>= 7.0.3),
93 libusermetricsoutput1-dev,
94 libxcb1-dev,
95@@ -52,6 +53,8 @@
96 unity-notifications-impl-1,
97 qtdeclarative5-xmllistmodel-plugin,
98 unity8-fake-env | qtubuntu-shell,
99+ unity8-private | unity-launcher-impl,
100+ unity-launcher-impl-2,
101 Recommends: ${unity-default-masterscopes},
102 indicators-client-plugin-datetime (>= 0.6.1),
103 indicators-client-plugin-messaging (>= 0.6.1),
104@@ -67,6 +70,8 @@
105 Pre-Depends: ${misc:Pre-Depends}
106 Depends: ${misc:Depends},
107 ${shlibs:Depends},
108+Provides: unity-launcher-impl,
109+ unity-launcher-impl-2
110 Description: Unity 8 private libs
111 The Unity 8 shell is the primary user interface for Ubuntu devices.
112 .
113
114=== modified file 'plugins/Unity/CMakeLists.txt'
115--- plugins/Unity/CMakeLists.txt 2013-07-09 14:01:59 +0000
116+++ plugins/Unity/CMakeLists.txt 2013-07-10 17:15:31 +0000
117@@ -21,7 +21,6 @@
118 categoryresults.cpp
119 plugin.cpp
120 bottombarvisibilitycommunicatorshell.cpp
121- launchermodel.cpp
122 applicationpreview.cpp
123 genericpreview.cpp
124 moviepreview.cpp
125@@ -49,3 +48,5 @@
126
127 # export the qmldir and qmltypes files
128 export_qmlplugin(Unity 0.1 Unity TARGETS Unity-qml)
129+
130+add_subdirectory(Launcher)
131
132=== added directory 'plugins/Unity/Launcher'
133=== added file 'plugins/Unity/Launcher/CMakeLists.txt'
134--- plugins/Unity/Launcher/CMakeLists.txt 1970-01-01 00:00:00 +0000
135+++ plugins/Unity/Launcher/CMakeLists.txt 2013-07-10 17:15:31 +0000
136@@ -0,0 +1,27 @@
137+include(FindPkgConfig)
138+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
139+
140+include_directories(
141+ ${CMAKE_CURRENT_SOURCE_DIR}
142+)
143+
144+set(QMLLAUNCHERPLUGIN_SRC
145+ plugin.cpp
146+ launchermodel.cpp
147+ launcheritem.cpp
148+ quicklistmodel.cpp
149+ common/quicklistentry.cpp
150+ backend/launcherbackend.cpp
151+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
152+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
153+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
154+ )
155+
156+add_library(UnityLauncher-qml MODULE
157+ ${QMLLAUNCHERPLUGIN_SRC}
158+ )
159+
160+qt5_use_modules(UnityLauncher-qml Qml)
161+
162+# export the qmldir and qmltypes files
163+export_qmlplugin(Unity.Launcher 0.1 Unity/Launcher TARGETS UnityLauncher-qml)
164
165=== added directory 'plugins/Unity/Launcher/backend'
166=== added file 'plugins/Unity/Launcher/backend/launcherbackend.cpp'
167--- plugins/Unity/Launcher/backend/launcherbackend.cpp 1970-01-01 00:00:00 +0000
168+++ plugins/Unity/Launcher/backend/launcherbackend.cpp 2013-07-10 17:15:31 +0000
169@@ -0,0 +1,145 @@
170+/*
171+ * Copyright (C) 2013 Canonical, Ltd.
172+ *
173+ * Authors:
174+ * Michael Zanetti <michael.zanetti@canonical.com>
175+ *
176+ * This program is free software; you can redistribute it and/or modify
177+ * it under the terms of the GNU General Public License as published by
178+ * the Free Software Foundation; version 3.
179+ *
180+ * This program is distributed in the hope that it will be useful,
181+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
182+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
183+ * GNU General Public License for more details.
184+ *
185+ * You should have received a copy of the GNU General Public License
186+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
187+ */
188+
189+#include "launcherbackend.h"
190+
191+#include <QHash>
192+
193+LauncherBackend::LauncherBackend(QObject *parent):
194+ QObject(parent)
195+{
196+
197+ // TODO: load default pinned ones from default config, instead of hardcoding here...
198+
199+ m_storedApps <<
200+ QLatin1String("phone-app.desktop") <<
201+ QLatin1String("camera-app.desktop") <<
202+ QLatin1String("gallery-app.desktop") <<
203+ QLatin1String("facebook-webapp.desktop") <<
204+ QLatin1String("webbrowser-app.desktop") <<
205+ QLatin1String("twitter-webapp.desktop") <<
206+ QLatin1String("gmail-webapp.desktop") <<
207+ QLatin1String("ubuntu-weather-app.desktop") <<
208+ QLatin1String("notes-app.desktop") <<
209+ QLatin1String("ubuntu-calendar-app.desktop");
210+
211+ // TODO: get stuff from desktop files instead this hardcoded map
212+ m_displayNameMap.insert("phone-app.desktop", "Phone");
213+ m_displayNameMap.insert("camera-app.desktop", "Camera");
214+ m_displayNameMap.insert("gallery-app.desktop", "Gallery");
215+ m_displayNameMap.insert("facebook-webapp.desktop", "Facebook");
216+ m_displayNameMap.insert("webbrowser-app.desktop", "Browser");
217+ m_displayNameMap.insert("twitter-webapp.desktop", "Twitter");
218+ m_displayNameMap.insert("gmail-webapp.desktop", "GMail");
219+ m_displayNameMap.insert("ubuntu-weather-app.desktop", "Weather");
220+ m_displayNameMap.insert("notes-app.desktop", "Notes");
221+ m_displayNameMap.insert("ubuntu-calendar-app.desktop", "Calendar");
222+
223+ // TODO: get stuff from desktop files instead this hardcoded map
224+ m_iconMap.insert("phone-app.desktop", "phone-app");
225+ m_iconMap.insert("camera-app.desktop", "camera");
226+ m_iconMap.insert("gallery-app.desktop", "gallery");
227+ m_iconMap.insert("facebook-webapp.desktop", "facebook");
228+ m_iconMap.insert("webbrowser-app.desktop", "browser");
229+ m_iconMap.insert("twitter-webapp.desktop", "twitter");
230+ m_iconMap.insert("gmail-webapp.desktop", "gmail");
231+ m_iconMap.insert("ubuntu-weather-app.desktop", "weather");
232+ m_iconMap.insert("notes-app.desktop", "notepad");
233+ m_iconMap.insert("ubuntu-calendar-app.desktop", "calendar");
234+
235+}
236+
237+LauncherBackend::~LauncherBackend()
238+{
239+
240+}
241+
242+QStringList LauncherBackend::storedApplications() const
243+{
244+ return m_storedApps;
245+}
246+
247+void LauncherBackend::setStoredApplications(const QStringList &appIds)
248+{
249+ m_storedApps = appIds;
250+ // TODO: Cleanup pinned state from settings for apps not in list any more.
251+}
252+
253+QString LauncherBackend::desktopFile(const QString &appId) const
254+{
255+ // TODO: return real path instead of this hardcoded one
256+ return QLatin1String("/usr/share/applications/") + appId;
257+}
258+
259+QString LauncherBackend::displayName(const QString &appId) const
260+{
261+ return m_displayNameMap.value(appId);
262+}
263+
264+QString LauncherBackend::icon(const QString &appId) const
265+{
266+ return m_iconMap.value(appId);
267+}
268+
269+bool LauncherBackend::isPinned(const QString &appId) const
270+{
271+ // TODO: return app's pinned state from settings
272+ Q_UNUSED(appId)
273+ return true;
274+}
275+
276+void LauncherBackend::setPinned(const QString &appId, bool pinned)
277+{
278+ // TODO: Store pinned state in settings.
279+ Q_UNUSED(appId)
280+ Q_UNUSED(pinned)
281+}
282+
283+QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
284+{
285+ // TODO: Get static (from .desktop file) and dynamic (from the app itself)
286+ // entries and return them here. Frontend related entries (like "Pin to launcher")
287+ // don't matter here. This is just the backend part.
288+ // TODO: emit quickListChanged() when the dynamic part changes
289+ Q_UNUSED(appId)
290+ return QList<QuickListEntry>();
291+}
292+
293+int LauncherBackend::progress(const QString &appId) const
294+{
295+ // TODO: Return value for progress emblem.
296+ // TODO: emit progressChanged() when this value changes.
297+ Q_UNUSED(appId)
298+ return -1;
299+}
300+
301+int LauncherBackend::count(const QString &appId) const
302+{
303+ // TODO: Return value for count emblem.
304+ // TODO: emit countChanged() when this value changes.
305+ Q_UNUSED(appId)
306+ return 0;
307+}
308+
309+void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
310+{
311+ // TODO: execute the given quicklist action
312+ Q_UNUSED(appId)
313+ Q_UNUSED(quickListId)
314+}
315
316=== added file 'plugins/Unity/Launcher/backend/launcherbackend.h'
317--- plugins/Unity/Launcher/backend/launcherbackend.h 1970-01-01 00:00:00 +0000
318+++ plugins/Unity/Launcher/backend/launcherbackend.h 2013-07-10 17:15:31 +0000
319@@ -0,0 +1,132 @@
320+/* Copyright (C) 2013 Canonical, Ltd.
321+ *
322+ * Authors:
323+ * Michael Zanetti <michael.zanetti@canonical.com>
324+ *
325+ * This program is free software; you can redistribute it and/or modify
326+ * it under the terms of the GNU General Public License as published by
327+ * the Free Software Foundation; version 3.
328+ *
329+ * This program is distributed in the hope that it will be useful,
330+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
331+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332+ * GNU General Public License for more details.
333+ *
334+ * You should have received a copy of the GNU General Public License
335+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
336+ */
337+
338+#ifndef LAUNCHERBACKEND_H
339+#define LAUNCHERBACKEND_H
340+
341+#include "common/quicklistentry.h"
342+
343+#include <QObject>
344+#include <QStringList>
345+#include <QHash>
346+
347+/**
348+ * @brief An interface that provides all the data needed by the launcher.
349+ */
350+
351+class LauncherBackend : public QObject
352+{
353+ Q_OBJECT
354+
355+
356+public:
357+ LauncherBackend(QObject *parent = 0);
358+ virtual ~LauncherBackend();
359+
360+ /**
361+ * @brief Returns a list of stored applications.
362+ * @returns A list of application IDs.
363+ */
364+ QStringList storedApplications() const;
365+
366+ /**
367+ * @brief Set the list of stored applications.
368+ *
369+ * Any previously stored information for apps not contained
370+ * in the list any more, e.g. the pinned state, will be
371+ * discarded.
372+ *
373+ * @param appIds The new list of stored applications.
374+ */
375+ void setStoredApplications(const QStringList &appIds);
376+
377+ /**
378+ * @brief Get the full path to the .desktop file.
379+ * @returns The full path to the .dekstop file.
380+ */
381+ QString desktopFile(const QString &appId) const;
382+
383+ /**
384+ * @brief Get the user friendly name of an application.
385+ * @param appId The ID of the application.
386+ * @returns The user friendly name of the application.
387+ */
388+ QString displayName(const QString &appId) const;
389+
390+ /**
391+ * @brief Get the icon of an application.
392+ * @param appId The ID of the application.
393+ * @returns The full path to the icon for the application.
394+ */
395+ QString icon(const QString &appId) const;
396+
397+ /**
398+ * @brief Is the app manually pinned?
399+ * @returns true if pinned, otherwise false.
400+ */
401+ bool isPinned(const QString &appId) const;
402+
403+ /**
404+ * @brief Change the pinned state of an application.
405+ * @param appId The application where the pinned flag should be set.
406+ * @param pinned true if pinned, otherwise false.
407+ */
408+ void setPinned(const QString &appId, bool pinned);
409+
410+ //TODO: Fill in getters for all the other things needed from the .desktop file.
411+
412+ /**
413+ * @brief Get the QuickList for an application.
414+ * @param appId The ID of the application.
415+ * @returns A QuickListModelInterface containing the QuickList.
416+ */
417+ QList<QuickListEntry> quickList(const QString &appId) const;
418+
419+ /**
420+ * @brief Execute an action from the quickList
421+ * @param appId The app ID for which the action was triggered
422+ * @param the quicklist ID of the action that was triggered
423+ */
424+ void triggerQuickListAction(const QString &appId, const QString &entryId);
425+
426+ /**
427+ * @brief Get the progress for the progress overlay of an application.
428+ * @param appId The ID of the application.
429+ * @returns The percentage of the overlay progress bar. -1 if no progress bar available.
430+ */
431+ int progress(const QString &appId) const;
432+
433+ /**
434+ * @brief Get the count of the count overlay of an application.
435+ * @param appId The ID of the application.
436+ * @returns The number to be displayed in the overlay. -1 if no count overlay is available.
437+ */
438+ int count(const QString &appId) const;
439+
440+Q_SIGNALS:
441+ void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
442+ void progressChanged(const QString &appId, int progress);
443+ void countChanged(const QString &appId, int count);
444+
445+private:
446+ QStringList m_storedApps;
447+ QHash<QString, QString> m_displayNameMap;
448+ QHash<QString, QString> m_iconMap;
449+};
450+
451+#endif // LAUNCHERBACKEND_H
452
453=== added directory 'plugins/Unity/Launcher/common'
454=== added file 'plugins/Unity/Launcher/common/quicklistentry.cpp'
455--- plugins/Unity/Launcher/common/quicklistentry.cpp 1970-01-01 00:00:00 +0000
456+++ plugins/Unity/Launcher/common/quicklistentry.cpp 2013-07-10 17:15:31 +0000
457@@ -0,0 +1,54 @@
458+/* Copyright (C) 2013 Canonical, Ltd.
459+ *
460+ * Authors:
461+ * Michael Zanetti <michael.zanetti@canonical.com>
462+ *
463+ * This program is free software; you can redistribute it and/or modify
464+ * it under the terms of the GNU General Public License as published by
465+ * the Free Software Foundation; version 3.
466+ *
467+ * This program is distributed in the hope that it will be useful,
468+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
469+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
470+ * GNU General Public License for more details.
471+ *
472+ * You should have received a copy of the GNU General Public License
473+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
474+ */
475+
476+#include "quicklistentry.h"
477+
478+QuickListEntry::QuickListEntry()
479+{
480+
481+}
482+
483+QString QuickListEntry::actionId() const
484+{
485+ return m_actionId;
486+}
487+
488+void QuickListEntry::setActionId(const QString &actionId)
489+{
490+ m_actionId = actionId;
491+}
492+
493+QString QuickListEntry::text() const
494+{
495+ return m_text;
496+}
497+
498+void QuickListEntry::setText(const QString &text)
499+{
500+ m_text = text;
501+}
502+
503+QString QuickListEntry::icon() const
504+{
505+ return m_icon;
506+}
507+
508+void QuickListEntry::setIcon(const QString &icon)
509+{
510+ m_icon = icon;
511+}
512
513=== added file 'plugins/Unity/Launcher/common/quicklistentry.h'
514--- plugins/Unity/Launcher/common/quicklistentry.h 1970-01-01 00:00:00 +0000
515+++ plugins/Unity/Launcher/common/quicklistentry.h 2013-07-10 17:15:31 +0000
516@@ -0,0 +1,44 @@
517+/* Copyright (C) 2013 Canonical, Ltd.
518+ *
519+ * Authors:
520+ * Michael Zanetti <michael.zanetti@canonical.com>
521+ *
522+ * This program is free software; you can redistribute it and/or modify
523+ * it under the terms of the GNU General Public License as published by
524+ * the Free Software Foundation; version 3.
525+ *
526+ * This program is distributed in the hope that it will be useful,
527+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
528+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
529+ * GNU General Public License for more details.
530+ *
531+ * You should have received a copy of the GNU General Public License
532+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
533+ */
534+
535+#ifndef QUICKLISTENTRY_H
536+#define QUICKLISTENTRY_H
537+
538+#include <QString>
539+
540+class QuickListEntry
541+{
542+public:
543+ QuickListEntry();
544+
545+ QString actionId() const;
546+ void setActionId(const QString &actionId);
547+
548+ QString text() const;
549+ void setText(const QString &text);
550+
551+ QString icon() const;
552+ void setIcon(const QString &icon);
553+
554+private:
555+ QString m_actionId;
556+ QString m_text;
557+ QString m_icon;
558+};
559+
560+#endif // QUICKLISTENTRY
561
562=== added file 'plugins/Unity/Launcher/launcheritem.cpp'
563--- plugins/Unity/Launcher/launcheritem.cpp 1970-01-01 00:00:00 +0000
564+++ plugins/Unity/Launcher/launcheritem.cpp 2013-07-10 17:15:31 +0000
565@@ -0,0 +1,127 @@
566+/*
567+ * Copyright 2013 Canonical Ltd.
568+ *
569+ * This program is free software; you can redistribute it and/or modify
570+ * it under the terms of the GNU Lesser General Public License as published by
571+ * the Free Software Foundation; version 3.
572+ *
573+ * This program is distributed in the hope that it will be useful,
574+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
575+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
576+ * GNU Lesser General Public License for more details.
577+ *
578+ * You should have received a copy of the GNU Lesser General Public License
579+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
580+ *
581+ * Authors:
582+ * Michael Zanetti <michael.zanetti@canonical.com>
583+ */
584+
585+#include "launcheritem.h"
586+#include "quicklistmodel.h"
587+
588+LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent) :
589+ LauncherItemInterface(parent),
590+ m_appId(appId),
591+ m_desktopFile(desktopFile),
592+ m_name(name),
593+ m_icon(icon),
594+ m_pinned(false),
595+ m_running(false),
596+ m_recent(false),
597+ m_progress(-1),
598+ m_count(0),
599+ m_quickList(new QuickListModel(this))
600+{
601+
602+}
603+
604+QString LauncherItem::appId() const
605+{
606+ return m_appId;
607+}
608+
609+QString LauncherItem::desktopFile() const
610+{
611+ return m_desktopFile;
612+}
613+
614+QString LauncherItem::name() const
615+{
616+ return m_name;
617+}
618+
619+QString LauncherItem::icon() const
620+{
621+ return m_icon;
622+}
623+
624+bool LauncherItem::pinned() const
625+{
626+ return m_pinned;
627+}
628+
629+void LauncherItem::setPinned(bool pinned)
630+{
631+ if (m_pinned != pinned) {
632+ m_pinned = pinned;
633+ Q_EMIT pinnedChanged(pinned);
634+ }
635+}
636+
637+bool LauncherItem::running() const
638+{
639+ return m_running;
640+}
641+
642+void LauncherItem::setRunning(bool running)
643+{
644+ if (m_running != running) {
645+ m_running = running;
646+ Q_EMIT runningChanged(running);
647+ }
648+}
649+
650+bool LauncherItem::recent() const
651+{
652+ return m_recent;
653+}
654+
655+void LauncherItem::setRecent(bool recent)
656+{
657+ if (m_recent != recent) {
658+ m_recent = recent;
659+ Q_EMIT recentChanged(recent);
660+ }
661+}
662+
663+int LauncherItem::progress() const
664+{
665+ return m_progress;
666+}
667+
668+void LauncherItem::setProgress(int progress)
669+{
670+ if (m_progress != progress) {
671+ m_progress = progress;
672+ Q_EMIT progressChanged(progress);
673+ }
674+}
675+
676+int LauncherItem::count() const
677+{
678+ return m_count;
679+}
680+
681+void LauncherItem::setCount(int count)
682+{
683+ if (m_count != count) {
684+ m_count = count;
685+ Q_EMIT countChanged(count);
686+ }
687+}
688+
689+unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
690+{
691+ return m_quickList;
692+}
693
694=== added file 'plugins/Unity/Launcher/launcheritem.h'
695--- plugins/Unity/Launcher/launcheritem.h 1970-01-01 00:00:00 +0000
696+++ plugins/Unity/Launcher/launcheritem.h 2013-07-10 17:15:31 +0000
697@@ -0,0 +1,76 @@
698+/*
699+ * Copyright 2013 Canonical Ltd.
700+ *
701+ * This program is free software; you can redistribute it and/or modify
702+ * it under the terms of the GNU Lesser General Public License as published by
703+ * the Free Software Foundation; version 3.
704+ *
705+ * This program is distributed in the hope that it will be useful,
706+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
707+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
708+ * GNU Lesser General Public License for more details.
709+ *
710+ * You should have received a copy of the GNU Lesser General Public License
711+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
712+ *
713+ * Authors:
714+ * Michael Zanetti <michael.zanetti@canonical.com>
715+ */
716+
717+#ifndef LAUNCHERITEM_H
718+#define LAUNCHERITEM_H
719+
720+#include "quicklistmodel.h"
721+
722+#include <unity/shell/launcher/LauncherItemInterface.h>
723+
724+class QuickListModel;
725+
726+using namespace unity::shell::launcher;
727+
728+class LauncherItem: public LauncherItemInterface
729+{
730+ Q_OBJECT
731+public:
732+ LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
733+
734+ QString appId() const;
735+ QString desktopFile() const;
736+ QString name() const;
737+ QString icon() const;
738+
739+ bool pinned() const;
740+ void setPinned(bool pinned);
741+
742+ bool running() const;
743+ void setRunning(bool running);
744+
745+ bool recent() const;
746+ void setRecent(bool recent);
747+
748+ int progress() const;
749+ void setProgress(int progress);
750+
751+ int count() const;
752+ void setCount(int count);
753+
754+ unity::shell::launcher::QuickListModelInterface *quickList() const;
755+
756+Q_SIGNALS:
757+ void favoriteChanged(bool favorite);
758+ void runningChanged(bool running);
759+
760+private:
761+ QString m_appId;
762+ QString m_desktopFile;
763+ QString m_name;
764+ QString m_icon;
765+ bool m_pinned;
766+ bool m_running;
767+ bool m_recent;
768+ int m_progress;
769+ int m_count;
770+ QuickListModel *m_quickList;
771+};
772+
773+#endif // LAUNCHERITEM_H
774
775=== added file 'plugins/Unity/Launcher/launchermodel.cpp'
776--- plugins/Unity/Launcher/launchermodel.cpp 1970-01-01 00:00:00 +0000
777+++ plugins/Unity/Launcher/launchermodel.cpp 2013-07-10 17:15:31 +0000
778@@ -0,0 +1,170 @@
779+/*
780+ * Copyright 2013 Canonical Ltd.
781+ *
782+ * This program is free software; you can redistribute it and/or modify
783+ * it under the terms of the GNU Lesser General Public License as published by
784+ * the Free Software Foundation; version 3.
785+ *
786+ * This program is distributed in the hope that it will be useful,
787+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
788+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
789+ * GNU Lesser General Public License for more details.
790+ *
791+ * You should have received a copy of the GNU Lesser General Public License
792+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
793+ *
794+ * Authors:
795+ * Michael Zanetti <michael.zanetti@canonical.com>
796+ */
797+
798+#include "launchermodel.h"
799+#include "launcheritem.h"
800+#include "backend/launcherbackend.h"
801+
802+LauncherModel::LauncherModel(QObject *parent):
803+ LauncherModelInterface(parent),
804+ m_backend(new LauncherBackend(this))
805+{
806+ Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
807+ LauncherItem *item = new LauncherItem(entry,
808+ m_backend->desktopFile(entry),
809+ m_backend->displayName(entry),
810+ m_backend->icon(entry),
811+ this);
812+ if (m_backend->isPinned(entry)) {
813+ item->setPinned(true);
814+ } else {
815+ item->setRecent(true);
816+ }
817+ m_list.append(item);
818+ }
819+}
820+
821+LauncherModel::~LauncherModel()
822+{
823+ while (!m_list.empty()) {
824+ m_list.takeFirst()->deleteLater();
825+ }
826+}
827+
828+int LauncherModel::rowCount(const QModelIndex &parent) const
829+{
830+ Q_UNUSED(parent)
831+ return m_list.count();
832+}
833+
834+QVariant LauncherModel::data(const QModelIndex &index, int role) const
835+{
836+ LauncherItem *item = m_list.at(index.row());
837+ switch(role) {
838+ case RoleAppId:
839+ return item->desktopFile();
840+ case RoleDesktopFile:
841+ return item->desktopFile();
842+ case RoleName:
843+ return item->name();
844+ case RoleIcon:
845+ return item->icon();
846+ case RolePinned:
847+ return item->pinned();
848+ }
849+
850+ return QVariant();
851+}
852+
853+unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
854+{
855+ if (index < 0 || index >= m_list.count()) {
856+ return 0;
857+ }
858+ return m_list.at(index);
859+}
860+
861+void LauncherModel::move(int oldIndex, int newIndex)
862+{
863+ // Perform the move in our list
864+ beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
865+ m_list.move(oldIndex, newIndex);
866+ endMoveRows();
867+
868+ storeAppList();
869+
870+ pin(m_list.at(newIndex)->appId());
871+}
872+
873+void LauncherModel::pin(const QString &appId, int index)
874+{
875+ int currentIndex = findApplication(appId);
876+
877+ if (currentIndex >= 0) {
878+ if (index == -1 || index == currentIndex) {
879+ m_list.at(currentIndex)->setPinned(true);
880+ QModelIndex modelIndex = this->index(currentIndex);
881+ Q_EMIT dataChanged(modelIndex, modelIndex);
882+ } else {
883+ move(currentIndex, index);
884+ }
885+ } else {
886+ if (index == -1) {
887+ index = m_list.count();
888+ }
889+ beginInsertRows(QModelIndex(), index, index);
890+ LauncherItem *item = new LauncherItem(appId,
891+ m_backend->desktopFile(appId),
892+ m_backend->displayName(appId),
893+ m_backend->icon(appId));
894+ item->setPinned(true);
895+ m_list.insert(index, item);
896+ endInsertRows();
897+ }
898+}
899+
900+void LauncherModel::requestRemove(const QString &appId)
901+{
902+ int index = findApplication(appId);
903+ if (index < 0) {
904+ return;
905+ }
906+
907+ beginRemoveRows(QModelIndex(), index, index);
908+ m_list.takeAt(index)->deleteLater();
909+ endRemoveRows();
910+
911+ storeAppList();
912+}
913+
914+void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
915+{
916+ int index = findApplication(appId);
917+ if (index < 0) {
918+ return;
919+ }
920+
921+ QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(index)->quickList());
922+ if (model) {
923+ QString actionId = model->get(actionIndex).actionId();
924+ m_backend->triggerQuickListAction(appId, actionId);
925+ }
926+}
927+
928+void LauncherModel::storeAppList()
929+{
930+ QStringList appIds;
931+ Q_FOREACH(LauncherItem *item, m_list) {
932+ if (item->pinned() || item->recent()) {
933+ appIds << item->appId();
934+ }
935+ }
936+ m_backend->setStoredApplications(appIds);
937+}
938+
939+int LauncherModel::findApplication(const QString &appId)
940+{
941+ for (int i = 0; i < m_list.count(); ++i) {
942+ LauncherItem *item = m_list.at(i);
943+ if (item->appId() == appId) {
944+ return i;
945+ }
946+ }
947+ return -1;
948+}
949
950=== added file 'plugins/Unity/Launcher/launchermodel.h'
951--- plugins/Unity/Launcher/launchermodel.h 1970-01-01 00:00:00 +0000
952+++ plugins/Unity/Launcher/launchermodel.h 2013-07-10 17:15:31 +0000
953@@ -0,0 +1,61 @@
954+/*
955+ * Copyright 2013 Canonical Ltd.
956+ *
957+ * This program is free software; you can redistribute it and/or modify
958+ * it under the terms of the GNU Lesser General Public License as published by
959+ * the Free Software Foundation; version 3.
960+ *
961+ * This program is distributed in the hope that it will be useful,
962+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
963+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
964+ * GNU Lesser General Public License for more details.
965+ *
966+ * You should have received a copy of the GNU Lesser General Public License
967+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
968+ *
969+ * Authors:
970+ * Michael Zanetti <michael.zanetti@canonical.com>
971+ */
972+
973+#ifndef LAUNCHERMODELH
974+#define LAUNCHERMODEL_H
975+
976+// unity-api
977+#include <unity/shell/launcher/LauncherModelInterface.h>
978+
979+// Qt
980+#include <QAbstractListModel>
981+
982+class LauncherItem;
983+class LauncherBackend;
984+
985+using namespace unity::shell::launcher;
986+
987+class LauncherModel: public LauncherModelInterface
988+{
989+ Q_OBJECT
990+
991+public:
992+ LauncherModel(QObject *parent = 0);
993+ ~LauncherModel();
994+
995+ int rowCount(const QModelIndex &parent) const;
996+
997+ QVariant data(const QModelIndex &index, int role) const;
998+
999+ Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
1000+ Q_INVOKABLE void move(int oldIndex, int newIndex);
1001+ Q_INVOKABLE void pin(const QString &appId, int index = -1);
1002+ Q_INVOKABLE void requestRemove(const QString &appId);
1003+ Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
1004+
1005+private:
1006+ void storeAppList();
1007+ int findApplication(const QString &appId);
1008+
1009+private:
1010+ QList<LauncherItem*> m_list;
1011+ LauncherBackend *m_backend;
1012+};
1013+
1014+#endif // LAUNCHERMODEL_H
1015
1016=== added file 'plugins/Unity/Launcher/plugin.cpp'
1017--- plugins/Unity/Launcher/plugin.cpp 1970-01-01 00:00:00 +0000
1018+++ plugins/Unity/Launcher/plugin.cpp 2013-07-10 17:15:31 +0000
1019@@ -0,0 +1,47 @@
1020+/*
1021+ * Copyright 2013 Canonical Ltd.
1022+ *
1023+ * This program is free software; you can redistribute it and/or modify
1024+ * it under the terms of the GNU Lesser General Public License as published by
1025+ * the Free Software Foundation; version 3.
1026+ *
1027+ * This program is distributed in the hope that it will be useful,
1028+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1029+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1030+ * GNU Lesser General Public License for more details.
1031+ *
1032+ * You should have received a copy of the GNU Lesser General Public License
1033+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1034+ *
1035+ * Authors:
1036+ * Michael Zanetti <michael.zanetti@canonical.com>
1037+ */
1038+
1039+// Qt
1040+#include <QtQml>
1041+
1042+// self
1043+#include "plugin.h"
1044+
1045+// local
1046+#include "launchermodel.h"
1047+#include "launcheritem.h"
1048+
1049+
1050+using namespace unity::shell::launcher;
1051+
1052+static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
1053+{
1054+ return new LauncherModel();
1055+}
1056+
1057+void UnityLauncherPlugin::registerTypes(const char *uri)
1058+{
1059+ Q_ASSERT(uri == QLatin1String("Unity.Launcher"));
1060+
1061+ qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
1062+ qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
1063+
1064+ qmlRegisterSingletonType<LauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
1065+ qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
1066+}
1067
1068=== added file 'plugins/Unity/Launcher/plugin.h'
1069--- plugins/Unity/Launcher/plugin.h 1970-01-01 00:00:00 +0000
1070+++ plugins/Unity/Launcher/plugin.h 2013-07-10 17:15:31 +0000
1071@@ -0,0 +1,34 @@
1072+/*
1073+ * Copyright (C) 2013 Canonical, Ltd.
1074+ *
1075+ * This program is free software; you can redistribute it and/or modify
1076+ * it under the terms of the GNU General Public License as published by
1077+ * the Free Software Foundation; version 3.
1078+ *
1079+ * This program is distributed in the hope that it will be useful,
1080+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1081+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1082+ * GNU General Public License for more details.
1083+ *
1084+ * You should have received a copy of the GNU General Public License
1085+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1086+ *
1087+ * Author: Michael Zanetti <michael.zanetti@canonical.com>
1088+ */
1089+
1090+#ifndef UNITY_LAUNCHER_PLUGIN_H
1091+#define UNITY_LAUNCHER_PLUGIN_H
1092+
1093+#include <QtQml/QQmlEngine>
1094+#include <QtQml/QQmlExtensionPlugin>
1095+
1096+class UnityLauncherPlugin : public QQmlExtensionPlugin
1097+{
1098+ Q_OBJECT
1099+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
1100+
1101+public:
1102+ void registerTypes(const char *uri);
1103+};
1104+
1105+#endif
1106
1107=== added file 'plugins/Unity/Launcher/qmldir'
1108--- plugins/Unity/Launcher/qmldir 1970-01-01 00:00:00 +0000
1109+++ plugins/Unity/Launcher/qmldir 2013-07-10 17:15:31 +0000
1110@@ -0,0 +1,2 @@
1111+module Unity.Launcher
1112+plugin UnityLauncher-qml
1113
1114=== added file 'plugins/Unity/Launcher/quicklistmodel.cpp'
1115--- plugins/Unity/Launcher/quicklistmodel.cpp 1970-01-01 00:00:00 +0000
1116+++ plugins/Unity/Launcher/quicklistmodel.cpp 2013-07-10 17:15:31 +0000
1117@@ -0,0 +1,60 @@
1118+/*
1119+ * Copyright 2013 Canonical Ltd.
1120+ *
1121+ * This program is free software; you can redistribute it and/or modify
1122+ * it under the terms of the GNU Lesser General Public License as published by
1123+ * the Free Software Foundation; version 3.
1124+ *
1125+ * This program is distributed in the hope that it will be useful,
1126+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1127+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1128+ * GNU Lesser General Public License for more details.
1129+ *
1130+ * You should have received a copy of the GNU Lesser General Public License
1131+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1132+ *
1133+ * Authors:
1134+ * Michael Zanetti <michael.zanetti@canonical.com>
1135+ */
1136+
1137+#include "quicklistmodel.h"
1138+
1139+QuickListModel::QuickListModel(QObject *parent) :
1140+ QuickListModelInterface(parent)
1141+{
1142+
1143+}
1144+
1145+QuickListModel::~QuickListModel()
1146+{
1147+
1148+}
1149+
1150+void QuickListModel::appendAction(const QuickListEntry &entry)
1151+{
1152+ beginInsertRows(QModelIndex(), m_list.count() - 1, m_list.count() -1);
1153+ m_list.append(entry);
1154+ endInsertRows();
1155+}
1156+
1157+QuickListEntry QuickListModel::get(int index) const
1158+{
1159+ return m_list.at(index);
1160+}
1161+
1162+int QuickListModel::rowCount(const QModelIndex &index) const
1163+{
1164+ Q_UNUSED(index)
1165+ return m_list.count();
1166+}
1167+
1168+QVariant QuickListModel::data(const QModelIndex &index, int role) const
1169+{
1170+ switch (role) {
1171+ case RoleLabel:
1172+ return m_list.at(index.row()).text();
1173+ case RoleIcon:
1174+ return m_list.at(index.row()).icon();
1175+ }
1176+ return QVariant();
1177+}
1178
1179=== added file 'plugins/Unity/Launcher/quicklistmodel.h'
1180--- plugins/Unity/Launcher/quicklistmodel.h 1970-01-01 00:00:00 +0000
1181+++ plugins/Unity/Launcher/quicklistmodel.h 2013-07-10 17:15:31 +0000
1182@@ -0,0 +1,48 @@
1183+/*
1184+ * Copyright 2013 Canonical Ltd.
1185+ *
1186+ * This program is free software; you can redistribute it and/or modify
1187+ * it under the terms of the GNU Lesser General Public License as published by
1188+ * the Free Software Foundation; version 3.
1189+ *
1190+ * This program is distributed in the hope that it will be useful,
1191+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1192+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1193+ * GNU Lesser General Public License for more details.
1194+ *
1195+ * You should have received a copy of the GNU Lesser General Public License
1196+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1197+ *
1198+ * Authors:
1199+ * Michael Zanetti <michael.zanetti@canonical.com>
1200+ */
1201+
1202+#ifndef QUICKLISTMODEL_H
1203+#define QUICKLISTMODEL_H
1204+
1205+#include "common/quicklistentry.h"
1206+
1207+#include <unity/shell/launcher/QuickListModelInterface.h>
1208+
1209+using namespace unity::shell::launcher;
1210+
1211+class QuickListModel: public QuickListModelInterface
1212+{
1213+ Q_OBJECT
1214+
1215+public:
1216+ explicit QuickListModel(QObject *parent = 0);
1217+
1218+ ~QuickListModel();
1219+
1220+ void appendAction(const QuickListEntry &entry);
1221+ QuickListEntry get(int index) const;
1222+
1223+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
1224+ QVariant data(const QModelIndex &index, int role) const;
1225+
1226+private:
1227+ QList<QuickListEntry> m_list;
1228+};
1229+
1230+#endif // QUICKLISTMODEL_H
1231
1232=== removed file 'plugins/Unity/launchermodel.cpp'
1233--- plugins/Unity/launchermodel.cpp 2013-06-05 22:03:08 +0000
1234+++ plugins/Unity/launchermodel.cpp 1970-01-01 00:00:00 +0000
1235@@ -1,153 +0,0 @@
1236-/*
1237- * Copyright (C) 2011 Canonical, Ltd.
1238- *
1239- * Authors:
1240- * Michael Zanetti <michael.zanetti@canonical.com>
1241- *
1242- * This program is free software; you can redistribute it and/or modify
1243- * it under the terms of the GNU General Public License as published by
1244- * the Free Software Foundation; version 3.
1245- *
1246- * This program is distributed in the hope that it will be useful,
1247- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1248- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1249- * GNU General Public License for more details.
1250- *
1251- * You should have received a copy of the GNU General Public License
1252- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1253- */
1254-
1255-#include "launchermodel.h"
1256-
1257-LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
1258-{
1259- // FIXME: Dummy data... Aggregate real data from backends
1260-
1261- // Fake favorites
1262- LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
1263- m_list.append(item);
1264- item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
1265- m_list.append(item);
1266- item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
1267- m_list.append(item);
1268- item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
1269- m_list.append(item);
1270- item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
1271- m_list.append(item);
1272- item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
1273- m_list.append(item);
1274- item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
1275- m_list.append(item);
1276- item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
1277- m_list.append(item);
1278- item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
1279- m_list.append(item);
1280- item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
1281- m_list.append(item);
1282-}
1283-
1284-LauncherModel::~LauncherModel()
1285-{
1286- while (!m_list.empty()) {
1287- m_list.takeFirst()->deleteLater();
1288- }
1289-}
1290-
1291-int LauncherModel::rowCount(const QModelIndex &parent) const
1292-{
1293- Q_UNUSED(parent)
1294- return m_list.count();
1295-}
1296-
1297-QVariant LauncherModel::data(const QModelIndex &index, int role) const
1298-{
1299- LauncherItem *item = m_list.at(index.row());
1300- switch(role) {
1301- case RoleName:
1302- return item->name();
1303- case RoleIcon:
1304- return item->icon();
1305- case RoleFavorite:
1306- return item->favorite();
1307- }
1308-
1309- return QVariant();
1310-}
1311-
1312-LauncherItem *LauncherModel::get(int index) const
1313-{
1314- if (index < 0 || index >= m_list.count()) {
1315- return 0;
1316- }
1317- return m_list.at(index);
1318-}
1319-
1320-void LauncherModel::move(int oldIndex, int newIndex)
1321-{
1322- beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
1323- m_list.move(oldIndex, newIndex);
1324- endMoveRows();
1325-}
1326-
1327-QHash<int, QByteArray> LauncherModel::roleNames() const
1328-{
1329- QHash<int, QByteArray> roles;
1330- roles.insert(RoleDesktopFile, "desktopFile");
1331- roles.insert(RoleName, "name");
1332- roles.insert(RoleIcon, "icon");
1333- roles.insert(RoleFavorite, "favorite");
1334- roles.insert(RoleRunning, "runnng");
1335- return roles;
1336-}
1337-
1338-
1339-LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
1340- QObject(parent),
1341- m_desktopFile(desktopFile),
1342- m_name(name),
1343- m_icon(icon),
1344- m_favorite(false)
1345-{
1346-
1347-}
1348-
1349-QString LauncherItem::desktopFile() const
1350-{
1351- return m_desktopFile;
1352-}
1353-
1354-QString LauncherItem::name() const
1355-{
1356- return m_name;
1357-}
1358-
1359-QString LauncherItem::icon() const
1360-{
1361- return m_icon;
1362-}
1363-
1364-bool LauncherItem::favorite() const
1365-{
1366- return m_favorite;
1367-}
1368-
1369-void LauncherItem::setFavorite(bool favorite)
1370-{
1371- if (m_favorite != favorite) {
1372- m_favorite = favorite;
1373- Q_EMIT favoriteChanged(m_favorite);
1374- }
1375-}
1376-
1377-bool LauncherItem::running() const
1378-{
1379- return m_running;
1380-}
1381-
1382-void LauncherItem::setRunning(bool running)
1383-{
1384- if (m_running != running) {
1385- m_running = running;
1386- Q_EMIT runningChanged(running);
1387- }
1388-}
1389
1390=== removed file 'plugins/Unity/launchermodel.h'
1391--- plugins/Unity/launchermodel.h 2013-06-05 22:03:08 +0000
1392+++ plugins/Unity/launchermodel.h 1970-01-01 00:00:00 +0000
1393@@ -1,86 +0,0 @@
1394-/*
1395- * Copyright (C) 2011 Canonical, Ltd.
1396- *
1397- * Authors:
1398- * Michael Zanetti <michael.zanetti@canonical.com>
1399- *
1400- * This program is free software; you can redistribute it and/or modify
1401- * it under the terms of the GNU General Public License as published by
1402- * the Free Software Foundation; version 3.
1403- *
1404- * This program is distributed in the hope that it will be useful,
1405- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1406- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1407- * GNU General Public License for more details.
1408- *
1409- * You should have received a copy of the GNU General Public License
1410- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1411- */
1412-
1413-#include <QAbstractListModel>
1414-
1415-class LauncherItem;
1416-
1417-class LauncherModel: public QAbstractListModel
1418-{
1419- Q_OBJECT
1420-
1421-public:
1422- enum Roles {
1423- RoleDesktopFile = Qt::UserRole,
1424- RoleName,
1425- RoleIcon,
1426- RoleFavorite,
1427- RoleRunning
1428- };
1429-
1430- LauncherModel(QObject *parent = 0);
1431- ~LauncherModel();
1432-
1433- int rowCount(const QModelIndex &parent) const;
1434-
1435- QVariant data(const QModelIndex &index, int role) const;
1436-
1437- Q_INVOKABLE LauncherItem* get(int index) const;
1438- Q_INVOKABLE void move(int oldIndex, int newIndex);
1439-
1440- QHash<int, QByteArray> roleNames() const;
1441-
1442-private:
1443- QList<LauncherItem*> m_list;
1444-};
1445-
1446-class LauncherItem: public QObject
1447-{
1448- Q_OBJECT
1449- Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
1450- Q_PROPERTY(QString name READ name CONSTANT)
1451- Q_PROPERTY(QString icon READ icon CONSTANT)
1452- Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged)
1453- Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
1454-
1455-public:
1456- LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
1457-
1458- QString desktopFile() const;
1459-
1460- QString name() const;
1461- QString icon() const;
1462-
1463- bool favorite() const;
1464- void setFavorite(bool favorite);
1465-
1466- bool running() const;
1467- void setRunning(bool running);
1468-
1469-Q_SIGNALS:
1470- void favoriteChanged(bool favorite);
1471- void runningChanged(bool running);
1472-
1473-private:
1474- QString m_desktopFile;
1475- QString m_name;
1476- QString m_icon;
1477- bool m_favorite;
1478- bool m_running;
1479-};
1480
1481=== modified file 'plugins/Unity/plugin.cpp'
1482--- plugins/Unity/plugin.cpp 2013-07-09 14:01:59 +0000
1483+++ plugins/Unity/plugin.cpp 2013-07-10 17:15:31 +0000
1484@@ -33,7 +33,6 @@
1485 #include "categories.h"
1486 #include "categoryresults.h"
1487 #include "bottombarvisibilitycommunicatorshell.h"
1488-#include "launchermodel.h"
1489
1490 // libqtdee
1491 #include "deelistmodel.h"
1492@@ -53,8 +52,6 @@
1493 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
1494 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
1495 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
1496- qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
1497- qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
1498 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
1499 }
1500
1501
1502=== modified file 'tests/mocks/Unity/CMakeLists.txt'
1503--- tests/mocks/Unity/CMakeLists.txt 2013-06-28 17:59:31 +0000
1504+++ tests/mocks/Unity/CMakeLists.txt 2013-07-10 17:15:31 +0000
1505@@ -24,7 +24,6 @@
1506 fake_scopes.cpp
1507 fake_categories.cpp
1508 fake_unity_plugin.cpp
1509- fake_launchermodel.cpp
1510 )
1511
1512 add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
1513@@ -41,3 +40,5 @@
1514 file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
1515 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
1516 )
1517+
1518+add_subdirectory(Launcher)
1519
1520=== added directory 'tests/mocks/Unity/Launcher'
1521=== added file 'tests/mocks/Unity/Launcher/CMakeLists.txt'
1522--- tests/mocks/Unity/Launcher/CMakeLists.txt 1970-01-01 00:00:00 +0000
1523+++ tests/mocks/Unity/Launcher/CMakeLists.txt 2013-07-10 17:15:31 +0000
1524@@ -0,0 +1,26 @@
1525+include(FindPkgConfig)
1526+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
1527+
1528+include_directories(
1529+ ${CMAKE_CURRENT_SOURCE_DIR}
1530+)
1531+
1532+set(MockLauncherModel_SOURCES
1533+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
1534+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
1535+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
1536+ plugin.cpp
1537+ MockLauncherModel.cpp
1538+ MockLauncherItem.cpp
1539+ MockQuickListModel.cpp
1540+)
1541+
1542+add_library(MockLauncherPlugin MODULE ${MockLauncherModel_SOURCES})
1543+
1544+qt5_use_modules(MockLauncherPlugin Core Quick)
1545+
1546+# copy files into build directory for shadow builds
1547+add_custom_target(LauncherPluginQmlDirFile ALL
1548+ COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
1549+ DEPENDS qmldir
1550+)
1551
1552=== added file 'tests/mocks/Unity/Launcher/MockLauncherItem.cpp'
1553--- tests/mocks/Unity/Launcher/MockLauncherItem.cpp 1970-01-01 00:00:00 +0000
1554+++ tests/mocks/Unity/Launcher/MockLauncherItem.cpp 2013-07-10 17:15:31 +0000
1555@@ -0,0 +1,134 @@
1556+/*
1557+ * Copyright 2013 Canonical Ltd.
1558+ *
1559+ * This program is free software; you can redistribute it and/or modify
1560+ * it under the terms of the GNU Lesser General Public License as published by
1561+ * the Free Software Foundation; version 3.
1562+ *
1563+ * This program is distributed in the hope that it will be useful,
1564+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1565+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1566+ * GNU Lesser General Public License for more details.
1567+ *
1568+ * You should have received a copy of the GNU Lesser General Public License
1569+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1570+ *
1571+ * Authors:
1572+ * Michael Zanetti <michael.zanetti@canonical.com>
1573+ */
1574+
1575+#include "MockLauncherItem.h"
1576+#include "MockQuickListModel.h"
1577+
1578+using namespace unity::shell::launcher;
1579+
1580+MockLauncherItem::MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
1581+ LauncherItemInterface(parent),
1582+ m_appId(appId),
1583+ m_desktopFile(desktopFile),
1584+ m_name(name),
1585+ m_icon(icon),
1586+ m_pinned(false),
1587+ m_running(false),
1588+ m_recent(false),
1589+ m_progress(8),
1590+ m_count(8),
1591+ m_quickList(new MockQuickListModel(this))
1592+{
1593+
1594+}
1595+
1596+QString MockLauncherItem::appId() const
1597+{
1598+ return m_appId;
1599+}
1600+
1601+QString MockLauncherItem::desktopFile() const
1602+{
1603+ return m_desktopFile;
1604+}
1605+
1606+QString MockLauncherItem::name() const
1607+{
1608+ return m_name;
1609+}
1610+
1611+QString MockLauncherItem::icon() const
1612+{
1613+ return m_icon;
1614+}
1615+
1616+bool MockLauncherItem::pinned() const
1617+{
1618+ return m_pinned;
1619+}
1620+
1621+void MockLauncherItem::setPinned(bool pinned)
1622+{
1623+ if (m_pinned != pinned)
1624+ {
1625+ m_pinned = pinned;
1626+ Q_EMIT pinnedChanged(m_pinned);
1627+ }
1628+}
1629+
1630+bool MockLauncherItem::running() const
1631+{
1632+ return m_running;
1633+}
1634+
1635+void MockLauncherItem::setRunning(bool running)
1636+{
1637+ if (m_running != running)
1638+ {
1639+ m_running = running;
1640+ Q_EMIT runningChanged(running);
1641+ }
1642+}
1643+
1644+bool MockLauncherItem::recent() const
1645+{
1646+ return m_recent;
1647+}
1648+
1649+void MockLauncherItem::setRecent(bool recent)
1650+{
1651+ if (m_recent != recent)
1652+ {
1653+ m_recent = recent;
1654+ Q_EMIT recentChanged(recent);
1655+ }
1656+}
1657+
1658+int MockLauncherItem::progress() const
1659+{
1660+ return m_progress;
1661+}
1662+
1663+void MockLauncherItem::setProgress(int progress)
1664+{
1665+ if (m_progress != progress)
1666+ {
1667+ m_progress = progress;
1668+ Q_EMIT progressChanged(progress);
1669+ }
1670+}
1671+
1672+int MockLauncherItem::count() const
1673+{
1674+ return m_count;
1675+}
1676+
1677+void MockLauncherItem::setCount(int count)
1678+{
1679+ if (m_count != count)
1680+ {
1681+ m_count = count;
1682+ Q_EMIT countChanged(count);
1683+ }
1684+}
1685+
1686+unity::shell::launcher::QuickListModelInterface *MockLauncherItem::quickList() const
1687+{
1688+ return m_quickList;
1689+}
1690
1691=== added file 'tests/mocks/Unity/Launcher/MockLauncherItem.h'
1692--- tests/mocks/Unity/Launcher/MockLauncherItem.h 1970-01-01 00:00:00 +0000
1693+++ tests/mocks/Unity/Launcher/MockLauncherItem.h 2013-07-10 17:15:31 +0000
1694@@ -0,0 +1,70 @@
1695+/*
1696+ * Copyright 2013 Canonical Ltd.
1697+ *
1698+ * This program is free software; you can redistribute it and/or modify
1699+ * it under the terms of the GNU Lesser General Public License as published by
1700+ * the Free Software Foundation; version 3.
1701+ *
1702+ * This program is distributed in the hope that it will be useful,
1703+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1704+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1705+ * GNU Lesser General Public License for more details.
1706+ *
1707+ * You should have received a copy of the GNU Lesser General Public License
1708+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1709+ *
1710+ * Authors:
1711+ * Michael Zanetti <michael.zanetti@canonical.com>
1712+ */
1713+
1714+#ifndef MOCKLAUNCHERITEM_H
1715+#define MOCKLAUNCHERITEM_H
1716+
1717+#include <unity/shell/launcher/LauncherItemInterface.h>
1718+
1719+class MockQuickListModel;
1720+
1721+using namespace unity::shell::launcher;
1722+
1723+class MockLauncherItem: public LauncherItemInterface
1724+{
1725+ Q_OBJECT
1726+public:
1727+ MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
1728+
1729+ QString appId() const;
1730+ QString desktopFile() const;
1731+ QString name() const;
1732+ QString icon() const;
1733+
1734+ bool pinned() const;
1735+ void setPinned(bool pinned);
1736+
1737+ bool running() const;
1738+ void setRunning(bool running);
1739+
1740+ bool recent() const;
1741+ void setRecent(bool recent);
1742+
1743+ int progress() const;
1744+ void setProgress(int progress);
1745+
1746+ int count() const;
1747+ void setCount(int count);
1748+
1749+ unity::shell::launcher::QuickListModelInterface *quickList() const;
1750+
1751+private:
1752+ QString m_appId;
1753+ QString m_desktopFile;
1754+ QString m_name;
1755+ QString m_icon;
1756+ bool m_pinned;
1757+ bool m_running;
1758+ bool m_recent;
1759+ int m_progress;
1760+ int m_count;
1761+ MockQuickListModel *m_quickList;
1762+};
1763+
1764+#endif // MOCKLAUNCHERITEM_H
1765
1766=== added file 'tests/mocks/Unity/Launcher/MockLauncherModel.cpp'
1767--- tests/mocks/Unity/Launcher/MockLauncherModel.cpp 1970-01-01 00:00:00 +0000
1768+++ tests/mocks/Unity/Launcher/MockLauncherModel.cpp 2013-07-10 17:15:31 +0000
1769@@ -0,0 +1,152 @@
1770+/*
1771+ * Copyright 2013 Canonical Ltd.
1772+ *
1773+ * This program is free software; you can redistribute it and/or modify
1774+ * it under the terms of the GNU Lesser General Public License as published by
1775+ * the Free Software Foundation; version 3.
1776+ *
1777+ * This program is distributed in the hope that it will be useful,
1778+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1779+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1780+ * GNU Lesser General Public License for more details.
1781+ *
1782+ * You should have received a copy of the GNU Lesser General Public License
1783+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1784+ *
1785+ * Authors:
1786+ * Michael Zanetti <michael.zanetti@canonical.com>
1787+ */
1788+
1789+#include "MockLauncherModel.h"
1790+#include "MockLauncherItem.h"
1791+
1792+MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
1793+{
1794+ MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
1795+ m_list.append(item);
1796+ item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera");
1797+ m_list.append(item);
1798+ item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
1799+ m_list.append(item);
1800+ item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
1801+ m_list.append(item);
1802+ item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
1803+ m_list.append(item);
1804+ item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
1805+ m_list.append(item);
1806+ item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
1807+ m_list.append(item);
1808+ item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
1809+ m_list.append(item);
1810+ item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
1811+ m_list.append(item);
1812+ item = new MockLauncherItem("ubuntu-calendar-app", "/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
1813+ m_list.append(item);
1814+}
1815+
1816+MockLauncherModel::~MockLauncherModel()
1817+{
1818+ while (!m_list.empty())
1819+ {
1820+ m_list.takeFirst()->deleteLater();
1821+ }
1822+}
1823+
1824+int MockLauncherModel::rowCount(const QModelIndex& parent) const
1825+{
1826+ Q_UNUSED(parent)
1827+ return m_list.count();
1828+}
1829+
1830+QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
1831+{
1832+ LauncherItemInterface *item = m_list.at(index.row());
1833+ switch(role)
1834+ {
1835+ case RoleDesktopFile:
1836+ return item->desktopFile();
1837+ case RoleName:
1838+ return item->name();
1839+ case RoleIcon:
1840+ return item->icon();
1841+ case RolePinned:
1842+ return item->pinned();
1843+ case RoleRunning:
1844+ return item->running();
1845+ case RoleRecent:
1846+ return item->recent();
1847+ case RoleProgress:
1848+ return item->progress();
1849+ case RoleCount:
1850+ return item->count();
1851+ }
1852+
1853+ return QVariant();
1854+}
1855+
1856+unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
1857+{
1858+ if (index < 0 || index >= m_list.count())
1859+ {
1860+ return 0;
1861+ }
1862+ return m_list.at(index);
1863+}
1864+
1865+void MockLauncherModel::move(int oldIndex, int newIndex)
1866+{
1867+ beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
1868+ m_list.move(oldIndex, newIndex);
1869+ endMoveRows();
1870+}
1871+
1872+void MockLauncherModel::pin(const QString &appId, int index)
1873+{
1874+ int currentIndex = findApp(appId);
1875+
1876+ if (currentIndex >= 0) {
1877+ if (index == -1 || index == currentIndex) {
1878+ m_list.at(currentIndex)->setPinned(true);
1879+ QModelIndex modelIndex = this->index(currentIndex);
1880+ Q_EMIT dataChanged(modelIndex, modelIndex);
1881+ } else {
1882+ move(currentIndex, index);
1883+ }
1884+ } else {
1885+ beginInsertRows(QModelIndex(), index, index);
1886+ m_list.insert(index, new MockLauncherItem(appId,
1887+ appId + ".desktop",
1888+ appId,
1889+ appId + ".png"));
1890+ m_list.at(index)->setPinned(true);
1891+ endInsertRows();
1892+ }
1893+}
1894+
1895+void MockLauncherModel::requestRemove(const QString &appId)
1896+{
1897+ int index = findApp(appId);
1898+ if (index >= 0) {
1899+ beginRemoveRows(QModelIndex(), index, 0);
1900+ m_list.takeAt(index)->deleteLater();
1901+ endRemoveRows();
1902+ }
1903+}
1904+
1905+void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
1906+{
1907+ Q_UNUSED(appId)
1908+ Q_UNUSED(actionIndex)
1909+ // Nothing to mock yet...
1910+}
1911+
1912+int MockLauncherModel::findApp(const QString &appId)
1913+{
1914+ for (int i = 0; i < m_list.count(); ++i) {
1915+ MockLauncherItem *item = m_list.at(i);
1916+ if (item->appId() == appId) {
1917+ return i;
1918+ }
1919+ }
1920+ return -1;
1921+}
1922
1923=== added file 'tests/mocks/Unity/Launcher/MockLauncherModel.h'
1924--- tests/mocks/Unity/Launcher/MockLauncherModel.h 1970-01-01 00:00:00 +0000
1925+++ tests/mocks/Unity/Launcher/MockLauncherModel.h 2013-07-10 17:15:31 +0000
1926@@ -0,0 +1,54 @@
1927+/*
1928+ * Copyright 2013 Canonical Ltd.
1929+ *
1930+ * This program is free software; you can redistribute it and/or modify
1931+ * it under the terms of the GNU Lesser General Public License as published by
1932+ * the Free Software Foundation; version 3.
1933+ *
1934+ * This program is distributed in the hope that it will be useful,
1935+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1936+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1937+ * GNU Lesser General Public License for more details.
1938+ *
1939+ * You should have received a copy of the GNU Lesser General Public License
1940+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1941+ *
1942+ * Authors:
1943+ * Michael Zanetti <michael.zanetti@canonical.com>
1944+ */
1945+
1946+#ifndef MOCKLAUNCHERMODEL_H
1947+#define MOCKLAUNCHERMODEL_H
1948+
1949+#include <unity/shell/launcher/LauncherModelInterface.h>
1950+
1951+class MockLauncherItem;
1952+
1953+using namespace unity::shell::launcher;
1954+
1955+class MockLauncherModel: public LauncherModelInterface
1956+{
1957+ Q_OBJECT
1958+
1959+public:
1960+ MockLauncherModel(QObject* parent = 0);
1961+ ~MockLauncherModel();
1962+
1963+ int rowCount(const QModelIndex& parent) const;
1964+
1965+ QVariant data(const QModelIndex& index, int role) const;
1966+
1967+ Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
1968+ Q_INVOKABLE void move(int oldIndex, int newIndex);
1969+ Q_INVOKABLE void pin(const QString &appId, int index = -1);
1970+ Q_INVOKABLE void requestRemove(const QString &appId);
1971+ Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
1972+
1973+private:
1974+ int findApp(const QString &appId);
1975+
1976+private:
1977+ QList<MockLauncherItem*> m_list;
1978+};
1979+
1980+#endif // MOCKLAUNCHERMODEL_H
1981
1982=== added file 'tests/mocks/Unity/Launcher/MockQuickListModel.cpp'
1983--- tests/mocks/Unity/Launcher/MockQuickListModel.cpp 1970-01-01 00:00:00 +0000
1984+++ tests/mocks/Unity/Launcher/MockQuickListModel.cpp 2013-07-10 17:15:31 +0000
1985@@ -0,0 +1,46 @@
1986+/*
1987+ * Copyright 2013 Canonical Ltd.
1988+ *
1989+ * This program is free software; you can redistribute it and/or modify
1990+ * it under the terms of the GNU Lesser General Public License as published by
1991+ * the Free Software Foundation; version 3.
1992+ *
1993+ * This program is distributed in the hope that it will be useful,
1994+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1995+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1996+ * GNU Lesser General Public License for more details.
1997+ *
1998+ * You should have received a copy of the GNU Lesser General Public License
1999+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2000+ *
2001+ * Authors:
2002+ * Michael Zanetti <michael.zanetti@canonical.com>
2003+ */
2004+
2005+#include <MockQuickListModel.h>
2006+
2007+using namespace unity::shell::launcher;
2008+
2009+MockQuickListModel::MockQuickListModel(QObject *parent) :
2010+ QuickListModelInterface(parent)
2011+{
2012+
2013+}
2014+
2015+QVariant MockQuickListModel::data(const QModelIndex &index, int role) const
2016+{
2017+ switch (role)
2018+ {
2019+ case RoleLabel:
2020+ return QLatin1String("test menu entry ") + QString::number(index.row());
2021+ case RoleIcon:
2022+ return QLatin1String("copy.png");
2023+ }
2024+ return QVariant();
2025+}
2026+
2027+int MockQuickListModel::rowCount(const QModelIndex &parent) const
2028+{
2029+ Q_UNUSED(parent)
2030+ return 4;
2031+}
2032
2033=== added file 'tests/mocks/Unity/Launcher/MockQuickListModel.h'
2034--- tests/mocks/Unity/Launcher/MockQuickListModel.h 1970-01-01 00:00:00 +0000
2035+++ tests/mocks/Unity/Launcher/MockQuickListModel.h 2013-07-10 17:15:31 +0000
2036@@ -0,0 +1,38 @@
2037+/*
2038+ * Copyright 2013 Canonical Ltd.
2039+ *
2040+ * This program is free software; you can redistribute it and/or modify
2041+ * it under the terms of the GNU Lesser General Public License as published by
2042+ * the Free Software Foundation; version 3.
2043+ *
2044+ * This program is distributed in the hope that it will be useful,
2045+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2046+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2047+ * GNU Lesser General Public License for more details.
2048+ *
2049+ * You should have received a copy of the GNU Lesser General Public License
2050+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2051+ *
2052+ * Authors:
2053+ * Michael Zanetti <michael.zanetti@canonical.com>
2054+ */
2055+
2056+#ifndef MOCKQUICKLISTMODEL_H
2057+#define MOCKQUICKLISTMODEL_H
2058+
2059+#include <unity/shell/launcher/QuickListModelInterface.h>
2060+
2061+using namespace unity::shell::launcher;
2062+
2063+class MockQuickListModel: public QuickListModelInterface
2064+{
2065+ Q_OBJECT
2066+public:
2067+ MockQuickListModel(QObject *parent = 0);
2068+
2069+ QVariant data(const QModelIndex &index, int role) const;
2070+
2071+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
2072+};
2073+
2074+#endif // MOCKQUICKLISTMODEL_H
2075
2076=== added file 'tests/mocks/Unity/Launcher/plugin.cpp'
2077--- tests/mocks/Unity/Launcher/plugin.cpp 1970-01-01 00:00:00 +0000
2078+++ tests/mocks/Unity/Launcher/plugin.cpp 2013-07-10 17:15:31 +0000
2079@@ -0,0 +1,45 @@
2080+/*
2081+ * Copyright 2013 Canonical Ltd.
2082+ *
2083+ * This program is free software; you can redistribute it and/or modify
2084+ * it under the terms of the GNU Lesser General Public License as published by
2085+ * the Free Software Foundation; version 3.
2086+ *
2087+ * This program is distributed in the hope that it will be useful,
2088+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2089+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2090+ * GNU Lesser General Public License for more details.
2091+ *
2092+ * You should have received a copy of the GNU Lesser General Public License
2093+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2094+ *
2095+ * Authors:
2096+ * Michael Zanetti <michael.zanetti@canonical.com>
2097+ */
2098+
2099+#include "plugin.h"
2100+#include "MockLauncherModel.h"
2101+#include "MockLauncherItem.h"
2102+
2103+#include <unity/shell/launcher/LauncherModelInterface.h>
2104+#include <unity/shell/launcher/LauncherItemInterface.h>
2105+
2106+#include <QtQml/qqml.h>
2107+
2108+using namespace unity::shell::launcher;
2109+
2110+static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
2111+{
2112+ return new MockLauncherModel();
2113+}
2114+
2115+// cppcheck-suppress unusedFunction
2116+void TestLauncherPlugin::registerTypes(const char* uri)
2117+{
2118+ // @uri Unity.Launcher
2119+ qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
2120+ qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
2121+
2122+ qmlRegisterSingletonType<MockLauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
2123+ qmlRegisterUncreatableType<MockLauncherItem>(uri, 0, 1, "LauncherItem", "Can't create LauncherItems in QML. Get them from the LauncherModel");
2124+}
2125
2126=== added file 'tests/mocks/Unity/Launcher/plugin.h'
2127--- tests/mocks/Unity/Launcher/plugin.h 1970-01-01 00:00:00 +0000
2128+++ tests/mocks/Unity/Launcher/plugin.h 2013-07-10 17:15:31 +0000
2129@@ -0,0 +1,35 @@
2130+/*
2131+ * Copyright 2013 Canonical Ltd.
2132+ *
2133+ * This program is free software; you can redistribute it and/or modify
2134+ * it under the terms of the GNU Lesser General Public License as published by
2135+ * the Free Software Foundation; version 3.
2136+ *
2137+ * This program is distributed in the hope that it will be useful,
2138+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2139+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2140+ * GNU Lesser General Public License for more details.
2141+ *
2142+ * You should have received a copy of the GNU Lesser General Public License
2143+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2144+ *
2145+ * Authors:
2146+ * Michael Zanetti <michael.zanetti@canonical.com>
2147+ */
2148+
2149+
2150+#ifndef TESTLAUNCHER_PLUGIN_H
2151+#define TESTLAUNCHER_PLUGIN_H
2152+
2153+#include <QtQml/QQmlExtensionPlugin>
2154+
2155+class TestLauncherPlugin : public QQmlExtensionPlugin
2156+{
2157+ Q_OBJECT
2158+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
2159+
2160+public:
2161+ void registerTypes(const char* uri);
2162+};
2163+
2164+#endif // TESTLAUNCHER_PLUGIN_H
2165
2166=== added file 'tests/mocks/Unity/Launcher/qmldir'
2167--- tests/mocks/Unity/Launcher/qmldir 1970-01-01 00:00:00 +0000
2168+++ tests/mocks/Unity/Launcher/qmldir 2013-07-10 17:15:31 +0000
2169@@ -0,0 +1,2 @@
2170+module Unity.Launcher
2171+plugin MockLauncherPlugin
2172
2173=== removed file 'tests/mocks/Unity/fake_launchermodel.cpp'
2174--- tests/mocks/Unity/fake_launchermodel.cpp 2013-06-05 22:03:08 +0000
2175+++ tests/mocks/Unity/fake_launchermodel.cpp 1970-01-01 00:00:00 +0000
2176@@ -1,150 +0,0 @@
2177-/*
2178- * Copyright (C) 2011 Canonical, Ltd.
2179- *
2180- * Authors:
2181- * Michael Zanetti <michael.zanetti@canonical.com>
2182- *
2183- * This program is free software; you can redistribute it and/or modify
2184- * it under the terms of the GNU General Public License as published by
2185- * the Free Software Foundation; version 3.
2186- *
2187- * This program is distributed in the hope that it will be useful,
2188- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2189- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2190- * GNU General Public License for more details.
2191- *
2192- * You should have received a copy of the GNU General Public License
2193- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2194- */
2195-
2196-#include "launchermodel.h"
2197-
2198-LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
2199-{
2200- LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
2201- m_list.append(item);
2202- item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
2203- m_list.append(item);
2204- item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
2205- m_list.append(item);
2206- item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
2207- m_list.append(item);
2208- item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
2209- m_list.append(item);
2210- item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
2211- m_list.append(item);
2212- item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
2213- m_list.append(item);
2214- item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
2215- m_list.append(item);
2216- item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
2217- m_list.append(item);
2218- item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
2219- m_list.append(item);
2220-}
2221-
2222-LauncherModel::~LauncherModel()
2223-{
2224- while (!m_list.empty()) {
2225- m_list.takeFirst()->deleteLater();
2226- }
2227-}
2228-
2229-int LauncherModel::rowCount(const QModelIndex &parent) const
2230-{
2231- Q_UNUSED(parent)
2232- return m_list.count();
2233-}
2234-
2235-QVariant LauncherModel::data(const QModelIndex &index, int role) const
2236-{
2237- LauncherItem *item = m_list.at(index.row());
2238- switch(role) {
2239- case RoleName:
2240- return item->name();
2241- case RoleIcon:
2242- return item->icon();
2243- case RoleFavorite:
2244- return item->favorite();
2245- }
2246-
2247- return QVariant();
2248-}
2249-
2250-LauncherItem *LauncherModel::get(int index) const
2251-{
2252- if (index < 0 || index >= m_list.count()) {
2253- return 0;
2254- }
2255- return m_list.at(index);
2256-}
2257-
2258-void LauncherModel::move(int oldIndex, int newIndex)
2259-{
2260- beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
2261- m_list.move(oldIndex, newIndex);
2262- endMoveRows();
2263-}
2264-
2265-QHash<int, QByteArray> LauncherModel::roleNames() const
2266-{
2267- QHash<int, QByteArray> roles;
2268- roles.insert(RoleDesktopFile, "desktopFile");
2269- roles.insert(RoleName, "name");
2270- roles.insert(RoleIcon, "icon");
2271- roles.insert(RoleFavorite, "favorite");
2272- roles.insert(RoleRunning, "runnng");
2273- return roles;
2274-}
2275-
2276-
2277-LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
2278- QObject(parent),
2279- m_desktopFile(desktopFile),
2280- m_name(name),
2281- m_icon(icon),
2282- m_favorite(false)
2283-{
2284-
2285-}
2286-
2287-QString LauncherItem::desktopFile() const
2288-{
2289- return m_desktopFile;
2290-}
2291-
2292-QString LauncherItem::name() const
2293-{
2294- return m_name;
2295-}
2296-
2297-QString LauncherItem::icon() const
2298-{
2299- return m_icon;
2300-}
2301-
2302-bool LauncherItem::favorite() const
2303-{
2304- return m_favorite;
2305-}
2306-
2307-void LauncherItem::setFavorite(bool favorite)
2308-{
2309- if (m_favorite != favorite) {
2310- m_favorite = favorite;
2311- Q_EMIT favoriteChanged(m_favorite);
2312- }
2313-}
2314-
2315-bool LauncherItem::running() const
2316-{
2317- return m_running;
2318-}
2319-
2320-void LauncherItem::setRunning(bool running)
2321-{
2322- if (m_running != running) {
2323- m_running = running;
2324- Q_EMIT runningChanged(running);
2325- }
2326-}
2327
2328=== removed file 'tests/mocks/Unity/fake_launchermodel.h'
2329--- tests/mocks/Unity/fake_launchermodel.h 2013-06-05 22:03:08 +0000
2330+++ tests/mocks/Unity/fake_launchermodel.h 1970-01-01 00:00:00 +0000
2331@@ -1,86 +0,0 @@
2332-/*
2333- * Copyright (C) 2011 Canonical, Ltd.
2334- *
2335- * Authors:
2336- * Michael Zanetti <michael.zanetti@canonical.com>
2337- *
2338- * This program is free software; you can redistribute it and/or modify
2339- * it under the terms of the GNU General Public License as published by
2340- * the Free Software Foundation; version 3.
2341- *
2342- * This program is distributed in the hope that it will be useful,
2343- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2344- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2345- * GNU General Public License for more details.
2346- *
2347- * You should have received a copy of the GNU General Public License
2348- * along with this program. If not, see <http://www.gnu.org/licenses/>.
2349- */
2350-
2351-#include <QAbstractListModel>
2352-
2353-class LauncherItem;
2354-
2355-class LauncherModel: public QAbstractListModel
2356-{
2357- Q_OBJECT
2358-
2359-public:
2360- enum Roles {
2361- RoleDesktopFile = Qt::UserRole,
2362- RoleName,
2363- RoleIcon,
2364- RoleFavorite,
2365- RoleRunning
2366- };
2367-
2368- LauncherModel(QObject *parent = 0);
2369- ~LauncherModel();
2370-
2371- int rowCount(const QModelIndex &parent) const;
2372-
2373- QVariant data(const QModelIndex &index, int role) const;
2374-
2375- Q_INVOKABLE LauncherItem* get(int index) const;
2376- Q_INVOKABLE void move(int oldIndex, int newIndex);
2377-
2378- QHash<int, QByteArray> roleNames() const;
2379-
2380-private:
2381- QList<LauncherItem*> m_list;
2382-};
2383-
2384-class LauncherItem: public QObject
2385-{
2386- Q_OBJECT
2387- Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
2388- Q_PROPERTY(QString name READ name CONSTANT)
2389- Q_PROPERTY(QString icon READ icon CONSTANT)
2390- Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged)
2391- Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
2392-
2393-public:
2394- LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
2395-
2396- QString desktopFile() const;
2397-
2398- QString name() const;
2399- QString icon() const;
2400-
2401- bool favorite() const;
2402- void setFavorite(bool favorite);
2403-
2404- bool running() const;
2405- void setRunning(bool running);
2406-
2407-Q_SIGNALS:
2408- void favoriteChanged(bool favorite);
2409- void runningChanged(bool running);
2410-
2411-private:
2412- QString m_desktopFile;
2413- QString m_name;
2414- QString m_icon;
2415- bool m_favorite;
2416- bool m_running;
2417-};
2418
2419=== modified file 'tests/mocks/Unity/fake_unity_plugin.cpp'
2420--- tests/mocks/Unity/fake_unity_plugin.cpp 2013-07-04 11:14:37 +0000
2421+++ tests/mocks/Unity/fake_unity_plugin.cpp 2013-07-10 17:15:31 +0000
2422@@ -23,7 +23,6 @@
2423 #include "fake_scopes.h"
2424 #include "fake_categories.h"
2425 #include "categoryresults.h"
2426-#include "fake_launchermodel.h"
2427
2428 // External
2429 #include <glib-object.h>
2430@@ -41,6 +40,4 @@
2431 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
2432 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
2433 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");
2434- qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
2435- qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create");
2436 }

Subscribers

People subscribed via source and target branches