Author: nevans Date: 2008-03-07 12:26:30 -0700 (Fri, 07 Mar 2008) New Revision: 6544
Modified: gnunet-gtk/src/plugins/chat/chat.c gnunet-gtk/src/plugins/chat/chat.h Log: Modified: gnunet-gtk/src/plugins/chat/chat.c =================================================================== --- gnunet-gtk/src/plugins/chat/chat.c 2008-03-07 11:41:00 UTC (rev 6543) +++ gnunet-gtk/src/plugins/chat/chat.c 2008-03-07 19:26:30 UTC (rev 6544) @@ -41,7 +41,34 @@ static struct GNUNET_GC_Configuration *chat_cfg; +static struct GNUNET_CHAT_gui_chat_client *list; +static void * +write_save_call (void *arg) +{ + struct GNUNET_CHAT_safe_write_struct *writeholder = arg; + GtkTextBuffer *buffer; + char *char_buf; + char *message_buf; + int message_buf_size; + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(writeholder->chatWindow)); + message_buf_size = snprintf(NULL,0,"<%s> %s",writeholder->senderNick,writeholder->message); + message_buf = GNUNET_malloc(message_buf_size); + snprintf(message_buf,message_buf_size,"<%s> %s",writeholder->senderNick,writeholder->message); + + if(g_utf8_validate(message_buf,message_buf_size,NULL)) + { + g_print("validated fine\n"); + } + else + g_print("didn't validate\n"); + //gtk_text_buffer_set_text(buffer,message_buf,message_buf_size); + + g_print ("%s: %s\n", writeholder->senderNick,writeholder->message); + return; +} + /** * A message was sent in the chat to us. * @@ -64,9 +91,26 @@ const char *message, GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options) { - g_print ("%s: %s\n", senderNick, message); + struct GNUNET_CHAT_gui_chat_client *client = cls; + GtkWidget *chatvbox; + GtkWidget *chattextviewer; + + GList *children; + struct GNUNET_CHAT_safe_write_struct writearg; + + children = gtk_container_get_children(client->chatFrame); + chattextviewer = g_list_nth_data(gtk_container_get_children(g_list_nth_data(gtk_container_get_children(GTK_VBOX(children->data)),0)),0); + + writearg.chatWindow = chattextviewer; + writearg.message = message; + writearg.senderNick = senderNick; + GNUNET_GTK_save_call (&write_save_call, &writearg); + /*Write the message to the appropriate room... - * Somehow G wants me to do this without knowing which room it's headed to, but I don't see how...*/ + * Somehow G wants me to do this without knowing which room it's headed to, but I don't see how... + * perhaps with the closure argument...*/ + + return GNUNET_OK; } @@ -95,12 +139,6 @@ } void -on_chat_room_name_key_press_event_chat (GtkWidget *widget, GdkEventKey *event, gpointer func_data) -{ - g_print("Key pressed....\n"); -} - -void on_chat_room_name_button_click_event_chat(GtkWidget* widget, gpointer data) { GtkEntry *room_entry; @@ -113,8 +151,11 @@ room_text = (char*)gtk_entry_get_text (room_entry); nick_text = (char*)gtk_entry_get_text (nick_entry); + + create_chat_room_tab(room_text,nick_text); - create_chat_room_tab(room_text,nick_text); + gtk_entry_set_text(nick_entry,""); + gtk_entry_set_text(room_entry,""); } int @@ -125,6 +166,8 @@ GtkWidget *chatnotebook; GtkWidget *chatLabel; struct GNUNET_CHAT_Room *chatRoom; + struct GNUNET_CHAT_gui_chat_client *client; + struct GNUNET_CHAT_gui_chat_client *pos; chatnotebook = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebook"); chatXML = glade_xml_new (GNUNET_GTK_get_glade_filename (), "chatFrame",PACKAGE_NAME); @@ -135,30 +178,56 @@ gtk_notebook_insert_page (GTK_NOTEBOOK(chatnotebook),newChatWindow,chatLabel,1); gtk_widget_show (chatnotebook); - + + client = GNUNET_malloc(sizeof(struct GNUNET_CHAT_gui_chat_client)); + client->room_name = GNUNET_malloc(strlen(room_name)); + strcpy(client->room_name,room_name); + + /* We do a silly strdup later on member_info... either check for NULL or only pass "" for member_info!! */ - chatRoom = GNUNET_CHAT_join_room (chat_ectx,chat_cfg,nick,room_name,&pub_key,priv_key,"",&receive_callback,NULL); + chatRoom = GNUNET_CHAT_join_room (chat_ectx,chat_cfg,nick,room_name,&pub_key,priv_key,"",&receive_callback,client); - return 1; + client->room = chatRoom; + client->chatFrame = newChatWindow; + client->number = gtk_notebook_get_current_page(GTK_NOTEBOOK(chatnotebook)); + + if (list == NULL) + list = client; + else + { + pos = list; + while(pos->next != NULL) + { + pos = pos->next; + } + pos->next = client; + } + + return GNUNET_OK; } int remove_chat_room_tab(char *room_name) { - return -1; + return GNUNET_SYSERR; } void on_chat_frame_send_button_click_event_chat(GtkWidget* widget, gpointer data) { GtkWidget *chatnotebook; - GtkWidget *chatvbox; + GtkWidget *chathbox; GtkWidget *chatlabel; GtkWidget *curr_page; + GList *children; + GtkEntry *chat_entry; + + char *message; gchar *room_name; - - + struct GNUNET_CHAT_gui_chat_client *client; + struct GNUNET_CHAT_gui_chat_client *pos; + chatnotebook = gtk_widget_get_ancestor (widget,GTK_TYPE_NOTEBOOK); curr_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(chatnotebook),gtk_notebook_get_current_page(GTK_NOTEBOOK(chatnotebook))); chatlabel = gtk_notebook_get_tab_label (GTK_NOTEBOOK(chatnotebook),curr_page); @@ -167,15 +236,44 @@ g_print("Label of current tab is %s\n",room_name); + chathbox = gtk_widget_get_ancestor (widget,GTK_TYPE_HBOX); + children = gtk_container_get_children (chathbox); + + chat_entry=NULL; + while(children != NULL) + { + if(strcmp(gtk_widget_get_name(children->data),"chatLineTextEntry") == 0) + { + chat_entry = GTK_ENTRY(children->data); + } + children = children->next; + } + + message = (char *)gtk_entry_get_text (chat_entry); + /* Almost there... need to find room in linked list (provided it exists!) * before sending out the message... */ - /*GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, - const char *message, - GNUNET_CHAT_MessageConfirmation callback, - void *cls, - GNUNET_CHAT_MSG_OPTIONS options, - const GNUNET_RSA_PublicKey * receiver);*/ + if (list == NULL) + return; + else + { + pos = list; + while((pos!=NULL)&&(strcmp(pos->room_name,room_name) != 0)) + { + pos = pos->next; + } + } + if(pos != NULL) + client = pos; + else + return; + + GNUNET_CHAT_send_message (client->room,message,NULL, + NULL,GNUNET_CHAT_MSG_OPTION_NONE,NULL); + + gtk_entry_set_text(chat_entry,""); + } /* end of chat.c */ Modified: gnunet-gtk/src/plugins/chat/chat.h =================================================================== --- gnunet-gtk/src/plugins/chat/chat.h 2008-03-07 11:41:00 UTC (rev 6543) +++ gnunet-gtk/src/plugins/chat/chat.h 2008-03-07 19:26:30 UTC (rev 6544) @@ -50,9 +50,17 @@ int number; GtkWidget *chatFrame; struct GNUNET_CHAT_Room *room; + gchar *room_name; }; +struct GNUNET_CHAT_safe_write_struct +{ + GtkWidget *chatWindow; + char *message; + char *senderNick; +}; + void on_chat_frame_send_button_click_event_chat(GtkWidget* widget, gpointer data); _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn