]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.cpp
49615d185b568666cad3180476161b531867c444
[dolphin.git] / src / dolphinviewcontainer.cpp
1 /*
2 * SPDX-FileCopyrightText: 2007 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "dolphinviewcontainer.h"
8
9 #include "admin/bar.h"
10 #include "admin/workerintegration.h"
11 #include "dolphin_compactmodesettings.h"
12 #include "dolphin_contentdisplaysettings.h"
13 #include "dolphin_detailsmodesettings.h"
14 #include "dolphin_generalsettings.h"
15 #include "dolphin_iconsmodesettings.h"
16 #include "dolphindebug.h"
17 #include "dolphinplacesmodelsingleton.h"
18 #include "filterbar/filterbar.h"
19 #include "global.h"
20 #include "kitemviews/kitemlistcontainer.h"
21 #include "search/bar.h"
22 #include "selectionmode/topbar.h"
23 #include "statusbar/dolphinstatusbar.h"
24
25 #include <KActionCollection>
26 #include <KApplicationTrader>
27 #include <KFileItemActions>
28 #include <KFilePlacesModel>
29 #include <KIO/JobUiDelegateFactory>
30 #include <KIO/MkpathJob>
31 #include <KIO/OpenUrlJob>
32 #include <KLocalizedString>
33 #include <KMessageWidget>
34 #include <KProtocolManager>
35 #include <KShell>
36 #include <kio_version.h>
37
38 #ifndef QT_NO_ACCESSIBILITY
39 #include <QAccessible>
40 #endif
41 #include <QApplication>
42 #include <QDesktopServices>
43 #include <QDropEvent>
44 #include <QGridLayout>
45 #include <QGuiApplication>
46 #include <QRegularExpression>
47 #include <QScrollBar>
48 #include <QStyle>
49 #include <QTimer>
50 #include <QUrl>
51 #include <QUrlQuery>
52
53 bool isSearchUrl(const QUrl &url)
54 {
55 return url.scheme().contains(QLatin1String("search"));
56 }
57
58 // An overview of the widgets contained by this ViewContainer
59 struct LayoutStructure {
60 int searchBar = 0;
61 int adminBar = 1;
62 int messageWidget = 2;
63 int selectionModeTopBar = 3;
64 int view = 4;
65 int selectionModeBottomBar = 5;
66 int filterBar = 6;
67 int statusBar = 7;
68 };
69 constexpr LayoutStructure positionFor;
70
71 DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
72 : QWidget(parent)
73 , m_topLayout(nullptr)
74 , m_urlNavigator{new DolphinUrlNavigator(url)}
75 , m_urlNavigatorConnected{nullptr}
76 , m_searchBar(nullptr)
77 , m_searchModeEnabled(false)
78 , m_adminBar{nullptr}
79 , m_authorizeToEnterFolderAction{nullptr}
80 , m_createFolderAction(nullptr)
81 , m_messageWidget(nullptr)
82 , m_selectionModeTopBar{nullptr}
83 , m_view(nullptr)
84 , m_filterBar(nullptr)
85 , m_selectionModeBottomBar{nullptr}
86 , m_statusBar(nullptr)
87 , m_statusBarTimer(nullptr)
88 , m_statusBarTimestamp()
89 , m_grabFocusOnUrlChange{true}
90 {
91 hide();
92
93 m_topLayout = new QGridLayout(this);
94 m_topLayout->setSpacing(0);
95 m_topLayout->setContentsMargins(0, 0, 0, 0);
96
97 m_messageWidget = new KMessageWidget(this);
98 m_messageWidget->setCloseButtonVisible(true);
99 m_messageWidget->setPosition(KMessageWidget::Header);
100 m_messageWidget->hide();
101
102 #if !defined(Q_OS_WIN) && !defined(Q_OS_HAIKU)
103 if (getuid() == 0) {
104 // We must be logged in as the root user; show a big scary warning
105 showMessage(i18n("Running Dolphin as root can be dangerous. Please be careful."), KMessageWidget::Warning);
106 }
107 #endif
108
109 // Initialize filter bar
110 m_filterBar = new FilterBar(this);
111 m_filterBar->setVisible(GeneralSettings::filterBar(), WithoutAnimation);
112
113 connect(m_filterBar, &FilterBar::filterChanged, this, &DolphinViewContainer::setNameFilter);
114 connect(m_filterBar, &FilterBar::closeRequest, this, &DolphinViewContainer::closeFilterBar);
115 connect(m_filterBar, &FilterBar::focusViewRequest, this, &DolphinViewContainer::requestFocus);
116
117 // Initialize the main view
118 m_view = new DolphinView(url, this);
119 connect(m_view, &DolphinView::urlChanged, m_filterBar, &FilterBar::clearIfUnlocked);
120 connect(m_view, &DolphinView::urlChanged, m_messageWidget, &KMessageWidget::hide);
121 // m_urlNavigator stays in sync with m_view's location changes and
122 // keeps track of them so going back and forth in the history works.
123 connect(m_view, &DolphinView::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
124 connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged, this, &DolphinViewContainer::slotUrlNavigatorLocationChanged);
125 connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlAboutToBeChanged, this, &DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged);
126 connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlSelectionRequested, this, &DolphinViewContainer::slotUrlSelectionRequested);
127 connect(m_view, &DolphinView::writeStateChanged, this, &DolphinViewContainer::writeStateChanged);
128 connect(m_view, &DolphinView::requestItemInfo, this, &DolphinViewContainer::showItemInfo);
129 connect(m_view, &DolphinView::itemActivated, this, &DolphinViewContainer::slotItemActivated);
130 connect(m_view, &DolphinView::fileMiddleClickActivated, this, &DolphinViewContainer::slotfileMiddleClickActivated);
131 connect(m_view, &DolphinView::itemsActivated, this, &DolphinViewContainer::slotItemsActivated);
132 connect(m_view, &DolphinView::redirection, this, &DolphinViewContainer::redirect);
133 connect(m_view, &DolphinView::directoryLoadingStarted, this, &DolphinViewContainer::slotDirectoryLoadingStarted);
134 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinViewContainer::slotDirectoryLoadingCompleted);
135 connect(m_view, &DolphinView::directoryLoadingCanceled, this, &DolphinViewContainer::slotDirectoryLoadingCanceled);
136 connect(m_view, &DolphinView::itemCountChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
137 connect(m_view, &DolphinView::selectionChanged, this, &DolphinViewContainer::delayedStatusBarUpdate);
138 connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::slotErrorMessageFromView);
139 connect(m_view, &DolphinView::urlIsFileError, this, &DolphinViewContainer::slotUrlIsFileError);
140 connect(m_view, &DolphinView::activated, this, &DolphinViewContainer::activate);
141 connect(m_view, &DolphinView::hiddenFilesShownChanged, this, &DolphinViewContainer::slotHiddenFilesShownChanged);
142 connect(m_view, &DolphinView::sortHiddenLastChanged, this, &DolphinViewContainer::slotSortHiddenLastChanged);
143 connect(m_view, &DolphinView::currentDirectoryRemoved, this, &DolphinViewContainer::slotCurrentDirectoryRemoved);
144
145 // Initialize status bar
146 m_statusBar = new DolphinStatusBar(this);
147 m_statusBar->setUrl(m_view->url());
148 m_statusBar->setZoomLevel(m_view->zoomLevel());
149 connect(m_view, &DolphinView::urlChanged, m_statusBar, &DolphinStatusBar::setUrl);
150 connect(m_view, &DolphinView::zoomLevelChanged, m_statusBar, &DolphinStatusBar::setZoomLevel);
151 connect(m_view, &DolphinView::infoMessage, m_statusBar, &DolphinStatusBar::setText);
152 connect(m_view, &DolphinView::operationCompletedMessage, m_statusBar, &DolphinStatusBar::setText);
153 connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::setDefaultText);
154 connect(m_view, &DolphinView::statusBarTextChanged, m_statusBar, &DolphinStatusBar::resetToDefaultText);
155 connect(m_view, &DolphinView::directoryLoadingProgress, m_statusBar, [this](int percent) {
156 m_statusBar->showProgress(i18nc("@info:progress", "Loading folder…"), percent);
157 });
158 connect(m_view, &DolphinView::directorySortingProgress, m_statusBar, [this](int percent) {
159 m_statusBar->showProgress(i18nc("@info:progress", "Sorting…"), percent);
160 });
161 connect(m_statusBar, &DolphinStatusBar::stopPressed, this, &DolphinViewContainer::stopDirectoryLoading);
162 connect(m_statusBar, &DolphinStatusBar::zoomLevelChanged, this, &DolphinViewContainer::slotStatusBarZoomLevelChanged);
163 connect(m_statusBar, &DolphinStatusBar::showMessage, this, [this](const QString &message, KMessageWidget::MessageType messageType) {
164 showMessage(message, messageType);
165 });
166 connect(m_statusBar, &DolphinStatusBar::widthUpdated, this, &DolphinViewContainer::updateStatusBarGeometry);
167 connect(m_statusBar, &DolphinStatusBar::urlChanged, this, &DolphinViewContainer::updateStatusBar);
168 connect(this, &DolphinViewContainer::showFilterBarChanged, this, &DolphinViewContainer::updateStatusBar);
169
170 m_statusBarTimer = new QTimer(this);
171 m_statusBarTimer->setSingleShot(true);
172 m_statusBarTimer->setInterval(300);
173 connect(m_statusBarTimer, &QTimer::timeout, this, &DolphinViewContainer::updateStatusBar);
174
175 KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self();
176 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished, this, &DolphinViewContainer::delayedStatusBarUpdate);
177
178 m_topLayout->addWidget(m_messageWidget, positionFor.messageWidget, 0);
179 m_topLayout->addWidget(m_view, positionFor.view, 0);
180 m_topLayout->addWidget(m_filterBar, positionFor.filterBar, 0);
181 if (GeneralSettings::showStatusBar() == GeneralSettings::EnumShowStatusBar::FullWidth) {
182 m_topLayout->addWidget(m_statusBar, positionFor.statusBar, 0);
183 }
184 connect(m_statusBar, &DolphinStatusBar::modeUpdated, this, [this]() {
185 const bool statusBarInLayout = m_topLayout->itemAtPosition(positionFor.statusBar, 0);
186 if (GeneralSettings::showStatusBar() == GeneralSettings::EnumShowStatusBar::FullWidth) {
187 if (!statusBarInLayout) {
188 m_topLayout->addWidget(m_statusBar, positionFor.statusBar, 0);
189 m_statusBar->setUrl(m_view->url());
190 }
191 } else {
192 if (statusBarInLayout) {
193 m_topLayout->removeWidget(m_statusBar);
194 }
195 }
196 updateStatusBarGeometry();
197 });
198 m_statusBar->setHidden(false);
199
200 setSearchBarVisible(isSearchUrl(url));
201
202 // Update view as the ContentDisplaySettings change
203 // this happens here and not in DolphinView as DolphinviewContainer and DolphinView are not in the same build target ATM
204 connect(ContentDisplaySettings::self(), &KCoreConfigSkeleton::configChanged, m_view, &DolphinView::reload);
205
206 KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
207 connect(placesModel, &KFilePlacesModel::dataChanged, this, &DolphinViewContainer::slotPlacesModelChanged);
208 connect(placesModel, &KFilePlacesModel::rowsInserted, this, &DolphinViewContainer::slotPlacesModelChanged);
209 connect(placesModel, &KFilePlacesModel::rowsRemoved, this, &DolphinViewContainer::slotPlacesModelChanged);
210
211 QApplication::instance()->installEventFilter(this);
212 }
213
214 DolphinViewContainer::~DolphinViewContainer()
215 {
216 }
217
218 QUrl DolphinViewContainer::url() const
219 {
220 return m_view->url();
221 }
222
223 KFileItem DolphinViewContainer::rootItem() const
224 {
225 return m_view->rootItem();
226 }
227
228 void DolphinViewContainer::setActive(bool active)
229 {
230 if (m_urlNavigatorConnected) {
231 m_urlNavigatorConnected->setActive(active);
232 }
233 m_view->setActive(active);
234 }
235
236 bool DolphinViewContainer::isActive() const
237 {
238 return m_view->isActive();
239 }
240
241 void DolphinViewContainer::setGrabFocusOnUrlChange(bool grabFocus)
242 {
243 m_grabFocusOnUrlChange = grabFocus;
244 }
245
246 const DolphinStatusBar *DolphinViewContainer::statusBar() const
247 {
248 return m_statusBar;
249 }
250
251 DolphinStatusBar *DolphinViewContainer::statusBar()
252 {
253 return m_statusBar;
254 }
255
256 const DolphinUrlNavigator *DolphinViewContainer::urlNavigator() const
257 {
258 return m_urlNavigatorConnected;
259 }
260
261 DolphinUrlNavigator *DolphinViewContainer::urlNavigator()
262 {
263 return m_urlNavigatorConnected;
264 }
265
266 const DolphinUrlNavigator *DolphinViewContainer::urlNavigatorInternalWithHistory() const
267 {
268 return m_urlNavigator.get();
269 }
270
271 DolphinUrlNavigator *DolphinViewContainer::urlNavigatorInternalWithHistory()
272 {
273 return m_urlNavigator.get();
274 }
275
276 const DolphinView *DolphinViewContainer::view() const
277 {
278 return m_view;
279 }
280
281 DolphinView *DolphinViewContainer::view()
282 {
283 return m_view;
284 }
285
286 void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator)
287 {
288 Q_CHECK_PTR(urlNavigator);
289 Q_ASSERT(!m_urlNavigatorConnected);
290 Q_ASSERT(m_urlNavigator.get() != urlNavigator);
291 Q_CHECK_PTR(m_view);
292
293 urlNavigator->setLocationUrl(m_view->url());
294 urlNavigator->setShowHiddenFolders(m_view->hiddenFilesShown());
295 urlNavigator->setSortHiddenFoldersLast(m_view->sortHiddenLast());
296 if (m_urlNavigatorVisualState) {
297 urlNavigator->setVisualState(*m_urlNavigatorVisualState.get());
298 m_urlNavigatorVisualState.reset();
299 }
300 urlNavigator->setActive(isActive());
301
302 // Url changes are still done via m_urlNavigator.
303 connect(urlNavigator, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
304 connect(urlNavigator, &DolphinUrlNavigator::urlsDropped, this, [=, this](const QUrl &destination, QDropEvent *event) {
305 m_view->dropUrls(destination, event, urlNavigator->dropWidget());
306 });
307 // Aside from these, only visual things need to be connected.
308 connect(m_view, &DolphinView::urlChanged, urlNavigator, &DolphinUrlNavigator::setLocationUrl);
309 connect(urlNavigator, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
310 connect(urlNavigator, &DolphinUrlNavigator::requestToLoseFocus, m_view, [this]() {
311 m_view->setFocus();
312 });
313
314 urlNavigator->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable());
315
316 m_urlNavigatorConnected = urlNavigator;
317 }
318
319 void DolphinViewContainer::disconnectUrlNavigator()
320 {
321 if (!m_urlNavigatorConnected) {
322 return;
323 }
324
325 disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
326 disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlsDropped, this, nullptr);
327 disconnect(m_view, &DolphinView::urlChanged, m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl);
328 disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
329 disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::requestToLoseFocus, m_view, nullptr);
330
331 m_urlNavigatorVisualState = m_urlNavigatorConnected->visualState();
332 m_urlNavigatorConnected = nullptr;
333 }
334
335 void DolphinViewContainer::setSearchBarVisible(bool visible)
336 {
337 if (!visible) {
338 if (isSearchBarVisible()) {
339 m_searchBar->setVisible(false, WithAnimation);
340 }
341 return;
342 }
343
344 if (!m_searchBar) {
345 m_searchBar = new Search::Bar(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), QUrl{} /** will be set below. */), this);
346 connect(m_searchBar, &Search::Bar::urlChangeRequested, this, [this](const QUrl &url) {
347 m_view->setViewPropertiesContext(isSearchUrl(url) ? QStringLiteral("search") : QString());
348 setGrabFocusOnUrlChange(false); // Prevent loss of focus while typing or refining a search.
349 setUrl(url);
350 setGrabFocusOnUrlChange(true);
351 });
352 connect(m_searchBar, &Search::Bar::focusViewRequest, this, &DolphinViewContainer::requestFocus);
353 connect(m_searchBar, &Search::Bar::showMessage, this, [this](const QString &message, KMessageWidget::MessageType messageType) {
354 showMessage(message, messageType);
355 });
356 connect(m_searchBar,
357 &Search::Bar::showInstallationProgress,
358 m_statusBar,
359 [this](const QString &currentlyRunningTaskTitle, int installationProgressPercent) {
360 m_statusBar->showProgress(currentlyRunningTaskTitle, installationProgressPercent, DolphinStatusBar::CancelLoading::Disallowed);
361 });
362 connect(m_searchBar, &Search::Bar::visibilityChanged, this, &DolphinViewContainer::searchBarVisibilityChanged);
363 m_topLayout->addWidget(m_searchBar, positionFor.searchBar, 0);
364 }
365
366 m_searchBar->setVisible(true, WithAnimation);
367
368 // The Search::Bar has been set visible but its state does not yet match with this view container or view.
369 // The view might for example already be searching because it was opened with a search URL. The Search::Bar needs to be updated to show the parameters of
370 // that search. And even if there is no search URL loaded in the view currently, we still need to figure out where the Search::Bar should be searching if
371 // the user starts a search from there. Let's figure out the search location in this method and let the DolphinQuery constructor figure out the rest from
372 // the current m_urlNavigator->locationUrl().
373 for (int i = m_urlNavigator->historyIndex(); i < m_urlNavigator->historySize(); i++) {
374 QUrl url = m_urlNavigator->locationUrl(i);
375 if (isSearchUrl(url)) {
376 // The previous location was a search URL. Try to see if that search URL has a valid search path so we keep searching in the same location.
377 const auto searchPath = Search::DolphinQuery(url, QUrl{}).searchPath(); // DolphinQuery is great at extracting the search path from a search URL.
378 if (searchPath.isValid()) {
379 m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), searchPath));
380 return;
381 }
382 } else if (url.scheme() == QLatin1String("tags")) {
383 continue; // We avoid setting a tags url as the backup search path because a DolphinQuery constructed from a tags url will already search tagged
384 // items everywhere.
385 } else {
386 m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), url));
387 return;
388 }
389 }
390 // We could not find any URL fit for searching in the history. This might happen because this view only ever loaded a search which searches "Everywhere"
391 // and therefore there is no specific search path to choose from. But the Search::Bar *needs* to know a search path because the user might switch from
392 // searching "Everywhere" to "Here" and it is everybody's guess what "Here" is supposed to mean in that context… We'll simply fall back to the user's home
393 // path for lack of a better option.
394 m_searchBar->updateStateToMatch(std::make_shared<const Search::DolphinQuery>(m_urlNavigator->locationUrl(), QUrl::fromUserInput(QDir::homePath())));
395 }
396
397 bool DolphinViewContainer::isSearchBarVisible() const
398 {
399 return m_searchBar && m_searchBar->isVisible() && m_searchBar->isEnabled();
400 }
401
402 void DolphinViewContainer::setFocusToSearchBar()
403 {
404 Q_ASSERT(isSearchBarVisible());
405 m_searchBar->selectAll();
406 }
407
408 void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)
409 {
410 const bool wasEnabled = m_view->selectionMode();
411 m_view->setSelectionModeEnabled(enabled);
412
413 if (!enabled) {
414 if (!wasEnabled) {
415 return; // nothing to do here
416 }
417 Q_CHECK_PTR(m_selectionModeTopBar); // there is no point in disabling selectionMode when it wasn't even enabled once.
418 Q_CHECK_PTR(m_selectionModeBottomBar);
419 m_selectionModeTopBar->setVisible(false, WithAnimation);
420 m_selectionModeBottomBar->setVisible(false, WithAnimation);
421 Q_EMIT selectionModeChanged(false);
422
423 if (!QApplication::focusWidget() || m_selectionModeTopBar->isAncestorOf(QApplication::focusWidget())
424 || m_selectionModeBottomBar->isAncestorOf(QApplication::focusWidget())) {
425 m_view->setFocus();
426 }
427 return;
428 }
429
430 if (!m_selectionModeTopBar) {
431 // Changing the location will disable selection mode.
432 connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged, this, [this]() {
433 setSelectionModeEnabled(false);
434 });
435
436 m_selectionModeTopBar = new SelectionMode::TopBar(this); // will be created hidden
437 connect(m_selectionModeTopBar, &SelectionMode::TopBar::selectionModeLeavingRequested, this, [this]() {
438 setSelectionModeEnabled(false);
439 });
440 m_topLayout->addWidget(m_selectionModeTopBar, positionFor.selectionModeTopBar, 0);
441 }
442
443 if (!m_selectionModeBottomBar) {
444 m_selectionModeBottomBar = new SelectionMode::BottomBar(actionCollection, this);
445 connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
446 m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
447 });
448 connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, &DolphinViewContainer::showErrorMessage);
449 connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
450 setSelectionModeEnabled(false);
451 });
452 m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
453 }
454 m_selectionModeBottomBar->resetContents(bottomBarContents);
455 if (bottomBarContents == SelectionMode::BottomBar::GeneralContents) {
456 m_selectionModeBottomBar->slotSelectionChanged(m_view->selectedItems(), m_view->url());
457 }
458
459 if (!wasEnabled) {
460 m_selectionModeTopBar->setVisible(true, WithAnimation);
461 m_selectionModeBottomBar->setVisible(true, WithAnimation);
462 Q_EMIT selectionModeChanged(true);
463 }
464 }
465
466 bool DolphinViewContainer::isSelectionModeEnabled() const
467 {
468 const bool isEnabled = m_view->selectionMode();
469 Q_ASSERT((!isEnabled
470 // We can't assert that the bars are invisible only because the selection mode is disabled because the hide animation might still be playing.
471 && (!m_selectionModeBottomBar || !m_selectionModeBottomBar->isEnabled() || !m_selectionModeBottomBar->isVisible()
472 || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::PasteContents))
473 || (isEnabled && m_selectionModeTopBar
474 && m_selectionModeTopBar->isVisible()
475 // The bottom bar is either visible or was hidden because it has nothing to show in GeneralContents mode e.g. because no items are selected.
476 && m_selectionModeBottomBar
477 && (m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::GeneralContents)));
478 return isEnabled;
479 }
480
481 void DolphinViewContainer::slotSplitTabDisabled()
482 {
483 if (m_selectionModeBottomBar) {
484 m_selectionModeBottomBar->slotSplitTabDisabled();
485 }
486 }
487
488 void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::MessageType messageType, std::initializer_list<QAction *> buttonActions)
489 {
490 if (message.isEmpty()) {
491 return;
492 }
493
494 m_messageWidget->setText(message);
495
496 // TODO: wrap at arbitrary character positions once QLabel can do this
497 // https://bugreports.qt.io/browse/QTBUG-1276
498 m_messageWidget->setWordWrap(true);
499 m_messageWidget->setMessageType(messageType);
500
501 const QList<QAction *> previousMessageWidgetActions = m_messageWidget->actions();
502 for (auto action : previousMessageWidgetActions) {
503 m_messageWidget->removeAction(action);
504 }
505 for (QAction *action : buttonActions) {
506 m_messageWidget->addAction(action);
507 }
508
509 m_messageWidget->setWordWrap(false);
510 const int unwrappedWidth = m_messageWidget->sizeHint().width();
511 m_messageWidget->setWordWrap(unwrappedWidth > size().width());
512
513 if (m_messageWidget->isVisible()) {
514 m_messageWidget->hide();
515 }
516 m_messageWidget->animatedShow();
517
518 #ifndef QT_NO_ACCESSIBILITY
519 if (QAccessible::isActive() && isActive()) {
520 // To announce the new message keyboard focus must be moved to the message label. However, we do not have direct access to the label that is internal
521 // to the KMessageWidget. Instead we setFocus() on the KMessageWidget and trust that it has set correct focus handling.
522 m_messageWidget->setFocus();
523 }
524 #endif
525 }
526
527 void DolphinViewContainer::showProgress(const QString &currentlyRunningTaskTitle, int progressPercent)
528 {
529 m_statusBar->showProgress(currentlyRunningTaskTitle, progressPercent, DolphinStatusBar::CancelLoading::Disallowed);
530 }
531
532 void DolphinViewContainer::readSettings()
533 {
534 // The startup settings should (only) get applied if they have been
535 // modified by the user. Otherwise keep the (possibly) different current
536 // setting of the filterbar.
537 if (GeneralSettings::modifiedStartupSettings()) {
538 setFilterBarVisible(GeneralSettings::filterBar());
539 }
540
541 m_view->readSettings();
542 m_statusBar->readSettings();
543 }
544
545 bool DolphinViewContainer::isFilterBarVisible() const
546 {
547 return m_filterBar->isEnabled(); // Gets disabled in AnimatedHeightWidget while animating towards a hidden state.
548 }
549
550 QString DolphinViewContainer::placesText() const
551 {
552 QString text;
553
554 if (isSearchBarVisible() && m_searchBar->isSearchConfigured()) {
555 text = m_searchBar->queryTitle();
556 } else {
557 text = url().adjusted(QUrl::StripTrailingSlash).fileName();
558 if (text.isEmpty()) {
559 text = url().host();
560 }
561 if (text.isEmpty()) {
562 text = url().scheme();
563 }
564 }
565
566 return text;
567 }
568
569 void DolphinViewContainer::reload()
570 {
571 view()->reload();
572 m_messageWidget->hide();
573 }
574
575 QString DolphinViewContainer::captionWindowTitle() const
576 {
577 if (GeneralSettings::showFullPathInTitlebar() && (!isSearchBarVisible() || !m_searchBar->isSearchConfigured())) {
578 if (!url().isLocalFile()) {
579 return url().adjusted(QUrl::StripTrailingSlash).toString();
580 }
581 return url().adjusted(QUrl::StripTrailingSlash).path();
582 } else {
583 return DolphinViewContainer::caption();
584 }
585 }
586
587 QString DolphinViewContainer::caption() const
588 {
589 // see KUrlNavigatorPrivate::firstButtonText().
590 if (url().path().isEmpty() || url().path() == QLatin1Char('/')) {
591 QUrlQuery query(url());
592 const QString title = query.queryItemValue(QStringLiteral("title"), QUrl::FullyDecoded);
593 if (!title.isEmpty()) {
594 return title;
595 }
596 }
597
598 if (isSearchBarVisible() && m_searchBar->isSearchConfigured()) {
599 return m_searchBar->queryTitle();
600 }
601
602 KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
603
604 QModelIndex url_index = placesModel->closestItem(url());
605
606 if (url_index.isValid() && placesModel->url(url_index).matches(url(), QUrl::StripTrailingSlash)) {
607 return placesModel->text(url_index);
608 }
609
610 if (!url().isLocalFile()) {
611 QUrl adjustedUrl = url().adjusted(QUrl::StripTrailingSlash);
612 QString caption;
613 if (!adjustedUrl.fileName().isEmpty()) {
614 caption = adjustedUrl.fileName();
615 } else if (!adjustedUrl.path().isEmpty() && adjustedUrl.path() != "/") {
616 caption = adjustedUrl.path();
617 } else if (!adjustedUrl.host().isEmpty()) {
618 caption = adjustedUrl.host();
619 } else {
620 caption = adjustedUrl.toString();
621 }
622 return caption;
623 }
624
625 QString fileName = url().adjusted(QUrl::StripTrailingSlash).fileName();
626 if (fileName.isEmpty()) {
627 fileName = '/';
628 }
629
630 return fileName;
631 }
632
633 void DolphinViewContainer::setUrl(const QUrl &newUrl)
634 {
635 if (newUrl != m_urlNavigator->locationUrl()) {
636 m_urlNavigator->setLocationUrl(newUrl);
637 if (m_searchBar && !Search::isSupportedSearchScheme(newUrl.scheme())) {
638 m_searchBar->setSearchPath(newUrl);
639 }
640 }
641 }
642
643 void DolphinViewContainer::setFilterBarVisible(bool visible)
644 {
645 Q_ASSERT(m_filterBar);
646 if (visible) {
647 m_view->hideToolTip(ToolTipManager::HideBehavior::Instantly);
648 m_filterBar->setVisible(true, WithAnimation);
649 m_filterBar->setFocus();
650 m_filterBar->selectAll();
651 Q_EMIT showFilterBarChanged(true);
652 } else {
653 closeFilterBar();
654 }
655 }
656
657 void DolphinViewContainer::delayedStatusBarUpdate()
658 {
659 if (m_statusBarTimer->isActive() && (m_statusBarTimestamp.elapsed() > 2000)) {
660 // No update of the statusbar has been done during the last 2 seconds,
661 // although an update has been requested. Trigger an immediate update.
662 m_statusBarTimer->stop();
663 updateStatusBar();
664 } else {
665 // Invoke updateStatusBar() with a small delay. This assures that
666 // when a lot of delayedStatusBarUpdates() are done in a short time,
667 // no bottleneck is given.
668 m_statusBarTimer->start();
669 }
670 }
671
672 void DolphinViewContainer::updateStatusBar()
673 {
674 m_statusBarTimestamp.start();
675 m_view->requestStatusBarText();
676 updateStatusBarGeometry();
677 }
678
679 void DolphinViewContainer::slotDirectoryLoadingStarted()
680 {
681 if (isSearchUrl(url())) {
682 // Search KIO-slaves usually don't provide any progress information. Give
683 // a hint to the user that a searching is done:
684 updateStatusBar();
685 m_statusBar->showProgress(i18nc("@info", "Searching…"), -1);
686 } else {
687 // Trigger an undetermined progress indication. The progress
688 // information in percent will be triggered by the percent() signal
689 // of the directory lister later.
690 m_statusBar->showProgress(QString(), -1);
691 }
692
693 if (m_urlNavigatorConnected) {
694 m_urlNavigatorConnected->setReadOnlyBadgeVisible(false);
695 }
696 }
697
698 void DolphinViewContainer::slotDirectoryLoadingCompleted()
699 {
700 m_statusBar->showProgress(QString(), 100);
701
702 if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
703 // The dir lister has been completed on a Baloo-URI and no items have been found. Instead
704 // of showing the default status bar information ("0 items") a more helpful information is given:
705 m_statusBar->setText(i18nc("@info:status", "No items found."));
706 } else {
707 updateStatusBar();
708 }
709
710 if (m_urlNavigatorConnected) {
711 m_urlNavigatorConnected->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable());
712 }
713
714 // Update admin bar visibility
715 if (m_view->url().scheme() == QStringLiteral("admin")) {
716 if (!m_adminBar) {
717 m_adminBar = new Admin::Bar(this);
718 m_topLayout->addWidget(m_adminBar, positionFor.adminBar, 0);
719 }
720 m_adminBar->setVisible(true, WithAnimation);
721 } else if (m_adminBar) {
722 m_adminBar->setVisible(false, WithAnimation);
723 }
724 }
725
726 void DolphinViewContainer::slotDirectoryLoadingCanceled()
727 {
728 m_statusBar->showProgress(QString(), 100);
729 m_statusBar->setText(QString());
730 }
731
732 void DolphinViewContainer::slotUrlIsFileError(const QUrl &url)
733 {
734 const KFileItem item(url);
735
736 // Find out if the file can be opened in the view (for example, this is the
737 // case if the file is an archive). The mime type must be known for that.
738 item.determineMimeType();
739 const QUrl &folderUrl = DolphinView::openItemAsFolderUrl(item, true);
740 if (!folderUrl.isEmpty()) {
741 setUrl(folderUrl);
742 } else {
743 slotItemActivated(item);
744 }
745 }
746
747 void DolphinViewContainer::slotItemActivated(const KFileItem &item)
748 {
749 // It is possible to activate items on inactive views by
750 // drag & drop operations. Assure that activating an item always
751 // results in an active view.
752 m_view->setActive(true);
753
754 const QUrl &url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
755 if (!url.isEmpty()) {
756 const auto modifiers = QGuiApplication::keyboardModifiers();
757 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
758 if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier) {
759 Q_EMIT activeTabRequested(url);
760 } else if (modifiers & Qt::ControlModifier) {
761 Q_EMIT tabRequested(url);
762 } else if (modifiers & Qt::ShiftModifier) {
763 Dolphin::openNewWindow({KFilePlacesModel::convertedUrl(url)}, this);
764 } else {
765 setUrl(url);
766 }
767 return;
768 }
769
770 KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl(), item.mimetype());
771 // Auto*Warning*Handling, errors are put in a KMessageWidget by us in slotOpenUrlFinished.
772 job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled, this));
773 job->setShowOpenOrExecuteDialog(true);
774 connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
775 job->start();
776 }
777
778 void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item)
779 {
780 KService::List services = KApplicationTrader::queryByMimeType(item.mimetype());
781
782 int indexOfAppToOpenFileWith = 1;
783
784 // executable scripts
785 auto mimeType = item.currentMimeType();
786 if (item.isLocalFile() && mimeType.inherits(QStringLiteral("application/x-executable")) && mimeType.inherits(QStringLiteral("text/plain"))
787 && QFileInfo(item.localPath()).isExecutable()) {
788 KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), QStringLiteral("Executable scripts"));
789 const QString value = cfgGroup.readEntry("behaviourOnLaunch", "alwaysAsk");
790
791 // in case KIO::WidgetsOpenOrExecuteFileHandler::promptUserOpenOrExecute would not open the file
792 if (value != QLatin1String("open")) {
793 indexOfAppToOpenFileWith = 0;
794 }
795 }
796
797 if (services.length() >= indexOfAppToOpenFileWith + 1) {
798 auto service = services.at(indexOfAppToOpenFileWith);
799
800 KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this);
801 job->setUrls({item.url()});
802
803 job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
804 connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
805 job->start();
806 } else {
807 // If no 2nd service available, try to open archives in new tabs, regardless of the "Open archives as folder" setting.
808 const QUrl &url = DolphinView::openItemAsFolderUrl(item);
809 const auto modifiers = QGuiApplication::keyboardModifiers();
810 if (!url.isEmpty()) {
811 // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
812 if (modifiers & Qt::ShiftModifier) {
813 Q_EMIT activeTabRequested(url);
814 } else {
815 Q_EMIT tabRequested(url);
816 }
817 }
818 }
819 }
820
821 void DolphinViewContainer::slotItemsActivated(const KFileItemList &items)
822 {
823 Q_ASSERT(items.count() >= 2);
824
825 KFileItemActions fileItemActions(this);
826 fileItemActions.runPreferredApplications(items);
827 }
828
829 void DolphinViewContainer::showItemInfo(const KFileItem &item)
830 {
831 if (item.isNull()) {
832 m_statusBar->resetToDefaultText();
833 } else {
834 m_statusBar->setText(item.getStatusBarInfo());
835 }
836 }
837
838 void DolphinViewContainer::closeFilterBar()
839 {
840 m_filterBar->closeFilterBar();
841 m_view->setFocus();
842 Q_EMIT showFilterBarChanged(false);
843 }
844
845 void DolphinViewContainer::clearFilterBar()
846 {
847 m_filterBar->clearIfUnlocked();
848 }
849
850 void DolphinViewContainer::setNameFilter(const QString &nameFilter)
851 {
852 m_view->hideToolTip(ToolTipManager::HideBehavior::Instantly);
853 m_view->setNameFilter(nameFilter);
854 delayedStatusBarUpdate();
855 }
856
857 void DolphinViewContainer::activate()
858 {
859 setActive(true);
860 }
861
862 void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const QUrl &)
863 {
864 saveViewState();
865 }
866
867 void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl &url)
868 {
869 if (m_urlNavigatorConnected) {
870 m_urlNavigatorConnected->slotReturnPressed();
871 }
872
873 if (KProtocolManager::supportsListing(url)) {
874 if (isSearchUrl(url)) {
875 setSearchBarVisible(true);
876 } else if (m_searchBar && m_searchBar->isSearchConfigured()) {
877 // Hide the search bar because it shows an outdated search which the user does not care about anymore.
878 setSearchBarVisible(false);
879 }
880
881 m_view->setUrl(url);
882 tryRestoreViewState();
883
884 if (m_grabFocusOnUrlChange && isActive()) {
885 // When an URL has been entered, the view should get the focus.
886 // The focus must be requested asynchronously, as changing the URL might create
887 // a new view widget.
888 QTimer::singleShot(0, this, &DolphinViewContainer::requestFocus);
889 }
890 } else if (KProtocolManager::isSourceProtocol(url)) {
891 if (url.scheme().startsWith(QLatin1String("http"))) {
892 showMessage(i18nc("@info:status", // krazy:exclude=qmethods
893 "Dolphin does not support web pages, the web browser has been launched"),
894 KMessageWidget::Information);
895 } else {
896 showMessage(i18nc("@info:status", "Protocol not supported by Dolphin, default application has been launched"), KMessageWidget::Information);
897 }
898
899 QDesktopServices::openUrl(url);
900 redirect(QUrl(), m_urlNavigator->locationUrl(1));
901 } else {
902 if (!url.scheme().isEmpty()) {
903 showMessage(i18nc("@info:status", "Invalid protocol '%1'", url.scheme()), KMessageWidget::Error);
904 } else {
905 showMessage(i18nc("@info:status", "Invalid protocol"), KMessageWidget::Error);
906 }
907 m_urlNavigator->goBack();
908 }
909 }
910
911 void DolphinViewContainer::slotUrlSelectionRequested(const QUrl &url)
912 {
913 // 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
914
915 m_view->markUrlAsCurrent(url); // makes the item scroll into view
916 }
917
918 void DolphinViewContainer::disableUrlNavigatorSelectionRequests()
919 {
920 disconnect(m_urlNavigator.get(), &KUrlNavigator::urlSelectionRequested, this, &DolphinViewContainer::slotUrlSelectionRequested);
921 }
922
923 void DolphinViewContainer::enableUrlNavigatorSelectionRequests()
924 {
925 connect(m_urlNavigator.get(), &KUrlNavigator::urlSelectionRequested, this, &DolphinViewContainer::slotUrlSelectionRequested);
926 }
927
928 void DolphinViewContainer::redirect(const QUrl &oldUrl, const QUrl &newUrl)
929 {
930 Q_UNUSED(oldUrl)
931 const bool block = m_urlNavigator->signalsBlocked();
932 m_urlNavigator->blockSignals(true);
933
934 // Assure that the location state is reset for redirection URLs. This
935 // allows to skip redirection URLs when going back or forward in the
936 // URL history.
937 m_urlNavigator->saveLocationState(QByteArray());
938 m_urlNavigator->setLocationUrl(newUrl);
939 setSearchBarVisible(isSearchUrl(newUrl));
940
941 m_urlNavigator->blockSignals(block);
942 }
943
944 void DolphinViewContainer::requestFocus()
945 {
946 m_view->setFocus();
947 }
948
949 void DolphinViewContainer::stopDirectoryLoading()
950 {
951 m_view->stopLoading();
952 m_statusBar->showProgress(QString(), 100);
953 }
954
955 void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
956 {
957 m_view->setZoomLevel(zoomLevel);
958 }
959
960 void DolphinViewContainer::slotErrorMessageFromView(const QString &message, const int kioErrorCode)
961 {
962 if (kioErrorCode == KIO::ERR_CANNOT_ENTER_DIRECTORY && m_view->url().scheme() == QStringLiteral("file")
963 && KProtocolInfo::isKnownProtocol(QStringLiteral("admin")) && !rootItem().isReadable()) {
964 // Explain to users that they need authentication to see the folder contents.
965 if (!m_authorizeToEnterFolderAction) { // This code is similar to parts of Admin::Bar::hideTheNextTimeAuthorizationExpires().
966 // We should not simply use the actAsAdminAction() itself here because that one always refers to the active view instead of this->m_view.
967 auto actAsAdminAction = Admin::WorkerIntegration::FriendAccess::actAsAdminAction();
968 m_authorizeToEnterFolderAction = new QAction{actAsAdminAction->icon(), actAsAdminAction->text(), this};
969 m_authorizeToEnterFolderAction->setToolTip(actAsAdminAction->toolTip());
970 m_authorizeToEnterFolderAction->setWhatsThis(actAsAdminAction->whatsThis());
971 connect(m_authorizeToEnterFolderAction, &QAction::triggered, this, [this, actAsAdminAction]() {
972 setActive(true);
973 actAsAdminAction->trigger();
974 });
975 }
976 showMessage(i18nc("@info", "Authorization required to enter this folder."), KMessageWidget::Error, {m_authorizeToEnterFolderAction});
977 return;
978 } else if (kioErrorCode == KIO::ERR_DOES_NOT_EXIST && m_view->url().isLocalFile()) {
979 if (!m_createFolderAction) {
980 m_createFolderAction = new QAction(this);
981 m_createFolderAction->setText(i18nc("@action", "Create missing folder"));
982 m_createFolderAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
983 m_createFolderAction->setToolTip(i18nc("@info:tooltip", "Create the folder at this path and open it"));
984 connect(m_createFolderAction, &QAction::triggered, this, [this](bool) {
985 KIO::MkpathJob *job = KIO::mkpath(m_view->url());
986 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Mkpath, {}, m_view->url(), job);
987 connect(job, &KJob::result, this, [this](KJob *job) {
988 if (job->error()) {
989 showErrorMessage(job->errorString());
990 } else {
991 m_view->reload();
992 m_messageWidget->animatedHide();
993 }
994 });
995 });
996 }
997 showMessage(message, KMessageWidget::Error, {m_createFolderAction});
998 return;
999 }
1000 Q_EMIT showErrorMessage(message);
1001 }
1002
1003 void DolphinViewContainer::showErrorMessage(const QString &message)
1004 {
1005 showMessage(message, KMessageWidget::Error);
1006 }
1007
1008 void DolphinViewContainer::slotPlacesModelChanged()
1009 {
1010 if (!GeneralSettings::showFullPathInTitlebar()) {
1011 Q_EMIT captionChanged();
1012 }
1013 }
1014
1015 void DolphinViewContainer::slotHiddenFilesShownChanged(bool showHiddenFiles)
1016 {
1017 if (m_urlNavigatorConnected) {
1018 m_urlNavigatorConnected->setShowHiddenFolders(showHiddenFiles);
1019 }
1020 }
1021
1022 void DolphinViewContainer::slotSortHiddenLastChanged(bool hiddenLast)
1023 {
1024 if (m_urlNavigatorConnected) {
1025 m_urlNavigatorConnected->setSortHiddenFoldersLast(hiddenLast);
1026 }
1027 }
1028
1029 void DolphinViewContainer::slotCurrentDirectoryRemoved()
1030 {
1031 const QString location(url().toDisplayString(QUrl::PreferLocalFile));
1032 if (url().isLocalFile()) {
1033 const QString dirPath = url().toLocalFile();
1034 const QString newPath = getNearestExistingAncestorOfPath(dirPath);
1035 const QUrl newUrl = QUrl::fromLocalFile(newPath);
1036 // #473377: Delay changing the url to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns.
1037 QTimer::singleShot(0, this, [&, newUrl, location] {
1038 setUrl(newUrl);
1039 showMessage(xi18n("Current location changed, <filename>%1</filename> is no longer accessible.", location), KMessageWidget::Warning);
1040 });
1041 } else
1042 showMessage(xi18n("Current location changed, <filename>%1</filename> is no longer accessible.", location), KMessageWidget::Warning);
1043 }
1044
1045 void DolphinViewContainer::slotOpenUrlFinished(KJob *job)
1046 {
1047 if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
1048 showErrorMessage(job->errorString());
1049 }
1050 }
1051
1052 void DolphinViewContainer::saveViewState()
1053 {
1054 QByteArray locationState;
1055 QDataStream stream(&locationState, QIODevice::WriteOnly);
1056 m_view->saveState(stream);
1057 m_urlNavigator->saveLocationState(locationState);
1058 }
1059
1060 void DolphinViewContainer::tryRestoreViewState()
1061 {
1062 QByteArray locationState = m_urlNavigator->locationState();
1063 if (!locationState.isEmpty()) {
1064 QDataStream stream(&locationState, QIODevice::ReadOnly);
1065 m_view->restoreState(stream);
1066 }
1067 }
1068
1069 QString DolphinViewContainer::getNearestExistingAncestorOfPath(const QString &path) const
1070 {
1071 QDir dir(path);
1072 do {
1073 dir.setPath(QDir::cleanPath(dir.filePath(QStringLiteral(".."))));
1074 } while (!dir.exists() && !dir.isRoot());
1075
1076 return dir.exists() ? dir.path() : QString{};
1077 }
1078
1079 void DolphinViewContainer::updateStatusBarGeometry()
1080 {
1081 if (!m_statusBar) {
1082 return;
1083 }
1084 if (GeneralSettings::showStatusBar() == GeneralSettings::EnumShowStatusBar::Small) {
1085 QRect statusBarRect(preferredSmallStatusBarGeometry());
1086 if (view()->layoutDirection() == Qt::RightToLeft) {
1087 const int splitterWidth = m_statusBar->clippingAmount();
1088 statusBarRect.setLeft(rect().width() - m_statusBar->width() + splitterWidth); // Add clipping amount.
1089 }
1090 // Move statusbar to bottomLeft, or bottomRight with right-to-left-layout.
1091 m_statusBar->setGeometry(statusBarRect);
1092 // Add 1 due to how qrect coordinates work.
1093 m_view->setStatusBarOffset(m_statusBar->geometry().height() - m_statusBar->clippingAmount() + 1);
1094 } else {
1095 m_view->setStatusBarOffset(0);
1096 }
1097 }
1098
1099 bool DolphinViewContainer::eventFilter(QObject *object, QEvent *event)
1100 {
1101 if (GeneralSettings::showStatusBar() == GeneralSettings::EnumShowStatusBar::Small && object == m_view) {
1102 switch (event->type()) {
1103 case QEvent::Resize: {
1104 m_statusBar->updateWidthToContent();
1105 break;
1106 }
1107 case QEvent::LayoutRequest: {
1108 m_statusBar->updateWidthToContent();
1109 break;
1110 }
1111 default:
1112 break;
1113 }
1114 }
1115 return false;
1116 }
1117
1118 QRect DolphinViewContainer::preferredSmallStatusBarGeometry()
1119 {
1120 // Add offset depending if horizontal scrollbar or filterbar is visible, we need to add 1 due to how QRect coordinates work.
1121 const int yPos = m_view->geometry().bottom() - m_view->horizontalScrollBarHeight() - m_statusBar->minimumHeight() + 1;
1122 QRect statusBarRect = rect().adjusted(0, yPos, 0, 0);
1123 return statusBarRect;
1124 }
1125
1126 #include "moc_dolphinviewcontainer.cpp"