changeset 13012:e3b9c6c7bcf6

[gaim-migrate @ 15365] Don't create duplicate transient statuses. So like, if you switch between "Available" and "Away" a bunch of times and use the same message everywhere, you'll only have one of each in your list of recent statuses committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 23 Jan 2006 04:54:37 +0000
parents 5e14039d0415
children 8fe78402c010
files src/gtkstatusbox.c src/savedstatuses.c src/savedstatuses.h
diffstat 3 files changed, 44 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkstatusbox.c	Mon Jan 23 04:25:04 2006 +0000
+++ b/src/gtkstatusbox.c	Mon Jan 23 04:54:37 2006 +0000
@@ -1067,9 +1067,17 @@
 
 		if (changed)
 		{
-			/* Create a new transient saved status */
-			saved_status = gaim_savedstatus_new(NULL, GPOINTER_TO_INT(data));
-			gaim_savedstatus_set_message(saved_status, message);
+			/* If we've used this type+message before, lookup the transient status */
+			saved_status = gaim_savedstatus_find_by_type_and_message(
+										GPOINTER_TO_INT(data), message);
+
+
+			/* If this type+message is unique then create a new transient saved status */
+			if (saved_status == NULL)
+			{
+				saved_status = gaim_savedstatus_new(NULL, GPOINTER_TO_INT(data));
+				gaim_savedstatus_set_message(saved_status, message);
+			}
 
 			/* Set the status for each account */
 			gaim_savedstatus_activate(saved_status);
--- a/src/savedstatuses.c	Mon Jan 23 04:25:04 2006 +0000
+++ b/src/savedstatuses.c	Mon Jan 23 04:54:37 2006 +0000
@@ -798,6 +798,27 @@
 	return NULL;
 }
 
+GaimSavedStatus *
+gaim_savedstatus_find_by_type_and_message(GaimStatusPrimitive type,
+										  const char *message)
+{
+	GList *iter;
+	GaimSavedStatus *status;
+
+	for (iter = saved_statuses; iter != NULL; iter = iter->next)
+	{
+		status = (GaimSavedStatus *)iter->data;
+		if ((status->type == type) &&
+			(((status->message == NULL) && (message == NULL)) ||
+			((status->message != NULL) && (message != NULL) && !strcmp(status->message, message))))
+		{
+			return status;
+		}
+	}
+
+	return NULL;
+}
+
 gboolean
 gaim_savedstatus_is_transient(const GaimSavedStatus *saved_status)
 {
--- a/src/savedstatuses.h	Mon Jan 23 04:25:04 2006 +0000
+++ b/src/savedstatuses.h	Mon Jan 23 04:54:37 2006 +0000
@@ -208,6 +208,18 @@
 GaimSavedStatus *gaim_savedstatus_find_by_creation_time(time_t creation_time);
 
 /**
+ * Finds a saved status with the specified primitive and message.
+ *
+ * @param type The GaimStatusPrimitive for the status you're trying
+ *        to find.
+ * @param message The message for the status you're trying
+ *        to find.
+ *
+ * @return The saved status if found, or NULL.
+ */
+GaimSavedStatus *gaim_savedstatus_find_by_type_and_message(GaimStatusPrimitive type, const char *message);
+
+/**
  * Determines if a given saved status is "transient."
  * A transient saved status is one that was not
  * explicitly added by the user.  Transient statuses