2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 static GtkWidget *textview;
32 static GtkWidget *entry_to;
33 static GtkWidget *entry_body;
36 hc_xmpp_chat (hc_xmpp_t *xmpp, iks *message)
38 GtkTextBuffer *textbuffer;
45 str = iks_string (iks_stack (message), message);
46 write (fd, str, strlen (str));
47 from = iks_find_attrib (message, "from");
48 to = iks_find_attrib (message, "to");
51 if (sent && to == NULL)
53 body = iks_cdata (iks_child (iks_find (message, "body")));
54 textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
55 gtk_text_buffer_get_end_iter (textbuffer, &textiter);
58 gtk_text_buffer_insert (textbuffer, &textiter, "> ", -1);
59 gtk_text_buffer_insert (textbuffer, &textiter, to, -1);
63 gtk_text_buffer_insert (textbuffer, &textiter, "< ", -1);
64 gtk_text_buffer_insert (textbuffer, &textiter, from, -1);
66 gtk_text_buffer_insert (textbuffer, &textiter, ": ", -1);
68 gtk_text_buffer_insert (textbuffer, &textiter, body, -1);
69 gtk_text_buffer_insert (textbuffer, &textiter, "\n", -1);
73 hc_xmpp_chat_send (GtkWidget *button, gpointer data)
78 xmpp = (hc_xmpp_t *) data;
79 to = (char *) gtk_entry_get_text (GTK_ENTRY (entry_to));
80 body = (char *) gtk_entry_get_text (GTK_ENTRY (entry_body));
81 hc_xmpp_send_message (xmpp, to, body);
85 hc_xmpp_chat_open (hc_xmpp_t *xmpp)
91 fd = open ("/home/cascardo/.hcxmpp/log", O_RDWR | O_APPEND | O_CREAT);
94 fprintf (stderr, "Could not open log file: %s\n", strerror (errno));
97 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
98 vbox = gtk_vbox_new (FALSE, 5);
99 hbox = gtk_hbox_new (FALSE, 5);
100 entry_to = gtk_entry_new ();
101 entry_body = gtk_entry_new ();
102 button = gtk_button_new_with_label ("Send");
103 g_signal_connect (G_OBJECT (button), "clicked",
104 G_CALLBACK (hc_xmpp_chat_send), xmpp);
105 textview = gtk_text_view_new ();
106 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD_CHAR);
107 gtk_container_add (GTK_CONTAINER (window), vbox);
108 gtk_container_add (GTK_CONTAINER (vbox), textview);
109 gtk_container_add (GTK_CONTAINER (vbox), hbox);
110 gtk_container_add (GTK_CONTAINER (hbox), entry_to);
111 gtk_container_add (GTK_CONTAINER (hbox), entry_body);
112 gtk_container_add (GTK_CONTAINER (hbox), button);
113 gtk_widget_show_all (window);
114 hc_xmpp_set_msg_hook (xmpp, hc_xmpp_chat);
115 hc_xmpp_set_sent_msg_hook (xmpp, hc_xmpp_chat);