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();
|
||||
|
||||
if (handleDBusError(mountreply, this))
|
||||
{
|
||||
if (handleDBusError(mountreply, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mountreply.value())
|
||||
{
|
||||
if (!mountreply.value()) {
|
||||
error(KIO::ERR_COULD_NOT_MOUNT, i18n("Could not mount device filesystem"));
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusReply<QString> urlreply = interface.mountPoint();
|
||||
QDBusReply< QVariantMap > urlreply = interface.getDirectories();
|
||||
|
||||
if (handleDBusError(urlreply, this))
|
||||
{
|
||||
if (handleDBusError(urlreply, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString url = urlreply.value();
|
||||
QVariantMap urls = urlreply.value();
|
||||
|
||||
KIO::UDSEntry entry;
|
||||
entry.insert(KIO::UDSEntry::UDS_NAME, "files");
|
||||
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Camera pictures"));
|
||||
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 + "/DCIM/Camera");
|
||||
listEntry(entry, false);
|
||||
for (QVariantMap::iterator it = urls.begin(); it != urls.end(); it++) {
|
||||
|
||||
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);
|
||||
QString path = it.key();
|
||||
QString name = it.value().toString();
|
||||
|
||||
KIO::UDSEntry entry;
|
||||
entry.insert(KIO::UDSEntry::UDS_NAME, "files");
|
||||
entry.insert(KIO::UDSEntry::UDS_DISPLAY_NAME, name);
|
||||
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, path);
|
||||
listEntry(entry, false);
|
||||
}
|
||||
|
||||
listEntry(KIO::UDSEntry(), true);
|
||||
infoMessage("");
|
||||
|
|
|
@ -120,11 +120,16 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
|
|||
QDir().mkpath(mpoint);
|
||||
|
||||
const QString program = "sshfs";
|
||||
|
||||
QString path;
|
||||
if (np.has("multiPaths")) path = "/";
|
||||
else path = np.get<QString>("path");
|
||||
|
||||
const QStringList arguments = QStringList()
|
||||
<< QString("%1@%2:%3")
|
||||
.arg(np.get<QString>("user"))
|
||||
.arg(np.get<QString>("ip"))
|
||||
.arg(np.get<QString>("path"))
|
||||
.arg(path)
|
||||
<< mpoint
|
||||
<< "-p" << np.get<QString>("port")
|
||||
<< "-d"
|
||||
|
|
|
@ -70,7 +70,6 @@ void SftpConfig::defaults()
|
|||
Q_EMIT changed(true);
|
||||
}
|
||||
|
||||
|
||||
void SftpConfig::load()
|
||||
{
|
||||
KCModule::load();
|
||||
|
|
|
@ -53,7 +53,7 @@ struct SftpPlugin::Pimpl
|
|||
|
||||
SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
|
||||
: KdeConnectPlugin(parent, args)
|
||||
, m_d(new Pimpl)
|
||||
, m_d(new Pimpl())
|
||||
{
|
||||
addToDolphin();
|
||||
kDebug(debugArea()) << "Created device:" << device()->name();
|
||||
|
@ -140,14 +140,26 @@ bool SftpPlugin::startBrowsing()
|
|||
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -196,3 +208,9 @@ void SftpPlugin::knotify(int type, const QString& text, const QPixmap& icon) con
|
|||
, KNotification::CloseOnTimeout);
|
||||
}
|
||||
|
||||
QVariantMap SftpPlugin::getDirectories()
|
||||
{
|
||||
return remoteDirectories;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,12 +35,10 @@ class SftpPlugin
|
|||
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.sftp")
|
||||
|
||||
public:
|
||||
|
||||
explicit SftpPlugin(QObject *parent, const QVariantList &args);
|
||||
virtual ~SftpPlugin();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void packageReceived(const NetworkPackage& np);
|
||||
Q_SCRIPTABLE void mounted();
|
||||
Q_SCRIPTABLE void unmounted();
|
||||
|
@ -56,8 +54,7 @@ public Q_SLOTS:
|
|||
|
||||
Q_SCRIPTABLE bool startBrowsing();
|
||||
Q_SCRIPTABLE QString mountPoint();
|
||||
|
||||
|
||||
Q_SCRIPTABLE QVariantMap getDirectories(); //Actually a QMap<String, String>, but QDBus preffers this
|
||||
|
||||
private Q_SLOTS:
|
||||
void onMounted();
|
||||
|
@ -73,6 +70,8 @@ private:
|
|||
private:
|
||||
struct Pimpl;
|
||||
QScopedPointer<Pimpl> m_d;
|
||||
|
||||
QVariantMap remoteDirectories; //Actually a QMap<String, String>, but QDBus preffers this
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue