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

Start up fast again. I fixed the regression and cache-integrity checking

should now be back in the event loop.  I also did a bit more checking while
I was having fun with strace and now JuK *really* doesn't stat things until
it needs them.

svn path=/trunk/kdemultimedia/juk/; revision=220573
parent d04771d3
......@@ -23,7 +23,7 @@
#include "cache.h"
#include "cachedtag.h"
Cache *Cache::cache = 0;
Cache *Cache::m_cache = 0;
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -31,11 +31,11 @@ Cache *Cache::cache = 0;
Cache *Cache::instance()
{
if(cache == 0) {
cache = new Cache();
cache->load();
if(m_cache == 0) {
m_cache = new Cache();
m_cache->load();
}
return cache;
return m_cache;
}
void Cache::save()
......@@ -64,14 +64,14 @@ void Cache::save()
// protected methods
////////////////////////////////////////////////////////////////////////////////
Cache::Cache() : QDict<Tag>(cacheSize)
Cache::Cache() : QDict<Tag>(m_cacheSize)
{
}
Cache::~Cache()
{
delete cache;
delete m_cache;
}
void Cache::load()
......
......@@ -34,12 +34,12 @@ protected:
void load();
private:
static Cache *cache;
static Cache *m_cache;
/**
* Note this number is a prime number that should be larger than the target
* size of the dict.
*/
static const int cacheSize = 5003;
static const int m_cacheSize = 5003;
};
#endif
......@@ -23,7 +23,9 @@
////////////////////////////////////////////////////////////////////////////////
CachedTag::CachedTag(const QString &file) : Tag(file),
m_externalTag(0), m_tagTrackNumber(0), m_tagYear(0), m_tagSeconds(0), m_tagExists(false)
m_externalTag(0), m_tagTrackNumber(0),
m_tagYear(0), m_tagSeconds(0),
m_tagExists(false)
{
}
......
......@@ -53,10 +53,15 @@ void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem *CollectionList::createItem(const QFileInfo &file, QListViewItem *)
PlaylistItem *CollectionList::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *)
{
QString filePath = resolveSymLinks(file);
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
if(m_itemsDict.find(filePath))
return 0;
......@@ -245,6 +250,7 @@ void CollectionListItem::addChildItem(PlaylistItem *child)
void CollectionListItem::checkCurrent()
{
kdDebug() << "CollectionListItem::checkCurrent() (mp3)" << endl;
if(!data()->exists() || !data()->isFile())
CollectionList::instance()->clearItem(this);
else if(!data()->tag()->current()) {
......
......@@ -55,7 +55,9 @@ public:
QStringList albums() const { return m_albums.values(); }
CollectionListItem *lookup(const QString &file) { return m_itemsDict.find(file); }
virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *);
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
QListViewItem * = 0);
public slots:
virtual void paste() { decode(kapp->clipboard()->data()); }
......
......@@ -570,10 +570,15 @@ void Playlist::showEvent(QShowEvent *e)
KListView::showEvent(e);
}
PlaylistItem *Playlist::createItem(const QFileInfo &file, QListViewItem *after)
PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFilePath, QListViewItem *after)
{
QString filePath = resolveSymLinks(file);
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
CollectionListItem *item = CollectionList::instance()->lookup(filePath);
if(!item) {
......@@ -662,13 +667,17 @@ 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)
{
char real[PATH_MAX];
if(file.exists() && realpath(QFile::encodeName(file.absFilePath()).data(), real))
return QFile::decodeName(real);
else
return QString::null;
return file.filePath();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -794,7 +803,7 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
if(item.exists() && item.isFile() && item.isReadable()) {
if(after)
after = createItem(item, after);
after = createItem(item, QString::null, after);
else
after = createItem(item);
}
......@@ -1004,7 +1013,7 @@ QDataStream &operator>>(QDataStream &s, Playlist &p)
for(QStringList::Iterator it = files.begin(); it != files.end(); ++it ) {
QFileInfo info(*it);
after = p.createItem(info, after);
after = p.createItem(info, *it, after);
}
return s;
......
......@@ -96,7 +96,10 @@ public:
* of PlaylistItems virtual. In this case it allows for the creation of
* both PlaylistItems and CollectionListItems.
*/
virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *after = 0);
virtual PlaylistItem *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
QListViewItem *after = 0);
void createItems(const PlaylistItemList &siblings);
QString fileName() const { return m_fileName; }
......@@ -180,6 +183,10 @@ protected:
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void showEvent(QShowEvent *e);
/**
* 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);
KPopupMenu *rmbMenu() { return m_rmbMenu; }
......
......@@ -65,13 +65,6 @@ Tag::~Tag()
Tag::Tag(const QString &file) : m_info(file), m_fileName(file)
{
Cache::instance()->insert(file, this);
// We want to stamp the file with the modified time when the tag is
// created. Otherwise the file can be modified while JuK is running and
// it will never be updated because the m_info.lastModifed() would return
// that timestamp when creating the cache.
m_lastModified = m_info.lastModified();
}
QString Tag::readBitrate(const KFileMetaInfo &metaInfo)
......
......@@ -83,7 +83,8 @@ public:
// performance critical section of JuK.
inline QString absFilePath() const { return m_fileName; }
inline QDateTime lastModified() const { return m_lastModified; }
inline QDateTime lastModified() const
{ if(m_lastModified.isNull()) m_lastModified = m_info.lastModified(); return m_lastModified; }
inline bool fileExists() const { return m_info.exists() && m_info.isFile(); }
inline QFileInfo fileInfo() const { return m_info; }
......@@ -103,7 +104,7 @@ protected:
private:
QFileInfo m_info;
QString m_fileName;
QDateTime m_lastModified;
mutable QDateTime m_lastModified;
};
QDataStream &operator<<(QDataStream &s, const Tag &t);
......
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