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

Approved by PS Jenkins bot, Michał Sawicz.

commit8639e99e183967e69585c50cb263025cc7673ff8 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 11 Jul 2013, 08:19 (13 years ago) parentb77fc1cdc764fc
36 files changed+1644−492
CMakeLists.txt+1−2 Launcher/Launcher.qml+2−5 Launcher/LauncherPanel.qml+3−2 debian/control+5 plugins/Unity/CMakeLists.txt+2−1 plugins/Unity/Launcher/CMakeLists.txt+27 plugins/Unity/Launcher/backend/launcherbackend.cpp+145 plugins/Unity/Launcher/backend/launcherbackend.h+132 plugins/Unity/Launcher/common/quicklistentry.cpp+54 plugins/Unity/Launcher/common/quicklistentry.h+44 plugins/Unity/Launcher/launcheritem.cpp+127 plugins/Unity/Launcher/launcheritem.h+76 plugins/Unity/Launcher/launchermodel.cpp+170 plugins/Unity/Launcher/launchermodel.h+61 plugins/Unity/Launcher/plugin.cpp+47 plugins/Unity/Launcher/plugin.h+34 plugins/Unity/Launcher/qmldir+2 plugins/Unity/Launcher/quicklistmodel.cpp+60 plugins/Unity/Launcher/quicklistmodel.h+48 plugins/Unity/launchermodel.cpp−153 plugins/Unity/launchermodel.h−86 plugins/Unity/plugin.cpp−3 tests/mocks/Unity/CMakeLists.txt+2−1 tests/mocks/Unity/Launcher/CMakeLists.txt+26 tests/mocks/Unity/Launcher/MockLauncherItem.cpp+134 tests/mocks/Unity/Launcher/MockLauncherItem.h+70 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+152 tests/mocks/Unity/Launcher/MockLauncherModel.h+54 tests/mocks/Unity/Launcher/MockQuickListModel.cpp+46 tests/mocks/Unity/Launcher/MockQuickListModel.h+38 tests/mocks/Unity/Launcher/plugin.cpp+45 tests/mocks/Unity/Launcher/plugin.h+35 tests/mocks/Unity/Launcher/qmldir+2 tests/mocks/Unity/fake_launchermodel.cpp−150 tests/mocks/Unity/fake_launchermodel.h−86 tests/mocks/Unity/fake_unity_plugin.cpp−3
CMakeLists.txt+1−2
@@ -93,8 +93,6 @@ enable_testing()
9393include(autopilot)
9494declare_autopilot_test(unity8 ${CMAKE_SOURCE_DIR}/tests/autopilot/)
9595
96−add_subdirectory(tests)
97−
9896set(SHELL_APP unity8)
9997
10098set(shell_app_HDRS
@@ -132,6 +130,7 @@ install(FILES ${QML_JS_FILES}
132130 )
133131
134132# add subdirectories to build
133+add_subdirectory(tests)
135134add_subdirectory(plugins)
136135
137136# install subdirectories
Launcher/Launcher.qml+2−5
@@ -19,6 +19,7 @@ import "../Components"
1919import Ubuntu.Components 0.1
2020import Ubuntu.Gestures 0.1
2121import Unity 0.1
22+import Unity.Launcher 0.1
2223
2324Item {
2425 id: root
@@ -96,10 +97,6 @@ Item {
9697 }
9798 }
9899
99− LauncherModel {
100− id: launcherModel
101− }
102−
103100 MouseArea {
104101 id: launcherDragArea
105102 enabled: root.state == "visible"
@@ -152,7 +149,7 @@ Item {
152149 bottom: parent.bottom
153150 }
154151 x: -width
155− model: launcherModel
152+ model: LauncherModel
156153
157154 property bool animate: true
158155
Launcher/LauncherPanel.qml+3−2
@@ -17,6 +17,7 @@
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Unity 0.1
20+import Unity.Launcher 0.1
2021import "../Components/ListItems"
2122
2223Item {
@@ -140,7 +141,7 @@ Item {
140141 } else if (angle < -12) {
141142 launcherListView.flick(0, launcherListView.clickFlickSpeed);
142143 } else {
143− root.applicationSelected(launcherModel.get(index).desktopFile);
144+ root.applicationSelected(LauncherModel.get(index).desktopFile);
144145 }
145146 return;
146147 }
@@ -151,7 +152,7 @@ Item {
151152 } else if (angle < -30) {
152153 launcherListView.flick(0, launcherListView.clickFlickSpeed);
153154 } else {
154− root.applicationSelected(launcherModel.get(index).desktopFile);
155+ root.applicationSelected(LauncherModel.get(index).desktopFile);
155156 }
156157 }
157158 }
debian/control+5
@@ -13,6 +13,7 @@ Build-Depends: cmake,
1313 libpulse-dev,
1414 libqt5v8-5-private-dev,
1515 libunity-core-6.0-dev (<< 7.80),
16+ libunity-api-dev (>= 7.80.3),
1617 libunity-dev (>= 7.0.3),
1718 libusermetricsoutput1-dev,
1819 libxcb1-dev,
@@ -52,6 +53,8 @@ Depends: ${misc:Depends},
5253 unity-notifications-impl-1,
5354 qtdeclarative5-xmllistmodel-plugin,
5455 unity8-fake-env | qtubuntu-shell,
56+ unity8-private | unity-launcher-impl,
57+ unity-launcher-impl-2,
5558Recommends: ${unity-default-masterscopes},
5659 indicators-client-plugin-datetime (>= 0.6.1),
5760 indicators-client-plugin-messaging (>= 0.6.1),
@@ -67,6 +70,8 @@ Multi-Arch: same
6770Pre-Depends: ${misc:Pre-Depends}
6871Depends: ${misc:Depends},
6972 ${shlibs:Depends},
73+Provides: unity-launcher-impl,
74+ unity-launcher-impl-2
7075Description: Unity 8 private libs
7176 The Unity 8 shell is the primary user interface for Ubuntu devices.
7277 .
plugins/Unity/CMakeLists.txt+2−1
@@ -21,7 +21,6 @@ set(QMLPLUGIN_SRC
2121 categoryresults.cpp
2222 plugin.cpp
2323 bottombarvisibilitycommunicatorshell.cpp
24− launchermodel.cpp
2524 applicationpreview.cpp
2625 genericpreview.cpp
2726 moviepreview.cpp
@@ -49,3 +48,5 @@ qt5_use_modules(Unity-qml Qml)
4948
5049# export the qmldir and qmltypes files
5150export_qmlplugin(Unity 0.1 Unity TARGETS Unity-qml)
51+
52+add_subdirectory(Launcher)
plugins/Unity/Launcher/CMakeLists.txtnew file+27
@@ -0,0 +1,27 @@
1+include(FindPkgConfig)
2+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
3+
4+include_directories(
5+ ${CMAKE_CURRENT_SOURCE_DIR}
6+)
7+
8+set(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+
20+add_library(UnityLauncher-qml MODULE
21+ ${QMLLAUNCHERPLUGIN_SRC}
22+ )
23+
24+qt5_use_modules(UnityLauncher-qml Qml)
25+
26+# export the qmldir and qmltypes files
27+export_qmlplugin(Unity.Launcher 0.1 Unity/Launcher TARGETS UnityLauncher-qml)
plugins/Unity/Launcher/backend/launcherbackend.cppnew file+145
@@ -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+
24+LauncherBackend::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+
68+LauncherBackend::~LauncherBackend()
69+{
70+
71+}
72+
73+QStringList LauncherBackend::storedApplications() const
74+{
75+ return m_storedApps;
76+}
77+
78+void 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+
84+QString 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+
90+QString LauncherBackend::displayName(const QString &appId) const
91+{
92+ return m_displayNameMap.value(appId);
93+}
94+
95+QString LauncherBackend::icon(const QString &appId) const
96+{
97+ return m_iconMap.value(appId);
98+}
99+
100+bool 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+
107+void 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+
114+QList<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+
124+int 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+
132+int 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+
140+void 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+}
plugins/Unity/Launcher/backend/launcherbackend.hnew file+132
@@ -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+
32+class LauncherBackend : public QObject
33+{
34+ Q_OBJECT
35+
36+
37+public:
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+
121+Q_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+
126+private:
127+ QStringList m_storedApps;
128+ QHash<QString, QString> m_displayNameMap;
129+ QHash<QString, QString> m_iconMap;
130+};
131+
132+#endif // LAUNCHERBACKEND_H
plugins/Unity/Launcher/common/quicklistentry.cppnew file+54
@@ -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+
21+QuickListEntry::QuickListEntry()
22+{
23+
24+}
25+
26+QString QuickListEntry::actionId() const
27+{
28+ return m_actionId;
29+}
30+
31+void QuickListEntry::setActionId(const QString &actionId)
32+{
33+ m_actionId = actionId;
34+}
35+
36+QString QuickListEntry::text() const
37+{
38+ return m_text;
39+}
40+
41+void QuickListEntry::setText(const QString &text)
42+{
43+ m_text = text;
44+}
45+
46+QString QuickListEntry::icon() const
47+{
48+ return m_icon;
49+}
50+
51+void QuickListEntry::setIcon(const QString &icon)
52+{
53+ m_icon = icon;
54+}
plugins/Unity/Launcher/common/quicklistentry.hnew file+44
@@ -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+
24+class QuickListEntry
25+{
26+public:
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+
38+private:
39+ QString m_actionId;
40+ QString m_text;
41+ QString m_icon;
42+};
43+
44+#endif // QUICKLISTENTRY
plugins/Unity/Launcher/launcheritem.cppnew file+127
@@ -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+
23+LauncherItem::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+
39+QString LauncherItem::appId() const
40+{
41+ return m_appId;
42+}
43+
44+QString LauncherItem::desktopFile() const
45+{
46+ return m_desktopFile;
47+}
48+
49+QString LauncherItem::name() const
50+{
51+ return m_name;
52+}
53+
54+QString LauncherItem::icon() const
55+{
56+ return m_icon;
57+}
58+
59+bool LauncherItem::pinned() const
60+{
61+ return m_pinned;
62+}
63+
64+void LauncherItem::setPinned(bool pinned)
65+{
66+ if (m_pinned != pinned) {
67+ m_pinned = pinned;
68+ Q_EMIT pinnedChanged(pinned);
69+ }
70+}
71+
72+bool LauncherItem::running() const
73+{
74+ return m_running;
75+}
76+
77+void LauncherItem::setRunning(bool running)
78+{
79+ if (m_running != running) {
80+ m_running = running;
81+ Q_EMIT runningChanged(running);
82+ }
83+}
84+
85+bool LauncherItem::recent() const
86+{
87+ return m_recent;
88+}
89+
90+void LauncherItem::setRecent(bool recent)
91+{
92+ if (m_recent != recent) {
93+ m_recent = recent;
94+ Q_EMIT recentChanged(recent);
95+ }
96+}
97+
98+int LauncherItem::progress() const
99+{
100+ return m_progress;
101+}
102+
103+void LauncherItem::setProgress(int progress)
104+{
105+ if (m_progress != progress) {
106+ m_progress = progress;
107+ Q_EMIT progressChanged(progress);
108+ }
109+}
110+
111+int LauncherItem::count() const
112+{
113+ return m_count;
114+}
115+
116+void LauncherItem::setCount(int count)
117+{
118+ if (m_count != count) {
119+ m_count = count;
120+ Q_EMIT countChanged(count);
121+ }
122+}
123+
124+unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
125+{
126+ return m_quickList;
127+}
plugins/Unity/Launcher/launcheritem.hnew file+76
@@ -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+
27+class QuickListModel;
28+
29+using namespace unity::shell::launcher;
30+
31+class LauncherItem: public LauncherItemInterface
32+{
33+ Q_OBJECT
34+public:
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+
59+Q_SIGNALS:
60+ void favoriteChanged(bool favorite);
61+ void runningChanged(bool running);
62+
63+private:
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
plugins/Unity/Launcher/launchermodel.cppnew file+170
@@ -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+
24+LauncherModel::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+
43+LauncherModel::~LauncherModel()
44+{
45+ while (!m_list.empty()) {
46+ m_list.takeFirst()->deleteLater();
47+ }
48+}
49+
50+int LauncherModel::rowCount(const QModelIndex &parent) const
51+{
52+ Q_UNUSED(parent)
53+ return m_list.count();
54+}
55+
56+QVariant 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+
75+unity::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+
83+void 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+
95+void 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+
122+void 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+
136+void 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+
150+void 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+
161+int 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+}
plugins/Unity/Launcher/launchermodel.hnew file+61
@@ -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+
29+class LauncherItem;
30+class LauncherBackend;
31+
32+using namespace unity::shell::launcher;
33+
34+class LauncherModel: public LauncherModelInterface
35+{
36+ Q_OBJECT
37+
38+public:
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+
52+private:
53+ void storeAppList();
54+ int findApplication(const QString &appId);
55+
56+private:
57+ QList<LauncherItem*> m_list;
58+ LauncherBackend *m_backend;
59+};
60+
61+#endif // LAUNCHERMODEL_H
plugins/Unity/Launcher/plugin.cppnew file+47
@@ -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+
31+using namespace unity::shell::launcher;
32+
33+static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
34+{
35+ return new LauncherModel();
36+}
37+
38+void 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+}
plugins/Unity/Launcher/plugin.hnew file+34
@@ -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+
25+class UnityLauncherPlugin : public QQmlExtensionPlugin
26+{
27+ Q_OBJECT
28+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29+
30+public:
31+ void registerTypes(const char *uri);
32+};
33+
34+#endif
plugins/Unity/Launcher/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Unity.Launcher
2+plugin UnityLauncher-qml
plugins/Unity/Launcher/quicklistmodel.cppnew file+60
@@ -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+
22+QuickListModel::QuickListModel(QObject *parent) :
23+ QuickListModelInterface(parent)
24+{
25+
26+}
27+
28+QuickListModel::~QuickListModel()
29+{
30+
31+}
32+
33+void 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+
40+QuickListEntry QuickListModel::get(int index) const
41+{
42+ return m_list.at(index);
43+}
44+
45+int QuickListModel::rowCount(const QModelIndex &index) const
46+{
47+ Q_UNUSED(index)
48+ return m_list.count();
49+}
50+
51+QVariant 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+}
plugins/Unity/Launcher/quicklistmodel.hnew file+48
@@ -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+
27+using namespace unity::shell::launcher;
28+
29+class QuickListModel: public QuickListModelInterface
30+{
31+ Q_OBJECT
32+
33+public:
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+
44+private:
45+ QList<QuickListEntry> m_list;
46+};
47+
48+#endif // QUICKLISTMODEL_H
plugins/Unity/launchermodel.cppdeleted−153
@@ -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−
22−LauncherModel::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−
49−LauncherModel::~LauncherModel()
50−{
51− while (!m_list.empty()) {
52− m_list.takeFirst()->deleteLater();
53− }
54−}
55−
56−int LauncherModel::rowCount(const QModelIndex &parent) const
57−{
58− Q_UNUSED(parent)
59− return m_list.count();
60−}
61−
62−QVariant 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−
77−LauncherItem *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−
85−void LauncherModel::move(int oldIndex, int newIndex)
86−{
87− beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
88− m_list.move(oldIndex, newIndex);
89− endMoveRows();
90−}
91−
92−QHash<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−
104−LauncherItem::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−
114−QString LauncherItem::desktopFile() const
115−{
116− return m_desktopFile;
117−}
118−
119−QString LauncherItem::name() const
120−{
121− return m_name;
122−}
123−
124−QString LauncherItem::icon() const
125−{
126− return m_icon;
127−}
128−
129−bool LauncherItem::favorite() const
130−{
131− return m_favorite;
132−}
133−
134−void LauncherItem::setFavorite(bool favorite)
135−{
136− if (m_favorite != favorite) {
137− m_favorite = favorite;
138− Q_EMIT favoriteChanged(m_favorite);
139− }
140−}
141−
142−bool LauncherItem::running() const
143−{
144− return m_running;
145−}
146−
147−void LauncherItem::setRunning(bool running)
148−{
149− if (m_running != running) {
150− m_running = running;
151− Q_EMIT runningChanged(running);
152− }
153−}
plugins/Unity/launchermodel.hdeleted−86
@@ -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−
22−class LauncherItem;
23−
24−class LauncherModel: public QAbstractListModel
25−{
26− Q_OBJECT
27−
28−public:
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−
49−private:
50− QList<LauncherItem*> m_list;
51−};
52−
53−class 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−
62−public:
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−
76−Q_SIGNALS:
77− void favoriteChanged(bool favorite);
78− void runningChanged(bool running);
79−
80−private:
81− QString m_desktopFile;
82− QString m_name;
83− QString m_icon;
84− bool m_favorite;
85− bool m_running;
86−};
plugins/Unity/plugin.cpp−3
@@ -33,7 +33,6 @@
3333#include "categories.h"
3434#include "categoryresults.h"
3535#include "bottombarvisibilitycommunicatorshell.h"
36−#include "launchermodel.h"
3736
3837// libqtdee
3938#include "deelistmodel.h"
@@ -53,8 +52,6 @@ void UnityPlugin::registerTypes(const char *uri)
5352 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
5453 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
5554 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.");
5855 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
5956}
6057
tests/mocks/Unity/CMakeLists.txt+2−1
@@ -24,7 +24,6 @@ set(UnityQML_SOURCES
2424 fake_scopes.cpp
2525 fake_categories.cpp
2626 fake_unity_plugin.cpp
27− fake_launchermodel.cpp
2827)
2928
3029add_library(FakeUnityQml MODULE ${UnityQML_SOURCES})
@@ -41,3 +40,5 @@ qt5_use_modules(FakeUnityQml Qml)
4140file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/qmldir"
4241 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
4342 )
43+
44+add_subdirectory(Launcher)
tests/mocks/Unity/Launcher/CMakeLists.txtnew file+26
@@ -0,0 +1,26 @@
1+include(FindPkgConfig)
2+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
3+
4+include_directories(
5+ ${CMAKE_CURRENT_SOURCE_DIR}
6+)
7+
8+set(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+
18+add_library(MockLauncherPlugin MODULE ${MockLauncherModel_SOURCES})
19+
20+qt5_use_modules(MockLauncherPlugin Core Quick)
21+
22+# copy files into build directory for shadow builds
23+add_custom_target(LauncherPluginQmlDirFile ALL
24+ COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
25+ DEPENDS qmldir
26+)
tests/mocks/Unity/Launcher/MockLauncherItem.cppnew file+134
@@ -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+
23+using namespace unity::shell::launcher;
24+
25+MockLauncherItem::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+
41+QString MockLauncherItem::appId() const
42+{
43+ return m_appId;
44+}
45+
46+QString MockLauncherItem::desktopFile() const
47+{
48+ return m_desktopFile;
49+}
50+
51+QString MockLauncherItem::name() const
52+{
53+ return m_name;
54+}
55+
56+QString MockLauncherItem::icon() const
57+{
58+ return m_icon;
59+}
60+
61+bool MockLauncherItem::pinned() const
62+{
63+ return m_pinned;
64+}
65+
66+void MockLauncherItem::setPinned(bool pinned)
67+{
68+ if (m_pinned != pinned)
69+ {
70+ m_pinned = pinned;
71+ Q_EMIT pinnedChanged(m_pinned);
72+ }
73+}
74+
75+bool MockLauncherItem::running() const
76+{
77+ return m_running;
78+}
79+
80+void MockLauncherItem::setRunning(bool running)
81+{
82+ if (m_running != running)
83+ {
84+ m_running = running;
85+ Q_EMIT runningChanged(running);
86+ }
87+}
88+
89+bool MockLauncherItem::recent() const
90+{
91+ return m_recent;
92+}
93+
94+void MockLauncherItem::setRecent(bool recent)
95+{
96+ if (m_recent != recent)
97+ {
98+ m_recent = recent;
99+ Q_EMIT recentChanged(recent);
100+ }
101+}
102+
103+int MockLauncherItem::progress() const
104+{
105+ return m_progress;
106+}
107+
108+void MockLauncherItem::setProgress(int progress)
109+{
110+ if (m_progress != progress)
111+ {
112+ m_progress = progress;
113+ Q_EMIT progressChanged(progress);
114+ }
115+}
116+
117+int MockLauncherItem::count() const
118+{
119+ return m_count;
120+}
121+
122+void MockLauncherItem::setCount(int count)
123+{
124+ if (m_count != count)
125+ {
126+ m_count = count;
127+ Q_EMIT countChanged(count);
128+ }
129+}
130+
131+unity::shell::launcher::QuickListModelInterface *MockLauncherItem::quickList() const
132+{
133+ return m_quickList;
134+}
tests/mocks/Unity/Launcher/MockLauncherItem.hnew file+70
@@ -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+
25+class MockQuickListModel;
26+
27+using namespace unity::shell::launcher;
28+
29+class MockLauncherItem: public LauncherItemInterface
30+{
31+ Q_OBJECT
32+public:
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+
57+private:
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
tests/mocks/Unity/Launcher/MockLauncherModel.cppnew file+152
@@ -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+
23+MockLauncherModel::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+
47+MockLauncherModel::~MockLauncherModel()
48+{
49+ while (!m_list.empty())
50+ {
51+ m_list.takeFirst()->deleteLater();
52+ }
53+}
54+
55+int MockLauncherModel::rowCount(const QModelIndex& parent) const
56+{
57+ Q_UNUSED(parent)
58+ return m_list.count();
59+}
60+
61+QVariant 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+
87+unity::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+
96+void MockLauncherModel::move(int oldIndex, int newIndex)
97+{
98+ beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
99+ m_list.move(oldIndex, newIndex);
100+ endMoveRows();
101+}
102+
103+void 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+
126+void 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+
136+void MockLauncherModel::quickListActionInvoked(const QString &appId, int actionIndex)
137+{
138+ Q_UNUSED(appId)
139+ Q_UNUSED(actionIndex)
140+ // Nothing to mock yet...
141+}
142+
143+int 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+}
tests/mocks/Unity/Launcher/MockLauncherModel.hnew file+54
@@ -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+
25+class MockLauncherItem;
26+
27+using namespace unity::shell::launcher;
28+
29+class MockLauncherModel: public LauncherModelInterface
30+{
31+ Q_OBJECT
32+
33+public:
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+
47+private:
48+ int findApp(const QString &appId);
49+
50+private:
51+ QList<MockLauncherItem*> m_list;
52+};
53+
54+#endif // MOCKLAUNCHERMODEL_H
tests/mocks/Unity/Launcher/MockQuickListModel.cppnew file+46
@@ -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+
22+using namespace unity::shell::launcher;
23+
24+MockQuickListModel::MockQuickListModel(QObject *parent) :
25+ QuickListModelInterface(parent)
26+{
27+
28+}
29+
30+QVariant 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+
42+int MockQuickListModel::rowCount(const QModelIndex &parent) const
43+{
44+ Q_UNUSED(parent)
45+ return 4;
46+}
tests/mocks/Unity/Launcher/MockQuickListModel.hnew file+38
@@ -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+
25+using namespace unity::shell::launcher;
26+
27+class MockQuickListModel: public QuickListModelInterface
28+{
29+ Q_OBJECT
30+public:
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
tests/mocks/Unity/Launcher/plugin.cppnew file+45
@@ -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+
29+using namespace unity::shell::launcher;
30+
31+static QObject* modelProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
32+{
33+ return new MockLauncherModel();
34+}
35+
36+// cppcheck-suppress unusedFunction
37+void 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+}
tests/mocks/Unity/Launcher/plugin.hnew file+35
@@ -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+
26+class TestLauncherPlugin : public QQmlExtensionPlugin
27+{
28+ Q_OBJECT
29+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
30+
31+public:
32+ void registerTypes(const char* uri);
33+};
34+
35+#endif // TESTLAUNCHER_PLUGIN_H
tests/mocks/Unity/Launcher/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Unity.Launcher
2+plugin MockLauncherPlugin
tests/mocks/Unity/fake_launchermodel.cppdeleted−150
@@ -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−
22−LauncherModel::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−
46−LauncherModel::~LauncherModel()
47−{
48− while (!m_list.empty()) {
49− m_list.takeFirst()->deleteLater();
50− }
51−}
52−
53−int LauncherModel::rowCount(const QModelIndex &parent) const
54−{
55− Q_UNUSED(parent)
56− return m_list.count();
57−}
58−
59−QVariant 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−
74−LauncherItem *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−
82−void LauncherModel::move(int oldIndex, int newIndex)
83−{
84− beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
85− m_list.move(oldIndex, newIndex);
86− endMoveRows();
87−}
88−
89−QHash<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−
101−LauncherItem::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−
111−QString LauncherItem::desktopFile() const
112−{
113− return m_desktopFile;
114−}
115−
116−QString LauncherItem::name() const
117−{
118− return m_name;
119−}
120−
121−QString LauncherItem::icon() const
122−{
123− return m_icon;
124−}
125−
126−bool LauncherItem::favorite() const
127−{
128− return m_favorite;
129−}
130−
131−void LauncherItem::setFavorite(bool favorite)
132−{
133− if (m_favorite != favorite) {
134− m_favorite = favorite;
135− Q_EMIT favoriteChanged(m_favorite);
136− }
137−}
138−
139−bool LauncherItem::running() const
140−{
141− return m_running;
142−}
143−
144−void LauncherItem::setRunning(bool running)
145−{
146− if (m_running != running) {
147− m_running = running;
148− Q_EMIT runningChanged(running);
149− }
150−}
tests/mocks/Unity/fake_launchermodel.hdeleted−86
@@ -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−
22−class LauncherItem;
23−
24−class LauncherModel: public QAbstractListModel
25−{
26− Q_OBJECT
27−
28−public:
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−
49−private:
50− QList<LauncherItem*> m_list;
51−};
52−
53−class 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−
62−public:
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−
76−Q_SIGNALS:
77− void favoriteChanged(bool favorite);
78− void runningChanged(bool running);
79−
80−private:
81− QString m_desktopFile;
82− QString m_name;
83− QString m_icon;
84− bool m_favorite;
85− bool m_running;
86−};
tests/mocks/Unity/fake_unity_plugin.cpp−3
@@ -23,7 +23,6 @@
2323#include "fake_scopes.h"
2424#include "fake_categories.h"
2525#include "categoryresults.h"
26−#include "fake_launchermodel.h"
2726
2827// External
2928#include <glib-object.h>
@@ -41,6 +40,4 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4140 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
4241 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
4342 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");
4643}