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