summaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-17 12:07:36 +0200
committerxengineering <me@xengineering.eu>2022-08-19 12:13:49 +0200
commite7dd56d2ac25afccf578454e06f02f45187248b9 (patch)
treed5e809a652e513124c3b2ee534f04b214d2c4e7f /gtk.c
parentcf6b9a69d92a1c0007cb6d1a8c74aaf1f90b4ee2 (diff)
downloadlimox-e7dd56d2ac25afccf578454e06f02f45187248b9.tar
limox-e7dd56d2ac25afccf578454e06f02f45187248b9.tar.zst
limox-e7dd56d2ac25afccf578454e06f02f45187248b9.zip
Implement widget creation for roster items
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/gtk.c b/gtk.c
index 19af543..82997a9 100644
--- a/gtk.c
+++ b/gtk.c
@@ -7,7 +7,6 @@
struct chat {
- GtkWidget* roster_item; // the button in the roster list
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
@@ -81,7 +80,7 @@ static void to_roster(void) {
void send_message(struct chat* chat) {
// get recipient and message text
- const char* recipient = gtk_button_get_label(GTK_BUTTON(chat->roster_item));
+ 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
@@ -100,7 +99,6 @@ void add_chat(char* jid) {
// create chat struct and initialize
struct chat* chat = malloc(sizeof(struct chat));
- chat->roster_item = gtk_button_new_with_label(jid);
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();
@@ -128,11 +126,6 @@ void add_chat(char* jid) {
g_signal_connect_swapped(send_button, "clicked", G_CALLBACK(send_message),
chat);
- // add chat to roster list
- gtk_box_append(GTK_BOX(roster_content_box), chat->roster_item);
- g_signal_connect_swapped(chat->roster_item, "clicked", G_CALLBACK(to_chat),
- chat->chat_layout_box);
-
// append chat to linked list of chats
struct chat* current = chats;
while (true) {
@@ -151,27 +144,30 @@ void add_chat(char* jid) {
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;
- }
+ //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
- }
- }
+ //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);
+ //GtkWidget* message = gtk_label_new(content);
+ //gtk_box_append(GTK_BOX(chat->chat_content_box), message);
}
@@ -210,15 +206,6 @@ static void build_static_widgets(void) {
roster_content_box);
gtk_box_append(GTK_BOX(roster_layout_box), roster_scrolled);
- // TODO remove this
- // add dummy roster items
- for (int i=0; i<10; i++) {
- // char buffer[50];
- char* buffer = malloc(50*sizeof(char));
- sprintf(buffer, "contact-%d@example.com", i+1);
- add_chat(buffer);
- }
-
// TODO just for debugging
for (int i=0; i<20; i++) {
add_incoming_text_message("contact-2@example.com", "Just a test.");
@@ -271,11 +258,25 @@ void gui_add_message(const char* sender_jid, const char* content) {
void* gui_add_roster_item(const char* jid, const char* sub, const char* name) {
+ // print debug message
if (name) {
printf("roster item: %s, %s, sub:%s\n", name, jid, sub);
} else {
printf("roster item: (no name), %s, sub:%s\n", jid, sub);
}
- return NULL; // TODO return pointer to GTK widget
+ // create widget for roster item
+ GtkWidget* roster_item_widget;
+ if (name == NULL || strcmp(name, "") == 0) {
+ roster_item_widget = gtk_button_new_with_label(name);
+ } else {
+ roster_item_widget = gtk_button_new_with_label(jid);
+ }
+
+ // 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),
+ // chat->chat_layout_box); TODO this should be realized again
+
+ return (void*)roster_item_widget;
}