]> Some of my projects - aniplayer-old.git/commitdiff
- DirectoryPlaylist updates it's playlist on every next()/prev() call in case new...
authorAPTX <APTX@.(none)>
Sat, 25 Jul 2009 18:20:42 +0000 (20:20 +0200)
committerAPTX <APTX@.(none)>
Sat, 25 Jul 2009 18:20:42 +0000 (20:20 +0200)
- Cleanup

src/abstractplaylist.h
src/directoryplaylist.cpp
src/directoryplaylist.h

index 4736be4b70d25ab8e7a047ecb4a36c85c6071b0f..94f53a1f88894f57a99af52f2b753e3c8adffb04 100644 (file)
@@ -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
index a5d8c8ee8fa4c713d9a25d42b8fe304761849eca..4fc361276b6b82f08e15c4b4ae4ad7a61f0a0106 100644 (file)
@@ -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);
+}
+
index d7b1e282de48cf834c39ee8efc812b9b2c7af68d..e0486d5e6f771c94bc70433d3fc4b8900310e04c 100644 (file)
@@ -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;