]> Some of my projects - aniplayer2.git/commitdiff
Add next/previous methods.
authorAPTX <marek321@gmail.com>
Sat, 16 Aug 2014 15:48:27 +0000 (17:48 +0200)
committerAPTX <marek321@gmail.com>
Sat, 16 Aug 2014 15:48:27 +0000 (17:48 +0200)
Hacky way to enable the next/previous buttons again.
Uses LML todetermine the next/previous file.

Also ensures the title is updated every time a
new file is opened.

aniplayer/aniplayer.cpp
aniplayer/aniplayer.h
player/mainwindow.cpp
player/mainwindow.h

index 9079fe1b0bff2d74a48e9bfef220a8ee9eb95829..90a10255773e4c46ee3fc36c1e9604aa6e5c60af 100644 (file)
@@ -7,6 +7,18 @@
 
 #include <QDebug>
 
+namespace {
+LocalMyList::File lmlFile(const QString& file)
+{
+       LocalMyList::File f = LocalMyList::instance()->database()->getFileByPath(QFileInfo(file).absoluteFilePath());
+       if (!f.fid)
+               f = LocalMyList::instance()->database()->getFileByPath(QFileInfo(file).canonicalFilePath());
+       if (!f.fid)
+               return {};
+       return f;
+}
+}
+
 AniPlayer::AniPlayer(QObject *parent) : QObject(parent), m_state(NoFileLoaded)
 {
        m_automark = 0;
@@ -68,6 +80,8 @@ bool AniPlayer::open(const QString &file)
        if (file == m_currentFile)
                return true;
 
+       emit message(tr("Opening: %1").arg(file));
+
        if (!iopen(file))
                return false;
 
@@ -182,6 +196,44 @@ bool AniPlayer::changeToStream(int i)
        return changeToStream(m_streams[i]);
 }
 
+bool AniPlayer::next()
+{
+       if (currentFile().isEmpty())
+               return false;
+
+       LocalMyList::File f = lmlFile(currentFile());
+       if (!f.fid)
+               return false;
+
+       LocalMyList::OpenFileData nextFile = LocalMyList::instance()->database()->nextEpisode(f.fid);
+       if (!nextFile.fid)
+               return false;
+       qDebug() << "next" << nextFile.localPath;
+       if (!open(nextFile.localPath))
+               return false;
+       play();
+       return true;
+}
+
+bool AniPlayer::previous()
+{
+       if (currentFile().isEmpty())
+               return false;
+
+       LocalMyList::File f = lmlFile(currentFile());
+       if (!f.fid)
+               return false;
+
+       LocalMyList::OpenFileData nextFile = LocalMyList::instance()->database()->previousEpisode(f.fid);
+       if (!nextFile.fid)
+               return false;
+
+       if (!open(nextFile.localPath))
+               return false;
+       play();
+       return true;
+}
+
 void AniPlayer::markWatched()
 {
        if (marked == Marked)
@@ -201,16 +253,12 @@ void AniPlayer::markWatched()
 
        using namespace LocalMyList;
        qDebug() << "path" << currentFile()<< QFileInfo(currentFile()).absoluteFilePath() << QFileInfo(currentFile()).canonicalFilePath();
-       File f = MyList::instance()->database()->getFileByPath(QFileInfo(currentFile()).absoluteFilePath());
+       File f = lmlFile(currentFile());
        if (!f.fid)
        {
-               f = MyList::instance()->database()->getFileByPath(QFileInfo(currentFile()).canonicalFilePath());
-               if (!f.fid)
-               {
-                       emit message(tr("File not in LocalMyList!"));
-                       marked = NotInMyList;
-                       return;
-               }
+               emit message(tr("File not in LocalMyList!"));
+               marked = NotInMyList;
+               return;
        }
        if (f.myWatched.isValid())
        {
@@ -291,7 +339,6 @@ void AniPlayer::setStreams(const StreamList &streams)
        emit streamsChanged(streams);
 }
 
-
 void AniPlayer::fileFinished()
 {
        ifileFinished();
index 52d96b642c77cf5b9030d0a74e177565b0fc1771..2843e9634ee36c6fb23cc55d6f8b09638a4230f5 100644 (file)
@@ -113,6 +113,9 @@ public slots:
        bool changeToStream(Stream *stream);
        bool changeToStream(int i);
 
+       bool next();
+       bool previous();
+
        // LML
        void markWatched();
        void setAutomark(int mark);
index 531b886280212c0c0b75d625602deff283087ee8..426d3d185a0dcd1093fb776df3dc2495743e98f3 100644 (file)
@@ -93,8 +93,8 @@ MainWindow::MainWindow(QWidget *parent) :
        connect(m_actions["opSkip"], SIGNAL(triggered()), this, SLOT(opSkip()));
        connect(m_actions["back1sec"], SIGNAL(triggered()), this, SLOT(skipback()));
 
-//     connect(m_actions["next"], SIGNAL(triggered()), playlist, SLOT(next()));
-//     connect(m_actions["previous"], SIGNAL(triggered()), playlist, SLOT(previous()));
+       connect(m_actions["next"], SIGNAL(triggered()), player, SLOT(next()));
+       connect(m_actions["previous"], SIGNAL(triggered()), player, SLOT(previous()));
 
        connect(player, SIGNAL(totalTimeChanged(qint64)), menu, SLOT(totalTimeChanged(qint64)));
        connect(menu->seekSlider(), SIGNAL(seekRequested(qint64)), player, SLOT(seek(qint64)));
@@ -110,6 +110,7 @@ MainWindow::MainWindow(QWidget *parent) :
        connect(player, SIGNAL(automarkChanged(int)), menu->seekSlider(), SLOT(setAutomark(int)));
 
        connect(player, SIGNAL(message(QString)), menu, SLOT(showMessage(QString)));
+       connect(player, SIGNAL(currentFileChanged(QString)), this, SLOT(handleCurrentFileChanged()));
 
        setCentralWidget(player->videoWidget());
 
@@ -174,16 +175,7 @@ bool MainWindow::open(const QString &file)
                return false;
        }
 
-//     playlist->setDirectory(fileInfo.absoluteDir());
-//     playlist->setCurrent(playlist->indexOfFile(file));
-
-       menu->showMessage(tr("Opening: %1").arg(file));
-
        player->open(file);
-
-//     updateAutomarkable();
-
-       updateWindowTitle(fileInfo);
        return true;
 }
 
@@ -459,6 +451,11 @@ void MainWindow::showConfigDialog()
        m_opSkip = dialog.opSkip();
 }
 
+void MainWindow::handleCurrentFileChanged()
+{
+       updateWindowTitle(QFileInfo(player->currentFile()));
+}
+
 void MainWindow::chaptersChanged()
 {
 /*
index 86ad4471b30377582d212c963b05d2b480bfd0ba..01da113b4cd1f91d1e50468a4c8bc9de4381e4cb 100644 (file)
@@ -46,6 +46,8 @@ private slots:
 
        void showConfigDialog();
 
+       void handleCurrentFileChanged();
+
 protected:
        void mousePressEvent(QMouseEvent *event);
        void mouseMoveEvent(QMouseEvent *event);