changeset 26342:d6b2944f04b3

s/category/type/ and s/muc/chat/ in the core and gateway type is a string. 'type' seems a more reasonable name (category and type are fairly specific XMPP-isms even though this is basically only ever going to be useful for XMPP). Changing the gateway type (i.e. prpl identifier) to a string means adding them doesn't require minor bumps (and sane fallback methods should be implementable).
author Paul Aurich <paul@darkrain42.org>
date Wed, 01 Apr 2009 05:26:25 +0000
parents 9d0bad6f4b0d
children b290c7b9fc73
files libpurple/disco.c libpurple/disco.h libpurple/protocols/jabber/disco.c pidgin/gtkdisco.c
diffstat 4 files changed, 115 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/disco.c	Tue Mar 31 18:32:33 2009 +0000
+++ b/libpurple/disco.c	Wed Apr 01 05:26:25 2009 +0000
@@ -56,8 +56,8 @@
 	gchar *name; /**< The name of the service. */
 	gchar *description; /**< The name of the service. */
 
-	PurpleDiscoServiceCategory category; /**< The category of service. */
 	PurpleDiscoServiceType type; /**< The type of service. */
+	gchar *gateway_type; /**< The type of the gateway service. */
 	PurpleDiscoServiceFlags flags;
 };
 
@@ -93,6 +93,7 @@
 {
 	g_free(r->name);
 	g_free(r->description);
+	g_free(r->gateway_type);
 	g_free(r);
 }
 
@@ -141,16 +142,15 @@
 		ops->add_service(list, service, parent);
 }
 
-PurpleDiscoService *purple_disco_list_service_new(PurpleDiscoServiceCategory category, const gchar *name,
-		PurpleDiscoServiceType type, const gchar *description, PurpleDiscoServiceFlags flags)
+PurpleDiscoService *purple_disco_list_service_new(PurpleDiscoServiceType type, const gchar *name,
+		const gchar *description, PurpleDiscoServiceFlags flags)
 {
 	PurpleDiscoService *s;
 
 	g_return_val_if_fail(name != NULL, NULL);
-	g_return_val_if_fail(category != PURPLE_DISCO_SERVICE_CAT_UNSET, NULL);
+	g_return_val_if_fail(type != PURPLE_DISCO_SERVICE_TYPE_UNSET, NULL);
 
 	s = g_new0(PurpleDiscoService, 1);
-	s->category = category;
 	s->name = g_strdup(name);
 	s->type = type;
 	s->description = g_strdup(description);
@@ -235,18 +235,10 @@
 	return service->description;
 }
 
-PurpleDiscoServiceCategory
-purple_disco_service_get_category(PurpleDiscoService *service)
-{
-	g_return_val_if_fail(service != NULL, PURPLE_DISCO_SERVICE_CAT_UNSET);
-
-	return service->category;
-}
-
 PurpleDiscoServiceType
 purple_disco_service_get_type(PurpleDiscoService *service)
 {
-	g_return_val_if_fail(service != NULL, PURPLE_DISCO_SERVICE_TYPE_NONE);
+	g_return_val_if_fail(service != NULL, PURPLE_DISCO_SERVICE_TYPE_UNSET);
 
 	return service->type;
 }
@@ -259,6 +251,21 @@
 	return service->flags;
 }
 
+void purple_disco_service_set_gateway_type(PurpleDiscoService *service, const gchar *type)
+{
+	g_return_if_fail(service != NULL);
+
+	g_free(service->gateway_type);
+	service->gateway_type = g_strdup(type);
+}
+
+const gchar *purple_disco_service_get_gateway_type(PurpleDiscoService *service)
+{
+	g_return_val_if_fail(service != NULL, NULL);
+
+	return service->gateway_type;
+}
+
 PurpleAccount* purple_disco_list_get_account(PurpleDiscoList *list)
 {
 	g_return_val_if_fail(list != NULL, NULL);
--- a/libpurple/disco.h	Tue Mar 31 18:32:33 2009 +0000
+++ b/libpurple/disco.h	Wed Apr 01 05:26:25 2009 +0000
@@ -40,34 +40,31 @@
 typedef void  (*PurpleDiscoCloseCallback) (PurpleDiscoList *list);
 
 /**
- * The categories of services.
- */
-typedef enum
-{
-	PURPLE_DISCO_SERVICE_CAT_UNSET,
-	PURPLE_DISCO_SERVICE_CAT_GATEWAY,
-	PURPLE_DISCO_SERVICE_CAT_DIRECTORY,
-	PURPLE_DISCO_SERVICE_CAT_MUC,
-	PURPLE_DISCO_SERVICE_CAT_OTHER
-} PurpleDiscoServiceCategory;
-
-/**
  * The types of services.
  */
 typedef enum
 {
-	PURPLE_DISCO_SERVICE_TYPE_NONE,
-	PURPLE_DISCO_SERVICE_TYPE_AIM,
-	PURPLE_DISCO_SERVICE_TYPE_GG,
-	PURPLE_DISCO_SERVICE_TYPE_GTALK,
-	PURPLE_DISCO_SERVICE_TYPE_ICQ,
-	PURPLE_DISCO_SERVICE_TYPE_IRC,
-	PURPLE_DISCO_SERVICE_TYPE_MAIL,
-	PURPLE_DISCO_SERVICE_TYPE_MSN,
-	PURPLE_DISCO_SERVICE_TYPE_USER,
-	PURPLE_DISCO_SERVICE_TYPE_QQ,
-	PURPLE_DISCO_SERVICE_TYPE_XMPP,
-	PURPLE_DISCO_SERVICE_TYPE_YAHOO
+	PURPLE_DISCO_SERVICE_TYPE_UNSET,
+	/**
+	 * A registerable gateway to another protocol. An example would be
+	 * XMPP legacy transports.
+	 */
+	PURPLE_DISCO_SERVICE_TYPE_GATEWAY,
+
+	/**
+	 * A directory (e.g. allows the user to search for other users).
+	 */
+	PURPLE_DISCO_SERVICE_TYPE_DIRECTORY,
+
+	/**
+	 * A chat (multi-user conversation).
+	 */
+	PURPLE_DISCO_SERVICE_TYPE_CHAT,
+
+	/**
+	 * Something else. Do we need more categories?
+	 */
+	PURPLE_DISCO_SERVICE_TYPE_OTHER
 } PurpleDiscoServiceType;
 
 /**
@@ -147,8 +144,10 @@
 /**
  * Create new service object
  */
-PurpleDiscoService *purple_disco_list_service_new(PurpleDiscoServiceCategory category, const gchar *name,
-		PurpleDiscoServiceType type, const gchar *description, PurpleDiscoServiceFlags flags);
+PurpleDiscoService *
+purple_disco_list_service_new(PurpleDiscoServiceType type, const gchar *name,
+                              const gchar *description,
+                              PurpleDiscoServiceFlags flags);
 
 /**
  * Add service to list
@@ -182,16 +181,6 @@
 const gchar* purple_disco_service_get_description(PurpleDiscoService *service);
 
 /**
- * Return a service's category.
- *
- * @param service The service.
- * @return The category.
- *
- * @since TODO
- */
-PurpleDiscoServiceCategory purple_disco_service_get_category(PurpleDiscoService *service);
-
-/**
  * Return a service's type.
  *
  * @param service The service.
@@ -210,6 +199,32 @@
  * @since TODO
  */
 PurpleDiscoServiceFlags purple_disco_service_get_flags(PurpleDiscoService *service);
+
+/**
+ * Set the gateway type for a gateway service. The gateway type is a string
+ * that represents a canonical name of the protocol to which this service is
+ * a gateway. For example, for an XMPP legacy transport to AIM, this would
+ * be "aim".
+ *
+ * These strings should conform to the names of the libpurple prpls where
+ * possible (so a UI can easily map types to icons) and, as a backup, the
+ * XMPP registry list of gateways at
+ * http://xmpp.org/registrar/disco-categories.html#gateway. 
+ */
+void purple_disco_service_set_gateway_type(PurpleDiscoService *service,
+                                           const gchar *type);
+
+/**
+ * Get the gateway type for a gateway service.
+ *
+ * @param service The service.
+ * @returns       The gateway type or NULL if none was set or service is not
+ *                a gateway.
+ *
+ * @see purple_disco_service_set_gateway_type().
+ */
+const gchar *purple_disco_service_get_gateway_type(PurpleDiscoService *service);
+
 /**
  * Get the account associated with a service list.
  *
--- a/libpurple/protocols/jabber/disco.c	Tue Mar 31 18:32:33 2009 +0000
+++ b/libpurple/protocols/jabber/disco.c	Wed Apr 01 05:26:25 2009 +0000
@@ -602,44 +602,43 @@
 	jabber_disco_list_data_destroy(data);
 }
 
-static PurpleDiscoServiceCategory
+static PurpleDiscoServiceType
 jabber_disco_category_from_string(const gchar *str)
 {
-	if (!strcasecmp(str, "gateway"))
-		return PURPLE_DISCO_SERVICE_CAT_GATEWAY;
-	else if (!strcasecmp(str, "directory"))
-		return PURPLE_DISCO_SERVICE_CAT_DIRECTORY;
-	else if (!strcasecmp(str, "conference"))
-		return PURPLE_DISCO_SERVICE_CAT_MUC;
+	if (!g_ascii_strcasecmp(str, "gateway"))
+		return PURPLE_DISCO_SERVICE_TYPE_GATEWAY;
+	else if (!g_ascii_strcasecmp(str, "directory"))
+		return PURPLE_DISCO_SERVICE_TYPE_DIRECTORY;
+	else if (!g_ascii_strcasecmp(str, "conference"))
+		return PURPLE_DISCO_SERVICE_TYPE_CHAT;
 
-	return PURPLE_DISCO_SERVICE_CAT_OTHER;
+	return PURPLE_DISCO_SERVICE_TYPE_OTHER;
 }
 
-static PurpleDiscoServiceType
+static const gchar *
 jabber_disco_type_from_string(const gchar *str)
 {
 	if (!strcasecmp(str, "xmpp"))
-		return PURPLE_DISCO_SERVICE_TYPE_XMPP;
+		return "jabber";
 	else if (!strcasecmp(str, "icq"))
-		return PURPLE_DISCO_SERVICE_TYPE_ICQ;
+		return "icq";
 	else if (!strcasecmp(str, "smtp"))
-		return PURPLE_DISCO_SERVICE_TYPE_MAIL;
-	else if (!strcasecmp(str, "user"))
-		return PURPLE_DISCO_SERVICE_TYPE_USER;
+		return "smtp";
 	else if (!strcasecmp(str, "yahoo"))
-		return PURPLE_DISCO_SERVICE_TYPE_YAHOO;
+		return "yahoo";
 	else if (!strcasecmp(str, "irc"))
-		return PURPLE_DISCO_SERVICE_TYPE_IRC;
+		return "irc";
 	else if (!strcasecmp(str, "gadu-gadu"))
-		return PURPLE_DISCO_SERVICE_TYPE_GG;
+		return "gg";
 	else if (!strcasecmp(str, "aim"))
-		return PURPLE_DISCO_SERVICE_TYPE_AIM;
+		return "aim";
 	else if (!strcasecmp(str, "qq"))
-		return PURPLE_DISCO_SERVICE_TYPE_QQ;
+		return "qq";
 	else if (!strcasecmp(str, "msn"))
-		return PURPLE_DISCO_SERVICE_TYPE_MSN;
+		return "msn";
 
-	return PURPLE_DISCO_SERVICE_TYPE_NONE;
+	/* fallback to the string itself */
+	return str;
 }
 
 static void
@@ -743,8 +742,8 @@
 	const char *acat, *atype, *adesc, *anode;
 	char *aname;
 	PurpleDiscoService *s;
-	PurpleDiscoServiceCategory cat;
 	PurpleDiscoServiceType type;
+	const char *gateway_type = NULL;
 	PurpleDiscoServiceFlags flags = PURPLE_DISCO_ADD;
 
 	list_data = disco_data->list_data;
@@ -787,8 +786,9 @@
 		aname = g_strdup(from);
 	}
 
-	cat = jabber_disco_category_from_string(acat);
-	type = jabber_disco_type_from_string(atype);
+	type = jabber_disco_category_from_string(acat);
+	if (type == PURPLE_DISCO_SERVICE_TYPE_GATEWAY)
+		gateway_type = jabber_disco_type_from_string(atype);
 
 	for (child = xmlnode_get_child(query, "feature"); child;
 			child = xmlnode_get_next_twin(child)) {
@@ -804,16 +804,19 @@
 			flags |= PURPLE_DISCO_BROWSE;
 
 		if (!strcmp(var, "http://jabber.org/protocol/muc"))
-			cat = PURPLE_DISCO_SERVICE_CAT_MUC;
+			type = PURPLE_DISCO_SERVICE_TYPE_CHAT;
 	}
 
-	purple_debug_info("disco", "service %s, category %s (%d), type %s (%d), description %s, flags %04x\n",
+	purple_debug_info("disco", "service %s, category %s (%d), type %s (%s), description %s, flags %04x\n",
 			aname,
-			acat, cat,
-			atype, type,
+			acat, type,
+			atype, gateway_type ? gateway_type : "(null)",
 			adesc, flags);
 
-	s = purple_disco_list_service_new(cat, aname, type, adesc, flags);
+	s = purple_disco_list_service_new(type, aname, adesc, flags);
+	if (type == PURPLE_DISCO_SERVICE_TYPE_GATEWAY)
+		purple_disco_service_set_gateway_type(s, gateway_type);
+
 	purple_disco_list_service_add(list, s, parent);
 
 	/* if (flags & PURPLE_DISCO_FLAG_BROWSE) - not all browsable services has this future */
--- a/pidgin/gtkdisco.c	Tue Mar 31 18:32:33 2009 +0000
+++ b/pidgin/gtkdisco.c	Wed Apr 01 05:26:25 2009 +0000
@@ -130,7 +130,7 @@
 	account = purple_disco_list_get_account(info->list);
 	name = purple_disco_service_get_name(info->service);
 
-	if (purple_disco_service_get_category(info->service) == PURPLE_DISCO_SERVICE_CAT_MUC)
+	if (purple_disco_service_get_type(info->service) == PURPLE_DISCO_SERVICE_TYPE_CHAT)
 		purple_blist_request_add_chat(account, NULL, NULL, name);
 	else
 		purple_blist_request_add_buddy(account, name, NULL, NULL);
@@ -459,8 +459,8 @@
 {
 	PidginDiscoList *pdl;
 	PidginDiscoDialog *dialog;
-	PurpleDiscoServiceCategory category;
 	PurpleDiscoServiceType type;
+	const char *gateway_type;
 	GtkTreeIter iter, parent_iter;
 	GtkTreeRowReference *rr;
 	GtkTreePath *path;
@@ -485,30 +485,18 @@
 
 	gtk_tree_store_append(pdl->model, &iter, (parent ? &parent_iter : NULL));
 
-	category = purple_disco_service_get_category(service);
 	type = purple_disco_service_get_type(service);
+	gateway_type = purple_disco_service_get_gateway_type(service);
 
-	if (type == PURPLE_DISCO_SERVICE_TYPE_XMPP)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "jabber.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_ICQ)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "icq.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_YAHOO)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "yahoo.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_GTALK)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "google-talk.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_IRC)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "irc.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_GG)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "gadu-gadu.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_AIM)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "aim.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_QQ)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "qq.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_MSN)
-		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "msn.png", NULL);
-	else if (type == PURPLE_DISCO_SERVICE_TYPE_USER)
+	if (type == PURPLE_DISCO_SERVICE_TYPE_GATEWAY && gateway_type) {
+		char *tmp = g_strconcat(gateway_type, ".png", NULL);
+		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", tmp, NULL);
+		g_free(tmp);
+#if 0
+	} else if (type == PURPLE_DISCO_SERVICE_TYPE_USER) {
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "status", "22", "person.png", NULL);
-	else if (category == PURPLE_DISCO_SERVICE_CAT_MUC)
+#endif
+	} else if (type == PURPLE_DISCO_SERVICE_TYPE_CHAT)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "status", "22", "chat.png", NULL);
 
 	if (filename) {