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)
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");
// Fix?

View file

@ -38,6 +38,7 @@ class DirectMpvPlayerBackend
Q_INTERFACES(BackendInterface)
Q_OBJECT
Q_PROPERTY(bool logging READ logging WRITE setLogging)
mpv_handle* mpv;
mpv_opengl_cb_context* mpv_gl;
@ -45,6 +46,7 @@ class DirectMpvPlayerBackend
bool onTop = false;
int lastTime = 0;
double lastSpeed = 0;
bool m_logging = true;
QString totalDurationString;
QString lastPositionString;
QSettings settings;
@ -52,6 +54,14 @@ class DirectMpvPlayerBackend
public:
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);
virtual ~DirectMpvPlayerBackend();

View file

@ -133,7 +133,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
if (!mpv)
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");
// Fix?
@ -396,6 +396,13 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd,
break;
}
case Enums::Commands::ForcePause: {
command(QVariantList() << "set" << "pause" << "yes");
break;
}
default: {
qDebug() << "Command not found: " << cmd;
break;
@ -556,6 +563,7 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
}
case MPV_EVENT_LOG_MESSAGE: {
if (m_logging) {
struct mpv_event_log_message* msg =
(struct mpv_event_log_message*)event->data;
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")) {
mpvLogger->info("{}", logMsg.toUtf8().constData());
}
}
break;
}

View file

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

View file

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

View file

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

View file

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

View file

@ -10,6 +10,7 @@ import player 1.0
Slider {
id: progressBar
objectName: "progressBar"
property string currentMediaURL: ""
to: 1
value: 0.0
Connections {
@ -52,19 +53,24 @@ Slider {
}
MouseArea {
id: mouseAreaProgressBar
width: parent.width
width: progressBar.width
height: parent.height
anchors.fill: parent
y: parent.y
x: parent.x
hoverEnabled: true
propagateComposedEvents: false
acceptedButtons: Qt.NoButton
z: 1
z: 100
property string currentTime: ""
onEntered: progressBarTimePreview.visible = true
onExited: progressBarTimePreview.visible = false
onPositionChanged: {
var a = (progressBar.to / progressBar.width) * mouseAreaProgressBar.mouseX
hoverProgressLabel.text = utils.createTimestamp(a)
var a = (progressBar.to / progressBar.availableWidth) * (mouseAreaProgressBar.mapToItem(progressBar, mouseAreaProgressBar.mouseX, 0).x - 2)
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
height: progressBar.getProgressBarHeight(
fun.nyanCat, mouseAreaProgressBar.containsMouse)
color: getAppearanceValueForTheme(appearance.themeName,
"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
}
}
color: getAppearanceValueForTheme(appearance.themeName,"progressBackgroundColor")
ProgressBar {
id: cachedLength
@ -155,6 +139,7 @@ Slider {
}
}
handle: Rectangle {
z: 70
id: handleRect

View file

@ -34,6 +34,15 @@ Window {
id: translate
}
Settings {
id: loggingSettings
category: "Logging"
property string logFile: "/tmp/KittehPlayer.log"
property bool logBackend: true
property bool logPreview: false
}
Settings {
id: backendSettings
category: "Backend"
@ -163,12 +172,15 @@ Window {
property int lastScreenVisibility
function toggleFullscreen() {
console.error("a", mainWindow.visibility, Window.FullScreen, lastScreenVisibility)
if (mainWindow.visibility != Window.FullScreen) {
lastScreenVisibility = mainWindow.visibility
mainWindow.visibility = Window.FullScreen
} else {
mainWindow.visibility = lastScreenVisibility
}
console.error("b", mainWindow.visibility, Window.FullScreen, lastScreenVisibility)
}
Utils {
@ -181,6 +193,15 @@ Window {
width: parent.width
height: parent.height
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 {
onTriggered: {
@ -376,9 +397,9 @@ Window {
width: parent.width
height: parent.height
anchors.left: parent.left
anchors.leftMargin: 10
anchors.leftMargin: 4
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
anchors.bottomMargin: 4
anchors.top: parent.top
font.family: appearance.fontName
font.pixelSize: menuBar.height - (anchors.bottomMargin + anchors.topMargin)
@ -399,6 +420,43 @@ Window {
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
}
}
}
}
}
}