Handle errorMessage in kdeconnect.sftp packet

This commit is contained in:
Erik Duisters 2019-01-22 18:42:00 +01:00
parent 74ba660cad
commit 273c9bb6e4
4 changed files with 23 additions and 2 deletions

View file

@ -143,7 +143,7 @@ void KioKdeconnect::listDevice()
}
if (!mountreply.value()) {
error(KIO::ERR_COULD_NOT_MOUNT, i18n("Could not mount device filesystem"));
error(KIO::ERR_COULD_NOT_MOUNT, interface.getMountError());
return;
}

View file

@ -82,6 +82,11 @@ void Mounter::onPackageReceived(const NetworkPacket& np)
unmount(false);
return;
}
if (np.has("errorMessage")) {
Q_EMIT failed(np.get<QString>("errorMessage", ""));
return;
}
//This is the previous code, to access sftp server using KIO. Now we are
//using the external binary sshfs, and accessing it as a local filesystem.

View file

@ -117,6 +117,16 @@ bool SftpPlugin::isMounted() const
return d->m_mounter && d->m_mounter->isMounted();
}
QString SftpPlugin::getMountError()
{
if (!mountError.isEmpty()) {
return mountError;
} else {
return i18n("Could not mount device filesystem");
}
}
bool SftpPlugin::startBrowsing()
{
if (mountAndWait()) {
@ -128,7 +138,7 @@ bool SftpPlugin::startBrowsing()
bool SftpPlugin::receivePacket(const NetworkPacket& np)
{
if (!(fields_c - np.body().keys().toSet()).isEmpty()) {
if (!(fields_c - np.body().keys().toSet()).isEmpty() && !np.has("errorMessage")) {
// packet is invalid
return false;
}
@ -147,6 +157,10 @@ bool SftpPlugin::receivePacket(const NetworkPacket& np)
remoteDirectories.insert(mountPoint(), i18n("All files"));
remoteDirectories.insert(mountPoint() + "/DCIM/Camera", i18n("Camera pictures"));
}
if (np.has("errorMessage")) {
mountError = np.get<QString>("errorMessage");
}
return true;
}

View file

@ -50,6 +50,7 @@ public Q_SLOTS:
Q_SCRIPTABLE void unmount();
Q_SCRIPTABLE bool mountAndWait();
Q_SCRIPTABLE bool isMounted() const;
Q_SCRIPTABLE QString getMountError();
Q_SCRIPTABLE bool startBrowsing();
Q_SCRIPTABLE QString mountPoint();
@ -71,6 +72,7 @@ private:
QString deviceId; //Storing it to avoid accessing device() from the destructor which could cause a crash
QVariantMap remoteDirectories; //Actually a QMap<String, String>, but QDBus prefers this
QString mountError;
};