[sysprof/wip/chergert/sysprof-3] libsysprof-ui: wire up a save action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/sysprof-3] libsysprof-ui: wire up a save action
- Date: Sun, 19 May 2019 18:04:42 +0000 (UTC)
commit 8d2d7d626f33ba069993b532fdc206ee5ec5350a
Author: Christian Hergert <chergert redhat com>
Date: Sun May 19 11:04:23 2019 -0700
libsysprof-ui: wire up a save action
We need this so we have something more simplified for consumers such as
Builder to avoid all the duplicated code.
src/libsysprof-ui/sysprof-display.c | 63 ++++++++++++++++++++++++++++++++++++
src/libsysprof-ui/sysprof-display.h | 2 ++
src/libsysprof-ui/sysprof-notebook.c | 24 ++++++++++++++
src/libsysprof-ui/sysprof-notebook.h | 2 ++
src/sysprof/gtk/menus.ui | 7 ++++
src/sysprof/sysprof-window.c | 12 +++++++
6 files changed, 110 insertions(+)
---
diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c
index ca4760e..dc90409 100644
--- a/src/libsysprof-ui/sysprof-display.c
+++ b/src/libsysprof-ui/sysprof-display.c
@@ -473,3 +473,66 @@ sysprof_display_open (SysprofDisplay *self,
update_title_child_property (self);
}
+
+void
+sysprof_display_save (SysprofDisplay *self)
+{
+ SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
+ g_autoptr(GFile) file = NULL;
+ GtkFileChooserNative *native;
+ SysprofCaptureReader *reader;
+ GtkWindow *parent;
+ gint res;
+
+ g_return_if_fail (SYSPROF_IS_DISPLAY (self));
+
+ if (!(reader = sysprof_capture_view_get_reader (priv->capture_view)))
+ return;
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
+
+ native = gtk_file_chooser_native_new (_("Save Recording"),
+ parent,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ _("Save"),
+ _("Cancel"));
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (native), TRUE);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (native), TRUE);
+ gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER (native), TRUE);
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (native), "capture.sysprof");
+
+ res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
+
+ switch (res)
+ {
+ case GTK_RESPONSE_ACCEPT:
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
+
+ if (g_file_is_native (file))
+ {
+ g_autofree gchar *path = g_file_get_path (file);
+ g_autoptr(GError) error = NULL;
+
+ if (!sysprof_capture_reader_save_as (reader, path, &error))
+ {
+ GtkWidget *msg;
+
+ msg = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT |
GTK_DIALOG_USE_HEADER_BAR,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Failed to save recording: %s"),
+ error->message);
+ gtk_window_present (GTK_WINDOW (msg));
+ g_signal_connect (msg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+ }
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
+}
diff --git a/src/libsysprof-ui/sysprof-display.h b/src/libsysprof-ui/sysprof-display.h
index 5826ab8..6bdd43b 100644
--- a/src/libsysprof-ui/sysprof-display.h
+++ b/src/libsysprof-ui/sysprof-display.h
@@ -51,5 +51,7 @@ gboolean sysprof_display_is_empty (SysprofDisplay *self);
SYSPROF_AVAILABLE_IN_ALL
void sysprof_display_open (SysprofDisplay *self,
GFile *file);
+SYSPROF_AVAILABLE_IN_ALL
+void sysprof_display_save (SysprofDisplay *self);
G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-notebook.c b/src/libsysprof-ui/sysprof-notebook.c
index bf89928..30a0aac 100644
--- a/src/libsysprof-ui/sysprof-notebook.c
+++ b/src/libsysprof-ui/sysprof-notebook.c
@@ -160,3 +160,27 @@ sysprof_notebook_open (SysprofNotebook *self,
sysprof_display_open (SYSPROF_DISPLAY (display), file);
}
+
+static SysprofDisplay *
+sysprof_notebook_get_current (SysprofNotebook *self)
+{
+ gint page;
+
+ g_assert (SYSPROF_IS_NOTEBOOK (self));
+
+ if ((page = gtk_notebook_get_current_page (GTK_NOTEBOOK (self))) >= 0)
+ return SYSPROF_DISPLAY (gtk_notebook_get_nth_page (GTK_NOTEBOOK (self), page));
+
+ return NULL;
+}
+
+void
+sysprof_notebook_save (SysprofNotebook *self)
+{
+ SysprofDisplay *display;
+
+ g_return_if_fail (SYSPROF_IS_NOTEBOOK (self));
+
+ if ((display = sysprof_notebook_get_current (self)))
+ sysprof_display_save (display);
+}
diff --git a/src/libsysprof-ui/sysprof-notebook.h b/src/libsysprof-ui/sysprof-notebook.h
index de3cfc1..c3f3d3d 100644
--- a/src/libsysprof-ui/sysprof-notebook.h
+++ b/src/libsysprof-ui/sysprof-notebook.h
@@ -46,5 +46,7 @@ void sysprof_notebook_close_current (SysprofNotebook *self);
SYSPROF_AVAILABLE_IN_ALL
void sysprof_notebook_open (SysprofNotebook *self,
GFile *file);
+SYSPROF_AVAILABLE_IN_ALL
+void sysprof_notebook_save (SysprofNotebook *self);
G_END_DECLS
diff --git a/src/sysprof/gtk/menus.ui b/src/sysprof/gtk/menus.ui
index 3f9aa3d..88e380a 100644
--- a/src/sysprof/gtk/menus.ui
+++ b/src/sysprof/gtk/menus.ui
@@ -20,6 +20,13 @@
<attribute name="accel"><primary>o</attribute>
</item>
</section>
+ <section id="win-menu-save">
+ <item>
+ <attribute name="label" translatable="yes">Save Captureā¦</attribute>
+ <attribute name="action">win.save-capture</attribute>
+ <attribute name="accel"><primary>s</attribute>
+ </item>
+ </section>
<section id="win-menu-close">
<item>
<attribute name="label" translatable="yes">Close</attribute>
diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c
index 98e4f24..7ef7226 100644
--- a/src/sysprof/sysprof-window.c
+++ b/src/sysprof/sysprof-window.c
@@ -105,6 +105,17 @@ close_tab_cb (GSimpleAction *action,
sysprof_notebook_close_current (self->notebook);
}
+static void
+save_capture_cb (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ SysprofWindow *self = user_data;
+
+ g_return_if_fail (SYSPROF_IS_WINDOW (self));
+
+ sysprof_notebook_save (self->notebook);
+}
static void
sysprof_window_class_init (SysprofWindowClass *klass)
@@ -127,6 +138,7 @@ sysprof_window_init (SysprofWindow *self)
{ "close-tab", close_tab_cb },
{ "new-tab", new_tab_cb },
{ "switch-tab", switch_tab_cb, "i" },
+ { "save-capture", save_capture_cb },
};
gtk_widget_init_template (GTK_WIDGET (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]