Add open on remote device (Desktop)
Summary: Add openFile to Share Plugin and extend handler to open local file urls Future extension: Modify the desktop file to allow Open with > Open on connected device Depends on D16605 Test Plan: Apply Android patch. Use kdeconnect-handler file:///somefile. Check phone for reaction Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: sredman, kdeconnect Tags: #kde_connect Maniphest Tasks: T8637 Differential Revision: https://phabricator.kde.org/D15294
This commit is contained in:
parent
8d831d018b
commit
ccd476c150
3 changed files with 21 additions and 2 deletions
|
@ -173,6 +173,18 @@ void SharePlugin::shareText(const QString& text)
|
|||
sendPacket(packet);
|
||||
}
|
||||
|
||||
void SharePlugin::openFile(const QUrl& url)
|
||||
{
|
||||
NetworkPacket packet(PACKET_TYPE_SHARE_REQUEST);
|
||||
if(url.isLocalFile()) {
|
||||
QSharedPointer<QIODevice> ioFile(new QFile(url.toLocalFile()));
|
||||
packet.setPayload(ioFile, ioFile->size());
|
||||
packet.set<QString>(QStringLiteral("filename"), QUrl(url).fileName());
|
||||
packet.set<bool>(QStringLiteral("open"), true);
|
||||
}
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
QString SharePlugin::dbusPath() const
|
||||
{
|
||||
return "/modules/kdeconnect/devices/" + device()->id() + "/share";
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
///Helper method, QDBus won't recognize QUrl
|
||||
Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url)); }
|
||||
Q_SCRIPTABLE void shareText(const QString& text);
|
||||
Q_SCRIPTABLE void openFile(const QString& file) { openFile(QUrl(file)); }
|
||||
|
||||
bool receivePacket(const NetworkPacket& np) override;
|
||||
void connected() override {}
|
||||
|
@ -53,6 +54,8 @@ Q_SIGNALS:
|
|||
|
||||
private:
|
||||
void shareUrl(const QUrl& url);
|
||||
void openFile(const QUrl& url);
|
||||
|
||||
|
||||
QUrl destinationDir() const;
|
||||
|
||||
|
|
|
@ -64,9 +64,11 @@ int main(int argc, char** argv)
|
|||
KAboutData::setApplicationData(about);
|
||||
|
||||
QUrl urlToShare;
|
||||
bool open;
|
||||
{
|
||||
QCommandLineParser parser;
|
||||
parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share"));
|
||||
parser.addOption(QCommandLineOption(QStringLiteral("open"), QStringLiteral("Open the file on the remote device")));
|
||||
parser.addHelpOption();
|
||||
about.setupCommandLine(&parser);
|
||||
parser.process(app);
|
||||
|
@ -77,6 +79,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst());
|
||||
open = parser.isSet(QStringLiteral("open"));
|
||||
}
|
||||
|
||||
DevicesModel model;
|
||||
|
@ -95,7 +98,7 @@ int main(int argc, char** argv)
|
|||
if (urlToShare.scheme() == QLatin1String("tel")) {
|
||||
displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme);
|
||||
uidialog.label->setText(i18n("Device to call %1 with:", displayUrl));
|
||||
} else if (urlToShare.isLocalFile()) {
|
||||
} else if (urlToShare.isLocalFile() && open) {
|
||||
displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile);
|
||||
uidialog.label->setText(i18n("Device to send %1 to:", displayUrl));
|
||||
} else {
|
||||
|
@ -110,8 +113,9 @@ int main(int argc, char** argv)
|
|||
const int currentDeviceIndex = uidialog.devicePicker->currentIndex();
|
||||
if(!url.isEmpty() && currentDeviceIndex >= 0) {
|
||||
const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString();
|
||||
const QString action = open && url.isLocalFile() ? QStringLiteral("openFile") : QStringLiteral("shareUrl");
|
||||
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl"));
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), action);
|
||||
msg.setArguments({ url.toString() });
|
||||
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue