]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
[KStandardItemListWidget] Request the pixmap size we want and let the icon loader...
[dolphin.git] / src / dolphintabwidget.cpp
index 7928c510e2aaa4df15ab281eaf863966baa80422..ec0c783bc34a491426dadda1d5ce4656dbbf4f01 100644 (file)
@@ -130,6 +130,11 @@ void DolphinTabWidget::refreshViews()
     }
 }
 
+bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
+{
+    return indexByUrl(url).first >= 0;
+}
+
 void DolphinTabWidget::openNewActivatedTab()
 {
     const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer();
@@ -161,6 +166,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
     QWidget* focusWidget = QApplication::focusWidget();
 
     DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this);
+    tabPage->setActive(false);
     tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
     connect(tabPage, &DolphinTabPage::activeViewChanged,
             this, &DolphinTabWidget::activeViewChanged);
@@ -170,7 +176,7 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
     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
@@ -186,11 +192,13 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
     QList<QUrl>::const_iterator it = dirs.constBegin();
     while (it != dirs.constEnd()) {
         const QUrl& primaryUrl = *(it++);
-        const QPair<int, bool> viewLocation = getIndexByUrl(primaryUrl);
-        if (viewLocation.first >= 0) {
-            setCurrentIndex(viewLocation.first);
-            const auto tabPage = tabPageAt(viewLocation.first);
-            if (viewLocation.second) {
+        const QPair<int, bool> indexInfo = indexByUrl(primaryUrl);
+        const int index = indexInfo.first;
+        const bool isInPrimaryView = indexInfo.second;
+        if (index >= 0) {
+            setCurrentIndex(index);
+            const auto tabPage = tabPageAt(index);
+            if (isInPrimaryView) {
                 tabPage->primaryViewContainer()->setActive(true);
             } else {
                 tabPage->secondaryViewContainer()->setActive(true);
@@ -329,7 +337,12 @@ void DolphinTabWidget::tabUrlChanged(const QUrl& url)
     const int index = indexOf(qobject_cast<QWidget*>(sender()));
     if (index >= 0) {
         tabBar()->setTabText(index, tabName(tabPageAt(index)));
-        tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
+        if (tabBar()->isVisible()) {
+            tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
+        } 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()) {
@@ -357,6 +370,13 @@ void DolphinTabWidget::tabInserted(int index)
     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, QIcon::fromTheme(KIO::iconNameForUrl(tabPageAt(i)->activeViewContainer()->url())));
+            }
+        }
+
         tabBar()->show();
     }
 
@@ -387,7 +407,7 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
     return name.replace('&', QLatin1String("&&"));
 }
 
-QPair<int, bool> DolphinTabWidget::getIndexByUrl(const QUrl& url) const
+QPair<int, bool> DolphinTabWidget::indexByUrl(const QUrl& url) const
 {
     for (int i = 0; i < count(); i++) {
         const auto tabPage = tabPageAt(i);