diff options
-rw-r--r-- | src/application.c | 9 | ||||
-rw-r--r-- | src/application.h | 11 | ||||
-rw-r--r-- | src/chat/messenger.c | 2 | ||||
-rw-r--r-- | src/event.c | 57 | ||||
-rw-r--r-- | src/file.c | 6 | ||||
-rw-r--r-- | src/ui/accounts.c | 44 | ||||
-rw-r--r-- | src/ui/accounts.h | 4 | ||||
-rw-r--r-- | src/ui/chat.c | 20 | ||||
-rw-r--r-- | src/ui/media_preview.c | 34 | ||||
-rw-r--r-- | src/ui/media_preview.h | 2 | ||||
-rw-r--r-- | src/ui/messenger.c | 2 |
11 files changed, 123 insertions, 68 deletions
diff --git a/src/application.c b/src/application.c index 3259e57..f39a9b7 100644 --- a/src/application.c +++ b/src/application.c | |||
@@ -642,6 +642,15 @@ application_call_event(MESSENGER_Application *app, | |||
642 | g_timeout_add(0, G_SOURCE_FUNC(_application_event_call), call); | 642 | g_timeout_add(0, G_SOURCE_FUNC(_application_event_call), call); |
643 | } | 643 | } |
644 | 644 | ||
645 | void | ||
646 | application_call_sync_event(MESSENGER_Application *app, | ||
647 | MESSENGER_ApplicationEvent event) | ||
648 | { | ||
649 | g_assert((app) && (event)); | ||
650 | |||
651 | event(app); | ||
652 | } | ||
653 | |||
645 | typedef struct MESSENGER_ApplicationMessageEventCall | 654 | typedef struct MESSENGER_ApplicationMessageEventCall |
646 | { | 655 | { |
647 | MESSENGER_Application *app; | 656 | MESSENGER_Application *app; |
diff --git a/src/application.h b/src/application.h index f26e01d..3b9b798 100644 --- a/src/application.h +++ b/src/application.h | |||
@@ -253,6 +253,17 @@ application_call_event(MESSENGER_Application *app, | |||
253 | MESSENGER_ApplicationEvent event); | 253 | MESSENGER_ApplicationEvent event); |
254 | 254 | ||
255 | /** | 255 | /** |
256 | * Calls a given event with the messenger application | ||
257 | * syncronously. | ||
258 | * | ||
259 | * @param app Messenger application | ||
260 | * @param event Event | ||
261 | */ | ||
262 | void | ||
263 | application_call_sync_event(MESSENGER_Application *app, | ||
264 | MESSENGER_ApplicationEvent event); | ||
265 | |||
266 | /** | ||
256 | * Calls a given message event with the messenger | 267 | * Calls a given message event with the messenger |
257 | * application asyncronously but explicitly synchronized | 268 | * application asyncronously but explicitly synchronized |
258 | * via mutex. | 269 | * via mutex. |
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 6381719..6134857 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -114,7 +114,7 @@ _chat_messenger_message(void *cls, | |||
114 | } | 114 | } |
115 | case GNUNET_CHAT_KIND_LOGOUT: | 115 | case GNUNET_CHAT_KIND_LOGOUT: |
116 | { | 116 | { |
117 | application_call_event(app, event_cleanup_profile); | 117 | application_call_sync_event(app, event_cleanup_profile); |
118 | break; | 118 | break; |
119 | } | 119 | } |
120 | case GNUNET_CHAT_KIND_UPDATE: | 120 | case GNUNET_CHAT_KIND_UPDATE: |
diff --git a/src/event.c b/src/event.c index f921da9..0df6a74 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -309,6 +309,29 @@ _iterate_profile_groups(void *cls, | |||
309 | return GNUNET_YES; | 309 | return GNUNET_YES; |
310 | } | 310 | } |
311 | 311 | ||
312 | void | ||
313 | event_update_profile(MESSENGER_Application *app) | ||
314 | { | ||
315 | g_assert(app); | ||
316 | |||
317 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
318 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | ||
319 | |||
320 | const char *name = GNUNET_CHAT_get_name(chat->handle); | ||
321 | |||
322 | ui_avatar_set_text(ui->profile_avatar, name); | ||
323 | ui_label_set_text(ui->profile_label, name); | ||
324 | |||
325 | const char *key = GNUNET_CHAT_get_key(chat->handle); | ||
326 | |||
327 | ui_label_set_text(ui->profile_key_label, key); | ||
328 | |||
329 | gtk_stack_set_visible_child(ui->chats_stack, ui->no_chat_box); | ||
330 | |||
331 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); | ||
332 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); | ||
333 | } | ||
334 | |||
312 | static void | 335 | static void |
313 | _clear_chat_entry(GtkWidget *widget, | 336 | _clear_chat_entry(GtkWidget *widget, |
314 | gpointer user_data) | 337 | gpointer user_data) |
@@ -339,29 +362,6 @@ _clear_chat_entry(GtkWidget *widget, | |||
339 | ui_chat_entry_dispose(entry, app); | 362 | ui_chat_entry_dispose(entry, app); |
340 | } | 363 | } |
341 | 364 | ||
342 | void | ||
343 | event_update_profile(MESSENGER_Application *app) | ||
344 | { | ||
345 | g_assert(app); | ||
346 | |||
347 | UI_MESSENGER_Handle *ui = &(app->ui.messenger); | ||
348 | CHAT_MESSENGER_Handle *chat = &(app->chat.messenger); | ||
349 | |||
350 | const char *name = GNUNET_CHAT_get_name(chat->handle); | ||
351 | |||
352 | ui_avatar_set_text(ui->profile_avatar, name); | ||
353 | ui_label_set_text(ui->profile_label, name); | ||
354 | |||
355 | const char *key = GNUNET_CHAT_get_key(chat->handle); | ||
356 | |||
357 | ui_label_set_text(ui->profile_key_label, key); | ||
358 | |||
359 | gtk_stack_set_visible_child(ui->chats_stack, ui->no_chat_box); | ||
360 | |||
361 | GNUNET_CHAT_iterate_contacts(chat->handle, _iterate_profile_contacts, app); | ||
362 | GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); | ||
363 | } | ||
364 | |||
365 | static int | 365 | static int |
366 | _cleanup_profile_contacts(void *cls, | 366 | _cleanup_profile_contacts(void *cls, |
367 | UNUSED struct GNUNET_CHAT_Handle *handle, | 367 | UNUSED struct GNUNET_CHAT_Handle *handle, |
@@ -372,6 +372,16 @@ _cleanup_profile_contacts(void *cls, | |||
372 | return GNUNET_YES; | 372 | return GNUNET_YES; |
373 | } | 373 | } |
374 | 374 | ||
375 | static int | ||
376 | _cleanup_profile_files(void *cls, | ||
377 | UNUSED struct GNUNET_CHAT_Handle *handle, | ||
378 | struct GNUNET_CHAT_File *file) | ||
379 | { | ||
380 | if (file) | ||
381 | file_destroy_info(file); | ||
382 | return GNUNET_YES; | ||
383 | } | ||
384 | |||
375 | void | 385 | void |
376 | event_cleanup_profile(MESSENGER_Application *app) | 386 | event_cleanup_profile(MESSENGER_Application *app) |
377 | { | 387 | { |
@@ -388,6 +398,7 @@ event_cleanup_profile(MESSENGER_Application *app) | |||
388 | g_list_free(entries); | 398 | g_list_free(entries); |
389 | 399 | ||
390 | GNUNET_CHAT_iterate_contacts(chat->handle, _cleanup_profile_contacts, NULL); | 400 | GNUNET_CHAT_iterate_contacts(chat->handle, _cleanup_profile_contacts, NULL); |
401 | GNUNET_CHAT_iterate_files(chat->handle, _cleanup_profile_files, NULL); | ||
391 | } | 402 | } |
392 | 403 | ||
393 | gboolean | 404 | gboolean |
@@ -58,6 +58,9 @@ file_destroy_info(struct GNUNET_CHAT_File *file) | |||
58 | if (!info) | 58 | if (!info) |
59 | return; | 59 | return; |
60 | 60 | ||
61 | if (info->preview_widgets) | ||
62 | g_list_free(info->preview_widgets); | ||
63 | |||
61 | file_unload_preview_image(file); | 64 | file_unload_preview_image(file); |
62 | 65 | ||
63 | if (info->update_task) | 66 | if (info->update_task) |
@@ -115,7 +118,8 @@ file_remove_widget_from_preview(const struct GNUNET_CHAT_File *file, | |||
115 | if (!info) | 118 | if (!info) |
116 | return; | 119 | return; |
117 | 120 | ||
118 | info->preview_widgets = g_list_remove(info->preview_widgets, widget); | 121 | if (info->preview_widgets) |
122 | info->preview_widgets = g_list_remove(info->preview_widgets, widget); | ||
119 | 123 | ||
120 | if (!(info->preview_widgets)) | 124 | if (!(info->preview_widgets)) |
121 | file_unload_preview_image(file); | 125 | file_unload_preview_image(file); |
diff --git a/src/ui/accounts.c b/src/ui/accounts.c index 261993d..e0db9e4 100644 --- a/src/ui/accounts.c +++ b/src/ui/accounts.c | |||
@@ -139,11 +139,10 @@ _iterate_accounts(void *cls, | |||
139 | 139 | ||
140 | g_object_set_qdata(G_OBJECT(row), app->quarks.data, account); | 140 | g_object_set_qdata(G_OBJECT(row), app->quarks.data, account); |
141 | 141 | ||
142 | g_object_set_qdata_full( | 142 | g_object_set_qdata( |
143 | G_OBJECT(row), | 143 | G_OBJECT(row), |
144 | app->quarks.ui, | 144 | app->quarks.ui, |
145 | entry, | 145 | entry |
146 | (GDestroyNotify) ui_account_entry_delete | ||
147 | ); | 146 | ); |
148 | 147 | ||
149 | return GNUNET_YES; | 148 | return GNUNET_YES; |
@@ -200,14 +199,11 @@ ui_accounts_dialog_init(MESSENGER_Application *app, | |||
200 | ); | 199 | ); |
201 | } | 200 | } |
202 | 201 | ||
203 | void | 202 | static void |
204 | ui_accounts_dialog_refresh(MESSENGER_Application *app, | 203 | _ui_accounts_cleanup_listbox(UI_ACCOUNTS_Handle *handle, |
205 | UI_ACCOUNTS_Handle *handle) | 204 | MESSENGER_Application *app) |
206 | { | 205 | { |
207 | g_assert((app) && (handle)); | 206 | g_assert(handle); |
208 | |||
209 | if (!(handle->accounts_listbox)) | ||
210 | return; | ||
211 | 207 | ||
212 | GList *list = gtk_container_get_children( | 208 | GList *list = gtk_container_get_children( |
213 | GTK_CONTAINER(handle->accounts_listbox) | 209 | GTK_CONTAINER(handle->accounts_listbox) |
@@ -221,6 +217,13 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, | |||
221 | if ((!row) || (!gtk_list_box_row_get_selectable(row))) | 217 | if ((!row) || (!gtk_list_box_row_get_selectable(row))) |
222 | goto skip_row; | 218 | goto skip_row; |
223 | 219 | ||
220 | UI_ACCOUNT_ENTRY_Handle *entry = g_object_get_qdata( | ||
221 | G_OBJECT(row), | ||
222 | app->quarks.ui | ||
223 | ); | ||
224 | |||
225 | ui_account_entry_delete(entry); | ||
226 | |||
224 | gtk_container_remove( | 227 | gtk_container_remove( |
225 | GTK_CONTAINER(handle->accounts_listbox), | 228 | GTK_CONTAINER(handle->accounts_listbox), |
226 | GTK_WIDGET(row) | 229 | GTK_WIDGET(row) |
@@ -232,6 +235,18 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, | |||
232 | 235 | ||
233 | if (list) | 236 | if (list) |
234 | g_list_free(list); | 237 | g_list_free(list); |
238 | } | ||
239 | |||
240 | void | ||
241 | ui_accounts_dialog_refresh(MESSENGER_Application *app, | ||
242 | UI_ACCOUNTS_Handle *handle) | ||
243 | { | ||
244 | g_assert((app) && (handle)); | ||
245 | |||
246 | if (!(handle->accounts_listbox)) | ||
247 | return; | ||
248 | |||
249 | _ui_accounts_cleanup_listbox(handle, app); | ||
235 | 250 | ||
236 | GNUNET_CHAT_iterate_accounts( | 251 | GNUNET_CHAT_iterate_accounts( |
237 | app->chat.messenger.handle, | 252 | app->chat.messenger.handle, |
@@ -241,12 +256,17 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, | |||
241 | } | 256 | } |
242 | 257 | ||
243 | void | 258 | void |
244 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle) | 259 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle, |
260 | MESSENGER_Application *app) | ||
245 | { | 261 | { |
246 | g_assert(handle); | 262 | g_assert((handle) && (app)); |
247 | 263 | ||
248 | if (handle->builder) | 264 | if (handle->builder) |
265 | { | ||
266 | _ui_accounts_cleanup_listbox(handle, app); | ||
267 | |||
249 | g_object_unref(handle->builder); | 268 | g_object_unref(handle->builder); |
269 | } | ||
250 | 270 | ||
251 | guint show = handle->show_queued; | 271 | guint show = handle->show_queued; |
252 | memset(handle, 0, sizeof(*handle)); | 272 | memset(handle, 0, sizeof(*handle)); |
diff --git a/src/ui/accounts.h b/src/ui/accounts.h index 99fb453..344a0a0 100644 --- a/src/ui/accounts.h +++ b/src/ui/accounts.h | |||
@@ -66,8 +66,10 @@ ui_accounts_dialog_refresh(MESSENGER_Application *app, | |||
66 | * state of a given accounts dialog handle. | 66 | * state of a given accounts dialog handle. |
67 | * | 67 | * |
68 | * @param handle Accounts dialog handle | 68 | * @param handle Accounts dialog handle |
69 | * @param app Messenger application | ||
69 | */ | 70 | */ |
70 | void | 71 | void |
71 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle); | 72 | ui_accounts_dialog_cleanup(UI_ACCOUNTS_Handle *handle, |
73 | MESSENGER_Application *app); | ||
72 | 74 | ||
73 | #endif /* UI_ACCOUNTS_H_ */ | 75 | #endif /* UI_ACCOUNTS_H_ */ |
diff --git a/src/ui/chat.c b/src/ui/chat.c index 177d61c..0cd85da 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -2036,11 +2036,10 @@ iterate_ui_chat_update_context_media(void *cls, | |||
2036 | ); | 2036 | ); |
2037 | 2037 | ||
2038 | g_object_set_qdata(G_OBJECT(child), closure->app->quarks.data, file); | 2038 | g_object_set_qdata(G_OBJECT(child), closure->app->quarks.data, file); |
2039 | g_object_set_qdata_full( | 2039 | g_object_set_qdata( |
2040 | G_OBJECT(child), | 2040 | G_OBJECT(child), |
2041 | closure->app->quarks.ui, | 2041 | closure->app->quarks.ui, |
2042 | handle, | 2042 | handle |
2043 | (GDestroyNotify) ui_media_preview_delete | ||
2044 | ); | 2043 | ); |
2045 | 2044 | ||
2046 | gtk_widget_set_size_request(GTK_WIDGET(child), 80, 80); | 2045 | gtk_widget_set_size_request(GTK_WIDGET(child), 80, 80); |
@@ -2065,6 +2064,13 @@ _chat_update_media(UI_CHAT_Handle *handle, | |||
2065 | GtkWidget *widget = GTK_WIDGET(item->data); | 2064 | GtkWidget *widget = GTK_WIDGET(item->data); |
2066 | item = item->next; | 2065 | item = item->next; |
2067 | 2066 | ||
2067 | UI_MEDIA_PREVIEW_Handle *media = g_object_get_qdata( | ||
2068 | G_OBJECT(widget), | ||
2069 | app->quarks.ui | ||
2070 | ); | ||
2071 | |||
2072 | ui_media_preview_delete(media); | ||
2073 | |||
2068 | gtk_container_remove( | 2074 | gtk_container_remove( |
2069 | GTK_CONTAINER(handle->chat_media_flowbox), | 2075 | GTK_CONTAINER(handle->chat_media_flowbox), |
2070 | widget | 2076 | widget |
@@ -2289,12 +2295,12 @@ ui_chat_delete(UI_CHAT_Handle *handle) | |||
2289 | 2295 | ||
2290 | ui_picker_delete(handle->picker); | 2296 | ui_picker_delete(handle->picker); |
2291 | 2297 | ||
2292 | if (handle->loads) | ||
2293 | g_list_free_full(handle->loads, (GDestroyNotify) ui_file_load_entry_delete); | ||
2294 | |||
2295 | _chat_update_contacts(handle, handle->app, NULL); | 2298 | _chat_update_contacts(handle, handle->app, NULL); |
2296 | _chat_update_files(handle, handle->app, NULL); | ||
2297 | _chat_update_media(handle, handle->app, NULL); | 2299 | _chat_update_media(handle, handle->app, NULL); |
2300 | _chat_update_files(handle, handle->app, NULL); | ||
2301 | |||
2302 | if (handle->loads) | ||
2303 | g_list_free_full(handle->loads, (GDestroyNotify) ui_file_load_entry_delete); | ||
2298 | 2304 | ||
2299 | g_object_unref(handle->builder); | 2305 | g_object_unref(handle->builder); |
2300 | 2306 | ||
diff --git a/src/ui/media_preview.c b/src/ui/media_preview.c index 88051be..c24da51 100644 --- a/src/ui/media_preview.c +++ b/src/ui/media_preview.c | |||
@@ -117,6 +117,8 @@ ui_media_preview_new(MESSENGER_Application *app) | |||
117 | 117 | ||
118 | UI_MEDIA_PREVIEW_Handle* handle = g_malloc(sizeof(UI_MEDIA_PREVIEW_Handle)); | 118 | UI_MEDIA_PREVIEW_Handle* handle = g_malloc(sizeof(UI_MEDIA_PREVIEW_Handle)); |
119 | 119 | ||
120 | handle->file = NULL; | ||
121 | |||
120 | handle->builder = ui_builder_from_resource( | 122 | handle->builder = ui_builder_from_resource( |
121 | application_get_resource_path(app, "ui/media_preview.ui") | 123 | application_get_resource_path(app, "ui/media_preview.ui") |
122 | ); | 124 | ); |
@@ -145,24 +147,18 @@ void | |||
145 | ui_media_preview_update(UI_MEDIA_PREVIEW_Handle *handle, | 147 | ui_media_preview_update(UI_MEDIA_PREVIEW_Handle *handle, |
146 | struct GNUNET_CHAT_File *file) | 148 | struct GNUNET_CHAT_File *file) |
147 | { | 149 | { |
148 | g_assert((handle) && (file)); | 150 | g_assert(handle); |
149 | |||
150 | struct GNUNET_CHAT_File *previous = (struct GNUNET_CHAT_File *) g_object_get_qdata( | ||
151 | G_OBJECT(handle->preview_drawing_area), | ||
152 | handle->app->quarks.data | ||
153 | ); | ||
154 | 151 | ||
155 | if (previous) | 152 | if (handle->file) |
156 | file_remove_widget_from_preview(previous, GTK_WIDGET(handle->preview_drawing_area)); | 153 | file_remove_widget_from_preview(handle->file, GTK_WIDGET(handle->preview_drawing_area)); |
157 | 154 | ||
158 | file_load_preview_image(file); | 155 | if (file) |
159 | file_add_widget_to_preview(file, GTK_WIDGET(handle->preview_drawing_area)); | 156 | { |
157 | file_load_preview_image(file); | ||
158 | file_add_widget_to_preview(file, GTK_WIDGET(handle->preview_drawing_area)); | ||
159 | } | ||
160 | 160 | ||
161 | g_object_set_qdata( | 161 | handle->file = file; |
162 | G_OBJECT(handle->preview_drawing_area), | ||
163 | handle->app->quarks.data, | ||
164 | file | ||
165 | ); | ||
166 | } | 162 | } |
167 | 163 | ||
168 | void | 164 | void |
@@ -170,13 +166,7 @@ ui_media_preview_delete(UI_MEDIA_PREVIEW_Handle *handle) | |||
170 | { | 166 | { |
171 | g_assert(handle); | 167 | g_assert(handle); |
172 | 168 | ||
173 | struct GNUNET_CHAT_File *file = (struct GNUNET_CHAT_File *) g_object_get_qdata( | 169 | ui_media_preview_update(handle, NULL); |
174 | G_OBJECT(handle->preview_drawing_area), | ||
175 | handle->app->quarks.data | ||
176 | ); | ||
177 | |||
178 | if (file) | ||
179 | file_remove_widget_from_preview(file, GTK_WIDGET(handle->preview_drawing_area)); | ||
180 | 170 | ||
181 | g_object_unref(handle->builder); | 171 | g_object_unref(handle->builder); |
182 | 172 | ||
diff --git a/src/ui/media_preview.h b/src/ui/media_preview.h index 520ea47..9954e2d 100644 --- a/src/ui/media_preview.h +++ b/src/ui/media_preview.h | |||
@@ -31,6 +31,8 @@ | |||
31 | 31 | ||
32 | typedef struct UI_MEDIA_PREVIEW_Handle | 32 | typedef struct UI_MEDIA_PREVIEW_Handle |
33 | { | 33 | { |
34 | const struct GNUNET_CHAT_File *file; | ||
35 | |||
34 | GtkBuilder *builder; | 36 | GtkBuilder *builder; |
35 | 37 | ||
36 | GtkWidget *media_box; | 38 | GtkWidget *media_box; |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index a4fb0cb..65f4d46 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -387,7 +387,7 @@ handle_main_window_destroy(UNUSED GtkWidget *window, | |||
387 | #endif | 387 | #endif |
388 | 388 | ||
389 | ui_messenger_cleanup(&(app->ui.messenger)); | 389 | ui_messenger_cleanup(&(app->ui.messenger)); |
390 | ui_accounts_dialog_cleanup(&(app->ui.accounts)); | 390 | ui_accounts_dialog_cleanup(&(app->ui.accounts), app); |
391 | 391 | ||
392 | application_exit(app, MESSENGER_QUIT); | 392 | application_exit(app, MESSENGER_QUIT); |
393 | } | 393 | } |