summaryrefslogtreecommitdiff
path: root/widgets/mainwindow_show_messages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/mainwindow_show_messages.cpp')
-rw-r--r--widgets/mainwindow_show_messages.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/widgets/mainwindow_show_messages.cpp b/widgets/mainwindow_show_messages.cpp
new file mode 100644
index 00000000..6e7236d7
--- /dev/null
+++ b/widgets/mainwindow_show_messages.cpp
@@ -0,0 +1,67 @@
+#include "mainwindow.h"
+#include "MessageBox.hpp"
+#include <QProcess>
+#include <QStringList>
+#include <QSplashScreen>
+#include <QStatusBar>
+#include <QTimer>
+
+void MainWindow::showSoundInError(const QString& errorMsg)
+{
+ if (m_splash && m_splash->isVisible ()) m_splash->hide ();
+ MessageBox::critical_message (this, tr ("Error in Sound Input"), errorMsg);
+}
+
+void MainWindow::showSoundOutError(const QString& errorMsg)
+{
+ noteTxStopReason (TxEvidence::TxStopReason::Error);
+ if (m_splash && m_splash->isVisible ()) m_splash->hide ();
+ MessageBox::critical_message (this, tr ("Error in Sound Output"), errorMsg);
+}
+
+void MainWindow::showStatusMessage(const QString& statusMsg)
+{
+ statusBar()->showMessage(statusMsg, 5000);
+}
+
+bool MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::ExitStatus status)
+{
+ if (m_valid && (exit_code || QProcess::NormalExit != status))
+ {
+ QStringList arguments;
+ for (auto argument: process->arguments ())
+ {
+ if (argument.contains (' ')) argument = '"' + argument + '"';
+ arguments << argument;
+ }
+ if (m_splash && m_splash->isVisible ()) m_splash->hide ();
+ MessageBox::critical_message (this, tr ("Subprocess Error")
+ , tr ("Subprocess failed with exit code %1")
+ .arg (exit_code)
+ , tr ("Running: %1\n%2")
+ .arg (process->program () + ' ' + arguments.join (' '))
+ .arg (QString {process->readAllStandardError()}));
+ return true;
+ }
+ return false;
+}
+
+void MainWindow::subProcessError (QProcess * process, QProcess::ProcessError)
+{
+ if (m_valid)
+ {
+ QStringList arguments;
+ for (auto argument: process->arguments ())
+ {
+ if (argument.contains (' ')) argument = '"' + argument + '"';
+ arguments << argument;
+ }
+ if (m_splash && m_splash->isVisible ()) m_splash->hide ();
+ MessageBox::critical_message (this, tr ("Subprocess error")
+ , tr ("Running: %1\n%2")
+ .arg (process->program () + ' ' + arguments.join (' '))
+ .arg (process->errorString ()));
+ m_valid = false; // ensures exit if still constructing
+ QTimer::singleShot (0, this, SLOT (close ()));
+ }
+}