1
0
Fork 0

Reformat code.

This commit is contained in:
namedkitten 2020-05-06 12:43:01 +01:00
parent e1dd828968
commit 9cf2aafd73
57 changed files with 3906 additions and 3995 deletions

5
.clang-format Normal file
View file

@ -0,0 +1,5 @@
---
Language: Cpp
BasedOnStyle: WebKit
...

View file

@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -x
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
pushd $SOURCE_DIR
find . -name "*.qml" -exec qmlfmt -w {} \;
find . -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -exec clang-format90 -style mozilla -i {} \;
find . -name "*.qml" -exec qmlfmt -i 2 -w {} \;
clang-format -style=file -i $(find src -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h")
#find . -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -exec clang-format -style=file -i {} \;
popd

View file

@ -1,24 +1,24 @@
#include "src/Backends/MPV/MPVBackend.hpp"
#include <QtCore/qglobal.h>
#include <mpv/render_gl.h>
#include "src/Backends/MPVCommon/MPVCommon.hpp"
#include "src/qthelper.hpp"
#include "src/utils.hpp"
#include <QByteArray>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QEvent>
#include <QDebug>
#include <QEvent>
#include <QGuiApplication>
#include <QIcon>
#include <QMetaObject>
#include <QObject>
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
#include <QQuickWindow>
#include <stdio.h>
#include <QtCore/qglobal.h>
#include <clocale>
#include <iostream>
#include "src/qthelper.hpp"
#include <mpv/render_gl.h>
#include <stdexcept>
#include "src/Backends/MPVCommon/MPVCommon.hpp"
#include "src/utils.hpp"
#include <stdio.h>
class QQuickItem;
class QSize;
@ -26,27 +26,23 @@ class QSize;
#ifdef ENABLE_X11
#include <QX11Info> // IWYU pragma: keep
#include <QtX11Extras/QX11Info> // IWYU pragma: keep
#include <qx11info_x11.h> // IWYU pragma: keep
#include <X11/Xlib.h> // IWYU pragma: keep
#include <X11/Xutil.h> // IWYU pragma: keep
#include <qx11info_x11.h> // IWYU pragma: keep
#endif
#include <qpa/qplatformnativeinterface.h> // IWYU pragma: keep
#endif
bool usedirect = false;
namespace {
void
wakeup(void* ctx)
void wakeup(void* ctx)
{
QCoreApplication::postEvent((MPVBackend*)ctx, new QEvent(QEvent::User));
}
void
on_mpv_redraw(void* ctx)
void on_mpv_redraw(void* ctx)
{
QMetaObject::invokeMethod(
reinterpret_cast<MPVBackend*>(ctx), "update", Qt::QueuedConnection);
@ -61,8 +57,7 @@ get_proc_address_mpv(void* ctx, const char* name)
} // namespace
class MpvRenderer : public QQuickFramebufferObject::Renderer
{
class MpvRenderer : public QQuickFramebufferObject::Renderer {
MPVBackend* obj;
public:
@ -70,14 +65,12 @@ public:
: obj{ new_obj }
{
if (usedirect) {
int r =
mpv_opengl_cb_init_gl(obj->mpv_gl_cb, NULL, get_proc_address_mpv, QOpenGLContext::currentContext());
int r = mpv_opengl_cb_init_gl(obj->mpv_gl_cb, NULL, get_proc_address_mpv, QOpenGLContext::currentContext());
if (r < 0) {
std::cout << "No." << std::endl;
throw std::runtime_error("failed to initialize mpv GL context");
}
}
}
virtual ~MpvRenderer() {}
@ -107,7 +100,7 @@ public:
#endif
if (QGuiApplication::platformName().contains("wayland")) {
params[2].type = MPV_RENDER_PARAM_WL_DISPLAY;
auto *native = QGuiApplication::platformNativeInterface();
auto* native = QGuiApplication::platformNativeInterface();
params[2].data = native->nativeResourceForWindow("display", NULL);
}
#endif
@ -120,7 +113,6 @@ public:
}
QMetaObject::invokeMethod(obj, "startPlayer");
return QQuickFramebufferObject::Renderer::createFramebufferObject(size);
}
@ -228,7 +220,7 @@ MPVBackend::~MPVBackend()
if (usedirect && mpv_gl_cb) {
mpv_opengl_cb_uninit_gl(mpv_gl_cb);
} else if (mpv_gl){
} else if (mpv_gl) {
mpv_render_context_free(mpv_gl);
}
@ -236,15 +228,13 @@ MPVBackend::~MPVBackend()
printf("MPV terminated.\n");
}
void
MPVBackend::on_update(void* ctx)
void MPVBackend::on_update(void* ctx)
{
MPVBackend* self = (MPVBackend*)ctx;
emit self->onUpdate();
}
void
MPVBackend::doUpdate()
void MPVBackend::doUpdate()
{
update();
}
@ -255,23 +245,20 @@ MPVBackend::getProperty(const QString& name) const
return mpv::qt::get_property_variant(mpv, name);
}
void
MPVBackend::command(const QVariant& params)
void MPVBackend::command(const QVariant& params)
{
mpv::qt::node_builder node(params);
mpv_command_node(mpv, node.node(), nullptr);
}
void
MPVBackend::setProperty(const QString& name, const QVariant& value)
void MPVBackend::setProperty(const QString& name, const QVariant& value)
{
mpv::qt::node_builder node(value);
qDebug() << "Setting property" << name << "to" << value;
mpv_set_property(mpv, name.toUtf8().data(), MPV_FORMAT_NODE, node.node());
}
void
MPVBackend::setOption(const QString& name, const QVariant& value)
void MPVBackend::setOption(const QString& name, const QVariant& value)
{
mpv::qt::set_option_variant(mpv, name, value);
}
@ -294,24 +281,19 @@ MPVBackend::getStats()
return MPVCommon::getStats(this);
}
void
MPVBackend::updateDurationString(int numTime)
void MPVBackend::updateDurationString(int numTime)
{
QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
MPVCommon::updateDurationString(this, numTime, metaMethod);
}
void
MPVBackend::toggleOnTop()
void MPVBackend::toggleOnTop()
{
onTop = !onTop;
Utils::AlwaysOnTop(window()->winId(), onTop);
}
bool
MPVBackend::event(QEvent* event)
bool MPVBackend::event(QEvent* event)
{
if (event->type() == QEvent::User) {
on_mpv_events();
@ -319,8 +301,7 @@ MPVBackend::event(QEvent* event)
return QObject::event(event);
}
void
MPVBackend::on_mpv_events()
void MPVBackend::on_mpv_events()
{
while (mpv) {
mpv_event* event = mpv_wait_event(mpv, 0);
@ -337,8 +318,7 @@ MPVBackend::getAudioDevices(const QVariant& drivers) const
return MPVCommon::getAudioDevices(drivers);
}
void
MPVBackend::handle_mpv_event(mpv_event* event)
void MPVBackend::handle_mpv_event(mpv_event* event)
{
MPVCommon::handle_mpv_event(this, event);
}

View file

@ -1,24 +1,23 @@
#ifndef MPVBackend_H
#define MPVBackend_H
#include <mpv/client.h>
#include <mpv/opengl_cb.h>
#include <mpv/render.h>
#include "src/backendinterface.hpp"
#include "src/enums.hpp"
#include <QEvent>
#include <QMetaType>
#include <QObject>
#include <QEvent>
#include <QQuickItem>
#include <QQuickFramebufferObject>
#include <QQuickItem>
#include <QSettings>
#include <QString>
#include <QVariant>
#include "src/backendinterface.hpp"
#include "src/enums.hpp"
#include <mpv/client.h>
#include <mpv/opengl_cb.h>
#include <mpv/render.h>
class MPVBackend
: public QQuickFramebufferObject
, public BackendInterface
{
: public QQuickFramebufferObject,
public BackendInterface {
Q_INTERFACES(BackendInterface)
Q_OBJECT

View file

@ -1,35 +1,35 @@
#include "src/Backends/MPVCommon/MPVCommon.hpp"
#include "spdlog/logger.h"
#include "src/backendinterface.hpp"
#include "src/logger.h"
#include "src/utils.hpp"
#include <QByteArray>
#include <QCoreApplication>
#include <QJsonObject>
#include <QList>
#include <QLocale>
#include <QMap>
#include <QMetaObject>
#include <QMetaMethod>
#include <QMetaObject>
#include <QObject>
#include <QSettings>
#include <spdlog/fmt/fmt.h>
#include <string.h>
#include <exception>
#include <memory>
#include "spdlog/logger.h"
#include "src/backendinterface.hpp"
#include "src/logger.h"
#include "src/utils.hpp"
#include <spdlog/fmt/fmt.h>
#include <string.h>
auto mpvLogger = initLogger("mpv");
QString humanSize(uint64_t bytes)
{
const char *suffix[5] = {"B", "KB", "MB", "GB", "TB"};
const char* suffix[5] = { "B", "KB", "MB", "GB", "TB" };
char length = sizeof(suffix) / sizeof(suffix[0]);
int i = 0;
double dblBytes = bytes;
if (bytes > 1024) {
for (i = 0; (bytes / 1024) > 0 && i<length-1; i++, bytes /= 1024)
for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024)
dblBytes = bytes / 1024.0;
}
@ -38,7 +38,7 @@ QString humanSize(uint64_t bytes)
return QString(output);
}
static inline QVariant mpvnode_to_variant(const mpv_node *node)
static inline QVariant mpvnode_to_variant(const mpv_node* node)
{
if (!node) {
return QVariant();
@ -54,14 +54,14 @@ static inline QVariant mpvnode_to_variant(const mpv_node *node)
case MPV_FORMAT_DOUBLE:
return QVariant(node->u.double_);
case MPV_FORMAT_NODE_ARRAY: {
mpv_node_list *list = node->u.list;
mpv_node_list* list = node->u.list;
QVariantList qlist;
for (int n = 0; n < list->num; n++)
qlist.append(mpvnode_to_variant(&list->values[n]));
return QVariant(qlist);
}
case MPV_FORMAT_NODE_MAP: {
mpv_node_list *list = node->u.list;
mpv_node_list* list = node->u.list;
QVariantMap qmap;
for (int n = 0; n < list->num; n++) {
qmap.insert(QString::fromUtf8(list->keys[n]),
@ -74,12 +74,11 @@ static inline QVariant mpvnode_to_variant(const mpv_node *node)
}
}
namespace MPVCommon {
QString getStats(BackendInterface *b) {
QString getStats(BackendInterface* b)
{
QString stats;
stats =
"<style> blockquote { text-indent: 0px; margin-left:40px; margin-top: 0px; "
stats = "<style> blockquote { text-indent: 0px; margin-left:40px; margin-top: 0px; "
"margin-bottom: 0px; padding-bottom: 0px; padding-top: 0px; padding-left: "
"0px; } b span p br { margin-bottom: 0px; margin-top: 0px; padding-top: "
"0px; padding-botom: 0px; text-indent: 0px; } </style>";
@ -116,8 +115,7 @@ QString getStats(BackendInterface *b) {
cacheStats += "<br>";
stats += cacheStats;
}
QString fileSize =
humanSize(b->getProperty("file-size").toInt()).remove("-");
QString fileSize = humanSize(b->getProperty("file-size").toInt()).remove("-");
stats += "<b>Size:</b> " + fileSize + "<br>";
stats += "</blockquote>";
@ -252,7 +250,7 @@ QString getStats(BackendInterface *b) {
return stats;
}
QVariant playerCommand(BackendInterface *b, const Enums::Commands& cmd, const QVariant& args)
QVariant playerCommand(BackendInterface* b, const Enums::Commands& cmd, const QVariant& args)
{
switch (cmd) {
case Enums::Commands::TogglePlayPause: {
@ -284,10 +282,8 @@ QVariant playerCommand(BackendInterface *b, const Enums::Commands& cmd, const QV
case Enums::Commands::AddSpeed: {
QString speedString =
QString::number(b->getProperty("speed").toDouble() + args.toDouble());
QVariant newSpeed =
QVariant(speedString.left(speedString.lastIndexOf('.') + 2));
QString speedString = QString::number(b->getProperty("speed").toDouble() + args.toDouble());
QVariant newSpeed = QVariant(speedString.left(speedString.lastIndexOf('.') + 2));
b->playerCommand(Enums::Commands::SetSpeed, newSpeed);
break;
@ -295,10 +291,8 @@ QVariant playerCommand(BackendInterface *b, const Enums::Commands& cmd, const QV
case Enums::Commands::SubtractSpeed: {
QString speedString =
QString::number(b->getProperty("speed").toDouble() - args.toDouble());
QVariant newSpeed =
QVariant(speedString.left(speedString.lastIndexOf('.') + 2));
QString speedString = QString::number(b->getProperty("speed").toDouble() - args.toDouble());
QVariant newSpeed = QVariant(speedString.left(speedString.lastIndexOf('.') + 2));
b->playerCommand(Enums::Commands::SetSpeed, newSpeed);
break;
}
@ -420,7 +414,7 @@ QVariant playerCommand(BackendInterface *b, const Enums::Commands& cmd, const QV
return QVariant("NoOutput");
}
void updateDurationString(BackendInterface *b, int numTime, QMetaMethod metaMethod)
void updateDurationString(BackendInterface* b, int numTime, QMetaMethod metaMethod)
{
QVariant speed = b->getProperty("speed");
QSettings settings;
@ -442,16 +436,14 @@ void updateDurationString(BackendInterface *b, int numTime, QMetaMethod metaMeth
durationString += " / ";
durationString += b->totalDurationString;
if (b->lastSpeed != 1) {
if (settings.value("Appearance/themeName", "").toString() !=
"RoosterTeeth") {
if (settings.value("Appearance/themeName", "").toString() != "RoosterTeeth") {
durationString += " (" + speed.toString() + "x)";
}
}
emit b->durationStringChanged(durationString);
}
void
handle_mpv_event(BackendInterface *b, mpv_event* event)
void handle_mpv_event(BackendInterface* b, mpv_event* event)
{
switch (event->event_id) {
case MPV_EVENT_PROPERTY_CHANGE: {
@ -466,8 +458,7 @@ handle_mpv_event(BackendInterface *b, mpv_event* event)
double time = *(double*)prop->data;
emit b->durationChanged(time);
}
} else if (strcmp(prop->name, "mute") == 0 ||
strcmp(prop->name, "volume") == 0) {
} else if (strcmp(prop->name, "mute") == 0 || strcmp(prop->name, "volume") == 0) {
double volume = b->getProperty("volume").toDouble();
bool mute = b->getProperty("mute").toBool();
if (mute || volume == 0) {
@ -529,8 +520,7 @@ handle_mpv_event(BackendInterface *b, mpv_event* event)
}
case MPV_EVENT_LOG_MESSAGE: {
struct mpv_event_log_message* msg =
(struct mpv_event_log_message*)event->data;
struct mpv_event_log_message* msg = (struct mpv_event_log_message*)event->data;
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
QString msgLevel = QString(msg->level);
if (msgLevel.startsWith("d") || msgLevel.startsWith("t")) {
@ -567,5 +557,4 @@ QVariantMap getAudioDevices(const QVariant& drivers)
}
return newDrivers;
}
}

View file

@ -1,24 +1,21 @@
#ifndef MPVCommon_H
#define MPVCommon_H
#include <mpv/client.h>
#include "src/enums.hpp"
#include <QMetaType>
#include <QString>
#include <QVariant>
#include "src/enums.hpp"
#include <mpv/client.h>
class BackendInterface;
class QMetaMethod;
namespace MPVCommon {
QString getStats(BackendInterface *b);
QVariant playerCommand(BackendInterface *b, const Enums::Commands& cmd, const QVariant& args);
void updateDurationString(BackendInterface *b, int numTime, QMetaMethod metaMethod);
void handle_mpv_event(BackendInterface *b, mpv_event* event);
QString getStats(BackendInterface* b);
QVariant playerCommand(BackendInterface* b, const Enums::Commands& cmd, const QVariant& args);
void updateDurationString(BackendInterface* b, int numTime, QMetaMethod metaMethod);
void handle_mpv_event(BackendInterface* b, mpv_event* event);
QVariantMap getAudioDevices(const QVariant& drivers);
}
#endif

View file

@ -1,24 +1,22 @@
#include "src/Backends/MPVNoFBO/MPVNoFBOBackend.hpp"
#include "src/Backends/MPVCommon/MPVCommon.hpp"
#include "src/qthelper.hpp"
#include "src/utils.hpp"
#include <QApplication>
#include <QByteArray>
#include <QCoreApplication>
#include <QEvent>
#include <QDebug>
#include <QEvent>
#include <QIcon>
#include <QMetaObject>
#include <QOpenGLContext>
#include <QQuickWindow>
#include <clocale>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <clocale>
#include "src/qthelper.hpp"
#include <stdexcept>
#include "src/Backends/MPVCommon/MPVCommon.hpp"
#include "src/utils.hpp"
void
nofbowakeup(void* ctx)
void nofbowakeup(void* ctx)
{
QCoreApplication::postEvent((MPVNoFBOBackend*)ctx, new QEvent(QEvent::User));
}
@ -52,8 +50,7 @@ MPVNoFBORenderer::~MPVNoFBORenderer()
exit(0);
}
void
MPVNoFBORenderer::paint()
void MPVNoFBORenderer::paint()
{
window->resetOpenGLState();
@ -145,8 +142,7 @@ MPVNoFBOBackend::~MPVNoFBOBackend()
printf("MPV terminated.\n");
}
void
MPVNoFBOBackend::sync()
void MPVNoFBOBackend::sync()
{
if (!renderer) {
@ -163,14 +159,12 @@ MPVNoFBOBackend::sync()
renderer->size = window()->size() * window()->devicePixelRatio();
}
void
MPVNoFBOBackend::swapped()
void MPVNoFBOBackend::swapped()
{
mpv_opengl_cb_report_flip(mpv_gl, 0);
}
void
MPVNoFBOBackend::cleanup()
void MPVNoFBOBackend::cleanup()
{
if (renderer) {
delete renderer;
@ -178,15 +172,13 @@ MPVNoFBOBackend::cleanup()
}
}
void
MPVNoFBOBackend::on_update(void* ctx)
void MPVNoFBOBackend::on_update(void* ctx)
{
MPVNoFBOBackend* self = (MPVNoFBOBackend*)ctx;
emit self->onUpdate();
}
void
MPVNoFBOBackend::doUpdate()
void MPVNoFBOBackend::doUpdate()
{
window()->update();
update();
@ -198,29 +190,24 @@ MPVNoFBOBackend::getProperty(const QString& name) const
return mpv::qt::get_property_variant(mpv, name);
}
void
MPVNoFBOBackend::command(const QVariant& params)
void MPVNoFBOBackend::command(const QVariant& params)
{
mpv::qt::command_variant(mpv, params);
}
void
MPVNoFBOBackend::setProperty(const QString& name, const QVariant& value)
void MPVNoFBOBackend::setProperty(const QString& name, const QVariant& value)
{
mpv::qt::set_property_variant(mpv, name, value);
}
void
MPVNoFBOBackend::setOption(const QString& name, const QVariant& value)
void MPVNoFBOBackend::setOption(const QString& name, const QVariant& value)
{
mpv::qt::set_option_variant(mpv, name, value);
}
void
MPVNoFBOBackend::launchAboutQt()
void MPVNoFBOBackend::launchAboutQt()
{
QApplication* qapp =
qobject_cast<QApplication*>(QCoreApplication::instance());
QApplication* qapp = qobject_cast<QApplication*>(QCoreApplication::instance());
qapp->aboutQt();
}
@ -237,8 +224,7 @@ MPVNoFBOBackend::playerCommand(const Enums::Commands& cmd,
return MPVCommon::playerCommand(this, cmd, args);
}
void
MPVNoFBOBackend::handleWindowChanged(QQuickWindow* win)
void MPVNoFBOBackend::handleWindowChanged(QQuickWindow* win)
{
if (!win)
return;
@ -260,15 +246,13 @@ MPVNoFBOBackend::handleWindowChanged(QQuickWindow* win)
win->setClearBeforeRendering(false);
}
void
MPVNoFBOBackend::toggleOnTop()
void MPVNoFBOBackend::toggleOnTop()
{
onTop = !onTop;
Utils::AlwaysOnTop(window()->winId(), onTop);
}
bool
MPVNoFBOBackend::event(QEvent* event)
bool MPVNoFBOBackend::event(QEvent* event)
{
if (event->type() == QEvent::User) {
on_mpv_events();
@ -276,8 +260,7 @@ MPVNoFBOBackend::event(QEvent* event)
return QObject::event(event);
}
void
MPVNoFBOBackend::on_mpv_events()
void MPVNoFBOBackend::on_mpv_events()
{
while (mpv) {
mpv_event* event = mpv_wait_event(mpv, 0);
@ -288,8 +271,7 @@ MPVNoFBOBackend::on_mpv_events()
}
}
void
MPVNoFBOBackend::updateDurationString(int numTime)
void MPVNoFBOBackend::updateDurationString(int numTime)
{
QMetaMethod metaMethod = sender()->metaObject()->method(senderSignalIndex());
MPVCommon::updateDurationString(this, numTime, metaMethod);
@ -301,8 +283,7 @@ MPVNoFBOBackend::getAudioDevices(const QVariant& drivers) const
return MPVCommon::getAudioDevices(drivers);
}
void
MPVNoFBOBackend::handle_mpv_event(mpv_event* event)
void MPVNoFBOBackend::handle_mpv_event(mpv_event* event)
{
MPVCommon::handle_mpv_event(this, event);
}
@ -312,5 +293,3 @@ MPVNoFBOBackend::getStats()
{
return MPVCommon::getStats(this);
}

View file

@ -1,8 +1,8 @@
#ifndef MPVNoFBOBackend_H
#define MPVNoFBOBackend_H
#include <mpv/client.h>
#include <mpv/opengl_cb.h>
#include "src/backendinterface.hpp"
#include "src/enums.hpp"
#include <QEvent>
#include <QMetaType>
#include <QObject>
@ -12,11 +12,10 @@
#include <QSize>
#include <QString>
#include <QVariant>
#include "src/backendinterface.hpp"
#include "src/enums.hpp"
#include <mpv/client.h>
#include <mpv/opengl_cb.h>
class MPVNoFBORenderer : public QObject
{
class MPVNoFBORenderer : public QObject {
Q_OBJECT
mpv_handle* mpv;
mpv_opengl_cb_context* mpv_gl;
@ -33,9 +32,8 @@ public slots:
};
class MPVNoFBOBackend
: public QQuickItem
, public BackendInterface
{
: public QQuickItem,
public BackendInterface {
Q_INTERFACES(BackendInterface)
Q_OBJECT

View file

@ -5,10 +5,10 @@ class QObject;
Process::Process(QObject* parent)
: QProcess(parent)
{}
{
}
void
Process::start(const QString& program, const QVariantList& arguments)
void Process::start(const QString& program, const QVariantList& arguments)
{
QStringList args;

View file

@ -6,8 +6,7 @@
#include <QProcess>
#include <QString>
class Process : public QProcess
{
class Process : public QProcess {
Q_OBJECT
public:

View file

@ -3,9 +3,9 @@
#include <QByteArray>
#include <QCryptographicHash>
#include <QFileInfo>
#include <QIODevice>
#include <QImage>
#include <QImageReader>
#include <QIODevice>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
@ -16,16 +16,13 @@ ThumbnailCache::ThumbnailCache(QObject* parent)
: QObject(parent)
, manager(new QNetworkAccessManager(this))
{
cacheFolder =
QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
"/thumbs");
cacheFolder = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/thumbs");
if (!cacheFolder.exists()) {
cacheFolder.mkpath(".");
}
}
void
ThumbnailCache::addURL(const QString& name, const QString& mediaURL)
void ThumbnailCache::addURL(const QString& name, const QString& mediaURL)
{
QString hashedURL = QString(

View file

@ -1,12 +1,11 @@
#ifndef ThumbnailCache_H
#define ThumbnailCache_H
#include <QDir>
#include <QNetworkAccessManager>
#include <QObject>
#include <QString>
#include <QNetworkAccessManager>
class ThumbnailCache : public QObject
{
class ThumbnailCache : public QObject {
Q_OBJECT
public:
@ -16,8 +15,7 @@ public slots:
Q_INVOKABLE void addURL(const QString& name, const QString& url);
signals:
void thumbnailReady(const QString& name,
const QString& url,
void thumbnailReady(const QString& name, const QString& url,
const QString& filePath);
private:

View file

@ -2,8 +2,7 @@
#define BackendInterface_H
#include "enums.hpp"
#include <QObject>
class BackendInterface
{
class BackendInterface {
public:
virtual ~BackendInterface(){};
int lastTime = 0;
@ -14,7 +13,8 @@ public:
public slots:
// All 5 required for Player API
virtual QVariant playerCommand(const Enums::Commands& command,
const QVariant& args) = 0;
const QVariant& args)
= 0;
virtual QVariant playerCommand(const Enums::Commands& command) = 0;
virtual void toggleOnTop() = 0;
// Optional but handy for MPV or custom backend settings.

View file

@ -6,21 +6,18 @@
namespace Enums {
Q_NAMESPACE
enum class PlayStatus : int
{
enum class PlayStatus : int {
Playing = 0,
Paused = 1
};
Q_ENUM_NS(PlayStatus)
enum class VolumeStatus : int
{
enum class VolumeStatus : int {
Muted = 0,
Low = 1,
Normal = 2
};
Q_ENUM_NS(VolumeStatus)
enum class Commands : int
{
enum class Commands : int {
TogglePlayPause = 0,
ToggleMute = 1,
SetAudioDevice = 2,
@ -48,18 +45,15 @@ enum class Commands : int
};
Q_ENUM_NS(Commands)
enum class Backends : int
{
enum class Backends : int {
MPVBackend = 0,
DirectMPVBackend = 1
};
Q_ENUM_NS(Backends)
}
// Forces meta generation.
class Dummy : public QObject
{
class Dummy : public QObject {
Q_OBJECT
};

View file

@ -1,37 +1,35 @@
#include <QByteArray>
#include <QSettings>
#include <QString>
#include <QVariant>
#include <spdlog/logger.h>
#include <iterator>
#include <vector>
#include <iosfwd> // IWYU pragma: keep
#include <memory> // IWYU pragma: keep
#include <spdlog/spdlog.h> // IWYU pragma: export
#include <spdlog/sinks/basic_file_sink.h> // IWYU pragma: export
#include <spdlog/sinks/daily_file_sink.h> // IWYU pragma: export
#include <spdlog/sinks/stdout_color_sinks.h> // IWYU pragma: export
#include "spdlog/common.h"
#include "spdlog/details/file_helper-inl.h"
#include "spdlog/sinks/ansicolor_sink-inl.h"
#include "spdlog/sinks/base_sink-inl.h"
#include "spdlog/sinks/basic_file_sink-inl.h"
#include "spdlog/spdlog-inl.h"
#include <QByteArray>
#include <QSettings>
#include <QString>
#include <QVariant>
#include <iosfwd> // IWYU pragma: keep
#include <iterator>
#include <memory> // IWYU pragma: keep
#include <spdlog/logger.h>
#include <spdlog/sinks/basic_file_sink.h> // IWYU pragma: export
#include <spdlog/sinks/daily_file_sink.h> // IWYU pragma: export
#include <spdlog/sinks/stdout_color_sinks.h> // IWYU pragma: export
#include <spdlog/spdlog.h> // IWYU pragma: export
#include <vector>
std::shared_ptr<spdlog::logger>
initLogger(std::string name)
{
QSettings settings("KittehPlayer", "KittehPlayer");
QString logFile =
settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString();
QString logFile = settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString();
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(
logFile.toUtf8().constData()));
auto console =
std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
auto console = std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
console->set_pattern("[%l][%n] %v%$");
spdlog::register_logger(console);

View file

@ -7,7 +7,6 @@
#include <spdlog/sinks/stdout_color_sinks.h> // IWYU pragma: keep
#include <spdlog/spdlog.h> // IWYU pragma: keep
std::shared_ptr<spdlog::logger>
initLogger(std::string name);
std::shared_ptr<spdlog::logger> initLogger(std::string name);
#endif

View file

@ -1,24 +1,24 @@
#include <QtGlobal>
#include <locale.h>
#include <QApplication>
#include <QProcess>
#include <QtQml>
#include <QQmlApplicationEngine>
#include <QtGlobal>
#include <QtQml>
#include <locale.h>
#ifdef QT_QML_DEBUG
#warning "QML Debugging Enabled!!!"
#include <QQmlDebug>
#endif
#include "logger.h"
#include "spdlog/logger.h"
#include <QSettings>
#include <QString>
#include <QUrl>
#include <QVariant>
#include <spdlog/fmt/fmt.h>
#include <cstdlib>
#include <exception>
#include <iosfwd>
#include <memory>
#include "logger.h"
#include "spdlog/logger.h"
#include <spdlog/fmt/fmt.h>
extern void registerTypes();
@ -29,8 +29,7 @@ extern void registerTypes();
auto qmlLogger = initLogger("qml");
auto miscLogger = initLogger("misc");
void
spdLogger(QtMsgType type, const QMessageLogContext& context, const QString& msg)
void spdLogger(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
std::string localMsg = msg.toUtf8().constData();
std::shared_ptr<spdlog::logger> logger;
@ -59,8 +58,7 @@ spdLogger(QtMsgType type, const QMessageLogContext& context, const QString& msg)
}
}
int
main(int argc, char* argv[])
int main(int argc, char* argv[])
{
qInstallMessageHandler(spdLogger);
@ -88,10 +86,10 @@ main(int argc, char* argv[])
// this is only to make it so KittehPlayer works first try on pinephone.
// TODO: launch a opengl window or use offscreen to see if GL_ARB_framebuffer_object
// can be found
if (! (settings.value("Backend/disableSunxiCheck", false).toBool() || ranFirstTimeSetup)) {
FILE *fd = popen("grep sun[x8]i /proc/modules", "r");
if (!(settings.value("Backend/disableSunxiCheck", false).toBool() || ranFirstTimeSetup)) {
FILE* fd = popen("grep sun[x8]i /proc/modules", "r");
char buf[16];
if (fread(buf, 1, sizeof (buf), fd) > 0) {
if (fread(buf, 1, sizeof(buf), fd) > 0) {
launcherLogger->info("Running on sunxi, switching to NoFBO.");
settings.setValue("Appearance/clickToPause", false);
settings.setValue("Appearance/doubleTapToSeek", true);
@ -102,12 +100,9 @@ main(int argc, char* argv[])
}
#endif
settings.setValue("Setup/ranSetup", true);
QString newpath =
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
QString newpath = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + "/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
setenv("PATH", newpath.toUtf8().constData(), 1);
registerTypes();

View file

@ -48,7 +48,8 @@ Item {
VideoProgress {
id: progressBar
visible: controlsBarItem.controlsShowing && appearance.themeName != "RoosterTeeth"
visible: controlsBarItem.controlsShowing
&& appearance.themeName != "RoosterTeeth"
bottomPadding: 0
rightPadding: 0
leftPadding: 0
@ -70,8 +71,7 @@ Item {
== "RoosterTeeth" ? 0 : progressBar.topPadding) : 0
Layout.fillWidth: true
Layout.fillHeight: true
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
visible: controlsBarItem.controlsShowing
z: 10
anchors {

View file

@ -6,8 +6,7 @@ Menu {
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 10
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
}
delegate: CustomMenuItem {}
}

View file

@ -46,14 +46,12 @@ Dialog {
return
}
var component = Qt.createComponent("ThumbnailProcess.qml")
var thumbnailerProcess = component.createObject(
playlistDialog, {
var thumbnailerProcess = component.createObject(playlistDialog, {
"name": thumbnailJobs[0]
})
if (String(titleJobs[0]).indexOf("://") !== -1) {
thumbnailerProcess.start(
"youtube-dl",
thumbnailerProcess.start("youtube-dl",
["--get-thumbnail", thumbnailJobs[0]])
} else {
thumbnailerProcess.start(
@ -85,8 +83,7 @@ Dialog {
var titleProcess = component.createObject(playlistDialog, {
"name": titleJobs[0]
})
titleProcess.start("youtube-dl",
["--get-title", titleJobs[0]])
titleProcess.start("youtube-dl", ["--get-title", titleJobs[0]])
titleJobs.shift()
titleJobsRunning += 1
}
@ -178,8 +175,7 @@ Dialog {
}
onClicked: {
player.playerCommand(Enums.Commands.SetPlaylistPos,
playlistPos)
player.playerCommand(Enums.Commands.SetPlaylistPos, playlistPos)
}
background: Rectangle {
color: current ? "orange" : "transparent"

View file

@ -12,7 +12,7 @@ Dialog {
width: 720
modality: Qt.NonModal
signal done;
signal done
ScrollView {
id: content
@ -30,7 +30,9 @@ Dialog {
text: translate.getTranslation("LANGUAGE", i18n.language)
verticalAlignment: Text.AlignVCenter
}
LanguageSettings { Layout.leftMargin: 30 }
LanguageSettings {
Layout.leftMargin: 30
}
Text {
height: 30
text: translate.getTranslation("APPEARANCE", i18n.language)
@ -39,7 +41,8 @@ Dialog {
CheckBox {
checked: appearance.titleOnlyOnFullscreen
onClicked: appearance.titleOnlyOnFullscreen = !appearance.titleOnlyOnFullscreen
text: translate.getTranslation("TITLE_ONLY_ON_FULLSCREEN", i18n.language)
text: translate.getTranslation("TITLE_ONLY_ON_FULLSCREEN",
i18n.language)
Layout.leftMargin: 30
}
CheckBox {
@ -55,7 +58,8 @@ Dialog {
Text {
id: seekByLabel
height: 30
text: translate.getTranslation("DOUBLE_TAP_TO_SEEK_BY", i18n.language)
text: translate.getTranslation("DOUBLE_TAP_TO_SEEK_BY",
i18n.language)
verticalAlignment: Text.AlignVCenter
}
TextField {
@ -110,7 +114,8 @@ Dialog {
inputMethodHints: Qt.ImhFormattedNumbersOnly
text: appearance.subtitlesFontSize
function setSubtitlesFontSize() {
appearance.subtitlesFontSize = parseInt(subtitlesFontSizeInput.text)
appearance.subtitlesFontSize = parseInt(
subtitlesFontSizeInput.text)
}
onEditingFinished: setSubtitlesFontSize()
}
@ -129,7 +134,9 @@ Dialog {
id: uiFadeTimeInput
anchors.left: uiFadeTimeLabel.right
anchors.leftMargin: 10
validator: IntValidator { bottom: 0 }
validator: IntValidator {
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
text: appearance.uiFadeTimer
function setUIFadeTime() {
@ -140,7 +147,6 @@ Dialog {
}
}
}
}
Connections {

View file

@ -7,7 +7,9 @@ ComboBox {
height: 30
editable: false
pressed: true
model: Object.keys(Translations.languages).map(function(key) {return Translations.languages[key];})
model: Object.keys(Translations.languages).map(function (key) {
return Translations.languages[key]
})
delegate: ItemDelegate {
height: 25
width: languageSelector.width
@ -22,7 +24,9 @@ ComboBox {
}
onActivated: {
console.warn(currentText)
i18n.language = Object.keys(Translations.languages).filter(function(key) {return Translations.languages[key] === currentText})[0];
i18n.language = Object.keys(Translations.languages).filter(function (key) {
return Translations.languages[key] === currentText
})[0]
}
Component.onCompleted: {
currentIndex = languageSelector.find(Translations.languages[i18n.language])

View file

@ -3,8 +3,7 @@ import QtQuick 2.0
Rectangle {
id: chapterMarker
property int time: 0
color: getAppearanceValueForTheme(appearance.themeName,
"chapterMarkerColor")
color: getAppearanceValueForTheme(appearance.themeName, "chapterMarkerColor")
width: 4
height: parent.height
x: progressBar.background.width / progressBar.to * time

View file

@ -7,8 +7,7 @@ Process {
if (String(name).indexOf("://") !== -1) {
playlistDialog.addThumbnailToCache(name, getOutput())
} else {
playlistDialog.addThumbnailToCache(name,
"/tmp/" + Qt.md5(name) + ".png")
playlistDialog.addThumbnailToCache(name, "/tmp/" + Qt.md5(name) + ".png")
}
}
}

View file

@ -44,16 +44,14 @@ MenuBar {
var track = newTracks[i]
var trackID = track["id"]
var trackType = track["type"]
var trackLang = LanguageCodes.localeCodeToEnglish(
String(track["lang"]))
var trackLang = LanguageCodes.localeCodeToEnglish(String(track["lang"]))
trackLang = trackLang == undefined ? "" : trackLang
var trackTitle = track["title"] == undefined ? "" : track["title"] + " "
var component = Qt.createComponent("TrackItem.qml")
if (trackType == "sub") {
var action = component.createObject(subMenu, {
"text": trackLang,
"trackID": String(
trackID),
"trackID": String(trackID),
"trackType": "sid",
"checked": track["selected"]
})
@ -62,8 +60,7 @@ MenuBar {
} else if (trackType == "audio") {
var action = component.createObject(audioMenu, {
"text": trackTitle + trackLang,
"trackID": String(
trackID),
"trackID": String(trackID),
"trackType": "aid",
"checked": track["selected"]
})
@ -72,8 +69,7 @@ MenuBar {
} else if (trackType == "video") {
var action = component.createObject(videoMenu, {
"text": "Video " + trackID + trackTitle,
"trackID": String(
trackID),
"trackID": String(trackID),
"trackType": "vid",
"checked": track["selected"]
})
@ -89,8 +85,7 @@ MenuBar {
nameFilters: ["All files (*)"]
selectMultiple: false
onAccepted: {
player.playerCommand(Enums.Commands.LoadFile,
String(fileDialog.fileUrl))
player.playerCommand(Enums.Commands.LoadFile, String(fileDialog.fileUrl))
fileDialog.close()
}
onRejected: {
@ -108,8 +103,7 @@ MenuBar {
}
TextField {
id: pathText
placeholderText: translate.getTranslation("URL_FILE_PATH",
i18n.language)
placeholderText: translate.getTranslation("URL_FILE_PATH", i18n.language)
}
}
@ -164,8 +158,7 @@ MenuBar {
background: Rectangle {
width: parent.width
implicitHeight: 10
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
}
CustomMenu {
@ -233,16 +226,14 @@ MenuBar {
shortcut: keybinds.forward5
}
Action {
text: translate.getTranslation("SPEED_DECREASE_POINT_ONE",
i18n.language)
text: translate.getTranslation("SPEED_DECREASE_POINT_ONE", i18n.language)
onTriggered: {
player.playerCommand(Enums.Commands.SubtractSpeed, 0.1)
}
shortcut: keybinds.decreaseSpeedByPointOne
}
Action {
text: translate.getTranslation("SPEED_INCREASE_POINT_ONE",
i18n.language)
text: translate.getTranslation("SPEED_INCREASE_POINT_ONE", i18n.language)
onTriggered: {
player.playerCommand(Enums.Commands.AddSpeed, 0.1)
}
@ -472,8 +463,7 @@ MenuBar {
shortcut: keybinds.nyanCat
}
Action {
text: translate.getTranslation("TOGGLE_ALWAYS_ON_TOP",
i18n.language)
text: translate.getTranslation("TOGGLE_ALWAYS_ON_TOP", i18n.language)
onTriggered: {
player.toggleOnTop()
}

View file

@ -30,8 +30,7 @@ Item {
Rectangle {
height: menuBar.height
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
anchors {
right: parent.right
left: menuBar.right
@ -54,8 +53,7 @@ Item {
font {
family: appearance.fontName
bold: true
pixelSize: appearance.scaleFactor * (height - anchors.topMargin
- anchors.bottomMargin - 2)
pixelSize: appearance.scaleFactor * (height - anchors.topMargin - anchors.bottomMargin - 2)
}
anchors {
left: parent.left

View file

@ -3,7 +3,8 @@ import player 1.0
SmoothButton {
property var playing: Enums.PlayStatus.Playing
iconSource: "icons/" + appearance.themeName + (playing == Enums.PlayStatus.Playing ? "/pause.svg" : "/play.svg")
iconSource: "icons/" + appearance.themeName
+ (playing == Enums.PlayStatus.Playing ? "/pause.svg" : "/play.svg")
onClicked: {
player.playerCommand(Enums.Commands.TogglePlayPause)
}

View file

@ -4,7 +4,7 @@ SmoothButton {
id: settingsButton
iconSource: "icons/" + appearance.themeName + "/settings.svg"
onClicked: {
switch(appearance.themeName) {
switch (appearance.themeName) {
case "YouTube":
appearance.themeName = "RoosterTeeth"
break

View file

@ -20,8 +20,10 @@ Control {
id: buttonImage
smooth: false
fillMode: Image.PreserveAspectFit
sourceSize.height: Math.floor(root.parent.height / (appearance.themeName == "Niconico" ? 1.8 : 1.25))
sourceSize.width: Math.floor(root.parent.height / (appearance.themeName == "Niconico" ? 1.8 : 1.25))
sourceSize.height: Math.floor(
root.parent.height / (appearance.themeName == "Niconico" ? 1.8 : 1.25))
sourceSize.width: Math.floor(
root.parent.height / (appearance.themeName == "Niconico" ? 1.8 : 1.25))
}
ColorOverlay {
id: colorOverlay
@ -38,7 +40,6 @@ Control {
}
}
MouseArea {
id: mouseArea
anchors.fill: parent

View file

@ -18,8 +18,7 @@ Rectangle {
implicitWidth: Math.max(
background ? background.implicitWidth : 0,
(handle ? handle.implicitWidth : 0) + leftPadding + rightPadding)
implicitHeight: Math.max(
background.implicitHeight,
implicitHeight: Math.max(background.implicitHeight,
handle.implicitHeight + topPadding + bottomPadding)
padding: 6

View file

@ -17,8 +17,7 @@ Slider {
width: hoverProgressLabel.width
height: hoverProgressLabel.height
z: 100
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
Text {
id: hoverProgressLabel
text: "0:00"
@ -92,7 +91,8 @@ Slider {
onPositionChanged: {
// code taken from https://github.com/qt/qtquickcontrols2/blob/39892547145ba4e73bebee86352bd384732b5d19/src/quicktemplates2/qquickslider.cpp#L138
var a = ((mouseAreaProgressBar.mouseX - (handleRect.width / 2)) / (progressBar.availableWidth - handleRect.width)) * progressBar.to
var a = ((mouseAreaProgressBar.mouseX - (handleRect.width / 2))
/ (progressBar.availableWidth - handleRect.width)) * progressBar.to
hoverProgressLabel.text = utils.createTimestamp(a)
timestampBox.x = mouseAreaProgressBar.mouseX - (timestampBox.width / 2)
timestampBox.y = progressBackground.y - timestampBox.height * 2
@ -105,8 +105,8 @@ Slider {
id: progressBackground
z: 30
width: progressBar.availableWidth
height: progressBar.getProgressBarHeight(
fun.nyanCat, mouseAreaProgressBar.containsMouse)
height: progressBar.getProgressBarHeight(fun.nyanCat,
mouseAreaProgressBar.containsMouse)
color: getAppearanceValueForTheme(appearance.themeName,
"progressBackgroundColor")

View file

@ -9,7 +9,7 @@ SmoothButton {
}
Connections {
target: player
onVolumeStatusChanged: function(status) {
onVolumeStatusChanged: function (status) {
if (status == Enums.VolumeStatus.Muted) {
volumeButton.iconSource = "qrc:/icons/" + appearance.themeName + "/volume-mute.svg"
} else if (status == Enums.VolumeStatus.Low) {

View file

@ -52,17 +52,15 @@ Slider {
"volumeSliderBackground")
}
MouseArea {
acceptedButtons: Qt.NoButton
z: 10
anchors.fill: parent
propagateComposedEvents: true
onWheel: {
if (wheel.angleDelta.y<0){
if (wheel.angleDelta.y < 0) {
volumeBar.value -= 5
}
else {
} else {
volumeBar.value += 5
}
}

View file

@ -2,14 +2,13 @@ import QtQuick 2.0
import "translations.js" as Translations
Item {
function getTranslation(code, language) {
var lang = Translations.translations[language]
if (lang == undefined || lang == "undefined") {
return "TranslationNotFound"
}
var text = String(Translations.translations[i18n.language][code])
if (text == "undefined"){
if (text == "undefined") {
console.warn(code, "missing for language", language)
}
var args = Array.prototype.slice.call(arguments, 1)

View file

@ -25,8 +25,8 @@ Window {
}
function getAppearanceValueForTheme(themeName, name) {
switch(themeName) {
case"YouTube":
switch (themeName) {
case "YouTube":
return youTubeAppearance[name]
case "Niconico":
return nicoNicoAppearance[name]
@ -256,12 +256,11 @@ Window {
argument = argument.substr(2)
if (argument.length > 0) {
var splitArg = argument.split(/=(.+)/)
if (splitArg[0] == "screen"
|| splitArg[0] == "fs-screen") {
if (splitArg[0] == "screen" || splitArg[0] == "fs-screen") {
for (var i = 0, len = Qt.application.screens.length; i < len; i++) {
var screen = Qt.application.screens[i]
console.log("Screen Name: " + screen["name"]
+ " Screen Number: " + String(
console.log(
"Screen Name: " + screen["name"] + " Screen Number: " + String(
i))
if (screen["name"] == splitArg[1] || String(
i) == splitArg[1]) {
@ -269,10 +268,8 @@ Window {
mainWindow.screen = screen
mainWindow.width = mainWindow.screen.width / 2
mainWindow.height = mainWindow.screen.height / 2
mainWindow.x = mainWindow.screen.virtualX
+ mainWindow.width / 2
mainWindow.y = mainWindow.screen.virtualY
+ mainWindow.height / 2
mainWindow.x = mainWindow.screen.virtualX + mainWindow.width / 2
mainWindow.y = mainWindow.screen.virtualY + mainWindow.height / 2
if (splitArg[0] == "fs-screen") {
toggleFullscreen()
}
@ -285,15 +282,13 @@ Window {
toggleFullscreen()
continue
}
if (splitArg[1] == undefined
|| splitArg[1].length == 0) {
if (splitArg[1] == undefined || splitArg[1].length == 0) {
splitArg[1] = "yes"
}
player.setOption(splitArg[0], splitArg[1])
}
} else {
player.playerCommand(Enums.Commands.AppendFile,
argument)
player.playerCommand(Enums.Commands.AppendFile, argument)
}
}
}
@ -369,11 +364,11 @@ Window {
function doubleMouseClick(mouse) {
if (appearance.doubleTapToSeek) {
if (mouse.x > (mouseAreaPlayer.width / 2)) {
player.playerCommand(Enums.Commands.Seek, String(
appearance.doubleTapToSeekBy))
player.playerCommand(Enums.Commands.Seek,
String(appearance.doubleTapToSeekBy))
} else {
player.playerCommand(Enums.Commands.Seek, "-" + String(
appearance.doubleTapToSeekBy))
player.playerCommand(Enums.Commands.Seek,
"-" + String(appearance.doubleTapToSeekBy))
}
} else {
toggleFullscreen()
@ -391,7 +386,8 @@ Window {
}
}
onReleased: {
var isLongEnough = Math.sqrt(xStart*xStart, mouse.x*mouse.x) > mainWindow.width * 0.3
var isLongEnough = Math.sqrt(xStart * xStart,
mouse.x * mouse.x) > mainWindow.width * 0.3
if (velocity > 2 && isLongEnough) {
appearance.scaleFactor += 0.2
} else if (velocity < -2 && isLongEnough) {
@ -421,10 +417,10 @@ Window {
Timer {
id: mouseAreaPlayerTimer
interval: appearance.uiFadeTimer
running: (! appearance.uiFadeTimer == 0)
running: (!appearance.uiFadeTimer == 0)
repeat: false
onTriggered: {
if (! (appearance.uiFadeTimer == 0) ) {
if (!(appearance.uiFadeTimer == 0)) {
globalConnections.hideUI()
}
}

View file

@ -2,11 +2,10 @@
#define QMLDEBUGGER_H
#include <QQuickItem>
#include <QVariant>
#include <QString>
#include <QVariant>
class QMLDebugger : public QObject
{
class QMLDebugger : public QObject {
Q_OBJECT
public:
Q_INVOKABLE static QString properties(QQuickItem* item,

View file

@ -5,26 +5,29 @@
#include <cstring>
#include <QVariant>
#include <QString>
#include <QList>
#include <QHash>
#include <QSharedPointer>
#include <QList>
#include <QMetaType>
#include <QSharedPointer>
#include <QString>
#include <QVariant>
namespace mpv {
namespace qt {
// Wrapper around mpv_handle. Does refcounting under the hood.
class Handle
{
// Wrapper around mpv_handle. Does refcounting under the hood.
class Handle {
struct container {
container(mpv_handle *h) : mpv(h) {}
container(mpv_handle* h)
: mpv(h)
{
}
~container() { mpv_terminate_destroy(mpv); }
mpv_handle *mpv;
mpv_handle* mpv;
};
QSharedPointer<container> sptr;
public:
public:
// Construct a new Handle from a raw mpv_handle with refcount 1. If the
// last Handle goes out of scope, the mpv_handle will be destroyed with
// mpv_terminate_destroy().
@ -33,7 +36,8 @@ public:
// destroying the mpv_handle.
// Never create multiple wrappers from the same raw mpv_handle; copy the
// wrapper instead (that's what it's for).
static Handle FromRawHandle(mpv_handle *handle) {
static Handle FromRawHandle(mpv_handle* handle)
{
Handle h;
h.sptr = QSharedPointer<container>(new container(handle));
return h;
@ -41,10 +45,10 @@ public:
// Return the raw handle; for use with the libmpv C API.
operator mpv_handle*() const { return sptr ? (*sptr).mpv : 0; }
};
};
static inline QVariant node_to_variant(const mpv_node *node)
{
static inline QVariant node_to_variant(const mpv_node* node)
{
switch (node->format) {
case MPV_FORMAT_STRING:
return QVariant(QString::fromUtf8(node->u.string));
@ -55,14 +59,14 @@ static inline QVariant node_to_variant(const mpv_node *node)
case MPV_FORMAT_DOUBLE:
return QVariant(node->u.double_);
case MPV_FORMAT_NODE_ARRAY: {
mpv_node_list *list = node->u.list;
mpv_node_list* list = node->u.list;
QVariantList qlist;
for (int n = 0; n < list->num; n++)
qlist.append(node_to_variant(&list->values[n]));
return QVariant(qlist);
}
case MPV_FORMAT_NODE_MAP: {
mpv_node_list *list = node->u.list;
mpv_node_list* list = node->u.list;
QVariantMap qmap;
for (int n = 0; n < list->num; n++) {
qmap.insert(QString::fromUtf8(list->keys[n]),
@ -73,22 +77,26 @@ static inline QVariant node_to_variant(const mpv_node *node)
default: // MPV_FORMAT_NONE, unknown values (e.g. future extensions)
return QVariant();
}
}
}
struct node_builder {
node_builder(const QVariant& v) {
struct node_builder {
node_builder(const QVariant& v)
{
set(&node_, v);
}
~node_builder() {
~node_builder()
{
free_node(&node_);
}
mpv_node *node() { return &node_; }
private:
mpv_node* node() { return &node_; }
private:
Q_DISABLE_COPY(node_builder)
mpv_node node_;
mpv_node_list *create_list(mpv_node *dst, bool is_map, int num) {
mpv_node_list* create_list(mpv_node* dst, bool is_map, int num)
{
dst->format = is_map ? MPV_FORMAT_NODE_MAP : MPV_FORMAT_NODE_ARRAY;
mpv_node_list *list = new mpv_node_list();
mpv_node_list* list = new mpv_node_list();
dst->u.list = list;
if (!list)
goto err;
@ -105,21 +113,24 @@ private:
free_node(dst);
return NULL;
}
char *dup_qstring(const QString &s) {
char* dup_qstring(const QString& s)
{
QByteArray b = s.toUtf8();
char *r = new char[b.size() + 1];
char* r = new char[b.size() + 1];
if (r)
std::memcpy(r, b.data(), b.size() + 1);
return r;
}
bool test_type(const QVariant &v, QMetaType::Type t) {
bool test_type(const QVariant& v, QMetaType::Type t)
{
// The Qt docs say: "Although this function is declared as returning
// "QVariant::Type(obsolete), the return value should be interpreted
// as QMetaType::Type."
// So a cast really seems to be needed to avoid warnings (urgh).
return static_cast<int>(v.type()) == static_cast<int>(t);
}
void set(mpv_node *dst, const QVariant &src) {
void set(mpv_node* dst, const QVariant& src)
{
if (test_type(src, QMetaType::QString)) {
dst->format = MPV_FORMAT_STRING;
dst->u.string = dup_qstring(src.toString());
@ -128,11 +139,7 @@ private:
} else if (test_type(src, QMetaType::Bool)) {
dst->format = MPV_FORMAT_FLAG;
dst->u.flag = src.toBool() ? 1 : 0;
} else if (test_type(src, QMetaType::Int) ||
test_type(src, QMetaType::LongLong) ||
test_type(src, QMetaType::UInt) ||
test_type(src, QMetaType::ULongLong))
{
} else if (test_type(src, QMetaType::Int) || test_type(src, QMetaType::LongLong) || test_type(src, QMetaType::UInt) || test_type(src, QMetaType::ULongLong)) {
dst->format = MPV_FORMAT_INT64;
dst->u.int64 = src.toLongLong();
} else if (test_type(src, QMetaType::Double)) {
@ -140,7 +147,7 @@ private:
dst->u.double_ = src.toDouble();
} else if (src.canConvert<QVariantList>()) {
QVariantList qlist = src.toList();
mpv_node_list *list = create_list(dst, false, qlist.size());
mpv_node_list* list = create_list(dst, false, qlist.size());
if (!list)
goto fail;
list->num = qlist.size();
@ -148,7 +155,7 @@ private:
set(&list->values[n], qlist[n]);
} else if (src.canConvert<QVariantMap>()) {
QVariantMap qmap = src.toMap();
mpv_node_list *list = create_list(dst, true, qmap.size());
mpv_node_list* list = create_list(dst, true, qmap.size());
if (!list)
goto fail;
list->num = qmap.size();
@ -167,14 +174,15 @@ private:
fail:
dst->format = MPV_FORMAT_NONE;
}
void free_node(mpv_node *dst) {
void free_node(mpv_node* dst)
{
switch (dst->format) {
case MPV_FORMAT_STRING:
delete[] dst->u.string;
break;
case MPV_FORMAT_NODE_ARRAY:
case MPV_FORMAT_NODE_MAP: {
mpv_node_list *list = dst->u.list;
mpv_node_list* list = dst->u.list;
if (list) {
for (int n = 0; n < list->num; n++) {
if (list->keys)
@ -188,22 +196,25 @@ private:
delete list;
break;
}
default: ;
default:;
}
dst->format = MPV_FORMAT_NONE;
}
};
};
/**
/**
* RAII wrapper that calls mpv_free_node_contents() on the pointer.
*/
struct node_autofree {
mpv_node *ptr;
node_autofree(mpv_node *a_ptr) : ptr(a_ptr) {}
struct node_autofree {
mpv_node* ptr;
node_autofree(mpv_node* a_ptr)
: ptr(a_ptr)
{
}
~node_autofree() { mpv_free_node_contents(ptr); }
};
};
/**
/**
* Return the given property as mpv_node converted to QVariant, or QVariant()
* on error.
*
@ -211,131 +222,136 @@ struct node_autofree {
*
* @param name the property name
*/
static inline QVariant get_property_variant(mpv_handle *ctx, const QString &name)
{
static inline QVariant get_property_variant(mpv_handle* ctx, const QString& name)
{
mpv_node node;
if (mpv_get_property(ctx, name.toUtf8().data(), MPV_FORMAT_NODE, &node) < 0)
return QVariant();
node_autofree f(&node);
return node_to_variant(&node);
}
}
/**
/**
* Set the given property as mpv_node converted from the QVariant argument.
* @deprecated use set_property() instead
*/
static inline int set_property_variant(mpv_handle *ctx, const QString &name,
const QVariant &v)
{
static inline int set_property_variant(mpv_handle* ctx, const QString& name,
const QVariant& v)
{
node_builder node(v);
return mpv_set_property(ctx, name.toUtf8().data(), MPV_FORMAT_NODE, node.node());
}
}
/**
/**
* Set the given option as mpv_node converted from the QVariant argument.
*
* @deprecated use set_property() instead
*/
static inline int set_option_variant(mpv_handle *ctx, const QString &name,
const QVariant &v)
{
static inline int set_option_variant(mpv_handle* ctx, const QString& name,
const QVariant& v)
{
node_builder node(v);
return mpv_set_option(ctx, name.toUtf8().data(), MPV_FORMAT_NODE, node.node());
}
}
/**
/**
* mpv_command_node() equivalent. Returns QVariant() on error (and
* unfortunately, the same on success).
*
* @deprecated use command() instead
*/
static inline QVariant command_variant(mpv_handle *ctx, const QVariant &args)
{
static inline QVariant command_variant(mpv_handle* ctx, const QVariant& args)
{
node_builder node(args);
mpv_node res;
if (mpv_command_node(ctx, node.node(), &res) < 0)
return QVariant();
node_autofree f(&res);
return node_to_variant(&res);
}
}
/**
/**
* This is used to return error codes wrapped in QVariant for functions which
* return QVariant.
*
* You can use get_error() or is_error() to extract the error status from a
* QVariant value.
*/
struct ErrorReturn
{
struct ErrorReturn {
/**
* enum mpv_error value (or a value outside of it if ABI was extended)
*/
int error;
ErrorReturn() : error(0) {}
explicit ErrorReturn(int err) : error(err) {}
};
ErrorReturn()
: error(0)
{
}
explicit ErrorReturn(int err)
: error(err)
{
}
};
/**
/**
* Return the mpv error code packed into a QVariant, or 0 (success) if it's not
* an error value.
*
* @return error code (<0) or success (>=0)
*/
static inline int get_error(const QVariant &v)
{
static inline int get_error(const QVariant& v)
{
if (!v.canConvert<ErrorReturn>())
return 0;
return v.value<ErrorReturn>().error;
}
}
/**
/**
* Return whether the QVariant carries a mpv error code.
*/
static inline bool is_error(const QVariant &v)
{
static inline bool is_error(const QVariant& v)
{
return get_error(v) < 0;
}
}
/**
/**
* Return the given property as mpv_node converted to QVariant, or QVariant()
* on error.
*
* @param name the property name
* @return the property value, or an ErrorReturn with the error code
*/
static inline QVariant get_property(mpv_handle *ctx, const QString &name)
{
static inline QVariant get_property(mpv_handle* ctx, const QString& name)
{
mpv_node node;
int err = mpv_get_property(ctx, name.toUtf8().data(), MPV_FORMAT_NODE, &node);
if (err < 0)
return QVariant::fromValue(ErrorReturn(err));
node_autofree f(&node);
return node_to_variant(&node);
}
}
/**
/**
* Set the given property as mpv_node converted from the QVariant argument.
*
* @return mpv error code (<0 on error, >= 0 on success)
*/
static inline int set_property(mpv_handle *ctx, const QString &name,
const QVariant &v)
{
static inline int set_property(mpv_handle* ctx, const QString& name,
const QVariant& v)
{
node_builder node(v);
return mpv_set_property(ctx, name.toUtf8().data(), MPV_FORMAT_NODE, node.node());
}
}
/**
/**
* mpv_command_node() equivalent.
*
* @param args command arguments, with args[0] being the command name as string
* @return the property value, or an ErrorReturn with the error code
*/
static inline QVariant command(mpv_handle *ctx, const QVariant &args)
{
static inline QVariant command(mpv_handle* ctx, const QVariant& args)
{
node_builder node(args);
mpv_node res;
int err = mpv_command_node(ctx, node.node(), &res);
@ -343,8 +359,7 @@ static inline QVariant command(mpv_handle *ctx, const QVariant &args)
return QVariant::fromValue(ErrorReturn(err));
node_autofree f(&res);
return node_to_variant(&res);
}
}
}
}

View file

@ -9,10 +9,10 @@
#include "utils.hpp"
#include <QSettings>
void registerTypes() {
void registerTypes()
{
QSettings settings;
qmlRegisterUncreatableMetaObject(
Enums::staticMetaObject, "player", 1, 0, "Enums", "Error: only enums");
qRegisterMetaType<Enums::PlayStatus>("Enums.PlayStatus");

View file

@ -36,8 +36,7 @@
#include <stdlib.h>
#include <string.h>
int
setenv(const char* var, const char* value, int overwrite)
int setenv(const char* var, const char* value, int overwrite)
{
/* Core implementation for both setenv() and unsetenv() functions;
* at the outset, assume that the requested operation may fail.

View file

@ -1,19 +1,19 @@
#include "utils.hpp"
#include "logger.h"
#include "spdlog/logger.h"
#include <QApplication>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QProcess>
#include <QStringList>
#include <memory>
#include "logger.h"
#include "spdlog/logger.h"
#if (defined(__linux__) || defined(__FreeBSD__)) && ENABLE_X11
#include <QX11Info> // IWYU pragma: keep
#include <X11/X.h> // IWYU pragma: keep
#include <X11/Xlib.h> // IWYU pragma: keep
#include <X11/Xutil.h> // IWYU pragma: keep
#include <qx11info_x11.h> // IWYU pragma: keep
#include <QX11Info> // IWYU pragma: keep
#undef Bool
#endif
@ -23,24 +23,19 @@ namespace Utils {
QString
getPlatformName()
{
QGuiApplication* qapp =
qobject_cast<QGuiApplication*>(QCoreApplication::instance());
QGuiApplication* qapp = qobject_cast<QGuiApplication*>(QCoreApplication::instance());
return qapp->platformName();
}
void
launchAboutQt()
void launchAboutQt()
{
QApplication* qapp =
qobject_cast<QApplication*>(QCoreApplication::instance());
QApplication* qapp = qobject_cast<QApplication*>(QCoreApplication::instance());
qapp->aboutQt();
}
void updateAppImage()
{
QString program =
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
"/usr/bin/appimageupdatetool";
QString program = QProcessEnvironment::systemEnvironment().value("APPDIR", "") + "/usr/bin/appimageupdatetool";
QProcess updater;
updater.setProcessChannelMode(QProcess::ForwardedChannels);
updater.start(program,
@ -72,8 +67,7 @@ createTimestamp(const int seconds)
}
}
void
SetScreensaver(WId wid, bool on)
void SetScreensaver(WId wid, bool on)
{
QProcess xdgScreensaver;
xdgScreensaver.setProcessChannelMode(QProcess::ForwardedChannels);
@ -89,8 +83,7 @@ SetScreensaver(WId wid, bool on)
xdgScreensaver.waitForFinished();
}
void
SetDPMS(bool on)
void SetDPMS(bool on)
{
#if defined(__linux__) || defined(__FreeBSD__)
if (getPlatformName() != "xcb") {
@ -118,8 +111,7 @@ SetDPMS(bool on)
#endif
}
void
AlwaysOnTop(WId wid, bool on)
void AlwaysOnTop(WId wid, bool on)
{
#if (defined(__linux__) || defined(__FreeBSD__)) && ENABLE_X11
Display* display = QX11Info::display();
@ -149,4 +141,3 @@ AlwaysOnTop(WId wid, bool on)
#endif
}
}

View file

@ -6,22 +6,16 @@
namespace Utils {
Q_NAMESPACE
void
SetDPMS(bool on);
void
SetScreensaver(WId wid, bool on);
void
AlwaysOnTop(WId wid, bool on);
void SetDPMS(bool on);
void SetScreensaver(WId wid, bool on);
void AlwaysOnTop(WId wid, bool on);
QString
createTimestamp(int seconds);
void
launchAboutQt();
void
updateAppImage();
void launchAboutQt();
void updateAppImage();
}
class UtilsClass : public QObject
{
class UtilsClass : public QObject {
Q_OBJECT
public slots:
void SetDPMS(bool on) { Utils::SetDPMS(on); };
@ -29,7 +23,6 @@ public slots:
void launchAboutQt() { Utils::launchAboutQt(); };
void updateAppImage() { Utils::updateAppImage(); };
QString createTimestamp(int seconds)
{
return Utils::createTimestamp(seconds);