changeset 10204:393f85d9f8dd

[gaim-migrate @ 11325] I moved some code from account.c to status.c. It's better there. This shouldn't hurt anything. In other news, the status API makes me hot. What makes you hot? Something that you want but you haven't got MartinFowlerSaysWhat? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 19 Nov 2004 03:08:27 +0000
parents 7ff9b8b22e7d
children 35eae887271a
files src/account.c src/status.c src/status.h
diffstat 3 files changed, 118 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Thu Nov 18 17:05:40 2004 +0000
+++ b/src/account.c	Fri Nov 19 03:08:27 2004 +0000
@@ -553,11 +553,7 @@
 						gboolean active, ...)
 {
 	GaimStatus *status;
-	gboolean changed = FALSE;
 	va_list args;
-	const char *id, *string_data;
-	int int_data;
-	gboolean boolean_data;
 
 	g_return_if_fail(account   != NULL);
 	g_return_if_fail(status_id != NULL);
@@ -573,62 +569,9 @@
 		return;
 	}
 
-	if (!active && gaim_status_is_exclusive(status))
-	{
-		gaim_debug(GAIM_DEBUG_ERROR, "accounts",
-				   "Cannot deactivate an exclusive status.\n");
-		return;
-	}
-
-	if (gaim_status_is_active(status) != active)
-		changed = TRUE;
-
-	/* Set any attributes */
 	va_start(args, active);
-	while ((id = va_arg(args, const char *)) != NULL)
-	{
-		GaimValue *value;
-		value = gaim_status_get_attr_value(status, id);
-		if (value->type == GAIM_TYPE_STRING)
-		{
-			string_data = va_arg(args, const char *);
-			if (((string_data == NULL) && (value->data.string_data == NULL)) ||
-				((string_data != NULL) && (value->data.string_data != NULL) &&
-				!strcmp(string_data, value->data.string_data)))
-			{
-				continue;
-			}
-			gaim_status_set_attr_string(status, id, string_data);
-			changed = TRUE;
-		}
-		else if (value->type == GAIM_TYPE_INT)
-		{
-			int_data = va_arg(args, int);
-			if (int_data == value->data.int_data)
-				continue;
-			gaim_status_set_attr_int(status, id, int_data);
-			changed = TRUE;
-		}
-		else if (value->type == GAIM_TYPE_BOOLEAN)
-		{
-			boolean_data = va_arg(args, gboolean);
-			if (boolean_data == value->data.boolean_data)
-				continue;
-			gaim_status_set_attr_int(status, id, boolean_data);
-			changed = TRUE;
-		}
-		else
-		{
-			/* We don't know what the data is--skip over it */
-			va_arg(args, void *);
-		}
-	}
+	gaim_status_set_active_with_attrs(status, active, args);
 	va_end(args);
-
-	if (!changed)
-		return;
-
-	gaim_status_set_active(status, active);
 }
 
 void
--- a/src/status.c	Thu Nov 18 17:05:40 2004 +0000
+++ b/src/status.c	Fri Nov 19 03:08:27 2004 +0000
@@ -628,50 +628,40 @@
 	}
 }
 
-void
-gaim_status_set_active(GaimStatus *status, gboolean active)
+static void
+status_has_changed(GaimStatus *status)
 {
-	GaimStatusType *status_type;
 	GaimPresence *presence;
 	GaimStatus *old_status;
 
-	g_return_if_fail(status != NULL);
-
-	if (status->active == active)
-		return;
-
-	status_type = gaim_status_get_type(status);
-
-	if (!active && gaim_status_type_is_exclusive(status_type))
-	{
-		gaim_debug_error("status",
-				   "Cannot deactivate an exclusive status (%s).\n",
-				   gaim_status_type_get_id(status_type));
-		return;
-	}
-
 	presence   = gaim_status_get_presence(status);
 	old_status = gaim_presence_get_active_status(presence);
 
-	if (gaim_status_type_is_exclusive(status_type))
+	/*
+	 * If this status is exclusive, then we must be setting it to "active."
+	 * Since we are setting it to active, we want to set the currently
+	 * active status to "inactive."
+	 */
+	if (gaim_status_is_exclusive(status))
 	{
 		const GList *l;
 
 		for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next)
 		{
 			GaimStatus *temp_status = l->data;
-			GaimStatusType *temp_type;
 
-			temp_type = gaim_status_get_type(temp_status);
+			if (temp_status == status)
+				continue;
 
-			if (gaim_status_type_is_independent(temp_type))
+			if (gaim_status_is_independent(temp_status))
 				continue;
 
 			if (gaim_status_is_active(temp_status))
 			{
 				/*
-				 * Since we don't want an infinite loop, we have to set
-				 * the active variable ourself.
+				 * Since we don't want infinite recursion, we have to set
+				 * the active variable ourself instead of calling
+				 * gaim_status_set_active().
 				 */
 				temp_status->active = FALSE;
 
@@ -682,9 +672,95 @@
 		}
 	}
 
+	notify_status_update(presence, old_status, status);
+}
+
+void
+gaim_status_set_active(GaimStatus *status, gboolean active)
+{
+	if (!active && gaim_status_is_exclusive(status))
+	{
+		gaim_debug_error("status",
+				   "Cannot deactivate an exclusive status (%s).\n",
+				   gaim_status_get_id(status));
+		return;
+	}
+
+	g_return_if_fail(status != NULL);
+
+	if (status->active == active)
+		return;
+
+	status->active = active;
+
+	status_has_changed(status);
+}
+
+void
+gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args)
+{
+	gboolean changed = FALSE;
+	const gchar *id;
+
+	if (!active && gaim_status_is_exclusive(status))
+	{
+		gaim_debug_error("status",
+				   "Cannot deactivate an exclusive status (%s).\n",
+				   gaim_status_get_id(status));
+		return;
+	}
+
+	g_return_if_fail(status != NULL);
+
+	if (status->active != active)
+		changed = TRUE;
+
 	status->active = active;
 
-	notify_status_update(presence, old_status, status);
+	/* Set any attributes */
+	while ((id = va_arg(args, const char *)) != NULL)
+	{
+		GaimValue *value;
+		value = gaim_status_get_attr_value(status, id);
+		if (value->type == GAIM_TYPE_STRING)
+		{
+			const gchar *string_data = va_arg(args, const char *);
+			if (((string_data == NULL) && (value->data.string_data == NULL)) ||
+				((string_data != NULL) && (value->data.string_data != NULL) &&
+				!strcmp(string_data, value->data.string_data)))
+			{
+				continue;
+			}
+			gaim_status_set_attr_string(status, id, string_data);
+			changed = TRUE;
+		}
+		else if (value->type == GAIM_TYPE_INT)
+		{
+			int int_data = va_arg(args, int);
+			if (int_data == value->data.int_data)
+				continue;
+			gaim_status_set_attr_int(status, id, int_data);
+			changed = TRUE;
+		}
+		else if (value->type == GAIM_TYPE_BOOLEAN)
+		{
+			gboolean boolean_data = va_arg(args, gboolean);
+			if (boolean_data == value->data.boolean_data)
+				continue;
+			gaim_status_set_attr_int(status, id, boolean_data);
+			changed = TRUE;
+		}
+		else
+		{
+			/* We don't know what the data is--skip over it */
+			va_arg(args, void *);
+		}
+	}
+
+	if (!changed)
+		return;
+
+	status_has_changed(status);
 }
 
 void
--- a/src/status.h	Thu Nov 18 17:05:40 2004 +0000
+++ b/src/status.h	Fri Nov 19 03:08:27 2004 +0000
@@ -377,12 +377,27 @@
  *
  * This should only be called by the account, conversation, and buddy APIs.
  *
- * @param status  The status.
+ * @param status The status.
  * @param active The active state.
  */
 void gaim_status_set_active(GaimStatus *status, gboolean active);
 
 /**
+ * Sets whether or not a status is active.
+ *
+ * This should only be called by the account, conversation, and buddy APIs.
+ *
+ * @param status The status.
+ * @param active The active state.
+ * @param args   A list of attributes to set on the status.  This list is
+ *               composed of key/value pairs, where each key is a valid
+ *               attribute name for this GaimStatusType.  The list should
+ *               be NULL terminated.
+ */
+void gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active,
+									   va_list args);
+
+/**
  * Sets the boolean value of an attribute in a status with the specified ID.
  *
  * @param status The status.