Commit 69dc2427 authored by Scott Wheeler's avatar Scott Wheeler

Ok, again, a few days without a suitable internet connection so, a list of

changes:

*) De-singleton-ified PlaylistSplitter and made appropriate changes to pass
   a pointer in the few places needed.

*) Added support for renaming a playlist without renaming the file using
   a comment in the m3u file to save the name.

*) Cleaned up the Tag API and made it an abstract class.  I added concrete
   implementations ID3Tag, OggTag and CachedTag, however only ID3Tag has
   an implementation at the moment.

svn path=/trunk/kdemultimedia/juk/; revision=182511
parent e2ecad0a
......@@ -3,12 +3,12 @@ bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_SOURCES = cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
SUBDIRS = pics data
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
......
/***************************************************************************
cachedtag.cpp - description
-------------------
begin : Sat Oct 5 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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 "cachedtag.h"
CachedTag::CachedTag(const QString &file) : Tag(file)
{
}
CachedTag::~CachedTag()
{
}
void CachedTag::save()
{
}
QString CachedTag::track() const
{
return(QString::null);
}
QString CachedTag::artist() const
{
return(QString::null);
}
QString CachedTag::album() const
{
return(QString::null);
}
Genre CachedTag::genre() const
{
Genre g;
return(g);
}
int CachedTag::trackNumber() const
{
return(0);
}
QString CachedTag::trackNumberString() const
{
return(QString::null);
}
int CachedTag::year() const
{
return(0);
}
QString CachedTag::yearString() const
{
return(QString::null);
}
QString CachedTag::comment() const
{
return(QString::null);
}
bool CachedTag::hasTag() const
{
return(false);
}
void CachedTag::setTrack(const QString &value)
{
}
void CachedTag::setArtist(const QString &value)
{
}
void CachedTag::setAlbum(const QString &value)
{
}
void CachedTag::setGenre(const Genre &value)
{
}
void CachedTag::setTrackNumber(int value)
{
}
void CachedTag::setYear(int value)
{
}
void CachedTag::setComment(const QString &value)
{
}
/***************************************************************************
cachedtag.h - description
-------------------
begin : Sat Oct 5 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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 CACHEDTAG_H
#define CACHEDTAG_H
#include "tag.h"
class CachedTag : public Tag
{
public:
CachedTag(const QString &file);
virtual ~CachedTag();
virtual void save();
virtual QString track() const;
virtual QString artist() const;
virtual QString album() const;
virtual Genre genre() const;
virtual int trackNumber() const;
virtual QString trackNumberString() const;
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);
virtual void setAlbum(const QString &value);
virtual void setGenre(const Genre &value);
virtual void setTrackNumber(int value);
virtual void setYear(int value);
virtual void setComment(const QString &value);
};
#endif
......@@ -33,9 +33,9 @@ CollectionList *CollectionList::instance()
return(list);
}
void CollectionList::initialize(QWidget *parent)
void CollectionList::initialize(PlaylistSplitter *s, QWidget *parent)
{
list = new CollectionList(parent);
list = new CollectionList(s, parent);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -69,7 +69,7 @@ PlaylistItem *CollectionList::createItem(const QFileInfo &file, QListViewItem *)
// protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionList::CollectionList(QWidget *parent) : Playlist(parent, "collectionList")
CollectionList::CollectionList(PlaylistSplitter *s, QWidget *parent) : Playlist(s, parent, "collectionList")
{
}
......@@ -91,8 +91,8 @@ void CollectionList::contentsDropEvent(QDropEvent *e)
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
if(PlaylistSplitter::instance())
PlaylistSplitter::instance()->add(files, this);
if(playlistSplitter())
playlistSplitter()->add(files, this);
}
}
}
......
......@@ -33,6 +33,7 @@
"initialize()" method.
*/
class PlaylistSplitter;
class CollectionListItem;
class CollectionList : public Playlist
......@@ -42,7 +43,7 @@ class CollectionList : public Playlist
Q_OBJECT
public:
static CollectionList *instance();
static void initialize(QWidget *parent);
static void initialize(PlaylistSplitter *s, QWidget *parent);
QStringList artists() const;
QStringList albums() const;
......@@ -51,7 +52,7 @@ public:
virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *);
protected:
CollectionList(QWidget *parent = 0);
CollectionList(PlaylistSplitter *s, QWidget *parent);
virtual ~CollectionList();
virtual void contentsDropEvent(QDropEvent *e);
......
/***************************************************************************
tag.cpp - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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 <qdir.h>
#include <qregexp.h>
#include <id3/misc_support.h>
#include "id3tag.h"
#include "genrelist.h"
#include "genrelistlist.h"
#define REPLACE true
// Warning: Some of this code is really old (~2 years) and may reflect some of
// my C days and or general bad design. However, I haven't gone to great length
// to replace it since it will be replaced when TagLib is ready to drop in.
// Basically, if you are looking for an example of my programming style -- look
// into the other classes. This is a leftover from QTagger 0.1. ;-)
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
ID3Tag::ID3Tag(const QString &file) : Tag(file)
{
fileName = file;
tag.Link(fileName.latin1());
changed = false;
// the easy ones -- these are supported in the id3 class
char *temp;
temp = ID3_GetArtist(&tag);
tagArtist = temp;
delete [] temp;
temp = ID3_GetAlbum(&tag);
tagAlbum = temp;
delete [] temp;
temp = ID3_GetTitle(&tag);
tagTrack = temp;
delete [] temp;
temp = ID3_GetTrack(&tag);
tagTrackNumberString = temp;
delete [] temp;
tagTrackNumberString.replace(QRegExp("^0+"), QString::null);
tagTrackNumber = ID3_GetTrackNum(&tag);
temp = ID3_GetComment(&tag);
tagComment = temp;
delete [] temp;
temp = ID3_GetGenre(&tag);
tagGenre = temp;
delete [] temp;
tagGenre.setID3v1(int(ID3_GetGenreNum(&tag)));
temp = ID3_GetYear(&tag);
tagYearString = temp;
delete [] temp;
tagExists = (tag.HasV2Tag() || tag.HasV1Tag());
if(tagTrack.length() <= 0) {
tagTrack = fileName;
while((tagTrack.right(4)).lower() == ".mp3")
tagTrack = tagTrack.left(tagTrack.length() - 4);
tagTrack = tagTrack.right(tagTrack.length() - tagTrack.findRev(QDir::separator(), -1) -1);
}
// parse the genre string for (<ID3v1 number>)
if(tagGenre == "(" + QString::number(tagGenre.getID3v1()) + ")" || tagGenre == QString::null)
tagGenre = GenreListList::ID3v1List()->name(tagGenre.getID3v1());
else if(tagGenre.find(QRegExp("\\([0-9]+\\)")) == 0)
tagGenre = tagGenre.mid(tagGenre.find(")") + 1);
// convert the year
tagYear = tagYearString.toInt();
if(tagYear <= 0)
tagYearString = QString::null;
}
ID3Tag::~ID3Tag()
{
save();
}
void ID3Tag::save()
{
if(changed) {
if(tagArtist.length() > 0)
ID3_AddArtist(&tag, tagArtist.latin1(), REPLACE);
else
ID3_RemoveArtists(&tag);
if(tagAlbum.length() > 0)
ID3_AddAlbum(&tag, tagAlbum.latin1(), REPLACE);
else
ID3_RemoveAlbums(&tag);
if(tagTrack.length() > 0)
ID3_AddTitle(&tag, tagTrack.latin1(), REPLACE);
else
ID3_RemoveTitles(&tag);
if(tagTrackNumber > 0)
ID3_AddTrack(&tag, uchar(tagTrackNumber), uchar(0), REPLACE);
else
ID3_RemoveTracks(&tag);
if(tagGenre.getID3v1() >= 0 && tagGenre.getID3v1() < int(GenreListList::ID3v1List()->count())) {
QString genreString;
if(tagGenre != GenreListList::ID3v1List()->name(tagGenre.getID3v1()))
genreString = "(" + QString::number(tagGenre.getID3v1()) + ")" + tagGenre;
else
genreString = "(" + QString::number(tagGenre.getID3v1()) + ")";
ID3_AddGenre(&tag, genreString.latin1(), REPLACE);
}
else
ID3_RemoveGenres(&tag);
if(tagYear > 0)
ID3_AddYear(&tag, tagYearString.latin1(), REPLACE);
else
ID3_RemoveYears(&tag);
ID3_RemoveComments(&tag);
if(tagComment.length()>0)
ID3_AddComment(&tag, tagComment.latin1(), REPLACE);
tag.Update();
changed = false;
}
}
QString ID3Tag::track() const // The song's name, not it's track number
{
return(tagTrack);
}
QString ID3Tag::artist() const
{
return(tagArtist);
}
QString ID3Tag::album() const
{
return(tagAlbum);
}
Genre ID3Tag::genre() const
{
return(tagGenre);
}
int ID3Tag::trackNumber() const
{
return(tagTrackNumber);
}
QString ID3Tag::trackNumberString() const
{
return(tagTrackNumberString);
}
int ID3Tag::year() const
{
return(tagYear);
}
QString ID3Tag::yearString() const
{
return(tagYearString);
}
QString ID3Tag::comment() const
{
return(tagComment);
}
bool ID3Tag::hasTag() const
{
return(tagExists);
}
/////////////////////////////////////////////////////
// functions that set information
/////////////////////////////////////////////////////
void ID3Tag::setTrack(const QString &value)
{
changed = true;
tagTrack = value;
};
void ID3Tag::setArtist(const QString &value)
{
changed = true;
tagArtist = value;
};
void ID3Tag::setAlbum(const QString &value)
{
changed = true;
tagAlbum = value;
};
void ID3Tag::setGenre(const Genre &value)
{
changed = true;
tagGenre = value;
};
void ID3Tag::setTrackNumber(int value)
{
changed = true;
tagTrackNumber = value;
if(tagTrackNumber > 0)
tagTrackNumberString.setNum(value);
else
tagTrackNumberString = QString::null;
};
void ID3Tag::setYear(int value)
{
changed = true;
tagYear = value;
if(tagYear > 0)
tagYearString.setNum(value);
else
tagYearString = QString::null;
};
void ID3Tag::setComment(const QString &value)
{
changed = true;
tagComment = value;
};
/***************************************************************************
id3tag.h - description
-------------------
begin : Sun Feb 17 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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 ID3TAG_H
#define ID3TAG_H
#include <qstring.h>
#include <id3/tag.h>
#include "tag.h"
class ID3Tag : public Tag
{
public:
ID3Tag(const QString &file);
virtual ~ID3Tag();
virtual void save();
virtual QString track() const;
virtual QString artist() const;
virtual QString album() const;
virtual Genre genre() const;
virtual int trackNumber() const;
virtual QString trackNumberString() const;
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);
virtual void setAlbum(const QString &value);
virtual void setGenre(const Genre &value);
virtual void setTrackNumber(int value);
virtual void setYear(int value);
virtual void setComment(const QString &value);
private:
ID3_Tag tag;
QString fileName;
bool changed;
QString tagTrack;
QString tagArtist;
QString tagAlbum;
Genre tagGenre;
int tagTrackNumber;
QString tagTrackNumberString;
int tagYear;
QString tagYearString;
QString tagComment;
bool tagExists;
};
#endif
......@@ -54,8 +54,7 @@ JuK::~JuK()
void JuK::setupLayout()
{
PlaylistSplitter::initialize(this);
splitter = PlaylistSplitter::instance();
splitter = new PlaylistSplitter(this, "playlistSplitter");
setCentralWidget(splitter);
// playlist item activation connection
......@@ -191,6 +190,7 @@ void JuK::saveConfig()
bool JuK::queryClose()
{
saveConfig();
delete(splitter);
return(true);
}
......
/***************************************************************************
oggtag.cpp - description
-------------------
begin : Sat Oct 5 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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 "oggtag.h"
OggTag::OggTag(const QString &file) : Tag(file)
{
}
OggTag::~OggTag()
{
}
void OggTag::save()
{
}
QString OggTag::track() const
{
return(QString::null);
}
QString OggTag::artist() const
{
return(QString::null);
}
QString OggTag::album() const
{
return(QString::null);
}
Genre OggTag::genre() const
{
Genre g;
return(g);
}
int OggTag::trackNumber() const
{
return(0);
}
QString OggTag::trackNumberString() const
{
return(QString::null);
}
int OggTag::year() const
{
return(0);
}
QString OggTag::yearString() const
{
return(QString::null);
}
QString OggTag::comment() const
{
return(QString::null);
}
bool OggTag::hasTag() const
{
return(false);
}
void OggTag::setTrack(const QString &value)
{
}
void OggTag::setArtist(const QString &value)
{
}
void OggTag::setAlbum(const QString &value)
{
}