feat: About dialog with version, commit, build time and settings path
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
82f91d00c0
commit
a0fa845b58
8 files changed
+170
-9
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "help_window.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "build_info.hpp"
|
||||
#include "layout_store.hpp"
|
||||
|
||||
namespace udpscope {
|
||||
namespace {
|
||||
|
||||
/// Nulled by the `close-request` handler so a second open cannot present a dead widget.
|
||||
/// One pointer per window, file-scope because there is one application.
|
||||
GtkWidget* g_about = nullptr;
|
||||
|
||||
gboolean on_window_close(GtkWindow* window, gpointer slot) {
|
||||
(void)window;
|
||||
*static_cast<GtkWidget**>(slot) = nullptr;
|
||||
return FALSE; // let the default handler destroy it
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void show_about(GtkWindow* parent, const std::string& session_path) {
|
||||
if (g_about != nullptr) {
|
||||
gtk_window_present(GTK_WINDOW(g_about));
|
||||
return;
|
||||
}
|
||||
|
||||
// GtkAboutDialog is not deprecated in GTK 4 (unlike GtkShortcutsWindow), so the
|
||||
// stock dialog is used here and the overview is hand-rolled.
|
||||
GtkWidget* dialog = gtk_about_dialog_new();
|
||||
g_about = dialog;
|
||||
GtkAboutDialog* about = GTK_ABOUT_DIALOG(dialog);
|
||||
gtk_about_dialog_set_program_name(about, "udpscope");
|
||||
gtk_about_dialog_set_version(about, build_info::kVersion);
|
||||
gtk_about_dialog_set_comments(about, "An oscilloscope for UDPStreamer sources.");
|
||||
gtk_about_dialog_set_license_type(about, GTK_LICENSE_MIT_X11);
|
||||
|
||||
char details[1024];
|
||||
std::snprintf(details, sizeof(details),
|
||||
"Commit: %s\nBuilt: %s\nSettings: %s\nSession file: %s",
|
||||
build_info::kCommit, build_info::kTimestamp, config_dir().c_str(),
|
||||
session_path.c_str());
|
||||
gtk_about_dialog_set_system_information(about, details);
|
||||
|
||||
gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
|
||||
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
|
||||
g_signal_connect(dialog, "close-request", G_CALLBACK(on_window_close), &g_about);
|
||||
gtk_window_present(GTK_WINDOW(dialog));
|
||||
}
|
||||
|
||||
} // namespace udpscope
|
||||
Reference in new issue
Block a user