From c2a90c7a94720c40e0a8590ffe05b62f8dd1109f Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 19 Dec 2016 08:27:46 +0100 Subject: [PATCH] [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) --- applets/icon/iconapplet.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/applets/icon/iconapplet.cpp b/applets/icon/iconapplet.cpp index 497c84744..efc73122a 100644 --- a/applets/icon/iconapplet.cpp +++ b/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));