]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Port away from deprecated KDesktopFileActions::userDefinedServices overload
[dolphin.git] / src / dolphinviewcontainer.cpp
index 549b62b0393c62bb8ba84b0d6bcb063e922339d0..5520bf794ab5f3272eebacce89090788531a409e 100644 (file)
@@ -30,7 +30,6 @@
 #include <KProtocolManager>
 #include <KShell>
 #include <KUrlComboBox>
-#include <KUrlNavigator>
 
 #include <QDropEvent>
 #include <QLoggingCategory>
@@ -197,6 +196,17 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
         }
     });
 
+    KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
+    connect(placesModel, &KFilePlacesModel::dataChanged,
+            this, &DolphinViewContainer::slotPlacesModelChanged);
+    connect(placesModel, &KFilePlacesModel::rowsInserted,
+            this, &DolphinViewContainer::slotPlacesModelChanged);
+    connect(placesModel, &KFilePlacesModel::rowsRemoved,
+            this, &DolphinViewContainer::slotPlacesModelChanged);
+
+    connect(this, &DolphinViewContainer::searchModeEnabledChanged,
+            this, &DolphinViewContainer::captionChanged);
+
     // Initialize kactivities resource instance
 
 #ifdef HAVE_KACTIVITIES
@@ -476,7 +486,8 @@ QString DolphinViewContainer::caption() const
     }
 
     KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
-    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, QUrl(url().adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/?")), 1, Qt::MatchRegExp);
+    const QString pattern = url().adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/?");
+    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, QRegularExpression::anchoredPattern(pattern), 1, Qt::MatchRegularExpression);
 
     if (!matchedPlaces.isEmpty()) {
         return placesModel->text(matchedPlaces.first());
@@ -727,6 +738,18 @@ void DolphinViewContainer::slotUrlSelectionRequested(const QUrl& url)
     m_view->markUrlAsCurrent(url); // makes the item scroll into view
 }
 
+void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
+{
+    disconnect(m_urlNavigator.get(), &KUrlNavigator::urlSelectionRequested,
+        this, &DolphinViewContainer::slotUrlSelectionRequested);
+}
+
+void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
+{
+    connect(m_urlNavigator.get(), &KUrlNavigator::urlSelectionRequested,
+        this, &DolphinViewContainer::slotUrlSelectionRequested);
+}
+
 void DolphinViewContainer::redirect(const QUrl& oldUrl, const QUrl& newUrl)
 {
     Q_UNUSED(oldUrl)
@@ -779,6 +802,13 @@ void DolphinViewContainer::showErrorMessage(const QString& msg)
     showMessage(msg, Error);
 }
 
+void DolphinViewContainer::slotPlacesModelChanged()
+{
+    if (!GeneralSettings::showFullPathInTitlebar() && !isSearchModeEnabled()) {
+        Q_EMIT captionChanged();
+    }
+}
+
 bool DolphinViewContainer::isSearchUrl(const QUrl& url) const
 {
     return url.scheme().contains(QLatin1String("search"));