Commit 8868775f authored by Scott Wheeler's avatar Scott Wheeler

More conversion of stuff over to FileHandle rather than Tag for passing

file information around.  There are a couple of temporary hacks added here
(i.e. FileHandle being a friend of Tag and accessing private member variables)
but those will go away once the cache is moved from being Tag based to FileHandle
based.

svn path=/trunk/kdemultimedia/juk/; revision=294201
parent 7a5ec339
......@@ -41,6 +41,8 @@ void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
{
m_list = new CollectionList(parent);
// TODO: don't fetch the fileInfo from the tag, but rather from the FileHandle
if(restoreOnLoad)
for(QDictIterator<Tag>it(*Cache::instance()); it.current(); ++it)
new CollectionListItem(it.current()->fileInfo(), it.current()->fileName());
......@@ -82,10 +84,10 @@ PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &a
void CollectionList::clear()
{
int result = KMessageBox::warningYesNo(this,
i18n("Removing an item from the collection will also remove it from "
"all of your playlists. Are you sure you want to continue?\n\n"
"Note, however, that if the directory that these files are in is in "
"your \"scan on startup\" list, they will be readded on startup."));
i18n("Removing an item from the collection will also remove it from "
"all of your playlists. Are you sure you want to continue?\n\n"
"Note, however, that if the directory that these files are in is in "
"your \"scan on startup\" list, they will be readded on startup."));
if(result == KMessageBox::Yes)
Playlist::clear();
......@@ -116,7 +118,7 @@ CollectionList::CollectionList(QWidget *parent) :
m_uniqueSets(m_uniqueSetCount, SortedStringList()),
m_uniqueSetLast(m_uniqueSetCount, QString::null)
{
m_dirWatch = new KDirWatch();
m_dirWatch = new KDirWatch;
connect(m_dirWatch, SIGNAL(deleted(const QString &)), this, SLOT(slotRemoveItem(const QString &)));
connect(m_dirWatch, SIGNAL(dirty(const QString &)), this, SLOT(slotRefreshItem(const QString &)));
m_dirWatch->startScan();
......@@ -239,7 +241,7 @@ bool CollectionListItem::checkCurrent()
if(!file().fileInfo().exists() || !file().fileInfo().isFile())
return false;
if(!file().tag()->current()) {
if(!file().current()) {
file().refresh();
slotRefresh();
}
......
......@@ -113,6 +113,20 @@ const QFileInfo &FileHandle::fileInfo() const
return d->fileInfo;
}
bool FileHandle::current() const
{
return(d->tag->m_modificationTime.isValid() &&
lastModified().isValid() &&
d->tag->m_modificationTime >= lastModified());
}
const QDateTime &FileHandle::lastModified() const
{
// TODO: this should be done internally once the cache is FileHandle based
return d->tag->lastModified();
}
FileHandle &FileHandle::operator=(const FileHandle &f)
{
if(&f == this)
......
......@@ -44,6 +44,9 @@ public:
QString absFilePath() const;
const QFileInfo &fileInfo() const;
bool current() const;
const QDateTime &lastModified() const;
FileHandle &operator=(const FileHandle &f);
bool operator==(const FileHandle &f) const;
......
......@@ -458,7 +458,7 @@ int Playlist::totalTime()
QListViewItemIterator it(this);
while (it.current()) {
PlaylistItem *item = static_cast<PlaylistItem *>(it.current());
if(item->file().tag()->current())
if(item->file().current())
time += item->file().tag()->seconds();
it++;
}
......
......@@ -82,9 +82,6 @@ void Tag::save()
{
TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF8);
if(!m_info.isWritable())
return;
TagLib::File *file = 0;
if(MediaFiles::isMP3(m_fileName))
......@@ -94,7 +91,7 @@ void Tag::save()
else if(MediaFiles::isFLAC(m_fileName))
file = new TagLib::FLAC::File(QFile::encodeName(m_fileName).data());
if(file && file->isValid() && file->tag()) {
if(file && file->isValid() && file->tag() && !file->readOnly()) {
file->tag()->setTitle(QStringToTString(m_title));
file->tag()->setArtist(QStringToTString(m_artist));
file->tag()->setAlbum(QStringToTString(m_album));
......@@ -112,21 +109,14 @@ void Tag::save()
delete file;
}
bool Tag::current() const
{
return(m_modificationTime.isValid() &&
lastModified().isValid() &&
m_modificationTime >= Tag::lastModified());
}
QDateTime Tag::lastModified() const
const QDateTime &Tag::lastModified() const
{
if(m_lastModified.isNull())
m_lastModified = m_info.lastModified();
return m_lastModified;
}
CacheDataStream &Tag::read(CacheDataStream &s)
{
switch(s.cacheVersion()) {
......@@ -202,7 +192,6 @@ CacheDataStream &Tag::read(CacheDataStream &s)
////////////////////////////////////////////////////////////////////////////////
Tag::Tag(const QString &file) :
m_info(file),
m_fileName(file),
m_track(0),
m_year(0),
......@@ -213,7 +202,6 @@ Tag::Tag(const QString &file) :
}
Tag::Tag(const QString &fileName, TagLib::File *file) :
m_info(fileName),
m_fileName(fileName)
{
m_title = TStringToQString(file->tag()->title()).stripWhiteSpace();
......@@ -233,8 +221,10 @@ Tag::Tag(const QString &fileName, TagLib::File *file) :
m_lengthString = QString::number(minutes) + (seconds >= 10 ? ":" : ":0") + QString::number(seconds);
if(m_title.isEmpty())
m_title = m_info.baseName(true);
if(m_title.isEmpty()) {
int i = m_fileName.findRev('.');
m_title = i > 0 ? m_fileName.left(i) : m_fileName;
}
Cache::instance()->insert(fileName, this);
}
......
......@@ -18,7 +18,6 @@
#ifndef TAG_H
#define TAG_H
#include <qfileinfo.h>
namespace TagLib { class File; }
......@@ -33,6 +32,7 @@ class CacheDataStream;
class Tag
{
friend class Cache;
friend class FileHandle;
public:
/**
* All Tag objects should be instantiated through this method. It determines
......@@ -64,25 +64,18 @@ public:
int seconds() const { return m_seconds; }
int bitrate() const { return m_bitrate; }
QString fileName() const { return m_fileName; }
QDateTime lastModified() const;
/**
* As a convenience, since producing a length string from a number of second
* isn't a one liner, provide the lenght in string form.
*/
QString lengthString() const { return m_lengthString; }
/**
* Check to see if the item is up to date.
*/
bool current() const;
bool fileExists() const { return m_info.exists() && m_info.isFile(); }
QFileInfo fileInfo() const { return m_info; }
CacheDataStream &read(CacheDataStream &s);
// TODO -- REMOVE THESE METHODS ONCE THE CACHE IS FILEHANDLE BASED
const QDateTime &lastModified() const;
const QFileInfo &fileInfo() const { return m_info; }
const QString &fileName() const { return m_fileName; }
private:
/*!
* Creates an empty tag for use in Cache restoration.
......@@ -93,7 +86,6 @@ private:
QFileInfo m_info;
QString m_fileName;
mutable QDateTime m_lastModified;
QString m_title;
QString m_artist;
QString m_album;
......@@ -104,7 +96,6 @@ private:
int m_seconds;
int m_bitrate;
QDateTime m_modificationTime;
QString m_lengthString;
};
......
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