on bionic help sign in
unity8/plugins/SessionBroadcast/SessionBroadcast.cpp
71 lines 2.6 kB history raw
1/*
2 * Copyright (C) 2013,2016 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 */
17#include "SessionBroadcast.h"
18#include <QDBusConnection>
19#include <QDBusConnectionInterface>
20#include <QDBusInterface>
22#include <glib.h>
24SessionBroadcast::SessionBroadcast(QObject* parent)
25 : QObject(parent)
27 m_username = QString::fromUtf8(g_get_user_name());
29 auto connection = QDBusConnection::SM_BUSNAME();
30 auto interface = connection.interface();
31 interface->startService(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"));
33 m_broadcaster = new QDBusInterface(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"),
34 QStringLiteral("/com/canonical/Unity/Greeter/Broadcast"),
35 QStringLiteral("com.canonical.Unity.Greeter.Broadcast"),
36 connection, this);
38 connect(m_broadcaster, SIGNAL(StartUrl(const QString &, const QString &)),
39 this, SLOT(onStartUrl(const QString &, const QString &)));
41 connect(m_broadcaster, SIGNAL(ShowHome(const QString &)),
42 this, SLOT(onShowHome(const QString &)));
45void SessionBroadcast::requestUrlStart(const QString &username, const QString &url)
47 m_broadcaster->asyncCall(QStringLiteral("RequestUrlStart"), username, url);
50void SessionBroadcast::requestHomeShown(const QString &username)
52 m_broadcaster->asyncCall(QStringLiteral("RequestHomeShown"), username);
55void SessionBroadcast::onStartUrl(const QString &username, const QString &url)
57 // Since this signal is just used for testing, we don't *really* care if
58 // username matches, but just in case we do eventually use the signal, we
59 // should only listen to our own requests.
60 if (username == m_username) {
61 Q_EMIT startUrl(url);
62 }
65void SessionBroadcast::onShowHome(const QString &username)
67 // Only listen to requests meant for us
68 if (username == m_username) {
69 Q_EMIT showHome();
70 }