aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-15 19:19:30 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-15 19:19:30 +0100
commit275ac387f9248f2095297cec465fc2c0c90da2d8 (patch)
treef5101c135306607359c46395bc91b74bd7dd425e /src/ui
parent5e1a9a66817f14e2d39962b3ebcee7752925aa95 (diff)
downloadmessenger-gtk-275ac387f9248f2095297cec465fc2c0c90da2d8.tar.gz
messenger-gtk-275ac387f9248f2095297cec465fc2c0c90da2d8.zip
Added button to leave the chat
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/chat.c112
-rw-r--r--src/ui/chat.h10
-rw-r--r--src/ui/chat_entry.c36
-rw-r--r--src/ui/chat_entry.h6
4 files changed, 157 insertions, 7 deletions
diff --git a/src/ui/chat.c b/src/ui/chat.c
index b96ecd5..c0ea685 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -27,6 +27,7 @@
27#include <gdk/gdkkeysyms.h> 27#include <gdk/gdkkeysyms.h>
28#include <stdlib.h> 28#include <stdlib.h>
29 29
30#include "chat_entry.h"
30#include "file_load_entry.h" 31#include "file_load_entry.h"
31#include "message.h" 32#include "message.h"
32#include "messenger.h" 33#include "messenger.h"
@@ -154,6 +155,55 @@ handle_back_button_click(UNUSED GtkButton *button,
154 } 155 }
155} 156}
156 157
158static void
159handle_reveal_identity_button_click(UNUSED GtkButton *button,
160 gpointer user_data)
161{
162 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data;
163
164 // TODO
165}
166
167static void
168handle_leave_chat_button_click(UNUSED GtkButton *button,
169 gpointer user_data)
170{
171 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data;
172
173 if ((!handle) || (!(handle->send_text_view)))
174 return;
175
176 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
177 g_object_get_qdata(
178 G_OBJECT(handle->send_text_view),
179 handle->app->quarks.data
180 )
181 );
182
183 if (!context)
184 return;
185
186 struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact(
187 context
188 );
189
190 struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(
191 context
192 );
193
194 if (contact)
195 GNUNET_CHAT_contact_delete(contact);
196 else if (group)
197 GNUNET_CHAT_group_leave(group);
198
199 UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context);
200
201 if ((!entry) || (!(handle->app)))
202 return;
203
204 ui_chat_entry_dispose(entry, handle->app);
205}
206
157static gint 207static gint
158handle_chat_messages_sort(GtkListBoxRow* row0, 208handle_chat_messages_sort(GtkListBoxRow* row0,
159 GtkListBoxRow* row1, 209 GtkListBoxRow* row1,
@@ -1089,6 +1139,40 @@ ui_chat_new(MESSENGER_Application *app)
1089 gtk_builder_get_object(handle->builder, "chat_details_contacts_box") 1139 gtk_builder_get_object(handle->builder, "chat_details_contacts_box")
1090 ); 1140 );
1091 1141
1142 handle->chat_details_files_box = GTK_BOX(
1143 gtk_builder_get_object(handle->builder, "chat_details_files_box")
1144 );
1145
1146 handle->chat_details_avatar = HDY_AVATAR(
1147 gtk_builder_get_object(handle->builder, "chat_details_avatar")
1148 );
1149
1150 handle->reveal_identity_button = GTK_BUTTON(
1151 gtk_builder_get_object(handle->builder, "reveal_identity_button")
1152 );
1153
1154 g_signal_connect(
1155 handle->reveal_identity_button,
1156 "clicked",
1157 G_CALLBACK(handle_reveal_identity_button_click),
1158 handle
1159 );
1160
1161 handle->leave_chat_button = GTK_BUTTON(
1162 gtk_builder_get_object(handle->builder, "leave_chat_button")
1163 );
1164
1165 g_signal_connect(
1166 handle->leave_chat_button,
1167 "clicked",
1168 G_CALLBACK(handle_leave_chat_button_click),
1169 handle
1170 );
1171
1172 handle->chat_notifications_switch = GTK_SWITCH(
1173 gtk_builder_get_object(handle->builder, "chat_notifications_switch")
1174 );
1175
1092 handle->selection_close_button = GTK_BUTTON( 1176 handle->selection_close_button = GTK_BUTTON(
1093 gtk_builder_get_object(handle->builder, "selection_close_button") 1177 gtk_builder_get_object(handle->builder, "selection_close_button")
1094 ); 1178 );
@@ -1355,7 +1439,7 @@ iterate_ui_chat_update_group_contacts(void *cls,
1355void 1439void
1356ui_chat_update(UI_CHAT_Handle *handle, 1440ui_chat_update(UI_CHAT_Handle *handle,
1357 MESSENGER_Application *app, 1441 MESSENGER_Application *app,
1358 const struct GNUNET_CHAT_Context* context) 1442 struct GNUNET_CHAT_Context* context)
1359{ 1443{
1360 GNUNET_assert((handle) && (app) && (context)); 1444 GNUNET_assert((handle) && (app) && (context));
1361 1445
@@ -1366,14 +1450,24 @@ ui_chat_update(UI_CHAT_Handle *handle,
1366 group = GNUNET_CHAT_context_get_group(context); 1450 group = GNUNET_CHAT_context_get_group(context);
1367 1451
1368 const char *title = NULL; 1452 const char *title = NULL;
1453 const char *icon = "action-unavailable-symbolic";
1454
1369 GString *subtitle = g_string_new(""); 1455 GString *subtitle = g_string_new("");
1370 1456
1371 if (contact) 1457 if (contact)
1458 {
1372 title = GNUNET_CHAT_contact_get_name(contact); 1459 title = GNUNET_CHAT_contact_get_name(contact);
1460 icon = "avatar-default-symbolic";
1461 }
1373 else if (group) 1462 else if (group)
1374 { 1463 {
1375 title = GNUNET_CHAT_group_get_name(group); 1464 title = GNUNET_CHAT_group_get_name(group);
1376 1465
1466 if ((title) && ('#' == *title))
1467 icon = "network-wired-symbolic";
1468 else
1469 icon = "system-users-symbolic";
1470
1377 g_string_append_printf( 1471 g_string_append_printf(
1378 subtitle, 1472 subtitle,
1379 _("%d members"), 1473 _("%d members"),
@@ -1381,6 +1475,12 @@ ui_chat_update(UI_CHAT_Handle *handle,
1381 ); 1475 );
1382 } 1476 }
1383 1477
1478 hdy_avatar_set_text(handle->chat_avatar, title? title : "");
1479 hdy_avatar_set_icon_name(handle->chat_avatar, icon);
1480
1481 hdy_avatar_set_text(handle->chat_details_avatar, title? title : "");
1482 hdy_avatar_set_icon_name(handle->chat_details_avatar, icon);
1483
1384 if (title) 1484 if (title)
1385 { 1485 {
1386 gtk_label_set_text(handle->chat_title, title); 1486 gtk_label_set_text(handle->chat_title, title);
@@ -1424,6 +1524,16 @@ ui_chat_update(UI_CHAT_Handle *handle,
1424 group? TRUE : FALSE 1524 group? TRUE : FALSE
1425 ); 1525 );
1426 1526
1527 gtk_widget_set_visible(
1528 GTK_WIDGET(handle->reveal_identity_button),
1529 contact? TRUE : FALSE
1530 );
1531
1532 gtk_widget_set_sensitive(
1533 GTK_WIDGET(handle->leave_chat_button),
1534 (contact) || (group)? TRUE : FALSE
1535 );
1536
1427 const int status = GNUNET_CHAT_context_get_status(context); 1537 const int status = GNUNET_CHAT_context_get_status(context);
1428 const gboolean activated = (GNUNET_OK == status? TRUE : FALSE); 1538 const gboolean activated = (GNUNET_OK == status? TRUE : FALSE);
1429 1539
diff --git a/src/ui/chat.h b/src/ui/chat.h
index 5173596..e28374c 100644
--- a/src/ui/chat.h
+++ b/src/ui/chat.h
@@ -90,6 +90,14 @@ typedef struct UI_CHAT_Handle
90 GtkLabel *chat_details_label; 90 GtkLabel *chat_details_label;
91 GtkButton *hide_chat_details_button; 91 GtkButton *hide_chat_details_button;
92 GtkBox *chat_details_contacts_box; 92 GtkBox *chat_details_contacts_box;
93 GtkBox *chat_details_files_box;
94
95 HdyAvatar *chat_details_avatar;
96
97 GtkButton *reveal_identity_button;
98 GtkButton *leave_chat_button;
99
100 GtkSwitch *chat_notifications_switch;
93 101
94 GtkButton *selection_close_button; 102 GtkButton *selection_close_button;
95 GtkLabel *selection_count_label; 103 GtkLabel *selection_count_label;
@@ -128,7 +136,7 @@ ui_chat_new(MESSENGER_Application *app);
128void 136void
129ui_chat_update(UI_CHAT_Handle *handle, 137ui_chat_update(UI_CHAT_Handle *handle,
130 MESSENGER_Application *app, 138 MESSENGER_Application *app,
131 const struct GNUNET_CHAT_Context* context); 139 struct GNUNET_CHAT_Context* context);
132 140
133void 141void
134ui_chat_delete(UI_CHAT_Handle *handle); 142ui_chat_delete(UI_CHAT_Handle *handle);
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c
index f538978..7ba67d2 100644
--- a/src/ui/chat_entry.c
+++ b/src/ui/chat_entry.c
@@ -71,7 +71,7 @@ ui_chat_entry_new(MESSENGER_Application *app)
71void 71void
72ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, 72ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
73 MESSENGER_Application *app, 73 MESSENGER_Application *app,
74 const struct GNUNET_CHAT_Context *context) 74 struct GNUNET_CHAT_Context *context)
75{ 75{
76 const struct GNUNET_CHAT_Contact* contact; 76 const struct GNUNET_CHAT_Contact* contact;
77 const struct GNUNET_CHAT_Group* group; 77 const struct GNUNET_CHAT_Group* group;
@@ -107,9 +107,6 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
107 107
108 ui_chat_update(handle->chat, app, context); 108 ui_chat_update(handle->chat, app, context);
109 109
110 hdy_avatar_set_text(handle->chat->chat_avatar, title? title : "");
111 hdy_avatar_set_icon_name(handle->chat->chat_avatar, icon);
112
113 if (!(handle->chat->messages)) 110 if (!(handle->chat->messages))
114 return; 111 return;
115 112
@@ -160,3 +157,34 @@ ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle)
160 157
161 g_free(handle); 158 g_free(handle);
162} 159}
160
161void
162ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle,
163 MESSENGER_Application *app)
164{
165 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
166
167 ui->chat_entries = g_list_remove(ui->chat_entries, handle);
168
169 gtk_container_remove(
170 GTK_CONTAINER(ui->chats_listbox),
171 gtk_widget_get_parent(handle->entry_box)
172 );
173
174 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) (
175 g_object_get_qdata(
176 G_OBJECT(handle->chat->send_text_view),
177 app->quarks.data
178 )
179 );
180
181 if (context)
182 GNUNET_CHAT_context_set_user_pointer(context, NULL);
183
184 gtk_container_remove(
185 GTK_CONTAINER(ui->chats_stack),
186 handle->chat->chat_box
187 );
188
189 ui_chat_entry_delete(handle);
190}
diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h
index 3a614c4..2515e2c 100644
--- a/src/ui/chat_entry.h
+++ b/src/ui/chat_entry.h
@@ -51,9 +51,13 @@ ui_chat_entry_new(MESSENGER_Application *app);
51void 51void
52ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, 52ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
53 MESSENGER_Application *app, 53 MESSENGER_Application *app,
54 const struct GNUNET_CHAT_Context *context); 54 struct GNUNET_CHAT_Context *context);
55 55
56void 56void
57ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle); 57ui_chat_entry_delete(UI_CHAT_ENTRY_Handle *handle);
58 58
59void
60ui_chat_entry_dispose(UI_CHAT_ENTRY_Handle *handle,
61 MESSENGER_Application *app);
62
59#endif /* UI_CHAT_ENTRY_H_ */ 63#endif /* UI_CHAT_ENTRY_H_ */