aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2010-11-01 17:54:27 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2010-11-01 17:54:27 +0000
commit24af8da3f8942c200ba0058341a66a888224aa3c (patch)
treec01647eef52405ff06ed13e6d151b75cddde3834 /src/qmmpui
parent15d744d752d16aa5621c98cd2de2d6ce3f6e6f46 (diff)
downloadqmmp-24af8da3f8942c200ba0058341a66a888224aa3c.tar.gz
qmmp-24af8da3f8942c200ba0058341a66a888224aa3c.tar.bz2
qmmp-24af8da3f8942c200ba0058341a66a888224aa3c.zip
changed playlist api, prepare for shortcut editor implementation, fixed direcory scan order (Closes issue 207)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1970 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/fileloader.cpp62
-rw-r--r--src/qmmpui/fileloader.h24
-rw-r--r--src/qmmpui/playlistmanager.cpp14
-rw-r--r--src/qmmpui/playlistmanager.h12
-rw-r--r--src/qmmpui/playlistmodel.cpp160
-rw-r--r--src/qmmpui/playlistmodel.h57
6 files changed, 110 insertions, 219 deletions
diff --git a/src/qmmpui/fileloader.cpp b/src/qmmpui/fileloader.cpp
index a20560486..6c53c62a8 100644
--- a/src/qmmpui/fileloader.cpp
+++ b/src/qmmpui/fileloader.cpp
@@ -23,8 +23,7 @@
#include "playlistsettings.h"
#include "playlistitem.h"
-FileLoader::FileLoader(QObject *parent)
- : QThread(parent),m_files_to_load(),m_directory()
+FileLoader::FileLoader(QObject *parent) : QThread(parent)
{
m_filters = MetaDataManager::instance()->nameFilters();
m_finished = false;
@@ -37,18 +36,12 @@ FileLoader::~FileLoader()
}
-void FileLoader::addFiles(const QStringList &files)
+void FileLoader::addFile(const QString &path)
{
- if (files.isEmpty ())
- return;
bool use_meta = PlaylistSettings::instance()->useMetadata();
- foreach(QString s, files)
- {
- QList <FileInfo *> playList = MetaDataManager::instance()->createPlayList(s, use_meta);
- foreach(FileInfo *info, playList)
+ QList <FileInfo *> playList = MetaDataManager::instance()->createPlayList(path, use_meta);
+ foreach(FileInfo *info, playList)
emit newPlayListItem(new PlayListItem(info));
- if (m_finished) return;
- }
}
@@ -59,13 +52,9 @@ void FileLoader::addDirectory(const QString& s)
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Name);
QFileInfoList l = dir.entryInfoList(m_filters);
- bool use_meta = PlaylistSettings::instance()->useMetadata();
- for (int i = 0; i < l.size(); ++i)
+ foreach(QFileInfo info, l)
{
- QFileInfo fileInfo = l.at(i);
- playList = MetaDataManager::instance()->createPlayList(fileInfo.absoluteFilePath (), use_meta);
- foreach(FileInfo *info, playList)
- emit newPlayListItem(new PlayListItem(info));
+ addFile(info.absoluteFilePath ());
if (m_finished) return;
}
dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
@@ -83,25 +72,44 @@ void FileLoader::addDirectory(const QString& s)
void FileLoader::run()
{
- if (!m_files_to_load.isEmpty())
- addFiles(m_files_to_load);
- else if (!m_directory.isEmpty())
- addDirectory(m_directory);
+ m_finished = false;
+ while(!m_files.isEmpty() || !m_directories.isEmpty())
+ {
+ if(!m_files.isEmpty())
+ {
+ addFile(m_files.dequeue());
+ continue;
+ }
+ if(!m_directories.isEmpty())
+ {
+ addDirectory(m_directories.dequeue());
+ continue;
+ }
+ }
+}
+
+void FileLoader::loadFile(const QString &path)
+{
+ m_files.enqueue(path);
+ start(QThread::IdlePriority);
}
-void FileLoader::setFilesToLoad(const QStringList & l)
+void FileLoader::loadFiles(const QStringList &paths)
{
- m_files_to_load = l;
- m_directory = QString();
+ m_files << paths;
+ start(QThread::IdlePriority);
}
-void FileLoader::setDirectoryToLoad(const QString & d)
+void FileLoader::loadDirectory(const QString &path)
{
- m_directory = d;
- m_files_to_load.clear();
+ m_directories.enqueue(path);
+ start(QThread::IdlePriority);
}
void FileLoader::finish()
{
m_finished = true;
+ m_files.clear();
+ m_directories.clear();
+ wait();
}
diff --git a/src/qmmpui/fileloader.h b/src/qmmpui/fileloader.h
index 466606ccb..7b3ad8862 100644
--- a/src/qmmpui/fileloader.h
+++ b/src/qmmpui/fileloader.h
@@ -22,6 +22,7 @@
#include <QObject>
#include <QDir>
+#include <QQueue>
#include <QThread>
class PlayListItem;
@@ -49,17 +50,22 @@ public:
*/
~FileLoader();
/*!
- * Call this method when you want to notify the thread about finishing
+ * Sets files to load
*/
void finish();
/*!
- * Sets filelist to load( directory to load will be cleaned )
+ * Sets file to load
*/
- void setFilesToLoad(const QStringList&);
+ void loadFile(const QString &path);
/*!
- * Sets directory to load( filelist to load will be cleaned )
+ * Sets files to load
*/
- void setDirectoryToLoad(const QString&);
+ void loadFiles(const QStringList &paths);
+ /*!
+ * Sets directory to load
+ */
+ void loadDirectory(const QString &path);
+
signals:
/*!
* Emitted when new playlist item is available.
@@ -69,13 +75,13 @@ signals:
protected:
virtual void run();
- void addFiles(const QStringList &files);
- void addDirectory(const QString& s);
+ void addFile(const QString &path);
+ void addDirectory(const QString &s);
private:
QStringList m_filters;
- QStringList m_files_to_load;
- QString m_directory;
+ QQueue <QString> m_files;
+ QQueue <QString> m_directories;
bool m_finished;
};
diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp
index 1db91cde0..6960b1068 100644
--- a/src/qmmpui/playlistmanager.cpp
+++ b/src/qmmpui/playlistmanager.cpp
@@ -444,19 +444,9 @@ void PlayListManager::showDetails()
m_selected->showDetails();
}
-void PlayListManager::addFile(const QString &path)
+void PlayListManager::add(const QStringList &paths)
{
- m_selected->addFile(path);
-}
-
-void PlayListManager::addFiles(const QStringList& l)
-{
- m_selected->addFiles(l);
-}
-
-void PlayListManager::addDirectory(const QString& dir)
-{
- m_selected->addDirectory(dir);
+ m_selected->add(paths);
}
void PlayListManager::randomizeList()
diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h
index de9108055..b8559b05b 100644
--- a/src/qmmpui/playlistmanager.h
+++ b/src/qmmpui/playlistmanager.h
@@ -249,17 +249,9 @@ public slots:
*/
void showDetails();
/*!
- * This is a convenience function and is the same as calling \b selectedPlayList()->addFile(path)
+ * This is a convenience function and is the same as calling \b selectedPlayList()->add(paths)
*/
- void addFile(const QString &path);
- /*!
- * This is a convenience function and is the same as calling \b selectedPlayList()->addFiles(l)
- */
- void addFiles(const QStringList& l);
- /*!
- * This is a convenience function and is the same as calling \b selectedPlayList()->addDirectory(dir)
- */
- void addDirectory(const QString& dir);
+ void add(const QStringList &paths);
/*!
* This is a convenience function and is the same as calling \b selectedPlayList()->randomizeList()
*/
diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp
index a710073b4..541fd3f26 100644
--- a/src/qmmpui/playlistmodel.cpp
+++ b/src/qmmpui/playlistmodel.cpp
@@ -73,22 +73,20 @@ PlayListModel::PlayListModel(const QString &name, QObject *parent)
m_total_length = 0;
m_current = 0;
is_repeatable_list = false;
- m_play_state = new NormalPlayState(this);
m_stop_item = 0;
+ m_play_state = new NormalPlayState(this);
+ m_loader = new FileLoader(this);
+ connect(m_loader, SIGNAL(newPlayListItem(PlayListItem*)),
+ SLOT(add(PlayListItem*)), Qt::QueuedConnection);
+ connect(m_loader, SIGNAL(finished()), SLOT(preparePlayState()));
+ connect(m_loader, SIGNAL(finished()), SIGNAL(loaderFinished()));
}
PlayListModel::~PlayListModel()
{
clear();
delete m_play_state;
- foreach(GuardedFileLoader l,m_running_loaders)
- {
- if (!l.isNull())
- {
- l->finish();
- l->wait();
- }
- }
+ m_loader->finish();
}
QString PlayListModel::name() const
@@ -115,7 +113,7 @@ void PlayListModel::add(PlayListItem *item)
m_current = m_items.indexOf(m_currentItem);
if (m_items.size() == 1)
- emit firstAdded();
+ emit firstAdded();
emit listChanged();
}
@@ -136,6 +134,29 @@ void PlayListModel::add(QList <PlayListItem *> items)
emit listChanged();
}
+void PlayListModel::add(const QString &path)
+{
+ QFileInfo f_info(path);
+ //if (f_info.exists() || path.contains("://"))
+ {
+ if (f_info.isDir())
+ m_loader->loadDirectory(path);
+ else
+ {
+ m_loader->loadFile(path);
+ loadPlaylist(path);
+ }
+ }
+}
+
+void PlayListModel::add(const QStringList &paths)
+{
+ foreach(QString str, paths)
+ {
+ add(str);
+ }
+}
+
int PlayListModel::count()
{
return m_items.size();
@@ -147,7 +168,7 @@ PlayListItem* PlayListModel::currentItem()
}
PlayListItem* PlayListModel::nextItem()
-{
+{
if(m_items.isEmpty() || !m_play_state)
return 0;
if(m_stop_item && m_stop_item == currentItem())
@@ -195,31 +216,21 @@ bool PlayListModel::next()
return true;
}
- if (isFileLoaderRunning())
+ if(m_loader->isRunning())
m_play_state->prepare();
return m_play_state->next();
}
bool PlayListModel::previous()
{
- if (isFileLoaderRunning())
+ if (m_loader->isRunning())
m_play_state->prepare();
return m_play_state->previous();
}
void PlayListModel::clear()
{
- foreach(GuardedFileLoader l,m_running_loaders)
- {
- if (!l.isNull())
- {
- l->finish();
- l->wait();
- }
- }
-
- m_running_loaders.clear();
-
+ m_loader->finish();
m_current = 0;
m_stop_item = 0;
while (!m_items.isEmpty())
@@ -407,13 +418,13 @@ void PlayListModel::selectAll()
emit listChanged();
}
-void PlayListModel::showDetails()
+void PlayListModel::showDetails(QWidget *parent)
{
for (int i = 0; i<m_items.size(); ++i)
{
if (m_items.at(i)->isSelected())
{
- QDialog *d = new DetailsDialog(m_items.at(i)); //TODO set parent widget
+ QDialog *d = new DetailsDialog(m_items.at(i), parent);
TagUpdater *updater = new TagUpdater(d, m_items.at(i));
m_editing_items.append(m_items.at(i));
connect(updater, SIGNAL(destroyed(QObject *)),SIGNAL(listChanged()));
@@ -423,92 +434,6 @@ void PlayListModel::showDetails()
}
}
-void PlayListModel::addFile(const QString& path)
-{
- if (path.isEmpty())
- return;
- QList <FileInfo *> playList =
- MetaDataManager::instance()->createPlayList(path, PlaylistSettings::instance()->useMetadata());
- foreach(FileInfo *info, playList)
- add(new PlayListItem(info));
-
- m_play_state->prepare();
-}
-
-FileLoader * PlayListModel::createFileLoader()
-{
- FileLoader* f_loader = new FileLoader(this);
-// f_loader->setStackSize(20 * 1024 * 1024);
- m_running_loaders << f_loader;
- connect(f_loader,SIGNAL(newPlayListItem(PlayListItem*)),SLOT(add(PlayListItem*)),Qt::QueuedConnection);
- connect(f_loader,SIGNAL(finished()),this,SLOT(preparePlayState()));
- connect(f_loader,SIGNAL(finished()),f_loader,SLOT(deleteLater()));
- return f_loader;
-}
-
-void PlayListModel::addFiles(const QStringList &files)
-{
- FileLoader* f_loader = createFileLoader();
- f_loader->setFilesToLoad(files);
- f_loader->start(QThread::IdlePriority);
-}
-
-void PlayListModel::addDirectory(const QString& s)
-{
- FileLoader* f_loader = createFileLoader();
- f_loader->setDirectoryToLoad(s);
- f_loader->start(QThread::IdlePriority);
-}
-
-void PlayListModel::addFileList(const QStringList &l)
-{
-// qWarning("void// PlayListModel::addFileList(const QStringList &l)");
- foreach(QString str,l)
- {
- QFileInfo f_info(str);
- if (f_info.exists() || str.contains("://"))
- {
- if (f_info.isDir())
- addDirectory(str);
- else
- {
- addFile(str);
- loadPlaylist(str);
- }
- }
- // Do processing the rest of events to avoid GUI freezing
- QApplication::processEvents(QEventLoop::AllEvents,10);
- }
-}
-
-bool PlayListModel::setFileList(const QStringList & l)
-{
- bool model_cleared = false;
- foreach(QString str,l)
- {
- QFileInfo f_info(str);
- if (f_info.exists() || str.contains("://"))
- {
- if (!model_cleared)
- {
- clear();
- model_cleared = true;
- }
- if (f_info.isDir())
- addDirectory(str);
- else
- {
- addFile(str);
- loadPlaylist(str);
- }
- }
- // Do processing the rest of events to avoid GUI freezing
- QApplication::processEvents(QEventLoop::AllEvents,10);
- }
-
- return model_cleared;
-}
-
int PlayListModel::firstSelectedUpper(int row)
{
for (int i = row - 1;i >= 0;i--)
@@ -895,7 +820,7 @@ void PlayListModel::loadPlaylist(const QString &f_name)
if (QFileInfo(list.at(i)).isRelative() && !list.at(i).contains("://"))
QString path = list[i].prepend(QFileInfo(f_name).canonicalPath () + QDir::separator ());
}
- addFiles(list);
+ m_loader->loadFiles(list);
file.close();
}
else
@@ -933,15 +858,6 @@ bool PlayListModel::isShuffle() const
return m_shuffle;
}
-bool PlayListModel::isFileLoaderRunning() const
-{
- foreach(FileLoader* l,m_running_loaders)
- if (l && l->isRunning())
- return true;
-
- return false;
-}
-
void PlayListModel::preparePlayState()
{
m_play_state->prepare();
diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h
index ac5668ffa..b44270758 100644
--- a/src/qmmpui/playlistmodel.h
+++ b/src/qmmpui/playlistmodel.h
@@ -298,6 +298,10 @@ signals:
* @param name New playlist name.
*/
void nameChanged(const QString& name);
+ /*!
+ * Emitted when playlist loader thread has finished.
+ */
+ void loaderFinished();
public slots:
/*!
@@ -306,10 +310,20 @@ public slots:
void add(PlayListItem *item);
/*!
* Adds a list of items to the playlist.
- * @param items List of items
+ * @param items List of items.
*/
void add(QList <PlayListItem *> items);
/*!
+ * Adds a list of files and directories to the playlist
+ * @param path Full path of file or directory.
+ */
+ void add(const QString &path);
+ /*!
+ * Adds a list of files and directories to the playlist
+ * @param paths Full paths of files and directories.
+ */
+ void add(const QStringList &paths);
+ /*!
* Removes all items.
*/
void clear();
@@ -343,35 +357,14 @@ public slots:
void selectAll();
/*!
* Shows details for the first selected item.
+ * @param parent parent Widget.
*/
- void showDetails();
+ void showDetails(QWidget *parent = 0);
/*!
* Emits update signals manually.
*/
void doCurrentVisibleRequest();
/*!
- * Adds file \b path to the playlist. File should be supported.
- */
- void addFile(const QString &path);
- /*!
- * Adds the list \b l of files to the model.
- */
- void addFiles(const QStringList& l);
- /*!
- * Adds \b dir to the model.
- */
- void addDirectory(const QString& dir);
- /*!
- * Removes previous items and loads list of files (regular files or directories),
- * returns \b true if at least one file has been successfully loaded,
- * otherwise returns \b false
- */
- bool setFileList(const QStringList &l);
- /*!
- * Loads list of files (regular files or directories)
- */
- void addFileList(const QStringList &l);
- /*!
* Randomly changes items order.
*/
void randomizeList();
@@ -434,14 +427,6 @@ private:
*/
int bottommostInSelection(int);
/*!
- * Creates and initializes file loader object.
- */
- FileLoader* createFileLoader();
- /*!
- * Is someone of file loaders is running?
- */
- bool isFileLoaderRunning()const;
- /*!
* Removes items from model. If \b inverted is \b false -
* selected items will be removed, else - unselected.
*/
@@ -473,13 +458,7 @@ private:
*/
PlayState* m_play_state;
int m_total_length;
- typedef QPointer<FileLoader> GuardedFileLoader;
- /*!
- * Vector of currently running file loaders.
- * All loaders are automatically sheduled for deletion
- * when finished.
- */
- QVector<GuardedFileLoader> m_running_loaders;
+ FileLoader *m_loader;
bool m_shuffle;
QString m_name;
};