[totem/wip/hadess/widget-cleanup] main: Simplify BaconTimeLabel creation
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/widget-cleanup] main: Simplify BaconTimeLabel creation
- Date: Tue, 8 Feb 2022 14:31:39 +0000 (UTC)
commit 7298b907995cd4bb19b7eae8ddd5c0db394c931e
Author: Bastien Nocera <hadess hadess net>
Date: Tue Feb 8 15:27:24 2022 +0100
main: Simplify BaconTimeLabel creation
Use G_DECLARE_FINAL_TYPE(), and remove intermediate private struct.
src/backend/bacon-time-label.c | 32 +++++++++++++++-----------------
src/backend/bacon-time-label.h | 23 ++---------------------
2 files changed, 17 insertions(+), 38 deletions(-)
---
diff --git a/src/backend/bacon-time-label.c b/src/backend/bacon-time-label.c
index a7d25205d..58cb636ce 100644
--- a/src/backend/bacon-time-label.c
+++ b/src/backend/bacon-time-label.c
@@ -25,13 +25,13 @@
#include <glib/gi18n.h>
#include "totem-time-helpers.h"
-struct _BaconTimeLabelPrivate {
+struct _BaconTimeLabel {
gint64 time;
gint64 length;
gboolean remaining;
};
-G_DEFINE_TYPE_WITH_PRIVATE (BaconTimeLabel, bacon_time_label, GTK_TYPE_LABEL)
+G_DEFINE_TYPE(BaconTimeLabel, bacon_time_label, GTK_TYPE_LABEL)
enum {
PROP_0,
@@ -44,8 +44,6 @@ bacon_time_label_init (BaconTimeLabel *label)
char *time_string;
PangoAttrList *attrs;
- label->priv = bacon_time_label_get_instance_private (label);
-
time_string = totem_time_to_string (0, FALSE, FALSE);
gtk_label_set_text (GTK_LABEL (label), time_string);
g_free (time_string);
@@ -55,9 +53,9 @@ bacon_time_label_init (BaconTimeLabel *label)
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
- label->priv->time = 0;
- label->priv->length = -1;
- label->priv->remaining = FALSE;
+ label->time = 0;
+ label->length = -1;
+ label->remaining = FALSE;
}
GtkWidget *
@@ -103,22 +101,22 @@ update_label_text (BaconTimeLabel *label)
gboolean force_hour = FALSE;
gint64 _time, length;
- _time = label->priv->time;
- length = label->priv->length;
+ _time = label->time;
+ length = label->length;
if (length > 60 * 60 * 1000)
force_hour = TRUE;
if (length <= 0 ||
_time > length) {
- if (!label->priv->remaining) {
+ if (!label->remaining) {
label_str = totem_time_to_string (_time, FALSE, force_hour);
} else {
/* translators: Unknown remaining time */
label_str = g_strdup (_("--:--"));
}
} else {
- if (!label->priv->remaining) {
+ if (!label->remaining) {
/* Elapsed */
label_str = totem_time_to_string (_time, FALSE, force_hour);
} else {
@@ -138,16 +136,16 @@ bacon_time_label_set_time (BaconTimeLabel *label,
{
g_return_if_fail (BACON_IS_TIME_LABEL (label));
- if (label->priv->length == -1 &&
+ if (label->length == -1 &&
length == -1)
return;
- if (_time / 1000 == label->priv->time / 1000 &&
- length / 1000 == label->priv->length / 1000)
+ if (_time / 1000 == label->time / 1000 &&
+ length / 1000 == label->length / 1000)
return;
- label->priv->time = _time;
- label->priv->length = length;
+ label->time = _time;
+ label->length = length;
update_label_text (label);
}
@@ -158,6 +156,6 @@ bacon_time_label_set_remaining (BaconTimeLabel *label,
{
g_return_if_fail (BACON_IS_TIME_LABEL (label));
- label->priv->remaining = remaining;
+ label->remaining = remaining;
update_label_text (label);
}
diff --git a/src/backend/bacon-time-label.h b/src/backend/bacon-time-label.h
index 5ad74a1cb..101e7517d 100644
--- a/src/backend/bacon-time-label.h
+++ b/src/backend/bacon-time-label.h
@@ -19,29 +19,12 @@
*
*/
-#ifndef BACON_TIME_LABEL_H
-#define BACON_TIME_LABEL_H
+#pragma once
#include <gtk/gtk.h>
#define BACON_TYPE_TIME_LABEL (bacon_time_label_get_type ())
-#define BACON_TIME_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BACON_TYPE_TIME_LABEL,
BaconTimeLabel))
-#define BACON_TIME_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BACON_TYPE_TIME_LABEL,
BaconTimeLabelClass))
-#define BACON_IS_TIME_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BACON_TYPE_TIME_LABEL))
-#define BACON_IS_TIME_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BACON_TYPE_TIME_LABEL))
-
-typedef struct BaconTimeLabel BaconTimeLabel;
-typedef struct BaconTimeLabelClass BaconTimeLabelClass;
-typedef struct _BaconTimeLabelPrivate BaconTimeLabelPrivate;
-
-struct BaconTimeLabel {
- GtkLabel parent;
- BaconTimeLabelPrivate *priv;
-};
-
-struct BaconTimeLabelClass {
- GtkLabelClass parent_class;
-};
+G_DECLARE_FINAL_TYPE(BaconTimeLabel, bacon_time_label, BACON, TIME_LABEL, GtkLabel)
G_MODULE_EXPORT GType bacon_time_label_get_type (void);
GtkWidget *bacon_time_label_new (void);
@@ -51,5 +34,3 @@ void bacon_time_label_set_time (BaconTimeLabel *label,
void
bacon_time_label_set_remaining (BaconTimeLabel *label,
gboolean remaining);
-
-#endif /* BACON_TIME_LABEL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]