diff options
Diffstat (limited to '')
-rw-r--r-- | src/db/ProxyDatabasePlugin.cxx | 52 | ||||
-rw-r--r-- | src/db/SimpleDatabasePlugin.cxx | 11 | ||||
-rw-r--r-- | src/db/SimpleDatabasePlugin.hxx | 5 |
3 files changed, 68 insertions, 0 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index 68ba5a542..f06728f80 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -62,6 +62,11 @@ public: VisitPlaylist visit_playlist, GError **error_r) const override; + virtual bool VisitUniqueTags(const DatabaseSelection &selection, + enum tag_type tag_type, + VisitString visit_string, + GError **error_r) const override; + protected: bool Configure(const struct config_param *param, GError **error_r); }; @@ -97,6 +102,17 @@ static constexpr struct { { TAG_NUM_OF_ITEM_TYPES, MPD_TAG_COUNT } }; +G_GNUC_CONST +static enum mpd_tag_type +Convert(enum tag_type tag_type) +{ + for (auto i = tag_table; i->d != TAG_NUM_OF_ITEM_TYPES; ++i) + if (i->d == tag_type) + return i->s; + + return MPD_TAG_COUNT; +} + static bool CheckError(const struct mpd_connection *connection, GError **error_r) { @@ -368,6 +384,42 @@ ProxyDatabase::Visit(const DatabaseSelection &selection, return success; } +bool +ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection, + enum tag_type tag_type, + VisitString visit_string, + GError **error_r) const +{ + enum mpd_tag_type tag_type2 = Convert(tag_type); + if (tag_type2 == MPD_TAG_COUNT) { + g_set_error_literal(error_r, libmpdclient_quark(), 0, + "Unsupported tag"); + return false; + } + + if (!mpd_search_db_tags(connection, tag_type2)) + return CheckError(connection, error_r); + + // TODO: match + (void)selection; + + if (!mpd_search_commit(connection)) + return CheckError(connection, error_r); + + bool result = true; + + struct mpd_pair *pair; + while (result && + (pair = mpd_recv_pair_tag(connection, tag_type2)) != nullptr) { + result = visit_string(pair->value, error_r); + mpd_return_pair(connection, pair); + } + + return mpd_response_finish(connection) && + CheckError(connection, error_r) && + result; +} + const DatabasePlugin proxy_db_plugin = { "proxy", ProxyDatabase::Create, diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx index a4077eb27..ed166de45 100644 --- a/src/db/SimpleDatabasePlugin.cxx +++ b/src/db/SimpleDatabasePlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "SimpleDatabasePlugin.hxx" #include "DatabaseSelection.hxx" +#include "DatabaseHelpers.hxx" extern "C" { #include "db_error.h" @@ -270,6 +271,16 @@ SimpleDatabase::Visit(const DatabaseSelection &selection, } bool +SimpleDatabase::VisitUniqueTags(const DatabaseSelection &selection, + enum tag_type tag_type, + VisitString visit_string, + GError **error_r) const +{ + return ::VisitUniqueTags(*this, selection, tag_type, visit_string, + error_r); +} + +bool SimpleDatabase::Save(GError **error_r) { db_lock(); diff --git a/src/db/SimpleDatabasePlugin.hxx b/src/db/SimpleDatabasePlugin.hxx index 1e990de13..0b7e838b5 100644 --- a/src/db/SimpleDatabasePlugin.hxx +++ b/src/db/SimpleDatabasePlugin.hxx @@ -66,6 +66,11 @@ public: VisitPlaylist visit_playlist, GError **error_r) const override; + virtual bool VisitUniqueTags(const DatabaseSelection &selection, + enum tag_type tag_type, + VisitString visit_string, + GError **error_r) const override; + protected: bool Configure(const struct config_param *param, GError **error_r); |