changeset 5858:96e5b32e75ad

[gaim-migrate @ 6289] conversation placement functions now have an ID string, rather than the pref being dependent on the order the functions are in the list. also, the pref is converted to the new system. and it's cool, and stuff. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 13 Jun 2003 23:49:26 +0000
parents 2fa4aa9c1885
children 022786c7ab53
files src/conversation.c src/conversation.h src/gaimrc.c src/gtkconv.c src/gtkprefs.c src/main.c src/prefs.c
diffstat 7 files changed, 146 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/src/conversation.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/conversation.c	Fri Jun 13 23:49:26 2003 +0000
@@ -41,6 +41,7 @@
 
 typedef struct
 {
+	char *id;
 	char *name;
 	GaimConvPlacementFunc fnc;
 
@@ -56,7 +57,6 @@
 static GList *windows = NULL;
 static GList *conv_placement_fncs = NULL;
 static GaimConvPlacementFunc place_conv = NULL;
-static int place_conv_index = -1;
 
 static gint
 insertname_compare(gconstpointer one, gconstpointer two)
@@ -926,7 +926,10 @@
 	}
 	else {
 		if (place_conv == NULL)
-			gaim_conv_placement_set_active(0);
+			gaim_prefs_set_string("/core/conversations/placement", "last");
+
+		if (!place_conv)
+			gaim_debug(GAIM_DEBUG_ERROR, "conversation", "This is about to suck.\n");
 
 		place_conv(conv);
 	}
@@ -2181,104 +2184,118 @@
 	conv_placement_new_window(conv);
 }
 
-static int
-add_conv_placement_fnc(const char *name, GaimConvPlacementFunc fnc)
+static ConvPlacementData *get_conv_placement_data(const char *id)
+{
+	ConvPlacementData *data = NULL;
+	GList *n;
+
+	for(n = conv_placement_fncs; n; n = n->next) {
+		data = n->data;
+		if(!strcmp(data->id, id))
+			return data;
+	}
+
+	return NULL;
+}
+
+static void
+add_conv_placement_fnc(const char *id, const char *name,
+		GaimConvPlacementFunc fnc)
 {
 	ConvPlacementData *data;
 
-	data = g_malloc0(sizeof(ConvPlacementData));
-
+	data = g_new(ConvPlacementData, 1);
+
+	data->id = g_strdup(id);
 	data->name = g_strdup(name);
 	data->fnc  = fnc;
 
 	conv_placement_fncs = g_list_append(conv_placement_fncs, data);
 
-	return gaim_conv_placement_get_fnc_count() - 1;
 }
 
 static void
 ensure_default_funcs(void)
 {
 	if (conv_placement_fncs == NULL) {
-		add_conv_placement_fnc(_("Last created window"),
+		add_conv_placement_fnc("last", _("Last created window"),
 							   conv_placement_last_created_win);
-		add_conv_placement_fnc(_("New window"),
+		add_conv_placement_fnc("new", _("New window"),
 							   conv_placement_new_window);
-		add_conv_placement_fnc(_("By group"),
+		add_conv_placement_fnc("group", _("By group"),
 							   conv_placement_by_group);
-		add_conv_placement_fnc(_("By account"),
+		add_conv_placement_fnc("account", _("By account"),
 							   conv_placement_by_account);
 	}
 }
 
-int
-gaim_conv_placement_add_fnc(const char *name, GaimConvPlacementFunc fnc)
+GList *gaim_conv_placement_get_options(void)
 {
-	g_return_val_if_fail(name != NULL, -1);
-	g_return_val_if_fail(fnc  != NULL, -1);
-
-	if (conv_placement_fncs == NULL)
-		ensure_default_funcs();
-
-	return add_conv_placement_fnc(name, fnc);
+	GList *n, *list = NULL;
+	ConvPlacementData *data;
+
+	ensure_default_funcs();
+
+	for(n = conv_placement_fncs; n; n = n->next) {
+		data = n->data;
+		list = g_list_append(list, data->name);
+		list = g_list_append(list, data->id);
+	}
+
+	return list;
+}
+
+
+void
+gaim_conv_placement_add_fnc(const char *id, const char *name, GaimConvPlacementFunc fnc)
+{
+	g_return_if_fail(id != NULL);
+	g_return_if_fail(name != NULL);
+	g_return_if_fail(fnc  != NULL);
+
+	ensure_default_funcs();
+
+	add_conv_placement_fnc(id, name, fnc);
 }
 
 void
-gaim_conv_placement_remove_fnc(int index)
+gaim_conv_placement_remove_fnc(const char *id)
 {
-	ConvPlacementData *data;
-	GList *node;
-
-	if (index < 0 || index > g_list_length(conv_placement_fncs))
+	ConvPlacementData *data = get_conv_placement_data(id);
+
+	if(!data)
 		return;
 
-	node = g_list_nth(conv_placement_fncs, index);
-	data = (ConvPlacementData *)node->data;
-
+	conv_placement_fncs = g_list_remove(conv_placement_fncs, data);
+
+	g_free(data->id);
 	g_free(data->name);
 	g_free(data);
-
-	conv_placement_fncs = g_list_remove_link(conv_placement_fncs, node);
-	g_list_free_1(node);
-}
-
-int
-gaim_conv_placement_get_fnc_count(void)
-{
-	ensure_default_funcs();
-
-	return g_list_length(conv_placement_fncs);
 }
 
 const char *
-gaim_conv_placement_get_name(int index)
+gaim_conv_placement_get_name(const char *id)
 {
 	ConvPlacementData *data;
 
 	ensure_default_funcs();
 
-	if (index < 0 || index > g_list_length(conv_placement_fncs))
-		return NULL;
-
-	data = g_list_nth_data(conv_placement_fncs, index);
-
-	if (data == NULL)
+	data = get_conv_placement_data(id);
+
+	if (!data)
 		return NULL;
 
 	return data->name;
 }
 
 GaimConvPlacementFunc
-gaim_conv_placement_get_fnc(int index)
+gaim_conv_placement_get_fnc(const char *id)
 {
 	ConvPlacementData *data;
 
 	ensure_default_funcs();
 
-	if (index < 0 || index > g_list_length(conv_placement_fncs))
-		return NULL;
-
-	data = g_list_nth_data(conv_placement_fncs, index);
+	data = get_conv_placement_data(id);
 
 	if (data == NULL)
 		return NULL;
@@ -2286,48 +2303,23 @@
 	return data->fnc;
 }
 
-int
-gaim_conv_placement_get_fnc_index(GaimConvPlacementFunc fnc)
+static void
+conv_placement_pref_cb(const char *name, GaimPrefType type, gpointer value,
+		gpointer data)
 {
-	ConvPlacementData *data;
-	GList *node;
-	int i;
+	GaimConvPlacementFunc fnc;
+
+	if(strcmp(name, "/core/conversations/placement"))
+		return;
 
 	ensure_default_funcs();
 
-	for (node = conv_placement_fncs, i = 0;
-		 node != NULL;
-		 node = node->next, i++) {
-
-		data = (ConvPlacementData *)node->data;
-
-		if (data->fnc == fnc)
-			return i;
-	}
-
-	return -1;
-}
-
-int
-gaim_conv_placement_get_active(void)
-{
-	return place_conv_index;
-}
-
-void
-gaim_conv_placement_set_active(int index)
-{
-	GaimConvPlacementFunc fnc;
-
-	ensure_default_funcs();
-
-	fnc = gaim_conv_placement_get_fnc(index);
+	fnc = gaim_conv_placement_get_fnc(value);
 
 	if (fnc == NULL)
 		return;
 
 	place_conv = fnc;
-	place_conv_index = index;
 }
 
 void
@@ -2341,3 +2333,30 @@
 {
 	return win_ui_ops;
 }
+
+void
+gaim_conversation_init(void)
+{
+	/* Conversations */
+	gaim_prefs_add_none("/core/conversations");
+	gaim_prefs_add_bool("/core/conversations/send_urls_as_links", TRUE);
+	gaim_prefs_add_bool("/core/conversations/away_back_on_send", TRUE);
+	gaim_prefs_add_bool("/core/conversations/use_alias_for_title", TRUE);
+	gaim_prefs_add_bool("/core/conversations/combine_chat_im", FALSE);
+	gaim_prefs_add_string("/core/conversations/placement", "last");
+
+	/* Conversations -> Chat */
+	gaim_prefs_add_none("/core/conversations/chat");
+	gaim_prefs_add_bool("/core/conversations/chat/show_join", TRUE);
+	gaim_prefs_add_bool("/core/conversations/chat/show_leave", TRUE);
+	gaim_prefs_add_bool("/core/conversations/chat/show_nick_change", TRUE);
+
+	/* Conversations -> IM */
+	gaim_prefs_add_none("/core/conversations/im");
+	gaim_prefs_add_bool("/core/conversations/im/show_login", TRUE);
+	gaim_prefs_add_bool("/core/conversations/im/send_typing", TRUE);
+
+	gaim_prefs_connect_callback("/core/conversations/placement",
+			conv_placement_pref_cb, NULL);
+	gaim_prefs_trigger_callback("/core/conversations/placement");
+}
--- a/src/conversation.h	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/conversation.h	Fri Jun 13 23:49:26 2003 +0000
@@ -1081,74 +1081,58 @@
 /*@{*/
 
 /**
+ * Returns a GList containing the IDs and Names of the registered placement
+ * functions.
+ *
+ * @return The list of IDs and names.
+ */
+GList *gaim_conv_placement_get_options(void);
+
+/**
  * Adds a conversation placement function to the list of possible functions.
  *
  * @param name The name of the function.
  * @param fnc  A pointer to the function.
- *
- * @return The index of this entry.
  */
-int gaim_conv_placement_add_fnc(const char *name, GaimConvPlacementFunc fnc);
+void gaim_conv_placement_add_fnc(const char *id, const char *name, GaimConvPlacementFunc fnc);
 
 /**
  * Removes a conversation placement function from the list of possible
  * functions.
  *
- * @param index The index of the function.
+ * @param id The id of the function.
  */
-void gaim_conv_placement_remove_fnc(int index);
-
-/**
- * Returns the number of conversation placement functions.
- *
- * @return The number of registered functions.
- */
-int gaim_conv_placement_get_fnc_count(void);
+void gaim_conv_placement_remove_fnc(const char *id);
 
 /**
  * Returns the name of the conversation placement function at the
- * specified index.
+ * specified id.
  *
- * @param index The index.
+ * @param id The id.
  *
- * @return The name of the function, or @c NULL if this index is out of
- *         range.
+ * @return The name of the function, or @c NULL if this id is invalid.
  */
-const char *gaim_conv_placement_get_name(int index);
+const char *gaim_conv_placement_get_name(const char *id);
 
 /**
  * Returns a pointer to the conversation placement function at the
- * specified index.
+ * specified id.
  *
- * @param index The index.
+ * @param id The id.
  *
  * @return A pointer to the function.
  */
-GaimConvPlacementFunc gaim_conv_placement_get_fnc(int index);
+GaimConvPlacementFunc gaim_conv_placement_get_fnc(const char *id);
 
 /**
- * Returns the index of the specified conversation placement function.
+ * Returns the id of the specified conversation placement function.
  *
  * @param fnc A pointer to the registered function.
  *
- * @return The index of the conversation, or -1 if the function is not
+ * @return The id of the conversation, or NULL if the function is not
  *         registered.
  */
-int gaim_conv_placement_get_fnc_index(GaimConvPlacementFunc fnc);
-
-/**
- * Returns the index of the active conversation placement function.
- *
- * @param index The index of the active function.
- */
-int gaim_conv_placement_get_active(void);
-
-/**
- * Sets the active conversation placement function.
- *
- * @param index The index of the function.
- */
-void gaim_conv_placement_set_active(int index);
+const char *gaim_conv_placement_get_fnc_id(GaimConvPlacementFunc fnc);
 
 /*@}*/
 
--- a/src/gaimrc.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/gaimrc.c	Fri Jun 13 23:49:26 2003 +0000
@@ -177,7 +177,6 @@
 static guint blist_options;
 static guint convo_options;
 static guint im_options;
-static guint conv_placement_option;
 static guint chat_options;
 static guint font_options;
 static guint sound_options;
@@ -967,9 +966,25 @@
 								(im_options & OPT_IM_POPDOWN));
 
 		} else if (!strcmp(p->option, "conv_placement")) {
-			conv_placement_option = atoi(p->value[0]);
-			/* XXX: this still needs converting */
-			gaim_conv_placement_set_active(conv_placement_option);
+			switch(atoi(p->value[0])) {
+				case 1:
+					gaim_prefs_set_string("/core/conversations/placement",
+							"new");
+				break;
+				case 2:
+					gaim_prefs_set_string("/core/conversations/placement",
+							"group");
+				break;
+				case 3:
+					gaim_prefs_set_string("/core/conversations/placement",
+							"account");
+				break;
+				case 0:
+				default:
+					gaim_prefs_set_string("/core/conversations/placement",
+							"last");
+				break;
+			}
 		} else if (!strcmp(p->option, "chat_options")) {
 			chat_options = atoi(p->value[0]);
 
--- a/src/gtkconv.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/gtkconv.c	Fri Jun 13 23:49:26 2003 +0000
@@ -5397,7 +5397,6 @@
 	gaim_prefs_add_int("/gaim/gtk/conversations/font_size", 3);
 	gaim_prefs_add_bool("/gaim/gtk/conversations/tabs", TRUE);
 	gaim_prefs_add_int("/gaim/gtk/conversations/tab_side", GTK_POS_TOP);
-	gaim_prefs_add_string("/gaim/gtk/conversations/placement", "");
 
 	/* Conversations -> Chat */
 	gaim_prefs_add_none("/gaim/gtk/conversations/chat");
--- a/src/gtkprefs.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/gtkprefs.c	Fri Jun 13 23:49:26 2003 +0000
@@ -958,14 +958,10 @@
 	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 	vbox = gaim_gtk_make_frame(ret, _("Conversations"));
 
-	/* Build a list of names. */
-	for (i = 0; i < gaim_conv_placement_get_fnc_count(); i++) {
-		names = g_list_append(names, (char *)gaim_conv_placement_get_name(i));
-		names = g_list_append(names, (char *)gaim_conv_placement_get_name(i));
-	}
+	names = gaim_conv_placement_get_options();
 
 	label = prefs_dropdown_from_list(vbox, _("_Placement:"), GAIM_PREF_STRING,
-									 "/gaim/gtk/conversations/placement",
+									 "/core/conversations/placement",
 									 names);
 
 	g_list_free(names);
--- a/src/main.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/main.c	Fri Jun 13 23:49:26 2003 +0000
@@ -892,6 +892,7 @@
 	gaim_set_sound_ui_ops(gaim_get_gtk_sound_ui_ops());
 	gaim_set_connection_ui_ops(gaim_get_gtk_connection_ui_ops());
 
+	gaim_conversation_init();
 	gaim_proxy_init();
 	gaim_sound_init();
 
--- a/src/prefs.c	Fri Jun 13 23:04:26 2003 +0000
+++ b/src/prefs.c	Fri Jun 13 23:49:26 2003 +0000
@@ -119,25 +119,6 @@
 	/* Buddies */
 	gaim_prefs_add_none("/core/buddies");
 	gaim_prefs_add_bool("/core/buddies/use_server_alias", TRUE);
-
-	/* Conversations */
-	gaim_prefs_add_none("/core/conversations");
-	gaim_prefs_add_bool("/core/conversations/send_urls_as_links", TRUE);
-	gaim_prefs_add_bool("/core/conversations/away_back_on_send", TRUE);
-	gaim_prefs_add_bool("/core/conversations/use_alias_for_title", TRUE);
-	gaim_prefs_add_bool("/core/conversations/combine_chat_im", FALSE);
-
-	/* Conversations -> Chat */
-	gaim_prefs_add_none("/core/conversations/chat");
-	gaim_prefs_add_bool("/core/conversations/chat/show_join", TRUE);
-	gaim_prefs_add_bool("/core/conversations/chat/show_leave", TRUE);
-	gaim_prefs_add_bool("/core/conversations/chat/show_nick_change", TRUE);
-
-	/* Conversations -> IM */
-	gaim_prefs_add_none("/core/conversations/im");
-	gaim_prefs_add_bool("/core/conversations/im/show_login", TRUE);
-	gaim_prefs_add_bool("/core/conversations/im/send_typing", TRUE);
-
 }
 
 static char *