summaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-19 12:13:32 +0200
committerxengineering <me@xengineering.eu>2022-08-19 12:15:39 +0200
commit8d707d0dd403b4fdef885956f31dad43dee0a91b (patch)
tree7720cfca40f0f22e3a02002b4a3345596a0184b6 /gtk.c
parent43aa02ccbd484d8c7cecec7c38c446847b34e007 (diff)
downloadlimox-8d707d0dd403b4fdef885956f31dad43dee0a91b.tar
limox-8d707d0dd403b4fdef885956f31dad43dee0a91b.tar.zst
limox-8d707d0dd403b4fdef885956f31dad43dee0a91b.zip
Implement incoming messages
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/gtk.c b/gtk.c
index 9813531..0f03472 100644
--- a/gtk.c
+++ b/gtk.c
@@ -77,35 +77,6 @@ void send_message() {
//gtk_entry_set_buffer(GTK_ENTRY(chat->text_entry), empty_buffer);
}
-void add_incoming_text_message(char* sender_jid, char* content) {
-
- printf("Trying to add message '%s' to chat with '%s'.\n", content, sender_jid);
-
- // do not add message if list of chats is empty
- //if (chats == NULL) {
- // return;
- //}
-
- // find chat with corresponding JID
- //struct chat* chat = chats;
- //while (true) {
- // const char* jid = gtk_button_get_label(GTK_BUTTON(chat->roster_item));
- // if (strcmp(jid, sender_jid) == 0) {
- // break; // this seems to be the correct chat
- // } else if (chat->next == NULL) {
- // return; // no matching chat found - cannot add message
- // } else {
- // chat = chat->next; // go to next chat in linked list
- // }
- //}
-
-
- // add given message content to the chat
- //GtkWidget* message = gtk_label_new(content);
- //gtk_box_append(GTK_BOX(chat->chat_content_box), message);
-
-}
-
static void build_static_widgets(void) {
// main window with stack
@@ -223,8 +194,18 @@ void gui_add_chat_widget(chat_t* chat) {
void gui_add_message_widget(message_t* message, chat_t* chat) {
- // TODO
- printf("Received from %s:\n%s\n", message->sender_jid, message->content);
+ const char* connector = "\n";
+ char* label_content = malloc(sizeof(char)*(strlen(message->sender_jid)
+ + strlen(connector)
+ + strlen(message->content)));
+ sprintf(label_content, "%s%s%s", message->sender_jid, connector,
+ message->content);
+ GtkWidget* label = gtk_label_new(label_content);
+ gtk_label_set_wrap(GTK_LABEL(label), TRUE);
+ message->widget = (void*)label;
+ gtk_box_append(GTK_BOX(chat->widget), label);
+ free(label_content);
+
}
static void to_chat(chat_t* chat) {