db_visitor: add method playlist()
This commit is contained in:
parent
a94d4be466
commit
c779e2674a
@ -72,14 +72,51 @@ print_visitor_song_info(struct song *song, void *data,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
print_visitor_playlist(const struct playlist_metadata *playlist, void *ctx,
|
||||
G_GNUC_UNUSED GError **error_r)
|
||||
{
|
||||
struct client *client = ctx;
|
||||
client_printf(client, "playlist: %s\n", playlist->name);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
print_visitor_playlist_info(const struct playlist_metadata *playlist,
|
||||
void *ctx, G_GNUC_UNUSED GError **error_r)
|
||||
{
|
||||
struct client *client = ctx;
|
||||
client_printf(client, "playlist: %s\n", playlist->name);
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
struct tm tm;
|
||||
#endif
|
||||
char timestamp[32];
|
||||
time_t t = playlist->mtime;
|
||||
strftime(timestamp, sizeof(timestamp),
|
||||
#ifdef G_OS_WIN32
|
||||
"%Y-%m-%dT%H:%M:%SZ",
|
||||
gmtime(&t)
|
||||
#else
|
||||
"%FT%TZ",
|
||||
gmtime_r(&t, &tm)
|
||||
#endif
|
||||
);
|
||||
client_printf(client, "Last-Modified: %s\n", timestamp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct db_visitor print_visitor = {
|
||||
.directory = print_visitor_directory,
|
||||
.song = print_visitor_song,
|
||||
.playlist = print_visitor_playlist,
|
||||
};
|
||||
|
||||
static const struct db_visitor print_info_visitor = {
|
||||
.directory = print_visitor_directory,
|
||||
.song = print_visitor_song_info,
|
||||
.playlist = print_visitor_playlist_info,
|
||||
};
|
||||
|
||||
struct search_data {
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
struct directory;
|
||||
struct song;
|
||||
struct playlist_metadata;
|
||||
|
||||
struct db_visitor {
|
||||
/**
|
||||
@ -38,6 +39,14 @@ struct db_visitor {
|
||||
* @return true to continue the operation, false on error (set error_r)
|
||||
*/
|
||||
bool (*song)(struct song *song, void *ctx, GError **error_r);
|
||||
|
||||
/**
|
||||
* Visit a playlist. Optional method.
|
||||
*
|
||||
* @return true to continue the operation, false on error (set error_r)
|
||||
*/
|
||||
bool (*playlist)(const struct playlist_metadata *playlist, void *ctx,
|
||||
GError **error_r);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -184,6 +184,14 @@ directory_walk(const struct directory *directory, bool recursive,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (visitor->playlist != NULL) {
|
||||
const struct playlist_vector *pv = &directory->playlists;
|
||||
for (const struct playlist_metadata *i = pv->head;
|
||||
i != NULL; i = i->next)
|
||||
if (!visitor->playlist(i, ctx, error_r))
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct dirvec *dv = &directory->children;
|
||||
for (size_t i = 0; i < dv->nr; ++i) {
|
||||
struct directory *child = dv->base[i];
|
||||
|
Loading…
Reference in New Issue
Block a user