kio_desktop: Fix creating a new folder while at "desktop:"

If you navigate to "desktop:" (without a / at the end) then create a new
folder, you'll end up with "/home/user/DesktopNew Folder", that's because
the path part of the url is empty. Change the code to always add / to the
beginning of the path when needed.

Drive-by change: silence a compiler warning about an unused parameter.
wilder-5.22
Ahmad Samir 6 years ago committed by David Faure
parent 1fd9988afa
commit 68306ef15a
  1. 22
      kioslave/desktop/kio_desktop.cpp

@ -109,16 +109,18 @@ void DesktopProtocol::checkLocalInstall()
bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl) bool DesktopProtocol::rewriteUrl(const QUrl &url, QUrl &newUrl)
{ {
newUrl.setScheme(QStringLiteral("file")); QString oldPath = url.path();
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); // So that creating a new folder while at "desktop:" (without a '/' after ':')
if (desktopPath.endsWith('/')) { // doesn't create "/home/user/DesktopNew Folder" instead of "/home/user/Desktop/New Folder".
desktopPath.chop(1); if (oldPath.isEmpty() || !oldPath.startsWith(QLatin1Char('/'))) {
oldPath.prepend(QLatin1Char('/'));
} }
QString filePath = desktopPath + url.path();
if (filePath.endsWith('/')) { newUrl.setScheme(QStringLiteral("file"));
filePath.chop(1); // ForwardingSlaveBase always appends a '/' const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
} newUrl.setPath(desktopPath + oldPath);
newUrl.setPath(filePath); newUrl = newUrl.adjusted(QUrl::StripTrailingSlash);
return true; return true;
} }
@ -240,6 +242,8 @@ void DesktopProtocol::virtual_hook(int id, void *data)
void DesktopProtocol::fileSystemFreeSpace(const QUrl &url) void DesktopProtocol::fileSystemFreeSpace(const QUrl &url)
{ {
Q_UNUSED(url)
const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
const KDiskFreeSpaceInfo spaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(desktopPath); const KDiskFreeSpaceInfo spaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(desktopPath);
if (spaceInfo.isValid()) { if (spaceInfo.isValid()) {

Loading…
Cancel
Save