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