summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c25
-rw-r--r--data.h3
-rw-r--r--gtk.c10
3 files changed, 32 insertions, 6 deletions
diff --git a/data.c b/data.c
index 7645679..3780fd0 100644
--- a/data.c
+++ b/data.c
@@ -102,3 +102,28 @@ void data_add_incoming_message(const char* sender_jid, const char* content) {
// received message so that future responses go to this ressource
}
+
+void data_add_outgoing_message(const char* sender_jid, const char* content,
+ chat_t* chat) {
+
+ // allocate and initialize message_t
+ message_t* msg = malloc(sizeof(message_t));
+ msg->sender_jid = malloc(sizeof(char)*strlen(sender_jid));
+ strcpy(msg->sender_jid, sender_jid);
+ msg->recipient_jid = malloc(sizeof(char)*strlen(chat->jid));
+ strcpy(msg->recipient_jid, chat->jid);
+ msg->content = malloc(sizeof(char)*strlen(content));
+ strcpy(msg->content, content);
+ msg->next = NULL;
+
+ // find pointer to next message of chat and add this message
+ message_t* m;
+ for (m = chat->messages; m != NULL; m=m->next);
+ m = msg;
+
+ // TODO send this message via XMPP
+
+ // create GUI widget for this message
+ gui_add_message_widget(msg, chat);
+
+}
diff --git a/data.h b/data.h
index 51d9b01..68a4b9b 100644
--- a/data.h
+++ b/data.h
@@ -12,6 +12,7 @@ typedef enum {
typedef struct _message_t {
char* content;
char* sender_jid;
+ char* recipient_jid;
struct _message_t* next;
void* widget;
} message_t;
@@ -34,4 +35,6 @@ typedef struct _roster_item_t {
void data_add_roster_item(const char* jid, const char* subscription,
const char* name);
void data_add_incoming_message(const char* sender_jid, const char* content);
+void data_add_outgoing_message(const char* sender_jid, const char* content,
+ chat_t* chat);
#endif
diff --git a/gtk.c b/gtk.c
index 477bd71..1a13bfa 100644
--- a/gtk.c
+++ b/gtk.c
@@ -68,17 +68,15 @@ static void disconnect_cb(void) {
void send_message(chat_t* chat) {
+ // cast void* to GUI-specific chat_widget_t*
chat_widget_t* chat_widget = (chat_widget_t*)chat->widget;
+ // get text of message and own JID
const char* text = gtk_editable_get_text(GTK_EDITABLE(chat_widget->entry));
const char* self = gtk_editable_get_text(GTK_EDITABLE(connector_jid_entry));
- // execute dummy XMPP send TODO
- printf("Sending from %s to %s:\n> %s\n", self, chat->jid, text);
-
- //// add message content to the chat
- //GtkWidget* message = gtk_label_new(text);
- //gtk_box_append(GTK_BOX(chat->chat_content_box), message);
+ // add message to datastructure
+ data_add_outgoing_message(self, text, chat);
// clear text input
GtkEntryBuffer* buffer;