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

I've gotten through most of the process of centralizing data in the

FileListItemData class.  More commits to come.

svn path=/trunk/kdemultimedia/juk/; revision=144639
parent 20f60098
......@@ -23,21 +23,16 @@
// public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : QObject(parent), KListViewItem(parent), QFileInfo(*file)
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : QObject(parent), KListViewItem(parent)
{
audioData = 0;
tag = new Tag(filePath());
data = new FileListItemData(file);
refresh();
}
FileListItem::FileListItem(FileListItem *item, KListView *parent) : QObject(parent), KListViewItem(parent), QFileInfo(*item)
FileListItem::FileListItem(FileListItem *item, KListView *parent) : QObject(parent), KListViewItem(parent)
{
// kdDebug() << "FileListItem(FileListItem *item, KListView *parent)" << endl;
if(item) {
tag = item->getTag();
audioData = item->getAudioData();
data = item->getData()->newUser();
connect(item, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *)));
addSibling(item);
......@@ -47,42 +42,29 @@ FileListItem::FileListItem(FileListItem *item, KListView *parent) : QObject(pare
FileListItem::~FileListItem()
{
if(tag)
delete(tag);
if(audioData)
delete(audioData);
data->deleteUser();
emit(destroyed(this));
}
Tag *FileListItem::getTag()
void FileListItem::setFile(QString file)
{
if(!tag)
tag = new Tag(filePath());
return(tag);
data->setFile(file);
refresh();
}
AudioData *FileListItem::getAudioData()
{
if(!audioData) {
audioData = new AudioData(filePath());
}
return(audioData);
FileListItemData *FileListItem::getData()
{
return(data);
}
void FileListItem::setFile(QString fileName)
{
setFile(fileName);
if(audioData) {
delete(audioData);
(void) getAudioData();
}
if(tag) {
delete(tag);
(void) getTag();
}
Tag *FileListItem::getTag()
{
return(data->getTag());
}
AudioData *FileListItem::getAudioData()
{
return(data->getAudioData());
}
void FileListItem::refresh()
......@@ -99,6 +81,14 @@ void FileListItem::refresh()
emit(refreshed());
}
// 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()); }
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -178,7 +168,6 @@ int FileListItem::compare(FileListItem *firstItem, FileListItem *secondItem, int
void FileListItem::parentDestroyed(FileListItem *parent)
{
audioData = 0;
tag = 0;
disconnect(parent, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *)));
}
......@@ -25,8 +25,9 @@
#include "tag.h"
#include "audiodata.h"
#include "filelistitemdata.h"
class FileListItem : public QObject, public KListViewItem, public QFileInfo {
class FileListItem : public QObject, public KListViewItem {
Q_OBJECT
public:
enum ColumnType { TrackColumn = 0, ArtistColumn = 1, AlbumColumn = 2, TrackNumberColumn = 3,
......@@ -36,10 +37,18 @@ public:
FileListItem(FileListItem *item, KListView *parent);
~FileListItem();
FileListItemData *getData();
Tag *getTag();
AudioData *getAudioData();
void setFile(QString fileName);
void setFile(QString file);
// QFileInfo-ish methods
QString fileName() const;
QString filePath() const;
QString absFilePath() const;
QString dirPath(bool absPath = false) const;
bool isWritable() const;
public slots:
void refresh();
......@@ -54,6 +63,7 @@ private:
int compare(QListViewItem *item, int column, bool ascending) const;
int compare(FileListItem *firstItem, FileListItem *secondItem, int column, bool ascending) const;
FileListItemData *data;
QFileInfo *fileInfo;
Tag *tag;
AudioData *audioData;
......
......@@ -17,7 +17,59 @@
#include "filelistitemdata.h"
FileListItemData::FileListItemData(){
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
FileListItemData::FileListItemData(QFileInfo *file) : QFileInfo(*file)
{
referenceCount = 1;
// initialize pointers to null
cache = 0;
tag = 0;
audioData = 0;
}
FileListItemData::~FileListItemData()
{
delete(cache);
delete(tag);
delete(audioData);
}
FileListItemData *FileListItemData::newUser()
{
referenceCount++;
return(this);
}
void FileListItemData::deleteUser()
{
referenceCount--;
if(referenceCount <= 0)
delete(this);
}
Tag *FileListItemData::getTag()
{
if(!tag)
tag = new Tag(filePath());
return(tag);
}
FileListItemData::~FileListItemData(){
AudioData *FileListItemData::getAudioData()
{
if(!audioData) {
audioData = new AudioData(filePath());
}
return(audioData);
}
void FileListItemData::setFile(QString file)
{
delete(tag);
tag = 0;
QFileInfo::setFile(file);
}
......@@ -22,16 +22,28 @@
#include "tag.h"
#include "cacheitem.h"
#include "audiodata.h"
class FileListItemData : public QFileInfo
{
public:
FileListItemData();
FileListItemData(QFileInfo *file);
~FileListItemData();
FileListItemData *newUser();
void deleteUser();
Tag *getTag();
AudioData *getAudioData();
void setFile(QString file);
private:
int referenceCount;
CacheItem *cache;
Tag *tag;
AudioData *audioData;
};
#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