chiark / gitweb /
DisOrder 4.1
[disorder] / disobedience / choose.c
1 /*
2  * This file is part of DisOrder
3  * Copyright (C) 2008 Richard Kettlewell
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 /** @file disobedience/choose.c
21  * @brief Hierarchical track selection and search
22  *
23  * We now use an ordinary GtkTreeStore/GtkTreeView.
24  *
25  * We don't want to pull the entire tree in memory, but we want directories to
26  * show up as having children.  Therefore we give directories a placeholder
27  * child and replace their children when they are opened.  Placeholders have
28  * TRACK_COLUMN="" and ISFILE_COLUMN=FALSE (so that they don't get check boxes,
29  * lengths, etc).
30  *
31  * TODO:
32  * - sweep up contracted nodes, replacing their content with a placeholder
33  */
34
35 #include "disobedience.h"
36 #include "choose.h"
37 #include <gdk/gdkkeysyms.h>
38
39 /** @brief The current selection tree */
40 GtkTreeStore *choose_store;
41
42 /** @brief The view onto the selection tree */
43 GtkWidget *choose_view;
44
45 /** @brief The selection tree's selection */
46 GtkTreeSelection *choose_selection;
47
48 /** @brief Count of file listing operations in flight */
49 static int choose_list_in_flight;
50
51 /** @brief If nonzero autocollapse column won't be set */
52 static int choose_suppress_set_autocollapse;
53
54 static char *choose_get_string(GtkTreeIter *iter, int column) {
55   gchar *gs;
56   gtk_tree_model_get(GTK_TREE_MODEL(choose_store), iter,
57                      column, &gs,
58                      -1);
59   char *s = xstrdup(gs);
60   g_free(gs);
61   return s;
62 }
63
64 char *choose_get_track(GtkTreeIter *iter) {
65   char *s = choose_get_string(iter, TRACK_COLUMN);
66   return *s ? s : 0;                    /* Placeholder -> NULL */
67 }
68
69 char *choose_get_sort(GtkTreeIter *iter) {
70   return choose_get_string(iter, SORT_COLUMN);
71 }
72
73 char *choose_get_display(GtkTreeIter *iter) {
74   return choose_get_string(iter, NAME_COLUMN);
75 }
76
77 int choose_is_file(GtkTreeIter *iter) {
78   gboolean isfile;
79   gtk_tree_model_get(GTK_TREE_MODEL(choose_store), iter,
80                      ISFILE_COLUMN, &isfile,
81                      -1);
82   return isfile;
83 }
84
85 int choose_is_dir(GtkTreeIter *iter) {
86   gboolean isfile;
87   gtk_tree_model_get(GTK_TREE_MODEL(choose_store), iter,
88                      ISFILE_COLUMN, &isfile,
89                      -1);
90   if(isfile)
91     return FALSE;
92   return !choose_is_placeholder(iter);
93 }
94
95 int choose_is_placeholder(GtkTreeIter *iter) {
96   return choose_get_string(iter, TRACK_COLUMN)[0] == 0;
97 }
98
99 int choose_can_autocollapse(GtkTreeIter *iter) {
100   gboolean autocollapse;
101   gtk_tree_model_get(GTK_TREE_MODEL(choose_store), iter,
102                      AUTOCOLLAPSE_COLUMN, &autocollapse,
103                      -1);
104   return autocollapse;
105 }
106
107 /** @brief Remove node @p it and all its children
108  * @param Iterator, updated to point to next
109  * @return True if iterator remains valid
110  *
111  * TODO is this necessary?  gtk_tree_store_remove() does not document what
112  * happens to children.
113  */
114 static gboolean choose_remove_node(GtkTreeIter *it) {
115   GtkTreeIter child[1];
116   gboolean childv = gtk_tree_model_iter_children(GTK_TREE_MODEL(choose_store),
117                                                  child,
118                                                  it);
119   while(childv)
120     childv = choose_remove_node(child);
121   return gtk_tree_store_remove(choose_store, it);
122 }
123
124 /** @brief Update length and state fields */
125 static gboolean choose_set_state_callback(GtkTreeModel attribute((unused)) *model,
126                                           GtkTreePath attribute((unused)) *path,
127                                           GtkTreeIter *it,
128                                           gpointer attribute((unused)) data) {
129   if(choose_is_file(it)) {
130     const char *track = choose_get_track(it);
131     const long l = namepart_length(track);
132     char length[64];
133     if(l > 0)
134       byte_snprintf(length, sizeof length, "%ld:%02ld", l / 60, l % 60);
135     else
136       length[0] = 0;
137     gtk_tree_store_set(choose_store, it,
138                        LENGTH_COLUMN, length,
139                        STATE_COLUMN, queued(track),
140                        -1);
141     if(choose_is_search_result(track))
142       gtk_tree_store_set(choose_store, it,
143                          BG_COLUMN, SEARCH_RESULT_BG,
144                          FG_COLUMN, SEARCH_RESULT_FG,
145                          -1);
146     else
147       gtk_tree_store_set(choose_store, it,
148                          BG_COLUMN, (char *)0,
149                          FG_COLUMN, (char *)0,
150                          -1);
151   }
152   return FALSE;                         /* continue walking */
153 }
154
155 /** @brief Called when the queue or playing track change */
156 static void choose_set_state(const char attribute((unused)) *event,
157                              void attribute((unused)) *eventdata,
158                              void attribute((unused)) *callbackdata) {
159   gtk_tree_model_foreach(GTK_TREE_MODEL(choose_store),
160                          choose_set_state_callback,
161                          NULL);
162 }
163
164 /** @brief (Re-)populate a node
165  * @param parent_ref Node to populate or NULL to fill root
166  * @param nvec Number of children to add
167  * @param vec Children
168  * @param files 1 if children are files, 0 if directories
169  *
170  * Adjusts the set of files (or directories) below @p parent_ref to match those
171  * listed in @p nvec and @p vec.
172  *
173  * @parent_ref will be destroyed.
174  */
175 static void choose_populate(GtkTreeRowReference *parent_ref,
176                             int nvec, char **vec,
177                             int isfile) {
178   const char *type = isfile ? "track" : "dir";
179   //fprintf(stderr, "%d new children of type %s\n", nvec, type);
180   if(!nvec)
181     goto skip;
182   /* Compute parent_* */
183   GtkTreeIter pit[1], *parent_it;
184   GtkTreePath *parent_path;
185   if(parent_ref) {
186     parent_path = gtk_tree_row_reference_get_path(parent_ref);
187     parent_it = pit;
188     gboolean pitv = gtk_tree_model_get_iter(GTK_TREE_MODEL(choose_store),
189                                             pit, parent_path);
190     assert(pitv);
191     /*fprintf(stderr, "choose_populate %s: parent path is [%s]\n",
192             type,
193             gtk_tree_path_to_string(parent_path));*/
194   } else {
195     parent_path = 0;
196     parent_it = 0;
197     /*fprintf(stderr, "choose_populate %s: populating the root\n",
198             type);*/
199   }
200   /* Both td[] and the current node set are sorted so we can do a single linear
201    * pass to insert new nodes and remove unwanted ones.  The total performance
202    * may be worse than linear depending on the performance of GTK+'s insert and
203    * delete operations. */
204   //fprintf(stderr, "sorting tracks\n");
205   struct tracksort_data *td = tracksort_init(nvec, vec, type);
206   GtkTreeIter it[1];
207   gboolean itv = gtk_tree_model_iter_children(GTK_TREE_MODEL(choose_store),
208                                               it,
209                                               parent_it);
210   int inserted = 0, deleted_placeholder = 0;
211   //fprintf(stderr, "inserting tracks type=%s\n", type);
212   while(nvec > 0 || itv) {
213     /*fprintf(stderr, "td[] = %s, it=%s [%s]\n",
214             nvec > 0 ? td->track : "(none)",
215             itv ? choose_get_track(it) : "(!itv)",
216             itv ? (choose_is_file(it) ? "file" : "dir") : "");*/
217     enum { INSERT, DELETE, SKIP_TREE, SKIP_BOTH } action;
218     const char *track = itv ? choose_get_track(it) : 0;
219     if(itv && !track) {
220       //fprintf(stderr, " placeholder\n");
221       action = DELETE;
222       ++deleted_placeholder;
223     } else if(nvec > 0 && itv) {
224       /* There's both a tree row and a td[] entry */
225       const int cmp = compare_tracks(td->sort, choose_get_sort(it),
226                                      td->display, choose_get_display(it),
227                                      td->track, track);
228       //fprintf(stderr, " cmp=%d\n", cmp);
229       if(cmp < 0)
230         /* td < it, so we insert td before it */
231         action = INSERT;
232       else if(cmp > 0) {
233         /* td > it, so we must either delete it (if the same type) or skip it */
234         if(choose_is_file(it) == isfile)
235           action = DELETE;
236         else
237           action = SKIP_TREE;
238       } else
239         /* td = it, so we step past both */
240         action = SKIP_BOTH;
241     } else if(nvec > 0) {
242       /* We've reached the end of the tree rows, but new have tracks left in
243        * td[] */
244       //fprintf(stderr, " inserting\n");
245       action = INSERT;
246     } else {
247       /* We've reached the end of the new tracks from td[], but there are
248        * further tracks in the tree */
249       //fprintf(stderr, " deleting\n");
250       if(choose_is_file(it) == isfile)
251         action = DELETE;
252       else
253         action = SKIP_TREE;
254     }
255     
256     switch(action) {
257     case INSERT: {
258       //fprintf(stderr, " INSERT %s\n", td->track);
259       /* Insert a new row from td[] before it, or at the end if it is no longer
260        * valid */
261       GtkTreeIter child[1];
262       gtk_tree_store_insert_before(choose_store,
263                                    child, /* new row */
264                                    parent_it, /* parent */
265                                    itv ? it : NULL); /* successor */
266       gtk_tree_store_set(choose_store, child,
267                          NAME_COLUMN, td->display,
268                          ISFILE_COLUMN, isfile,
269                          TRACK_COLUMN, td->track,
270                          SORT_COLUMN, td->sort,
271                          AUTOCOLLAPSE_COLUMN, FALSE,
272                          -1);
273       /* Update length and state; we expect this to kick off length lookups
274        * rather than necessarily get the right value the first time round. */
275       choose_set_state_callback(0, 0, child, 0);
276       /* If we inserted a directory, insert a placeholder too, so it appears to
277        * have children; it will be deleted when we expand the directory. */
278       if(!isfile) {
279         //fprintf(stderr, "  inserting a placeholder\n");
280         GtkTreeIter placeholder[1];
281
282         gtk_tree_store_append(choose_store, placeholder, child);
283         gtk_tree_store_set(choose_store, placeholder,
284                            NAME_COLUMN, "Waddling...",
285                            TRACK_COLUMN, "",
286                            ISFILE_COLUMN, FALSE,
287                            -1);
288       }
289       ++inserted;
290       ++td;
291       --nvec;
292       break;
293     }
294     case SKIP_BOTH:
295       //fprintf(stderr, " SKIP_BOTH\n");
296       ++td;
297       --nvec;
298       /* fall thru */
299     case SKIP_TREE:
300       //fprintf(stderr, " SKIP_TREE\n");
301       itv = gtk_tree_model_iter_next(GTK_TREE_MODEL(choose_store), it);
302       break;
303     case DELETE:
304       //fprintf(stderr, " DELETE\n");
305       itv = choose_remove_node(it);
306       break;
307     }
308   }
309   /*fprintf(stderr, "inserted=%d deleted_placeholder=%d\n\n",
310           inserted, deleted_placeholder);*/
311   if(parent_ref) {
312     /* If we deleted a placeholder then we must re-expand the row */
313     if(deleted_placeholder) {
314       ++choose_suppress_set_autocollapse;
315       gtk_tree_view_expand_row(GTK_TREE_VIEW(choose_view), parent_path, FALSE);
316       --choose_suppress_set_autocollapse;
317     }
318     gtk_tree_row_reference_free(parent_ref);
319     gtk_tree_path_free(parent_path);
320   }
321 skip:
322   /* We only notify others that we've inserted tracks when there are no more
323    * insertions pending, so that they don't have to keep track of how many
324    * requests they've made.  */
325   if(--choose_list_in_flight == 0) {
326     /* Notify interested parties that we inserted some tracks, AFTER making
327      * sure that the row is properly expanded */
328     //fprintf(stderr, "raising choose-more-tracks\n");
329     event_raise("choose-more-tracks", 0);
330   }
331   //fprintf(stderr, "choose_list_in_flight -> %d-\n", choose_list_in_flight);
332 }
333
334 static void choose_dirs_completed(void *v,
335                                   const char *err,
336                                   int nvec, char **vec) {
337   if(err) {
338     popup_protocol_error(0, err);
339     return;
340   }
341   choose_populate(v, nvec, vec, 0/*!isfile*/);
342 }
343
344 static void choose_files_completed(void *v,
345                                    const char *err,
346                                    int nvec, char **vec) {
347   if(err) {
348     popup_protocol_error(0, err);
349     return;
350   }
351   choose_populate(v, nvec, vec, 1/*isfile*/);
352 }
353
354 void choose_play_completed(void attribute((unused)) *v,
355                            const char *err) {
356   if(err)
357     popup_protocol_error(0, err);
358 }
359
360 static void choose_state_toggled
361     (GtkCellRendererToggle attribute((unused)) *cell_renderer,
362      gchar *path_str,
363      gpointer attribute((unused)) user_data) {
364   GtkTreeIter it[1];
365   /* Identify the track */
366   gboolean itv =
367     gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(choose_store),
368                                         it,
369                                         path_str);
370   if(!itv)
371     return;
372   if(!choose_is_file(it))
373     return;
374   const char *track = choose_get_track(it);
375   if(queued(track))
376     return;
377   disorder_eclient_play(client, track, choose_play_completed, 0);
378   
379 }
380
381 /** @brief (Re-)get the children of @p path
382  * @param path Path to target row
383  * @param iter Iterator pointing at target row
384  *
385  * Called from choose_row_expanded() to make sure that the contents are present
386  * and from choose_refill_callback() to (re-)synchronize.
387  */
388 static void choose_refill_row(GtkTreePath *path,
389                               GtkTreeIter *iter) {
390   const char *track = choose_get_track(iter);
391   disorder_eclient_files(client, choose_files_completed,
392                          track,
393                          NULL,
394                          gtk_tree_row_reference_new(GTK_TREE_MODEL(choose_store),
395                                                     path));
396   disorder_eclient_dirs(client, choose_dirs_completed,
397                         track,
398                         NULL,
399                         gtk_tree_row_reference_new(GTK_TREE_MODEL(choose_store),
400                                                    path));
401   /* The row references are destroyed in the _completed handlers. */
402   choose_list_in_flight += 2;
403 }
404
405 static void choose_row_expanded(GtkTreeView attribute((unused)) *treeview,
406                                 GtkTreeIter *iter,
407                                 GtkTreePath *path,
408                                 gpointer attribute((unused)) user_data) {
409   /*fprintf(stderr, "row-expanded path=[%s]\n\n",
410           gtk_tree_path_to_string(path));*/
411   /* We update a node's contents whenever it is expanded, even if it was
412    * already populated; the effect is that contracting and expanding a node
413    * suffices to update it to the latest state on the server. */
414   choose_refill_row(path, iter);
415   if(!choose_suppress_set_autocollapse) {
416     if(choose_auto_expanding) {
417       /* This was an automatic expansion; mark it the row for auto-collapse. */
418       gtk_tree_store_set(choose_store, iter,
419                          AUTOCOLLAPSE_COLUMN, TRUE,
420                          -1);
421       /*fprintf(stderr, "enable auto-collapse for %s\n",
422               gtk_tree_path_to_string(path));*/
423     } else {
424       /* This was a manual expansion.  Inhibit automatic collapse on this row
425        * and all its ancestors.  */
426       gboolean itv;
427       do {
428         gtk_tree_store_set(choose_store, iter,
429                            AUTOCOLLAPSE_COLUMN, FALSE,
430                            -1);
431         /*fprintf(stderr, "suppress auto-collapse for %s\n",
432                 gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(choose_store),
433                                                     iter));*/
434         GtkTreeIter child = *iter;
435         itv = gtk_tree_model_iter_parent(GTK_TREE_MODEL(choose_store),
436                                          iter,
437                                          &child);
438       } while(itv);
439       /* The effect of this is that if you expand a row that's actually a
440        * sibling of the real target of the auto-expansion, it stays expanded
441        * when you clear a search.  That's find and good, but it _still_ stays
442        * expanded if you expand it and then collapse it.
443        *
444        * An alternative policy would be to only auto-collapse rows that don't
445        * have any expanded children (apart from ones also subject to
446        * auto-collapse).  I'm not sure what the most usable policy is.
447        */
448     }
449   }
450 }
451
452 static void choose_auto_collapse_callback(GtkTreeView *tree_view,
453                                           GtkTreePath *path,
454                                           gpointer attribute((unused)) user_data) {
455   GtkTreeIter it[1];
456
457   gtk_tree_model_get_iter(GTK_TREE_MODEL(choose_store), it, path);
458   if(choose_can_autocollapse(it)) {
459     /*fprintf(stderr, "collapse %s\n",
460             gtk_tree_path_to_string(path));*/
461     gtk_tree_store_set(choose_store, it,
462                        AUTOCOLLAPSE_COLUMN, FALSE,
463                        -1);
464     gtk_tree_view_collapse_row(tree_view, path);
465   }
466 }
467
468 /** @brief Perform automatic collapse after a search is cleared */
469 void choose_auto_collapse(void) {
470   gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(choose_view),
471                                   choose_auto_collapse_callback,
472                                   0);
473 }
474
475 /** @brief Called from choose_refill() with each expanded row */
476 static void choose_refill_callback(GtkTreeView attribute((unused)) *tree_view,
477                                    GtkTreePath *path,
478                                    gpointer attribute((unused)) user_data) {
479   GtkTreeIter it[1];
480
481   gtk_tree_model_get_iter(GTK_TREE_MODEL(choose_store), it, path);
482   choose_refill_row(path, it);
483 }
484
485 /** @brief Synchronize all visible data with the server
486  *
487  * Called at startup, when a rescan completes, and via periodic_slow().
488  */
489 static void choose_refill(const char attribute((unused)) *event,
490                           void attribute((unused)) *eventdata,
491                           void attribute((unused)) *callbackdata) {
492   //fprintf(stderr, "choose_refill\n");
493   /* Update the root */
494   disorder_eclient_files(client, choose_files_completed, "", NULL, NULL); 
495   disorder_eclient_dirs(client, choose_dirs_completed, "", NULL, NULL); 
496   choose_list_in_flight += 2;
497   /* Update all expanded rows */
498   gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(choose_view),
499                                   choose_refill_callback,
500                                   0);
501   //fprintf(stderr, "choose_list_in_flight -> %d+\n", choose_list_in_flight);
502 }
503
504 /** @brief Called for key-*-event on the main view
505  */
506 static gboolean choose_key_event(GtkWidget attribute((unused)) *widget,
507                                  GdkEventKey *event,
508                                  gpointer attribute((unused)) user_data) {
509   /*fprintf(stderr, "choose_key_event type=%d state=%#x keyval=%#x\n",
510           event->type, event->state, event->keyval);*/
511   switch(event->keyval) {
512   case GDK_Page_Up:
513   case GDK_Page_Down:
514   case GDK_Up:
515   case GDK_Down:
516   case GDK_Home:
517   case GDK_End:
518     return FALSE;                       /* We'll take these */
519   case 'f': case 'F':
520     /* ^F is expected to start a search.  We implement this by focusing the
521      * search entry box. */
522     if((event->state & ~(GDK_LOCK_MASK|GDK_SHIFT_MASK)) == GDK_CONTROL_MASK
523        && event->type == GDK_KEY_PRESS) {
524       choose_search_new();
525       return TRUE;                      /* Handled it */
526     }
527     break;
528   case 'g': case 'G':
529     /* ^G is expected to go the next match.  We simulate a click on the 'next'
530      * button. */
531     if((event->state & ~(GDK_LOCK_MASK|GDK_SHIFT_MASK)) == GDK_CONTROL_MASK
532        && event->type == GDK_KEY_PRESS) {
533       choose_next_clicked(0, 0);
534       return TRUE;                      /* Handled it */
535     }
536     break;
537   }
538   gtk_widget_event(user_data, (GdkEvent *)event);
539   return TRUE;                          /* Handled it */
540 }
541
542 /** @brief Create the choose tab */
543 GtkWidget *choose_widget(void) {
544   /* Create the tree store. */
545   choose_store = gtk_tree_store_new(CHOOSE_COLUMNS,
546                                     G_TYPE_BOOLEAN,
547                                     G_TYPE_STRING,
548                                     G_TYPE_STRING,
549                                     G_TYPE_BOOLEAN,
550                                     G_TYPE_STRING,
551                                     G_TYPE_STRING,
552                                     G_TYPE_STRING,
553                                     G_TYPE_STRING,
554                                     G_TYPE_BOOLEAN);
555
556   /* Create the view */
557   choose_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(choose_store));
558   gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(choose_view), TRUE);
559   /* Suppress built-in typeahead find, we do our own search support. */
560   gtk_tree_view_set_enable_search(GTK_TREE_VIEW(choose_view), FALSE);
561
562   /* Create cell renderers and columns */
563   /* TODO use a table */
564   {
565     GtkCellRenderer *r = gtk_cell_renderer_toggle_new();
566     GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes
567       ("Queued",
568        r,
569        "active", STATE_COLUMN,
570        "visible", ISFILE_COLUMN,
571        (char *)0);
572     gtk_tree_view_column_set_resizable(c, TRUE);
573     gtk_tree_view_column_set_reorderable(c, TRUE);
574     gtk_tree_view_append_column(GTK_TREE_VIEW(choose_view), c);
575     g_signal_connect(r, "toggled",
576                      G_CALLBACK(choose_state_toggled), 0);
577   }
578   {
579     GtkCellRenderer *r = gtk_cell_renderer_text_new();
580     GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes
581       ("Length",
582        r,
583        "text", LENGTH_COLUMN,
584        (char *)0);
585     gtk_tree_view_column_set_resizable(c, TRUE);
586     gtk_tree_view_column_set_reorderable(c, TRUE);
587     g_object_set(r, "xalign", (gfloat)1.0, (char *)0);
588     gtk_tree_view_append_column(GTK_TREE_VIEW(choose_view), c);
589   }
590   {
591     GtkCellRenderer *r = gtk_cell_renderer_text_new();
592     GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes
593       ("Track",
594        r,
595        "text", NAME_COLUMN,
596        "background", BG_COLUMN,
597        "foreground", FG_COLUMN,
598        (char *)0);
599     gtk_tree_view_column_set_resizable(c, TRUE);
600     gtk_tree_view_column_set_reorderable(c, TRUE);
601     g_object_set(c, "expand", TRUE, (char *)0);
602     gtk_tree_view_append_column(GTK_TREE_VIEW(choose_view), c);
603     gtk_tree_view_set_expander_column(GTK_TREE_VIEW(choose_view), c);
604   }
605   
606   /* The selection should support multiple things being selected */
607   choose_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(choose_view));
608   gtk_tree_selection_set_mode(choose_selection, GTK_SELECTION_MULTIPLE);
609
610   /* Catch button presses */
611   g_signal_connect(choose_view, "button-press-event",
612                    G_CALLBACK(choose_button_event), 0);
613   g_signal_connect(choose_view, "button-release-event",
614                    G_CALLBACK(choose_button_event), 0);
615   /* Catch row expansions so we can fill in placeholders */
616   g_signal_connect(choose_view, "row-expanded",
617                    G_CALLBACK(choose_row_expanded), 0);
618
619   event_register("queue-list-changed", choose_set_state, 0);
620   event_register("playing-track-changed", choose_set_state, 0);
621   event_register("search-results-changed", choose_set_state, 0);
622   event_register("lookups-completed", choose_set_state, 0);
623
624   /* After a rescan we update the choose tree.  We get a rescan-complete
625    * automatically at startup and upon connection too. */
626   event_register("rescan-complete", choose_refill, 0);
627
628   /* Make the widget scrollable */
629   GtkWidget *scrolled = scroll_widget(choose_view);
630
631   /* Pack vertically with the search widget */
632   GtkWidget *vbox = gtk_vbox_new(FALSE/*homogenous*/, 1/*spacing*/);
633   gtk_box_pack_start(GTK_BOX(vbox), scrolled,
634                      TRUE/*expand*/, TRUE/*fill*/, 0/*padding*/);
635   gtk_box_pack_end(GTK_BOX(vbox), choose_search_widget(),
636                    FALSE/*expand*/, FALSE/*fill*/, 0/*padding*/);
637   
638   g_object_set_data(G_OBJECT(vbox), "type", (void *)&choose_tabtype);
639
640   /* Redirect keyboard activity to the search widget */
641   g_signal_connect(choose_view, "key-press-event",
642                    G_CALLBACK(choose_key_event), choose_search_entry);
643   g_signal_connect(choose_view, "key-release-event",
644                    G_CALLBACK(choose_key_event), choose_search_entry);
645
646   return vbox;
647 }
648
649 /*
650 Local Variables:
651 c-basic-offset:2
652 comment-column:40
653 fill-column:79
654 indent-tabs-mode:nil
655 End:
656 */