From 90d3aeb642ba4d6445932343010294a39b33efe2 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 12 Nov 2009 22:00:02 +0000 Subject: added multiple playlists support git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1363 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/CMakeLists.txt | 3 + src/qmmpui/mediaplayer.cpp | 43 ++-- src/qmmpui/mediaplayer.h | 12 +- src/qmmpui/playlistmanager.cpp | 395 +++++++++++++++++++++++++++++ src/qmmpui/playlistmanager.h | 200 +++++++++++++++ src/qmmpui/playlistmodel.cpp | 206 +++------------ src/qmmpui/playlistmodel.h | 81 ++---- src/qmmpui/qmmpui.pro | 6 +- src/qmmpui/translations/libqmmpui_cs.ts | 8 + src/qmmpui/translations/libqmmpui_de.ts | 8 + src/qmmpui/translations/libqmmpui_it.ts | 8 + src/qmmpui/translations/libqmmpui_lt.ts | 8 + src/qmmpui/translations/libqmmpui_pl.ts | 8 + src/qmmpui/translations/libqmmpui_pt_BR.ts | 8 + src/qmmpui/translations/libqmmpui_ru.ts | 8 + src/qmmpui/translations/libqmmpui_tr.ts | 8 + src/qmmpui/translations/libqmmpui_uk_UA.ts | 8 + src/qmmpui/translations/libqmmpui_zh_CN.ts | 8 + src/qmmpui/translations/libqmmpui_zh_TW.ts | 8 + 19 files changed, 767 insertions(+), 267 deletions(-) create mode 100644 src/qmmpui/playlistmanager.cpp create mode 100644 src/qmmpui/playlistmanager.h (limited to 'src/qmmpui') diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index af54b4145..84b640b7a 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -38,6 +38,7 @@ SET(libqmmpui_SRCS playlistsettings.cpp detailsdialog.cpp tageditor.cpp + playlistmanager.cpp ) SET(libqmmpui_MOC_HDRS @@ -60,6 +61,7 @@ SET(libqmmpui_MOC_HDRS playlistsettings.h detailsdialog.h tageditor.h + playlistmanager.h ) SET(libqmmpui_DEVEL_HDRS @@ -78,6 +80,7 @@ SET(libqmmpui_DEVEL_HDRS playlistparser.h detailsdialog.h tageditor.h + playlistmanager.h ) diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp index 0d47dd257..d50cea3ce 100644 --- a/src/qmmpui/mediaplayer.cpp +++ b/src/qmmpui/mediaplayer.cpp @@ -22,11 +22,7 @@ #include #include #include - -#include -#include "playlistmodel.h" #include "playlistitem.h" - #include "mediaplayer.h" #define MAX_SKIPS 5 @@ -37,7 +33,7 @@ MediaPlayer::MediaPlayer(QObject *parent) : QObject(parent) { m_instance = this; - m_model = 0; + m_pl_manager = 0; m_core = 0; m_skips = 0; m_repeat = FALSE; @@ -47,7 +43,6 @@ MediaPlayer::MediaPlayer(QObject *parent) qApp->installTranslator(translator); } - MediaPlayer::~MediaPlayer() {} @@ -56,20 +51,20 @@ MediaPlayer* MediaPlayer::instance() return m_instance; } -void MediaPlayer::initialize(SoundCore *core, PlayListModel *model) +void MediaPlayer::initialize(SoundCore *core, PlayListManager *pl_manager) { Q_CHECK_PTR(core); - Q_CHECK_PTR(model); + Q_CHECK_PTR(m_pl_manager); m_core = core; - m_model = model; + m_pl_manager = pl_manager; m_repeat = FALSE; connect(m_core, SIGNAL(aboutToFinish()), SLOT(updateNextUrl())); connect(m_core, SIGNAL(finished()), SLOT(next())); } -PlayListModel *MediaPlayer::playListModel() +PlayListManager *MediaPlayer::playListManager() { - return m_model; + return m_pl_manager; } bool MediaPlayer::isRepeatable() const @@ -79,17 +74,17 @@ bool MediaPlayer::isRepeatable() const void MediaPlayer::play() { - m_model->doCurrentVisibleRequest(); + m_pl_manager->currentPlayList()->doCurrentVisibleRequest(); if (m_core->state() == Qmmp::Paused) { m_core->pause(); return; } - if (m_model->count() == 0) + if (m_pl_manager->currentPlayList()->count() == 0) return; - QString s = m_model->currentItem()->url(); + QString s = m_pl_manager->currentPlayList()->currentItem()->url(); if (s.isEmpty()) { m_nextUrl.clear(); @@ -122,11 +117,11 @@ void MediaPlayer::play() break; } qApp->processEvents(); - if (!m_model->isEmptyQueue()) + if (!m_pl_manager->currentPlayList()->isEmptyQueue()) { - m_model->setCurrentToQueued(); + m_pl_manager->currentPlayList()->setCurrentToQueued(); } - else if (!m_model->next()) + else if (!m_pl_manager->currentPlayList()->next()) { stop(); return; @@ -148,11 +143,11 @@ void MediaPlayer::stop() void MediaPlayer::next() { - if (!m_model->isEmptyQueue()) + if (!m_pl_manager->currentPlayList()->isEmptyQueue()) { - m_model->setCurrentToQueued(); + m_pl_manager->currentPlayList()->setCurrentToQueued(); } - else if (!m_model->next()) + else if (!m_pl_manager->currentPlayList()->next()) { stop(); return; @@ -168,7 +163,7 @@ void MediaPlayer::next() void MediaPlayer::previous() { - if (!m_model->previous()) + if (!m_pl_manager->currentPlayList()->previous()) { stop(); return; @@ -200,10 +195,10 @@ void MediaPlayer::setRepeatable(bool r) void MediaPlayer::updateNextUrl() { - if(m_model->nextItem() && !isRepeatable()) + if(m_pl_manager->currentPlayList()->nextItem() && !isRepeatable()) { - m_core->play(m_model->nextItem()->url(), TRUE); - m_nextUrl = m_model->nextItem()->url(); + m_core->play(m_pl_manager->currentPlayList()->nextItem()->url(), TRUE); + m_nextUrl = m_pl_manager->currentPlayList()->nextItem()->url(); qDebug("MediaPlayer: sending next url"); } else diff --git a/src/qmmpui/mediaplayer.h b/src/qmmpui/mediaplayer.h index d0b84fad3..77969542c 100644 --- a/src/qmmpui/mediaplayer.h +++ b/src/qmmpui/mediaplayer.h @@ -21,9 +21,9 @@ #define MEDIAPLAYER_H #include +#include +#include "playlistmanager.h" -class PlayListModel; -class SoundCore; /*! @brief The MediaPlayer class provides a simple way to use SoundCore and PlayListModel together. * @author Ilya Kotov @@ -50,11 +50,11 @@ public: * @param core Pointer to the SoundCore object. * @param model Playlist model */ - void initialize(SoundCore *core, PlayListModel *model); + void initialize(SoundCore *core, PlayListManager *pl_mamager); /*! - * Returns playlist model pointer + * Returns playlist manager pointer */ - PlayListModel *playListModel(); + PlayListManager *playListManager(); /*! * Returns \b true if "Repeate Track" option is enabled, otherwise returns \b false */ @@ -94,7 +94,7 @@ private slots: void updateNextUrl(); private: - PlayListModel *m_model; + PlayListManager *m_pl_manager; SoundCore *m_core; static MediaPlayer* m_instance; bool m_repeat; diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp new file mode 100644 index 000000000..f49d72749 --- /dev/null +++ b/src/qmmpui/playlistmanager.cpp @@ -0,0 +1,395 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "playlistsettings.h" +#include "playlistmanager.h" + +PlayListManager::PlayListManager(QObject *parent) : QObject(parent) +{ + m_current = 0; + m_selected = 0; + m_repeatable = FALSE; + m_shuffle = FALSE; + readPlayLists(); +} + +PlayListManager::~PlayListManager() +{ + writePlayLists(); + delete PlaylistSettings::instance(); +} + +PlayListModel *PlayListManager::selectedPlayList() const +{ + return m_selected; +} + +PlayListModel *PlayListManager::currentPlayList() const +{ + return m_current; +} + +QList PlayListManager::playLists() const +{ + return m_models; +} + +QStringList PlayListManager::playListNames() const +{ + QStringList names; + foreach(PlayListModel *model, m_models) + names << model->name(); + return names; +} + +void PlayListManager::selectPlayList(PlayListModel *model) +{ + if(model != m_selected && m_models.contains(model)) + { + PlayListModel *prev = m_selected; + m_selected = model; + emit selectedPlayListChanged(model, prev); + } +} + +void PlayListManager::selectPlayList(int i) +{ + if(i > m_models.count() - 1) + return; + selectPlayList(playListAt(i)); +} + +void PlayListManager::activatePlayList(PlayListModel *model) +{ + if(model != m_current && m_models.contains(model)) + { + PlayListModel *prev = m_current; + m_current = model; + emit currentPlayListChanged(model, prev); + } +} + +PlayListModel *PlayListManager::createPlayList(const QString &name) +{ + PlayListModel *model = new PlayListModel (name.isEmpty() ? tr("Playlist") : name, this); + int i = m_models.indexOf(m_selected); + m_models.insert(i, model); + model->prepareForRepeatablePlaying(m_repeatable); + model->prepareForShufflePlaying(m_shuffle); + emit playListAdded(i); + return model; +} + +void PlayListManager::removePlayList(PlayListModel *model) +{ + if(m_models.count() < 2 || !m_models.contains(model)) + return; + + int i = m_models.indexOf(model); + + if(m_current == model) + activatePlayList(m_models.at(i + (i > 0) ? -1 : 1)); + if(m_selected == model) + selectPlayList(m_models.at(i + (i > 0) ? -1 : 1)); + m_models.removeAt(i); + model->deleteLater(); + emit playListRemoved(i); +} + +void PlayListManager::setRepeatableList(bool r) +{ + if(m_repeatable == r) + return; + m_repeatable = r; + foreach(PlayListModel *model, m_models) + model->prepareForRepeatablePlaying(r); + emit repeatableListChanged(r); +} + +void PlayListManager::setShuffle(bool s) +{ + if(m_shuffle == s) + return; + m_shuffle = s; + foreach(PlayListModel *model, m_models) + model->prepareForShufflePlaying(s); + emit shuffleChanged(s); +} + +int PlayListManager::count() +{ + return m_models.count(); +} + +int PlayListManager::indexOf(PlayListModel *model) +{ + return m_models.indexOf(model); +} + +PlayListModel *PlayListManager::playListAt(int i) +{ + if(i >= 0 || i < m_models.count()) + return m_models.at(i); + return 0; +} + +bool PlayListManager::convertUnderscore() +{ + return PlaylistSettings::instance()->convertUnderscore(); +} + +bool PlayListManager::convertTwenty() +{ + return PlaylistSettings::instance()->convertTwenty(); +} + +bool PlayListManager::useMetadata() +{ + return PlaylistSettings::instance()->useMetadata(); +} + +const QString PlayListManager::format() const +{ + return PlaylistSettings::instance()->format(); +} + +void PlayListManager::setConvertUnderscore(bool yes) +{ + PlaylistSettings::instance()->setConvertUnderscore(yes); + emit settingsChanged(); +} + +void PlayListManager::setConvertTwenty(bool yes) +{ + PlaylistSettings::instance()->setConvertTwenty(yes); + emit settingsChanged(); +} + +void PlayListManager::setUseMetadata(bool yes) +{ + PlaylistSettings::instance()->setUseMetadata(yes); + emit settingsChanged(); +} + +void PlayListManager::setFormat(const QString &format) +{ + PlaylistSettings::instance()->setFormat(format); + emit settingsChanged(); +} + +bool PlayListManager::isRepeatableList() const +{ + return m_repeatable; +} + +bool PlayListManager::isShuffle() const +{ + return m_shuffle; +} + +void PlayListManager::readPlayLists() +{ + QString line, param, value; + int s; + QList infoList; + QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); + file.open(QIODevice::ReadOnly); + QByteArray array = file.readAll(); + file.close(); + QBuffer buffer(&array); + buffer.open(QIODevice::ReadOnly); + + while (!buffer.atEnd()) + { + line = QString::fromUtf8(buffer.readLine()).trimmed(); + if ((s = line.indexOf("=")) < 0) + continue; + + param = line.left(s); + value = line.right(line.size() - s - 1); + + if(param == "playlist") + { + if(!m_models.isEmpty()) + { + foreach(FileInfo *info, infoList) + m_models.last()->add(new PlayListItem(info)); + } + infoList.clear(); + m_models << new PlayListModel(value, this); + } + else if (param == "file") + infoList << new FileInfo(value); + else if (infoList.isEmpty()) + continue; + else if (param == "title") + infoList.last()->setMetaData(Qmmp::TITLE, value); + else if (param == "artist") + infoList.last()->setMetaData(Qmmp::ARTIST, value); + else if (param == "album") + infoList.last()->setMetaData(Qmmp::ALBUM, value); + else if (param == "comment") + infoList.last()->setMetaData(Qmmp::COMMENT, value); + else if (param == "genre") + infoList.last()->setMetaData(Qmmp::GENRE, value); + else if (param == "composer") + infoList.last()->setMetaData(Qmmp::COMPOSER, value); + else if (param == "year") + infoList.last()->setMetaData(Qmmp::YEAR, value); + else if (param == "track") + infoList.last()->setMetaData(Qmmp::TRACK, value); + else if (param == "disc") + infoList.last()->setMetaData(Qmmp::DISCNUMBER, value); + else if (param == "length") + infoList.last()->setLength(value.toInt()); + } + buffer.close(); + if(!m_models.isEmpty()) + { + foreach(FileInfo *info, infoList) + m_models.last()->add(new PlayListItem(info)); + } + else + m_models << new PlayListModel("Default",this); + m_selected = m_models.at(0); + m_current = m_models.at(0); +} + +void PlayListManager::writePlayLists() +{ + QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); + file.open(QIODevice::WriteOnly); + foreach(PlayListModel *model, m_models) + { + QList items = model->items(); + file.write(QString("playlist=%1").arg(model->name()).toUtf8() +"\n"); + foreach(PlayListItem* m, items) + { + file.write(QString("file=%1").arg(m->url()).toUtf8() +"\n"); + file.write(QString("title=%1").arg(m->title()).toUtf8() +"\n"); + file.write(QString("artist=%1").arg(m->artist()).toUtf8() +"\n"); + file.write(QString("album=%1").arg(m->album()).toUtf8() +"\n"); + file.write(QString("comment=%1").arg(m->comment()).toUtf8() +"\n"); + file.write(QString("genre=%1").arg(m->genre()).toUtf8() +"\n"); + file.write(QString("composer=%1").arg(m->composer()).toUtf8() +"\n"); + file.write(QString("year=%1").arg(m->year()).toUtf8() +"\n"); + file.write(QString("track=%1").arg(m->track()).toUtf8() +"\n"); + file.write(QString("disc=%1").arg(m->discNumber()).toUtf8() +"\n"); + file.write(QString("length=%1").arg(m->length()).toUtf8() +"\n"); + } + } + file.close(); +} + +void PlayListManager::clear() +{ + m_selected->clear(); +} + +void PlayListManager::clearSelection() +{ + m_selected->clearSelection(); +} + +void PlayListManager::removeSelected() +{ + m_selected->removeSelected(); +} + +void PlayListManager::removeUnselected() +{ + m_selected->removeUnselected(); +} + +void PlayListManager::removeAt (int i) +{ + m_selected->removeAt(i); +} + +void PlayListManager::removeItem (PlayListItem *item) +{ + m_selected->removeItem(item); +} + +void PlayListManager::invertSelection() +{ + m_selected->invertSelection(); +} + +void PlayListManager::selectAll() +{ + m_selected->selectAll(); +} + +void PlayListManager::showDetails() +{ + m_selected->showDetails(); +} + +void PlayListManager::addFile(const QString &path) +{ + m_selected->addFile(path); +} + +void PlayListManager::addFiles(const QStringList& l) +{ + m_selected->addFiles(l); +} + +void PlayListManager::addDirectory(const QString& dir) +{ + m_selected->addDirectory(dir); +} + +void PlayListManager::randomizeList() +{ + m_selected->randomizeList(); +} + +void PlayListManager::reverseList() +{ + m_selected->reverseList(); +} + +void PlayListManager::sortSelection(int mode) +{ + m_selected->sortSelection(mode); +} + +void PlayListManager::sort(int mode) +{ + m_selected->sort(mode); +} + +void PlayListManager::addToQueue() +{ + m_selected->addToQueue(); +} + +void PlayListManager::clearInvalidItems() +{ + m_selected->clearInvalidItems(); +} diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h new file mode 100644 index 000000000..d6550e063 --- /dev/null +++ b/src/qmmpui/playlistmanager.h @@ -0,0 +1,200 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PLAYLISTMANAGER_H +#define PLAYLISTMANAGER_H + +#include +#include "playlistmodel.h" + +/*! + * @author Ilya Kotov + */ +class PlayListManager : public QObject +{ +Q_OBJECT +public: + PlayListManager(QObject *parent); + ~PlayListManager(); + + QList playLists() const; + QStringList playListNames() const; + PlayListModel *selectedPlayList() const; + PlayListModel *currentPlayList() const; + int count(); + int indexOf(PlayListModel *model); + PlayListModel *playListAt(int i); + /*! + * Returns state of the "Convert underscores to blanks" option (\b true - enabled, \b false - disabled). + */ + bool convertUnderscore(); + /*! + * Returns state of the "Convert %20 to blanks" option (\b true - enabled, \b false - disabled). + */ + bool convertTwenty(); + /*! + * Returns the state of metadata usage (\b true - use, \b false - not use). + */ + bool useMetadata(); + /*! + * Returns title format string. + */ + const QString format() const; + /*! + * Sets the "Convert underscores to blanks" option state to \b enabled + * @param enabled Option state (\b true - enabled, \b false - disabled) + */ + void setConvertUnderscore(bool enabled); + /*! + * Sets the "Convert %20 to blanks" option state to \b enabled + * @param enabled Option state (\b true - enabled, \b false - disabled) + */ + void setConvertTwenty(bool enabled); + /*! + * Sets metadata usage option state to \b enabled + * @param enabled Option state (\b true - enabled, \b false - disabled) + */ + void setUseMetadata(bool enabled); + /*! + * Sets short title format + * @param format title format. (Expressions: "%p" - artist, "%a" - album, "%t" - title, "%n" - track, + * "%g" - genre, "%c" - comment, "%C" - composer, "%D" - disc number "%f" - file name, " + * %F" - full path, "%y" - year) + */ + void setFormat(const QString &format); + /*! + * Returns state of "Repeat All" option. + */ + bool isRepeatableList() const; + /*! + * Returns state of "Shuffle" option. + */ + bool isShuffle() const; + +signals: + void currentPlayListChanged (PlayListModel *current, PlayListModel *previous); + void selectedPlayListChanged (PlayListModel *selected, PlayListModel *previous); + void playListAdded(int index); + void playListRemoved(int index); + /*! + * Emitted when state of the "Repeat All" option has changed. + * @param state New state of the "Repeat All" option (\b true - enabled, \b false disabled) + */ + void repeatableListChanged(bool state); + /*! + * Emitted when state of the "Shuffle" option has changed. + * @param state New state of the "Shuffle" option (\b true - enabled, \b false disabled) + */ + void shuffleChanged(bool state); + /*! + * Emitted when other settings (format, metadata, etc) have changed. + */ + void settingsChanged(); + +public slots: + void selectPlayList(PlayListModel *model); + void selectPlayList(int index); + void activatePlayList(PlayListModel *model); + PlayListModel *createPlayList(const QString &name = QString()); + void removePlayList(PlayListModel *model); + void setRepeatableList(bool r); + void setShuffle(bool s); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->clear() + */ + void clear(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->clearSelection() + */ + void clearSelection(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->removeSelected() + */ + void removeSelected(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->removeUnselected() + */ + void removeUnselected(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->removeAt(i) + */ + void removeAt (int i); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->removeItem(item) + */ + void removeItem (PlayListItem *item); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->invertSelection() + */ + void invertSelection(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->selectAll() + */ + void selectAll(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->showDetails() + */ + void showDetails(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->addFile(path) + */ + void addFile(const QString &path); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->addFiles(l) + */ + void addFiles(const QStringList& l); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->addDirectory(dir) + */ + void addDirectory(const QString& dir); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->randomizeList() + */ + void randomizeList(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->reverseList() + */ + void reverseList(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->sortSelection(mode) + */ + void sortSelection(int mode); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->sort(mode) + */ + void sort(int mode); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->addToQueue() + */ + void addToQueue(); + /*! + * This is a convenience function and is the same as calling \b selectedPlayList()->clearInvalidItems() + */ + void clearInvalidItems(); + +private: + void readPlayLists(); + void writePlayLists(); + QList m_models; + PlayListModel *m_current; + PlayListModel *m_selected; + bool m_repeatable, m_shuffle; +}; + +#endif // PLAYLISTMANAGER_H diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp index 0f1eda511..c87ad7409 100644 --- a/src/qmmpui/playlistmodel.cpp +++ b/src/qmmpui/playlistmodel.cpp @@ -34,11 +34,12 @@ #include "playlistparser.h" #include "playlistformat.h" #include "fileloader.h" -#include "playlistmodel.h" #include "playlistitem.h" #include "playstate.h" #include "detailsdialog.h" #include "playlistsettings.h" +#include "playlistmodel.h" + #define INVALID_ROW -1 @@ -63,27 +64,22 @@ void TagUpdater::updateTag() } } - -PlayListModel::PlayListModel(QObject *parent) +PlayListModel::PlayListModel(const QString &name, QObject *parent) : QObject(parent) , m_selection() { qsrand(time(0)); + m_name = name; m_shuffle = 0; m_total_length = 0; m_current = 0; - m_block_update_signals = false; is_repeatable_list = false; m_play_state = new NormalPlayState(this); - readSettings(); } PlayListModel::~PlayListModel() { - writeSettings(); clear(); delete m_play_state; - //qDeleteAll(m_registered_pl_formats); - foreach(GuardedFileLoader l,m_running_loaders) { if (!l.isNull()) @@ -92,10 +88,19 @@ PlayListModel::~PlayListModel() l->wait(); } } - delete PlaylistSettings::instance(); } -void PlayListModel::load(PlayListItem *item) +QString PlayListModel::name() const +{ + return m_name; +} + +void PlayListModel::setName(const QString &name) +{ + m_name = name; +} + +void PlayListModel::add(PlayListItem *item) { if (m_items.isEmpty()) m_currentItem = item; @@ -105,9 +110,25 @@ void PlayListModel::load(PlayListItem *item) if (m_items.size() == 1) emit firstAdded(); + m_current = m_items.indexOf(m_currentItem); + emit listChanged(); +} - if (!m_block_update_signals) - emit listChanged(); +void PlayListModel::add(QList items) +{ + if(items.isEmpty()) + return; + if (m_items.isEmpty()) + m_currentItem = items.at(0); + + foreach(PlayListItem *item, items) + m_total_length += item->length(); + m_items.append(items); + + if (m_items.size() == items.size()) + emit firstAdded(); + m_current = m_items.indexOf(m_currentItem); + emit listChanged(); } int PlayListModel::count() @@ -117,10 +138,7 @@ int PlayListModel::count() PlayListItem* PlayListModel::currentItem() { - if (m_items.isEmpty()) - return 0; - else - return m_items.at(qMin(m_items.size() - 1, m_current)); + return m_items.isEmpty() ? 0 : m_items.at(qMin(m_items.size() - 1, m_current)); } PlayListItem* PlayListModel::nextItem() @@ -153,12 +171,10 @@ bool PlayListModel::setCurrent(int c) return TRUE; } - bool PlayListModel::next() { if (isFileLoaderRunning()) m_play_state->prepare(); - return m_play_state->next(); } @@ -166,8 +182,7 @@ bool PlayListModel::previous() { if (isFileLoaderRunning()) m_play_state->prepare(); - - return m_play_state->previous();//) + return m_play_state->previous(); } void PlayListModel::clear() @@ -362,89 +377,6 @@ void PlayListModel::showDetails() } } -void PlayListModel::readSettings() -{ - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - m_current = settings.value("Playlist/current",0).toInt(); - - QString line, param, value; - int s; - QList infoList; - QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); - file.open(QIODevice::ReadOnly); - QByteArray array = file.readAll(); - file.close(); - QBuffer buffer(&array); - buffer.open(QIODevice::ReadOnly); - while (!buffer.atEnd()) - { - line = QString::fromUtf8(buffer.readLine()).trimmed(); - if ((s = line.indexOf("=")) < 0) - continue; - - param = line.left(s); - value = line.right(line.size() - s - 1); - - if (param == "file") - infoList << new FileInfo(value); - else if (infoList.isEmpty()) - continue; - else if (param == "title") - infoList.last()->setMetaData(Qmmp::TITLE, value); - else if (param == "artist") - infoList.last()->setMetaData(Qmmp::ARTIST, value); - else if (param == "album") - infoList.last()->setMetaData(Qmmp::ALBUM, value); - else if (param == "comment") - infoList.last()->setMetaData(Qmmp::COMMENT, value); - else if (param == "genre") - infoList.last()->setMetaData(Qmmp::GENRE, value); - else if (param == "composer") - infoList.last()->setMetaData(Qmmp::COMPOSER, value); - else if (param == "year") - infoList.last()->setMetaData(Qmmp::YEAR, value); - else if (param == "track") - infoList.last()->setMetaData(Qmmp::TRACK, value); - else if (param == "disc") - infoList.last()->setMetaData(Qmmp::DISCNUMBER, value); - else if (param == "length") - infoList.last()->setLength(value.toInt()); - } - buffer.close(); - if (m_current > infoList.count() - 1) - m_current = 0; - m_block_update_signals = TRUE; - foreach(FileInfo *info, infoList) - load(new PlayListItem(info)); - m_block_update_signals = FALSE; - if(!m_items.isEmpty()) - m_currentItem = m_items.at(m_current); - doCurrentVisibleRequest(); -} - -void PlayListModel::writeSettings() -{ - QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); - file.open(QIODevice::WriteOnly); - foreach(PlayListItem* m, m_items) - { - file.write(QString("file=%1").arg(m->url()).toUtf8() +"\n"); - file.write(QString("title=%1").arg(m->title()).toUtf8() +"\n"); - file.write(QString("artist=%1").arg(m->artist()).toUtf8() +"\n"); - file.write(QString("album=%1").arg(m->album()).toUtf8() +"\n"); - file.write(QString("comment=%1").arg(m->comment()).toUtf8() +"\n"); - file.write(QString("genre=%1").arg(m->genre()).toUtf8() +"\n"); - file.write(QString("composer=%1").arg(m->composer()).toUtf8() +"\n"); - file.write(QString("year=%1").arg(m->year()).toUtf8() +"\n"); - file.write(QString("track=%1").arg(m->track()).toUtf8() +"\n"); - file.write(QString("disc=%1").arg(m->discNumber()).toUtf8() +"\n"); - file.write(QString("length=%1").arg(m->length()).toUtf8() +"\n"); - } - file.close(); - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - settings.setValue("Playlist/current", m_current); -} - void PlayListModel::addFile(const QString& path) { if (path.isEmpty()) @@ -452,7 +384,7 @@ void PlayListModel::addFile(const QString& path) QList playList = MetaDataManager::instance()->createPlayList(path, PlaylistSettings::instance()->useMetadata()); foreach(FileInfo *info, playList) - emit load(new PlayListItem(info)); + add(new PlayListItem(info)); m_play_state->prepare(); } @@ -462,7 +394,7 @@ FileLoader * PlayListModel::createFileLoader() FileLoader* f_loader = new FileLoader(this); // f_loader->setStackSize(20 * 1024 * 1024); m_running_loaders << f_loader; - connect(f_loader,SIGNAL(newPlayListItem(PlayListItem*)),this,SLOT(load(PlayListItem*)),Qt::QueuedConnection); + connect(f_loader,SIGNAL(newPlayListItem(PlayListItem*)), SLOT(add(PlayListItem*)),Qt::QueuedConnection); connect(f_loader,SIGNAL(finished()),this,SLOT(preparePlayState())); connect(f_loader,SIGNAL(finished()),f_loader,SLOT(deleteLater())); return f_loader; @@ -583,8 +515,6 @@ void PlayListModel::moveItems(int from, int to) } } - - int PlayListModel::topmostInSelection(int row) { if (row == 0) @@ -654,14 +584,7 @@ void PlayListModel::addToQueue() { QList selected_items = getSelectedItems(); foreach(PlayListItem* file,selected_items) - {/* - if(isQueued(file)) - m_queued_songs.removeAt(m_queued_songs.indexOf(file)); - else - m_queued_songs.append(file); - */ setQueued(file); - } emit listChanged(); } @@ -671,7 +594,6 @@ void PlayListModel::setQueued(PlayListItem* file) m_queued_songs.removeAt(m_queued_songs.indexOf(file)); else m_queued_songs.append(file); - emit listChanged(); } @@ -885,14 +807,11 @@ void PlayListModel::prepareForShufflePlaying(bool val) m_play_state = new NormalPlayState(this); m_shuffle = val; - - emit shuffleChanged(val); } void PlayListModel::prepareForRepeatablePlaying(bool val) { is_repeatable_list = val; - emit repeatableListChanged(val); } void PlayListModel::doCurrentVisibleRequest() @@ -901,13 +820,6 @@ void PlayListModel::doCurrentVisibleRequest() emit listChanged(); } -void PlayListModel::setUpdatesEnabled(bool yes) -{ - m_block_update_signals = !yes; - if (yes) - emit listChanged(); -} - void PlayListModel::loadPlaylist(const QString &f_name) { PlaylistFormat* prs = PlaylistParser::instance()->findByPath(f_name); @@ -975,50 +887,6 @@ void PlayListModel::preparePlayState() m_play_state->prepare(); } -bool PlayListModel::convertUnderscore() -{ - return PlaylistSettings::instance()->convertUnderscore(); -} - -bool PlayListModel::convertTwenty() -{ - return PlaylistSettings::instance()->convertTwenty(); -} - -bool PlayListModel::useMetadata() -{ - return PlaylistSettings::instance()->useMetadata(); -} - -const QString PlayListModel::format() const -{ - return PlaylistSettings::instance()->format(); -} - -void PlayListModel::setConvertUnderscore(bool yes) -{ - PlaylistSettings::instance()->setConvertUnderscore(yes); - emit settingsChanged(); -} - -void PlayListModel::setConvertTwenty(bool yes) -{ - PlaylistSettings::instance()->setConvertTwenty(yes); - emit settingsChanged(); -} - -void PlayListModel::setUseMetadata(bool yes) -{ - PlaylistSettings::instance()->setUseMetadata(yes); - emit settingsChanged(); -} - -void PlayListModel::setFormat(const QString &format) -{ - PlaylistSettings::instance()->setFormat(format); - emit settingsChanged(); -} - void PlayListModel::clearInvalidItems() { foreach(PlayListItem *item, m_items) diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index 8e945da57..834d38f1f 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -26,6 +26,7 @@ #include #include #include +#include "playlistitem.h" class FileLoader; class PlayListItem; @@ -102,11 +103,14 @@ public: * Constructs a playlist model. * @param parent QObject parent */ - PlayListModel(QObject *parent = 0); + PlayListModel(const QString &name, QObject *parent = 0); /*! * Object destructor. */ ~PlayListModel(); + + QString name() const; + void setName(const QString &name); /*! * Returns number of items. */ @@ -201,15 +205,15 @@ public: /*! * Returns list with selected rows indexes. */ - QList getSelectedRows()const; + QList getSelectedRows() const; /*! * Returns list of \b PlayListItem pointers that are selected. */ - QList getSelectedItems()const; + QList getSelectedItems() const; /*! * Returns list of all \b PlayListItem pointers. */ - QList items()const + QList items() const { return m_items; } @@ -232,7 +236,6 @@ public: * Loads playlist with \b f_name name. */ void loadPlaylist(const QString& f_name); - /*! * Saves current songs to the playlist with \b f_name name. */ @@ -272,26 +275,17 @@ signals: * Emitted when first item has added. */ void firstAdded(); - /*! - * Emitted when state of the "Repeat All" option has changed. - * @param state New state of the "Repeat All" option (\b true - enabled, \b false disabled) - */ - void repeatableListChanged(bool state); - /*! - * Emitted when state of the "Shuffle" option has changed. - * @param state New state of the "Shuffle" option (\b true - enabled, \b false disabled) - */ - void shuffleChanged(bool state); - /*! - * Emitted when other settings (format, metadata, etc) have changed. - */ - void settingsChanged(); public slots: /*! * Adds \b item to the playlist. */ - void load(PlayListItem *item); + void add(PlayListItem *item); + /*! + * Adds a list of items to the playlist. + * @param items List of items + */ + void add(QList items); /*! * Removes all items. */ @@ -386,44 +380,6 @@ public slots: * Sets \b f media file to queue. */ void setQueued(PlayListItem* f); - /*! - * Returns state of the "Convert underscores to blanks" option (\b true - enabled, \b false - disabled). - */ - bool convertUnderscore(); - /*! - * Returns state of the "Convert %20 to blanks" option (\b true - enabled, \b false - disabled). - */ - bool convertTwenty(); - /*! - * Returns the state of metadata usage (\b true - use, \b false - not use). - */ - bool useMetadata(); - /*! - * Returns title format string. - */ - const QString format() const; - /*! - * Sets the "Convert underscores to blanks" option state to \b enabled - * @param enabled Option state (\b true - enabled, \b false - disabled) - */ - void setConvertUnderscore(bool enabled); - /*! - * Sets the "Convert %20 to blanks" option state to \b enabled - * @param enabled Option state (\b true - enabled, \b false - disabled) - */ - void setConvertTwenty(bool enabled); - /*! - * Sets metadata usage option state to \b enabled - * @param enabled Option state (\b true - enabled, \b false - disabled) - */ - void setUseMetadata(bool enabled); - /*! - * Sets short title format - * @param format title format. (Expressions: "%p" - artist, "%a" - album, "%t" - title, "%n" - track, - * "%g" - genre, "%c" - comment, "%C" - composer, "%D" - disc number "%f" - file name, " - * %F" - full path, "%y" - year) - */ - void setFormat(const QString &format); /*! * Removes invalid items from playlist */ @@ -465,13 +421,6 @@ private: QList m_editing_items; PlayListItem* m_currentItem; int m_current; - void readSettings(); - void writeSettings(); - void setUpdatesEnabled(bool); - bool updatesEnabled()const - { - return !m_block_update_signals; - } /*! * This flyweight object represents current selection. */ @@ -488,7 +437,6 @@ private: * Current playing state (Normal or Shuffle) */ PlayState* m_play_state; - bool m_block_update_signals; int m_total_length; typedef QPointer GuardedFileLoader; /*! @@ -498,6 +446,7 @@ private: */ QVector m_running_loaders; bool m_shuffle; + QString m_name; }; diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index ea0cb623b..e3096c8cc 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -36,7 +36,8 @@ HEADERS += general.h \ mediaplayer.h \ playlistsettings.h \ detailsdialog.h \ - tageditor.h + tageditor.h \ + playlistmanager.h SOURCES += general.cpp \ generalhandler.cpp \ playlistparser.cpp \ @@ -51,7 +52,8 @@ SOURCES += general.cpp \ mediaplayer.cpp \ playlistsettings.cpp \ detailsdialog.cpp \ - tageditor.cpp + tageditor.cpp \ + playlistmanager.cpp FORMS += detailsdialog.ui \ tageditor.ui unix:DESTDIR = . diff --git a/src/qmmpui/translations/libqmmpui_cs.ts b/src/qmmpui/translations/libqmmpui_cs.ts index ea9a4dfa7..5ba850bf1 100644 --- a/src/qmmpui/translations/libqmmpui_cs.ts +++ b/src/qmmpui/translations/libqmmpui_cs.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_de.ts b/src/qmmpui/translations/libqmmpui_de.ts index fd71c68ab..3fba815bb 100644 --- a/src/qmmpui/translations/libqmmpui_de.ts +++ b/src/qmmpui/translations/libqmmpui_de.ts @@ -72,6 +72,14 @@ p, li { white-space: pre-wrap; } <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_it.ts b/src/qmmpui/translations/libqmmpui_it.ts index 9f2776e71..4fd497a3f 100644 --- a/src/qmmpui/translations/libqmmpui_it.ts +++ b/src/qmmpui/translations/libqmmpui_it.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_lt.ts b/src/qmmpui/translations/libqmmpui_lt.ts index 05e6cbb63..106a1e353 100644 --- a/src/qmmpui/translations/libqmmpui_lt.ts +++ b/src/qmmpui/translations/libqmmpui_lt.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_pl.ts b/src/qmmpui/translations/libqmmpui_pl.ts index 505d60a25..6e1b6ccb9 100644 --- a/src/qmmpui/translations/libqmmpui_pl.ts +++ b/src/qmmpui/translations/libqmmpui_pl.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_pt_BR.ts b/src/qmmpui/translations/libqmmpui_pt_BR.ts index b6a6c4c31..160f36849 100644 --- a/src/qmmpui/translations/libqmmpui_pt_BR.ts +++ b/src/qmmpui/translations/libqmmpui_pt_BR.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_ru.ts b/src/qmmpui/translations/libqmmpui_ru.ts index 3708ba4f0..ad4b32096 100644 --- a/src/qmmpui/translations/libqmmpui_ru.ts +++ b/src/qmmpui/translations/libqmmpui_ru.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_tr.ts b/src/qmmpui/translations/libqmmpui_tr.ts index 06ce067a6..167aad31b 100644 --- a/src/qmmpui/translations/libqmmpui_tr.ts +++ b/src/qmmpui/translations/libqmmpui_tr.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_uk_UA.ts b/src/qmmpui/translations/libqmmpui_uk_UA.ts index bc68cd376..57771a6fb 100644 --- a/src/qmmpui/translations/libqmmpui_uk_UA.ts +++ b/src/qmmpui/translations/libqmmpui_uk_UA.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_zh_CN.ts b/src/qmmpui/translations/libqmmpui_zh_CN.ts index 257d42b9a..3ef670ebf 100644 --- a/src/qmmpui/translations/libqmmpui_zh_CN.ts +++ b/src/qmmpui/translations/libqmmpui_zh_CN.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory diff --git a/src/qmmpui/translations/libqmmpui_zh_TW.ts b/src/qmmpui/translations/libqmmpui_zh_TW.ts index 3cbe3c90c..8b3b6a60a 100644 --- a/src/qmmpui/translations/libqmmpui_zh_TW.ts +++ b/src/qmmpui/translations/libqmmpui_zh_TW.ts @@ -68,6 +68,14 @@ p, li { white-space: pre-wrap; } + + PlayListManager + + + Playlist + + + QtFileDialogFactory -- cgit v1.2.3-13-gbd6f