aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/chat
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/chat')
-rw-r--r--src/plugins/chat/Makefile.am22
-rw-r--r--src/plugins/chat/chat.c447
2 files changed, 0 insertions, 469 deletions
diff --git a/src/plugins/chat/Makefile.am b/src/plugins/chat/Makefile.am
deleted file mode 100644
index bcfd16e8..00000000
--- a/src/plugins/chat/Makefile.am
+++ /dev/null
@@ -1,22 +0,0 @@
1INCLUDES = \
2 -I$(top_srcdir)/intl \
3 -I$(top_srcdir)/src/include \
4 @GTK_CFLAGS@ \
5 @GNUNETGTK_CFLAGS@
6
7plugindir = $(libdir)/GNUnet
8
9plugin_LTLIBRARIES = \
10 libgnunetgtkmodule_chat.la
11
12libgnunetgtkmodule_chat_la_SOURCES = \
13 chat.c
14
15libgnunetgtkmodule_chat_la_LIBADD = \
16 $(top_builddir)/src/common/libgnunetgtk_common.la \
17 -lgnunetutil \
18 -lgnunetchatapi \
19 @GTK_LIBS@ @GNUNETGTK_LIBS@
20
21libgnunetgtkmodule_chat_la_LDFLAGS = \
22 -export-dynamic -avoid-version -module
diff --git a/src/plugins/chat/chat.c b/src/plugins/chat/chat.c
deleted file mode 100644
index 4f7350db..00000000
--- a/src/plugins/chat/chat.c
+++ /dev/null
@@ -1,447 +0,0 @@
1/*
2 This file is part of GNUnet
3 (C) 2008 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/plugins/about/chat.c
23 * @author Christian Grothoff
24 * @author Igor Wronsky
25 * @author Nathan Evans
26 */
27
28#include "platform.h"
29#include <GNUnet/gnunet_util_pseudonym.h>
30#include <GNUnet/gnunet_chat_lib.h>
31#include "gnunetgtk_common.h"
32
33struct GNUNET_CHAT_safe_write_struct
34{
35 GtkWidget *text_view;
36 const char *message;
37 const char *sender;
38};
39
40struct GNUNET_CHAT_safe_nick_write_struct
41{
42 GtkListStore *model;
43 GdkPixbuf *icon;
44 const struct GNUNET_MetaData *meta;
45 const char *nick;
46 GNUNET_HashCode pid;
47};
48
49struct GNUNET_CHAT_gui_chat_client
50{
51 struct GNUNET_CHAT_gui_chat_client *next;
52 GtkWidget *send_button;
53 GtkWidget *text_view;
54 GtkListStore *nick_model;
55 GtkWidget *chatFrame;
56 GtkWidget *chat_entry;
57 GtkWidget *tab_label;
58 GladeXML *chatXML;
59 GladeXML *labelXML;
60 struct GNUNET_CHAT_Room *room;
61 GNUNET_HashCode mypid;
62};
63
64/**
65 * For nicknames in chat view.
66 */
67enum
68{
69 CHAT_NICKNAME = 0,
70 CHAT_METADATA,
71 CHAT_ICON,
72 CHAT_PID,
73 CHAT_NUM,
74};
75
76
77static struct GNUNET_Mutex *lock;
78
79static struct GNUNET_GE_Context *chat_ectx;
80
81static struct GNUNET_GC_Configuration *chat_cfg;
82
83static struct GNUNET_CHAT_gui_chat_client *list;
84
85static void *
86write_save_call (void *arg)
87{
88 struct GNUNET_CHAT_safe_write_struct *cls = arg;
89 GtkTextBuffer *buffer;
90 char *message_buf;
91 int message_buf_size;
92
93 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (cls->text_view));
94 message_buf_size =
95 snprintf (NULL, 0, "<%s>: %s\n", cls->sender, cls->message);
96 message_buf = GNUNET_malloc (message_buf_size + 1);
97 GNUNET_snprintf (message_buf,
98 message_buf_size + 1,
99 "<%s>: %s\n", cls->sender, cls->message);
100 gtk_text_buffer_insert_at_cursor (buffer, message_buf, message_buf_size);
101 GNUNET_free (message_buf);
102 return NULL;
103}
104
105/**
106 * Safe call to add a nick to the chat room view
107 */
108static void *
109add_nick_save_call (void *arg)
110{
111 struct GNUNET_CHAT_safe_nick_write_struct *cls = arg;
112 GtkListStore *model;
113 GtkTreeIter iter;
114 GNUNET_HashCode *pid;
115
116 model = GTK_LIST_STORE (cls->model);
117 gtk_list_store_append (model, &iter);
118 pid = GNUNET_malloc (sizeof (GNUNET_HashCode));
119 *pid = cls->pid;
120 gtk_list_store_set (model,
121 &iter,
122 CHAT_PID, pid,
123 CHAT_METADATA,
124 GNUNET_meta_data_duplicate (cls->meta), CHAT_ICON,
125 cls->icon, CHAT_NICKNAME, cls->nick, -1);
126 return NULL;
127}
128
129/**
130 * Safe call to remove a nick from the chat room view
131 */
132static void *
133remove_nick_save_call (void *arg)
134{
135 struct GNUNET_CHAT_safe_nick_write_struct *cls = arg;
136 GtkListStore *model;
137 GtkTreeIter iter;
138 GNUNET_HashCode *pid;
139 struct GNUNET_MetaData *meta;
140
141 model = GTK_LIST_STORE (cls->model);
142 /* find and remove existing entry */
143 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter))
144 {
145 do
146 {
147 pid = NULL;
148 gtk_tree_model_get (GTK_TREE_MODEL (model),
149 &iter,
150 CHAT_PID, &pid, CHAT_METADATA, &meta, -1);
151 if ((pid != NULL) &&
152 (0 == memcmp (pid, &cls->pid, sizeof (GNUNET_HashCode))))
153 {
154 GNUNET_meta_data_destroy (meta);
155 GNUNET_free (pid);
156 gtk_list_store_remove (model, &iter);
157 return NULL; /* done! */
158 }
159 }
160 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
161 }
162 return NULL;
163}
164
165
166/**
167 * This method is called when the user clicks on
168 * the "CANCEL (X)" button in the TAB of the
169 * chat notebook.
170 */
171void
172on_closeChatButton_clicked_chat (GtkWidget * chatPage,
173 GtkWidget * closeButton)
174{
175 struct GNUNET_CHAT_gui_chat_client *pos;
176 struct GNUNET_CHAT_gui_chat_client *prev;
177 GtkNotebook *chatnotebook;
178 int index;
179 int i;
180
181 prev = NULL;
182 pos = list;
183 while (pos != NULL)
184 {
185 if (pos->tab_label == chatPage)
186 break;
187 prev = pos;
188 pos = pos->next;
189 }
190 if (prev == NULL)
191 list = pos->next;
192 else
193 prev->next = pos;
194 GNUNET_GE_ASSERT (NULL, pos != NULL);
195 GNUNET_GTK_run_with_save_calls
196 ((GNUNET_ThreadMainFunction) & GNUNET_CHAT_leave_room, pos->room);
197
198 chatnotebook =
199 GTK_NOTEBOOK (glade_xml_get_widget
200 (GNUNET_GTK_get_main_glade_XML (), "chatnotebook"));
201 /* remove page from notebook */
202 index = -1;
203 for (i = gtk_notebook_get_n_pages (chatnotebook) - 1; i >= 0; i--)
204 if (pos->chatFrame == gtk_notebook_get_nth_page (chatnotebook, i))
205 index = i;
206 GNUNET_GE_BREAK (NULL, index != -1);
207 gtk_notebook_remove_page (chatnotebook, index);
208 UNREF (pos->chatXML);
209 UNREF (pos->labelXML);
210 GNUNET_free (pos);
211}
212
213
214
215/**
216 * A message was sent in the chat to us.
217 *
218 * @param senderNick what is the nickname of the sender? (maybe NULL)
219 * @param message the message (maybe NULL, especially if confirmation
220 * is requested before delivery; the protocol will ensure
221 * that this function is called again with the full message
222 * if a confirmation is transmitted; if the message is NULL,
223 * the user is merely asked if engaging in the exchange is ok
224 * @param room in which room was the message received?
225 * @param options options for the message
226 * @return GNUNET_OK to accept the message now, GNUNET_NO to
227 * accept (but user is away), GNUNET_SYSERR to signal denied delivery
228 */
229static int
230receive_callback (void *cls,
231 struct GNUNET_CHAT_Room *room,
232 const GNUNET_HashCode * sender,
233 const struct GNUNET_MetaData *member_info,
234 const char *message, GNUNET_CHAT_MSG_OPTIONS options)
235{
236 struct GNUNET_CHAT_gui_chat_client *client = cls;
237 struct GNUNET_CHAT_safe_write_struct writearg;
238 char *sndr;
239
240 sndr =
241 sender == NULL
242 ? GNUNET_strdup ( _("anonymous"))
243 : GNUNET_pseudonym_id_to_name (chat_ectx,
244 chat_cfg,
245 sender);
246 writearg.text_view = client->text_view;
247 writearg.message = message;
248 writearg.sender = sndr;
249 GNUNET_GTK_save_call (&write_save_call, &writearg);
250 GNUNET_free_non_null (sndr);
251 return GNUNET_OK;
252}
253
254static int
255member_list_callback (void *cls,
256 const struct GNUNET_MetaData *member_info,
257 const GNUNET_RSA_PublicKey * pkey,
258 GNUNET_CHAT_MSG_OPTIONS opt)
259{
260 struct GNUNET_CHAT_gui_chat_client *client = cls;
261 struct GNUNET_CHAT_safe_nick_write_struct writearg;
262 char *nick;
263 char *path;
264 char *filename;
265
266 GNUNET_hash (pkey, sizeof (GNUNET_RSA_PublicKey), &writearg.pid);
267 nick = GNUNET_pseudonym_id_to_name (chat_ectx, chat_cfg, &writearg.pid);
268 writearg.model = client->nick_model;
269 writearg.icon = NULL;
270 if (0 == memcmp (&writearg.pid, &client->mypid, sizeof (GNUNET_HashCode)))
271 {
272 path = GNUNET_get_installation_path (GNUNET_IPK_SELF_PREFIX);
273 filename =
274 GNUNET_malloc (strlen (path) +
275 strlen ("share/gnunet-gtk/self.png") + 1);
276 strcpy (filename, path);
277 GNUNET_free (path);
278 strcat (filename, "share/gnunet-gtk/self.png");
279 writearg.icon = gdk_pixbuf_new_from_file (filename, NULL);
280 GNUNET_free (filename);
281 }
282 writearg.meta = member_info;
283 writearg.nick = nick;
284 if (member_info != NULL)
285 GNUNET_GTK_save_call (&add_nick_save_call, &writearg);
286 else
287 GNUNET_GTK_save_call (&remove_nick_save_call, &writearg);
288 GNUNET_free (nick);
289 if (writearg.icon != NULL)
290 g_object_unref (writearg.icon);
291 return GNUNET_OK;
292}
293
294void
295on_chat_frame_send_button_click_event_chat (GtkWidget * widget, gpointer data)
296{
297 unsigned int seq;
298 const char *message;
299 struct GNUNET_CHAT_gui_chat_client *pos;
300
301 GNUNET_mutex_lock (lock);
302 pos = list;
303 while ((pos != NULL) && (pos->send_button != widget) &&
304 (pos->chat_entry != widget))
305 pos = pos->next;
306 GNUNET_GE_ASSERT (NULL, pos != NULL);
307
308 message = (const char *) gtk_entry_get_text (GTK_ENTRY (pos->chat_entry));
309 if (strlen (message) > 0)
310 {
311 GNUNET_CHAT_send_message (pos->room,
312 message, GNUNET_CHAT_MSG_OPTION_NONE, NULL,
313 &seq);
314 gtk_entry_set_text (GTK_ENTRY (pos->chat_entry), "");
315 }
316 GNUNET_mutex_unlock (lock);
317}
318
319static void
320create_chat_room_tab (const char *room_name, const char *nick)
321{
322 GtkWidget *chatnotebook;
323 GtkLabel *label;
324 GtkTreeView *treeview;
325 struct GNUNET_CHAT_gui_chat_client *client;
326 struct GNUNET_MetaData *meta;
327 GtkCellRenderer *renderer;
328 GtkTreeViewColumn *column;
329 int col;
330
331 chatnotebook =
332 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebook");
333
334 client = GNUNET_malloc (sizeof (struct GNUNET_CHAT_gui_chat_client));
335 client->chatXML =
336 glade_xml_new (GNUNET_GTK_get_glade_filename (),
337 "chatFrame", PACKAGE_NAME);
338 GNUNET_GTK_connect_glade_with_plugins (client->chatXML);
339 client->chatFrame =
340 GNUNET_GTK_extract_main_widget_from_window (client->chatXML, "chatFrame");
341 client->labelXML =
342 glade_xml_new (GNUNET_GTK_get_glade_filename (),
343 "chatTabLabelWindow", PACKAGE_NAME);
344 GNUNET_GTK_connect_glade_with_plugins (client->labelXML);
345 client->tab_label
346 = GNUNET_GTK_extract_main_widget_from_window (client->labelXML,
347 "chatTabLabelWindow");
348 label = GTK_LABEL (glade_xml_get_widget (client->labelXML, "chatTabLabel"));
349 gtk_label_set (label, room_name);
350 gtk_notebook_append_page (GTK_NOTEBOOK (chatnotebook),
351 client->chatFrame, client->tab_label);
352 gtk_widget_show (chatnotebook);
353
354 client->nick_model = gtk_list_store_new (CHAT_NUM, G_TYPE_STRING, /* nickname */
355 G_TYPE_POINTER, /* metadata */
356 GDK_TYPE_PIXBUF, /* icon */
357 G_TYPE_POINTER); /* pid */
358 client->send_button =
359 glade_xml_get_widget (client->chatXML, "chatSendButton");
360 client->text_view = glade_xml_get_widget (client->chatXML, "chatLogViewer");
361 client->chat_entry =
362 glade_xml_get_widget (client->chatXML, "chatLineTextEntry");
363 treeview =
364 GTK_TREE_VIEW (glade_xml_get_widget
365 (client->chatXML, "roomMembersTreeView"));
366 gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (client->nick_model));
367
368 renderer = gtk_cell_renderer_text_new ();
369 col = gtk_tree_view_insert_column_with_attributes (treeview,
370 -1,
371 _("Nickname"),
372 renderer,
373 "text", CHAT_NICKNAME,
374 NULL);
375 column = gtk_tree_view_get_column (treeview, col - 1);
376 gtk_tree_view_column_set_resizable (column, TRUE);
377 gtk_tree_view_column_set_clickable (column, TRUE);
378 gtk_tree_view_column_set_reorderable (column, TRUE);
379 gtk_tree_view_column_set_sort_column_id (column, CHAT_NICKNAME);
380 gtk_tree_view_column_set_min_width (column, 0);
381
382 renderer = gtk_cell_renderer_pixbuf_new ();
383 col = gtk_tree_view_insert_column_with_attributes (treeview,
384 -1,
385 "",
386 renderer,
387 "pixbuf", CHAT_ICON,
388 NULL);
389 column = gtk_tree_view_get_column (treeview, col - 1);
390 gtk_tree_view_column_set_resizable (column, TRUE);
391 gtk_tree_view_column_set_clickable (column, FALSE);
392 gtk_tree_view_column_set_reorderable (column, FALSE);
393
394 GNUNET_mutex_lock (lock);
395 client->next = list;
396 list = client;
397 GNUNET_mutex_unlock (lock);
398
399 meta = GNUNET_meta_data_create ();
400 GNUNET_meta_data_insert (meta, EXTRACTOR_TITLE, nick);
401 client->room =
402 GNUNET_CHAT_join_room (chat_ectx, chat_cfg, nick,
403 meta,
404 room_name,
405 -1,
406 &receive_callback, client, &member_list_callback,
407 client, NULL, NULL, &client->mypid);
408 GNUNET_meta_data_destroy (meta);
409}
410
411void
412on_chat_room_name_button_click_event_chat (GtkWidget * widget, gpointer data)
413{
414 GtkEntry *room_entry;
415 GtkEntry *nick_entry;
416 const char *room_text;
417 const char *nick_text;
418
419 room_entry =
420 GTK_ENTRY (glade_xml_get_widget
421 (GNUNET_GTK_get_main_glade_XML (), "chatRoomNameEntry"));
422 nick_entry =
423 GTK_ENTRY (glade_xml_get_widget
424 (GNUNET_GTK_get_main_glade_XML (), "chatRoomMonikerEntry"));
425 room_text = (const char *) gtk_entry_get_text (room_entry);
426 nick_text = (const char *) gtk_entry_get_text (nick_entry);
427 create_chat_room_tab (room_text, nick_text);
428 gtk_entry_set_text (nick_entry, "");
429 gtk_entry_set_text (room_entry, "");
430}
431
432void
433init_chat (struct GNUNET_GE_Context *ectx,
434 struct GNUNET_GC_Configuration *cfg)
435{
436 GtkWidget *tab;
437
438 chat_ectx = ectx;
439 chat_cfg = cfg;
440 lock = GNUNET_mutex_create (GNUNET_NO);
441 tab =
442 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
443 "chatnotebookvbox");
444 gtk_widget_show (tab);
445}
446
447/* end of chat.c */