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:
parent
61de9ba315
commit
2bf82b1029
3 changed files with 132 additions and 32 deletions
|
@ -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})
|
||||||
|
|
|
@ -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>
|
||||||
|
@ -26,17 +41,62 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="devicePicker"/>
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="devicePicker"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="orientation">
|
<item>
|
||||||
<enum>Qt::Horizontal</enum>
|
<widget class="QRadioButton" name="sendUrlRadioButton">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="standardButtons">
|
<string>Send URL</string>
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
</property>
|
||||||
</property>
|
</widget>
|
||||||
</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>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -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);
|
urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
urlToShare = QUrl::fromUserInput(parser.positionalArguments().constFirst(), QDir::currentPath(), QUrl::AssumeLocalFile);
|
|
||||||
open = parser.isSet(QStringLiteral("open"));
|
open = parser.isSet(QStringLiteral("open"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,27 +72,63 @@ 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);
|
||||||
|
|
||||||
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) {
|
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 {
|
||||||
|
|
Loading…
Reference in a new issue