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.
This commit is contained in:
Piyush Aggarwal 2020-11-23 19:25:06 +05:30
parent 61de9ba315
commit 2bf82b1029
3 changed files with 132 additions and 32 deletions

View file

@ -9,6 +9,7 @@ target_link_libraries(kdeconnect-handler
Qt5::Widgets Qt5::Widgets
KF5::CoreAddons KF5::CoreAddons
KF5::I18n KF5::I18n
KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM
) )
install(TARGETS kdeconnect-handler ${INSTALL_TARGETS_DEFAULT_ARGS}) install(TARGETS kdeconnect-handler ${INSTALL_TARGETS_DEFAULT_ARGS})

View file

@ -7,16 +7,31 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>420</width> <width>420</width>
<height>104</height> <height>138</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Device to open the url with:</string> <string>Select device:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -25,9 +40,52 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<widget class="QComboBox" name="devicePicker"/> <widget class="QComboBox" name="devicePicker"/>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="sendUrlRadioButton">
<property name="text">
<string>Send URL</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="sendFileRadioButton">
<property name="text">
<string>Send File</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="urlHorizontalLayout"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="openOnPeerCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open on peer device</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
@ -39,6 +97,8 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>

View file

@ -11,9 +11,13 @@
#include <QTextStream> #include <QTextStream>
#include <QUrl> #include <QUrl>
#include <QDBusMessage> #include <QDBusMessage>
#include <QFileDialog>
#include <QMessageBox>
#include <QAbstractButton>
#include <KAboutData> #include <KAboutData>
#include <KLocalizedString> #include <KLocalizedString>
#include <KUrlRequester>
#include <dbushelper.h> #include <dbushelper.h>
@ -51,12 +55,9 @@ int main(int argc, char** argv)
about.setupCommandLine(&parser); about.setupCommandLine(&parser);
parser.process(app); parser.process(app);
about.processCommandLine(&parser); about.processCommandLine(&parser);
if (parser.positionalArguments().count() != 1) { if (parser.positionalArguments().count() == 1) {
parser.showHelp(1);
return 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")); open = parser.isSet(QStringLiteral("open"));
} }
@ -71,9 +72,34 @@ int main(int argc, char** argv)
Ui::Dialog uidialog; Ui::Dialog uidialog;
uidialog.setupUi(&dialog); uidialog.setupUi(&dialog);
uidialog.devicePicker->setModel(&proxyModel); uidialog.devicePicker->setModel(&proxyModel);
uidialog.openOnPeerCheckBox->setChecked(open);
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; QString displayUrl;
if (urlToShare.scheme() == QLatin1String("tel")) { if (urlToShare.scheme() == QLatin1String("tel")) {
displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme); displayUrl = urlToShare.toDisplayString(QUrl::RemoveScheme);
uidialog.label->setText(i18n("Device to call %1 with:", displayUrl)); uidialog.label->setText(i18n("Device to call %1 with:", displayUrl));
@ -88,10 +114,21 @@ int main(int argc, char** argv)
uidialog.label->setText(i18n("Device to send %1 to:", displayUrl)); 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) { if (dialog.exec() == QDialog::Accepted) {
QUrl url = urlToShare; const QUrl url = urlRequester->url();
open = uidialog.openOnPeerCheckBox->isChecked();
const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); const int currentDeviceIndex = uidialog.devicePicker->currentIndex();
if(!url.isEmpty() && currentDeviceIndex >= 0) { if(!url.isEmpty() && currentDeviceIndex >= 0) {
const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); 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)); blockOnReply(DBusHelper::sessionBus().asyncCall(msg));
return 0; return 0;
} else { } else {
QTextStream(stderr) << (i18n("Couldn't share %1", url.toString())) << endl; QMessageBox::critical(nullptr, description,
i18n("Couldn't share %1", url.toString())
);
return 1; return 1;
} }
} else { } else {