Fix bug with uninitialized variable.
[cascardo/chat.git] / ui.c
1 /*
2  *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #include <gtk/gtk.h>
21 #include <stdio.h>
22 #include <glib.h>
23 #include <udns.h>
24 #include "tcp_connect.h"
25 #include "xmpp.h"
26
27 static gboolean
28 rploop (GIOChannel *src, GIOCondition cond, gpointer xmpp)
29 {
30   hc_xmpp_read_and_parse (xmpp);
31   return TRUE;
32 }
33
34 GtkWidget *entry1;
35 GtkWidget *entry2;
36 GtkWidget *entry3;
37
38 extern void hc_xmpp_chat_open (hc_xmpp_t *);
39
40 static void
41 connect_clicked (GtkWidget *button, gpointer data)
42 {
43   GIOChannel *channel;
44   hc_xmpp_t *xmpp;
45   char *server;
46   char *user;
47   char *password;
48   server = (char *) gtk_entry_get_text (GTK_ENTRY (entry1));
49   user = (char *) gtk_entry_get_text (GTK_ENTRY (entry2));
50   password = (char *) gtk_entry_get_text (GTK_ENTRY (entry3));
51   xmpp = hc_xmpp_new (hc_xmpp_hook, server, user, password);
52   hc_xmpp_send_stream (xmpp);
53   channel = g_io_channel_unix_new (hc_xmpp_fd (xmpp));
54   g_io_add_watch (channel, G_IO_IN, rploop, xmpp);
55   hc_xmpp_chat_open (xmpp);
56 }
57
58 static void
59 ui (void)
60 {
61   GtkWidget *window;
62   GtkWidget *vbox;
63   GtkWidget *button;
64   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
65   vbox = gtk_vbox_new (TRUE, 5);
66   entry1 = gtk_entry_new ();
67   entry2 = gtk_entry_new ();
68   entry3 = gtk_entry_new ();
69   gtk_entry_set_visibility (GTK_ENTRY (entry3), FALSE);
70   button = gtk_button_new_with_label ("Connect");
71   g_signal_connect (G_OBJECT (button), "clicked",
72                     G_CALLBACK (connect_clicked), NULL);
73   gtk_container_add (GTK_CONTAINER (window), vbox);
74   gtk_container_add (GTK_CONTAINER (vbox), entry1);
75   gtk_container_add (GTK_CONTAINER (vbox), entry2);
76   gtk_container_add (GTK_CONTAINER (vbox), entry3);
77   gtk_container_add (GTK_CONTAINER (vbox), button);
78   gtk_widget_show_all (window);
79 }
80
81 int
82 main (int argc, char **argv)
83 {
84   GMainLoop *loop;
85   gtk_init (&argc, &argv);
86   dns_init (NULL, 1);
87   loop = g_main_loop_new (g_main_context_default (), TRUE);
88   ui ();
89   g_main_loop_run (loop);
90   return 0;
91 }