sftp plugin

This commit is contained in:
Samoilenko Yuri 2014-01-07 00:55:50 +04:00
parent c3bef92b73
commit f4813b88bc
7 changed files with 331 additions and 0 deletions

View file

@ -0,0 +1,46 @@
find_package(KDE4 REQUIRED)
find_package(QJSON REQUIRED)
find_package(QCA2 REQUIRED)
include(KDE4Defaults)
include_directories(
${QJSON_INCLUDE_DIR}
${QCA2_INCLUDE_DIR}
${KDE4_INCLUDES}
${CMAKE_SOURCE_DIR}
)
set(kdeconnect_sftp_SRCS
sftpplugin.cpp
sftpdbusinterface.cpp
../kdeconnectplugin.cpp
../pluginloader.cpp
../../networkpackage.cpp
../../filetransferjob.cpp
../../device.cpp
../../kdebugnamespace.cpp
)
kde4_add_plugin(kdeconnect_sftp ${kdeconnect_sftp_SRCS})
target_link_libraries(kdeconnect_sftp
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
${QT_QTNETWORK_LIBRARY}
${QJSON_LIBRARIES}
${QCA2_LIBRARIES}
)
install(TARGETS kdeconnect_sftp DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES kdeconnect_sftp.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
include(../../../macros.cmake)
generate_and_install_dbus_interface(
kdeconnect_sftp
sftpdbusinterface.h
org.kde.kdeconnect.device.sftp.xml
OPTIONS -a
)

21
kded/plugins/sftp/README Normal file
View file

@ -0,0 +1,21 @@
This plugins receives packages with type "kdeconnect.sftp" and reads the
following fields:
ip (string): ip of the curretly active network on device
port (string): port where sftp server starts
user (string): username to connect to sftp server
password (string): one session password to access sftp server
path (string): root directory to access device filesystem
This plugins sends packages with type "kdeconnect.sftp" and fills the
following fields:
startBrowsing (boolean): tell device to start sftp server and noify desktop
<TODO>
random password generation
using encrypted packages
</TODO>

View file

@ -0,0 +1,47 @@
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KdeConnect/Plugin
X-KDE-Library=kdeconnect_sftp
X-KDE-PluginInfo-Author=Samoilenko Yuri
X-KDE-PluginInfo-Email=kinnalru@gmail.com
X-KDE-PluginInfo-Name=kdeconnect_sftp
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://albertvaka.wordpress.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
Icon=system-file-manager
Name=SFTP browser
Name[cs]=SFTP browser
Name[da]=SFTP browser
Name[de]=SFTP browser
Name[es]=SFTP browser
Name[fr]=SFTP browser
Name[hu]=SFTP browser
Name[it]=SFTP browser
Name[nl]=SFTP browser
Name[pt]=SFTP browser
Name[pt_BR]=SFTP browser
Name[ru]=SFTP обозреватель
Name[sk]=SFTP browser
Name[sv]=SFTP browser
Name[tr]=SFTP browser
Name[uk]=SFTP обозреватель
Name[x-test]=xxSFTP browserxx
Comment=Browse device files in filemanager through SFTP
Comment[da]=Browse device files in filemanager through SFTP
Comment[de]=Browse device files in filemanager through SFTP
Comment[es]=Browse device files in filemanager through SFTP
Comment[fr]=Browse device files in filemanager through SFTP
Comment[hu]=Browse device files in filemanager through SFTP
Comment[it]=Browse device files in filemanager through SFTP
Comment[nl]=Browse device files in filemanager through SFTP
Comment[pt]=Browse device files in filemanager through SFTP
Comment[pt_BR]=Browse device files in filemanager through SFTP
Comment[ru]=Доступ к файлам на устройстве через SFTP
Comment[sv]=Browse device files in filemanager through SFTP
Comment[tr]=Browse device files in filemanager through SFTP
Comment[uk]=Доступ к файлам на устройстве через SFTP
Comment[x-test]=xxBrowse device files in filemanager through SFTPxx
X-KdeConnect-SupportedPackageType=kdeconnect.sftp

View file

@ -0,0 +1,40 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "sftpdbusinterface.h"
#include "../../kdebugnamespace.h"
SftpDbusInterface::SftpDbusInterface(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
}
SftpDbusInterface::~SftpDbusInterface()
{
kDebug(kdeconnect_kded()) << "Destroying SftpDbusInterface";
}
void SftpDbusInterface::browseFilesystem()
{
emit startBrowsing();
}

View file

@ -0,0 +1,45 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef SFTPDBUSINTERFACE_H
#define SFTPDBUSINTERFACE_H
#include <QDBusAbstractAdaptor>
class SftpDbusInterface
: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
public:
explicit SftpDbusInterface(QObject *parent);
virtual ~SftpDbusInterface();
Q_SCRIPTABLE void browseFilesystem();
Q_SIGNALS:
void startBrowsing();
private:
};
#endif

View file

@ -0,0 +1,82 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "sftpplugin.h"
#include <KNotification>
#include <KIcon>
#include <KLocalizedString>
#include <KRun>
#include <QMessageBox>
#include "../../kdebugnamespace.h"
#include "sftpdbusinterface.h"
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< SftpPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_sftp", "kdeconnect_sftp") )
SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
, sftpDbusInterface(new SftpDbusInterface(parent))
{
connect(sftpDbusInterface, SIGNAL(startBrowsing()), this, SLOT(startBrowsing()));
}
void SftpPlugin::connected()
{
}
SftpPlugin::~SftpPlugin()
{
//FIXME: Qt dbus does not allow to remove an adaptor! (it causes a crash in
// the next dbus access to its parent). The implication of not deleting this
// is that disabling the plugin does not remove the interface (that will
// return outdated values) and that enabling it again instantiates a second
// adaptor. This is also a memory leak until the entire device is destroyed.
//sftpDbusInterface->deleteLater();
}
void SftpPlugin::startBrowsing()
{
NetworkPackage np(PACKAGE_TYPE_SFTP);
np.set("startBrowsing", true);
device()->sendPackage(np);
}
bool SftpPlugin::receivePackage(const NetworkPackage& np)
{
KUrl url;
url.setProtocol("sftp");
url.setHost(np.get<QString>("ip"));
url.setPort(np.get<QString>("port").toInt());
url.setUser(np.get<QString>("user"));
url.setPass(np.get<QString>("password"));
url.setPath(np.get<QString>("home"));
if (url.isValid()) {
return KRun::runUrl(url, "inode/vnd.kde.service.sftp-ssh", 0);
}
return false;
}

View file

@ -0,0 +1,50 @@
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef SFTPPLUGIN_H
#define SFTPPLUGIN_H
#include "../kdeconnectplugin.h"
#define PACKAGE_TYPE_SFTP QLatin1String("kdeconnect.sftp")
class SftpDbusInterface;
class SftpPlugin
: public KdeConnectPlugin
{
Q_OBJECT
public:
explicit SftpPlugin(QObject *parent, const QVariantList &args);
virtual ~SftpPlugin();
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
virtual void connected();
private Q_SLOTS:
void startBrowsing();
private:
SftpDbusInterface* sftpDbusInterface;
};
#endif