diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-09-25 20:52:56 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-09-25 20:52:56 +0000 |
| commit | 525d822bec49c9952388b71ffd7c293528b31c24 (patch) | |
| tree | 5573da458b29dcf72b5f9226935957c84c6d6c1f | |
| parent | 9f84a7baad27edb52a1a443a1f7f3aa7ab7594c1 (diff) | |
| download | qmmp-525d822bec49c9952388b71ffd7c293528b31c24.tar.gz qmmp-525d822bec49c9952388b71ffd7c293528b31c24.tar.bz2 qmmp-525d822bec49c9952388b71ffd7c293528b31c24.zip | |
using QMap for metadata
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@561 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/plugins/Input/mad/decodermadfactory.cpp | 22 | ||||
| -rw-r--r-- | src/plugins/Input/mad/decodermadfactory.h | 2 | ||||
| -rw-r--r-- | src/qmmp/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/qmmp/decoder.cpp | 8 | ||||
| -rw-r--r-- | src/qmmp/decoder.h | 4 | ||||
| -rw-r--r-- | src/qmmp/decoderfactory.h | 4 | ||||
| -rw-r--r-- | src/qmmp/fileinfo.cpp (renamed from src/qmmp/filetag.cpp) | 77 | ||||
| -rw-r--r-- | src/qmmp/fileinfo.h (renamed from src/qmmp/filetag.h) | 49 | ||||
| -rw-r--r-- | src/qmmp/qmmp.h | 1 | ||||
| -rw-r--r-- | src/qmmp/qmmp.pro | 12 | ||||
| -rw-r--r-- | src/ui/playlistitem.cpp | 54 | ||||
| -rw-r--r-- | src/ui/playlistitem.h | 6 |
13 files changed, 113 insertions, 134 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 97ede40c6..1e5300d19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ CONFIGURE_FILE( ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") -SET(QMMP_VERSION 0.2.3) +SET(QMMP_VERSION 0.3.0) SET(QMMP_SOVERSION 0) SET(SVN_VERSION TRUE) 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 <QStringList> #include <QUrl> -#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<DecoderFactory*> *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/filetag.cpp b/src/qmmp/fileinfo.cpp index 27cc27c18..5b03c3456 100644 --- a/src/qmmp/filetag.cpp +++ b/src/qmmp/fileinfo.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -17,20 +17,22 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "filetag.h" +#include "fileinfo.h" -FileTag::FileTag() -{} +FileInfo::FileInfo() +{ + m_length = 0; +} -FileTag::FileTag(const FileTag &other) +/*FileInfo::FileInfo(const FileInfo &other) { *this = other; -} +}*/ -FileTag::~FileTag() +FileInfo::~FileInfo() {} -void FileTag::operator=(const FileTag &tag) +/*void FileInfo::operator=(const FileInfo &tag) { setValue(TITLE,tag.title ()); setValue(ARTIST,tag.artist ()); @@ -42,59 +44,50 @@ void FileTag::operator=(const FileTag &tag) 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) +bool FileInfo::operator==(const FileInfo &tag) { - if (value > 0) - m_numValues.insert (name, value); + 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(); } -const QString FileTag::title () const +bool FileInfo::operator!=(const FileInfo &tag) { - return m_strValues[TITLE]; -} - -const QString FileTag::artist () const -{ - return m_strValues[ARTIST]; -} - -const QString FileTag::album () const -{ - return m_strValues[ALBUM]; -} + return !operator==(tag); +}*/ -const QString FileTag::comment () const +const qint64 FileInfo::length () const { - return m_strValues[COMMENT]; + return m_length; } -const QString FileTag::genre () const +const QString FileInfo::metaData (Qmmp::MetaData key) const { - return m_strValues[GENRE]; + return m_metaData[key]; } -const uint FileTag::year () const +bool FileInfo::isEmpty() { - return m_numValues[YEAR]; + return m_metaData.isEmpty(); //TODO add correct test } -const uint FileTag::track () const +void FileInfo::setLength(qint64 length) { - return m_numValues[TRACK]; + m_length = length; } -const uint FileTag::length () const +void FileInfo::setMetaData(Qmmp::MetaData key, const QString &value) { - return m_numValues[LENGTH]; + m_metaData.insert(key, value); } -const bool FileTag::isEmpty () const +void FileInfo::setMetaData(Qmmp::MetaData key, int value) { - return m_strValues.isEmpty(); + m_metaData.insert(key, QString::number(value)); } diff --git a/src/qmmp/filetag.h b/src/qmmp/fileinfo.h index 3501a61ad..4ae56137d 100644 --- a/src/qmmp/filetag.h +++ b/src/qmmp/fileinfo.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -17,51 +17,36 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef FILETAG_H -#define FILETAG_H +#ifndef FILEINFO_H +#define FILEINFO_H #include <QString> #include <QMap> +#include "qmmp.h" + /** @author Ilya Kotov <forkotov02@hotmail.ru> */ -class FileTag +class FileInfo { public: - FileTag(); - FileTag(const FileTag &other); + FileInfo(); + //FileInfo(const FileInfo &other); - ~FileTag(); + ~FileInfo(); - enum Type - { - TITLE = 0, - ARTIST, - ALBUM, - COMMENT, - GENRE, - YEAR, - TRACK, - LENGTH - }; + const qint64 length () const; + const QString metaData (Qmmp::MetaData key) const; + bool isEmpty(); - 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; + void setLength(qint64 length); + void setMetaData(Qmmp::MetaData key, const QString &value); + void setMetaData(Qmmp::MetaData key, int value); private: - QMap <uint, QString> m_strValues; - QMap <uint, uint> m_numValues; + QMap <Qmmp::MetaData, QString> m_metaData; + qint64 m_length; }; #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 <qmmpui/songinfo.h> -class FileTag; +class FileInfo; /** @author Ilya Kotov <forkotov02@hotmail.ru> */ @@ -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; |
