Unity 8
SessionBroadcast.cpp
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  */
16 
17 #include "SessionBroadcast.h"
18 #include <QDBusConnection>
19 #include <QDBusConnectionInterface>
20 #include <QDBusInterface>
21 
22 #include <glib.h>
23 
24 SessionBroadcast::SessionBroadcast(QObject* parent)
25  : QObject(parent)
26 {
27  m_username = QString::fromUtf8(g_get_user_name());
28 
29  auto connection = QDBusConnection::SM_BUSNAME();
30  auto interface = connection.interface();
31  interface->startService(QStringLiteral("com.canonical.Unity.Greeter.Broadcast"));
32 
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);
37 
38  connect(m_broadcaster, SIGNAL(StartUrl(const QString &, const QString &)),
39  this, SLOT(onStartUrl(const QString &, const QString &)));
40 
41  connect(m_broadcaster, SIGNAL(ShowHome(const QString &)),
42  this, SLOT(onShowHome(const QString &)));
43 }
44 
45 void SessionBroadcast::requestUrlStart(const QString &username, const QString &url)
46 {
47  m_broadcaster->asyncCall(QStringLiteral("RequestUrlStart"), username, url);
48 }
49 
50 void SessionBroadcast::requestHomeShown(const QString &username)
51 {
52  m_broadcaster->asyncCall(QStringLiteral("RequestHomeShown"), username);
53 }
54 
55 void SessionBroadcast::onStartUrl(const QString &username, const QString &url)
56 {
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  }
63 }
64 
65 void SessionBroadcast::onShowHome(const QString &username)
66 {
67  // Only listen to requests meant for us
68  if (username == m_username) {
69  Q_EMIT showHome();
70  }
71 }