mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-15 18:58:55 +01:00
XSPF support in the GUI
This commit is contained in:
parent
65d88ac831
commit
eb5d4cc309
@ -20,6 +20,7 @@
|
||||
#include "stylesheetloader.h"
|
||||
#include "albumcovermanager.h"
|
||||
#include "m3uparser.h"
|
||||
#include "xspfparser.h"
|
||||
#include "playlistsequence.h"
|
||||
|
||||
#include "qxtglobalshortcut.h"
|
||||
@ -41,7 +42,7 @@
|
||||
const int MainWindow::kStateVersion = 1;
|
||||
const char* MainWindow::kSettingsGroup = "MainWindow";
|
||||
const char* MainWindow::kMediaFilterSpec =
|
||||
"Music (*.mp3 *.ogg *.flac *.mpc *.m4a *.aac *.wma);;Playlists (*.m3u)";
|
||||
"Music (*.mp3 *.ogg *.flac *.mpc *.m4a *.aac *.wma);;Playlists (*.m3u *.xspf *.xml)";
|
||||
|
||||
MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
@ -637,6 +638,12 @@ void MainWindow::AddMedia() {
|
||||
M3UParser parser(&file, info.dir());
|
||||
const SongList& songs = parser.Parse();
|
||||
playlist_->InsertSongs(songs);
|
||||
} else if (path.endsWith(".xspf") || path.endsWith(".xml")) {
|
||||
QFile file(path);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
XSPFParser parser(&file);
|
||||
const SongList& songs = parser.Parse();
|
||||
playlist_->InsertSongs(songs);
|
||||
} else {
|
||||
QUrl url(path);
|
||||
if (url.scheme().isEmpty())
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "songplaylistitem.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
||||
SongPlaylistItem::SongPlaylistItem()
|
||||
@ -14,23 +15,65 @@ SongPlaylistItem::SongPlaylistItem(const Song& song)
|
||||
|
||||
void SongPlaylistItem::Save(QSettings& settings) const {
|
||||
settings.setValue("filename", song_.filename());
|
||||
settings.setValue("library_directory", song_.directory_id());
|
||||
|
||||
settings.setValue("art_automatic", song_.art_automatic());
|
||||
settings.setValue("art_manual", song_.art_manual());
|
||||
|
||||
if (song_.filetype() == Song::Type_Stream) {
|
||||
SaveStream(settings);
|
||||
} else {
|
||||
SaveFile(settings);
|
||||
}
|
||||
}
|
||||
|
||||
void SongPlaylistItem::SaveFile(QSettings& settings) const {
|
||||
settings.setValue("stream", false);
|
||||
settings.setValue("library_directory", song_.directory_id());
|
||||
}
|
||||
|
||||
void SongPlaylistItem::SaveStream(QSettings& settings) const {
|
||||
settings.setValue("stream", true);
|
||||
settings.setValue("title", song_.title());
|
||||
settings.setValue("artist", song_.artist());
|
||||
settings.setValue("album", song_.album());
|
||||
settings.setValue("length", song_.length());
|
||||
}
|
||||
|
||||
void SongPlaylistItem::Restore(const QSettings& settings) {
|
||||
QString filename(settings.value("filename").toString());
|
||||
int directory_id(settings.value("library_directory", -1).toInt());
|
||||
|
||||
song_.InitFromFile(filename, directory_id);
|
||||
song_.set_art_automatic(settings.value("art_automatic").toString());
|
||||
song_.set_art_manual(settings.value("art_manual").toString());
|
||||
|
||||
const bool stream = settings.value("stream", false).toBool();
|
||||
if (stream) {
|
||||
RestoreStream(settings);
|
||||
} else {
|
||||
RestoreFile(settings);
|
||||
}
|
||||
}
|
||||
|
||||
void SongPlaylistItem::RestoreFile(const QSettings& settings) {
|
||||
QString filename(settings.value("filename").toString());
|
||||
|
||||
int directory_id(settings.value("library_directory", -1).toInt());
|
||||
song_.InitFromFile(filename, directory_id);
|
||||
}
|
||||
|
||||
void SongPlaylistItem::RestoreStream(const QSettings& settings) {
|
||||
QString filename(settings.value("filename").toString());
|
||||
song_.set_filename(filename);
|
||||
song_.set_filetype(Song::Type_Stream);
|
||||
|
||||
song_.Init(settings.value("title", "Unknown").toString(),
|
||||
settings.value("artist", "Unknown").toString(),
|
||||
settings.value("album", "Unknown").toString(),
|
||||
settings.value("length", -1).toInt());
|
||||
}
|
||||
|
||||
QUrl SongPlaylistItem::Url() {
|
||||
return QUrl::fromLocalFile(song_.filename());
|
||||
if (QFile::exists(song_.filename())) {
|
||||
return QUrl::fromLocalFile(song_.filename());
|
||||
} else {
|
||||
return song_.filename();
|
||||
}
|
||||
}
|
||||
|
||||
void SongPlaylistItem::Reload() {
|
||||
|
@ -20,6 +20,11 @@ class SongPlaylistItem : public PlaylistItem {
|
||||
QUrl Url();
|
||||
|
||||
private:
|
||||
void SaveFile(QSettings& settings) const;
|
||||
void SaveStream(QSettings& settings) const;
|
||||
|
||||
void RestoreFile(const QSettings& settings);
|
||||
void RestoreStream(const QSettings& settings);
|
||||
Song song_;
|
||||
};
|
||||
|
||||
|
@ -355,9 +355,7 @@ XineEngine::determineAndShowErrorMessage()
|
||||
}
|
||||
|
||||
// TODO
|
||||
/*Amarok::StatusBar::instance()->longMessage(
|
||||
"<b>" + i18n("Error Loading Media") + "</b><p>" + body + "<p>" + m_url.prettyURL(),
|
||||
KDE::StatusBar::Error );*/
|
||||
qWarning() << body;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -104,10 +104,17 @@ Song XSPFParser::ParseTrack(QXmlStreamReader* reader) const {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement: {
|
||||
if (reader->name() == "track") {
|
||||
song.Init(title, artist, album, length);
|
||||
return song;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// At least make an effort if we never find a </track>.
|
||||
song.Init(title, artist, album, length);
|
||||
return song;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user