-/** @brief Called with a list of files just below some node */
-static void got_files(void *v, int nvec, char **vec) {
- struct callbackdata *cbd = v;
- struct choosenode *cn = cbd->u.choosenode;
- int n;
-
- D(("got_files %d files for %s %s", nvec, cn->path, flags(cn)));
- /* Complicated by the need to resolve aliases. We can save a bit of effort
- * by re-using cbd though. */
- cn->flags &= ~CN_GETTING_FILES;
- if((cn->pending = nvec)) {
- cn->flags |= CN_RESOLVING_FILES;
- for(n = 0; n < nvec; ++n)
- disorder_eclient_resolve(client, got_resolved_file, vec[n], cbd);
- }
- /* If there are no files and the directories are all read by now, we're
- * done */
- if(!(cn->flags & CN_GETTING_ANY))
- filled(cn);
-}
-
-/** @brief Called with an alias resolved filename */
-static void got_resolved_file(void *v, const char *track) {
- struct callbackdata *cbd = v;
- struct choosenode *cn = cbd->u.choosenode, *file_cn;
-
- D(("resolved %s %s %d left", cn->path, flags(cn), cn->pending - 1));
- /* TODO as below */
- 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) {
- cn->flags &= ~CN_RESOLVING_FILES;
- updated_node(cn, 1);
- if(!(cn->flags & CN_GETTING_ANY))
- filled(cn);
- }
-}
-
-/** @brief 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 %s", nvec, cn->path, flags(cn)));
- /* TODO this depends on local configuration for trackname_transform().
- * This will work, since the defaults are now built-in, but it'll be
- * (potentially) different to the server's configured settings.
- *
- * Really we want a variant of files/dirs that produces both the
- * raw filename and the transformed name for a chosen context.
- */
- 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);
- cn->flags &= ~CN_GETTING_DIRS;
- if(!(cn->flags & CN_GETTING_ANY))
- filled(cn);
-}
-
-/** @brief 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 */
- if(cn->flags & CN_GETTING_ANY)
- return;
- 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);
- cn->flags |= CN_GETTING_FILES|CN_GETTING_DIRS;
-}
-
-/** @brief Expand a node */
-static void expand_node(struct choosenode *cn, int contingent) {
- D(("expand_node %s %d %s", cn->path, contingent, flags(cn)));
- 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;
- if(contingent)
- cn->flags |= CN_CONTINGENT;
- else
- cn->flags &= ~CN_CONTINGENT;
- /* If this node is not contingently expanded, mark all its parents back to
- * the root as not contingent either, so they won't be contracted when the
- * search results change */
- if(!contingent) {
- struct choosenode *cnp;
-
- for(cnp = cn->parent; cnp; cnp = cnp->parent)
- cnp->flags &= ~CN_CONTINGENT;
- }
- /* TODO: visual feedback */
- cn->fill(cn);
-}
-
-/** @brief Make sure all the search results below @p cn are expanded
- * @param cn Node to start at