on xenial help sign in
Add URLDispatcher intercepter
965723aMichael Terry
GreeterShell.qml+5
@@ -229,6 +229,11 @@ BasicShell {
229 }
229 }
230*/
230*/
231
231
232+ Connections {
233+ target: LightDM.URLDispatcher
234+ onDispatchURL: shell.activateApplication(url)
235+ }
236+
232 GreeterEdgeDemo {
237 GreeterEdgeDemo {
233 id: edgeDemo
238 id: edgeDemo
234 greeter: greeter
239 greeter: greeter
plugins/LightDM/CMakeLists.txt+2−1
@@ -17,6 +17,7 @@ set(QMLPLUGIN_SRC
17 ${CMAKE_SOURCE_DIR}/plugins/Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
17 ${CMAKE_SOURCE_DIR}/plugins/Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
18 Greeter.cpp
18 Greeter.cpp
19 plugin.cpp
19 plugin.cpp
20+ URLDispatcher.cpp
20 UsersModel.cpp
21 UsersModel.cpp
21 )
22 )
22
23
@@ -29,7 +30,7 @@ target_link_libraries(LightDM-qml
29 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
30 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
30 )
31 )
31
32
32−qt5_use_modules(LightDM-qml Qml)
33+qt5_use_modules(LightDM-qml DBus Qml)
33
34
34# export the qmldir qmltypes and plugin files
35# export the qmldir qmltypes and plugin files
35export_qmlfiles(LightDM LightDM)
36export_qmlfiles(LightDM LightDM)
plugins/LightDM/URLDispatcher.cppnew file+56
@@ -0,0 +1,56 @@
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 "URLDispatcher.h"
18+
19+#include <QDBusConnection>
20+
21+class DBusURLDispatcher : public QObject
22+{
23+ Q_OBJECT
24+ Q_CLASSINFO("D-Bus Interface", "com.canonical.URLDispatcher")
25+
26+public:
27+ explicit DBusURLDispatcher(URLDispatcher *parent);
28+
29+ Q_SCRIPTABLE void DispatchURL(const QString &url);
30+
31+private:
32+ URLDispatcher *m_parent;
33+};
34+
35+DBusURLDispatcher::DBusURLDispatcher(URLDispatcher *parent)
36+ : QObject(parent),
37+ m_parent(parent)
38+{
39+}
40+
41+void DBusURLDispatcher::DispatchURL(const QString &url)
42+{
43+ Q_EMIT m_parent->dispatchURL(url);
44+}
45+
46+URLDispatcher::URLDispatcher(QObject *parent)
47+ : QObject(parent)
48+{
49+ // Own url dispatcher on DBus, we want to intercept these calls
50+ QDBusConnection connection = QDBusConnection::sessionBus();
51+ DBusURLDispatcher *dispatcher = new DBusURLDispatcher(this);
52+ connection.registerObject("/com/canonical/URLDispatcher", dispatcher, QDBusConnection::ExportScriptableContents);
53+ connection.registerService("com.canonical.URLDispatcher");
54+}
55+
56+#include "URLDispatcher.moc"
plugins/LightDM/URLDispatcher.hnew file+34
@@ -0,0 +1,34 @@
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+#ifndef UNITY_URLDISPATCHER_H
18+#define UNITY_URLDISPATCHER_H
19+
20+#include <QObject>
21+#include <QString>
22+
23+class URLDispatcher : public QObject
24+{
25+ Q_OBJECT
26+
27+public:
28+ explicit URLDispatcher(QObject *parent=0);
29+
30+Q_SIGNALS:
31+ void dispatchURL(const QString &url);
32+};
33+
34+#endif
plugins/LightDM/plugin.cpp+9
@@ -19,6 +19,7 @@
19
19
20#include "plugin.h"
20#include "plugin.h"
21#include "Greeter.h"
21#include "Greeter.h"
22+#include "URLDispatcher.h"
22#include "UsersModel.h"
23#include "UsersModel.h"
23#include <libusermetricsoutput/ColorTheme.h>
24#include <libusermetricsoutput/ColorTheme.h>
24#include <libusermetricsoutput/UserMetrics.h>
25#include <libusermetricsoutput/UserMetrics.h>
@@ -34,6 +35,13 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
34 return new Greeter();
35 return new Greeter();
35}
36}
36
37
38+static QObject *dispatcher_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
39+{
40+ Q_UNUSED(engine)
41+ Q_UNUSED(scriptEngine)
42+ return new URLDispatcher();
43+}
44+
37static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
45static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
38{
46{
39 Q_UNUSED(engine)
47 Q_UNUSED(engine)
@@ -55,6 +63,7 @@ void LightDMPlugin::registerTypes(const char *uri)
55
63
56 Q_ASSERT(uri == QLatin1String("LightDM"));
64 Q_ASSERT(uri == QLatin1String("LightDM"));
57 qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
65 qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
66+ qmlRegisterSingletonType<URLDispatcher>(uri, 0, 1, "URLDispatcher", dispatcher_provider);
58 qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
67 qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
59 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
68 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
60 qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
69 qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);