@@ -0,0 +1,70 @@
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: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#include "SessionBroadcast.h"
20+#include <QDBusConnection>
21+#include <QDBusConnectionInterface>
22+#include <QDBusInterface>
23+#include <QFileInfo>
24+
25+SessionBroadcast::SessionBroadcast(QObject* parent)
26+ : QObject(parent),
27+ broadcaster(NULL)
28+{
29+ auto connection = QDBusConnection::SM_BUSNAME();
30+ auto interface = connection.interface();
31+ interface->startService("com.canonical.Unity.Greeter.Broadcast");
32+ broadcaster = new QDBusInterface("com.canonical.Unity.Greeter.Broadcast",
33+ "/com/canonical/Unity/Greeter/Broadcast",
34+ "com.canonical.Unity.Greeter.Broadcast",
35+ connection, this);
36+
37+ connection.connect("com.canonical.Unity.Greeter.Broadcast",
38+ "/com/canonical/Unity/Greeter/Broadcast",
39+ "com.canonical.Unity.Greeter.Broadcast",
40+ "StartApplication",
41+ this,
42+ SLOT(onStartApplication(const QString &, const QString &)));
43+}
44+
45+void SessionBroadcast::requestApplicationStart(const QString &username, const QString &appId)
46+{
47+ // unity-greeter-session-broadcast deals in short appIds. That is,
48+ // desktop file names without the ".desktop". It doesn't really allow
49+ // for arbitrary-path desktop files, for security reasons (hard to
50+ // contain with apparmor and such). So we need to mangle the names a bit.
51+ // If incoming appId is random path like /hello/foobar.desktop, then just
52+ // do our best and ask for foobar.
53+ QString desktopSuffix = ".desktop";
54+ QString mangled = appId;
55+ if (mangled.endsWith(desktopSuffix))
56+ mangled.chop(desktopSuffix.size());
57+ mangled = QFileInfo(mangled).fileName(); // chop off path
58+
59+ broadcaster->asyncCall("RequestApplicationStart", username, mangled);
60+}
61+
62+void SessionBroadcast::onStartApplication(const QString &username, const QString &appId)
63+{
64+ // Since this signal is just used for testing, we don't *really* care if
65+ // username matches, but just in case we do eventually use the signal, we
66+ // should only listen to our own requests.
67+ if (username == qgetenv("USER")) {
68+ Q_EMIT startApplication(appId);
69+ }
70+}