diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e4fed27..499f6452 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,79 +1,79 @@ cmake_minimum_required(VERSION 3.0) project(kdeconnect) set(KDECONNECT_VERSION_MAJOR 1) set(KDECONNECT_VERSION_MINOR 3) set(KDECONNECT_VERSION_PATCH 0) set(KDECONNECT_VERSION "${KDECONNECT_VERSION_MAJOR}.${KDECONNECT_VERSION_MINOR}.${KDECONNECT_VERSION_PATCH}") set(QT_MIN_VERSION "5.7.0") -set(KF5_MIN_VERSION "5.42.0") +set(KF5_MIN_VERSION "5.45.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Quick) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils OPTIONAL_COMPONENTS DocTools ) find_package(Qca-qt5 2.1.0 REQUIRED) include_directories(${CMAKE_SOURCE_DIR}) configure_file(kdeconnect-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/kdeconnect-version.h) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMAddTests) include(ECMSetupVersion) include(ECMInstallIcons) include(FeatureSummary) include(KDEConnectMacros.cmake) add_definitions(-DQT_NO_URL_CAST_FROM_STRING -DQT_NO_KEYWORDS) include(GenerateExportHeader) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(core) add_subdirectory(kcm) add_subdirectory(kcmplugin) if(NOT WIN32) add_subdirectory(kio) add_subdirectory(plasmoid) endif() add_subdirectory(icon) add_subdirectory(interfaces) option(EXPERIMENTALAPP_ENABLED OFF) if(EXPERIMENTALAPP_ENABLED) add_subdirectory(app) endif() add_subdirectory(daemon) add_subdirectory(plugins) add_subdirectory(cli) add_subdirectory(indicator) add_subdirectory(fileitemactionplugin) add_subdirectory(urlhandler) add_subdirectory(nautilus-extension) option(SMSAPP_ENABLED OFF) if(SMSAPP_ENABLED) find_package(KF5People REQUIRED) add_subdirectory(smsapp) endif() if(KF5DocTools_FOUND) add_subdirectory(doc) endif() if(BUILD_TESTING) add_subdirectory(tests) endif() install(FILES org.kde.kdeconnect.kcm.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index f208136f..00b98c4b 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -1,99 +1,99 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef DEVICESMODEL_H #define DEVICESMODEL_H #include #include #include #include "interfaces/kdeconnectinterfaces_export.h" class QDBusPendingCallWatcher; class DaemonDbusInterface; class DeviceDbusInterface; class KDECONNECTINTERFACES_EXPORT DevicesModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int displayFilter READ displayFilter WRITE setDisplayFilter) Q_PROPERTY(int count READ rowCount NOTIFY rowsChanged) public: enum ModelRoles { NameModelRole = Qt::DisplayRole, IconModelRole = Qt::DecorationRole, StatusModelRole = Qt::InitialSortOrderRole, IdModelRole = Qt::UserRole, IconNameRole, DeviceRole }; Q_ENUM(ModelRoles); // A device is always paired or reachable or both // You can combine the Paired and Reachable flags enum StatusFilterFlag { NoFilter = 0x00, Paired = 0x01, // show device only if it's paired Reachable = 0x02 // show device only if it's reachable }; Q_DECLARE_FLAGS(StatusFilterFlags, StatusFilterFlag) Q_FLAGS(StatusFilterFlags) Q_ENUM(StatusFilterFlag) explicit DevicesModel(QObject* parent = nullptr); ~DevicesModel() override; void setDisplayFilter(int flags); int displayFilter() const; QVariant data(const QModelIndex& index, int role) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; QHash roleNames() const override; + int rowForDevice(const QString& id) const; private Q_SLOTS: void deviceAdded(const QString& id); void deviceRemoved(const QString& id); void deviceUpdated(const QString& id, bool isVisible); void refreshDeviceList(); void receivedDeviceList(QDBusPendingCallWatcher* watcher); void nameChanged(const QString& newName); Q_SIGNALS: void rowsChanged(); private: - int rowForDevice(const QString& id) const; void clearDevices(); void appendDevice(DeviceDbusInterface* dev); bool passesFilter(DeviceDbusInterface* dev) const; DaemonDbusInterface* m_dbusInterface; QVector m_deviceList; StatusFilterFlag m_displayFilter; }; //Q_DECLARE_OPERATORS_FOR_FLAGS(DevicesModel::StatusFilterFlag) #endif // DEVICESMODEL_H diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 421afacd..9e59719e 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -1,373 +1,392 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "kcm.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ui_kcm.h" #include "interfaces/dbusinterfaces.h" #include "interfaces/devicesmodel.h" #include "devicessortproxymodel.h" #include "kdeconnect-version.h" K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin();) static QString createId() { return QStringLiteral("kcm")+QString::number(QCoreApplication::applicationPid()); } -KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList&) +KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList& args) : KCModule(KAboutData::pluginData(QStringLiteral("kdeconnect-kcm")), parent) , kcmUi(new Ui::KdeConnectKcmUi()) , daemon(new DaemonDbusInterface(this)) , devicesModel(new DevicesModel(this)) , currentDevice(nullptr) { KAboutData* about = new KAboutData(QStringLiteral("kdeconnect-kcm"), i18n("KDE Connect Settings"), QStringLiteral(KDECONNECT_VERSION_STRING), i18n("KDE Connect Settings module"), KAboutLicense::KAboutLicense::GPL_V2, i18n("(C) 2015 Albert Vaca Cintora"), QString(), QStringLiteral("https://community.kde.org/KDEConnect") ); about->addAuthor(i18n("Albert Vaca Cintora")); setAboutData(about); kcmUi->setupUi(this); sortProxyModel = new DevicesSortProxyModel(devicesModel); kcmUi->deviceList->setModel(sortProxyModel); kcmUi->deviceInfo->setVisible(false); kcmUi->progressBar->setVisible(false); kcmUi->messages->setVisible(false); //Workaround: If we set this directly (or if we set it in the .ui file), the layout breaks kcmUi->noDeviceLinks->setWordWrap(false); QTimer::singleShot(0, [this] { kcmUi->noDeviceLinks->setWordWrap(true); }); setWhenAvailable(daemon->announcedName(), [this](const QString& announcedName) { kcmUi->rename_label->setText(announcedName); kcmUi->rename_edit->setText(announcedName); }, this); connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi->rename_edit, SLOT(setText(QString))); connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi->rename_label, SLOT(setText(QString))); setRenameMode(false); setButtons(KCModule::Help | KCModule::NoAdditionalButton); connect(devicesModel, &QAbstractItemModel::dataChanged, this, &KdeConnectKcm::resetSelection); connect(kcmUi->deviceList->selectionModel(), &QItemSelectionModel::currentChanged, this, &KdeConnectKcm::deviceSelected); connect(kcmUi->accept_button, &QAbstractButton::clicked, this, &KdeConnectKcm::acceptPairing); connect(kcmUi->reject_button, &QAbstractButton::clicked, this, &KdeConnectKcm::rejectPairing); connect(kcmUi->pair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::requestPair); connect(kcmUi->unpair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::unpair); connect(kcmUi->ping_button, &QAbstractButton::clicked, this, &KdeConnectKcm::sendPing); connect(kcmUi->refresh_button,&QAbstractButton::clicked, this, &KdeConnectKcm::refresh); connect(kcmUi->rename_edit,&QLineEdit::returnPressed, this, &KdeConnectKcm::renameDone); connect(kcmUi->renameDone_button,&QAbstractButton::clicked, this, &KdeConnectKcm::renameDone); connect(kcmUi->renameShow_button,&QAbstractButton::clicked, this, &KdeConnectKcm::renameShow); daemon->acquireDiscoveryMode(createId()); + + if (!args.isEmpty() && args.first().type() == QVariant::String) { + const QString input = args.first().toString(); + const auto colonIdx = input.indexOf(QLatin1Char(':')); + const QString deviceId = input.left(colonIdx); + const QString pluginCM = colonIdx < 0 ? QString() : input.mid(colonIdx+1); + + connect(devicesModel, &DevicesModel::rowsInserted, this, [this, deviceId, pluginCM]() { + auto row = devicesModel->rowForDevice(deviceId); + if (row >= 0) { + const QModelIndex idx = sortProxyModel->mapFromSource(devicesModel->index(row)); + kcmUi->deviceList->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); + } + if (!pluginCM.isEmpty()) { + kcmUi->pluginSelector->showConfiguration(pluginCM); + } + disconnect(devicesModel, &DevicesModel::rowsInserted, this, nullptr); + }); + } } void KdeConnectKcm::renameShow() { setRenameMode(true); } void KdeConnectKcm::renameDone() { QString newName = kcmUi->rename_edit->text(); if (newName.isEmpty()) { //Rollback changes kcmUi->rename_edit->setText(kcmUi->rename_label->text()); } else { kcmUi->rename_label->setText(newName); daemon->setAnnouncedName(newName); } setRenameMode(false); } void KdeConnectKcm::setRenameMode(bool b) { kcmUi->renameDone_button->setVisible(b); kcmUi->rename_edit->setVisible(b); kcmUi->renameShow_button->setVisible(!b); kcmUi->rename_label->setVisible(!b); } KdeConnectKcm::~KdeConnectKcm() { daemon->releaseDiscoveryMode(createId()); delete kcmUi; } void KdeConnectKcm::refresh() { daemon->acquireDiscoveryMode(createId()); daemon->forceOnNetworkChange(); } void KdeConnectKcm::resetSelection() { if (!currentDevice) { return; } kcmUi->deviceList->selectionModel()->setCurrentIndex(sortProxyModel->mapFromSource(currentIndex), QItemSelectionModel::ClearAndSelect); } void KdeConnectKcm::deviceSelected(const QModelIndex& current) { if (currentDevice) { disconnect(currentDevice, 0, this, 0); } //Store previous device config pluginsConfigChanged(); if (!current.isValid()) { currentDevice = nullptr; kcmUi->deviceInfo->setVisible(false); return; } currentIndex = sortProxyModel->mapToSource(current); currentDevice = devicesModel->getDevice(currentIndex.row()); kcmUi->noDevicePlaceholder->setVisible(false); bool valid = (currentDevice != nullptr && currentDevice->isValid()); kcmUi->deviceInfo->setVisible(valid); if (!valid) { return; } kcmUi->messages->setVisible(false); resetDeviceView(); connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice())); connect(currentDevice, SIGNAL(trustedChanged(bool)), this, SLOT(trustedChanged(bool))); connect(currentDevice, SIGNAL(pairingError(QString)), this, SLOT(pairingFailed(QString))); connect(currentDevice, &DeviceDbusInterface::hasPairingRequestsChangedProxy, this, &KdeConnectKcm::currentDevicePairingChanged); } void KdeConnectKcm::currentDevicePairingChanged(bool pairing) { if (pairing) { setCurrentDeviceTrusted(RequestedByPeer); } else { setWhenAvailable(currentDevice->isTrusted(), [this](bool trusted) { setCurrentDeviceTrusted(trusted ? Trusted : NotTrusted); }, this); } } void KdeConnectKcm::resetCurrentDevice() { const QStringList supportedPluginNames = currentDevice->supportedPlugins(); if (m_oldSupportedPluginNames != supportedPluginNames) { resetDeviceView(); } } void KdeConnectKcm::resetDeviceView() { //KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time delete kcmUi->pluginSelector; kcmUi->pluginSelector = new KPluginSelector(this); kcmUi->deviceInfo_layout->addWidget(kcmUi->pluginSelector); kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id())); kcmUi->name_label->setText(currentDevice->name()); setWhenAvailable(currentDevice->isTrusted(), [this](bool trusted) { if (trusted) setCurrentDeviceTrusted(Trusted); else setWhenAvailable(currentDevice->hasPairingRequests(), [this](bool haspr) { setCurrentDeviceTrusted(haspr ? RequestedByPeer : NotTrusted); }, this); }, this); const QList pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins(QStringLiteral("kdeconnect/"))); QList availablePluginInfo; m_oldSupportedPluginNames = currentDevice->supportedPlugins(); for (auto it = pluginInfo.cbegin(), itEnd = pluginInfo.cend(); it!=itEnd; ++it) { if (m_oldSupportedPluginNames.contains(it->pluginName())) { availablePluginInfo.append(*it); } } KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile()); kcmUi->pluginSelector->addPlugins(availablePluginInfo, KPluginSelector::ReadConfigFile, i18n("Available plugins"), QString(), deviceConfig); connect(kcmUi->pluginSelector, &KPluginSelector::changed, this, &KdeConnectKcm::pluginsConfigChanged); } void KdeConnectKcm::requestPair() { if (!currentDevice) { return; } kcmUi->messages->hide(); setCurrentDeviceTrusted(Requested); currentDevice->requestPair(); } void KdeConnectKcm::unpair() { if (!currentDevice) { return; } setCurrentDeviceTrusted(NotTrusted); currentDevice->unpair(); } void KdeConnectKcm::acceptPairing() { if (!currentDevice) { return; } currentDevice->acceptPairing(); } void KdeConnectKcm::rejectPairing() { if (!currentDevice) { return; } currentDevice->rejectPairing(); } void KdeConnectKcm::pairingFailed(const QString& error) { if (sender() != currentDevice) return; setCurrentDeviceTrusted(NotTrusted); kcmUi->messages->setText(i18n("Error trying to pair: %1",error)); kcmUi->messages->animatedShow(); } void KdeConnectKcm::trustedChanged(bool trusted) { DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender(); if (senderDevice == currentDevice) setCurrentDeviceTrusted(trusted ? Trusted : NotTrusted); } void KdeConnectKcm::setCurrentDeviceTrusted(KdeConnectKcm::TrustStatus trusted) { kcmUi->accept_button->setVisible(trusted == RequestedByPeer); kcmUi->reject_button->setVisible(trusted == RequestedByPeer); kcmUi->pair_button->setVisible(trusted == NotTrusted); kcmUi->unpair_button->setVisible(trusted == Trusted); kcmUi->progressBar->setVisible(trusted == Requested); kcmUi->ping_button->setVisible(trusted == Trusted); switch (trusted) { case Trusted: kcmUi->status_label->setText(i18n("(paired)")); break; case NotTrusted: kcmUi->status_label->setText(i18n("(not paired)")); break; case RequestedByPeer: kcmUi->status_label->setText(i18n("(incoming pair request)")); break; case Requested: kcmUi->status_label->setText(i18n("(pairing requested)")); break; } } void KdeConnectKcm::pluginsConfigChanged() { //Store previous selection if (!currentDevice) return; DeviceDbusInterface* auxCurrentDevice = currentDevice; currentDevice = nullptr; //HACK to avoid infinite recursion (for some reason calling save on pluginselector emits changed) kcmUi->pluginSelector->save(); currentDevice = auxCurrentDevice; currentDevice->reloadPlugins(); } void KdeConnectKcm::save() { pluginsConfigChanged(); KCModule::save(); } void KdeConnectKcm::sendPing() { if (!currentDevice) return; currentDevice->pluginCall(QStringLiteral("ping"), QStringLiteral("sendPing")); } QSize KdeConnectKcm::sizeHint() const { return QSize(890,550); //Golden ratio :D } QSize KdeConnectKcm::minimumSizeHint() const { return QSize(500,300); } #include "kcm.moc" #include "moc_kcm.cpp" diff --git a/plugins/runcommand/runcommandplugin.cpp b/plugins/runcommand/runcommandplugin.cpp index 3c19c0cf..482501e4 100644 --- a/plugins/runcommand/runcommandplugin.cpp +++ b/plugins/runcommand/runcommandplugin.cpp @@ -1,93 +1,96 @@ /** * Copyright 2013 Albert Vaca * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "runcommandplugin.h" #include #include #include #include #include #include #include #include #include #include #define PACKET_TYPE_RUNCOMMAND QStringLiteral("kdeconnect.runcommand") K_PLUGIN_FACTORY_WITH_JSON( KdeConnectPluginFactory, "kdeconnect_runcommand.json", registerPlugin< RunCommandPlugin >(); ) Q_LOGGING_CATEGORY(KDECONNECT_PLUGIN_RUNCOMMAND, "kdeconnect.plugin.runcommand") RunCommandPlugin::RunCommandPlugin(QObject* parent, const QVariantList& args) : KdeConnectPlugin(parent, args) { connect(config(), &KdeConnectPluginConfig::configChanged, this, &RunCommandPlugin::configChanged); } RunCommandPlugin::~RunCommandPlugin() { } bool RunCommandPlugin::receivePacket(const NetworkPacket& np) { if (np.get(QStringLiteral("requestCommandList"), false)) { sendConfig(); return true; } if (np.has(QStringLiteral("key"))) { QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->get(QStringLiteral("commands"), "{}")); QJsonObject commands = commandsDocument.object(); QString key = np.get(QStringLiteral("key")); QJsonValue value = commands[key]; if (value == QJsonValue::Undefined) { qCWarning(KDECONNECT_PLUGIN_RUNCOMMAND) << key << "is not a configured command"; } const QJsonObject commandJson = value.toObject(); qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << "/bin/sh" << "-c" << commandJson[QStringLiteral("command")].toString(); QProcess::startDetached(QStringLiteral("/bin/sh"), QStringList()<< QStringLiteral("-c") << commandJson[QStringLiteral("command")].toString()); return true; + } else if (np.has("setup")) { + QProcess::startDetached(QStringLiteral("kcmshell5"), {QStringLiteral("kdeconnect"), QStringLiteral("--args"), QString(device()->id() + QStringLiteral(":kdeconnect_runcommand")) }); } return false; } void RunCommandPlugin::connected() { sendConfig(); } void RunCommandPlugin::sendConfig() { QString commands = config()->get(QStringLiteral("commands"),QStringLiteral("{}")); NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}}); + np.set(QStringLiteral("canAddCommand"), true); sendPacket(np); } void RunCommandPlugin::configChanged() { sendConfig(); } #include "runcommandplugin.moc"