Commit 634e518d authored by Scott Wheeler's avatar Scott Wheeler

Modified the API for FileListItemData -- this had somewhat recusive effects

svn path=/trunk/kdemultimedia/juk/; revision=149548
parent 32198be2
...@@ -71,7 +71,7 @@ void FileList::append(FileListItem *item) ...@@ -71,7 +71,7 @@ void FileList::append(FileListItem *item)
{ {
if(item && members.contains(item->absFilePath()) == 0) { if(item && members.contains(item->absFilePath()) == 0) {
members.append(item->absFilePath()); members.append(item->absFilePath());
(void) new FileListItem(item, this); (void) new FileListItem(*item, this);
} }
} }
...@@ -84,6 +84,15 @@ void FileList::append(QPtrList<QListViewItem> *items) ...@@ -84,6 +84,15 @@ void FileList::append(QPtrList<QListViewItem> *items)
} }
} }
void FileList::remove(QPtrList<QListViewItem> *items)
{
QPtrListIterator<QListViewItem> it(*items);
while(it.current()) {
delete(it.current());
++it;
}
}
FileListItem *FileList::getSelectedItem() FileListItem *FileList::getSelectedItem()
{ {
return(dynamic_cast<FileListItem *>(currentItem())); return(dynamic_cast<FileListItem *>(currentItem()));
...@@ -117,28 +126,27 @@ void FileList::setup() ...@@ -117,28 +126,27 @@ void FileList::setup()
void FileList::appendImpl(QString item) void FileList::appendImpl(QString item)
{ {
processEvents(); processEvents();
QFileInfo *file = new QFileInfo(QDir::cleanDirPath(item)); QFileInfo file(QDir::cleanDirPath(item));
if(file->exists()) { if(file.exists()) {
if(file->isDir()) { if(file.isDir()) {
QDir dir(file->filePath()); QDir dir(file.filePath());
QStringList dirContents=dir.entryList(); QStringList dirContents=dir.entryList();
for(QStringList::Iterator it = dirContents.begin(); it != dirContents.end(); ++it) { for(QStringList::Iterator it = dirContents.begin(); it != dirContents.end(); ++it) {
if(*it != "." && *it != "..") { if(*it != "." && *it != "..") {
appendImpl(file->filePath() + QDir::separator() + *it); appendImpl(file.filePath() + QDir::separator() + *it);
} }
} }
} }
else { else {
// QFileInfo::extension() doesn't always work, so I'm getting old-school on this. -- fixed in Qt 3 // QFileInfo::extension() doesn't always work, so I'm getting old-school on this. -- fixed in Qt 3
// QString extension = file->filePath().right(file->filePath().length() - (file->filePath().findRev(".") + 1)); // QString extension = file.filePath().right(file.filePath().length() - (file.filePath().findRev(".") + 1));
QString extension = file->extension(false); QString extension = file.extension(false);
if(extensions.contains(extension) > 0 && members.contains(file->absFilePath()) == 0) { if(extensions.contains(extension) > 0 && members.contains(file.absFilePath()) == 0) {
members.append(file->absFilePath()); members.append(file.absFilePath());
(void) new FileListItem(file, this); (void) new FileListItem(file, this);
} }
} }
} }
delete(file);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -37,6 +37,8 @@ public: ...@@ -37,6 +37,8 @@ public:
void append(QStringList *items); void append(QStringList *items);
void append(FileListItem *item); void append(FileListItem *item);
void append(QPtrList<QListViewItem> *items); void append(QPtrList<QListViewItem> *items);
void remove(QPtrList<QListViewItem> *items);
FileListItem *getSelectedItem(); FileListItem *getSelectedItem();
......
...@@ -23,21 +23,19 @@ ...@@ -23,21 +23,19 @@
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : QObject(parent), KListViewItem(parent) FileListItem::FileListItem(QFileInfo &file, KListView *parent) : QObject(parent), KListViewItem(parent)
{ {
data = new FileListItemData(file); data = new FileListItemData(file);
refresh(); refresh();
} }
FileListItem::FileListItem(FileListItem *item, KListView *parent) : QObject(parent), KListViewItem(parent) FileListItem::FileListItem(FileListItem &item, KListView *parent) : QObject(parent), KListViewItem(parent)
{ {
if(item) { data = item.getData()->newUser();
data = item->getData()->newUser(); // connect(&item, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *)));
connect(item, SIGNAL(destroyed(FileListItem *)), this, SLOT(parentDestroyed(FileListItem *))); addSibling(&item);
addSibling(item);
refresh();
refresh();
}
} }
FileListItem::~FileListItem() FileListItem::~FileListItem()
......
...@@ -33,8 +33,8 @@ public: ...@@ -33,8 +33,8 @@ public:
enum ColumnType { TrackColumn = 0, ArtistColumn = 1, AlbumColumn = 2, TrackNumberColumn = 3, enum ColumnType { TrackColumn = 0, ArtistColumn = 1, AlbumColumn = 2, TrackNumberColumn = 3,
GenreColumn = 4, YearColumn = 5, LengthColumn = 6, FileNameColumn = 7 }; GenreColumn = 4, YearColumn = 5, LengthColumn = 6, FileNameColumn = 7 };
FileListItem(QFileInfo *file, KListView *parent); FileListItem(QFileInfo &file, KListView *parent);
FileListItem(FileListItem *item, KListView *parent); FileListItem(FileListItem &item, KListView *parent);
~FileListItem(); ~FileListItem();
FileListItemData *getData(); FileListItemData *getData();
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
// public methods // public methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FileListItemData::FileListItemData(QFileInfo *file) : QFileInfo(*file) FileListItemData::FileListItemData(QFileInfo &file) : QFileInfo(file)
{ {
referenceCount = 1; referenceCount = 1;
...@@ -46,8 +46,7 @@ FileListItemData *FileListItemData::newUser() ...@@ -46,8 +46,7 @@ FileListItemData *FileListItemData::newUser()
void FileListItemData::deleteUser() void FileListItemData::deleteUser()
{ {
referenceCount--; if(--referenceCount == 0)
if(referenceCount <= 0)
delete(this); delete(this);
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <qfileinfo.h> #include <qfileinfo.h>
#include <stdlib.h>
#include "tag.h" #include "tag.h"
#include "cacheitem.h" #include "cacheitem.h"
#include "audiodata.h" #include "audiodata.h"
...@@ -27,7 +29,7 @@ ...@@ -27,7 +29,7 @@
class FileListItemData : public QFileInfo class FileListItemData : public QFileInfo
{ {
public: public:
FileListItemData(QFileInfo *file); FileListItemData(QFileInfo &file);
~FileListItemData(); ~FileListItemData();
FileListItemData *newUser(); FileListItemData *newUser();
......
...@@ -58,6 +58,13 @@ void PlaylistWidget::add(QPtrList<QListViewItem> *items) ...@@ -58,6 +58,13 @@ void PlaylistWidget::add(QPtrList<QListViewItem> *items)
playlistList->append(items); playlistList->append(items);
} }
void PlaylistWidget::remove(QPtrList<QListViewItem> *items)
{
playlistList->remove(items);
}
FileList *PlaylistWidget::getPlaylistList() FileList *PlaylistWidget::getPlaylistList()
{ {
return(playlistList); return(playlistList);
......
...@@ -36,6 +36,8 @@ public: ...@@ -36,6 +36,8 @@ public:
void add(FileListItem *item); void add(FileListItem *item);
void add(QPtrList<QListViewItem> *items); void add(QPtrList<QListViewItem> *items);
void remove(QPtrList<QListViewItem> *items);
FileList *getPlaylistList(); FileList *getPlaylistList();
QPtrList<QListViewItem> *getSelectedItems(); QPtrList<QListViewItem> *getSelectedItems();
FileListItem *firstItem(); FileListItem *firstItem();
......
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