diff --git a/src/DirectMpvPlayerBackend.cpp b/src/DirectMpvPlayerBackend.cpp index ce66b8a..ef4f073 100644 --- a/src/DirectMpvPlayerBackend.cpp +++ b/src/DirectMpvPlayerBackend.cpp @@ -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? diff --git a/src/DirectMpvPlayerBackend.h b/src/DirectMpvPlayerBackend.h index 709c289..d06a348 100644 --- a/src/DirectMpvPlayerBackend.h +++ b/src/DirectMpvPlayerBackend.h @@ -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(); diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 2f5079e..e15fc9a 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -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? @@ -395,6 +395,13 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd, break; } + + case Enums::Commands::ForcePause: { + + command(QVariantList() << "set" << "pause" << "yes"); + + break; + } default: { qDebug() << "Command not found: " << cmd; @@ -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; } diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index f16ea84..324330f 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -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); diff --git a/src/enums.hpp b/src/enums.hpp index 71a1f74..83cdbd8 100644 --- a/src/enums.hpp +++ b/src/enums.hpp @@ -44,6 +44,7 @@ enum class Commands : int BackwardFrame = 20, SetTrack = 21, SetPlaylistPos = 22, + ForcePause = 23, }; Q_ENUM_NS(Commands) enum class Backends : int diff --git a/src/logger.cpp b/src/logger.cpp index 9b3c4dc..1a89d0b 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -2,18 +2,24 @@ #include #include +#include #include std::shared_ptr initLogger(std::string name) { + QSettings settings("KittehPlayer", "KittehPlayer"); + + QString logFile = settings.value("Logging/logFile", "/tmp/KittehPlayer.log").toString(); + std::vector sinks; sinks.push_back(std::make_shared()); sinks.push_back(std::make_shared( - "/tmp/KittehPlayer.log")); + logFile.toUtf8().constData())); auto console = std::make_shared(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); diff --git a/src/main.cpp b/src/main.cpp index 63a9bd6..76aaaca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,9 +87,8 @@ main(int argc, char* argv[]) qInstallMessageHandler(spdLogger); auto launcherLogger = initLogger("launcher"); - launcherLogger->info("Starting up!"); - + QString backendString; #ifdef DISABLE_MpvPlayerBackend Enums::Backends backend = Enums::Backends::DirectMpvBackend; @@ -98,13 +97,15 @@ 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; diff --git a/src/qml/UIComponents/VideoProgress.qml b/src/qml/UIComponents/VideoProgress.qml index b8c6664..833e8ea 100644 --- a/src/qml/UIComponents/VideoProgress.qml +++ b/src/qml/UIComponents/VideoProgress.qml @@ -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 diff --git a/src/qml/main.qml b/src/qml/main.qml index 9457ddb..33658f9 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -33,7 +33,16 @@ Window { Translator { 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 + } + } + } } } }