From: APTX Date: Sat, 25 Jul 2009 18:20:42 +0000 (+0200) Subject: - DirectoryPlaylist updates it's playlist on every next()/prev() call in case new... X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=168c4abd33f8e75c90b6e5da6f7446d627b10802;p=aniplayer-old.git - DirectoryPlaylist updates it's playlist on every next()/prev() call in case new files appear or existing files are removed. - Cleanup --- diff --git a/src/abstractplaylist.h b/src/abstractplaylist.h index 4736be4..94f53a1 100644 --- a/src/abstractplaylist.h +++ b/src/abstractplaylist.h @@ -21,8 +21,8 @@ public slots: virtual void setCurrent(int index) = 0; signals: - virtual void currentChanged(int index) = 0; - virtual void currentChanged(const QString &newCurrent) = 0; + void currentChanged(int index); + void currentChanged(const QString &newCurrent); }; #endif // ABSTRACTPLAYLIST_H diff --git a/src/directoryplaylist.cpp b/src/directoryplaylist.cpp index a5d8c8e..4fc3612 100644 --- a/src/directoryplaylist.cpp +++ b/src/directoryplaylist.cpp @@ -24,24 +24,14 @@ void DirectoryPlaylist::setDirectory(QDir directory) m_directory = directory; - entryList = m_directory.entryInfoList( - QStringList() - << "*.mkv" - << "*.mp4" - << "*.ogg" - << "*.ogm" - << "*.wmv" - << "*.avi", - QDir::Files | QDir::Readable, - QDir::Name); + updateEntrylist(); + m_currentIndex = 0; } int DirectoryPlaylist::indexOfFile(const QString &file) const { -qDebug() << file; int tmp = entryList.indexOf(file); -qDebug() << "indexOfFile" << tmp; return tmp; } @@ -62,6 +52,8 @@ int DirectoryPlaylist::currentIndex() const void DirectoryPlaylist::next() { + updateEntrylist(); + if (entryList.isEmpty()) return; @@ -75,6 +67,8 @@ void DirectoryPlaylist::next() void DirectoryPlaylist::previous() { + updateEntrylist(); + if (entryList.isEmpty()) return; @@ -99,3 +93,28 @@ void DirectoryPlaylist::setCurrent(int index) emit currentChanged(m_currentIndex); emit currentChanged(entryList[m_currentIndex].absoluteFilePath()); } + +void DirectoryPlaylist::updateEntrylist() +{ + QFileInfo previousItem; + + if (m_currentIndex != -1) + previousItem = entryList[m_currentIndex]; + + entryList = m_directory.entryInfoList( + QStringList() + << "*.mkv" + << "*.mp4" + << "*.ogg" + << "*.ogm" + << "*.wmv" + << "*.avi", + QDir::Files | QDir::Readable, + QDir::Name); + + if (m_currentIndex == -1) + return; + + m_currentIndex = entryList.indexOf(previousItem); +} + diff --git a/src/directoryplaylist.h b/src/directoryplaylist.h index d7b1e28..e0486d5 100644 --- a/src/directoryplaylist.h +++ b/src/directoryplaylist.h @@ -20,20 +20,18 @@ public: int indexOfFile(const QString &file) const; - virtual bool isEmpty() const; - virtual int count() const; - virtual int currentIndex() const; + bool isEmpty() const; + int count() const; + int currentIndex() const; public slots: - virtual void next(); - virtual void previous(); - virtual void setCurrent(int index); - -signals: - virtual void currentChanged(int index); - virtual void currentChanged(const QString &newCurrent); + void next(); + void previous(); + void setCurrent(int index); private: + void updateEntrylist(); + QDir m_directory; QFileInfoList entryList;