on xenial help sign in
add surface titles to launcher's quicklist
commitae9bc90dca13441d6be9b65a8acc1d57a829fc11 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 2 Mar 2017, 14:28 (10 years ago) parenteb835af
7 files changed+141−23
plugins/Unity/Launcher/launcheritem.cpp+27−6 plugins/Unity/Launcher/launcheritem.h+3−2 plugins/Unity/Launcher/launchermodel.cpp+20−9 plugins/Unity/Launcher/quicklistmodel.cpp+7 plugins/Unity/Launcher/quicklistmodel.h+1 tests/plugins/Unity/Launcher/CMakeLists.txt+3 tests/plugins/Unity/Launcher/launchermodeltest.cpp+80−6
plugins/Unity/Launcher/launcheritem.cpp+27−6
@@ -35,7 +35,6 @@ LauncherItem::LauncherItem(const QString &appId, const QString &name, const QStr
3535 m_countVisible(false),
3636 m_focused(false),
3737 m_alerting(false),
38− m_surfaceCount(0),
3938 m_quickList(new QuickListModel(this))
4039{
4140 Q_ASSERT(parent != nullptr);
@@ -223,14 +222,36 @@ void LauncherItem::setAlerting(bool alerting)
223222
224223int LauncherItem::surfaceCount() const
225224{
226− return m_surfaceCount;
225+ return m_surfaces.count();
227226}
228227
229−void LauncherItem::setSurfaceCount(int surfaceCount)
228+void LauncherItem::setSurfaces(const QList<QPair<QString, QString> > &surfaces)
230229{
231− if (m_surfaceCount != surfaceCount) {
232− m_surfaceCount = surfaceCount;
233− Q_EMIT surfaceCountChanged(surfaceCount);
230+ if (m_surfaces != surfaces) {
231+ m_surfaces = surfaces;
232+
233+ QList<QuickListEntry> removedEntries;
234+ for (int i = 0; i < m_quickList->rowCount(); ++i) {
235+ QuickListEntry entry = m_quickList->get(i);
236+ if (entry.actionId().startsWith(QStringLiteral("surface_"))) {
237+ removedEntries.append(entry);
238+ }
239+ }
240+ Q_FOREACH (const QuickListEntry &entry, removedEntries) {
241+ m_quickList->removeAction(entry);
242+ }
243+ for (int i = 0; i < surfaces.count(); ++i) {
244+ QuickListEntry entry;
245+ entry.setActionId(QStringLiteral("surface_") + surfaces.at(i).first);
246+ entry.setText(surfaces.at(i).second);
247+ entry.setIsPrivate(true);
248+ if (i == surfaces.count() - 1) {
249+ entry.setHasSeparator(true);
250+ }
251+ m_quickList->insertAction(entry, i + 1);
252+ }
253+
254+ Q_EMIT surfaceCountChanged(m_surfaces.count());
234255 }
235256}
236257
plugins/Unity/Launcher/launcheritem.h+3−2
@@ -23,6 +23,7 @@
2323#include "quicklistmodel.h"
2424
2525#include <unity/shell/launcher/LauncherItemInterface.h>
26+#include <unity/shell/application/MirSurfaceInterface.h>
2627
2728class QuickListModel;
2829
@@ -62,7 +63,7 @@ private:
6263 void setCountVisible(bool countVisible);
6364 void setFocused(bool focused);
6465 void setAlerting(bool alerting);
65− void setSurfaceCount(int surfaceCount);
66+ void setSurfaces(const QList<QPair<QString, QString >> &surfaces);
6667
6768private:
6869 QString m_appId;
@@ -77,7 +78,7 @@ private:
7778 bool m_countVisible;
7879 bool m_focused;
7980 bool m_alerting;
80− int m_surfaceCount;
81+ QList<QPair<QString, QString> > m_surfaces;
8182 QuickListModel *m_quickList;
8283 QuickListEntry m_quitAction;
8384
plugins/Unity/Launcher/launchermodel.cpp+20−9
@@ -204,6 +204,19 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
204204 if (m_appManager) {
205205 m_appManager->stopApplication(appId);
206206 }
207+ } else if (actionId.startsWith("surface_")){
208+ ApplicationInfoInterface *appInfo = m_appManager->findApplication(appId);
209+ if (!appInfo) {
210+ qWarning() << "App for" << appId << "not found in launcher. Cannot invoke quicklist action";
211+ }
212+ for (int i = 0; i < appInfo->surfaceList()->count(); ++i) {
213+ MirSurfaceInterface *iface = appInfo->surfaceList()->get(i);
214+ QString id = actionId;
215+ id.remove(QRegExp("^surface_"));
216+ if (id == iface->persistentId()) {
217+ iface->activate();
218+ }
219+ }
207220 // Nope, we don't know this action, let the backend forward it to the application
208221 } else {
209222 // TODO: forward quicklist action to app, possibly via m_dbusIface
@@ -517,18 +530,12 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
517530 item->setRecent(true);
518531 Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleRecent});
519532 }
520− if (item->surfaceCount() != app->surfaceCount()) {
521− item->setSurfaceCount(app->surfaceCount());
522− Q_EMIT dataChanged(index(itemIndex), index(itemIndex), {RoleSurfaceCount});
523− }
524−
525533 item->setRunning(true);
526534 } else {
527535 LauncherItem *item = new LauncherItem(app->appId(), app->name(), app->icon().toString(), this);
528536 item->setRecent(true);
529537 item->setRunning(true);
530538 item->setFocused(app->focused());
531− item->setSurfaceCount(app->surfaceCount());
532539 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
533540 m_list.append(item);
534541 endInsertRows();
@@ -540,6 +547,7 @@ void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
540547
541548void LauncherModel::applicationSurfaceCountChanged(int count)
542549{
550+ Q_UNUSED(count)
543551 ApplicationInfoInterface *app = static_cast<ApplicationInfoInterface*>(sender());
544552 int idx = findApplication(app->appId());
545553 if (idx < 0) {
@@ -547,10 +555,13 @@ void LauncherModel::applicationSurfaceCountChanged(int count)
547555 return;
548556 }
549557 LauncherItem *item = m_list.at(idx);
550− if (item->surfaceCount() != count) {
551− item->setSurfaceCount(count);
552− Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
558+ QList<QPair<QString, QString> > surfaces;
559+ for (int i = 0; i < app->surfaceList()->count(); ++i) {
560+ MirSurfaceInterface* iface = app->surfaceList()->get(i);
561+ surfaces.append(qMakePair<QString, QString>(iface->persistentId(), iface->name()));
553562 }
563+ item->setSurfaces(surfaces);
564+ Q_EMIT dataChanged(index(idx), index(idx), {RoleSurfaceCount});
554565}
555566
556567void LauncherModel::applicationRemoved(const QModelIndex &parent, int row)
plugins/Unity/Launcher/quicklistmodel.cpp+7
@@ -37,6 +37,13 @@ void QuickListModel::appendAction(const QuickListEntry &entry)
3737 endInsertRows();
3838}
3939
40+void QuickListModel::insertAction(const QuickListEntry &entry, int index)
41+{
42+ beginInsertRows(QModelIndex(), index, index);
43+ m_list.insert(index, entry);
44+ endInsertRows();
45+}
46+
4047void QuickListModel::updateAction(const QuickListEntry &entry)
4148{
4249 for (int i = 0; i < m_list.count(); ++i) {
plugins/Unity/Launcher/quicklistmodel.h+1
@@ -36,6 +36,7 @@ public:
3636 ~QuickListModel();
3737
3838 void appendAction(const QuickListEntry &entry);
39+ void insertAction(const QuickListEntry &entry, int index);
3940
4041 /**
4142 * @brief Update an existing action
tests/plugins/Unity/Launcher/CMakeLists.txt+3
@@ -34,6 +34,9 @@ add_executable(launchermodeltestExec
3434 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
3535 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
3636 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
37+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
38+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
39+ ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
3740 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
3841 )
3942target_link_libraries(launchermodeltestExec
tests/plugins/Unity/Launcher/launchermodeltest.cpp+80−6
@@ -17,6 +17,7 @@
1717// unity-api
1818#include <unity/shell/launcher/LauncherModelInterface.h>
1919#include <unity/shell/application/ApplicationInfoInterface.h>
20+#include <unity/shell/application/MirSurfaceListInterface.h>
2021
2122#include "launcheritem.h"
2223#include "launchermodel.h"
@@ -37,11 +38,72 @@
3738namespace unityapi = unity::shell::application;
3839
3940// This is a mock, specifically to test the LauncherModel
41+class MockSurface: public unity::shell::application::MirSurfaceInterface
42+{
43+ Q_OBJECT
44+public:
45+ MockSurface(const QString &id, QObject* parent): unityapi::MirSurfaceInterface(parent), m_id(id) {}
46+ Mir::Type type() const override { return Mir::NormalType;}
47+ QString name() const override { return QStringLiteral("mock surface"); }
48+ QString persistentId() const override { return m_id; }
49+ QPoint position() const override { return QPoint(); }
50+ QSize size() const override { return QSize(); }
51+ void resize(const QSize &size) override { Q_UNUSED(size) }
52+ void resize(int width, int height) override { Q_UNUSED(width); Q_UNUSED(height) }
53+ Mir::State state() const override { return Mir::RestoredState; }
54+ bool live() const override { return true; }
55+ bool visible() const override { return true; }
56+ Mir::OrientationAngle orientationAngle() const override { return Mir::Angle0; }
57+ void setOrientationAngle(Mir::OrientationAngle angle) override { Q_UNUSED(angle); }
58+ int minimumWidth() const override { return 0; }
59+ int minimumHeight() const override { return 0; }
60+ int maximumWidth() const override { return 0; }
61+ int maximumHeight() const override { return 0; }
62+ int widthIncrement() const override { return 0; }
63+ int heightIncrement() const override { return 0; }
64+ void setKeymap(const QString &) override {}
65+ Mir::ShellChrome shellChrome() const override { return Mir::NormalChrome; }
66+ QString keymap() const override { return QStringLiteral("de_DE"); }
67+ bool focused() const override { return true; }
68+ QRect inputBounds() const override { return QRect(); }
69+ bool confinesMousePointer() const override { return false; }
70+ QPoint requestedPosition() const override { return QPoint(); }
71+ void setRequestedPosition(const QPoint &) override {}
72+ MirSurfaceInterface* parentSurface() const override { return nullptr; }
73+ MirSurfaceListInterface* childSurfaceList() const override { return nullptr; }
74+ void close() override {}
75+ void activate() override {}
76+ void requestState(Mir::State) override {}
77+
78+private:
79+ QString m_id;
80+};
81+
82+class MockSurfaceList: public unity::shell::application::MirSurfaceListInterface
83+{
84+ Q_OBJECT
85+public:
86+ MockSurfaceList(QObject *parent): unityapi::MirSurfaceListInterface(parent) {}
87+ int rowCount(const QModelIndex & = QModelIndex()) const override { return m_list.count(); }
88+ QVariant data(const QModelIndex &, int) const override { return QVariant(); }
89+ Q_INVOKABLE MirSurfaceInterface* get(int index) override { return m_list.at(index); }
90+ void append(MirSurfaceInterface* surface) {
91+ beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
92+ m_list.append(surface);
93+ endInsertRows();
94+ }
95+private:
96+ QList<MirSurfaceInterface*> m_list;
97+
98+};
99+
40100class MockApp: public unity::shell::application::ApplicationInfoInterface
41101{
42102 Q_OBJECT
43103public:
44− MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) { }
104+ MockApp(const QString &appId, QObject *parent = 0): ApplicationInfoInterface(appId, parent), m_appId(appId), m_focused(false) {
105+ m_surfaces = new MockSurfaceList(this);
106+ }
45107
46108 RequestedState requestedState() const override { return RequestedRunning; }
47109 void setRequestedState(RequestedState) override {}
@@ -64,10 +126,10 @@ public:
64126 void setExemptFromLifecycle(bool) override {}
65127 QSize initialSurfaceSize() const override { return QSize(); }
66128 void setInitialSurfaceSize(const QSize &) override {}
67− MirSurfaceListInterface* surfaceList() const override { return nullptr; }
129+ MirSurfaceListInterface* surfaceList() const override { return m_surfaces; }
68130 MirSurfaceListInterface* promptSurfaceList() const override { return nullptr; }
69− int surfaceCount() const override { return m_surfaceCount; }
70− void setSurfaceCount(int count) { m_surfaceCount = count; Q_EMIT surfaceCountChanged(count); }
131+ int surfaceCount() const override { return m_surfaces->count(); }
132+ void setSurfaces(MockSurfaceList* surfaces) { m_surfaces = surfaces; Q_EMIT surfaceCountChanged(m_surfaces->count()); }
71133 void close() override {}
72134
73135 // Methods used for mocking (not in the interface)
@@ -75,7 +137,7 @@ public:
75137private:
76138 QString m_appId;
77139 bool m_focused;
78− int m_surfaceCount = 0;
140+ MockSurfaceList *m_surfaces;
79141};
80142
81143// This is a mock, specifically to test the LauncherModel
@@ -748,8 +810,20 @@ private Q_SLOTS:
748810
749811 QCOMPARE(launcherModel->get(0)->surfaceCount(), 0);
750812 MockApp *app = qobject_cast<MockApp*>(appManager->findApplication(appId));
751− app->setSurfaceCount(1);
813+ MockSurfaceList* surfaces = new MockSurfaceList(appManager);
814+ surfaces->append(new MockSurface("foobar", surfaces));
815+ app->setSurfaces(surfaces);
752816 QCOMPARE(launcherModel->get(0)->surfaceCount(), 1);
817+
818+ // Make sure the new surface appears in the quicklist
819+ QuickListModel *quickList = qobject_cast<QuickListModel*>(launcherModel->get(0)->quickList());
820+ bool found = false;
821+ for (int i = 0; i < quickList->rowCount(); ++i) {
822+ if (quickList->get(i).actionId() == "surface_foobar") {
823+ found = true;
824+ }
825+ }
826+ QCOMPARE(found, true);
753827 }
754828};
755829