X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f588a7d48b7cef5351d8b0f030a6ec5e76229976..aeb2b11fe452f2cb341e20e7d44aadf8a4e8d271:/src/dolphinviewcontainer.cpp
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp
index cf7778c82..fbad258ac 100644
--- a/src/dolphinviewcontainer.cpp
+++ b/src/dolphinviewcontainer.cpp
@@ -6,6 +6,7 @@
#include "dolphinviewcontainer.h"
+#include "admin/bar.h"
#include "dolphin_compactmodesettings.h"
#include "dolphin_contentdisplaysettings.h"
#include "dolphin_detailsmodesettings.h"
@@ -46,12 +47,13 @@
// An overview of the widgets contained by this ViewContainer
struct LayoutStructure {
int searchBox = 0;
- int messageWidget = 1;
- int selectionModeTopBar = 2;
- int view = 3;
- int selectionModeBottomBar = 4;
- int filterBar = 5;
- int statusBar = 6;
+ int adminBar = 1;
+ int messageWidget = 2;
+ int selectionModeTopBar = 3;
+ int view = 4;
+ int selectionModeBottomBar = 5;
+ int filterBar = 6;
+ int statusBar = 7;
};
constexpr LayoutStructure positionFor;
@@ -62,6 +64,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
, m_urlNavigatorConnected{nullptr}
, m_searchBox(nullptr)
, m_searchModeEnabled(false)
+ , m_adminBar{nullptr}
, m_messageWidget(nullptr)
, m_selectionModeTopBar{nullptr}
, m_view(nullptr)
@@ -103,10 +106,10 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
m_messageWidget->setPosition(KMessageWidget::Header);
m_messageWidget->hide();
-#ifndef Q_OS_WIN
+#if !defined(Q_OS_WIN) && !defined(Q_OS_HAIKU)
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);
+ showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), KMessageWidget::Warning);
}
#endif
@@ -138,8 +141,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinViewContainer::slotDirectoryLoadingCompleted);
connect(m_view, &DolphinView::directoryLoadingCanceled, this, &DolphinViewContainer::slotDirectoryLoadingCanceled);
connect(m_view, &DolphinView::itemCountChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
- connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinViewContainer::updateDirectoryLoadingProgress);
- connect(m_view, &DolphinView::directorySortingProgress, this, &DolphinViewContainer::updateDirectorySortingProgress);
connect(m_view, &DolphinView::selectionChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::showErrorMessage);
connect(m_view, &DolphinView::urlIsFileError, this, &DolphinViewContainer::slotUrlIsFileError);
@@ -147,6 +148,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
connect(m_view, &DolphinView::hiddenFilesShownChanged, this, &DolphinViewContainer::slotHiddenFilesShownChanged);
connect(m_view, &DolphinView::sortHiddenLastChanged, this, &DolphinViewContainer::slotSortHiddenLastChanged);
connect(m_view, &DolphinView::currentDirectoryRemoved, this, &DolphinViewContainer::slotCurrentDirectoryRemoved);
+ connect(m_view, &DolphinView::urlChanged, this, &DolphinViewContainer::updateAdminBarVisibility);
// Initialize status bar
m_statusBar = new DolphinStatusBar(this);
@@ -158,6 +160,12 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
connect(m_view, &DolphinView::operationCompletedMessage, m_statusBar, &DolphinStatusBar::setText);
connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::setDefaultText);
connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::resetToDefaultText);
+ connect(m_view, &DolphinView::directoryLoadingProgress, m_statusBar, [this](int percent) {
+ m_statusBar->showProgress(i18nc("@info:progress", "Loading folderâ¦"), percent);
+ });
+ connect(m_view, &DolphinView::directorySortingProgress, m_statusBar, [this](int percent) {
+ m_statusBar->showProgress(i18nc("@info:progress", "Sortingâ¦"), percent);
+ });
connect(m_statusBar, &DolphinStatusBar::stopPressed, this, &DolphinViewContainer::stopDirectoryLoading);
connect(m_statusBar, &DolphinStatusBar::zoomLevelChanged, this, &DolphinViewContainer::slotStatusBarZoomLevelChanged);
@@ -176,6 +184,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
m_topLayout->addWidget(m_statusBar, positionFor.statusBar, 0);
setSearchModeEnabled(isSearchUrl(url));
+ updateAdminBarVisibility(url);
// Update view as the ContentDisplaySettings change
// this happens here and not in DolphinView as DolphinviewContainer and DolphinView are not in the same build target ATM
@@ -297,6 +306,8 @@ void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator
connect(m_view, &DolphinView::urlChanged, urlNavigator, &DolphinUrlNavigator::setLocationUrl);
connect(urlNavigator, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
+ urlNavigator->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable());
+
m_urlNavigatorConnected = urlNavigator;
}
@@ -355,9 +366,7 @@ void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollecti
connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
});
- connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, [this](const QString &errorMessage) {
- showErrorMessage(errorMessage);
- });
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, &DolphinViewContainer::showErrorMessage);
connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
setSelectionModeEnabled(false);
});
@@ -397,32 +406,18 @@ void DolphinViewContainer::slotSplitTabDisabled()
}
}
-void DolphinViewContainer::showMessage(const QString &msg, MessageType type)
+void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::MessageType messageType)
{
- if (msg.isEmpty()) {
+ if (message.isEmpty()) {
return;
}
- m_messageWidget->setText(msg);
+ m_messageWidget->setText(message);
// 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;
- case Error:
- m_messageWidget->setMessageType(KMessageWidget::Error);
- break;
- default:
- Q_ASSERT(false);
- break;
- }
+ m_messageWidget->setMessageType(messageType);
m_messageWidget->setWordWrap(false);
const int unwrappedWidth = m_messageWidget->sizeHint().width();
@@ -615,45 +610,28 @@ void DolphinViewContainer::updateStatusBar()
m_view->requestStatusBarText();
}
-void DolphinViewContainer::updateDirectoryLoadingProgress(int percent)
-{
- if (m_statusBar->progressText().isEmpty()) {
- m_statusBar->setProgressText(i18nc("@info:progress", "Loading folderâ¦"));
- }
- m_statusBar->setProgress(percent);
-}
-
-void DolphinViewContainer::updateDirectorySortingProgress(int percent)
-{
- if (m_statusBar->progressText().isEmpty()) {
- m_statusBar->setProgressText(i18nc("@info:progress", "Sortingâ¦"));
- }
- m_statusBar->setProgress(percent);
-}
-
void DolphinViewContainer::slotDirectoryLoadingStarted()
{
if (isSearchUrl(url())) {
// Search KIO-slaves usually don't provide any progress information. Give
// a hint to the user that a searching is done:
updateStatusBar();
- m_statusBar->setProgressText(i18nc("@info", "Searchingâ¦"));
- m_statusBar->setProgress(-1);
+ m_statusBar->showProgress(i18nc("@info", "Searchingâ¦"), -1);
} else {
// Trigger an undetermined progress indication. The progress
// information in percent will be triggered by the percent() signal
// of the directory lister later.
- m_statusBar->setProgressText(QString());
- updateDirectoryLoadingProgress(-1);
+ m_statusBar->showProgress(QString(), -1);
+ }
+
+ if (m_urlNavigatorConnected) {
+ m_urlNavigatorConnected->setReadOnlyBadgeVisible(false);
}
}
void DolphinViewContainer::slotDirectoryLoadingCompleted()
{
- if (!m_statusBar->progressText().isEmpty()) {
- m_statusBar->setProgressText(QString());
- m_statusBar->setProgress(100);
- }
+ m_statusBar->showProgress(QString(), 100);
if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
// The dir lister has been completed on a Baloo-URI and no items have been found. Instead
@@ -662,15 +640,15 @@ void DolphinViewContainer::slotDirectoryLoadingCompleted()
} else {
updateStatusBar();
}
+
+ if (m_urlNavigatorConnected) {
+ m_urlNavigatorConnected->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable());
+ }
}
void DolphinViewContainer::slotDirectoryLoadingCanceled()
{
- if (!m_statusBar->progressText().isEmpty()) {
- m_statusBar->setProgressText(QString());
- m_statusBar->setProgress(100);
- }
-
+ m_statusBar->showProgress(QString(), 100);
m_statusBar->setText(QString());
}
@@ -768,6 +746,20 @@ void DolphinViewContainer::showItemInfo(const KFileItem &item)
}
}
+void DolphinViewContainer::updateAdminBarVisibility(const QUrl &url)
+{
+ if (url.scheme() == QStringLiteral("admin")) {
+ if (!m_adminBar) {
+ m_adminBar = new Admin::Bar(this);
+ m_topLayout->addWidget(m_adminBar, positionFor.adminBar, 0);
+ connect(m_adminBar, &Admin::Bar::activated, this, &DolphinViewContainer::activate);
+ }
+ m_adminBar->setVisible(true, WithAnimation);
+ } else if (m_adminBar) {
+ m_adminBar->setVisible(false, WithAnimation);
+ }
+}
+
void DolphinViewContainer::closeFilterBar()
{
m_filterBar->closeFilterBar();
@@ -820,18 +812,18 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl &url)
if (url.scheme().startsWith(QLatin1String("http"))) {
showMessage(i18nc("@info:status", // krazy:exclude=qmethods
"Dolphin does not support web pages, the web browser has been launched"),
- Information);
+ KMessageWidget::Information);
} else {
- showMessage(i18nc("@info:status", "Protocol not supported by Dolphin, default application has been launched"), Information);
+ showMessage(i18nc("@info:status", "Protocol not supported by Dolphin, default application has been launched"), KMessageWidget::Information);
}
QDesktopServices::openUrl(url);
redirect(QUrl(), m_urlNavigator->locationUrl(1));
} else {
if (!url.scheme().isEmpty()) {
- showMessage(i18nc("@info:status", "Invalid protocol '%1'", url.scheme()), Error);
+ showMessage(i18nc("@info:status", "Invalid protocol '%1'", url.scheme()), KMessageWidget::Error);
} else {
- showMessage(i18nc("@info:status", "Invalid protocol"), Error);
+ showMessage(i18nc("@info:status", "Invalid protocol"), KMessageWidget::Error);
}
m_urlNavigator->goBack();
}
@@ -839,7 +831,8 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl &url)
void DolphinViewContainer::slotUrlSelectionRequested(const QUrl &url)
{
- m_view->markUrlsAsSelected({url});
+ // We do not want to select any item here because there is no reason to assume that the user wants to edit the folder we are emerging from. BUG: 424723
+
m_view->markUrlAsCurrent(url); // makes the item scroll into view
}
@@ -897,7 +890,7 @@ void DolphinViewContainer::closeSearchBox()
void DolphinViewContainer::stopDirectoryLoading()
{
m_view->stopLoading();
- m_statusBar->setProgress(100);
+ m_statusBar->showProgress(QString(), 100);
}
void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
@@ -905,9 +898,9 @@ void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
m_view->setZoomLevel(zoomLevel);
}
-void DolphinViewContainer::showErrorMessage(const QString &msg)
+void DolphinViewContainer::showErrorMessage(const QString &message)
{
- showMessage(msg, Error);
+ showMessage(message, KMessageWidget::Error);
}
void DolphinViewContainer::slotPlacesModelChanged()
@@ -941,7 +934,7 @@ void DolphinViewContainer::slotCurrentDirectoryRemoved()
setUrl(newUrl);
}
- showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), Warning);
+ showMessage(xi18n("Current location changed, %1 is no longer accessible.", location), KMessageWidget::Warning);
}
void DolphinViewContainer::slotOpenUrlFinished(KJob *job)