From 2bf82b1029ef2edcf99905a10dea193d698071f9 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Mon, 23 Nov 2020 19:25:06 +0530 Subject: [PATCH] revamp kdeconnect-handler to support full control by GUI Current implementation of kdeconnect-handler did not support controlling the function of kdeconnect-handler completely through GUI. This patch enables that by adding knobs to the GUI and doing necessary changes to the cpp. --- urlhandler/CMakeLists.txt | 1 + urlhandler/dialog.ui | 82 ++++++++++++++++++++++++++----- urlhandler/kdeconnect-handler.cpp | 81 ++++++++++++++++++++++-------- 3 files changed, 132 insertions(+), 32 deletions(-) diff --git a/urlhandler/CMakeLists.txt b/urlhandler/CMakeLists.txt index 0ef5cfe53..29e3247c8 100644 --- a/urlhandler/CMakeLists.txt +++ b/urlhandler/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries(kdeconnect-handler Qt5::Widgets KF5::CoreAddons KF5::I18n + KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM ) install(TARGETS kdeconnect-handler ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/urlhandler/dialog.ui b/urlhandler/dialog.ui index 2779e0320..5b46a6d1a 100644 --- a/urlhandler/dialog.ui +++ b/urlhandler/dialog.ui @@ -7,16 +7,31 @@ 0 0 420 - 104 + 138 + + + 0 + 0 + + + + + 0 + 0 + + - Device to open the url with: + Select device: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop true @@ -26,17 +41,62 @@ - + + + + + - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + Send URL + + + + + + + Send File + + + + + + + + + + + + + + + 0 + 0 + + + + Open on peer device + + + false + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/urlhandler/kdeconnect-handler.cpp b/urlhandler/kdeconnect-handler.cpp index dc234e493..e0847cae8 100644 --- a/urlhandler/kdeconnect-handler.cpp +++ b/urlhandler/kdeconnect-handler.cpp @@ -11,9 +11,13 @@ #include #include #include +#include +#include +#include #include #include +#include #include @@ -51,12 +55,9 @@ int main(int argc, char** argv) about.setupCommandLine(&parser); parser.process(app); about.processCommandLine(&parser); - if (parser.positionalArguments().count() != 1) { - parser.showHelp(1); - return 1; + if (parser.positionalArguments().count() == 1) { + urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile); } - - urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile); open = parser.isSet(QStringLiteral("open")); } @@ -71,27 +72,63 @@ int main(int argc, char** argv) Ui::Dialog uidialog; uidialog.setupUi(&dialog); uidialog.devicePicker->setModel(&proxyModel); + uidialog.openOnPeerCheckBox->setChecked(open); - QString displayUrl; + KUrlRequester* urlRequester = new KUrlRequester(&dialog); + urlRequester->setStartDir(QUrl::fromLocalFile(QDir::homePath())); + uidialog.urlHorizontalLayout->addWidget(urlRequester); + + QObject::connect(uidialog.sendUrlRadioButton, &QRadioButton::toggled, [&uidialog, urlRequester](const bool checked) { + if (checked) { + urlRequester->setPlaceholderText(i18n("Enter URL here")); + urlRequester->button()->setVisible(false); + uidialog.openOnPeerCheckBox->setVisible(false); + } + }); + + QObject::connect(uidialog.sendFileRadioButton, &QAbstractButton::toggled, [&uidialog, urlRequester](const bool checked) { + if (checked) { + urlRequester->setPlaceholderText(i18n("Enter file location here")); + urlRequester->button()->setVisible(true); + uidialog.openOnPeerCheckBox->setVisible(true); + } + }); + + if (!urlToShare.isEmpty()) { + uidialog.sendUrlRadioButton->setVisible(false); + uidialog.sendFileRadioButton->setVisible(false); + urlRequester->setVisible(false); + + QString displayUrl; + if (urlToShare.scheme() == QLatin1String("tel")) { + displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme); + uidialog.label->setText(i18n("Device to call %1 with:", displayUrl)); + } else if (urlToShare.isLocalFile() && open) { + displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); + uidialog.label->setText(i18n("Device to open %1 on:", displayUrl)); + } else if (urlToShare.scheme() == QLatin1String("sms")) { + displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); + uidialog.label->setText(i18n("Device to send a SMS with:")); + } else { + displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); + uidialog.label->setText(i18n("Device to send %1 to:", displayUrl)); + } - if (urlToShare.scheme() == QLatin1String("tel")) { - displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme); - uidialog.label->setText(i18n("Device to call %1 with:", displayUrl)); - } else if (urlToShare.isLocalFile() && open) { - displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); - uidialog.label->setText(i18n("Device to open %1 on:", displayUrl)); - } else if (urlToShare.scheme() == QLatin1String("sms")) { - displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); - uidialog.label->setText(i18n("Device to send a SMS with:")); - } else { - displayUrl = urlToShare.toDisplayString(QUrl::PreferLocalFile); - uidialog.label->setText(i18n("Device to send %1 to:", displayUrl)); } - dialog.setWindowTitle(displayUrl); + if (open || urlToShare.isLocalFile()) { + uidialog.sendFileRadioButton->setChecked(true); + urlRequester->setUrl(QUrl(urlToShare.toLocalFile())); + + } else { + uidialog.sendUrlRadioButton->setChecked(true); + urlRequester->setUrl(urlToShare); + } + if (dialog.exec() == QDialog::Accepted) { - QUrl url = urlToShare; + const QUrl url = urlRequester->url(); + open = uidialog.openOnPeerCheckBox->isChecked(); const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); if(!url.isEmpty() && currentDeviceIndex >= 0) { const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); @@ -102,7 +139,9 @@ int main(int argc, char** argv) blockOnReply(DBusHelper::sessionBus().asyncCall(msg)); return 0; } else { - QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; + QMessageBox::critical(nullptr, description, + i18n("Couldn't share %1", url.toString()) + ); return 1; } } else {