comparison src/audacious/ui_jumptotrack.c @ 4029:76da6fe8cb39

- Branch merge
author Ralf Ertzinger <ralf@skytale.net>
date Wed, 28 Nov 2007 16:55:02 +0100
parents c2b2828186ba
children 008708425c83
comparison
equal deleted inserted replaced
4028:bb709f82068b 4029:76da6fe8cb39
78 #include "visualization.h" 78 #include "visualization.h"
79 79
80 #include "ui_skinned_window.h" 80 #include "ui_skinned_window.h"
81 81
82 static GtkWidget *jump_to_track_win = NULL; 82 static GtkWidget *jump_to_track_win = NULL;
83 static gulong serial = 0;
83 84
84 static void 85 static void
85 change_song(guint pos) 86 change_song(guint pos)
86 { 87 {
87 if (playback_get_playing()) 88 if (playback_get_playing())
88 playback_stop(); 89 playback_stop();
89 90
90 playlist_set_position(playlist_get_active(), pos); 91 playlist_set_position(playlist_get_active(), pos);
91 playback_initiate(); 92 playback_initiate();
93 }
94
95 void
96 ui_jump_to_track_hide(void)
97 {
98 g_return_if_fail(jump_to_track_win);
99 gtk_widget_hide(jump_to_track_win);
92 } 100 }
93 101
94 static void 102 static void
95 ui_jump_to_track_jump(GtkTreeView * treeview) 103 ui_jump_to_track_jump(GtkTreeView * treeview)
96 { 104 {
107 115
108 gtk_tree_model_get(model, &iter, 0, &pos, -1); 116 gtk_tree_model_get(model, &iter, 0, &pos, -1);
109 117
110 change_song(pos - 1); 118 change_song(pos - 1);
111 119
112 /* FIXME: should only hide window */ 120 if(cfg.close_jtf_dialog)
113 if(cfg.close_jtf_dialog){ 121 ui_jump_to_track_hide();
114 gtk_widget_destroy(jump_to_track_win);
115 jump_to_track_win = NULL;
116 }
117 } 122 }
118 123
119 static void 124 static void
120 ui_jump_to_track_toggle_cb(GtkWidget * toggle) 125 ui_jump_to_track_toggle_cb(GtkWidget * toggle)
121 { 126 {
210 GdkEventKey * event, 215 GdkEventKey * event,
211 gpointer data) 216 gpointer data)
212 { 217 {
213 switch (event->keyval) { 218 switch (event->keyval) {
214 case GDK_Escape: 219 case GDK_Escape:
215 /* FIXME: show only hide window */ 220 ui_jump_to_track_hide();
216 gtk_widget_destroy(jump_to_track_win);
217 jump_to_track_win = NULL;
218 return TRUE; 221 return TRUE;
219 case GDK_KP_Enter: 222 case GDK_KP_Enter:
220 ui_jump_to_track_queue_cb(NULL, data); 223 ui_jump_to_track_queue_cb(NULL, data);
221 return TRUE; 224 return TRUE;
222 default: 225 default:
245 } 248 }
246 249
247 return rv; 250 return rv;
248 } 251 }
249 252
250 /* FIXME: Clear the entry when the list gets updated */
251 void 253 void
252 ui_jump_to_track_update(GtkWidget * widget, gpointer user_data) 254 ui_jump_to_track_update(GtkWidget * widget, gpointer user_data)
253 { 255 {
254 /* FIXME: Is not in sync with playlist due to delayed extinfo
255 * reading */
256 guint row; 256 guint row;
257 GList *playlist_glist; 257 GList *playlist_glist;
258 gchar *desc_buf = NULL; 258 gchar *desc_buf = NULL;
259 GtkTreeIter iter; 259 GtkTreeIter iter;
260 GtkTreeSelection *selection; 260 GtkTreeSelection *selection;
261 Playlist *playlist; 261 Playlist *playlist;
262 262
263 GtkTreeModel *store; 263 GtkTreeModel *store;
264 264
265 GtkTreeView *tree = GTK_TREE_VIEW(g_object_get_data(user_data, "treeview"));
266 GtkEntry *edit = g_object_get_data(user_data, "edit");
267
265 if (!jump_to_track_win) 268 if (!jump_to_track_win)
266 return; 269 return;
267 270
268 store = gtk_tree_view_get_model(GTK_TREE_VIEW(user_data)); 271 /* clear edit widget */
272 if(edit){
273 gtk_entry_set_text(edit, "\0");
274 }
275
276 store = gtk_tree_view_get_model(tree);
269 gtk_list_store_clear(GTK_LIST_STORE(store)); 277 gtk_list_store_clear(GTK_LIST_STORE(store));
270 278
271 row = 1; 279 row = 1;
272 playlist = playlist_get_active(); 280 playlist = playlist_get_active();
273 for (playlist_glist = playlist->entries; playlist_glist; 281 for (playlist_glist = playlist->entries; playlist_glist;
294 g_free(desc_buf); 302 g_free(desc_buf);
295 desc_buf = NULL; 303 desc_buf = NULL;
296 } 304 }
297 305
298 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); 306 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
299 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(user_data)); 307 selection = gtk_tree_view_get_selection(tree);
300 gtk_tree_selection_select_iter(selection, &iter); 308 gtk_tree_selection_select_iter(selection, &iter);
309 serial = playlist->serial; // important. --yaz
301 } 310 }
302 311
303 static void 312 static void
304 ui_jump_to_track_edit_cb(GtkEntry * entry, gpointer user_data) 313 ui_jump_to_track_edit_cb(GtkEntry * entry, gpointer user_data)
305 { 314 {
441 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL ); 450 gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL );
442 451
443 gtk_list_store_clear(jtf_store); 452 gtk_list_store_clear(jtf_store);
444 453
445 row = 1; 454 row = 1;
446
447 playlist = playlist_get_active(); 455 playlist = playlist_get_active();
448 456
449 PLAYLIST_LOCK(playlist); 457 PLAYLIST_LOCK(playlist);
450
451 for (playlist_glist = playlist->entries; playlist_glist; 458 for (playlist_glist = playlist->entries; playlist_glist;
452 playlist_glist = g_list_next(playlist_glist)) { 459 playlist_glist = g_list_next(playlist_glist)) {
453 460
454 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data); 461 PlaylistEntry *entry = PLAYLIST_ENTRY(playlist_glist->data);
455 462
468 gtk_list_store_append(GTK_LIST_STORE(jtf_store), &iter); 475 gtk_list_store_append(GTK_LIST_STORE(jtf_store), &iter);
469 gtk_list_store_set(GTK_LIST_STORE(jtf_store), &iter, 476 gtk_list_store_set(GTK_LIST_STORE(jtf_store), &iter,
470 0, row, 1, desc_buf, -1); 477 0, row, 1, desc_buf, -1);
471 row++; 478 row++;
472 479
473 if (desc_buf) { 480 g_free(desc_buf);
474 g_free(desc_buf); 481 desc_buf = NULL;
475 desc_buf = NULL; 482 }
476 }
477 }
478
479 PLAYLIST_UNLOCK(playlist); 483 PLAYLIST_UNLOCK(playlist);
480 484
481 /* attach liststore to treeview */ 485 /* attach liststore to treeview */
482 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(jtf_store)); 486 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(jtf_store));
483 g_object_unref(jtf_store); 487 g_object_unref(jtf_store);
488 serial = playlist->serial;
484 return FALSE; 489 return FALSE;
490 }
491
492 static gboolean
493 watchdog(gpointer storage)
494 {
495 GtkWidget *widget;
496 Playlist *playlist = playlist_get_active();
497
498 if(serial == playlist->serial)
499 return TRUE;
500
501 widget = g_object_get_data(storage, "widget");
502 ui_jump_to_track_update(widget, storage);
503 return TRUE;
485 } 504 }
486 505
487 void 506 void
488 ui_jump_to_track(void) 507 ui_jump_to_track(void)
489 { 508 {
490 GtkWidget *scrollwin; 509 GtkWidget *scrollwin;
491 GtkWidget *vbox, *bbox, *sep; 510 GtkWidget *vbox, *bbox, *sep;
492 GtkWidget *toggle; 511 GtkWidget *toggle;
493 GtkWidget *jump, *queue, *cancel; 512 GtkWidget *jump, *queue, *close;
494 GtkWidget *rescan, *edit; 513 GtkWidget *rescan, *edit;
495 GtkWidget *search_label, *hbox; 514 GtkWidget *search_label, *hbox;
496 515
497 GtkWidget *treeview; 516 GtkWidget *treeview = NULL;
498 GtkListStore *jtf_store; 517 GtkListStore *jtf_store;
499 518
500 GtkCellRenderer *renderer; 519 GtkCellRenderer *renderer;
501 GtkTreeViewColumn *column; 520 GtkTreeViewColumn *column;
521
522 gpointer storage;
502 523
503 if (jump_to_track_win) { 524 if (jump_to_track_win) {
504 gtk_window_present(GTK_WINDOW(jump_to_track_win)); 525 gtk_window_present(GTK_WINDOW(jump_to_track_win));
505 return; 526 return;
506 } 527 }
610 G_CALLBACK(ui_jump_to_track_selection_changed_cb), 631 G_CALLBACK(ui_jump_to_track_selection_changed_cb),
611 queue); 632 queue);
612 633
613 rescan = gtk_button_new_from_stock(GTK_STOCK_REFRESH); 634 rescan = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
614 gtk_box_pack_start(GTK_BOX(bbox), rescan, FALSE, FALSE, 0); 635 gtk_box_pack_start(GTK_BOX(bbox), rescan, FALSE, FALSE, 0);
636
637 /* pack to container */
638 storage = g_object_new(G_TYPE_OBJECT, NULL);
639 g_object_set_data(storage, "widget", rescan);
640 g_object_set_data(storage, "treeview", treeview);
641 g_object_set_data(storage, "edit", edit);
642
615 g_signal_connect(rescan, "clicked", 643 g_signal_connect(rescan, "clicked",
616 G_CALLBACK(ui_jump_to_track_update), treeview); 644 G_CALLBACK(ui_jump_to_track_update), storage);
645
617 GTK_WIDGET_SET_FLAGS(rescan, GTK_CAN_DEFAULT); 646 GTK_WIDGET_SET_FLAGS(rescan, GTK_CAN_DEFAULT);
618 gtk_widget_grab_default(rescan); 647 gtk_widget_grab_default(rescan);
619 648
620 jump = gtk_button_new_from_stock(GTK_STOCK_JUMP_TO); 649 jump = gtk_button_new_from_stock(GTK_STOCK_JUMP_TO);
621 gtk_box_pack_start(GTK_BOX(bbox), jump, FALSE, FALSE, 0); 650 gtk_box_pack_start(GTK_BOX(bbox), jump, FALSE, FALSE, 0);
625 treeview); 654 treeview);
626 655
627 GTK_WIDGET_SET_FLAGS(jump, GTK_CAN_DEFAULT); 656 GTK_WIDGET_SET_FLAGS(jump, GTK_CAN_DEFAULT);
628 gtk_widget_grab_default(jump); 657 gtk_widget_grab_default(jump);
629 658
630 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); 659 close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
631 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0); 660 gtk_box_pack_start(GTK_BOX(bbox), close, FALSE, FALSE, 0);
632 g_signal_connect_swapped(cancel, "clicked", 661 /* g_signal_connect_swapped(close, "clicked", */
633 G_CALLBACK(gtk_widget_destroy), 662 /* G_CALLBACK(gtk_widget_destroy), */
634 jump_to_track_win); 663 /* jump_to_track_win); */
635 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); 664 g_signal_connect_swapped(close, "clicked",
665 G_CALLBACK(gtk_widget_hide),
666 jump_to_track_win); // just hide --yaz
667 GTK_WIDGET_SET_FLAGS(close, GTK_CAN_DEFAULT);
636 668
637 g_timeout_add(100, (GSourceFunc)ui_jump_to_track_fill, treeview); 669 g_timeout_add(100, (GSourceFunc)ui_jump_to_track_fill, treeview);
670 g_timeout_add(500, (GSourceFunc)watchdog, storage);
638 671
639 gtk_widget_show_all(jump_to_track_win); 672 gtk_widget_show_all(jump_to_track_win);
640 gtk_widget_grab_focus(edit); 673 gtk_widget_grab_focus(edit);
641 } 674 }
642 675