X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/3bfdf0d2f043a5891649c4d817d367dd4718d888..bd47eb2e6d:/src/dolphinmainwindow.cpp?ds=sidebyside diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ff834700b..cd232577d 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -98,7 +99,10 @@ DolphinMainWindow::DolphinMainWindow() : m_settingsDialog(), m_controlButton(0), m_updateToolBarTimer(0), - m_lastHandleUrlStatJob(0) + m_lastHandleUrlStatJob(0), + m_terminalPanel(0), + m_placesPanel(0), + m_tearDownFromPlacesRequested(false) { Q_INIT_RESOURCE(dolphin); @@ -246,6 +250,11 @@ void DolphinMainWindow::changeUrl(const QUrl &url) void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url) { + if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) { + m_placesPanel->proceedWithTearDown(); + m_tearDownFromPlacesRequested = false; + } + m_activeViewContainer->setAutoGrabFocus(false); changeUrl(url); m_activeViewContainer->setAutoGrabFocus(true); @@ -962,26 +971,54 @@ void DolphinMainWindow::tabCountChanged(int count) void DolphinMainWindow::setUrlAsCaption(const QUrl& url) { - QString caption; + static KFilePlacesModel s_placesModel; + + QString schemePrefix; if (!url.isLocalFile()) { - caption.append(url.scheme() + " - "); + schemePrefix.append(url.scheme() + " - "); if (!url.host().isEmpty()) { - caption.append(url.host() + " - "); + schemePrefix.append(url.host() + " - "); } } if (GeneralSettings::showFullPathInTitlebar()) { const QString path = url.adjusted(QUrl::StripTrailingSlash).path(); - caption.append(path); + setWindowTitle(schemePrefix + path); + return; + } + + const auto& matchedPlaces = s_placesModel.match(s_placesModel.index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly); + + if (!matchedPlaces.isEmpty()) { + setWindowTitle(s_placesModel.text(matchedPlaces.first())); + return; + } + + QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName(); + if (fileName.isEmpty()) { + fileName = '/'; + } + + setWindowTitle(schemePrefix + fileName); +} + +void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) +{ + if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { + m_tearDownFromPlacesRequested = true; + m_terminalPanel->goHome(); + // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged } else { - QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName(); - if (fileName.isEmpty()) { - fileName = '/'; - } - caption.append(fileName); + m_placesPanel->proceedWithTearDown(); } +} - setWindowTitle(caption); +void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath) +{ + if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { + m_tearDownFromPlacesRequested = false; + m_terminalPanel->goHome(); + } } void DolphinMainWindow::setupActions() @@ -1236,21 +1273,21 @@ void DolphinMainWindow::setupDockWidgets() terminalDock->setLocked(lock); terminalDock->setObjectName(QStringLiteral("terminalDock")); terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); - TerminalPanel* terminalPanel = new TerminalPanel(terminalDock); - terminalPanel->setCustomContextMenuActions({lockLayoutAction}); - terminalDock->setWidget(terminalPanel); + m_terminalPanel = new TerminalPanel(terminalDock); + m_terminalPanel->setCustomContextMenuActions({lockLayoutAction}); + terminalDock->setWidget(m_terminalPanel); - connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); - connect(terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged); + connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); + connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged); connect(terminalDock, &DolphinDockWidget::visibilityChanged, - terminalPanel, &TerminalPanel::dockVisibilityChanged); + m_terminalPanel, &TerminalPanel::dockVisibilityChanged); QAction* terminalAction = terminalDock->toggleViewAction(); createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel")); addDockWidget(Qt::BottomDockWidgetArea, terminalDock); connect(this, &DolphinMainWindow::urlChanged, - terminalPanel, &TerminalPanel::setUrl); + m_terminalPanel, &TerminalPanel::setUrl); if (GeneralSettings::version() < 200) { terminalDock->hide(); @@ -1269,28 +1306,31 @@ void DolphinMainWindow::setupDockWidgets() placesDock->setObjectName(QStringLiteral("placesDock")); placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - PlacesPanel* placesPanel = new PlacesPanel(placesDock); - placesPanel->setCustomContextMenuActions({lockLayoutAction}); - placesDock->setWidget(placesPanel); + m_placesPanel = new PlacesPanel(placesDock); + m_placesPanel->setCustomContextMenuActions({lockLayoutAction}); + placesDock->setWidget(m_placesPanel); - QAction* placesAction = placesDock->toggleViewAction(); + QAction *placesAction = placesDock->toggleViewAction(); createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel")); addDockWidget(Qt::LeftDockWidgetArea, placesDock); - connect(placesPanel, &PlacesPanel::placeActivated, + connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated); - connect(placesPanel, &PlacesPanel::placeMiddleClicked, + connect(m_placesPanel, &PlacesPanel::placeMiddleClicked, this, &DolphinMainWindow::openNewTab); - connect(placesPanel, &PlacesPanel::errorMessage, + connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage); connect(this, &DolphinMainWindow::urlChanged, - placesPanel, &PlacesPanel::setUrl); + m_placesPanel, &PlacesPanel::setUrl); connect(placesDock, &DolphinDockWidget::visibilityChanged, m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged); connect(this, &DolphinMainWindow::settingsChanged, - placesPanel, &PlacesPanel::readSettings); - - m_tabWidget->slotPlacesPanelVisibilityChanged(placesPanel->isVisible()); + m_placesPanel, &PlacesPanel::readSettings); + connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, + this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested); + connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, + this, &DolphinMainWindow::slotStorageTearDownExternallyRequested); + m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible()); // Add actions into the "Panels" menu KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);