on xenial help sign in
Add URLDispatcher intercepter
commit965723a9bc850fcf4ef199a89ba4308ab68b9f52 authorMichael Terry <michael.terry@canonical.com> dateWed 4 Dec 2013, 17:57 (13 years ago) parentbcf629e
5 files changed+106−1
GreeterShell.qml+5 plugins/LightDM/CMakeLists.txt+2−1 plugins/LightDM/URLDispatcher.cpp+56 plugins/LightDM/URLDispatcher.h+34 plugins/LightDM/plugin.cpp+9
GreeterShell.qml+5
@@ -229,6 +229,11 @@ BasicShell {
229229 }
230230*/
231231
232+ Connections {
233+ target: LightDM.URLDispatcher
234+ onDispatchURL: shell.activateApplication(url)
235+ }
236+
232237 GreeterEdgeDemo {
233238 id: edgeDemo
234239 greeter: greeter
plugins/LightDM/CMakeLists.txt+2−1
@@ -17,6 +17,7 @@ set(QMLPLUGIN_SRC
1717 ${CMAKE_SOURCE_DIR}/plugins/Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
1818 Greeter.cpp
1919 plugin.cpp
20+ URLDispatcher.cpp
2021 UsersModel.cpp
2122 )
2223
@@ -29,7 +30,7 @@ target_link_libraries(LightDM-qml
2930 ${LIBUSERMETRICSOUTPUT_LDFLAGS}
3031 )
3132
32−qt5_use_modules(LightDM-qml Qml)
33+qt5_use_modules(LightDM-qml DBus Qml)
3334
3435# export the qmldir qmltypes and plugin files
3536export_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 @@
1919
2020#include "plugin.h"
2121#include "Greeter.h"
22+#include "URLDispatcher.h"
2223#include "UsersModel.h"
2324#include <libusermetricsoutput/ColorTheme.h>
2425#include <libusermetricsoutput/UserMetrics.h>
@@ -34,6 +35,13 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3435 return new Greeter();
3536}
3637
38+static QObject *dispatcher_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
39+{
40+ Q_UNUSED(engine)
41+ Q_UNUSED(scriptEngine)
42+ return new URLDispatcher();
43+}
44+
3745static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3846{
3947 Q_UNUSED(engine)
@@ -55,6 +63,7 @@ void LightDMPlugin::registerTypes(const char *uri)
5563
5664 Q_ASSERT(uri == QLatin1String("LightDM"));
5765 qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
66+ qmlRegisterSingletonType<URLDispatcher>(uri, 0, 1, "URLDispatcher", dispatcher_provider);
5867 qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
5968 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
6069 qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);