strawberry/app/main_window.hpp
trvon 2e5637fe6c
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Add "Start at login" to the tray app
A checkable tray menu item and a Diagnostics-tab checkbox write or
remove ~/.config/autostart/strawberry-tray.desktop (XDG autostart,
atomic write), pointing at the installed strawberry-tray when there is
one. Sessions that do not run autostart entries on their own (sway, i3,
Hyprland, niri without uwsm/dex) get a note with the exact line to add
to the compositor config instead of a silent no-op; GNOME, KDE, XFCE and
the like, or an active xdg-desktop-autostart.target, need nothing more.

The logic is Qt-free (app/autostart.cpp) with a unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:59:52 -06:00

128 lines
4.3 KiB
C++

#ifndef STRAWBERRY_APP_MAIN_WINDOW_HPP
#define STRAWBERRY_APP_MAIN_WINDOW_HPP
#include "strawberry/evidence_store.hpp"
#include "tray_state.hpp"
#include <QJsonObject>
#include <QMainWindow>
#include <vector>
class QCheckBox;
class QComboBox;
class QLabel;
class QLineEdit;
class QListWidget;
class QPushButton;
class QTabWidget;
class QTableWidget;
class QTextBrowser;
class QUrl;
namespace strawberry::app {
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(const EvidenceStore& store, QWidget* parent = nullptr);
/// Refresh the findings table (store contents or seen-state changed).
void refresh_findings(const AckMap& seen);
/// Daemon status (empty object + error when unreachable).
void update_status(const QJsonObject& status, const QString& error, const TrayState& tray);
/// Result line for a reload/rescan command.
void show_command_result(const QString& verb, bool ok, const QString& message);
void show_finding(const QString& finding_id);
void show_process(const QString& node_id);
/// Select a tab by name (findings, processes, rules, allowlist, diagnostics).
void select_tab(const QString& name);
/// Reply data of the `policy` verb (feeds, allowlist, history, feed state).
void update_policy(const QJsonObject& policy, const QString& error);
/// Result of a policy change (allowlist/feed edit).
void show_policy_result(const QString& verb, bool ok, const QString& message);
/// "Start at login" state, plus a note when the session needs more
/// than the autostart entry (e.g. sway) or the change failed.
void set_autostart_state(bool enabled, const QString& note);
signals:
void finding_viewed(const QString& finding_id, qint64 last_seen);
void mark_all_seen_requested();
void command_requested(const QString& verb);
void policy_change_requested(const QString& verb, const QJsonObject& payload);
void autostart_toggled(bool enable);
private:
QWidget* build_findings_tab();
QWidget* build_processes_tab();
QWidget* build_diagnostics_tab();
QWidget* build_rules_tab();
QWidget* build_allowlist_tab();
QWidget* build_response_tab();
void render_response();
void render_rules();
void render_allowlist();
void add_feed_dialog();
void add_allowlist_dialog();
/// Confirm, then request an allowlist entry.
void propose_allowlist(const QString& kind, const QString& value, const QString& rule, const QString& context);
void render_finding_detail(const FindingRecord& finding);
void run_process_search();
void render_process_detail(const ProcessSearchResult& result);
void on_link(const QUrl& url);
void render_diagnostics();
const EvidenceStore& store_;
AckMap seen_;
std::vector<FindingRecord> findings_;
QTabWidget* tabs_ = nullptr;
QComboBox* severity_filter_ = nullptr;
QCheckBox* unseen_only_ = nullptr;
QTableWidget* findings_table_ = nullptr;
QTextBrowser* finding_detail_ = nullptr;
QLabel* findings_banner_ = nullptr;
QLineEdit* process_query_ = nullptr;
QListWidget* process_results_ = nullptr;
QTextBrowser* process_detail_ = nullptr;
std::vector<ProcessSearchResult> process_hits_;
QTextBrowser* diagnostics_ = nullptr;
QLabel* command_result_ = nullptr;
QCheckBox* autostart_ = nullptr;
QLabel* autostart_note_ = nullptr;
QPushButton* reload_button_ = nullptr;
QPushButton* rescan_button_ = nullptr;
QJsonObject status_;
QString status_error_;
TrayState tray_;
QLabel* rules_summary_ = nullptr;
QTableWidget* feeds_table_ = nullptr;
QLabel* rules_result_ = nullptr;
QTableWidget* allow_table_ = nullptr;
QListWidget* history_list_ = nullptr;
QLabel* allow_result_ = nullptr;
QJsonObject policy_;
QString policy_error_;
QLabel* response_status_ = nullptr;
QCheckBox* contain_auto_ = nullptr;
QComboBox* contain_severity_ = nullptr;
QComboBox* prevention_mode_ = nullptr;
QComboBox* prevention_severity_ = nullptr;
QTableWidget* contain_table_ = nullptr;
QTableWidget* quarantine_table_ = nullptr;
QLabel* response_result_ = nullptr;
QLabel* process_result_ = nullptr;
bool protection_dirty_ = false;
};
} // namespace strawberry::app
#endif // STRAWBERRY_APP_MAIN_WINDOW_HPP