]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Tabs: ensure to have folder icons for remote folders
authorMéven Car <meven29@gmail.com>
Tue, 24 Nov 2020 17:07:56 +0000 (18:07 +0100)
committerNate Graham <nate@kde.org>
Mon, 30 Aug 2021 14:58:08 +0000 (14:58 +0000)
KIO::iconForUrl relies on filename to find the icon for remote files.
Appending / at the end of the filename allows it to interpret it as
a folder.

This causes inconsistent tab icons.

To reproduce:

Open in a tab a url on a smb or sftp folder, i.e sftp:/my-server/photos

Before:
Icon is a cloud.

After:
Icon is a folder

Previously a folder icon could be presented if the tab was first opened
with a url with a trailing /

src/dolphintabwidget.cpp
src/tests/dolphinmainwindowtest.cpp

index cfb695e7db24a05a1f3a931f0823859ff917adf3..0e7012d3b687316be7097b249ea023b79f404d72 100644 (file)
@@ -383,7 +383,9 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url)
         tabBar()->setTabText(index, tabName(tabPageAt(index)));
         tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
         if (tabBar()->isVisible()) {
         tabBar()->setTabText(index, tabName(tabPageAt(index)));
         tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
         if (tabBar()->isVisible()) {
-            tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
+            // ensure the path url ends with a slash to have proper folder icon for remote folders
+            const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/"));
+            tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl)));
         } else {
             // Mark as dirty, actually load once the tab bar actually gets shown
             tabBar()->setTabIcon(index, QIcon());
         } else {
             // Mark as dirty, actually load once the tab bar actually gets shown
             tabBar()->setTabIcon(index, QIcon());
@@ -427,7 +429,9 @@ void DolphinTabWidget::tabInserted(int index)
         for (int i = 0; i < count(); ++i) {
             const QUrl url = tabPageAt(i)->activeViewContainer()->url();
             if (tabBar()->tabIcon(i).isNull()) {
         for (int i = 0; i < count(); ++i) {
             const QUrl url = tabPageAt(i)->activeViewContainer()->url();
             if (tabBar()->tabIcon(i).isNull()) {
-                tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(url)));
+                // ensure the path url ends with a slash to have proper folder icon for remote folders
+                const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/"));
+                tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl)));
             }
             if (tabBar()->tabToolTip(i).isEmpty()) {
                 tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
             }
             if (tabBar()->tabToolTip(i).isEmpty()) {
                 tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
index 40f8f6bcd8620c40d263cc03aefee470fe4e37fe..b40d3dbbf79e580dcadbc3041c4f7ed7e991d13a 100644 (file)
@@ -211,7 +211,8 @@ void DolphinMainWindowTest::testOpenInNewTabTitle()
     QCOMPARE(tabWidget->count(), 2);
     QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1));
     if (!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull()) {
     QCOMPARE(tabWidget->count(), 2);
     QVERIFY(tabWidget->tabText(0) != tabWidget->tabText(1));
     if (!tabWidget->tabIcon(0).isNull() && !tabWidget->tabIcon(1).isNull()) {
-        QVERIFY(tabWidget->tabIcon(0).name() != tabWidget->tabIcon(1).name());
+        QCOMPARE(QStringLiteral("inode-directory"), tabWidget->tabIcon(0).name());
+        QCOMPARE(QStringLiteral("inode-directory"), tabWidget->tabIcon(1).name());
     }
 }
 
     }
 }