Introduce a URL handler and offer handling tel:/// urls
Summary: Makes it possible to handle tel urls with any KDE Connect device Test Plan: Manual testing Reviewers: #kde_connect, albertvaka, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: nicolasfella Differential Revision: https://phabricator.kde.org/D6120
This commit is contained in:
parent
72162bf8c9
commit
077bed106f
8 changed files with 266 additions and 21 deletions
|
@ -54,6 +54,7 @@ add_subdirectory(plugins)
|
||||||
add_subdirectory(cli)
|
add_subdirectory(cli)
|
||||||
add_subdirectory(indicator)
|
add_subdirectory(indicator)
|
||||||
add_subdirectory(fileitemactionplugin)
|
add_subdirectory(fileitemactionplugin)
|
||||||
|
add_subdirectory(urlhandler)
|
||||||
if(KF5DocTools_FOUND)
|
if(KF5DocTools_FOUND)
|
||||||
add_subdirectory(doc)
|
add_subdirectory(doc)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -27,33 +27,13 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KLocalizedString>
|
|
||||||
|
|
||||||
#include "interfaces/devicesmodel.h"
|
#include "interfaces/devicesmodel.h"
|
||||||
#include "interfaces/notificationsmodel.h"
|
#include "interfaces/notificationsmodel.h"
|
||||||
#include "interfaces/dbusinterfaces.h"
|
#include "interfaces/dbusinterfaces.h"
|
||||||
|
#include "interfaces/dbushelpers.h"
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
Q_REQUIRED_RESULT T blockOnReply(QDBusPendingReply<T> reply)
|
|
||||||
{
|
|
||||||
reply.waitForFinished();
|
|
||||||
if (reply.isError()) {
|
|
||||||
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return reply.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
void blockOnReply(QDBusPendingReply<void> reply)
|
|
||||||
{
|
|
||||||
reply.waitForFinished();
|
|
||||||
if (reply.isError()) {
|
|
||||||
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
48
interfaces/dbushelpers.h
Normal file
48
interfaces/dbushelpers.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of
|
||||||
|
* the License or (at your option) version 3 or any later version
|
||||||
|
* accepted by the membership of KDE e.V. (or its successor approved
|
||||||
|
* by the membership of KDE e.V.), which shall act as a proxy
|
||||||
|
* defined in Section 14 of version 3 of the license.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DBUSHELPERS_H
|
||||||
|
#define DBUSHELPERS_H
|
||||||
|
|
||||||
|
#include <QDBusPendingReply>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Q_REQUIRED_RESULT T blockOnReply(QDBusPendingReply<T> reply)
|
||||||
|
{
|
||||||
|
reply.waitForFinished();
|
||||||
|
if (reply.isError()) {
|
||||||
|
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return reply.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void blockOnReply(QDBusPendingReply<void> reply)
|
||||||
|
{
|
||||||
|
reply.waitForFinished();
|
||||||
|
if (reply.isError()) {
|
||||||
|
QTextStream(stderr) << i18n("error: ") << reply.error().message() << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
13
urlhandler/CMakeLists.txt
Normal file
13
urlhandler/CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
ki18n_wrap_ui(telhandler_SRCS dialog.ui)
|
||||||
|
|
||||||
|
add_executable(kdeconnect-handler kdeconnect-handler.cpp ${telhandler_SRCS})
|
||||||
|
|
||||||
|
target_link_libraries(kdeconnect-handler
|
||||||
|
kdeconnectinterfaces
|
||||||
|
Qt5::Widgets
|
||||||
|
KF5::CoreAddons
|
||||||
|
KF5::I18n
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS kdeconnect-handler ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
|
install(PROGRAMS org.kde.kdeconnect.telhandler.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
|
3
urlhandler/Messages.sh
Normal file
3
urlhandler/Messages.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
$XGETTEXT `find . -name '*.cpp'` -o $podir/kdeconnect-urlhandler.pot
|
82
urlhandler/dialog.ui
Normal file
82
urlhandler/dialog.ui
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>104</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Device to open the url with:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="urlLabel">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="devicePicker"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>224</x>
|
||||||
|
<y>80</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>103</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>292</x>
|
||||||
|
<y>86</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>103</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
110
urlhandler/kdeconnect-handler.cpp
Normal file
110
urlhandler/kdeconnect-handler.cpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2017 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of
|
||||||
|
* the License or (at your option) version 3 or any later version
|
||||||
|
* accepted by the membership of KDE e.V. (or its successor approved
|
||||||
|
* by the membership of KDE e.V.), which shall act as a proxy
|
||||||
|
* defined in Section 14 of version 3 of the license.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusConnection>
|
||||||
|
|
||||||
|
#include <KAboutData>
|
||||||
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
#include <interfaces/devicesmodel.h>
|
||||||
|
#include <interfaces/devicessortproxymodel.h>
|
||||||
|
#include <interfaces/dbusinterfaces.h>
|
||||||
|
#include <interfaces/dbushelpers.h>
|
||||||
|
#include "kdeconnect-version.h"
|
||||||
|
#include "ui_dialog.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show only devices that can be shared to
|
||||||
|
*/
|
||||||
|
class ShareDevicesProxyModel : public DevicesSortProxyModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override {
|
||||||
|
const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
|
||||||
|
auto device = qobject_cast<DeviceDbusInterface*>(idx.data(DevicesModel::DeviceRole).value<QObject*>());
|
||||||
|
return device->supportedPlugins().contains(QStringLiteral("kdeconnect_share"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
const QString description = i18n("KDE Connect URL handler");
|
||||||
|
KAboutData about(QStringLiteral("kdeconnect-urlhandler"),
|
||||||
|
description,
|
||||||
|
QStringLiteral(KDECONNECT_VERSION_STRING),
|
||||||
|
description,
|
||||||
|
KAboutLicense::GPL,
|
||||||
|
i18n("(C) 2017 Aleix Pol Gonzalez"));
|
||||||
|
about.addAuthor( QStringLiteral("Aleix Pol Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") );
|
||||||
|
KAboutData::setApplicationData(about);
|
||||||
|
|
||||||
|
QUrl urlToShare;
|
||||||
|
{
|
||||||
|
QCommandLineParser parser;
|
||||||
|
parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
|
||||||
|
parser.addHelpOption();
|
||||||
|
about.setupCommandLine(&parser);
|
||||||
|
parser.process(app);
|
||||||
|
about.processCommandLine(&parser);
|
||||||
|
if (parser.positionalArguments().count() != 1) {
|
||||||
|
parser.showHelp(1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst());
|
||||||
|
}
|
||||||
|
|
||||||
|
DevicesModel model;
|
||||||
|
model.setDisplayFilter(DevicesModel::Paired | DevicesModel::Reachable);
|
||||||
|
ShareDevicesProxyModel proxyModel;
|
||||||
|
proxyModel.setSourceModel(&model);
|
||||||
|
|
||||||
|
QDialog dialog;
|
||||||
|
dialog.setWindowTitle(urlToShare.toDisplayString());
|
||||||
|
Ui::Dialog uidialog;
|
||||||
|
uidialog.setupUi(&dialog);
|
||||||
|
uidialog.devicePicker->setModel(&proxyModel);
|
||||||
|
uidialog.urlLabel->setText(urlToShare.toDisplayString());
|
||||||
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
|
QUrl url = urlToShare;
|
||||||
|
const int currentDeviceIndex = uidialog.devicePicker->currentIndex();
|
||||||
|
if(!url.isEmpty() && currentDeviceIndex >= 0) {
|
||||||
|
const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString();
|
||||||
|
|
||||||
|
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl"));
|
||||||
|
msg.setArguments({ url.toString() });
|
||||||
|
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
8
urlhandler/org.kde.kdeconnect.telhandler.desktop
Normal file
8
urlhandler/org.kde.kdeconnect.telhandler.desktop
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=KDE Connect Phone URL Handler
|
||||||
|
Exec=kdeconnect-handler %U
|
||||||
|
Icon=kdeconnect
|
||||||
|
Type=Application
|
||||||
|
NoDisplay=true
|
||||||
|
|
||||||
|
MimeType=x-scheme-handler/tel
|
Loading…
Reference in a new issue