]> Some of my projects - aniplayer-old.git/commitdiff
- Make DirectoryPlaylist work
authorunknown <Marek@.(none)>
Sat, 28 Mar 2009 13:47:42 +0000 (14:47 +0100)
committerunknown <Marek@.(none)>
Sat, 28 Mar 2009 13:47:42 +0000 (14:47 +0100)
src/directoryplaylist.cpp
src/directoryplaylist.h
src/videowindow.cpp

index 450da39d5ec758c4c82c908167bab8d01a14471e..ce69fc5897767555a913ec1f83289ada5c4c8984 100644 (file)
@@ -1,5 +1,7 @@
 #include "directoryplaylist.h"
 
+#include <QDebug>
+
 DirectoryPlaylist::DirectoryPlaylist(QObject *parent)
        : AbstractPlaylist(parent), m_currentIndex(-1)
 {
@@ -17,25 +19,30 @@ DirectoryPlaylist::~DirectoryPlaylist()
 
 void DirectoryPlaylist::setDirectory(QDir directory)
 {
+       if (m_directory == directory)
+               return;
+
        m_directory = directory;
-       m_currentIndex = 2;
-       emit currentChanged(m_currentIndex - 2);
-       emit currentChanged(m_directory[m_currentIndex]);
+       entryList = m_directory.entryInfoList(QDir::Files | QDir::Readable, QDir::Name);
+       m_currentIndex = 0;
 }
 
 int DirectoryPlaylist::indexOfFile(const QString &file) const
 {
-       return m_directory.entryList().indexOf(file);
+qDebug() << file;
+       int tmp = entryList.indexOf(file);
+qDebug() << "indexOfFile" << tmp;
+       return tmp;
 }
 
 bool DirectoryPlaylist::isEmpty() const
 {
-       return m_directory.count() == 2;
+       return entryList.count();
 }
 
 int DirectoryPlaylist::count() const
 {
-       return m_directory.count() - 2;
+       return m_directory.count();
 }
 
 int DirectoryPlaylist::currentIndex() const
@@ -47,20 +54,20 @@ void DirectoryPlaylist::next()
 {
        ++m_currentIndex;
        if (m_currentIndex == count())
-               m_currentIndex = 2;
+               m_currentIndex = 0;
 
-       emit currentChanged(m_currentIndex - 2);
-       emit currentChanged(m_directory[m_currentIndex]);
+       emit currentChanged(m_currentIndex);
+       emit currentChanged(entryList[m_currentIndex].absoluteFilePath());
 }
 
 void DirectoryPlaylist::previous()
 {
        --m_currentIndex;
        if (m_currentIndex == 1)
-               m_currentIndex = m_directory.count() - 1;
+               m_currentIndex = entryList.count() - 1;
 
-       emit currentChanged(m_currentIndex - 2);
-       emit currentChanged(m_directory[m_currentIndex]);
+       emit currentChanged(m_currentIndex);
+       emit currentChanged(entryList[m_currentIndex].absoluteFilePath());
 }
 
 void DirectoryPlaylist::setCurrent(int index)
@@ -68,11 +75,11 @@ void DirectoryPlaylist::setCurrent(int index)
        if (index == m_currentIndex)
                return;
 
-       if (index < 0 || index > count() - 2)
+       if (index < 0 || index > count() - 1)
                return;
 
-       m_currentIndex = index + 2;
+       m_currentIndex = index;
 
-       emit currentChanged(m_currentIndex - 2);
-       emit currentChanged(m_directory[m_currentIndex]);
+       emit currentChanged(m_currentIndex);
+       emit currentChanged(entryList[m_currentIndex].absoluteFilePath());
 }
index aa501e1c8a58a16d55ace9639e3c4dbc58d2600b..d7b1e282de48cf834c39ee8efc812b9b2c7af68d 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "abstractplaylist.h"
 #include <QDir>
+#include <QFileInfo>
 
 class DirectoryPlaylist : public AbstractPlaylist
 {
@@ -34,6 +35,8 @@ signals:
 
 private:
        QDir m_directory;
+       QFileInfoList entryList;
+
        int m_currentIndex;
 };
 
index fa85c1e76e9b47bc3d56ebd49df87a0045db0293..377ef654afd5744cec7d073b2e3f7b7554f53ea0 100644 (file)
@@ -84,8 +84,8 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
        addAction("play", "Play", QKeySequence("P"));
        addAction("pause", "Pause", QKeySequence("W"));
        addAction("stop", "Stop", QKeySequence("X"));
-//     addAction("next", "Next", QKeySequence("."));
-//     addAction("previous", "Previous", QKeySequence(","));
+       addAction("next", "Next", QKeySequence("CTRL+."));
+       addAction("previous", "Previous", QKeySequence("CTRL+,"));
 #ifndef BROWSERPLUGIN_BUILD
        addAction("togglePinMenu", "Pin Menu", QKeySequence(), true);
        addAction("toggleStayOnTop", "Stay on top", QKeySequence("T"), true);
@@ -138,9 +138,9 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
        connect(videoWidget, SIGNAL(menuToggleRequested()), this, SLOT(toggleMenu()));
        connect(videoWidget, SIGNAL(volumeChangeRequested(int)), this, SLOT(changeVolume(int)));
 
-//     connect(m_actions["next"], SIGNAL(triggered()), playlist, SLOT(next()));
-//     connect(m_actions["previous"], SIGNAL(triggered()), playlist, SLOT(previous()));
-//     connect(playlist, SIGNAL(currentChanged(QString)), this, SLOT(play(QString)));
+       connect(m_actions["next"], SIGNAL(triggered()), playlist, SLOT(next()));
+       connect(m_actions["previous"], SIGNAL(triggered()), playlist, SLOT(previous()));
+       connect(playlist, SIGNAL(currentChanged(QString)), this, SLOT(play(QString)));
 #ifndef BROWSERPLUGIN_BUILD
        connect(menu, SIGNAL(positionChanged()), this, SLOT(moveWithMenu()));
 #endif
@@ -164,7 +164,7 @@ VideoWindow::VideoWindow(QWidget *parent) : QMainWindow(parent)
 
        anidb->setCompression(true);
        anidb->setIdlePolicy(AniDBUdpClient::LogoutIdlePolicy);
-
+qDebug() << m_currentFile;
        open(m_currentFile);
 }
 
@@ -223,7 +223,7 @@ void VideoWindow::open(const QString &file, bool closeOnStop)
 {
        if (file == "")
                return;
-
+qDebug() << "open => " << file;
        QFileInfo fileInfo(file);
        if (!fileInfo.exists())
        {
@@ -275,8 +275,6 @@ void VideoWindow::play(const QString &file, bool closeOnStop)
        play(closeOnStop);
 }
 
-void play(const QString &file);
-
 void VideoWindow::togglePlay()
 {
        Phonon::State state = mediaObject->state();