aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/chat/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/chat/chat.c')
-rw-r--r--src/plugins/chat/chat.c485
1 files changed, 223 insertions, 262 deletions
diff --git a/src/plugins/chat/chat.c b/src/plugins/chat/chat.c
index 9be89250..159627f0 100644
--- a/src/plugins/chat/chat.c
+++ b/src/plugins/chat/chat.c
@@ -23,165 +23,157 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @author Igor Wronsky 24 * @author Igor Wronsky
25 * @author Nathan Evans 25 * @author Nathan Evans
26 *
27 */ 26 */
28 27
29#include "platform.h" 28#include "platform.h"
30#include <GNUnet/gnunet_chat_lib.h> 29#include <GNUnet/gnunet_chat_lib.h>
30#include <GNUnet/gnunet_pseudonym_lib.h>
31#include "gnunetgtk_common.h" 31#include "gnunetgtk_common.h"
32 32
33/* YUCK -- why? */
34#include "../fs/meta.h"
35#include "../fs/meta.c"
36
37
38struct GNUNET_CHAT_safe_write_struct 33struct GNUNET_CHAT_safe_write_struct
39{ 34{
40 GtkWidget *chatWindow; 35 GtkWidget * text_view;
41 const char *message; 36 const char *message;
42 const GNUNET_HashCode *sender; 37 const char *sender;
43}; 38};
44 39
45struct GNUNET_CHAT_safe_nick_write_struct 40struct GNUNET_CHAT_safe_nick_write_struct
46{ 41{
47 GtkWidget *nickList; 42 GtkListStore *model;
43 GdkPixbuf * icon;
44 const struct GNUNET_ECRS_MetaData *meta;
48 const char *nick; 45 const char *nick;
46 GNUNET_HashCode pid;
49}; 47};
50 48
51struct GNUNET_CHAT_gui_chat_client 49struct GNUNET_CHAT_gui_chat_client
52{ 50{
53 struct GNUNET_CHAT_gui_chat_client *next; 51 struct GNUNET_CHAT_gui_chat_client *next;
54 struct GNUNET_CHAT_gui_chat_client *prev; 52 GtkWidget * text_view;
55 int number; 53 GtkListStore * nick_model;
56 GtkWidget *chatFrame; 54 GtkWidget *chatFrame;
55 GtkWidget *chat_entry;
56 GladeXML *chatXML;
57 struct GNUNET_CHAT_Room *room; 57 struct GNUNET_CHAT_Room *room;
58 gchar *room_name; 58 GNUNET_HashCode mypid;
59
60}; 59};
61 60
62struct GNUNET_CHAT_member_list 61/**
62 * For nicknames in chat view.
63 */
64enum
63{ 65{
64 struct GNUNET_CHAT_member_list *next; 66 CHAT_NICKNAME = 0,
65 struct GNUNET_CHAT_member_list *prev; 67 CHAT_METADATA,
66 char *nick; 68 CHAT_ICON,
69 CHAT_PID,
70 CHAT_NUM,
67}; 71};
68 72
69 73
70static struct GNUNET_ClientServerConnection *sock;
71
72static struct GNUNET_Mutex *lock; 74static struct GNUNET_Mutex *lock;
73 75
74static struct GNUNET_CronManager *cron;
75
76static struct GNUNET_GE_Context *chat_ectx; 76static struct GNUNET_GE_Context *chat_ectx;
77 77
78static struct GNUNET_GC_Configuration *chat_cfg; 78static struct GNUNET_GC_Configuration *chat_cfg;
79 79
80static struct GNUNET_CHAT_gui_chat_client *list; 80static struct GNUNET_CHAT_gui_chat_client *list;
81 81
82static struct GNUNET_CHAT_member_list *room_member_list;
83
84static void * 82static void *
85write_save_call (void *arg) 83write_save_call (void *arg)
86{ 84{
87 struct GNUNET_CHAT_safe_write_struct *writeholder = arg; 85 struct GNUNET_CHAT_safe_write_struct *cls = arg;
88 GtkTextBuffer *buffer; 86 GtkTextBuffer *buffer;
89 char *message_buf; 87 char *message_buf;
90 int message_buf_size; 88 int message_buf_size;
91 89
92 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (writeholder->chatWindow)); 90 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (cls->text_view));
93 message_buf_size = 91 message_buf_size =
94 snprintf (NULL, 0, "<> %s", /* writeholder->senderNick,*/ 92 snprintf (NULL, 0,
95 writeholder->message); 93 "<%s> %s\n",
96 message_buf = GNUNET_malloc (message_buf_size + 2); 94 cls->sender,
97 snprintf (message_buf, message_buf_size + 2, "<FIXME> %s\n", 95 cls->message);
98 /*writeholder->senderNick,*/ writeholder->message); 96 message_buf = GNUNET_malloc (message_buf_size + 1);
99 gtk_text_buffer_insert_at_cursor (buffer, message_buf, 97 GNUNET_snprintf (message_buf,
98 message_buf_size + 1,
99 "<%s> %s\n",
100 cls->sender,
101 cls->message);
102 gtk_text_buffer_insert_at_cursor (buffer,
103 message_buf,
100 message_buf_size + 1); 104 message_buf_size + 1);
101 105 GNUNET_free(message_buf);
102 return NULL; 106 return NULL;
103} 107}
104 108
105/* Safe call to add a nick to the chat room view */ 109/**
106/* static */ void * 110 * Safe call to add a nick to the chat room view
107write_nick_save_call (void *arg) 111 */
112static void *
113add_nick_save_call (void *arg)
108{ 114{
109 struct GNUNET_CHAT_safe_nick_write_struct *writeholder = arg; 115 struct GNUNET_CHAT_safe_nick_write_struct *cls = arg;
110 116 GtkListStore * model;
111 GtkTextBuffer *buffer; 117 GtkTreeIter iter;
112 char *message_buf; 118 GNUNET_HashCode * pid;
113 int message_buf_size; 119
114 struct GNUNET_CHAT_member_list *pos = room_member_list; 120 model = GTK_LIST_STORE (cls->model);
115 121 gtk_list_store_append (model, &iter);
116 g_print ("received chat name %s\n", writeholder->nick); 122 pid = GNUNET_malloc(sizeof(GNUNET_HashCode));
117 while (pos != NULL) 123 *pid = cls->pid;
118 { 124 gtk_list_store_set(model,
119 if (strcmp (pos->nick, writeholder->nick) == 0) 125 &iter,
120 return NULL; 126 CHAT_PID, pid,
121 pos = pos->next; 127 CHAT_METADATA, GNUNET_ECRS_meta_data_duplicate(cls->meta),
122 } 128 CHAT_ICON, cls->icon,
123 129 CHAT_NICKNAME, cls->nick,
124 g_print ("adding chat name %s to the list\n", writeholder->nick); 130 -1);
125
126 pos = GNUNET_malloc (sizeof (struct GNUNET_CHAT_member_list));
127 pos->nick = GNUNET_malloc (strlen (writeholder->nick) + 1);
128 strcpy (pos->nick, writeholder->nick);
129 pos->next = room_member_list;
130 if (room_member_list != NULL)
131 room_member_list->prev = pos;
132 room_member_list = pos;
133 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (writeholder->nickList));
134 message_buf_size = snprintf (NULL, 0, "%s", writeholder->nick);
135 message_buf = GNUNET_malloc (message_buf_size + 2);
136 snprintf (message_buf, message_buf_size + 2, "%s\n", writeholder->nick);
137 gtk_text_buffer_insert_at_cursor (buffer, message_buf,
138 message_buf_size + 1);
139
140 return NULL; 131 return NULL;
141} 132}
142 133
143/* Safe call to remove a nick from the chat room view */ 134/**
144/* static */ void * 135 * Safe call to remove a nick from the chat room view
136 */
137static void *
145remove_nick_save_call (void *arg) 138remove_nick_save_call (void *arg)
146{ 139{
147 struct GNUNET_CHAT_safe_nick_write_struct *writeholder = arg; 140 struct GNUNET_CHAT_safe_nick_write_struct *cls = arg;
148 141 GtkListStore * model;
149 GtkTextBuffer *buffer = 142 GtkTreeIter iter;
150 gtk_text_view_get_buffer (GTK_TEXT_VIEW (writeholder->nickList)); 143 GNUNET_HashCode * pid;
151 char *message_buf; 144 struct GNUNET_ECRS_MetaData * meta;
152 int message_buf_size;
153 struct GNUNET_CHAT_member_list *pos = room_member_list;
154 145
155 while (pos != NULL) 146 model = GTK_LIST_STORE (cls->model);
147 /* find and remove existing entry */
148 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
156 { 149 {
157 if (strcmp (pos->nick, writeholder->nick) == 0) 150 do
158 { 151 {
159 pos->prev->next = pos->next; 152 pid = NULL;
160 pos->next->prev = pos->prev; 153 gtk_tree_model_get (GTK_TREE_MODEL (model),
161 GNUNET_free (pos); 154 &iter,
162 /*buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(writeholder->nickList)); */ 155 CHAT_PID, &pid,
163 buffer = gtk_text_buffer_new (NULL); 156 CHAT_METADATA, &meta,
164 return NULL; 157 -1);
158 if ( (pid != NULL) &&
159 (0 == memcmp(pid,
160 &cls->pid,
161 sizeof(GNUNET_HashCode))) )
162 {
163 GNUNET_ECRS_meta_data_destroy(meta);
164 GNUNET_free(pid);
165 gtk_list_store_remove(model, &iter);
166 return NULL; /* done! */
167 }
165 } 168 }
166 pos = pos->next; 169 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
167 } 170 }
168
169 return NULL;
170
171
172 message_buf_size = snprintf (NULL, 0, "%s", writeholder->nick);
173 message_buf = GNUNET_malloc (message_buf_size + 2);
174 snprintf (message_buf, message_buf_size + 2, "%s\n", writeholder->nick);
175 gtk_text_buffer_insert_at_cursor (buffer, message_buf,
176 message_buf_size + 1);
177
178 return NULL; 171 return NULL;
179} 172}
180 173
181/** 174/**
182 * A message was sent in the chat to us. 175 * A message was sent in the chat to us.
183 * 176 *
184 * @param timestamp when was the message sent?
185 * @param senderNick what is the nickname of the sender? (maybe NULL) 177 * @param senderNick what is the nickname of the sender? (maybe NULL)
186 * @param message the message (maybe NULL, especially if confirmation 178 * @param message the message (maybe NULL, especially if confirmation
187 * is requested before delivery; the protocol will ensure 179 * is requested before delivery; the protocol will ensure
@@ -202,28 +194,15 @@ receive_callback (void *cls,
202 GNUNET_CHAT_MSG_OPTIONS options) 194 GNUNET_CHAT_MSG_OPTIONS options)
203{ 195{
204 struct GNUNET_CHAT_gui_chat_client *client = cls; 196 struct GNUNET_CHAT_gui_chat_client *client = cls;
205 GtkWidget *chattextviewer;
206 GList *children;
207 struct GNUNET_CHAT_safe_write_struct writearg; 197 struct GNUNET_CHAT_safe_write_struct writearg;
208 198 char * sndr;
209 children = gtk_container_get_children (GTK_CONTAINER (client->chatFrame)); 199
210 chattextviewer = 200 sndr = sender == NULL ? _("anonymous") : GNUNET_PSEUDO_id_to_name(chat_ectx, chat_cfg, sender);
211 g_list_nth_data ((gtk_container_get_children 201 writearg.text_view = client->text_view;
212 (GTK_CONTAINER
213 (g_list_nth_data
214 (gtk_container_get_children
215 (GTK_CONTAINER (children->data)), 0)))), 0);
216
217 writearg.chatWindow = chattextviewer;
218 writearg.message = message; 202 writearg.message = message;
219 writearg.sender = sender; 203 writearg.sender = sndr;
220 GNUNET_GTK_save_call (&write_save_call, &writearg); 204 GNUNET_GTK_save_call (&write_save_call, &writearg);
221 205 GNUNET_free_non_null(sndr);
222 /*Write the message to the appropriate room...
223 * Somehow G wants me to do this without knowing which room it's headed to, but I don't see how...
224 * perhaps with the closure argument...*/
225
226
227 return GNUNET_OK; 206 return GNUNET_OK;
228} 207}
229 208
@@ -234,88 +213,144 @@ member_list_callback (void *cls,
234 GNUNET_CHAT_MSG_OPTIONS opt) 213 GNUNET_CHAT_MSG_OPTIONS opt)
235{ 214{
236 struct GNUNET_CHAT_gui_chat_client *client = cls; 215 struct GNUNET_CHAT_gui_chat_client *client = cls;
237 GtkWidget *chatnicklist;
238#if 0
239 struct GNUNET_CHAT_safe_nick_write_struct writearg; 216 struct GNUNET_CHAT_safe_nick_write_struct writearg;
240#endif 217 char *nick;
241 chatnicklist = 218
242 g_list_nth_data (gtk_container_get_children 219 GNUNET_hash(pkey,
243 (GTK_CONTAINER (client->chatFrame)), 1); 220 sizeof(GNUNET_RSA_PublicKey),
244 chatnicklist = 221 &writearg.pid);
245 g_list_nth_data (gtk_container_get_children 222 nick = GNUNET_PSEUDO_id_to_name(chat_ectx,
246 (GTK_CONTAINER (chatnicklist)), 0); 223 chat_cfg,
247#if 0 224 &writearg.pid);
248 /* chatnicklist is the GtkTextView object */ 225 writearg.model = client->nick_model;
249 writearg.nick = member_info; 226 /* FIXME: set icon if pid == ours */
250 writearg.nickList = chatnicklist; 227 writearg.icon = NULL;
251 228 writearg.meta = member_info;
252 if (is_joining) 229 writearg.nick = nick;
253 GNUNET_GTK_save_call (&write_nick_save_call, &writearg); 230 if (member_info != NULL)
231 GNUNET_GTK_save_call (&add_nick_save_call, &writearg);
254 else 232 else
255 GNUNET_GTK_save_call (&remove_nick_save_call, &writearg); 233 GNUNET_GTK_save_call (&remove_nick_save_call, &writearg);
256#endif 234 GNUNET_free(nick);
257 return GNUNET_OK; 235 return GNUNET_OK;
258} 236}
259 237
260void 238void
261init_chat (struct GNUNET_GE_Context *ectx, 239on_chat_frame_send_button_click_event_chat (GtkWidget * widget, gpointer data)
262 struct GNUNET_GC_Configuration *cfg)
263{ 240{
264 GtkWidget *tab; 241 GtkWidget *chatnotebook;
265 242 unsigned int seq;
266 chat_ectx = ectx; 243 const char *message;
267 chat_cfg = cfg; 244 struct GNUNET_CHAT_gui_chat_client *pos;
268 room_member_list = NULL;
269
270
271 /*priv_key = GNUNET_RSA_create_key ();
272 GNUNET_RSA_get_public_key (priv_key, &pub_key); */
273
274 sock = GNUNET_client_connection_create (chat_ectx, chat_cfg);
275 lock = GNUNET_mutex_create (GNUNET_NO);
276 cron = GNUNET_GTK_get_cron_manager ();
277 245
278 tab = 246 chatnotebook = gtk_widget_get_ancestor (widget, GTK_TYPE_NOTEBOOK);
279 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 247 GNUNET_mutex_lock(lock);
280 "chatnotebookvbox"); 248 pos = list;
249 while ( (pos != NULL) &&
250 (pos->chatFrame != chatnotebook) )
251 pos = pos->next;
252 GNUNET_GE_ASSERT(NULL, pos != NULL);
253
254 message = (const char *) gtk_entry_get_text (GTK_ENTRY(pos->chat_entry));
255 GNUNET_CHAT_send_message (pos->room,
256 message,
257 GNUNET_CHAT_MSG_OPTION_NONE,
258 NULL, &seq);
259 gtk_entry_set_text (GTK_ENTRY(pos->chat_entry), "");
260}
281 261
282 gtk_widget_show (tab); 262/** FIXME: move to gtkcommon! */
263static GtkWidget *
264extractMainWidgetFromWindow (GladeXML * xml, const char *windowName)
265{
266 GtkContainer *window;
267 GtkWidget *ret;
268
269 window = GTK_CONTAINER (glade_xml_get_widget (xml, windowName));
270 ret = gtk_bin_get_child (GTK_BIN (window));
271 gtk_widget_ref (ret);
272 gtk_container_remove (window, ret);
273 gtk_widget_destroy (GTK_WIDGET (window));
274 return ret;
283} 275}
284 276
285static int 277static void
286create_chat_room_tab (char *room_name, char *nick) 278create_chat_room_tab (const char *room_name,
279 const char *nick)
287{ 280{
288 GladeXML *chatXML;
289 GtkWidget *newChatWindow;
290 GtkWidget *chatnotebook;
291 GtkWidget *chatLabel; 281 GtkWidget *chatLabel;
292 struct GNUNET_CHAT_Room *chatRoom; 282 GtkWidget *chatnotebook;
283 GtkTreeView *treeview;
293 struct GNUNET_CHAT_gui_chat_client *client; 284 struct GNUNET_CHAT_gui_chat_client *client;
294 struct GNUNET_CHAT_gui_chat_client *pos;
295 struct GNUNET_ECRS_MetaData * meta; 285 struct GNUNET_ECRS_MetaData * meta;
296 GNUNET_HashCode me; 286 GtkCellRenderer *renderer;
297 287 GtkTreeViewColumn *column;
288 int col;
289
298 chatnotebook = 290 chatnotebook =
299 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebook"); 291 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebook");
300 chatXML =
301 glade_xml_new (GNUNET_GTK_get_glade_filename (), "chatFrame",
302 PACKAGE_NAME);
303 GNUNET_GTK_connect_glade_with_plugins (chatXML);
304 newChatWindow = extractMainWidgetFromWindow (chatXML, "chatFrame");
305 292
293 client = GNUNET_malloc (sizeof (struct GNUNET_CHAT_gui_chat_client));
294 client->chatXML =
295 glade_xml_new (GNUNET_GTK_get_glade_filename (),
296 "chatFrame",
297 PACKAGE_NAME);
298 GNUNET_GTK_connect_glade_with_plugins (client->chatXML);
299 client->chatFrame = extractMainWidgetFromWindow (client->chatXML,
300 "chatFrame");
306 chatLabel = gtk_label_new (room_name); 301 chatLabel = gtk_label_new (room_name);
307 gtk_notebook_insert_page (GTK_NOTEBOOK (chatnotebook), newChatWindow, 302 gtk_notebook_insert_page (GTK_NOTEBOOK (chatnotebook),
303 client->chatFrame,
308 chatLabel, 1); 304 chatLabel, 1);
305 gtk_widget_show (client->chatFrame);
306 gtk_widget_show (chatLabel);
307
308 client->nick_model = gtk_list_store_new (CHAT_NUM,
309 G_TYPE_STRING, /* nickname */
310 G_TYPE_POINTER, /* metadata */
311 GDK_TYPE_PIXBUF, /* icon */
312 G_TYPE_POINTER); /* pid */
313 client->text_view = glade_xml_get_widget (client->chatXML, "chatLogViewer");
314 client->chat_entry = glade_xml_get_widget (client->chatXML, "chatLineTextEntry");
315 treeview = GTK_TREE_VIEW(glade_xml_get_widget (client->chatXML, "roomMembersTreeView"));
316 gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (list->nick_model));
317
318 renderer = gtk_cell_renderer_text_new ();
319 col = gtk_tree_view_insert_column_with_attributes (treeview,
320 -1,
321 _("Nickname"),
322 renderer,
323 "text", CHAT_NICKNAME,
324 NULL);
325 column = gtk_tree_view_get_column (treeview, col - 1);
326 gtk_tree_view_column_set_resizable (column, TRUE);
327 gtk_tree_view_column_set_clickable (column, TRUE);
328 gtk_tree_view_column_set_reorderable (column, TRUE);
329 gtk_tree_view_column_set_sort_column_id (column, CHAT_NICKNAME);
330 gtk_tree_view_column_set_min_width (column, 0);
331
332 renderer = gtk_cell_renderer_pixbuf_new ();
333 col = gtk_tree_view_insert_column_with_attributes (treeview,
334 -1,
335 "",
336 renderer,
337 "pixbuf", CHAT_ICON,
338 NULL);
339 column = gtk_tree_view_get_column (treeview, col - 1);
340 gtk_tree_view_column_set_resizable (column, TRUE);
341 gtk_tree_view_column_set_clickable (column, FALSE);
342 gtk_tree_view_column_set_reorderable (column, FALSE);
343
344 GNUNET_mutex_lock(lock);
345 client->next = list;
346 list = client;
347 GNUNET_mutex_unlock(lock);
309 348
310 gtk_widget_show (chatnotebook);
311
312 client = GNUNET_malloc (sizeof (struct GNUNET_CHAT_gui_chat_client));
313 client->room_name = GNUNET_malloc (strlen (room_name));
314 strcpy (client->room_name, room_name);
315
316 /* We do a silly strdup later on member_info... either check for NULL or only pass "" for member_info!! */
317 meta = GNUNET_ECRS_meta_data_create(); 349 meta = GNUNET_ECRS_meta_data_create();
318 chatRoom = 350 GNUNET_ECRS_meta_data_insert(meta,
351 EXTRACTOR_TITLE,
352 nick);
353 client->room =
319 GNUNET_CHAT_join_room (chat_ectx, chat_cfg, nick, 354 GNUNET_CHAT_join_room (chat_ectx, chat_cfg, nick,
320 meta, 355 meta,
321 room_name, 356 room_name,
@@ -323,37 +358,17 @@ create_chat_room_tab (char *room_name, char *nick)
323 &receive_callback, client, &member_list_callback, 358 &receive_callback, client, &member_list_callback,
324 client, 359 client,
325 NULL, NULL, 360 NULL, NULL,
326 &me); 361 &client->mypid);
327 GNUNET_ECRS_meta_data_destroy(meta); 362 GNUNET_ECRS_meta_data_destroy(meta);
328 client->room = chatRoom;
329 client->chatFrame = newChatWindow;
330 client->number =
331 gtk_notebook_get_current_page (GTK_NOTEBOOK (chatnotebook));
332
333 if (list == NULL)
334 list = client;
335 else
336 {
337 pos = list;
338 while (pos->next != NULL)
339 {
340 pos = pos->next;
341 }
342 pos->next = client;
343 }
344
345 return GNUNET_OK;
346} 363}
347 364
348
349
350void 365void
351on_chat_room_name_button_click_event_chat (GtkWidget * widget, gpointer data) 366on_chat_room_name_button_click_event_chat (GtkWidget * widget, gpointer data)
352{ 367{
353 GtkEntry *room_entry; 368 GtkEntry *room_entry;
354 GtkEntry *nick_entry; 369 GtkEntry *nick_entry;
355 char *room_text; 370 const char *room_text;
356 char *nick_text; 371 const char *nick_text;
357 372
358 room_entry = 373 room_entry =
359 GTK_ENTRY (glade_xml_get_widget 374 GTK_ENTRY (glade_xml_get_widget
@@ -361,80 +376,26 @@ on_chat_room_name_button_click_event_chat (GtkWidget * widget, gpointer data)
361 nick_entry = 376 nick_entry =
362 GTK_ENTRY (glade_xml_get_widget 377 GTK_ENTRY (glade_xml_get_widget
363 (GNUNET_GTK_get_main_glade_XML (), "chatRoomMonikerEntry")); 378 (GNUNET_GTK_get_main_glade_XML (), "chatRoomMonikerEntry"));
364 379 room_text = (const char *) gtk_entry_get_text (room_entry);
365 room_text = (char *) gtk_entry_get_text (room_entry); 380 nick_text = (const char *) gtk_entry_get_text (nick_entry);
366 nick_text = (char *) gtk_entry_get_text (nick_entry);
367
368 create_chat_room_tab (room_text, nick_text); 381 create_chat_room_tab (room_text, nick_text);
369
370 gtk_entry_set_text (nick_entry, ""); 382 gtk_entry_set_text (nick_entry, "");
371 gtk_entry_set_text (room_entry, ""); 383 gtk_entry_set_text (room_entry, "");
372} 384}
373 385
374void 386void
375on_chat_frame_send_button_click_event_chat (GtkWidget * widget, gpointer data) 387init_chat (struct GNUNET_GE_Context *ectx,
388 struct GNUNET_GC_Configuration *cfg)
376{ 389{
377 GtkWidget *chatnotebook; 390 GtkWidget *tab;
378 GtkWidget *chathbox;
379 GtkWidget *chatlabel;
380 GtkWidget *curr_page;
381 GList *children;
382 GtkEntry *chat_entry;
383 unsigned int seq;
384 char *message;
385 const gchar *room_name;
386 struct GNUNET_CHAT_gui_chat_client *client;
387 struct GNUNET_CHAT_gui_chat_client *pos;
388
389 chatnotebook = gtk_widget_get_ancestor (widget, GTK_TYPE_NOTEBOOK);
390 curr_page =
391 gtk_notebook_get_nth_page (GTK_NOTEBOOK (chatnotebook),
392 gtk_notebook_get_current_page (GTK_NOTEBOOK
393 (chatnotebook)));
394 chatlabel =
395 gtk_notebook_get_tab_label (GTK_NOTEBOOK (chatnotebook), curr_page);
396
397 room_name = gtk_label_get_text (GTK_LABEL (chatlabel));
398
399 chathbox = gtk_widget_get_ancestor (widget, GTK_TYPE_HBOX);
400 children = gtk_container_get_children (GTK_CONTAINER (chathbox));
401
402 chat_entry = NULL;
403 while (children != NULL)
404 {
405 if (strcmp (gtk_widget_get_name (children->data), "chatLineTextEntry")
406 == 0)
407 {
408 chat_entry = GTK_ENTRY (children->data);
409 }
410 children = children->next;
411 }
412
413 message = (char *) gtk_entry_get_text (chat_entry);
414
415 /* Almost there... need to find room in linked list (provided it exists!)
416 * before sending out the message...
417 */
418 if (list == NULL)
419 return;
420 else
421 {
422 pos = list;
423 while ((pos != NULL) && (strcmp (pos->room_name, room_name) != 0))
424 {
425 pos = pos->next;
426 }
427 }
428 if (pos != NULL)
429 client = pos;
430 else
431 return;
432
433 GNUNET_CHAT_send_message (client->room, message,
434 GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
435
436 gtk_entry_set_text (chat_entry, "");
437 391
392 chat_ectx = ectx;
393 chat_cfg = cfg;
394 lock = GNUNET_mutex_create (GNUNET_NO);
395 tab =
396 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
397 "chatnotebookvbox");
398 gtk_widget_show (tab);
438} 399}
439 400
440/* end of chat.c */ 401/* end of chat.c */