From 4c5fc228e690c3e2df9b5ca3f31d4ed9bf5c7345 Mon Sep 17 00:00:00 2001 From: APTX Date: Sun, 31 May 2015 12:18:03 +0200 Subject: [PATCH] Add MyList::playFile This method opens the file from OpenFileData in a video player. play-next now uses this method. It is available in the scripting API. --- localmylist/mylist.cpp | 18 ++++++++++++++++++ localmylist/mylist.h | 12 ++++++++++++ play-next/main.cpp | 3 +-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/localmylist/mylist.cpp b/localmylist/mylist.cpp index c46da34..64a6e2d 100644 --- a/localmylist/mylist.cpp +++ b/localmylist/mylist.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "database.h" #include "abstracttask.h" @@ -175,6 +176,23 @@ void MyList::voteEpisode(int aid, int epno, const QString &epType, double vote) database()->addPendingMyListUpdate(pmu); } +bool MyList::playFile(const OpenFileData &ofd, const QStringList &additionalArguments) +{ + if (!ofd.fid) + return false; + + QSettings &settings = *defaultLocalQSettings(); + settings.beginGroup("cli"); + QString player = settings.value("player", QString()).toString(); + settings.endGroup(); + + if (player.isEmpty()) + return false; + + QStringList args = QStringList() << ofd.path << additionalArguments; + + return QProcess::startDetached(player, args); +} void MyList::setupUdpClient() { diff --git a/localmylist/mylist.h b/localmylist/mylist.h index b53fe6f..9fa1a54 100644 --- a/localmylist/mylist.h +++ b/localmylist/mylist.h @@ -62,6 +62,18 @@ public slots: void voteEpisode(int eid, double vote); void voteEpisode(int aid, int epno, const QString &epType, double vote); + /** + * @brief playFile open a file in a video player + * @param ofd OpenFileData - file to open + * @param additionalArguments Additional arguments to pass to the player. + * The file's path is passed as the first argument + * @return true on success, false on failure + * + * @note cli/player must be set in the local config + */ + bool playFile(const LocalMyList::OpenFileData &ofd, + const QStringList &additionalArguments = QStringList()); + AbstractTask *addFile(const QFileInfo &file); AbstractTask *addDirectory(const QDir &directory); AbstractTask *importTitles(const QFileInfo &file); diff --git a/play-next/main.cpp b/play-next/main.cpp index abbd241..b00a516 100644 --- a/play-next/main.cpp +++ b/play-next/main.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "mylist.h" #include "database.h" @@ -61,7 +60,7 @@ int main(int argc, char *argv[]) cout << "EPISODE " << data.epno << " - " << data.episodeTitle << endl; cout << "Starting player..." << endl; - QProcess::startDetached(player, QStringList() << data.path); + MyList::instance()->playFile(data); return 0; -- 2.52.0