From: APTX Date: Sat, 16 Aug 2014 15:48:27 +0000 (+0200) Subject: Add next/previous methods. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=f7ac244dcbc92b2dfcdc666cbbb8c72b532628a2;p=aniplayer2.git Add next/previous methods. 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. --- diff --git a/aniplayer/aniplayer.cpp b/aniplayer/aniplayer.cpp index 9079fe1..90a1025 100644 --- a/aniplayer/aniplayer.cpp +++ b/aniplayer/aniplayer.cpp @@ -7,6 +7,18 @@ #include +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(); diff --git a/aniplayer/aniplayer.h b/aniplayer/aniplayer.h index 52d96b6..2843e96 100644 --- a/aniplayer/aniplayer.h +++ b/aniplayer/aniplayer.h @@ -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); diff --git a/player/mainwindow.cpp b/player/mainwindow.cpp index 531b886..426d3d1 100644 --- a/player/mainwindow.cpp +++ b/player/mainwindow.cpp @@ -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() { /* diff --git a/player/mainwindow.h b/player/mainwindow.h index 86ad447..01da113 100644 --- a/player/mainwindow.h +++ b/player/mainwindow.h @@ -46,6 +46,8 @@ private slots: void showConfigDialog(); + void handleCurrentFileChanged(); + protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);