diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-05 21:03:58 +0100 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-05 21:03:58 +0100 |
commit | b9456513b0d6d5f7e9faddb667cd1bede5ad7de6 (patch) | |
tree | ec4fd810d7b821bbd9a97fa7251629f2884d63c3 | |
parent | c73999534098d4a660b6b0863eeec565edea22f8 (diff) |
ported stuff to new file add API
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | deadbeef.h | 119 | ||||
-rw-r--r-- | main.c | 56 | ||||
-rw-r--r-- | playlist.c | 183 | ||||
-rw-r--r-- | playlist.h | 20 | ||||
-rw-r--r-- | plugins.c | 4 | ||||
-rw-r--r-- | plugins/gtkui/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/gtkui/actionhandlers.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/fileman.c | 36 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 52 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.h | 8 |
11 files changed, 343 insertions, 147 deletions
diff --git a/configure.ac b/configure.ac index 1cf6f08a..d7aaf07b 100644 --- a/configure.ac +++ b/configure.ac @@ -178,8 +178,8 @@ AS_IF([test "${enable_portable}" != "no" -a "${enable_staticlink}" != "no"], [ PREFIXFLAGS=" -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\"" ]) -CXXFLAGS="$CXXFLAGS $INSANE_CXXFLAGS -D_GNU_SOURCE $PREFIXFLAGS" -CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE $PREFIXFLAGS" +CXXFLAGS="$CXXFLAGS $INSANE_CXXFLAGS -D_GNU_SOURCE $PREFIXFLAGS -DDDB_WARN_DEPRECATED=1" +CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE $PREFIXFLAGS -DDDB_WARN_DEPRECATED=1" AS_IF([test "${enable_staticlink}" != "no"], [ HAVE_ZLIB=yes @@ -65,6 +65,9 @@ extern "C" { // // if you also want to get the deprecation warnings, use the following: // #define DDB_WARN_DEPRECATED 1 +// +// NOTE: deprecation doesn't mean the API is going to be removed, it just means +// that there's a better replacement in the newer deadbeef versions. // api version history: // 9.9 -- devel @@ -604,8 +607,8 @@ typedef struct { void (*plt_sort) (ddb_playlist_t *plt, int iter, int id, const char *format, int order); // add files and folders to current playlist - int (*plt_add_file) (ddb_playlist_t *plt, const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); - int (*plt_add_dir) (ddb_playlist_t *plt, const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); + int (*plt_add_file) (ddb_playlist_t *plt, const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data) DEPRECATED_15; + int (*plt_add_dir) (ddb_playlist_t *plt, const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data) DEPRECATED_15; // cuesheet support DB_playItem_t *(*plt_insert_cue_from_buffer) (ddb_playlist_t *plt, DB_playItem_t *after, DB_playItem_t *origin, const uint8_t *buffer, int buffersize, int numsamples, int samplerate); @@ -622,65 +625,85 @@ typedef struct { void (*pl_item_unref) (DB_playItem_t *it); void (*pl_item_copy) (DB_playItem_t *out, DB_playItem_t *in); + // request lock for adding files to playlist // this function may return -1 if it is not possible to add files right now. - // caller must cancel operation in this case, or wait until previous add - // finishes - int (*pl_add_files_begin) (ddb_playlist_t *plt); + // caller must cancel operation in this case, + // or wait until previous operation finishes + int (*pl_add_files_begin) (ddb_playlist_t *plt) DEPRECATED_15; + // release the lock for adding files to playlist // end must be called when add files operation is finished - void (*pl_add_files_end) (void); + void (*pl_add_files_end) (void) DEPRECATED_15; // most of this functions are self explanatory // if you don't get what they do -- look in the code - // NOTE: many of pl_* functions, especially the ones that operate on current - // playlist, are going to be nuked somewhere around 0.6 release, in favor of - // more explicit plt_* family. - // they are marked with DEPRECATED comment - // DEPRECATED: please use plt_get_item_idx - int (*pl_get_idx_of) (DB_playItem_t *it) DEPRECATED; - int (*pl_get_idx_of_iter) (DB_playItem_t *it, int iter) DEPRECATED; + // --- the following functions work with current playlist --- - // DEPRECATED: please use plt_get_item_for_idx - DB_playItem_t * (*pl_get_for_idx) (int idx) DEPRECATED; - DB_playItem_t * (*pl_get_for_idx_and_iter) (int idx, int iter) DEPRECATED; + // get index of the track in MAIN + int (*pl_get_idx_of) (DB_playItem_t *it); - // DEPRECATED: please use plt_get_totaltime - float (*pl_get_totaltime) (void) DEPRECATED; + // get index of the track in MAIN or SEARCH + int (*pl_get_idx_of_iter) (DB_playItem_t *it, int iter); - // DEPRECATED: please use plt_get_item_count - int (*pl_getcount) (int iter) DEPRECATED; + // get track for index in MAIN + DB_playItem_t * (*pl_get_for_idx) (int idx); - // DEPRECATED: please use plt_delete_selected - int (*pl_delete_selected) (void) DEPRECATED; + // get track for index in MAIN or SEARCH + DB_playItem_t * (*pl_get_for_idx_and_iter) (int idx, int iter); - // DEPRECATED: please use plt_set_cursor - void (*pl_set_cursor) (int iter, int cursor) DEPRECATED; + // get total play time of all tracks in MAIN + float (*pl_get_totaltime) (void); - // DEPRECATED: please use plt_get_cursor - int (*pl_get_cursor) (int iter) DEPRECATED; + // get number of tracks in MAIN or SEARCH + int (*pl_getcount) (int iter); - // DEPRECATED: please use plt_crop_selected - void (*pl_crop_selected) (void) DEPRECATED; + // delete selected tracks + int (*pl_delete_selected) (void); - // DEPRECATED: please use plt_getselcount - int (*pl_getselcount) (void) DEPRECATED; + // set cursor position in MAIN or SEARCH + void (*pl_set_cursor) (int iter, int cursor); - // DEPRECATED: please use plt_get_first - DB_playItem_t *(*pl_get_first) (int iter) DEPRECATED; - - // DEPRECATED: please use plt_get_last - DB_playItem_t *(*pl_get_last) (int iter) DEPRECATED; + // get cursor position in MAIN + int (*pl_get_cursor) (int iter); + + // remove all except selected tracks + void (*pl_crop_selected) (void); + + // get number of selected tracks + int (*pl_getselcount) (void); + + // get first track in MAIN or SEARCH + DB_playItem_t *(*pl_get_first) (int iter); + + // get last track in MAIN or SEARCH + DB_playItem_t *(*pl_get_last) (int iter); + // --- misc functions --- + + // mark the track as selected or unselected (1 or 0 respectively) void (*pl_set_selected) (DB_playItem_t *it, int sel); + + // test whether the track is selected int (*pl_is_selected) (DB_playItem_t *it); + + // save current playlist int (*pl_save_current) (void); + + // save all playlists int (*pl_save_all) (void); + + // select all tracks in current playlist void (*pl_select_all) (void); + + // get next track DB_playItem_t *(*pl_get_next) (DB_playItem_t *it, int iter); + + // get previous track DB_playItem_t *(*pl_get_prev) (DB_playItem_t *it, int iter); + /* - this function formats line for display in playlist + pl_format_title formats the line for display in playlist @it pointer to playlist item @idx number of that item in playlist (or -1) @s output buffer @@ -706,8 +729,11 @@ typedef struct { more to come */ int (*pl_format_title) (DB_playItem_t *it, int idx, char *s, int size, int id, const char *fmt); + // _escaped version wraps all conversions with '' and replaces every ' in conversions with \' int (*pl_format_title_escaped) (DB_playItem_t *it, int idx, char *s, int size, int id, const char *fmt); + + // format duration 't' (fractional seconds) into string, for display in playlist void (*pl_format_time) (float t, char *dur, int size); // find which playlist the specified item belongs to, returns NULL if none @@ -928,8 +954,12 @@ typedef struct { // the callback will be called for each file // the visibility is taken from plt_add_* arguments // the callback must return 0 to continue, or -1 to abort the operation. - void (*listen_file_added) (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); - void (*unlisten_file_added) (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); + // returns ID + int (*listen_file_added) (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); + void (*unlisten_file_added) (int id); + + int (*listen_file_add_beginend) (void (*callback_begin) (ddb_fileadd_data_t *data, void *user_data), void (*callback_end)(ddb_fileadd_data_t *data, void *user_data), void *user_data); + void (*unlisten_file_add_beginend) (int id); // visibility is a number, which tells listeners about the caller. // the value DDB_FILEADD_VISIBILITY_GUI (or 0) is reserved for callers which @@ -951,6 +981,19 @@ typedef struct { int (*plt_add_dir2) (int visibility, ddb_playlist_t *plt, const char *dirname, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data); ddb_playItem_t * (*plt_insert_file2) (int visibility, ddb_playlist_t *playlist, ddb_playItem_t *after, const char *fname, int *pabort, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data); ddb_playItem_t *(*plt_insert_dir2) (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); + + // request lock for adding files to playlist + // returns 0 on success + // this function may return -1 if it is not possible to add files right now. + // caller must cancel operation in this case, + // or wait until previous operation finishes + // NOTE: it's not guaranteed that all deadbeef versions support + // adding the files to different playlists in parallel. + int (*plt_add_files_begin) (ddb_playlist_t *plt, int visibility); + + // 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); #endif } DB_functions_t; @@ -283,6 +283,12 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi parg++; } if (parg < pend) { + playlist_t *curr_plt = plt_get_curr (); + if (plt_add_files_begin (curr_plt, 0) != 0) { + plt_unref (curr_plt); + snprintf (sendback, sbsize, "it's not allowed to add files to playlist right now, because another file adding operation is in progress. please try again later."); + return 0; + } if (conf_get_int ("cli_add_to_specific_playlist", 1)) { char str[200]; conf_get_str ("cli_add_playlist_name", "Default", str, sizeof (str)); @@ -295,46 +301,38 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi } } // add files - playlist_t *curr_plt = plt_get_curr (); if (!queue) { plt_clear (curr_plt); messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); plt_reset_cursor (curr_plt); } - if (parg < pend) { - if (deadbeef->pl_add_files_begin ((ddb_playlist_t *)curr_plt) != 0) { - plt_unref (curr_plt); - snprintf (sendback, sbsize, "it's not allowed to add files to playlist right now, because another file adding operation is in progress. please try again later."); - return 0; + while (parg < pend) { + char resolved[PATH_MAX]; + const char *pname; + if (realpath (parg, resolved)) { + pname = resolved; } - while (parg < pend) { - char resolved[PATH_MAX]; - const char *pname; - if (realpath (parg, resolved)) { - pname = resolved; - } - else { - pname = parg; - } - if (deadbeef->plt_add_dir ((ddb_playlist_t*)curr_plt, pname, NULL, NULL) < 0) { - if (deadbeef->plt_add_file ((ddb_playlist_t*)curr_plt, pname, NULL, NULL) < 0) { - int ab = 0; - playItem_t *it = plt_load (curr_plt, NULL, pname, &ab, NULL, NULL); - if (it) { - pl_item_unref (it); - } - else { - fprintf (stderr, "failed to add file or folder %s\n", pname); - } + else { + pname = parg; + } + if (deadbeef->plt_add_dir2 (0, (ddb_playlist_t*)curr_plt, pname, NULL, NULL) < 0) { + if (deadbeef->plt_add_file2 (0, (ddb_playlist_t*)curr_plt, pname, NULL, NULL) < 0) { + int ab = 0; + playItem_t *it = plt_load2 (0, curr_plt, NULL, pname, &ab, NULL, NULL); + if (it) { + pl_item_unref (it); + } + else { + fprintf (stderr, "failed to add file or folder %s\n", pname); } } - parg += strlen (parg); - parg++; } - deadbeef->pl_add_files_end (); - plt_unref (curr_plt); + parg += strlen (parg); + parg++; } messagepump_push (DB_EV_PLAYLIST_REFRESH, 0, 0, 0); + plt_add_files_end (curr_plt, 0); + plt_unref (curr_plt); if (!queue) { messagepump_push (DB_EV_PLAY_CURRENT, 0, 1, 0); return 2; // don't reload playlist at startup @@ -120,6 +120,25 @@ static int no_remove_notify; static playlist_t *addfiles_playlist; // current playlist for adding files/folders; set in pl_add_files_begin +typedef struct ddb_fileadd_listener_s { + int id; + int (*callback)(ddb_fileadd_data_t *data, void *user_data); + void *user_data; + struct ddb_fileadd_listener_s *next; +} ddb_fileadd_listener_t; + +static ddb_fileadd_listener_t *file_add_listeners; + +typedef struct ddb_fileadd_beginend_listener_s { + int id; + void (*callback_begin)(ddb_fileadd_data_t *data, void *user_data); + void (*callback_end)(ddb_fileadd_data_t *data, void *user_data); + void *user_data; + struct ddb_fileadd_beginend_listener_s *next; +} ddb_fileadd_beginend_listener_t; + +static ddb_fileadd_beginend_listener_t *file_add_beginend_listeners; + void pl_set_order (int order) { int prev_order = pl_order; @@ -788,12 +807,19 @@ plt_move (int from, int to) { void plt_clear (playlist_t *plt) { + pl_lock (); + if (addfiles_playlist) { + fprintf (stderr, "forbidden to clear playlist while add files in progress\n"); + pl_unlock (); + return; + } while (plt->head[PL_MAIN]) { plt_remove_item (plt, plt->head[PL_MAIN]); } plt->current_row[PL_MAIN] = -1; plt->current_row[PL_SEARCH] = -1; plt_modified (plt); + pl_unlock (); } void @@ -1341,6 +1367,11 @@ plt_insert_file_int (int visibility, playlist_t *playlist, playItem_t *after, co } eol++; + ddb_fileadd_data_t d; + memset (&d, 0, sizeof (d)); + d.visibility = visibility; + d.plt = (ddb_playlist_t *)playlist; + DB_decoder_t **decoders = plug_get_decoder_list (); // match by decoder for (int i = 0; decoders[i]; i++) { @@ -1354,6 +1385,15 @@ plt_insert_file_int (int visibility, playlist_t *playlist, playItem_t *after, co if (cb && cb (inserted, user_data) < 0) { *pabort = 1; } + if (file_add_listeners) { + d.track = (ddb_playItem_t *)inserted; + for (ddb_fileadd_listener_t *l = file_add_listeners; l; l = l->next) { + if (l->callback (&d, l->user_data) < 0) { + *pabort = 1; + break; + } + } + } trace ("file has been added by decoder: %s\n", decoders[i]->plugin.id); return inserted; } @@ -1369,6 +1409,15 @@ plt_insert_file_int (int visibility, playlist_t *playlist, playItem_t *after, co if (cb && cb (inserted, user_data) < 0) { *pabort = 1; } + if (file_add_listeners) { + d.track = (ddb_playItem_t *)inserted; + for (ddb_fileadd_listener_t *l = file_add_listeners; l; l = l->next) { + if (l->callback (&d, l->user_data) < 0) { + *pabort = 1; + break; + } + } + } return inserted; } } @@ -1494,30 +1543,12 @@ plt_add_dir (playlist_t *plt, const char *dirname, int (*cb)(playItem_t *it, voi int pl_add_files_begin (playlist_t *plt) { - pl_lock (); - if (addfiles_playlist) { - pl_unlock (); - return -1; - } - addfiles_playlist = plt; - if (addfiles_playlist) { - plt_ref (addfiles_playlist); - } - pl_unlock (); - trace ("adding to playlist %p (%s)\n", plt, addfiles_playlist->title); - return 0; + return plt_add_files_begin (plt, 0); } void pl_add_files_end (void) { - trace ("end adding to playlist %s\n", addfiles_playlist->title); - pl_lock (); - if (addfiles_playlist) { - plt_unref (addfiles_playlist); - } - addfiles_playlist = NULL; - pl_unlock (); - messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); + return plt_add_files_end (addfiles_playlist, 0); } int @@ -3939,30 +3970,32 @@ plt_save_config (playlist_t *plt) { return plt_save_n (i); } -typedef struct ddb_fileadd_listener_s { - int (*callback)(ddb_fileadd_data_t *data, void *user_data); - void *user_data; - struct ddb_fileadd_listener_s *next; -} ddb_fileadd_listener_t; +int +listen_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data) { + ddb_fileadd_listener_t *l; -static ddb_fileadd_listener_t *file_add_listeners; + int id = 1; + for (l = file_add_listeners; l; l = l->next) { + if (l->id > id) { + id = l->id+1; + } + } -void -listen_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data) { - ddb_fileadd_listener_t *l = malloc (sizeof (ddb_fileadd_listener_t)); + l = malloc (sizeof (ddb_fileadd_listener_t)); memset (l, 0, sizeof (ddb_fileadd_listener_t)); + l->id = id; l->callback = callback; l->user_data = user_data; l->next = file_add_listeners; file_add_listeners = l; - + return id; } void -unlisten_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data) { +unlisten_file_added (int id) { ddb_fileadd_listener_t *prev = NULL; for (ddb_fileadd_listener_t *l = file_add_listeners; l; prev = l, l = l->next) { - if (l->callback == callback && l->user_data == user_data) { + if (l->id == id) { if (prev) { prev->next = l->next; } @@ -3975,7 +4008,46 @@ unlisten_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), } } -DB_playItem_t * +int +listen_file_add_beginend (void (*callback_begin) (ddb_fileadd_data_t *data, void *user_data), void (*callback_end)(ddb_fileadd_data_t *data, void *user_data), void *user_data) { + ddb_fileadd_beginend_listener_t *l; + + int id = 1; + for (l = file_add_beginend_listeners; l; l = l->next) { + if (l->id > id) { + id = l->id+1; + } + } + + l = malloc (sizeof (ddb_fileadd_beginend_listener_t)); + memset (l, 0, sizeof (ddb_fileadd_beginend_listener_t)); + l->id = id; + l->callback_begin = callback_begin; + l->callback_end = callback_end; + l->user_data = user_data; + l->next = file_add_beginend_listeners; + file_add_beginend_listeners = l; + return id; +} + +void +unlisten_file_add_beginend (int id) { + ddb_fileadd_beginend_listener_t *prev = NULL; + for (ddb_fileadd_beginend_listener_t *l = file_add_beginend_listeners; l; prev = l, l = l->next) { + if (l->id == id) { + if (prev) { + prev->next = l->next; + } + else { + file_add_beginend_listeners = l->next; + } + free (l); + break; + } + } +} + +playItem_t * plt_load2 (int visibility, playlist_t *plt, playItem_t *after, const char *fname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data) { plt_load_int (visibility, plt, after, fname, pabort, callback, user_data); } @@ -4007,3 +4079,48 @@ playItem_t * plt_insert_dir2 (int visibility, playlist_t *plt, playItem_t *after, const char *dirname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data) { return plt_insert_dir_int (visibility, plt, NULL, after, dirname, pabort, callback, user_data); } + +int +plt_add_files_begin (playlist_t *plt, int visibility) { + pl_lock (); + if (addfiles_playlist) { + pl_unlock (); + return -1; + } + if (plt->files_adding) { + pl_unlock (); + return -1; + } + addfiles_playlist = plt; + plt_ref (addfiles_playlist); + plt->files_adding = 1; + plt->files_add_visibility = visibility; + pl_unlock (); + ddb_fileadd_data_t d; + memset (&d, 0, sizeof (d)); + d.visibility = visibility; + d.plt = (ddb_playlist_t *)plt; + for (ddb_fileadd_beginend_listener_t *l = file_add_beginend_listeners; l; l = l->next) { + l->callback_begin (&d, l->user_data); + } + return 0; +} + +void +plt_add_files_end (playlist_t *plt, int visibility) { + pl_lock (); + if (addfiles_playlist) { + plt_unref (addfiles_playlist); + } + addfiles_playlist = NULL; + messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); + plt->files_adding = 0; + pl_unlock (); + ddb_fileadd_data_t d; + memset (&d, 0, sizeof (d)); + d.visibility = visibility; + d.plt = (ddb_playlist_t *)plt; + for (ddb_fileadd_beginend_listener_t *l = file_add_beginend_listeners; l; l = l->next) { + l->callback_end (&d, l->user_data); + } +} @@ -67,7 +67,9 @@ typedef struct playlist_s { int current_row[PL_MAX_ITERATORS]; // current row (cursor) struct DB_metaInfo_s *meta; // linked list storing metainfo int refc; + int files_add_visibility; unsigned fast_mode : 1; + unsigned files_adding : 1; } playlist_t; // global playlist control functions @@ -486,13 +488,19 @@ plt_get_idx (playlist_t *plt); int plt_save_config (playlist_t *plt); -void +int listen_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); void -unlisten_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); +unlisten_file_added (int id); + +int +listen_file_add_beginend (void (*callback_begin) (ddb_fileadd_data_t *data, void *user_data), void (*callback_end)(ddb_fileadd_data_t *data, void *user_data), void *user_data); + +void +unlisten_file_add_beginend (int id); -DB_playItem_t * +playItem_t * plt_load2 (int visibility, playlist_t *plt, playItem_t *after, const char *fname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data); int @@ -507,4 +515,10 @@ plt_insert_file2 (int visibility, playlist_t *playlist, playItem_t *after, const playItem_t * plt_insert_dir2 (int visibility, playlist_t *plt, playItem_t *after, const char *dirname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data); +int +plt_add_files_begin (playlist_t *plt, int visibility); + +void +plt_add_files_end (playlist_t *plt, int visibility); + #endif // __PLAYLIST_H @@ -355,11 +355,15 @@ static DB_functions_t deadbeef_api = { .plt_save_config = (int (*)(ddb_playlist_t *))plt_save_config, .listen_file_added = listen_file_added, .unlisten_file_added = unlisten_file_added, + .listen_file_add_beginend = listen_file_add_beginend, + .unlisten_file_add_beginend = unlisten_file_add_beginend, .plt_load2 = (DB_playItem_t * (*) (int visibility, ddb_playlist_t *plt, ddb_playItem_t *after, const char *fname, int *pabort, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data))plt_load2, .plt_add_file2 = (int (*) (int visibility, ddb_playlist_t *plt, const char *fname, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data))plt_add_file2, .plt_add_dir2 = (int (*) (int visibility, ddb_playlist_t *plt, const char *dirname, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data))plt_add_dir2, .plt_insert_file2 = (ddb_playItem_t * (*) (int visibility, ddb_playlist_t *playlist, ddb_playItem_t *after, const char *fname, int *pabort, int (*callback)(DB_playItem_t *it, void *user_data), void *user_data))plt_insert_file2, .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, }; DB_functions_t *deadbeef = &deadbeef_api; diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am index bd8a75c7..5278a483 100644 --- a/plugins/gtkui/Makefile.am +++ b/plugins/gtkui/Makefile.am @@ -159,7 +159,7 @@ ddb_gui_GTK2_la_CFLAGS = -std=c99 -I$(GTK_ROOT_216)/include/gtk-2.0 -I$(GTK_ROOT else ddb_gui_GTK2_la_LIBADD = $(LDADD) $(GTK2_DEPS_LIBS) $(SM_LIBADD) ../libparser/libparser.a $(GTKGLEXT2_LIBS) -ddb_gui_GTK2_la_CFLAGS = -std=c99 $(GTK2_DEPS_CFLAGS) $(SM_CFLAGS) $(GTKGLEXT_CFLAGS_GTK2) +ddb_gui_GTK2_la_CFLAGS = -std=c99 $(GTK2_DEPS_CFLAGS) $(SM_CFLAGS) $(GTKGLEXT_CFLAGS_GTK2) -DDDB_WARN_DEPRECATED=1 endif endif diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index b60617bf..879f8f09 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -400,9 +400,9 @@ action_add_location_handler_cb (void *user_data) { const char *text = gtk_entry_get_text (entry); if (text) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); - if (!deadbeef->pl_add_files_begin (plt)) { - deadbeef->plt_add_file (plt, text, NULL, NULL); - deadbeef->pl_add_files_end (); + if (!deadbeef->plt_add_files_begin (plt, 0)) { + deadbeef->plt_add_file2 (0, plt, text, NULL, NULL); + deadbeef->plt_add_files_end (plt, 0); playlist_refresh (); } if (plt) { diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c index 4ed4c827..a62765ac 100644 --- a/plugins/gtkui/fileman.c +++ b/plugins/gtkui/fileman.c @@ -8,18 +8,18 @@ #include "progress.h" #include "support.h" -void -gtkpl_add_dir (DdbListview *ps, char *folder) { - ddb_playlist_t *plt = deadbeef->plt_get_curr (); - gtkui_original_plt_add_dir (plt, folder, gtkui_add_file_info_cb, NULL); - deadbeef->plt_unref (plt); - g_free (folder); -} +//void +//gtkpl_add_dir (DdbListview *ps, char *folder) { +// ddb_playlist_t *plt = deadbeef->plt_get_curr (); +// gtkui_original_plt_add_dir (plt, folder, gtkui_add_file_info_cb, NULL); +// deadbeef->plt_unref (plt); +// g_free (folder); +//} static void gtkpl_adddir_cb (gpointer data, gpointer userdata) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); - gtkui_original_plt_add_dir (plt, data, gtkui_add_file_info_cb, userdata); + deadbeef->plt_add_dir2 (0, plt, data, NULL, NULL); deadbeef->plt_unref (plt); g_free (data); } @@ -28,7 +28,7 @@ void gtkpl_add_dirs (GSList *lst) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); int empty = 0 == deadbeef->plt_get_item_count (plt, PL_MAIN); - if (deadbeef->pl_add_files_begin (plt) < 0) { + if (deadbeef->plt_add_files_begin (plt, 0) < 0) { deadbeef->plt_unref (plt); g_slist_free (lst); return; @@ -51,14 +51,14 @@ gtkpl_add_dirs (GSList *lst) { deadbeef->pl_unlock (); g_slist_foreach(lst, gtkpl_adddir_cb, NULL); g_slist_free (lst); - deadbeef->pl_add_files_end (); + deadbeef->plt_add_files_end (plt, 0); deadbeef->plt_unref (plt); } static void gtkpl_addfile_cb (gpointer data, gpointer userdata) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); - gtkui_original_plt_add_file (plt, data, gtkui_add_file_info_cb, userdata); + deadbeef->plt_add_file2 (0, plt, data, NULL, 0); deadbeef->plt_unref (plt); g_free (data); } @@ -66,14 +66,14 @@ gtkpl_addfile_cb (gpointer data, gpointer userdata) { void gtkpl_add_files (GSList *lst) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); - if (deadbeef->pl_add_files_begin (plt) < 0) { + if (deadbeef->plt_add_files_begin (plt, 0) < 0) { g_slist_free (lst); deadbeef->plt_unref (plt); return; } g_slist_foreach(lst, gtkpl_addfile_cb, NULL); g_slist_free (lst); - deadbeef->pl_add_files_end (); + deadbeef->plt_add_files_end (plt, 0); deadbeef->plt_save_config (plt); deadbeef->plt_unref (plt); deadbeef->conf_save (); @@ -183,7 +183,7 @@ set_dnd_cursor_idle (gpointer data) { void gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); - if (deadbeef->pl_add_files_begin (plt) < 0) { + if (deadbeef->plt_add_files_begin (plt, 0) < 0) { free (ptr); deadbeef->plt_unref (plt); return; @@ -209,11 +209,11 @@ gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { //strncpy (fname, p, pe - p); //fname[pe - p] = 0; int abort = 0; - DdbListviewIter inserted = deadbeef->plt_insert_dir (plt, after, fname, &abort, gtkui_add_file_info_cb, NULL); + DdbListviewIter inserted = deadbeef->plt_insert_dir2 (0, plt, after, fname, &abort, NULL, NULL); if (!inserted && !abort) { - inserted = deadbeef->plt_insert_file (plt, after, fname, &abort, gtkui_add_file_info_cb, NULL); + inserted = deadbeef->plt_insert_file2 (0, plt, after, fname, &abort, NULL, NULL); if (!inserted && !abort) { - inserted = gtkui_original_plt_load (plt, after, fname, &abort, gtkui_add_file_info_cb, NULL); + inserted = deadbeef->plt_load2 (0, plt, after, fname, &abort, NULL, NULL); } } if (inserted) { @@ -238,7 +238,7 @@ gtkpl_add_fm_dropped_files (DB_playItem_t *drop_before, char *ptr, int length) { } free (ptr); - deadbeef->pl_add_files_end (); + deadbeef->plt_add_files_end (plt, 0); deadbeef->plt_save_config (plt); deadbeef->plt_unref (plt); g_idle_add (set_dnd_cursor_idle, first); diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 53f45f1f..65c85138 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -82,11 +82,15 @@ GtkWidget *traymenu; GtkWidget *theme_treeview; GtkWidget *theme_button; +int fileadded_listener_id; +int fileadd_beginend_listener_id; // overriden API methods +#if 0 int (*gtkui_original_plt_add_dir) (ddb_playlist_t *plt, const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); int (*gtkui_original_plt_add_file) (ddb_playlist_t *plt, const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); int (*gtkui_original_pl_add_files_begin) (ddb_playlist_t *plt); void (*gtkui_original_pl_add_files_end) (void); +#endif // cached config variables int gtkui_embolden_current_track; @@ -912,6 +916,34 @@ gtkui_connect_cb (void *none) { return FALSE; } +int +gtkui_add_file_info_cb (ddb_fileadd_data_t *data, void *user_data) { + if (data->visibility == 0) { + if (progress_is_aborted ()) { + return -1; + } + deadbeef->pl_lock (); + const char *fname = deadbeef->pl_find_meta (data->track, ":URI"); + g_idle_add (gtkui_set_progress_text_idle, (gpointer)strdup(fname)); // slowwwww + deadbeef->pl_unlock (); + } + return 0; +} + +void +gtkui_add_file_begin_cb (ddb_fileadd_data_t *data, void *user_data) { + if (data->visibility == 0) { + progress_show (); + } +} + +void +gtkui_add_file_end_cb (ddb_fileadd_data_t *data, void *user_data) { + if (data->visibility == 0) { + progress_hide (); + } +} + void gtkui_thread (void *ctx) { #ifdef __linux__ @@ -1055,6 +1087,9 @@ gtkui_thread (void *ctx) { deadbeef->pl_format_title (NULL, -1, str, sizeof (str), -1, fmt); gtk_window_set_title (GTK_WINDOW (mainwin), str); + fileadded_listener_id = deadbeef->listen_file_added (gtkui_add_file_info_cb, NULL); + fileadd_beginend_listener_id = deadbeef->listen_file_add_beginend (gtkui_add_file_begin_cb, gtkui_add_file_end_cb, NULL); +#if 0 // override default file adding APIs to show progress bar gtkui_original_plt_add_dir = deadbeef->plt_add_dir; deadbeef->plt_add_dir = gtkui_plt_add_dir; @@ -1070,6 +1105,7 @@ gtkui_thread (void *ctx) { gtkui_original_plt_load = deadbeef->plt_load; deadbeef->plt_load = gtkui_plt_load; +#endif supereq_plugin = deadbeef->plug_get_for_id ("supereq"); @@ -1080,6 +1116,8 @@ gtkui_thread (void *ctx) { gtkui_is_retina = is_retina (mainwin); #endif gtk_main (); + deadbeef->unlisten_file_added (fileadded_listener_id); + deadbeef->unlisten_file_add_beginend (fileadd_beginend_listener_id); w_free (); @@ -1117,18 +1155,7 @@ gtkui_set_progress_text_idle (gpointer data) { return FALSE; } -int -gtkui_add_file_info_cb (DB_playItem_t *it, void *data) { - if (progress_is_aborted ()) { - return -1; - } - deadbeef->pl_lock (); - const char *fname = deadbeef->pl_find_meta (it, ":URI"); - g_idle_add (gtkui_set_progress_text_idle, (gpointer)strdup(fname)); // slowwwww - deadbeef->pl_unlock (); - return 0; -} - +#if 0 DB_playItem_t * (*gtkui_original_plt_load) (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); int @@ -1165,6 +1192,7 @@ gtkui_plt_load (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, in return it; } +#endif void gtkui_playlist_set_curr (int playlist) { diff --git a/plugins/gtkui/gtkui.h b/plugins/gtkui/gtkui.h index 2d768c40..34e639a4 100644 --- a/plugins/gtkui/gtkui.h +++ b/plugins/gtkui/gtkui.h @@ -132,12 +132,6 @@ gtkui_progress_hide_idle (gpointer data); gboolean gtkui_set_progress_text_idle (gpointer data); -int -gtkui_add_file_info_cb (DB_playItem_t *it, void *data); - -extern int (*gtkui_original_plt_add_dir) (ddb_playlist_t *plt, const char *dirname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); -extern int (*gtkui_original_plt_add_file) (ddb_playlist_t *plt, const char *fname, int (*cb)(DB_playItem_t *it, void *data), void *user_data); - void gtkui_playlist_set_curr (int playlist); @@ -153,8 +147,6 @@ gtkui_trackinfochanged (DB_playItem_t *it); gboolean redraw_queued_tracks_cb (gpointer plt); -extern DB_playItem_t * (*gtkui_original_plt_load) (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data); - void mainwin_toggle_visible (void); |