on xenial help sign in
Ext. SDs
commit1344ba37cd3e1969911c0da06332ba579e3a97e4 authorMichał Sawicz <michal.sawicz@canonical.com> dateMon 30 Sep 2013, 22:15 (13 years ago) parent4d86fb716c4b50
11 files changed+434−3
Greeter/PinLockscreen.qml → Components/PinLockscreen.qml Greeter/PinPadButton.qml → Components/PinPadButton.qml Notifications/Notification.qml+42−1 Notifications/NotificationMenuItemFactory.qml+96 plugins/Utils/CMakeLists.txt+2−1 plugins/Utils/plugin.cpp+2 plugins/Utils/unitymenumodelpaths.cpp+182 plugins/Utils/unitymenumodelpaths.h+82 tests/mocks/QMenuModel/UnityMenuModel.qml+26 tests/mocks/QMenuModel/qmldir+1 tests/qmltests/CMakeLists.txt+1−1
Greeter/PinLockscreen.qml → Components/PinLockscreen.qmlrenamed

The content is the same.

Greeter/PinPadButton.qml → Components/PinPadButton.qmlrenamed

The content is the same.

Notifications/Notification.qml+42−1
@@ -17,6 +17,8 @@
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
1919import Unity.Notifications 1.0
20+import QMenuModel 0.1
21+import Utils 0.1
2022
2123UbuntuShape {
2224 id: notification
@@ -38,6 +40,24 @@ UbuntuShape {
3840
3941 clip: true
4042
43+ UnityMenuModelPaths {
44+ id: paths
45+
46+ source: hints["x-canonical-private-menu-model"]
47+
48+ busNameHint: "busName"
49+ actionsHint: "actions"
50+ menuObjectPathHint: "menuPath"
51+ }
52+
53+ UnityMenuModel {
54+ id: unityMenuModel
55+
56+ busName: paths.busName
57+ actions: paths.actions
58+ menuObjectPath: paths.menuObjectPath
59+ }
60+
4161 Behavior on implicitHeight {
4262 id: heightBehavior
4363
@@ -141,6 +161,27 @@ UbuntuShape {
141161 }
142162 }
143163
164+ Column {
165+ objectName: "dialogListView"
166+ spacing: units.gu(2)
167+
168+ visible: count > 0
169+
170+ anchors.left: parent.left; anchors.right: parent.right
171+
172+ Repeater {
173+ model: unityMenuModel
174+
175+ NotificationMenuItemFactory {
176+ anchors.left: parent.left; anchors.right: parent.right
177+
178+ menuModel: unityMenuModel
179+ menuData: model
180+ menuIndex: index
181+ }
182+ }
183+ }
184+
144185 Item {
145186 id: buttonRow
146187
@@ -195,7 +236,7 @@ UbuntuShape {
195236 top: parent.top
196237 bottom: parent.bottom
197238 }
198− gradient: notification.hints == Notification.ButtonTint ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
239+ gradient: notification.hints["x-canonical-private-button-tint"] == "true" ? UbuntuColors.orangeGradient : UbuntuColors.greyGradient
199240 visible: width > 0
200241 onClicked: notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
201242 }
Notifications/NotificationMenuItemFactory.qmlnew file+96
@@ -0,0 +1,96 @@
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+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+import QtQuick 2.0
21+import Ubuntu.Components 0.1
22+import "../Components"
23+
24+Loader {
25+ id: menuFactory
26+
27+ property QtObject menuModel: null
28+ property QtObject menuData: null
29+ property int menuIndex
30+ property var notification
31+
32+ property var _map: {
33+ "com.canonical.snapdecision.textfield": textfield,
34+ "com.canonical.snapdecision.pinlock" : pinLock,
35+ }
36+
37+ sourceComponent: {
38+ if (menuData.type !== undefined) {
39+ var component = _map[menuData.type];
40+ if (component !== undefined) {
41+ return component;
42+ }
43+ } else {
44+ if (menuData.isSeparator) {
45+ return divMenu;
46+ }
47+ }
48+ return standardMenu;
49+ }
50+
51+ Component {
52+ id: textfield
53+
54+ Column {
55+ spacing: units.gu(.5)
56+
57+ anchors.left: parent.left; anchors.right: parent.right
58+
59+ Component.onCompleted: {
60+ menuModel.loadExtendedAttributes(menuIndex, {"x-echo-mode-password": "bool"});
61+ textfield.echoMode = menuData.ext.xEchoModePassword ? TextInput.Password : TextInput.Normal
62+ }
63+
64+ Label {
65+ fontSize: "medium"
66+ color: "white"
67+ text: menuData.label
68+ }
69+
70+ TextField {
71+ id: textfield
72+
73+ anchors.left: parent.left; anchors.right: parent.right
74+
75+ onTextChanged: {
76+ menuModel.changeState(menuIndex, text);
77+ }
78+ }
79+ }
80+ }
81+
82+ Component {
83+ id: pinLock
84+ PinLockscreen {
85+ anchors.left: parent.left; anchors.right: parent.right
86+
87+ onEntered: {
88+ menuModel.changeState(menuIndex, passphrase);
89+ }
90+
91+ onCancel: {
92+ menuModel.activate(menuIndex, false);
93+ }
94+ }
95+ }
96+}
plugins/Utils/CMakeLists.txt+2−1
@@ -9,6 +9,7 @@ set(QMLPLUGIN_SRC
99 qlimitproxymodelqml.cpp
1010 qsortfilterproxymodelqml.cpp
1111 ubuntuwindow.cpp
12+ unitymenumodelpaths.cpp
1213 plugin.cpp
1314 )
1415
@@ -21,7 +22,7 @@ add_library(Utils-qml SHARED
2122# files directly in targets.
2223set_target_properties(Utils-qml PROPERTIES COMPILE_FLAGS -fvisibility=default)
2324
24−qt5_use_modules(Utils-qml Qml Quick)
25+qt5_use_modules(Utils-qml Qml Quick DBus)
2526
2627# export the qmldir qmltypes and plugin files
2728export_qmlfiles(Utils Utils)
plugins/Utils/plugin.cpp+2
@@ -28,6 +28,7 @@
2828#include "qlimitproxymodelqml.h"
2929#include "qsortfilterproxymodelqml.h"
3030#include "ubuntuwindow.h"
31+#include "unitymenumodelpaths.h"
3132
3233static QObject* applicationsPathsSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
3334 Q_UNUSED(engine);
@@ -41,6 +42,7 @@ void UtilsPlugin::registerTypes(const char *uri)
4142 qmlRegisterType<QAbstractItemModel>();
4243 qmlRegisterType<QLimitProxyModelQML>(uri, 0, 1, "LimitProxyModel");
4344 qmlRegisterType<QSortFilterProxyModelQML>(uri, 0, 1, "SortFilterProxyModel");
45+ qmlRegisterType<UnityMenuModelPaths>(uri, 0, 1, "UnityMenuModelPaths");
4446 qmlRegisterExtendedType<QQuickWindow, UbuntuWindow>(uri, 0, 1, "Window");
4547 qmlRegisterSingletonType<ApplicationPaths>(uri, 0, 1, "ApplicationPaths", applicationsPathsSingleton);
4648}
plugins/Utils/unitymenumodelpaths.cppnew file+182
@@ -0,0 +1,182 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
17+ */
18+
19+
20+#include "unitymenumodelpaths.h"
21+#include <QDBusArgument>
22+
23+static QVariant parseVariantData(const QVariant& var);
24+
25+const QDBusArgument &operator>>(const QDBusArgument &arg, QVariantMap &map)
26+{
27+ arg.beginMap();
28+ map.clear();
29+ while (!arg.atEnd()) {
30+ QString key;
31+ QVariant value;
32+ arg.beginMapEntry();
33+
34+ arg >> key >> value;
35+ map.insertMulti(key, parseVariantData(value)); // re-parse for qdbusargument
36+
37+ arg.endMapEntry();
38+ }
39+ arg.endMap();
40+ return arg;
41+}
42+
43+static QVariant parseVariantData(const QVariant& var) {
44+ if ((int)var.type() == QMetaType::User && var.userType() == qMetaTypeId<QDBusArgument>()) {
45+ QDBusArgument arg(var.value<QDBusArgument>());
46+ if (arg.currentType() == QDBusArgument::MapType) {
47+ QVariantMap map;
48+ arg >> map;
49+ return map;
50+ }
51+ return arg.asVariant();
52+ }
53+
54+ return var;
55+}
56+
57+UnityMenuModelPaths::UnityMenuModelPaths(QObject *parent)
58+ : QObject(parent)
59+{
60+}
61+
62+QVariant UnityMenuModelPaths::source() const
63+{
64+ return m_sourceData;
65+}
66+
67+void UnityMenuModelPaths::setSource(const QVariant& data)
68+{
69+ if (m_sourceData != data) {
70+ m_sourceData = data;
71+ Q_EMIT sourceChanged();
72+
73+ updateData();
74+ }
75+}
76+
77+void UnityMenuModelPaths::updateData()
78+{
79+ QVariantMap dataMap = parseVariantData(m_sourceData).toMap();
80+
81+ if (!m_busNameHint.isEmpty() && dataMap.contains(m_busNameHint)) {
82+ setBusName(dataMap[m_busNameHint].toByteArray());
83+ } else {
84+ setBusName("");
85+ }
86+
87+ if (!m_menuObjectPathHint.isEmpty() && dataMap.contains(m_menuObjectPathHint)) {
88+ setMenuObjectPath(dataMap[m_menuObjectPathHint].toByteArray());
89+ } else {
90+ setMenuObjectPath("");
91+ }
92+
93+ if (!m_actionsHint.isEmpty() && dataMap.contains(m_actionsHint)) {
94+ setActions(dataMap[m_actionsHint].toMap());
95+ } else {
96+ setActions(QVariantMap());
97+ }
98+}
99+
100+QByteArray UnityMenuModelPaths::busName() const
101+{
102+ return m_busName;
103+}
104+
105+void UnityMenuModelPaths::setBusName(const QByteArray &name)
106+{
107+ if (m_busName != name) {
108+ m_busName = name;
109+ Q_EMIT busNameChanged();
110+ }
111+}
112+
113+QVariantMap UnityMenuModelPaths::actions() const
114+{
115+ return m_actions;
116+}
117+
118+void UnityMenuModelPaths::setActions(const QVariantMap &actions)
119+{
120+ if (m_actions != actions) {
121+ m_actions = actions;
122+ Q_EMIT actionsChanged();
123+ }
124+}
125+
126+QByteArray UnityMenuModelPaths::menuObjectPath() const
127+{
128+ return m_menuObjectPath;
129+}
130+
131+void UnityMenuModelPaths::setMenuObjectPath(const QByteArray &path)
132+{
133+ if (m_menuObjectPath != path) {
134+ m_menuObjectPath = path;
135+ Q_EMIT menuObjectPathChanged();
136+ }
137+}
138+
139+QByteArray UnityMenuModelPaths::busNameHint() const
140+{
141+ return m_busNameHint;
142+}
143+
144+void UnityMenuModelPaths::setBusNameHint(const QByteArray &nameHint)
145+{
146+ if (m_busNameHint != nameHint) {
147+ m_busNameHint = nameHint;
148+ Q_EMIT busNameHintChanged();
149+
150+ updateData();
151+ }
152+}
153+
154+QByteArray UnityMenuModelPaths::actionsHint() const
155+{
156+ return m_actionsHint;
157+}
158+
159+void UnityMenuModelPaths::setActionsHint(const QByteArray &actionsHint)
160+{
161+ if (m_actionsHint != actionsHint) {
162+ m_actionsHint = actionsHint;
163+ Q_EMIT actionsHintChanged();
164+
165+ updateData();
166+ }
167+}
168+
169+QByteArray UnityMenuModelPaths::menuObjectPathHint() const
170+{
171+ return m_menuObjectPathHint;
172+}
173+
174+void UnityMenuModelPaths::setMenuObjectPathHint(const QByteArray &pathHint)
175+{
176+ if (m_menuObjectPathHint != pathHint) {
177+ m_menuObjectPathHint = pathHint;
178+ Q_EMIT menuObjectPathHintChanged();
179+
180+ updateData();
181+ }
182+}
plugins/Utils/unitymenumodelpaths.hnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Author: Nick Dedekind <nick.dedekind@canonical.com>
17+ */
18+
19+#ifndef UNITY_MENU_MODEL_PATHS_H
20+#define UNITY_MENU_MODEL_PATHS_H
21+
22+#include <QVariant>
23+
24+class UnityMenuModelPaths : public QObject
25+{
26+ Q_OBJECT
27+
28+ Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged)
29+ Q_PROPERTY(QByteArray busName READ busName NOTIFY busNameChanged)
30+ Q_PROPERTY(QVariantMap actions READ actions NOTIFY actionsChanged)
31+ Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath NOTIFY menuObjectPathChanged)
32+
33+ Q_PROPERTY(QByteArray busNameHint READ busNameHint WRITE setBusNameHint NOTIFY busNameHintChanged)
34+ Q_PROPERTY(QByteArray actionsHint READ actionsHint WRITE setActionsHint NOTIFY actionsHintChanged)
35+ Q_PROPERTY(QByteArray menuObjectPathHint READ menuObjectPathHint WRITE setMenuObjectPathHint NOTIFY menuObjectPathHintChanged)
36+
37+public:
38+ explicit UnityMenuModelPaths(QObject *parent = 0);
39+
40+ QVariant source() const;
41+ void setSource(const QVariant& data);
42+
43+ QByteArray busName() const;
44+ QVariantMap actions() const;
45+ QByteArray menuObjectPath() const;
46+
47+ QByteArray busNameHint() const;
48+ QByteArray actionsHint() const;
49+ QByteArray menuObjectPathHint() const;
50+
51+Q_SIGNALS:
52+ void sourceChanged();
53+ void busNameChanged();
54+ void actionsChanged();
55+ void menuObjectPathChanged();
56+
57+ void busNameHintChanged();
58+ void actionsHintChanged();
59+ void menuObjectPathHintChanged();
60+
61+private:
62+ void setBusName(const QByteArray &name);
63+ void setActions(const QVariantMap& actions);
64+ void setMenuObjectPath(const QByteArray &path);
65+
66+ void setBusNameHint(const QByteArray& nameHint);
67+ void setActionsHint(const QByteArray &actionsHint);
68+ void setMenuObjectPathHint(const QByteArray &pathHint);
69+
70+ void updateData();
71+
72+ QVariant m_sourceData;
73+ QByteArray m_busName;
74+ QVariantMap m_actions;
75+ QByteArray m_menuObjectPath;
76+
77+ QByteArray m_busNameHint;
78+ QByteArray m_actionsHint;
79+ QByteArray m_menuObjectPathHint;
80+};
81+
82+#endif // UNITY_MENU_MODEL_PATHS_H
tests/mocks/QMenuModel/UnityMenuModel.qmlnew file+26
@@ -0,0 +1,26 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Mirco Müller <mirco.mueller@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+import QtQuick 2.0
21+
22+QtObject {
23+ property variant busName
24+ property variant actions
25+ property variant menuObjectPath
26+}
tests/mocks/QMenuModel/qmldir+1
@@ -1,2 +1,3 @@
11module QMenuModel
22QDBusActionGroup 0.1 QDBusActionGroup.qml
3+UnityMenuModel 0.1 UnityMenuModel.qml
tests/qmltests/CMakeLists.txt+1−1
@@ -63,7 +63,7 @@ add_qml_test(Greeter Infographics IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qml
6363add_qml_test(Hud Hud)
6464add_qml_test(Hud Result)
6565add_qml_test(Launcher Launcher IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
66−add_qml_test(Notifications Notifications IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_SOURCE_DIR}/tests/mocks)
66+add_qml_test(Notifications Notifications IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_SOURCE_DIR}/tests/mocks)
6767add_qml_test(Panel IndicatorRow)
6868add_qml_test(Panel Indicators IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
6969add_qml_test(Panel MenuContent IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})