Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 22ba13ca authored by Scott Wheeler's avatar Scott Wheeler

Here's the first part of support for OggVorbis comments. It's just read

only at the moment and supports *most* fields.  The rest is coming in the
next few commits.

svn path=/trunk/kdemultimedia/juk/; revision=182647
parent 71abfda9
......@@ -33,14 +33,19 @@ public:
void load(const QString &file);
QString name(int ID3v1);
/**
* Do a "reverse" lookup. Given an ID3v1 genre name, find the index.
*/
int findIndex(const QString &item);
private:
QValueVector<QString> index;
bool hasIndex;
/** This is used for creating a mapping between ID3v1 genre numbers and the
name that is associated with those genres. There is no reason that this
should be called for GenreLists other than the ID3v1 GenreList. */
/**
* This is used for creating a mapping between ID3v1 genre numbers and the
* name that is associated with those genres. There is no reason that this
* should be called for GenreLists other than the ID3v1 GenreList.
*/
void initializeIndex();
};
......
......@@ -15,11 +15,19 @@
* *
***************************************************************************/
#include <kdebug.h>
#include "oggtag.h"
#include "genrelistlist.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
OggTag::OggTag(const QString &file) : Tag(file)
{
metaInfo = KFileMetaInfo(file);
commentGroup = KFileMetaInfoGroup(metaInfo.group("Comment"));
}
OggTag::~OggTag()
......@@ -34,43 +42,44 @@ void OggTag::save()
QString OggTag::track() const
{
return(QString::null);
return readCommentString("Album");
}
QString OggTag::artist() const
{
return(QString::null);
return readCommentString("Artist");
}
QString OggTag::album() const
{
return(QString::null);
return readCommentString("Album");
}
Genre OggTag::genre() const
{
Genre g;
return(g);
QString genreName = readCommentString("Genre");
int index = GenreListList::ID3v1List()->findIndex(genreName);
return Genre(genreName, index);
}
int OggTag::trackNumber() const
{
return(0);
return readCommentInt("Tracknumber");
}
QString OggTag::trackNumberString() const
{
return(QString::null);
return readCommentString("Tracknumber");
}
int OggTag::year() const
{
return(0);
return readCommentInt("Year");
}
QString OggTag::yearString() const
{
return(QString::null);
return readCommentString("Year");
}
QString OggTag::comment() const
......@@ -80,7 +89,10 @@ QString OggTag::comment() const
bool OggTag::hasTag() const
{
return(false);
if(metaInfo.isValid() && !metaInfo.isEmpty())
return(true);
else
return(false);
}
void OggTag::setTrack(const QString &value)
......@@ -117,3 +129,33 @@ void OggTag::setComment(const QString &value)
{
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
QString OggTag::readCommentString(const QString &key) const
{
if(metaInfo.isValid() && !metaInfo.isEmpty() &&
commentGroup.isValid() && !commentGroup.isEmpty() &&
commentGroup.contains(key))
return(commentGroup.item(key).string());
else
return(QString::null);
}
int OggTag::readCommentInt(const QString &key) const
{
if(metaInfo.isValid() && !metaInfo.isEmpty() &&
commentGroup.isValid() && !commentGroup.isEmpty() &&
commentGroup.contains(key)) {
bool ok;
int value = commentGroup.item(key).value().toInt(&ok);
if(ok)
return(value);
else
return(-1);
}
else
return(-1);
}
......@@ -18,6 +18,8 @@
#ifndef OGGTAG_H
#define OGGTAG_H
#include <kfilemetainfo.h>
#include "tag.h"
class OggTag : public Tag
......@@ -46,6 +48,21 @@ public:
virtual void setTrackNumber(int value);
virtual void setYear(int value);
virtual void setComment(const QString &value);
private:
/**
* Simplifies reading a string from a KFMI group. Returns QString::null if
* something went wrong or the key was not found.
*/
QString readCommentString(const QString &key) const;
/**
* Simplifies reading an int from a KFMI group. Returns -1 if something went
* wrong or the key was not found.
*/
int readCommentInt(const QString &key) const;
KFileMetaInfo metaInfo;
KFileMetaInfoGroup commentGroup;
};
#endif
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