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 c02e4fcb authored by Scott Wheeler's avatar Scott Wheeler

Another 10 files sacrificed to TagLib. Yay for removing code! :-) (TagLib

handles these abstractions internally and transparently.)

svn path=/trunk/kdemultimedia/juk/; revision=262554
parent 22f83bfe
......@@ -6,8 +6,8 @@ juk_SOURCES = directorylistbase.ui \
sortedstringlist.cpp systemtray.cpp splashscreen.cpp \
statuslabel.cpp cachedtag.cpp collectionlist.cpp \
playlistitem.cpp playlist.cpp playlistsplitter.cpp \
playlistbox.cpp tageditor.cpp cache.cpp genrelistreader.cpp \
genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp \
playlistbox.cpp tageditor.cpp cache.cpp \
player.cpp tag.cpp customaction.cpp \
slideraction.cpp keydialog.cpp juk.cpp main.cpp tagguesser.cpp \
tagguesserconfigdlgwidget.ui tagguesserconfigdlg.cpp jukIface.skel \
playlistsearch.cpp searchwidget.cpp filerenamer.cpp dynamicplaylist.cpp \
......
......@@ -69,7 +69,7 @@ QString CachedTag::album() const
return m_tagAlbum;
}
Genre CachedTag::genre() const
QString CachedTag::genre() const
{
if(m_externalTag)
return m_externalTag->genre();
......@@ -132,7 +132,7 @@ void CachedTag::setAlbum(const QString &value)
proxiedTag()->setAlbum(value);
}
void CachedTag::setGenre(const Genre &value)
void CachedTag::setGenre(const QString &value)
{
proxiedTag()->setGenre(value);
}
......@@ -186,20 +186,19 @@ QDataStream &CachedTag::read(QDataStream &s)
>> m_tagArtist
>> m_tagAlbum
>> m_tagGenre
>> dummyInt // TODO: remove
>> m_tagTrackNumber
>> m_tagTrackNumberString
>> m_tagYear
>> m_tagYearString
>> m_tagComment
>> m_tagBitrateString
>> m_tagLengthString
>> m_tagSeconds
>> dummyString // TODO: remove
>> dummyString // TODO: remove
>> m_modificationTime;
//Try to reduce memory usage: share tags that frequently repeat, squeeze others
// Try to reduce memory usage: share tags that frequently repeat, squeeze others
m_tagTrack.squeeze();
m_tagComment = StringShare::tryShare(m_tagComment);
m_tagArtist = StringShare::tryShare(m_tagArtist);
......
......@@ -33,7 +33,7 @@ public:
virtual QString track() const;
virtual QString artist() const;
virtual QString album() const;
virtual Genre genre() const;
virtual QString genre() const;
virtual int trackNumber() const;
virtual QString trackNumberString() const;
virtual int year() const;
......@@ -43,7 +43,7 @@ public:
virtual void setTrack(const QString &value);
virtual void setArtist(const QString &value);
virtual void setAlbum(const QString &value);
virtual void setGenre(const Genre &value);
virtual void setGenre(const QString &value);
virtual void setTrackNumber(int value);
virtual void setYear(int value);
virtual void setComment(const QString &value);
......@@ -67,7 +67,7 @@ private:
QString m_tagTrack;
QString m_tagArtist;
QString m_tagAlbum;
Genre m_tagGenre;
QString m_tagGenre;
int m_tagTrackNumber;
QString m_tagTrackNumberString;
int m_tagYear;
......
......@@ -18,7 +18,7 @@ AC_DEFUN(AC_NO_GST,
have_gst=false
])
KDE_CHECK_HEADER(kde/gst/gstreamer.h,
KDE_CHECK_HEADER(kde/gst/gstreamer.hh,
AC_HAVE_GST,
AC_NO_GST
)
......
juk_datadir = $(kde_datadir)/juk
juk_data_DATA = id3v1.genreml
<genreList name="id3v1">
<genre id3v1="123">A Capella</genre>
<genre id3v1="34">Acid</genre>
<genre id3v1="74">Acid Jazz</genre>
<genre id3v1="73">Acid Punk</genre>
<genre id3v1="99">Acoustic</genre>
<genre id3v1="40">Alt. Rock</genre>
<genre id3v1="20">Alternative</genre>
<genre id3v1="26">Ambient</genre>
<genre id3v1="145">Anime</genre>
<genre id3v1="90">Avantgarde</genre>
<genre id3v1="116">Ballad</genre>
<genre id3v1="41">Bass</genre>
<genre id3v1="135">Beat</genre>
<genre id3v1="85">Bebob</genre>
<genre id3v1="96">Big Band</genre>
<genre id3v1="138">Black Metal</genre>
<genre id3v1="89">Bluegrass</genre>
<genre id3v1="0">Blues</genre>
<genre id3v1="107">Booty Bass</genre>
<genre id3v1="132">BritPop</genre>
<genre id3v1="65">Cabaret</genre>
<genre id3v1="88">Celtic</genre>
<genre id3v1="104">Chamber Music</genre>
<genre id3v1="102">Chanson</genre>
<genre id3v1="97">Chorus</genre>
<genre id3v1="136">Christian Gangsta Rap</genre>
<genre id3v1="61">Christian Rap</genre>
<genre id3v1="141">Christian Rock</genre>
<genre id3v1="1">Classic Rock</genre>
<genre id3v1="32">Classical</genre>
<genre id3v1="112">Club</genre>
<genre id3v1="128">Club-House</genre>
<genre id3v1="57">Comedy</genre>
<genre id3v1="140">Contemporary Christian</genre>
<genre id3v1="2">Country</genre>
<genre id3v1="139">Crossover</genre>
<genre id3v1="58">Cult</genre>
<genre id3v1="3">Dance</genre>
<genre id3v1="125">Dance Hall</genre>
<genre id3v1="50">Darkwave</genre>
<genre id3v1="22">Death Metal</genre>
<genre id3v1="4">Disco </genre>
<genre id3v1="55">Dream</genre>
<genre id3v1="127">Drum &amp; Bass</genre>
<genre id3v1="122">Drum Solo</genre>
<genre id3v1="120">Duet</genre>
<genre id3v1="98">Easy Listening</genre>
<genre id3v1="52">Electronic</genre>
<genre id3v1="48">Ethnic</genre>
<genre id3v1="124">Euro-House</genre>
<genre id3v1="25">Euro-Techno</genre>
<genre id3v1="54">Eurodance</genre>
<genre id3v1="84">Fast Fusion</genre>
<genre id3v1="80">Folk</genre>
<genre id3v1="81">Folk/Rock</genre>
<genre id3v1="115">Folklore</genre>
<genre id3v1="119">Freestyle</genre>
<genre id3v1="5">Funk</genre>
<genre id3v1="30">Fusion</genre>
<genre id3v1="36">Game</genre>
<genre id3v1="59">Gangsta</genre>
<genre id3v1="126">Goa</genre>
<genre id3v1="38">Gospel</genre>
<genre id3v1="49">Gothic</genre>
<genre id3v1="91">Gothic Rock</genre>
<genre id3v1="6">Grunge</genre>
<genre id3v1="79">Hard Rock</genre>
<genre id3v1="129">Hardcore</genre>
<genre id3v1="137">Heavy Metal</genre>
<genre id3v1="7">Hip-Hop</genre>
<genre id3v1="35">House</genre>
<genre id3v1="100">Humour</genre>
<genre id3v1="131">Indie</genre>
<genre id3v1="19">Industrial</genre>
<genre id3v1="46">Instrum. Pop</genre>
<genre id3v1="47">Instrum. Rock</genre>
<genre id3v1="33">Instrumental</genre>
<genre id3v1="8">Jazz</genre>
<genre id3v1="29">Jazz+Funk</genre>
<genre id3v1="146">Jpop</genre>
<genre id3v1="63">Jungle</genre>
<genre id3v1="86">Latin</genre>
<genre id3v1="71">Lo-Fi</genre>
<genre id3v1="45">Meditative</genre>
<genre id3v1="142">Merengue</genre>
<genre id3v1="9">Metal</genre>
<genre id3v1="77">Musical</genre>
<genre id3v1="82">National Folk</genre>
<genre id3v1="64">Native American</genre>
<genre id3v1="133">Negerpunk</genre>
<genre id3v1="10">New Age</genre>
<genre id3v1="66">New Wave</genre>
<genre id3v1="39">Noise</genre>
<genre id3v1="11">Oldies</genre>
<genre id3v1="103">Opera</genre>
<genre id3v1="12">Other</genre>
<genre id3v1="75">Polka</genre>
<genre id3v1="134">Polsk Punk</genre>
<genre id3v1="13">Pop</genre>
<genre id3v1="53">Pop-Folk</genre>
<genre id3v1="62">Pop/Funk</genre>
<genre id3v1="109">Porn Groove</genre>
<genre id3v1="117">Power Ballad</genre>
<genre id3v1="23">Pranks</genre>
<genre id3v1="108">Primus</genre>
<genre id3v1="92">Progress. Rock</genre>
<genre id3v1="93">Psychadel. Rock</genre>
<genre id3v1="67">Psychadelic</genre>
<genre id3v1="43">Punk</genre>
<genre id3v1="121">Punk Rock</genre>
<genre id3v1="14">R&amp;B</genre>
<genre id3v1="15">Rap</genre>
<genre id3v1="68">Rave</genre>
<genre id3v1="16">Reggae</genre>
<genre id3v1="76">Retro</genre>
<genre id3v1="87">Revival</genre>
<genre id3v1="118">Rhythmic Soul</genre>
<genre id3v1="17">Rock</genre>
<genre id3v1="78">Rock &amp; Roll</genre>
<genre id3v1="143">Salsa</genre>
<genre id3v1="114">Samba</genre>
<genre id3v1="110">Satire</genre>
<genre id3v1="69">Showtunes</genre>
<genre id3v1="21">Ska</genre>
<genre id3v1="111">Slow Jam</genre>
<genre id3v1="95">Slow Rock</genre>
<genre id3v1="105">Sonata</genre>
<genre id3v1="42">Soul</genre>
<genre id3v1="37">Sound Clip</genre>
<genre id3v1="24">Soundtrack</genre>
<genre id3v1="56">Southern Rock</genre>
<genre id3v1="44">Space</genre>
<genre id3v1="101">Speech</genre>
<genre id3v1="83">Swing</genre>
<genre id3v1="94">Symphonic Rock</genre>
<genre id3v1="106">Symphony</genre>
<genre id3v1="147">Synthpop</genre>
<genre id3v1="113">Tango</genre>
<genre id3v1="18">Techno</genre>
<genre id3v1="51">Techno-Indust.</genre>
<genre id3v1="130">Terror</genre>
<genre id3v1="144">Thrash Metal</genre>
<genre id3v1="60">Top 40</genre>
<genre id3v1="70">Trailer</genre>
<genre id3v1="31">Trance</genre>
<genre id3v1="72">Tribal</genre>
<genre id3v1="27">Trip-Hop</genre>
<genre id3v1="28">Vocal</genre>
</genreList>
/***************************************************************************
genre.cpp - description
-------------------
begin : Tue Feb 5 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "genre.h"
#include "genrelistlist.h"
#include "stringshare.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
Genre::Genre() :
m_ID3v1(255)
{
}
Genre::Genre(const QString &name) :
m_name(StringShare::tryShare(name))
{
m_ID3v1 = GenreListList::ID3v1List().findIndex(name);
if(m_ID3v1 < 0)
m_ID3v1 = 255;
}
Genre::Genre(const QString &name, int ID3v1) :
m_name(StringShare::tryShare(name)),
m_ID3v1(ID3v1)
{
}
////////////////////////////////////////////////////////////////////////////////
// related functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const Genre &g)
{
s << g.name() << g.ID3v1();
return s;
}
QDataStream &operator>>(QDataStream &s, Genre &g)
{
QString name;
int n;
s >> name >> n;
g.setName(StringShare::tryShare(name));
g.setID3v1(n);
return s;
}
/***************************************************************************
genre.h - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef GENRE_H
#define GENRE_H
#include <qstring.h>
#include <qdatastream.h>
class Genre
{
public:
Genre();
explicit Genre(const QString &name);
explicit Genre(const QString &name, int ID3v1);
QString name() const { return m_name; }
void setName(const QString &name) { m_name = name; }
int ID3v1() const { return m_ID3v1; }
void setID3v1(int ID3v1) { m_ID3v1 = ID3v1; }
private:
QString m_name;
int m_ID3v1;
};
QDataStream &operator<<(QDataStream &s, const Genre &g);
QDataStream &operator>>(QDataStream &s, Genre &g);
#endif
/***************************************************************************
genrelist.cpp - description
-------------------
begin : Sun Mar 3 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <kdebug.h>
#include "genrelist.h"
#include "genrelistreader.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
GenreList::GenreList(bool createIndex) : QValueList<Genre>(), m_hasIndex(createIndex)
{
}
GenreList::GenreList(const QString &file, bool createIndex) : QValueList<Genre>(), m_hasIndex(createIndex)
{
load(file);
}
void GenreList::load(const QString &file)
{
GenreListReader handler(*this);
QFile input(file);
QXmlInputSource source(input);
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
reader.parse(source);
if(m_hasIndex)
initializeIndex();
}
QString GenreList::ID3v1Name(int ID3v1)
{
if(m_hasIndex && ID3v1 >= 0 && ID3v1 < int(m_index.size()))
return m_index[ID3v1];
else
return QString::null;
}
int GenreList::findIndex(const QString &item)
{
// cache the previous search -- since there are a lot of "two in a row"
// searchs this should optimize things a little (this is also why this
// method isn't a "const" method)
static QString lastItem;
static int lastIndex;
// a cache hit
if(!lastItem.isEmpty() && lastItem == item)
return lastIndex;
int i = 0;
for(GenreList::Iterator it = begin(); it != end(); ++it) {
if(item == (*it).name()) {
lastItem = item;
lastIndex = i;
return i;
}
i++;
}
return -1;
}
QString GenreList::name() const
{
return m_listName;
}
void GenreList::setName(const QString &n)
{
m_listName = n;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void GenreList::initializeIndex()
{
m_index.clear();
m_index.resize(size());
for(GenreList::Iterator it = begin(); it != end(); ++it)
if((*it).ID3v1() >= 0 && (*it).ID3v1() < int(m_index.size()))
m_index[(*it).ID3v1()] = (*it).name();
}
/***************************************************************************
genrelist.h - description
-------------------
begin : Sun Mar 3 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef GENRELIST_H
#define GENRELIST_H
#include <qvaluelist.h>
#include <qvaluevector.h>
#include "genre.h"
class GenreList : public QValueList<Genre>
{
public:
GenreList(bool createIndex = false);
GenreList(const QString &file, bool createIndex = false);
void load(const QString &file);
/**
* Given an ID3v1 "number", look up the name.
*/
QString ID3v1Name(int ID3v1);
/**
* Do a "reverse" lookup. Given an ID3v1 genre name, find the m_index. Though
* I didn't realize it at the time that I wrote it, this is a
* reimplimentation from QValueList; ours however caches the last search so
* it should speed things up a bit for "two in a row" searches that are
* common.
*/
int findIndex(const QString &item);
QString name() const;
void setName(const QString &n);
bool readOnly() const { return m_readOnlyList; }
void setReadOnly(bool ro) { m_readOnlyList = ro; }
private:
/**
* 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();
QValueVector<QString> m_index;
bool m_hasIndex;
QString m_listName;
bool m_readOnlyList;
};
#endif
/***************************************************************************
genrelistlist.cpp - description
-------------------
begin : Sun Mar 3 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <kstandarddirs.h>
#include <kdebug.h>
#include <qdir.h>
#include "genrelistlist.h"
////////////////////////////////////////////////////////////////////////////////
// static members
////////////////////////////////////////////////////////////////////////////////
// There are some nasty hacks here to get around not being able to call locate()
// in the initialization of a static data member. As a result, the function
// below can not be called in the initialization of another static member and
// if it is, well, all hell will break loose and you'll get a strange segfault.
// public
GenreList GenreListList::ID3v1List()
{
if(!ID3v1) {
ID3v1 = new GenreList(true);
ID3v1->load(locate("data", "juk/id3v1.genreml"));
ID3v1->setReadOnly(true);
}
return *ID3v1;
}
GenreListList GenreListList::lists()
{
GenreListList l;
if(ID3v1)
l.append(*ID3v1);
QDir dir(KGlobal::dirs()->saveLocation("appdata"));
QStringList files = dir.entryList("*.genreml");
for(QStringList::Iterator it = files.begin(); it != files.end(); it++) {
GenreList genreList(*it);
if(!genreList.isEmpty())
l.append(genreList);
}
return l;
}
// private
GenreList *GenreListList::ID3v1 = 0;
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
GenreListList::GenreListList()
{
}
GenreListList::~GenreListList()
{
}
/***************************************************************************
genrelistlist.h - description
-------------------
begin : Sun Mar 3 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef GENRELISTLIST_H
#define GENRELISTLIST_H
#include <qvaluelist.h>
#include "genrelist.h"
class GenreListList : public QValueList<GenreList>
{
public:
GenreListList();
~GenreListList();
static GenreList ID3v1List();
static GenreListList lists();
private:
static GenreList *ID3v1;
};
#endif
/***************************************************************************
genrelistreader.cpp - description
-------------------
begin : Mon Mar 4 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <kdebug.h>
#include "genrelistreader.h"
#include "genrelist.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
GenreListReader::GenreListReader(GenreList &genreList) :
QXmlDefaultHandler(),
m_list(genreList), m_inGenreTag(false)
{
}
GenreListReader::~GenreListReader()
{
}
bool GenreListReader::startElement(const QString &, const QString &,
const QString &element,
const QXmlAttributes &attributes)
{
if(element.lower() == "genre") {
m_inGenreTag = true;
if(attributes.index("id3v1") != -1)
m_ID3v1 = attributes.value("id3v1").toInt();
else
m_ID3v1 = 255;
}
else if(element.lower() == "genrelist") {
if(attributes.index("name") != -1)
m_list.setName(attributes.value("name"));
}
else
m_ID3v1 = 255;
return true;