changeset 10340:84d73473c019

[gaim-migrate @ 11549] Minor improvements. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 09 Dec 2004 05:22:18 +0000
parents 3eb03f22e082
children 681c69bfc267
files src/status.c src/status.h
diffstat 2 files changed, 55 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/status.c	Thu Dec 09 05:21:39 2004 +0000
+++ b/src/status.c	Thu Dec 09 05:22:18 2004 +0000
@@ -1656,8 +1656,18 @@
 }
 
 GaimStatusSaved *
-gaim_statuses_find_saved(const GaimStatusType *status_type, const char *id)
+gaim_statuses_find_saved(const char *name)
 {
+	GList *l;
+	GaimStatusSaved *status;
+
+	for (l = saved_statuses; l != NULL; l = g_list_next(l))
+	{
+		status = (GaimStatusSaved *)l->data;
+		if (!strcmp(status->name, name))
+			return status;
+	}
+
 	return NULL;
 }
 
@@ -1667,6 +1677,18 @@
 	return saved_status->name;
 }
 
+const GaimStatusType *
+gaim_statuses_saved_get_type(const GaimStatusSaved *saved_status)
+{
+	return saved_status->type;
+}
+
+const char *
+gaim_statuses_saved_get_message(const GaimStatusSaved *saved_status)
+{
+	return saved_status->message;
+}
+
 void *
 gaim_statuses_get_handle() {
 	static int handle;
@@ -1732,6 +1754,7 @@
 void
 gaim_statuses_sync(void)
 {
+	/* TODO: Write me, baby. */
 }
 
 /**
@@ -1747,8 +1770,6 @@
  *   </status>
  *
  * I know.  Moving, huh?
- *
- * TODO: Make sure the name is unique before adding it to the linked list.
  */
 static void
 gaim_statuses_read_parse_status(xmlnode *status)
@@ -1756,10 +1777,11 @@
 	xmlnode *node;
 	const char *name, *state, *message;
 	GaimStatusSaved *new;
+	int i;
 
 	name = xmlnode_get_attrib(status, "name");
 	if (name == NULL)
-		name = "TODO: Make up something unique";
+		name = "No Title";
 
 	node = xmlnode_get_child(status, "state");
 	if (node != NULL) {
@@ -1781,6 +1803,14 @@
 	if (message != NULL)
 		new->message = g_strdup(message);
 
+	/* Ensure the title is unique */
+	i = 2;
+	while (gaim_statuses_find_saved(new->name) != NULL) {
+		g_free(new->name);
+		new->name = g_strdup_printf("%s %d", name, i);
+		i++;
+	}
+
 	saved_statuses = g_list_append(saved_statuses, new);
 }
 
--- a/src/status.h	Thu Dec 09 05:21:39 2004 +0000
+++ b/src/status.h	Thu Dec 09 05:22:18 2004 +0000
@@ -894,15 +894,13 @@
 const GList *gaim_statuses_get_saved(void);
 
 /**
- * Finds a saved status with the specified status type and primary ID.
+ * Finds a saved status with the specified title.
  *
- * @param status_type The status type of the status.
- * @param id          The primary attribute ID.
+ * @param name The name of the saved status.
  *
  * @return The saved status if found, or NULL.
  */
-GaimStatusSaved *gaim_statuses_find_saved(const GaimStatusType *status_type,
-										  const char *id);
+GaimStatusSaved *gaim_statuses_find_saved(const char *name);
 
 /**
  * Return the name of a given saved status.
@@ -914,6 +912,24 @@
 const char *gaim_statuses_saved_get_name(const GaimStatusSaved *saved_status);
 
 /**
+ * Return the name of a given saved status.
+ *
+ * @param saved_status The saved status.
+ *
+ * @return The name.
+ */
+const GaimStatusType *gaim_statuses_saved_get_type(const GaimStatusSaved *saved_status);
+
+/**
+ * Return the name of a given saved status.
+ *
+ * @param saved_status The saved status.
+ *
+ * @return The name.
+ */
+const char *gaim_statuses_saved_get_message(const GaimStatusSaved *saved_status);
+
+/**
  * Get the handle for the status subsystem.
  *
  * @return the handle to the status subsystem