[GnomeMeeting-devel-list] [PATCH] private (and object-like) text chat
- From: PUYDT Julien <julien puydt laposte net>
- To: GnomeMeeting Devel Liste <gnomemeeting-devel-list gnome org>
- Subject: [GnomeMeeting-devel-list] [PATCH] private (and object-like) text chat
- Date: Tue, 06 Apr 2004 14:37:52 +0200
Hi,
the following patch does several things:
* it modifies the api of the gnomemeting_text_chat_* functions to get a
GtkWidget* as first argument (except _new, of course), that is the chat
window, to which the chat's data is attached;
* it makes the format of the chat's data private;
* it modifies the rest of gm to cope with those changes (!).
Snark
diff -ur gnomemeeting-cvs-20040402.CVS/src/chat_window.cpp gnomemeeting-cvs-20040402.CVS.patched/src/chat_window.cpp
--- gnomemeeting-cvs-20040402.CVS/src/chat_window.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/chat_window.cpp 2004-04-06 14:22:17.000000000 +0200
@@ -43,18 +43,41 @@
#include "chat_window.h"
#include "ldap_window.h"
#include "gnomemeeting.h"
-#include "ldap_window.h"
#include "callbacks.h"
#include "misc.h"
-#include "callbacks.h"
#include "gtk-text-tag-addon.h"
#include "gtk-text-buffer-addon.h"
#include "gtk-text-view-addon.h"
#include "gtk_menu_extensions.h"
-extern GtkWidget *gm;
+typedef struct _GmTextChat
+{
+ GtkWidget *text_view;
+ GtkTextBuffer *text_buffer;
+ gboolean something_typed;
+ gchar *begin_msg;
+} GmTextChat;
+/* DESCRIPTION : Called when the chat window is destroyed
+ * BEHAVIOR : Frees the GmTextChat* that is embedded in the window
+ * PRE : /
+ */
+static void
+gm_text_chat_destroy (gpointer chat_pointer)
+{
+ GmTextChat *chat = (GmTextChat *)chat_pointer;
+
+ g_return_if_fail (chat != NULL);
+
+ if (chat->begin_msg != NULL) {
+ g_free (chat->begin_msg);
+ chat->begin_msg = NULL;
+ }
+ /* the rest of the structure is automatically freed:
+ * the main window has the chat_window, and the chat_window has them
+ */
+}
#ifndef DISABLE_GNOME
/* DESCRIPTION : Called when an URL is clicked.
@@ -137,6 +160,7 @@
gpointer data)
{
GMH323EndPoint *endpoint = GnomeMeeting::Process ()->Endpoint ();
+ GtkWidget *chat_window = GnomeMeeting::Process ()->GetTextChatWindow ();
PString s;
if (endpoint) {
@@ -168,7 +192,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_window, utf8_local, s, 0);
g_free (utf8_local);
gtk_entry_set_text (GTK_ENTRY (w), "");
@@ -179,30 +203,28 @@
}
}
-void gnomemeeting_text_chat_clear (GtkWidget *w,
- GmTextChat *chat)
+void gnomemeeting_text_chat_clear (GtkWidget *chat_window)
{
GmWindow *gw = NULL;
+ GmTextChat *chat = NULL;
GtkTextIter start_iter, end_iter;
-
- gw = GnomeMeeting::Process ()->GetMainWindow ();
+ chat = (GmTextChat *)g_object_get_data (G_OBJECT (chat_window), "GMObject");
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_delete (chat->text_buffer, &start_iter, &end_iter);
+ gw = GnomeMeeting::Process ()->GetMainWindow ();
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 (GtkWidget *chat_window)
{
GmTextChat *chat = NULL;
- GmWindow *gw = NULL;
- gw = GnomeMeeting::Process ()->GetMainWindow ();
- chat = GnomeMeeting::Process ()->GetTextChat ();
+ chat = (GmTextChat *)g_object_get_data (G_OBJECT (chat_window), "GMObject");
// find the time at which the event occured
time_t *timeptr;
@@ -226,11 +248,10 @@
}
void
-gnomemeeting_text_chat_call_stop_notification (void)
+gnomemeeting_text_chat_call_stop_notification (GtkWidget *chat_window)
{
GtkTextIter iter;
GmTextChat *chat = NULL;
- GmWindow *gw = NULL;
gchar *text = NULL;
// find the time at which the event occured
@@ -247,8 +268,7 @@
text = g_strdup_printf ("---- Call ends at %s\n", time_str);
// displays the message
- gw = GnomeMeeting::Process ()->GetMainWindow ();
- chat = GnomeMeeting::Process ()->GetTextChat ();
+ chat = (GmTextChat *)g_object_get_data (G_OBJECT (chat_window), "GMObject");
gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
if (chat->something_typed == TRUE)
@@ -260,20 +280,16 @@
}
void
-gnomemeeting_text_chat_insert (PString local,
- PString str,
- int user)
+gnomemeeting_text_chat_insert (GtkWidget *chat_window, PString name,
+ PString str, int user)
{
gchar *msg = NULL;
GtkTextIter iter;
GtkTextMark *mark;
-
GmTextChat *chat = NULL;
GmWindow *gw = NULL;
- gw = GnomeMeeting::Process ()->GetMainWindow ();
- chat = GnomeMeeting::Process ()->GetTextChat ();
-
+ chat = (GmTextChat *)g_object_get_data (G_OBJECT (chat_window), "GMObject");
gtk_text_buffer_get_end_iter (chat->text_buffer, &iter);
// delayed call begin notification first!
@@ -286,7 +302,7 @@
}
}
- msg = g_strdup_printf ("%s: ", (const char *) local);
+ msg = g_strdup_printf ("%s: ", (const char *) name);
if (user == 1)
gtk_text_buffer_insert_with_tags_by_name (chat->text_buffer, &iter, msg,
@@ -307,12 +323,13 @@
gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (chat->text_view), mark,
0.0, FALSE, 0,0);
+ gw = GnomeMeeting::Process ()->GetMainWindow ();
gtk_menu_set_sensitive (gw->main_menu, "clear_text_chat", TRUE);
}
GtkWidget *
-gnomemeeting_text_chat_new (GmTextChat *chat)
+gnomemeeting_text_chat_new ()
{
GtkWidget *entry = NULL;
GtkWidget *scr = NULL;
@@ -321,14 +338,19 @@
GtkWidget *frame = NULL;
GtkWidget *hbox = NULL;
GtkWidget *chat_window = NULL;
-
+ GmTextChat *chat = NULL;
GtkTextIter iter;
GtkTextMark *mark = NULL;
GtkTextTag *regex_tag = NULL;
/* Get the structs from the application */
+ chat = new GmTextChat ();
chat_window = gtk_frame_new (NULL);
+ g_object_set_data_full (G_OBJECT (chat_window), "GMObject",
+ (gpointer) chat,
+ (GDestroyNotify) (gm_text_chat_destroy));
+
gtk_frame_set_shadow_type (GTK_FRAME (chat_window), GTK_SHADOW_NONE);
table = gtk_table_new (1, 3, FALSE);
diff -ur gnomemeeting-cvs-20040402.CVS/src/chat_window.h gnomemeeting-cvs-20040402.CVS.patched/src/chat_window.h
--- gnomemeeting-cvs-20040402.CVS/src/chat_window.h 2004-01-20 12:00:38.000000000 +0100
+++ gnomemeeting-cvs-20040402.CVS.patched/src/chat_window.h 2004-04-06 14:01:47.000000000 +0200
@@ -43,47 +43,41 @@
#include "common.h"
-
G_BEGIN_DECLS
-
/* DESCRIPTION : /
* BEHAVIOR : Initializes the text chat view.
* PRE : /
*/
GtkWidget *
-gnomemeeting_text_chat_new (GmTextChat *);
+gnomemeeting_text_chat_new ();
/* DESCRIPTION : /
* BEHAVIOR : Clears the text chat view.
- * PRE : The first parameter is fictive so that the function
- * can be used in a callback.
+ * PRE : /
*/
void
-gnomemeeting_text_chat_clear (GtkWidget *,
- GmTextChat *);
+gnomemeeting_text_chat_clear (GtkWidget *);
/* 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 (GtkWidget *);
void
-gnomemeeting_text_chat_call_stop_notification (void);
+gnomemeeting_text_chat_call_stop_notification (GtkWidget *);
/* DESCRIPTION : /
* BEHAVIOR : Displays the colored text chat message,
- * with some enhancements (context menu
- * for uris, graphics for smileys, etc)
- * PRE : The name of the user, the name of the remote user,
+ * with some enhancements (context menu
+ * for uris, graphics for smileys, etc)
+ * PRE : The name of the (local or remote) user, the message and
* 0 for local user string, 1 for remote user received string.
*/
void
-gnomemeeting_text_chat_insert (PString,
- PString,
- int);
+gnomemeeting_text_chat_insert (GtkWidget *, PString, PString, int);
G_END_DECLS
diff -ur gnomemeeting-cvs-20040402.CVS/src/common.h gnomemeeting-cvs-20040402.CVS.patched/src/common.h
--- gnomemeeting-cvs-20040402.CVS/src/common.h 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/common.h 2004-04-06 14:01:07.000000000 +0200
@@ -111,7 +111,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;
@@ -146,16 +145,6 @@
NUM_SECTIONS
} ControlPanelSection;
-
-struct _GmTextChat
-{
- GtkWidget *text_view;
- GtkTextBuffer *text_buffer;
- gboolean something_typed;
- gchar *begin_msg;
-};
-
-
struct _GmRtpData
{
int tr_audio_bytes;
diff -ur gnomemeeting-cvs-20040402.CVS/src/config.cpp gnomemeeting-cvs-20040402.CVS.patched/src/config.cpp
--- gnomemeeting-cvs-20040402.CVS/src/config.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/config.cpp 2004-04-06 08:40:37.000000000 +0200
@@ -1625,8 +1625,8 @@
view_widget_changed_nt, gw->statusbar);
gm_conf_notifier_add (USER_INTERFACE_KEY "main_window/show_chat_window",
- menu_toggle_changed_nt,
- gtk_menu_get_widget (gw->main_menu, "text_chat"));
+ menu_toggle_changed_nt, gtk_menu_get_widget (gw->main_menu, "text_chat"));
+
gm_conf_notifier_add (USER_INTERFACE_KEY "main_window/show_chat_window",
view_widget_changed_nt, gw->chat_window);
diff -ur gnomemeeting-cvs-20040402.CVS/src/connection.cpp gnomemeeting-cvs-20040402.CVS.patched/src/connection.cpp
--- gnomemeeting-cvs-20040402.CVS/src/connection.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/connection.cpp 2004-04-05 20:21:15.000000000 +0200
@@ -271,7 +271,7 @@
gnomemeeting_threads_enter ();
if (utf8_remote && strcmp (utf8_remote, ""))
- gnomemeeting_text_chat_insert (utf8_remote, val, 1);
+ gnomemeeting_text_chat_insert (gw->chat_window, utf8_remote, val, 1);
if (!GTK_WIDGET_VISIBLE (gw->chat_window))
gm_conf_set_bool (USER_INTERFACE_KEY "main_window/show_chat_window", true);
diff -ur gnomemeeting-cvs-20040402.CVS/src/endpoint.cpp gnomemeeting-cvs-20040402.CVS.patched/src/endpoint.cpp
--- gnomemeeting-cvs-20040402.CVS/src/endpoint.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/endpoint.cpp 2004-04-05 20:23:18.000000000 +0200
@@ -82,7 +82,7 @@
/* Get the GTK structures */
gw = GnomeMeeting::Process ()->GetMainWindow ();
lw = GnomeMeeting::Process ()->GetLdapWindow ();
- chat = GnomeMeeting::Process ()->GetTextChat ();
+ chat_window = GnomeMeeting::Process ()->GetTextChatWindow ();
/* Initialise the endpoint paramaters */
video_grabber = NULL;
@@ -978,7 +978,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_window);
gtk_label_set_text (GTK_LABEL (gw->remote_name), (const char *) utf8_name);
gtk_window_set_title (GTK_WINDOW (gw->remote_video_window),
@@ -1270,7 +1270,7 @@
gnomemeeting_log_insert (msg_reason);
- gnomemeeting_text_chat_call_stop_notification ();
+ gnomemeeting_text_chat_call_stop_notification (chat_window);
gnomemeeting_statusbar_flash (gw->statusbar, msg_reason);
gnomemeeting_threads_leave ();
@@ -1338,7 +1338,7 @@
/* We empty the text chat buffer */
if (auto_clear_text_chat)
- gnomemeeting_text_chat_clear (NULL, chat);
+ gnomemeeting_text_chat_clear (chat_window);
/* set-on-top to False */
diff -ur gnomemeeting-cvs-20040402.CVS/src/endpoint.h gnomemeeting-cvs-20040402.CVS.patched/src/endpoint.h
--- gnomemeeting-cvs-20040402.CVS/src/endpoint.h 2004-03-27 20:03:13.000000000 +0100
+++ gnomemeeting-cvs-20040402.CVS.patched/src/endpoint.h 2004-04-05 20:24:09.000000000 +0200
@@ -627,7 +627,7 @@
GmWindow *gw;
GmLdapWindow *lw;
- GmTextChat *chat;
+ GtkWidget *chat_window;
/* The encoding video grabber */
diff -ur gnomemeeting-cvs-20040402.CVS/src/gnomemeeting.cpp gnomemeeting-cvs-20040402.CVS.patched/src/gnomemeeting.cpp
--- gnomemeeting-cvs-20040402.CVS/src/gnomemeeting.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/gnomemeeting.cpp 2004-04-06 13:27:08.000000000 +0200
@@ -108,7 +108,7 @@
pw = new GmPrefWindow ();
lw = new GmLdapWindow ();
dw = new GmDruidWindow ();
- chat = new GmTextChat ();
+ chat_window = gnomemeeting_text_chat_new ();
chw = new GmCallsHistoryWindow ();
rtp = new GmRtpData ();
@@ -163,7 +163,7 @@
delete (pw);
delete (lw);
delete (dw);
- delete (chat);
+ /* delete (chat_window); unneeded: embedded in the main window! */
delete (chw);
delete (rtp);
}
@@ -391,10 +391,10 @@
}
-GmTextChat *
-GnomeMeeting::GetTextChat ()
+GtkWidget *
+GnomeMeeting::GetTextChatWindow ()
{
- return chat;
+ return chat_window;
}
@@ -433,6 +433,7 @@
/* Build the GUI */
gnomemeeting_stock_icons_init ();
+ gw->chat_window = chat_window;
gw->tips = gtk_tooltips_new ();
gw->log_window = gnomemeeting_log_window_new ();
gw->calls_history_window = gnomemeeting_calls_history_window_new (chw);
diff -ur gnomemeeting-cvs-20040402.CVS/src/gnomemeeting.h gnomemeeting-cvs-20040402.CVS.patched/src/gnomemeeting.h
--- gnomemeeting-cvs-20040402.CVS/src/gnomemeeting.h 2004-03-27 20:03:13.000000000 +0100
+++ gnomemeeting-cvs-20040402.CVS.patched/src/gnomemeeting.h 2004-04-06 13:25:03.000000000 +0200
@@ -144,11 +144,10 @@
/* DESCRIPTION : /
- * BEHAVIOR : Returns a pointer to the GmTextChat
- * structure of widgets.
+ * BEHAVIOR : Returns a pointer to the chat window
* PRE : /
*/
- GmTextChat *GetTextChat ();
+ GtkWidget *GetTextChatWindow ();
/* DESCRIPTION : /
@@ -201,7 +200,7 @@
GmDruidWindow *dw;
GmCallsHistoryWindow *chw;
GmPrefWindow *pw;
- GmTextChat *chat;
+ GtkWidget *chat_window;
GmRtpData *rtp;
PMutex ep_var_mutex;
diff -ur gnomemeeting-cvs-20040402.CVS/src/main_window.cpp gnomemeeting-cvs-20040402.CVS.patched/src/main_window.cpp
--- gnomemeeting-cvs-20040402.CVS/src/main_window.cpp 2004-04-05 17:33:57.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/main_window.cpp 2004-04-05 20:55:03.000000000 +0200
@@ -969,17 +969,14 @@
GtkWidget *event_box = NULL;
GtkWidget *main_toolbar = NULL;
GtkWidget *left_toolbar = NULL;
+ GtkWidget *chat_window = NULL;
int main_notebook_section = 0;
- GmTextChat *chat = NULL;
-
static GtkTargetEntry dnd_targets [] =
{
{"text/plain", GTK_TARGET_SAME_APP, 0}
};
-
- chat = GnomeMeeting::Process ()->GetTextChat ();
accel = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel);
@@ -1164,14 +1161,14 @@
/* The Chat Window */
- gw->chat_window = gnomemeeting_text_chat_new (chat);
- gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (gw->chat_window),
+ chat_window = GnomeMeeting::Process ()->GetTextChatWindow ();
+ gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (chat_window),
2, 4, 0, 3,
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
6, 6);
if (gm_conf_get_bool (USER_INTERFACE_KEY "main_window/show_chat_window"))
- gtk_widget_show_all (GTK_WIDGET (gw->chat_window));
+ gtk_widget_show_all (GTK_WIDGET (chat_window));
gtk_widget_set_size_request (GTK_WIDGET (gw->main_notebook),
GM_QCIF_WIDTH + GM_FRAME_SIZE, -1);
diff -ur gnomemeeting-cvs-20040402.CVS/src/menu.cpp gnomemeeting-cvs-20040402.CVS.patched/src/menu.cpp
--- gnomemeeting-cvs-20040402.CVS/src/menu.cpp 2004-04-01 21:13:41.000000000 +0200
+++ gnomemeeting-cvs-20040402.CVS.patched/src/menu.cpp 2004-04-05 20:27:42.000000000 +0200
@@ -59,6 +59,8 @@
/* Static functions */
+static void text_chat_clear_cb (GtkWidget *,
+ gpointer);
static void zoom_changed_callback (GtkWidget *,
gpointer);
@@ -80,6 +82,22 @@
/* GTK Callbacks */
+/* DESCRIPTION : This callback is called when the user clicks on the
+ * clear text chat menu entry
+ * BEHAVIOR : clears text chat
+ * PRE : /
+ */
+static void
+text_chat_clear_cb (GtkWidget *widget,
+ gpointer data)
+{
+ GtkWidget *chat_window = NULL;
+
+ chat_window = GTK_WIDGET (data);
+ gnomemeeting_text_chat_clear (chat_window);
+}
+
+
/* DESCRIPTION : This callback is called when the user changes the zoom
* factor in the menu.
* BEHAVIOR : Sets zoom to 1:2 if data == 0, 1:1 if data == 1,
@@ -212,7 +230,7 @@
gnomemeeting_init_menu (GtkAccelGroup *accel)
{
GmWindow *gw = NULL;
- GmTextChat *chat = NULL;
+ GtkWidget *cw = NULL;
GtkWidget *menubar = NULL;
@@ -221,7 +239,7 @@
bool show_status_bar = false;
bool show_chat_window = false;
- chat = GnomeMeeting::Process ()->GetTextChat ();
+ cw = GnomeMeeting::Process ()->GetTextChatWindow ();
gw = GnomeMeeting::Process ()->GetMainWindow ();
menubar = gtk_menu_bar_new ();
@@ -394,8 +412,8 @@
GTK_MENU_ENTRY("clear_text_chat", _("_Clear Text Chat"),
_("Clear the text chat"),
GTK_STOCK_CLEAR, 'L',
- GTK_SIGNAL_FUNC (gnomemeeting_text_chat_clear),
- (gpointer) chat, FALSE),
+ GTK_SIGNAL_FUNC (text_chat_clear_cb),
+ (gpointer) cw, FALSE),
GTK_MENU_SEPARATOR,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]