on xenial help sign in
update to next, upcoming version of unity-api
4ecd038Michael Zanetti
plugins/Unity/Launcher/CMakeLists.txt+3
@@ -12,9 +12,12 @@ set(QMLLAUNCHERPLUGIN_SRC
12 plugin.cpp
12 plugin.cpp
13 launchermodel.cpp
13 launchermodel.cpp
14 launcheritem.cpp
14 launcheritem.cpp
15+ quicklistmodel.cpp
16+ common/quicklistentry.cpp
15 backend/launcherbackend.cpp
17 backend/launcherbackend.cpp
16 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
18 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
17 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
19 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
20+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
18 )
21 )
19
22
20add_library(UnityLauncher-qml MODULE
23add_library(UnityLauncher-qml MODULE
plugins/Unity/Launcher/backend/launcherbackend.cpp+19−3
@@ -99,24 +99,32 @@ QString LauncherBackend::icon(const QString &appId) const
99bool LauncherBackend::isPinned(const QString &appId) const
99bool LauncherBackend::isPinned(const QString &appId) const
100{
100{
101 // TODO: return app's pinned state from settings
101 // TODO: return app's pinned state from settings
102+ Q_UNUSED(appId)
102 return true;
103 return true;
103}
104}
104
105
105void LauncherBackend::setPinned(const QString &appId, bool pinned)
106void LauncherBackend::setPinned(const QString &appId, bool pinned)
106{
107{
107 // TODO: Store pinned state in settings.
108 // TODO: Store pinned state in settings.
109+ Q_UNUSED(appId)
110+ Q_UNUSED(pinned)
108}
111}
109
112
110−QuickListModelInterface* LauncherBackend::quickList(const QString &appId) const
113+QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
111{
114{
112− // TODO: No clue where to get the quicklist from, but this is the place to return it.
115+ // TODO: Get static (from .desktop file) and dynamic (from the app itself)
113− return 0;
116+ // entries and return them here. Frontend related entries (like "Pin to launcher")
117+ // don't matter here. This is just the backend part.
118+ // TODO: emit quickListChanged() when the dynamic part changes
119+ Q_UNUSED(appId)
120+ return QList<QuickListEntry>();
114}
121}
115
122
116int LauncherBackend::progress(const QString &appId) const
123int LauncherBackend::progress(const QString &appId) const
117{
124{
118 // TODO: Return value for progress emblem.
125 // TODO: Return value for progress emblem.
119 // TODO: emit progressChanged() when this value changes.
126 // TODO: emit progressChanged() when this value changes.
127+ Q_UNUSED(appId)
120 return -1;
128 return -1;
121}
129}
122
130
@@ -124,5 +132,13 @@ int LauncherBackend::count(const QString &appId) const
124{
132{
125 // TODO: Return value for count emblem.
133 // TODO: Return value for count emblem.
126 // TODO: emit countChanged() when this value changes.
134 // TODO: emit countChanged() when this value changes.
135+ Q_UNUSED(appId)
127 return 0;
136 return 0;
128}
137}
138+
139+void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
140+{
141+ // TODO: execute the given quicklist action
142+ Q_UNUSED(appId)
143+ Q_UNUSED(quickListId)
144+}
plugins/Unity/Launcher/backend/launcherbackend.h+11−3
@@ -19,11 +19,11 @@
19#ifndef LAUNCHERBACKEND_H
19#ifndef LAUNCHERBACKEND_H
20#define LAUNCHERBACKEND_H
20#define LAUNCHERBACKEND_H
21
21
22+#include "common/quicklistentry.h"
23+
22#include <QObject>
24#include <QObject>
23#include <QStringList>
25#include <QStringList>
24
26
25−class QuickListModelInterface;
26−
27/**
27/**
28 * @brief An interface that provides all the data needed by the launcher.
28 * @brief An interface that provides all the data needed by the launcher.
29 */
29 */
@@ -94,7 +94,14 @@ public:
94 * @param appId The ID of the application.
94 * @param appId The ID of the application.
95 * @returns A QuickListModelInterface containing the QuickList.
95 * @returns A QuickListModelInterface containing the QuickList.
96 */
96 */
97− QuickListModelInterface* quickList(const QString &appId) const;
97+ QList<QuickListEntry> quickList(const QString &appId) const;
98+
99+ /**
100+ * @brief Execute an action from the quickList
101+ * @param appId The app ID for which the action was triggered
102+ * @param the quicklist ID of the action that was triggered
103+ */
104+ void triggerQuickListAction(const QString &appId, const QString &entryId);
98
105
99 /**
106 /**
100 * @brief Get the progress for the progress overlay of an application.
107 * @brief Get the progress for the progress overlay of an application.
@@ -111,6 +118,7 @@ public:
111 int count(const QString &appId) const;
118 int count(const QString &appId) const;
112
119
113Q_SIGNALS:
120Q_SIGNALS:
121+ void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
114 void progressChanged(const QString &appId, int progress);
122 void progressChanged(const QString &appId, int progress);
115 void countChanged(const QString &appId, int count);
123 void countChanged(const QString &appId, int count);
116
124
plugins/Unity/Launcher/backend/quicklistmodel.hdeleted−63
@@ -1,63 +0,0 @@
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 QUICKLISTMODEL_H
20−#define QUICKLISTMODEL_H
21−
22−/**
23− * @brief A model containing QuickList actions for an application in the launcher.
24− *
25− * @description The model has the following roles:
26− * - RoleLabel: The text entry in the QuickList menu (QString).
27− * - RoleIcon: The icon to be shown for this entry (QString).
28− * - RoleCheckable: Wether the item is checkable or not (bool).
29− * - RoleGroup: A group this item is in. Items in the same group are exclusive (int). -1 for no group.
30− */
31−class QuickListModelInterface: public QAbstractListModel
32−{
33− Q_OBJECT
34−
35−protected:
36− /// @cond
37− explicit QuickListModelInterface(QObject *parent = 0) : QAbstractListModel(parent) {}
38− /// @endcond
39−public:
40− enum Roles {
41− RoleLabel,
42− RoleIcon,
43− RoleCheckable,
44− RoleGroup
45− }
46−
47− /// @cond
48− virtual ~QuickListModelInterface() {}
49− /// @endcond
50−
51− /// @cond
52− QHash<int, QByteArray> roleNames() const {
53− QHash<int, QByteArray> roles;
54− roles.insert(RoleText, "label");
55− roles.insert(RoleIcon, "icon");
56− roles.insert(RoleCheckable, "checkable");
57− roles.insert(RoleGroup, "group");
58− }
59− /// @endcond
60−
61−}
62−
63−#endif // QUICKLISTMODE_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.cpp+15−8
@@ -18,6 +18,7 @@
18 */
18 */
19
19
20#include "launcheritem.h"
20#include "launcheritem.h"
21+#include "quicklistmodel.h"
21
22
22LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent) :
23LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent) :
23 LauncherItemInterface(parent),
24 LauncherItemInterface(parent),
@@ -25,11 +26,12 @@ LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, con
25 m_desktopFile(desktopFile),
26 m_desktopFile(desktopFile),
26 m_name(name),
27 m_name(name),
27 m_icon(icon),
28 m_icon(icon),
28− m_favorite(false),
29+ m_pinned(false),
29 m_running(false),
30 m_running(false),
30 m_recent(false),
31 m_recent(false),
31 m_progress(-1),
32 m_progress(-1),
32− m_count(0)
33+ m_count(0),
34+ m_quickList(new QuickListModel(this))
33{
35{
34
36
35}
37}
@@ -54,16 +56,16 @@ QString LauncherItem::icon() const
54 return m_icon;
56 return m_icon;
55}
57}
56
58
57−bool LauncherItem::favorite() const
59+bool LauncherItem::pinned() const
58{
60{
59− return m_favorite;
61+ return m_pinned;
60}
62}
61
63
62−void LauncherItem::setFavorite(bool favorite)
64+void LauncherItem::setPinned(bool pinned)
63{
65{
64− if (m_favorite != favorite) {
66+ if (m_pinned != pinned) {
65− m_favorite = favorite;
67+ m_pinned = pinned;
66− Q_EMIT favoriteChanged(favorite);
68+ Q_EMIT pinnedChanged(pinned);
67 }
69 }
68}
70}
69
71
@@ -118,3 +120,8 @@ void LauncherItem::setCount(int count)
118 Q_EMIT countChanged(count);
120 Q_EMIT countChanged(count);
119 }
121 }
120}
122}
123+
124+unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
125+{
126+ return m_quickList;
127+}
plugins/Unity/Launcher/launcheritem.h+10−3
@@ -20,8 +20,12 @@
20#ifndef LAUNCHERITEM_H
20#ifndef LAUNCHERITEM_H
21#define LAUNCHERITEM_H
21#define LAUNCHERITEM_H
22
22
23+#include "quicklistmodel.h"
24+
23#include <unity/shell/launcher/LauncherItemInterface.h>
25#include <unity/shell/launcher/LauncherItemInterface.h>
24
26
27+class QuickListModel;
28+
25using namespace unity::shell::launcher;
29using namespace unity::shell::launcher;
26
30
27class LauncherItem: public LauncherItemInterface
31class LauncherItem: public LauncherItemInterface
@@ -37,8 +41,8 @@ public:
37 QString name() const;
41 QString name() const;
38 QString icon() const;
42 QString icon() const;
39
43
40− bool favorite() const;
44+ bool pinned() const;
41− void setFavorite(bool favorite);
45+ void setPinned(bool pinned);
42
46
43 bool running() const;
47 bool running() const;
44 void setRunning(bool running);
48 void setRunning(bool running);
@@ -52,6 +56,8 @@ public:
52 int count() const;
56 int count() const;
53 void setCount(int count);
57 void setCount(int count);
54
58
59+ unity::shell::launcher::QuickListModelInterface *quickList() const;
60+
55Q_SIGNALS:
61Q_SIGNALS:
56 void favoriteChanged(bool favorite);
62 void favoriteChanged(bool favorite);
57 void runningChanged(bool running);
63 void runningChanged(bool running);
@@ -61,11 +67,12 @@ private:
61 QString m_desktopFile;
67 QString m_desktopFile;
62 QString m_name;
68 QString m_name;
63 QString m_icon;
69 QString m_icon;
64− bool m_favorite;
70+ bool m_pinned;
65 bool m_running;
71 bool m_running;
66 bool m_recent;
72 bool m_recent;
67 int m_progress;
73 int m_progress;
68 int m_count;
74 int m_count;
75+ QuickListModel *m_quickList;
69};
76};
70
77
71#endif // LAUNCHERITEM_H
78#endif // LAUNCHERITEM_H
plugins/Unity/Launcher/launchermodel.cpp+17−7
@@ -32,7 +32,7 @@ LauncherModel::LauncherModel(QObject *parent):
32 m_backend->icon(entry),
32 m_backend->icon(entry),
33 this);
33 this);
34 if (m_backend->isPinned(entry)) {
34 if (m_backend->isPinned(entry)) {
35− item->setFavorite(true);
35+ item->setPinned(true);
36 } else {
36 } else {
37 item->setRecent(true);
37 item->setRecent(true);
38 }
38 }
@@ -63,8 +63,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
63 return item->name();
63 return item->name();
64 case RoleIcon:
64 case RoleIcon:
65 return item->icon();
65 return item->icon();
66− case RoleFavorite:
66+ case RolePinned:
67− return item->favorite();
67+ return item->pinned();
68 }
68 }
69
69
70 return QVariant();
70 return QVariant();
@@ -93,9 +93,9 @@ void LauncherModel::move(int oldIndex, int newIndex)
93void LauncherModel::pin(int index)
93void LauncherModel::pin(int index)
94{
94{
95 LauncherItem *item = m_list.at(index);
95 LauncherItem *item = m_list.at(index);
96− if (!item->favorite()) {
96+ if (!item->pinned()) {
97
97
98− item->setFavorite(true);
98+ item->setPinned(true);
99 item->setRecent(false);
99 item->setRecent(false);
100
100
101 m_backend->setPinned(item->appId(), true);
101 m_backend->setPinned(item->appId(), true);
@@ -116,13 +116,23 @@ void LauncherModel::remove(int index)
116 storeAppList();
116 storeAppList();
117}
117}
118
118
119+void LauncherModel::triggerQuickListAction(int itemIndex, int quickListIndex)
120+{
121+ QString appId = m_list.at(itemIndex)->appId();
122+ QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(itemIndex)->quickList());
123+ if (model) {
124+ QString actionId = model->get(quickListIndex).actionId();
125+ m_backend->triggerQuickListAction(appId, actionId);
126+ }
127+}
128+
119QHash<int, QByteArray> LauncherModel::roleNames() const
129QHash<int, QByteArray> LauncherModel::roleNames() const
120{
130{
121 QHash<int, QByteArray> roles;
131 QHash<int, QByteArray> roles;
122 roles.insert(RoleDesktopFile, "desktopFile");
132 roles.insert(RoleDesktopFile, "desktopFile");
123 roles.insert(RoleName, "name");
133 roles.insert(RoleName, "name");
124 roles.insert(RoleIcon, "icon");
134 roles.insert(RoleIcon, "icon");
125− roles.insert(RoleFavorite, "favorite");
135+ roles.insert(RolePinned, "pinned");
126 roles.insert(RoleRunning, "runnng");
136 roles.insert(RoleRunning, "runnng");
127 return roles;
137 return roles;
128}
138}
@@ -131,7 +141,7 @@ void LauncherModel::storeAppList()
131{
141{
132 QStringList appIds;
142 QStringList appIds;
133 Q_FOREACH(LauncherItem *item, m_list) {
143 Q_FOREACH(LauncherItem *item, m_list) {
134− if (item->favorite() || item->recent()) {
144+ if (item->pinned() || item->recent()) {
135 appIds << item->appId();
145 appIds << item->appId();
136 }
146 }
137 }
147 }
plugins/Unity/Launcher/launchermodel.h+1
@@ -47,6 +47,7 @@ public:
47 Q_INVOKABLE void move(int oldIndex, int newIndex);
47 Q_INVOKABLE void move(int oldIndex, int newIndex);
48 Q_INVOKABLE void pin(int index);
48 Q_INVOKABLE void pin(int index);
49 Q_INVOKABLE void remove(int index);
49 Q_INVOKABLE void remove(int index);
50+ Q_INVOKABLE void triggerQuickListAction(int itemIndex, int quickListIndex);
50
51
51 QHash<int, QByteArray> roleNames() const;
52 QHash<int, QByteArray> roleNames() const;
52
53
plugins/Unity/Launcher/quicklistmodel.cppnew file+40
@@ -0,0 +1,40 @@
1+#include "quicklistmodel.h"
2+
3+QuickListModel::QuickListModel(QObject *parent) :
4+ QuickListModelInterface(parent)
5+{
6+
7+}
8+
9+QuickListModel::~QuickListModel()
10+{
11+
12+}
13+
14+void QuickListModel::appendAction(const QuickListEntry &entry)
15+{
16+ beginInsertRows(QModelIndex(), m_list.count() - 1, m_list.count() -1);
17+ m_list.append(entry);
18+ endInsertRows();
19+}
20+
21+QuickListEntry QuickListModel::get(int index) const
22+{
23+ return m_list.at(index);
24+}
25+
26+int QuickListModel::rowCount(const QModelIndex &index) const
27+{
28+ return m_list.count();
29+}
30+
31+QVariant QuickListModel::data(const QModelIndex &index, int role) const
32+{
33+ switch (role) {
34+ case RoleLabel:
35+ return m_list.at(index.row()).text();
36+ case RoleIcon:
37+ return m_list.at(index.row()).icon();
38+ }
39+ return QVariant();
40+}
plugins/Unity/Launcher/quicklistmodel.hnew file+47
@@ -0,0 +1,47 @@
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 QUICKLISTMODEL_H
20+#define QUICKLISTMODEL_H
21+
22+#include "common/quicklistentry.h"
23+
24+#include <unity/shell/launcher/QuickListModelInterface.h>
25+
26+using namespace unity::shell::launcher;
27+
28+class QuickListModel: public QuickListModelInterface
29+{
30+ Q_OBJECT
31+
32+public:
33+ explicit QuickListModel(QObject *parent = 0);
34+
35+ ~QuickListModel();
36+
37+ void appendAction(const QuickListEntry &entry);
38+ QuickListEntry get(int index) const;
39+
40+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
41+ QVariant data(const QModelIndex &index, int role) const;
42+
43+private:
44+ QList<QuickListEntry> m_list;
45+};
46+
47+#endif // QUICKLISTMODEL_H
tests/mocks/Unity/Launcher/CMakeLists.txtnew file+40
@@ -0,0 +1,40 @@
1+set(CMAKE_AUTOMOC ON)
2+
3+include(FindPkgConfig)
4+find_package(Qt5Core REQUIRED)
5+find_package(Qt5Quick REQUIRED)
6+
7+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher)
8+
9+include_directories(
10+ ${CMAKE_CURRENT_SOURCE_DIR}
11+ ${LAUNCHER_API_INCLUDEDIR}
12+)
13+
14+set(MockLauncherModel_SOURCES
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+ plugin.cpp
19+ MockLauncherModel.cpp
20+ MockLauncherItem.cpp
21+ MockQuickListModel.cpp
22+)
23+
24+add_library(MockLauncherPlugin MODULE ${MockLauncherModel_SOURCES})
25+
26+qt5_use_modules(MockLauncherPlugin Core Quick)
27+
28+# copy files into build directory for shadow builds
29+add_custom_target(LauncherPluginQmlDirFile ALL
30+ COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" ${CMAKE_CURRENT_BINARY_DIR}
31+ DEPENDS qmldir
32+)
33+
34+install(TARGETS MockLauncherPlugin
35+ DESTINATION ${SHELL_APP_DIR}/plugins/mocks/Unity/Launcher
36+ )
37+
38+install(FILES qmldir
39+ DESTINATION ${SHELL_APP_DIR}/plugins/mocks/Unity/Launcher
40+ )
tests/mocks/Unity/Launcher/MockLauncherItem.cppnew file+128
@@ -0,0 +1,128 @@
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& desktopFile, const QString& name, const QString& icon, QObject* parent):
26+ LauncherItemInterface(parent),
27+ m_desktopFile(desktopFile),
28+ m_name(name),
29+ m_icon(icon),
30+ m_pinned(false),
31+ m_running(false),
32+ m_recent(false),
33+ m_progress(8),
34+ m_count(8),
35+ m_quickList(new MockQuickListModel(this))
36+{
37+
38+}
39+
40+QString MockLauncherItem::desktopFile() const
41+{
42+ return m_desktopFile;
43+}
44+
45+QString MockLauncherItem::name() const
46+{
47+ return m_name;
48+}
49+
50+QString MockLauncherItem::icon() const
51+{
52+ return m_icon;
53+}
54+
55+bool MockLauncherItem::pinned() const
56+{
57+ return m_pinned;
58+}
59+
60+void MockLauncherItem::setPinned(bool pinned)
61+{
62+ if (m_pinned != pinned)
63+ {
64+ m_pinned = pinned;
65+ Q_EMIT pinnedChanged(m_pinned);
66+ }
67+}
68+
69+bool MockLauncherItem::running() const
70+{
71+ return m_running;
72+}
73+
74+void MockLauncherItem::setRunning(bool running)
75+{
76+ if (m_running != running)
77+ {
78+ m_running = running;
79+ Q_EMIT runningChanged(running);
80+ }
81+}
82+
83+bool MockLauncherItem::recent() const
84+{
85+ return m_recent;
86+}
87+
88+void MockLauncherItem::setRecent(bool recent)
89+{
90+ if (m_recent != recent)
91+ {
92+ m_recent = recent;
93+ Q_EMIT recentChanged(recent);
94+ }
95+}
96+
97+int MockLauncherItem::progress() const
98+{
99+ return m_progress;
100+}
101+
102+void MockLauncherItem::setProgress(int progress)
103+{
104+ if (m_progress != progress)
105+ {
106+ m_progress = progress;
107+ Q_EMIT progressChanged(progress);
108+ }
109+}
110+
111+int MockLauncherItem::count() const
112+{
113+ return m_count;
114+}
115+
116+void MockLauncherItem::setCount(int count)
117+{
118+ if (m_count != count)
119+ {
120+ m_count = count;
121+ Q_EMIT countChanged(count);
122+ }
123+}
124+
125+unity::shell::launcher::QuickListModelInterface *MockLauncherItem::quickList() const
126+{
127+ return m_quickList;
128+}
tests/mocks/Unity/Launcher/MockLauncherItem.hnew file+69
@@ -0,0 +1,69 @@
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& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
34+
35+ QString desktopFile() const;
36+
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_desktopFile;
59+ QString m_name;
60+ QString m_icon;
61+ bool m_pinned;
62+ bool m_running;
63+ bool m_recent;
64+ int m_progress;
65+ int m_count;
66+ MockQuickListModel *m_quickList;
67+};
68+
69+#endif // MOCKLAUNCHERITEM_H
tests/mocks/Unity/Launcher/MockLauncherModel.cppnew file+122
@@ -0,0 +1,122 @@
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("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
26+ m_list.append(item);
27+ item = new MockLauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
28+ m_list.append(item);
29+ item = new MockLauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
30+ m_list.append(item);
31+ item = new MockLauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
32+ m_list.append(item);
33+ item = new MockLauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
34+ m_list.append(item);
35+ item = new MockLauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
36+ m_list.append(item);
37+ item = new MockLauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
38+ m_list.append(item);
39+ item = new MockLauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
40+ m_list.append(item);
41+ item = new MockLauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
42+ m_list.append(item);
43+ item = new MockLauncherItem("/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(int index)
104+{
105+ m_list.at(index)->setPinned(true);
106+ QModelIndex modelIndex = this->index(index);
107+ Q_EMIT dataChanged(modelIndex, modelIndex);
108+}
109+
110+void MockLauncherModel::remove(int index)
111+{
112+ beginRemoveRows(QModelIndex(), index, 0);
113+ m_list.takeAt(index)->deleteLater();
114+ endRemoveRows();
115+}
116+
117+void MockLauncherModel::triggerQuickListAction(int itemIndex, int quickListIndex)
118+{
119+ Q_UNUSED(itemIndex)
120+ Q_UNUSED(quickListIndex)
121+ // Nothing to mock yet...
122+}
tests/mocks/Unity/Launcher/MockLauncherModel.hnew file+51
@@ -0,0 +1,51 @@
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(int index);
44+ Q_INVOKABLE void remove(int index);
45+ Q_INVOKABLE void triggerQuickListAction(int itemIndex, int quickListIndex);
46+
47+private:
48+ QList<MockLauncherItem*> m_list;
49+};
50+
51+#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