From e34d60f58d7845641646eb872bbd9c0e8ee40f2a Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Thu, 5 Oct 2023 06:25:52 -0500
Subject: Qt UI: QoI improvements to launching tools

* Terminal now uses dark background with light text, which makes root
  prompt readable when started from Install CD.

* Tools are now spawned instead of run modally.  This means you can
  interact with the Horizon wizard while using the Terminal or Web
  browser.  If a tool is still running at the end, Horizon will prompt
  the user before allowing them to commit to disk.
---
 ui/qt5/commitpage.cc    | 17 +++++++++++++++++
 ui/qt5/commitpage.hh    |  1 +
 ui/qt5/horizonwizard.hh |  3 +++
 ui/qt5/intropage.cc     | 15 +++++++++------
 4 files changed, 30 insertions(+), 6 deletions(-)

(limited to 'ui')

diff --git a/ui/qt5/commitpage.cc b/ui/qt5/commitpage.cc
index ed35c19..7856a4a 100644
--- a/ui/qt5/commitpage.cc
+++ b/ui/qt5/commitpage.cc
@@ -18,6 +18,7 @@
 
 #include <QLabel>
 #include <QVariant>
+#include <QMessageBox>
 #include <QVBoxLayout>
 
 CommitPage::CommitPage(QWidget *parent) : HorizonWizardPage(parent) {
@@ -110,3 +111,19 @@ void CommitPage::initializePage() {
             .arg(softString)
             .arg(field("hostname").toString()));
 }
+
+bool CommitPage::validatePage() {
+    bool running = std::any_of(
+        horizonWizard()->tools.begin(), horizonWizard()->tools.end(),
+        [](QProcess *tool) {
+            return tool->state() == QProcess::Running;
+        });
+
+    if(running) {
+        QMessageBox::information(horizonWizard(), tr("Tool(s) Still Running"),
+                                 tr("You must quit all tools before beginning System Installation."));
+	return false;
+    }
+
+    return true;
+}
diff --git a/ui/qt5/commitpage.hh b/ui/qt5/commitpage.hh
index a4f480e..71f869d 100644
--- a/ui/qt5/commitpage.hh
+++ b/ui/qt5/commitpage.hh
@@ -22,6 +22,7 @@ public:
     CommitPage(QWidget *parent = nullptr);
 
     void initializePage();
+    bool validatePage();
 private:
     QLabel *choices;
 };
diff --git a/ui/qt5/horizonwizard.hh b/ui/qt5/horizonwizard.hh
index ce5c22d..b39287c 100644
--- a/ui/qt5/horizonwizard.hh
+++ b/ui/qt5/horizonwizard.hh
@@ -14,6 +14,7 @@
 #define HORIZONWIZARD_HH
 
 #include <diskman/disk.hh>
+#include <QProcess>
 #include <QShortcut>
 #include <QWizard>
 #include <map>
@@ -159,6 +160,8 @@ public:
 #ifdef HAS_INSTALL_ENV
     /*! The disks present on this computer. */
     std::vector<Horizon::DiskMan::Disk> disks;
+    /*! Any spawned tools from the intro page. */
+    std::vector<QProcess *> tools;
 #endif
     /*! Whether to automatically partition the disk. */
     bool auto_part;
diff --git a/ui/qt5/intropage.cc b/ui/qt5/intropage.cc
index da32373..76d7644 100644
--- a/ui/qt5/intropage.cc
+++ b/ui/qt5/intropage.cc
@@ -42,16 +42,19 @@ IntroPage::IntroPage(QWidget *parent) : HorizonWizardPage(parent) {
     toolButton->setWhatsThis(tr("Displays a menu of utilities that you can launch from the Installation Environment."));
     toolMenu = new QMenu("&Tools", toolButton);
     connect(toolMenu->addAction("&Terminal"), &QAction::triggered, [=](void) {
-        QProcess p;
-        p.execute("xterm", {"-fa", "Liberation Mono", "-fs", "12"});
+        QProcess *p = new QProcess(this);
+        p->start("xterm", {"-fa", "Liberation Mono", "-fs", "12", "-bg", "DarkGreen", "-fg", "White"});
+        horizonWizard()->tools.push_back(p);
     });
     connect(toolMenu->addAction("&Partition Editor"), &QAction::triggered, [=](void) {
-        QProcess p;
-        p.execute("partitionmanager", QStringList());
+        QProcess *p = new QProcess(this);
+        p->start("partitionmanager", QStringList());
+        horizonWizard()->tools.push_back(p);
     });
     connect(toolMenu->addAction("&Web Browser"), &QAction::triggered, [=](void){
-        QProcess p;
-        p.execute("netsurf-gtk", QStringList());
+        QProcess *p = new QProcess(this);
+        p->start("netsurf-gtk", QStringList());
+        horizonWizard()->tools.push_back(p);
     });
     toolButton->setMenu(toolMenu);
 
-- 
cgit v1.2.3-70-g09d2