3 * This file is part of DisOrder
4 * Copyright (C) 2006-2008 Richard Kettlewell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 /** @file disobedience/choose.c
22 * @brief Hierarchical track selection and search
24 * We don't use the built-in tree widgets because they require that you know
25 * the children of a node on demand, and we have to wait for the server to tell
29 #include "disobedience.h"
32 /* Choose track ------------------------------------------------------------ */
38 struct timeval gtkbits
;
39 struct timeval menuupdate
;
40 struct timeval new_widgets
;
41 struct timeval undisplay
;
42 struct timeval colors
;
43 struct timeval markers
;
44 struct timeval location
;
45 struct timeval selection
;
48 #define BEGIN(WHAT) do { \
49 struct timeval started##WHAT, finished##WHAT; \
50 xgettimeofday(&started##WHAT, 0)
53 xgettimeofday(&finished##WHAT, 0); \
54 times.WHAT = tvadd(times.WHAT, tvsub(finished##WHAT, started##WHAT)); \
57 #define INIT() memset(×, 0, sizeof times)
59 #define REPORT() do { \
60 fprintf(stderr, "total=%g\n" \
71 tvdouble(times.total), \
72 tvdouble(times.gtkbits), \
73 tvdouble(times.menuupdate), \
74 tvdouble(times.new_widgets), \
75 tvdouble(times.undisplay), \
76 tvdouble(times.colors), \
77 tvdouble(times.markers), \
78 tvdouble(times.location), \
79 tvdouble(times.selection), \
80 (tvdouble(times.gtkbits) \
81 + tvdouble(times.menuupdate) \
82 + tvdouble(times.new_widgets) \
83 + tvdouble(times.undisplay) \
84 + tvdouble(times.colors) \
85 + tvdouble(times.markers) \
86 + tvdouble(times.location) \
87 + tvdouble(times.selection))); \
90 #define BEGIN(WHAT) do {
91 #define END(WHAT) } while(0)
92 #define INIT() ((void)0)
93 #define REPORT() ((void)0)
112 /** @brief Accumulated information about the tree widget */
114 /** @brief Maximum width required */
116 /** @brief Maximum height required */
120 /* instantiate the node vector type */
122 VECTOR_TYPE(nodevector
, struct choosenode
*, xrealloc
);
124 /** @brief Signature of function called when a choosenode is filled */
125 typedef void (when_filled_callback
)(struct choosenode
*cn
,
128 /** @brief One node in the virtual filesystem */
130 struct choosenode
*parent
; /**< @brief parent node */
131 const char *path
; /**< @brief full path or 0 */
132 const char *sort
; /**< @brief sort key */
133 const char *display
; /**< @brief display name */
134 int pending
; /**< @brief pending resolve queries */
136 #define CN_EXPANDABLE 0x0001 /**< @brief node is expandable */
137 #define CN_EXPANDED 0x0002 /**< @brief node is expanded
139 * Expandable items are directories;
140 * non-expandable ones are files. */
141 #define CN_DISPLAYED 0x0004 /**< @brief widget is displayed in layout */
142 #define CN_SELECTED 0x0008 /**< @brief node is selected */
143 #define CN_GETTING_FILES 0x0010 /**< @brief files inbound */
144 #define CN_RESOLVING_FILES 0x0020 /**< @brief resolved files inbound */
145 #define CN_GETTING_DIRS 0x0040 /**< @brief directories inbound */
146 #define CN_GETTING_ANY 0x0070 /**< @brief getting something */
147 #define CN_CONTINGENT 0x0080 /**< @brief expansion contingent on search */
148 struct nodevector children
; /**< @brief vector of children */
149 void (*fill
)(struct choosenode
*); /**< @brief request child fill or 0 for leaf */
150 GtkWidget
*container
; /**< @brief the container for this row */
151 GtkWidget
*hbox
; /**< @brief the hbox for this row */
152 GtkWidget
*arrow
; /**< @brief arrow widget or 0 */
153 GtkWidget
*label
; /**< @brief text label for this node */
154 GtkWidget
*marker
; /**< @brief queued marker */
156 when_filled_callback
*whenfilled
; /**< @brief called when filled or 0 */
157 void *wfu
; /**< @brief passed to @c whenfilled */
158 int ymin
; /**< @brief least Y value */
159 int ymax
; /**< @brief greatest Y value */
162 /** @brief One item in the popup menu */
163 struct choose_menuitem
{
165 const char *name
; /**< @brief name */
168 void (*activate
)(GtkMenuItem
*menuitem
, gpointer user_data
);
169 /**< @brief Called to activate the menu item.
171 * @p user_data is the choosenode the mouse pointer is over. */
173 gboolean (*sensitive
)(struct choosenode
*cn
);
174 /* @brief Called to determine whether the menu item should be sensitive.
179 gulong handlerid
; /**< @brief signal handler ID */
180 GtkWidget
*w
; /**< @brief menu item widget */
185 static GtkWidget
*chooselayout
;
186 static GtkAdjustment
*vadjust
;
187 static GtkWidget
*searchentry
; /**< @brief search terms */
188 static GtkWidget
*nextsearch
; /**< @brief next search result */
189 static GtkWidget
*prevsearch
; /**< @brief previous search result */
190 static struct choosenode
*root
;
191 static GtkWidget
*track_menu
; /**< @brief track popup menu */
192 static GtkWidget
*dir_menu
; /**< @brief directory popup menu */
193 static struct choosenode
*last_click
; /**< @brief last clicked node for selection */
194 static int files_visible
; /**< @brief total files visible */
195 static int files_selected
; /**< @brief total files selected */
196 static int gets_in_flight
; /**< @brief total gets in flight */
197 static int search_in_flight
; /**< @brief a search is underway */
198 static int search_obsolete
; /**< @brief the current search is void */
199 static char **searchresults
; /**< @brief search results */
200 static int nsearchresults
; /**< @brief number of results */
201 static int nsearchvisible
; /**< @brief number of search results visible */
202 static struct hash
*searchhash
; /**< @brief hash of search results */
203 static struct progress_window
*spw
; /**< @brief progress window */
204 static struct choosenode
**searchnodes
; /**< @brief choosenodes of search results */
205 static int suppress_redisplay
; /**< @brief suppress redisplay */
207 /* Forward Declarations */
209 static void clear_children(struct choosenode
*cn
);
210 static struct choosenode
*newnode(struct choosenode
*parent
,
215 void (*fill
)(struct choosenode
*));
216 static void fill_root_node(struct choosenode
*cn
);
217 static void fill_directory_node(struct choosenode
*cn
);
218 static void got_files(void *v
, const char *error
, int nvec
, char **vec
);
219 static void got_resolved_file(void *v
, const char *error
, const char *track
);
220 static void got_dirs(void *v
, const char *error
, int nvec
, char **vec
);
222 static void expand_node(struct choosenode
*cn
, int contingent
);
223 static void contract_node(struct choosenode
*cn
);
224 static void updated_node(struct choosenode
*cn
, int redisplay
,
227 static void display_selection(struct choosenode
*cn
);
228 static void clear_selection(struct choosenode
*cn
);
230 static void redisplay_tree(const char *why
);
231 static struct displaydata
display_tree(struct choosenode
*cn
, int x
, int y
);
232 static void undisplay_tree(struct choosenode
*cn
);
233 static void initiate_search(void);
234 static void delete_widgets(struct choosenode
*cn
);
235 static void expand_from(struct choosenode
*cn
);
236 static struct choosenode
*first_search_result(struct choosenode
*cn
);
238 static void clicked_choosenode(GtkWidget
attribute((unused
)) *widget
,
239 GdkEventButton
*event
,
242 static void activate_track_play(GtkMenuItem
*menuitem
, gpointer user_data
);
243 static void activate_track_properties(GtkMenuItem
*menuitem
, gpointer user_data
);
245 static gboolean
sensitive_track_play(struct choosenode
*cn
);
246 static gboolean
sensitive_track_properties(struct choosenode
*cn
);
248 static void activate_dir_play(GtkMenuItem
*menuitem
, gpointer user_data
);
249 static void activate_dir_properties(GtkMenuItem
*menuitem
, gpointer user_data
);
250 static void activate_dir_select(GtkMenuItem
*menuitem
, gpointer user_data
);
252 static gboolean
sensitive_dir_play(struct choosenode
*cn
);
253 static gboolean
sensitive_dir_properties(struct choosenode
*cn
);
254 static gboolean
sensitive_dir_select(struct choosenode
*cn
);
256 /** @brief Track menu items */
257 static struct choose_menuitem track_menuitems
[] = {
258 { "Play track", activate_track_play
, sensitive_track_play
, 0, 0 },
259 { "Track properties", activate_track_properties
, sensitive_track_properties
, 0, 0 },
263 /** @brief Directory menu items */
264 static struct choose_menuitem dir_menuitems
[] = {
265 { "Play all tracks", activate_dir_play
, sensitive_dir_play
, 0, 0 },
266 { "Track properties", activate_dir_properties
, sensitive_dir_properties
, 0, 0 },
267 { "Select all tracks", activate_dir_select
, sensitive_dir_select
, 0, 0 },
271 /* Maintaining the data structure ------------------------------------------ */
273 static char *cnflags(const struct choosenode
*cn
) {
274 unsigned f
= cn
->flags
, n
;
277 static const char *bits
[] = {
287 #define NBITS (sizeof bits / sizeof *bits)
291 dynstr_append(d
, '0');
293 for(n
= 0; n
< NBITS
; ++n
) {
294 const unsigned bit
= 1 << n
;
297 dynstr_append(d
, '|');
298 dynstr_append_string(d
, bits
[n
]);
305 dynstr_append(d
, '|');
306 sprintf(buf
, "%#x", f
);
307 dynstr_append_string(d
, buf
);
314 /** @brief Create a new node */
315 static struct choosenode
*newnode(struct choosenode
*parent
,
320 void (*fill
)(struct choosenode
*)) {
321 struct choosenode
*const n
= xmalloc(sizeof *n
);
323 D(("newnode %s %s", path
, display
));
324 if(flags
& CN_EXPANDABLE
)
330 n
->display
= display
;
333 nodevector_init(&n
->children
);
336 nodevector_append(&parent
->children
, n
);
340 /** @brief Called when a node has been filled
342 * Response for calling @c whenfilled.
344 static void filled(struct choosenode
*cn
) {
345 when_filled_callback
*const whenfilled
= cn
->whenfilled
;
349 whenfilled(cn
, cn
->wfu
);
351 if(nsearchvisible
< nsearchresults
) {
352 /* There is still search expansion work to do */
353 D(("filled %s %d/%d", cn
->path
, nsearchvisible
, nsearchresults
));
356 if(gets_in_flight
== 0 && nsearchvisible
< nsearchresults
)
360 /** @brief Fill the root */
361 static void fill_root_node(struct choosenode
*cn
) {
362 D(("fill_root_node"));
364 /* More de-duping possible here */
365 if(cn
->flags
& CN_GETTING_ANY
)
367 gtk_label_set_text(GTK_LABEL(report_label
), "getting files");
368 disorder_eclient_dirs(client
, got_dirs
, "", 0, cn
);
369 disorder_eclient_files(client
, got_files
, "", 0, cn
);
370 cn
->flags
|= CN_GETTING_FILES
|CN_GETTING_DIRS
;
374 /** @brief Delete all the widgets owned by @p cn */
375 static void delete_cn_widgets(struct choosenode
*cn
) {
378 gtk_widget_destroy(cn
->arrow
);
383 gtk_widget_destroy(cn
->label
);
388 gtk_widget_destroy(cn
->marker
);
393 gtk_widget_destroy(cn
->hbox
);
398 gtk_widget_destroy(cn
->container
);
403 /** @brief Recursively clear all the children of @p cn
405 * All the widgets at or below @p cn are deleted. All choosenodes below
406 * it are emptied. i.e. we prune the tree at @p cn.
408 static void clear_children(struct choosenode
*cn
) {
411 D(("clear_children %s", cn
->path
));
412 /* Recursively clear subtrees */
413 for(n
= 0; n
< cn
->children
.nvec
; ++n
) {
414 clear_children(cn
->children
.vec
[n
]);
415 delete_cn_widgets(cn
->children
.vec
[n
]);
417 cn
->children
.nvec
= 0;
420 /** @brief Called with a list of files just below some node */
421 static void got_files(void *v
, const char *error
, int nvec
, char **vec
) {
422 struct choosenode
*cn
= v
;
426 popup_protocol_error(0, error
);
430 D(("got_files %d files for %s %s", nvec
, cn
->path
, cnflags(cn
)));
431 /* Complicated by the need to resolve aliases. */
432 cn
->flags
&= ~CN_GETTING_FILES
;
434 if((cn
->pending
= nvec
)) {
435 cn
->flags
|= CN_RESOLVING_FILES
;
436 for(n
= 0; n
< nvec
; ++n
) {
437 disorder_eclient_resolve(client
, got_resolved_file
, vec
[n
], cn
);
441 /* If there are no files and the directories are all read by now, we're
443 if(!(cn
->flags
& CN_GETTING_ANY
))
446 redisplay_tree("got_files");
449 /** @brief Called with an alias resolved filename */
450 static void got_resolved_file(void *v
, const char *error
, const char *track
) {
451 struct choosenode
*const cn
= v
, *file_cn
;
454 popup_protocol_error(0, error
);
456 D(("resolved %s %s %d left", cn
->path
, cnflags(cn
), cn
->pending
- 1));
458 file_cn
= newnode(cn
, track
,
459 trackname_transform("track", track
, "display"),
460 trackname_transform("track", track
, "sort"),
461 0/*flags*/, 0/*fill*/);
463 /* Only bother updating when we've got the lot */
464 if(--cn
->pending
== 0) {
465 cn
->flags
&= ~CN_RESOLVING_FILES
;
466 updated_node(cn
, gets_in_flight
== 0, "got_resolved_file");
467 if(!(cn
->flags
& CN_GETTING_ANY
))
473 /** @brief Called with a list of directories just below some node */
474 static void got_dirs(void *v
, const char *error
, int nvec
, char **vec
) {
475 struct choosenode
*cn
= v
;
479 popup_protocol_error(0, error
);
483 D(("got_dirs %d dirs for %s %s", nvec
, cn
->path
, cnflags(cn
)));
484 /* TODO this depends on local configuration for trackname_transform().
485 * This will work, since the defaults are now built-in, but it'll be
486 * (potentially) different to the server's configured settings.
488 * Really we want a variant of files/dirs that produces both the
489 * raw filename and the transformed name for a chosen context.
492 for(n
= 0; n
< nvec
; ++n
)
494 trackname_transform("dir", vec
[n
], "display"),
495 trackname_transform("dir", vec
[n
], "sort"),
496 CN_EXPANDABLE
, fill_directory_node
);
497 updated_node(cn
, gets_in_flight
== 0, "got_dirs");
498 cn
->flags
&= ~CN_GETTING_DIRS
;
499 if(!(cn
->flags
& CN_GETTING_ANY
))
503 /** @brief Fill a child node */
504 static void fill_directory_node(struct choosenode
*cn
) {
505 D(("fill_directory_node %s", cn
->path
));
507 if(cn
->flags
& CN_GETTING_ANY
)
509 assert(report_label
!= 0);
510 gtk_label_set_text(GTK_LABEL(report_label
), "getting files");
512 disorder_eclient_dirs(client
, got_dirs
, cn
->path
, 0, cn
);
513 disorder_eclient_files(client
, got_files
, cn
->path
, 0, cn
);
514 cn
->flags
|= CN_GETTING_FILES
|CN_GETTING_DIRS
;
518 /** @brief Expand a node */
519 static void expand_node(struct choosenode
*cn
, int contingent
) {
520 D(("expand_node %s %d %s", cn
->path
, contingent
, cnflags(cn
)));
521 assert(cn
->flags
& CN_EXPANDABLE
);
522 /* If node is already expanded do nothing. */
523 if(cn
->flags
& CN_EXPANDED
) return;
524 /* We mark the node as expanded and request that it fill itself. When it has
525 * completed it will called updated_node() and we can redraw at that
527 cn
->flags
|= CN_EXPANDED
;
529 cn
->flags
|= CN_CONTINGENT
;
531 cn
->flags
&= ~CN_CONTINGENT
;
532 /* If this node is not contingently expanded, mark all its parents back to
533 * the root as not contingent either, so they won't be contracted when the
534 * search results change */
536 struct choosenode
*cnp
;
538 for(cnp
= cn
->parent
; cnp
; cnp
= cnp
->parent
)
539 cnp
->flags
&= ~CN_CONTINGENT
;
541 /* TODO: visual feedback */
545 /** @brief Make sure all the search results below @p cn are expanded
546 * @param cn Node to start at
548 static void expand_from(struct choosenode
*cn
) {
551 if(nsearchvisible
== nsearchresults
)
554 /* Are any of the search tracks at/below this point? */
555 if(!(cn
== root
|| hash_find(searchhash
, cn
->path
)))
557 D(("expand_from %d/%d visible %s",
558 nsearchvisible
, nsearchresults
, cn
->path
));
559 if(cn
->flags
& CN_EXPANDABLE
) {
560 if(cn
->flags
& CN_EXPANDED
)
561 /* This node is marked as expanded already. children.nvec might be 0,
562 * indicating that expansion is still underway. We should get another
563 * callback when it is expanded. */
564 for(n
= 0; n
< cn
->children
.nvec
&& gets_in_flight
< 10; ++n
)
565 expand_from(cn
->children
.vec
[n
]);
567 /* This node is not expanded yet */
571 /* This is an actual search result */
573 progress_window_progress(spw
, nsearchvisible
, nsearchresults
);
574 if(nsearchvisible
== nsearchresults
) {
575 if(suppress_redisplay
) {
576 suppress_redisplay
= 0;
577 redisplay_tree("all search results visible");
579 /* We've got the lot. We make sure the first result is visible. */
580 cn
= first_search_result(root
);
581 gtk_adjustment_clamp_page(vadjust
, cn
->ymin
, cn
->ymax
);
586 /** @brief Contract all contingently expanded nodes below @p cn */
587 static void contract_contingent(struct choosenode
*cn
) {
590 if(cn
->flags
& CN_CONTINGENT
)
593 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
594 contract_contingent(cn
->children
.vec
[n
]);
597 /** @brief Contract a node */
598 static void contract_node(struct choosenode
*cn
) {
599 D(("contract_node %s", cn
->path
));
600 assert(cn
->flags
& CN_EXPANDABLE
);
601 /* If node is already contracted do nothing. */
602 if(!(cn
->flags
& CN_EXPANDED
)) return;
603 cn
->flags
&= ~(CN_EXPANDED
|CN_CONTINGENT
);
604 /* Clear selection below this node */
606 /* Zot children. We never used to do this but the result would be that over
607 * time you'd end up with the entire tree pulled into memory. If the server
608 * is over a slow network it will make interactivity slightly worse; if
609 * anyone complains we can make it an option. */
611 /* We can contract a node immediately. */
612 redisplay_tree("contract_node");
615 /** @brief qsort() callback for ordering choosenodes */
616 static int compare_choosenode(const void *av
, const void *bv
) {
617 const struct choosenode
*const *aa
= av
, *const *bb
= bv
;
618 const struct choosenode
*a
= *aa
, *b
= *bb
;
620 return compare_tracks(a
->sort
, b
->sort
,
621 a
->display
, b
->display
,
625 /** @brief Called when an expandable node is updated. */
626 static void updated_node(struct choosenode
*cn
, int redisplay
,
628 D(("updated_node %s", cn
->path
));
629 assert(cn
->flags
& CN_EXPANDABLE
);
630 /* It might be that the node has been de-expanded since we requested the
631 * update. In that case we ignore this notification. */
632 if(!(cn
->flags
& CN_EXPANDED
)) return;
634 qsort(cn
->children
.vec
, cn
->children
.nvec
, sizeof (struct choosenode
*),
639 snprintf(whywhy
, sizeof whywhy
, "updated_node %s", why
);
640 redisplay_tree(whywhy
);
644 /* Searching --------------------------------------------------------------- */
646 /** @brief Return true if @p track is a search result
648 * In particular the return value is one more than the index of the track
651 static int is_search_result(const char *track
) {
654 if(searchhash
&& (r
= hash_find(searchhash
, track
)))
655 return 1 + *(int *)r
;
660 /** @brief Return the first search result at or below @p cn */
661 static struct choosenode
*first_search_result(struct choosenode
*cn
) {
663 struct choosenode
*r
;
665 if(cn
->flags
& CN_EXPANDABLE
) {
666 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
667 if((r
= first_search_result(cn
->children
.vec
[n
])))
669 } else if(is_search_result(cn
->path
))
674 /** @brief Called with a list of search results
676 * This is called from eclient with a (possibly empty) list of search results,
677 * and also from initiate_seatch with an always empty list to indicate that
678 * we're not searching for anything in particular. */
679 static void search_completed(void attribute((unused
)) *v
,
681 int nvec
, char **vec
) {
686 popup_protocol_error(0, error
);
690 search_in_flight
= 0;
691 /* Contract any choosenodes that were only expanded to show search
693 suppress_redisplay
= 1;
694 contract_contingent(root
);
695 suppress_redisplay
= 0;
696 if(search_obsolete
) {
697 /* This search has been obsoleted by user input since it started.
698 * Therefore we throw away the result and search again. */
702 /* Stash the search results */
704 nsearchresults
= nvec
;
706 /* Create a new search hash for fast identification of results */
707 searchhash
= hash_new(sizeof(int));
708 for(n
= 0; n
< nvec
; ++n
) {
709 int *const ip
= xmalloc(sizeof (int *));
710 static const int minus_1
= -1;
712 /* The filename itself lives in the hash */
713 hash_add(searchhash
, vec
[n
], ip
, HASH_INSERT_OR_REPLACE
);
714 /* So do its ancestor directories */
715 for(s
= vec
[n
] + 1; *s
; ++s
) {
718 hash_add(searchhash
, vec
[n
], &minus_1
, HASH_INSERT_OR_REPLACE
);
723 /* We don't yet know that the results are visible */
726 progress_window_progress(spw
, 0, 0);
729 if(nsearchresults
> 50)
730 spw
= progress_window_new("Fetching search results");
731 /* Initiate expansion */
733 /* The search results buttons are usable */
734 gtk_widget_set_sensitive(nextsearch
, 1);
735 gtk_widget_set_sensitive(prevsearch
, 1);
736 suppress_redisplay
= 1; /* avoid lots of redisplays */
738 searchhash
= 0; /* for the gc */
739 redisplay_tree("no search results"); /* remove search markers */
740 /* The search results buttons are not usable */
741 gtk_widget_set_sensitive(nextsearch
, 0);
742 gtk_widget_set_sensitive(prevsearch
, 0);
747 /** @brief Initiate a search
749 * If a search is underway we set @ref search_obsolete and restart the search
750 * in search_completed() above.
752 static void initiate_search(void) {
755 /* Find out what the user is after */
756 terms
= xstrdup(gtk_entry_get_text(GTK_ENTRY(searchentry
)));
757 /* Strip leading and trailing space */
758 while(*terms
== ' ') ++terms
;
759 e
= terms
+ strlen(terms
);
760 while(e
> terms
&& e
[-1] == ' ') --e
;
762 /* If a search is already underway then mark it as obsolete. We'll revisit
763 * when it returns. */
764 if(search_in_flight
) {
769 /* There's still something left. Initiate the search. */
770 if(disorder_eclient_search(client
, search_completed
, terms
, 0)) {
771 /* The search terms are bad! We treat this as if there were no search
772 * terms at all. Some kind of feedback would be handy. */
773 fprintf(stderr
, "bad terms [%s]\n", terms
); /* TODO */
774 search_completed(0, 0, 0, 0);
776 search_in_flight
= 1;
779 /* No search terms - we want to see all tracks */
780 search_completed(0, 0, 0, 0);
784 /** @brief Called when the cancel search button is clicked */
785 static void clearsearch_clicked(GtkButton
attribute((unused
)) *button
,
786 gpointer
attribute((unused
)) userdata
) {
787 gtk_entry_set_text(GTK_ENTRY(searchentry
), "");
788 /* Put the input focus back */
789 gtk_widget_grab_focus(searchentry
);
792 /** @brief Called when the 'next search result' button is clicked */
793 static void next_clicked(GtkButton
attribute((unused
)) *button
,
794 gpointer
attribute((unused
)) userdata
) {
795 /* We want to find the highest (lowest ymax) track that is below the current
798 const gdouble bottom
= gtk_adjustment_get_value(vadjust
) + vadjust
->page_size
;
799 const struct choosenode
*candidate
= 0;
801 for(n
= 0; n
< nsearchresults
; ++n
) {
802 const struct choosenode
*const cn
= searchnodes
[n
];
807 || cn
->ymax
< candidate
->ymax
))
811 gtk_adjustment_clamp_page(vadjust
, candidate
->ymin
, candidate
->ymax
);
814 /** @brief Called when the 'previous search result' button is clicked */
815 static void prev_clicked(GtkButton
attribute((unused
)) *button
,
816 gpointer
attribute((unused
)) userdata
) {
817 /* We want to find the lowest (greated ymax) track that is above the current
820 const gdouble top
= gtk_adjustment_get_value(vadjust
);
821 const struct choosenode
*candidate
= 0;
823 for(n
= 0; n
< nsearchresults
; ++n
) {
824 const struct choosenode
*const cn
= searchnodes
[n
];
829 || cn
->ymax
> candidate
->ymax
))
833 gtk_adjustment_clamp_page(vadjust
, candidate
->ymin
, candidate
->ymax
);
836 /* Display functions ------------------------------------------------------- */
838 /** @brief Delete all the widgets in the tree */
839 static void delete_widgets(struct choosenode
*cn
) {
842 delete_cn_widgets(cn
);
843 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
844 delete_widgets(cn
->children
.vec
[n
]);
845 cn
->flags
&= ~(CN_DISPLAYED
|CN_SELECTED
);
849 /** @brief Update the display */
850 static void redisplay_tree(const char *why
) {
851 struct displaydata d
;
852 guint oldwidth
, oldheight
;
854 D(("redisplay_tree %s", why
));
855 if(suppress_redisplay
) {
856 /*fprintf(stderr, "redisplay_tree %s suppressed\n", why);*/
860 /*fprintf(stderr, "redisplay_tree %s suppressed (gets_in_flight)\n", why);*/
865 /*fprintf(stderr, "redisplay_tree %s *** NOT SUPPRESSED ***\n", why);*/
866 /* We'll count these up empirically each time */
869 /* Correct the layout and find out how much space it uses */
870 MTAG_PUSH("display_tree");
871 searchnodes
= nsearchresults ?
xcalloc(nsearchresults
,
872 sizeof (struct choosenode
*)) : 0;
873 d
= display_tree(root
, 0, 0);
877 /* We must set the total size or scrolling will not work (it wouldn't be hard
878 * for GtkLayout to figure it out for itself but presumably you're supposed
879 * to be able to have widgets off the edge of the layuot.)
881 * There is a problem: if we shrink the size then the part of the screen that
882 * is outside the new size but inside the old one is not updated. I think
883 * this is arguably bug in GTK+ but it's easy to force a redraw if this
884 * region is nonempty.
886 gtk_layout_get_size(GTK_LAYOUT(chooselayout
), &oldwidth
, &oldheight
);
887 if(oldwidth
> d
.width
|| oldheight
> d
.height
)
888 gtk_widget_queue_draw(chooselayout
);
889 gtk_layout_set_size(GTK_LAYOUT(chooselayout
), d
.width
, d
.height
);
891 /* Notify the main menu of any recent changes */
899 /** @brief Recursive step for redisplay_tree()
900 * @param cn Node to display
901 * @param x X coordinate for @p cn
902 * @param y Y coordinate for @p cn
904 * Makes sure all displayed widgets from CN down exist and are in their proper
905 * place and return the maximum space used.
907 static struct displaydata
display_tree(struct choosenode
*cn
, int x
, int y
) {
910 struct displaydata d
, cd
;
912 const int search_result
= is_search_result(cn
->path
);
914 D(("display_tree %s %d,%d", cn
->path
, x
, y
));
916 /* An expandable item contains an arrow and a text label. When you press the
917 * button it flips its expand state.
919 * A non-expandable item has just a text label and no arrow.
923 MTAG_PUSH("make_widgets_1");
924 /* Widgets need to be created */
926 cn
->hbox
= gtk_hbox_new(FALSE
, 1);
927 if(cn
->flags
& CN_EXPANDABLE
) {
929 cn
->arrow
= gtk_arrow_new(cn
->flags
& CN_EXPANDED ? GTK_ARROW_DOWN
935 if((pb
= find_image("notes.png"))) {
937 cn
->marker
= gtk_image_new_from_pixbuf(pb
);
941 MTAG_PUSH("make_widgets_2");
943 cn
->label
= gtk_label_new(cn
->display
);
945 gtk_container_add(GTK_CONTAINER(cn
->hbox
), cn
->arrow
);
946 gtk_container_add(GTK_CONTAINER(cn
->hbox
), cn
->label
);
948 gtk_container_add(GTK_CONTAINER(cn
->hbox
), cn
->marker
);
950 MTAG_PUSH("make_widgets_3");
952 cn
->container
= gtk_event_box_new();
953 gtk_container_add(GTK_CONTAINER(cn
->container
), cn
->hbox
);
954 g_signal_connect(cn
->container
, "button-release-event",
955 G_CALLBACK(clicked_choosenode
), cn
);
956 g_signal_connect(cn
->container
, "button-press-event",
957 G_CALLBACK(clicked_choosenode
), cn
);
958 g_object_ref(cn
->container
);
959 /* Show everything by default */
960 gtk_widget_show_all(cn
->container
);
964 assert(cn
->container
);
968 gtk_widget_set_style(cn
->container
, search_style
);
969 gtk_widget_set_style(cn
->label
, search_style
);
971 gtk_widget_set_style(cn
->container
, layout_style
);
972 gtk_widget_set_style(cn
->label
, layout_style
);
975 /* Make sure the icon is right */
977 if(cn
->flags
& CN_EXPANDABLE
)
978 gtk_arrow_set(GTK_ARROW(cn
->arrow
),
979 cn
->flags
& CN_EXPANDED ? GTK_ARROW_DOWN
: GTK_ARROW_RIGHT
,
982 /* Make sure the queued marker is right */
983 /* TODO: doesn't always work */
984 (queued(cn
->path
) ? gtk_widget_show
: gtk_widget_hide
)(cn
->marker
);
986 /* Put the widget in the right place */
988 if(cn
->flags
& CN_DISPLAYED
)
989 gtk_layout_move(GTK_LAYOUT(chooselayout
), cn
->container
, x
, y
);
991 gtk_layout_put(GTK_LAYOUT(chooselayout
), cn
->container
, x
, y
);
992 cn
->flags
|= CN_DISPLAYED
;
993 /* Now chooselayout has a ref to the container */
994 g_object_unref(cn
->container
);
997 /* Set the widget's selection status */
999 if(!(cn
->flags
& CN_EXPANDABLE
))
1000 display_selection(cn
);
1002 /* Find the size used so we can get vertical positioning right. */
1003 gtk_widget_size_request(cn
->container
, &req
);
1004 d
.width
= x
+ req
.width
;
1005 d
.height
= y
+ req
.height
;
1007 cn
->ymax
= d
.height
;
1008 if(cn
->flags
& CN_EXPANDED
) {
1009 /* We'll offset children by the size of the arrow whatever it might be. */
1011 gtk_widget_size_request(cn
->arrow
, &req
);
1013 for(n
= 0; n
< cn
->children
.nvec
; ++n
) {
1014 cd
= display_tree(cn
->children
.vec
[n
], x
+ aw
, d
.height
);
1015 if(cd
.width
> d
.width
)
1017 d
.height
= cd
.height
;
1021 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
1022 undisplay_tree(cn
->children
.vec
[n
]);
1025 if(!(cn
->flags
& CN_EXPANDABLE
)) {
1027 if(cn
->flags
& CN_SELECTED
)
1030 /* update the search results array */
1032 searchnodes
[search_result
- 1] = cn
;
1033 /* report back how much space we used */
1034 D(("display_tree %s %d,%d total size %dx%d", cn
->path
, x
, y
,
1035 d
.width
, d
.height
));
1039 /** @brief Remove widgets for newly hidden nodes */
1040 static void undisplay_tree(struct choosenode
*cn
) {
1043 D(("undisplay_tree %s", cn
->path
));
1044 /* Remove this widget from the display */
1045 if(cn
->flags
& CN_DISPLAYED
) {
1046 gtk_container_remove(GTK_CONTAINER(chooselayout
), cn
->container
);
1047 cn
->flags
^= CN_DISPLAYED
;
1049 /* Remove children too */
1050 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
1051 undisplay_tree(cn
->children
.vec
[n
]);
1054 /* Selection --------------------------------------------------------------- */
1056 /** @brief Mark the widget @p cn according to its selection state */
1057 static void display_selection(struct choosenode
*cn
) {
1058 /* Need foreground and background colors */
1059 gtk_widget_set_state(cn
->label
, (cn
->flags
& CN_SELECTED
1060 ? GTK_STATE_SELECTED
: GTK_STATE_NORMAL
));
1061 gtk_widget_set_state(cn
->container
, (cn
->flags
& CN_SELECTED
1062 ? GTK_STATE_SELECTED
: GTK_STATE_NORMAL
));
1065 /** @brief Set the selection state of a widget
1067 * Directories can never be selected, we just ignore attempts to do so. */
1068 static void set_selection(struct choosenode
*cn
, int selected
) {
1069 unsigned f
= selected ? CN_SELECTED
: 0;
1071 D(("set_selection %d %s", selected
, cn
->path
));
1072 if(!(cn
->flags
& CN_EXPANDABLE
) && (cn
->flags
& CN_SELECTED
) != f
) {
1073 cn
->flags
^= CN_SELECTED
;
1074 /* Maintain selection count */
1079 display_selection(cn
);
1080 /* Update main menu sensitivity */
1085 /** @brief Recursively clear all selection bits from CN down */
1086 static void clear_selection(struct choosenode
*cn
) {
1089 set_selection(cn
, 0);
1090 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
1091 clear_selection(cn
->children
.vec
[n
]);
1094 /* User actions ------------------------------------------------------------ */
1096 /** @brief Called when disorder_eclient_play completes */
1097 void play_completed(void attribute((unused
)) *v
,
1098 const char *error
) {
1100 popup_protocol_error(0, error
);
1103 /** @brief Clicked on something
1105 * This implements playing, all the modifiers for selection, etc.
1107 static void clicked_choosenode(GtkWidget
attribute((unused
)) *widget
,
1108 GdkEventButton
*event
,
1109 gpointer user_data
) {
1110 struct choosenode
*cn
= user_data
;
1111 int ind
, last_ind
, n
;
1113 D(("clicked_choosenode %s", cn
->path
));
1114 if(event
->type
== GDK_BUTTON_RELEASE
1115 && event
->button
== 1) {
1117 if(cn
->flags
& CN_EXPANDABLE
) {
1118 /* This is a directory. Flip its expansion status. */
1119 if(cn
->flags
& CN_EXPANDED
)
1122 expand_node(cn
, 0/*!contingent*/);
1125 /* This is a file. Adjust selection status */
1126 /* TODO the basic logic here is essentially the same as that in queue.c.
1127 * Can we share code at all? */
1128 switch(event
->state
& (GDK_SHIFT_MASK
|GDK_CONTROL_MASK
)) {
1130 clear_selection(root
);
1131 set_selection(cn
, 1);
1134 case GDK_CONTROL_MASK
:
1135 set_selection(cn
, !(cn
->flags
& CN_SELECTED
));
1138 case GDK_SHIFT_MASK
:
1139 case GDK_SHIFT_MASK
|GDK_CONTROL_MASK
:
1140 if(last_click
&& last_click
->parent
== cn
->parent
) {
1141 /* Figure out where the current and last clicks are in the list */
1142 ind
= last_ind
= -1;
1143 for(n
= 0; n
< cn
->parent
->children
.nvec
; ++n
) {
1144 if(cn
->parent
->children
.vec
[n
] == cn
)
1146 if(cn
->parent
->children
.vec
[n
] == last_click
)
1149 /* Test shouldn't ever fail, but still */
1150 if(ind
>= 0 && last_ind
>= 0) {
1151 if(!(event
->state
& GDK_CONTROL_MASK
)) {
1152 for(n
= 0; n
< cn
->parent
->children
.nvec
; ++n
)
1153 set_selection(cn
->parent
->children
.vec
[n
], 0);
1156 for(n
= last_ind
; n
<= ind
; ++n
)
1157 set_selection(cn
->parent
->children
.vec
[n
], 1);
1159 for(n
= ind
; n
<= last_ind
; ++n
)
1160 set_selection(cn
->parent
->children
.vec
[n
], 1);
1161 if(event
->state
& GDK_CONTROL_MASK
)
1165 /* TODO trying to select a range that doesn't share a single parent
1166 * currently does not work, but it ought to. */
1170 } else if(event
->type
== GDK_BUTTON_RELEASE
1171 && event
->button
== 2) {
1172 /* Middle click - play the pointed track */
1173 if(!(cn
->flags
& CN_EXPANDABLE
)) {
1174 clear_selection(root
);
1175 set_selection(cn
, 1);
1176 gtk_label_set_text(GTK_LABEL(report_label
), "adding track to queue");
1177 disorder_eclient_play(client
, cn
->path
, play_completed
, 0);
1180 } else if(event
->type
== GDK_BUTTON_PRESS
1181 && event
->button
== 3) {
1182 struct choose_menuitem
*const menuitems
=
1183 (cn
->flags
& CN_EXPANDABLE ? dir_menuitems
: track_menuitems
);
1184 GtkWidget
*const menu
=
1185 (cn
->flags
& CN_EXPANDABLE ? dir_menu
: track_menu
);
1186 /* Right click. Pop up a menu. */
1187 /* If the current file isn't selected, switch the selection to just that.
1188 * (If we're looking at a directory then leave the selection alone.) */
1189 if(!(cn
->flags
& CN_EXPANDABLE
) && !(cn
->flags
& CN_SELECTED
)) {
1190 clear_selection(root
);
1191 set_selection(cn
, 1);
1194 /* Set the item sensitivity and callbacks */
1195 for(n
= 0; menuitems
[n
].name
; ++n
) {
1196 if(menuitems
[n
].handlerid
)
1197 g_signal_handler_disconnect(menuitems
[n
].w
,
1198 menuitems
[n
].handlerid
);
1199 gtk_widget_set_sensitive(menuitems
[n
].w
,
1200 menuitems
[n
].sensitive(cn
));
1201 menuitems
[n
].handlerid
= g_signal_connect
1202 (menuitems
[n
].w
, "activate", G_CALLBACK(menuitems
[n
].activate
), cn
);
1204 set_tool_colors(menu
);
1205 /* Pop up the menu */
1206 gtk_widget_show_all(menu
);
1207 gtk_menu_popup(GTK_MENU(menu
), 0, 0, 0, 0,
1208 event
->button
, event
->time
);
1212 /** @brief Called BY GTK+ to tell us the search entry box has changed */
1213 static void searchentry_changed(GtkEditable
attribute((unused
)) *editable
,
1214 gpointer
attribute((unused
)) user_data
) {
1218 /* Track menu items -------------------------------------------------------- */
1220 /** @brief Recursive step for gather_selected() */
1221 static void recurse_selected(struct choosenode
*cn
, struct vector
*v
) {
1224 if(cn
->flags
& CN_EXPANDABLE
) {
1225 if(cn
->flags
& CN_EXPANDED
)
1226 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
1227 recurse_selected(cn
->children
.vec
[n
], v
);
1229 if((cn
->flags
& CN_SELECTED
) && cn
->path
)
1230 vector_append(v
, (char *)cn
->path
);
1234 /*** @brief Get a list of all the selected tracks */
1235 static const char **gather_selected(int *ntracks
) {
1239 recurse_selected(root
, &v
);
1240 vector_terminate(&v
);
1241 if(ntracks
) *ntracks
= v
.nvec
;
1242 return (const char **)v
.vec
;
1245 /** @brief Called when the track menu's play option is activated */
1246 static void activate_track_play(GtkMenuItem
attribute((unused
)) *menuitem
,
1247 gpointer
attribute((unused
)) user_data
) {
1248 const char **tracks
= gather_selected(0);
1251 gtk_label_set_text(GTK_LABEL(report_label
), "adding track to queue");
1252 for(n
= 0; tracks
[n
]; ++n
)
1253 disorder_eclient_play(client
, tracks
[n
], play_completed
, 0);
1256 /** @brief Called when the menu's properties option is activated */
1257 static void activate_track_properties(GtkMenuItem
attribute((unused
)) *menuitem
,
1258 gpointer
attribute((unused
)) user_data
) {
1260 const char **tracks
= gather_selected(&ntracks
);
1262 properties(ntracks
, tracks
);
1265 /** @brief Determine whether the menu's play option should be sensitive */
1266 static gboolean
sensitive_track_play(struct choosenode
attribute((unused
)) *cn
) {
1267 return (!!files_selected
1268 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1269 && (last_rights
& RIGHT_PLAY
));
1272 /** @brief Determine whether the menu's properties option should be sensitive */
1273 static gboolean
sensitive_track_properties(struct choosenode
attribute((unused
)) *cn
) {
1274 return (!!files_selected
1275 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1276 && (last_rights
& RIGHT_PREFS
));
1279 /* Directory menu items ---------------------------------------------------- */
1281 /** @brief Return the file children of @p cn
1283 * The list is terminated by a null pointer.
1285 static const char **dir_files(struct choosenode
*cn
, int *nfiles
) {
1286 const char **files
= xcalloc(cn
->children
.nvec
+ 1, sizeof (char *));
1289 for(n
= m
= 0; n
< cn
->children
.nvec
; ++n
)
1290 if(!(cn
->children
.vec
[n
]->flags
& CN_EXPANDABLE
))
1291 files
[m
++] = cn
->children
.vec
[n
]->path
;
1293 if(nfiles
) *nfiles
= m
;
1297 static void play_dir(struct choosenode
*cn
,
1298 void attribute((unused
)) *wfu
) {
1300 const char **tracks
= dir_files(cn
, &ntracks
);
1302 gtk_label_set_text(GTK_LABEL(report_label
), "adding track to queue");
1303 for(n
= 0; n
< ntracks
; ++n
)
1304 disorder_eclient_play(client
, tracks
[n
], play_completed
, 0);
1307 static void properties_dir(struct choosenode
*cn
,
1308 void attribute((unused
)) *wfu
) {
1310 const char **tracks
= dir_files(cn
, &ntracks
);
1312 properties(ntracks
, tracks
);
1315 static void select_dir(struct choosenode
*cn
,
1316 void attribute((unused
)) *wfu
) {
1319 clear_selection(root
);
1320 for(n
= 0; n
< cn
->children
.nvec
; ++n
)
1321 set_selection(cn
->children
.vec
[n
], 1);
1324 /** @brief Ensure @p cn is expanded and then call @p callback */
1325 static void call_with_dir(struct choosenode
*cn
,
1326 when_filled_callback
*whenfilled
,
1328 if(!(cn
->flags
& CN_EXPANDABLE
))
1329 return; /* something went wrong */
1330 if(cn
->flags
& CN_EXPANDED
)
1331 /* @p cn is already open */
1332 whenfilled(cn
, wfu
);
1334 /* @p cn is not open, arrange for the callback to go off when it is
1336 cn
->whenfilled
= whenfilled
;
1338 expand_node(cn
, 0/*not contingnet upon search*/);
1342 /** @brief Called when the directory menu's play option is activated */
1343 static void activate_dir_play(GtkMenuItem
attribute((unused
)) *menuitem
,
1344 gpointer user_data
) {
1345 struct choosenode
*const cn
= (struct choosenode
*)user_data
;
1347 call_with_dir(cn
, play_dir
, 0);
1350 /** @brief Called when the directory menu's properties option is activated */
1351 static void activate_dir_properties(GtkMenuItem
attribute((unused
)) *menuitem
,
1352 gpointer user_data
) {
1353 struct choosenode
*const cn
= (struct choosenode
*)user_data
;
1355 call_with_dir(cn
, properties_dir
, 0);
1358 /** @brief Called when the directory menu's select option is activated */
1359 static void activate_dir_select(GtkMenuItem
attribute((unused
)) *menuitem
,
1360 gpointer user_data
) {
1361 struct choosenode
*const cn
= (struct choosenode
*)user_data
;
1363 call_with_dir(cn
, select_dir
, 0);
1366 /** @brief Determine whether the directory menu's play option should be sensitive */
1367 static gboolean
sensitive_dir_play(struct choosenode
attribute((unused
)) *cn
) {
1368 return !!(disorder_eclient_state(client
) & DISORDER_CONNECTED
);
1371 /** @brief Determine whether the directory menu's properties option should be sensitive */
1372 static gboolean
sensitive_dir_properties(struct choosenode
attribute((unused
)) *cn
) {
1373 return !!(disorder_eclient_state(client
) & DISORDER_CONNECTED
);
1376 /** @brief Determine whether the directory menu's select option should be sensitive */
1377 static gboolean
sensitive_dir_select(struct choosenode
attribute((unused
)) *cn
) {
1381 /* Main menu plumbing ------------------------------------------------------ */
1383 /** @brief Determine whether the edit menu's properties option should be sensitive */
1384 static int choose_properties_sensitive(void attribute((unused
)) *extra
) {
1385 return !!files_selected
&& (disorder_eclient_state(client
) & DISORDER_CONNECTED
);
1388 /** @brief Called when the edit menu's properties option is activated */
1389 static void choose_properties_activate(void attribute((unused
)) *extra
) {
1390 activate_track_properties(0, 0);
1393 /** @brief Called when the choose tab is selected */
1394 static void choose_tab_selected(void) {
1395 gtk_widget_grab_focus(searchentry
);
1398 /** @brief Main menu callbacks for Choose screen */
1399 static const struct tabtype tabtype_choose
= {
1400 choose_properties_sensitive
,
1401 NULL
/*choose_selectall_sensitive*/,
1402 NULL
/*choose_selectnone_sensitive*/,
1403 choose_properties_activate
,
1404 NULL
/*choose_selectall_activate*/,
1405 NULL
/*choose_selectnone_activate*/,
1406 choose_tab_selected
,
1410 /* Public entry points ----------------------------------------------------- */
1412 /** @brief Called when we have just logged in
1414 * Entirely resets the choose tab.
1416 static void choose_logged_in(const char attribute((unused
)) *event
,
1417 void attribute((unused
)) *eventdata
,
1418 void attribute((unused
)) *callbackdata
) {
1420 undisplay_tree(root
);
1421 root
= newnode(0/*parent*/, "<root>", "All files", "",
1422 CN_EXPANDABLE
, fill_root_node
);
1423 expand_node(root
, 0); /* will call redisplay_tree */
1426 /** @brief Create a track choice widget */
1427 GtkWidget
*choose_widget(void) {
1429 GtkWidget
*scrolled
;
1430 GtkWidget
*vbox
, *hbox
, *clearsearch
;
1433 * +--vbox-------------------------------------------------------+
1434 * | +-hbox----------------------------------------------------+ |
1435 * | | searchentry | clearsearch | |
1436 * | +---------------------------------------------------------+ |
1437 * | +-scrolled------------------------------------------------+ |
1438 * | | +-chooselayout------------------------------------++--+ | |
1439 * | | | Tree structure is manually layed out in here ||^^| | |
1444 * | | +-------------------------------------------------++--+ | |
1445 * | | +-------------------------------------------------+ | |
1447 * | | +-------------------------------------------------+ | |
1448 * | +---------------------------------------------------------+ |
1449 * +-------------------------------------------------------------+
1452 /* Text entry box for search terms */
1454 searchentry
= gtk_entry_new();
1455 gtk_widget_set_style(searchentry
, tool_style
);
1456 g_signal_connect(searchentry
, "changed", G_CALLBACK(searchentry_changed
), 0);
1457 gtk_tooltips_set_tip(tips
, searchentry
, "Enter search terms here; search is automatic", "");
1459 /* Cancel button to clear the search */
1461 clearsearch
= gtk_button_new_from_stock(GTK_STOCK_CANCEL
);
1462 gtk_widget_set_style(clearsearch
, tool_style
);
1463 g_signal_connect(G_OBJECT(clearsearch
), "clicked",
1464 G_CALLBACK(clearsearch_clicked
), 0);
1465 gtk_tooltips_set_tip(tips
, clearsearch
, "Clear search terms", "");
1467 /* Up and down buttons to find previous/next results; initially they are not
1468 * usable as there are no search results. */
1469 prevsearch
= iconbutton("up.png", "Previous search result");
1470 g_signal_connect(G_OBJECT(prevsearch
), "clicked",
1471 G_CALLBACK(prev_clicked
), 0);
1472 gtk_widget_set_style(prevsearch
, tool_style
);
1473 gtk_widget_set_sensitive(prevsearch
, 0);
1474 nextsearch
= iconbutton("down.png", "Next search result");
1475 g_signal_connect(G_OBJECT(nextsearch
), "clicked",
1476 G_CALLBACK(next_clicked
), 0);
1477 gtk_widget_set_style(nextsearch
, tool_style
);
1478 gtk_widget_set_sensitive(nextsearch
, 0);
1480 /* hbox packs the search tools button together on a line */
1482 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*spacing*/);
1483 gtk_box_pack_start(GTK_BOX(hbox
), searchentry
,
1484 TRUE
/*expand*/, TRUE
/*fill*/, 0/*padding*/);
1485 gtk_box_pack_start(GTK_BOX(hbox
), prevsearch
,
1486 FALSE
/*expand*/, FALSE
/*fill*/, 0/*padding*/);
1487 gtk_box_pack_start(GTK_BOX(hbox
), nextsearch
,
1488 FALSE
/*expand*/, FALSE
/*fill*/, 0/*padding*/);
1489 gtk_box_pack_start(GTK_BOX(hbox
), clearsearch
,
1490 FALSE
/*expand*/, FALSE
/*fill*/, 0/*padding*/);
1492 /* chooselayout contains the currently visible subset of the track
1495 chooselayout
= gtk_layout_new(0, 0);
1496 gtk_widget_set_style(chooselayout
, layout_style
);
1497 choose_logged_in(0, 0, 0);
1498 event_register("logged-in", choose_logged_in
, 0);
1499 /* Create the popup menus */
1501 track_menu
= gtk_menu_new();
1502 g_signal_connect(track_menu
, "destroy", G_CALLBACK(gtk_widget_destroyed
),
1504 for(n
= 0; track_menuitems
[n
].name
; ++n
) {
1506 track_menuitems
[n
].w
=
1507 gtk_menu_item_new_with_label(track_menuitems
[n
].name
);
1508 gtk_menu_attach(GTK_MENU(track_menu
), track_menuitems
[n
].w
,
1512 dir_menu
= gtk_menu_new();
1513 g_signal_connect(dir_menu
, "destroy", G_CALLBACK(gtk_widget_destroyed
),
1515 for(n
= 0; dir_menuitems
[n
].name
; ++n
) {
1517 dir_menuitems
[n
].w
=
1518 gtk_menu_item_new_with_label(dir_menuitems
[n
].name
);
1519 gtk_menu_attach(GTK_MENU(dir_menu
), dir_menuitems
[n
].w
,
1522 /* The layout is scrollable */
1523 scrolled
= scroll_widget(chooselayout
);
1524 vadjust
= gtk_layout_get_vadjustment(GTK_LAYOUT(chooselayout
));
1526 /* The scrollable layout and the search hbox go together in a vbox */
1528 vbox
= gtk_vbox_new(FALSE
/*homogenous*/, 1/*spacing*/);
1529 gtk_box_pack_start(GTK_BOX(vbox
), hbox
,
1530 FALSE
/*expand*/, FALSE
/*fill*/, 0/*padding*/);
1531 gtk_box_pack_end(GTK_BOX(vbox
), scrolled
,
1532 TRUE
/*expand*/, TRUE
/*fill*/, 0/*padding*/);
1534 g_object_set_data(G_OBJECT(vbox
), "type", (void *)&tabtype_choose
);
1538 /** @brief Called when something we care about here might have changed */
1539 void choose_update(void) {
1540 redisplay_tree("choose_update");
1548 indent-tabs-mode:nil