summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-09-29 19:35:36 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-09-29 19:35:36 +0200
commit5fa0da2d9b0edf78097a0d29b1bde3c260a36af4 (patch)
tree482e126fc249cc7210ecf28a20de8328c44c983c
parente09702f21f6313b0a44fcfcb10ee06dd70364b2f (diff)
added new APIs for saving current playlist
-rw-r--r--deadbeef.h7
-rw-r--r--playlist.c28
-rw-r--r--playlist.h8
-rw-r--r--plugins.c3
-rw-r--r--plugins/gtkui/actionhandlers.c2
5 files changed, 42 insertions, 6 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 3a0d754b..adc7ea34 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -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
diff --git a/playlist.c b/playlist.c
index f59d8251..9b78551f 100644
--- a/playlist.c
+++ b/playlist.c
@@ -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);
+}
diff --git a/playlist.h b/playlist.h
index 8fe90c25..4536556c 100644
--- a/playlist.h
+++ b/playlist.h
@@ -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
diff --git a/plugins.c b/plugins.c
index b59062f0..2c96ebd3 100644
--- a/plugins.c
+++ b/plugins.c
@@ -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 ();