[GnomeMeeting-devel-list] [PATCH] removes unneeded begin/end call notification in text-chat



Hi,

the current notification in text-chat has two problems:
* if the call doesn't really happen (you don't answer or deny the call),
you still get the call end message;
* if no text chat occurs, you still get the call begin/end messages;

This patch fixes both problems.

Notice that:
* it introduces new variables in a structure, but those should be
considered as do-not-read and do-not-modify outside of chat_window.cpp;
* in src/gnomemeeting.cpp, there is a: chat = new GmTextChat (); (that
doesn't really initialize anything as far as I know, since GmTextChat is
just a struct) and in src/main_window.cpp: gw->chat_window =
gnomemeeting_text_chat_new (chat); (that has the side-effect that it
really does initialize the chat!). I find it wrong...

Snark
diff -ur gnomemeeting-cvs-20040122.CVS/src/chat_window.cpp gnomemeeting-cvs-20040122.CVS.patched/src/chat_window.cpp
--- gnomemeeting-cvs-20040122.CVS/src/chat_window.cpp	2004-01-20 12:46:57.000000000 +0100
+++ gnomemeeting-cvs-20040122.CVS.patched/src/chat_window.cpp	2004-01-22 14:04:57.000000000 +0100
@@ -193,14 +193,38 @@
   gtk_menu_set_sensitive (gw->main_menu, "clear_text_chat", FALSE);
 }
 
-/* DESCRIPTION  :  /
- * BEHAVIOR     :  Used by the two notification functions, to display an informative
- *		text message when an event occurs; starting allows to know if the
- *		call is beginning or ending
- * PRE          :  /
- */
-static void
-gnomemeeting_text_chat_call_startstop_notification (gboolean starting)
+void
+gnomemeeting_text_chat_call_start_notification (void)
+{
+  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;
+  char *time_str;
+  
+  time_str = (char *) malloc (21);
+  timeptr = new (time_t);
+ 
+  time (timeptr);
+  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);
+
+  // we are ready to trigger the message display
+  chat->something_typed = FALSE;
+  
+  //  free what we should
+  g_free (time_str);
+}
+
+void
+gnomemeeting_text_chat_call_stop_notification (void)
 {
   GtkTextIter iter;
   GmTextChat *chat = NULL;
@@ -218,35 +242,21 @@
   strftime(time_str, 20, "%H:%M:%S", localtime (timeptr));
 
   // prepare the message to be displayed
-  if (starting)
-    text = g_strdup_printf ("---- Call begins at %s\n", time_str);
-  else
-    text = g_strdup_printf ("---- Call ends at %s\n", time_str);
+  text = g_strdup_printf ("---- Call ends at %s\n", time_str);
 
   // displays the message
   gw = GnomeMeeting::Process ()->GetMainWindow ();
   chat = GnomeMeeting::Process ()->GetTextChat ();
   gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
 
-  gtk_text_buffer_insert(chat->text_buffer, &iter, text, -1);
+  if (chat->something_typed == TRUE)
+    gtk_text_buffer_insert(chat->text_buffer, &iter, text, -1);
 
   // freeing what we need to
   free (time_str);
   g_free (text);
 }
 
-void
-gnomemeeting_text_chat_call_start_notification (void)
-{
-   gnomemeeting_text_chat_call_startstop_notification (TRUE);
-}
-
-void
-gnomemeeting_text_chat_call_stop_notification (void)
-{
-   gnomemeeting_text_chat_call_startstop_notification (FALSE);
-}
-
 void 
 gnomemeeting_text_chat_insert (PString local,
 			       PString str,
@@ -264,6 +274,16 @@
 
   gtk_text_buffer_get_end_iter (chat->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;
+    }
+  }
+
   msg = g_strdup_printf ("%s: ", (const char *) local);
 
   if (user == 1)
@@ -318,6 +338,9 @@
 				  GTK_POLICY_AUTOMATIC,
 				  GTK_POLICY_ALWAYS);
 
+  chat->begin_msg = NULL;
+  chat->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),
diff -ur gnomemeeting-cvs-20040122.CVS/src/common.h gnomemeeting-cvs-20040122.CVS.patched/src/common.h
--- gnomemeeting-cvs-20040122.CVS/src/common.h	2004-01-20 12:46:57.000000000 +0100
+++ gnomemeeting-cvs-20040122.CVS.patched/src/common.h	2004-01-22 13:14:38.000000000 +0100
@@ -160,6 +160,8 @@
 {
   GtkWidget     *text_view;
   GtkTextBuffer *text_buffer;
+  gboolean	something_typed;
+  gchar		*begin_msg;
 };
 
 


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