Skip to content

Commit

Permalink
Merge pull request #655 from mjakeman/comment-tile-date
Browse files Browse the repository at this point in the history
Add date to comment tiles
  • Loading branch information
mjakeman authored Jun 6, 2024
2 parents 984264a + ed44abc commit 95cd2e6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
28 changes: 22 additions & 6 deletions src/exm-comment-tile.blp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Gtk 4.0;
using Adw 1;

template $ExmCommentTile : Gtk.Widget {
styles ["comment-tile"]
template $ExmCommentTile: Gtk.Widget {
styles [
"comment-tile"
]

Gtk.Box {
orientation: vertical;
Expand All @@ -11,14 +12,20 @@ template $ExmCommentTile : Gtk.Widget {
orientation: horizontal;

Gtk.Label author {
styles ["dim-label"]
styles [
"heading"
]

xalign: 0;
label: bind template.comment as <$ExmComment>.author;
}

Gtk.Label author_badge {
styles ["author-badge"]
label: _("Author");
styles [
"author-badge"
]

label: _("Author");
visible: bind template.comment as <$ExmComment>.is_extension_creator;
}

Expand All @@ -31,5 +38,14 @@ template $ExmCommentTile : Gtk.Widget {
}

$TextDisplay display {}

Gtk.Label date {
styles [
"dim-label"
]

margin-top: 6;
xalign: 0;
}
}
}
18 changes: 15 additions & 3 deletions src/exm-comment-tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct _ExmCommentTile

GtkLabel *author;
GtkLabel *author_badge;
GtkLabel *date;
ExmRating *rating;
TextDisplay *display;
};
Expand All @@ -38,8 +39,6 @@ exm_comment_tile_new (ExmComment *comment)
static void
exm_comment_tile_finalize (GObject *object)
{
ExmCommentTile *self = (ExmCommentTile *)object;

G_OBJECT_CLASS (exm_comment_tile_parent_class)->finalize (object);
}

Expand Down Expand Up @@ -87,16 +86,28 @@ exm_comment_tile_constructed (GObject *object)
g_return_if_fail (EXM_IS_COMMENT (self->comment));

TextFrame *frame;
GDateTime *datetime;

gchar *text;
gchar *text, *date;
g_object_get (self->comment,
"comment", &text,
"date", &date,
NULL);

frame = format_parse_html (text);
g_free (text);

datetime = g_date_time_new_from_iso8601 (date, g_time_zone_new_utc ());
g_free (date);

g_object_set (self->display, "frame", frame, NULL);

if (datetime != NULL)
{
gtk_label_set_label (self->date, g_date_time_format (datetime, "%x"));
g_date_time_unref (datetime);
}

G_OBJECT_CLASS (exm_comment_tile_parent_class)->constructed (object);
}

Expand Down Expand Up @@ -126,6 +137,7 @@ exm_comment_tile_class_init (ExmCommentTileClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, display);
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, author);
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, author_badge);
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, date);
gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, rating);

gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
Expand Down
23 changes: 23 additions & 0 deletions src/web/model/exm-comment.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct _ExmComment
gchar *comment;
gchar *author;
int rating;
gchar *date;
};

static JsonSerializableIface *serializable_iface = NULL;
Expand All @@ -26,6 +27,7 @@ enum {
PROP_COMMENT,
PROP_AUTHOR,
PROP_RATING,
PROP_DATE,
N_PROPS
};

Expand Down Expand Up @@ -67,6 +69,9 @@ exm_comment_get_property (GObject *object,
case PROP_RATING:
g_value_set_int (value, self->rating);
break;
case PROP_DATE:
g_value_set_string (value, self->date);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand Down Expand Up @@ -94,6 +99,9 @@ exm_comment_set_property (GObject *object,
case PROP_RATING:
self->rating = g_value_get_int (value);
break;
case PROP_DATE:
self->date = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand Down Expand Up @@ -136,6 +144,13 @@ exm_comment_class_init (ExmCommentClass *klass)
-1, 5, -1, /* min -1, max 5, default -1 */
G_PARAM_READWRITE);

properties [PROP_DATE] =
g_param_spec_string ("date",
"Date",
"Date",
NULL,
G_PARAM_READWRITE);

g_object_class_install_properties (object_class, N_PROPS, properties);
}

Expand All @@ -161,6 +176,14 @@ exm_comment_deserialize_property (JsonSerializable *serializable,
g_value_set_string (value, json_object_get_string_member (obj, "username"));
return TRUE;
}
else if (strcmp (property_name, "date") == 0)
{
JsonObject *obj;

obj = json_node_get_object (property_node);
g_value_set_string (value, json_object_get_string_member (obj, "timestamp"));
return TRUE;
}

return serializable_iface->deserialize_property (serializable,
property_name,
Expand Down

0 comments on commit 95cd2e6

Please sign in to comment.