Commit d82513ce authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇 Committed by David Faure

[Notifications] Display URL relative to Place similar to KUrlNavigator

This changes the displayed destination of a file operation in the summary
to be relative to the closest user's place, similar to how the KUrlNavigator
(address bar) does it in Dolphin, for example:

* /tmp: Root/tmp
* /home/user/Documents: Documents
* /home/user/Documents/foo/bar: Documents/foo/bar
* ftp://example.com/var/www/clients/user/blog/uploads: My Blog/uploads
* sftp://192.168.0.123/home/user/stuff/kf5/plasma-workspace: Build Server/stuff/kf5/plasma-workspace

Especially for remote locations the user has bookmarked this can tremendously
clean up the displayed address, showing a nice name rather than the full URL.

The other logic about showing local paths and replacement of $HOME by tilde has been
removed as both Root and Home are default places that are likely to be present.
parent c58e8109
......@@ -81,9 +81,6 @@ QUrl JobPrivate::localFileOrUrl(const QString &urlString)
}
// Tries to return a more user-friendly displayed destination
// - if it is a place, show the name, e.g. "Downloads"
// - if it is inside home, abbreviate that to tilde ~/foo
// - otherwise print URL (without password)
QString JobPrivate::prettyDestUrl() const
{
QUrl url = m_destUrl;
......@@ -100,27 +97,26 @@ QString JobPrivate::prettyDestUrl() const
m_placesModel = createPlacesModel();
}
// If we copy into a "place", show its pretty name instead of a URL/path
for (int row = 0; row < m_placesModel->rowCount(); ++row) {
const QModelIndex idx = m_placesModel->index(row, 0);
if (m_placesModel->isHidden(idx)) {
continue;
}
// Mimic KUrlNavigator and show a pretty place name,
// for example Documents/foo/bar rather than /home/user/Documents/foo/bar
const QModelIndex closestIdx = m_placesModel->closestItem(url);
if (closestIdx.isValid()) {
const QUrl placeUrl = m_placesModel->url(closestIdx);
if (m_placesModel->url(idx).matches(url, QUrl::StripTrailingSlash)) {
return m_placesModel->text(idx);
}
}
QString text = m_placesModel->text(closestIdx);
if (url.isLocalFile()) {
QString destUrlString = url.toLocalFile();
QString pathInsidePlace = url.path().mid(placeUrl.path().length());
if (!pathInsidePlace.isEmpty()
&& !pathInsidePlace.startsWith(QLatin1Char('/'))) {
pathInsidePlace.prepend(QLatin1Char('/'));
}
const QString homePath = QDir::homePath();
if (destUrlString.startsWith(homePath)) {
destUrlString = QLatin1String("~") + destUrlString.mid(homePath.length());
if (pathInsidePlace != QLatin1Char('/')) {
text.append(pathInsidePlace);
}
return destUrlString;
return text;
}
return url.toDisplayString(QUrl::RemoveUserInfo);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment