[Icon Applet] Restore some nicer file name heuristic

For local files, the base name is used, for http(s):// URLs the host name
is used and only if that fails we'll fallback to fileName (which still can be empty)
wilder-5.14
Kai Uwe Broulik 9 years ago
parent 71507de04b
commit c2a90c7a94
  1. 15
      applets/icon/iconapplet.cpp

@ -109,6 +109,8 @@ void IconApplet::populate()
}
backingDesktopFile.append(desiredDesktopFileName);
QString name; // ends up as "Name" in the .desktop file for "Link" files below
if (m_url.isLocalFile()) {
const QString localUrlString = m_url.toLocalFile();
@ -138,6 +140,8 @@ void IconApplet::populate()
return;
}
name = QFileInfo(localUrlString).baseName();
}
// in all other cases just make it a link
@ -148,7 +152,16 @@ void IconApplet::populate()
KDesktopFile linkDesktopFile(backingDesktopFile);
auto desktopGroup = linkDesktopFile.desktopGroup();
desktopGroup.writeEntry(QStringLiteral("Name"), m_url.fileName());
if (name.isEmpty()) {
if (m_url.scheme().startsWith(QLatin1String("http"))) {
name = m_url.host();
} else {
name = m_url.fileName();
}
}
desktopGroup.writeEntry(QStringLiteral("Name"), name);
desktopGroup.writeEntry(QStringLiteral("Type"), QStringLiteral("Link"));
desktopGroup.writeEntry(QStringLiteral("URL"), m_url);
desktopGroup.writeEntry(QStringLiteral("Icon"), KIO::iconNameForUrl(m_url));

Loading…
Cancel
Save