From 525d822bec49c9952388b71ffd7c293528b31c24 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 25 Sep 2008 20:52:56 +0000 Subject: using QMap for metadata git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@561 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/mad/decodermadfactory.cpp | 22 +++--- src/plugins/Input/mad/decodermadfactory.h | 2 +- src/qmmp/CMakeLists.txt | 6 +- src/qmmp/decoder.cpp | 8 +-- src/qmmp/decoder.h | 4 +- src/qmmp/decoderfactory.h | 4 +- src/qmmp/fileinfo.cpp | 93 ++++++++++++++++++++++++++ src/qmmp/fileinfo.h | 52 +++++++++++++++ src/qmmp/filetag.cpp | 100 ---------------------------- src/qmmp/filetag.h | 67 ------------------- src/qmmp/qmmp.h | 1 + src/qmmp/qmmp.pro | 12 ++-- src/ui/playlistitem.cpp | 54 +++++++-------- src/ui/playlistitem.h | 6 +- 14 files changed, 205 insertions(+), 226 deletions(-) create mode 100644 src/qmmp/fileinfo.cpp create mode 100644 src/qmmp/fileinfo.h delete mode 100644 src/qmmp/filetag.cpp delete mode 100644 src/qmmp/filetag.h (limited to 'src') diff --git a/src/plugins/Input/mad/decodermadfactory.cpp b/src/plugins/Input/mad/decodermadfactory.cpp index 10afdefc4..cc0ecd020 100644 --- a/src/plugins/Input/mad/decodermadfactory.cpp +++ b/src/plugins/Input/mad/decodermadfactory.cpp @@ -98,9 +98,9 @@ Decoder *DecoderMADFactory::create(QObject *parent, QIODevice *input, Output *ou return new DecoderMAD(parent, this, input, output); } -FileTag *DecoderMADFactory::createTag(const QString &source) +FileInfo *DecoderMADFactory::getFileInfo(const QString &source) { - FileTag *ftag = new FileTag(); + FileInfo *info = new FileInfo(); TagLib::Tag *tag = 0; TagLib::MPEG::File fileRef(source.toLocal8Bit ()); @@ -165,24 +165,24 @@ FileTag *DecoderMADFactory::createTag(const QString &source) TagLib::String genre = tag->genre(); TagLib::String title = tag->title(); - ftag->setValue(FileTag::ALBUM, + info->setMetaData(Qmmp::ALBUM, codec->toUnicode(album.toCString(utf)).trimmed()); - ftag->setValue(FileTag::ARTIST, + info->setMetaData(Qmmp::ARTIST, codec->toUnicode(artist.toCString(utf)).trimmed()); - ftag->setValue(FileTag::COMMENT, + info->setMetaData(Qmmp::COMMENT, codec->toUnicode(comment.toCString(utf)).trimmed()); - ftag->setValue(FileTag::GENRE, + info->setMetaData(Qmmp::GENRE, codec->toUnicode(genre.toCString(utf)).trimmed()); - ftag->setValue(FileTag::TITLE, + info->setMetaData(Qmmp::TITLE, codec->toUnicode(title.toCString(utf)).trimmed()); - ftag->setValue(FileTag::YEAR, + info->setMetaData(Qmmp::YEAR, tag->year()); - ftag->setValue(FileTag::TRACK, + info->setMetaData(Qmmp::TRACK, tag->track()); } if (fileRef.audioProperties()) - ftag->setValue(FileTag::LENGTH,fileRef.audioProperties()->length()); - return ftag; + info->setLength(fileRef.audioProperties()->length()); + return info; } QObject* DecoderMADFactory::showDetails(QWidget *parent, const QString &path) diff --git a/src/plugins/Input/mad/decodermadfactory.h b/src/plugins/Input/mad/decodermadfactory.h index 3b1a45818..de51f2450 100644 --- a/src/plugins/Input/mad/decodermadfactory.h +++ b/src/plugins/Input/mad/decodermadfactory.h @@ -43,7 +43,7 @@ public: bool canDecode(QIODevice *input) const; const DecoderProperties properties() const; Decoder *create(QObject *, QIODevice *, Output *, const QString &); - FileTag *createTag(const QString &source); + FileInfo *getFileInfo(const QString &source); QObject* showDetails(QWidget *parent, const QString &path); void showSettings(QWidget *parent); void showAbout(QWidget *parent); diff --git a/src/qmmp/CMakeLists.txt b/src/qmmp/CMakeLists.txt index 996069f61..70fbee619 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -34,7 +34,7 @@ SET(libqmmp_SRCS recycler.cpp decoder.cpp output.cpp - filetag.cpp + fileinfo.cpp equ/iir.c equ/iir_cfs.c equ/iir_fpu.c @@ -53,7 +53,7 @@ SET(libqmmp_MOC_HDRS constants.h decoder.h output.h - filetag.h + fileinfo.h outputfactory.h equ/iir_cfs.h equ/iir_fpu.h @@ -75,7 +75,7 @@ SET(libqmmp_DEVEL_HDRS constants.h decoder.h output.h - filetag.h + fileinfo.h outputfactory.h decoderfactory.h soundcore.h diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 25d4f959b..da13ebfec 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -426,12 +426,12 @@ bool Decoder::isEnabled(DecoderFactory* factory) return !disabledList.contains(name); } -FileTag *Decoder::createTag(const QString& source) +FileInfo *Decoder::getFileInfo(const QString &fileName) { - DecoderFactory *fact = Decoder::findByPath(source); - if (fact && QFile::exists(source)) + DecoderFactory *fact = Decoder::findByPath(fileName); + if (fact && QFile::exists(fileName)) { - return fact->createTag(source); + return fact->getFileInfo(fileName); } return 0; } diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h index c74446916..1a19452f2 100644 --- a/src/qmmp/decoder.h +++ b/src/qmmp/decoder.h @@ -15,7 +15,7 @@ #include #include -#include "filetag.h" +#include "fileinfo.h" class QObject; class QIODevice; @@ -67,7 +67,7 @@ public: static DecoderFactory *findByMime(const QString&); static DecoderFactory *findByContent(QIODevice *); static DecoderFactory *findByURL(const QUrl &url); - static FileTag *createTag(const QString&); + static FileInfo *getFileInfo(const QString &fileName); static QStringList filters(); static QStringList nameFilters(); static QList *factories(); diff --git a/src/qmmp/decoderfactory.h b/src/qmmp/decoderfactory.h index 954f597b2..cf05ba124 100644 --- a/src/qmmp/decoderfactory.h +++ b/src/qmmp/decoderfactory.h @@ -30,7 +30,7 @@ class QTranslator; class Decoder; class Output; -class FileTag; +class FileInfo; class DecoderProperties { @@ -63,7 +63,7 @@ public: virtual const DecoderProperties properties() const = 0; virtual Decoder *create(QObject *, QIODevice *input = 0, Output *output = 0, const QString &path = QString()) = 0; - virtual FileTag *createTag(const QString &source) = 0; + virtual FileInfo *getFileInfo(const QString &source) = 0; virtual QObject* showDetails(QWidget *parent, const QString &path) = 0; virtual void showSettings(QWidget *parent) = 0; virtual void showAbout(QWidget *parent) = 0; diff --git a/src/qmmp/fileinfo.cpp b/src/qmmp/fileinfo.cpp new file mode 100644 index 000000000..5b03c3456 --- /dev/null +++ b/src/qmmp/fileinfo.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2008 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 "fileinfo.h" + +FileInfo::FileInfo() +{ + m_length = 0; +} + +/*FileInfo::FileInfo(const FileInfo &other) +{ + *this = other; +}*/ + +FileInfo::~FileInfo() +{} + +/*void FileInfo::operator=(const FileInfo &tag) +{ + setValue(TITLE,tag.title ()); + setValue(ARTIST,tag.artist ()); + setValue(ALBUM,tag.album ()); + setValue(COMMENT,tag.comment ()); + setValue(GENRE,tag.genre ()); + setValue(YEAR,tag.year ()); + setValue(TRACK,tag.track ()); + setValue(LENGTH,tag.length ()); +} + +bool FileInfo::operator==(const FileInfo &tag) +{ + return title() == tag.title() && + artist() == tag.artist() && + album() == tag.album() && + comment() == tag.comment() && + genre() == tag.genre() && + year() == tag.year() && + track() == tag.track() && + length() == tag.length() && + isEmpty() == tag.isEmpty(); +} + +bool FileInfo::operator!=(const FileInfo &tag) +{ + return !operator==(tag); +}*/ + +const qint64 FileInfo::length () const +{ + return m_length; +} + +const QString FileInfo::metaData (Qmmp::MetaData key) const +{ + return m_metaData[key]; +} + +bool FileInfo::isEmpty() +{ + return m_metaData.isEmpty(); //TODO add correct test +} + +void FileInfo::setLength(qint64 length) +{ + m_length = length; +} + +void FileInfo::setMetaData(Qmmp::MetaData key, const QString &value) +{ + m_metaData.insert(key, value); +} + +void FileInfo::setMetaData(Qmmp::MetaData key, int value) +{ + m_metaData.insert(key, QString::number(value)); +} diff --git a/src/qmmp/fileinfo.h b/src/qmmp/fileinfo.h new file mode 100644 index 000000000..4ae56137d --- /dev/null +++ b/src/qmmp/fileinfo.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2008 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 FILEINFO_H +#define FILEINFO_H + +#include +#include + +#include "qmmp.h" + +/** + @author Ilya Kotov +*/ +class FileInfo +{ +public: + FileInfo(); + //FileInfo(const FileInfo &other); + + ~FileInfo(); + + const qint64 length () const; + const QString metaData (Qmmp::MetaData key) const; + bool isEmpty(); + + void setLength(qint64 length); + void setMetaData(Qmmp::MetaData key, const QString &value); + void setMetaData(Qmmp::MetaData key, int value); + +private: + QMap m_metaData; + qint64 m_length; +}; + +#endif diff --git a/src/qmmp/filetag.cpp b/src/qmmp/filetag.cpp deleted file mode 100644 index 27cc27c18..000000000 --- a/src/qmmp/filetag.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 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 "filetag.h" - -FileTag::FileTag() -{} - -FileTag::FileTag(const FileTag &other) -{ - *this = other; -} - -FileTag::~FileTag() -{} - -void FileTag::operator=(const FileTag &tag) -{ - setValue(TITLE,tag.title ()); - setValue(ARTIST,tag.artist ()); - setValue(ALBUM,tag.album ()); - setValue(COMMENT,tag.comment ()); - setValue(GENRE,tag.genre ()); - setValue(YEAR,tag.year ()); - setValue(TRACK,tag.track ()); - setValue(LENGTH,tag.length ()); -} - -void FileTag::setValue(uint name, const QString &value) -{ - if (!value.isEmpty()) - m_strValues.insert (name, value); -} - -void FileTag::setValue(uint name, const uint &value) -{ - if (value > 0) - m_numValues.insert (name, value); -} - -const QString FileTag::title () const -{ - return m_strValues[TITLE]; -} - -const QString FileTag::artist () const -{ - return m_strValues[ARTIST]; -} - -const QString FileTag::album () const -{ - return m_strValues[ALBUM]; -} - -const QString FileTag::comment () const -{ - return m_strValues[COMMENT]; -} - -const QString FileTag::genre () const -{ - return m_strValues[GENRE]; -} - -const uint FileTag::year () const -{ - return m_numValues[YEAR]; -} - -const uint FileTag::track () const -{ - return m_numValues[TRACK]; -} - -const uint FileTag::length () const -{ - return m_numValues[LENGTH]; -} - -const bool FileTag::isEmpty () const -{ - return m_strValues.isEmpty(); -} diff --git a/src/qmmp/filetag.h b/src/qmmp/filetag.h deleted file mode 100644 index 3501a61ad..000000000 --- a/src/qmmp/filetag.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 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 FILETAG_H -#define FILETAG_H - -#include -#include - -/** - @author Ilya Kotov -*/ -class FileTag -{ -public: - FileTag(); - FileTag(const FileTag &other); - - ~FileTag(); - - enum Type - { - TITLE = 0, - ARTIST, - ALBUM, - COMMENT, - GENRE, - YEAR, - TRACK, - LENGTH - }; - - void operator=(const FileTag &tag); - void setValue(uint name, const QString &value); - void setValue(uint name, const uint &value); - const QString title () const; - const QString artist () const; - const QString album () const; - const QString comment () const; - const QString genre () const; - const uint year () const; - const uint track () const; - const uint length () const; - const bool isEmpty () const; - -private: - QMap m_strValues; - QMap m_numValues; -}; - -#endif diff --git a/src/qmmp/qmmp.h b/src/qmmp/qmmp.h index 1c52ae0dd..bb469afae 100644 --- a/src/qmmp/qmmp.h +++ b/src/qmmp/qmmp.h @@ -27,6 +27,7 @@ class Qmmp { public: enum State {Playing = 0, Paused, Stopped, Buffering, NormalError, FatalError }; + enum MetaData {TITLE = 0, ARTIST, ALBUM, COMMENT, GENRE, YEAR, TRACK}; }; diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index e123bd48f..85b4838a5 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -5,7 +5,6 @@ HEADERS += recycler.h \ constants.h \ decoder.h \ output.h \ - filetag.h \ outputfactory.h \ equ\iir_cfs.h \ equ\iir_fpu.h \ @@ -18,8 +17,9 @@ HEADERS += recycler.h \ visualfactory.h \ effect.h \ effectfactory.h \ - statehandler.h \ - qmmp.h + statehandler.h \ + qmmp.h \ + fileinfo.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -29,11 +29,11 @@ SOURCES += recycler.cpp \ soundcore.cpp \ streamreader.cpp \ downloader.cpp \ - filetag.cpp \ visual.cpp \ effect.cpp \ - statehandler.cpp \ - qmmp.cpp + statehandler.cpp \ + qmmp.cpp \ + fileinfo.cpp TARGET = ../../lib/qmmp CONFIG += release \ diff --git a/src/ui/playlistitem.cpp b/src/ui/playlistitem.cpp index c7f600c8e..6d30d4180 100644 --- a/src/ui/playlistitem.cpp +++ b/src/ui/playlistitem.cpp @@ -26,14 +26,14 @@ PlayListItem::PlayListItem() : SongInfo(), m_flag(FREE) { - m_tag = 0; + m_info = 0; } PlayListItem::PlayListItem(const QString& path) : SongInfo(), m_flag(FREE) { m_selected = FALSE; m_current = FALSE; - m_tag = 0; + m_info = 0; setValue(SongInfo::PATH, path); setValue(SongInfo::STREAM, path.startsWith("http://")); //TODO do this inside SongInfo QSettings settings ( QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat ); @@ -47,7 +47,7 @@ PlayListItem::PlayListItem(const QString& path) : SongInfo(), m_flag(FREE) if (m_use_meta && !path.startsWith("http://")) { - m_tag = Decoder::createTag(path); + m_info = Decoder::getFileInfo(path); readMetadata(); } else if (path.startsWith("http://") && m_fullStreamPath) @@ -90,28 +90,28 @@ PlayListItem::FLAGS PlayListItem::flag() const return m_flag; } -void PlayListItem::updateTags(const FileTag *tag) +/*void PlayListItem::updateTags(const FileTag *tag) { - if (m_tag) + if (m_info) { - delete m_tag; - m_tag = 0; + delete m_info; + m_info = 0; } if (!tag->isEmpty()) - m_tag = new FileTag(*tag); + m_info = new FileTag(*tag); readMetadata(); -} +}*/ void PlayListItem::updateTags() { if (path().startsWith("http://")) return; - if (m_tag) + if (m_info) { - delete m_tag; - m_tag = 0; + delete m_info; + m_info = 0; } - m_tag = Decoder::createTag(path()); + m_info = Decoder::getFileInfo(path()); readMetadata(); } @@ -129,18 +129,18 @@ void PlayListItem::readMetadata() { //clear(); m_title.clear(); - if (m_tag) //read length first - setValue(SongInfo::LENGTH, m_tag->length()); - if (m_use_meta && m_tag && !m_tag->isEmpty()) + if (m_info) //read length first //TODO fix this + setValue(SongInfo::LENGTH, uint(m_info->length())); + if (m_use_meta && m_info && !m_info->isEmpty()) { - //fill SongInfo - setValue(SongInfo::TITLE, m_tag->title()); - setValue(SongInfo::ARTIST, m_tag->artist()); - setValue(SongInfo::ALBUM, m_tag->album()); - setValue(SongInfo::COMMENT, m_tag->comment()); - setValue(SongInfo::GENRE, m_tag->genre()); - setValue(SongInfo::YEAR, m_tag->year()); - setValue(SongInfo::TRACK, m_tag->track()); + //fill SongInfo //TODO optimize + setValue(SongInfo::TITLE, m_info->metaData(Qmmp::TITLE)); + setValue(SongInfo::ARTIST, m_info->metaData(Qmmp::ARTIST)); + setValue(SongInfo::ALBUM, m_info->metaData(Qmmp::ALBUM)); + setValue(SongInfo::COMMENT, m_info->metaData(Qmmp::COMMENT)); + setValue(SongInfo::GENRE, m_info->metaData(Qmmp::GENRE)); + setValue(SongInfo::YEAR, m_info->metaData(Qmmp::YEAR).toUInt()); + setValue(SongInfo::TRACK, m_info->metaData(Qmmp::TRACK).toUInt()); //generate playlist string m_title = m_format; m_title = printTag(m_title, "%p", artist()); @@ -159,9 +159,9 @@ void PlayListItem::readMetadata() else m_title = path().split('/',QString::SkipEmptyParts).takeLast (); } - if (m_tag) - delete m_tag; - m_tag = 0; + if (m_info) + delete m_info; + m_info = 0; if (m_convertUnderscore) m_title.replace("_", " "); if (m_convertTwenty) diff --git a/src/ui/playlistitem.h b/src/ui/playlistitem.h index 04bf4b97c..6e028b202 100644 --- a/src/ui/playlistitem.h +++ b/src/ui/playlistitem.h @@ -22,7 +22,7 @@ #include -class FileTag; +class FileInfo; /** @author Ilya Kotov */ @@ -52,14 +52,14 @@ public: const QString text() const; void setText(const QString &title); //modify functions - void updateTags(const FileTag *tag); + //void updateTags(const FileTag *tag); void updateTags(); private: void readMetadata(); QString printTag(QString str, QString regExp, QString tagStr); QString m_title; - FileTag *m_tag; + FileInfo *m_info; bool m_selected; bool m_current; bool m_use_meta; -- cgit v1.2.3-13-gbd6f