File indexing completed on 2024-04-21 04:56:54

0001 /**
0002  * SPDX-FileCopyrightText: 2014 Samoilenko Yuri <kinnalru@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <KFilePlacesModel>
0010 #include <core/device.h>
0011 #include <core/kdeconnectplugin.h>
0012 
0013 #define PACKET_TYPE_SFTP_REQUEST QStringLiteral("kdeconnect.sftp.request")
0014 class Mounter;
0015 
0016 class SftpPlugin : public KdeConnectPlugin
0017 {
0018     Q_OBJECT
0019     Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
0020 
0021 public:
0022     explicit SftpPlugin(QObject *parent, const QVariantList &args);
0023     ~SftpPlugin() override;
0024 
0025     void receivePacket(const NetworkPacket &np) override;
0026     QString dbusPath() const override
0027     {
0028         return QLatin1String("/modules/kdeconnect/devices/%1/sftp").arg(deviceId);
0029     }
0030 
0031     Q_SCRIPTABLE bool startBrowsing();
0032     Q_SCRIPTABLE void mount();
0033     Q_SCRIPTABLE void unmount();
0034     Q_SCRIPTABLE bool mountAndWait();
0035     Q_SCRIPTABLE bool isMounted() const;
0036     Q_SCRIPTABLE QString getMountError();
0037     Q_SCRIPTABLE QString mountPoint();
0038     Q_SCRIPTABLE QVariantMap getDirectories(); // Actually a QMap<String, String>, but QDBus prefers this
0039 
0040 Q_SIGNALS:
0041     Q_SCRIPTABLE void mounted();
0042     Q_SCRIPTABLE void unmounted();
0043 
0044 private Q_SLOTS:
0045     void onMounted();
0046     void onUnmounted();
0047     void onFailed(const QString &message);
0048 
0049 private:
0050     void knotify(int type, const QString &text, const QPixmap &icon) const;
0051     void addToDolphin();
0052     void removeFromDolphin();
0053     // Add KIO entry to Dolphin's Places
0054     KFilePlacesModel m_placesModel;
0055     Mounter *m_mounter;
0056     QString deviceId; // Storing it to avoid accessing device() from the destructor which could cause a crash
0057 
0058     QVariantMap remoteDirectories; // Actually a QMap<String, String>, but QDBus prefers this
0059     QString mountError;
0060 };