on xenial help sign in
update to next, upcoming version of unity-api
commit4ecd038dfb829cc0796dac2e82f553020e6a0763 authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 5 Jul 2013, 13:25 (13 years ago) parent3114d70
22 files changed+837−87
plugins/Unity/Launcher/CMakeLists.txt+3 plugins/Unity/Launcher/backend/launcherbackend.cpp+19−3 plugins/Unity/Launcher/backend/launcherbackend.h+11−3 plugins/Unity/Launcher/backend/quicklistmodel.h−63 plugins/Unity/Launcher/common/quicklistentry.cpp+54 plugins/Unity/Launcher/common/quicklistentry.h+44 plugins/Unity/Launcher/launcheritem.cpp+15−8 plugins/Unity/Launcher/launcheritem.h+10−3 plugins/Unity/Launcher/launchermodel.cpp+17−7 plugins/Unity/Launcher/launchermodel.h+1 plugins/Unity/Launcher/quicklistmodel.cpp+40 plugins/Unity/Launcher/quicklistmodel.h+47 tests/mocks/Unity/Launcher/CMakeLists.txt+40 tests/mocks/Unity/Launcher/MockLauncherItem.cpp+128 tests/mocks/Unity/Launcher/MockLauncherItem.h+69 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+122 tests/mocks/Unity/Launcher/MockLauncherModel.h+51 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
plugins/Unity/Launcher/CMakeLists.txt+3
@@ -12,9 +12,12 @@ set(QMLLAUNCHERPLUGIN_SRC
1212 plugin.cpp
1313 launchermodel.cpp
1414 launcheritem.cpp
15+ quicklistmodel.cpp
16+ common/quicklistentry.cpp
1517 backend/launcherbackend.cpp
1618 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
1719 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
20+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
1821 )
1922
2023add_library(UnityLauncher-qml MODULE
plugins/Unity/Launcher/backend/launcherbackend.cpp+19−3
@@ -99,24 +99,32 @@ QString LauncherBackend::icon(const QString &appId) const
9999bool LauncherBackend::isPinned(const QString &appId) const
100100{
101101 // TODO: return app's pinned state from settings
102+ Q_UNUSED(appId)
102103 return true;
103104}
104105
105106void LauncherBackend::setPinned(const QString &appId, bool pinned)
106107{
107108 // TODO: Store pinned state in settings.
109+ Q_UNUSED(appId)
110+ Q_UNUSED(pinned)
108111}
109112
110−QuickListModelInterface* LauncherBackend::quickList(const QString &appId) const
113+QList<QuickListEntry> LauncherBackend::quickList(const QString &appId) const
111114{
112− // TODO: No clue where to get the quicklist from, but this is the place to return it.
113− return 0;
115+ // TODO: Get static (from .desktop file) and dynamic (from the app itself)
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>();
114121}
115122
116123int LauncherBackend::progress(const QString &appId) const
117124{
118125 // TODO: Return value for progress emblem.
119126 // TODO: emit progressChanged() when this value changes.
127+ Q_UNUSED(appId)
120128 return -1;
121129}
122130
@@ -124,5 +132,13 @@ int LauncherBackend::count(const QString &appId) const
124132{
125133 // TODO: Return value for count emblem.
126134 // TODO: emit countChanged() when this value changes.
135+ Q_UNUSED(appId)
127136 return 0;
128137}
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 @@
1919#ifndef LAUNCHERBACKEND_H
2020#define LAUNCHERBACKEND_H
2121
22+#include "common/quicklistentry.h"
23+
2224#include <QObject>
2325#include <QStringList>
2426
25−class QuickListModelInterface;
26−
2727/**
2828 * @brief An interface that provides all the data needed by the launcher.
2929 */
@@ -94,7 +94,14 @@ public:
9494 * @param appId The ID of the application.
9595 * @returns A QuickListModelInterface containing the QuickList.
9696 */
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);
98105
99106 /**
100107 * @brief Get the progress for the progress overlay of an application.
@@ -111,6 +118,7 @@ public:
111118 int count(const QString &appId) const;
112119
113120Q_SIGNALS:
121+ void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
114122 void progressChanged(const QString &appId, int progress);
115123 void countChanged(const QString &appId, int count);
116124
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 @@
1818 */
1919
2020#include "launcheritem.h"
21+#include "quicklistmodel.h"
2122
2223LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent) :
2324 LauncherItemInterface(parent),
@@ -25,11 +26,12 @@ LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, con
2526 m_desktopFile(desktopFile),
2627 m_name(name),
2728 m_icon(icon),
28− m_favorite(false),
29+ m_pinned(false),
2930 m_running(false),
3031 m_recent(false),
3132 m_progress(-1),
32− m_count(0)
33+ m_count(0),
34+ m_quickList(new QuickListModel(this))
3335{
3436
3537}
@@ -54,16 +56,16 @@ QString LauncherItem::icon() const
5456 return m_icon;
5557}
5658
57−bool LauncherItem::favorite() const
59+bool LauncherItem::pinned() const
5860{
59− return m_favorite;
61+ return m_pinned;
6062}
6163
62−void LauncherItem::setFavorite(bool favorite)
64+void LauncherItem::setPinned(bool pinned)
6365{
64− if (m_favorite != favorite) {
65− m_favorite = favorite;
66− Q_EMIT favoriteChanged(favorite);
66+ if (m_pinned != pinned) {
67+ m_pinned = pinned;
68+ Q_EMIT pinnedChanged(pinned);
6769 }
6870}
6971
@@ -118,3 +120,8 @@ void LauncherItem::setCount(int count)
118120 Q_EMIT countChanged(count);
119121 }
120122}
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 @@
2020#ifndef LAUNCHERITEM_H
2121#define LAUNCHERITEM_H
2222
23+#include "quicklistmodel.h"
24+
2325#include <unity/shell/launcher/LauncherItemInterface.h>
2426
27+class QuickListModel;
28+
2529using namespace unity::shell::launcher;
2630
2731class LauncherItem: public LauncherItemInterface
@@ -37,8 +41,8 @@ public:
3741 QString name() const;
3842 QString icon() const;
3943
40− bool favorite() const;
41− void setFavorite(bool favorite);
44+ bool pinned() const;
45+ void setPinned(bool pinned);
4246
4347 bool running() const;
4448 void setRunning(bool running);
@@ -52,6 +56,8 @@ public:
5256 int count() const;
5357 void setCount(int count);
5458
59+ unity::shell::launcher::QuickListModelInterface *quickList() const;
60+
5561Q_SIGNALS:
5662 void favoriteChanged(bool favorite);
5763 void runningChanged(bool running);
@@ -61,11 +67,12 @@ private:
6167 QString m_desktopFile;
6268 QString m_name;
6369 QString m_icon;
64− bool m_favorite;
70+ bool m_pinned;
6571 bool m_running;
6672 bool m_recent;
6773 int m_progress;
6874 int m_count;
75+ QuickListModel *m_quickList;
6976};
7077
7178#endif // LAUNCHERITEM_H
plugins/Unity/Launcher/launchermodel.cpp+17−7
@@ -32,7 +32,7 @@ LauncherModel::LauncherModel(QObject *parent):
3232 m_backend->icon(entry),
3333 this);
3434 if (m_backend->isPinned(entry)) {
35− item->setFavorite(true);
35+ item->setPinned(true);
3636 } else {
3737 item->setRecent(true);
3838 }
@@ -63,8 +63,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
6363 return item->name();
6464 case RoleIcon:
6565 return item->icon();
66− case RoleFavorite:
67− return item->favorite();
66+ case RolePinned:
67+ return item->pinned();
6868 }
6969
7070 return QVariant();
@@ -93,9 +93,9 @@ void LauncherModel::move(int oldIndex, int newIndex)
9393void LauncherModel::pin(int index)
9494{
9595 LauncherItem *item = m_list.at(index);
96− if (!item->favorite()) {
96+ if (!item->pinned()) {
9797
98− item->setFavorite(true);
98+ item->setPinned(true);
9999 item->setRecent(false);
100100
101101 m_backend->setPinned(item->appId(), true);
@@ -116,13 +116,23 @@ void LauncherModel::remove(int index)
116116 storeAppList();
117117}
118118
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+
119129QHash<int, QByteArray> LauncherModel::roleNames() const
120130{
121131 QHash<int, QByteArray> roles;
122132 roles.insert(RoleDesktopFile, "desktopFile");
123133 roles.insert(RoleName, "name");
124134 roles.insert(RoleIcon, "icon");
125− roles.insert(RoleFavorite, "favorite");
135+ roles.insert(RolePinned, "pinned");
126136 roles.insert(RoleRunning, "runnng");
127137 return roles;
128138}
@@ -131,7 +141,7 @@ void LauncherModel::storeAppList()
131141{
132142 QStringList appIds;
133143 Q_FOREACH(LauncherItem *item, m_list) {
134− if (item->favorite() || item->recent()) {
144+ if (item->pinned() || item->recent()) {
135145 appIds << item->appId();
136146 }
137147 }
plugins/Unity/Launcher/launchermodel.h+1
@@ -47,6 +47,7 @@ public:
4747 Q_INVOKABLE void move(int oldIndex, int newIndex);
4848 Q_INVOKABLE void pin(int index);
4949 Q_INVOKABLE void remove(int index);
50+ Q_INVOKABLE void triggerQuickListAction(int itemIndex, int quickListIndex);
5051
5152 QHash<int, QByteArray> roleNames() const;
5253
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