2016-11-23 16:49:41 +00:00
|
|
|
/*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2021-05-23 06:50:54 +01:00
|
|
|
* SPDX-FileCopyrightText: 2020 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
2016-11-23 16:49:41 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2016-11-23 16:49:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "deviceindicator.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <QDateTime>
|
2017-01-11 17:04:01 +00:00
|
|
|
#include <QFileDialog>
|
2021-06-12 12:33:40 +01:00
|
|
|
#include <QStandardPaths>
|
2016-11-23 16:49:41 +00:00
|
|
|
|
2019-03-11 17:50:14 +00:00
|
|
|
#include "interfaces/dbusinterfaces.h"
|
|
|
|
|
2019-06-09 16:28:49 +01:00
|
|
|
#include <dbushelper.h>
|
2021-06-12 12:33:40 +01:00
|
|
|
#include <dbushelpers.h>
|
2021-05-23 06:50:54 +01:00
|
|
|
#include <systray_actions.h>
|
2016-11-23 16:49:41 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device)
|
2016-11-23 16:49:41 +00:00
|
|
|
: QMenu(device->name(), nullptr)
|
|
|
|
, m_device(device)
|
2019-07-20 09:23:33 +01:00
|
|
|
, m_remoteCommandsInterface(new RemoteCommandsDbusInterface(m_device->id()))
|
2016-11-23 16:49:41 +00:00
|
|
|
{
|
|
|
|
setIcon(QIcon::fromTheme(device->iconName()));
|
|
|
|
|
2016-11-23 17:43:17 +00:00
|
|
|
connect(device, SIGNAL(nameChanged(QString)), this, SLOT(setText(QString)));
|
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// Battery status
|
2017-02-20 23:08:03 +00:00
|
|
|
auto battery = new BatteryAction(device);
|
|
|
|
addAction(battery);
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_battery")),
|
|
|
|
[battery](bool available) {
|
|
|
|
battery->setVisible(available);
|
|
|
|
battery->setDisabled(available);
|
|
|
|
},
|
|
|
|
this);
|
2016-11-23 17:43:17 +00:00
|
|
|
|
2021-05-18 09:34:43 +01:00
|
|
|
auto connectivity = new ConnectivityAction(device);
|
|
|
|
addAction(connectivity);
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_connectivity_report")),
|
|
|
|
[connectivity](bool available) {
|
|
|
|
connectivity->setVisible(available);
|
|
|
|
connectivity->setDisabled(available);
|
|
|
|
},
|
|
|
|
this);
|
2021-05-18 09:34:43 +01:00
|
|
|
|
2021-06-12 01:51:43 +01:00
|
|
|
this->addSeparator();
|
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// Browse device filesystem
|
2018-12-07 14:53:07 +00:00
|
|
|
auto browse = addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Browse device"));
|
2022-09-10 22:23:52 +01:00
|
|
|
connect(browse, &QAction::triggered, device, [device]() {
|
|
|
|
SftpDbusInterface *sftpIface = new SftpDbusInterface(device->id(), device);
|
2016-11-23 17:43:17 +00:00
|
|
|
sftpIface->startBrowsing();
|
|
|
|
sftpIface->deleteLater();
|
|
|
|
});
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_sftp")),
|
|
|
|
[browse](bool available) {
|
|
|
|
browse->setVisible(available);
|
|
|
|
},
|
|
|
|
this);
|
2017-01-11 16:54:52 +00:00
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// Find device
|
2018-12-07 14:53:07 +00:00
|
|
|
auto findDevice = addAction(QIcon::fromTheme(QStringLiteral("irc-voice")), i18n("Ring device"));
|
2022-09-10 22:23:52 +01:00
|
|
|
connect(findDevice, &QAction::triggered, device, [device]() {
|
|
|
|
FindMyPhoneDeviceDbusInterface *iface = new FindMyPhoneDeviceDbusInterface(device->id(), device);
|
2016-11-23 17:43:17 +00:00
|
|
|
iface->ring();
|
|
|
|
iface->deleteLater();
|
|
|
|
});
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_findmyphone")),
|
|
|
|
[findDevice](bool available) {
|
|
|
|
findDevice->setVisible(available);
|
|
|
|
},
|
|
|
|
this);
|
2016-11-23 17:43:17 +00:00
|
|
|
|
2021-06-12 12:33:40 +01:00
|
|
|
// Get a photo
|
|
|
|
auto getPhoto = addAction(QIcon::fromTheme(QStringLiteral("camera-photo")), i18n("Get a photo"));
|
2022-09-10 22:23:52 +01:00
|
|
|
connect(getPhoto, &QAction::triggered, this, [device]() {
|
|
|
|
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"),
|
|
|
|
QStringLiteral("/modules/kdeconnect/devices/") + device->id() + QStringLiteral("/photo"),
|
|
|
|
QStringLiteral("org.kde.kdeconnect.device.photo"),
|
|
|
|
QStringLiteral("requestPhoto"));
|
|
|
|
msg.setArguments({QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()
|
|
|
|
+ QDateTime::currentDateTime().toString(QStringLiteral("/dd-MM-yy_hh-mm-ss.png"))});
|
2022-04-12 06:40:03 +01:00
|
|
|
blockOnReply(QDBusConnection::sessionBus().asyncCall(msg));
|
2021-06-12 12:33:40 +01:00
|
|
|
});
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_photo")),
|
|
|
|
[getPhoto](bool available) {
|
|
|
|
getPhoto->setVisible(available);
|
|
|
|
},
|
|
|
|
this);
|
2021-06-12 12:33:40 +01:00
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// Send file
|
2022-09-10 22:23:52 +01:00
|
|
|
const QString kdeconnectHandlerExecutable = QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), {QCoreApplication::applicationDirPath()});
|
2021-06-12 01:40:06 +01:00
|
|
|
if (!kdeconnectHandlerExecutable.isEmpty()) {
|
|
|
|
auto handlerApp = addAction(QIcon::fromTheme(QStringLiteral("document-share")), i18n("Send a file/URL"));
|
2022-09-10 22:23:52 +01:00
|
|
|
QObject::connect(handlerApp, &QAction::triggered, device, [device, kdeconnectHandlerExecutable]() {
|
|
|
|
QProcess::startDetached(kdeconnectHandlerExecutable, {QStringLiteral("--device"), device->id()});
|
2021-06-12 01:40:06 +01:00
|
|
|
});
|
|
|
|
handlerApp->setVisible(true);
|
|
|
|
}
|
2019-07-20 09:23:33 +01:00
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// SMS Messages
|
2022-09-10 22:23:52 +01:00
|
|
|
const QString kdeconnectsmsExecutable = QStandardPaths::findExecutable(QStringLiteral("kdeconnect-sms"), {QCoreApplication::applicationDirPath()});
|
2019-08-19 06:39:05 +01:00
|
|
|
if (!kdeconnectsmsExecutable.isEmpty()) {
|
2019-07-20 15:02:38 +01:00
|
|
|
auto smsapp = addAction(QIcon::fromTheme(QStringLiteral("message-new")), i18n("SMS Messages..."));
|
2022-09-10 22:23:52 +01:00
|
|
|
QObject::connect(smsapp, &QAction::triggered, device, [device, kdeconnectsmsExecutable]() {
|
|
|
|
QProcess::startDetached(kdeconnectsmsExecutable, {QStringLiteral("--device"), device->id()});
|
2019-07-20 15:02:38 +01:00
|
|
|
});
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_sms")),
|
|
|
|
[smsapp](bool available) {
|
|
|
|
smsapp->setVisible(available);
|
|
|
|
},
|
|
|
|
this);
|
2019-07-20 15:02:38 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 03:18:52 +00:00
|
|
|
// Run command
|
2022-09-10 22:23:52 +01:00
|
|
|
QMenu *remoteCommandsMenu = new QMenu(i18n("Run command"), this);
|
|
|
|
QAction *menuAction = remoteCommandsMenu->menuAction();
|
|
|
|
QAction *addCommandAction = remoteCommandsMenu->addAction(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add commands"));
|
2019-07-20 09:23:33 +01:00
|
|
|
connect(addCommandAction, &QAction::triggered, m_remoteCommandsInterface, &RemoteCommandsDbusInterface::editCommands);
|
|
|
|
|
|
|
|
addAction(menuAction);
|
2022-09-10 22:23:52 +01:00
|
|
|
setWhenAvailable(
|
|
|
|
device->hasPlugin(QStringLiteral("kdeconnect_remotecommands")),
|
|
|
|
[this, remoteCommandsMenu, menuAction](bool available) {
|
|
|
|
menuAction->setVisible(available);
|
|
|
|
|
|
|
|
if (!available)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto cmds = QJsonDocument::fromJson(m_remoteCommandsInterface->commands()).object();
|
|
|
|
|
|
|
|
for (auto it = cmds.constBegin(), itEnd = cmds.constEnd(); it != itEnd; ++it) {
|
|
|
|
const QJsonObject cont = it->toObject();
|
|
|
|
QString key = it.key();
|
|
|
|
QAction *action = remoteCommandsMenu->addAction(cont.value(QStringLiteral("name")).toString());
|
|
|
|
connect(action, &QAction::triggered, [this, key] {
|
|
|
|
m_remoteCommandsInterface->triggerCommand(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
this);
|
2016-11-23 16:49:41 +00:00
|
|
|
}
|