changeset 8570:1a62ab7225f3

[gaim-migrate @ 9318] This is what you've been waiting for, the infamous status rewrite! It's amazing, all the stuff it can do, and... oh wait, no, this is just basic core support for the list account option, which doesn't even have UI support yet. Sorry everyone. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 03 Apr 2004 03:30:57 +0000
parents ee13d1befabe
children a3ea56f147c7
files src/accountopt.c src/accountopt.h
diffstat 2 files changed, 126 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/accountopt.c	Sat Apr 03 03:17:51 2004 +0000
+++ b/src/accountopt.c	Sat Apr 03 03:30:57 2004 +0000
@@ -30,12 +30,9 @@
 {
 	GaimAccountOption *option;
 
-	g_return_val_if_fail(type == GAIM_PREF_BOOLEAN ||
-						 type == GAIM_PREF_INT ||
-						 type == GAIM_PREF_STRING,
-						 NULL);
-	g_return_val_if_fail(text != NULL, NULL);
-	g_return_val_if_fail(pref_name != NULL, NULL);
+	g_return_val_if_fail(type      != GAIM_PREF_NONE, NULL);
+	g_return_val_if_fail(text      != NULL,           NULL);
+	g_return_val_if_fail(pref_name != NULL,           NULL);
 
 	option = g_new0(GaimAccountOption, 1);
 
@@ -95,6 +92,22 @@
 	return option;
 }
 
+GaimAccountOption *
+gaim_account_option_list_new(const char *text, const char *pref_name,
+							 GList *list)
+{
+	GaimAccountOption *option;
+
+	option = gaim_account_option_new(GAIM_PREF_STRING_LIST, text, pref_name);
+
+	if (option == NULL)
+		return NULL;
+
+	option->default_value.list = list;
+
+	return option;
+}
+
 void
 gaim_account_option_destroy(GaimAccountOption *option)
 {
@@ -106,10 +119,18 @@
 	if (option->pref_name != NULL)
 		g_free(option->pref_name);
 
-	if (option->type == GAIM_PREF_STRING &&
-		option->default_value.string != NULL) {
-
-		g_free(option->default_value.string);
+	if (option->type == GAIM_PREF_STRING)
+	{
+		if (option->default_value.string != NULL)
+			g_free(option->default_value.string);
+	}
+	else if (option->type == GAIM_PREF_STRING_LIST)
+	{
+		if (option->default_value.list != NULL)
+		{
+			g_list_foreach(option->default_value.list, (GFunc)g_free, NULL);
+			g_list_free(option->default_value.list);
+		}
 	}
 
 	g_free(option);
@@ -147,6 +168,36 @@
 	option->default_value.string = (value == NULL ? NULL : g_strdup(value));
 }
 
+void
+gaim_account_option_set_list(GaimAccountOption *option, GList *values)
+{
+	g_return_if_fail(option != NULL);
+	g_return_if_fail(option->type == GAIM_PREF_STRING_LIST);
+
+	if (option->default_value.list != NULL)
+	{
+		g_list_foreach(option->default_value.list, (GFunc)g_free, NULL);
+		g_list_free(option->default_value.list);
+	}
+
+	option->default_value.list = values;
+}
+
+void
+gaim_account_option_add_list_item(GaimAccountOption *option,
+								  const char *key, const char *value)
+{
+	g_return_if_fail(option != NULL);
+	g_return_if_fail(key    != NULL);
+	g_return_if_fail(value  != NULL);
+	g_return_if_fail(option->type == GAIM_PREF_STRING_LIST);
+
+	option->default_value.list = g_list_append(option->default_value.list,
+											   g_strdup(key));
+	option->default_value.list = g_list_append(option->default_value.list,
+											   g_strdup(value));
+}
+
 GaimPrefType
 gaim_account_option_get_type(const GaimAccountOption *option)
 {
@@ -198,7 +249,18 @@
 	return option->default_value.string;
 }
 
+const GList *
+gaim_account_option_get_list(const GaimAccountOption *option)
+{
+	g_return_val_if_fail(option != NULL, NULL);
+	g_return_val_if_fail(option->type == GAIM_PREF_STRING_LIST, NULL);
 
+	return option->default_value.list;
+}
+
+/**************************************************************************
+ * Account User Split API
+ **************************************************************************/
 GaimAccountUserSplit *
 gaim_account_user_split_new(const char *text, const char *default_value,
 							char sep)
--- a/src/accountopt.h	Sat Apr 03 03:17:51 2004 +0000
+++ b/src/accountopt.h	Sat Apr 03 03:30:57 2004 +0000
@@ -45,6 +45,7 @@
 		gboolean boolean;   /**< The default boolean value.             */
 		int integer;        /**< The default integer value.             */
 		char *string;       /**< The default string value.              */
+		GList *list;        /**< The default list value.                */
 
 	} default_value;
 
@@ -125,6 +126,25 @@
 												  const char *default_value);
 
 /**
+ * Creates a new list account option.
+ *
+ * The list passed will be owned by the account option, and the
+ * strings inside will be freed automatically.
+ *
+ * The list is in key, value pairs. The key is the ID stored and used
+ * internally, and the value is the label displayed.
+ *
+ * @param text      The text of the option.
+ * @param pref_name The account preference name for the option.
+ * @param list      The key, value list.
+ *
+ * @return The account option.
+ */
+GaimAccountOption *gaim_account_option_list_new(const char *text,
+												const char *pref_name,
+												GList *list);
+
+/**
  * Destroys an account option.
  *
  * @param option The option to destroy.
@@ -159,6 +179,30 @@
 											const char *value);
 
 /**
+ * Sets the list values for an account option.
+ *
+ * The list passed will be owned by the account option, and the
+ * strings inside will be freed automatically.
+ *
+ * The list is in key, value pairs. The key is the ID stored and used
+ * internally, and the value is the label displayed.
+ *
+ * @param option The account option.
+ * @param values The default list value.
+ */
+void gaim_account_option_set_list(GaimAccountOption *option, GList *values);
+
+/**
+ * Adds an item to a list account option.
+ *
+ * @param option The account option.
+ * @param key    The key.
+ * @param value  The value.
+ */
+void gaim_account_option_add_list_item(GaimAccountOption *option,
+									   const char *key, const char *value);
+
+/**
  * Returns the specified account option's type.
  *
  * @param option The account option.
@@ -211,7 +255,16 @@
  * @return The default string value.
  */
 const char *gaim_account_option_get_default_string(
-		const GaimAccountOption *option);
+	const GaimAccountOption *option);
+
+/**
+ * Returns the list values for an account option.
+ *
+ * @param option The account option.
+ *
+ * @return The list values.
+ */
+const GList *gaim_account_option_get_list(const GaimAccountOption *option);
 
 /*@}*/