PATCH: update gaim frontend for CVS version



I tried to just make a patch for the gaim.patch file, but couldn't
figure out if this was acceptable behavior or even possible (the patch
command didn't like it).  So basically I just changed 4 lines.

Gaim cvs has a changed plugin API and some modified signals for received
IMs, so I just updated the patch in dashboard/frontends to reflect this.

I tested it, should work with current anonymous CVS.

-- 
David Smock <d-smock northwestern edu>
diff -u --recursive --exclude=CVS --new-file pristine/gaim/plugins/Makefile.am gaim/plugins/Makefile.am
--- pristine/gaim/plugins/Makefile.am	2003-12-13 14:04:09.000000000 -0500
+++ gaim/plugins/Makefile.am	2004-01-08 22:11:17.000000000 -0500
@@ -21,6 +21,7 @@
 spellchk_la_LDFLAGS    = -module -avoid-version
 statenotify_la_LDFLAGS = -module -avoid-version
 timestamp_la_LDFLAGS   = -module -avoid-version
+dashboard_la_LDFLAGS   = -module -avoid-version
 
 if PLUGINS
 
@@ -33,6 +34,7 @@
 	relnot.la      \
 	spellchk.la    \
 	statenotify.la \
+	dashboard.la   \
 	timestamp.la
 
 autorecon_la_SOURCES   = autorecon.c
@@ -44,6 +46,7 @@
 spellchk_la_SOURCES    = spellchk.c
 statenotify_la_SOURCES = statenotify.c
 timestamp_la_SOURCES   = timestamp.c
+dashboard_la_SOURCES   = dashboard.c
 
 endif # PLUGINS
 
diff -u --recursive --exclude=CVS --new-file pristine/gaim/plugins/dashboard-frontend.c gaim/plugins/dashboard-frontend.c
--- pristine/gaim/plugins/dashboard-frontend.c	1969-12-31 19:00:00.000000000 -0500
+++ gaim/plugins/dashboard-frontend.c	2004-01-08 22:11:17.000000000 -0500
@@ -0,0 +1,443 @@
+#ifndef __DASHBOARD_FRONTEND_H__
+#define __DASHBOARD_FRONTEND_H__
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <glib.h>
+
+#if GLIB_CHECK_VERSION (2,0,0)
+#include <glib/giochannel.h>
+#endif
+
+#define DASHBOARD_PORT 5913
+#define NATMIN(a,b) ((a) < (b) ? (a) : (b))
+
+/*
+ * Open a connection to the dashboard.  We never block and at
+ * the first sign of a problem we bail.
+ */
+static int
+dashboard_connect_with_timeout (int  *fd,
+				long  timeout_usecs)
+{
+	struct sockaddr_in  sock;
+	struct timeval      timeout;
+	fd_set write_fds;
+
+	*fd = socket (PF_INET, SOCK_STREAM, 0);
+	if (*fd < 0) {
+		perror ("Dashboard: socket");
+		return 0;
+	}
+
+	/*
+	 * Set the socket to be non-blocking so that connect ()
+	 * doesn't block.
+	 */
+	if (fcntl (*fd, F_SETFL, O_NONBLOCK) < 0) {
+		perror ("Dashboard: setting O_NONBLOCK");
+
+		if (close(*fd) < 0)
+			perror ("Dashboard: closing socket (1)");
+		
+		return 0;
+	}
+
+	bzero ((char *) &sock, sizeof (sock));
+	sock.sin_family      = AF_INET;
+	sock.sin_port        = htons (DASHBOARD_PORT);
+	sock.sin_addr.s_addr = inet_addr ("127.0.0.1");
+
+	timeout.tv_sec = 0;
+	timeout.tv_usec = timeout_usecs;
+
+	while (1) {
+
+		/*
+		 * Try to connect.
+		 */
+		if (connect (*fd, (struct sockaddr *) &sock,
+			     sizeof (struct sockaddr_in)) < 0) {
+
+			if (errno != EAGAIN &&
+			    errno != EINPROGRESS) {
+				perror ("Dashboard: connect");
+
+				if (close(*fd) < 0)
+					perror ("Dashboard: closing socket (2)");
+
+				return 0;
+			}
+				
+		} else
+			return 1;
+
+		/*
+		 * We couldn't connect, so we select on the fd and
+		 * wait for the timer to run out, or for the fd to be
+		 * ready.
+		 */
+		FD_ZERO (&write_fds);
+		FD_SET (*fd, &write_fds);
+
+		while (select (getdtablesize (), NULL, &write_fds, NULL, &timeout) < 0) {
+			if (errno != EINTR) {
+				perror ("Dashboard: select");
+
+				if (close(*fd) < 0)
+					perror ("Dashboard: closing socket (3)");
+		
+				return 0;
+			}
+		}
+
+		if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
+			fprintf (stderr, "Dashboard: Connection timed out.\n");
+
+			if (close(*fd) < 0)
+				perror ("Dashboard: closing socket (4)");
+		
+			return 0;
+		}
+		
+	}
+
+	return 1;
+}
+
+typedef struct {
+	char *rawcluepacket;
+	int bytes_written;
+} CluepacketInfo;
+
+#if GLIB_CHECK_VERSION(2,0,0)
+
+static gboolean
+cluepacket_write_cb (GIOChannel   *channel,
+		     GIOCondition  cond,
+		     gpointer      user_data)
+{
+	CluepacketInfo *info = user_data;
+	GIOError err;
+	int total_bytes;
+
+	total_bytes = strlen (info->rawcluepacket);
+
+	do {
+		int b;
+
+		err = g_io_channel_write (channel,
+					  info->rawcluepacket + info->bytes_written,
+					  total_bytes - info->bytes_written,
+					  &b);
+		info->bytes_written += b;
+	} while (info->bytes_written < total_bytes && err == G_IO_ERROR_NONE);
+
+	if (err == G_IO_ERROR_NONE) {
+		/* We're all done sending */
+		fprintf (stderr, "Dashboard: Sent.\n");
+		goto cleanup;
+	}
+
+	if (err == G_IO_ERROR_AGAIN) {
+		/* Hand control back to the main loop */
+		return TRUE;
+	}
+
+	/* Otherwise... */
+	fprintf (stderr, "Dashboard: Error trying to send cluepacket.\n");
+
+cleanup:
+	g_io_channel_close (channel);
+	g_free (info->rawcluepacket);
+	g_free (info);
+
+	return FALSE;
+}
+
+static void
+dashboard_send_raw_cluepacket (const char *rawcluepacket)
+{
+	int fd;
+	GIOChannel *channel;
+	CluepacketInfo *info;
+
+	fprintf (stderr, "Dashboard: Sending cluepacket...\n");
+
+	/* Connect. */
+	if (! dashboard_connect_with_timeout (&fd, 200000))
+		return;
+
+	channel = g_io_channel_unix_new (fd);
+
+	info = g_new0 (CluepacketInfo, 1);
+	info->rawcluepacket = g_strdup (rawcluepacket);
+
+	g_io_add_watch (channel,
+			G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+			cluepacket_write_cb,
+			info);
+
+	g_io_channel_unref (channel);
+}
+
+#endif /* GLIB_CHECK_VERSION (2,0,0) */
+
+/*
+ * Sends a raw cluepacket to the dashboard.
+ */
+static void
+dashboard_send_raw_cluepacket_sync (const char *rawcluepacket)
+{
+	int                 fd;
+	int                 total_bytes;
+	int                 bytes_written;
+	const char         *p;
+	int                 eagain_count;
+
+	fprintf (stderr, "Dashboard: Sending cluepacket...\n");
+	fprintf (stderr, "Cluepacket: %s\n", rawcluepacket);
+
+	/* Connect. */
+	if (! dashboard_connect_with_timeout (&fd, 200000))
+		return;
+
+	/* Write out the cluepacket */
+	total_bytes = strlen (rawcluepacket);
+	bytes_written = 0;
+	p = rawcluepacket;
+	eagain_count = 0;
+	while (bytes_written < total_bytes) {
+		int b;
+
+		b = write (fd, p, total_bytes - bytes_written);
+		if (b < 0) {
+			fprintf (stderr, "Dashboard: Error writing: %s\n", strerror (errno));
+
+			if (errno != EAGAIN && errno != EWOULDBLOCK) {
+				close (fd);
+				return;
+			}
+
+			eagain_count ++;
+
+			if (eagain_count > 10) {
+				close (fd);
+				return;
+			}
+		}
+
+		bytes_written += b;
+		p += b;
+	}
+
+	close (fd);
+
+	fprintf (stderr, "Dashboard: Sent.\n");
+}
+
+#if !GLIB_CHECK_VERSION (2,0,0)
+static char *
+lame_xml_quote (const char *str)
+{
+	char       *retval;
+	const char *p;
+	char       *q;
+
+	if (str == NULL || strlen (str) == 0)
+		return g_strdup ("");
+
+	retval = g_new (char, strlen (str) * 3);
+
+	q = retval;
+	for (p = str; *p != '\0'; p ++) {
+		switch (*p) {
+
+		case '<':
+			*q ++ = '&';
+			*q ++ = 'l';
+			*q ++ = 't';
+			*q ++ = ';';
+			break;
+
+		case '>':
+			*q ++ = '&';
+			*q ++ = 'g';
+			*q ++ = 't';
+			*q ++ = ';';
+			break;
+			
+		case '&':
+			*q ++ = '&';
+			*q ++ = 'a';
+			*q ++ = 'm';
+			*q ++ = 'p';
+			*q ++ = ';';
+			break;
+		default:
+			*q ++ = *p;
+			break;
+		}
+	}
+
+	*q = '\0';
+
+	return retval;
+}
+#endif
+
+static char *
+dashboard_xml_quote (const char *str)
+{
+#if GLIB_CHECK_VERSION (2,0,0)
+	return g_markup_escape_text (str, strlen (str));
+#else
+	return lame_xml_quote (str);
+#endif
+}
+
+static char *
+dashboard_build_clue (const char *text,
+		      const char *type,
+		      int         relevance)
+{
+	char *text_xml;
+	char *clue;
+
+	if (text == NULL || strlen (text) == 0)
+		return g_strdup ("");
+
+	text_xml = dashboard_xml_quote (text);
+
+	clue = g_strdup_printf ("    <Clue Type=\"%s\" Relevance=\"%d\">%s</Clue>\n",
+				type, relevance, text_xml);
+
+	g_free (text_xml);
+
+	return clue;
+}
+
+static char *
+dashboard_build_cluepacket_from_cluelist (const char *frontend,
+					  gboolean    focused,
+					  const char *context,
+					  GList      *clues)
+{
+	char  *cluepacket;
+	char  *new_cluepacket;
+	GList *l;
+
+	g_return_val_if_fail (frontend != NULL, NULL);
+	g_return_val_if_fail (clues    != NULL, NULL);
+
+	cluepacket = g_strdup_printf (
+		"<CluePacket>\n"
+		"    <Frontend>%s</Frontend>\n"
+		"    <Context>%s</Context>\n"
+		"    <Focused>%s</Focused>\n",
+		frontend,
+		context,
+		focused ? "true" : "false");
+
+	for (l = clues; l != NULL; l = l->next) {
+		const char *clue = (const char *) l->data;
+
+		new_cluepacket = g_strconcat (cluepacket, clue, NULL);
+		g_free (cluepacket);
+
+		cluepacket = new_cluepacket;
+	}
+
+	new_cluepacket = g_strconcat (cluepacket, "</CluePacket>\n", NULL);
+	g_free (cluepacket);
+
+	cluepacket = new_cluepacket;
+
+	return cluepacket;
+}
+
+static char *
+dashboard_build_cluepacket_v (const char *frontend,
+			      gboolean    focused,
+			      const char *context,
+			      va_list     args)
+{
+	char    *cluep;
+	GList   *clue_list;
+	char    *retval;
+
+	g_return_val_if_fail (frontend != NULL, NULL);
+
+	cluep     = va_arg (args, char *);
+	clue_list = NULL;
+	while (cluep) {
+		clue_list = g_list_append (clue_list, cluep);
+		cluep = va_arg (args, char *);
+	}
+
+	retval = dashboard_build_cluepacket_from_cluelist (frontend, focused, context, clue_list);
+
+	g_list_free (clue_list);
+
+	return retval;
+}
+
+static char *
+dashboard_build_cluepacket (const char *frontend,
+			    gboolean    focused,
+			    const char *context,
+			    ...)
+{
+	char    *retval;
+	va_list  args;
+
+	g_return_val_if_fail (frontend != NULL, NULL);
+
+	va_start (args, context);
+
+	retval = dashboard_build_cluepacket_v (frontend, focused, context, args);
+
+	va_end (args);
+
+	return retval;
+}
+
+
+static char *
+dashboard_build_cluepacket_then_free_clues (const char *frontend,
+					    gboolean    focused,
+					    const char *context,
+					    ...)
+{
+	char    *retval;
+	char    *cluep;
+	va_list  args;
+
+	g_return_val_if_fail (frontend != NULL, NULL);
+
+	/* Build the cluepacket */
+	va_start (args, context);
+	retval = dashboard_build_cluepacket_v (frontend, focused, context, args);
+	va_end (args);
+
+	/* Free the clues */
+	va_start (args, context);
+	cluep = va_arg (args, char *);
+	while (cluep) {
+		g_free (cluep);
+		cluep = va_arg (args, char *);
+	}
+
+	va_end (args);
+
+	return retval;
+}
+
+#endif /* ! __DASHBOARD_FRONTEND_H__ */
diff -u --recursive --exclude=CVS --new-file pristine/gaim/plugins/dashboard.c gaim/plugins/dashboard.c
--- pristine/gaim/plugins/dashboard.c	1969-12-31 19:00:00.000000000 -0500
+++ gaim/plugins/dashboard.c	2004-01-12 23:48:25.086900066 -0500
@@ -0,0 +1,562 @@
+
+#include "internal.h"
+#include "gtkinternal.h"
+#include "conversation.h"
+#include "signals.h"
+#include "gtkconv.h"
+#include "gtkimhtml.h"
+#include "gtkplugin.h"
+#include "debug.h"
+#include "prefs.h"
+
+#include "dashboard-frontend.c"
+
+#define PLUGIN_ID "dashboard"
+
+
+
+static gboolean
+gaim_gtkconv_is_focused (GaimGtkConversation *gtkconv)
+{
+	if (gtkconv == NULL)	return FALSE;
+	if (GTK_WIDGET_HAS_FOCUS (gtkconv->imhtml) ||
+	    GTK_WIDGET_HAS_FOCUS (gtkconv->entry))
+		return TRUE;
+
+	return FALSE;
+}
+
+static char *
+strip_uninteresting (char *text)
+{
+	char *new;
+	char *srcp, *dstp;
+	int   first_char;
+	int   copy;
+	int   in_parens;
+
+	new = g_strdup (text);
+
+	first_char = TRUE;
+	copy       = TRUE;
+	in_parens  = FALSE;
+	dstp       = new;
+
+	for (srcp = text; *srcp != '\0'; srcp ++) {
+		if (first_char && *srcp == '(') {
+			copy       = FALSE;
+			first_char = FALSE;
+			in_parens  = TRUE;
+		}
+
+		if (*srcp == ')')
+			in_parens = FALSE;
+
+		if (*srcp == '\n')
+			first_char = TRUE;
+
+		if (copy) {
+			*dstp = *srcp;
+			dstp ++;
+		}
+
+		if (*srcp == ':' && ! in_parens && ! first_char && ! copy)
+			copy = TRUE;
+
+	}
+
+	*dstp = '\0';
+
+	g_free (text);
+	return new;
+}
+
+/*
+ * Generate a clue out of a range of recent lines in an IM
+ * conversation.
+ */
+static char *
+gaim_conv_gen_chunkclue (GaimConversation *conv,
+			 int               start_num_lines_back,
+			 int               end_num_lines_back,
+			 int               relevance)
+{
+	GaimGtkConversation *gtkconv;
+	GtkTextIter  start_iter;
+	GtkTextIter  end_iter;
+	char        *convchunk;
+	int          num_lines;
+	char        *clue;
+
+	gtkconv = GAIM_GTK_CONVERSATION (conv);
+
+	num_lines = gtk_text_buffer_get_line_count (GTK_IMHTML (gtkconv->imhtml)->text_buffer);
+
+	start_num_lines_back = NATMIN (num_lines, start_num_lines_back);
+	end_num_lines_back   = NATMIN (num_lines, end_num_lines_back);
+
+	gtk_text_buffer_get_end_iter (GTK_IMHTML (gtkconv->imhtml)->text_buffer, &end_iter);
+	gtk_text_buffer_get_end_iter (GTK_IMHTML (gtkconv->imhtml)->text_buffer, &start_iter);
+
+	gtk_text_iter_backward_lines (&start_iter, start_num_lines_back);
+	gtk_text_iter_backward_lines (&end_iter, end_num_lines_back);
+
+	convchunk = gtk_text_buffer_get_text (GTK_IMHTML (gtkconv->imhtml)->text_buffer,
+					      &start_iter, &end_iter, FALSE);
+
+	convchunk = strip_uninteresting (convchunk);
+
+	if (convchunk == NULL || strlen (convchunk) == 0) {
+		g_free (convchunk);
+		return g_strdup ("");
+	}
+
+	clue = dashboard_build_clue (convchunk, "textblock", relevance);
+
+	g_free (convchunk);
+
+	return clue;
+}
+
+static char *
+gaim_account_get_imname_cluetype (GaimAccount *account)
+{
+	GaimProtocol proto;
+
+	proto = gaim_account_get_protocol (account);
+
+	switch (proto) {
+		case GAIM_PROTO_TOC:      return "aim_name";     break;
+		case GAIM_PROTO_OSCAR:    return "aim_name";     break;
+		case GAIM_PROTO_YAHOO:    return "yahoo_name";   break;
+		case GAIM_PROTO_ICQ:      return "icq_name";     break;
+		case GAIM_PROTO_MSN:      return "msn_name";     break;
+		case GAIM_PROTO_IRC:      return "irc_name";     break;
+		case GAIM_PROTO_JABBER:   return "jabber_name";  break;
+		case GAIM_PROTO_NAPSTER:  return "napster_name"; break;
+		case GAIM_PROTO_ZEPHYR:   return "zephyr_name";  break;
+		case GAIM_PROTO_GADUGADU: return "gg_name";      break;
+		case GAIM_PROTO_MOO:      return "moo_name";     break;
+		case GAIM_PROTO_TREPIA:   return "trepia_name";  break;
+
+		default:
+			break;
+	}
+
+	return "";
+}
+
+static char *
+gaim_conv_gen_buddy_clues (GaimConversation *conv,
+			   GaimAccount      *account,
+			   const char       *imname)
+{
+	GaimBuddy        *b;
+	const char          *name        = NULL;
+	const char          *proto       = NULL;
+	char                *imname_clue;
+	char                *name_clue;
+	char                *clues;
+
+	g_return_val_if_fail (account != NULL, NULL);
+	g_return_val_if_fail (imname != NULL, NULL);
+
+	/* Map the protocol name to a clue type. */
+	proto = gaim_account_get_imname_cluetype (account);
+
+	/* Get the buddy alias */
+	if ((b = gaim_find_buddy (account, imname)))
+		name = gaim_get_buddy_alias_only (b);
+	fprintf(stderr,"|%s|\n",name);
+/*	if (strcmp (name, imname) == 0)
+		name = NULL;*/
+	/* Build the clues */
+	if (name != NULL)
+	{
+		 fprintf(stderr,"alias\n");
+		 imname_clue = dashboard_build_clue (imname, proto,    5);
+		 name_clue   = dashboard_build_clue (name,   "name",   5);
+		 clues = g_strdup_printf ("%s %s", imname_clue, name_clue);
+	}
+	else
+	{
+		 fprintf(stderr,"no alias\n");
+		 imname_clue = dashboard_build_clue (imname, proto,    5);
+		 clues = g_strdup_printf( "%s", imname_clue);
+	}
+	g_free (imname_clue);
+/*	g_free (name_clue);*/
+
+	return clues;
+}
+
+/*
+ * Generates and sends a cluepacket for an IM conversation.
+ */
+static void
+gaim_conv_send_cluepacket (GaimConversation *conv)
+{
+	GaimGtkConversation *gtkconv;
+	GaimAccount         *account;
+	const char          *imname;
+	char                 context[600];
+	char                *cluepacket;
+
+	if (conv == NULL)
+		return;
+
+	gtkconv = GAIM_GTK_CONVERSATION (conv);
+
+	fprintf (stderr, "Gaim/Dashboard: Building cluepacket...\n");
+
+	/* Get the imname and name of the buddy we're talking to. */
+	account = gaim_conversation_get_account (conv);
+	g_return_if_fail (account != NULL);
+
+	imname = gaim_conversation_get_name (conv);
+	g_return_if_fail (imname != NULL);
+
+	/* Write the context */
+	snprintf (context, sizeof (context), "IM with %s", imname);
+
+	/* Build a cluepacket. */
+	cluepacket = dashboard_build_cluepacket_then_free_clues (
+		"Gaim",
+		gaim_gtkconv_is_focused (gtkconv),
+		context,
+		gaim_conv_gen_buddy_clues (conv, account, imname),
+		gaim_conv_gen_chunkclue   (conv, 20,   0,    10),
+//		gaim_conv_gen_chunkclue   (conv, 10,  5,     8),
+//		gaim_conv_gen_chunkclue   (conv, 15, 10,     6),
+//		gaim_conv_gen_chunkclue   (conv, 20, 15,     4),
+		NULL);
+
+	/* Send it off. */
+	dashboard_send_raw_cluepacket (cluepacket);
+
+	g_free (cluepacket);
+}
+
+gboolean
+conv_focus_in_cb (GtkWidget     *widget,
+		  GdkEventFocus *event,
+		  gpointer       user_data)
+{
+	GaimConversation *conv = NULL;
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus"))
+		return FALSE;
+	conv = user_data;
+	if (conv)
+		gaim_conv_send_cluepacket (conv);
+
+	return TRUE;
+}
+
+static int
+attach_signals(GaimConversation *conv)
+{
+	/* TODO I can't seem to get passing a GaimConversation to a callback to work
+	 * correctly, so in the interest of not g_object_set_data'ing on multiple
+	 * widgets, I'm going to just _set_data on ->entry and _connect_swapped the
+	 * other signals, if I ever get passing the GaimConversation to work I'll
+	 * stop this ugliness */
+	GaimGtkConversation *gtkconv = NULL;
+	GSList *imhtml_ids = NULL, *entry_ids = NULL;
+	guint id;
+
+	gtkconv = GAIM_GTK_CONVERSATION(conv);
+
+
+	if (gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus")) {
+		id = g_signal_connect (G_OBJECT (gtkconv->entry),"focus-in-event",G_CALLBACK (conv_focus_in_cb),conv);
+		imhtml_ids = g_slist_append(imhtml_ids, GUINT_TO_POINTER(id));
+		id = g_signal_connect (G_OBJECT (gtkconv->imhtml),"focus-in-event",G_CALLBACK (conv_focus_in_cb),conv);
+		entry_ids = g_slist_append(entry_ids, GUINT_TO_POINTER(id));
+	}
+
+
+
+	gaim_conversation_set_data(conv, "notify-imhtml-signals", imhtml_ids);
+	gaim_conversation_set_data(conv, "notify-entry-signals", entry_ids);
+
+	return 0;
+}
+
+static void
+detach_signals(GaimConversation *conv)
+{
+	GaimGtkConversation *gtkconv = NULL;
+	GSList *ids = NULL;
+
+	gtkconv = GAIM_GTK_CONVERSATION(conv);
+
+	ids = gaim_conversation_get_data(conv, "notify-imhtml-signals");
+	for (; ids != NULL; ids = ids->next)
+		g_signal_handler_disconnect(gtkconv->imhtml, GPOINTER_TO_INT(ids->data));
+
+	ids = gaim_conversation_get_data(conv, "notify-entry-signals");
+	for (; ids != NULL; ids = ids->next)
+		g_signal_handler_disconnect(gtkconv->entry, GPOINTER_TO_INT(ids->data));
+
+
+	gaim_conversation_set_data(conv, "notify-imhtml-signals", NULL);
+	gaim_conversation_set_data(conv, "notify-entry-signals", NULL);
+}
+
+
+static gboolean
+chat_recv_im(GaimAccount *account, char *who, char *text, int id, void *m)
+{
+	GaimConversation *c = NULL;
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_recv"))
+		return FALSE;
+	c = gaim_find_chat (gaim_account_get_connection(account),id);
+	if (c == NULL)	return FALSE;
+	gaim_conv_send_cluepacket (c);
+	return FALSE;
+}
+
+static void
+chat_sent_im (GaimAccount *account, char *text, int id, void *m)
+
+{
+	GaimConversation *c = NULL;
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_sent"))
+		return;
+	c = gaim_find_chat(gaim_account_get_connection(account), id);
+	if (c == NULL)	return;
+	gaim_conv_send_cluepacket (c);
+}
+
+static gboolean
+im_recv_im(GaimAccount *account, char *who, char *what, int *flags, void *m)
+
+{
+	GaimConversation *c = NULL;
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/im_recv"))
+		return FALSE;
+	c = gaim_find_conversation_with_account (who,account);
+	if (c == NULL)	return FALSE;
+	gaim_conv_send_cluepacket (c);
+
+	return FALSE;
+}
+
+static void
+im_sent_im(GaimAccount *account, char *who, void *m)
+{
+	GaimConversation *c = NULL;
+	if(!gaim_prefs_get_bool("/plugins/gtk/dashboard/im_sent"))
+		return;
+	c = gaim_find_conversation_with_account (who,account);
+	if (c == NULL)	return;
+	gaim_conv_send_cluepacket (c);
+}
+
+
+
+
+void
+new_conv(GaimConversation *conv)
+{
+	
+	if (gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus"))
+		attach_signals(conv);
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/new_conv"))
+		return;
+
+	
+	gaim_conv_send_cluepacket (conv);
+	fprintf (stderr, "sent cluepacket\n");
+}
+/*
+void
+conv_switch (GaimConversation *old_conv,GaimConversation *new_conv)
+{
+	GaimGtkConversation *gtkconv = NULL;
+	fprintf (stderr, "conv_switch\n");
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_switch"))
+		return;
+
+	gtkconv = GAIM_GTK_CONVERSATION(new_conv);
+
+
+	if (new_conv == NULL)
+		return;
+
+	if (gtkconv == NULL)	return;
+		gaim_conv_send_cluepacket (new_conv);
+}
+*/
+void
+chat_join (GaimConversation *conv)
+{
+	if (conv == NULL)	return;
+	if (gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus"))
+		attach_signals(conv);
+	if (!gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_join"))	return;
+	gaim_conv_send_cluepacket (conv);
+}
+
+static void
+type_toggle_cb(GtkWidget *widget, gpointer event)
+{
+	gchar str[40] = "/plugins/gtk/dashboard/";
+	gboolean on = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+	GList *convs = gaim_get_conversations();
+	GaimConversation *conv;
+
+	strcat(str, event);
+	gaim_prefs_set_bool(str,on);
+
+	if (strcmp(event,"conv_focus") == 0)
+	{
+		while (convs)
+		{
+			conv = (GaimConversation *)convs->data;
+			if (on)	attach_signals(conv);
+			else	detach_signals(conv);
+			convs = convs->next;
+		}
+	}
+
+	if (on)	fprintf(stderr,"T:  %s\n",event);
+	else	fprintf(stderr,"F:  %s\n",event);
+	
+	if (gaim_prefs_get_bool(str))
+		printf("good:  %s\n",str);
+	else
+		printf("bad:  %s\n",str);
+}
+
+static GtkWidget *
+get_config_frame(GaimPlugin *plugin)
+{
+	GtkWidget *vbox2  = NULL;
+	GtkWidget *vbox1  = NULL;
+	GtkWidget *frame = NULL;
+	GtkWidget *toggle = NULL;
+
+
+	vbox1 = gtk_vbox_new(FALSE, 18);
+	gtk_container_set_border_width(GTK_CONTAINER (vbox1), 12);
+	
+	frame = gaim_gtk_make_frame(vbox1, _("Notify Dashboard upon following events:"));
+	vbox2 = gtk_vbox_new(FALSE,5);
+	gtk_container_add(GTK_CONTAINER(frame),vbox2);
+	
+	toggle = gtk_check_button_new_with_mnemonic(_("_Received IM"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/im_recv"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "im_recv");
+
+	toggle = gtk_check_button_new_with_mnemonic(_("R_eceived Chat"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_recv"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "chat_recv");
+
+	toggle = gtk_check_button_new_with_mnemonic(_("_Sent IM"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/im_sent"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "im_sent");
+
+	toggle = gtk_check_button_new_with_mnemonic(_("S_ent Chat"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_sent"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "chat_sent");
+
+	toggle = gtk_check_button_new_with_mnemonic(_("_Conversation Created"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/new_conv"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "new_conv");
+
+	toggle = gtk_check_button_new_with_mnemonic(_("C_hat Joined"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/chat_join"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "chat_join");
+
+/*	toggle = gtk_check_button_new_with_mnemonic(_("C_onversation Switched"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_switch"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "conv_switch");*/
+
+	toggle = gtk_check_button_new_with_mnemonic(_("Conversation _Window Receives Click"));
+	gtk_box_pack_start(GTK_BOX(vbox2),toggle,FALSE,FALSE,0);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus"));
+	g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(type_toggle_cb), "conv_focus");
+
+	gtk_widget_show_all(vbox1);
+	return vbox1;
+}
+static gboolean
+plugin_load (GaimPlugin *plugin)
+{
+	void *conv_handle = gaim_conversations_get_handle();
+	GList *convs = gaim_get_conversations();
+	GaimConversation *conv;
+
+	gaim_signal_connect (conv_handle, "received-im-msg", plugin, GAIM_CALLBACK(im_recv_im), NULL);
+	gaim_signal_connect (conv_handle, "received-chat-msg", plugin, GAIM_CALLBACK(chat_recv_im), NULL);
+	gaim_signal_connect (conv_handle, "sent-im-msg", plugin, GAIM_CALLBACK(im_sent_im), NULL);
+	gaim_signal_connect (conv_handle, "sent-chat-msg", plugin, GAIM_CALLBACK(chat_sent_im), NULL);
+	gaim_signal_connect (conv_handle, "conversation-created", plugin, GAIM_CALLBACK(new_conv), NULL);
+	gaim_signal_connect (conv_handle, "chat-joined", plugin, GAIM_CALLBACK(chat_join), NULL);
+/*	gaim_signal_connect (conv_handle, "conversation-switched", plugin, GAIM_CALLBACK(conv_switch), NULL);*/
+	if (gaim_prefs_get_bool("/plugins/gtk/dashboard/conv_focus"))
+	{
+		while (convs)
+		{
+			conv = (GaimConversation *)convs->data;
+			attach_signals(conv);
+			convs = convs->next;
+		}
+	}
+	return TRUE;
+}
+
+static GaimGtkPluginUiInfo ui_info =
+{
+	get_config_frame
+};
+
+static GaimPluginInfo info =
+{
+	GAIM_PLUGIN_API_VERSION,                          /**< api_version    */
+	GAIM_PLUGIN_STANDARD,                             /**< type           */
+	GAIM_GTK_PLUGIN_TYPE,                             /**< ui_requirement */
+	0,                                                /**< flags          */
+	NULL,                                             /**< dependencies   */
+	GAIM_PRIORITY_DEFAULT,                            /**< priority       */
+	PLUGIN_ID,                                        /**< id             */
+	N_ ("Dashboard"),                                 /**< name           */
+	VERSION,                                          /**< version        */
+	N_ ("This plugin sends cluepackets to Dashboard, an 'association engine'.  See Dashboard website for more information."),                                     /**< summary        */
+	N_ ("This plugin sends cluepackets to Dashboard, an 'association engine'.  See Dashboard website for more information."),                                    /**< description    */
+	"Nat Friedman <nat nat org>, Joe Gasiorek <gasiorek yakko cs wmich edu>",                     /**< author         */
+	"http://www.nat.org/dashboard";,                                          /**< homepage       */
+	plugin_load,                                      /**< load           */
+	NULL,                                             /**< unload         */
+	NULL,                                             /**< destroy        */
+	&ui_info,                                             /**< ui_info        */
+	NULL,                                              /**< extra_info     */
+       NULL,
+       NULL
+};
+
+static void
+init_plugin (GaimPlugin *plugin)
+{
+	gaim_prefs_add_none("/plugins/gtk");
+	gaim_prefs_add_none("/plugins/gtk/dashboard");
+
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/im_recv",TRUE);
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/chat_recv",TRUE);
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/im_sent",TRUE);
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/chat_sent",TRUE);
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/new_conv",TRUE);
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/chat_join",TRUE);
+/*	gaim_prefs_add_bool("/plugins/gtk/dashboard/conv_switch",TRUE);*/
+	gaim_prefs_add_bool("/plugins/gtk/dashboard/conv_focus",TRUE);
+}
+
+GAIM_INIT_PLUGIN (dashboard, init_plugin, info);


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