[GnomeMeeting-devel-list] [PATCH] private text chat



Hi,

this patch makes two things:
1) put the structures internal to the text chat in a private part of the
GmTextChat struct ;
2) clean the api ; it is now used like this :
chat = gnomemeeting_text_chat_new ();
tip = gnomemeeting_text_chat_foo (chat, ...); 
... (other uses, first argument is always GmTextChat*)
gnomemeeting_text_chat_destroy (chat);

Snark
diff -urN gnomemeeting-cvs-20040224.CVS/src/chat_window.cpp gnomemeeting-cvs-20040224.CVS.patched/src/chat_window.cpp
--- gnomemeeting-cvs-20040224.CVS/src/chat_window.cpp	2004-02-08 15:14:14.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/chat_window.cpp	2004-02-27 17:34:32.000000000 +0100
@@ -56,6 +56,15 @@
 
 extern GtkWidget *gm;
 
+struct _GmTextChatPrivate
+{
+  GtkWidget     *window;
+  GtkWidget     *text_view;
+  GtkTextBuffer *text_buffer;
+  gboolean	something_typed;
+  gchar		*begin_msg;
+};
+
 
 #ifndef DISABLE_GNOME
 /* DESCRIPTION  :  Called when an URL is clicked.
@@ -135,6 +144,7 @@
 		     gpointer data)
 {
   GMH323EndPoint *endpoint = GnomeMeeting::Process ()->Endpoint ();
+  GmTextChat *chat = (GmTextChat *)data;
   PString s;
     
   if (endpoint) {
@@ -166,7 +176,7 @@
 	  utf8_local = gnomemeeting_from_iso88591_to_utf8 (local);
 
 	if (utf8_local)
-	  gnomemeeting_text_chat_insert (utf8_local, s, 0);
+	  gnomemeeting_text_chat_insert (chat, utf8_local, s, 0);
 	g_free (utf8_local);
                 
 	gtk_entry_set_text (GTK_ENTRY (w), "");
@@ -177,30 +187,27 @@
   }
 }
 
-void gnomemeeting_text_chat_clear (GtkWidget *w,
-				   GmTextChat *chat)
+void gnomemeeting_text_chat_clear (GmTextChat *chat)
 {
   GmWindow *gw = NULL;
   GtkTextIter start_iter, end_iter;
 
   gw = GnomeMeeting::Process ()->GetMainWindow ();
   
-  gtk_text_buffer_get_start_iter (chat->text_buffer, &start_iter);
-  gtk_text_buffer_get_end_iter (chat->text_buffer, &end_iter);
+  gtk_text_buffer_get_start_iter (chat->internal->text_buffer, &start_iter);
+  gtk_text_buffer_get_end_iter (chat->internal->text_buffer, &end_iter);
 
-  gtk_text_buffer_delete (chat->text_buffer, &start_iter, &end_iter);
+  gtk_text_buffer_delete (chat->internal->text_buffer, &start_iter, &end_iter);
 
   gtk_menu_set_sensitive (gw->main_menu, "clear_text_chat", FALSE);
 }
 
 void
-gnomemeeting_text_chat_call_start_notification (void)
+gnomemeeting_text_chat_call_start_notification (GmTextChat *chat)
 {
-  GmTextChat *chat = NULL;
   GmWindow *gw = NULL;
 
   gw = GnomeMeeting::Process ()->GetMainWindow ();
-  chat = GnomeMeeting::Process ()->GetTextChat ();
 	
   // find the time at which the event occured
   time_t *timeptr;
@@ -213,21 +220,22 @@
   strftime(time_str, 20, "%H:%M:%S", localtime (timeptr));
 
   // prepare the message
-  if (chat->begin_msg) g_free (chat->begin_msg); // shouldn't happen...
-  chat->begin_msg = g_strdup_printf ("---- Call begins at %s\n", time_str);
+  if (chat->internal->begin_msg)
+    g_free (chat->internal->begin_msg); // shouldn't happen...
+  chat->internal->begin_msg = g_strdup_printf ("---- Call begins at %s\n", 
+					       time_str);
 
   // we are ready to trigger the message display
-  chat->something_typed = FALSE;
+  chat->internal->something_typed = FALSE;
   
   //  free what we should
   g_free (time_str);
 }
 
 void
-gnomemeeting_text_chat_call_stop_notification (void)
+gnomemeeting_text_chat_call_stop_notification (GmTextChat *chat)
 {
   GtkTextIter iter;
-  GmTextChat *chat = NULL;
   GmWindow *gw = NULL;
   gchar *text = NULL;
 
@@ -246,11 +254,10 @@
 
   // displays the message
   gw = GnomeMeeting::Process ()->GetMainWindow ();
-  chat = GnomeMeeting::Process ()->GetTextChat ();
-  gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
+  gtk_text_buffer_get_end_iter (chat->internal->text_buffer, &iter);
 
-  if (chat->something_typed == TRUE)
-    gtk_text_buffer_insert(chat->text_buffer, &iter, text, -1);
+  if (chat->internal->something_typed == TRUE)
+    gtk_text_buffer_insert(chat->internal->text_buffer, &iter, text, -1);
 
   // freeing what we need to
   free (time_str);
@@ -258,7 +265,8 @@
 }
 
 void 
-gnomemeeting_text_chat_insert (PString local,
+gnomemeeting_text_chat_insert (GmTextChat *chat,
+			       PString local,
 			       PString str,
 			       int user)
 {
@@ -266,51 +274,60 @@
   GtkTextIter iter;
   GtkTextMark *mark;
   
-  GmTextChat *chat = NULL;
   GmWindow *gw = NULL;
 
   gw = GnomeMeeting::Process ()->GetMainWindow ();
-  chat = GnomeMeeting::Process ()->GetTextChat ();
 
-  gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
+  gtk_text_buffer_get_end_iter (chat->internal->text_buffer, &iter);
 
   // delayed call begin notification first!
-  if (chat->something_typed == FALSE) {
-    chat->something_typed = TRUE;
-    if (chat->begin_msg) { // should always be true
-      gtk_text_buffer_insert(chat->text_buffer, &iter, chat->begin_msg, -1);
-      g_free (chat->begin_msg);
-      chat->begin_msg = NULL;
+  if (chat->internal->something_typed == FALSE) {
+    chat->internal->something_typed = TRUE;
+    if (chat->internal->begin_msg) { // should always be true
+      gtk_text_buffer_insert(chat->internal->text_buffer,
+			     &iter, chat->internal->begin_msg, -1);
+      g_free (chat->internal->begin_msg);
+      chat->internal->begin_msg = NULL;
     }
   }
 
   msg = g_strdup_printf ("%s: ", (const char *) local);
 
   if (user == 1)
-    gtk_text_buffer_insert_with_tags_by_name (chat->text_buffer, &iter, msg, 
-					      -1, "primary-user", NULL);
+    gtk_text_buffer_insert_with_tags_by_name (chat->internal->text_buffer,
+					      &iter, msg, -1,
+					      "primary-user", NULL);
   else
-    gtk_text_buffer_insert_with_tags_by_name (chat->text_buffer, &iter, msg, 
-					      -1, "secondary-user", NULL);
+    gtk_text_buffer_insert_with_tags_by_name (chat->internal->text_buffer,
+					      &iter, msg, -1,
+					      "secondary-user", NULL);
   
   g_free (msg);
   
-  gtk_text_buffer_insert_with_regex (chat->text_buffer, &iter, 
+  gtk_text_buffer_insert_with_regex (chat->internal->text_buffer, &iter, 
 					 (const char *) str);
 
-  gtk_text_buffer_insert (chat->text_buffer, &iter, "\n", -1);
+  gtk_text_buffer_insert (chat->internal->text_buffer, &iter, "\n", -1);
 
-  mark = gtk_text_buffer_get_mark (chat->text_buffer, "current-position");
+  mark = gtk_text_buffer_get_mark (chat->internal->text_buffer,
+				   "current-position");
 
-  gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (chat->text_view), mark, 
-				0.0, FALSE, 0,0);
+  gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (chat->internal->text_view),
+				mark, 0.0, FALSE, 0,0);
 
   gtk_menu_set_sensitive (gw->main_menu, "clear_text_chat", TRUE);
 }
 
+void
+gnomemeeting_text_chat_destroy (GmTextChat *chat)
+{
+  // gtk_widget_destroy (chat->internal->window) unneeded: embedded elsewhere!
+  delete (chat->internal);
+  delete (chat);
+}
 
-GtkWidget *
-gnomemeeting_text_chat_new (GmTextChat *chat)
+GmTextChat*
+gnomemeeting_text_chat_new ()
 {
   GtkWidget *entry = NULL;
   GtkWidget *scr = NULL;
@@ -318,55 +335,61 @@
   GtkWidget *table = NULL;
   GtkWidget *frame = NULL;
   GtkWidget *hbox = NULL;
-  GtkWidget *chat_window = NULL;
+  GmTextChat *chat = NULL;
 
   GtkTextIter  iter;
   GtkTextMark *mark = NULL;
   GtkTextTag *regex_tag = NULL;
 
+  /* create the basic data */
+  chat = new GmTextChat ();
+  chat->internal = new GmTextChatPrivate ();
 
   /* Get the structs from the application */
-  chat_window = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (chat_window), GTK_SHADOW_NONE);
+  chat->internal->window = gtk_frame_new (NULL);
+  gtk_frame_set_shadow_type (GTK_FRAME (chat->internal->window),
+			     GTK_SHADOW_NONE);
   table = gtk_table_new (1, 3, FALSE);
   
   gtk_container_set_border_width (GTK_CONTAINER (table), 0);
-  gtk_container_add (GTK_CONTAINER (chat_window), table);
+  gtk_container_add (GTK_CONTAINER (chat->internal->window), table);
 
   scr = gtk_scrolled_window_new (NULL, NULL);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr),
 				  GTK_POLICY_AUTOMATIC,
 				  GTK_POLICY_ALWAYS);
 
-  chat->begin_msg = NULL;
-  chat->something_typed = FALSE;
+  chat->internal->begin_msg = NULL;
+  chat->internal->something_typed = FALSE;
 
-  chat->text_view = gtk_text_view_new_with_regex ();
-  gtk_text_view_set_editable (GTK_TEXT_VIEW (chat->text_view), FALSE);
-  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (chat->text_view),
+  chat->internal->text_view = gtk_text_view_new_with_regex ();
+  gtk_text_view_set_editable (GTK_TEXT_VIEW (chat->internal->text_view), 
+			      FALSE);
+  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (chat->internal->text_view),
 			       GTK_WRAP_WORD);
 
-  chat->text_buffer = 
-    gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->text_view));
+  chat->internal->text_buffer = 
+    gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->internal->text_view));
 
-  gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
-  gtk_text_view_set_cursor_visible  (GTK_TEXT_VIEW (chat->text_view), false);
+  gtk_text_buffer_get_end_iter (chat->internal->text_buffer, &iter);
+  gtk_text_view_set_cursor_visible  (GTK_TEXT_VIEW (chat->internal->text_view),
+				     false);
 
-  mark = gtk_text_buffer_create_mark (chat->text_buffer, 
+  mark = gtk_text_buffer_create_mark (chat->internal->text_buffer, 
 				      "current-position", &iter, FALSE);
 
-  gtk_text_buffer_create_tag (chat->text_buffer, "primary-user",
+  gtk_text_buffer_create_tag (chat->internal->text_buffer, "primary-user",
 			      "foreground", "red", 
 			      "weight", 900, NULL);
 
-  gtk_text_buffer_create_tag (chat->text_buffer,
+  gtk_text_buffer_create_tag (chat->internal->text_buffer,
 			      "secondary-user",
 			      "foreground", "darkblue", 
 			      "weight", 900, NULL);
 
   
   /* Create the various tags for the different urls types */
-  regex_tag = gtk_text_buffer_create_tag (chat->text_buffer,
+  regex_tag = gtk_text_buffer_create_tag (chat->internal->text_buffer,
 					  "uri-http",
 					  "foreground", "blue",
 					  NULL);
@@ -383,7 +406,8 @@
   }
 
   
-  regex_tag = gtk_text_buffer_create_tag (chat->text_buffer, "uri-h323",
+  regex_tag = gtk_text_buffer_create_tag (chat->internal->text_buffer,
+					  "uri-h323",
 					  "foreground", "pink",
 					  NULL);
   if (gtk_text_tag_set_regex (regex_tag,
@@ -398,14 +422,14 @@
 				       NULL);
   }
 
-  regex_tag = gtk_text_buffer_create_tag (chat->text_buffer, "smileys",
-					  "foreground", "grey",
+  regex_tag = gtk_text_buffer_create_tag (chat->internal->text_buffer,
+					  "smileys", "foreground", "grey",
 					  NULL);
   if (gtk_text_tag_set_regex (regex_tag,
 			      "(:[-]?(\\)|\\(|o|O|p|P|D|\\||/)|\\}:(\\(|\\))|\\|[-]?(\\(|\\))|:'\\(|:\\[|:-(\\.|\\*|x)|;[-]?\\)|(8|B)[-]?\\)|X(\\(|\\||\\))|\\((\\.|\\|)\\)|x\\*O)"))
     gtk_text_tag_set_regex_display (regex_tag, gtk_text_buffer_insert_smiley);
 
-  regex_tag = gtk_text_buffer_create_tag (chat->text_buffer, "latex",
+  regex_tag = gtk_text_buffer_create_tag (chat->internal->text_buffer, "latex",
 					  "foreground", "grey",
 					  NULL);
   if (gtk_text_tag_set_regex (regex_tag,
@@ -417,7 +441,7 @@
   /* */
   frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
-  gtk_container_add (GTK_CONTAINER (scr), chat->text_view);
+  gtk_container_add (GTK_CONTAINER (scr), chat->internal->text_view);
   gtk_container_add (GTK_CONTAINER (frame), scr);
   
   gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (frame), 
@@ -448,7 +472,13 @@
 		    0, 0);
 
   g_signal_connect (GTK_OBJECT (entry), "activate",
-		    G_CALLBACK (chat_entry_activate), chat->text_view);
+		    G_CALLBACK (chat_entry_activate), chat);
 
-  return chat_window;
+  return chat;
+}
+
+GtkWidget*
+gnomemeeting_text_chat_window (GmTextChat *chat)
+{
+  return chat->internal->window;
 }
diff -urN gnomemeeting-cvs-20040224.CVS/src/chat_window.h gnomemeeting-cvs-20040224.CVS.patched/src/chat_window.h
--- gnomemeeting-cvs-20040224.CVS/src/chat_window.h	2004-01-20 12:00:38.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/chat_window.h	2004-02-27 17:27:07.000000000 +0100
@@ -43,17 +43,31 @@
 
 #include "common.h"
 
-
 G_BEGIN_DECLS
 
+typedef struct _GmTextChat GmTextChat;
+typedef struct _GmTextChatPrivate GmTextChatPrivate;
+
+struct _GmTextChat
+{
+  GmTextChatPrivate *internal;
+};
 
 /* DESCRIPTION  :  /
- * BEHAVIOR     :  Initializes the text chat view.
+ * BEHAVIOR     :  Initializes/destroys the text chat.
  * PRE          :  /
  */
-GtkWidget *
-gnomemeeting_text_chat_new (GmTextChat *);
+GmTextChat *
+gnomemeeting_text_chat_new ();
+void
+gnomemeeting_text_chat_destroy (GmTextChat *);
 
+/* DESCRIPTION  :  /
+ * BEHAVIOR     :  Initializes/destroys the text chat.
+ * PRE          :  /
+ */
+GtkWidget*
+gnomemeeting_text_chat_window (GmTextChat *);
 
 /* DESCRIPTION  :  /
  * BEHAVIOR     :  Clears the text chat view.
@@ -61,17 +75,16 @@
  *                 can be used in a callback.
  */
 void
-gnomemeeting_text_chat_clear (GtkWidget *,
-			      GmTextChat *);
+gnomemeeting_text_chat_clear (GmTextChat *);
 
 
 /* DESCRIPTION: /
  * BEHAVIOR :  Signals the text chat that a connection begins or ends
  */
 void
-gnomemeeting_text_chat_call_start_notification (void);
+gnomemeeting_text_chat_call_start_notification (GmTextChat *);
 void
-gnomemeeting_text_chat_call_stop_notification (void);
+gnomemeeting_text_chat_call_stop_notification (GmTextChat *);
 
 /* DESCRIPTION  :  /
  * BEHAVIOR     :  Displays the colored text chat message,
@@ -81,7 +94,8 @@
  *                 0 for local user string, 1 for remote user received string.
  */
 void
-gnomemeeting_text_chat_insert (PString,
+gnomemeeting_text_chat_insert (GmTextChat *,
+			       PString,
 			       PString,
 			       int);
 
diff -urN gnomemeeting-cvs-20040224.CVS/src/common.h gnomemeeting-cvs-20040224.CVS.patched/src/common.h
--- gnomemeeting-cvs-20040224.CVS/src/common.h	2004-02-01 22:53:25.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/common.h	2004-02-27 17:07:40.000000000 +0100
@@ -120,7 +120,6 @@
 typedef struct _GmPrefWindow GmPrefWindow;
 typedef struct _GmLdapWindow GmLdapWindow;
 typedef struct _GmLdapWindowPage GmLdapWindowPage;
-typedef struct _GmTextChat GmTextChat;
 typedef struct _GmDruidWindow GmDruidWindow;
 typedef struct _GmCallsHistoryWindow GmCallsHistoryWindow;
 typedef struct _GmRtpData GmRtpData;
@@ -156,15 +155,6 @@
 } ControlPanelSection;
 
 
-struct _GmTextChat
-{
-  GtkWidget     *text_view;
-  GtkTextBuffer *text_buffer;
-  gboolean	something_typed;
-  gchar		*begin_msg;
-};
-
-
 struct _GmRtpData
 {
   int   tr_audio_bytes;
diff -urN gnomemeeting-cvs-20040224.CVS/src/connection.cpp gnomemeeting-cvs-20040224.CVS.patched/src/connection.cpp
--- gnomemeeting-cvs-20040224.CVS/src/connection.cpp	2004-02-10 23:01:14.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/connection.cpp	2004-02-27 17:22:14.000000000 +0100
@@ -270,7 +270,8 @@
 
   gnomemeeting_threads_enter ();
   if (utf8_remote && strcmp (utf8_remote, "")) 
-    gnomemeeting_text_chat_insert (utf8_remote, val, 1);
+    gnomemeeting_text_chat_insert (GnomeMeeting::Process ()->GetTextChat (),
+				   utf8_remote, val, 1);
   
   if (!GTK_WIDGET_VISIBLE (gw->chat_window))
     gconf_set_bool (USER_INTERFACE_KEY "main_window/show_chat_window", true);
diff -urN gnomemeeting-cvs-20040224.CVS/src/endpoint.cpp gnomemeeting-cvs-20040224.CVS.patched/src/endpoint.cpp
--- gnomemeeting-cvs-20040224.CVS/src/endpoint.cpp	2004-02-18 22:06:33.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/endpoint.cpp	2004-02-27 17:28:37.000000000 +0100
@@ -980,7 +980,7 @@
   gnomemeeting_statusbar_push (gw->statusbar, _("Connected"));
   gnomemeeting_log_insert (_("Connected with %s using %s"), 
 			 utf8_name, utf8_app);
-  gnomemeeting_text_chat_call_start_notification ();
+  gnomemeeting_text_chat_call_start_notification (chat);
 
   gtk_label_set_text (GTK_LABEL (gw->remote_name), (const char *) utf8_name);
   gtk_window_set_title (GTK_WINDOW (gw->remote_video_window), 
@@ -1272,7 +1272,7 @@
 
 
   gnomemeeting_log_insert (msg_reason);
-  gnomemeeting_text_chat_call_stop_notification ();
+  gnomemeeting_text_chat_call_stop_notification (chat);
   gnomemeeting_statusbar_flash (gw->statusbar, msg_reason);
   gnomemeeting_threads_leave ();
 
@@ -1339,7 +1339,7 @@
   
   /* We empty the text chat buffer */
   if (auto_clear_text_chat)
-    gnomemeeting_text_chat_clear (NULL, chat);
+    gnomemeeting_text_chat_clear (chat);
 
 
   /* set-on-top to False */
diff -urN gnomemeeting-cvs-20040224.CVS/src/endpoint.h gnomemeeting-cvs-20040224.CVS.patched/src/endpoint.h
--- gnomemeeting-cvs-20040224.CVS/src/endpoint.h	2004-02-16 20:03:30.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/endpoint.h	2004-02-27 17:26:20.000000000 +0100
@@ -43,6 +43,7 @@
 #include "../config.h"
 
 #include "common.h"
+#include "chat_window.h"
 
 #ifdef HAS_IXJ
 #include <ixjlid.h>
diff -urN gnomemeeting-cvs-20040224.CVS/src/gnomemeeting.cpp gnomemeeting-cvs-20040224.CVS.patched/src/gnomemeeting.cpp
--- gnomemeeting-cvs-20040224.CVS/src/gnomemeeting.cpp	2004-02-10 23:01:15.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/gnomemeeting.cpp	2004-02-27 17:22:47.000000000 +0100
@@ -107,7 +107,7 @@
   pw = new GmPrefWindow ();
   lw = new GmLdapWindow ();
   dw = new GmDruidWindow ();
-  chat = new GmTextChat ();
+  chat = gnomemeeting_text_chat_new ();
   chw = new GmCallsHistoryWindow ();
   rtp = new GmRtpData ();
 
@@ -162,7 +162,7 @@
   delete (pw);
   delete (lw);
   delete (dw);
-  delete (chat);
+  gnomemeeting_text_chat_destroy (chat);
   delete (chw);
   delete (rtp);
 }
diff -urN gnomemeeting-cvs-20040224.CVS/src/main_window.cpp gnomemeeting-cvs-20040224.CVS.patched/src/main_window.cpp
--- gnomemeeting-cvs-20040224.CVS/src/main_window.cpp	2004-02-16 20:03:30.000000000 +0100
+++ gnomemeeting-cvs-20040224.CVS.patched/src/main_window.cpp	2004-02-27 17:17:07.000000000 +0100
@@ -1161,7 +1161,7 @@
 
 
   /* The Chat Window */
-  gw->chat_window = gnomemeeting_text_chat_new (chat);
+  gw->chat_window = gnomemeeting_text_chat_window (chat);
   gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (gw->chat_window), 
  		    2, 4, 0, 3,
  		    (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]