]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Show home folder if needed after unmounting mounted disk
[dolphin.git] / src / dolphinmainwindow.cpp
index 7a1a043710a48b3dd97344c96defd0d967106497..2c91cd07a7a846b1d718cdf61f38736d0e54928c 100644 (file)
@@ -70,7 +70,6 @@
 #include <QDialog>
 #include <QFileInfo>
 #include <QLineEdit>
-#include <QMenu>
 #include <QMenuBar>
 #include <QPushButton>
 #include <QShowEvent>
@@ -205,9 +204,14 @@ DolphinMainWindow::~DolphinMainWindow()
 QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
 {
     QVector<DolphinViewContainer*> viewContainers;
-    viewContainers.reserve(m_tabWidget->count());
+
     for (int i = 0; i < m_tabWidget->count(); ++i) {
-        viewContainers << m_tabWidget->tabPageAt(i)->activeViewContainer();
+        DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i);
+
+        viewContainers << tabPage->primaryViewContainer();
+        if (tabPage->splitViewEnabled()) {
+            viewContainers << tabPage->secondaryViewContainer();
+        }
     }
     return viewContainers;
 }
@@ -475,7 +479,10 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
         closedByUser = false;
     }
 
-    if (m_tabWidget->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser) {
+    if (m_tabWidget->count() > 1
+        && GeneralSettings::confirmClosingMultipleTabs()
+        && !GeneralSettings::rememberOpenedTabs()
+        && closedByUser) {
         // Ask the user if he really wants to quit and close all tabs.
         // Open a confirmation dialog with 3 buttons:
         // QDialogButtonBox::Yes    -> Quit
@@ -943,18 +950,6 @@ void DolphinMainWindow::toggleShowMenuBar()
     }
 }
 
-QString DolphinMainWindow::activeContainerLocalPath()
-{
-    KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url());
-    KJobWidgets::setWindow(statJob, this);
-    statJob->exec();
-    QUrl url = statJob->mostLocalUrl();
-    if (url.isLocalFile()) {
-        return url.toLocalFile();
-    }
-    return QDir::homePath();
-}
-
 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
 {
     m_searchTools.clear();
@@ -1001,7 +996,31 @@ void DolphinMainWindow::openPreferredSearchTool()
 
 void DolphinMainWindow::openTerminal()
 {
-    KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
+    const QUrl url = m_activeViewContainer->url();
+
+    if (url.isLocalFile()) {
+        KToolInvocation::invokeTerminal(QString(), url.toLocalFile());
+        return;
+    }
+
+     // Not a local file, with protocol Class ":local", try stat'ing
+    if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
+        KIO::StatJob *job = KIO::mostLocalUrl(url);
+        KJobWidgets::setWindow(job, this);
+        connect(job, &KJob::result, this, [job]() {
+            QUrl statUrl;
+            if (!job->error()) {
+                statUrl = job->mostLocalUrl();
+            }
+
+            KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
+        });
+
+        return;
+    }
+
+    // Nothing worked, just use $HOME
+    KToolInvocation::invokeTerminal(QString(), QDir::homePath());
 }
 
 void DolphinMainWindow::editSettings()
@@ -1252,6 +1271,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();
@@ -1263,12 +1286,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<DolphinViewContainer*> 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
@@ -1349,20 +1387,20 @@ void DolphinMainWindow::setupActions()
         "action they are removed from their old location.") +  cutCopyPastePara);
 
     QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
-    copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to inactive split view"));
+    copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
     copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
         "the <emphasis>active</emphasis> view to the inactive split view."));
     copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
-    copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to inactive split view"));
+    copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
     actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT + Qt::Key_F5 );
     connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView);
 
     QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
-    moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to inactive split view"));
+    moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
     moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
         "the <emphasis>active</emphasis> view to the inactive split view."));
     moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
-    moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to inactive split view"));
+    moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
     actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT + Qt::Key_F6 );
     connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView);
 
@@ -1546,7 +1584,6 @@ void DolphinMainWindow::setupActions()
     actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL + Qt::SHIFT + Qt::Key_F);
     connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
 
-#ifdef HAVE_TERMINAL
     if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
         QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
         openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
@@ -1557,13 +1594,14 @@ void DolphinMainWindow::setupActions()
         actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
         connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
 
+#ifdef HAVE_TERMINAL
         QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
         focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
         focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
         actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL + Qt::SHIFT + Qt::Key_F4);
         connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
-    }
 #endif
+    }
 
     // setup 'Bookmarks' menu
     KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
@@ -2095,6 +2133,8 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             this, &DolphinMainWindow::goForward);
     connect(view, &DolphinView::urlActivated,
             this, &DolphinMainWindow::handleUrl);
+    connect(view, &DolphinView::goUpRequested,
+            this, &DolphinMainWindow::goUp);
 
     const KUrlNavigator* navigator = container->urlNavigator();
     connect(navigator, &KUrlNavigator::urlChanged,