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
1c772ef6
Commit
1c772ef6
authored
Feb 27, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Playlist: use the Error library to return errors
parent
809b89b5
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
76 additions
and
75 deletions
+76
-75
Partition.hxx
src/Partition.hxx
+3
-3
PlaylistSave.cxx
src/PlaylistSave.cxx
+6
-3
PlaylistCommands.cxx
src/command/PlaylistCommands.cxx
+4
-6
QueueCommands.cxx
src/command/QueueCommands.cxx
+11
-9
DatabaseQueue.cxx
src/db/DatabaseQueue.cxx
+3
-9
PlaylistQueue.cxx
src/playlist/PlaylistQueue.cxx
+18
-12
PlaylistQueue.hxx
src/playlist/PlaylistQueue.hxx
+6
-4
Playlist.hxx
src/queue/Playlist.hxx
+10
-4
PlaylistEdit.cxx
src/queue/PlaylistEdit.cxx
+15
-25
No files found.
src/Partition.hxx
View file @
1c772ef6
...
...
@@ -55,10 +55,10 @@ struct Partition final : private PlayerListener, private MixerListener {
playlist
.
Clear
(
pc
);
}
PlaylistResult
AppendURI
(
const
SongLoader
&
loader
,
unsigned
AppendURI
(
const
SongLoader
&
loader
,
const
char
*
uri_utf8
,
unsigned
*
added_id
=
nullpt
r
)
{
return
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
,
added_id
);
Error
&
erro
r
)
{
return
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
,
error
);
}
PlaylistResult
DeletePosition
(
unsigned
position
)
{
...
...
src/PlaylistSave.cxx
View file @
1c772ef6
...
...
@@ -114,13 +114,16 @@ playlist_load_spl(struct playlist &playlist, PlayerControl &pc,
end_index
=
contents
.
size
();
const
SongLoader
loader
(
nullptr
,
nullptr
);
Error
error2
;
for
(
unsigned
i
=
start_index
;
i
<
end_index
;
++
i
)
{
const
auto
&
uri_utf8
=
contents
[
i
];
if
((
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
.
c_str
()))
!=
PlaylistResult
::
SUCCESS
)
FormatError
(
playlist_domain
,
"can't add file
\"
%s
\"
"
,
uri_utf8
.
c_str
());
unsigned
id
=
playlist
.
AppendURI
(
pc
,
loader
,
uri_utf8
.
c_str
(),
error2
);
if
(
id
==
0
)
FormatError
(
error2
,
"can't add file
\"
%s
\"
"
,
uri_utf8
.
c_str
());
}
return
true
;
...
...
src/command/PlaylistCommands.cxx
View file @
1c772ef6
...
...
@@ -66,16 +66,14 @@ handle_load(Client &client, int argc, char *argv[])
}
else
if
(
!
check_range
(
client
,
&
start_index
,
&
end_index
,
argv
[
2
]))
return
CommandResult
::
ERROR
;
Error
error
;
const
SongLoader
loader
(
client
);
const
PlaylistResult
result
=
playlist_open_into_queue
(
argv
[
1
],
if
(
!
playlist_open_into_queue
(
argv
[
1
],
start_index
,
end_index
,
client
.
playlist
,
client
.
player_control
,
loader
);
if
(
result
!=
PlaylistResult
::
NO_SUCH_LIST
)
return
print_playlist_result
(
client
,
result
);
client
.
player_control
,
loader
,
error
))
return
print_error
(
client
,
error
);
Error
error
;
if
(
playlist_load_spl
(
client
.
playlist
,
client
.
player_control
,
argv
[
1
],
start_index
,
end_index
,
error
))
...
...
src/command/QueueCommands.cxx
View file @
1c772ef6
...
...
@@ -64,8 +64,12 @@ handle_add(Client &client, gcc_unused int argc, char *argv[])
if
(
uri_has_scheme
(
uri
)
||
PathTraitsUTF8
::
IsAbsolute
(
uri
))
{
const
SongLoader
loader
(
client
);
auto
result
=
client
.
partition
.
AppendURI
(
loader
,
uri
);
return
print_playlist_result
(
client
,
result
);
Error
error
;
unsigned
id
=
client
.
partition
.
AppendURI
(
loader
,
uri
,
error
);
if
(
id
==
0
)
return
print_error
(
client
,
error
);
return
CommandResult
::
OK
;
}
#ifdef ENABLE_DATABASE
...
...
@@ -88,18 +92,16 @@ handle_addid(Client &client, int argc, char *argv[])
return
CommandResult
::
ERROR
;
const
SongLoader
loader
(
client
);
unsigned
added_id
;
auto
result
=
client
.
partition
.
AppendURI
(
loader
,
uri
,
&
added_id
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
return
print_playlist_result
(
client
,
result
);
Error
error
;
unsigned
added_id
=
client
.
partition
.
AppendURI
(
loader
,
uri
,
error
);
if
(
added_id
==
0
)
return
print_error
(
client
,
error
);
if
(
argc
==
3
)
{
unsigned
to
;
if
(
!
check_unsigned
(
client
,
&
to
,
argv
[
2
]))
return
CommandResult
::
ERROR
;
result
=
client
.
partition
.
MoveId
(
added_id
,
to
);
PlaylistResult
result
=
client
.
partition
.
MoveId
(
added_id
,
to
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
{
CommandResult
ret
=
print_playlist_result
(
client
,
result
);
...
...
src/db/DatabaseQueue.cxx
View file @
1c772ef6
...
...
@@ -23,7 +23,6 @@
#include "Interface.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
#include <functional>
...
...
@@ -32,17 +31,12 @@ static bool
AddToQueue
(
Partition
&
partition
,
const
LightSong
&
song
,
Error
&
error
)
{
const
Storage
&
storage
=
*
partition
.
instance
.
storage
;
PlaylistResult
result
=
unsigned
id
=
partition
.
playlist
.
AppendSong
(
partition
.
pc
,
DatabaseDetachSong
(
storage
,
song
),
nullptr
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
{
error
.
Set
(
playlist_domain
,
int
(
result
),
"Playlist error"
);
return
false
;
}
return
true
;
error
);
return
id
!=
0
;
}
bool
...
...
src/playlist/PlaylistQueue.cxx
View file @
1c772ef6
...
...
@@ -27,16 +27,18 @@
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "fs/Traits.hxx"
#include "util/Error.hxx"
#ifdef ENABLE_DATABASE
#include "SongLoader.hxx"
#endif
PlaylistResult
bool
playlist_load_into_queue
(
const
char
*
uri
,
SongEnumerator
&
e
,
unsigned
start_index
,
unsigned
end_index
,
playlist
&
dest
,
PlayerControl
&
pc
,
const
SongLoader
&
loader
)
const
SongLoader
&
loader
,
Error
&
error
)
{
const
std
::
string
base_uri
=
uri
!=
nullptr
?
PathTraitsUTF8
::
GetParent
(
uri
)
...
...
@@ -58,20 +60,21 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
continue
;
}
PlaylistResult
result
=
dest
.
AppendSong
(
pc
,
std
::
move
(
*
song
)
);
unsigned
id
=
dest
.
AppendSong
(
pc
,
std
::
move
(
*
song
),
error
);
delete
song
;
if
(
result
!=
PlaylistResult
::
SUCCESS
)
return
result
;
if
(
id
==
0
)
return
false
;
}
return
PlaylistResult
::
SUCCESS
;
return
true
;
}
PlaylistResult
bool
playlist_open_into_queue
(
const
char
*
uri
,
unsigned
start_index
,
unsigned
end_index
,
playlist
&
dest
,
PlayerControl
&
pc
,
const
SongLoader
&
loader
)
const
SongLoader
&
loader
,
Error
&
error
)
{
Mutex
mutex
;
Cond
cond
;
...
...
@@ -81,13 +84,16 @@ playlist_open_into_queue(const char *uri,
loader
.
GetStorage
(),
#endif
mutex
,
cond
);
if
(
playlist
==
nullptr
)
return
PlaylistResult
::
NO_SUCH_LIST
;
if
(
playlist
==
nullptr
)
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_LIST
),
"No such playlist"
);
return
false
;
}
PlaylistResult
result
=
bool
result
=
playlist_load_into_queue
(
uri
,
*
playlist
,
start_index
,
end_index
,
dest
,
pc
,
loader
);
dest
,
pc
,
loader
,
error
);
delete
playlist
;
return
result
;
}
src/playlist/PlaylistQueue.hxx
View file @
1c772ef6
...
...
@@ -26,6 +26,7 @@
#include "PlaylistError.hxx"
class
Error
;
class
SongLoader
;
class
SongEnumerator
;
struct
playlist
;
...
...
@@ -40,21 +41,22 @@ struct PlayerControl;
* @param start_index the index of the first song
* @param end_index the index of the last song (excluding)
*/
PlaylistResult
bool
playlist_load_into_queue
(
const
char
*
uri
,
SongEnumerator
&
e
,
unsigned
start_index
,
unsigned
end_index
,
playlist
&
dest
,
PlayerControl
&
pc
,
const
SongLoader
&
loader
);
const
SongLoader
&
loader
,
Error
&
error
);
/**
* Opens a playlist with a playlist plugin and append to the specified
* play queue.
*/
PlaylistResult
bool
playlist_open_into_queue
(
const
char
*
uri
,
unsigned
start_index
,
unsigned
end_index
,
playlist
&
dest
,
PlayerControl
&
pc
,
const
SongLoader
&
loader
);
const
SongLoader
&
loader
,
Error
&
error
);
#endif
src/queue/Playlist.hxx
View file @
1c772ef6
...
...
@@ -146,14 +146,20 @@ public:
void
DatabaseModified
(
const
Database
&
db
);
#endif
PlaylistResult
AppendSong
(
PlayerControl
&
pc
,
/**
* @return the new song id or 0 on error
*/
unsigned
AppendSong
(
PlayerControl
&
pc
,
DetachedSong
&&
song
,
unsigned
*
added_id
=
nullpt
r
);
Error
&
erro
r
);
PlaylistResult
AppendURI
(
PlayerControl
&
pc
,
/**
* @return the new song id or 0 on error
*/
unsigned
AppendURI
(
PlayerControl
&
pc
,
const
SongLoader
&
loader
,
const
char
*
uri_utf8
,
unsigned
*
added_id
=
nullpt
r
);
Error
&
erro
r
);
protected
:
void
DeleteInternal
(
PlayerControl
&
pc
,
...
...
src/queue/PlaylistEdit.cxx
View file @
1c772ef6
...
...
@@ -32,7 +32,6 @@
#include "DetachedSong.hxx"
#include "SongLoader.hxx"
#include "Idle.hxx"
#include "Log.hxx"
#include <stdlib.h>
...
...
@@ -55,14 +54,16 @@ playlist::Clear(PlayerControl &pc)
OnModified
();
}
PlaylistResult
playlist
::
AppendSong
(
PlayerControl
&
pc
,
DetachedSong
&&
song
,
unsigned
*
added_id
)
unsigned
playlist
::
AppendSong
(
PlayerControl
&
pc
,
DetachedSong
&&
song
,
Error
&
error
)
{
unsigned
id
;
if
(
queue
.
IsFull
())
return
PlaylistResult
::
TOO_LARGE
;
if
(
queue
.
IsFull
())
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
TOO_LARGE
),
"Playlist is too large"
);
return
0
;
}
const
DetachedSong
*
const
queued_song
=
GetQueuedSong
();
...
...
@@ -84,30 +85,19 @@ playlist::AppendSong(PlayerControl &pc,
UpdateQueuedSong
(
pc
,
queued_song
);
OnModified
();
if
(
added_id
)
*
added_id
=
id
;
return
PlaylistResult
::
SUCCESS
;
return
id
;
}
PlaylistResult
playlist
::
AppendURI
(
PlayerControl
&
pc
,
const
SongLoader
&
loader
,
const
char
*
uri
,
unsigned
*
added_id
)
unsigned
playlist
::
AppendURI
(
PlayerControl
&
pc
,
const
SongLoader
&
loader
,
const
char
*
uri
,
Error
&
error
)
{
FormatDebug
(
playlist_domain
,
"add to playlist: %s"
,
uri
);
Error
error
;
DetachedSong
*
song
=
loader
.
LoadSong
(
uri
,
error
);
if
(
song
==
nullptr
)
{
// TODO: return the Error
LogError
(
error
);
return
error
.
IsDomain
(
playlist_domain
)
?
PlaylistResult
(
error
.
GetCode
())
:
PlaylistResult
::
NO_SUCH_SONG
;
}
if
(
song
==
nullptr
)
return
0
;
PlaylistResult
result
=
AppendSong
(
pc
,
std
::
move
(
*
song
),
added_id
);
unsigned
result
=
AppendSong
(
pc
,
std
::
move
(
*
song
),
error
);
delete
song
;
return
result
;
...
...
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