aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-13 22:02:37 +0200
committerMax Kellermann <max@duempel.org>2011-09-13 22:02:37 +0200
commitc779e2674abbc3eed08e49296c188a9f9ed5270e (patch)
tree35a3a84bb32f595c7916eda865c38e0b27d38418
parenta94d4be466ea3a48389361b483f72df45834f7d2 (diff)
downloadmpd-c779e2674abbc3eed08e49296c188a9f9ed5270e.tar.gz
mpd-c779e2674abbc3eed08e49296c188a9f9ed5270e.tar.xz
mpd-c779e2674abbc3eed08e49296c188a9f9ed5270e.zip
db_visitor: add method playlist()
Diffstat (limited to '')
-rw-r--r--src/db_print.c37
-rw-r--r--src/db_visitor.h9
-rw-r--r--src/directory.c8
3 files changed, 54 insertions, 0 deletions
diff --git a/src/db_print.c b/src/db_print.c
index d398a22ac..8f9bd5b97 100644
--- a/src/db_print.c
+++ b/src/db_print.c
@@ -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 {
diff --git a/src/db_visitor.h b/src/db_visitor.h
index 3eb215c86..f68054ec2 100644
--- a/src/db_visitor.h
+++ b/src/db_visitor.h
@@ -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
diff --git a/src/directory.c b/src/directory.c
index e6ccc60b7..ebc4013eb 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -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];