-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support passing URLs as cmdline arguments #15
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#include <QDir> | ||
#include <QCommandLineParser> | ||
|
||
#include "program_arg.h" | ||
#include "singleinstance.h" | ||
|
||
int main(int argc, char *argv[]) | ||
|
@@ -36,6 +37,7 @@ int main(int argc, char *argv[]) | |
parser.addHelpOption(); | ||
parser.addVersionOption(); | ||
parser.addPositionalArgument("media", QCoreApplication::translate("KokoVP", "Media files to play")); | ||
parser.addPositionalArgument("urls", QCoreApplication::translate("KokoVP", "URLs to play")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How multiple position arguments lists should work at all? Maybe just accept media by local file paths and by urls? |
||
|
||
// A boolean option with a single name (-p) | ||
QCommandLineOption newInstanceOption(QStringList() << "n" << "new-instance", QCoreApplication::translate("KokoVP", "Force open in new instance")); | ||
|
@@ -58,7 +60,7 @@ int main(int argc, char *argv[]) | |
{ | ||
if (inst.connectServer()) | ||
{ | ||
inst.sendMessage("open:" + parser.positionalArguments().join(',')); | ||
inst.sendMessage(ProgramArgument(ProgramCmd::OPEN, parser.positionalArguments())); | ||
inst.closeSocket(); | ||
return 0; | ||
} | ||
|
@@ -70,8 +72,8 @@ int main(int argc, char *argv[]) | |
KokoVP w; | ||
if (parser.positionalArguments().length()>0) | ||
{ | ||
w.handleNewMessage("open:" + parser.positionalArguments().join(',')); | ||
w.handleNewMessage("playlast"); | ||
w.handleNewMessage(ProgramArgument(ProgramCmd::OPEN, parser.positionalArguments())); | ||
w.handleNewMessage(ProgramArgument(ProgramCmd::PLAYLAST)); | ||
} | ||
QObject::connect(&inst, &SingleInstance::newMessage, &w, &KokoVP::handleNewMessage); | ||
w.showNormal(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ PlayerController::PlayerController(PlayerWidget *parent) | |
prop("volume")->set(50); | ||
prop("pause")->set(true); | ||
p->setProp("audio-file-auto-exts", Extensions.audio()); | ||
connect(p, &PlayerWidget::fileLoaded, this, &PlayerController::handleFileLoad); | ||
connect(p, &PlayerWidget::endFile, this, &PlayerController::endFile); | ||
connect(p, &PlayerWidget::endFile, this, &PlayerController::handleFileEnd); | ||
connect(p, &PlayerWidget::fileLoaded, this, &PlayerController::handleMediaLoad); | ||
connect(p, &PlayerWidget::endFile, this, &PlayerController::endMediaRessource); | ||
connect(p, &PlayerWidget::endFile, this, &PlayerController::handleMediaEnd); | ||
} | ||
|
||
PropertyObserver *PlayerController::prop(QString name) | ||
|
@@ -51,31 +51,31 @@ void PlayerController::setOption(const QString &name, const QVariant &value) | |
p->setOption(name, value); | ||
} | ||
|
||
void PlayerController::handleFileEnd() | ||
void PlayerController::handleMediaEnd() | ||
{ | ||
haveFile = false; | ||
if (!queuedFile.isEmpty()) | ||
haveMediaUrl = false; | ||
if (!queuedMediaUrl.isEmpty()) | ||
{ | ||
QUrl f = queuedFile; | ||
queuedFile = QUrl(); | ||
open(f); | ||
QUrl url = queuedMediaUrl; | ||
queuedMediaUrl = QUrl(); | ||
open(url); | ||
} | ||
} | ||
|
||
void PlayerController::open(const QUrl &file) | ||
void PlayerController::open(const QUrl &url) | ||
{ | ||
if (haveFile) | ||
if (haveMediaUrl) | ||
{ | ||
queuedFile = file; | ||
queuedMediaUrl = url; | ||
return stop(); | ||
} | ||
p_tracks.clear(); | ||
|
||
// Here we need to scan siblings folder for possible external subtitles and audio | ||
//, then set it to sub-file-paths and audio-file-paths OPTIONs (not properties) | ||
if (file.isLocalFile()) | ||
if (url.isLocalFile()) | ||
{ | ||
QDir mediaDir = QFileInfo(file.toLocalFile()).absoluteDir(); | ||
QDir mediaDir = QFileInfo(url.toLocalFile()).absoluteDir(); | ||
|
||
if (p_extSubMaxDepth>=0 && p_extSubMode!="no") | ||
{ | ||
|
@@ -94,7 +94,7 @@ void PlayerController::open(const QUrl &file) | |
} | ||
} | ||
|
||
p->command(QStringList{"loadfile", file.path()}); | ||
p->command(QStringList{"loadfile", url.toString()}); | ||
} | ||
|
||
void PlayerController::stop() | ||
|
@@ -164,10 +164,10 @@ bool PlayerController::isPlaying() | |
return !getProp("pause").toBool(); | ||
} | ||
|
||
void PlayerController::handleFileLoad() | ||
void PlayerController::handleMediaLoad() | ||
{ | ||
lastFile = currentFile(); | ||
haveFile = true; | ||
lastMediaUrl = currentMediaUrl(); | ||
haveMediaUrl = true; | ||
bool ok; | ||
int tracksCount = getProp("track-list/count").toInt(&ok); | ||
assert(ok); | ||
|
@@ -188,7 +188,7 @@ void PlayerController::handleFileLoad() | |
t.type = Track::TRACK_TYPE_SUB; | ||
|
||
if (t.isExternal) | ||
t.filename = p->getProp(trackAddr + "external-filename").toString(); | ||
t.mediaUrl = p->getProp(trackAddr + "external-mediaUrl").toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wont work. |
||
|
||
p_tracks.append(t); | ||
} | ||
|
@@ -200,5 +200,5 @@ void PlayerController::handleFileLoad() | |
|
||
p->setProp("pause", false); // Previous file can be paused, when new file is loaded, it's time to de-pause player | ||
emit tracksUpdated(); | ||
emit fileMetaUpdated(p->getProp("media-title").toString(), prop("duration")->get().toDouble()); | ||
emit mediaMetaUpdated(p->getProp("media-title").toString(), prop("duration")->get().toDouble()); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Massive rename without exact purpose. file can be accessed by url as well. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <QDataStream> | ||
|
||
#include "program_arg.h" | ||
|
||
ProgramArgument::ProgramArgument(const ProgramCmd &cmd, const QStringList &args) | ||
: cmd{cmd}, args{args} | ||
{ | ||
} | ||
|
||
QDataStream &operator>>(QDataStream &istream, ProgramArgument &pa) | ||
{ | ||
istream >> pa.cmd >> pa.args; | ||
return istream; | ||
} | ||
|
||
QDataStream &operator<<(QDataStream &ostream, const ProgramArgument &pa) | ||
{ | ||
ostream << pa.cmd << pa.args; | ||
return ostream; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. program_arg is over-engineering. SingleInstance is designed to be as simple as possible stream communication and doesn't require additional structure. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef PROGRAM_ARG_H | ||
#define PROGRAM_ARG_H | ||
|
||
#include <QString> | ||
#include <QStringList> | ||
|
||
class QDataStream; | ||
|
||
enum class ProgramCmd | ||
{ | ||
NONE, | ||
OPEN, | ||
PLAYLAST, | ||
}; | ||
|
||
struct ProgramArgument | ||
{ | ||
explicit ProgramArgument(const ProgramCmd &cmd = ProgramCmd::NONE, const QStringList &args = QStringList()); | ||
|
||
ProgramCmd cmd; | ||
QStringList args; | ||
|
||
friend QDataStream &operator>>(QDataStream &istream, ProgramArgument &pa); | ||
friend QDataStream &operator<<(QDataStream &ostream, const ProgramArgument &pa); | ||
}; | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really useful for achieving accepting URLs. Needs testing and fixing mentioned issue, but anyway.