SFTP plugin now supports devices with multiple external storages
This commit is contained in:
parent
279dbe5598
commit
7a214e72ee
5 changed files with 50 additions and 35 deletions
|
@ -136,44 +136,38 @@ void KioKdeconnect::listDevice()
|
||||||
|
|
||||||
QDBusReply<bool> mountreply = interface.mountAndWait();
|
QDBusReply<bool> mountreply = interface.mountAndWait();
|
||||||
|
|
||||||
if (handleDBusError(mountreply, this))
|
if (handleDBusError(mountreply, this)) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mountreply.value())
|
if (!mountreply.value()) {
|
||||||
{
|
|
||||||
error(KIO::ERR_COULD_NOT_MOUNT, i18n("Could not mount device filesystem"));
|
error(KIO::ERR_COULD_NOT_MOUNT, i18n("Could not mount device filesystem"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusReply<QString> urlreply = interface.mountPoint();
|
QDBusReply< QVariantMap > urlreply = interface.getDirectories();
|
||||||
|
|
||||||
if (handleDBusError(urlreply, this))
|
if (handleDBusError(urlreply, this)) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString url = urlreply.value();
|
QVariantMap urls = urlreply.value();
|
||||||
|
|
||||||
|
for (QVariantMap::iterator it = urls.begin(); it != urls.end(); it++) {
|
||||||
|
|
||||||
|
QString path = it.key();
|
||||||
|
QString name = it.value().toString();
|
||||||
|
|
||||||
KIO::UDSEntry entry;
|
KIO::UDSEntry entry;
|
||||||
entry.insert(KIO::UDSEntry::UDS_NAME, "files");
|
entry.insert(KIO::UDSEntry::UDS_NAME, "files");
|
||||||
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Camera pictures"));
|
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, name);
|
||||||
entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "folder");
|
entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "folder");
|
||||||
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
|
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
|
||||||
entry.insert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH);
|
entry.insert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH);
|
||||||
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "");
|
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "");
|
||||||
entry.insert(KIO::UDSEntry::UDS_URL, url + "/DCIM/Camera");
|
entry.insert(KIO::UDSEntry::UDS_URL, path);
|
||||||
listEntry(entry, false);
|
|
||||||
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_NAME, "files");
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("All files"));
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_ICON_NAME, "folder");
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH);
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "");
|
|
||||||
entry.insert(KIO::UDSEntry::UDS_URL, url);
|
|
||||||
listEntry(entry, false);
|
listEntry(entry, false);
|
||||||
|
}
|
||||||
|
|
||||||
listEntry(KIO::UDSEntry(), true);
|
listEntry(KIO::UDSEntry(), true);
|
||||||
infoMessage("");
|
infoMessage("");
|
||||||
|
|
|
@ -120,11 +120,16 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
|
||||||
QDir().mkpath(mpoint);
|
QDir().mkpath(mpoint);
|
||||||
|
|
||||||
const QString program = "sshfs";
|
const QString program = "sshfs";
|
||||||
|
|
||||||
|
QString path;
|
||||||
|
if (np.has("multiPaths")) path = "/";
|
||||||
|
else path = np.get<QString>("path");
|
||||||
|
|
||||||
const QStringList arguments = QStringList()
|
const QStringList arguments = QStringList()
|
||||||
<< QString("%1@%2:%3")
|
<< QString("%1@%2:%3")
|
||||||
.arg(np.get<QString>("user"))
|
.arg(np.get<QString>("user"))
|
||||||
.arg(np.get<QString>("ip"))
|
.arg(np.get<QString>("ip"))
|
||||||
.arg(np.get<QString>("path"))
|
.arg(path)
|
||||||
<< mpoint
|
<< mpoint
|
||||||
<< "-p" << np.get<QString>("port")
|
<< "-p" << np.get<QString>("port")
|
||||||
<< "-d"
|
<< "-d"
|
||||||
|
|
|
@ -70,7 +70,6 @@ void SftpConfig::defaults()
|
||||||
Q_EMIT changed(true);
|
Q_EMIT changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SftpConfig::load()
|
void SftpConfig::load()
|
||||||
{
|
{
|
||||||
KCModule::load();
|
KCModule::load();
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct SftpPlugin::Pimpl
|
||||||
|
|
||||||
SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
|
SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
, m_d(new Pimpl)
|
, m_d(new Pimpl())
|
||||||
{
|
{
|
||||||
addToDolphin();
|
addToDolphin();
|
||||||
kDebug(debugArea()) << "Created device:" << device()->name();
|
kDebug(debugArea()) << "Created device:" << device()->name();
|
||||||
|
@ -140,14 +140,26 @@ bool SftpPlugin::startBrowsing()
|
||||||
|
|
||||||
bool SftpPlugin::receivePackage(const NetworkPackage& np)
|
bool SftpPlugin::receivePackage(const NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (!(fields_c - np.body().keys().toSet()).isEmpty())
|
if (!(fields_c - np.body().keys().toSet()).isEmpty()) {
|
||||||
{
|
|
||||||
// package is invalid
|
// package is invalid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT packageReceived(np);
|
Q_EMIT packageReceived(np);
|
||||||
|
|
||||||
|
remoteDirectories.clear();
|
||||||
|
if (np.has("multiPaths")) {
|
||||||
|
QStringList paths = np.get<QStringList>("multiPaths",QStringList());
|
||||||
|
QStringList names = np.get<QStringList>("pathNames",QStringList());
|
||||||
|
int size = qMin<int>(names.size(), paths.size());
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
remoteDirectories.insert(mountPoint() + paths.at(i), names.at(i));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
remoteDirectories.insert(mountPoint(), i18n("All files"));
|
||||||
|
remoteDirectories.insert(mountPoint() + "/DCIM/Camera", i18n("Camera pictures"));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,3 +208,9 @@ void SftpPlugin::knotify(int type, const QString& text, const QPixmap& icon) con
|
||||||
, KNotification::CloseOnTimeout);
|
, KNotification::CloseOnTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantMap SftpPlugin::getDirectories()
|
||||||
|
{
|
||||||
|
return remoteDirectories;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,12 +35,10 @@ class SftpPlugin
|
||||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit SftpPlugin(QObject *parent, const QVariantList &args);
|
explicit SftpPlugin(QObject *parent, const QVariantList &args);
|
||||||
virtual ~SftpPlugin();
|
virtual ~SftpPlugin();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
||||||
void packageReceived(const NetworkPackage& np);
|
void packageReceived(const NetworkPackage& np);
|
||||||
Q_SCRIPTABLE void mounted();
|
Q_SCRIPTABLE void mounted();
|
||||||
Q_SCRIPTABLE void unmounted();
|
Q_SCRIPTABLE void unmounted();
|
||||||
|
@ -56,8 +54,7 @@ public Q_SLOTS:
|
||||||
|
|
||||||
Q_SCRIPTABLE bool startBrowsing();
|
Q_SCRIPTABLE bool startBrowsing();
|
||||||
Q_SCRIPTABLE QString mountPoint();
|
Q_SCRIPTABLE QString mountPoint();
|
||||||
|
Q_SCRIPTABLE QVariantMap getDirectories(); //Actually a QMap<String, String>, but QDBus preffers this
|
||||||
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onMounted();
|
void onMounted();
|
||||||
|
@ -73,6 +70,8 @@ private:
|
||||||
private:
|
private:
|
||||||
struct Pimpl;
|
struct Pimpl;
|
||||||
QScopedPointer<Pimpl> m_d;
|
QScopedPointer<Pimpl> m_d;
|
||||||
|
|
||||||
|
QVariantMap remoteDirectories; //Actually a QMap<String, String>, but QDBus preffers this
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue