on xenial help sign in
Add Session logout.
commit578bc338334c96501d095926a8279b15bc567e65 authorYing-Chun Liu <paul.liu@canonical.com> dateTue 6 May 2014, 22:28 (12 years ago) parentb2d436e
8 files changed+261−1
plugins/Unity/CMakeLists.txt+1 plugins/Unity/Session/CMakeLists.txt+23 plugins/Unity/Session/dbusunitysessionservice.cpp+58 plugins/Unity/Session/dbusunitysessionservice.h+84 plugins/Unity/Session/plugin.cpp+41 plugins/Unity/Session/plugin.h+35 plugins/Unity/Session/qmldir+3 qml/Shell.qml+16−1
plugins/Unity/CMakeLists.txt+1
@@ -1,2 +1,3 @@
11add_subdirectory(Indicators)
22add_subdirectory(Launcher)
3+add_subdirectory(Session)
plugins/Unity/Session/CMakeLists.txtnew file+23
@@ -0,0 +1,23 @@
1+include(Plugins)
2+include(FindPkgConfig)
3+
4+include_directories(
5+ ${CMAKE_CURRENT_SOURCE_DIR}
6+)
7+
8+set(QMLSESSIONPLUGIN_SRC
9+ plugin.cpp
10+ dbusunitysessionservice.cpp
11+ )
12+
13+add_library(UnitySession-qml MODULE
14+ ${QMLSESSIONPLUGIN_SRC}
15+ )
16+
17+target_link_libraries(UnitySession-qml)
18+
19+qt5_use_modules(UnitySession-qml DBus Qml)
20+
21+# export the qmldir and qmltypes files
22+export_qmlfiles(Unity.Session Unity/Session)
23+export_qmlplugin(Unity.Session 0.1 Unity/Session TARGETS UnitySession-qml)
plugins/Unity/Session/dbusunitysessionservice.cppnew file+58
@@ -0,0 +1,58 @@
1+/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4 -*- */
2+/*
3+ * Copyright (C) 2014 Canonical, Ltd.
4+ *
5+ * This program is free software: you can redistribute it and/or modify it under
6+ * the terms of the GNU Lesser General Public License version 3, as published by
7+ * the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+// local
19+#include "dbusunitysessionservice.h"
20+
21+// Qt
22+#include <QDBusConnection>
23+
24+DBusUnitySessionService::DBusUnitySessionService() : QObject()
25+{
26+ QDBusConnection connection = QDBusConnection::sessionBus();
27+
28+ connection.registerService("com.canonical.Unity.Session");
29+ connection.registerObject("/com/canonical/Unity/Session", this,
30+ QDBusConnection::ExportScriptableSignals
31+ | QDBusConnection::ExportScriptableSlots
32+ | QDBusConnection::ExportScriptableInvokables);
33+}
34+
35+DBusUnitySessionService::DBusUnitySessionService(QObject *parent) : QObject(parent)
36+{
37+ QDBusConnection connection = QDBusConnection::sessionBus();
38+
39+ connection.registerService("com.canonical.Unity.Session");
40+ connection.registerObject("/com/canonical/Unity/Session", this,
41+ QDBusConnection::ExportScriptableSignals
42+ | QDBusConnection::ExportScriptableSlots
43+ | QDBusConnection::ExportScriptableInvokables);
44+}
45+
46+DBusUnitySessionService::~DBusUnitySessionService()
47+{
48+}
49+
50+void DBusUnitySessionService::Logout()
51+{
52+ Q_EMIT logoutReady();
53+}
54+
55+void DBusUnitySessionService::RequestLogout()
56+{
57+ Q_EMIT logoutRequested(false);
58+}
plugins/Unity/Session/dbusunitysessionservice.hnew file+84
@@ -0,0 +1,84 @@
1+/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4 -*- */
2+/*
3+ * Copyright (C) 2014 Canonical, Ltd.
4+ *
5+ * This program is free software: you can redistribute it and/or modify it under
6+ * the terms of the GNU Lesser General Public License version 3, as published by
7+ * the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#ifndef DBUSUNITYSESSIONSERVICE_H_1397562297
19+#define DBUSUNITYSESSIONSERVICE_H_1397562297
20+
21+#include <QObject>
22+
23+/**
24+ * DBusUnitySessionService provides com.canonical.Unity.Session dbus
25+ * interface.
26+ *
27+ * com.canonical.Unity.Session interface provides public methods
28+ * and signals to handle Logout/Reboot/Shutdown.
29+ */
30+class DBusUnitySessionService : public QObject
31+{
32+ Q_OBJECT
33+ Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
34+
35+public:
36+ DBusUnitySessionService();
37+ explicit DBusUnitySessionService(QObject* parent);
38+ ~DBusUnitySessionService();
39+
40+Q_SIGNALS:
41+ /**
42+ * logoutRequested signal
43+ *
44+ * This signal is emitted when some applications request the system to
45+ * logout.
46+ * @param have_inhibitors if there are any special running applications
47+ * which inhibit the logout.
48+ */
49+ void logoutRequested(bool have_inhibitors);
50+
51+ /**
52+ * logoutReady signal
53+ *
54+ * This signal is emitted when all the apps are closed. And the system
55+ * is safe to logout.
56+ */
57+ void logoutReady();
58+
59+public Q_SLOTS:
60+ /**
61+ * Logout the system.
62+ *
63+ * This method directly logout the system without user's confirmation.
64+ * Ordinary applications should avoid calling this method. Please call
65+ * RequestLogout() to ask the user to decide logout or not.
66+ * This method will stop all the running applications and then signal
67+ * logoutReady when all the apps stopped.
68+ */
69+ Q_SCRIPTABLE void Logout();
70+
71+ /**
72+ * Issue a logout request.
73+ *
74+ * This method emit the logoutRequested signal to the shell with a boolean
75+ * which indicates if there's any inhibitors. The shell should receive
76+ * this signal and display a dialog to ask the user to confirm the logout
77+ * action. If confirmed, shell can call Logout() method to kill the apps
78+ * and then logout
79+ */
80+ Q_SCRIPTABLE void RequestLogout();
81+
82+};
83+
84+#endif // DBUSUNITYSESSIONSERVICE_H_1397562297
plugins/Unity/Session/plugin.cppnew file+41
@@ -0,0 +1,41 @@
1+/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4 -*- */
2+/*
3+ * Copyright (C) 2014 Canonical, Ltd.
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; version 3.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ * Authors: Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18+ */
19+
20+#include "plugin.h"
21+#include "dbusunitysessionservice.h"
22+
23+#include <QAbstractItemModel>
24+#include <QDBusConnection>
25+#include <QtQml/qqml.h>
26+
27+static QObject *dbusunitysessionservice_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
28+{
29+ Q_UNUSED(engine)
30+ Q_UNUSED(scriptEngine)
31+
32+ return new DBusUnitySessionService();
33+}
34+
35+void SessionPlugin::registerTypes(const char *uri)
36+{
37+ qmlRegisterType<QAbstractItemModel>();
38+
39+ Q_ASSERT(uri == QLatin1String("Unity.Session"));
40+ qmlRegisterSingletonType<DBusUnitySessionService>(uri, 0, 1, "DBusUnitySessionService", dbusunitysessionservice_provider);
41+}
plugins/Unity/Session/plugin.hnew file+35
@@ -0,0 +1,35 @@
1+/* -*- mode: c++; indent-tabs-mode: nil; tab-width: 4 -*- */
2+/*
3+ * Copyright (C) 2014 Canonical, Ltd.
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; version 3.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ * Authors: Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18+ */
19+
20+#ifndef SESSION_PLUGIN_H
21+#define SESSION_PLUGIN_H
22+
23+#include <QtQml/QQmlEngine>
24+#include <QtQml/QQmlExtensionPlugin>
25+
26+class SessionPlugin : 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
plugins/Unity/Session/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.Session
2+plugin UnitySession-qml
3+typeinfo plugin.qmltypes
qml/Shell.qml+16−1
@@ -33,6 +33,7 @@ import "Components"
3333import "Bottombar"
3434import "Notifications"
3535import Unity.Notifications 1.0 as NotificationBackend
36+import Unity.Session 0.1
3637
3738FocusScope {
3839 id: shell
@@ -276,8 +277,22 @@ FocusScope {
276277 stages.hide();
277278 }
278279 }
280+ }
281+
282+ Connections {
283+ target: DBusUnitySessionService
279284
280− onUnityLogout: {
285+ onLogoutRequested: {
286+ }
287+
288+ onLogoutReady: {
289+ while (true) {
290+ var app = ApplicationManager.get(0);
291+ if (app === null) {
292+ break;
293+ }
294+ ApplicationManager.stopApplication(app.appId);
295+ }
281296 Qt.quit();
282297 }
283298 }