-#include "timeval.h"
-
-/* Choose track ------------------------------------------------------------ */
-
-#if TDEBUG
-/* Timing */
-static struct {
- struct timeval total;
- struct timeval gtkbits;
- struct timeval menuupdate;
- struct timeval new_widgets;
- struct timeval undisplay;
- struct timeval colors;
- struct timeval markers;
- struct timeval location;
- struct timeval selection;
-} times;
-
-#define BEGIN(WHAT) do { \
- struct timeval started##WHAT, finished##WHAT; \
- xgettimeofday(&started##WHAT, 0)
-
-#define END(WHAT) \
- xgettimeofday(&finished##WHAT, 0); \
- times.WHAT = tvadd(times.WHAT, tvsub(finished##WHAT, started##WHAT)); \
-} while(0)
-
-#define INIT() memset(×, 0, sizeof times)
-
-#define REPORT() do { \
- fprintf(stderr, "total=%g\n" \
- "gtkbits=%g\n" \
- "menuupdate=%g\n" \
- "new_widgets=%g\n" \
- "undisplay=%g\n" \
- "colors=%g\n" \
- "markers=%g\n" \
- "location=%g\n" \
- "selection=%g\n" \
- "accumulation=%g\n" \
- "\n", \
- tvdouble(times.total), \
- tvdouble(times.gtkbits), \
- tvdouble(times.menuupdate), \
- tvdouble(times.new_widgets), \
- tvdouble(times.undisplay), \
- tvdouble(times.colors), \
- tvdouble(times.markers), \
- tvdouble(times.location), \
- tvdouble(times.selection), \
- (tvdouble(times.gtkbits) \
- + tvdouble(times.menuupdate) \
- + tvdouble(times.new_widgets) \
- + tvdouble(times.undisplay) \
- + tvdouble(times.colors) \
- + tvdouble(times.markers) \
- + tvdouble(times.location) \
- + tvdouble(times.selection))); \
-} while(0)
-#else
-#define BEGIN(WHAT) do {
-#define END(WHAT) } while(0)
-#define INIT() ((void)0)
-#define REPORT() ((void)0)
-#endif
-
-WT(label);
-WT(event_box);
-WT(menu);
-WT(menu_item);
-WT(layout);
-WT(vbox);
-WT(arrow);
-WT(hbox);
-WT(button);
-WT(image);
-WT(entry);
-
-/* Types */
-
-struct choosenode;
-
-/** @brief Accumulated information about the tree widget */
-struct displaydata {
- /** @brief Maximum width required */
- guint width;
- /** @brief Maximum height required */
- guint height;
-};
-
-/* instantiate the node vector type */
-
-VECTOR_TYPE(nodevector, struct choosenode *, xrealloc);
-
-/** @brief Signature of function called when a choosenode is filled */
-typedef void (when_filled_callback)(struct choosenode *cn,
- void *wfu);
-
-/** @brief One node in the virtual filesystem */
-struct choosenode {
- struct choosenode *parent; /**< @brief parent node */
- const char *path; /**< @brief full path or 0 */
- const char *sort; /**< @brief sort key */
- const char *display; /**< @brief display name */
- int pending; /**< @brief pending resolve queries */
- unsigned flags;
-#define CN_EXPANDABLE 0x0001 /**< @brief node is expandable */
-#define CN_EXPANDED 0x0002 /**< @brief node is expanded
- *
- * Expandable items are directories;
- * non-expandable ones are files. */
-#define CN_DISPLAYED 0x0004 /**< @brief widget is displayed in layout */
-#define CN_SELECTED 0x0008 /**< @brief node is selected */
-#define CN_GETTING_FILES 0x0010 /**< @brief files inbound */
-#define CN_RESOLVING_FILES 0x0020 /**< @brief resolved files inbound */
-#define CN_GETTING_DIRS 0x0040 /**< @brief directories inbound */
-#define CN_GETTING_ANY 0x0070 /**< @brief getting something */
-#define CN_CONTINGENT 0x0080 /**< @brief expansion contingent on search */
- struct nodevector children; /**< @brief vector of children */
- void (*fill)(struct choosenode *); /**< @brief request child fill or 0 for leaf */
- GtkWidget *container; /**< @brief the container for this row */
- GtkWidget *hbox; /**< @brief the hbox for this row */
- GtkWidget *arrow; /**< @brief arrow widget or 0 */
- GtkWidget *label; /**< @brief text label for this node */
- GtkWidget *marker; /**< @brief queued marker */
-
- when_filled_callback *whenfilled; /**< @brief called when filled or 0 */
- void *wfu; /**< @brief passed to @c whenfilled */
- int ymin; /**< @brief least Y value */
- int ymax; /**< @brief greatest Y value */
-};
-
-/** @brief One item in the popup menu */
-struct choose_menuitem {
- /* Parameters */
- const char *name; /**< @brief name */
-
- /* Callbacks */
- void (*activate)(GtkMenuItem *menuitem, gpointer user_data);
- /**< @brief Called to activate the menu item.
- *
- * @p user_data is the choosenode the mouse pointer is over. */
-
- gboolean (*sensitive)(struct choosenode *cn);
- /* @brief Called to determine whether the menu item should be sensitive.
- *
- * TODO? */
-
- /* State */
- gulong handlerid; /**< @brief signal handler ID */
- GtkWidget *w; /**< @brief menu item widget */
-};
-
-/* Variables */
-
-static GtkWidget *chooselayout;
-static GtkAdjustment *vadjust;
-static GtkWidget *searchentry; /**< @brief search terms */
-static GtkWidget *nextsearch; /**< @brief next search result */
-static GtkWidget *prevsearch; /**< @brief previous search result */
-static struct choosenode *root;
-static GtkWidget *track_menu; /**< @brief track popup menu */
-static GtkWidget *dir_menu; /**< @brief directory popup menu */
-static struct choosenode *last_click; /**< @brief last clicked node for selection */
-static int files_visible; /**< @brief total files visible */
-static int files_selected; /**< @brief total files selected */
-static int gets_in_flight; /**< @brief total gets in flight */
-static int search_in_flight; /**< @brief a search is underway */
-static int search_obsolete; /**< @brief the current search is void */
-static char **searchresults; /**< @brief search results */
-static int nsearchresults; /**< @brief number of results */
-static int nsearchvisible; /**< @brief number of search results visible */
-static struct hash *searchhash; /**< @brief hash of search results */
-static struct progress_window *spw; /**< @brief progress window */
-static struct choosenode **searchnodes; /**< @brief choosenodes of search results */
-static int suppress_redisplay; /**< @brief suppress redisplay */
-
-/* Forward Declarations */
-
-static void clear_children(struct choosenode *cn);
-static struct choosenode *newnode(struct choosenode *parent,
- const char *path,
- const char *display,
- const char *sort,
- unsigned flags,
- void (*fill)(struct choosenode *));
-static void fill_root_node(struct choosenode *cn);
-static void fill_directory_node(struct choosenode *cn);
-static void got_files(void *v, int nvec, char **vec);
-static void got_resolved_file(void *v, const char *track);
-static void got_dirs(void *v, int nvec, char **vec);
-
-static void expand_node(struct choosenode *cn, int contingent);
-static void contract_node(struct choosenode *cn);
-static void updated_node(struct choosenode *cn, int redisplay,
- const char *why);
-
-static void display_selection(struct choosenode *cn);
-static void clear_selection(struct choosenode *cn);
-
-static void redisplay_tree(const char *why);
-static struct displaydata display_tree(struct choosenode *cn, int x, int y);
-static void undisplay_tree(struct choosenode *cn);
-static void initiate_search(void);
-static void delete_widgets(struct choosenode *cn);
-static void expand_from(struct choosenode *cn);
-static struct choosenode *first_search_result(struct choosenode *cn);
-
-static void clicked_choosenode(GtkWidget attribute((unused)) *widget,
- GdkEventButton *event,
- gpointer user_data);
-
-static void activate_track_play(GtkMenuItem *menuitem, gpointer user_data);
-static void activate_track_properties(GtkMenuItem *menuitem, gpointer user_data);
-
-static gboolean sensitive_track_play(struct choosenode *cn);
-static gboolean sensitive_track_properties(struct choosenode *cn);
-
-static void activate_dir_play(GtkMenuItem *menuitem, gpointer user_data);
-static void activate_dir_properties(GtkMenuItem *menuitem, gpointer user_data);
-static void activate_dir_select(GtkMenuItem *menuitem, gpointer user_data);
-
-static gboolean sensitive_dir_play(struct choosenode *cn);
-static gboolean sensitive_dir_properties(struct choosenode *cn);
-static gboolean sensitive_dir_select(struct choosenode *cn);