[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:27:15 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=9fc9e72
The following commit has been merged in the master branch:
commit 9fc9e72374c67bf8e7dd097e5881fdfeb97b15d3
Author: Samoilenko Yuri <kinnalru at gmail.com>
Date: Wed Jan 15 20:36:01 2014 +0400
Code cleaning and stabilization
- SftpDbusInterface merged to SftpPlugin object
- mountpoint cleaning technique to avoid fuse errors with dangling mountpoints
---
kcm/kcm.cpp | 2 +-
kded/plugins/kdeconnectplugin.cpp | 5 +
kded/plugins/kdeconnectplugin.h | 1 +
kded/plugins/sftp/CMakeLists.txt | 3 +-
kded/plugins/sftp/sftpdbusinterface.cpp | 40 --------
kded/plugins/sftp/sftpdbusinterface.h | 45 ---------
kded/plugins/sftp/sftpplugin.cpp | 157 +++++++++++++++++---------------
kded/plugins/sftp/sftpplugin.h | 20 ++--
libkdeconnect/dbusinterfaces.cpp | 2 +-
9 files changed, 108 insertions(+), 167 deletions(-)
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index 0130670..78c897b 100644
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -257,5 +257,5 @@ void KdeConnectKcm::sendPing()
void KdeConnectKcm::browseFilesystem()
{
if (!currentDevice) return;
- SftpDbusInterface(currentDevice->id(), this).browseFilesystem();
+ SftpDbusInterface(currentDevice->id(), this).startBrowsing();
}
diff --git a/kded/plugins/kdeconnectplugin.cpp b/kded/plugins/kdeconnectplugin.cpp
index 1f3691e..4971c49 100644
--- a/kded/plugins/kdeconnectplugin.cpp
+++ b/kded/plugins/kdeconnectplugin.cpp
@@ -32,3 +32,8 @@ Device* KdeConnectPlugin::device()
{
return mDevice;
}
+
+Device const* KdeConnectPlugin::device() const
+{
+ return mDevice;
+}
diff --git a/kded/plugins/kdeconnectplugin.h b/kded/plugins/kdeconnectplugin.h
index 051fdc4..e8ff017 100644
--- a/kded/plugins/kdeconnectplugin.h
+++ b/kded/plugins/kdeconnectplugin.h
@@ -39,6 +39,7 @@ class KDE_EXPORT KdeConnectPlugin
public:
KdeConnectPlugin(QObject* parent, const QVariantList& args);
Device* device();
+ Device const* device() const;
public Q_SLOTS:
/**
diff --git a/kded/plugins/sftp/CMakeLists.txt b/kded/plugins/sftp/CMakeLists.txt
index 2410eab..eaf942e 100644
--- a/kded/plugins/sftp/CMakeLists.txt
+++ b/kded/plugins/sftp/CMakeLists.txt
@@ -13,7 +13,6 @@ include_directories(
set(kdeconnect_sftp_SRCS
sftpplugin.cpp
- sftpdbusinterface.cpp
../kdeconnectplugin.cpp
../pluginloader.cpp
../../networkpackage.cpp
@@ -40,7 +39,7 @@ include(../../../macros.cmake)
generate_and_install_dbus_interface(
kdeconnect_sftp
- sftpdbusinterface.h
+ sftpplugin.h
org.kde.kdeconnect.device.sftp.xml
OPTIONS -a
)
diff --git a/kded/plugins/sftp/sftpdbusinterface.cpp b/kded/plugins/sftp/sftpdbusinterface.cpp
deleted file mode 100644
index e30a999..0000000
--- a/kded/plugins/sftp/sftpdbusinterface.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright 2013 Albert Vaca <albertvaka at 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();
-}
-
-
diff --git a/kded/plugins/sftp/sftpdbusinterface.h b/kded/plugins/sftp/sftpdbusinterface.h
deleted file mode 100644
index 80dc127..0000000
--- a/kded/plugins/sftp/sftpdbusinterface.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright 2013 Albert Vaca <albertvaka at 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
diff --git a/kded/plugins/sftp/sftpplugin.cpp b/kded/plugins/sftp/sftpplugin.cpp
index bdedd24..2400977 100644
--- a/kded/plugins/sftp/sftpplugin.cpp
+++ b/kded/plugins/sftp/sftpplugin.cpp
@@ -20,6 +20,8 @@
#include "sftpplugin.h"
+#include <QDBusConnection>
+
#include <KIconLoader>
#include <KLocalizedString>
#include <KNotification>
@@ -28,25 +30,31 @@
#include <KStandardDirs>
#include "../../kdebugnamespace.h"
-#include "sftpdbusinterface.h"
K_PLUGIN_FACTORY( KdeConnectPluginFactory, registerPlugin< SftpPlugin >(); )
K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_sftp", "kdeconnect_sftp") )
-static const char* mount_c = "sftpmount";
static const char* passwd_c = "sftppassword";
static const QSet<QString> fields_c = QSet<QString>() <<
"ip" << "port" << "user" << "port" << "password" << "path";
-SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
- : KdeConnectPlugin(parent, args)
- , sftpDbusInterface(new SftpDbusInterface(parent))
- , mountProc(0)
+struct SftpPlugin::Pimpl
{
+ Pimpl() {};
+
+ QString mountPoint;
+ QPointer<KProcess> mountProc;
+};
- connect(sftpDbusInterface, SIGNAL(startBrowsing()), this, SLOT(startBrowsing()));
+SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
+ : KdeConnectPlugin(parent, args)
+ , m_d(new Pimpl)
+{
+ m_d->mountPoint = KStandardDirs::locateLocal("appdata", device()->name() + "/", true,
+ KComponentData("kdeconnect", "kdeconnect"));
+ QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents);
}
void SftpPlugin::connected()
@@ -55,13 +63,7 @@ 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();
+ QDBusConnection::sessionBus().unregisterObject(dbusPath(), QDBusConnection::UnregisterTree);
stopBrowsing();
}
@@ -74,82 +76,81 @@ void SftpPlugin::startBrowsing()
void SftpPlugin::stopBrowsing()
{
- if (mountProc)
+ cleanMountPoint();
+ if (m_d->mountProc)
{
- mountProc->terminate();
- QTimer::singleShot(15000, mountProc, SLOT(kill()));
- mountProc->waitForFinished();
+ m_d->mountProc->terminate();
+ QTimer::singleShot(5000, m_d->mountProc, SLOT(kill()));
+ m_d->mountProc->waitForFinished();
}
}
bool SftpPlugin::receivePackage(const NetworkPackage& np)
{
- if (!mountProc.isNull()) {
+ if (!(fields_c - np.body().keys().toSet()).isEmpty())
+ {
+ // package is invalid
return false;
}
- if (!(fields_c - np.body().keys().toSet()).isEmpty()) {
- // package is invalid
- return false;
+ if (!m_d->mountProc.isNull())
+ {
+ return new KRun(KUrl::fromLocalFile(m_d->mountPoint), 0);
}
- mountProc = new KProcess(this);
- mountProc->setOutputChannelMode(KProcess::SeparateChannels);
+ m_d->mountProc = new KProcess(this);
+ m_d->mountProc->setOutputChannelMode(KProcess::SeparateChannels);
- connect(mountProc, SIGNAL(started()), SLOT(onStarted()));
- connect(mountProc, SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError)));
- connect(mountProc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus)));
- connect(mountProc, SIGNAL(finished(int,QProcess::ExitStatus)), mountProc, SLOT(deleteLater()));
-
+ connect(m_d->mountProc, SIGNAL(started()), SLOT(onStarted()));
+ connect(m_d->mountProc, SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError)));
+ connect(m_d->mountProc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus)));
+ connect(m_d->mountProc, SIGNAL(finished(int,QProcess::ExitStatus)), m_d->mountProc, SLOT(deleteLater()));
- const QString mount = KStandardDirs::locateLocal("appdata", device()->name() + "/", true,
- KComponentData("kdeconnect", "kdeconnect"));
const QString program = "sshfs";
const QStringList arguments = QStringList()
- << QString("%1@%2:%3")
- .arg(np.get<QString>("user"))
- .arg(np.get<QString>("ip"))
- .arg(np.get<QString>("path"))
- << "-p" << np.get<QString>("port")
- << "-d"
- << "-f"
- << "-o" << "password_stdin"
- << mount;
+ << QString("%1@%2:%3")
+ .arg(np.get<QString>("user"))
+ .arg(np.get<QString>("ip"))
+ .arg(np.get<QString>("path"))
+ << "-p" << np.get<QString>("port")
+ << "-d"
+ << "-f"
+ << "-o" << "password_stdin"
+ << m_d->mountPoint;
- mountProc->setProgram(program, arguments);
- mountProc->setProperty(passwd_c, np.get<QString>("password"));
- mountProc->setProperty(mount_c, mount);
+ m_d->mountProc->setProgram(program, arguments);
+ m_d->mountProc->setProperty(passwd_c, np.get<QString>("password"));
- mountProc->start();
+ cleanMountPoint();
+ m_d->mountProc->start();
return true;
}
void SftpPlugin::onStarted()
{
- mountProc->write(mountProc->property(passwd_c).toString().toLocal8Bit() + "
");
- mountProc->closeWriteChannel();
+ m_d->mountProc->write(m_d->mountProc->property(passwd_c).toString().toLocal8Bit() + "
");
+ m_d->mountProc->closeWriteChannel();
- KNotification::event(KNotification::Notification
- , i18n("Device %1").arg(device()->name())
- , i18n("Filesystem mounted at %1").arg(mountProc->property(mount_c).toString())
- , KIconLoader::global()->loadIcon("drive-removable-media", KIconLoader::Desktop)
- , 0, KNotification::CloseOnTimeout
- )->sendEvent();
+ knotify(KNotification::Notification
+ , i18n("Device %1").arg(device()->name())
+ , i18n("Filesystem mounted at %1").arg(m_d->mountPoint)
+ , KIconLoader::global()->loadIcon("drive-removable-media", KIconLoader::Desktop)
+ );
- new KRun(KUrl::fromLocalFile(mountProc->property(mount_c).toString()), 0);
+ new KRun(KUrl::fromLocalFile(m_d->mountPoint), 0);
}
void SftpPlugin::onError(QProcess::ProcessError error)
{
if (error == QProcess::FailedToStart)
{
- KNotification::event(KNotification::Error
- , i18n("Device %1").arg(device()->name())
- , i18n("Failed to start sshfs")
- , KIconLoader::global()->loadIcon("dialog-error", KIconLoader::Desktop)
- , 0, KNotification::CloseOnTimeout
- )->sendEvent();
+ knotify(KNotification::Error
+ , i18n("Device %1").arg(device()->name())
+ , i18n("Failed to start sshfs")
+ , KIconLoader::global()->loadIcon("dialog-error", KIconLoader::Desktop)
+ );
+ cleanMountPoint();
}
}
@@ -159,20 +160,34 @@ void SftpPlugin::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
if (exitStatus == QProcess::NormalExit)
{
- KNotification::event(KNotification::Notification
- , i18n("Device %1").arg(device()->name())
- , i18n("Filesystem unmounted")
- , KIconLoader::global()->loadIcon("dialog-ok", KIconLoader::Desktop)
- , 0, KNotification::CloseOnTimeout
- )->sendEvent();
+ knotify(KNotification::Notification
+ , i18n("Device %1").arg(device()->name())
+ , i18n("Filesystem unmounted")
+ , KIconLoader::global()->loadIcon("dialog-ok", KIconLoader::Desktop)
+ );
}
else
{
- KNotification::event(KNotification::Error
- , i18n("Device %1").arg(device()->name())
- , i18n("Error when accessing to filesystem")
- , KIconLoader::global()->loadIcon("dialog-error", KIconLoader::Desktop)
- , 0, KNotification::CloseOnTimeout
- )->sendEvent();
+ knotify(KNotification::Error
+ , i18n("Device %1").arg(device()->name())
+ , i18n("Error when accessing to filesystem")
+ , KIconLoader::global()->loadIcon("dialog-error", KIconLoader::Desktop)
+ );
}
+
+ cleanMountPoint();
+ m_d->mountProc = 0;
+}
+
+void SftpPlugin::knotify(int type, const QString& title, const QString& text, const QPixmap& icon) const
+{
+ KNotification::event(KNotification::StandardEvent(type), title, text, icon, 0
+ , KNotification::CloseOnTimeout);
+}
+
+void SftpPlugin::cleanMountPoint()
+{
+ if (m_d->mountProc.isNull()) return;
+
+ KProcess::execute(QStringList() << "fusermount" << "-u" << m_d->mountPoint, 10000);
}
diff --git a/kded/plugins/sftp/sftpplugin.h b/kded/plugins/sftp/sftpplugin.h
index 8975bd5..a3100e4 100644
--- a/kded/plugins/sftp/sftpplugin.h
+++ b/kded/plugins/sftp/sftpplugin.h
@@ -27,13 +27,14 @@
#define PACKAGE_TYPE_SFTP QLatin1String("kdeconnect.sftp")
-class SftpDbusInterface;
+class KNotification;
class SftpPlugin
: public KdeConnectPlugin
{
Q_OBJECT
-
+ Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
+
public:
explicit SftpPlugin(QObject *parent, const QVariantList &args);
virtual ~SftpPlugin();
@@ -41,18 +42,23 @@ public:
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
virtual void connected();
+
+ Q_SCRIPTABLE void startBrowsing();
+ Q_SCRIPTABLE void stopBrowsing();
private Q_SLOTS:
- void startBrowsing();
- void stopBrowsing();
-
void onStarted();
void onError(QProcess::ProcessError error);
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
- SftpDbusInterface* sftpDbusInterface;
- QPointer<KProcess> mountProc;
+ QString dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/sftp"; }
+ void knotify(int type, const QString& title, const QString& text, const QPixmap& icon) const;
+ void cleanMountPoint();
+
+private:
+ struct Pimpl;
+ QScopedPointer<Pimpl> m_d;
};
#endif
diff --git a/libkdeconnect/dbusinterfaces.cpp b/libkdeconnect/dbusinterfaces.cpp
index 6f3529e..1292a1c 100644
--- a/libkdeconnect/dbusinterfaces.cpp
+++ b/libkdeconnect/dbusinterfaces.cpp
@@ -52,7 +52,7 @@ NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, co
}
SftpDbusInterface::SftpDbusInterface(const QString& id, QObject* parent)
- : OrgKdeKdeconnectDeviceSftpInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
+ : OrgKdeKdeconnectDeviceSftpInterface("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent)
{
}
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list