diff --git a/src/libsysprof-ui/libsysprof-ui.gresource.xml b/src/libsysprof-ui/libsysprof-ui.gresource.xml
index 46b0c6e1..c3e80a0a 100644
--- a/src/libsysprof-ui/libsysprof-ui.gresource.xml
+++ b/src/libsysprof-ui/libsysprof-ui.gresource.xml
@@ -25,6 +25,7 @@
ui/sysprof-profiler-menu-button.ui
ui/sysprof-recording-state-view.ui
ui/sysprof-tab.ui
+ ui/sysprof-time-label.ui
ui/sysprof-visualizer-view.ui
diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build
index f6ee0979..9ee8c6c6 100644
--- a/src/libsysprof-ui/meson.build
+++ b/src/libsysprof-ui/meson.build
@@ -42,6 +42,7 @@ libsysprof_ui_private_sources = [
'sysprof-environ-variable.c',
'sysprof-environ.c',
'sysprof-tab.c',
+ 'sysprof-time-label.c',
'sysprof-theme-manager.c',
'../stackstash.c',
]
diff --git a/src/libsysprof-ui/sysprof-recording-state-view.c b/src/libsysprof-ui/sysprof-recording-state-view.c
index 687f728f..a5eb8c91 100644
--- a/src/libsysprof-ui/sysprof-recording-state-view.c
+++ b/src/libsysprof-ui/sysprof-recording-state-view.c
@@ -21,13 +21,14 @@
#include "config.h"
#include "sysprof-recording-state-view.h"
+#include "sysprof-time-label.h"
typedef struct
{
- SysprofProfiler *profiler;
- GtkLabel *elapsed;
- GtkLabel *samples;
- gulong notify_elapsed_handler;
+ SysprofProfiler *profiler;
+ SysprofTimeLabel *elapsed;
+ GtkLabel *samples;
+ gulong notify_elapsed_handler;
} SysprofRecordingStateViewPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (SysprofRecordingStateView, sysprof_recording_state_view, GTK_TYPE_BIN)
@@ -55,9 +56,6 @@ sysprof_recording_state_view_notify_elapsed (SysprofRecordingStateView *self,
g_autofree gchar *str = NULL;
SysprofCaptureWriter *writer;
gint64 elapsed;
- guint hours;
- guint minutes;
- guint seconds;
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
g_assert (SYSPROF_IS_PROFILER (profiler));
@@ -78,20 +76,7 @@ sysprof_recording_state_view_notify_elapsed (SysprofRecordingStateView *self,
}
elapsed = (gint64)sysprof_profiler_get_elapsed (profiler);
-
- hours = elapsed / (60 * 60);
- if (hours > 0)
- minutes = (elapsed % (hours * 60 * 60)) / 60;
- else
- minutes = elapsed / 60;
- seconds = elapsed % 60;
-
- if (hours == 0)
- str = g_strdup_printf ("%02u:%02u", minutes, seconds);
- else
- str = g_strdup_printf ("%02u:%02u:%02u", hours, minutes, seconds);
-
- gtk_label_set_label (priv->elapsed, str);
+ sysprof_time_label_set_duration (priv->elapsed, elapsed);
}
static void
@@ -168,10 +153,11 @@ sysprof_recording_state_view_class_init (SysprofRecordingStateViewClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gnome/sysprof/ui/sysprof-recording-state-view.ui");
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-recording-state-view.ui");
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, elapsed);
gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, samples);
+
+ g_type_ensure (SYSPROF_TYPE_TIME_LABEL);
}
static void
@@ -189,7 +175,7 @@ sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self,
g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self));
g_assert (!profiler || SYSPROF_IS_PROFILER (profiler));
- gtk_label_set_label (priv->elapsed, "00:00");
+ sysprof_time_label_set_duration (priv->elapsed, 0);
if (profiler != priv->profiler)
{
@@ -199,8 +185,6 @@ sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self,
g_clear_object (&priv->profiler);
}
- gtk_label_set_label (priv->elapsed, "00:00");
-
if (profiler != NULL)
{
priv->profiler = g_object_ref (profiler);
diff --git a/src/libsysprof-ui/sysprof-time-label.c b/src/libsysprof-ui/sysprof-time-label.c
new file mode 100644
index 00000000..eac8898b
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-time-label.c
@@ -0,0 +1,103 @@
+/* sysprof-time-label.c
+ *
+ * Copyright 2019 Christian Hergert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "sysprof-time-label"
+
+#include "config.h"
+
+#include "sysprof-time-label.h"
+
+#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
+
+struct _SysprofTimeLabel
+{
+ GtkBox parent;
+
+ GtkLabel *minutes;
+ GtkLabel *seconds;
+};
+
+G_DEFINE_TYPE (SysprofTimeLabel, sysprof_time_label, GTK_TYPE_BOX)
+
+static void
+sysprof_time_label_class_init (SysprofTimeLabelClass *klass)
+{
+}
+
+static void
+sysprof_time_label_init (SysprofTimeLabel *self)
+{
+ PangoAttrList *attrs = pango_attr_list_new ();
+ GtkWidget *sep;
+
+ pango_attr_list_insert (attrs, pango_attr_scale_new (4));
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+
+ gtk_box_set_spacing (GTK_BOX (self), 3);
+
+ self->minutes = g_object_new (GTK_TYPE_LABEL,
+ "attributes", attrs,
+ "visible", TRUE,
+ "xalign", 1.0f,
+ NULL);
+ gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (self->minutes),
+ "pack-type", GTK_PACK_START,
+ "expand", TRUE,
+ "fill", TRUE,
+ NULL);
+
+ sep = g_object_new (GTK_TYPE_LABEL,
+ "attributes", attrs,
+ "visible", TRUE,
+ "label", ":",
+ NULL);
+ gtk_box_set_center_widget (GTK_BOX (self), sep);
+
+ self->seconds = g_object_new (GTK_TYPE_LABEL,
+ "attributes", attrs,
+ "visible", TRUE,
+ "xalign", 0.0f,
+ NULL);
+ gtk_container_add_with_properties (GTK_CONTAINER (self), GTK_WIDGET (self->seconds),
+ "pack-type", GTK_PACK_END,
+ "expand", TRUE,
+ "fill", TRUE,
+ NULL);
+}
+
+void
+sysprof_time_label_set_duration (SysprofTimeLabel *self,
+ guint duration)
+{
+ gchar minstr[12];
+ gchar secstr[12];
+ gint min, sec;
+
+ g_return_if_fail (SYSPROF_IS_TIME_LABEL (self));
+
+ min = duration / 60;
+ sec = duration % 60;
+
+ g_snprintf (minstr, sizeof minstr, "%02d", min);
+ g_snprintf (secstr, sizeof secstr, "%02d", sec);
+
+ gtk_label_set_label (self->minutes, minstr);
+ gtk_label_set_label (self->seconds, secstr);
+}
diff --git a/src/libsysprof-ui/sysprof-time-label.h b/src/libsysprof-ui/sysprof-time-label.h
new file mode 100644
index 00000000..7d4304c8
--- /dev/null
+++ b/src/libsysprof-ui/sysprof-time-label.h
@@ -0,0 +1,34 @@
+/* sysprof-time-label.h
+ *
+ * Copyright 2019 Christian Hergert
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include
+
+G_BEGIN_DECLS
+
+#define SYSPROF_TYPE_TIME_LABEL (sysprof_time_label_get_type())
+
+G_DECLARE_FINAL_TYPE (SysprofTimeLabel, sysprof_time_label, SYSPROF, TIME_LABEL, GtkBox)
+
+void sysprof_time_label_set_duration (SysprofTimeLabel *self,
+ guint duration);
+
+G_END_DECLS
diff --git a/src/libsysprof-ui/ui/sysprof-recording-state-view.ui b/src/libsysprof-ui/ui/sysprof-recording-state-view.ui
index 4b42b7dc..08f06ae1 100644
--- a/src/libsysprof-ui/ui/sysprof-recording-state-view.ui
+++ b/src/libsysprof-ui/ui/sysprof-recording-state-view.ui
@@ -20,17 +20,11 @@
-
diff --git a/src/libsysprof-ui/ui/sysprof-time-label.ui b/src/libsysprof-ui/ui/sysprof-time-label.ui
new file mode 100644
index 00000000..d23376d7
--- /dev/null
+++ b/src/libsysprof-ui/ui/sysprof-time-label.ui
@@ -0,0 +1,50 @@
+
+
+
+
+
+ False
+ 2
+
+
+ True
+ False
+ :
+
+
+ False
+ True
+ 3
+
+
+
+
+ True
+ False
+ 00
+ 2
+ 1
+
+
+ True
+ True
+ 2
+
+
+
+
+ True
+ False
+ 00
+ 2
+ 0
+
+
+ True
+ True
+ end
+ 4
+
+
+
+