-static void got_resolved_file(void *v, const char *track) {
- struct callbackdata *cbd = v;
- struct choosenode *cn = cbd->u.choosenode, *file_cn;
-
- file_cn = newnode(cn, track,
- trackname_transform("track", track, "display"),
- trackname_transform("track", track, "sort"),
- 0/*flags*/, 0/*fill*/);
- /* Only bother updating when we've got the lot */
- if(--cn->pending == 0)
- updated_node(cn, 1);
-}
-
-/* Called with a list of directories just below some node */
-static void got_dirs(void *v, int nvec, char **vec) {
- struct callbackdata *cbd = v;
- struct choosenode *cn = cbd->u.choosenode;
- int n;
-
- D(("got_dirs %d dirs for %s", nvec, cn->path));
- for(n = 0; n < nvec; ++n)
- newnode(cn, vec[n],
- trackname_transform("dir", vec[n], "display"),
- trackname_transform("dir", vec[n], "sort"),
- CN_EXPANDABLE, fill_directory_node);
- updated_node(cn, 1);
-}
-
-/* Fill a child node */
-static void fill_directory_node(struct choosenode *cn) {
- struct callbackdata *cbd;
-
- D(("fill_directory_node %s", cn->path));
- /* TODO: caching */
- /* TODO: de-dupe against fill_letter_node */
- assert(report_label != 0);
- gtk_label_set_text(GTK_LABEL(report_label), "getting files");
- clear_children(cn);
- cbd = xmalloc(sizeof *cbd);
- cbd->u.choosenode = cn;
- disorder_eclient_dirs(client, got_dirs, cn->path, 0, cbd);
- cbd = xmalloc(sizeof *cbd);
- cbd->u.choosenode = cn;
- disorder_eclient_files(client, got_files, cn->path, 0, cbd);
-}
-
-/* Expand a node */
-static void expand_node(struct choosenode *cn) {
- D(("expand_node %s", cn->path));
- assert(cn->flags & CN_EXPANDABLE);
- /* If node is already expanded do nothing. */
- if(cn->flags & CN_EXPANDED) return;
- /* We mark the node as expanded and request that it fill itself. When it has
- * completed it will called updated_node() and we can redraw at that
- * point. */
- cn->flags |= CN_EXPANDED;
- /* TODO: visual feedback */
- cn->fill(cn);
-}
-
-/* Contract a node */
-static void contract_node(struct choosenode *cn) {
- D(("contract_node %s", cn->path));
- assert(cn->flags & CN_EXPANDABLE);
- /* If node is already contracted do nothing. */
- if(!(cn->flags & CN_EXPANDED)) return;
- cn->flags &= ~CN_EXPANDED;
- /* Clear selection below this node */
- clear_selection(cn);
- /* Zot children. We never used to do this but the result would be that over
- * time you'd end up with the entire tree pulled into memory. If the server
- * is over a slow network it will make interactivity slightly worse; if
- * anyone complains we can make it an option. */
- clear_children(cn);
- /* We can contract a node immediately. */
- redisplay_tree();
-}
-
-/* qsort callback for ordering choosenodes */
-static int compare_choosenode(const void *av, const void *bv) {
- const struct choosenode *const *aa = av, *const *bb = bv;
- const struct choosenode *a = *aa, *b = *bb;
-
- return compare_tracks(a->sort, b->sort,
- a->display, b->display,
- a->path, b->path);
-}
-
-/* Called when an expandable node is updated. */
-static void updated_node(struct choosenode *cn, int redisplay) {
- D(("updated_node %s", cn->path));
- assert(cn->flags & CN_EXPANDABLE);
- /* It might be that the node has been de-expanded since we requested the
- * update. In that case we ignore this notification. */
- if(!(cn->flags & CN_EXPANDED)) return;
- /* Sort children */
- qsort(cn->children.vec, cn->children.nvec, sizeof (struct choosenode *),
- compare_choosenode);
- if(redisplay)
- redisplay_tree();
-}
-
-/* Searching --------------------------------------------------------------- */
-
-static int compare_track_for_qsort(const void *a, const void *b) {
- return compare_path(*(char **)a, *(char **)b);
-}
-
-/* Return true iff FILE is a child of DIR */
-static int is_child(const char *dir, const char *file) {
- const size_t dlen = strlen(dir);
-
- return (!strncmp(file, dir, dlen)
- && file[dlen] == '/'
- && strchr(file + dlen + 1, '/') == 0);