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 | 91 | | |||
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 | QString displayUrl; | 96 | QString displayUrl; | ||
94 | 97 | | |||
95 | if (urlToShare.scheme() == QLatin1String("tel")) { | 98 | if (urlToShare.scheme() == QLatin1String("tel")) { | ||
96 | displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme); | 99 | displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme); | ||
97 | uidialog.label->setText(i18n("Device to call %1 with:", displayUrl)); | 100 | uidialog.label->setText(i18n("Device to call %1 with:", displayUrl)); | ||
98 | } else if (urlToShare.isLocalFile()) { | 101 | } else if (urlToShare.isLocalFile() && open) { | ||
99 | displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); | 102 | displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); | ||
100 | uidialog.label->setText(i18n("Device to send %1 to:", displayUrl)); | 103 | uidialog.label->setText(i18n("Device to send %1 to:", displayUrl)); | ||
101 | } else { | 104 | } else { | ||
102 | displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); | 105 | displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); | ||
103 | uidialog.label->setText(i18n("Device to open %1 on:", displayUrl)); | 106 | uidialog.label->setText(i18n("Device to open %1 on:", displayUrl)); | ||
104 | } | 107 | } | ||
105 | 108 | | |||
106 | dialog.setWindowTitle(displayUrl); | 109 | dialog.setWindowTitle(displayUrl); | ||
107 | 110 | | |||
108 | if (dialog.exec() == QDialog::Accepted) { | 111 | if (dialog.exec() == QDialog::Accepted) { | ||
109 | QUrl url = urlToShare; | 112 | QUrl url = urlToShare; | ||
110 | const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); | 113 | const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); | ||
111 | if(!url.isEmpty() && currentDeviceIndex >= 0) { | 114 | if(!url.isEmpty() && currentDeviceIndex >= 0) { | ||
112 | const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); | 115 | const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); | ||
116 | const QString action = open && url.isLocalFile() ? QStringLiteral("openFile") : QStringLiteral("shareUrl"); | ||||
113 | 117 | | |||
114 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); | 118 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), action); | ||
115 | msg.setArguments({ url.toString() }); | 119 | msg.setArguments({ url.toString() }); | ||
116 | blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); | 120 | blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); | ||
117 | return 0; | 121 | return 0; | ||
118 | } else { | 122 | } else { | ||
119 | QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; | 123 | QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; | ||
120 | return 1; | 124 | return 1; | ||
121 | } | 125 | } | ||
122 | } else { | 126 | } else { | ||
123 | return 1; | 127 | return 1; | ||
124 | } | 128 | } | ||
125 | } | 129 | } |