]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Merge remote-tracking branch 'origin/Applications/17.12'
[dolphin.git] / src / dolphinmainwindow.cpp
index 3df25001c986407440743d7d694b6cdc319db878..de43bab4c2ca86f148a480d0d1cd58c87e5f497c 100644 (file)
@@ -90,16 +90,21 @@ namespace {
 }
 
 DolphinMainWindow::DolphinMainWindow() :
-    KXmlGuiWindow(0),
-    m_newFileMenu(0),
-    m_tabWidget(0),
-    m_activeViewContainer(0),
-    m_actionHandler(0),
-    m_remoteEncoding(0),
+    KXmlGuiWindow(nullptr),
+    m_newFileMenu(nullptr),
+    m_tabWidget(nullptr),
+    m_activeViewContainer(nullptr),
+    m_actionHandler(nullptr),
+    m_remoteEncoding(nullptr),
     m_settingsDialog(),
-    m_controlButton(0),
-    m_updateToolBarTimer(0),
-    m_lastHandleUrlStatJob(0)
+    m_controlButton(nullptr),
+    m_updateToolBarTimer(nullptr),
+    m_lastHandleUrlStatJob(nullptr),
+#ifndef Q_OS_WIN
+    m_terminalPanel(nullptr),
+#endif
+    m_placesPanel(nullptr),
+    m_tearDownFromPlacesRequested(false)
 {
     Q_INIT_RESOURCE(dolphin);
 
@@ -247,6 +252,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);
@@ -741,7 +751,7 @@ void DolphinMainWindow::editSettings()
 void DolphinMainWindow::handleUrl(const QUrl& url)
 {
     delete m_lastHandleUrlStatJob;
-    m_lastHandleUrlStatJob = 0;
+    m_lastHandleUrlStatJob = nullptr;
 
     if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
         activeViewContainer()->setUrl(url);
@@ -761,7 +771,7 @@ void DolphinMainWindow::handleUrl(const QUrl& url)
 
 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
 {
-    m_lastHandleUrlStatJob = 0;
+    m_lastHandleUrlStatJob = nullptr;
     const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
     const QUrl url = static_cast<KIO::StatJob*>(job)->url();
     if (entry.isDir()) {
@@ -902,7 +912,7 @@ void DolphinMainWindow::updateToolBar()
 
 void DolphinMainWindow::slotControlButtonDeleted()
 {
-    m_controlButton = 0;
+    m_controlButton = nullptr;
     m_updateToolBarTimer->start();
 }
 
@@ -994,6 +1004,29 @@ void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
     setWindowTitle(schemePrefix + fileName);
 }
 
+void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+    if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+        m_tearDownFromPlacesRequested = true;
+        m_terminalPanel->goHome();
+        // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
+    } else {
+        m_placesPanel->proceedWithTearDown();
+    }
+#endif
+}
+
+void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
+{
+#ifndef Q_OS_WIN
+    if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+        m_tearDownFromPlacesRequested = false;
+        m_terminalPanel->goHome();
+    }
+#endif
+}
+
 void DolphinMainWindow::setupActions()
 {
     // setup 'File' menu
@@ -1063,7 +1096,7 @@ void DolphinMainWindow::setupActions()
     actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
     stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
     stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
-    stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-visiting")));
+    stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
     stashSplit->setCheckable(false);
     stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
     connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
@@ -1141,7 +1174,7 @@ void DolphinMainWindow::setupActions()
     }
 
     // setup 'Settings' menu
-    KToggleAction* showMenuBar = KStandardAction::showMenubar(0, 0, actionCollection());
+    KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
     connect(showMenuBar, &KToggleAction::triggered,                   // Fixes #286822
             this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
     KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
@@ -1246,21 +1279,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();
@@ -1279,28 +1312,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);
 
-    QActionplacesAction = 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);
@@ -1400,10 +1436,10 @@ void DolphinMainWindow::createControlButton()
 void DolphinMainWindow::deleteControlButton()
 {
     delete m_controlButton;
-    m_controlButton = 0;
+    m_controlButton = nullptr;
 
     delete m_updateToolBarTimer;
-    m_updateToolBarTimer = 0;
+    m_updateToolBarTimer = nullptr;
 }
 
 bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)