]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Introduce HAVE_TERMINAL
[dolphin.git] / src / dolphinmainwindow.cpp
index c0446fa4ced7c66d876826fcb9fe253a288216ad..076869c1ac0bea75365e03745582b9e53708f580 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "dolphinmainwindow.h"
 
+#include "config-terminal.h"
 #include "global.h"
 #include "dolphindockwidget.h"
 #include "dolphincontextmenu.h"
@@ -407,7 +408,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
 
         bool doNotAskAgainCheckboxResult = false;
 
-        const int result = KMessageBox::createKMessageBox(dialog,
+        const auto result = KMessageBox::createKMessageBox(dialog,
             buttons,
             QMessageBox::Warning,
             i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
@@ -434,6 +435,58 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
         }
     }
 
+    if (m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) {
+        // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
+        // Open a confirmation dialog with 3 buttons:
+        // QDialogButtonBox::Yes    -> Quit
+        // QDialogButtonBox::No     -> Show Terminal Panel
+        // QDialogButtonBox::Cancel -> do nothing
+        QDialog *dialog = new QDialog(this, Qt::Dialog);
+        dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
+        dialog->setModal(true);
+        auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel;
+        if (!m_terminalPanel->isVisible()) {
+            standardButtons |= QDialogButtonBox::No;
+        }
+        QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons);
+        KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
+        if (!m_terminalPanel->isVisible()) {
+            KGuiItem::assign(
+                    buttons->button(QDialogButtonBox::No),
+                    KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("utilities-terminal"))));
+        }
+        KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
+
+        bool doNotAskAgainCheckboxResult = false;
+
+        const auto result = KMessageBox::createKMessageBox(
+                dialog,
+                buttons,
+                QMessageBox::Warning,
+                i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()),
+                QStringList(),
+                i18n("Do not ask again"),
+                &doNotAskAgainCheckboxResult,
+                KMessageBox::Dangerous);
+
+        if (doNotAskAgainCheckboxResult) {
+            GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
+        }
+
+        switch (result) {
+            case QDialogButtonBox::Yes:
+                // Quit
+                break;
+            case QDialogButtonBox::No:
+                actionCollection()->action("show_terminal_panel")->trigger();
+                // Do not quit, ignore quit event
+                Q_FALLTHROUGH();
+            default:
+                event->ignore();
+                return;
+        }
+    }
+
     GeneralSettings::setVersion(CurrentDolphinVersion);
     GeneralSettings::self()->save();
 
@@ -1008,7 +1061,10 @@ void DolphinMainWindow::tabCountChanged(int count)
 
 void DolphinMainWindow::updateWindowTitle()
 {
-    setWindowTitle(m_activeViewContainer->caption());
+    const QString newTitle = m_activeViewContainer->caption();
+    if (windowTitle() != newTitle) {
+        setWindowTitle(newTitle);
+    }
 }
 
 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
@@ -1158,7 +1214,7 @@ void DolphinMainWindow::setupActions()
     compareFiles->setEnabled(false);
     connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
 
-#ifndef Q_OS_WIN
+#ifdef HAVE_TERMINAL
     if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
         QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
         openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
@@ -1277,7 +1333,7 @@ void DolphinMainWindow::setupDockWidgets()
             this, &DolphinMainWindow::showErrorMessage);
 
     // Setup "Terminal"
-#ifndef Q_OS_WIN
+#ifdef HAVE_TERMINAL
     if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
         DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
         terminalDock->setLocked(lock);