Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
* New: save support for m3u/m3u8 playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
bylee20 committed Mar 2, 2014
1 parent bcaa50f commit 8d37786
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cmplayer/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,9 @@ void MainWindow::connectMenus() {
connect(playlist["save"], &QAction::triggered, this, [this] () {
const Playlist &list = d->playlist.playlist();
if (!list.isEmpty()) {
auto file = _GetSaveFileName(this, tr("Save File"), QString(), tr("Playlist") + " (*.pls)");
auto file = _GetSaveFileName(this, tr("Save File"), QString(), Info::playlistExtFilter());
if (!file.isEmpty()) {
if (QFileInfo(file).suffix().compare("pls", Qt::CaseInsensitive) != 0)
if (QFileInfo(file).suffix().isEmpty())
file += ".pls";
list.save(file);
}
Expand Down
12 changes: 6 additions & 6 deletions src/cmplayer/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ bool Playlist::save(const QString &filePath, Type type) const {
return false;
if (type == Unknown)
type = guessType(file.fileName());
QTextStream out(&file);
out.setCodec("UTF-8");
switch (type) {
case PLS:
return savePLS(&file);
return savePLS(out);
case M3U:
case M3U8:
return saveM3U(&file);
return saveM3U(out);
default:
return false;
}
Expand Down Expand Up @@ -94,8 +96,7 @@ Playlist::Type Playlist::guessType(const QString &fileName) {
return Unknown;
}

bool Playlist::savePLS(QFile *file) const {
QTextStream out(file);
bool Playlist::savePLS(QTextStream &out) const {
const int count = size();
out << "[playlist]" << endl << "NumberOfEntries=" << count << endl << endl;
for (int i=0; i<count; ++i)
Expand All @@ -105,8 +106,7 @@ bool Playlist::savePLS(QFile *file) const {
return true;
}

bool Playlist::saveM3U(QFile *file) const {
QTextStream out(file);
bool Playlist::saveM3U(QTextStream &out) const {
const int count = size();
out << "#EXTM3U\n";
for (int i=0; i<count; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/cmplayer/playlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Playlist : public QList<Mrl> {
Playlist &loadAll(const QDir &dir);
static Type guessType(const QString &fileName);
private:
bool savePLS(QFile *file) const;
bool saveM3U(QFile *file) const;
bool savePLS(QTextStream &out) const;
bool saveM3U(QTextStream &out) const;
bool load(QTextStream &in, QString enc, Type type);
bool loadPLS(QTextStream &in);
bool loadM3U(QTextStream &in);
Expand Down

0 comments on commit 8d37786

Please sign in to comment.