]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Merge branch 'Applications/18.08'
[dolphin.git] / src / dolphinviewcontainer.cpp
index 7b995955f59398399d8fb2a2f7ce6466b998f3d1..f747d442ee81e769f3fac28decb21c17a30ca64a 100644 (file)
@@ -31,6 +31,7 @@
 #include "views/viewproperties.h"
 
 #include <KFileItemActions>
+#include <KFilePlacesModel>
 #include <KIO/PreviewJob>
 #include <KLocalizedString>
 #include <KMessageWidget>
@@ -161,12 +162,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     connect(m_urlNavigator, &KUrlNavigator::returnPressed,
             this, &DolphinViewContainer::slotReturnPressed);
     connect(m_urlNavigator, &KUrlNavigator::urlsDropped, this, [=](const QUrl &destination, QDropEvent *event) {
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 37, 0)
         m_view->dropUrls(destination, event, m_urlNavigator->dropWidget());
-#else
-        // TODO: remove as soon as we can hard-depend of KF5 >= 5.37
-        m_view->dropUrls(destination, event, m_view);
-#endif
     });
 
     connect(m_view, &DolphinView::directoryLoadingCompleted, this, [this]() {
@@ -414,6 +410,52 @@ void DolphinViewContainer::reload()
     m_messageWidget->hide();
 }
 
+QString DolphinViewContainer::caption() const
+{
+    if (GeneralSettings::showFullPathInTitlebar()) {
+        if (!url().isLocalFile()) {
+            return url().adjusted(QUrl::StripTrailingSlash).toString();
+        }
+        return url().adjusted(QUrl::StripTrailingSlash).path();
+    }
+
+    KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
+    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url(), 1, Qt::MatchExactly);
+
+    if (!matchedPlaces.isEmpty()) {
+        return placesModel->text(matchedPlaces.first());
+    }
+    if (!url().isLocalFile()) {
+        QUrl adjustedUrl = url().adjusted(QUrl::StripTrailingSlash);
+        QString caption;
+        if (!adjustedUrl.fileName().isEmpty()) {
+            caption = adjustedUrl.fileName();
+        } else if (!adjustedUrl.path().isEmpty() && adjustedUrl.path() != "/") {
+            caption = adjustedUrl.path();
+        } else if (!adjustedUrl.host().isEmpty()) {
+            caption = adjustedUrl.host();
+        } else {
+            caption = adjustedUrl.toString();
+        }
+        return caption;
+    }
+
+    QString fileName = url().adjusted(QUrl::StripTrailingSlash).fileName();
+    if (fileName.isEmpty()) {
+        fileName = '/';
+    }
+
+    if (isSearchModeEnabled()) {
+        if(currentSearchText().isEmpty()){
+            return i18n("Search");
+        } else {
+            return i18n("Search for %1", currentSearchText());
+        }
+    }
+
+    return fileName;
+}
+
 void DolphinViewContainer::setUrl(const QUrl& newUrl)
 {
     if (newUrl != m_urlNavigator->locationUrl()) {