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
98cb8f39
Commit
98cb8f39
authored
Jan 25, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playlist: moved savePlaylist() and loadPlaylsit() to playlist_save.c
parent
69c74afa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
65 deletions
+83
-65
command.c
src/command.c
+3
-2
playlist.c
src/playlist.c
+0
-61
playlist.h
src/playlist.h
+0
-2
playlist_save.c
src/playlist_save.c
+65
-0
playlist_save.h
src/playlist_save.h
+15
-0
No files found.
src/command.c
View file @
98cb8f39
...
...
@@ -20,6 +20,7 @@
#include "player_control.h"
#include "playlist.h"
#include "playlist_print.h"
#include "playlist_save.h"
#include "queue_print.h"
#include "ls.h"
#include "directory.h"
...
...
@@ -668,7 +669,7 @@ handle_save(struct client *client,
{
enum
playlist_result
result
;
result
=
s
avePlaylist
(
argv
[
1
]
);
result
=
s
pl_save_queue
(
argv
[
1
],
playlist_get_queue
()
);
return
print_playlist_result
(
client
,
result
);
}
...
...
@@ -677,7 +678,7 @@ handle_load(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{
enum
playlist_result
result
;
result
=
loadPlaylist
(
argv
[
1
]);
result
=
playlist_load_spl
(
argv
[
1
]);
return
print_playlist_result
(
client
,
result
);
}
...
...
src/playlist.c
View file @
98cb8f39
...
...
@@ -1025,38 +1025,6 @@ void shufflePlaylist(void)
incrPlaylistVersion
();
}
enum
playlist_result
savePlaylist
(
const
char
*
utf8file
)
{
FILE
*
fp
;
char
*
path
;
if
(
!
is_valid_playlist_name
(
utf8file
))
return
PLAYLIST_RESULT_BAD_NAME
;
path
=
map_spl_utf8_to_fs
(
utf8file
);
if
(
path
==
NULL
)
return
PLAYLIST_RESULT_DISABLED
;
if
(
g_file_test
(
path
,
G_FILE_TEST_EXISTS
))
{
g_free
(
path
);
return
PLAYLIST_RESULT_LIST_EXISTS
;
}
while
(
!
(
fp
=
fopen
(
path
,
"w"
))
&&
errno
==
EINTR
);
g_free
(
path
);
if
(
fp
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
for
(
unsigned
i
=
0
;
i
<
queue_length
(
&
playlist
.
queue
);
i
++
)
playlist_print_song
(
fp
,
queue_get
(
&
playlist
.
queue
,
i
));
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
;
idle_add
(
IDLE_STORED_PLAYLIST
);
return
PLAYLIST_RESULT_SUCCESS
;
}
int
getPlaylistCurrentSong
(
void
)
{
if
(
playlist
.
current
>=
0
)
...
...
@@ -1124,35 +1092,6 @@ unsigned getPlaylistSongId(unsigned song)
return
queue_position_to_id
(
&
playlist
.
queue
,
song
);
}
enum
playlist_result
loadPlaylist
(
const
char
*
utf8file
)
{
GPtrArray
*
list
;
if
(
!
(
list
=
spl_load
(
utf8file
)))
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
for
(
unsigned
i
=
0
;
i
<
list
->
len
;
++
i
)
{
const
char
*
temp
=
g_ptr_array_index
(
list
,
i
);
if
((
addToPlaylist
(
temp
,
NULL
))
!=
PLAYLIST_RESULT_SUCCESS
)
{
/* for windows compatibility, convert slashes */
char
*
temp2
=
g_strdup
(
temp
);
char
*
p
=
temp2
;
while
(
*
p
)
{
if
(
*
p
==
'\\'
)
*
p
=
'/'
;
p
++
;
}
if
((
addToPlaylist
(
temp
,
NULL
))
!=
PLAYLIST_RESULT_SUCCESS
)
{
g_warning
(
"can't add file
\"
%s
\"
"
,
temp2
);
}
free
(
temp2
);
}
}
spl_free
(
list
);
return
PLAYLIST_RESULT_SUCCESS
;
}
/*
* Not supporting '/' was done out of laziness, and we should really
* strive to support it in the future.
...
...
src/playlist.h
View file @
98cb8f39
...
...
@@ -144,8 +144,6 @@ enum playlist_result swapSongsInPlaylist(unsigned song1, unsigned song2);
enum
playlist_result
swapSongsInPlaylistById
(
unsigned
id1
,
unsigned
id2
);
enum
playlist_result
loadPlaylist
(
const
char
*
utf8file
);
bool
getPlaylistRepeatStatus
(
void
);
void
setPlaylistRepeatStatus
(
bool
status
);
...
...
src/playlist_save.c
View file @
98cb8f39
...
...
@@ -23,6 +23,7 @@
#include "path.h"
#include "ls.h"
#include "database.h"
#include "idle.h"
#include <glib.h>
...
...
@@ -62,3 +63,67 @@ playlist_print_uri(FILE *file, const char *uri)
g_free
(
s
);
}
}
enum
playlist_result
spl_save_queue
(
const
char
*
name_utf8
,
const
struct
queue
*
queue
)
{
char
*
path_fs
;
FILE
*
file
;
if
(
!
is_valid_playlist_name
(
name_utf8
))
return
PLAYLIST_RESULT_BAD_NAME
;
path_fs
=
map_spl_utf8_to_fs
(
name_utf8
);
if
(
path_fs
==
NULL
)
return
PLAYLIST_RESULT_DISABLED
;
if
(
g_file_test
(
path_fs
,
G_FILE_TEST_EXISTS
))
{
g_free
(
path_fs
);
return
PLAYLIST_RESULT_LIST_EXISTS
;
}
file
=
fopen
(
path_fs
,
"w"
);
g_free
(
path_fs
);
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
for
(
unsigned
i
=
0
;
i
<
queue_length
(
queue
);
i
++
)
playlist_print_song
(
file
,
queue_get
(
queue
,
i
));
fclose
(
file
);
idle_add
(
IDLE_STORED_PLAYLIST
);
return
PLAYLIST_RESULT_SUCCESS
;
}
enum
playlist_result
playlist_load_spl
(
const
char
*
name_utf8
)
{
GPtrArray
*
list
;
list
=
spl_load
(
name_utf8
);
if
(
list
==
NULL
)
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
for
(
unsigned
i
=
0
;
i
<
list
->
len
;
++
i
)
{
const
char
*
temp
=
g_ptr_array_index
(
list
,
i
);
if
((
addToPlaylist
(
temp
,
NULL
))
!=
PLAYLIST_RESULT_SUCCESS
)
{
/* for windows compatibility, convert slashes */
char
*
temp2
=
g_strdup
(
temp
);
char
*
p
=
temp2
;
while
(
*
p
)
{
if
(
*
p
==
'\\'
)
*
p
=
'/'
;
p
++
;
}
if
((
addToPlaylist
(
temp
,
NULL
))
!=
PLAYLIST_RESULT_SUCCESS
)
{
g_warning
(
"can't add file
\"
%s
\"
"
,
temp2
);
}
g_free
(
temp2
);
}
}
spl_free
(
list
);
return
PLAYLIST_RESULT_SUCCESS
;
}
src/playlist_save.h
View file @
98cb8f39
...
...
@@ -19,6 +19,8 @@
#ifndef MPD_PLAYLIST_SAVE_H
#define MPD_PLAYLIST_SAVE_H
#include "playlist.h"
#include <stdio.h>
struct
song
;
...
...
@@ -29,4 +31,17 @@ playlist_print_song(FILE *fp, const struct song *song);
void
playlist_print_uri
(
FILE
*
fp
,
const
char
*
uri
);
/**
* Saves a queue object into a stored playlist file.
*/
enum
playlist_result
spl_save_queue
(
const
char
*
name_utf8
,
const
struct
queue
*
queue
);
/**
* Loads a stored playlist file, and append all songs to the global
* playlist.
*/
enum
playlist_result
playlist_load_spl
(
const
char
*
name_utf8
);
#endif
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