Commit 6df2292a authored by Scott Wheeler's avatar Scott Wheeler

A cubic assload of source cleanups.

svn path=/trunk/kdemultimedia/juk/; revision=176264
parent bb258845
......@@ -3,12 +3,12 @@ bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = audiodata.cpp cacheitem.cpp filelistitemdata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp
juk_SOURCES = cache.cpp audiodata.cpp cacheitem.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.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 taggerwidget.cpp taggerwidget.h slideraction.cpp slideraction.h playlistwidget.cpp playlistwidget.h customaction.h customaction.cpp filelist.cpp filelist.h tag.cpp tag.h filelistitem.cpp filelistitem.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 filelistitemdata.cpp filelistitemdata.h cacheitem.cpp cacheitem.h audiodata.cpp audiodata.h
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc taggerwidget.cpp taggerwidget.h slideraction.cpp slideraction.h playlistwidget.cpp playlistwidget.h customaction.h customaction.cpp filelist.cpp filelist.h tag.cpp tag.h filelistitem.cpp filelistitem.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 cacheitem.cpp cacheitem.h audiodata.cpp audiodata.h cache.cpp cache.h
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
......
This diff is collapsed.
......@@ -62,8 +62,6 @@ AudioData::AudioData(const char* filein)
success = false;
fileglob = strdup(filein);
lengthchar = 0;
FILE* file;
if ((file = fopen(filein, "r")))
......@@ -80,8 +78,6 @@ AudioData::AudioData(const char* filein)
AudioData::~AudioData()
{
free(fileglob);
if(lengthchar)
free(lengthchar);
}
bool AudioData::readLayerInfo (FILE* file)
......@@ -164,23 +160,27 @@ bool AudioData::headCheck(unsigned long head)
return true;
}
int AudioData::getBitrate(){
int AudioData::getBitrate() const
{
return (bitrates[version][layer - 1][bitrate_index]);
}
int AudioData::getSamplerate(){
int AudioData::getSamplerate() const
{
return (s_freq[version][sampling_frequency]);
}
const char* AudioData::getMpegver(){
QString AudioData::getMpegver() const
{
return (version_names[version]);
}
int AudioData::getLayer() {
int AudioData::getLayer() const
{
return layer;
}
const char* AudioData::getMode(int mode)
QString AudioData::getMode(int mode)
{
if ((mode >= 0) && (mode < 5))
return (mode_names[mode]);
......@@ -188,16 +188,18 @@ const char* AudioData::getMode(int mode)
return "Stereo";
}
int AudioData::getMode()
int AudioData::getMode() const
{
return mode;
}
int AudioData::getLength() {
int AudioData::getLength() const
{
return length;
}
char* AudioData::getLengthChar() {
QString AudioData::getLengthChar() const
{
if(success) {
int min, sec;
char buf[6];
......@@ -205,18 +207,18 @@ char* AudioData::getLengthChar() {
min=length/60;
sec=length%60;
sprintf (buf, "%d:%02d", min, sec);
lengthchar=strdup (buf);
return lengthchar;
return buf;
}
else
return 0;
}
int AudioData::getSize() {
int AudioData::getSize() const
{
return filelen;
}
bool AudioData::getResult()
bool AudioData::getResult() const
{
return success;
}
......@@ -8,6 +8,7 @@
fileinfo.h was modified to just include header information instead of
header and id3 information. These changes were made by Scott Wheeler
(scott@slackorama.net) on 1/13/2002 based on Mp3Kult v0.5.
***************************************************************************/
/***************************************************************************
......@@ -17,39 +18,46 @@
* (at your option) any later version. *
***************************************************************************/
#ifndef AUDIODATA_H
#define AUDIODATA_H
#include <qstring.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
// I've started hacking a little on this file; both the API and the
// implementation. There's still a lot of ugly, non-Qt-happy stuff
// in here, but that will be fixed, well, as I feel motivated.
// (And fortunately I can blame someone else for this file. ;-) )
class AudioData
{
public:
AudioData(const char* filein);
~AudioData();
virtual ~AudioData();
int getBitrate();
int getSamplerate();
const char* getMpegver();
int getLayer();
static const char* getMode(int mode);
int getMode();
int getLength();
char* getLengthChar();
int getSize();
int getBitrate() const;
int getSamplerate() const;
QString getMpegver() const;
int getLayer() const;
static QString getMode(int mode);
int getMode() const;
int getLength() const;
QString getLengthChar() const;
int getSize() const;
bool getResult();
bool getResult() const;
private:
bool success;
char* fileglob;
int length;
char* lengthchar;
int version;
int filelen;
int layer;
......
/***************************************************************************
filelistitemdata.cpp - description
cache.cpp - description
-------------------
begin : Fri Mar 22 2002
begin : Sat Sep 7 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
***************************************************************************/
/***************************************************************************
* *
......@@ -15,60 +15,50 @@
* *
***************************************************************************/
#include "filelistitemdata.h"
#include "cache.h"
Cache *Cache::cache = 0;
////////////////////////////////////////////////////////////////////////////////
// public methods
// Cache public methods
////////////////////////////////////////////////////////////////////////////////
FileListItemData::FileListItemData(QFileInfo &file) : QFileInfo(file)
Cache *Cache::instance()
{
referenceCount = 1;
// initialize pointers to null
cache = 0;
tag = 0;
audioData = 0;
if(!cache)
cache = new Cache();
return(cache);
}
FileListItemData::~FileListItemData()
Cache::Item *Cache::item(const QString &fileName) const
{
delete(cache);
delete(tag);
delete(audioData);
return(0);
}
FileListItemData *FileListItemData::newUser()
{
referenceCount++;
return(this);
}
////////////////////////////////////////////////////////////////////////////////
// Cache protected methods
////////////////////////////////////////////////////////////////////////////////
void FileListItemData::deleteUser()
Cache::Cache()
{
if(--referenceCount == 0)
delete(this);
}
Tag *FileListItemData::getTag()
Cache::~Cache()
{
if(!tag)
tag = new Tag(filePath());
return(tag);
delete(cache);
}
AudioData *FileListItemData::getAudioData()
////////////////////////////////////////////////////////////////////////////////
// Cache::Item public methods
////////////////////////////////////////////////////////////////////////////////
Cache::Item::Item()
{
if(!audioData) {
audioData = new AudioData(filePath());
}
return(audioData);
}
void FileListItemData::setFile(QString file)
Cache::Item::~Item()
{
delete(tag);
tag = 0;
QFileInfo::setFile(file);
}
/***************************************************************************
filelistitemdata.h - description
cache.h - description
-------------------
begin : Fri Mar 22 2002
begin : Sat Sep 7 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
***************************************************************************/
/***************************************************************************
* *
......@@ -15,37 +15,37 @@
* *
***************************************************************************/
#ifndef FILELISTITEMDATA_H
#define FILELISTITEMDATA_H
#include <qfileinfo.h>
#ifndef CACHE_H
#define CACHE_H
#include <stdlib.h>
#include <qstring.h>
#include "tag.h"
#include "cacheitem.h"
#include "audiodata.h"
// Eventually this should implement the same interface as the Tag class; in fact
// there should be an abstract API for both of them to use. But, for the
// moment this is just a place holder to fill in the design.
class FileListItemData : public QFileInfo
class Cache
{
public:
FileListItemData(QFileInfo &file);
~FileListItemData();
FileListItemData *newUser();
void deleteUser();
class Item;
Tag *getTag();
AudioData *getAudioData();
static Cache *instance();
Item *item(const QString &fileName) const;
void setFile(QString file);
protected:
Cache();
virtual ~Cache();
private:
int referenceCount;
static Cache *cache;
};
CacheItem *cache;
Tag *tag;
AudioData *audioData;
class Cache::Item
{
public:
Item();
virtual ~Item();
};
#endif
......@@ -22,7 +22,7 @@ class CacheItem
{
public:
CacheItem();
~CacheItem();
virtual ~CacheItem();
};
#endif
......@@ -29,6 +29,7 @@ CustomAction::CustomAction(const QString &text, QObject *parent, const char *nam
CustomAction::~CustomAction()
{
}
int CustomAction::plug(QWidget *parent, int index)
......
......@@ -24,12 +24,16 @@
#include <qstring.h>
#include <qobject.h>
// Many months after writing this, despite having felt rather clever at the time
// I am now rather convinced that this is The Wrong Way (tm) to have handled
// things and will hopefully un-hack this later.
class CustomAction : public KAction
{
Q_OBJECT
public:
CustomAction(const QString &text, QObject *parent, const char *name);
~CustomAction();
virtual ~CustomAction();
virtual int plug(QWidget *parent, int index = -1);
virtual void unplug(QWidget *widget);
......
This diff is collapsed.
......@@ -49,11 +49,10 @@ FileList::FileList(QStringList &items, QWidget *parent, const char *name) : KLis
FileList::~FileList()
{
delete(artistList);
delete(albumList);
}
void FileList::append(QString item)
void FileList::append(const QString &item)
{
QApplication::setOverrideCursor(Qt::waitCursor);
appendImpl(item);
......@@ -61,10 +60,10 @@ void FileList::append(QString item)
emit(dataChanged());
}
void FileList::append(QStringList &items)
void FileList::append(const QStringList &items)
{
QApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::Iterator it = items.begin(); it != items.end(); ++it)
for(QStringList::ConstIterator it = items.begin(); it != items.end(); ++it)
appendImpl(*it);
QApplication::restoreOverrideCursor();
emit(dataChanged());
......@@ -109,12 +108,12 @@ QPtrList<FileListItem> FileList::selectedItems()
return(list);
}
QStringList *FileList::getArtistList()
QStringList FileList::getArtistList() const
{
return(artistList);
}
QStringList *FileList::getAlbumList()
QStringList FileList::getAlbumList() const
{
return(albumList);
}
......@@ -126,8 +125,6 @@ QStringList *FileList::getAlbumList()
void FileList::setup()
{
processed = 0;
artistList = new QStringList();
albumList = new QStringList();
extensions.append("mp3");
......@@ -148,7 +145,7 @@ void FileList::setup()
setSorting(1);
}
void FileList::appendImpl(QString item)
void FileList::appendImpl(const QString &item)
{
processEvents();
QFileInfo file(QDir::cleanDirPath(item));
......
......@@ -31,10 +31,10 @@ public:
FileList(QWidget *parent = 0, const char *name = 0);
FileList(QString &item, QWidget *parent = 0, const char *name = 0);
FileList(QStringList &items, QWidget *parent = 0, const char *name = 0);
~FileList();
virtual ~FileList();
void append(QString item);
void append(QStringList &items);
void append(const QString &item);
void append(const QStringList &items);
void append(FileListItem *item);
void append(QPtrList<FileListItem> &items);
......@@ -42,17 +42,19 @@ public:
QPtrList<FileListItem> selectedItems();
QStringList *getArtistList();
QStringList *getAlbumList();
// yay for implicit sharing!
QStringList getArtistList() const;
QStringList getAlbumList() const;
private:
void setup();
void appendImpl(QString item);
void appendImpl(const QString &item);
QStringList extensions;
QStringList members;
QStringList *artistList;
QStringList *albumList;
QStringList artistList;
QStringList albumList;
void processEvents();
int processed;
......
......@@ -19,14 +19,110 @@
#include "filelistitem.h"
#include "filelist.h"
#include "cache.h"
class FileListItem::Data : public QFileInfo
{
public:
static Data *newUser(const QFileInfo &file);
Data *newUser();
void deleteUser();
Tag *getTag();
AudioData *getAudioData();
void setFile(const QString &file);
protected:
// Because we're trying to use this as a shared item, we want all access
// to be through pointers (so that it's safe to use delete this). Thus
// creation of the object should be done by the newUser methods above
// and deletion should be handled by deleteUser. Making the constructor
// and destructor private ensures this.
Data(const QFileInfo &file);
virtual ~Data();
private:
int referenceCount;
Cache::Item *cache;
Tag *tag;
AudioData *audioData;
};
////////////////////////////////////////////////////////////////////////////////
// FileListItem::Data public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::Data *FileListItem::Data::newUser(const QFileInfo &file)
{
return(new Data(file));
}
FileListItem::Data *FileListItem::Data::newUser()
{
referenceCount++;
return(this);
}
void FileListItem::Data::deleteUser()
{
if(--referenceCount == 0)
delete(this);
}
Tag *FileListItem::Data::getTag()
{
if(!tag)
tag = new Tag(filePath());
return(tag);
}
AudioData *FileListItem::Data::getAudioData()
{
if(!audioData) {
audioData = new AudioData(filePath());
}
return(audioData);
}
void FileListItem::Data::setFile(const QString &file)
{
delete(tag);
tag = 0;
QFileInfo::setFile(file);
}
////////////////////////////////////////////////////////////////////////////////
// FileListItem::Data protected methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::Data::Data(const QFileInfo &file) : QFileInfo(file)
{
referenceCount = 1;
// initialize pointers to null
cache = 0;
tag = 0;
audioData = 0;
}
FileListItem::Data::~Data()
{
delete(cache);
delete(tag);
delete(audioData);
}
////////////////////////////////////////////////////////////////////////////////
// public methods
// FileListItem public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo &file, FileList *parent) : QObject(parent), KListViewItem(parent)
FileListItem::FileListItem(const QFileInfo &file, FileList *parent) : QObject(parent), KListViewItem(parent)
{
data = new FileListItemData(file);
data = Data::newUser(file);
refresh();
connect(this, SIGNAL(refreshed()), parent, SIGNAL(dataChanged()));
}
......@@ -46,13 +142,13 @@ FileListItem::~FileListItem()
data->deleteUser();
}
void FileListItem::setFile(QString file)
void FileListItem::setFile(const QString &file)
{
data->setFile(file);
refresh();
}
FileListItemData *FileListItem::getData()
FileListItem::Data *FileListItem::getData()
{
return(data);
}
......@@ -67,6 +163,18 @@ AudioData *FileListItem::getAudioData()
return(data->getAudioData());
}
// QFileInfo-ish methods
QString FileListItem::fileName() const { return(data->fileName()); }
QString FileListItem::filePath() const { return(data->filePath()); }
QString FileListItem::absFilePath() const { return(data->absFilePath()); }
QString FileListItem::dirPath(bool absPath) const { return(data->dirPath(absPath)); }
bool FileListItem::isWritable() const { return(data->isWritable()); }
////////////////////////////////////////////////////////////////////////////////
// FileListItem public slots
////////////////////////////////////////////////////////////////////////////////
void FileListItem::refresh()
{
// This should be the only function that needs to be rewritten if the structure of
......@@ -84,49 +192,61 @@ void FileListItem::refresh()
FileList *fileList = static_cast<FileList *>(listView());
if(text(ArtistColumn) != getTag()->getArtist() &&
fileList->getArtistList()->contains(getTag()->getArtist()) == 0)
fileList->getArtistList()->append(getTag()->getArtist());
fileList->getArtistList().contains(getTag()->getArtist()) == 0)
fileList->getArtistList().append(getTag()->getArtist());
if(text(AlbumColumn) != getTag()->getAlbum() &&
fileList->getAlbumList()->contains(getTag()->getAlbum()) == 0)
fileList->getAlbumList()->append(getTag()->getAlbum());
fileList->getAlbumList().contains(getTag()->getAlbum()) == 0)
fileList->getAlbumList().append(getTag()->getAlbum());
setText(TrackColumn, getTag()->getTrack());
setText(ArtistColumn, getTag()->getArtist());
setText(AlbumColumn, getTag()->getAlbum());
setText(TrackNumberColumn, getTag()->getTrackNumberString());
setText(GenreColumn, getTag()->getGenre());
setText(YearColumn, getTag()->getYearString());
setText(LengthColumn, getAudioData()->getLengthChar());
setText(FileNameColumn, filePath());
if(Cache::instance()->item(absFilePath())) {
emit(refreshed());
}
// ... do stuff relative to a cache hit. At the moment this will never
// happen since the cache isn't yet implemented.
// QFileInfo-ish methods
// The current though is that "Tag" and "Cache::Item" should share a
// common virtual interface so that the below code could actually be
// used through that interface. In this if block it would just be
// decided what object the meta data was going to come from and then
// something like metaData->getArtist() could be used, where metaData
// is either a Tag or a Cache::Item.
QString FileListItem::fileName() const { return(data->fileName()); }
QString FileListItem::filePath() const { return(data->filePath()); }
QString FileListItem::absFilePath() const { return(data->absFilePath()); }
QString FileListItem::dirPath(bool absPath) const { return(data->dirPath(absPath)); }
bool FileListItem::isWritable() const { return(data->isWritable()); }
// And on further thought this should also be hidden in
// FileListItem::Data. I'll work on that later.
}
else {
setText(TrackColumn, getTag()->getTrack());
setText(ArtistColumn, getTag()->getArtist());
setText(AlbumColumn, getTag()->getAlbum());
setText(TrackNumberColumn, getTag()->getTrackNumberString());
setText(GenreColumn, getTag()->getGenre());
setText(YearColumn, getTag()->getYearString());
setText(LengthColumn, getAudioData()->getLengthChar());
setText(FileNameColumn, filePath());
emit(refreshed());
}
}
////////////////////////////////////////////////////////////////////////////////
// public slots
// FileListItem protected slots
////////////////////////////////////////////////////////////////////////////////
void FileListItem::addSibling(FileListItem *sibling)
void FileListItem::addSibling(const FileListItem *sibling)
{
connect(sibling, SIGNAL(refreshed()), this, SLOT(refresh()));
}
void FileListItem::removeSibling(FileListItem *sibling)
void FileListItem::removeSibling(const FileListItem *sibling)
{
disconnect(sibling, SIGNAL(refreshed()), this, SLOT(refresh()));
}
////////////////////////////////////////////////////////////////////////////////
// private methods
// FileListItem private methods
////////////////////////////////////////////////////////////////////////////////
int FileListItem::compare(QListViewItem *item, int column, bool ascending) const
......@@ -142,9 +262,8 @@ int FileListItem::compare(QListViewItem *item, int column, bool ascending) const
// (artist, album, track number, track name) in that order.
if(fileListItem && thisFileListItem) {
if(compare(thisFileListItem, fileListItem, column, ascending) != 0) {
if(compare(thisFileListItem, fileListItem, column, ascending) != 0)
return(compare(thisFileListItem, fileListItem, column, ascending));
}
else {
for(int i = ArtistColumn; i <= TrackNumberColumn; i++) {
if(compare(thisFileListItem, fileListItem, i, ascending) != 0)
......@@ -177,7 +296,6 @@ int FileListItem::compare(FileListItem *firstItem, FileListItem *secondItem, int
else