diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-09-29 19:35:36 +0200 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-09-29 19:35:36 +0200 |
commit | 5fa0da2d9b0edf78097a0d29b1bde3c260a36af4 (patch) | |
tree | 482e126fc249cc7210ecf28a20de8328c44c983c | |
parent | e09702f21f6313b0a44fcfcb10ee06dd70364b2f (diff) |
added new APIs for saving current playlist
-rw-r--r-- | deadbeef.h | 7 | ||||
-rw-r--r-- | playlist.c | 28 | ||||
-rw-r--r-- | playlist.h | 8 | ||||
-rw-r--r-- | plugins.c | 3 | ||||
-rw-r--r-- | plugins/gtkui/actionhandlers.c | 2 |
5 files changed, 42 insertions, 6 deletions
@@ -813,6 +813,13 @@ typedef struct { void (*background_job_increment) (void); void (*background_job_decrement) (void); int (*have_background_jobs) (void); + + // utility function to get plt idx from handle + int (*plt_get_idx) (ddb_playlist_t *plt); + + // save referenced playlist in config + int (*plt_save_n) (int n); + int (*plt_save_config) (ddb_playlist_t *plt); } DB_functions_t; // NOTE: an item placement must be selected like this @@ -414,7 +414,7 @@ plt_add (int before, const char *title) { plt_gen_conf (); if (!plt_loading) { - pl_save_n (before); + plt_save_n (before); conf_save (); messagepump_push (DB_EV_PLAYLISTSWITCHED, 0, 0, 0); } @@ -464,7 +464,7 @@ plt_remove (int plt) { UNLOCK; plt_gen_conf (); conf_save (); - pl_save_n (0); + plt_save_n (0); messagepump_push (DB_EV_PLAYLISTSWITCHED, 0, 0, 0); return; } @@ -2073,7 +2073,7 @@ save_fail: } int -pl_save_n (int n) { +plt_save_n (int n) { char path[PATH_MAX]; if (snprintf (path, sizeof (path), "%s/playlists", dbconfdir) > sizeof (path)) { fprintf (stderr, "error: failed to make path string for playlists folder\n"); @@ -2103,7 +2103,7 @@ pl_save_n (int n) { int pl_save_current (void) { - return pl_save_n (plt_get_curr_idx ()); + return plt_save_n (plt_get_curr_idx ()); } int @@ -3890,3 +3890,23 @@ pl_ensure_lock (void) { assert(0); #endif } + +int +plt_get_idx (playlist_t *plt) { + int i; + playlist_t *p; + for (i = 0, p = playlists_head; p && p != plt; i++, p = p->next); + if (p == 0) { + return -1; + } + return i; +} + +int +plt_save_config (playlist_t *plt) { + int i = plt_get_idx (plt); + if (i == -1) { + return -1; + } + return plt_save_n (i); +} @@ -299,7 +299,7 @@ int plt_save (playlist_t *plt, playItem_t *first, playItem_t *last, const char *fname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); int -pl_save_n (int n); +plt_save_n (int n); int pl_save_current (void); @@ -479,4 +479,10 @@ pl_meta_exists (playItem_t *it, const char *key); int plt_get_meta (playlist_t *handle, const char *key, char *val, int size); +int +plt_get_idx (playlist_t *plt); + +int +plt_save_config (playlist_t *plt); + #endif // __PLAYLIST_H @@ -347,6 +347,9 @@ static DB_functions_t deadbeef_api = { .background_job_increment = background_job_increment, .background_job_decrement = background_job_decrement, .have_background_jobs = have_background_jobs, + .plt_get_idx = (int (*)(ddb_playlist_t *))plt_get_idx, + .plt_save_n = plt_save_n, + .plt_save_config = (int (*)(ddb_playlist_t *))plt_save_config, }; DB_functions_t *deadbeef = &deadbeef_api; diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index 1a2b8e64..9b47c2cc 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -649,8 +649,8 @@ load_playlist_thread (void *data) { if (it) { deadbeef->pl_item_unref (it); } + deadbeef->plt_save_config (plt); deadbeef->plt_unref (plt); - deadbeef->pl_save_all (); } g_free (fname); gtkui_playlist_changed (); |