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
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;
}
void DirectoryPlaylist::next()
{
+ updateEntrylist();
+
if (entryList.isEmpty())
return;
void DirectoryPlaylist::previous()
{
+ updateEntrylist();
+
if (entryList.isEmpty())
return;
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);
+}
+
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;