on xenial help sign in
Add logout support.
625c324Ying-Chun Liu
plugins/Unity/CMakeLists.txt+1
@@ -1,2 +1,3 @@
1add_subdirectory(Indicators)
1add_subdirectory(Indicators)
2add_subdirectory(Launcher)
2add_subdirectory(Launcher)
3+add_subdirectory(Session)
plugins/Unity/Session/CMakeLists.txtnew file+17
@@ -0,0 +1,17 @@
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+)
4+
5+set(QMLSESSIONPLUGIN_SRC
6+ plugin.cpp
7+ dbusunitysessionservice.cpp
8+ )
9+
10+add_library(UnitySession-qml MODULE
11+ ${QMLSESSIONPLUGIN_SRC}
12+ )
13+
14+qt5_use_modules(UnitySession-qml DBus Qml)
15+
16+# export the qmldir and qmltypes files
17+add_unity8_plugin(Unity.Session 0.1 Unity/Session TARGETS UnitySession-qml)
plugins/Unity/Session/dbusunitysessionservice.cppnew file+46
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * 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+
17+// local
18+#include "dbusunitysessionservice.h"
19+
20+// Qt
21+#include <QDBusConnection>
22+
23+DBusUnitySessionService::DBusUnitySessionService() : QObject()
24+{
25+ QDBusConnection connection = QDBusConnection::sessionBus();
26+
27+ connection.registerService("com.canonical.Unity");
28+ connection.registerObject("/com/canonical/Unity/Session", this,
29+ QDBusConnection::ExportScriptableSignals
30+ | QDBusConnection::ExportScriptableSlots
31+ | QDBusConnection::ExportScriptableInvokables);
32+}
33+
34+DBusUnitySessionService::~DBusUnitySessionService()
35+{
36+}
37+
38+void DBusUnitySessionService::Logout()
39+{
40+ Q_EMIT logoutReady();
41+}
42+
43+void DBusUnitySessionService::RequestLogout()
44+{
45+ Q_EMIT logoutRequested(false);
46+}
plugins/Unity/Session/dbusunitysessionservice.hnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * 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+
17+#ifndef DBUSUNITYSESSIONSERVICE_H
18+#define DBUSUNITYSESSIONSERVICE_H
19+
20+#include <QObject>
21+
22+/**
23+ * DBusUnitySessionService provides com.canonical.Unity.Session dbus
24+ * interface.
25+ *
26+ * com.canonical.Unity.Session interface provides public methods
27+ * and signals to handle Logout/Reboot/Shutdown.
28+ */
29+class DBusUnitySessionService : public QObject
30+{
31+ Q_OBJECT
32+ Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
33+
34+public:
35+ DBusUnitySessionService();
36+ ~DBusUnitySessionService();
37+
38+Q_SIGNALS:
39+ /**
40+ * logoutRequested signal
41+ *
42+ * This signal is emitted when some applications request the system to
43+ * logout.
44+ * @param have_inhibitors if there are any special running applications
45+ * which inhibit the logout.
46+ */
47+ void logoutRequested(bool have_inhibitors);
48+
49+ /**
50+ * logoutReady signal
51+ *
52+ * This signal is emitted when all the apps are closed. And the system
53+ * is safe to logout.
54+ */
55+ void logoutReady();
56+
57+public Q_SLOTS:
58+ /**
59+ * Logout the system.
60+ *
61+ * This method directly logout the system without user's confirmation.
62+ * Ordinary applications should avoid calling this method. Please call
63+ * RequestLogout() to ask the user to decide logout or not.
64+ * This method will stop all the running applications and then signal
65+ * logoutReady when all the apps stopped.
66+ */
67+ Q_SCRIPTABLE void Logout();
68+
69+ /**
70+ * Issue a logout request.
71+ *
72+ * This method emit the logoutRequested signal to the shell with a boolean
73+ * which indicates if there's any inhibitors. The shell should receive
74+ * this signal and display a dialog to ask the user to confirm the logout
75+ * action. If confirmed, shell can call Logout() method to kill the apps
76+ * and then logout
77+ */
78+ Q_SCRIPTABLE void RequestLogout();
79+
80+};
81+
82+#endif // DBUSUNITYSESSIONSERVICE_H
plugins/Unity/Session/plugin.cppnew file+40
@@ -0,0 +1,40 @@
1+/*
2+ * Copyright (C) 2014 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+ * Authors: Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
17+ */
18+
19+#include "plugin.h"
20+#include "dbusunitysessionservice.h"
21+
22+#include <QAbstractItemModel>
23+#include <QDBusConnection>
24+#include <QtQml/qqml.h>
25+
26+static QObject *dbusunitysessionservice_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
27+{
28+ Q_UNUSED(engine)
29+ Q_UNUSED(scriptEngine)
30+
31+ return new DBusUnitySessionService();
32+}
33+
34+void SessionPlugin::registerTypes(const char *uri)
35+{
36+ qmlRegisterType<QAbstractItemModel>();
37+
38+ Q_ASSERT(uri == QLatin1String("Unity.Session"));
39+ qmlRegisterSingletonType<DBusUnitySessionService>(uri, 0, 1, "DBusUnitySessionService", dbusunitysessionservice_provider);
40+}
plugins/Unity/Session/plugin.hnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2014 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+ * Authors: Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
17+ */
18+
19+#ifndef SESSION_PLUGIN_H
20+#define SESSION_PLUGIN_H
21+
22+#include <QtQml/QQmlEngine>
23+#include <QtQml/QQmlExtensionPlugin>
24+
25+class SessionPlugin : public QQmlExtensionPlugin
26+{
27+ Q_OBJECT
28+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29+
30+public:
31+ void registerTypes(const char *uri);
32+};
33+
34+#endif
plugins/Unity/Session/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.Session
2+plugin UnitySession-qml
3+typeinfo UnitySession.qmltypes
qml/Shell.qml+25
@@ -31,6 +31,7 @@ import "Panel"
31import "Components"
31import "Components"
32import "Notifications"
32import "Notifications"
33import Unity.Notifications 1.0 as NotificationBackend
33import Unity.Notifications 1.0 as NotificationBackend
34+import Unity.Session 0.1
34
35
35FocusScope {
36FocusScope {
36 id: shell
37 id: shell
@@ -267,6 +268,30 @@ FocusScope {
267 }
268 }
268 }
269 }
269
270
271+ Connections {
272+ target: DBusUnitySessionService
273+
274+ function closeAllApps() {
275+ while (true) {
276+ var app = ApplicationManager.get(0);
277+ if (app === null) {
278+ break;
279+ }
280+ ApplicationManager.stopApplication(app.appId);
281+ }
282+ }
283+
284+ onLogoutRequested: {
285+ // TODO: Display a dialog to ask the user to confirm.
286+ DBusUnitySessionService.Logout();
287+ }
288+
289+ onLogoutReady: {
290+ closeAllApps();
291+ Qt.quit();
292+ }
293+ }
294+
270 Loader {
295 Loader {
271 id: applicationsDisplayLoader
296 id: applicationsDisplayLoader
272 anchors.fill: parent
297 anchors.fill: parent
src/main.cpp+1
@@ -161,6 +161,7 @@ Load the testability driver");
161
161
162 view->setSource(source);
162 view->setSource(source);
163 view->setColor("transparent");
163 view->setColor("transparent");
164+ QObject::connect(view->engine(), SIGNAL(quit()), application, SLOT(quit()));
164
165
165 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
166 if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || parser.isSet(fullscreenOption)) {
166 view->showFullScreen();
167 view->showFullScreen();
tests/plugins/Unity/CMakeLists.txt+1
@@ -1,2 +1,3 @@
1add_subdirectory(Indicators)
1add_subdirectory(Indicators)
2add_subdirectory(Launcher)
2add_subdirectory(Launcher)
3+add_subdirectory(Session)
tests/plugins/Unity/Session/CMakeLists.txtnew file+20
@@ -0,0 +1,20 @@
1+include_directories(
2+ ${CMAKE_CURRENT_BINARY_DIR}
3+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Session
4+)
5+
6+add_definitions(-DSM_BUSNAME=sessionBus)
7+add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
8+add_definitions(-DSESSION_TESTING)
9+
10+### SessionBackendTest
11+set(testBackendCommand dbus-test-runner --task ${CMAKE_CURRENT_BINARY_DIR}/sessionbackendtestExec
12+ --parameter -o --parameter ${CMAKE_BINARY_DIR}/sessionbackendtest.xml,xunitxml
13+ --parameter -o --parameter -,txt)
14+add_test(NAME sessionbackendtest COMMAND ${testBackendCommand})
15+add_custom_target(sessionbackendtest ${testBackendCommand})
16+add_executable(sessionbackendtestExec
17+ sessionbackendtest.cpp
18+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Session/dbusunitysessionservice.cpp
19+)
20+qt5_use_modules(sessionbackendtestExec Test Core Qml DBus)
tests/plugins/Unity/Session/sessionbackendtest.cppnew file+64
@@ -0,0 +1,64 @@
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+ * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18+ */
19+
20+#include <QtTest>
21+#include <QDBusConnection>
22+#include <QDBusMessage>
23+#include <QDBusInterface>
24+#include <QDBusReply>
25+#include <QDBusVariant>
26+
27+#include "dbusunitysessionservice.h"
28+
29+class SessionBackendTest : public QObject
30+{
31+ Q_OBJECT
32+
33+private Q_SLOTS:
34+
35+ void initTestCase() {
36+ }
37+
38+ void testDbusIfaceMethods_data() {
39+ QTest::addColumn<QString>("method");
40+
41+ QTest::newRow("Logout") << "RequestLogout";
42+ }
43+
44+ void testDbusIfaceMethods() {
45+ QFETCH(QString, method);
46+
47+ DBusUnitySessionService dbusUnitySessionService;
48+
49+ QDBusConnection con = QDBusConnection::sessionBus();
50+ QDBusInterface interface ("com.canonical.Unity",
51+ "/com/canonical/Unity/Session",
52+ "com.canonical.Unity.Session",
53+ con);
54+ QDBusReply<void> reply;
55+
56+ QCOMPARE(interface.isValid(), true);
57+ reply = interface.call(method);
58+ QCOMPARE(reply.isValid(), true);
59+
60+ }
61+};
62+
63+QTEST_GUILESS_MAIN(SessionBackendTest)
64+#include "sessionbackendtest.moc"