diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -217,6 +217,12 @@ */ QString tabName(DolphinTabPage* tabPage) const; + /** + * @param tabPage The tab page to get the icon of + * @return The icon of the tab page + */ + QIcon tabIcon(DolphinTabPage *tabPage) const; + private: /** Caches the (negated) places panel visibility */ bool m_placesSelectorVisible; diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -170,7 +170,7 @@ if (tabPlacement == AfterCurrentTab) { newTabIndex = currentIndex() + 1; } - insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); + insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage)); if (focusWidget) { // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened @@ -322,8 +322,14 @@ { const int index = indexOf(qobject_cast(sender())); if (index >= 0) { - tabBar()->setTabText(index, tabName(tabPageAt(index))); - tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); + DolphinTabPage *tabPage = tabPageAt(index); + tabBar()->setTabText(index, tabName(tabPage)); + if (tabBar()->isVisible()) { + tabBar()->setTabIcon(index, tabIcon(tabPage)); + } else { + // Mark as dirty, actually load once the tab bar actually gets shown + tabBar()->setTabIcon(index, QIcon()); + } // Emit the currentUrlChanged signal if the url of the current tab has been changed. if (index == currentIndex()) { @@ -351,6 +357,13 @@ QTabWidget::tabInserted(index); if (count() > 1) { + // Resolve all pending tab icons + for (int i = 0; i < count(); ++i) { + if (tabBar()->tabIcon(i).isNull()) { + tabBar()->setTabIcon(i, tabIcon(tabPageAt(i))); + } + } + tabBar()->show(); } @@ -381,6 +394,14 @@ return name.replace('&', QLatin1String("&&")); } +QIcon DolphinTabWidget::tabIcon(DolphinTabPage *tabPage) const +{ + if (!tabPage) { + return QIcon(); + } + return QIcon::fromTheme(KIO::iconNameForUrl(tabPage->activeViewContainer()->url())); +} + int DolphinTabWidget::getIndexByUrl(const QUrl& url) const { for (int i = 0; i < count(); i++) {