aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-18 01:08:15 +0100
committerJacki <jacki@thejackimonster.de>2024-01-18 01:08:15 +0100
commit74268f92c68c98757c16a7bce3b253297567744c (patch)
tree7822d52f7162f1e12e532e9246d299d478e28f13
parenta0554cc463f6b7c4ca7d2704da213a71fe28900b (diff)
downloadmessenger-gtk-74268f92c68c98757c16a7bce3b253297567744c.tar.gz
messenger-gtk-74268f92c68c98757c16a7bce3b253297567744c.zip
Add popover for sending text options
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--resources/ui/chat.ui40
-rw-r--r--resources/ui/play_media.ui1
-rw-r--r--src/ui/chat.c126
-rw-r--r--src/ui/chat.h8
-rw-r--r--src/ui/chat_entry.c1
-rw-r--r--src/ui/message.c4
-rw-r--r--src/ui/picker.c8
7 files changed, 172 insertions, 16 deletions
diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui
index f6e0fb0..f590a67 100644
--- a/resources/ui/chat.ui
+++ b/resources/ui/chat.ui
@@ -1046,4 +1046,44 @@ Author: Tobias Frisch
1046 </object> 1046 </object>
1047 </child> 1047 </child>
1048 </object> 1048 </object>
1049 <object class="GtkPopover" id="send_popover">
1050 <property name="can-focus">False</property>
1051 <property name="relative-to">send_record_button</property>
1052 <child>
1053 <object class="GtkBox">
1054 <property name="visible">True</property>
1055 <property name="can-focus">False</property>
1056 <property name="orientation">vertical</property>
1057 <child>
1058 <object class="GtkButton" id="send_later_button">
1059 <property name="label" translatable="yes">Send later</property>
1060 <property name="visible">True</property>
1061 <property name="sensitive">False</property>
1062 <property name="can-focus">True</property>
1063 <property name="receives-default">True</property>
1064 <property name="relief">none</property>
1065 </object>
1066 <packing>
1067 <property name="expand">False</property>
1068 <property name="fill">True</property>
1069 <property name="position">0</property>
1070 </packing>
1071 </child>
1072 <child>
1073 <object class="GtkButton" id="send_now_button">
1074 <property name="label" translatable="yes">Send now</property>
1075 <property name="visible">True</property>
1076 <property name="can-focus">True</property>
1077 <property name="receives-default">True</property>
1078 <property name="relief">none</property>
1079 </object>
1080 <packing>
1081 <property name="expand">False</property>
1082 <property name="fill">True</property>
1083 <property name="position">1</property>
1084 </packing>
1085 </child>
1086 </object>
1087 </child>
1088 </object>
1049</interface> 1089</interface>
diff --git a/resources/ui/play_media.ui b/resources/ui/play_media.ui
index cb2786b..4e76f4e 100644
--- a/resources/ui/play_media.ui
+++ b/resources/ui/play_media.ui
@@ -316,6 +316,7 @@ audio-volume-medium-symbolic</property>
316 <child> 316 <child>
317 <object class="GtkButton" id="settings_button"> 317 <object class="GtkButton" id="settings_button">
318 <property name="visible">True</property> 318 <property name="visible">True</property>
319 <property name="sensitive">False</property>
319 <property name="can-focus">True</property> 320 <property name="can-focus">True</property>
320 <property name="receives-default">True</property> 321 <property name="receives-default">True</property>
321 <property name="relief">none</property> 322 <property name="relief">none</property>
diff --git a/src/ui/chat.c b/src/ui/chat.c
index debf934..4844d93 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -472,7 +472,9 @@ handle_send_text_buffer_changed(GtkTextBuffer *buffer,
472 472
473static gboolean 473static gboolean
474_send_text_from_view(MESSENGER_Application *app, 474_send_text_from_view(MESSENGER_Application *app,
475 GtkTextView *text_view) 475 UI_CHAT_Handle *handle,
476 GtkTextView *text_view,
477 gint64 action_time)
476{ 478{
477 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view); 479 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view);
478 480
@@ -485,6 +487,12 @@ _send_text_from_view(MESSENGER_Application *app,
485 if (0 == strlen(text)) 487 if (0 == strlen(text))
486 return FALSE; 488 return FALSE;
487 489
490 if (action_time >= UI_CHAT_SEND_BUTTON_HOLD_INTERVAL)
491 {
492 gtk_popover_popup(handle->send_popover);
493 return FALSE;
494 }
495
488 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) ( 496 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
489 g_object_get_qdata(G_OBJECT(text_view), app->quarks.data) 497 g_object_get_qdata(G_OBJECT(text_view), app->quarks.data)
490 ); 498 );
@@ -589,7 +597,51 @@ handle_send_record_button_click(GtkButton *button,
589 g_object_get_qdata(G_OBJECT(button), app->quarks.widget) 597 g_object_get_qdata(G_OBJECT(button), app->quarks.widget)
590 ); 598 );
591 599
592 _send_text_from_view(app, text_view); 600 _send_text_from_view(app, handle, text_view, handle->send_pressed_time);
601}
602
603static void
604handle_send_later_button_click(GtkButton *button,
605 gpointer user_data)
606{
607 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
608
609 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
610 g_object_get_qdata(G_OBJECT(button), app->quarks.ui)
611 );
612
613 handle->send_pressed_time = 0;
614
615 if (gtk_widget_is_visible(GTK_WIDGET(handle->send_popover)))
616 gtk_popover_popdown(handle->send_popover);
617
618 if (gtk_stack_get_visible_child(handle->send_stack) != handle->send_text_box)
619 return;
620
621 // TODO
622}
623
624static void
625handle_send_now_button_click(GtkButton *button,
626 gpointer user_data)
627{
628 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
629
630 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
631 g_object_get_qdata(G_OBJECT(button), app->quarks.ui)
632 );
633
634 if (gtk_widget_is_visible(GTK_WIDGET(handle->send_popover)))
635 gtk_popover_popdown(handle->send_popover);
636
637 if (gtk_stack_get_visible_child(handle->send_stack) != handle->send_text_box)
638 return;
639
640 GtkTextView *text_view = GTK_TEXT_VIEW(
641 g_object_get_qdata(G_OBJECT(handle->send_record_button), app->quarks.widget)
642 );
643
644 _send_text_from_view(app, handle, text_view, 0);
593} 645}
594 646
595static gboolean 647static gboolean
@@ -603,6 +655,12 @@ handle_send_record_button_pressed(GtkWidget *widget,
603 g_object_get_qdata(G_OBJECT(widget), app->quarks.widget) 655 g_object_get_qdata(G_OBJECT(widget), app->quarks.widget)
604 ); 656 );
605 657
658 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
659 g_object_get_qdata(G_OBJECT(widget), app->quarks.ui)
660 );
661
662 handle->send_pressed_time = g_get_monotonic_time();
663
606 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view); 664 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view);
607 665
608 GtkTextIter start, end; 666 GtkTextIter start, end;
@@ -614,10 +672,6 @@ handle_send_record_button_pressed(GtkWidget *widget,
614 if (0 < strlen(text)) 672 if (0 < strlen(text))
615 return FALSE; 673 return FALSE;
616 674
617 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
618 g_object_get_qdata(G_OBJECT(widget), app->quarks.ui)
619 );
620
621 if ((handle->recorded) || (!(handle->record_pipeline)) || 675 if ((handle->recorded) || (!(handle->record_pipeline)) ||
622 (handle->recording_filename[0]) || 676 (handle->recording_filename[0]) ||
623 (gtk_revealer_get_child_revealed(handle->picker_revealer)) || 677 (gtk_revealer_get_child_revealed(handle->picker_revealer)) ||
@@ -680,6 +734,12 @@ handle_send_record_button_released(GtkWidget *widget,
680 g_object_get_qdata(G_OBJECT(widget), app->quarks.widget) 734 g_object_get_qdata(G_OBJECT(widget), app->quarks.widget)
681 ); 735 );
682 736
737 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
738 g_object_get_qdata(G_OBJECT(widget), app->quarks.ui)
739 );
740
741 handle->send_pressed_time = g_get_monotonic_time() - handle->send_pressed_time;
742
683 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view); 743 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view);
684 744
685 GtkTextIter start, end; 745 GtkTextIter start, end;
@@ -691,10 +751,6 @@ handle_send_record_button_released(GtkWidget *widget,
691 if (0 < strlen(text)) 751 if (0 < strlen(text))
692 return FALSE; 752 return FALSE;
693 753
694 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
695 g_object_get_qdata(G_OBJECT(widget), app->quarks.ui)
696 );
697
698 if ((handle->recorded) || (!(handle->record_pipeline)) || 754 if ((handle->recorded) || (!(handle->record_pipeline)) ||
699 (!(handle->recording_filename[0])) || 755 (!(handle->recording_filename[0])) ||
700 (gtk_revealer_get_child_revealed(handle->picker_revealer)) || 756 (gtk_revealer_get_child_revealed(handle->picker_revealer)) ||
@@ -728,8 +784,12 @@ handle_send_text_key_press (GtkWidget *widget,
728 ((event->keyval != GDK_KEY_Return) && 784 ((event->keyval != GDK_KEY_Return) &&
729 (event->keyval != GDK_KEY_KP_Enter))) 785 (event->keyval != GDK_KEY_KP_Enter)))
730 return FALSE; 786 return FALSE;
787
788 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) (
789 g_object_get_qdata(G_OBJECT(widget), app->quarks.ui)
790 );
731 791
732 return _send_text_from_view(app, GTK_TEXT_VIEW(widget)); 792 return _send_text_from_view(app, handle, GTK_TEXT_VIEW(widget), 0);
733} 793}
734 794
735static void 795static void
@@ -1269,6 +1329,18 @@ ui_chat_new(MESSENGER_Application *app)
1269 gtk_builder_get_object(handle->builder, "send_record_symbol") 1329 gtk_builder_get_object(handle->builder, "send_record_symbol")
1270 ); 1330 );
1271 1331
1332 handle->send_popover = GTK_POPOVER(
1333 gtk_builder_get_object(handle->builder, "send_popover")
1334 );
1335
1336 handle->send_now_button = GTK_BUTTON(
1337 gtk_builder_get_object(handle->builder, "send_now_button")
1338 );
1339
1340 handle->send_later_button = GTK_BUTTON(
1341 gtk_builder_get_object(handle->builder, "send_later_button")
1342 );
1343
1272 GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer( 1344 GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer(
1273 handle->send_text_view 1345 handle->send_text_view
1274 ); 1346 );
@@ -1288,6 +1360,20 @@ ui_chat_new(MESSENGER_Application *app)
1288 ); 1360 );
1289 1361
1290 g_signal_connect( 1362 g_signal_connect(
1363 handle->send_later_button,
1364 "clicked",
1365 G_CALLBACK(handle_send_later_button_click),
1366 app
1367 );
1368
1369 g_signal_connect(
1370 handle->send_now_button,
1371 "clicked",
1372 G_CALLBACK(handle_send_now_button_click),
1373 app
1374 );
1375
1376 g_signal_connect(
1291 handle->send_record_button, 1377 handle->send_record_button,
1292 "button-press-event", 1378 "button-press-event",
1293 G_CALLBACK(handle_send_record_button_pressed), 1379 G_CALLBACK(handle_send_record_button_pressed),
@@ -1327,11 +1413,29 @@ ui_chat_new(MESSENGER_Application *app)
1327 ); 1413 );
1328 1414
1329 g_object_set_qdata( 1415 g_object_set_qdata(
1416 G_OBJECT(handle->send_text_view),
1417 app->quarks.ui,
1418 handle
1419 );
1420
1421 g_object_set_qdata(
1330 G_OBJECT(handle->send_record_button), 1422 G_OBJECT(handle->send_record_button),
1331 app->quarks.ui, 1423 app->quarks.ui,
1332 handle 1424 handle
1333 ); 1425 );
1334 1426
1427 g_object_set_qdata(
1428 G_OBJECT(handle->send_later_button),
1429 app->quarks.ui,
1430 handle
1431 );
1432
1433 g_object_set_qdata(
1434 G_OBJECT(handle->send_now_button),
1435 app->quarks.ui,
1436 handle
1437 );
1438
1335 handle->recording_close_button = GTK_BUTTON( 1439 handle->recording_close_button = GTK_BUTTON(
1336 gtk_builder_get_object(handle->builder, "recording_close_button") 1440 gtk_builder_get_object(handle->builder, "recording_close_button")
1337 ); 1441 );
diff --git a/src/ui/chat.h b/src/ui/chat.h
index 5d80fc4..42729aa 100644
--- a/src/ui/chat.h
+++ b/src/ui/chat.h
@@ -33,6 +33,8 @@
33 33
34#include <gnunet/gnunet_chat_lib.h> 34#include <gnunet/gnunet_chat_lib.h>
35 35
36#define UI_CHAT_SEND_BUTTON_HOLD_INTERVAL 500000 // in microseconds
37
36typedef struct MESSENGER_Application MESSENGER_Application; 38typedef struct MESSENGER_Application MESSENGER_Application;
37typedef struct UI_MESSAGE_Handle UI_MESSAGE_Handle; 39typedef struct UI_MESSAGE_Handle UI_MESSAGE_Handle;
38typedef struct UI_PICKER_Handle UI_PICKER_Handle; 40typedef struct UI_PICKER_Handle UI_PICKER_Handle;
@@ -40,6 +42,8 @@ typedef struct UI_FILE_LOAD_ENTRY_Handle UI_FILE_LOAD_ENTRY_Handle;
40 42
41typedef struct UI_CHAT_Handle 43typedef struct UI_CHAT_Handle
42{ 44{
45 gint64 send_pressed_time;
46
43 gboolean recorded; 47 gboolean recorded;
44 gboolean playing; 48 gboolean playing;
45 49
@@ -122,6 +126,10 @@ typedef struct UI_CHAT_Handle
122 GtkButton *send_record_button; 126 GtkButton *send_record_button;
123 GtkImage *send_record_symbol; 127 GtkImage *send_record_symbol;
124 128
129 GtkPopover *send_popover;
130 GtkButton *send_later_button;
131 GtkButton *send_now_button;
132
125 GtkButton *recording_close_button; 133 GtkButton *recording_close_button;
126 GtkButton *recording_play_button; 134 GtkButton *recording_play_button;
127 GtkImage *play_pause_symbol; 135 GtkImage *play_pause_symbol;
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c
index 8d90e59..b0da90d 100644
--- a/src/ui/chat_entry.c
+++ b/src/ui/chat_entry.c
@@ -27,7 +27,6 @@
27#include "message.h" 27#include "message.h"
28 28
29#include "../application.h" 29#include "../application.h"
30#include "../contact.h"
31#include "../ui.h" 30#include "../ui.h"
32#include <gnunet/gnunet_chat_lib.h> 31#include <gnunet/gnunet_chat_lib.h>
33#include <gnunet/gnunet_time_lib.h> 32#include <gnunet/gnunet_time_lib.h>
diff --git a/src/ui/message.c b/src/ui/message.c
index bcd8e51..7c4d2e6 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -517,6 +517,10 @@ _message_media_supports_file_extension(const gchar *filename)
517 517
518 if (0 == g_strcmp0(extension, ".ogg")) 518 if (0 == g_strcmp0(extension, ".ogg"))
519 return TRUE; 519 return TRUE;
520 if (0 == g_strcmp0(extension, ".mp3"))
521 return TRUE;
522 if (0 == g_strcmp0(extension, ".wav"))
523 return TRUE;
520 524
521 return FALSE; 525 return FALSE;
522} 526}
diff --git a/src/ui/picker.c b/src/ui/picker.c
index e8d45d9..61ca4ba 100644
--- a/src/ui/picker.c
+++ b/src/ui/picker.c
@@ -32,7 +32,7 @@
32 32
33static void 33static void
34handle_emoji_button_click(GtkButton *button, 34handle_emoji_button_click(GtkButton *button,
35 gpointer user_data) 35 gpointer user_data)
36{ 36{
37 GtkTextView *text_view = GTK_TEXT_VIEW(user_data); 37 GtkTextView *text_view = GTK_TEXT_VIEW(user_data);
38 GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(text_view); 38 GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(text_view);
@@ -45,9 +45,9 @@ handle_emoji_button_click(GtkButton *button,
45 45
46static void 46static void
47_add_emoji_buttons(GtkFlowBox *flow_box, 47_add_emoji_buttons(GtkFlowBox *flow_box,
48 GtkTextView *text_view, 48 GtkTextView *text_view,
49 size_t characters_count, 49 size_t characters_count,
50 const uint32_t *characters) 50 const uint32_t *characters)
51{ 51{
52 glong items_written; 52 glong items_written;
53 GError *error; 53 GError *error;