aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--src/DatabaseCommands.cxx5
-rw-r--r--src/DatabasePlaylist.cxx30
-rw-r--r--src/DatabasePlaylist.hxx2
-rw-r--r--src/DatabasePrint.cxx53
-rw-r--r--src/DatabasePrint.hxx6
-rw-r--r--src/DatabaseQueue.cxx24
-rw-r--r--src/DatabaseQueue.hxx2
-rw-r--r--src/DatabaseSelection.hxx9
-rw-r--r--src/Directory.cxx12
-rw-r--r--src/db/SimpleDatabasePlugin.cxx7
-rw-r--r--src/directory.h3
12 files changed, 57 insertions, 97 deletions
diff --git a/Makefile.am b/Makefile.am
index 8ce408879..ec55c1bb6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1054,6 +1054,7 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
src/song.c src/song_sort.c src/song_save.c \
src/tag.c src/tag_pool.c src/tag_save.c \
src/path.c \
+ src/locate.c \
src/text_file.c \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c
diff --git a/src/DatabaseCommands.cxx b/src/DatabaseCommands.cxx
index e0449e9c8..9dbe4e47f 100644
--- a/src/DatabaseCommands.cxx
+++ b/src/DatabaseCommands.cxx
@@ -67,8 +67,11 @@ handle_match(struct client *client, int argc, char *argv[], bool fold_case)
return COMMAND_RETURN_ERROR;
}
+ const DatabaseSelection selection("", true, list);
+
GError *error = NULL;
- enum command_return ret = findSongsIn(client, "", list, &error)
+ enum command_return ret =
+ db_selection_print(client, selection, true, &error)
? COMMAND_RETURN_OK
: print_error(client, error);
diff --git a/src/DatabasePlaylist.cxx b/src/DatabasePlaylist.cxx
index bdd55fc5a..c6ad9c543 100644
--- a/src/DatabasePlaylist.cxx
+++ b/src/DatabasePlaylist.cxx
@@ -23,7 +23,6 @@
extern "C" {
#include "dbUtils.h"
-#include "locate.h"
#include "stored_playlist.h"
}
@@ -40,34 +39,21 @@ AddSong(const char *playlist_path_utf8,
}
bool
-addAllInToStoredPlaylist(const char *uri_utf8, const char *playlist_path_utf8,
- GError **error_r)
+search_add_to_playlist(const char *uri, const char *playlist_path_utf8,
+ const struct locate_item_list *criteria,
+ GError **error_r)
{
- const DatabaseSelection selection(uri_utf8, true);
+ const DatabaseSelection selection(uri, true, criteria);
using namespace std::placeholders;
const auto f = std::bind(AddSong, playlist_path_utf8, _1, _2);
return GetDatabase()->Visit(selection, f, error_r);
}
-static bool
-SearchAddSong(const char *playlist_path_utf8,
- const struct locate_item_list *criteria,
- song &song, GError **error_r)
-{
- return !locate_list_song_match(&song, criteria) ||
- spl_append_song(playlist_path_utf8, &song, error_r);
-}
-
bool
-search_add_to_playlist(const char *uri, const char *playlist_path_utf8,
- const struct locate_item_list *criteria,
- GError **error_r)
+addAllInToStoredPlaylist(const char *uri_utf8, const char *playlist_path_utf8,
+ GError **error_r)
{
- const DatabaseSelection selection(uri, true);
-
- using namespace std::placeholders;
- const auto f = std::bind(SearchAddSong, playlist_path_utf8,
- criteria, _1, _2);
- return GetDatabase()->Visit(selection, f, error_r);
+ return search_add_to_playlist(uri_utf8, playlist_path_utf8, nullptr,
+ error_r);
}
diff --git a/src/DatabasePlaylist.hxx b/src/DatabasePlaylist.hxx
index 961dc5f2c..269585c32 100644
--- a/src/DatabasePlaylist.hxx
+++ b/src/DatabasePlaylist.hxx
@@ -25,7 +25,7 @@
struct locate_item_list;
-gcc_nonnull(1,2,3)
+gcc_nonnull(1,2)
bool
search_add_to_playlist(const char *uri, const char *path_utf8,
const struct locate_item_list *criteria,
diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx
index 9f2f46d6b..174ce1b70 100644
--- a/src/DatabasePrint.cxx
+++ b/src/DatabasePrint.cxx
@@ -129,37 +129,19 @@ db_selection_print(struct client *client, const DatabaseSelection &selection,
bool full, GError **error_r)
{
using namespace std::placeholders;
- const auto d = std::bind(PrintDirectory, client, _1);
+ const auto d = selection.match == nullptr
+ ? std::bind(PrintDirectory, client, _1)
+ : VisitDirectory();
const auto s = std::bind(full ? PrintSongFull : PrintSongBrief,
client, _1);
- const auto p = std::bind(full ? PrintPlaylistFull : PrintPlaylistBrief,
- client, _1, _2);
+ const auto p = selection.match == nullptr
+ ? std::bind(full ? PrintPlaylistFull : PrintPlaylistBrief,
+ client, _1, _2)
+ : VisitPlaylist();
return GetDatabase()->Visit(selection, d, s, p, error_r);
}
-static bool
-MatchPrintSong(struct client *client, const struct locate_item_list *criteria,
- song &song)
-{
- if (locate_list_song_match(&song, criteria))
- song_print_info(client, &song);
-
- return true;
-}
-
-bool
-findSongsIn(struct client *client, const char *uri,
- const struct locate_item_list *criteria,
- GError **error_r)
-{
- const DatabaseSelection selection(uri, true);
-
- using namespace std::placeholders;
- const auto f = std::bind(MatchPrintSong, client, criteria, _1);
- return GetDatabase()->Visit(selection, f, error_r);
-}
-
struct SearchStats {
int numberOfSongs;
unsigned long playTime;
@@ -172,13 +154,10 @@ static void printSearchStats(struct client *client, SearchStats *stats)
}
static bool
-stats_visitor_song(SearchStats &stats, const struct locate_item_list *criteria,
- song &song)
+stats_visitor_song(SearchStats &stats, song &song)
{
- if (locate_list_song_match(&song, criteria)) {
- stats.numberOfSongs++;
- stats.playTime += song_get_duration(&song);
- }
+ stats.numberOfSongs++;
+ stats.playTime += song_get_duration(&song);
return true;
}
@@ -188,14 +167,14 @@ searchStatsForSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria,
GError **error_r)
{
- const DatabaseSelection selection(name, true);
+ const DatabaseSelection selection(name, true, criteria);
SearchStats stats;
stats.numberOfSongs = 0;
stats.playTime = 0;
using namespace std::placeholders;
- const auto f = std::bind(stats_visitor_song, std::ref(stats), criteria,
+ const auto f = std::bind(stats_visitor_song, std::ref(stats),
_1);
if (!GetDatabase()->Visit(selection, f, error_r))
return false;
@@ -257,11 +236,9 @@ visitTag(struct client *client, StringSet &set,
static bool
unique_tags_visitor_song(struct client *client,
enum tag_type tag_type,
- const struct locate_item_list *criteria,
StringSet &set, song &song)
{
- if (locate_list_song_match(&song, criteria))
- visitTag(client, set, song, tag_type);
+ visitTag(client, set, song, tag_type);
return true;
}
@@ -271,13 +248,13 @@ listAllUniqueTags(struct client *client, int type,
const struct locate_item_list *criteria,
GError **error_r)
{
- const DatabaseSelection selection("", true);
+ const DatabaseSelection selection("", true, criteria);
StringSet set;
using namespace std::placeholders;
const auto f = std::bind(unique_tags_visitor_song, client,
- (enum tag_type)type, criteria, std::ref(set),
+ (enum tag_type)type, std::ref(set),
_1);
if (!GetDatabase()->Visit(selection, f, error_r))
return false;
diff --git a/src/DatabasePrint.hxx b/src/DatabasePrint.hxx
index 95670502e..729bcd19a 100644
--- a/src/DatabasePrint.hxx
+++ b/src/DatabasePrint.hxx
@@ -46,12 +46,6 @@ printInfoForAllIn(struct client *client, const char *uri_utf8,
gcc_nonnull(1,2,3)
bool
-findSongsIn(struct client *client, const char *name,
- const struct locate_item_list *criteria,
- GError **error_r);
-
-gcc_nonnull(1,2,3)
-bool
searchStatsForSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria,
GError **error_r);
diff --git a/src/DatabaseQueue.cxx b/src/DatabaseQueue.cxx
index acbf90741..26ac2c6fd 100644
--- a/src/DatabaseQueue.cxx
+++ b/src/DatabaseQueue.cxx
@@ -23,7 +23,6 @@
extern "C" {
#include "dbUtils.h"
-#include "locate.h"
#include "playlist.h"
}
@@ -47,31 +46,18 @@ AddToQueue(struct player_control *pc, song &song, GError **error_r)
}
bool
-addAllIn(struct player_control *pc, const char *uri, GError **error_r)
+findAddIn(struct player_control *pc, const char *uri,
+ const struct locate_item_list *criteria, GError **error_r)
{
- const DatabaseSelection selection(uri, true);
+ const DatabaseSelection selection(uri, true, criteria);
using namespace std::placeholders;
const auto f = std::bind(AddToQueue, pc, _1, _2);
return GetDatabase()->Visit(selection, f, error_r);
}
-static bool
-MatchAddSong(struct player_control *pc,
- const struct locate_item_list *criteria,
- song &song, GError **error_r)
-{
- return !locate_list_song_match(&song, criteria) ||
- AddToQueue(pc, song, error_r);
-}
-
bool
-findAddIn(struct player_control *pc, const char *uri,
- const struct locate_item_list *criteria, GError **error_r)
+addAllIn(struct player_control *pc, const char *uri, GError **error_r)
{
- const DatabaseSelection selection(uri, true);
-
- using namespace std::placeholders;
- const auto f = std::bind(MatchAddSong, pc, criteria, _1, _2);
- return GetDatabase()->Visit(selection, f, error_r);
+ return findAddIn(pc, uri, nullptr, error_r);
}
diff --git a/src/DatabaseQueue.hxx b/src/DatabaseQueue.hxx
index 546836cac..cf8c3ba5d 100644
--- a/src/DatabaseQueue.hxx
+++ b/src/DatabaseQueue.hxx
@@ -26,7 +26,7 @@
struct locate_item_list;
struct player_control;
-gcc_nonnull(1,2,3)
+gcc_nonnull(1,2)
bool
findAddIn(struct player_control *pc, const char *name,
const struct locate_item_list *criteria, GError **error_r);
diff --git a/src/DatabaseSelection.hxx b/src/DatabaseSelection.hxx
index 3e5232288..35e2c27c9 100644
--- a/src/DatabaseSelection.hxx
+++ b/src/DatabaseSelection.hxx
@@ -25,6 +25,8 @@
#include <assert.h>
#include <stddef.h>
+struct locate_item_list;
+
struct DatabaseSelection {
/**
* The base URI of the search (UTF-8). Must not begin or end
@@ -38,8 +40,11 @@ struct DatabaseSelection {
*/
bool recursive;
- DatabaseSelection(const char *_uri, bool _recursive)
- :uri(_uri), recursive(_recursive) {
+ const locate_item_list *match;
+
+ DatabaseSelection(const char *_uri, bool _recursive,
+ const locate_item_list *_match=nullptr)
+ :uri(_uri), recursive(_recursive), match(_match) {
assert(uri != NULL);
}
};
diff --git a/src/Directory.cxx b/src/Directory.cxx
index b10a0224f..326fa24e9 100644
--- a/src/Directory.cxx
+++ b/src/Directory.cxx
@@ -28,6 +28,7 @@ extern "C" {
#include "util/list_sort.h"
#include "db_visitor.h"
#include "db_lock.h"
+#include "locate.h"
}
#include <glib.h>
@@ -281,7 +282,7 @@ directory_sort(struct directory *directory)
}
bool
-directory::Walk(bool recursive,
+directory::Walk(bool recursive, const locate_item_list *match,
VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist,
GError **error_r) const
@@ -291,7 +292,9 @@ directory::Walk(bool recursive,
if (visit_song) {
struct song *song;
directory_for_each_song(song, this)
- if (!visit_song(*song, error_r))
+ if ((match == NULL ||
+ locate_list_song_match(song, match)) &&
+ !visit_song(*song, error_r))
return false;
}
@@ -309,8 +312,9 @@ directory::Walk(bool recursive,
return false;
if (recursive &&
- !child->Walk(recursive, visit_directory, visit_song,
- visit_playlist, error_r))
+ !child->Walk(recursive, match,
+ visit_directory, visit_song, visit_playlist,
+ error_r))
return false;
}
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index e1cf0167b..08a285d3b 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -27,6 +27,7 @@ extern "C" {
#include "db_save.h"
#include "db_lock.h"
#include "conf.h"
+#include "locate.h"
}
#include "directory.h"
@@ -247,7 +248,9 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
if (directory == NULL) {
struct song *song;
if (visit_song &&
- (song = GetSong(selection.uri, NULL)) != NULL)
+ (song = GetSong(selection.uri, NULL)) != NULL &&
+ (selection.match == NULL ||
+ locate_list_song_match(song, selection.match)))
return visit_song(*song, error_r);
g_set_error(error_r, db_quark(), DB_NOT_FOUND,
@@ -260,7 +263,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
return false;
db_lock();
- bool ret = directory->Walk(selection.recursive,
+ bool ret = directory->Walk(selection.recursive, selection.match,
visit_directory, visit_song, visit_playlist,
error_r);
db_unlock();
diff --git a/src/directory.h b/src/directory.h
index c7e70121f..81eb140c2 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -54,6 +54,7 @@
struct song;
struct db_visitor;
+struct locate_item_list;
struct directory {
/**
@@ -95,7 +96,7 @@ struct directory {
/**
* Caller must lock #db_mutex.
*/
- bool Walk(bool recursive,
+ bool Walk(bool recursive, const locate_item_list *match,
VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist,
GError **error_r) const;