cpw.darkrain42.xmpp.disco: ead0d4fe: s/category/type/ and s/muc/chat/ in t

paul at darkrain42.org paul at darkrain42.org
Sat Apr 25 16:17:59 EDT 2009


-----------------------------------------------------------------
Revision: ead0d4fe7ad002d288919e966edd3a24ef98edfc
Ancestor: 4e8e52d0e0ee31bebe0d3a4a71652e53af466908
Author: paul at darkrain42.org
Date: 2009-04-01T05:26:25
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/ead0d4fe7ad002d288919e966edd3a24ef98edfc

Modified files:
        libpurple/disco.c libpurple/disco.h
        libpurple/protocols/jabber/disco.c pidgin/gtkdisco.c

ChangeLog: 

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).

-------------- next part --------------
============================================================
--- libpurple/disco.c	346c1e9279e50eac59307ae5ec4367a60fb649f5
+++ libpurple/disco.c	d2370d0a3a4c958aee998f0231bdb227c72acfe6
@@ -56,8 +56,8 @@ struct _PurpleDiscoService {
 	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 @@ static void purple_disco_list_service_de
 {
 	g_free(r->name);
 	g_free(r->description);
+	g_free(r->gateway_type);
 	g_free(r);
 }
 
@@ -141,16 +142,15 @@ void purple_disco_list_service_add(Purpl
 		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 @@ const gchar *purple_disco_service_get_de
 	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 @@ purple_disco_service_get_flags(PurpleDis
 	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);
============================================================
--- libpurple/disco.h	37ee5f1beb915973c11c9fd7798ea4b563035bec
+++ libpurple/disco.h	903ebee25357ea8b6a5c5f3c62996953471a143a
@@ -40,34 +40,31 @@ typedef void  (*PurpleDiscoCloseCallback
 typedef void  (*PurpleDiscoCloseCallback) (PurpleDiscoList *list);
 
 /**
- * The categories of services.
+ * The types 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;
+	PURPLE_DISCO_SERVICE_TYPE_UNSET,
+	/**
+	 * A registerable gateway to another protocol. An example would be
+	 * XMPP legacy transports.
+	 */
+	PURPLE_DISCO_SERVICE_TYPE_GATEWAY,
 
-/**
- * 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
+	/**
+	 * 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 @@ void purple_disco_cancel_get_list(Purple
 /**
  * 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,34 +181,50 @@ const gchar* purple_disco_service_get_de
 const gchar* purple_disco_service_get_description(PurpleDiscoService *service);
 
 /**
- * Return a service's category.
+ * Return a service's type.
  *
  * @param service The service.
- * @return The category.
+ * @return The type.
  *
  * @since TODO
  */
-PurpleDiscoServiceCategory purple_disco_service_get_category(PurpleDiscoService *service);
+PurpleDiscoServiceType purple_disco_service_get_type(PurpleDiscoService *service);
 
 /**
- * Return a service's type.
+ * Return a service's flags.
  *
  * @param service The service.
- * @return The type.
+ * @return The flags.
  *
  * @since TODO
  */
-PurpleDiscoServiceType purple_disco_service_get_type(PurpleDiscoService *service);
+PurpleDiscoServiceFlags purple_disco_service_get_flags(PurpleDiscoService *service);
 
 /**
- * Return a service's flags.
+ * 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.
- * @return The flags.
+ * @returns       The gateway type or NULL if none was set or service is not
+ *                a gateway.
  *
- * @since TODO
+ * @see purple_disco_service_set_gateway_type().
  */
-PurpleDiscoServiceFlags purple_disco_service_get_flags(PurpleDiscoService *service);
+const gchar *purple_disco_service_get_gateway_type(PurpleDiscoService *service);
+
 /**
  * Get the account associated with a service list.
  *
============================================================
--- libpurple/protocols/jabber/disco.c	0d805fdca078031c73eae41628e3f3740a97cd91
+++ libpurple/protocols/jabber/disco.c	d3dcce25948d967cbab2370ed5c9192e285f681e
@@ -602,44 +602,43 @@ disco_proto_data_destroy_cb(PurpleDiscoL
 	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 @@ jabber_disco_service_info_cb(JabberStrea
 	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 @@ jabber_disco_service_info_cb(JabberStrea
 		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 @@ jabber_disco_service_info_cb(JabberStrea
 			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 */
============================================================
--- pidgin/gtkdisco.c	ced88e22d73955d1cd3fb731ddaea284990a9384
+++ pidgin/gtkdisco.c	cc66500943c2753c0377c7ec1c28bca49745d23a
@@ -130,7 +130,7 @@ static void add_room_to_blist_cb(GtkButt
 	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 @@ static void pidgin_disco_add_service(Pur
 {
 	PidginDiscoList *pdl;
 	PidginDiscoDialog *dialog;
-	PurpleDiscoServiceCategory category;
 	PurpleDiscoServiceType type;
+	const char *gateway_type;
 	GtkTreeIter iter, parent_iter;
 	GtkTreeRowReference *rr;
 	GtkTreePath *path;
@@ -485,30 +485,18 @@ static void pidgin_disco_add_service(Pur
 
 	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) {


More information about the Commits mailing list