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

Implemented the basics of a custom genre system. This touched a lot of

the code.  Also a new function had to be added to id3lib, which hopefully
will be added to id3lib CVS soon.  The next step with custom genres is
to allow an editor for custom genre lists.

These additions allow for keeping track of v1 and v2 genres in the same
tag.

svn path=/trunk/kdemultimedia/juk/; revision=143242
parent 612f6497
......@@ -32,6 +32,20 @@ Genre::Genre(QString genreName, int id3v1Number) : QString(genreName)
id3v1 = id3v1Number;
}
Genre &Genre::operator=(const QString &genreName)
{
Genre genre(genreName, this->getId3v1());
*this = genre;
return(*this);
}
Genre &Genre::operator=(const char *genreName)
{
Genre genre(genreName, this->getId3v1());
*this = genre;
return(*this);
}
int Genre::getId3v1()
{
return(id3v1);
......
......@@ -24,7 +24,10 @@ class Genre : public QString
{
public:
Genre();
Genre(QString genreName, int id3v1Number);
Genre(QString genreName, int id3v1Number = 255);
Genre &operator=(const QString &);
Genre &operator=(const char *);
int getId3v1();
......
......@@ -92,9 +92,9 @@ int GenreList::findIndex(QString item)
void GenreList::initializeIndex()
{
kdDebug() << "initializeIndex()" << endl;
// kdDebug() << "initializeIndex()" << endl;
index.clear();
kdDebug() << "Cleared size: " << index.size() << endl;
// kdDebug() << "Cleared size: " << index.size() << endl;
index.resize(count() + 1);
for(GenreList::Iterator it = begin(); it != end(); ++it) {
if((*it).getId3v1() >= 0 && (*it).getId3v1() <= int(index.size())) {
......
......@@ -15,6 +15,8 @@
* *
***************************************************************************/
#include "kdebug.h"
#include "genrelistreader.h"
////////////////////////////////////////////////////////////////////////////////
......@@ -24,6 +26,7 @@
GenreListReader::GenreListReader(GenreList *genreList)
{
list = genreList;
inGenreTag = false;
}
GenreListReader::~GenreListReader()
......@@ -54,8 +57,8 @@ bool GenreListReader::endElement(const QString&, const QString&, const QString&
bool GenreListReader::characters(const QString& content)
{
if(inGenreTag) {
if(inGenreTag)
list->append(Genre(content, id3v1));
}
return(true);
};
......@@ -31,7 +31,6 @@
SliderAction::SliderAction(const QString &text, QObject *parent, const char *name)
: CustomAction(text, parent, name)
{
connect(this, SIGNAL(pluggedIn(QWidget *)), this, SLOT(createWidget(QWidget *)));
}
SliderAction::~SliderAction()
......
......@@ -15,13 +15,15 @@
* *
***************************************************************************/
#include <kdebug.h>
#include <qdir.h>
#include <qregexp.h>
#include <id3/misc_support.h>
#include "tag.h"
#include "genre.h"
#include "genrelist.h"
#include "genrelistlist.h"
......@@ -48,8 +50,8 @@ Tag::Tag(QString file)
trackNumber = ID3_GetTrackNum(&tag);
trackNumberString = ID3_GetTrack(&tag);
comment = ID3_GetComment(&tag);
genreNumber = int(ID3_GetGenreNum(&tag));
genre = ID3_GetGenre(&tag);
genre.setId3v1(int(ID3_GetGenreNum(&tag)));
yearString = ID3_GetYear(&tag);
hasTagBool = (tag.HasV2Tag() || tag.HasV1Tag());
......@@ -67,14 +69,16 @@ Tag::Tag(QString file)
}
///////////////////////////////////////////////////////
// get the genrename from the genre number
// parse the genre string for (<id3v1 number>)
///////////////////////////////////////////////////////
if(genre == "(" + QString::number(genreNumber) + ")" || genre == QString::null)
genre = GenreListList::id3v1List()->name(genreNumber);
if(genre == "(" + QString::number(genre.getId3v1()) + ")" || genre == QString::null)
genre = GenreListList::id3v1List()->name(genre.getId3v1());
else if(genre.find(QRegExp("\\([0-9]+\\)")) == 0)
genre = genre.mid(genre.find(")") + 1);
///////////////////////////////////////////////////////
// convert the year to a string
// convert the year
///////////////////////////////////////////////////////
year = yearString.toInt();
......@@ -120,9 +124,16 @@ void Tag::save()
else {
ID3_RemoveTracks(&tag);
}
ID3_AddGenre(&tag, 1, REPLACE);
if(genreNumber>=0 && genreNumber<255) {
ID3_AddGenre(&tag, genreNumber, REPLACE);
// ID3_AddGenre(&tag, 1, REPLACE);
if(genre.getId3v1() >=0 && genre.getId3v1() < int(GenreListList::id3v1List()->count())) {
QString genreString;
if(genre != GenreListList::id3v1List()->name(genre.getId3v1()))
genreString = "(" + QString::number(genre.getId3v1()) + ")" + genre;
else
genreString = "(" + QString::number(genre.getId3v1()) + ")";
ID3_AddGenre(&tag, genreString.latin1(), REPLACE);
}
else {
ID3_RemoveGenres(&tag);
......@@ -152,8 +163,7 @@ QString Tag::getFileName() { return fileName; }
QString Tag::getTrack() { return trackName; } // The song's name, not it's track number
QString Tag::getArtist() { return artistName; }
QString Tag::getAlbum() { return albumName; }
QString Tag::getGenre() { return genre; }
int Tag::getGenreNumber() { return genreNumber; }
Genre Tag::getGenre() { return genre; }
int Tag::getTrackNumber() { return trackNumber; }
QString Tag::getTrackNumberString() { return trackNumberString; }
int Tag::getYear() { return year; }
......@@ -181,15 +191,10 @@ void Tag::setAlbum(QString value)
changed = true;
albumName = value;
};
void Tag::setGenre(int value)
void Tag::setGenre(Genre value)
{
changed = true;
if(value >= 0 && value <= 255) {
genreNumber = value;
}
else {
genreNumber = 255;
}
genre = value;
};
void Tag::setTrackNumber(int value)
{
......
......@@ -22,6 +22,8 @@
#include <id3/tag.h>
#include "genre.h"
class Tag
{
public:
......@@ -37,8 +39,7 @@ public:
QString getTrack(); // The song's name, not it's track number
QString getArtist();
QString getAlbum();
QString getGenre();
int getGenreNumber();
Genre getGenre();
int getTrackNumber();
QString getTrackNumberString();
int getYear();
......@@ -51,8 +52,7 @@ public:
void setTrack(QString value); // The song's name, not it's track number
void setArtist(QString value);
void setAlbum(QString value);
void setGenre(QString value);
void setGenre(int value);
void setGenre(Genre value);
void setTrackNumber(int value);
void setYear(int value);
void setComment(QString value);
......@@ -70,8 +70,7 @@ private:
QString trackName;
int trackNumber;
QString trackNumberString;
QString genre;
int genreNumber;
Genre genre;
int year;
QString yearString;
QString comment;
......
......@@ -67,7 +67,7 @@ FileListItem *TaggerWidget::getSelectedItem()
void TaggerWidget::save()
{
kdDebug() << "TaggerWidget::save()" << endl;
// kdDebug() << "TaggerWidget::save()" << endl;
QPtrList<QListViewItem> items = taggerList->selectedItems();
if(items.count() > 0) {
......@@ -97,12 +97,18 @@ void TaggerWidget::save()
item->getTag()->setArtist(artistNameBox->currentText());
item->getTag()->setTrack(trackNameBox->text());
item->getTag()->setAlbum(albumNameBox->currentText());
// item->getTag()->setGenre(genreBox->currentText());
// item->getTag()->setGenre(genreBox->currentItem() - 1);
item->getTag()->setTrackNumber(trackSpin->value());
item->getTag()->setYear(yearSpin->value());
item->getTag()->setComment(commentBox->text());
// item->getTag()->setGenre(genreBox->currentText());
// item->getTag()->setGenre(genreBox->currentItem() - 1);
if(genreList->findIndex(genreBox->currentText()) >= 0)
item->getTag()->setGenre((*genreList)[genreList->findIndex(genreBox->currentText())]);
else
item->getTag()->setGenre(Genre(genreBox->currentText(), item->getTag()->getGenre().getId3v1()));
item->getTag()->save();
item->refresh();
......@@ -121,6 +127,7 @@ void TaggerWidget::save()
void TaggerWidget::setChanged()
{
changed = true;
// kdDebug() << "setChanged()" << endl;
}
////////////////////////////////////////////////////////////////////////////////
......@@ -195,7 +202,7 @@ void TaggerWidget::setupLayout()
leftColumnLayout->addWidget(new QLabel(i18n("Genre"), bottem));
genreBox = new KComboBox(false, bottem, "genreBox");
genreBox = new KComboBox(true, bottem, "genreBox");
leftColumnLayout->addWidget(genreBox);
......@@ -250,7 +257,8 @@ void TaggerWidget::setupLayout()
connect(artistNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(trackNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(albumNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(genreBox, SIGNAL(activated(const QString&)), this, SLOT(setChanged()));
connect(genreBox, SIGNAL(activated(int)), this, SLOT(setChanged()));
connect(genreBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(fileNameBox, SIGNAL(textChanged(const QString&)), this, SLOT(setChanged()));
connect(yearSpin, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
connect(trackSpin, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
......@@ -264,7 +272,7 @@ void TaggerWidget::readConfig()
genreBox->clear();
// add values to the genre box
genreBox->insertItem(QString::null);
for(GenreList::Iterator it = genreList->begin(); it != genreList->end(); ++it)
for(GenreList::Iterator it = genreList->begin(); it != genreList->end(); ++it)
genreBox->insertItem((*it));
}
}
......@@ -294,8 +302,10 @@ void TaggerWidget::updateBoxes() // this needs to be updated to properly work wi
if(genreList && genreList->findIndex(tag->getGenre()) >= 0)
genreBox->setCurrentItem(genreList->findIndex(tag->getGenre()) + 1);
else
else {
genreBox->setCurrentItem(0);
genreBox->setEditText(tag->getGenre());
}
fileNameBox->setText(fileInfo->fileName());
trackSpin->setValue(tag->getTrackNumber());
......
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