Commit 3bca3e32 authored by Michael Pyne's avatar Michael Pyne

Remove FileHandle::null concept and manual memory mgmt.

On second thought the whole FileHandle::null thing seems silly now.  It
made sense as an optimization when it was introduced but the extra
conceptual baggage is hard to maintain and far less important now.
parent 192fc005
......@@ -325,12 +325,12 @@ FileHandle Cache::loadNextCachedItem()
{
if(!m_loadFile.isOpen() || !m_loadDataStream.device()) {
qCWarning(JUK_LOG) << "Already completed reading cache file.";
return FileHandle::null();
return FileHandle();
}
if(m_loadDataStream.status() == QDataStream::ReadCorruptData) {
qCCritical(JUK_LOG) << "Attempted to read file handle from corrupt cache file.";
return FileHandle::null();
return FileHandle();
}
if(!m_loadDataStream.atEnd()) {
......@@ -344,7 +344,7 @@ FileHandle Cache::loadNextCachedItem()
m_loadDataStream.setDevice(0);
m_loadFile.close();
return FileHandle::null();
return FileHandle();
}
}
......
......@@ -19,6 +19,7 @@
#include <QFileInfo>
#include <QSharedData>
#include <QScopedPointer>
#include "filehandleproperties.h"
#include "tag.h"
......@@ -51,14 +52,8 @@ public:
baseModificationTime = fileInfo.lastModified();
}
~FileHandlePrivate()
{
delete tag;
delete coverInfo;
}
mutable Tag *tag;
mutable CoverInfo *coverInfo;
mutable QScopedPointer<Tag> tag;
mutable QScopedPointer<CoverInfo> coverInfo;
QFileInfo fileInfo;
QString absFilePath;
QDateTime baseModificationTime;
......@@ -69,23 +64,19 @@ public:
// public methods
////////////////////////////////////////////////////////////////////////////////
FileHandle::FileHandle()
: d(new FileHandlePrivate(QFileInfo()))
{
}
FileHandle::FileHandle(const FileHandle &f) :
d(f.d)
{
if(!d)
qCDebug(JUK_LOG) << "The source FileHandle was not initialized.";
}
FileHandle::FileHandle(const QFileInfo &info) :
d(new FileHandlePrivate(info))
{
if(!info.exists())
qCWarning(JUK_LOG) << "File" << info.filePath() << "no longer exists!";
}
FileHandle::FileHandle()
: FileHandle(QFileInfo()) // delegating ctor
{
}
FileHandle::FileHandle(const QString &path)
......@@ -105,8 +96,7 @@ FileHandle::~FileHandle() = default;
void FileHandle::refresh()
{
d->fileInfo.refresh();
delete d->tag;
d->tag = new Tag(d->absFilePath);
d->tag.reset(new Tag(d->absFilePath));
}
void FileHandle::setFile(const QString &path)
......@@ -127,17 +117,17 @@ void FileHandle::setFile(const QString &path)
Tag *FileHandle::tag() const
{
if(Q_UNLIKELY(!d->tag))
d->tag = new Tag(d->absFilePath);
d->tag.reset(new Tag(d->absFilePath));
return d->tag;
return d->tag.data();
}
CoverInfo *FileHandle::coverInfo() const
{
if(Q_UNLIKELY(!d->coverInfo))
d->coverInfo = new CoverInfo(*this);
d->coverInfo.reset(new CoverInfo(*this));
return d->coverInfo;
return d->coverInfo.data();
}
QString FileHandle::absFilePath() const
......@@ -152,7 +142,7 @@ const QFileInfo &FileHandle::fileInfo() const
bool FileHandle::isNull() const
{
return (*this == null() || d->absFilePath.isEmpty());
return d->absFilePath.isEmpty();
}
bool FileHandle::current() const
......@@ -176,7 +166,7 @@ void FileHandle::read(CacheDataStream &s)
case 1:
default:
if(!d->tag)
d->tag = new Tag(d->absFilePath, true);
d->tag.reset(new Tag(d->absFilePath, true));
s >> *(d->tag);
s >> d->baseModificationTime;
......@@ -212,12 +202,6 @@ QString FileHandle::property(const QString &name) const
return FileHandleProperties::property(*this, name.toUtf8());
}
const FileHandle &FileHandle::null() // static
{
static FileHandle f;
return f;
}
////////////////////////////////////////////////////////////////////////////////
// related functions
////////////////////////////////////////////////////////////////////////////////
......
......@@ -73,8 +73,6 @@ public:
static QStringList properties();
QString property(const QString &name) const;
static const FileHandle &null();
private:
class FileHandlePrivate;
QExplicitlySharedDataPointer<FileHandlePrivate> d;
......
......@@ -77,7 +77,7 @@ void HistoryPlaylist::appendProposedItem(const FileHandle &file)
void HistoryPlaylist::slotCreateNewItem()
{
createItem(m_file);
m_file = FileHandle::null();
m_file = FileHandle();
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -252,7 +252,7 @@ void PlayerManager::play(const QString &file)
void PlayerManager::play()
{
play(FileHandle::null());
play(FileHandle());
}
void PlayerManager::pause()
......@@ -284,7 +284,7 @@ void PlayerManager::stop()
m_media->stop();
if(!m_file.isNull()) {
m_file = FileHandle::null();
m_file = FileHandle();
emit signalItemChanged(m_file);
}
}
......
......@@ -395,7 +395,7 @@ QString Playlist::name() const
FileHandle Playlist::currentFile() const
{
return playingItem() ? playingItem()->file() : FileHandle::null();
return playingItem() ? playingItem()->file() : FileHandle();
}
int Playlist::time() const
......
......@@ -255,7 +255,7 @@ void Scrobbler::nowPlaying(const FileHandle& file)
sign(params);
post(params);
m_file = file; // May be FileHandle::null()
m_file = file; // May be empty FileHandle
m_playbackTimer = QDateTime::currentDateTime();
}
......
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