Commit 13505df0 authored by Michael Pyne's avatar Michael Pyne

Apply some cleanup to file loading code.

parent eb4a4d15
......@@ -1136,25 +1136,18 @@ void Playlist::createItems(const PlaylistItemList &siblings, PlaylistItem *after
void Playlist::addFiles(const QStringList &files, PlaylistItem *after)
{
if(!after)
after = static_cast<PlaylistItem *>(topLevelItem(topLevelItemCount() - 1));
m_blockDataChanged = true;
m_itemsLoading++;
setEnabled(false);
FileHandleList queue;
for(const auto &file : files) {
// some files added here will launch threads that will do cleanup (fix
// the cursor, allow data updates etc) when the last thread is done.
// Managed by m_itemsLoading going to 0 which is why we ++ above.
addUntypedFile(file, queue, true, &after);
addUntypedFile(file, after);
}
addFileHelper(queue, &after, true);
// If no items are being loaded by now then we must have loaded all M3U
// playlists or something, so cleanup immediately since no threads will
// have been launched.
......@@ -1647,25 +1640,11 @@ void Playlist::addFilesFromDirectory(const QString &dirPath)
(void) QtConcurrent::run(loader, &DirectoryLoader::startLoading);
}
/**
* Super spaghetti function that adds music files, m3u playlist files, or directories
* into the playlist as appropriate, but only if the playlist doesn't already contain
* the file.
*
* @p file is the file to add (music, playlist or directory)
* @p files is the current batch of FileHandles to add into this playlist
* (maintained by addFileHelper)
* @p after is a pointer to a PlaylistItem* which itself points to the item to
* insert after (maintained by addFileHelper)
*/
void Playlist::addUntypedFile(const QString &file, FileHandleList &files, bool importPlaylists,
PlaylistItem **after)
void Playlist::addUntypedFile(const QString &file, PlaylistItem *after)
{
if(hasItem(file) && !m_allowDuplicates)
return;
addFileHelper(files, after);
const QFileInfo fileInfo(file);
const QString canonicalPath = fileInfo.canonicalFilePath();
......@@ -1674,11 +1653,11 @@ void Playlist::addUntypedFile(const QString &file, FileHandleList &files, bool i
{
FileHandle f(fileInfo);
f.tag();
files.append(f);
createItem(f, after);
return;
}
if(importPlaylists && MediaFiles::isPlaylistFile(file)) {
if(MediaFiles::isPlaylistFile(file)) {
addPlaylistFile(canonicalPath);
return;
}
......@@ -1693,39 +1672,6 @@ void Playlist::addUntypedFile(const QString &file, FileHandleList &files, bool i
}
}
void Playlist::addFileHelper(FileHandleList &files, PlaylistItem **after, bool ignoreTimer)
{
static QTime time = QTime::currentTime();
// Process new items every 10 seconds, when we've loaded 1000 items, or when
// it's been requested in the API.
if(ignoreTimer || time.elapsed() > 10000 ||
(files.count() >= 1000 && time.elapsed() > 1000))
{
time.restart();
const bool focus = hasFocus();
const bool visible = isVisible() && files.count() > 20;
if(visible)
m_collection->raiseDistraction();
PlaylistItem *newAfter = *after;
foreach(const FileHandle &fileHandle, files)
newAfter = createItem(fileHandle, newAfter);
*after = newAfter;
files.clear();
if(visible)
m_collection->lowerDistraction();
if(focus)
setFocus();
}
}
// Called directly or after a threaded directory load has completed, managed by
// m_itemsLoading
void Playlist::cleanupAfterAllFileLoadsCompleted()
......
......@@ -189,7 +189,7 @@ public:
* items since it has the overhead of checking to see if the file is a playlist
* or directory first.
*/
virtual void addFiles(const QStringList &files, PlaylistItem *after = 0);
virtual void addFiles(const QStringList &files, PlaylistItem *after = nullptr);
/**
* Returns the file name associated with this playlist (an m3u file) or
......@@ -540,10 +540,7 @@ private:
void addPlaylistFile(const QString &m3uFile);
void addFilesFromDirectory(const QString &dirPath);
void addUntypedFile(const QString &file, FileHandleList &files, bool importPlaylists,
PlaylistItem **after);
void addFileHelper(FileHandleList &files, PlaylistItem **after,
bool ignoreTimer = false);
void addUntypedFile(const QString &file, PlaylistItem *after = nullptr);
void cleanupAfterAllFileLoadsCompleted();
void redisplaySearch() { setSearch(m_search); }
......
......@@ -673,32 +673,6 @@ void PlaylistCollection::raise(Playlist *playlist)
playlistItemsChanged();
}
void PlaylistCollection::raiseDistraction()
{
if(m_belowDistraction)
return;
m_belowDistraction = currentPlaylist();
if(!m_distraction) {
m_distraction = new QWidget(m_playlistStack);
m_playlistStack->addWidget(m_distraction);
}
m_playlistStack->setCurrentWidget(m_distraction);
}
void PlaylistCollection::lowerDistraction()
{
if(!m_distraction)
return;
if(m_belowDistraction)
m_playlistStack->setCurrentWidget(m_belowDistraction);
m_belowDistraction = 0;
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -171,14 +171,6 @@ public:
*/
QStringList excludedFolders() const { return m_excludedFolderList; }
/**
* This is used to put up a temporary widget over the top of the playlist
* stack. This is part of a trick to significantly speed up painting by
* hiding the playlist to which items are being added.
*/
void raiseDistraction();
void lowerDistraction();
class ActionHandler;
friend PlaylistCollection::ActionHandler;
......
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