X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/48b58f830a585b773435c9af5ee2fe8f0c7c641d..30bf49d5d1539e9d02944230cf4489ebbccf5a45:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 1620f3c36..5978ae938 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -20,11 +20,13 @@ #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" +#include "dolphinplacesmodelsingleton.h" #include "dolphindebug.h" #include "filterbar/filterbar.h" #include "global.h" #include "search/dolphinsearchbox.h" #include "statusbar/dolphinstatusbar.h" +#include "trash/dolphintrash.h" #include "views/viewmodecontroller.h" #include "views/viewproperties.h" @@ -50,8 +52,11 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : QWidget(parent), m_topLayout(nullptr), + m_navigatorWidget(nullptr), m_urlNavigator(nullptr), + m_emptyTrashButton(nullptr), m_searchBox(nullptr), + m_searchModeEnabled(false), m_messageWidget(nullptr), m_view(nullptr), m_filterBar(nullptr), @@ -69,7 +74,12 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : m_topLayout->setSpacing(0); m_topLayout->setMargin(0); - m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this); + m_navigatorWidget = new QWidget(this); + QHBoxLayout* navigatorLayout = new QHBoxLayout(m_navigatorWidget); + navigatorLayout->setSpacing(0); + navigatorLayout->setMargin(0); + + m_urlNavigator = new KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, this); connect(m_urlNavigator, &KUrlNavigator::activated, this, &DolphinViewContainer::activate); connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged, @@ -82,6 +92,13 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : KUrlComboBox* editor = m_urlNavigator->editor(); editor->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode())); + m_emptyTrashButton = new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")), i18nc("@action:button", "Empty Trash"), this); + m_emptyTrashButton->setFlat(true); + connect(m_emptyTrashButton, &QPushButton::clicked, this, [this]() { Trash::empty(this); }); + connect(&Trash::instance(), &Trash::emptinessChanged, m_emptyTrashButton, &QPushButton::setDisabled); + m_emptyTrashButton->setDisabled(Trash::isEmpty()); + m_emptyTrashButton->hide(); + m_searchBox = new DolphinSearchBox(this); m_searchBox->hide(); connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate); @@ -93,6 +110,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); @@ -138,12 +163,11 @@ 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]() { + m_emptyTrashButton->setVisible(m_view->url().scheme() == QLatin1String("trash")); }); // Initialize status bar @@ -184,7 +208,10 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : connect(m_view, &DolphinView::urlChanged, m_filterBar, &FilterBar::slotUrlChanged); - m_topLayout->addWidget(m_urlNavigator); + navigatorLayout->addWidget(m_urlNavigator); + navigatorLayout->addWidget(m_emptyTrashButton); + + m_topLayout->addWidget(m_navigatorWidget); m_topLayout->addWidget(m_searchBox); m_topLayout->addWidget(m_messageWidget); m_topLayout->addWidget(m_view); @@ -336,7 +363,7 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled) } m_searchBox->setVisible(enabled); - m_urlNavigator->setVisible(!enabled); + m_navigatorWidget->setVisible(!enabled); if (enabled) { const QUrl& locationUrl = m_urlNavigator->locationUrl(); @@ -352,11 +379,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 @@ -384,6 +413,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()) {