summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-11-23 21:25:27 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-11-23 21:26:15 +0100
commit215c8e04d10ade25d87ffbc71ba65fc5dd1f039e (patch)
tree9fdfcf1a9596279f59f76af6db722d14670d57a3
parent8baad4fe4f4a95022d5f902089680605627d289b (diff)
gtkui: cleanup songchanged_cb; prevent auto-switching playlists because of cursor follows playback; added plt_deselect_all API
-rw-r--r--deadbeef.h3
-rw-r--r--playlist.c9
-rw-r--r--playlist.h3
-rw-r--r--plugins.c1
-rw-r--r--plugins/gtkui/ddblistview.c1
-rw-r--r--plugins/gtkui/widgets.c69
6 files changed, 35 insertions, 51 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 0a270421..e179cb33 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -997,6 +997,9 @@ typedef struct {
// release the lock for adding files to playlist
// end must be called when add files operation is finished
void (*plt_add_files_end) (ddb_playlist_t *plt, int visibility);
+
+ // deselect all tracks in playlist
+ void (*plt_deselect_all) (ddb_playlist_t *plt);
#endif
} DB_functions_t;
diff --git a/playlist.c b/playlist.c
index 83f1d4c7..eb6268cc 100644
--- a/playlist.c
+++ b/playlist.c
@@ -4129,3 +4129,12 @@ plt_add_files_end (playlist_t *plt, int visibility) {
l->callback_end (&d, l->user_data);
}
}
+
+void
+plt_deselect_all (playlist_t *playlist) {
+ LOCK;
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ it->selected = 0;
+ }
+ UNLOCK;
+}
diff --git a/playlist.h b/playlist.h
index aa5dfa88..b8bdeb40 100644
--- a/playlist.h
+++ b/playlist.h
@@ -521,4 +521,7 @@ plt_add_files_begin (playlist_t *plt, int visibility);
void
plt_add_files_end (playlist_t *plt, int visibility);
+void
+plt_deselect_all (playlist_t *plt);
+
#endif // __PLAYLIST_H
diff --git a/plugins.c b/plugins.c
index 21de3b01..0d9872ef 100644
--- a/plugins.c
+++ b/plugins.c
@@ -364,6 +364,7 @@ static DB_functions_t deadbeef_api = {
.plt_insert_dir2 = (ddb_playItem_t *(*) (int visibility, ddb_playlist_t *plt, ddb_playItem_t *after, const char *dirname, int *pabort, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data))plt_insert_dir2,
.plt_add_files_begin = (int (*) (ddb_playlist_t *plt, int visibility))plt_add_files_begin,
.plt_add_files_end = (void (*) (ddb_playlist_t *plt, int visibility))plt_add_files_end,
+ .plt_deselect_all = (void (*) (ddb_playlist_t *plt))plt_deselect_all,
};
DB_functions_t *deadbeef = &deadbeef_api;
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 51f6d951..70fec5b9 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -2894,6 +2894,7 @@ ddb_listview_scroll_to (DdbListview *listview, int pos) {
gtk_range_set_value (GTK_RANGE (listview->scrollbar), pos - a.height/2);
}
}
+
int
ddb_listview_is_scrolling (DdbListview *listview) {
return listview->dragwait;
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index f4bb371b..597ccd05 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -1621,7 +1621,7 @@ struct fromto_t {
};
static gboolean
-tabbed_songchanged_cb (gpointer p) {
+songchanged_cb (gpointer p) {
struct fromto_t *ft = p;
DB_playItem_t *from = ft->from;
DB_playItem_t *to = ft->to;
@@ -1632,8 +1632,21 @@ tabbed_songchanged_cb (gpointer p) {
int scroll_follows_playback = deadbeef->conf_get_int ("playlist.scroll.followplayback", 1);
int plt = deadbeef->streamer_get_current_playlist ();
if (plt != -1) {
- if (cursor_follows_playback && plt != deadbeef->plt_get_curr_idx ()) {
- deadbeef->plt_set_curr_idx (plt);
+ if (plt != deadbeef->plt_get_curr_idx ()) {
+ ddb_playlist_t *p = deadbeef->plt_get_for_idx (plt);
+ if (p) {
+ to_idx = deadbeef->plt_get_item_idx (p, to, PL_MAIN);
+ if (cursor_follows_playback) {
+ char conf[100];
+ snprintf (conf, sizeof (conf), "playlist.cursor.%d", plt);
+ deadbeef->conf_set_int (conf, to_idx);
+ deadbeef->plt_deselect_all (p);
+ deadbeef->pl_set_selected (to, 1);
+ deadbeef->plt_set_cursor (p, PL_MAIN, to_idx);
+ }
+ deadbeef->plt_unref (p);
+ }
+ goto end;
}
to_idx = deadbeef->pl_get_idx_of (to);
if (to_idx != -1) {
@@ -1646,7 +1659,7 @@ tabbed_songchanged_cb (gpointer p) {
}
}
}
-
+end:
if (from) {
int idx = deadbeef->pl_get_idx_of (from);
if (idx != -1) {
@@ -1667,52 +1680,6 @@ tabbed_songchanged_cb (gpointer p) {
}
static gboolean
-songchanged_cb (gpointer data) {
- struct fromto_t *ft = data;
- DB_playItem_t *from = ft->from;
- DB_playItem_t *to = ft->to;
- w_playlist_t *p = (w_playlist_t *)ft->w;
- int to_idx = -1;
- if (!ddb_listview_is_scrolling (DDB_LISTVIEW (p->list)) && to) {
- int cursor_follows_playback = deadbeef->conf_get_int ("playlist.scroll.cursorfollowplayback", 1);
- int scroll_follows_playback = deadbeef->conf_get_int ("playlist.scroll.followplayback", 1);
- int plt = deadbeef->streamer_get_current_playlist ();
- if (plt != -1) {
- if (cursor_follows_playback && plt != deadbeef->plt_get_curr_idx ()) {
- deadbeef->plt_set_curr_idx (plt);
- }
- to_idx = deadbeef->pl_get_idx_of (to);
- if (to_idx != -1) {
- if (cursor_follows_playback) {
- ddb_listview_set_cursor_noscroll (DDB_LISTVIEW (p->list), to_idx);
- }
- if (scroll_follows_playback && plt == deadbeef->plt_get_curr_idx ()) {
- ddb_listview_scroll_to (DDB_LISTVIEW (p->list), to_idx);
- }
- }
- }
- }
-
- if (from) {
- int idx = deadbeef->pl_get_idx_of (from);
- if (idx != -1) {
- ddb_listview_draw_row (DDB_LISTVIEW (p->list), idx, from);
- }
- }
- if (to && to_idx != -1) {
- ddb_listview_draw_row (DDB_LISTVIEW (p->list), to_idx, to);
- }
- if (ft->from) {
- deadbeef->pl_item_unref (ft->from);
- }
- if (ft->to) {
- deadbeef->pl_item_unref (ft->to);
- }
- free (ft);
- return FALSE;
-}
-
-static gboolean
trackfocus_cb (gpointer p) {
w_playlist_t *tp = p;
deadbeef->pl_lock ();
@@ -1752,7 +1719,7 @@ w_tabbed_playlist_message (ddb_gtkui_widget_t *w, uint32_t id, uintptr_t ctx, ui
deadbeef->pl_item_ref (ft->to);
}
ft->w = w;
- g_idle_add (tabbed_songchanged_cb, ft);
+ g_idle_add (songchanged_cb, ft);
break;
case DB_EV_TRACKINFOCHANGED:
{