diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-15 11:38:15 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-15 11:38:15 +0100 |
commit | a0664a80213bcf5731c7ddf39d38f47171622960 (patch) | |
tree | b7da55bd57342c60df19b5bdd6620231787c59cc | |
parent | 760976b15f400194d9264a5295e27e70b88afb73 (diff) | |
download | messenger-gtk-a0664a80213bcf5731c7ddf39d38f47171622960.tar.gz messenger-gtk-a0664a80213bcf5731c7ddf39d38f47171622960.zip |
Fixed memory leaks regarding gtk builders
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/event.c | 2 | ||||
-rw-r--r-- | src/ui/chat.c | 26 | ||||
-rw-r--r-- | src/ui/chat.h | 1 | ||||
-rw-r--r-- | src/ui/chat_entry.c | 17 | ||||
-rw-r--r-- | src/ui/chat_entry.h | 13 | ||||
-rw-r--r-- | src/ui/message.c | 25 | ||||
-rw-r--r-- | src/ui/message.h | 16 | ||||
-rw-r--r-- | src/ui/messenger.c | 50 | ||||
-rw-r--r-- | src/ui/messenger.h | 1 | ||||
-rw-r--r-- | src/ui/new_contact.c | 14 | ||||
-rw-r--r-- | src/ui/new_contact.h | 11 | ||||
-rw-r--r-- | src/ui/new_platform.c | 34 | ||||
-rw-r--r-- | src/ui/new_platform.h | 16 |
13 files changed, 136 insertions, 90 deletions
diff --git a/src/event.c b/src/event.c index da5295e..6e585b2 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -201,7 +201,7 @@ event_receive_message(MESSENGER_Application *app, | |||
201 | message->message_box | 201 | message->message_box |
202 | ); | 202 | ); |
203 | 203 | ||
204 | g_free(message); // TODO: this is just a test! | 204 | ui_message_delete(message); |
205 | 205 | ||
206 | gtk_label_set_text(handle->text_label, text? text : ""); | 206 | gtk_label_set_text(handle->text_label, text? text : ""); |
207 | gtk_label_set_text(handle->timestamp_label, time? time : ""); | 207 | gtk_label_set_text(handle->timestamp_label, time? time : ""); |
diff --git a/src/ui/chat.c b/src/ui/chat.c index 7e5c1fc..b4dcca9 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -138,16 +138,16 @@ ui_chat_new(MESSENGER_Application *app) | |||
138 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); | 138 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); |
139 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); | 139 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); |
140 | 140 | ||
141 | GtkBuilder* builder = gtk_builder_new_from_file( | 141 | handle->builder = gtk_builder_new_from_file( |
142 | "resources/ui/chat.ui" | 142 | "resources/ui/chat.ui" |
143 | ); | 143 | ); |
144 | 144 | ||
145 | handle->chat_box = GTK_WIDGET( | 145 | handle->chat_box = GTK_WIDGET( |
146 | gtk_builder_get_object(builder, "chat_box") | 146 | gtk_builder_get_object(handle->builder, "chat_box") |
147 | ); | 147 | ); |
148 | 148 | ||
149 | handle->back_button = GTK_BUTTON( | 149 | handle->back_button = GTK_BUTTON( |
150 | gtk_builder_get_object(builder, "back_button") | 150 | gtk_builder_get_object(handle->builder, "back_button") |
151 | ); | 151 | ); |
152 | 152 | ||
153 | g_object_bind_property( | 153 | g_object_bind_property( |
@@ -166,15 +166,15 @@ ui_chat_new(MESSENGER_Application *app) | |||
166 | ); | 166 | ); |
167 | 167 | ||
168 | handle->chat_title = GTK_LABEL( | 168 | handle->chat_title = GTK_LABEL( |
169 | gtk_builder_get_object(builder, "chat_title") | 169 | gtk_builder_get_object(handle->builder, "chat_title") |
170 | ); | 170 | ); |
171 | 171 | ||
172 | handle->chat_subtitle = GTK_LABEL( | 172 | handle->chat_subtitle = GTK_LABEL( |
173 | gtk_builder_get_object(builder, "chat_subtitle") | 173 | gtk_builder_get_object(handle->builder, "chat_subtitle") |
174 | ); | 174 | ); |
175 | 175 | ||
176 | handle->chat_details_button = GTK_BUTTON( | 176 | handle->chat_details_button = GTK_BUTTON( |
177 | gtk_builder_get_object(builder, "chat_details_button") | 177 | gtk_builder_get_object(handle->builder, "chat_details_button") |
178 | ); | 178 | ); |
179 | 179 | ||
180 | g_signal_connect( | 180 | g_signal_connect( |
@@ -185,27 +185,27 @@ ui_chat_new(MESSENGER_Application *app) | |||
185 | ); | 185 | ); |
186 | 186 | ||
187 | handle->messages_listbox = GTK_LIST_BOX( | 187 | handle->messages_listbox = GTK_LIST_BOX( |
188 | gtk_builder_get_object(builder, "messages_listbox") | 188 | gtk_builder_get_object(handle->builder, "messages_listbox") |
189 | ); | 189 | ); |
190 | 190 | ||
191 | handle->attach_file_button = GTK_BUTTON( | 191 | handle->attach_file_button = GTK_BUTTON( |
192 | gtk_builder_get_object(builder, "attach_file_button") | 192 | gtk_builder_get_object(handle->builder, "attach_file_button") |
193 | ); | 193 | ); |
194 | 194 | ||
195 | handle->send_text_view = GTK_TEXT_VIEW( | 195 | handle->send_text_view = GTK_TEXT_VIEW( |
196 | gtk_builder_get_object(builder, "send_text_view") | 196 | gtk_builder_get_object(handle->builder, "send_text_view") |
197 | ); | 197 | ); |
198 | 198 | ||
199 | handle->emoji_button = GTK_BUTTON( | 199 | handle->emoji_button = GTK_BUTTON( |
200 | gtk_builder_get_object(builder, "emoji_button") | 200 | gtk_builder_get_object(handle->builder, "emoji_button") |
201 | ); | 201 | ); |
202 | 202 | ||
203 | handle->send_record_button = GTK_BUTTON( | 203 | handle->send_record_button = GTK_BUTTON( |
204 | gtk_builder_get_object(builder, "send_record_button") | 204 | gtk_builder_get_object(handle->builder, "send_record_button") |
205 | ); | 205 | ); |
206 | 206 | ||
207 | handle->send_record_symbol = GTK_IMAGE( | 207 | handle->send_record_symbol = GTK_IMAGE( |
208 | gtk_builder_get_object(builder, "send_record_symbol") | 208 | gtk_builder_get_object(handle->builder, "send_record_symbol") |
209 | ); | 209 | ); |
210 | 210 | ||
211 | GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer( | 211 | GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer( |
@@ -245,5 +245,7 @@ ui_chat_new(MESSENGER_Application *app) | |||
245 | void | 245 | void |
246 | ui_chat_delete(UI_CHAT_Handle *handle) | 246 | ui_chat_delete(UI_CHAT_Handle *handle) |
247 | { | 247 | { |
248 | g_object_unref(handle->builder); | ||
249 | |||
248 | g_free(handle); | 250 | g_free(handle); |
249 | } | 251 | } |
diff --git a/src/ui/chat.h b/src/ui/chat.h index 5415647..250ac08 100644 --- a/src/ui/chat.h +++ b/src/ui/chat.h | |||
@@ -33,6 +33,7 @@ typedef struct MESSENGER_Application MESSENGER_Application; | |||
33 | 33 | ||
34 | typedef struct UI_CHAT_Handle | 34 | typedef struct UI_CHAT_Handle |
35 | { | 35 | { |
36 | GtkBuilder *builder; | ||
36 | GtkWidget *chat_box; | 37 | GtkWidget *chat_box; |
37 | 38 | ||
38 | GtkButton *back_button; | 39 | GtkButton *back_button; |
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c index 3de1ada..21b793e 100644 --- a/src/ui/chat_entry.c +++ b/src/ui/chat_entry.c | |||
@@ -32,31 +32,30 @@ ui_chat_entry_new(MESSENGER_Application *app) | |||
32 | UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); | 32 | UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); |
33 | 33 | ||
34 | handle->chat = ui_chat_new(app); | 34 | handle->chat = ui_chat_new(app); |
35 | 35 | handle->builder = gtk_builder_new_from_file("resources/ui/chat_entry.ui"); | |
36 | GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/chat_entry.ui"); | ||
37 | 36 | ||
38 | handle->entry_box = GTK_WIDGET( | 37 | handle->entry_box = GTK_WIDGET( |
39 | gtk_builder_get_object(builder, "entry_box") | 38 | gtk_builder_get_object(handle->builder, "entry_box") |
40 | ); | 39 | ); |
41 | 40 | ||
42 | handle->entry_avatar = HDY_AVATAR( | 41 | handle->entry_avatar = HDY_AVATAR( |
43 | gtk_builder_get_object(builder, "entry_avatar") | 42 | gtk_builder_get_object(handle->builder, "entry_avatar") |
44 | ); | 43 | ); |
45 | 44 | ||
46 | handle->title_label = GTK_LABEL( | 45 | handle->title_label = GTK_LABEL( |
47 | gtk_builder_get_object(builder, "title_label") | 46 | gtk_builder_get_object(handle->builder, "title_label") |
48 | ); | 47 | ); |
49 | 48 | ||
50 | handle->timestamp_label = GTK_LABEL( | 49 | handle->timestamp_label = GTK_LABEL( |
51 | gtk_builder_get_object(builder, "timestamp_label") | 50 | gtk_builder_get_object(handle->builder, "timestamp_label") |
52 | ); | 51 | ); |
53 | 52 | ||
54 | handle->text_label = GTK_LABEL( | 53 | handle->text_label = GTK_LABEL( |
55 | gtk_builder_get_object(builder, "text_label") | 54 | gtk_builder_get_object(handle->builder, "text_label") |
56 | ); | 55 | ); |
57 | 56 | ||
58 | handle->read_receipt_image = GTK_IMAGE( | 57 | handle->read_receipt_image = GTK_IMAGE( |
59 | gtk_builder_get_object(builder, "read_receipt_image") | 58 | gtk_builder_get_object(handle->builder, "read_receipt_image") |
60 | ); | 59 | ); |
61 | 60 | ||
62 | return handle; | 61 | return handle; |
@@ -67,5 +66,7 @@ ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle) | |||
67 | { | 66 | { |
68 | ui_chat_delete(handle->chat); | 67 | ui_chat_delete(handle->chat); |
69 | 68 | ||
69 | g_object_unref(handle->builder); | ||
70 | |||
70 | g_free(handle); | 71 | g_free(handle); |
71 | } | 72 | } |
diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h index 4842eaf..48f3116 100644 --- a/src/ui/chat_entry.h +++ b/src/ui/chat_entry.h | |||
@@ -30,16 +30,17 @@ | |||
30 | typedef struct UI_CHAT_ENTRY_Handle | 30 | typedef struct UI_CHAT_ENTRY_Handle |
31 | { | 31 | { |
32 | UI_CHAT_Handle *chat; | 32 | UI_CHAT_Handle *chat; |
33 | GtkBuilder *builder; | ||
33 | 34 | ||
34 | GtkWidget* entry_box; | 35 | GtkWidget *entry_box; |
35 | 36 | ||
36 | HdyAvatar* entry_avatar; | 37 | HdyAvatar *entry_avatar; |
37 | 38 | ||
38 | GtkLabel* title_label; | 39 | GtkLabel *title_label; |
39 | GtkLabel* timestamp_label; | 40 | GtkLabel *timestamp_label; |
40 | 41 | ||
41 | GtkLabel* text_label; | 42 | GtkLabel *text_label; |
42 | GtkImage* read_receipt_image; | 43 | GtkImage *read_receipt_image; |
43 | } UI_CHAT_ENTRY_Handle; | 44 | } UI_CHAT_ENTRY_Handle; |
44 | 45 | ||
45 | UI_CHAT_ENTRY_Handle* | 46 | UI_CHAT_ENTRY_Handle* |
diff --git a/src/ui/message.c b/src/ui/message.c index f48bbaa..f89f5ef 100644 --- a/src/ui/message.c +++ b/src/ui/message.c | |||
@@ -31,23 +31,22 @@ ui_message_new(MESSENGER_Application *app, | |||
31 | bool sent) | 31 | bool sent) |
32 | { | 32 | { |
33 | UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); | 33 | UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); |
34 | GtkBuilder* builder; | ||
35 | 34 | ||
36 | if (sent) | 35 | if (sent) |
37 | builder = gtk_builder_new_from_file("resources/ui/message-sent.ui"); | 36 | handle->builder = gtk_builder_new_from_file("resources/ui/message-sent.ui"); |
38 | else | 37 | else |
39 | builder = gtk_builder_new_from_file("resources/ui/message.ui"); | 38 | handle->builder = gtk_builder_new_from_file("resources/ui/message.ui"); |
40 | 39 | ||
41 | handle->message_box = GTK_WIDGET( | 40 | handle->message_box = GTK_WIDGET( |
42 | gtk_builder_get_object(builder, "message_box") | 41 | gtk_builder_get_object(handle->builder, "message_box") |
43 | ); | 42 | ); |
44 | 43 | ||
45 | handle->sender_avatar = HDY_AVATAR( | 44 | handle->sender_avatar = HDY_AVATAR( |
46 | gtk_builder_get_object(builder, "sender_avatar") | 45 | gtk_builder_get_object(handle->builder, "sender_avatar") |
47 | ); | 46 | ); |
48 | 47 | ||
49 | handle->sender_label = GTK_LABEL( | 48 | handle->sender_label = GTK_LABEL( |
50 | gtk_builder_get_object(builder, "sender_label") | 49 | gtk_builder_get_object(handle->builder, "sender_label") |
51 | ); | 50 | ); |
52 | 51 | ||
53 | if (sent) | 52 | if (sent) |
@@ -59,16 +58,24 @@ ui_message_new(MESSENGER_Application *app, | |||
59 | } | 58 | } |
60 | 59 | ||
61 | handle->text_label = GTK_LABEL( | 60 | handle->text_label = GTK_LABEL( |
62 | gtk_builder_get_object(builder, "text_label") | 61 | gtk_builder_get_object(handle->builder, "text_label") |
63 | ); | 62 | ); |
64 | 63 | ||
65 | handle->timestamp_label = GTK_LABEL( | 64 | handle->timestamp_label = GTK_LABEL( |
66 | gtk_builder_get_object(builder, "timestamp_label") | 65 | gtk_builder_get_object(handle->builder, "timestamp_label") |
67 | ); | 66 | ); |
68 | 67 | ||
69 | handle->read_receipt_image = GTK_IMAGE( | 68 | handle->read_receipt_image = GTK_IMAGE( |
70 | gtk_builder_get_object(builder, "read_receipt_image") | 69 | gtk_builder_get_object(handle->builder, "read_receipt_image") |
71 | ); | 70 | ); |
72 | 71 | ||
73 | return handle; | 72 | return handle; |
74 | } | 73 | } |
74 | |||
75 | void | ||
76 | ui_message_delete(UI_MESSAGE_Handle *handle) | ||
77 | { | ||
78 | g_object_unref(handle->builder); | ||
79 | |||
80 | g_free(handle); | ||
81 | } | ||
diff --git a/src/ui/message.h b/src/ui/message.h index b55cb8d..1b3a80c 100644 --- a/src/ui/message.h +++ b/src/ui/message.h | |||
@@ -34,19 +34,23 @@ typedef struct MESSENGER_Application MESSENGER_Application; | |||
34 | 34 | ||
35 | typedef struct UI_MESSAGE_Handle | 35 | typedef struct UI_MESSAGE_Handle |
36 | { | 36 | { |
37 | GtkWidget* message_box; | 37 | GtkBuilder *builder; |
38 | GtkWidget *message_box; | ||
38 | 39 | ||
39 | HdyAvatar* sender_avatar; | 40 | HdyAvatar *sender_avatar; |
40 | GtkLabel* sender_label; | 41 | GtkLabel *sender_label; |
41 | 42 | ||
42 | GtkLabel* text_label; | 43 | GtkLabel *text_label; |
43 | 44 | ||
44 | GtkLabel* timestamp_label; | 45 | GtkLabel *timestamp_label; |
45 | GtkImage* read_receipt_image; | 46 | GtkImage *read_receipt_image; |
46 | } UI_MESSAGE_Handle; | 47 | } UI_MESSAGE_Handle; |
47 | 48 | ||
48 | UI_MESSAGE_Handle* | 49 | UI_MESSAGE_Handle* |
49 | ui_message_new(MESSENGER_Application *app, | 50 | ui_message_new(MESSENGER_Application *app, |
50 | bool sent); | 51 | bool sent); |
51 | 52 | ||
53 | void | ||
54 | ui_message_delete(UI_MESSAGE_Handle *handle); | ||
55 | |||
52 | #endif /* UI_MESSAGE_H_ */ | 56 | #endif /* UI_MESSAGE_H_ */ |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 3de94de..bc3a8dd 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -131,10 +131,10 @@ ui_messenger_init(MESSENGER_Application *app, | |||
131 | { | 131 | { |
132 | handle->chat_entries = g_list_alloc(); | 132 | handle->chat_entries = g_list_alloc(); |
133 | 133 | ||
134 | GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/messenger.ui"); | 134 | handle->builder = gtk_builder_new_from_file("resources/ui/messenger.ui"); |
135 | 135 | ||
136 | handle->main_window = GTK_APPLICATION_WINDOW( | 136 | handle->main_window = GTK_APPLICATION_WINDOW( |
137 | gtk_builder_get_object(builder, "main_window") | 137 | gtk_builder_get_object(handle->builder, "main_window") |
138 | ); | 138 | ); |
139 | 139 | ||
140 | gtk_application_add_window( | 140 | gtk_application_add_window( |
@@ -148,19 +148,19 @@ ui_messenger_init(MESSENGER_Application *app, | |||
148 | ); | 148 | ); |
149 | 149 | ||
150 | handle->leaflet_chat = HDY_LEAFLET( | 150 | handle->leaflet_chat = HDY_LEAFLET( |
151 | gtk_builder_get_object(builder, "leaflet_chat") | 151 | gtk_builder_get_object(handle->builder, "leaflet_chat") |
152 | ); | 152 | ); |
153 | 153 | ||
154 | handle->flap_user_details = HDY_FLAP( | 154 | handle->flap_user_details = HDY_FLAP( |
155 | gtk_builder_get_object(builder, "flap_user_details") | 155 | gtk_builder_get_object(handle->builder, "flap_user_details") |
156 | ); | 156 | ); |
157 | 157 | ||
158 | handle->flap_chat_details = HDY_FLAP( | 158 | handle->flap_chat_details = HDY_FLAP( |
159 | gtk_builder_get_object(builder, "flap_chat_details") | 159 | gtk_builder_get_object(handle->builder, "flap_chat_details") |
160 | ); | 160 | ); |
161 | 161 | ||
162 | handle->title_bar = HDY_HEADER_BAR( | 162 | handle->title_bar = HDY_HEADER_BAR( |
163 | gtk_builder_get_object(builder, "title_bar") | 163 | gtk_builder_get_object(handle->builder, "title_bar") |
164 | ); | 164 | ); |
165 | 165 | ||
166 | g_object_bind_property( | 166 | g_object_bind_property( |
@@ -182,15 +182,15 @@ ui_messenger_init(MESSENGER_Application *app, | |||
182 | ); | 182 | ); |
183 | 183 | ||
184 | handle->profile_avatar = HDY_AVATAR( | 184 | handle->profile_avatar = HDY_AVATAR( |
185 | gtk_builder_get_object(builder, "profile_avatar") | 185 | gtk_builder_get_object(handle->builder, "profile_avatar") |
186 | ); | 186 | ); |
187 | 187 | ||
188 | handle->profile_label = GTK_LABEL( | 188 | handle->profile_label = GTK_LABEL( |
189 | gtk_builder_get_object(builder, "profile_label") | 189 | gtk_builder_get_object(handle->builder, "profile_label") |
190 | ); | 190 | ); |
191 | 191 | ||
192 | handle->hide_user_details_button = GTK_BUTTON( | 192 | handle->hide_user_details_button = GTK_BUTTON( |
193 | gtk_builder_get_object(builder, "hide_user_details_button") | 193 | gtk_builder_get_object(handle->builder, "hide_user_details_button") |
194 | ); | 194 | ); |
195 | 195 | ||
196 | g_signal_connect( | 196 | g_signal_connect( |
@@ -201,19 +201,19 @@ ui_messenger_init(MESSENGER_Application *app, | |||
201 | ); | 201 | ); |
202 | 202 | ||
203 | handle->favourites_button = GTK_BUTTON( | 203 | handle->favourites_button = GTK_BUTTON( |
204 | gtk_builder_get_object(builder, "favourites_button") | 204 | gtk_builder_get_object(handle->builder, "favourites_button") |
205 | ); | 205 | ); |
206 | 206 | ||
207 | handle->account_details_button = GTK_BUTTON( | 207 | handle->account_details_button = GTK_BUTTON( |
208 | gtk_builder_get_object(builder, "account_details_button") | 208 | gtk_builder_get_object(handle->builder, "account_details_button") |
209 | ); | 209 | ); |
210 | 210 | ||
211 | handle->account_details_symbol = GTK_IMAGE( | 211 | handle->account_details_symbol = GTK_IMAGE( |
212 | gtk_builder_get_object(builder, "account_details_symbol") | 212 | gtk_builder_get_object(handle->builder, "account_details_symbol") |
213 | ); | 213 | ); |
214 | 214 | ||
215 | handle->account_details_revealer = GTK_REVEALER( | 215 | handle->account_details_revealer = GTK_REVEALER( |
216 | gtk_builder_get_object(builder, "account_details_revealer") | 216 | gtk_builder_get_object(handle->builder, "account_details_revealer") |
217 | ); | 217 | ); |
218 | 218 | ||
219 | g_signal_connect( | 219 | g_signal_connect( |
@@ -224,19 +224,19 @@ ui_messenger_init(MESSENGER_Application *app, | |||
224 | ); | 224 | ); |
225 | 225 | ||
226 | handle->accounts_listbox = GTK_LIST_BOX( | 226 | handle->accounts_listbox = GTK_LIST_BOX( |
227 | gtk_builder_get_object(builder, "accounts_listbox") | 227 | gtk_builder_get_object(handle->builder, "accounts_listbox") |
228 | ); | 228 | ); |
229 | 229 | ||
230 | handle->new_contact_button = GTK_BUTTON( | 230 | handle->new_contact_button = GTK_BUTTON( |
231 | gtk_builder_get_object(builder, "new_contact_button") | 231 | gtk_builder_get_object(handle->builder, "new_contact_button") |
232 | ); | 232 | ); |
233 | 233 | ||
234 | handle->new_group_button = GTK_BUTTON( | 234 | handle->new_group_button = GTK_BUTTON( |
235 | gtk_builder_get_object(builder, "new_group_button") | 235 | gtk_builder_get_object(handle->builder, "new_group_button") |
236 | ); | 236 | ); |
237 | 237 | ||
238 | handle->new_platform_button = GTK_BUTTON( | 238 | handle->new_platform_button = GTK_BUTTON( |
239 | gtk_builder_get_object(builder, "new_platform_button") | 239 | gtk_builder_get_object(handle->builder, "new_platform_button") |
240 | ); | 240 | ); |
241 | 241 | ||
242 | g_signal_connect( | 242 | g_signal_connect( |
@@ -254,15 +254,15 @@ ui_messenger_init(MESSENGER_Application *app, | |||
254 | ); | 254 | ); |
255 | 255 | ||
256 | handle->contacts_button = GTK_BUTTON( | 256 | handle->contacts_button = GTK_BUTTON( |
257 | gtk_builder_get_object(builder, "contacts_button") | 257 | gtk_builder_get_object(handle->builder, "contacts_button") |
258 | ); | 258 | ); |
259 | 259 | ||
260 | handle->settings_button = GTK_BUTTON( | 260 | handle->settings_button = GTK_BUTTON( |
261 | gtk_builder_get_object(builder, "settings_button") | 261 | gtk_builder_get_object(handle->builder, "settings_button") |
262 | ); | 262 | ); |
263 | 263 | ||
264 | handle->user_details_button = GTK_BUTTON( | 264 | handle->user_details_button = GTK_BUTTON( |
265 | gtk_builder_get_object(builder, "user_details_button") | 265 | gtk_builder_get_object(handle->builder, "user_details_button") |
266 | ); | 266 | ); |
267 | 267 | ||
268 | g_signal_connect( | 268 | g_signal_connect( |
@@ -273,11 +273,11 @@ ui_messenger_init(MESSENGER_Application *app, | |||
273 | ); | 273 | ); |
274 | 274 | ||
275 | handle->chats_search = GTK_SEARCH_ENTRY( | 275 | handle->chats_search = GTK_SEARCH_ENTRY( |
276 | gtk_builder_get_object(builder, "chats_search") | 276 | gtk_builder_get_object(handle->builder, "chats_search") |
277 | ); | 277 | ); |
278 | 278 | ||
279 | handle->chats_listbox = GTK_LIST_BOX( | 279 | handle->chats_listbox = GTK_LIST_BOX( |
280 | gtk_builder_get_object(builder, "chats_listbox") | 280 | gtk_builder_get_object(handle->builder, "chats_listbox") |
281 | ); | 281 | ); |
282 | 282 | ||
283 | g_signal_connect( | 283 | g_signal_connect( |
@@ -288,11 +288,11 @@ ui_messenger_init(MESSENGER_Application *app, | |||
288 | ); | 288 | ); |
289 | 289 | ||
290 | handle->chats_stack = GTK_STACK( | 290 | handle->chats_stack = GTK_STACK( |
291 | gtk_builder_get_object(builder, "chats_stack") | 291 | gtk_builder_get_object(handle->builder, "chats_stack") |
292 | ); | 292 | ); |
293 | 293 | ||
294 | handle->hide_chat_details_button = GTK_BUTTON( | 294 | handle->hide_chat_details_button = GTK_BUTTON( |
295 | gtk_builder_get_object(builder, "hide_chat_details_button") | 295 | gtk_builder_get_object(handle->builder, "hide_chat_details_button") |
296 | ); | 296 | ); |
297 | 297 | ||
298 | g_signal_connect( | 298 | g_signal_connect( |
@@ -315,6 +315,8 @@ ui_messenger_init(MESSENGER_Application *app, | |||
315 | void | 315 | void |
316 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) | 316 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) |
317 | { | 317 | { |
318 | g_object_unref(handle->builder); | ||
319 | |||
318 | GList *list = handle->chat_entries; | 320 | GList *list = handle->chat_entries; |
319 | 321 | ||
320 | while (list) { | 322 | while (list) { |
diff --git a/src/ui/messenger.h b/src/ui/messenger.h index 6cd4c9d..28829c2 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h | |||
@@ -35,6 +35,7 @@ typedef struct UI_MESSENGER_Handle | |||
35 | { | 35 | { |
36 | GList *chat_entries; | 36 | GList *chat_entries; |
37 | 37 | ||
38 | GtkBuilder *builder; | ||
38 | GtkApplicationWindow *main_window; | 39 | GtkApplicationWindow *main_window; |
39 | 40 | ||
40 | HdyLeaflet *leaflet_chat; | 41 | HdyLeaflet *leaflet_chat; |
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c index f9cd215..28bc2bf 100644 --- a/src/ui/new_contact.c +++ b/src/ui/new_contact.c | |||
@@ -188,10 +188,10 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
188 | 188 | ||
189 | pthread_create(&(handle->video_tid), NULL, _ui_new_contact_video_thread, handle); | 189 | pthread_create(&(handle->video_tid), NULL, _ui_new_contact_video_thread, handle); |
190 | 190 | ||
191 | GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/new_contact.ui"); | 191 | handle->builder = gtk_builder_new_from_file("resources/ui/new_contact.ui"); |
192 | 192 | ||
193 | handle->dialog = GTK_DIALOG( | 193 | handle->dialog = GTK_DIALOG( |
194 | gtk_builder_get_object(builder, "new_contact_dialog") | 194 | gtk_builder_get_object(handle->builder, "new_contact_dialog") |
195 | ); | 195 | ); |
196 | 196 | ||
197 | gtk_window_set_title( | 197 | gtk_window_set_title( |
@@ -205,7 +205,7 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
205 | ); | 205 | ); |
206 | 206 | ||
207 | handle->id_drawing_area = GTK_DRAWING_AREA( | 207 | handle->id_drawing_area = GTK_DRAWING_AREA( |
208 | gtk_builder_get_object(builder, "id_drawing_area") | 208 | gtk_builder_get_object(handle->builder, "id_drawing_area") |
209 | ); | 209 | ); |
210 | 210 | ||
211 | g_signal_connect( | 211 | g_signal_connect( |
@@ -216,11 +216,11 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
216 | ); | 216 | ); |
217 | 217 | ||
218 | handle->id_entry = GTK_ENTRY( | 218 | handle->id_entry = GTK_ENTRY( |
219 | gtk_builder_get_object(builder, "platform_entry") | 219 | gtk_builder_get_object(handle->builder, "platform_entry") |
220 | ); | 220 | ); |
221 | 221 | ||
222 | handle->cancel_button = GTK_BUTTON( | 222 | handle->cancel_button = GTK_BUTTON( |
223 | gtk_builder_get_object(builder, "cancel_button") | 223 | gtk_builder_get_object(handle->builder, "cancel_button") |
224 | ); | 224 | ); |
225 | 225 | ||
226 | g_signal_connect( | 226 | g_signal_connect( |
@@ -231,7 +231,7 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
231 | ); | 231 | ); |
232 | 232 | ||
233 | handle->confirm_button = GTK_BUTTON( | 233 | handle->confirm_button = GTK_BUTTON( |
234 | gtk_builder_get_object(builder, "confirm_button") | 234 | gtk_builder_get_object(handle->builder, "confirm_button") |
235 | ); | 235 | ); |
236 | 236 | ||
237 | g_signal_connect( | 237 | g_signal_connect( |
@@ -261,6 +261,8 @@ ui_new_contact_dialog_cleanup(UI_NEW_CONTACT_Handle *handle) | |||
261 | 261 | ||
262 | handle->idle_processing = 0; | 262 | handle->idle_processing = 0; |
263 | 263 | ||
264 | g_object_unref(handle->builder); | ||
265 | |||
264 | zbar_image_scanner_destroy(handle->scanner); | 266 | zbar_image_scanner_destroy(handle->scanner); |
265 | zbar_video_destroy(handle->video); | 267 | zbar_video_destroy(handle->video); |
266 | } | 268 | } |
diff --git a/src/ui/new_contact.h b/src/ui/new_contact.h index 760c32d..ae1c7f3 100644 --- a/src/ui/new_contact.h +++ b/src/ui/new_contact.h | |||
@@ -37,13 +37,14 @@ typedef struct UI_NEW_CONTACT_Handle | |||
37 | zbar_image_t *image; | 37 | zbar_image_t *image; |
38 | zbar_image_scanner_t *scanner; | 38 | zbar_image_scanner_t *scanner; |
39 | 39 | ||
40 | GtkDialog* dialog; | 40 | GtkBuilder *builder; |
41 | GtkDialog *dialog; | ||
41 | 42 | ||
42 | GtkDrawingArea* id_drawing_area; | 43 | GtkDrawingArea *id_drawing_area; |
43 | GtkEntry* id_entry; | 44 | GtkEntry *id_entry; |
44 | 45 | ||
45 | GtkButton* cancel_button; | 46 | GtkButton *cancel_button; |
46 | GtkButton* confirm_button; | 47 | GtkButton *confirm_button; |
47 | 48 | ||
48 | pthread_t video_tid; | 49 | pthread_t video_tid; |
49 | guint idle_processing; | 50 | guint idle_processing; |
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c index 0eb0ced..6521b83 100644 --- a/src/ui/new_platform.c +++ b/src/ui/new_platform.c | |||
@@ -89,14 +89,21 @@ handle_confirm_button_click(UNUSED GtkButton *button, | |||
89 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.dialog)); | 89 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.dialog)); |
90 | } | 90 | } |
91 | 91 | ||
92 | static void | ||
93 | handle_dialog_destroy(UNUSED GtkWidget *window, | ||
94 | gpointer user_data) | ||
95 | { | ||
96 | ui_new_platform_dialog_cleanup((UI_NEW_PLATFORM_Handle*) user_data); | ||
97 | } | ||
98 | |||
92 | void | 99 | void |
93 | ui_new_platform_dialog_init(MESSENGER_Application *app, | 100 | ui_new_platform_dialog_init(MESSENGER_Application *app, |
94 | UI_NEW_PLATFORM_Handle *handle) | 101 | UI_NEW_PLATFORM_Handle *handle) |
95 | { | 102 | { |
96 | GtkBuilder* builder = gtk_builder_new_from_file("resources/ui/new_platform.ui"); | 103 | handle->builder = gtk_builder_new_from_file("resources/ui/new_platform.ui"); |
97 | 104 | ||
98 | handle->dialog = GTK_DIALOG( | 105 | handle->dialog = GTK_DIALOG( |
99 | gtk_builder_get_object(builder, "new_platform_dialog") | 106 | gtk_builder_get_object(handle->builder, "new_platform_dialog") |
100 | ); | 107 | ); |
101 | 108 | ||
102 | gtk_window_set_title( | 109 | gtk_window_set_title( |
@@ -110,15 +117,15 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
110 | ); | 117 | ); |
111 | 118 | ||
112 | handle->platform_avatar = HDY_AVATAR( | 119 | handle->platform_avatar = HDY_AVATAR( |
113 | gtk_builder_get_object(builder, "platform_avatar") | 120 | gtk_builder_get_object(handle->builder, "platform_avatar") |
114 | ); | 121 | ); |
115 | 122 | ||
116 | handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON( | 123 | handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON( |
117 | gtk_builder_get_object(builder, "platform_avatar_file") | 124 | gtk_builder_get_object(handle->builder, "platform_avatar_file") |
118 | ); | 125 | ); |
119 | 126 | ||
120 | handle->platform_entry = GTK_ENTRY( | 127 | handle->platform_entry = GTK_ENTRY( |
121 | gtk_builder_get_object(builder, "platform_entry") | 128 | gtk_builder_get_object(handle->builder, "platform_entry") |
122 | ); | 129 | ); |
123 | 130 | ||
124 | g_signal_connect( | 131 | g_signal_connect( |
@@ -136,7 +143,7 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
136 | ); | 143 | ); |
137 | 144 | ||
138 | handle->cancel_button = GTK_BUTTON( | 145 | handle->cancel_button = GTK_BUTTON( |
139 | gtk_builder_get_object(builder, "cancel_button") | 146 | gtk_builder_get_object(handle->builder, "cancel_button") |
140 | ); | 147 | ); |
141 | 148 | ||
142 | g_signal_connect( | 149 | g_signal_connect( |
@@ -147,7 +154,7 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
147 | ); | 154 | ); |
148 | 155 | ||
149 | handle->confirm_button = GTK_BUTTON( | 156 | handle->confirm_button = GTK_BUTTON( |
150 | gtk_builder_get_object(builder, "confirm_button") | 157 | gtk_builder_get_object(handle->builder, "confirm_button") |
151 | ); | 158 | ); |
152 | 159 | ||
153 | g_signal_connect( | 160 | g_signal_connect( |
@@ -156,4 +163,17 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
156 | G_CALLBACK(handle_confirm_button_click), | 163 | G_CALLBACK(handle_confirm_button_click), |
157 | app | 164 | app |
158 | ); | 165 | ); |
166 | |||
167 | g_signal_connect( | ||
168 | handle->dialog, | ||
169 | "destroy", | ||
170 | G_CALLBACK(handle_dialog_destroy), | ||
171 | handle | ||
172 | ); | ||
173 | } | ||
174 | |||
175 | void | ||
176 | ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle) | ||
177 | { | ||
178 | g_object_unref(handle->builder); | ||
159 | } | 179 | } |
diff --git a/src/ui/new_platform.h b/src/ui/new_platform.h index 12fcbe3..e2ec288 100644 --- a/src/ui/new_platform.h +++ b/src/ui/new_platform.h | |||
@@ -29,19 +29,23 @@ | |||
29 | 29 | ||
30 | typedef struct UI_NEW_PLATFORM_Handle | 30 | typedef struct UI_NEW_PLATFORM_Handle |
31 | { | 31 | { |
32 | GtkDialog* dialog; | 32 | GtkBuilder *builder; |
33 | GtkDialog *dialog; | ||
33 | 34 | ||
34 | HdyAvatar* platform_avatar; | 35 | HdyAvatar *platform_avatar; |
35 | GtkFileChooserButton* platform_avatar_file; | 36 | GtkFileChooserButton *platform_avatar_file; |
36 | 37 | ||
37 | GtkEntry* platform_entry; | 38 | GtkEntry *platform_entry; |
38 | 39 | ||
39 | GtkButton* cancel_button; | 40 | GtkButton *cancel_button; |
40 | GtkButton* confirm_button; | 41 | GtkButton *confirm_button; |
41 | } UI_NEW_PLATFORM_Handle; | 42 | } UI_NEW_PLATFORM_Handle; |
42 | 43 | ||
43 | void | 44 | void |
44 | ui_new_platform_dialog_init(MESSENGER_Application *app, | 45 | ui_new_platform_dialog_init(MESSENGER_Application *app, |
45 | UI_NEW_PLATFORM_Handle *handle); | 46 | UI_NEW_PLATFORM_Handle *handle); |
46 | 47 | ||
48 | void | ||
49 | ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle); | ||
50 | |||
47 | #endif /* UI_NEW_PLATFORM_H_ */ | 51 | #endif /* UI_NEW_PLATFORM_H_ */ |