aboutsummaryrefslogtreecommitdiff
path: root/src/event.c
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-13 13:56:02 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-13 13:56:02 +0100
commit43019c37a2a12147c401d75327e19e2ac383d6f4 (patch)
tree50c569d564b9c75559e1d7165f973ae956da04a1 /src/event.c
parent85b243c149d96ac88c5afd20993bbe18c50e16ca (diff)
downloadmessenger-gtk-43019c37a2a12147c401d75327e19e2ac383d6f4.tar.gz
messenger-gtk-43019c37a2a12147c401d75327e19e2ac383d6f4.zip
Added warning handling and leave messages, cleaning some code and fixed issue with QR pixel data
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/event.c')
-rw-r--r--src/event.c120
1 files changed, 93 insertions, 27 deletions
diff --git a/src/event.c b/src/event.c
index c4f3a19..544bf43 100644
--- a/src/event.c
+++ b/src/event.c
@@ -51,7 +51,8 @@ _show_notification(MESSENGER_Application *app,
51 UNUSED struct GNUNET_CHAT_Context *context, 51 UNUSED struct GNUNET_CHAT_Context *context,
52 const struct GNUNET_CHAT_Contact *contact, 52 const struct GNUNET_CHAT_Contact *contact,
53 const gchar *text, 53 const gchar *text,
54 const gchar *icon) 54 const gchar *icon,
55 const gchar *category)
55{ 56{
56 if (app->settings.disable_notifications) 57 if (app->settings.disable_notifications)
57 return; 58 return;
@@ -67,10 +68,7 @@ _show_notification(MESSENGER_Application *app,
67 68
68 app->notifications = g_list_append(app->notifications, notification); 69 app->notifications = g_list_append(app->notifications, notification);
69 70
70 if (0 == g_strcmp0(icon, "avatar-default-symbolic")) 71 notify_notification_set_category(notification, category);
71 notify_notification_set_category(notification, "presence.online");
72 else
73 notify_notification_set_category(notification, "im.received");
74 72
75 g_signal_connect( 73 g_signal_connect(
76 notification, 74 notification,
@@ -82,15 +80,25 @@ _show_notification(MESSENGER_Application *app,
82 notify_notification_show(notification, NULL); 80 notify_notification_show(notification, NULL);
83} 81}
84 82
85static void 83void
86_clear_each_selectable_widget(GtkWidget *widget, 84event_handle_warning(MESSENGER_Application *app,
87 gpointer user_data) 85 struct GNUNET_CHAT_Context *context,
86 const struct GNUNET_CHAT_Message *msg)
88{ 87{
89 GtkContainer *container = GTK_CONTAINER(user_data); 88 const gchar *text = GNUNET_CHAT_message_get_text(msg);
90 GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget);
91 89
92 if (gtk_list_box_row_get_selectable(row)) 90 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
93 gtk_container_remove(container, widget); 91 msg
92 );
93
94 _show_notification(
95 app,
96 context,
97 contact,
98 text,
99 "dialog-warning-symbolic",
100 "im.error"
101 );
94} 102}
95 103
96void 104void
@@ -177,6 +185,48 @@ _iterate_profile_groups(void *cls,
177 return GNUNET_YES; 185 return GNUNET_YES;
178} 186}
179 187
188static void
189_clear_chat_entry(GtkWidget *widget,
190 gpointer user_data)
191{
192 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
193
194 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
195 GtkListBoxRow *row = GTK_LIST_BOX_ROW(widget);
196
197 if (!gtk_list_box_row_get_selectable(row))
198 return;
199
200 UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) g_object_get_qdata(
201 G_OBJECT(row),
202 app->quarks.ui
203 );
204
205 ui->chat_entries = g_list_remove(ui->chat_entries, entry);
206
207 gtk_container_remove(
208 GTK_CONTAINER(ui->chats_listbox),
209 widget
210 );
211
212 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
213 g_object_get_qdata(
214 G_OBJECT(entry->chat->send_text_view),
215 app->quarks.data
216 )
217 );
218
219 if (context)
220 GNUNET_CHAT_context_set_user_pointer(context, NULL);
221
222 gtk_container_remove(
223 GTK_CONTAINER(ui->chats_stack),
224 entry->chat->chat_box
225 );
226
227 ui_chat_entry_delete(entry);
228}
229
180void 230void
181event_update_profile(MESSENGER_Application *app) 231event_update_profile(MESSENGER_Application *app)
182{ 232{
@@ -198,8 +248,8 @@ event_update_profile(MESSENGER_Application *app)
198 248
199 gtk_container_foreach( 249 gtk_container_foreach(
200 GTK_CONTAINER(ui->chats_listbox), 250 GTK_CONTAINER(ui->chats_listbox),
201 _clear_each_selectable_widget, 251 _clear_chat_entry,
202 ui->chats_listbox 252 app
203 ); 253 );
204 254
205 gtk_stack_set_visible_child(ui->chats_stack, ui->no_chat_box); 255 gtk_stack_set_visible_child(ui->chats_stack, ui->no_chat_box);
@@ -215,10 +265,17 @@ event_update_chats(MESSENGER_Application *app,
215{ 265{
216 UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); 266 UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context);
217 267
218 if (!handle) 268 const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(
219 _add_new_chat_entry(app, context); 269 msg
220 else 270 );
221 ui_chat_entry_update(handle, app, context); 271
272 if (GNUNET_CHAT_KIND_JOIN == kind)
273 if (!handle)
274 _add_new_chat_entry(app, context);
275 else
276 ui_chat_entry_update(handle, app, context);
277 else if (handle)
278 _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app);
222 279
223 contact_create_info(GNUNET_CHAT_message_get_sender(msg)); 280 contact_create_info(GNUNET_CHAT_message_get_sender(msg));
224} 281}
@@ -243,9 +300,9 @@ _update_contact_context(MESSENGER_Application *app,
243} 300}
244 301
245void 302void
246event_joining_contact(MESSENGER_Application *app, 303event_presence_contact(MESSENGER_Application *app,
247 struct GNUNET_CHAT_Context *context, 304 struct GNUNET_CHAT_Context *context,
248 const struct GNUNET_CHAT_Message *msg) 305 const struct GNUNET_CHAT_Message *msg)
249{ 306{
250 UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); 307 UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context);
251 308
@@ -259,6 +316,10 @@ event_joining_contact(MESSENGER_Application *app,
259 if (!contact) 316 if (!contact)
260 return; 317 return;
261 318
319 const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(
320 msg
321 );
322
262 UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) ( 323 UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) (
263 GNUNET_CHAT_member_get_user_pointer(context, contact) 324 GNUNET_CHAT_member_get_user_pointer(context, contact)
264 ); 325 );
@@ -275,15 +336,18 @@ event_joining_contact(MESSENGER_Application *app,
275 contact_add_name_avatar_to_info(contact, message->sender_avatar); 336 contact_add_name_avatar_to_info(contact, message->sender_avatar);
276 contact_add_name_label_to_info(contact, message->sender_label); 337 contact_add_name_label_to_info(contact, message->sender_label);
277 338
278 const gchar *join_message = _("joined the chat"); 339 const gchar *presence_message = (
340 GNUNET_CHAT_KIND_JOIN == kind? _("joined the chat") : _("left the chat")
341 );
279 342
280 if (!ui_messenger_is_context_active(&(app->ui.messenger), context)) 343 if (!ui_messenger_is_context_active(&(app->ui.messenger), context))
281 _show_notification( 344 _show_notification(
282 app, 345 app,
283 context, 346 context,
284 contact, 347 contact,
285 join_message, 348 presence_message,
286 "avatar-default-symbolic" 349 "avatar-default-symbolic",
350 "presence.online"
287 ); 351 );
288 352
289 struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp( 353 struct GNUNET_TIME_Absolute timestamp = GNUNET_CHAT_message_get_timestamp(
@@ -292,7 +356,7 @@ event_joining_contact(MESSENGER_Application *app,
292 356
293 const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); 357 const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp);
294 358
295 gtk_label_set_text(message->text_label, join_message); 359 gtk_label_set_text(message->text_label, presence_message);
296 gtk_label_set_text(message->timestamp_label, time? time : ""); 360 gtk_label_set_text(message->timestamp_label, time? time : "");
297 361
298 ui_chat_add_message(handle->chat, app, message); 362 ui_chat_add_message(handle->chat, app, message);
@@ -370,7 +434,8 @@ event_invitation(MESSENGER_Application *app,
370 context, 434 context,
371 contact, 435 contact,
372 invite_message, 436 invite_message,
373 "mail-message-new-symbolic" 437 "mail-message-new-symbolic",
438 "im.received"
374 ); 439 );
375 440
376 gtk_label_set_text(message->text_label, invite_message); 441 gtk_label_set_text(message->text_label, invite_message);
@@ -441,7 +506,8 @@ event_receive_message(MESSENGER_Application *app,
441 context, 506 context,
442 contact, 507 contact,
443 text, 508 text,
444 "mail-unread-symbolic" 509 "mail-unread-symbolic",
510 "im.received"
445 ); 511 );
446 512
447 gtk_label_set_text(message->text_label, text? text : ""); 513 gtk_label_set_text(message->text_label, text? text : "");