Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5582367d
Commit
5582367d
authored
Dec 18, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/DatabasePrint: support sorting by "modified-since"
Closes #172
parent
7a55ab6a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
11 deletions
+40
-11
protocol.xml
doc/protocol.xml
+2
-1
SongFilter.hxx
src/SongFilter.hxx
+5
-0
DatabaseCommands.cxx
src/command/DatabaseCommands.cxx
+14
-3
DatabasePrint.cxx
src/db/DatabasePrint.cxx
+15
-7
DatabasePrint.hxx
src/db/DatabasePrint.hxx
+4
-0
No files found.
doc/protocol.xml
View file @
5582367d
...
...
@@ -1702,7 +1702,8 @@ OK
"ArtistSort", "AlbumSort" or "AlbumArtistSort" instead.
These will automatically fall back to the former if
"*Sort" doesn't exist. "AlbumArtist" falls back to just
"Artist".
"Artist". The type "Last-Modified" can sort by file
modification time.
</para>
<para>
...
...
src/SongFilter.hxx
View file @
5582367d
...
...
@@ -35,6 +35,11 @@
#define LOCATE_TAG_BASE_TYPE (TAG_NUM_OF_ITEM_TYPES + 1)
#define LOCATE_TAG_MODIFIED_SINCE (TAG_NUM_OF_ITEM_TYPES + 2)
/**
* Special value for the db_selection_print() sort parameter.
*/
#define SORT_TAG_LAST_MODIFIED (TAG_NUM_OF_ITEM_TYPES + 3)
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
...
...
src/command/DatabaseCommands.cxx
View file @
5582367d
...
...
@@ -55,6 +55,19 @@ handle_lsinfo2(Client &client, const char *uri, Response &r)
return
CommandResult
::
OK
;
}
static
TagType
ParseSortTag
(
const
char
*
s
)
{
if
(
StringIsEqualIgnoreCase
(
s
,
"Last-Modified"
))
return
TagType
(
SORT_TAG_LAST_MODIFIED
);
TagType
tag
=
tag_name_parse_i
(
s
);
if
(
tag
==
TAG_NUM_OF_ITEM_TYPES
)
throw
ProtocolError
(
ACK_ERROR_ARG
,
"Unknown sort tag"
);
return
tag
;
}
static
CommandResult
handle_match
(
Client
&
client
,
Request
args
,
Response
&
r
,
bool
fold_case
)
{
...
...
@@ -76,9 +89,7 @@ handle_match(Client &client, Request args, Response &r, bool fold_case)
++
s
;
}
sort
=
tag_name_parse_i
(
s
);
if
(
sort
==
TAG_NUM_OF_ITEM_TYPES
)
throw
ProtocolError
(
ACK_ERROR_ARG
,
"Unknown sort tag"
);
sort
=
ParseSortTag
(
s
);
args
.
pop_back
();
args
.
pop_back
();
...
...
src/db/DatabasePrint.cxx
View file @
5582367d
...
...
@@ -220,13 +220,21 @@ db_selection_print(Response &r, Partition &partition,
db
.
Visit
(
selection
,
d
,
collect_songs
,
p
);
}
std
::
stable_sort
(
songs
.
begin
(),
songs
.
end
(),
[
sort
,
descending
](
const
DetachedSong
&
a
,
const
DetachedSong
&
b
){
return
CompareTags
(
sort
,
descending
,
a
.
GetTag
(),
b
.
GetTag
());
});
if
(
sort
==
TagType
(
SORT_TAG_LAST_MODIFIED
))
std
::
stable_sort
(
songs
.
begin
(),
songs
.
end
(),
[
descending
](
const
DetachedSong
&
a
,
const
DetachedSong
&
b
){
return
descending
?
a
.
GetLastModified
()
>
b
.
GetLastModified
()
:
a
.
GetLastModified
()
<
b
.
GetLastModified
();
});
else
std
::
stable_sort
(
songs
.
begin
(),
songs
.
end
(),
[
sort
,
descending
](
const
DetachedSong
&
a
,
const
DetachedSong
&
b
){
return
CompareTags
(
sort
,
descending
,
a
.
GetTag
(),
b
.
GetTag
());
});
if
(
window_end
<
songs
.
size
())
songs
.
erase
(
std
::
next
(
songs
.
begin
(),
window_end
),
...
...
src/db/DatabasePrint.hxx
View file @
5582367d
...
...
@@ -38,6 +38,10 @@ db_selection_print(Response &r, Partition &partition,
const
DatabaseSelection
&
selection
,
bool
full
,
bool
base
);
/**
* @param sort the sort tag; TAG_NUM_OF_ITEM_TYPES means don't sort;
* LOCATE_TAG_MODIFIED_SINCE means sort by file modification time
*/
void
db_selection_print
(
Response
&
r
,
Partition
&
partition
,
const
DatabaseSelection
&
selection
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment