From 77a3ed6a77d96d7bb5c4f8dff3b27b3637b01928 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sat, 8 Jul 2023 16:54:26 -0700 Subject: [PATCH] sysprof: allow capturing to disk from greeter --- src/sysprof/sysprof-greeter.c | 68 ++++++++++++++++++++++++++++++++++ src/sysprof/sysprof-greeter.ui | 1 + 2 files changed, 69 insertions(+) diff --git a/src/sysprof/sysprof-greeter.c b/src/sysprof/sysprof-greeter.c index 2f24f758..cd941c16 100644 --- a/src/sysprof/sysprof-greeter.c +++ b/src/sysprof/sysprof-greeter.c @@ -20,6 +20,7 @@ #include "config.h" +#include #include #include @@ -140,6 +141,72 @@ sysprof_greeter_record_to_memory_action (GtkWidget *widget, g_object_ref (self)); } +static void +sysprof_greeter_choose_file_for_record_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + GtkFileDialog *dialog = (GtkFileDialog *)object; + g_autoptr(SysprofGreeter) self = user_data; + g_autoptr(GError) error = NULL; + g_autoptr(GFile) file = NULL; + + g_assert (GTK_IS_FILE_DIALOG (dialog)); + g_assert (G_IS_ASYNC_RESULT (result)); + g_assert (SYSPROF_IS_GREETER (self)); + + if ((file = gtk_file_dialog_save_finish (dialog, result, &error))) + { + if (g_file_is_native (file)) + { + g_autoptr(SysprofCaptureWriter) writer = NULL; + g_autoptr(SysprofProfiler) profiler = NULL; + + profiler = sysprof_greeter_create_profiler (self); + writer = sysprof_capture_writer_new (g_file_peek_path (file), 0); + + gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); + + sysprof_profiler_record_async (profiler, + writer, + NULL, + sysprof_greeter_record_cb, + g_object_ref (self)); + } + } +} + +static void +sysprof_greeter_record_to_file_action (GtkWidget *widget, + const char *action_name, + GVariant *param) +{ + SysprofGreeter *self = (SysprofGreeter *)widget; + g_autoptr(GtkFileDialog) dialog = NULL; + g_autoptr(GDateTime) now = NULL; + g_autofree char *now_str = NULL; + g_autofree char *initial_name = NULL; + + g_assert (SYSPROF_IS_GREETER (self)); + + now = g_date_time_new_now_local (); + now_str = g_date_time_format (now, "%Y-%m-%d %H:%M:%S"); + initial_name = g_strdup_printf (_("System Capture from %s.syscap"), now_str); + g_strdelimit (initial_name, G_DIR_SEPARATOR_S, '-'); + + dialog = gtk_file_dialog_new (); + gtk_file_dialog_set_title (dialog, _("Record to File")); + gtk_file_dialog_set_accept_label (dialog, _("Record")); + gtk_file_dialog_set_modal (dialog, TRUE); + gtk_file_dialog_set_initial_name (dialog, initial_name); + + gtk_file_dialog_save (dialog, + GTK_WINDOW (self), + NULL, + sysprof_greeter_choose_file_for_record_cb, + g_object_ref (self)); +} + static void sysprof_greeter_dispose (GObject *object) { @@ -204,6 +271,7 @@ sysprof_greeter_class_init (SysprofGreeterClass *klass) gtk_widget_class_bind_template_callback (widget_class, sysprof_greeter_view_stack_notify_visible_child); gtk_widget_class_install_action (widget_class, "win.record-to-memory", NULL, sysprof_greeter_record_to_memory_action); + gtk_widget_class_install_action (widget_class, "win.record-to-file", NULL, sysprof_greeter_record_to_file_action); } static void diff --git a/src/sysprof/sysprof-greeter.ui b/src/sysprof/sysprof-greeter.ui index d296114b..2e9bbc94 100644 --- a/src/sysprof/sysprof-greeter.ui +++ b/src/sysprof/sysprof-greeter.ui @@ -341,6 +341,7 @@ Record to _File… + win.record-to-file true true