summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-12-17 22:39:47 +0100
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-12-17 22:39:47 +0100
commitfc493f5e80de2860c73b998c8ce187ea68bedcdf (patch)
tree6cc06a89530d8b2bc9d8ca1a3e361cf9fdc465af
parentf30ba666c5fa2a16c0b5b2ee1d253ab2ac71de09 (diff)
fix bug #1020: incorrect cursor/scroll after deleting playlists
-rw-r--r--deadbeef.h14
-rw-r--r--playlist.c21
-rw-r--r--playlist.h7
-rw-r--r--plugins.c3
-rw-r--r--plugins/gtkui/ddbtabstrip.c22
-rw-r--r--plugins/gtkui/mainplaylist.c12
-rw-r--r--plugins/gtkui/widgets.c32
-rw-r--r--plugins/pltbrowser/pltbrowser.c25
8 files changed, 64 insertions, 72 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 4fe1b5b6..496766c4 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -71,6 +71,7 @@ extern "C" {
// api version history:
// 9.9 -- devel
+// 1.6 -- deadbeef-0.6.1
// 1.5 -- deadbeef-0.6
// 1.4 -- deadbeef-0.5.5
// 1.3 -- deadbeef-0.5.3
@@ -90,7 +91,7 @@ extern "C" {
// 0.1 -- deadbeef-0.2.0
#define DB_API_VERSION_MAJOR 1
-#define DB_API_VERSION_MINOR 5
+#define DB_API_VERSION_MINOR 6
#define DDB_DEPRECATED(x)
@@ -109,6 +110,12 @@ extern "C" {
#define DDB_API_LEVEL DB_API_VERSION_MINOR
#endif
+#if (DDB_WARN_DEPRECATED && DDB_API_LEVEL >= 6)
+#define DEPRECATED_16 DDB_DEPRECATED("since deadbeef API 1.6")
+#else
+#define DEPRECATED_16
+#endif
+
#if (DDB_WARN_DEPRECATED && DDB_API_LEVEL >= 5)
#define DEPRECATED_15 DDB_DEPRECATED("since deadbeef API 1.5")
#else
@@ -1014,6 +1021,11 @@ typedef struct {
// deselect all tracks in playlist
void (*plt_deselect_all) (ddb_playlist_t *plt);
#endif
+ // since 1.6
+#if (DDB_API_LEVEL >= 6)
+ void (*plt_set_scroll) (ddb_playlist_t *plt, int scroll);
+ int (*plt_get_scroll) (ddb_playlist_t *plt);
+#endif
} DB_functions_t;
// NOTE: an item placement must be selected like this
diff --git a/playlist.c b/playlist.c
index 3cf80dae..33a059cd 100644
--- a/playlist.c
+++ b/playlist.c
@@ -265,6 +265,10 @@ plt_gen_conf (void) {
char s[100];
snprintf (s, sizeof (s), "playlist.tab.%02d", i);
conf_set_str (s, p->title);
+ snprintf (s, sizeof (s), "playlist.cursor.%d", i);
+ conf_set_int (s, p->current_row[PL_MAIN]);
+ snprintf (s, sizeof (s), "playlist.scroll.%d", i);
+ conf_set_int (s, p->scroll);
}
UNLOCK;
}
@@ -2166,6 +2170,7 @@ pl_save_all (void) {
int curr = plt_get_curr_idx ();
int err = 0;
+ plt_gen_conf ();
plt_loading = 1;
for (i = 0; i < cnt; i++, p = p->next) {
if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, i) > sizeof (path)) {
@@ -2523,6 +2528,11 @@ pl_load_all (void) {
if (trk) {
pl_item_unref (trk);
}
+ char conf[100];
+ snprintf (conf, sizeof (conf), "playlist.cursor.%d", i);
+ plt->current_row[PL_MAIN] = deadbeef->conf_get_int (conf, -1);
+ snprintf (conf, sizeof (conf), "playlist.scroll.%d", i);
+ plt->scroll = deadbeef->conf_get_int (conf, 0);
plt_unref (plt);
if (!it) {
@@ -4133,3 +4143,14 @@ plt_deselect_all (playlist_t *playlist) {
}
UNLOCK;
}
+
+void
+plt_set_scroll (playlist_t *plt, int scroll) {
+ plt->scroll = scroll;
+}
+
+int
+plt_get_scroll (playlist_t *plt) {
+ return plt->scroll;
+}
+
diff --git a/playlist.h b/playlist.h
index b8bdeb40..9328dcca 100644
--- a/playlist.h
+++ b/playlist.h
@@ -65,6 +65,7 @@ typedef struct playlist_s {
playItem_t *head[PL_MAX_ITERATORS]; // head of linked list
playItem_t *tail[PL_MAX_ITERATORS]; // tail of linked list
int current_row[PL_MAX_ITERATORS]; // current row (cursor)
+ int scroll;
struct DB_metaInfo_s *meta; // linked list storing metainfo
int refc;
int files_add_visibility;
@@ -524,4 +525,10 @@ plt_add_files_end (playlist_t *plt, int visibility);
void
plt_deselect_all (playlist_t *plt);
+void
+plt_set_scroll (playlist_t *plt, int scroll);
+
+int
+plt_get_scroll (playlist_t *plt);
+
#endif // __PLAYLIST_H
diff --git a/plugins.c b/plugins.c
index 0d9872ef..d314570c 100644
--- a/plugins.c
+++ b/plugins.c
@@ -365,6 +365,9 @@ static DB_functions_t deadbeef_api = {
.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,
+ // ******* new 1.6 APIs ********
+ .plt_set_scroll = (void (*) (ddb_playlist_t *plt, int scroll))plt_set_scroll,
+ .plt_get_scroll = (int (*) (ddb_playlist_t *plt))plt_get_scroll,
};
DB_functions_t *deadbeef = &deadbeef_api;
diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c
index e347fc9d..5bc1234b 100644
--- a/plugins/gtkui/ddbtabstrip.c
+++ b/plugins/gtkui/ddbtabstrip.c
@@ -1065,30 +1065,8 @@ on_tabstrip_motion_notify_event (GtkWidget *widget,
x += width - tab_overlap_size;
}
if (inspos >= 0 && inspos != ts->dragging) {
- char str1[100];
- char str2[100];
- char strcursor1[100];
- char strcursor2[100];
- int pos1;
- int pos2;
- int cursor1;
- int cursor2;
- snprintf (str1, sizeof (str1), "playlist.scroll.%d", ts->dragging);
- pos1 = deadbeef->conf_get_int (str1, 0);
- snprintf (str2, sizeof (str2), "playlist.scroll.%d", inspos);
- pos2 = deadbeef->conf_get_int (str2, 0);
-
- snprintf (strcursor1, sizeof (strcursor1), "playlist.cursor.%d", ts->dragging);
- cursor1 = deadbeef->conf_get_int (strcursor1, 0);
- snprintf (strcursor2, sizeof (strcursor2), "playlist.cursor.%d", inspos);
- cursor2 = deadbeef->conf_get_int (strcursor2, 0);
-
deadbeef->plt_move (ts->dragging, inspos);
tab_moved = 1;
- deadbeef->conf_set_int (str1, pos2);
- deadbeef->conf_set_int (str2, pos1);
- deadbeef->conf_set_int (strcursor1, cursor2);
- deadbeef->conf_set_int (strcursor2, cursor1);
ts->dragging = inspos;
deadbeef->conf_set_int ("playlist.current", ts->dragging);
}
diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
index d1920021..477d3550 100644
--- a/plugins/gtkui/mainplaylist.c
+++ b/plugins/gtkui/mainplaylist.c
@@ -64,9 +64,6 @@ main_get_cursor (void) {
static void
main_set_cursor (int cursor) {
- char conf[100];
- snprintf (conf, sizeof (conf), "playlist.cursor.%d", deadbeef->plt_get_curr_idx ());
- deadbeef->conf_set_int (conf, cursor);
return deadbeef->pl_set_cursor (PL_MAIN, cursor);
}
@@ -275,10 +272,11 @@ void main_col_free_user_data (void *data) {
void
main_vscroll_changed (int pos) {
coverart_reset_queue ();
- int curr = deadbeef->plt_get_curr_idx ();
- char conf[100];
- snprintf (conf, sizeof (conf), "playlist.scroll.%d", curr);
- deadbeef->conf_set_int (conf, pos);
+ ddb_playlist_t *plt = deadbeef->plt_get_curr ();
+ if (plt) {
+ deadbeef->plt_set_scroll (plt, pos);
+ deadbeef->plt_unref (plt);
+ }
}
void
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index b8e94810..ae58ef22 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -1603,26 +1603,25 @@ refresh_cb (gpointer data) {
static gboolean
playlistswitch_cb (gpointer p) {
w_playlist_t *tp = (w_playlist_t *)p;
- int curr = deadbeef->plt_get_curr_idx ();
- char conf[100];
- snprintf (conf, sizeof (conf), "playlist.scroll.%d", curr);
- int scroll = deadbeef->conf_get_int (conf, 0);
- snprintf (conf, sizeof (conf), "playlist.cursor.%d", curr);
- int cursor = deadbeef->conf_get_int (conf, -1);
- deadbeef->pl_set_cursor (PL_MAIN, cursor);
if (!strcmp (tp->base.type, "tabbed_playlist")) {
ddb_tabstrip_refresh (((w_tabbed_playlist_t *)tp)->tabstrip);
}
- if (cursor != -1) {
- DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (cursor, PL_MAIN);
- if (it) {
- deadbeef->pl_set_selected (it, 1);
- deadbeef->pl_item_unref (it);
+ ddb_playlist_t *plt = deadbeef->plt_get_curr ();
+ if (plt) {
+ int cursor = deadbeef->plt_get_cursor (plt, PL_MAIN);
+ int scroll = deadbeef->plt_get_scroll (plt);
+ if (cursor != -1) {
+ DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (cursor, PL_MAIN);
+ if (it) {
+ deadbeef->pl_set_selected (it, 1);
+ deadbeef->pl_item_unref (it);
+ }
}
- }
+ deadbeef->plt_unref (plt);
- ddb_listview_refresh (tp->list, DDB_LIST_CHANGED | DDB_REFRESH_LIST | DDB_REFRESH_VSCROLL);
- ddb_listview_set_vscroll (tp->list, scroll);
+ ddb_listview_refresh (tp->list, DDB_LIST_CHANGED | DDB_REFRESH_LIST | DDB_REFRESH_VSCROLL);
+ ddb_listview_set_vscroll (tp->list, scroll);
+ }
return FALSE;
}
@@ -1649,9 +1648,6 @@ songchanged_cb (gpointer p) {
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);
diff --git a/plugins/pltbrowser/pltbrowser.c b/plugins/pltbrowser/pltbrowser.c
index 3ebf02f5..0d729715 100644
--- a/plugins/pltbrowser/pltbrowser.c
+++ b/plugins/pltbrowser/pltbrowser.c
@@ -53,31 +53,9 @@ on_pltbrowser_row_inserted (GtkTreeModel *tree_model, GtkTreePath *path, GtkTree
return;
}
- char str1[100];
- char str2[100];
- char strcursor1[100];
- char strcursor2[100];
- int pos1;
- int pos2;
- int cursor1;
- int cursor2;
- snprintf (str1, sizeof (str1), "playlist.scroll.%d", plt->last_selected);
- pos1 = deadbeef->conf_get_int (str1, 0);
- snprintf (str2, sizeof (str2), "playlist.scroll.%d", idx);
- pos2 = deadbeef->conf_get_int (str2, 0);
-
- snprintf (strcursor1, sizeof (strcursor1), "playlist.cursor.%d", plt->last_selected);
- cursor1 = deadbeef->conf_get_int (strcursor1, 0);
- snprintf (strcursor2, sizeof (strcursor2), "playlist.cursor.%d", idx);
- cursor2 = deadbeef->conf_get_int (strcursor2, 0);
-
deadbeef->plt_move (plt->last_selected, idx);
- deadbeef->conf_set_int (str1, pos2);
- deadbeef->conf_set_int (str2, pos1);
- deadbeef->conf_set_int (strcursor1, cursor2);
- deadbeef->conf_set_int (strcursor2, cursor1);
plt->last_selected = idx;
- deadbeef->conf_set_int ("playlist.current", idx);
+ deadbeef->plt_set_curr_idx (idx);
deadbeef->sendmessage (DB_EV_PLAYLISTSWITCHED, 0, 0, 0);
}
@@ -94,7 +72,6 @@ on_pltbrowser_cursor_changed (GtkTreeView *treeview, gpointer user_data) {
if (indices) {
if (indices[0] >= 0) {
deadbeef->plt_set_curr_idx (indices[0]);
- deadbeef->conf_set_int ("playlist.current", indices[0]);
w->last_selected = indices[0];
}
g_free (indices);