]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
GIT_SILENT: minor qstring optimization
[dolphin.git] / src / dolphintabwidget.cpp
index afb5462e1ad4fcdc9cff9fdd12a1b705d0c23ca4..0546316f7763edc628b1425115b11deefbb1796c 100644 (file)
@@ -171,7 +171,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
@@ -187,9 +187,15 @@ 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 int index = getIndexByUrl(primaryUrl);
-        if (index >= 0) {
-            setCurrentIndex(index);
+        const QPair<int, bool> viewLocation = getIndexByUrl(primaryUrl);
+        if (viewLocation.first >= 0) {
+            setCurrentIndex(viewLocation.first);
+            const auto tabPage = tabPageAt(viewLocation.first);
+            if (viewLocation.second) {
+                tabPage->primaryViewContainer()->setActive(true);
+            } else {
+                tabPage->secondaryViewContainer()->setActive(true);
+            }
             continue;
         }
         if (splitView && (it != dirs.constEnd())) {
@@ -324,7 +330,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()) {
@@ -352,6 +363,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();
     }
 
@@ -382,16 +400,17 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
     return name.replace('&', QLatin1String("&&"));
 }
 
-int DolphinTabWidget::getIndexByUrl(const QUrl& url) const
+QPair<int, bool> DolphinTabWidget::getIndexByUrl(const QUrl& url) const
 {
     for (int i = 0; i < count(); i++) {
-        // Conversion to display string is necessary to deal with the '~' alias.
-        // i.e. to acknowledge that ~/ is equivalent to /home/user/
-        const QUrl tabUrl = tabPageAt(i)->activeViewContainer()->url();
-        if (url == tabUrl ||
-            url.toDisplayString(QUrl::StripTrailingSlash) == tabUrl.toDisplayString(QUrl::StripTrailingSlash)) {
-            return i;
+        const auto tabPage = tabPageAt(i);
+        if (url == tabPage->primaryViewContainer()->url()) {
+            return qMakePair(i, true);
+        }
+
+        if (tabPage->splitViewEnabled() && url == tabPage->secondaryViewContainer()->url()) {
+            return qMakePair(i, false);
         }
     }
-    return -1;
+    return qMakePair(-1, false);
 }