#include "config.h" #include "totem-time-label.h" #include #include "video-utils.h" static void totem_time_label_class_init (TotemTimeLabelClass *class); static void totem_time_label_init (TotemTimeLabel *label); struct _TotemTimeLabelPrivate { gint64 time; gint64 length; gboolean seeking; }; G_DEFINE_TYPE (TotemTimeLabel, totem_time_label, GTK_TYPE_LABEL) #define TOTEM_TIME_LABEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TOTEM_TYPE_TIME_LABEL, TotemTimeLabelPrivate)) static void totem_time_label_init (TotemTimeLabel *label) { char *time; label->priv = G_TYPE_INSTANCE_GET_PRIVATE (label, TOTEM_TYPE_TIME_LABEL, TotemTimeLabelPrivate); time = totem_time_to_string (0); gtk_label_set_text (GTK_LABEL (label), time); g_free (time); label->priv->time = 0; label->priv->length = -1; label->priv->seeking = FALSE; } GtkWidget* totem_time_label_new (void) { return GTK_WIDGET (g_object_new (TOTEM_TYPE_TIME_LABEL, NULL)); } static void totem_time_label_class_init (TotemTimeLabelClass *klass) { g_type_class_add_private (klass, sizeof (TotemTimeLabelPrivate)); } void totem_time_label_set_time (TotemTimeLabel *label, gint64 time, gint64 length) { char *label_str; g_return_if_fail (TOTEM_IS_TIME_LABEL (label)); if (time / 1000 == label->priv->time / 1000 && length / 1000 == label->priv->length / 1000) return; if (length <= 0) { label_str = totem_time_to_string (time); } else { char *time_str, *length_str; time_str = totem_time_to_string (time); length_str = totem_time_to_string (length); if (label->priv->seeking == FALSE) /* Elapsed / Total Length */ label_str = g_strdup_printf (_("%s / %s"), time_str, length_str); else /* Seeking to Time / Total Length */ label_str = g_strdup_printf (_("Seek to %s / %s"), time_str, length_str); g_free (time_str); g_free (length_str); } gtk_label_set_text (GTK_LABEL (label), label_str); g_free (label_str); label->priv->time = time; label->priv->length = length; } void totem_time_label_set_seeking (TotemTimeLabel *label, gboolean seeking) { g_return_if_fail (TOTEM_IS_TIME_LABEL (label)); label->priv->seeking = seeking; }