diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-03-06 10:39:45 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-03-06 10:39:45 +0000 |
| commit | cda0f909b32538ec98b891590ae17c4115da0846 (patch) | |
| tree | 30a26589705f3f4c73f5b4bd2a1e529f69a8e5e6 /src/qmmpui | |
| parent | 6f2cb48f2aefdea338d59111fd9f80440b6c1dc1 (diff) | |
| download | qmmp-cda0f909b32538ec98b891590ae17c4115da0846.tar.gz qmmp-cda0f909b32538ec98b891590ae17c4115da0846.tar.bz2 qmmp-cda0f909b32538ec98b891590ae17c4115da0846.zip | |
playlist api changes and optimizations
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@822 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/qmmpui/fileloader.cpp | 15 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.cpp | 4 | ||||
| -rw-r--r-- | src/qmmpui/playlistitem.cpp | 32 | ||||
| -rw-r--r-- | src/qmmpui/playlistitem.h | 6 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.cpp | 54 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.h | 14 | ||||
| -rw-r--r-- | src/qmmpui/playlistsettings.cpp | 91 | ||||
| -rw-r--r-- | src/qmmpui/playlistsettings.h | 53 | ||||
| -rw-r--r-- | src/qmmpui/qmmpui.pro | 6 |
10 files changed, 226 insertions, 51 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index 0531bf210..de658a045 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -41,6 +41,7 @@ SET(libqmmpui_SRCS playlistmodel.cpp playlistitem.cpp mediaplayer.cpp + playlistsettings.cpp ) SET(libqmmpui_MOC_HDRS @@ -60,6 +61,7 @@ SET(libqmmpui_MOC_HDRS playlistmodel.h playlistitem.h mediaplayer.h + playlistsettings.h ) SET(libqmmpui_DEVEL_HDRS diff --git a/src/qmmpui/fileloader.cpp b/src/qmmpui/fileloader.cpp index ce5ccb56c..2a72e772b 100644 --- a/src/qmmpui/fileloader.cpp +++ b/src/qmmpui/fileloader.cpp @@ -20,6 +20,7 @@ #include <qmmp/decoder.h> #include "fileloader.h" +#include "playlistsettings.h" #include "playlistitem.h" FileLoader::FileLoader(QObject *parent) @@ -43,13 +44,9 @@ void FileLoader::addFiles(const QStringList &files) foreach(QString s, files) { - /*if (s.startsWith("http://") || Decoder::supports(s)) - {*/ - //emit newPlayListItem(new PlayListItem(s)); - QList <FileInfo *> playList = Decoder::createPlayList(s); + QList <FileInfo *> playList = Decoder::createPlayList(s, PlaylistSettings::instance()->useMetadata()); foreach(FileInfo *info, playList) emit newPlayListItem(new PlayListItem(info)); - //} if (m_finished) return; } } @@ -67,14 +64,10 @@ void FileLoader::addDirectory(const QString& s) QFileInfo fileInfo = l.at(i); QString suff = fileInfo.completeSuffix(); list << fileInfo; - - /*if (Decoder::supports(fileInfo.absoluteFilePath ())) - {*/ - playList = Decoder::createPlayList(fileInfo.absoluteFilePath ()); + playList = Decoder::createPlayList(fileInfo.absoluteFilePath (), + PlaylistSettings::instance()->useMetadata()); foreach(FileInfo *info, playList) emit newPlayListItem(new PlayListItem(info)); - //emit newPlayListItem(new PlayListItem(fileInfo.absoluteFilePath ())); - //} if (m_finished) return; } dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp index f15517d09..6c1224e1f 100644 --- a/src/qmmpui/mediaplayer.cpp +++ b/src/qmmpui/mediaplayer.cpp @@ -119,7 +119,6 @@ void MediaPlayer::play() else if (!m_model->next()) { stop(); - //display->hideTimeDisplay(); return; } play(); @@ -145,7 +144,6 @@ void MediaPlayer::next() else if (!m_model->next()) { stop(); - //display->hideTimeDisplay(); return; } //m_playlist->update(); @@ -155,8 +153,6 @@ void MediaPlayer::next() stop(); play(); } - /*else - display->hideTimeDisplay();*/ } void MediaPlayer::previous() diff --git a/src/qmmpui/playlistitem.cpp b/src/qmmpui/playlistitem.cpp index f52aec350..7912c502b 100644 --- a/src/qmmpui/playlistitem.cpp +++ b/src/qmmpui/playlistitem.cpp @@ -21,7 +21,7 @@ #include <QDir> #include <qmmp/decoder.h> - +#include "playlistsettings.h" #include "playlistitem.h" PlayListItem::PlayListItem() : AbstractPlaylistItem(), m_flag(FREE) @@ -29,26 +29,12 @@ PlayListItem::PlayListItem() : AbstractPlaylistItem(), m_flag(FREE) m_info = 0; } -PlayListItem::PlayListItem(FileInfo *info, QSettings *settings) : AbstractPlaylistItem(), m_flag(FREE) +PlayListItem::PlayListItem(FileInfo *info) : AbstractPlaylistItem(), m_flag(FREE) { m_selected = FALSE; m_current = FALSE; m_info = info; - //use external settings or create new - QSettings *s = settings; - if (!s) - s = new QSettings (Qmmp::configFile(), QSettings::IniFormat); - - m_use_meta = s->value ("PlayList/load_metadata", TRUE).toBool(); //TODO move to libqmmp - //format - m_format = s->value("PlayList/title_format", "%p - %t").toString(); - //other properties - m_convertUnderscore = s->value ("PlayList/convert_underscore", TRUE).toBool(); - m_convertTwenty = s->value ("PlayList/convert_twenty", TRUE).toBool(); - if (!settings) //delete created settings only - delete s; - setMetaData(info->metaData()); setMetaData(Qmmp::URL, m_info->path()); setLength(m_info->length()); @@ -124,7 +110,7 @@ void PlayListItem::setText(const QString &title) void PlayListItem::readMetadata() { - m_title = m_format; + m_title = PlaylistSettings::instance()->format(); m_title = printTag(m_title, "%p", artist()); m_title = printTag(m_title, "%a", album()); m_title = printTag(m_title, "%t", title()); @@ -142,14 +128,15 @@ void PlayListItem::readMetadata() if (m_info) delete m_info; m_info = 0; - if (m_convertUnderscore) + if (PlaylistSettings::instance()->convertUnderscore()) m_title.replace("_", " "); - if (m_convertTwenty) + if (PlaylistSettings::instance()->convertTwenty()) m_title.replace("%20", " "); } QString PlayListItem::printTag(QString str, QString regExp, QString tagStr) { + QString format = PlaylistSettings::instance()->format(); if (!tagStr.isEmpty()) str.replace(regExp, tagStr); else @@ -162,9 +149,9 @@ QString PlayListItem::printTag(QString str, QString regExp, QString tagStr) if (nextPos < 0) { //last separator - regExpPos = m_format.lastIndexOf(regExp); - nextPos = m_format.lastIndexOf("%", regExpPos - 1); - QString lastSep = m_format.right (m_format.size() - nextPos - 2); + regExpPos = format.lastIndexOf(regExp); + nextPos = format.lastIndexOf("%", regExpPos - 1); + QString lastSep = format.right (format.size() - nextPos - 2); str.remove(lastSep); str.remove(regExp); } @@ -173,4 +160,3 @@ QString PlayListItem::printTag(QString str, QString regExp, QString tagStr) } return str; } - diff --git a/src/qmmpui/playlistitem.h b/src/qmmpui/playlistitem.h index 5fbc6a716..6f7a6755d 100644 --- a/src/qmmpui/playlistitem.h +++ b/src/qmmpui/playlistitem.h @@ -40,8 +40,7 @@ public: */ enum FLAGS{FREE = 0,EDITING,SCHEDULED_FOR_DELETION}; PlayListItem(); - //PlayListItem(const QString& path); - PlayListItem(FileInfo *info, QSettings *settings = 0); + PlayListItem(FileInfo *info); ~PlayListItem(); @@ -65,9 +64,6 @@ private: FileInfo *m_info; bool m_selected; bool m_current; - bool m_use_meta; - bool m_convertUnderscore, m_convertTwenty; - QString m_format; FLAGS m_flag; }; diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp index efcf2cbd7..0b1ed5361 100644 --- a/src/qmmpui/playlistmodel.cpp +++ b/src/qmmpui/playlistmodel.cpp @@ -41,6 +41,7 @@ #include "playlistmodel.h" #include "playlistitem.h" #include "playstate.h" +#include "playlistsettings.h" #include <QMetaType> @@ -96,6 +97,7 @@ PlayListModel::~PlayListModel() l->wait(); } } + delete PlaylistSettings::instance(); } void PlayListModel::load(PlayListItem *item) @@ -424,7 +426,7 @@ void PlayListModel::readSettings() m_current = 0; m_block_update_signals = TRUE; foreach(FileInfo *info, infoList) - load(new PlayListItem(info, &settings)); //using one and the same settings object for all playlist items + load(new PlayListItem(info)); m_block_update_signals = FALSE; doCurrentVisibleRequest(); } @@ -454,11 +456,7 @@ void PlayListModel::addFile(const QString& path) { if (path.isEmpty()) return; - /*if(path.startsWith("http://")) - load(new PlayListItem(path)); - else if(Decoder::supports(path)) - load(new PlayListItem(path));*/ - QList <FileInfo *> playList = Decoder::createPlayList(path); + QList <FileInfo *> playList = Decoder::createPlayList(path, PlaylistSettings::instance()->useMetadata()); foreach(FileInfo *info, playList) emit load(new PlayListItem(info)); @@ -952,3 +950,47 @@ 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(); +} diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index e90bc007c..d133f25d6 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -196,6 +196,7 @@ signals: void firstAdded(); void repeatableListChanged(bool); void shuffleChanged(bool); + void settingsChanged(); public slots: void load(PlayListItem *); @@ -265,6 +266,19 @@ public slots: void preparePlayState(); + + /*! + * settings + */ + bool convertUnderscore(); + bool convertTwenty(); + bool useMetadata(); + const QString format() const; + void setConvertUnderscore(bool); + void setConvertTwenty(bool); + void setUseMetadata(bool); + void setFormat(const QString &format); + private: /*! diff --git a/src/qmmpui/playlistsettings.cpp b/src/qmmpui/playlistsettings.cpp new file mode 100644 index 000000000..22b392237 --- /dev/null +++ b/src/qmmpui/playlistsettings.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** + * 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 <QSettings> +#include <qmmp/qmmp.h> +#include "playlistsettings.h" + +PlaylistSettings *PlaylistSettings::m_instance = 0; + +PlaylistSettings::PlaylistSettings() +{ + QSettings s (Qmmp::configFile(), QSettings::IniFormat); + m_format = s.value("PlayList/title_format", "%p - %t").toString(); + m_convertUnderscore = s.value ("PlayList/convert_underscore", TRUE).toBool(); + m_convertTwenty = s.value ("PlayList/convert_twenty", TRUE).toBool(); + m_useMetadata = s.value ("PlayList/load_metadata", TRUE).toBool(); +} + +PlaylistSettings::~PlaylistSettings() +{ + m_instance = 0; + QSettings s(Qmmp::configFile(), QSettings::IniFormat); + s.setValue("PlayList/title_format", m_format); + s.setValue("PlayList/convert_underscore", m_convertUnderscore); + s.setValue("PlayList/convert_twenty", m_convertTwenty); + s.setValue("PlayList/load_metadata", m_useMetadata); +} + +PlaylistSettings *PlaylistSettings::instance() +{ + if (!m_instance) + m_instance = new PlaylistSettings(); + return m_instance; +} + +const QString PlaylistSettings::format() const +{ + return m_format; +} + +bool PlaylistSettings::convertUnderscore() +{ + return m_convertUnderscore; +} + +bool PlaylistSettings::convertTwenty() +{ + return m_convertTwenty; +} + +bool PlaylistSettings::useMetadata() +{ + return m_useMetadata; +} + +void PlaylistSettings::setConvertUnderscore(bool yes) +{ + m_convertUnderscore = yes; +} + +void PlaylistSettings::setConvertTwenty(bool yes) +{ + m_convertTwenty = yes; +} + +void PlaylistSettings::setFormat(const QString &format) +{ + m_format = format; +} + +void PlaylistSettings::setUseMetadata(bool yes) +{ + m_useMetadata = yes; +} diff --git a/src/qmmpui/playlistsettings.h b/src/qmmpui/playlistsettings.h new file mode 100644 index 000000000..5efc81393 --- /dev/null +++ b/src/qmmpui/playlistsettings.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * 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 PLAYLISTSETTINGS_H +#define PLAYLISTSETTINGS_H + +#include <QString> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class PlaylistSettings +{ +public: + PlaylistSettings(); + + ~PlaylistSettings(); + + static PlaylistSettings* instance(); + bool convertUnderscore(); + bool convertTwenty(); + bool useMetadata(); + const QString format() const; + void setConvertUnderscore(bool); + void setConvertTwenty(bool); + void setFormat(const QString &format); + void setUseMetadata(bool); + +private: + static PlaylistSettings* m_instance; + bool m_convertUnderscore, m_convertTwenty; + bool m_useMetadata; + QString m_format; + +}; + +#endif diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 5148a612e..5c81345a0 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -45,7 +45,8 @@ HEADERS += general.h \ playlistmodel.h \ playstate.h \ fileloader.h \ - mediaplayer.h + mediaplayer.h \ + playlistsettings.h SOURCES += general.cpp \ generalhandler.cpp \ playlistparser.cpp \ @@ -57,7 +58,8 @@ SOURCES += general.cpp \ playstate.cpp \ playlistitem.cpp \ fileloader.cpp \ - mediaplayer.cpp + mediaplayer.cpp \ + playlistsettings.cpp DESTDIR = . |
