talkatu/talkatu

A few random tweaks to TalkatuHistory
gtk4
2022-02-02, Gary Kramlich
7baf8643ecb6
Parents 68f23f6ebc61
Children a315690c201a
A few random tweaks to TalkatuHistory

The big take away here is that we unparent our children during our dispose.

Testing Done:
Ran the demo and verified that the warning about history still having a child was gone.

Reviewed at https://reviews.imfreedom.org/r/1278/
--- a/talkatu/data/history.ui Wed Feb 02 02:46:24 2022 -0600
+++ b/talkatu/data/history.ui Wed Feb 02 02:55:48 2022 -0600
@@ -24,8 +24,7 @@
<!-- interface-copyright Gary Kramlich <grim@reaperworld.com> -->
<template class="TalkatuHistory" parent="GtkWidget">
<child>
- <object class="GtkListBox" id="list_box">
- </object>
+ <object class="GtkListBox" id="list_box"/>
</child>
</template>
</interface>
--- a/talkatu/talkatuhistory.c Wed Feb 02 02:46:24 2022 -0600
+++ b/talkatu/talkatuhistory.c Wed Feb 02 02:55:48 2022 -0600
@@ -20,7 +20,6 @@
#include <talkatu/talkatuhistory.h>
-#include <talkatu/talkatuattachmentpreview.h>
#include <talkatu/talkatuhistoryrow.h>
#include <talkatu/talkatumessage.h>
@@ -32,23 +31,35 @@
struct _TalkatuHistory {
GtkWidget parent;
- GtkListBox *list_box;
+ GtkWidget *list_box;
};
G_DEFINE_TYPE(TalkatuHistory, talkatu_history, GTK_TYPE_WIDGET)
/******************************************************************************
- * GObject Stuff
+ * GObject Implementation
*****************************************************************************/
static void
+talkatu_history_dispose(GObject *obj) {
+ TalkatuHistory *history = TALKATU_HISTORY(obj);
+
+ g_clear_pointer(&history->list_box, gtk_widget_unparent);
+
+ G_OBJECT_CLASS(talkatu_history_parent_class)->dispose(obj);
+}
+
+static void
talkatu_history_init(TalkatuHistory *history) {
gtk_widget_init_template(GTK_WIDGET(history));
}
static void
talkatu_history_class_init(TalkatuHistoryClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+ obj_class->dispose = talkatu_history_dispose;
+
gtk_widget_class_set_template_from_resource(
widget_class,
"/org/imfreedom/keep/talkatu/talkatu/ui/history.ui"
@@ -72,10 +83,7 @@
* Returns: (transfer full): The new #TalkatuHistory instance.
*/
GtkWidget *talkatu_history_new(void) {
- return g_object_new(
- TALKATU_TYPE_HISTORY,
- NULL
- );
+ return g_object_new(TALKATU_TYPE_HISTORY, NULL);
}
/**