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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-06-26 09:52:31 +0000
+++ CMakeLists.txt 2013-07-10 17:15:31 +0000
@@ -93,8 +93,6 @@
93include(autopilot)93include(autopilot)
94declare_autopilot_test(unity8 ${CMAKE_SOURCE_DIR}/tests/autopilot/)94declare_autopilot_test(unity8 ${CMAKE_SOURCE_DIR}/tests/autopilot/)
9595
96add_subdirectory(tests)
97
98set(SHELL_APP unity8)96set(SHELL_APP unity8)
9997
100set(shell_app_HDRS98set(shell_app_HDRS
@@ -132,6 +130,7 @@
132 )130 )
133131
134# add subdirectories to build132# add subdirectories to build
133add_subdirectory(tests)
135add_subdirectory(plugins)134add_subdirectory(plugins)
136135
137# install subdirectories136# install subdirectories
138137
=== modified file 'Launcher/Launcher.qml'
--- Launcher/Launcher.qml 2013-07-02 19:24:33 +0000
+++ Launcher/Launcher.qml 2013-07-10 17:15:31 +0000
@@ -19,6 +19,7 @@
19import Ubuntu.Components 0.119import Ubuntu.Components 0.1
20import Ubuntu.Gestures 0.120import Ubuntu.Gestures 0.1
21import Unity 0.121import Unity 0.1
22import Unity.Launcher 0.1
2223
23Item {24Item {
24 id: root25 id: root
@@ -96,10 +97,6 @@
96 }97 }
97 }98 }
9899
99 LauncherModel {
100 id: launcherModel
101 }
102
103 MouseArea {100 MouseArea {
104 id: launcherDragArea101 id: launcherDragArea
105 enabled: root.state == "visible"102 enabled: root.state == "visible"
@@ -152,7 +149,7 @@
152 bottom: parent.bottom149 bottom: parent.bottom
153 }150 }
154 x: -width151 x: -width
155 model: launcherModel152 model: LauncherModel
156153
157 property bool animate: true154 property bool animate: true
158155
159156
=== modified file 'Launcher/LauncherPanel.qml'
--- Launcher/LauncherPanel.qml 2013-07-10 08:51:12 +0000
+++ Launcher/LauncherPanel.qml 2013-07-10 17:15:31 +0000
@@ -17,6 +17,7 @@
17import QtQuick 2.017import QtQuick 2.0
18import Ubuntu.Components 0.118import Ubuntu.Components 0.1
19import Unity 0.119import Unity 0.1
20import Unity.Launcher 0.1
20import "../Components/ListItems"21import "../Components/ListItems"
2122
22Item {23Item {
@@ -140,7 +141,7 @@
140 } else if (angle < -12) {141 } else if (angle < -12) {
141 launcherListView.flick(0, launcherListView.clickFlickSpeed);142 launcherListView.flick(0, launcherListView.clickFlickSpeed);
142 } else {143 } else {
143 root.applicationSelected(launcherModel.get(index).desktopFile);144 root.applicationSelected(LauncherModel.get(index).desktopFile);
144 }145 }
145 return;146 return;
146 }147 }
@@ -151,7 +152,7 @@
151 } else if (angle < -30) {152 } else if (angle < -30) {
152 launcherListView.flick(0, launcherListView.clickFlickSpeed);153 launcherListView.flick(0, launcherListView.clickFlickSpeed);
153 } else {154 } else {
154 root.applicationSelected(launcherModel.get(index).desktopFile);155 root.applicationSelected(LauncherModel.get(index).desktopFile);
155 }156 }
156 }157 }
157 }158 }
158159
=== modified file 'debian/control'
--- debian/control 2013-07-04 10:34:48 +0000
+++ debian/control 2013-07-10 17:15:31 +0000
@@ -13,6 +13,7 @@
13 libpulse-dev,13 libpulse-dev,
14 libqt5v8-5-private-dev,14 libqt5v8-5-private-dev,
15 libunity-core-6.0-dev (<< 7.80),15 libunity-core-6.0-dev (<< 7.80),
16 libunity-api-dev (>= 7.80.3),
16 libunity-dev (>= 7.0.3),17 libunity-dev (>= 7.0.3),
17 libusermetricsoutput1-dev,18 libusermetricsoutput1-dev,
18 libxcb1-dev,19 libxcb1-dev,
@@ -52,6 +53,8 @@
52 unity-notifications-impl-1,53 unity-notifications-impl-1,
53 qtdeclarative5-xmllistmodel-plugin,54 qtdeclarative5-xmllistmodel-plugin,
54 unity8-fake-env | qtubuntu-shell,55 unity8-fake-env | qtubuntu-shell,
56 unity8-private | unity-launcher-impl,
57 unity-launcher-impl-2,
55Recommends: ${unity-default-masterscopes},58Recommends: ${unity-default-masterscopes},
56 indicators-client-plugin-datetime (>= 0.6.1),59 indicators-client-plugin-datetime (>= 0.6.1),
57 indicators-client-plugin-messaging (>= 0.6.1),60 indicators-client-plugin-messaging (>= 0.6.1),
@@ -67,6 +70,8 @@
67Pre-Depends: ${misc:Pre-Depends}70Pre-Depends: ${misc:Pre-Depends}
68Depends: ${misc:Depends},71Depends: ${misc:Depends},
69 ${shlibs:Depends},72 ${shlibs:Depends},
73Provides: unity-launcher-impl,
74 unity-launcher-impl-2
70Description: Unity 8 private libs75Description: Unity 8 private libs
71 The Unity 8 shell is the primary user interface for Ubuntu devices.76 The Unity 8 shell is the primary user interface for Ubuntu devices.
72 .77 .
7378
=== modified file 'plugins/Unity/CMakeLists.txt'
--- plugins/Unity/CMakeLists.txt 2013-07-09 14:01:59 +0000
+++ plugins/Unity/CMakeLists.txt 2013-07-10 17:15:31 +0000
@@ -21,7 +21,6 @@
21 categoryresults.cpp21 categoryresults.cpp
22 plugin.cpp22 plugin.cpp
23 bottombarvisibilitycommunicatorshell.cpp23 bottombarvisibilitycommunicatorshell.cpp
24 launchermodel.cpp
25 applicationpreview.cpp24 applicationpreview.cpp
26 genericpreview.cpp25 genericpreview.cpp
27 moviepreview.cpp26 moviepreview.cpp
@@ -49,3 +48,5 @@
4948
50# export the qmldir and qmltypes files49# export the qmldir and qmltypes files
51export_qmlplugin(Unity 0.1 Unity TARGETS Unity-qml)50export_qmlplugin(Unity 0.1 Unity TARGETS Unity-qml)
51
52add_subdirectory(Launcher)
5253
=== added directory 'plugins/Unity/Launcher'
=== added file 'plugins/Unity/Launcher/CMakeLists.txt'
--- plugins/Unity/Launcher/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/CMakeLists.txt 2013-07-10 17:15:31 +0000
@@ -0,0 +1,27 @@
1include(FindPkgConfig)
2pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
3
4include_directories(
5 ${CMAKE_CURRENT_SOURCE_DIR}
6)
7
8set(QMLLAUNCHERPLUGIN_SRC
9 plugin.cpp
10 launchermodel.cpp
11 launcheritem.cpp
12 quicklistmodel.cpp
13 common/quicklistentry.cpp
14 backend/launcherbackend.cpp
15 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
16 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
17 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
18 )
19
20add_library(UnityLauncher-qml MODULE
21 ${QMLLAUNCHERPLUGIN_SRC}
22 )
23
24qt5_use_modules(UnityLauncher-qml Qml)
25
26# export the qmldir and qmltypes files
27export_qmlplugin(Unity.Launcher 0.1 Unity/Launcher TARGETS UnityLauncher-qml)
028
=== added directory 'plugins/Unity/Launcher/backend'
=== added file 'plugins/Unity/Launcher/backend/launcherbackend.cpp'
--- plugins/Unity/Launcher/backend/launcherbackend.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/backend/launcherbackend.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,145 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "launcherbackend.h"
21
22#include <QHash>
23
24LauncherBackend::LauncherBackend(QObject *parent):
25 QObject(parent)
26{
27
28 // TODO: load default pinned ones from default config, instead of hardcoding here...
29
30 m_storedApps <<
31 QLatin1String("phone-app.desktop") <<
32 QLatin1String("camera-app.desktop") <<
33 QLatin1String("gallery-app.desktop") <<
34 QLatin1String("facebook-webapp.desktop") <<
35 QLatin1String("webbrowser-app.desktop") <<
36 QLatin1String("twitter-webapp.desktop") <<
37 QLatin1String("gmail-webapp.desktop") <<
38 QLatin1String("ubuntu-weather-app.desktop") <<
39 QLatin1String("notes-app.desktop") <<
40 QLatin1String("ubuntu-calendar-app.desktop");
41
42 // TODO: get stuff from desktop files instead this hardcoded map
43 m_displayNameMap.insert("phone-app.desktop", "Phone");
44 m_displayNameMap.insert("camera-app.desktop", "Camera");
45 m_displayNameMap.insert("gallery-app.desktop", "Gallery");
46 m_displayNameMap.insert("facebook-webapp.desktop", "Facebook");
47 m_displayNameMap.insert("webbrowser-app.desktop", "Browser");
48 m_displayNameMap.insert("twitter-webapp.desktop", "Twitter");
49 m_displayNameMap.insert("gmail-webapp.desktop", "GMail");
50 m_displayNameMap.insert("ubuntu-weather-app.desktop", "Weather");
51 m_displayNameMap.insert("notes-app.desktop", "Notes");
52 m_displayNameMap.insert("ubuntu-calendar-app.desktop", "Calendar");
53
54 // TODO: get stuff from desktop files instead this hardcoded map
55 m_iconMap.insert("phone-app.desktop", "phone-app");
56 m_iconMap.insert("camera-app.desktop", "camera");
57 m_iconMap.insert("gallery-app.desktop", "gallery");
58 m_iconMap.insert("facebook-webapp.desktop", "facebook");
59 m_iconMap.insert("webbrowser-app.desktop", "browser");
60 m_iconMap.insert("twitter-webapp.desktop", "twitter");
61 m_iconMap.insert("gmail-webapp.desktop", "gmail");
62 m_iconMap.insert("ubuntu-weather-app.desktop", "weather");
63 m_iconMap.insert("notes-app.desktop", "notepad");
64 m_iconMap.insert("ubuntu-calendar-app.desktop", "calendar");
65
66}
67
68LauncherBackend::~LauncherBackend()
69{
70
71}
72
73QStringList LauncherBackend::storedApplications() const
74{
75 return m_storedApps;
76}
77
78void LauncherBackend::setStoredApplications(const QStringList &appIds)
79{
80 m_storedApps = appIds;
81 // TODO: Cleanup pinned state from settings for apps not in list any more.
82}
83
84QString LauncherBackend::desktopFile(const QString &appId) const
85{
86 // TODO: return real path instead of this hardcoded one
87 return QLatin1String("/usr/share/applications/") + appId;
88}
89
90QString LauncherBackend::displayName(const QString &appId) const
91{
92 return m_displayNameMap.value(appId);
93}
94
95QString LauncherBackend::icon(const QString &appId) const
96{
97 return m_iconMap.value(appId);
98}
99
100bool LauncherBackend::isPinned(const QString &appId) const
101{
102 // TODO: return app's pinned state from settings
103 Q_UNUSED(appId)
104 return true;
105}
106
107void LauncherBackend::setPinned(const QString &appId, bool pinned)
108{
109 // TODO: Store pinned state in settings.
110 Q_UNUSED(appId)
111 Q_UNUSED(pinned)
112}
113
114QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
115{
116 // TODO: Get static (from .desktop file) and dynamic (from the app itself)
117 // entries and return them here. Frontend related entries (like "Pin to launcher")
118 // don't matter here. This is just the backend part.
119 // TODO: emit quickListChanged() when the dynamic part changes
120 Q_UNUSED(appId)
121 return QList<QuickListEntry>();
122}
123
124int LauncherBackend::progress(const QString &appId) const
125{
126 // TODO: Return value for progress emblem.
127 // TODO: emit progressChanged() when this value changes.
128 Q_UNUSED(appId)
129 return -1;
130}
131
132int LauncherBackend::count(const QString &appId) const
133{
134 // TODO: Return value for count emblem.
135 // TODO: emit countChanged() when this value changes.
136 Q_UNUSED(appId)
137 return 0;
138}
139
140void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
141{
142 // TODO: execute the given quicklist action
143 Q_UNUSED(appId)
144 Q_UNUSED(quickListId)
145}
0146
=== added file 'plugins/Unity/Launcher/backend/launcherbackend.h'
--- plugins/Unity/Launcher/backend/launcherbackend.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/backend/launcherbackend.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,132 @@
1/* Copyright (C) 2013 Canonical, Ltd.
2 *
3 * Authors:
4 * Michael Zanetti <michael.zanetti@canonical.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LAUNCHERBACKEND_H
20#define LAUNCHERBACKEND_H
21
22#include "common/quicklistentry.h"
23
24#include <QObject>
25#include <QStringList>
26#include <QHash>
27
28/**
29 * @brief An interface that provides all the data needed by the launcher.
30 */
31
32class LauncherBackend : public QObject
33{
34 Q_OBJECT
35
36
37public:
38 LauncherBackend(QObject *parent = 0);
39 virtual ~LauncherBackend();
40
41 /**
42 * @brief Returns a list of stored applications.
43 * @returns A list of application IDs.
44 */
45 QStringList storedApplications() const;
46
47 /**
48 * @brief Set the list of stored applications.
49 *
50 * Any previously stored information for apps not contained
51 * in the list any more, e.g. the pinned state, will be
52 * discarded.
53 *
54 * @param appIds The new list of stored applications.
55 */
56 void setStoredApplications(const QStringList &appIds);
57
58 /**
59 * @brief Get the full path to the .desktop file.
60 * @returns The full path to the .dekstop file.
61 */
62 QString desktopFile(const QString &appId) const;
63
64 /**
65 * @brief Get the user friendly name of an application.
66 * @param appId The ID of the application.
67 * @returns The user friendly name of the application.
68 */
69 QString displayName(const QString &appId) const;
70
71 /**
72 * @brief Get the icon of an application.
73 * @param appId The ID of the application.
74 * @returns The full path to the icon for the application.
75 */
76 QString icon(const QString &appId) const;
77
78 /**
79 * @brief Is the app manually pinned?
80 * @returns true if pinned, otherwise false.
81 */
82 bool isPinned(const QString &appId) const;
83
84 /**
85 * @brief Change the pinned state of an application.
86 * @param appId The application where the pinned flag should be set.
87 * @param pinned true if pinned, otherwise false.
88 */
89 void setPinned(const QString &appId, bool pinned);
90
91 //TODO: Fill in getters for all the other things needed from the .desktop file.
92
93 /**
94 * @brief Get the QuickList for an application.
95 * @param appId The ID of the application.
96 * @returns A QuickListModelInterface containing the QuickList.
97 */
98 QList<QuickListEntry> quickList(const QString &appId) const;
99
100 /**
101 * @brief Execute an action from the quickList
102 * @param appId The app ID for which the action was triggered
103 * @param the quicklist ID of the action that was triggered
104 */
105 void triggerQuickListAction(const QString &appId, const QString &entryId);
106
107 /**
108 * @brief Get the progress for the progress overlay of an application.
109 * @param appId The ID of the application.
110 * @returns The percentage of the overlay progress bar. -1 if no progress bar available.
111 */
112 int progress(const QString &appId) const;
113
114 /**
115 * @brief Get the count of the count overlay of an application.
116 * @param appId The ID of the application.
117 * @returns The number to be displayed in the overlay. -1 if no count overlay is available.
118 */
119 int count(const QString &appId) const;
120
121Q_SIGNALS:
122 void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
123 void progressChanged(const QString &appId, int progress);
124 void countChanged(const QString &appId, int count);
125
126private:
127 QStringList m_storedApps;
128 QHash<QString, QString> m_displayNameMap;
129 QHash<QString, QString> m_iconMap;
130};
131
132#endif // LAUNCHERBACKEND_H
0133
=== added directory 'plugins/Unity/Launcher/common'
=== added file 'plugins/Unity/Launcher/common/quicklistentry.cpp'
--- plugins/Unity/Launcher/common/quicklistentry.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/common/quicklistentry.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,54 @@
1/* Copyright (C) 2013 Canonical, Ltd.
2 *
3 * Authors:
4 * Michael Zanetti <michael.zanetti@canonical.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "quicklistentry.h"
20
21QuickListEntry::QuickListEntry()
22{
23
24}
25
26QString QuickListEntry::actionId() const
27{
28 return m_actionId;
29}
30
31void QuickListEntry::setActionId(const QString &actionId)
32{
33 m_actionId = actionId;
34}
35
36QString QuickListEntry::text() const
37{
38 return m_text;
39}
40
41void QuickListEntry::setText(const QString &text)
42{
43 m_text = text;
44}
45
46QString QuickListEntry::icon() const
47{
48 return m_icon;
49}
50
51void QuickListEntry::setIcon(const QString &icon)
52{
53 m_icon = icon;
54}
055
=== added file 'plugins/Unity/Launcher/common/quicklistentry.h'
--- plugins/Unity/Launcher/common/quicklistentry.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/common/quicklistentry.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,44 @@
1/* Copyright (C) 2013 Canonical, Ltd.
2 *
3 * Authors:
4 * Michael Zanetti <michael.zanetti@canonical.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef QUICKLISTENTRY_H
20#define QUICKLISTENTRY_H
21
22#include <QString>
23
24class QuickListEntry
25{
26public:
27 QuickListEntry();
28
29 QString actionId() const;
30 void setActionId(const QString &actionId);
31
32 QString text() const;
33 void setText(const QString &text);
34
35 QString icon() const;
36 void setIcon(const QString &icon);
37
38private:
39 QString m_actionId;
40 QString m_text;
41 QString m_icon;
42};
43
44#endif // QUICKLISTENTRY
045
=== added file 'plugins/Unity/Launcher/launcheritem.cpp'
--- plugins/Unity/Launcher/launcheritem.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/launcheritem.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,127 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "launcheritem.h"
21#include "quicklistmodel.h"
22
23LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent) :
24 LauncherItemInterface(parent),
25 m_appId(appId),
26 m_desktopFile(desktopFile),
27 m_name(name),
28 m_icon(icon),
29 m_pinned(false),
30 m_running(false),
31 m_recent(false),
32 m_progress(-1),
33 m_count(0),
34 m_quickList(new QuickListModel(this))
35{
36
37}
38
39QString LauncherItem::appId() const
40{
41 return m_appId;
42}
43
44QString LauncherItem::desktopFile() const
45{
46 return m_desktopFile;
47}
48
49QString LauncherItem::name() const
50{
51 return m_name;
52}
53
54QString LauncherItem::icon() const
55{
56 return m_icon;
57}
58
59bool LauncherItem::pinned() const
60{
61 return m_pinned;
62}
63
64void LauncherItem::setPinned(bool pinned)
65{
66 if (m_pinned != pinned) {
67 m_pinned = pinned;
68 Q_EMIT pinnedChanged(pinned);
69 }
70}
71
72bool LauncherItem::running() const
73{
74 return m_running;
75}
76
77void LauncherItem::setRunning(bool running)
78{
79 if (m_running != running) {
80 m_running = running;
81 Q_EMIT runningChanged(running);
82 }
83}
84
85bool LauncherItem::recent() const
86{
87 return m_recent;
88}
89
90void LauncherItem::setRecent(bool recent)
91{
92 if (m_recent != recent) {
93 m_recent = recent;
94 Q_EMIT recentChanged(recent);
95 }
96}
97
98int LauncherItem::progress() const
99{
100 return m_progress;
101}
102
103void LauncherItem::setProgress(int progress)
104{
105 if (m_progress != progress) {
106 m_progress = progress;
107 Q_EMIT progressChanged(progress);
108 }
109}
110
111int LauncherItem::count() const
112{
113 return m_count;
114}
115
116void LauncherItem::setCount(int count)
117{
118 if (m_count != count) {
119 m_count = count;
120 Q_EMIT countChanged(count);
121 }
122}
123
124unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
125{
126 return m_quickList;
127}
0128
=== added file 'plugins/Unity/Launcher/launcheritem.h'
--- plugins/Unity/Launcher/launcheritem.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/launcheritem.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,76 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef LAUNCHERITEM_H
21#define LAUNCHERITEM_H
22
23#include "quicklistmodel.h"
24
25#include <unity/shell/launcher/LauncherItemInterface.h>
26
27class QuickListModel;
28
29using namespace unity::shell::launcher;
30
31class LauncherItem: public LauncherItemInterface
32{
33 Q_OBJECT
34public:
35 LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
36
37 QString appId() const;
38 QString desktopFile() const;
39 QString name() const;
40 QString icon() const;
41
42 bool pinned() const;
43 void setPinned(bool pinned);
44
45 bool running() const;
46 void setRunning(bool running);
47
48 bool recent() const;
49 void setRecent(bool recent);
50
51 int progress() const;
52 void setProgress(int progress);
53
54 int count() const;
55 void setCount(int count);
56
57 unity::shell::launcher::QuickListModelInterface *quickList() const;
58
59Q_SIGNALS:
60 void favoriteChanged(bool favorite);
61 void runningChanged(bool running);
62
63private:
64 QString m_appId;
65 QString m_desktopFile;
66 QString m_name;
67 QString m_icon;
68 bool m_pinned;
69 bool m_running;
70 bool m_recent;
71 int m_progress;
72 int m_count;
73 QuickListModel *m_quickList;
74};
75
76#endif // LAUNCHERITEM_H
077
=== added file 'plugins/Unity/Launcher/launchermodel.cpp'
--- plugins/Unity/Launcher/launchermodel.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/launchermodel.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,170 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "launchermodel.h"
21#include "launcheritem.h"
22#include "backend/launcherbackend.h"
23
24LauncherModel::LauncherModel(QObject *parent):
25 LauncherModelInterface(parent),
26 m_backend(new LauncherBackend(this))
27{
28 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
29 LauncherItem *item = new LauncherItem(entry,
30 m_backend->desktopFile(entry),
31 m_backend->displayName(entry),
32 m_backend->icon(entry),
33 this);
34 if (m_backend->isPinned(entry)) {
35 item->setPinned(true);
36 } else {
37 item->setRecent(true);
38 }
39 m_list.append(item);
40 }
41}
42
43LauncherModel::~LauncherModel()
44{
45 while (!m_list.empty()) {
46 m_list.takeFirst()->deleteLater();
47 }
48}
49
50int LauncherModel::rowCount(const QModelIndex &parent) const
51{
52 Q_UNUSED(parent)
53 return m_list.count();
54}
55
56QVariant LauncherModel::data(const QModelIndex &index, int role) const
57{
58 LauncherItem *item = m_list.at(index.row());
59 switch(role) {
60 case RoleAppId:
61 return item->desktopFile();
62 case RoleDesktopFile:
63 return item->desktopFile();
64 case RoleName:
65 return item->name();
66 case RoleIcon:
67 return item->icon();
68 case RolePinned:
69 return item->pinned();
70 }
71
72 return QVariant();
73}
74
75unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) const
76{
77 if (index < 0 || index >= m_list.count()) {
78 return 0;
79 }
80 return m_list.at(index);
81}
82
83void LauncherModel::move(int oldIndex, int newIndex)
84{
85 // Perform the move in our list
86 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
87 m_list.move(oldIndex, newIndex);
88 endMoveRows();
89
90 storeAppList();
91
92 pin(m_list.at(newIndex)->appId());
93}
94
95void LauncherModel::pin(const QString &appId, int index)
96{
97 int currentIndex = findApplication(appId);
98
99 if (currentIndex >= 0) {
100 if (index == -1 || index == currentIndex) {
101 m_list.at(currentIndex)->setPinned(true);
102 QModelIndex modelIndex = this->index(currentIndex);
103 Q_EMIT dataChanged(modelIndex, modelIndex);
104 } else {
105 move(currentIndex, index);
106 }
107 } else {
108 if (index == -1) {
109 index = m_list.count();
110 }
111 beginInsertRows(QModelIndex(), index, index);
112 LauncherItem *item = new LauncherItem(appId,
113 m_backend->desktopFile(appId),
114 m_backend->displayName(appId),
115 m_backend->icon(appId));
116 item->setPinned(true);
117 m_list.insert(index, item);
118 endInsertRows();
119 }
120}
121
122void LauncherModel::requestRemove(const QString &appId)
123{
124 int index = findApplication(appId);
125 if (index < 0) {
126 return;
127 }
128
129 beginRemoveRows(QModelIndex(), index, index);
130 m_list.takeAt(index)->deleteLater();
131 endRemoveRows();
132
133 storeAppList();
134}
135
136void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
137{
138 int index = findApplication(appId);
139 if (index < 0) {
140 return;
141 }
142
143 QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(index)->quickList());
144 if (model) {
145 QString actionId = model->get(actionIndex).actionId();
146 m_backend->triggerQuickListAction(appId, actionId);
147 }
148}
149
150void LauncherModel::storeAppList()
151{
152 QStringList appIds;
153 Q_FOREACH(LauncherItem *item, m_list) {
154 if (item->pinned() || item->recent()) {
155 appIds << item->appId();
156 }
157 }
158 m_backend->setStoredApplications(appIds);
159}
160
161int LauncherModel::findApplication(const QString &appId)
162{
163 for (int i = 0; i < m_list.count(); ++i) {
164 LauncherItem *item = m_list.at(i);
165 if (item->appId() == appId) {
166 return i;
167 }
168 }
169 return -1;
170}
0171
=== added file 'plugins/Unity/Launcher/launchermodel.h'
--- plugins/Unity/Launcher/launchermodel.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/launchermodel.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,61 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef LAUNCHERMODELH
21#define LAUNCHERMODEL_H
22
23// unity-api
24#include <unity/shell/launcher/LauncherModelInterface.h>
25
26// Qt
27#include <QAbstractListModel>
28
29class LauncherItem;
30class LauncherBackend;
31
32using namespace unity::shell::launcher;
33
34class LauncherModel: public LauncherModelInterface
35{
36 Q_OBJECT
37
38public:
39 LauncherModel(QObject *parent = 0);
40 ~LauncherModel();
41
42 int rowCount(const QModelIndex &parent) const;
43
44 QVariant data(const QModelIndex &index, int role) const;
45
46 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
47 Q_INVOKABLE void move(int oldIndex, int newIndex);
48 Q_INVOKABLE void pin(const QString &appId, int index = -1);
49 Q_INVOKABLE void requestRemove(const QString &appId);
50 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
51
52private:
53 void storeAppList();
54 int findApplication(const QString &appId);
55
56private:
57 QList<LauncherItem*> m_list;
58 LauncherBackend *m_backend;
59};
60
61#endif // LAUNCHERMODEL_H
062
=== added file 'plugins/Unity/Launcher/plugin.cpp'
--- plugins/Unity/Launcher/plugin.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/plugin.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,47 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20// Qt
21#include <QtQml>
22
23// self
24#include "plugin.h"
25
26// local
27#include "launchermodel.h"
28#include "launcheritem.h"
29
30
31using namespace unity::shell::launcher;
32
33static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
34{
35 return new LauncherModel();
36}
37
38void UnityLauncherPlugin::registerTypes(const char *uri)
39{
40 Q_ASSERT(uri == QLatin1String("Unity.Launcher"));
41
42 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
43 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
44
45 qmlRegisterSingletonType<LauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
46 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
47}
048
=== added file 'plugins/Unity/Launcher/plugin.h'
--- plugins/Unity/Launcher/plugin.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/plugin.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Michael Zanetti <michael.zanetti@canonical.com>
17 */
18
19#ifndef UNITY_LAUNCHER_PLUGIN_H
20#define UNITY_LAUNCHER_PLUGIN_H
21
22#include <QtQml/QQmlEngine>
23#include <QtQml/QQmlExtensionPlugin>
24
25class UnityLauncherPlugin : public QQmlExtensionPlugin
26{
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29
30public:
31 void registerTypes(const char *uri);
32};
33
34#endif
035
=== added file 'plugins/Unity/Launcher/qmldir'
--- plugins/Unity/Launcher/qmldir 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/qmldir 2013-07-10 17:15:31 +0000
@@ -0,0 +1,2 @@
1module Unity.Launcher
2plugin UnityLauncher-qml
03
=== added file 'plugins/Unity/Launcher/quicklistmodel.cpp'
--- plugins/Unity/Launcher/quicklistmodel.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/quicklistmodel.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,60 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "quicklistmodel.h"
21
22QuickListModel::QuickListModel(QObject *parent) :
23 QuickListModelInterface(parent)
24{
25
26}
27
28QuickListModel::~QuickListModel()
29{
30
31}
32
33void QuickListModel::appendAction(const QuickListEntry &entry)
34{
35 beginInsertRows(QModelIndex(), m_list.count() - 1, m_list.count() -1);
36 m_list.append(entry);
37 endInsertRows();
38}
39
40QuickListEntry QuickListModel::get(int index) const
41{
42 return m_list.at(index);
43}
44
45int QuickListModel::rowCount(const QModelIndex &index) const
46{
47 Q_UNUSED(index)
48 return m_list.count();
49}
50
51QVariant QuickListModel::data(const QModelIndex &index, int role) const
52{
53 switch (role) {
54 case RoleLabel:
55 return m_list.at(index.row()).text();
56 case RoleIcon:
57 return m_list.at(index.row()).icon();
58 }
59 return QVariant();
60}
061
=== added file 'plugins/Unity/Launcher/quicklistmodel.h'
--- plugins/Unity/Launcher/quicklistmodel.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Launcher/quicklistmodel.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,48 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef QUICKLISTMODEL_H
21#define QUICKLISTMODEL_H
22
23#include "common/quicklistentry.h"
24
25#include <unity/shell/launcher/QuickListModelInterface.h>
26
27using namespace unity::shell::launcher;
28
29class QuickListModel: public QuickListModelInterface
30{
31 Q_OBJECT
32
33public:
34 explicit QuickListModel(QObject *parent = 0);
35
36 ~QuickListModel();
37
38 void appendAction(const QuickListEntry &entry);
39 QuickListEntry get(int index) const;
40
41 int rowCount(const QModelIndex &parent = QModelIndex()) const;
42 QVariant data(const QModelIndex &index, int role) const;
43
44private:
45 QList<QuickListEntry> m_list;
46};
47
48#endif // QUICKLISTMODEL_H
049
=== removed file 'plugins/Unity/launchermodel.cpp'
--- plugins/Unity/launchermodel.cpp 2013-06-05 22:03:08 +0000
+++ plugins/Unity/launchermodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,153 +0,0 @@
1/*
2 * Copyright (C) 2011 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "launchermodel.h"
21
22LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
23{
24 // FIXME: Dummy data... Aggregate real data from backends
25
26 // Fake favorites
27 LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
28 m_list.append(item);
29 item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
30 m_list.append(item);
31 item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
32 m_list.append(item);
33 item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
34 m_list.append(item);
35 item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
36 m_list.append(item);
37 item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
38 m_list.append(item);
39 item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
40 m_list.append(item);
41 item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
42 m_list.append(item);
43 item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
44 m_list.append(item);
45 item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
46 m_list.append(item);
47}
48
49LauncherModel::~LauncherModel()
50{
51 while (!m_list.empty()) {
52 m_list.takeFirst()->deleteLater();
53 }
54}
55
56int LauncherModel::rowCount(const QModelIndex &parent) const
57{
58 Q_UNUSED(parent)
59 return m_list.count();
60}
61
62QVariant LauncherModel::data(const QModelIndex &index, int role) const
63{
64 LauncherItem *item = m_list.at(index.row());
65 switch(role) {
66 case RoleName:
67 return item->name();
68 case RoleIcon:
69 return item->icon();
70 case RoleFavorite:
71 return item->favorite();
72 }
73
74 return QVariant();
75}
76
77LauncherItem *LauncherModel::get(int index) const
78{
79 if (index < 0 || index >= m_list.count()) {
80 return 0;
81 }
82 return m_list.at(index);
83}
84
85void LauncherModel::move(int oldIndex, int newIndex)
86{
87 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
88 m_list.move(oldIndex, newIndex);
89 endMoveRows();
90}
91
92QHash<int, QByteArray> LauncherModel::roleNames() const
93{
94 QHash<int, QByteArray> roles;
95 roles.insert(RoleDesktopFile, "desktopFile");
96 roles.insert(RoleName, "name");
97 roles.insert(RoleIcon, "icon");
98 roles.insert(RoleFavorite, "favorite");
99 roles.insert(RoleRunning, "runnng");
100 return roles;
101}
102
103
104LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
105 QObject(parent),
106 m_desktopFile(desktopFile),
107 m_name(name),
108 m_icon(icon),
109 m_favorite(false)
110{
111
112}
113
114QString LauncherItem::desktopFile() const
115{
116 return m_desktopFile;
117}
118
119QString LauncherItem::name() const
120{
121 return m_name;
122}
123
124QString LauncherItem::icon() const
125{
126 return m_icon;
127}
128
129bool LauncherItem::favorite() const
130{
131 return m_favorite;
132}
133
134void LauncherItem::setFavorite(bool favorite)
135{
136 if (m_favorite != favorite) {
137 m_favorite = favorite;
138 Q_EMIT favoriteChanged(m_favorite);
139 }
140}
141
142bool LauncherItem::running() const
143{
144 return m_running;
145}
146
147void LauncherItem::setRunning(bool running)
148{
149 if (m_running != running) {
150 m_running = running;
151 Q_EMIT runningChanged(running);
152 }
153}
1540
=== removed file 'plugins/Unity/launchermodel.h'
--- plugins/Unity/launchermodel.h 2013-06-05 22:03:08 +0000
+++ plugins/Unity/launchermodel.h 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
1/*
2 * Copyright (C) 2011 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <QAbstractListModel>
21
22class LauncherItem;
23
24class LauncherModel: public QAbstractListModel
25{
26 Q_OBJECT
27
28public:
29 enum Roles {
30 RoleDesktopFile = Qt::UserRole,
31 RoleName,
32 RoleIcon,
33 RoleFavorite,
34 RoleRunning
35 };
36
37 LauncherModel(QObject *parent = 0);
38 ~LauncherModel();
39
40 int rowCount(const QModelIndex &parent) const;
41
42 QVariant data(const QModelIndex &index, int role) const;
43
44 Q_INVOKABLE LauncherItem* get(int index) const;
45 Q_INVOKABLE void move(int oldIndex, int newIndex);
46
47 QHash<int, QByteArray> roleNames() const;
48
49private:
50 QList<LauncherItem*> m_list;
51};
52
53class LauncherItem: public QObject
54{
55 Q_OBJECT
56 Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
57 Q_PROPERTY(QString name READ name CONSTANT)
58 Q_PROPERTY(QString icon READ icon CONSTANT)
59 Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged)
60 Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
61
62public:
63 LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
64
65 QString desktopFile() const;
66
67 QString name() const;
68 QString icon() const;
69
70 bool favorite() const;
71 void setFavorite(bool favorite);
72
73 bool running() const;
74 void setRunning(bool running);
75
76Q_SIGNALS:
77 void favoriteChanged(bool favorite);
78 void runningChanged(bool running);
79
80private:
81 QString m_desktopFile;
82 QString m_name;
83 QString m_icon;
84 bool m_favorite;
85 bool m_running;
86};
870
=== modified file 'plugins/Unity/plugin.cpp'
--- plugins/Unity/plugin.cpp 2013-07-09 14:01:59 +0000
+++ plugins/Unity/plugin.cpp 2013-07-10 17:15:31 +0000
@@ -33,7 +33,6 @@
33#include "categories.h"33#include "categories.h"
34#include "categoryresults.h"34#include "categoryresults.h"
35#include "bottombarvisibilitycommunicatorshell.h"35#include "bottombarvisibilitycommunicatorshell.h"
36#include "launchermodel.h"
3736
38// libqtdee37// libqtdee
39#include "deelistmodel.h"38#include "deelistmodel.h"
@@ -53,8 +52,6 @@
53 qmlRegisterType<Categories>(uri, 0, 1, "Categories");52 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
54 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");53 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
55 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");54 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
56 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
57 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
58 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");55 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
59}56}
6057
6158
=== modified file 'tests/mocks/Unity/CMakeLists.txt'
--- tests/mocks/Unity/CMakeLists.txt 2013-06-28 17:59:31 +0000
+++ tests/mocks/Unity/CMakeLists.txt 2013-07-10 17:15:31 +0000
@@ -24,7 +24,6 @@
24 fake_scopes.cpp24 fake_scopes.cpp
25 fake_categories.cpp25 fake_categories.cpp
26 fake_unity_plugin.cpp26 fake_unity_plugin.cpp
27 fake_launchermodel.cpp
28)27)
2928
30add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})29add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
@@ -41,3 +40,5 @@
41file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"40file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
42 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}41 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
43 )42 )
43
44add_subdirectory(Launcher)
4445
=== added directory 'tests/mocks/Unity/Launcher'
=== added file 'tests/mocks/Unity/Launcher/CMakeLists.txt'
--- tests/mocks/Unity/Launcher/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/CMakeLists.txt 2013-07-10 17:15:31 +0000
@@ -0,0 +1,26 @@
1include(FindPkgConfig)
2pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
3
4include_directories(
5 ${CMAKE_CURRENT_SOURCE_DIR}
6)
7
8set(MockLauncherModel_SOURCES
9 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
10 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
11 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
12 plugin.cpp
13 MockLauncherModel.cpp
14 MockLauncherItem.cpp
15 MockQuickListModel.cpp
16)
17
18add_library(MockLauncherPlugin MODULE ${MockLauncherModel_SOURCES})
19
20qt5_use_modules(MockLauncherPlugin Core Quick)
21
22# copy files into build directory for shadow builds
23add_custom_target(LauncherPluginQmlDirFile ALL
24 COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
25 DEPENDS qmldir
26)
027
=== added file 'tests/mocks/Unity/Launcher/MockLauncherItem.cpp'
--- tests/mocks/Unity/Launcher/MockLauncherItem.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockLauncherItem.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,134 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "MockLauncherItem.h"
21#include "MockQuickListModel.h"
22
23using namespace unity::shell::launcher;
24
25MockLauncherItem::MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
26 LauncherItemInterface(parent),
27 m_appId(appId),
28 m_desktopFile(desktopFile),
29 m_name(name),
30 m_icon(icon),
31 m_pinned(false),
32 m_running(false),
33 m_recent(false),
34 m_progress(8),
35 m_count(8),
36 m_quickList(new MockQuickListModel(this))
37{
38
39}
40
41QString MockLauncherItem::appId() const
42{
43 return m_appId;
44}
45
46QString MockLauncherItem::desktopFile() const
47{
48 return m_desktopFile;
49}
50
51QString MockLauncherItem::name() const
52{
53 return m_name;
54}
55
56QString MockLauncherItem::icon() const
57{
58 return m_icon;
59}
60
61bool MockLauncherItem::pinned() const
62{
63 return m_pinned;
64}
65
66void MockLauncherItem::setPinned(bool pinned)
67{
68 if (m_pinned != pinned)
69 {
70 m_pinned = pinned;
71 Q_EMIT pinnedChanged(m_pinned);
72 }
73}
74
75bool MockLauncherItem::running() const
76{
77 return m_running;
78}
79
80void MockLauncherItem::setRunning(bool running)
81{
82 if (m_running != running)
83 {
84 m_running = running;
85 Q_EMIT runningChanged(running);
86 }
87}
88
89bool MockLauncherItem::recent() const
90{
91 return m_recent;
92}
93
94void MockLauncherItem::setRecent(bool recent)
95{
96 if (m_recent != recent)
97 {
98 m_recent = recent;
99 Q_EMIT recentChanged(recent);
100 }
101}
102
103int MockLauncherItem::progress() const
104{
105 return m_progress;
106}
107
108void MockLauncherItem::setProgress(int progress)
109{
110 if (m_progress != progress)
111 {
112 m_progress = progress;
113 Q_EMIT progressChanged(progress);
114 }
115}
116
117int MockLauncherItem::count() const
118{
119 return m_count;
120}
121
122void MockLauncherItem::setCount(int count)
123{
124 if (m_count != count)
125 {
126 m_count = count;
127 Q_EMIT countChanged(count);
128 }
129}
130
131unity::shell::launcher::QuickListModelInterface *MockLauncherItem::quickList() const
132{
133 return m_quickList;
134}
0135
=== added file 'tests/mocks/Unity/Launcher/MockLauncherItem.h'
--- tests/mocks/Unity/Launcher/MockLauncherItem.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockLauncherItem.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,70 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef MOCKLAUNCHERITEM_H
21#define MOCKLAUNCHERITEM_H
22
23#include <unity/shell/launcher/LauncherItemInterface.h>
24
25class MockQuickListModel;
26
27using namespace unity::shell::launcher;
28
29class MockLauncherItem: public LauncherItemInterface
30{
31 Q_OBJECT
32public:
33 MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
34
35 QString appId() const;
36 QString desktopFile() const;
37 QString name() const;
38 QString icon() const;
39
40 bool pinned() const;
41 void setPinned(bool pinned);
42
43 bool running() const;
44 void setRunning(bool running);
45
46 bool recent() const;
47 void setRecent(bool recent);
48
49 int progress() const;
50 void setProgress(int progress);
51
52 int count() const;
53 void setCount(int count);
54
55 unity::shell::launcher::QuickListModelInterface *quickList() const;
56
57private:
58 QString m_appId;
59 QString m_desktopFile;
60 QString m_name;
61 QString m_icon;
62 bool m_pinned;
63 bool m_running;
64 bool m_recent;
65 int m_progress;
66 int m_count;
67 MockQuickListModel *m_quickList;
68};
69
70#endif // MOCKLAUNCHERITEM_H
071
=== added file 'tests/mocks/Unity/Launcher/MockLauncherModel.cpp'
--- tests/mocks/Unity/Launcher/MockLauncherModel.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockLauncherModel.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,152 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "MockLauncherModel.h"
21#include "MockLauncherItem.h"
22
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
24{
25 MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
26 m_list.append(item);
27 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera");
28 m_list.append(item);
29 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
30 m_list.append(item);
31 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
32 m_list.append(item);
33 item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
34 m_list.append(item);
35 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
36 m_list.append(item);
37 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
38 m_list.append(item);
39 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
40 m_list.append(item);
41 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
42 m_list.append(item);
43 item = new MockLauncherItem("ubuntu-calendar-app", "/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
44 m_list.append(item);
45}
46
47MockLauncherModel::~MockLauncherModel()
48{
49 while (!m_list.empty())
50 {
51 m_list.takeFirst()->deleteLater();
52 }
53}
54
55int MockLauncherModel::rowCount(const QModelIndex& parent) const
56{
57 Q_UNUSED(parent)
58 return m_list.count();
59}
60
61QVariant MockLauncherModel::data(const QModelIndex& index, int role) const
62{
63 LauncherItemInterface *item = m_list.at(index.row());
64 switch(role)
65 {
66 case RoleDesktopFile:
67 return item->desktopFile();
68 case RoleName:
69 return item->name();
70 case RoleIcon:
71 return item->icon();
72 case RolePinned:
73 return item->pinned();
74 case RoleRunning:
75 return item->running();
76 case RoleRecent:
77 return item->recent();
78 case RoleProgress:
79 return item->progress();
80 case RoleCount:
81 return item->count();
82 }
83
84 return QVariant();
85}
86
87unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index) const
88{
89 if (index < 0 || index >= m_list.count())
90 {
91 return 0;
92 }
93 return m_list.at(index);
94}
95
96void MockLauncherModel::move(int oldIndex, int newIndex)
97{
98 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
99 m_list.move(oldIndex, newIndex);
100 endMoveRows();
101}
102
103void MockLauncherModel::pin(const QString &appId, int index)
104{
105 int currentIndex = findApp(appId);
106
107 if (currentIndex >= 0) {
108 if (index == -1 || index == currentIndex) {
109 m_list.at(currentIndex)->setPinned(true);
110 QModelIndex modelIndex = this->index(currentIndex);
111 Q_EMIT dataChanged(modelIndex, modelIndex);
112 } else {
113 move(currentIndex, index);
114 }
115 } else {
116 beginInsertRows(QModelIndex(), index, index);
117 m_list.insert(index, new MockLauncherItem(appId,
118 appId + ".desktop",
119 appId,
120 appId + ".png"));
121 m_list.at(index)->setPinned(true);
122 endInsertRows();
123 }
124}
125
126void MockLauncherModel::requestRemove(const QString &appId)
127{
128 int index = findApp(appId);
129 if (index >= 0) {
130 beginRemoveRows(QModelIndex(), index, 0);
131 m_list.takeAt(index)->deleteLater();
132 endRemoveRows();
133 }
134}
135
136void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
137{
138 Q_UNUSED(appId)
139 Q_UNUSED(actionIndex)
140 // Nothing to mock yet...
141}
142
143int MockLauncherModel::findApp(const QString &appId)
144{
145 for (int i = 0; i < m_list.count(); ++i) {
146 MockLauncherItem *item = m_list.at(i);
147 if (item->appId() == appId) {
148 return i;
149 }
150 }
151 return -1;
152}
0153
=== added file 'tests/mocks/Unity/Launcher/MockLauncherModel.h'
--- tests/mocks/Unity/Launcher/MockLauncherModel.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockLauncherModel.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef MOCKLAUNCHERMODEL_H
21#define MOCKLAUNCHERMODEL_H
22
23#include <unity/shell/launcher/LauncherModelInterface.h>
24
25class MockLauncherItem;
26
27using namespace unity::shell::launcher;
28
29class MockLauncherModel: public LauncherModelInterface
30{
31 Q_OBJECT
32
33public:
34 MockLauncherModel(QObject* parent = 0);
35 ~MockLauncherModel();
36
37 int rowCount(const QModelIndex& parent) const;
38
39 QVariant data(const QModelIndex& index, int role) const;
40
41 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
42 Q_INVOKABLE void move(int oldIndex, int newIndex);
43 Q_INVOKABLE void pin(const QString &appId, int index = -1);
44 Q_INVOKABLE void requestRemove(const QString &appId);
45 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
46
47private:
48 int findApp(const QString &appId);
49
50private:
51 QList<MockLauncherItem*> m_list;
52};
53
54#endif // MOCKLAUNCHERMODEL_H
055
=== added file 'tests/mocks/Unity/Launcher/MockQuickListModel.cpp'
--- tests/mocks/Unity/Launcher/MockQuickListModel.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockQuickListModel.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include <MockQuickListModel.h>
21
22using namespace unity::shell::launcher;
23
24MockQuickListModel::MockQuickListModel(QObject *parent) :
25 QuickListModelInterface(parent)
26{
27
28}
29
30QVariant MockQuickListModel::data(const QModelIndex &index, int role) const
31{
32 switch (role)
33 {
34 case RoleLabel:
35 return QLatin1String("test menu entry ") + QString::number(index.row());
36 case RoleIcon:
37 return QLatin1String("copy.png");
38 }
39 return QVariant();
40}
41
42int MockQuickListModel::rowCount(const QModelIndex &parent) const
43{
44 Q_UNUSED(parent)
45 return 4;
46}
047
=== added file 'tests/mocks/Unity/Launcher/MockQuickListModel.h'
--- tests/mocks/Unity/Launcher/MockQuickListModel.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/MockQuickListModel.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#ifndef MOCKQUICKLISTMODEL_H
21#define MOCKQUICKLISTMODEL_H
22
23#include <unity/shell/launcher/QuickListModelInterface.h>
24
25using namespace unity::shell::launcher;
26
27class MockQuickListModel: public QuickListModelInterface
28{
29 Q_OBJECT
30public:
31 MockQuickListModel(QObject *parent = 0);
32
33 QVariant data(const QModelIndex &index, int role) const;
34
35 int rowCount(const QModelIndex &parent = QModelIndex()) const;
36};
37
38#endif // MOCKQUICKLISTMODEL_H
039
=== added file 'tests/mocks/Unity/Launcher/plugin.cpp'
--- tests/mocks/Unity/Launcher/plugin.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/plugin.cpp 2013-07-10 17:15:31 +0000
@@ -0,0 +1,45 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20#include "plugin.h"
21#include "MockLauncherModel.h"
22#include "MockLauncherItem.h"
23
24#include <unity/shell/launcher/LauncherModelInterface.h>
25#include <unity/shell/launcher/LauncherItemInterface.h>
26
27#include <QtQml/qqml.h>
28
29using namespace unity::shell::launcher;
30
31static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
32{
33 return new MockLauncherModel();
34}
35
36// cppcheck-suppress unusedFunction
37void TestLauncherPlugin::registerTypes(const char* uri)
38{
39 // @uri Unity.Launcher
40 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
41 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
42
43 qmlRegisterSingletonType<MockLauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
44 qmlRegisterUncreatableType<MockLauncherItem>(uri, 0, 1, "LauncherItem", "Can't create LauncherItems in QML. Get them from the LauncherModel");
45}
046
=== added file 'tests/mocks/Unity/Launcher/plugin.h'
--- tests/mocks/Unity/Launcher/plugin.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/plugin.h 2013-07-10 17:15:31 +0000
@@ -0,0 +1,35 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
19
20
21#ifndef TESTLAUNCHER_PLUGIN_H
22#define TESTLAUNCHER_PLUGIN_H
23
24#include <QtQml/QQmlExtensionPlugin>
25
26class TestLauncherPlugin : public QQmlExtensionPlugin
27{
28 Q_OBJECT
29 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
30
31public:
32 void registerTypes(const char* uri);
33};
34
35#endif // TESTLAUNCHER_PLUGIN_H
036
=== added file 'tests/mocks/Unity/Launcher/qmldir'
--- tests/mocks/Unity/Launcher/qmldir 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Launcher/qmldir 2013-07-10 17:15:31 +0000
@@ -0,0 +1,2 @@
1module Unity.Launcher
2plugin MockLauncherPlugin
03
=== removed file 'tests/mocks/Unity/fake_launchermodel.cpp'
--- tests/mocks/Unity/fake_launchermodel.cpp 2013-06-05 22:03:08 +0000
+++ tests/mocks/Unity/fake_launchermodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,150 +0,0 @@
1/*
2 * Copyright (C) 2011 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "launchermodel.h"
21
22LauncherModel::LauncherModel(QObject *parent): QAbstractListModel(parent)
23{
24 LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
25 m_list.append(item);
26 item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
27 m_list.append(item);
28 item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
29 m_list.append(item);
30 item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
31 m_list.append(item);
32 item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
33 m_list.append(item);
34 item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
35 m_list.append(item);
36 item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
37 m_list.append(item);
38 item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
39 m_list.append(item);
40 item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
41 m_list.append(item);
42 item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
43 m_list.append(item);
44}
45
46LauncherModel::~LauncherModel()
47{
48 while (!m_list.empty()) {
49 m_list.takeFirst()->deleteLater();
50 }
51}
52
53int LauncherModel::rowCount(const QModelIndex &parent) const
54{
55 Q_UNUSED(parent)
56 return m_list.count();
57}
58
59QVariant LauncherModel::data(const QModelIndex &index, int role) const
60{
61 LauncherItem *item = m_list.at(index.row());
62 switch(role) {
63 case RoleName:
64 return item->name();
65 case RoleIcon:
66 return item->icon();
67 case RoleFavorite:
68 return item->favorite();
69 }
70
71 return QVariant();
72}
73
74LauncherItem *LauncherModel::get(int index) const
75{
76 if (index < 0 || index >= m_list.count()) {
77 return 0;
78 }
79 return m_list.at(index);
80}
81
82void LauncherModel::move(int oldIndex, int newIndex)
83{
84 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
85 m_list.move(oldIndex, newIndex);
86 endMoveRows();
87}
88
89QHash<int, QByteArray> LauncherModel::roleNames() const
90{
91 QHash<int, QByteArray> roles;
92 roles.insert(RoleDesktopFile, "desktopFile");
93 roles.insert(RoleName, "name");
94 roles.insert(RoleIcon, "icon");
95 roles.insert(RoleFavorite, "favorite");
96 roles.insert(RoleRunning, "runnng");
97 return roles;
98}
99
100
101LauncherItem::LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent):
102 QObject(parent),
103 m_desktopFile(desktopFile),
104 m_name(name),
105 m_icon(icon),
106 m_favorite(false)
107{
108
109}
110
111QString LauncherItem::desktopFile() const
112{
113 return m_desktopFile;
114}
115
116QString LauncherItem::name() const
117{
118 return m_name;
119}
120
121QString LauncherItem::icon() const
122{
123 return m_icon;
124}
125
126bool LauncherItem::favorite() const
127{
128 return m_favorite;
129}
130
131void LauncherItem::setFavorite(bool favorite)
132{
133 if (m_favorite != favorite) {
134 m_favorite = favorite;
135 Q_EMIT favoriteChanged(m_favorite);
136 }
137}
138
139bool LauncherItem::running() const
140{
141 return m_running;
142}
143
144void LauncherItem::setRunning(bool running)
145{
146 if (m_running != running) {
147 m_running = running;
148 Q_EMIT runningChanged(running);
149 }
150}
1510
=== removed file 'tests/mocks/Unity/fake_launchermodel.h'
--- tests/mocks/Unity/fake_launchermodel.h 2013-06-05 22:03:08 +0000
+++ tests/mocks/Unity/fake_launchermodel.h 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
1/*
2 * Copyright (C) 2011 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <QAbstractListModel>
21
22class LauncherItem;
23
24class LauncherModel: public QAbstractListModel
25{
26 Q_OBJECT
27
28public:
29 enum Roles {
30 RoleDesktopFile = Qt::UserRole,
31 RoleName,
32 RoleIcon,
33 RoleFavorite,
34 RoleRunning
35 };
36
37 LauncherModel(QObject *parent = 0);
38 ~LauncherModel();
39
40 int rowCount(const QModelIndex &parent) const;
41
42 QVariant data(const QModelIndex &index, int role) const;
43
44 Q_INVOKABLE LauncherItem* get(int index) const;
45 Q_INVOKABLE void move(int oldIndex, int newIndex);
46
47 QHash<int, QByteArray> roleNames() const;
48
49private:
50 QList<LauncherItem*> m_list;
51};
52
53class LauncherItem: public QObject
54{
55 Q_OBJECT
56 Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
57 Q_PROPERTY(QString name READ name CONSTANT)
58 Q_PROPERTY(QString icon READ icon CONSTANT)
59 Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged)
60 Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
61
62public:
63 LauncherItem(const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
64
65 QString desktopFile() const;
66
67 QString name() const;
68 QString icon() const;
69
70 bool favorite() const;
71 void setFavorite(bool favorite);
72
73 bool running() const;
74 void setRunning(bool running);
75
76Q_SIGNALS:
77 void favoriteChanged(bool favorite);
78 void runningChanged(bool running);
79
80private:
81 QString m_desktopFile;
82 QString m_name;
83 QString m_icon;
84 bool m_favorite;
85 bool m_running;
86};
870
=== modified file 'tests/mocks/Unity/fake_unity_plugin.cpp'
--- tests/mocks/Unity/fake_unity_plugin.cpp 2013-07-04 11:14:37 +0000
+++ tests/mocks/Unity/fake_unity_plugin.cpp 2013-07-10 17:15:31 +0000
@@ -23,7 +23,6 @@
23#include "fake_scopes.h"23#include "fake_scopes.h"
24#include "fake_categories.h"24#include "fake_categories.h"
25#include "categoryresults.h"25#include "categoryresults.h"
26#include "fake_launchermodel.h"
2726
28// External27// External
29#include <glib-object.h>28#include <glib-object.h>
@@ -41,6 +40,4 @@
41 qmlRegisterType<Scope>(uri, 0, 1, "Scope");40 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
42 qmlRegisterType<Categories>(uri, 0, 1, "Categories");41 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
43 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");42 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");
44 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
45 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create");
46}43}

Subscribers

People subscribed via source and target branches