changeset 9191:06b28fb24300

[gaim-migrate @ 9986] " This patch was inspired by Robert Story's previous timestamp patch (#944943). That was rejected because of a timing inconsistency issue mentioned by Faceprint. This patch disables timestamps in a given conversation when no messages have been displayed since the last timestamp. When a new message is about to be displayed in a disabled timestamp conversation, a timestamp is inserted first to maintain timing consistency. Then the timestamp display is reenabled and the IM message is printed. This patch also handles a bug in the original timestamp plugin. Previously, when the timestamp interval was modified in the preferences, no current open conversations are affected. I have modified it so that all open conversations use the new interval. I would have sent this as a separate patch, but this is my first patch and didn't want to mess it up :)." --Eddie Sohn i liked the original patch and was somewhat disappointed that it didn't get fixed to address Nathan's concern, so i'm happy to merge this one in. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 06 Jun 2004 02:08:57 +0000
parents 9e3289499977
children 5655dcd94d0f
files COPYRIGHT plugins/timestamp.c src/gtkpounce.c
diffstat 3 files changed, 145 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Sun Jun 06 02:07:59 2004 +0000
+++ b/COPYRIGHT	Sun Jun 06 02:08:57 2004 +0000
@@ -126,6 +126,7 @@
 Alex Smith
 David Smock
 Phil Snowberger
+Eddie (tr1sk) Sohn
 Mark Spencer <markster@marko.net>
 Lex Spoon
 Kevin Stange
--- a/plugins/timestamp.c	Sun Jun 06 02:07:59 2004 +0000
+++ b/plugins/timestamp.c	Sun Jun 06 02:08:57 2004 +0000
@@ -38,34 +38,121 @@
 /* Set the default to 5 minutes. */
 static int interval = 5 * 60 * 1000;
 
-static GSList *timestamp_timeouts;
+static GSList *timestamp_timeouts = NULL;
 
 static gboolean do_timestamp (gpointer data)
 {
 	GaimConversation *c = (GaimConversation *)data;
 	char *buf;
 	char mdate[6];
+	int is_conversation_active;
 	time_t tim = time(NULL);
-
+	
 	if (!g_list_find(gaim_get_conversations(), c))
 		return FALSE;
 
-	strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
-	buf = g_strdup_printf("            %s", mdate);
-	gaim_conversation_write(c, NULL, buf, GAIM_MESSAGE_NO_LOG, tim);
-	g_free(buf);
+	/* is_conversation_active is true if an im has been displayed since the last timestamp */
+	is_conversation_active = GPOINTER_TO_INT(gaim_conversation_get_data(c, "timestamp-conv-active"));
+	
+	if (is_conversation_active){
+		gaim_conversation_set_data(c, "timestamp-conv-active", GINT_TO_POINTER(FALSE));
+		strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
+		buf = g_strdup_printf("            %s", mdate);
+		gaim_conversation_write(c, NULL, buf, GAIM_MESSAGE_NO_LOG, tim);
+		g_free(buf);
+	}
+	else
+		gaim_conversation_set_data(c, "timestamp-enabled", GINT_TO_POINTER(FALSE));
+	
 	return TRUE;
 }
 
+
+static gboolean
+timestamp_displaying_conv_msg(GaimAccount *account, GaimConversation *conv,
+		     char **buffer, void *data)
+{
+	int is_timestamp_enabled;
+	
+	if (!g_list_find(gaim_get_conversations(), conv))
+		return FALSE;
+	
+	/* set to true, since there has been an im since the last timestamp */
+	gaim_conversation_set_data(conv, "timestamp-conv-active", GINT_TO_POINTER(TRUE));
+	
+	is_timestamp_enabled = GPOINTER_TO_INT(gaim_conversation_get_data(conv, "timestamp-enabled"));
+	
+	if (!is_timestamp_enabled){
+		gaim_conversation_set_data(conv, "timestamp-enabled", GINT_TO_POINTER(TRUE));
+		do_timestamp((gpointer)conv);
+	}
+	
+	return FALSE;
+}
+
+static gboolean
+timestamp_receiving_msg(GaimAccount *account, char **sender, char **buffer,
+				   int *flags, void *data)
+{
+	GaimConversation* conv;
+	
+	conv = gaim_find_conversation_with_account(*sender, account);
+	if (conv != NULL)
+		return timestamp_displaying_conv_msg(account, conv, buffer, data);
+	return FALSE;
+}
+
+
 static void timestamp_new_convo(GaimConversation *conv)
 {
-	do_timestamp(conv);
+	if (!g_list_find(gaim_get_conversations(), conv))
+		return;
+	
+	/*
+	This if statement stops conversations that have already been initialized for timestamps
+	from being reinitialized.  This prevents every active conversation from immediately being spammed
+	with a new timestamp when the user modifies the timer interval.
+	*/
+	if (!gaim_conversation_get_data(conv, "timestamp-initialized")){
+		gaim_conversation_set_data(conv, "timestamp-initialized", GINT_TO_POINTER(TRUE));
+		gaim_conversation_set_data(conv, "timestamp-enabled", GINT_TO_POINTER(TRUE));
+		gaim_conversation_set_data(conv, "timestamp-conv-active", GINT_TO_POINTER(TRUE));
+		do_timestamp(conv);
+	}
 
 	timestamp_timeouts = g_slist_append(timestamp_timeouts,
 			GINT_TO_POINTER(g_timeout_add(interval, do_timestamp, conv)));
+}
 
+
+static void destroy_timer_list()
+{
+	GSList *to;
+
+	for (to = timestamp_timeouts; to != NULL; to = to->next)
+		g_source_remove(GPOINTER_TO_INT(to->data));
+
+	g_slist_free(timestamp_timeouts);
+	
+	timestamp_timeouts = NULL;
 }
 
+static void init_timer_list()
+{
+	GList *cnvs;
+	GaimConversation *c;
+	
+	if (timestamp_timeouts != NULL)
+		destroy_timer_list();
+	
+	for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
+		c = cnvs->data;
+		timestamp_new_convo(c);
+	}
+}
+
+
+
 static void set_timestamp(GtkWidget *button, GtkWidget *spinner) {
 	int tm;
 
@@ -78,6 +165,9 @@
 
 	interval = tm;
 	gaim_prefs_set_int("/plugins/gtk/timestamp/interval", interval);
+	
+	destroy_timer_list();
+	init_timer_list();
 }
 
 static GtkWidget *
@@ -124,34 +214,39 @@
 static gboolean
 plugin_load(GaimPlugin *plugin)
 {
-	GList *cnvs;
-	GaimConversation *c;
+	void *conv_handle = gaim_conversations_get_handle();
+	
+	init_timer_list();
 
-	timestamp_timeouts = NULL;
-	for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
-		c = cnvs->data;
-		timestamp_new_convo(c);
-	}
+	gaim_signal_connect(conv_handle, "conversation-created",
+					plugin, GAIM_CALLBACK(timestamp_new_convo), NULL);
 
-	gaim_signal_connect(gaim_conversations_get_handle(),
-						"conversation-created",
-						plugin, GAIM_CALLBACK(timestamp_new_convo), NULL);
+	//record IM display events for each conversation
+	gaim_signal_connect(conv_handle, "receiving-im-msg",
+					plugin, GAIM_CALLBACK(timestamp_receiving_msg), NULL);
+	gaim_signal_connect(conv_handle, "displaying-im-msg",
+					plugin, GAIM_CALLBACK(timestamp_displaying_conv_msg), NULL);
 
 	interval = gaim_prefs_get_int("/plugins/gtk/timestamp/interval");
 
 	return TRUE;
 }
 
+
+
 static gboolean
 plugin_unload(GaimPlugin *plugin)
 {
-	GSList *to;
+	void *conv_handle = gaim_conversations_get_handle();
 
-	for (to = timestamp_timeouts; to != NULL; to = to->next)
-		g_source_remove(GPOINTER_TO_INT(to->data));
-
-	g_slist_free(timestamp_timeouts);
-
+	gaim_signal_disconnect(conv_handle, "conversation-created",
+					plugin, GAIM_CALLBACK(timestamp_new_convo));
+	gaim_signal_disconnect(conv_handle, "receiving-im-msg",
+					plugin, GAIM_CALLBACK(timestamp_receiving_msg));
+	gaim_signal_disconnect(conv_handle, "displaying-im-msg",
+					plugin, GAIM_CALLBACK(timestamp_displaying_conv_msg));
+	
+	destroy_timer_list();
 	return TRUE;
 }
 
--- a/src/gtkpounce.c	Sun Jun 06 02:07:59 2004 +0000
+++ b/src/gtkpounce.c	Sun Jun 06 02:08:57 2004 +0000
@@ -879,9 +879,11 @@
 	GaimConversation *conv;
 	GaimAccount *account;
 	GaimBuddy *buddy;
+	GaimPlugin *proto;
 	const char *pouncee;
 	const char *alias;
-
+	const char *proto_id;
+	
 	pouncee = gaim_pounce_get_pouncee(pounce);
 	account = gaim_pounce_get_pouncer(pounce);
 
@@ -889,6 +891,10 @@
 
 	alias = gaim_get_buddy_alias(buddy);
 
+	/*find the protocol id for the window title and/or message*/
+	proto = gaim_find_prpl(gaim_account_get_protocol_id(account));
+	proto_id = proto->info->name;
+
 	if (gaim_pounce_action_is_enabled(pounce, "open-window")) {
 		conv = gaim_find_conversation_with_account(pouncee, account);
 
@@ -899,19 +905,28 @@
 	if (gaim_pounce_action_is_enabled(pounce, "popup-notify")) {
 		char tmp[1024];
 
+		/*Here we place the protocol name in the pounce dialog to lessen confusion about what
+		  protocol a pounce is for*/
 		g_snprintf(tmp, sizeof(tmp),
-				   (events & GAIM_POUNCE_TYPING) ? _("%s has started typing to you") :
-				   (events & GAIM_POUNCE_SIGNON) ? _("%s has signed on") :
-				   (events & GAIM_POUNCE_IDLE_RETURN) ? _("%s has returned from being idle") :
-				   (events & GAIM_POUNCE_AWAY_RETURN) ? _("%s has returned from being away") :
-				   (events & GAIM_POUNCE_TYPING_STOPPED) ? _("%s has stopped typing to you") :
-				   (events & GAIM_POUNCE_SIGNOFF) ? _("%s has signed off") :
-				   (events & GAIM_POUNCE_IDLE) ? _("%s has become idle") :
-				   (events & GAIM_POUNCE_AWAY) ? _("%s has gone away.") :
+				   (events & GAIM_POUNCE_TYPING) ? _("%s has started typing to you (%s)") :
+				   (events & GAIM_POUNCE_SIGNON) ? _("%s has signed on (%s)") :
+				   (events & GAIM_POUNCE_IDLE_RETURN) ? _("%s has returned from being idle (%s)") :
+				   (events & GAIM_POUNCE_AWAY_RETURN) ? _("%s has returned from being away (%s)") :
+				   (events & GAIM_POUNCE_TYPING_STOPPED) ? _("%s has stopped typing to you %s") :
+				   (events & GAIM_POUNCE_SIGNOFF) ? _("%s has signed off (%s)") :
+				   (events & GAIM_POUNCE_IDLE) ? _("%s has become idle (%s)") :
+				   (events & GAIM_POUNCE_AWAY) ? _("%s has gone away. (%s)") :
 				   _("Unknown pounce event. Please report this!"),
-				   alias);
+				   alias,proto_id);
 
-		gaim_notify_info(NULL, NULL, tmp, (char*)gaim_date_full());
+		/*Ok here is where I change the second argument, title,
+		  from NULL to the account name if that's all we have
+		  or the account alias if we have that*/
+		if(gaim_account_get_alias(account)) {
+		  gaim_notify_info(NULL, gaim_account_get_alias(account), tmp, (char*)gaim_date_full());
+		} else {
+		  gaim_notify_info(NULL, gaim_account_get_username(account), tmp, (char*)gaim_date_full());		 
+		}
 	}
 
 	if (gaim_pounce_action_is_enabled(pounce, "send-message")) {