1
0
Fork 0

[UI+Backend] Improved logging and added preview on progress bar hover.

This commit is contained in:
NamedKitten 2018-12-12 08:28:53 +00:00
parent fc31931cd4
commit 1dea7dfff9
9 changed files with 120 additions and 40 deletions

View file

@ -75,7 +75,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent)
if (!mpv) if (!mpv)
throw std::runtime_error("could not create mpv context"); throw std::runtime_error("could not create mpv context");
mpv_set_option_string(mpv, "terminal", "yes"); mpv_set_option_string(mpv, "terminal", "no");
mpv_set_option_string(mpv, "msg-level", "all=v"); mpv_set_option_string(mpv, "msg-level", "all=v");
// Fix? // Fix?

View file

@ -38,6 +38,7 @@ class DirectMpvPlayerBackend
Q_INTERFACES(BackendInterface) Q_INTERFACES(BackendInterface)
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool logging READ logging WRITE setLogging)
mpv_handle* mpv; mpv_handle* mpv;
mpv_opengl_cb_context* mpv_gl; mpv_opengl_cb_context* mpv_gl;
@ -45,6 +46,7 @@ class DirectMpvPlayerBackend
bool onTop = false; bool onTop = false;
int lastTime = 0; int lastTime = 0;
double lastSpeed = 0; double lastSpeed = 0;
bool m_logging = true;
QString totalDurationString; QString totalDurationString;
QString lastPositionString; QString lastPositionString;
QSettings settings; QSettings settings;
@ -52,6 +54,14 @@ class DirectMpvPlayerBackend
public: public:
static void on_update(void* ctx); static void on_update(void* ctx);
void setLogging(bool a)
{
if (a != m_logging) {
m_logging = a;
}
}
bool logging() const { return m_logging; }
DirectMpvPlayerBackend(QQuickItem* parent = 0); DirectMpvPlayerBackend(QQuickItem* parent = 0);
virtual ~DirectMpvPlayerBackend(); virtual ~DirectMpvPlayerBackend();

View file

@ -133,7 +133,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
if (!mpv) if (!mpv)
throw std::runtime_error("could not create mpv context"); throw std::runtime_error("could not create mpv context");
mpv_set_option_string(mpv, "terminal", "on"); mpv_set_option_string(mpv, "terminal", "off");
mpv_set_option_string(mpv, "msg-level", "all=v"); mpv_set_option_string(mpv, "msg-level", "all=v");
// Fix? // Fix?
@ -396,6 +396,13 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
break; break;
} }
case Enums::Commands::ForcePause: {
command(QVariantList() << "set" << "pause" << "yes");
break;
}
default: { default: {
qDebug() << "Command not found: " << cmd; qDebug() << "Command not found: " << cmd;
break; break;
@ -556,6 +563,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} }
case MPV_EVENT_LOG_MESSAGE: { case MPV_EVENT_LOG_MESSAGE: {
if (m_logging) {
struct mpv_event_log_message* msg = struct mpv_event_log_message* msg =
(struct mpv_event_log_message*)event->data; (struct mpv_event_log_message*)event->data;
QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text); QString logMsg = "[" + QString(msg->prefix) + "] " + QString(msg->text);
@ -565,6 +573,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
} else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) { } else if (msgLevel.startsWith("v") || msgLevel.startsWith("i")) {
mpvLogger->info("{}", logMsg.toUtf8().constData()); mpvLogger->info("{}", logMsg.toUtf8().constData());
} }
}
break; break;
} }

View file

@ -24,11 +24,14 @@ class MpvPlayerBackend
Q_INTERFACES(BackendInterface) Q_INTERFACES(BackendInterface)
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool logging READ logging WRITE setLogging)
mpv_handle* mpv; mpv_handle* mpv;
mpv_render_context* mpv_gl; mpv_render_context* mpv_gl;
QSettings settings; QSettings settings;
bool onTop = false; bool onTop = false;
bool m_logging = true;
int lastTime = 0; int lastTime = 0;
double lastSpeed = 0; double lastSpeed = 0;
QString totalDurationString; QString totalDurationString;
@ -43,6 +46,14 @@ public:
virtual ~MpvPlayerBackend(); virtual ~MpvPlayerBackend();
virtual Renderer* createRenderer() const; virtual Renderer* createRenderer() const;
void setLogging(bool a)
{
if (a != m_logging) {
m_logging = a;
}
}
bool logging() const { return m_logging; }
public slots: public slots:
QVariant playerCommand(const Enums::Commands& command, const QVariant& args); QVariant playerCommand(const Enums::Commands& command, const QVariant& args);
QVariant playerCommand(const Enums::Commands& command); QVariant playerCommand(const Enums::Commands& command);
@ -60,7 +71,6 @@ signals:
void onUpdate(); void onUpdate();
void mpv_events(); void mpv_events();
void onMpvEvent(mpv_event* event); void onMpvEvent(mpv_event* event);
// All below required for Player API // All below required for Player API
void playStatusChanged(const Enums::PlayStatus& status); void playStatusChanged(const Enums::PlayStatus& status);
void volumeStatusChanged(const Enums::VolumeStatus& status); void volumeStatusChanged(const Enums::VolumeStatus& status);

View file

@ -44,6 +44,7 @@ enum class Commands : int
BackwardFrame = 20, BackwardFrame = 20,
SetTrack = 21, SetTrack = 21,
SetPlaylistPos = 22, SetPlaylistPos = 22,
ForcePause = 23,
}; };
Q_ENUM_NS(Commands) Q_ENUM_NS(Commands)
enum class Backends : int enum class Backends : int

View file

@ -2,18 +2,24 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QSettings>
#include <iostream> #include <iostream>
std::shared_ptr<spdlog::logger> std::shared_ptr<spdlog::logger>
initLogger(std::string name) initLogger(std::string name)
{ {
QSettings settings("KittehPlayer", "KittehPlayer");
QString logFile = settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString();
std::vector<spdlog::sink_ptr> sinks; 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::stdout_color_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>( sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(
"/tmp/KittehPlayer.log")); logFile.toUtf8().constData()));
auto console = auto console =
std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks)); std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
console->set_pattern("%^[%d-%m-%Y %T.%e][%l][%n] %v%$"); console->set_pattern("%^[%d-%m-%Y %T.%e][%l][%n] %v%$");
console->error(logFile.toUtf8().constData());
spdlog::register_logger(console); spdlog::register_logger(console);

View file

@ -87,7 +87,6 @@ main(int argc, char* argv[])
qInstallMessageHandler(spdLogger); qInstallMessageHandler(spdLogger);
auto launcherLogger = initLogger("launcher"); auto launcherLogger = initLogger("launcher");
launcherLogger->info("Starting up!"); launcherLogger->info("Starting up!");
QString backendString; QString backendString;
@ -98,14 +97,16 @@ main(int argc, char* argv[])
#endif #endif
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1); setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
QApplication app(argc, argv); QApplication app(argc, argv);
#ifdef __linux__
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
#endif
app.setOrganizationName("KittehPlayer"); app.setOrganizationName("KittehPlayer");
app.setOrganizationDomain("namedkitten.pw"); app.setOrganizationDomain("namedkitten.pw");
app.setApplicationName("KittehPlayer"); app.setApplicationName("KittehPlayer");
#ifdef __linux__
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
#endif
QSettings settings; QSettings settings;
bool checkForUpdates = bool checkForUpdates =

View file

@ -10,6 +10,7 @@ import player 1.0
Slider { Slider {
id: progressBar id: progressBar
objectName: "progressBar" objectName: "progressBar"
property string currentMediaURL: ""
to: 1 to: 1
value: 0.0 value: 0.0
Connections { Connections {
@ -52,19 +53,24 @@ Slider {
} }
MouseArea { MouseArea {
id: mouseAreaProgressBar id: mouseAreaProgressBar
width: parent.width width: progressBar.width
height: parent.height height: parent.height
anchors.fill: parent anchors.fill: parent
y: parent.y
x: parent.x
hoverEnabled: true hoverEnabled: true
propagateComposedEvents: false propagateComposedEvents: false
acceptedButtons: Qt.NoButton acceptedButtons: Qt.NoButton
z: 1 z: 100
property string currentTime: ""
onEntered: progressBarTimePreview.visible = true
onExited: progressBarTimePreview.visible = false
onPositionChanged: { onPositionChanged: {
var a = (progressBar.to / progressBar.width) * mouseAreaProgressBar.mouseX var a = (progressBar.to / progressBar.availableWidth) * (mouseAreaProgressBar.mapToItem(progressBar, mouseAreaProgressBar.mouseX, 0).x - 2)
hoverProgressLabel.text = utils.createTimestamp(a) progressBarTimePreview.playerCommand(Enums.Commands.SeekAbsolute, a)
progressBarTimePreview.x = mouseAreaProgressBar.mapToItem(controlsOverlay, mouseAreaProgressBar.mouseX, 0).x - progressBarTimePreview.width / 2
progressBarTimePreview.y = progressBackground.y - progressBarTimePreview.height - controlsBar.height * 2
} }
} }
@ -75,29 +81,7 @@ Slider {
width: progressBar.availableWidth width: progressBar.availableWidth
height: progressBar.getProgressBarHeight( height: progressBar.getProgressBarHeight(
fun.nyanCat, mouseAreaProgressBar.containsMouse) fun.nyanCat, mouseAreaProgressBar.containsMouse)
color: getAppearanceValueForTheme(appearance.themeName, color: getAppearanceValueForTheme(appearance.themeName,"progressBackgroundColor")
"progressBackgroundColor")
Rectangle {
x: (mouseAreaProgressBar.mouseX - hoverProgressLabel.width / 2)
y: progressBackground.y - (hoverProgressLabel.height * 2)
visible: mouseAreaProgressBar.containsMouse
color: getAppearanceValueForTheme(appearance.themeName,
"mainBackground")
height: hoverProgressLabel.height
width: hoverProgressLabel.width
z: 80
Text {
id: hoverProgressLabel
text: "0:00"
color: "white"
padding: 2
font.family: appearance.fontName
font.pixelSize: mainWindow.virtualHeight / 50
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
}
}
ProgressBar { ProgressBar {
id: cachedLength id: cachedLength
@ -155,6 +139,7 @@ Slider {
} }
} }
handle: Rectangle { handle: Rectangle {
z: 70 z: 70
id: handleRect id: handleRect

View file

@ -34,6 +34,15 @@ Window {
id: translate id: translate
} }
Settings {
id: loggingSettings
category: "Logging"
property string logFile: "/tmp/KittehPlayer.log"
property bool logBackend: true
property bool logPreview: false
}
Settings { Settings {
id: backendSettings id: backendSettings
category: "Backend" category: "Backend"
@ -163,12 +172,15 @@ Window {
property int lastScreenVisibility property int lastScreenVisibility
function toggleFullscreen() { function toggleFullscreen() {
console.error("a", mainWindow.visibility, Window.FullScreen, lastScreenVisibility)
if (mainWindow.visibility != Window.FullScreen) { if (mainWindow.visibility != Window.FullScreen) {
lastScreenVisibility = mainWindow.visibility lastScreenVisibility = mainWindow.visibility
mainWindow.visibility = Window.FullScreen mainWindow.visibility = Window.FullScreen
} else { } else {
mainWindow.visibility = lastScreenVisibility mainWindow.visibility = lastScreenVisibility
} }
console.error("b", mainWindow.visibility, Window.FullScreen, lastScreenVisibility)
} }
Utils { Utils {
@ -181,6 +193,15 @@ Window {
width: parent.width width: parent.width
height: parent.height height: parent.height
z: 1 z: 1
logging: loggingSettings.logBackend
onPlaylistChanged: function (playlist) {
for (var thing in playlist) {
var item = playlist[thing]
if (playlist[thing]["current"]) {progressBarTimePreview.playerCommand(Enums.Commands.LoadFile, String(playlist[thing]["filename"]))}
progressBarTimePreview.playerCommand(Enums.Commands.ForcePause)
}
}
Action { Action {
onTriggered: { onTriggered: {
@ -376,9 +397,9 @@ Window {
width: parent.width width: parent.width
height: parent.height height: parent.height
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 10 anchors.leftMargin: 4
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 8 anchors.bottomMargin: 4
anchors.top: parent.top anchors.top: parent.top
font.family: appearance.fontName font.family: appearance.fontName
font.pixelSize: menuBar.height - (anchors.bottomMargin + anchors.topMargin) font.pixelSize: menuBar.height - (anchors.bottomMargin + anchors.topMargin)
@ -399,6 +420,43 @@ Window {
ControlsBar { ControlsBar {
id: controlsBar id: controlsBar
PlayerBackend {
id: progressBarTimePreview
height: 144
width: 256
z: 80
visible: true
logging: loggingSettings.logPreview
onDurationStringChanged: function (durationString) {
hoverProgressLabel.text = durationString
}
function startPlayer() {
update()
progressBarTimePreview.playerCommand(Enums.Commands.SetTrack, ["aid", "no"])
progressBarTimePreview.playerCommand(Enums.Commands.SetTrack, ["sid", "no"])
progressBarTimePreview.setOption("ytdl-format", "worstvideo[height<=?" + String(height) + "]/worst")
}
Rectangle {
anchors.bottom: parent.bottom
width: hoverProgressLabel.width
height: hoverProgressLabel.height
anchors.right: parent.right
color: getAppearanceValueForTheme(appearance.themeName, "mainBackground")
Text {
id: hoverProgressLabel
text: "0:00"
color: "white"
padding: 2
z: 90
font.family: appearance.fontName
font.pixelSize: mainWindow.virtualHeight / 50
verticalAlignment: Text.AlignVCenter
renderType: Text.NativeRendering
}
}
}
} }
} }
} }