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

*) Ported Playlist::createItem() over to using FileHandle.

*) Removed an extra copy of the path in CollectionListItem
*) Avoid two calls to PlaylistItem::refresh() on creating CollectionListItems
*) Moved resolveSymLinks() from being a static public of Playlist to being
   a helper function in FileHandle.

svn path=/trunk/kdemultimedia/juk/; revision=303018
parent b518eb5d
......@@ -49,7 +49,7 @@ void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
it != Cache::instance()->end();
++it)
{
new CollectionListItem((*it).fileInfo(), (*it).absFilePath());
new CollectionListItem(*it);
}
}
}
......@@ -58,22 +58,16 @@ void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *, bool)
PlaylistItem *CollectionList::createItem(const FileHandle &file, QListViewItem *, bool)
{
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
if(m_itemsDict.find(filePath))
if(m_itemsDict.find(file.absFilePath()))
return 0;
PlaylistItem *item = new CollectionListItem(file, filePath);
PlaylistItem *item = new CollectionListItem(file);
if(!item->isValid()) {
kdError() << "CollectinList::createItem() -- A valid tag was not created for \"" << file.filePath() << "\"" << endl;
kdError() << "CollectinList::createItem() -- A valid tag was not created for \""
<< file.absFilePath() << "\"" << endl;
delete item;
return 0;
}
......@@ -225,18 +219,17 @@ void CollectionListItem::refresh()
// CollectionListItem protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionListItem::CollectionListItem(const QFileInfo &info, const QString &path) :
CollectionListItem::CollectionListItem(const FileHandle &file) :
PlaylistItem(CollectionList::instance()),
m_shuttingDown(false),
m_path(path)
m_shuttingDown(false)
{
CollectionList *l = CollectionList::instance();
if(l) {
l->addToDict(m_path, this);
l->addToDict(file.absFilePath(), this);
setFile(FileHandle(info, path));
data()->fileHandle = file;
if(file().tag()) {
if(file.tag()) {
refresh();
l->emitCountChanged();
// l->addWatched(m_path);
......@@ -263,11 +256,8 @@ CollectionListItem::~CollectionListItem()
}
CollectionList *l = CollectionList::instance();
if(l) {
QString path = Playlist::resolveSymLinks(file().absFilePath());
// l->removeWatched(m_path);
l->removeFromDict(m_path);
}
if(l)
l->removeFromDict(file().absFilePath());
}
void CollectionListItem::addChildItem(PlaylistItem *child)
......
......@@ -70,8 +70,8 @@ public:
QStringList viewModeItems(UniqueSetType t) const { return m_viewModeItems[t].values(); }
CollectionListItem *lookup(const QString &file) { return m_itemsDict.find(file); }
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
virtual PlaylistItem *createItem(const FileHandle &file,
QListViewItem * = 0,
bool = false);
......@@ -147,7 +147,7 @@ public:
virtual void refresh();
protected:
CollectionListItem(const QFileInfo &file, const QString &path);
CollectionListItem(const FileHandle &file);
virtual ~CollectionListItem();
void addChildItem(PlaylistItem *child);
......@@ -163,7 +163,6 @@ protected:
private:
bool m_shuttingDown;
QString m_path;
PlaylistItemList m_children;
};
......
......@@ -15,6 +15,9 @@
* *
***************************************************************************/
#include <limits.h>
#include <stdlib.h>
#include <kdebug.h>
#include <qfileinfo.h>
......@@ -23,6 +26,17 @@
#include "tag.h"
#include "cache.h"
static QString resolveSymLinks(const QFileInfo &file) // static
{
char real[PATH_MAX];
if(file.exists() && realpath(QFile::encodeName(file.absFilePath()).data(), real))
return QFile::decodeName(real);
else
return file.filePath();
}
/**
* A simple reference counter -- pasted from TagLib.
*/
......@@ -114,7 +128,7 @@ Tag *FileHandle::tag() const
QString FileHandle::absFilePath() const
{
if(d->absFilePath.isNull())
d->absFilePath = d->fileInfo.absFilePath();
d->absFilePath = resolveSymLinks(d->fileInfo.absFilePath());
return d->absFilePath;
}
......
......@@ -114,7 +114,7 @@ QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p)
s >> fileName;
s >> dateTime;
after = p.createItem<HistoryPlaylistItem, CollectionListItem, CollectionList>(QFileInfo(fileName), fileName, after, false);
after = p.createItem<HistoryPlaylistItem, CollectionListItem, CollectionList>(FileHandle(fileName), after, false);
after->setDateTime(dateTime);
}
......
......@@ -32,8 +32,6 @@
#include <id3v1genres.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <math.h>
......@@ -779,10 +777,10 @@ void Playlist::addColumn(const QString &label)
KListView::addColumn(label, 30);
}
PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFilePath,
PlaylistItem *Playlist::createItem(const FileHandle &file,
QListViewItem *after, bool emitChanged)
{
return createItem<PlaylistItem, CollectionListItem, CollectionList>(file, absFilePath, after, emitChanged);
return createItem<PlaylistItem, CollectionListItem, CollectionList>(file, after, emitChanged);
}
void Playlist::createItems(const PlaylistItemList &siblings)
......@@ -853,18 +851,6 @@ bool Playlist::isColumnVisible(int c) const
return columnWidth(c) != 0;
}
// Though it's somewhat obvious, this function will stat the file, so only use it when
// you're out of a performance critical loop.
QString Playlist::resolveSymLinks(const QFileInfo &file) // static
{
char real[PATH_MAX];
if(file.exists() && realpath(QFile::encodeName(file.absFilePath()).data(), real))
return QFile::decodeName(real);
else
return file.filePath();
}
void Playlist::polish()
{
KListView::polish();
......@@ -986,9 +972,9 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
MediaFiles::isMediaFile(item.fileName()))
{
if(after)
after = createItem(item, QString::null, after, false);
after = createItem(FileHandle(item, item.absFilePath()), after, false);
else
after = createItem(item, QString::null, 0, false);
after = createItem(FileHandle(item, item.absFilePath()), 0, false);
}
}
......@@ -1462,10 +1448,8 @@ QDataStream &operator>>(QDataStream &s, Playlist &p)
p.setColumnWidthUpdatesDisabled(true);
for(QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
QFileInfo info(*it);
after = p.createItem(info, *it, after, false);
}
for(QStringList::Iterator it = files.begin(); it != files.end(); ++it )
after = p.createItem(FileHandle(*it), after, false);
p.emitCountChanged();
p.setColumnWidthUpdatesDisabled(false);
......
......@@ -131,8 +131,7 @@ public:
* of PlaylistItems virtual. In this case it allows for the creation of
* both PlaylistItems and CollectionListItems.
*/
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
virtual PlaylistItem *createItem(const FileHandle &file,
QListViewItem *after = 0,
bool emitChanged = true);
......@@ -144,8 +143,7 @@ public:
* be the same.
*/
template <class ItemType, class CollectionItemType, class CollectionListType>
ItemType *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
ItemType *createItem(const FileHandle &file,
QListViewItem *after = 0,
bool emitChanged = true);
......@@ -408,12 +406,6 @@ protected:
template <class CollectionItemType, class ItemType, class SiblingType>
void createItems(const QValueList<SiblingType *> &siblings);
/**
* Though it's somewhat obvious, this function will stat the file, so only use it when
* you're out of a performance critical loop.
*/
static QString resolveSymLinks(const QFileInfo &file);
signals:
/**
* This is emitted when the playlist selection is changed. This is used
......@@ -646,38 +638,27 @@ QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations
template <class ItemType, class CollectionItemType, class CollectionListType>
ItemType *Playlist::createItem(const QFileInfo &file, const QString &absFilePath,
QListViewItem *after, bool emitChanged)
ItemType *Playlist::createItem(const FileHandle &file, QListViewItem *after,
bool emitChanged)
{
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
CollectionItemType *item = CollectionListType::instance()->lookup(filePath);
CollectionItemType *item = CollectionListType::instance()->lookup(file.absFilePath());
if(!item) {
item = new CollectionItemType(file, filePath);
item = new CollectionItemType(file);
setupItem(item);
// If a valid tag was not created, destroy the CollectionListItem.
if(!item->isValid()) {
kdError(65432) << "Playlist::createItem() -- A valid tag was not created for \""
<< file.filePath() << "\"" << endl;
<< file.absFilePath() << "\"" << endl;
delete item;
return 0;
}
}
if(item && !m_members.insert(filePath) || m_allowDuplicates) {
ItemType *i;
if(after)
i = new ItemType(item, this, after);
else
i = new ItemType(item, this);
if(item && !m_members.insert(file.absFilePath()) || m_allowDuplicates) {
ItemType *i = after ? new ItemType(item, this, after) : new ItemType(item, this);
setupItem(i);
if(!m_randomList.isEmpty() && !m_visibleChanged)
......@@ -705,7 +686,7 @@ void Playlist::createItems(const QValueList<SiblingType *> &siblings)
QValueListConstIterator<SiblingType *> it = siblings.begin();
for(; it != siblings.end(); ++it) {
if(!m_members.insert(resolveSymLinks((*it)->file().absFilePath())) || m_allowDuplicates) {
if(!m_members.insert((*it)->file().absFilePath()) || m_allowDuplicates) {
newItem = new ItemType((*it)->collectionItem(), this, newItem);
setupItem(newItem);
if(!m_randomList.isEmpty() && !m_visibleChanged)
......
......@@ -626,7 +626,7 @@ PlaylistItem *PlaylistSplitter::addImpl(const QString &file, Playlist *list, Pla
if(fileInfo.isFile() && fileInfo.isReadable()) {
if(MediaFiles::isMediaFile(file))
return list->createItem(fileInfo, QString::null, after, false);
return list->createItem(FileHandle(fileInfo, fileInfo.absFilePath()), after, false);
if(m_importPlaylists && MediaFiles::isPlaylistFile(file)) {
openPlaylist(fileInfo.absFilePath());
......
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