@@ -1,80 +0,0 @@
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−
17−#include "Upstart.h"
18−
19−#include <QDBusConnection>
20−#include <QProcess>
21−#include <unistd.h>
22−
23−class URLDispatcher : public QObject
24−{
25− Q_OBJECT
26− Q_CLASSINFO("D-Bus Interface", "com.canonical.URLDispatcher")
27−
28−public:
29− explicit URLDispatcher(Upstart *parent);
30−
31− Q_SCRIPTABLE void DispatchURL(const QString &url);
32−
33−private:
34− Upstart *m_parent;
35−};
36−
37−URLDispatcher::URLDispatcher(Upstart *parent)
38− : QObject(parent),
39− m_parent(parent)
40−{
41−}
42−
43−void URLDispatcher::DispatchURL(const QString &url)
44−{
45− Q_EMIT m_parent->dispatchURL(url);
46−}
47−
48−// Normal unity8 sessions are entirely driven by Upstart. But greeters
49−// are special. They need access to the file descriptors that lightdm
50−// creates for them and don't want to start all the services that a normal
51−// session would. So it's inconvenient to live within an upstart session.
52−// But... we still want to use Upstart for some services. So rather than being
53−// spawned *by* Upstart like unity8 is, we spawn *it* instead.
54−Upstart::Upstart(QObject *parent)
55− : QObject(parent)
56−{
57− // This class also manages our url-dispatcher interception, as it's sort of
58− // a service provided by Upstart normally. We intercept url-dispatcher
59− // because rather than spawning the handler for the URL in our own session,
60− // we want to do notify the user session to do it for us (and start an
61− // unlock in the process).
62− QDBusConnection connection = QDBusConnection::sessionBus();
63− URLDispatcher *dispatcher = new URLDispatcher(this);
64− connection.registerObject("/com/canonical/URLDispatcher", dispatcher, QDBusConnection::ExportScriptableContents);
65− connection.registerService("com.canonical.URLDispatcher");
66−
67− // Start upstart (unless it's already running, like if the user is testing
68− // locally on their desktop)
69− if (QString(qgetenv("UPSTART_SESSION")).isEmpty())
70− {
71− QProcess *upstart = new QProcess(this);
72− QString command = "/sbin/init --user --startup-event=unity8-greeter-started";
73− // in main.cpp, we convert client to server. Convert back here.
74− if (qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver")
75− command.prepend("/usr/bin/env QT_QPA_PLATFORM=ubuntumirclient ");
76− upstart->start(command);
77− }
78−}
79−
80−#include "Upstart.moc"