[Formatting] Improved code formatting.
This commit is contained in:
parent
c180f3f17f
commit
058ff6b8c9
118
.clang-format
Normal file
118
.clang-format
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: Mozilla
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterExternBlock: true
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Mozilla
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeComma
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 120
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 2
|
||||||
|
ContinuationIndentWidth: 1
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: false
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: true
|
||||||
|
ObjCSpaceBeforeProtocolList: false
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Cpp11
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
|
@ -14,21 +14,17 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void
|
void wakeup(void* ctx)
|
||||||
wakeup(void* ctx)
|
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod((MpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
||||||
(MpvPlayerBackend*)ctx, "on_mpv_events", Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void on_mpv_redraw(void* ctx)
|
||||||
on_mpv_redraw(void* ctx)
|
|
||||||
{
|
{
|
||||||
MpvPlayerBackend::on_update(ctx);
|
MpvPlayerBackend::on_update(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
static void* get_proc_address_mpv(void* ctx, const char* name)
|
||||||
get_proc_address_mpv(void* ctx, const char* name)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(ctx)
|
Q_UNUSED(ctx)
|
||||||
|
|
||||||
|
@ -58,15 +54,10 @@ public:
|
||||||
{
|
{
|
||||||
// init mpv_gl:
|
// init mpv_gl:
|
||||||
if (!obj->mpv_gl) {
|
if (!obj->mpv_gl) {
|
||||||
mpv_opengl_init_params gl_init_params{ get_proc_address_mpv,
|
mpv_opengl_init_params gl_init_params{ get_proc_address_mpv, nullptr, nullptr };
|
||||||
nullptr,
|
mpv_render_param params[]{ { MPV_RENDER_PARAM_API_TYPE, const_cast<char*>(MPV_RENDER_API_TYPE_OPENGL) },
|
||||||
nullptr };
|
|
||||||
mpv_render_param params[]{
|
|
||||||
{ MPV_RENDER_PARAM_API_TYPE,
|
|
||||||
const_cast<char*>(MPV_RENDER_API_TYPE_OPENGL) },
|
|
||||||
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
|
{ MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params },
|
||||||
{ MPV_RENDER_PARAM_INVALID, nullptr }
|
{ MPV_RENDER_PARAM_INVALID, nullptr } };
|
||||||
};
|
|
||||||
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
|
if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0)
|
||||||
throw std::runtime_error("failed to initialize mpv GL context");
|
throw std::runtime_error("failed to initialize mpv GL context");
|
||||||
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
|
mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj);
|
||||||
|
@ -81,14 +72,12 @@ public:
|
||||||
obj->window()->resetOpenGLState();
|
obj->window()->resetOpenGLState();
|
||||||
|
|
||||||
QOpenGLFramebufferObject* fbo = framebufferObject();
|
QOpenGLFramebufferObject* fbo = framebufferObject();
|
||||||
mpv_opengl_fbo mpfbo{ .fbo = static_cast<int>(fbo->handle()),
|
mpv_opengl_fbo mpfbo{
|
||||||
.w = fbo->width(),
|
.fbo = static_cast<int>(fbo->handle()), .w = fbo->width(), .h = fbo->height(), .internal_format = 0
|
||||||
.h = fbo->height(),
|
};
|
||||||
.internal_format = 0 };
|
|
||||||
int flip_y{ 0 };
|
int flip_y{ 0 };
|
||||||
|
|
||||||
mpv_render_param params[] = {
|
mpv_render_param params[] = { // Specify the default framebuffer (0) as target. This will
|
||||||
// Specify the default framebuffer (0) as target. This will
|
|
||||||
// render onto the entire screen. If you want to show the video
|
// render onto the entire screen. If you want to show the video
|
||||||
// in a smaller rectangle or apply fancy transformations, you'll
|
// in a smaller rectangle or apply fancy transformations, you'll
|
||||||
// need to render into a separate FBO and draw it manually.
|
// need to render into a separate FBO and draw it manually.
|
||||||
|
@ -143,11 +132,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
||||||
if (mpv_initialize(mpv) < 0)
|
if (mpv_initialize(mpv) < 0)
|
||||||
throw std::runtime_error("could not initialize mpv context");
|
throw std::runtime_error("could not initialize mpv context");
|
||||||
|
|
||||||
connect(this,
|
connect(this, &MpvPlayerBackend::onUpdate, this, &MpvPlayerBackend::doUpdate, Qt::QueuedConnection);
|
||||||
&MpvPlayerBackend::onUpdate,
|
|
||||||
this,
|
|
||||||
&MpvPlayerBackend::doUpdate,
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MpvPlayerBackend::~MpvPlayerBackend()
|
MpvPlayerBackend::~MpvPlayerBackend()
|
||||||
|
@ -157,53 +142,44 @@ MpvPlayerBackend::~MpvPlayerBackend()
|
||||||
mpv_terminate_destroy(mpv);
|
mpv_terminate_destroy(mpv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::on_update(void* ctx)
|
||||||
MpvPlayerBackend::on_update(void* ctx)
|
|
||||||
{
|
{
|
||||||
MpvPlayerBackend* self = (MpvPlayerBackend*)ctx;
|
MpvPlayerBackend* self = (MpvPlayerBackend*)ctx;
|
||||||
emit self->onUpdate();
|
emit self->onUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::doUpdate()
|
||||||
MpvPlayerBackend::doUpdate()
|
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant MpvPlayerBackend::getProperty(const QString& name) const
|
||||||
MpvPlayerBackend::getProperty(const QString& name) const
|
|
||||||
{
|
{
|
||||||
return mpv::qt::get_property_variant(mpv, name);
|
return mpv::qt::get_property_variant(mpv, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::command(const QVariant& params)
|
||||||
MpvPlayerBackend::command(const QVariant& params)
|
|
||||||
{
|
{
|
||||||
mpv::qt::command_variant(mpv, params);
|
mpv::qt::command_variant(mpv, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setProperty(const QString& name, const QVariant& value)
|
||||||
MpvPlayerBackend::setProperty(const QString& name, const QVariant& value)
|
|
||||||
{
|
{
|
||||||
mpv::qt::set_property_variant(mpv, name, value);
|
mpv::qt::set_property_variant(mpv, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setOption(const QString& name, const QVariant& value)
|
||||||
MpvPlayerBackend::setOption(const QString& name, const QVariant& value)
|
|
||||||
{
|
{
|
||||||
mpv::qt::set_option_variant(mpv, name, value);
|
mpv::qt::set_option_variant(mpv, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::launchAboutQt()
|
||||||
MpvPlayerBackend::launchAboutQt()
|
|
||||||
{
|
{
|
||||||
QApplication* qapp =
|
QApplication* qapp = qobject_cast<QApplication*>(QCoreApplication::instance());
|
||||||
qobject_cast<QApplication*>(QCoreApplication::instance());
|
|
||||||
qapp->aboutQt();
|
qapp->aboutQt();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant MpvPlayerBackend::getaudioDevices() const
|
||||||
MpvPlayerBackend::getaudioDevices() const
|
|
||||||
{
|
{
|
||||||
QVariant drivers = getProperty("audio-device-list");
|
QVariant drivers = getProperty("audio-device-list");
|
||||||
QVariant currentDevice = getProperty("audio-device");
|
QVariant currentDevice = getProperty("audio-device");
|
||||||
|
@ -224,111 +200,94 @@ MpvPlayerBackend::getaudioDevices() const
|
||||||
return QVariant(newDrivers);
|
return QVariant(newDrivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setAudioDevice(const QString& name)
|
||||||
MpvPlayerBackend::setAudioDevice(const QString& name)
|
|
||||||
{
|
{
|
||||||
setProperty("audio-device", name);
|
setProperty("audio-device", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::togglePlayPause()
|
||||||
MpvPlayerBackend::togglePlayPause()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "cycle"
|
command(QVariantList() << "cycle"
|
||||||
<< "pause");
|
<< "pause");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::toggleMute()
|
||||||
MpvPlayerBackend::toggleMute()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "cycle"
|
command(QVariantList() << "cycle"
|
||||||
<< "mute");
|
<< "mute");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::nextAudioTrack()
|
||||||
MpvPlayerBackend::nextAudioTrack()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "cycle"
|
command(QVariantList() << "cycle"
|
||||||
<< "audio");
|
<< "audio");
|
||||||
}
|
}
|
||||||
void
|
void MpvPlayerBackend::nextSubtitleTrack()
|
||||||
MpvPlayerBackend::nextSubtitleTrack()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "cycle"
|
command(QVariantList() << "cycle"
|
||||||
<< "sub");
|
<< "sub");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::nextVideoTrack()
|
||||||
MpvPlayerBackend::nextVideoTrack()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "cycle"
|
command(QVariantList() << "cycle"
|
||||||
<< "video");
|
<< "video");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::prevPlaylistItem()
|
||||||
MpvPlayerBackend::prevPlaylistItem()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "playlist-prev");
|
command(QVariantList() << "playlist-prev");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::nextPlaylistItem()
|
||||||
MpvPlayerBackend::nextPlaylistItem()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "playlist-next"
|
command(QVariantList() << "playlist-next"
|
||||||
<< "force");
|
<< "force");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::loadFile(const QVariant& filename)
|
||||||
MpvPlayerBackend::loadFile(const QVariant& filename)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "loadfile" << filename);
|
command(QVariantList() << "loadfile" << filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setVolume(const QVariant& volume)
|
||||||
MpvPlayerBackend::setVolume(const QVariant& volume)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "set"
|
command(QVariantList() << "set"
|
||||||
<< "volume" << volume);
|
<< "volume" << volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::addVolume(const QVariant& volume)
|
||||||
MpvPlayerBackend::addVolume(const QVariant& volume)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "add"
|
command(QVariantList() << "add"
|
||||||
<< "volume" << volume);
|
<< "volume" << volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::seekAbsolute(const QVariant& seekTime)
|
||||||
MpvPlayerBackend::seekAbsolute(const QVariant& seekTime)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "seek" << seekTime << "absolute");
|
command(QVariantList() << "seek" << seekTime << "absolute");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::seek(const QVariant& seekTime)
|
||||||
MpvPlayerBackend::seek(const QVariant& seekTime)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "seek" << seekTime);
|
command(QVariantList() << "seek" << seekTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant MpvPlayerBackend::getTracks() const
|
||||||
MpvPlayerBackend::getTracks() const
|
|
||||||
{
|
{
|
||||||
return mpv::qt::get_property_variant(mpv, "track-list");
|
return mpv::qt::get_property_variant(mpv, "track-list");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setTrack(const QVariant& track, const QVariant& id)
|
||||||
MpvPlayerBackend::setTrack(const QVariant& track, const QVariant& id)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "set" << track << id);
|
command(QVariantList() << "set" << track << id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant MpvPlayerBackend::getTrack(const QString& track)
|
||||||
MpvPlayerBackend::getTrack(const QString& track)
|
|
||||||
{
|
{
|
||||||
return mpv::qt::get_property_variant(mpv, track);
|
return mpv::qt::get_property_variant(mpv, track);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant
|
QVariant MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||||
MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
|
||||||
{
|
{
|
||||||
int d = seconds.toInt();
|
int d = seconds.toInt();
|
||||||
double h = floor(d / 3600);
|
double h = floor(d / 3600);
|
||||||
|
@ -336,60 +295,50 @@ MpvPlayerBackend::createTimestamp(const QVariant& seconds) const
|
||||||
double s = floor(d % 3600 % 60);
|
double s = floor(d % 3600 % 60);
|
||||||
|
|
||||||
QString hour = h > 0 ? QString::number(h) + ":" : "";
|
QString hour = h > 0 ? QString::number(h) + ":" : "";
|
||||||
QString minute = h < 1 ? QString::number(m) + ":"
|
QString minute =
|
||||||
: (m < 10 ? "0" + QString::number(m) + ":"
|
h < 1 ? QString::number(m) + ":" : (m < 10 ? "0" + QString::number(m) + ":" : QString::number(m) + ":");
|
||||||
: QString::number(m) + ":");
|
|
||||||
QString second = s < 10 ? "0" + QString::number(s) : QString::number(s);
|
QString second = s < 10 ? "0" + QString::number(s) : QString::number(s);
|
||||||
return hour + minute + second;
|
return hour + minute + second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::toggleOnTop()
|
||||||
MpvPlayerBackend::toggleOnTop()
|
|
||||||
{
|
{
|
||||||
onTop = !onTop;
|
onTop = !onTop;
|
||||||
AlwaysOnTop(window()->winId(), onTop);
|
AlwaysOnTop(window()->winId(), onTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::toggleStats()
|
||||||
MpvPlayerBackend::toggleStats()
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "script-binding"
|
command(QVariantList() << "script-binding"
|
||||||
<< "stats/display-stats-toggle");
|
<< "stats/display-stats-toggle");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::addSpeed(const QVariant& speed)
|
||||||
MpvPlayerBackend::addSpeed(const QVariant& speed)
|
|
||||||
{
|
{
|
||||||
QString speedString =
|
QString speedString = QString::number(getProperty("speed").toDouble() + speed.toDouble());
|
||||||
QString::number(getProperty("speed").toDouble() + speed.toDouble());
|
|
||||||
speedString = speedString.left(speedString.lastIndexOf('.') + 2);
|
speedString = speedString.left(speedString.lastIndexOf('.') + 2);
|
||||||
setSpeed(QVariant(speedString));
|
setSpeed(QVariant(speedString));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::subtractSpeed(const QVariant& speed)
|
||||||
MpvPlayerBackend::subtractSpeed(const QVariant& speed)
|
|
||||||
{
|
{
|
||||||
QString speedString =
|
QString speedString = QString::number(getProperty("speed").toDouble() - speed.toDouble());
|
||||||
QString::number(getProperty("speed").toDouble() - speed.toDouble());
|
|
||||||
speedString = speedString.left(speedString.lastIndexOf('.') + 2);
|
speedString = speedString.left(speedString.lastIndexOf('.') + 2);
|
||||||
setSpeed(QVariant(speedString));
|
setSpeed(QVariant(speedString));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::changeSpeed(const QVariant& speedFactor)
|
||||||
MpvPlayerBackend::changeSpeed(const QVariant& speedFactor)
|
|
||||||
{
|
{
|
||||||
setSpeed(QVariant(getProperty("speed").toDouble() * speedFactor.toDouble()));
|
setSpeed(QVariant(getProperty("speed").toDouble() * speedFactor.toDouble()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::setSpeed(const QVariant& speed)
|
||||||
MpvPlayerBackend::setSpeed(const QVariant& speed)
|
|
||||||
{
|
{
|
||||||
command(QVariantList() << "set"
|
command(QVariantList() << "set"
|
||||||
<< "speed" << speed.toString());
|
<< "speed" << speed.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::on_mpv_events()
|
||||||
MpvPlayerBackend::on_mpv_events()
|
|
||||||
{
|
{
|
||||||
while (mpv) {
|
while (mpv) {
|
||||||
mpv_event* event = mpv_wait_event(mpv, 0);
|
mpv_event* event = mpv_wait_event(mpv, 0);
|
||||||
|
@ -400,8 +349,7 @@ MpvPlayerBackend::on_mpv_events()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::updateDurationStringText()
|
||||||
MpvPlayerBackend::updateDurationStringText()
|
|
||||||
{
|
{
|
||||||
findChild<QObject*>("timeLabel")
|
findChild<QObject*>("timeLabel")
|
||||||
->setProperty("text",
|
->setProperty("text",
|
||||||
|
@ -411,8 +359,7 @@ MpvPlayerBackend::updateDurationStringText()
|
||||||
getProperty("speed").toString()));
|
getProperty("speed").toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::updatePrev(const QVariant& val)
|
||||||
MpvPlayerBackend::updatePrev(const QVariant& val)
|
|
||||||
{
|
{
|
||||||
if (val.toDouble() != 0) {
|
if (val.toDouble() != 0) {
|
||||||
findChild<QObject*>("playlistPrevButton")->setProperty("visible", true);
|
findChild<QObject*>("playlistPrevButton")->setProperty("visible", true);
|
||||||
|
@ -421,37 +368,29 @@ MpvPlayerBackend::updatePrev(const QVariant& val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::updateVolume(const QVariant& val)
|
||||||
MpvPlayerBackend::updateVolume(const QVariant& val)
|
|
||||||
{
|
{
|
||||||
if (getProperty("mute").toBool() || (val.toDouble() == 0)) {
|
if (getProperty("mute").toBool() || (val.toDouble() == 0)) {
|
||||||
findChild<QObject*>("volumeButton")
|
findChild<QObject*>("volumeButton")->setProperty("iconSource", "qrc:/player/icons/volume-mute.svg");
|
||||||
->setProperty("iconSource", "qrc:/player/icons/volume-mute.svg");
|
|
||||||
} else {
|
} else {
|
||||||
if (val.toDouble() < 25) {
|
if (val.toDouble() < 25) {
|
||||||
findChild<QObject*>("volumeButton")
|
findChild<QObject*>("volumeButton")->setProperty("iconSource", "qrc:/player/icons/volume-down.svg");
|
||||||
->setProperty("iconSource", "qrc:/player/icons/volume-down.svg");
|
|
||||||
} else {
|
} else {
|
||||||
findChild<QObject*>("volumeButton")
|
findChild<QObject*>("volumeButton")->setProperty("iconSource", "qrc:/player/icons/volume-up.svg");
|
||||||
->setProperty("iconSource", "qrc:/player/icons/volume-up.svg");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::updatePlayPause(const QVariant& val)
|
||||||
MpvPlayerBackend::updatePlayPause(const QVariant& val)
|
|
||||||
{
|
{
|
||||||
if (val.toBool()) {
|
if (val.toBool()) {
|
||||||
findChild<QObject*>("playPauseButton")
|
findChild<QObject*>("playPauseButton")->setProperty("iconSource", "qrc:/player/icons/play.svg");
|
||||||
->setProperty("iconSource", "qrc:/player/icons/play.svg");
|
|
||||||
} else {
|
} else {
|
||||||
findChild<QObject*>("playPauseButton")
|
findChild<QObject*>("playPauseButton")->setProperty("iconSource", "qrc:/player/icons/pause.svg");
|
||||||
->setProperty("iconSource", "qrc:/player/icons/pause.svg");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
|
||||||
{
|
{
|
||||||
switch (event->event_id) {
|
switch (event->event_id) {
|
||||||
case MPV_EVENT_PROPERTY_CHANGE: {
|
case MPV_EVENT_PROPERTY_CHANGE: {
|
||||||
|
@ -488,8 +427,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
|
} else if (strcmp(prop->name, "demuxer-cache-duration") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||||
double duration = *(double*)prop->data;
|
double duration = *(double*)prop->data;
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(this, "setCachedDuration", Q_ARG(QVariant, duration));
|
||||||
this, "setCachedDuration", Q_ARG(QVariant, duration));
|
|
||||||
}
|
}
|
||||||
} else if (strcmp(prop->name, "playlist-pos") == 0) {
|
} else if (strcmp(prop->name, "playlist-pos") == 0) {
|
||||||
if (prop->format == MPV_FORMAT_DOUBLE) {
|
if (prop->format == MPV_FORMAT_DOUBLE) {
|
||||||
|
@ -516,8 +454,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickFramebufferObject::Renderer*
|
QQuickFramebufferObject::Renderer* MpvPlayerBackend::createRenderer() const
|
||||||
MpvPlayerBackend::createRenderer() const
|
|
||||||
{
|
{
|
||||||
window()->setPersistentOpenGLContext(true);
|
window()->setPersistentOpenGLContext(true);
|
||||||
window()->setPersistentSceneGraph(true);
|
window()->setPersistentSceneGraph(true);
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -16,8 +16,7 @@
|
||||||
#include "setenv_mingw.hpp"
|
#include "setenv_mingw.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int main(int argc, char* argv[])
|
||||||
main(int argc, char* argv[])
|
|
||||||
{
|
{
|
||||||
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
|
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
@ -26,15 +25,10 @@ main(int argc, char* argv[])
|
||||||
app.setApplicationName("KittehPlayer");
|
app.setApplicationName("KittehPlayer");
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (!qstrcmp(argv[i], "--update")) {
|
if (!qstrcmp(argv[i], "--update")) {
|
||||||
QString program =
|
QString program = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + "/usr/bin/appimageupdatetool";
|
||||||
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
|
||||||
"/usr/bin/appimageupdatetool";
|
|
||||||
QProcess updater;
|
QProcess updater;
|
||||||
updater.setProcessChannelMode(QProcess::ForwardedChannels);
|
updater.setProcessChannelMode(QProcess::ForwardedChannels);
|
||||||
updater.start(program,
|
updater.start(program, QStringList() << QProcessEnvironment::systemEnvironment().value("APPIMAGE", ""));
|
||||||
QStringList()
|
|
||||||
<< QProcessEnvironment::systemEnvironment().value(
|
|
||||||
"APPIMAGE", ""));
|
|
||||||
updater.waitForFinished();
|
updater.waitForFinished();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -42,8 +36,7 @@ main(int argc, char* argv[])
|
||||||
|
|
||||||
SetDPMS(false);
|
SetDPMS(false);
|
||||||
|
|
||||||
QString newpath =
|
QString newpath = QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
||||||
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
|
||||||
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
|
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
|
||||||
setenv("PATH", newpath.toUtf8().constData(), 1);
|
setenv("PATH", newpath.toUtf8().constData(), 1);
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int
|
int setenv(const char* var, const char* value, int overwrite)
|
||||||
setenv(const char* var, const char* value, int overwrite)
|
|
||||||
{
|
{
|
||||||
/* Core implementation for both setenv() and unsetenv() functions;
|
/* Core implementation for both setenv() and unsetenv() functions;
|
||||||
* at the outset, assume that the requested operation may fail.
|
* at the outset, assume that the requested operation may fail.
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
|
||||||
QString
|
QString getPlatformName()
|
||||||
getPlatformName()
|
|
||||||
{
|
{
|
||||||
QGuiApplication* qapp =
|
QGuiApplication* qapp = qobject_cast<QGuiApplication*>(QCoreApplication::instance());
|
||||||
qobject_cast<QGuiApplication*>(QCoreApplication::instance());
|
|
||||||
return qapp->platformName();
|
return qapp->platformName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +18,7 @@ getPlatformName()
|
||||||
#include <X11/extensions/dpms.h>
|
#include <X11/extensions/dpms.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
void
|
void SetDPMS(bool on)
|
||||||
SetDPMS(bool on)
|
|
||||||
{
|
{
|
||||||
qDebug() << getPlatformName();
|
qDebug() << getPlatformName();
|
||||||
if (getPlatformName() != "xcb") {
|
if (getPlatformName() != "xcb") {
|
||||||
|
@ -37,8 +34,7 @@ SetDPMS(bool on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void AlwaysOnTop(WId wid, bool on)
|
||||||
AlwaysOnTop(WId wid, bool on)
|
|
||||||
{
|
{
|
||||||
qDebug() << "On Top:" << on;
|
qDebug() << "On Top:" << on;
|
||||||
Display* display = QX11Info::display();
|
Display* display = QX11Info::display();
|
||||||
|
@ -57,23 +53,17 @@ AlwaysOnTop(WId wid, bool on)
|
||||||
event.xclient.data.l[3] = 0;
|
event.xclient.data.l[3] = 0;
|
||||||
event.xclient.data.l[4] = 0;
|
event.xclient.data.l[4] = 0;
|
||||||
|
|
||||||
XSendEvent(display,
|
XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
|
||||||
DefaultRootWindow(display),
|
|
||||||
False,
|
|
||||||
SubstructureRedirectMask | SubstructureNotifyMask,
|
|
||||||
&event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void
|
void AlwaysOnTop(WId wid, bool on)
|
||||||
AlwaysOnTop(WId wid, bool on)
|
|
||||||
{
|
{
|
||||||
qDebug() << "Can't set on top for platform: " << getPlatformName();
|
qDebug() << "Can't set on top for platform: " << getPlatformName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void SetDPMS(bool on)
|
||||||
SetDPMS(bool on)
|
|
||||||
{
|
{
|
||||||
qDebug() << "Can't set DPMS for platform: " << getPlatformName();
|
qDebug() << "Can't set DPMS for platform: " << getPlatformName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
void
|
void SetDPMS(bool on);
|
||||||
SetDPMS(bool on);
|
void AlwaysOnTop(WId wid, bool on);
|
||||||
void
|
|
||||||
AlwaysOnTop(WId wid, bool on);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue