X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=chat.c;h=dfa83eb2ab2e4a8ed47e2178369f3761157cd6ac;hb=e582eafca3304cc1da1f2df162df56c091493784;hp=75fdf852f090971b283cf1de00c9ea305974233c;hpb=ed117cfe5afa4a0360f0d319eb187fd0f3a40155;p=cascardo%2Fchat.git diff --git a/chat.c b/chat.c index 75fdf85..dfa83eb 100644 --- a/chat.c +++ b/chat.c @@ -26,30 +26,49 @@ #include #include "xmpp.h" #include "message.h" +#include "presence.h" static int fd; static GtkWidget *textview; static GtkWidget *entry_to; static GtkWidget *entry_body; +static GtkWidget *entry_status; static void hc_xmpp_chat (hc_xmpp_t *xmpp, iks *message) { GtkTextBuffer *textbuffer; - GtkTextIter *textiter; + GtkTextIter textiter; char *str; char *from; + char *to; char *body; + int sent = 0; str = iks_string (iks_stack (message), message); write (fd, str, strlen (str)); from = iks_find_attrib (message, "from"); + to = iks_find_attrib (message, "to"); + if (from == NULL) + sent = 1; + if (sent && to == NULL) + return; body = iks_cdata (iks_child (iks_find (message, "body"))); textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); - gtk_text_buffer_get_end_iter (textbuffer, textiter); - gtk_text_buffer_insert (textbuffer, textiter, from, -1); - gtk_text_buffer_insert (textbuffer, textiter, ": ", -1); - gtk_text_buffer_insert (textbuffer, textiter, body, -1); - gtk_text_buffer_insert (textbuffer, textiter, "\n", -1); + gtk_text_buffer_get_end_iter (textbuffer, &textiter); + if (sent) + { + gtk_text_buffer_insert (textbuffer, &textiter, "> ", -1); + gtk_text_buffer_insert (textbuffer, &textiter, to, -1); + } + else + { + gtk_text_buffer_insert (textbuffer, &textiter, "< ", -1); + gtk_text_buffer_insert (textbuffer, &textiter, from, -1); + } + gtk_text_buffer_insert (textbuffer, &textiter, ": ", -1); + if (body) + gtk_text_buffer_insert (textbuffer, &textiter, body, -1); + gtk_text_buffer_insert (textbuffer, &textiter, "\n", -1); } static void @@ -64,13 +83,25 @@ hc_xmpp_chat_send (GtkWidget *button, gpointer data) hc_xmpp_send_message (xmpp, to, body); } +static void +hc_xmpp_chat_status (GtkWidget *button, gpointer data) +{ + hc_xmpp_t* xmpp; + char *status; + xmpp = (hc_xmpp_t *) data; + status = (char *) gtk_entry_get_text (GTK_ENTRY (entry_status)); + hc_xmpp_send_presence (xmpp, NULL, NULL, status); +} + void hc_xmpp_chat_open (hc_xmpp_t *xmpp) { GtkWidget *window; GtkWidget *vbox; GtkWidget *hbox; + GtkWidget *hbox2; GtkWidget *button; + GtkWidget *button2; fd = open ("/home/cascardo/.hcxmpp/log", O_RDWR | O_APPEND | O_CREAT); if (fd < 0) { @@ -80,18 +111,27 @@ hc_xmpp_chat_open (hc_xmpp_t *xmpp) window = gtk_window_new (GTK_WINDOW_TOPLEVEL); vbox = gtk_vbox_new (FALSE, 5); hbox = gtk_hbox_new (FALSE, 5); + hbox2 = gtk_hbox_new (FALSE, 5); entry_to = gtk_entry_new (); entry_body = gtk_entry_new (); + entry_status = gtk_entry_new (); button = gtk_button_new_with_label ("Send"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (hc_xmpp_chat_send), xmpp); + button2 = gtk_button_new_with_label ("Change Status"); + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (hc_xmpp_chat_status), xmpp); textview = gtk_text_view_new (); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD_CHAR); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_add (GTK_CONTAINER (vbox), textview); gtk_container_add (GTK_CONTAINER (vbox), hbox); + gtk_container_add (GTK_CONTAINER (vbox), hbox2); gtk_container_add (GTK_CONTAINER (hbox), entry_to); gtk_container_add (GTK_CONTAINER (hbox), entry_body); gtk_container_add (GTK_CONTAINER (hbox), button); + gtk_container_add (GTK_CONTAINER (hbox2), entry_status); + gtk_container_add (GTK_CONTAINER (hbox2), button2); gtk_widget_show_all (window); hc_xmpp_set_msg_hook (xmpp, hc_xmpp_chat); hc_xmpp_set_sent_msg_hook (xmpp, hc_xmpp_chat);