X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1501825d447bf0d316750368d8579a95a38ce537..e9a39700:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 8d4f50270..e755e7281 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -216,6 +216,20 @@ QVector DolphinMainWindow::viewContainers() const return viewContainers; } +void DolphinMainWindow::setViewsWithInvalidPathsToHome() +{ + const QVector theViewContainers = viewContainers(); + for (DolphinViewContainer *viewContainer : theViewContainers) { + + // Only consider local dirs, not remote locations and abstract protocols + if (viewContainer->url().isLocalFile()) { + if (!QFileInfo::exists(viewContainer->url().toLocalFile())) { + viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath())); + } + } + } +} + void DolphinMainWindow::openDirectories(const QList& dirs, bool splitView) { m_tabWidget->openDirectories(dirs, splitView); @@ -292,7 +306,7 @@ void DolphinMainWindow::changeUrl(const QUrl &url) updateViewActions(); updateGoActions(); - emit urlChanged(url); + Q_EMIT urlChanged(url); } void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url) @@ -327,7 +341,7 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) compareFilesAction->setEnabled(false); } - emit selectionChanged(selection); + Q_EMIT selectionChanged(selection); } void DolphinMainWindow::updateHistory() @@ -413,7 +427,7 @@ void DolphinMainWindow::openInNewTab() const KFileItemList& list = m_activeViewContainer->view()->selectedItems(); bool tabCreated = false; - foreach (const KFileItem& item, list) { + for (const KFileItem& item : list) { const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (!url.isEmpty()) { openNewTabAfterCurrentTab(url); @@ -847,7 +861,8 @@ void DolphinMainWindow::replaceLocation() void DolphinMainWindow::togglePanelLockState() { const bool newLockState = !GeneralSettings::lockPanels(); - foreach (QObject* child, children()) { + const auto childrenObjects = children(); + for (QObject* child : childrenObjects) { DolphinDockWidget* dock = qobject_cast(child); if (dock) { dock->setLocked(newLockState); @@ -1247,7 +1262,7 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) updateSearchAction(); const QUrl url = viewContainer->url(); - emit urlChanged(url); + Q_EMIT urlChanged(url); } void DolphinMainWindow::tabCountChanged(int count) @@ -1271,6 +1286,10 @@ void DolphinMainWindow::updateWindowTitle() void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) { + connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() { + setViewsToHomeIfMountPathOpen(mountPath); + }); + if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { m_tearDownFromPlacesRequested = true; m_terminalPanel->goHome(); @@ -1282,12 +1301,27 @@ void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mo void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath) { + connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() { + setViewsToHomeIfMountPathOpen(mountPath); + }); + if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { m_tearDownFromPlacesRequested = false; m_terminalPanel->goHome(); } } +void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath) +{ + const QVector theViewContainers = viewContainers(); + for (DolphinViewContainer *viewContainer : theViewContainers) { + if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) { + viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath())); + } + } + disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr); +} + void DolphinMainWindow::setupActions() { // setup 'File' menu @@ -2050,7 +2084,8 @@ bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu) Q_ASSERT(menu); const KToolBar* toolBarWidget = toolBar(); - foreach (const QWidget* widget, action->associatedWidgets()) { + const auto associatedWidgets = action->associatedWidgets(); + for (const QWidget* widget : associatedWidgets) { if (widget == toolBarWidget) { return false; } @@ -2073,7 +2108,7 @@ void DolphinMainWindow::refreshViews() updateWindowTitle(); } - emit settingsChanged(); + Q_EMIT settingsChanged(); } void DolphinMainWindow::clearStatusBar()