Changeset View
Changeset View
Standalone View
Standalone View
urlhandler/kdeconnect-handler.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 57 | KAboutData about(QStringLiteral("kdeconnect-urlhandler"), | |||
---|---|---|---|---|---|
59 | QStringLiteral(KDECONNECT_VERSION_STRING), | 59 | QStringLiteral(KDECONNECT_VERSION_STRING), | ||
60 | description, | 60 | description, | ||
61 | KAboutLicense::GPL, | 61 | KAboutLicense::GPL, | ||
62 | i18n("(C) 2017 Aleix Pol Gonzalez")); | 62 | i18n("(C) 2017 Aleix Pol Gonzalez")); | ||
63 | about.addAuthor( QStringLiteral("Aleix Pol Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | 63 | about.addAuthor( QStringLiteral("Aleix Pol Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org") ); | ||
64 | KAboutData::setApplicationData(about); | 64 | KAboutData::setApplicationData(about); | ||
65 | 65 | | |||
66 | QUrl urlToShare; | 66 | QUrl urlToShare; | ||
67 | bool open; | ||||
67 | { | 68 | { | ||
68 | QCommandLineParser parser; | 69 | QCommandLineParser parser; | ||
69 | parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share")); | 70 | parser.addPositionalArgument(QStringLiteral("url"), i18n("URL to share")); | ||
71 | parser.addOption(QCommandLineOption(QStringLiteral("open"), QStringLiteral("Open the file on the remote device"))); | ||||
70 | parser.addHelpOption(); | 72 | parser.addHelpOption(); | ||
71 | about.setupCommandLine(&parser); | 73 | about.setupCommandLine(&parser); | ||
72 | parser.process(app); | 74 | parser.process(app); | ||
73 | about.processCommandLine(&parser); | 75 | about.processCommandLine(&parser); | ||
74 | if (parser.positionalArguments().count() != 1) { | 76 | if (parser.positionalArguments().count() != 1) { | ||
75 | parser.showHelp(1); | 77 | parser.showHelp(1); | ||
76 | return 1; | 78 | return 1; | ||
77 | } | 79 | } | ||
78 | 80 | | |||
79 | urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst()); | 81 | urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst()); | ||
82 | open = parser.isSet(QStringLiteral("open")); | ||||
80 | } | 83 | } | ||
81 | 84 | | |||
82 | DevicesModel model; | 85 | DevicesModel model; | ||
83 | model.setDisplayFilter(DevicesModel::Paired | DevicesModel::Reachable); | 86 | model.setDisplayFilter(DevicesModel::Paired | DevicesModel::Reachable); | ||
84 | ShareDevicesProxyModel proxyModel; | 87 | ShareDevicesProxyModel proxyModel; | ||
85 | proxyModel.setSourceModel(&model); | 88 | proxyModel.setSourceModel(&model); | ||
86 | 89 | | |||
87 | QDialog dialog; | 90 | QDialog dialog; | ||
88 | dialog.setWindowTitle(urlToShare.toDisplayString(QUrl::PreferLocalFile)); | 91 | dialog.setWindowTitle(urlToShare.toDisplayString(QUrl::PreferLocalFile)); | ||
89 | Ui::Dialog uidialog; | 92 | Ui::Dialog uidialog; | ||
90 | uidialog.setupUi(&dialog); | 93 | uidialog.setupUi(&dialog); | ||
91 | uidialog.devicePicker->setModel(&proxyModel); | 94 | uidialog.devicePicker->setModel(&proxyModel); | ||
92 | 95 | | |||
93 | if (urlToShare.scheme() == QLatin1String("tel")) { | 96 | if (urlToShare.scheme() == QLatin1String("tel")) { | ||
94 | uidialog.label->setText(i18n("Device to call this phone number with:")); | 97 | uidialog.label->setText(i18n("Device to call this phone number with:")); | ||
95 | uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::RemoveScheme)); | 98 | uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::RemoveScheme)); | ||
96 | } else if (urlToShare.isLocalFile()) { | 99 | } else if (urlToShare.isLocalFile()) { | ||
100 | | ||||
101 | if (open) { | ||||
102 | uidialog.label->setText(i18n("Device to open this file on:")); | ||||
103 | } else { | ||||
97 | uidialog.label->setText(i18n("Device to send this file to:")); | 104 | uidialog.label->setText(i18n("Device to send this file to:")); | ||
105 | } | ||||
106 | | ||||
98 | uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::PreferLocalFile)); | 107 | uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::PreferLocalFile)); | ||
99 | } else { | 108 | } else { | ||
100 | uidialog.urlLabel->setText(urlToShare.toDisplayString()); | 109 | uidialog.urlLabel->setText(urlToShare.toDisplayString()); | ||
101 | } | 110 | } | ||
102 | 111 | | |||
103 | if (dialog.exec() == QDialog::Accepted) { | 112 | if (dialog.exec() == QDialog::Accepted) { | ||
104 | QUrl url = urlToShare; | 113 | QUrl url = urlToShare; | ||
105 | const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); | 114 | const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); | ||
106 | if(!url.isEmpty() && currentDeviceIndex >= 0) { | 115 | if(!url.isEmpty() && currentDeviceIndex >= 0) { | ||
107 | const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); | 116 | const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); | ||
117 | const QString action = open && url.isLocalFile() ? QStringLiteral("openFile") : QStringLiteral("shareUrl"); | ||||
108 | 118 | | |||
109 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); | 119 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), action); | ||
110 | msg.setArguments({ url.toString() }); | 120 | msg.setArguments({ url.toString() }); | ||
111 | blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); | 121 | blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); | ||
112 | return 0; | 122 | return 0; | ||
113 | } else { | 123 | } else { | ||
114 | QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; | 124 | QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; | ||
115 | return 1; | 125 | return 1; | ||
116 | } | 126 | } | ||
117 | } else { | 127 | } else { | ||
118 | return 1; | 128 | return 1; | ||
119 | } | 129 | } | ||
120 | } | 130 | } |