4fa0e7161f5d0aa6068807e41c2bf935cdc6865f braney Tue Jul 12 18:40:16 2011 -0700 make it so unlisted hubs don't disappear when you deselect them, and add the ability to disconnect them diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c index 3158a07..3b71361 100644 --- src/hg/lib/hubConnect.c +++ src/hg/lib/hubConnect.c @@ -139,51 +139,83 @@ struct hubConnectStatus *hubConnectStatusForId(struct cart *cart, struct sqlConnection *conn, int id) /* Given a hub ID return associated status. Returns NULL if no such hub. If hub * exists but has problems will return with errorMessage field filled in. */ /* If the id is negative, then the hub is private and the number is the * offset into the private hubfile in the trash */ { struct hubConnectStatus *hub = NULL; hub = hubConnectStatusForIdDb(conn, id); return hub; } +struct hubConnectStatus *hubConnectStatusListFromCartAll(struct cart *cart) +/* Return list of all track hubs that are referenced by cart. */ +{ +struct hubConnectStatus *hubList = NULL, *hub; +struct slPair *pair, *pairList = cartVarsWithPrefix(cart, hgHubConnectHubVarPrefix); +struct sqlConnection *conn = hConnectCentral(); +for (pair = pairList; pair != NULL; pair = pair->next) + { + int id = hubIdFromCartName(pair->name); + hub = hubConnectStatusForId(cart, conn, id); + if (hub != NULL) + { + slAddHead(&hubList, hub); + } + } +slFreeList(&pairList); +hDisconnectCentral(&conn); +slReverse(&hubList); +return hubList; +} + struct hubConnectStatus *hubConnectStatusListFromCart(struct cart *cart) /* Return list of track hubs that are turned on by user in cart. */ { struct hubConnectStatus *hubList = NULL, *hub; struct slName *name, *nameList = hubConnectHubsInCart(cart); struct sqlConnection *conn = hConnectCentral(); for (name = nameList; name != NULL; name = name->next) { int id = sqlSigned(name->name); hub = hubConnectStatusForId(cart, conn, id); if (hub != NULL) { slAddHead(&hubList, hub); } } slFreeList(&nameList); hDisconnectCentral(&conn); slReverse(&hubList); return hubList; } +int hubIdFromCartName(char *cartName) +/* Given something like "hgHubConnect.hub.123" return 123 */ +{ +assert(startsWith("hgHubConnect.hub.", cartName)); + +char *ptr1 = strchr(cartName, '.'); +char *ptr2 = strchr(ptr1 + 1, '.'); + +return sqlUnsigned(ptr2+1); +} + int hubIdFromTrackName(char *trackName) /* Given something like "hub_123_myWig" return 123 */ { assert(startsWith("hub_", trackName)); char *ptr1 = trackName; ptr1 += 4; char *ptr2 = strchr(ptr1, '_'); if (ptr2 == NULL) errAbort("hub track %s not in correct format\n", trackName); char save = *ptr2; *ptr2 = 0; unsigned val = sqlUnsigned(ptr1); *ptr2 = save; return val; @@ -465,18 +497,39 @@ { struct sqlConnection *conn = hConnectCentral(); char query[512]; safef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", hubStatusTableName, url); unsigned id = sqlQuickNum(conn, query); if (id == 0) errAbort("could not find url %s in status table (%s)\n", url, hubStatusTableName); safef(query, sizeof(query), "delete from %s where hubUrl = \"%s\"", hubStatusTableName, url); sqlUpdate(conn, query); hDisconnectCentral(&conn); - } +void hubDisconnect(struct cart *cart, char *url) +{ +struct sqlConnection *conn = hConnectCentral(); +char query[512]; + +safef(query, sizeof(query), "select id from %s where hubUrl = \"%s\"", hubStatusTableName, url); +unsigned id = sqlQuickNum(conn, query); + +if (id == 0) + errAbort("could not find url %s in status table (%s)\n", + url, hubStatusTableName); + +safef(query, sizeof(query), "delete from %s where hubUrl = \"%s\"", hubStatusTableName, url); + +sqlUpdate(conn, query); +hDisconnectCentral(&conn); + +char buffer[1024]; + +safef(buffer, sizeof buffer, "hgHubConnect.hub.%d", id); +cartRemove(cart, buffer); +}