game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
terminalpanel.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// terminalpanel.h
4// ==============================================================================
5// Embedded terminal panel using QTermWidget for btop++ and other terminal apps
6// ==============================================================================
7
8#pragma once
9
10#include <QAction>
11#include <QComboBox>
12#include <QProcess>
13#include <QToolBar>
14#include <QVBoxLayout>
15#include <QWidget>
16
17// Forward declaration
18namespace Konsole
19{
20class TerminalDisplay;
21}
22
23class QTermWidget;
24
25/**
26 * @brief Terminal panel widget that embeds a terminal emulator
27 *
28 * Provides an embedded terminal for running btop++, htop, or other
29 * terminal-based system monitoring tools directly within the game launcher.
30 */
31class TerminalPanel : public QWidget
32{
33 Q_OBJECT
34
35 public:
36 explicit TerminalPanel(QWidget* parent = nullptr);
37 ~TerminalPanel() override;
38
39 /**
40 * @brief Start or restart the terminal with btop++
41 */
42 void startBtop();
43
44 /**
45 * @brief Start the terminal with a custom command
46 * @param command The command to execute in the terminal
47 */
48 void startCommand(const QString& command);
49
50 /**
51 * @brief Check if btop++ is available on the system
52 * @return true if btop++ is found in PATH
53 */
54 static bool isBtopAvailable();
55
56 /**
57 * @brief Check if htop is available as a fallback
58 * @return true if htop is found in PATH
59 */
60 static bool isHtopAvailable();
61
62 /**
63 * @brief Get the best available system monitor command
64 * @return Command string for btop++, htop, or top (in order of preference)
65 */
66 static QString getBestMonitorCommand();
67
68 /**
69 * @brief Pause the terminal process (suspends btop/htop to save CPU)
70 * Call when panel is hidden or window is minimized
71 */
72 void pauseProcess();
73
74 /**
75 * @brief Resume the terminal process
76 * Call when panel becomes visible again
77 */
78 void resumeProcess();
79
80 /**
81 * @brief Check if the terminal process is currently paused
82 * @return true if paused
83 */
84 bool isPaused() const
85 {
86 return isPaused_;
87 }
88
89 signals:
90 /**
91 * @brief Emitted when the terminal process finishes
92 * @param exitCode The exit code of the process
93 */
94 void processFinished(int exitCode);
95
96 private slots:
97 void onMonitorChanged(int index);
98 void onRestartClicked();
99 void onTerminalFinished();
100
101 private:
102 void setupUI();
103 void setupToolBar();
104 void applyDarkTheme();
105
106 QTermWidget* terminal_ = nullptr;
107 QToolBar* toolBar_ = nullptr;
108 QComboBox* monitorCombo_ = nullptr;
109 QAction* restartAction_ = nullptr;
110 QVBoxLayout* layout_ = nullptr;
111
112 QString currentCommand_;
113 bool isPaused_ = false;
114
115 // Cached color schemes (computed once at startup)
116 static QStringList cachedColorSchemes_;
117 static bool colorSchemesCached_;
118};
void processFinished(int exitCode)
Emitted when the terminal process finishes.
void resumeProcess()
Resume the terminal process Call when panel becomes visible again.
void startBtop()
Start or restart the terminal with btop++.
void pauseProcess()
Pause the terminal process (suspends btop/htop to save CPU) Call when panel is hidden or window is mi...
static bool isBtopAvailable()
Check if btop++ is available on the system.
void startCommand(const QString &command)
Start the terminal with a custom command.
TerminalPanel(QWidget *parent=nullptr)
~TerminalPanel() override
bool isPaused() const
Check if the terminal process is currently paused.
static bool isHtopAvailable()
Check if htop is available as a fallback.
static QString getBestMonitorCommand()
Get the best available system monitor command.