17 #include "URLDispatcher.h" 19 #include <QDBusConnection> 21 class URLDispatcherInterface :
public QObject
24 Q_CLASSINFO(
"D-Bus Interface",
"com.canonical.URLDispatcher")
27 explicit URLDispatcherInterface(URLDispatcher *parent);
29 Q_SCRIPTABLE
void DispatchURL(const QString &url, const QString &package);
32 URLDispatcherInterface::URLDispatcherInterface(URLDispatcher *parent)
37 void URLDispatcherInterface::DispatchURL(
const QString &url,
const QString &package)
40 Q_EMIT
static_cast<URLDispatcher *
>(parent())->urlRequested(url);
43 URLDispatcher::URLDispatcher(QObject *parent)
45 , m_dispatcher(nullptr)
49 bool URLDispatcher::active()
const 51 return m_dispatcher !=
nullptr;
54 void URLDispatcher::setActive(
bool value)
56 if (value == active())
59 QDBusConnection connection = QDBusConnection::sessionBus();
62 URLDispatcherInterface *dispatcher =
new URLDispatcherInterface(
this);
63 connection.registerObject(QStringLiteral(
"/com/canonical/URLDispatcher"),
65 QDBusConnection::ExportScriptableContents);
66 connection.registerService(QStringLiteral(
"com.canonical.URLDispatcher"));
67 m_dispatcher = dispatcher;
69 connection.unregisterService(QStringLiteral(
"com.canonical.URLDispatcher"));
71 m_dispatcher =
nullptr;
74 Q_EMIT activeChanged();
77 #include "URLDispatcher.moc"