59 for (
int i = 0; i <
__entries.size(); i++ ) {
70 XMLNode rootNode = doc.firstChildElement(
"playlist" );
71 if ( rootNode.isNull() ) {
72 ERRORLOG(
"playlist node not found" );
78 XMLNode capitalizedSongsNode = rootNode.firstChildElement(
"Songs" );
79 if ( ! capitalizedSongsNode.isNull() ) {
80 legacyNextNode = capitalizedSongsNode.firstChildElement(
"next" );
82 if ( ! legacyNextNode.isNull() ) {
85 if ( ret ==
nullptr ) {
90 WARNINGLOG( QString(
"Upgrading playlist [%1]" ).arg( pl_path ) );
95 QFileInfo fileInfo = QFileInfo( pl_path );
98 auto formatVersionNode = rootNode.firstChildElement(
"formatVersion" );
99 if ( ! formatVersionNode.isNull() ) {
100 WARNINGLOG( QString(
"Playlist file [%1] was created with a more recent version of Hydrogen than the current one!" )
101 .arg( fileInfo.absoluteFilePath() ) );
105 pPlaylist->
setFilename( fileInfo.absoluteFilePath() );
107 XMLNode songsNode = rootNode.firstChildElement(
"songs" );
108 if ( !songsNode.isNull() ) {
109 XMLNode nextNode = songsNode.firstChildElement(
"song" );
110 while ( !nextNode.isNull() ) {
112 QString songPath = nextNode.
read_string(
"path",
"",
false,
false );
113 if ( !songPath.isEmpty() ) {
115 QFileInfo songPathInfo( fileInfo.absoluteDir(), songPath );
116 pEntry->
filePath = songPathInfo.absoluteFilePath();
117 pEntry->
fileExists = songPathInfo.isReadable();
120 pPlaylist->
add( pEntry );
123 nextNode = nextNode.nextSiblingElement(
"song" );
131bool Playlist::save_file(
const QString& pl_path,
const QString& name,
bool overwrite,
bool useRelativePaths )
133 INFOLOG( QString(
"Saving palylist to %1" ).arg( pl_path ) );
135 ERRORLOG( QString(
"palylist %1 already exists" ).arg( pl_path ) );
145 save_to( &songs, useRelativePaths );
146 return doc.
write( pl_path );
153 for (
int i = 0; i <
size(); i++ ) {
156 if ( useRelativePaths ) {
157 path = fileInfo.absoluteDir().relativeFilePath( path );
172 if ( playlist !=
nullptr ) {
195 if (
size() == 0 || songNumber >=
size() ) {
209 if (
size() == 0 || songNumber >=
size() ) {
221 if ( !
get( index )->scriptEnabled || !QFile( file ).exists() ) {
225 std::system( file.toLocal8Bit() );
234 sOutput = QString(
"%1[Playlist]\n" ).arg( sPrefix )
235 .append( QString(
"%1%2filename: %3\n" ).arg( sPrefix ).arg( s ).arg(
__filename ) )
236 .append( QString(
"%1%2m_nSelectedSongNumber: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_nSelectedSongNumber ) )
237 .append( QString(
"%1%2m_nActiveSongNumber: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_nActiveSongNumber ) )
238 .append( QString(
"%1%2entries:\n" ).arg( sPrefix ).arg( s ) );
241 sOutput.append( QString(
"%1%2Entry:\n" ).arg( sPrefix ).arg( s + s ) )
242 .append( QString(
"%1%2filePath: %3\n" ).arg( sPrefix ).arg( s + s + s ).arg( ii->filePath ) )
243 .append( QString(
"%1%2fileExists: %3\n" ).arg( sPrefix ).arg( s + s + s ).arg( ii->fileExists ) )
244 .append( QString(
"%1%2scriptPath: %3\n" ).arg( sPrefix ).arg( s + s + s ).arg( ii->scriptPath ) )
245 .append( QString(
"%1%2scriptEnabled: %3\n" ).arg( sPrefix ).arg( s + s + s ).arg( ii->scriptEnabled ) );
248 sOutput.append( QString(
"%1%2m_bIsModified: %3\n" ).arg( sPrefix ).arg( s ).arg(
m_bIsModified ) );
250 sOutput = QString(
"[Playlist]" )
251 .append( QString(
" filename: %1" ).arg(
__filename ) )
254 .append(
", entries: {" );
257 sOutput.append( QString(
"[filePath: %1" ).arg( ii->filePath ) )
258 .append( QString(
", fileExists: %1" ).arg( ii->fileExists ) )
259 .append( QString(
", scriptPath: %1" ).arg( ii->scriptPath ) )
260 .append( QString(
", scriptEnabled: %1] " ).arg( ii->scriptEnabled ) );
265 sOutput.append( QString(
"}, m_bIsModified: %1\n" ).arg(
m_bIsModified ) );
static QString sPrintIndention
String used to format the debugging string output of some core classes.
static EventQueue * get_instance()
Returns a pointer to the current EventQueue singleton stored in __instance.
void push_event(const EventType type, const int nValue)
Queues the next event into the EventQueue.
static bool file_exists(const QString &path, bool silent=false)
returns true if the given path is an existing regular file
static Playlist * load_playlist(Playlist *pl, const QString &pl_path)
load playlist from a file
static Playlist * __instance
Object holding the current Playlist singleton.
void setNextSongByNumber(int SongNumber)
std::vector< Entry * > __entries
int m_nSelectedSongNumber
void save_to(XMLNode *node, bool useRelativePaths)
static void create_instance()
If __instance equals 0, a new Playlist singleton will be created and stored in it.
void activateSong(int SongNumber)
void execScript(int index)
void setFilename(const QString &filename)
void setSelectedSongNr(int songNumber)
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
void setActiveSongNumber(int ActiveSongNumber)
bool save_file(const QString &pl_path, const QString &name, bool overwrite, bool useRelativePaths)
const QString & getFilename()
static Playlist * load(const QString &filename, bool useRelativePaths)
static Playlist * load_file(const QString &pl_path, bool useRelativePaths)
bool getSongFilenameByNumber(int songNumber, QString &fileName)
XMLDoc is a subclass of QDomDocument with read and write methods.
XMLNode set_root(const QString &node_name, const QString &xmlns=nullptr)
create the xml header and root node
bool read(const QString &filepath, bool bSilent=false)
read the content of an xml file
bool write(const QString &filepath)
write itself into a file
XMLNode is a subclass of QDomNode with read and write values methods.
bool read_bool(const QString &node, bool default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a boolean stored into a child node
QString read_string(const QString &node, const QString &default_value, bool inexistent_ok=true, bool empty_ok=true, bool bSilent=false)
reads a string stored into a child node
XMLNode createNode(const QString &name)
create a new XMLNode that has to be appended into de XMLDoc
void write_string(const QString &node, const QString &value)
write a string into a child node
void write_bool(const QString &node, const bool value)
write a boolean into a child node
@ EVENT_PLAYLIST_LOADSONG