diff options
author | xengineering <me@xengineering.eu> | 2022-08-19 10:51:24 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-08-19 12:13:49 +0200 |
commit | 43aa02ccbd484d8c7cecec7c38c446847b34e007 (patch) | |
tree | 5e34779ee75c8788760d74a9f73a01575c335f54 /gtk.c | |
parent | 4c848f4085cd174d1ad54169632a95023774717b (diff) | |
download | limox-43aa02ccbd484d8c7cecec7c38c446847b34e007.tar limox-43aa02ccbd484d8c7cecec7c38c446847b34e007.tar.zst limox-43aa02ccbd484d8c7cecec7c38c446847b34e007.zip |
Implement new datastructures
Diffstat (limited to 'gtk.c')
-rw-r--r-- | gtk.c | 39 |
1 files changed, 22 insertions, 17 deletions
@@ -185,7 +185,7 @@ static void to_roster(void) { } -void* gui_add_chat(void) { +void gui_add_chat_widget(chat_t* chat) { // create chat page (GtkBox) and add it to the stack GtkWidget* chat_layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20); @@ -206,6 +206,9 @@ void* gui_add_chat(void) { gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), chat_content_box); + // save widget pointer + chat->widget = (void*)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); @@ -216,44 +219,46 @@ void* gui_add_chat(void) { //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) { +void gui_add_message_widget(message_t* message, chat_t* chat) { - printf("Received from %s:\n%s\n", sender_jid, content); + // TODO + printf("Received from %s:\n%s\n", message->sender_jid, message->content); } -static void to_chat(GtkWidget* roster_item_widget) { +static void to_chat(chat_t* chat) { - GtkWidget* chat_page = data_get_chat_page((void*)roster_item_widget); + //GtkWidget* chat_page = data_get_chat_page((void*)roster_item_widget); + GtkWidget* chat_page = chat->widget; // initialize as a far child + for (int i=0; i<3; i++) { // and then jump three levels up + chat_page = gtk_widget_get_parent(chat_page); + } gtk_stack_set_visible_child(GTK_STACK(stack), chat_page); } -void* gui_add_roster_item(const char* jid, const char* sub, const char* name) { +void gui_add_roster_item_widget(roster_item_t* item) { // print debug message - if (name) { - printf("roster item: %s, %s, sub:%s\n", name, jid, sub); + if (item->name) { + printf("roster item: %s, %s, sub:%d\n", item->name, item->jid, + item->sub); } else { - printf("roster item: (no name), %s, sub:%s\n", jid, sub); + printf("roster item: (no name), %s, sub:%d\n", item->jid, item->sub); } // create widget for roster item GtkWidget* roster_item_widget; - if (name == NULL || strcmp(name, "") == 0) { - roster_item_widget = gtk_button_new_with_label(name); + if (item->name == NULL || strcmp(item->name, "") == 0) { + roster_item_widget = gtk_button_new_with_label(item->jid); } else { - roster_item_widget = gtk_button_new_with_label(jid); + roster_item_widget = gtk_button_new_with_label(item->name); } // add roster item widget to roster page gtk_box_append(GTK_BOX(roster_content_box), roster_item_widget); g_signal_connect_swapped(roster_item_widget, "clicked", G_CALLBACK(to_chat), - roster_item_widget); + item->chat); - return (void*)roster_item_widget; } |