diff options
author | xengineering <me@xengineering.eu> | 2022-08-17 12:37:05 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-08-19 12:13:49 +0200 |
commit | c584fa579ab1ce12e162580a6e443b9035dd3f88 (patch) | |
tree | 15f08a4deb3577f28cd4cadbab7747d3012f55d2 /gtk.c | |
parent | e7dd56d2ac25afccf578454e06f02f45187248b9 (diff) | |
download | limox-c584fa579ab1ce12e162580a6e443b9035dd3f88.tar limox-c584fa579ab1ce12e162580a6e443b9035dd3f88.tar.zst limox-c584fa579ab1ce12e162580a6e443b9035dd3f88.zip |
Add new chat page creation
Diffstat (limited to 'gtk.c')
-rw-r--r-- | gtk.c | 133 |
1 files changed, 48 insertions, 85 deletions
@@ -6,17 +6,6 @@ #include "limox.h" -struct chat { - GtkWidget* chat_layout_box; // the layout box of the chat page - GtkWidget* chat_content_box; // the content box of the chat page - GtkWidget* text_entry; // where new messages are typed - struct chat* next; // entry to support the linked list -}; - - -// linked list of chats -static struct chat* chats = NULL; - // the GTK application is available as global variable static GtkApplication* app; @@ -69,77 +58,22 @@ static void disconnect_cb(void) { limox_disconnect(); } -static void to_chat(GtkWidget* layout_box) { - gtk_stack_set_visible_child(GTK_STACK(stack), layout_box); -} - -static void to_roster(void) { - gtk_stack_set_visible_child(GTK_STACK(stack), roster_layout_box); -} - -void send_message(struct chat* chat) { - - // get recipient and message text - const char* recipient = "dummy@example.com"; // TODO reimplement this - const char* text = gtk_editable_get_text(GTK_EDITABLE(chat->text_entry)); - - // execute dummy XMPP send TODO - printf("Sending to %s:\n> %s\n", recipient, text); - - // add message content to the chat - GtkWidget* message = gtk_label_new(text); - gtk_box_append(GTK_BOX(chat->chat_content_box), message); - - // clear text input - GtkEntryBuffer* empty_buffer = gtk_entry_buffer_new("", 0); - gtk_entry_set_buffer(GTK_ENTRY(chat->text_entry), empty_buffer); -} - -void add_chat(char* jid) { - - // create chat struct and initialize - struct chat* chat = malloc(sizeof(struct chat)); - chat->chat_layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20); - chat->chat_content_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); - chat->text_entry = gtk_entry_new(); - chat->next = NULL; +void send_message() { - // add chat page to stack - gtk_stack_add_child(GTK_STACK(stack), chat->chat_layout_box); + //// get recipient and message text + //const char* recipient = "dummy@example.com"; // TODO reimplement this + //const char* text = gtk_editable_get_text(GTK_EDITABLE(chat->text_entry)); - // add a button to go back to roster - GtkWidget* back = gtk_button_new_with_label("back"); - gtk_box_append(GTK_BOX(chat->chat_layout_box), back); - g_signal_connect_swapped(back, "clicked", G_CALLBACK(to_roster), NULL); - - // add a scrolled window to chat page - GtkWidget* scrolled = gtk_scrolled_window_new(); - gtk_widget_set_vexpand(scrolled, TRUE); - gtk_box_append(GTK_BOX(chat->chat_layout_box), scrolled); - gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), - chat->chat_content_box); + //// execute dummy XMPP send TODO + //printf("Sending to %s:\n> %s\n", recipient, text); - // add text entry and send button to chat page - gtk_box_append(GTK_BOX(chat->chat_layout_box), chat->text_entry); - GtkWidget* send_button = gtk_button_new_with_label("send"); - gtk_box_append(GTK_BOX(chat->chat_layout_box), send_button); - g_signal_connect_swapped(send_button, "clicked", G_CALLBACK(send_message), - chat); - - // append chat to linked list of chats - struct chat* current = chats; - while (true) { - if (current == NULL) { - chats = chat; - break; - } else if (current->next == NULL) { - current->next = chat; - break; - } else { - current = current->next; - } - } + //// add message content to the chat + //GtkWidget* message = gtk_label_new(text); + //gtk_box_append(GTK_BOX(chat->chat_content_box), message); + //// clear text input + //GtkEntryBuffer* empty_buffer = gtk_entry_buffer_new("", 0); + //gtk_entry_set_buffer(GTK_ENTRY(chat->text_entry), empty_buffer); } void add_incoming_text_message(char* sender_jid, char* content) { @@ -206,13 +140,6 @@ static void build_static_widgets(void) { roster_content_box); gtk_box_append(GTK_BOX(roster_layout_box), roster_scrolled); - // TODO just for debugging - for (int i=0; i<20; i++) { - add_incoming_text_message("contact-2@example.com", "Just a test."); - // message = gtk_label_new("Test message"); - // gtk_box_append(GTK_BOX(chat->chat_content_box), message); - } - } static void activate(void) { @@ -251,6 +178,42 @@ void gui_run(void) { } +void* gui_add_chat(void) { + + // create chat page (GtkBox) and add it to the stack + GtkWidget* chat_layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20); + gtk_stack_add_child(GTK_STACK(stack), chat_layout_box); + + // create and add back button + GtkWidget* back = gtk_button_new_with_label("back"); + gtk_box_append(GTK_BOX(chat_layout_box), back); + //g_signal_connect_swapped(back, "clicked", G_CALLBACK(to_roster), NULL); TODO + + // create and add scrolled window + GtkWidget* scrolled = gtk_scrolled_window_new(); + gtk_widget_set_vexpand(scrolled, TRUE); + gtk_box_append(GTK_BOX(chat_layout_box), scrolled); + + // create and add content box for dynamic message widgets + GtkWidget* chat_content_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); + gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), + chat_content_box); + + // create and add text input field + GtkWidget* text_entry = gtk_entry_new(); + gtk_box_append(GTK_BOX(chat_layout_box), text_entry); + + // create and add send button + GtkWidget* send_button = gtk_button_new_with_label("send"); + gtk_box_append(GTK_BOX(chat_layout_box), send_button); + //g_signal_connect_swapped(send_button, "clicked", G_CALLBACK(send_message), + // chat); // TODO + + // return chat page as void pointer for future reference + return (void*)chat_layout_box; + +} + void gui_add_message(const char* sender_jid, const char* content) { printf("Received from %s:\n%s\n", sender_jid, content); |