Allow user to change his status, sending a broadcast presence ui
authorThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Tue, 25 Nov 2008 12:29:59 +0000 (10:29 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 9 May 2011 01:13:12 +0000 (22:13 -0300)
chat.c

diff --git a/chat.c b/chat.c
index 090652c..9cfe397 100644 (file)
--- a/chat.c
+++ b/chat.c
 #include <fcntl.h>
 #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)
@@ -81,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)
     {
@@ -97,19 +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);