mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-ui: start on open support
This commit is contained in:
@ -35,9 +35,15 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
GFile *file;
|
||||||
|
SysprofProfiler *profiler;
|
||||||
|
|
||||||
|
/* Template Objects */
|
||||||
SysprofCaptureView *capture_view;
|
SysprofCaptureView *capture_view;
|
||||||
|
SysprofEmptyStateView *failed_view;
|
||||||
SysprofEmptyStateView *empty_view;
|
SysprofEmptyStateView *empty_view;
|
||||||
SysprofRecordingStateView *recording_view;
|
SysprofRecordingStateView *recording_view;
|
||||||
|
GtkStack *stack;
|
||||||
} SysprofDisplayPrivate;
|
} SysprofDisplayPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (SysprofDisplay, sysprof_display, GTK_TYPE_BIN)
|
G_DEFINE_TYPE_WITH_PRIVATE (SysprofDisplay, sysprof_display, GTK_TYPE_BIN)
|
||||||
@ -73,6 +79,9 @@ sysprof_display_dup_title (SysprofDisplay *self)
|
|||||||
|
|
||||||
g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL);
|
g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL);
|
||||||
|
|
||||||
|
if (priv->file != NULL)
|
||||||
|
return g_file_get_basename (priv->file);
|
||||||
|
|
||||||
if ((reader = sysprof_capture_view_get_reader (priv->capture_view)))
|
if ((reader = sysprof_capture_view_get_reader (priv->capture_view)))
|
||||||
{
|
{
|
||||||
const gchar *filename;
|
const gchar *filename;
|
||||||
@ -88,6 +97,11 @@ sysprof_display_dup_title (SysprofDisplay *self)
|
|||||||
static void
|
static void
|
||||||
sysprof_display_finalize (GObject *object)
|
sysprof_display_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
|
SysprofDisplay *self = (SysprofDisplay *)object;
|
||||||
|
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||||
|
|
||||||
|
g_clear_object (&priv->profiler);
|
||||||
|
|
||||||
G_OBJECT_CLASS (sysprof_display_parent_class)->finalize (object);
|
G_OBJECT_CLASS (sysprof_display_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +157,11 @@ sysprof_display_class_init (SysprofDisplayClass *klass)
|
|||||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-display.ui");
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-display.ui");
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay , empty_view);
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, capture_view);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay , recording_view);
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, empty_view);
|
||||||
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay , capture_view);
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, failed_view);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, recording_view);
|
||||||
|
gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, stack);
|
||||||
|
|
||||||
g_type_ensure (SYSPROF_TYPE_CAPTURE_VIEW);
|
g_type_ensure (SYSPROF_TYPE_CAPTURE_VIEW);
|
||||||
g_type_ensure (SYSPROF_TYPE_EMPTY_STATE_VIEW);
|
g_type_ensure (SYSPROF_TYPE_EMPTY_STATE_VIEW);
|
||||||
@ -157,3 +173,113 @@ sysprof_display_init (SysprofDisplay *self)
|
|||||||
{
|
{
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_display_get_profiler:
|
||||||
|
*
|
||||||
|
* Gets the proflier for the display.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none) (nullable): a #SysprofProfiler or %NULL
|
||||||
|
*
|
||||||
|
* Since: 3.34
|
||||||
|
*/
|
||||||
|
SysprofProfiler *
|
||||||
|
sysprof_display_get_profiler (SysprofDisplay *self)
|
||||||
|
{
|
||||||
|
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||||
|
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL);
|
||||||
|
|
||||||
|
return priv->profiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_display_is_empty:
|
||||||
|
*
|
||||||
|
* Checks if any content is or will be loaded into @self.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the tab is unperterbed.
|
||||||
|
*
|
||||||
|
* Since: 3.34
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
sysprof_display_is_empty (SysprofDisplay *self)
|
||||||
|
{
|
||||||
|
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||||
|
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE);
|
||||||
|
|
||||||
|
return priv->file == NULL &&
|
||||||
|
priv->profiler == NULL &&
|
||||||
|
NULL == sysprof_capture_view_get_reader (priv->capture_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_display_open_cb (GObject *object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofDisplay) self = user_data;
|
||||||
|
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||||
|
g_autoptr(SysprofCaptureReader) reader = NULL;
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_IS_DISPLAY (self));
|
||||||
|
g_assert (G_IS_TASK (result));
|
||||||
|
|
||||||
|
if (!(reader = g_task_propagate_pointer (G_TASK (result), &error)))
|
||||||
|
{
|
||||||
|
gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->failed_view));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sysprof_capture_view_load_async (priv->capture_view, reader, NULL, NULL, NULL);
|
||||||
|
gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->capture_view));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_display_open_worker (GTask *task,
|
||||||
|
gpointer source_object,
|
||||||
|
gpointer task_data,
|
||||||
|
GCancellable *cancellable)
|
||||||
|
{
|
||||||
|
g_autofree gchar *path = NULL;
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
SysprofCaptureReader *reader;
|
||||||
|
GFile *file = task_data;
|
||||||
|
|
||||||
|
g_assert (G_IS_TASK (task));
|
||||||
|
g_assert (source_object == NULL);
|
||||||
|
g_assert (G_IS_FILE (file));
|
||||||
|
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
path = g_file_get_path (file);
|
||||||
|
|
||||||
|
if (!(reader = sysprof_capture_reader_new (path, &error)))
|
||||||
|
g_task_return_error (task, g_steal_pointer ((&error)));
|
||||||
|
else
|
||||||
|
g_task_return_pointer (task,
|
||||||
|
g_steal_pointer (&reader),
|
||||||
|
(GDestroyNotify) sysprof_capture_reader_unref);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_display_open (SysprofDisplay *self,
|
||||||
|
GFile *file)
|
||||||
|
{
|
||||||
|
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||||
|
g_autoptr(GTask) task = NULL;
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_DISPLAY (self));
|
||||||
|
g_return_if_fail (G_IS_FILE (file));
|
||||||
|
g_return_if_fail (g_file_is_native (file));
|
||||||
|
g_return_if_fail (sysprof_display_is_empty (self));
|
||||||
|
|
||||||
|
g_set_object (&priv->file, file);
|
||||||
|
|
||||||
|
task = g_task_new (NULL, NULL, sysprof_display_open_cb, g_object_ref (self));
|
||||||
|
g_task_set_task_data (task, g_file_dup (file), g_object_unref);
|
||||||
|
g_task_run_in_thread (task, sysprof_display_open_worker);
|
||||||
|
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]);
|
||||||
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <sysprof.h>
|
||||||
|
|
||||||
#include "sysprof-version-macros.h"
|
#include "sysprof-version-macros.h"
|
||||||
|
|
||||||
@ -40,6 +41,13 @@ struct _SysprofDisplayClass
|
|||||||
} __attribute__((aligned(8)));
|
} __attribute__((aligned(8)));
|
||||||
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GtkWidget *sysprof_display_new (void);
|
GtkWidget *sysprof_display_new (void);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
SysprofProfiler *sysprof_display_get_profiler (SysprofDisplay *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
gboolean sysprof_display_is_empty (SysprofDisplay *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_display_open (SysprofDisplay *self,
|
||||||
|
GFile *file);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -83,6 +83,9 @@ sysprof_notebook_page_removed (GtkNotebook *notebook,
|
|||||||
g_assert (SYSPROF_IS_NOTEBOOK (notebook));
|
g_assert (SYSPROF_IS_NOTEBOOK (notebook));
|
||||||
g_assert (GTK_IS_WIDGET (child));
|
g_assert (GTK_IS_WIDGET (child));
|
||||||
|
|
||||||
|
if (gtk_widget_in_destruction (GTK_WIDGET (notebook)))
|
||||||
|
return;
|
||||||
|
|
||||||
if (gtk_notebook_get_n_pages (notebook) == 0)
|
if (gtk_notebook_get_n_pages (notebook) == 0)
|
||||||
{
|
{
|
||||||
child = sysprof_display_new ();
|
child = sysprof_display_new ();
|
||||||
@ -165,3 +168,51 @@ sysprof_notebook_close_current (SysprofNotebook *self)
|
|||||||
if ((page = gtk_notebook_get_current_page (GTK_NOTEBOOK (self))) >= 0)
|
if ((page = gtk_notebook_get_current_page (GTK_NOTEBOOK (self))) >= 0)
|
||||||
gtk_widget_destroy (gtk_notebook_get_nth_page (GTK_NOTEBOOK (self), page));
|
gtk_widget_destroy (gtk_notebook_get_nth_page (GTK_NOTEBOOK (self), page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
find_empty_display_cb (GtkWidget *widget,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GtkWidget **display = user_data;
|
||||||
|
|
||||||
|
g_assert (GTK_IS_WIDGET (widget));
|
||||||
|
g_assert (display != NULL);
|
||||||
|
|
||||||
|
if (*display != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (SYSPROF_IS_DISPLAY (widget) &&
|
||||||
|
sysprof_display_is_empty (SYSPROF_DISPLAY (widget)))
|
||||||
|
*display = widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_notebook_open (SysprofNotebook *self,
|
||||||
|
GFile *file)
|
||||||
|
{
|
||||||
|
GtkWidget *display = NULL;
|
||||||
|
gint page;
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_NOTEBOOK (self));
|
||||||
|
g_return_if_fail (g_file_is_native (file));
|
||||||
|
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (self),
|
||||||
|
find_empty_display_cb,
|
||||||
|
&display);
|
||||||
|
|
||||||
|
if (display == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
display = sysprof_display_new ();
|
||||||
|
page = gtk_notebook_insert_page (GTK_NOTEBOOK (self), display, NULL, -1);
|
||||||
|
gtk_widget_show (display);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
page = gtk_notebook_page_num (GTK_NOTEBOOK (self), display);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (self), page);
|
||||||
|
|
||||||
|
sysprof_display_open (SYSPROF_DISPLAY (display), file);
|
||||||
|
}
|
||||||
|
|||||||
@ -43,5 +43,8 @@ SYSPROF_AVAILABLE_IN_ALL
|
|||||||
GtkWidget *sysprof_notebook_new (void);
|
GtkWidget *sysprof_notebook_new (void);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_notebook_close_current (SysprofNotebook *self);
|
void sysprof_notebook_close_current (SysprofNotebook *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_notebook_open (SysprofNotebook *self,
|
||||||
|
GFile *file);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -31,6 +31,17 @@
|
|||||||
<property name="name">recording</property>
|
<property name="name">recording</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="SysprofEmptyStateView" id="failed_view">
|
||||||
|
<property name="icon-name">computer-fail-symbolic</property>
|
||||||
|
<property name="title" translatable="yes">Something went wrong</property>
|
||||||
|
<property name="subtitle" translatable="yes">Sysprof failed to access the requested performance data.</property>
|
||||||
|
<property name="visible">true</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">failed</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib/gi18n.h>
|
||||||
#include <sysprof-ui.h>
|
#include <sysprof-ui.h>
|
||||||
|
|
||||||
#include "sysprof-window.h"
|
#include "sysprof-window.h"
|
||||||
@ -134,13 +135,50 @@ sysprof_window_open (SysprofWindow *self,
|
|||||||
g_return_if_fail (SYSPROF_IS_WINDOW (self));
|
g_return_if_fail (SYSPROF_IS_WINDOW (self));
|
||||||
g_return_if_fail (G_IS_FILE (file));
|
g_return_if_fail (G_IS_FILE (file));
|
||||||
|
|
||||||
|
sysprof_notebook_open (self->notebook, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sysprof_window_open_from_dialog (SysprofWindow *self)
|
sysprof_window_open_from_dialog (SysprofWindow *self)
|
||||||
{
|
{
|
||||||
|
GtkFileChooserNative *dialog;
|
||||||
|
GtkFileFilter *filter;
|
||||||
|
gint response;
|
||||||
|
|
||||||
g_return_if_fail (SYSPROF_IS_WINDOW (self));
|
g_return_if_fail (SYSPROF_IS_WINDOW (self));
|
||||||
|
|
||||||
|
/* Translators: This is a window title. */
|
||||||
|
dialog = gtk_file_chooser_native_new (_("Open Capture…"),
|
||||||
|
GTK_WINDOW (self),
|
||||||
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
/* Translators: This is a button. */
|
||||||
|
_("Open"),
|
||||||
|
/* Translators: This is a button. */
|
||||||
|
_("Cancel"));
|
||||||
|
|
||||||
|
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
|
||||||
|
|
||||||
|
filter = gtk_file_filter_new ();
|
||||||
|
gtk_file_filter_set_name (filter, _("Sysprof Captures"));
|
||||||
|
gtk_file_filter_add_pattern (filter, "*.syscap");
|
||||||
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
|
||||||
|
|
||||||
|
filter = gtk_file_filter_new ();
|
||||||
|
gtk_file_filter_set_name (filter, _("All Files"));
|
||||||
|
gtk_file_filter_add_pattern (filter, "*");
|
||||||
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
|
||||||
|
|
||||||
|
response = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
|
||||||
|
|
||||||
|
if (response == GTK_RESPONSE_ACCEPT)
|
||||||
|
{
|
||||||
|
g_autoptr(GFile) file = NULL;
|
||||||
|
|
||||||
|
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
||||||
|
sysprof_window_open (self, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (dialog));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user