diff options
| -rw-r--r-- | src/qmmp/decoder.cpp | 53 | ||||
| -rw-r--r-- | src/qmmp/decoder.h | 4 | ||||
| -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 | ||||
| -rw-r--r-- | src/ui/configdialog.cpp | 27 |
13 files changed, 249 insertions, 112 deletions
diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index d3706590e..64b5b33af 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -188,11 +188,12 @@ void Decoder::finish() // static methods QList<DecoderFactory*> *Decoder::m_factories = 0; +DecoderFactory *Decoder::m_lastFactory = 0; QStringList Decoder::m_files; void Decoder::checkFactories() { - QSettings settings ( Qmmp::configFile(), QSettings::IniFormat ); + QSettings settings (Qmmp::configFile(), QSettings::IniFormat); if (!m_factories) { @@ -237,7 +238,6 @@ void Decoder::checkFactories() } } - QStringList Decoder::all() { checkFactories(); @@ -273,45 +273,17 @@ bool Decoder::supports(const QString &source) return FALSE; } -/*Decoder *Decoder::create(QObject *parent, const QString &source, - QIODevice *input, - Output *output) -{ - Decoder *decoder = 0; - DecoderFactory *fact = 0; - if (!input->open(QIODevice::ReadOnly)) - { - qDebug("Decoder: cannot open input"); - return decoder; - } - StreamReader* sreader = qobject_cast<StreamReader *>(input); - if (sreader) - { - fact = Decoder::findByMime(sreader->contentType()); - if (!fact) - fact = Decoder::findByContent(sreader); - } - else - fact = Decoder::findByPath(source); - if (fact) - { - decoder = fact->create(parent, input, output); - } - if (!decoder) - input->close(); - else - output->setStateHandler(decoder->stateHandler()); - return decoder; -}*/ - DecoderFactory *Decoder::findByPath(const QString& source) { checkFactories(); - DecoderFactory *fact; + DecoderFactory *fact = m_lastFactory; + if (fact && fact->supports(source) && isEnabled(fact)) //try last factory + return fact; foreach(fact, *m_factories) { if (fact->supports(source) && isEnabled(fact)) { + m_lastFactory = fact; return fact; } } @@ -398,19 +370,6 @@ bool Decoder::isEnabled(DecoderFactory* factory) return !disabledList.contains(name); } -/*FileInfo *Decoder::createFileInfo(const QString &fileName) -{ - DecoderFactory *fact = Decoder::findByPath(fileName); - if (fact && QFile::exists(fileName)) - { - FileInfo *info = fact->createFileInfo(fileName); - if (info && info->url().isEmpty()) - info->setUrl(QUrl::fromLocalFile (fileName)); - return fact->createFileInfo(fileName); - } - return 0; -}*/ - QList <FileInfo *> Decoder::createPlayList(const QString &fileName, bool useMetaData) { QList <FileInfo *> list; diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h index ef3a74308..df1313561 100644 --- a/src/qmmp/decoder.h +++ b/src/qmmp/decoder.h @@ -61,14 +61,11 @@ public: // static methods static QStringList all(); static bool supports(const QString &); - //static Decoder *create(QObject *, const QString &, QIODevice *, Output *); static DecoderFactory *findByPath(const QString&); static DecoderFactory *findByMime(const QString&); static DecoderFactory *findByContent(QIODevice *); static DecoderFactory *findByURL(const QUrl &url); - //static FileInfo *createFileInfo(const QString &fileName); static QList <FileInfo *> createPlayList(const QString &fileName, bool useMetaData = TRUE); - //static QList <FileInfo *> createPlayList(const QStringList &fileList); static QStringList filters(); static QStringList nameFilters(); static QList<DecoderFactory*> *factories(); @@ -102,6 +99,7 @@ private: bool m_useEQ; StateHandler *m_handler; static QList<DecoderFactory*> *m_factories; + static DecoderFactory *m_lastFactory; static QStringList m_files; }; 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 = . diff --git a/src/ui/configdialog.cpp b/src/ui/configdialog.cpp index df7d393fd..630a791ff 100644 --- a/src/ui/configdialog.cpp +++ b/src/ui/configdialog.cpp @@ -38,6 +38,8 @@ #include <qmmpui/general.h> #include <qmmpui/generalhandler.h> #include <qmmpui/filedialog.h> +#include <qmmpui/mediaplayer.h> +#include <qmmpui/playlistmodel.h> #include "skin.h" @@ -97,14 +99,14 @@ ConfigDialog::~ConfigDialog() void ConfigDialog::readSettings() { QSettings settings (Qmmp::configFile(), QSettings::IniFormat); - ui.formatLineEdit->setText( - settings.value ("PlayList/title_format", "%p - %t").toString()); - ui.metadataCheckBox->setChecked( - settings.value ("PlayList/load_metadata", TRUE).toBool()); - ui.underscoresCheckBox->setChecked(settings.value ("PlayList/convert_underscore", TRUE).toBool()); - ui.per20CheckBox->setChecked(settings.value ("PlayList/convert_twenty", TRUE).toBool()); + if (MediaPlayer *player = MediaPlayer::instance()) + { + ui.formatLineEdit->setText(player->playListModel()->format()); + ui.metadataCheckBox->setChecked(player->playListModel()->useMetadata()); + ui.underscoresCheckBox->setChecked(player->playListModel()->convertUnderscore()); + ui.per20CheckBox->setChecked(player->playListModel()->convertTwenty()); + } ui.protocolCheckBox->setChecked(settings.value ("PlayList/show_protocol", FALSE).toBool()); - //proxy settings ui.enableProxyCheckBox->setChecked(Qmmp::useProxy()); ui.authProxyCheckBox->setChecked(Qmmp::useProxyAuth()); @@ -540,10 +542,13 @@ void ConfigDialog::addTitleString( QAction * a) void ConfigDialog::saveSettings() { QSettings settings (Qmmp::configFile(), QSettings::IniFormat); - settings.setValue ("PlayList/title_format", ui.formatLineEdit->text().trimmed()); - settings.setValue ("PlayList/load_metadata", ui.metadataCheckBox->isChecked()); - settings.setValue ("PlayList/convert_underscore", ui.underscoresCheckBox->isChecked()); - settings.setValue ("PlayList/convert_twenty", ui.per20CheckBox->isChecked()); + if (MediaPlayer *player = MediaPlayer::instance()) + { + player->playListModel()->setFormat(ui.formatLineEdit->text().trimmed()); + player->playListModel()->setUseMetadata(ui.metadataCheckBox->isChecked()); + player->playListModel()->setConvertUnderscore(ui.underscoresCheckBox->isChecked()); + player->playListModel()->setConvertTwenty(ui.per20CheckBox->isChecked()); + } settings.setValue ("PlayList/show_protocol", ui.protocolCheckBox->isChecked()); FileDialog::setEnabled(FileDialog::registeredFactories().at(ui.fileDialogComboBox->currentIndex())); |
