aboutsummaryrefslogtreecommitdiff
path: root/src/ui/message.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/message.c')
-rw-r--r--src/ui/message.c135
1 files changed, 128 insertions, 7 deletions
diff --git a/src/ui/message.c b/src/ui/message.c
index 4aa7a85..9c93502 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -27,6 +27,85 @@
27#include <gnunet/gnunet_chat_lib.h> 27#include <gnunet/gnunet_chat_lib.h>
28 28
29#include "../application.h" 29#include "../application.h"
30#include "../file.h"
31
32static void
33handle_downloading_file(void *cls,
34 const struct GNUNET_CHAT_File *file,
35 uint64_t completed,
36 uint64_t size)
37{
38 MESSENGER_Application *app = (MESSENGER_Application*) cls;
39
40 if (!app)
41 return;
42
43 file_update_download_info(file, app, completed, size);
44}
45
46static void
47handle_file_button_click(GtkButton *button,
48 gpointer user_data)
49{
50 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
51
52 UI_MESSAGE_Handle* handle = g_hash_table_lookup(
53 app->ui.bindings, button
54 );
55
56 if (!handle)
57 return;
58
59 struct GNUNET_CHAT_File *file = g_hash_table_lookup(
60 app->ui.bindings, handle->file_progress_bar
61 );
62
63 if (!file)
64 return;
65
66 uint64_t size = GNUNET_CHAT_file_get_size(file);
67
68 if (size <= 0)
69 return;
70
71 uint64_t local_size = GNUNET_CHAT_file_get_local_size(file);
72
73 if (GNUNET_YES == GNUNET_CHAT_file_is_downloading(file))
74 {
75 GNUNET_CHAT_file_stop_download(file);
76
77 gtk_image_set_from_icon_name(
78 handle->file_status_image,
79 "folder-download-symbolic",
80 GTK_ICON_SIZE_BUTTON
81 );
82 }
83 else if (local_size < size)
84 {
85 GNUNET_CHAT_file_start_download(file, handle_downloading_file, app);
86
87 gtk_image_set_from_icon_name(
88 handle->file_status_image,
89 "process-stop-symbolic",
90 GTK_ICON_SIZE_BUTTON
91 );
92 }
93 else if (size > 0)
94 {
95 const gchar *preview = GNUNET_CHAT_file_open_preview(file);
96
97 if (!preview)
98 return;
99
100 GString* uri = g_string_new("file://");
101 g_string_append(uri, preview);
102
103 if (!g_app_info_launch_default_for_uri(uri->str, NULL, NULL))
104 GNUNET_CHAT_file_close_preview(file);
105
106 g_string_free(uri, TRUE);
107 }
108}
30 109
31static int 110static int
32handle_message_redraw_animation(gpointer user_data) 111handle_message_redraw_animation(gpointer user_data)
@@ -267,10 +346,19 @@ ui_message_new(MESSENGER_Application *app,
267 gtk_builder_get_object(builder, "file_button") 346 gtk_builder_get_object(builder, "file_button")
268 ); 347 );
269 348
349 g_signal_connect(
350 handle->file_button,
351 "clicked",
352 G_CALLBACK(handle_file_button_click),
353 app
354 );
355
270 handle->file_status_image = GTK_IMAGE( 356 handle->file_status_image = GTK_IMAGE(
271 gtk_builder_get_object(builder, "file_status_image") 357 gtk_builder_get_object(builder, "file_status_image")
272 ); 358 );
273 359
360 g_hash_table_insert(app->ui.bindings, handle->file_button, handle);
361
274 handle->preview_drawing_area = GTK_DRAWING_AREA( 362 handle->preview_drawing_area = GTK_DRAWING_AREA(
275 gtk_builder_get_object(builder, "preview_drawing_area") 363 gtk_builder_get_object(builder, "preview_drawing_area")
276 ); 364 );
@@ -308,15 +396,37 @@ ui_message_new(MESSENGER_Application *app,
308 396
309void 397void
310ui_message_update(UI_MESSAGE_Handle *handle, 398ui_message_update(UI_MESSAGE_Handle *handle,
399 MESSENGER_Application *app,
311 const struct GNUNET_CHAT_Message *msg) 400 const struct GNUNET_CHAT_Message *msg)
312{ 401{
313 struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg); 402 struct GNUNET_CHAT_File *file = NULL;
403
404 if (msg)
405 file = GNUNET_CHAT_message_get_file(msg);
406 else
407 file = g_hash_table_lookup(app->ui.bindings, handle->message_box);
314 408
315 if (!file) 409 if (!file)
316 return; 410 return;
317 411
318 if (GNUNET_YES != GNUNET_CHAT_file_is_local(file)) 412 if (g_hash_table_contains(app->ui.bindings, handle->message_box))
413 g_hash_table_replace(app->ui.bindings, handle->message_box, file);
414 else
415 g_hash_table_insert(app->ui.bindings, handle->message_box, file);
416
417 uint64_t size = GNUNET_CHAT_file_get_size(file);
418 uint64_t local_size = GNUNET_CHAT_file_get_local_size(file);
419
420 if ((size <= 0) || (size > local_size))
421 {
422 gtk_image_set_from_icon_name(
423 handle->file_status_image,
424 "folder-download-symbolic",
425 GTK_ICON_SIZE_BUTTON
426 );
427
319 goto file_content; 428 goto file_content;
429 }
320 430
321 if (!(handle->preview_drawing_area)) 431 if (!(handle->preview_drawing_area))
322 goto file_progress; 432 goto file_progress;
@@ -336,14 +446,14 @@ ui_message_update(UI_MESSAGE_Handle *handle,
336 if ((handle->preview_animation) || (handle->preview_animation)) 446 if ((handle->preview_animation) || (handle->preview_animation))
337 { 447 {
338 gtk_widget_set_size_request( 448 gtk_widget_set_size_request(
339 GTK_WIDGET(handle->preview_drawing_area), 449 GTK_WIDGET(handle->preview_drawing_area),
340 250, 450 250,
341 -1 451 -1
342 ); 452 );
343 453
344 gtk_stack_set_visible_child( 454 gtk_stack_set_visible_child(
345 handle->content_stack, 455 handle->content_stack,
346 GTK_WIDGET(handle->preview_drawing_area) 456 GTK_WIDGET(handle->preview_drawing_area)
347 ); 457 );
348 458
349 gtk_widget_queue_draw(GTK_WIDGET(handle->preview_drawing_area)); 459 gtk_widget_queue_draw(GTK_WIDGET(handle->preview_drawing_area));
@@ -355,6 +465,12 @@ ui_message_update(UI_MESSAGE_Handle *handle,
355file_progress: 465file_progress:
356 gtk_progress_bar_set_fraction(handle->file_progress_bar, 1.0); 466 gtk_progress_bar_set_fraction(handle->file_progress_bar, 1.0);
357 467
468 gtk_image_set_from_icon_name(
469 handle->file_status_image,
470 "document-open-symbolic",
471 GTK_ICON_SIZE_BUTTON
472 );
473
358file_content: 474file_content:
359 gtk_label_set_text(handle->filename_label, GNUNET_CHAT_file_get_name(file)); 475 gtk_label_set_text(handle->filename_label, GNUNET_CHAT_file_get_name(file));
360 476
@@ -364,6 +480,11 @@ file_content:
364 ); 480 );
365 481
366 gtk_revealer_set_reveal_child(handle->file_revealer, TRUE); 482 gtk_revealer_set_reveal_child(handle->file_revealer, TRUE);
483
484 if (g_hash_table_contains(app->ui.bindings, handle->file_progress_bar))
485 g_hash_table_replace(app->ui.bindings, handle->file_progress_bar, file);
486 else
487 g_hash_table_insert(app->ui.bindings, handle->file_progress_bar, file);
367} 488}
368 489
369void 490void