diff options
Diffstat (limited to 'plugins/gtkui/search.c')
-rw-r--r-- | plugins/gtkui/search.c | 244 |
1 files changed, 242 insertions, 2 deletions
diff --git a/plugins/gtkui/search.c b/plugins/gtkui/search.c index 026a3c61..bde3aba7 100644 --- a/plugins/gtkui/search.c +++ b/plugins/gtkui/search.c @@ -31,7 +31,9 @@ #include "search.h" #include "ddblistview.h" +#include "plcommon.h" #include "../../deadbeef.h" +#include "mainplaylist.h" #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) @@ -103,7 +105,7 @@ on_searchentry_changed (GtkEditable *editable, void search_refresh (void) { if (searchwin && GTK_WIDGET_VISIBLE (searchwin)) { - GtkWidget *pl = lookup_widget (mainwin, "searchlist"); + GtkWidget *pl = lookup_widget (searchwin, "searchlist"); ddb_listview_refresh (DDB_LISTVIEW (pl), DDB_REFRESH_VSCROLL | DDB_REFRESH_LIST | DDB_EXPOSE_LIST); } } @@ -180,7 +182,7 @@ on_searchwin_key_press_event (GtkWidget *widget, } } else if (event->keyval != GDK_Delete && event->keyval != GDK_Home && event->keyval != GDK_End){ - GtkWidget *pl = lookup_widget (mainwin, "searchlist"); + GtkWidget *pl = lookup_widget (searchwin, "searchlist"); if (!ddb_listview_handle_keypress (DDB_LISTVIEW (pl), event->keyval, event->state)) { return FALSE; } @@ -259,3 +261,241 @@ on_searchwin_window_state_event (GtkWidget *widget, return FALSE; } +static int +search_get_count (void) { + return deadbeef->pl_getcount (PL_SEARCH); +} + +static int +search_get_sel_count (void) { + int cnt = 0; + DB_playItem_t *it = deadbeef->pl_get_first (PL_SEARCH); + while (it) { + if (deadbeef->pl_is_selected (it)) { + cnt++; + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_SEARCH); + deadbeef->pl_item_unref (it); + it = next; + } + return cnt; +} + +static int +search_get_cursor (void) { + return deadbeef->pl_get_cursor (PL_SEARCH); +} + +static void +search_set_cursor (int cursor) { + return deadbeef->pl_set_cursor (PL_SEARCH, cursor); +} + +static DdbListviewIter search_head (void) { + return (DdbListviewIter)deadbeef->pl_get_first (PL_SEARCH); +} + +static DdbListviewIter search_tail (void) { + return (DdbListviewIter)deadbeef->pl_get_last(PL_SEARCH); +} + +static DdbListviewIter search_next (DdbListviewIter it) { + return (DdbListviewIter)deadbeef->pl_get_next(it, PL_SEARCH); +} + +static DdbListviewIter search_prev (DdbListviewIter it) { + return (DdbListviewIter)deadbeef->pl_get_prev(it, PL_SEARCH); +} + +static DdbListviewIter search_get_for_idx (int idx) { + return deadbeef->pl_get_for_idx_and_iter (idx, PL_SEARCH); +} + +int search_get_idx (DdbListviewIter it) { + DB_playItem_t *c = deadbeef->pl_get_first (PL_SEARCH); + int idx = 0; + while (c && c != it) { + DB_playItem_t *next = deadbeef->pl_get_next (c, PL_SEARCH); + deadbeef->pl_item_unref (c); + c = next; + idx++; + } + if (!c) { + return -1; + } + deadbeef->pl_item_unref (c); + return idx; +} + +int +search_is_selected (DdbListviewIter it) { + return deadbeef->pl_is_selected ((DB_playItem_t *)it); +} + +void +search_select (DdbListviewIter it, int sel) { + deadbeef->pl_set_selected ((DB_playItem_t *)it, sel); +} + +int +search_get_group (DdbListviewIter it, char *str, int size) { + return -1; +} + +void +search_col_sort (int col, int sort_order, void *user_data) { + col_info_t *c = (col_info_t*)user_data; + deadbeef->pl_sort (PL_SEARCH, c->id, c->format, sort_order-1); +} + +static int lock_column_config = 0; + +void +search_columns_changed (DdbListview *listview) { + if (!lock_column_config) { + rewrite_column_config (listview, "search"); + } +} + +void +search_column_size_changed (DdbListview *listview, int col) { + const char *title; + int width; + int align_right; + col_info_t *inf; + int minheight; + int res = ddb_listview_column_get_info (listview, col, &title, &width, &align_right, &minheight, (void **)&inf); + if (res == -1) { + return; + } +} + +void search_col_free_user_data (void *data) { + if (data) { + free (data); + } +} + +void search_handle_doubleclick (DdbListview *listview, DdbListviewIter iter, int idx) { + deadbeef->sendmessage (M_PLAYSONGNUM, 0, deadbeef->pl_get_idx_of ((DB_playItem_t *)iter), 0); +} + +void search_selection_changed (DdbListviewIter it, int idx) { + DdbListview *main = DDB_LISTVIEW (lookup_widget (searchwin, "playlist")); + ddb_listview_draw_row (main, main_get_idx ((DB_playItem_t *)it), it); +} + +void +search_delete_selected (void) { + deadbeef->pl_delete_selected (); + main_refresh (); + search_refresh (); +} + +DdbListviewBinding search_binding = { + // rows + .count = search_get_count, + .sel_count = search_get_sel_count, + + .cursor = search_get_cursor, + .set_cursor = search_set_cursor, + + .head = search_head, + .tail = search_tail, + .next = search_next, + .prev = search_prev, + + .get_for_idx = search_get_for_idx, + .get_idx = search_get_idx, + + .is_selected = search_is_selected, + .select = search_select, + + .get_group = search_get_group, + + .drag_n_drop = NULL, + .external_drag_n_drop = NULL, + + .draw_column_data = draw_column_data, + .draw_group_title = NULL, + + // columns + .col_sort = search_col_sort, + .columns_changed = search_columns_changed, + .column_size_changed = search_column_size_changed, + .col_free_user_data = search_col_free_user_data, + + // callbacks + .handle_doubleclick = search_handle_doubleclick, + .selection_changed = search_selection_changed, + .header_context_menu = header_context_menu, + .list_context_menu = list_context_menu, + .delete_selected = search_delete_selected, +}; + +void +search_playlist_init (GtkWidget *widget) { + DdbListview *listview = DDB_LISTVIEW(widget); + search_binding.ref = (void (*) (DdbListviewIter))deadbeef->pl_item_ref; + search_binding.unref = (void (*) (DdbListviewIter))deadbeef->pl_item_unref; + search_binding.is_selected = (int (*) (DdbListviewIter))deadbeef->pl_is_selected; + ddb_listview_set_binding (listview, &search_binding); + lock_column_config = 1; + // create default set of columns + DB_conf_item_t *col = deadbeef->conf_find ("search.column.", NULL); + if (!col) { + add_column_helper (listview, "Artist / Album", 150, DB_COLUMN_ARTIST_ALBUM, NULL, 0); + add_column_helper (listview, "Track №", 50, DB_COLUMN_TRACK, NULL, 1); + add_column_helper (listview, "Title / Track Artist", 150, DB_COLUMN_TITLE, NULL, 0); + add_column_helper (listview, "Duration", 50, DB_COLUMN_DURATION, NULL, 0); + } + else { + while (col) { + append_column_from_textdef (listview, col->value); + col = deadbeef->conf_find ("search.column.", col); + } + } + lock_column_config = 0; +#if 0 + extern GtkWidget *searchwin; + // init playlist control structure, and put it into widget user-data + memset (&search_playlist, 0, sizeof (search_playlist)); + search_playlist.title = "search"; + search_playlist.playlist = widget; + search_playlist.header = lookup_widget (searchwin, "searchheader"); + search_playlist.scrollbar = lookup_widget (searchwin, "searchscroll"); + search_playlist.hscrollbar = lookup_widget (searchwin, "searchhscroll"); + assert (search_playlist.header); + assert (search_playlist.scrollbar); +// search_playlist.pcurr = &search_current; +// search_playlist.pcount = &search_count; + search_playlist.get_count = search_get_count; +// search_playlist.multisel = 0; + search_playlist.iterator = PL_SEARCH; + search_playlist.scrollpos = 0; + search_playlist.hscrollpos = 0; +// search_playlist.row = -1; + search_playlist.clicktime = -1; + search_playlist.nvisiblerows = 0; + + // create default set of columns + DB_conf_item_t *col = deadbeef->conf_find ("search.column.", NULL); + if (!col) { + gtkpl_column_append (&search_playlist, gtkpl_column_alloc ("Artist / Album", 150, DB_COLUMN_ARTIST_ALBUM, NULL, 0)); + gtkpl_column_append (&search_playlist, gtkpl_column_alloc ("Track №", 50, DB_COLUMN_TRACK, NULL, 1)); + gtkpl_column_append (&search_playlist, gtkpl_column_alloc ("Title / Track Artist", 150, DB_COLUMN_TITLE, NULL, 0)); + gtkpl_column_append (&search_playlist, gtkpl_column_alloc ("Duration", 50, DB_COLUMN_DURATION, NULL, 0)); + } + else { + while (col) { + gtkpl_append_column_from_textdef (&search_playlist, col->value); + col = deadbeef->conf_find ("search.column.", col); + } + } + gtk_object_set_data (GTK_OBJECT (search_playlist.playlist), "ps", &search_playlist); + gtk_object_set_data (GTK_OBJECT (search_playlist.header), "ps", &search_playlist); + gtk_object_set_data (GTK_OBJECT (search_playlist.scrollbar), "ps", &search_playlist); + gtk_object_set_data (GTK_OBJECT (search_playlist.hscrollbar), "ps", &search_playlist); +#endif +} + |