Commit 602dd6fc authored by Scott Wheeler's avatar Scott Wheeler

Moved "audio data" information into the tag class. I am also now using

KFMI for both mp3 and ogg; this should remove the need for my AudioData
class, which I was hoping to replace anyway.

I also implemented output streaming operators for Tag and Genre, and input
for Genre.  I'll implement input streaming for CachedTag once the Cache
is ready for that.

svn path=/trunk/kdemultimedia/juk/; revision=183402
parent d5d01b61
......@@ -54,3 +54,26 @@ void Genre::setID3v1(int ID3v1Number)
{
ID3v1 = ID3v1Number;
}
////////////////////////////////////////////////////////////////////////////////
// related functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const Genre &g)
{
s << QString(g) << g.getID3v1();
return(s);
}
QDataStream &operator>>(QDataStream &s, Genre &g)
{
QString name;
int n;
s >> name >> n;
g = name;
g.setID3v1(n);
return(s);
}
......@@ -19,6 +19,7 @@
#define GENRE_H
#include <qstring.h>
#include <qdatastream.h>
class Genre : public QString
{
......@@ -35,4 +36,7 @@ private:
int ID3v1;
};
QDataStream &operator<<(QDataStream &s, const Genre &g);
QDataStream &operator>>(QDataStream &s, Genre &g);
#endif
......@@ -41,6 +41,8 @@
ID3Tag::ID3Tag(const QString &file) : Tag(file)
{
metaInfo = KFileMetaInfo(file, QString::null, KFileMetaInfo::Fastest);
fileName = file;
tag.Link(fileName.latin1());
......@@ -167,6 +169,11 @@ void ID3Tag::save()
}
}
bool ID3Tag::hasTag() const
{
return(tagExists);
}
QString ID3Tag::track() const // The song's name, not it's track number
{
return(tagTrack);
......@@ -211,10 +218,6 @@ QString ID3Tag::comment() const
{
return(tagComment);
}
bool ID3Tag::hasTag() const
{
return(tagExists);
}
/////////////////////////////////////////////////////
// functions that set information
......@@ -270,3 +273,17 @@ void ID3Tag::setComment(const QString &value)
tagComment = value;
};
QString ID3Tag::bitrateString() const
{
return(readBitrate(metaInfo));
}
QString ID3Tag::lengthString() const
{
return(readLength(metaInfo));
}
int ID3Tag::seconds() const
{
return(readSeconds(metaInfo));
}
......@@ -31,6 +31,7 @@ public:
virtual ~ID3Tag();
virtual void save();
virtual bool hasTag() const;
virtual QString track() const;
virtual QString artist() const;
......@@ -41,7 +42,6 @@ public:
virtual int year() const;
virtual QString yearString() const;
virtual QString comment() const;
virtual bool hasTag() const;
virtual void setTrack(const QString &value);
virtual void setArtist(const QString &value);
......@@ -51,6 +51,10 @@ public:
virtual void setYear(int value);
virtual void setComment(const QString &value);
virtual QString bitrateString() const;
virtual QString lengthString() const;
virtual int seconds() const;
private:
ID3_Tag tag;
QString fileName;
......@@ -66,6 +70,8 @@ private:
QString tagYearString;
QString tagComment;
bool tagExists;
KFileMetaInfo metaInfo;
};
#endif
......@@ -43,6 +43,14 @@ void OggTag::save()
metaInfo.applyChanges();
}
bool OggTag::hasTag() const
{
if(metaInfo.isValid() && !metaInfo.isEmpty())
return(true);
else
return(false);
}
QString OggTag::track() const
{
return readCommentString("Title");
......@@ -99,14 +107,6 @@ QString OggTag::comment() const
return readCommentString("Description");
}
bool OggTag::hasTag() const
{
if(metaInfo.isValid() && !metaInfo.isEmpty())
return(true);
else
return(false);
}
void OggTag::setTrack(const QString &value)
{
writeCommentItem("Title", value);
......@@ -146,6 +146,21 @@ void OggTag::setComment(const QString &value)
writeCommentItem("Description", value);
}
QString OggTag::bitrateString() const
{
return(readBitrate(metaInfo));
}
QString OggTag::lengthString() const
{
return(readLength(metaInfo));
}
int OggTag::seconds() const
{
return(readSeconds(metaInfo));
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......
......@@ -18,8 +18,6 @@
#ifndef OGGTAG_H
#define OGGTAG_H
#include <kfilemetainfo.h>
#include "tag.h"
class OggTag : public Tag
......@@ -29,6 +27,7 @@ public:
virtual ~OggTag();
virtual void save();
virtual bool hasTag() const;
virtual QString track() const;
virtual QString artist() const;
......@@ -39,7 +38,6 @@ public:
virtual int year() const;
virtual QString yearString() const;
virtual QString comment() const;
virtual bool hasTag() const;
virtual void setTrack(const QString &value);
virtual void setArtist(const QString &value);
......@@ -49,6 +47,10 @@ public:
virtual void setYear(int value);
virtual void setComment(const QString &value);
virtual QString bitrateString() const;
virtual QString lengthString() const;
virtual int seconds() const;
private:
/**
* Simplifies reading a string from a KFMI group. Returns QString::null if
......
......@@ -42,11 +42,6 @@ Tag *PlaylistItem::getTag()
return(data->getTag());
}
AudioData *PlaylistItem::getAudioData()
{
return(data->getAudioData());
}
// QFileInfo-ish methods
QString PlaylistItem::fileName() const { return(data->fileName()); }
......@@ -143,7 +138,7 @@ void PlaylistItem::refreshImpl()
setText(TrackNumberColumn, getTag()->trackNumberString());
setText(GenreColumn, getTag()->genre());
setText(YearColumn, getTag()->yearString());
setText(LengthColumn, getAudioData()->getLengthChar());
setText(LengthColumn, getTag()->lengthString());
setText(FileNameColumn, filePath());
}
}
......@@ -209,9 +204,9 @@ int PlaylistItem::compare(PlaylistItem *firstItem, PlaylistItem *secondItem, int
return(0);
}
else if(column == LengthColumn) {
if(firstItem->getAudioData()->getLength() > secondItem->getAudioData()->getLength())
if(firstItem->getTag()->seconds() > secondItem->getTag()->seconds())
return(1);
else if(firstItem->getAudioData()->getLength() < secondItem->getAudioData()->getLength())
else if(firstItem->getTag()->seconds() < secondItem->getTag()->seconds())
return(-1);
else
return(0);
......@@ -239,11 +234,9 @@ void PlaylistItem::Data::refresh()
{
delete(cache);
delete(tag);
delete(audioData);
cache = 0;
tag = 0;
audioData = 0;
}
void PlaylistItem::Data::deleteUser()
......@@ -262,13 +255,6 @@ Tag *PlaylistItem::Data::getTag()
return(tag);
}
AudioData *PlaylistItem::Data::getAudioData()
{
if(!audioData)
audioData = new AudioData(filePath());
return(audioData);
}
void PlaylistItem::Data::setFile(const QString &file)
{
delete(tag);
......@@ -288,7 +274,6 @@ PlaylistItem::Data::Data(const QFileInfo &file) : QFileInfo(file)
// initialize pointers to null
cache = 0;
tag = 0;
audioData = 0;
}
PlaylistItem::Data::~Data()
......@@ -301,7 +286,6 @@ PlaylistItem::Data::~Data()
Cache::instance()->replace(absFilePath(), new CacheItem(*tag));
delete(tag);
delete(audioData);
}
#include "playlistitem.moc"
......@@ -102,7 +102,6 @@ public:
void refresh();
Tag *getTag();
AudioData *getAudioData();
void setFile(const QString &file);
......@@ -121,7 +120,6 @@ private:
CacheItem *cache;
Tag *tag;
AudioData *audioData;
};
......
......@@ -15,7 +15,7 @@
* *
***************************************************************************/
#include <qfileinfo.h>
#include <qregexp.h>
#include "tag.h"
#include "id3tag.h"
......@@ -46,11 +46,77 @@ Tag::~Tag()
}
QString Tag::absFilePath() const
{
return(fileInfo.absFilePath());
}
QDateTime Tag::lastModified() const
{
return(fileInfo.lastModified());
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
Tag::Tag(const QString &file)
{
fileInfo.setFile(file);
}
QString Tag::readBitrate(const KFileMetaInfo &metaInfo)
{
if(metaInfo.isValid() && !metaInfo.isEmpty())
return(metaInfo.item("Bitrate").string().stripWhiteSpace().section(' ', 0, 0));
else
return(QString::null);
}
QString Tag::readLength(const KFileMetaInfo &metaInfo)
{
if(metaInfo.isValid() && !metaInfo.isEmpty())
return(metaInfo.item("Length").string().stripWhiteSpace().remove(QRegExp("^0+")));
else
return(QString::null);
}
int Tag::readSeconds(const KFileMetaInfo &metaInfo)
{
QStringList l = QStringList::split(':', readLength(metaInfo));
int total = 0;
for(QStringList::Iterator it = l.begin(); it != l.end(); ++it)
total = 60 * total + (*it).toInt();
return(total);
}
////////////////////////////////////////////////////////////////////////////////
// related functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const Tag &t)
{
s << t.hasTag()
<< t.track()
<< t.artist()
<< t.album()
<< t.genre()
<< t.trackNumber()
<< t.trackNumberString()
<< t.year()
<< t.yearString()
<< t.comment()
<< t.bitrateString()
<< t.lengthString()
<< t.seconds()
<< t.absFilePath()
<< t.lastModified();
return(s);
}
......@@ -18,12 +18,24 @@
#ifndef TAG_H
#define TAG_H
#include <qstring.h>
#include <kfilemetainfo.h>
#include <id3/tag.h>
#include <qstring.h>
#include <qdatetime.h>
#include <qfileinfo.h>
#include "genre.h"
/**
* This class is an abstract base class for concrete Tag classes. It provides
* an API and a creation method to hide the differences between these.
*
* There are two parts here: (1) those that are appropriately tag data, such as
* the artist name or year recorded and (2) data that is not "tag" data but can
* benefit from the same abstraction mechanism used by the tag class. This
* includes the track length and bitrate at the moment.
*/
class Tag
{
public:
......@@ -36,6 +48,7 @@ public:
virtual ~Tag();
virtual void save() = 0;
virtual bool hasTag() const = 0;
virtual QString track() const = 0;
virtual QString artist() const = 0;
......@@ -46,7 +59,6 @@ public:
virtual int year() const = 0;
virtual QString yearString() const = 0;
virtual QString comment() const = 0;
virtual bool hasTag() const = 0;
virtual void setTrack(const QString &value) = 0;
virtual void setArtist(const QString &value) = 0;
......@@ -56,6 +68,19 @@ public:
virtual void setYear(int value) = 0;
virtual void setComment(const QString &value) = 0;
virtual QString bitrateString() const = 0;
virtual QString lengthString() const = 0;
virtual int seconds() const = 0;
/**
* Reads the absolute path from the QFileInfo object associated with this tag.
*/
QString absFilePath() const;
/**
* Reads the modification date from the QFileInfo object associated with this tag.
*/
QDateTime lastModified() const;
protected:
/**
* The constructor is procetected since this is an abstract class and as
......@@ -67,6 +92,15 @@ protected:
* now, but reserving it for later use.
*/
Tag(const QString &file);
static inline QString readBitrate(const KFileMetaInfo &metaInfo);
static inline QString readLength(const KFileMetaInfo &metaInfo);
static inline int readSeconds(const KFileMetaInfo &metaInfo);
private:
QFileInfo fileInfo;
};
QDataStream &operator<<(QDataStream &s, const Tag &t);
#endif
......@@ -207,7 +207,6 @@ void TagEditor::refresh()
if(item) {
Tag *tag = item->getTag();
AudioData *audioData = item->getAudioData();
artistNameBox->setEditText(tag->artist());
trackNameBox->setText(tag->track());
......@@ -224,14 +223,8 @@ void TagEditor::refresh()
trackSpin->setValue(tag->trackNumber());
yearSpin->setValue(tag->year());
if(audioData->getResult()) {
lengthBox->setText(audioData->getLengthChar());
bitrateBox->setText(QString::number(audioData->getBitrate()));
}
else {
lengthBox->clear();
bitrateBox->clear();
}
lengthBox->setText(tag->lengthString());
bitrateBox->setText(tag->bitrateString());
commentBox->setText(tag->comment());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment