]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Fix crash during shutdown
[dolphin.git] / src / dolphinviewcontainer.cpp
index bf8ac8812f611a33039576b34b00078a13062827..767f2ae8f614041fa5cf6a59930c72bdcf78568c 100644 (file)
@@ -31,6 +31,7 @@
 #include "views/viewproperties.h"
 
 #include <KFileItemActions>
+#include <KFilePlacesModel>
 #include <KIO/PreviewJob>
 #include <KLocalizedString>
 #include <KMessageWidget>
@@ -39,7 +40,6 @@
 #include <KShell>
 #include <KUrlComboBox>
 #include <KUrlNavigator>
-#include <kio_version.h>
 
 #include <QDropEvent>
 #include <QLoggingCategory>
@@ -55,6 +55,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     m_urlNavigator(nullptr),
     m_emptyTrashButton(nullptr),
     m_searchBox(nullptr),
+    m_searchModeEnabled(false),
     m_messageWidget(nullptr),
     m_view(nullptr),
     m_filterBar(nullptr),
@@ -108,6 +109,14 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
     m_messageWidget->setCloseButtonVisible(true);
     m_messageWidget->hide();
 
+#ifndef Q_OS_WIN
+    if (getuid() == 0) {
+
+        // We must be logged in as the root user; show a big scary warning
+        showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), Warning);
+    }
+#endif
+
     m_view = new DolphinView(url, this);
     connect(m_view, &DolphinView::urlChanged,
             m_urlNavigator, &KUrlNavigator::setLocationUrl);
@@ -153,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]() {
@@ -307,6 +311,10 @@ void DolphinViewContainer::showMessage(const QString& msg, MessageType type)
 
     m_messageWidget->setText(msg);
 
+    // TODO: wrap at arbitrary character positions once QLabel can do this
+    // https://bugreports.qt.io/browse/QTBUG-1276
+    m_messageWidget->setWordWrap(true);
+
     switch (type) {
     case Information: m_messageWidget->setMessageType(KMessageWidget::Information); break;
     case Warning:     m_messageWidget->setMessageType(KMessageWidget::Warning); break;
@@ -374,11 +382,13 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled)
         }
         m_urlNavigator->setLocationUrl(url);
     }
+
+    m_searchModeEnabled = enabled;
 }
 
 bool DolphinViewContainer::isSearchModeEnabled() const
 {
-    return m_searchBox->isVisible();
+    return m_searchModeEnabled;
 }
 
 QString DolphinViewContainer::placesText() const
@@ -406,6 +416,53 @@ 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 (isSearchModeEnabled()) {
+        if (currentSearchText().isEmpty()){
+            return i18n("Search");
+        } else {
+            return i18n("Search for %1", currentSearchText());
+        }
+    }
+
+    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 = '/';
+    }
+
+    return fileName;
+}
+
 void DolphinViewContainer::setUrl(const QUrl& newUrl)
 {
     if (newUrl != m_urlNavigator->locationUrl()) {
@@ -630,7 +687,6 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
 
 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl& url)
 {
-    qCDebug(DolphinDebug) << "slotUrlSelectionRequested: " << url;
     m_view->markUrlsAsSelected({url});
     m_view->markUrlAsCurrent(url); // makes the item scroll into view
 }