on xenial help sign in
hide "private" launcher quicklist entries when the greeter is locked (LP: #1667649)

Approved by: Lukáš Tinkl

commitd7adde7feb86093a1591bb5f3a08ebf670b2ee38 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 21 Mar 2017, 10:53 (10 years ago) parentfa02b8768b8a15
20 files changed+214−7
CMakeLists.txt+1−1 debian/control+3−3 plugins/Greeter/Unity/Launcher/quicklistmodel.cpp+2 plugins/Unity/Launcher/launcheritem.cpp+3 plugins/Unity/Launcher/quicklistentry.cpp+11 plugins/Unity/Launcher/quicklistentry.h+4 plugins/Unity/Launcher/quicklistmodel.cpp+2 plugins/Utils/CMakeLists.txt+1 plugins/Utils/plugin.cpp+2 plugins/Utils/quicklistproxymodel.cpp+72 plugins/Utils/quicklistproxymodel.h+52 qml/Launcher/Launcher.qml+1 qml/Launcher/LauncherPanel.qml+7−1 qml/Shell.qml+1 tests/mocks/Unity/Launcher/MockLauncherModel.h+1−1 tests/mocks/Unity/Launcher/MockQuickListModel.cpp+3−1 tests/mocks/Unity/Launcher/MockQuickListModel.h+2 tests/mocks/Utils/CMakeLists.txt+2 tests/mocks/Utils/plugin.cpp+2 tests/qmltests/Launcher/tst_Launcher.qml+42
CMakeLists.txt+1−1
@@ -74,7 +74,7 @@ pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=26)
7474pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
7575pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
7676pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
77−pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=11)
77+pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=12)
7878pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
7979pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
8080pkg_check_modules(UAL REQUIRED ubuntu-app-launch-3)
debian/control+3−3
@@ -38,7 +38,7 @@ Build-Depends: cmake,
3838 libubuntugestures5-private-dev (>= 1.3.2030),
3939 libudev-dev,
4040 libudm-common-dev,
41− libunity-api-dev (>= 8.2),
41+ libunity-api-dev (>= 8.5),
4242 libusermetricsoutput1-dev,
4343# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
4444 libx11-dev[!arm64 !armhf],
@@ -132,7 +132,7 @@ Depends: dmz-cursor-theme,
132132 qtdeclarative5-qtmir-plugin (>= 0.4.8),
133133 qtdeclarative5-ubuntu-telephony0.1,
134134 ubuntu-system-settings (>= 0.4),
135− unity-launcher-impl-10,
135+ unity-launcher-impl-12,
136136 unity8-common (= ${source:Version}),
137137 unity8-private (= ${binary:Version}),
138138 unity8-private | unity-launcher-impl,
@@ -235,7 +235,7 @@ Depends: accountsservice-ubuntu-schemas (>= 0.0.7),
235235 ${misc:Depends},
236236 ${shlibs:Depends},
237237Provides: unity-launcher-impl,
238− unity-launcher-impl-10,
238+ unity-launcher-impl-12,
239239Description: Unity 8 private libs
240240 The Unity 8 shell is the primary user interface for Ubuntu devices.
241241 .
plugins/Greeter/Unity/Launcher/quicklistmodel.cpp+2
@@ -65,6 +65,8 @@ QVariant QuickListModel::data(const QModelIndex &index, int role) const
6565 return m_list.at(index.row()).icon();
6666 case RoleClickable:
6767 return m_list.at(index.row()).clickable();
68+ case RoleIsPrivate:
69+ return false; // The greeter plugin would just not add any private entries
6870 }
6971 return QVariant();
7072}
plugins/Unity/Launcher/launcheritem.cpp+3
@@ -48,11 +48,13 @@ LauncherItem::LauncherItem(const QString &appId, const QString &name, const QStr
4848 QuickListEntry pinningAction;
4949 pinningAction.setActionId(QStringLiteral("pin_item"));
5050 pinningAction.setText(gettext("Pin shortcut"));
51+ pinningAction.setIsPrivate(true);
5152 m_quickList->appendAction(pinningAction);
5253
5354 m_quitAction.setActionId(QStringLiteral("stop_item"));
5455 m_quitAction.setIcon(QStringLiteral("application-exit"));
5556 m_quitAction.setText(gettext("Quit"));
57+ m_quitAction.setIsPrivate(true);
5658}
5759
5860QString LauncherItem::appId() const
@@ -120,6 +122,7 @@ void LauncherItem::setPinned(bool pinned)
120122 QuickListEntry entry;
121123 entry.setActionId(QStringLiteral("pin_item"));
122124 entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
125+ entry.setIsPrivate(true);
123126 m_quickList->updateAction(entry);
124127}
125128
plugins/Unity/Launcher/quicklistentry.cpp+11
@@ -20,6 +20,7 @@
2020
2121QuickListEntry::QuickListEntry()
2222 : m_hasSeparator(false)
23+ , m_isPrivate(false)
2324{
2425}
2526
@@ -72,3 +73,13 @@ bool QuickListEntry::operator==(const QuickListEntry &other)
7273{
7374 return !other.actionId().isEmpty() && other.actionId() == m_actionId;
7475}
76+
77+bool QuickListEntry::isPrivate() const
78+{
79+ return m_isPrivate;
80+}
81+
82+void QuickListEntry::setIsPrivate(bool isPrivate)
83+{
84+ m_isPrivate = isPrivate;
85+}
plugins/Unity/Launcher/quicklistentry.h+4
@@ -42,11 +42,15 @@ public:
4242
4343 bool operator==(const QuickListEntry & other);
4444
45+ bool isPrivate() const;
46+ void setIsPrivate(bool isPrivate);
47+
4548private:
4649 QString m_actionId;
4750 QString m_text;
4851 QString m_icon;
4952 bool m_hasSeparator;
53+ bool m_isPrivate;
5054};
5155
5256#endif // QUICKLISTENTRY
plugins/Unity/Launcher/quicklistmodel.cpp+2
@@ -81,6 +81,8 @@ QVariant QuickListModel::data(const QModelIndex &index, int role) const
8181 return m_list.at(index.row()).clickable();
8282 case RoleHasSeparator:
8383 return m_list.at(index.row()).hasSeparator();
84+ case RoleIsPrivate:
85+ return m_list.at(index.row()).isPrivate();
8486 }
8587 return QVariant();
8688}
plugins/Utils/CMakeLists.txt+1
@@ -36,6 +36,7 @@ set(QMLPLUGIN_SRC
3636 URLDispatcher.cpp
3737 tabfocusfence.cpp
3838 expressionfiltermodel.cpp
39+ quicklistproxymodel.cpp
3940 plugin.cpp
4041 )
4142
plugins/Utils/plugin.cpp+2
@@ -42,6 +42,7 @@
4242#include "appdrawerproxymodel.h"
4343#include "tabfocusfence.h"
4444#include "expressionfiltermodel.h"
45+#include "quicklistproxymodel.h"
4546
4647static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
4748{
@@ -88,4 +89,5 @@ void UtilsPlugin::registerTypes(const char *uri)
8889 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
8990 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
9091 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
92+ qmlRegisterType<QuickListProxyModel>(uri, 0, 1, "QuickListProxyModel");
9193}
plugins/Utils/quicklistproxymodel.cppnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2017 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+
17+#include "quicklistproxymodel.h"
18+
19+#include <QDebug>
20+
21+QuickListProxyModel::QuickListProxyModel(QObject *parent):
22+ QSortFilterProxyModel(parent)
23+{
24+ connect(this, &QAbstractListModel::rowsInserted, this, &QuickListProxyModel::countChanged);
25+ connect(this, &QAbstractListModel::rowsRemoved, this, &QuickListProxyModel::countChanged);
26+ connect(this, &QAbstractListModel::layoutChanged, this, &QuickListProxyModel::countChanged);
27+}
28+
29+QAbstractItemModel *QuickListProxyModel::source() const
30+{
31+ return m_source;
32+}
33+
34+bool QuickListProxyModel::privateMode() const
35+{
36+ return m_privateMode;
37+}
38+
39+void QuickListProxyModel::setPrivateMode(bool privateMode)
40+{
41+ if (m_privateMode != privateMode) {
42+ m_privateMode = privateMode;
43+ invalidateFilter();
44+ Q_EMIT privateModeChanged();
45+ }
46+}
47+
48+void QuickListProxyModel::setSource(QAbstractItemModel *source)
49+{
50+ if (m_source != source) {
51+ m_source = source;
52+ setSourceModel(m_source);
53+ connect(m_source, &QAbstractItemModel::rowsRemoved, this, &QuickListProxyModel::invalidate);
54+ connect(m_source, &QAbstractItemModel::rowsInserted, this, &QuickListProxyModel::invalidate);
55+ Q_EMIT sourceChanged();
56+ }
57+}
58+
59+int QuickListProxyModel::count() const
60+{
61+ return rowCount();
62+}
63+
64+bool QuickListProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
65+{
66+ Q_UNUSED(source_parent)
67+
68+ if (m_privateMode) {
69+ return !m_source->data(m_source->index(source_row, 0), QuickListModelInterface::RoleIsPrivate).toBool();
70+ }
71+ return true;
72+}
plugins/Utils/quicklistproxymodel.hnew file+52
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (C) 2017 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+
17+#include <QSortFilterProxyModel>
18+
19+#include <unity/shell/launcher/QuickListModelInterface.h>
20+
21+using namespace unity::shell::launcher;
22+
23+class QuickListProxyModel: public QSortFilterProxyModel
24+{
25+ Q_OBJECT
26+ Q_PROPERTY(QAbstractItemModel* source READ source WRITE setSource NOTIFY sourceChanged)
27+ Q_PROPERTY(bool privateMode READ privateMode WRITE setPrivateMode NOTIFY privateModeChanged)
28+ Q_PROPERTY(int count READ count NOTIFY countChanged)
29+
30+public:
31+ QuickListProxyModel(QObject* parent = nullptr);
32+
33+ QAbstractItemModel* source() const;
34+ void setSource(QAbstractItemModel* source);
35+
36+ bool privateMode() const;
37+ void setPrivateMode(bool privateMode);
38+
39+ int count() const;
40+
41+protected:
42+ bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
43+
44+Q_SIGNALS:
45+ void sourceChanged();
46+ void privateModeChanged();
47+ void countChanged();
48+
49+private:
50+ QAbstractItemModel* m_source = nullptr;
51+ bool m_privateMode;
52+};
qml/Launcher/Launcher.qml+1
@@ -33,6 +33,7 @@ FocusScope {
3333 property Item blurSource: null
3434 property int topPanelHeight: 0
3535 property bool drawerEnabled: true
36+ property alias privateMode: panel.privateMode
3637
3738 property int panelWidth: units.gu(10)
3839 property int dragAreaWidth: units.gu(1)
qml/Launcher/LauncherPanel.qml+7−1
@@ -19,6 +19,7 @@ import QtQml.StateMachine 1.0 as DSM
1919import Ubuntu.Components 1.3
2020import Unity.Launcher 0.1
2121import Ubuntu.Components.Popups 1.3
22+import Utils 0.1
2223import "../Components"
2324
2425Rectangle {
@@ -29,6 +30,7 @@ Rectangle {
2930
3031 property var model
3132 property bool inverted: false
33+ property bool privateMode: false
3234 property bool dragging: false
3335 property bool moving: launcherListView.moving || launcherListView.flicking
3436 property bool preventHiding: moving || dndArea.draggedIndex >= 0 || quickList.state === "open" || dndArea.pressed
@@ -811,7 +813,11 @@ Rectangle {
811813
812814 Repeater {
813815 id: popoverRepeater
814− model: quickList.model
816+ objectName: "popoverRepeater"
817+ model: QuickListProxyModel {
818+ source: quickList.model
819+ privateMode: root.privateMode
820+ }
815821
816822 ListItem {
817823 objectName: "quickListEntry" + index
qml/Shell.qml+1
@@ -561,6 +561,7 @@ StyledItem {
561561 blurSource: greeter.shown ? greeter : stages
562562 topPanelHeight: panel.panelHeight
563563 drawerEnabled: !greeter.active
564+ privateMode: greeter.active
564565
565566 onShowDashHome: showHome()
566567 onLauncherApplicationSelected: {
tests/mocks/Unity/Launcher/MockLauncherModel.h+1−1
@@ -28,7 +28,7 @@ using namespace unity::shell::launcher;
2828
2929class MockLauncherModel: public LauncherModelInterface
3030{
31− Q_OBJECT
31+ Q_OBJECT
3232
3333public:
3434 MockLauncherModel(QObject* parent = 0);
tests/mocks/Unity/Launcher/MockQuickListModel.cpp+3−1
@@ -39,6 +39,8 @@ QVariant MockQuickListModel::data(const QModelIndex &index, int role) const
3939 return index.row() == 1 ? false : true;
4040 case RoleHasSeparator:
4141 return index.row() <= 1 ? true : false;
42+ case RoleIsPrivate:
43+ return index.row() == 4 ? true : false;
4244 }
4345 return QVariant();
4446}
@@ -46,5 +48,5 @@ QVariant MockQuickListModel::data(const QModelIndex &index, int role) const
4648int MockQuickListModel::rowCount(const QModelIndex &parent) const
4749{
4850 Q_UNUSED(parent)
49− return 4;
51+ return 5;
5052}
tests/mocks/Unity/Launcher/MockQuickListModel.h+2
@@ -27,6 +27,8 @@ using namespace unity::shell::launcher;
2727class MockQuickListModel: public QuickListModelInterface
2828{
2929 Q_OBJECT
30+ Q_PROPERTY(int count READ rowCount)
31+
3032public:
3133 MockQuickListModel(QObject *parent = 0);
3234
tests/mocks/Utils/CMakeLists.txt+2
@@ -27,6 +27,7 @@ set(QMLPLUGIN_SRC
2727 ${CMAKE_SOURCE_DIR}/plugins/Utils/appdrawerproxymodel.cpp
2828 ${CMAKE_SOURCE_DIR}/plugins/Utils/tabfocusfence.cpp
2929 ${CMAKE_SOURCE_DIR}/plugins/Utils/expressionfiltermodel.cpp
30+ ${CMAKE_SOURCE_DIR}/plugins/Utils/quicklistproxymodel.cpp
3031 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
3132 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
3233 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
@@ -35,6 +36,7 @@ set(QMLPLUGIN_SRC
3536 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/AppDrawerModelInterface.h
3637 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
3738 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
39+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
3840 constants.cpp
3941 plugin.cpp
4042 windowstatestorage.cpp
tests/mocks/Utils/plugin.cpp+2
@@ -43,6 +43,7 @@
4343#include <appdrawerproxymodel.h>
4444#include <tabfocusfence.h>
4545#include <expressionfiltermodel.h>
46+#include <quicklistproxymodel.h>
4647
4748static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
4849{
@@ -88,4 +89,5 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
8889 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
8990 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
9091 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
92+ qmlRegisterType<QuickListProxyModel>(uri, 0, 1, "QuickListProxyModel");
9193}
tests/qmltests/Launcher/tst_Launcher.qml+42
@@ -95,6 +95,11 @@ Rectangle {
9595 property: "lockedVisible"
9696 value: lockedVisibleCheckBox.checked
9797 }
98+ Binding {
99+ target: launcherLoader.item
100+ property: "privateMode"
101+ value: privateModeCheckBox.checked
102+ }
98103 Binding {
99104 target: launcherLoader.item
100105 property: "panelWidth"
@@ -120,6 +125,20 @@ Rectangle {
120125 }
121126 }
122127
128+ RowLayout {
129+ CheckBox {
130+ id: privateModeCheckBox
131+ checked: false
132+ }
133+ Label {
134+ text: "Private mode (lockscreen locked)"
135+ AbstractButton {
136+ anchors.fill: parent
137+ onClicked: privateModeCheckBox.checked = !privateModeCheckBox.checked
138+ }
139+ }
140+ }
141+
123142 Slider {
124143 id: widthSlider
125144 Layout.fillWidth: true
@@ -1242,6 +1261,7 @@ Rectangle {
12421261 keyClick(Qt.Key_Down);
12431262 keyClick(Qt.Key_Down);
12441263 keyClick(Qt.Key_Down);
1264+ keyClick(Qt.Key_Down);
12451265 tryCompare(quickList, "selectedIndex", 0)
12461266
12471267 // Left gets us back to the launcher
@@ -1493,6 +1513,28 @@ Rectangle {
14931513 compare(launcher.state, "visibleTemporary");
14941514 }
14951515
1516+ function test_hideQuicklistItemsInPrivateModel_data() {
1517+ return [
1518+ { tag: "private mode", private: true },
1519+ { tag: "normal mode", private: false }
1520+ ];
1521+ }
1522+
1523+ function test_hideQuicklistItemsInPrivateModel(data) {
1524+ privateModeCheckBox.checked = data.private;
1525+
1526+ revealByEdgePush();
1527+
1528+ var item = findChild(launcher, "launcherDelegate4");
1529+ var quickListShape = findChild(launcher, "quickListShape")
1530+
1531+ mousePress(item)
1532+ tryCompare(quickListShape, "visible", true)
1533+
1534+ var repeater = findChild(launcher, "popoverRepeater");
1535+ tryCompare(repeater, "count", LauncherModel.get(4).quickList.count - (data.private ? 1 : 0))
1536+ }
1537+
14961538 function test_hintOnSizeChange() {
14971539 var oldSize = launcher.panelWidth;
14981540 launcher.maxPanelX = -launcher.panelWidth;