From 2eedb86e3a18aa882676587049623c483a5058ae Mon Sep 17 00:00:00 2001 From: levovix0 Date: Wed, 24 Mar 2021 17:56:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BE=D1=81=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D1=81=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 18 ++++++------ DMusic_ru_RU.ts | 4 --- RemoteMediaController.cpp | 62 ++++++++++++++++++++++++++++++++++++++- RemoteMediaController.hpp | 29 ++++++++++++++++++ main.cpp | 9 +++++- qml.qrc | 1 + russian.ts | 23 +++++++++++++++ 7 files changed, 131 insertions(+), 15 deletions(-) delete mode 100644 DMusic_ru_RU.ts create mode 100644 russian.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index d82cf31..95b5788 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ endif() find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick LinguistTools Multimedia DBus ${qt_winextras} REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick LinguistTools Multimedia DBus ${qt_winextras} REQUIRED) -set(TS_FILES ${PROJECT_NAME}_ru_RU.ts) +set(TS_FILES russian.ts) file(GLOB PROJECT_SOURCES "*.cpp") file(GLOB project_headers "*.hpp") @@ -42,17 +42,17 @@ file(GLOB project_qml "*.qml") set(PROJECT_SOURCES ${PROJECT_SOURCES} ${TS_FILES}) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) - qt_add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${project_headers} qml.qrc) + qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) - qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) + qt_add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${project_headers} qml.qrc ${QM_FILES}) else() - if(ANDROID) - add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${project_headers} qml.qrc) - else() - add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${project_headers} qml.qrc) - endif() + qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) - qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) + if(ANDROID) + add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${project_headers} qml.qrc ${QM_FILES}) + else() + add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${project_headers} qml.qrc ${QM_FILES}) + endif() endif() target_compile_definitions(${PROJECT_NAME} PRIVATE diff --git a/DMusic_ru_RU.ts b/DMusic_ru_RU.ts deleted file mode 100644 index 6970a5b..0000000 --- a/DMusic_ru_RU.ts +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/RemoteMediaController.cpp b/RemoteMediaController.cpp index a63a3c3..ea8a88c 100644 --- a/RemoteMediaController.cpp +++ b/RemoteMediaController.cpp @@ -278,7 +278,7 @@ void Mpris2Player::onTrackChanged(Track* track) void Mpris2Player::onProgressChanged(qint64 ms) { - if (labs(ms - _prevPosition) > 100 || ms == 0 || _prevPosition == 0) //TODO: seek minimum by Settings + if (std::abs(ms - _prevPosition) > 100 || ms == 0 || _prevPosition == 0) //TODO: seek minimum by Settings emit Seeked(ms * 1000); _prevPosition = ms; } @@ -423,7 +423,67 @@ MediaPlayer* RemoteMediaController::target() void RemoteMediaController::setTarget(MediaPlayer* player) { +#ifdef Q_OS_WIN + delete _win; + _win = new ThumbnailController(player, this); +#endif if (!_isDBusServiceCreated) return; _mpris2Player = new Mpris2Player(player, this); _target = player; } + +#ifdef Q_OS_WIN + +ThumbnailController::ThumbnailController(MediaPlayer* player, QObject* parent) : QObject(parent), _player(player) +{ + _toolbar = new QWinThumbnailToolBar(this); + auto windows = QGuiApplication::allWindows(); + _toolbar->setWindow(windows[0]); + + _pausePlay = new QWinThumbnailToolButton(_toolbar); + _pausePlay->setEnabled(false); + _pausePlay->setToolTip(tr("Play")); + _pausePlay->setIcon(QIcon(":resources/player/play.svg")); + connect(_pausePlay, &QWinThumbnailToolButton::clicked, _player, &MediaPlayer::pause_or_play); + + _next = new QWinThumbnailToolButton(_toolbar); + _next->setEnabled(false); + _next->setToolTip(tr("Next")); + _next->setIcon(QIcon(":resources/player/next.svg")); + connect(_next, &QWinThumbnailToolButton::clicked, _player, &MediaPlayer::next); + + _prev = new QWinThumbnailToolButton(_toolbar); + _prev->setEnabled(false); + _prev->setToolTip(tr("Previous")); + _prev->setIcon(QIcon(":resources/player/prev.svg")); + connect(_prev, &QWinThumbnailToolButton::clicked, _player, &MediaPlayer::prev); + + _toolbar->addButton(_prev); + _toolbar->addButton(_pausePlay); + _toolbar->addButton(_next); + + connect(_player, &MediaPlayer::stateChanged, this, &ThumbnailController::updateToolbar); +} + +ThumbnailController::~ThumbnailController() +{ + +} + +void ThumbnailController::updateToolbar() +{ + if (_player->state() == QMediaPlayer::PlayingState) { + _pausePlay->setToolTip(tr("Pause")); + _pausePlay->setIcon(QIcon(":resources/player/pause.svg")); + } else { + _pausePlay->setToolTip(tr("Play")); + _pausePlay->setIcon(QIcon(":resources/player/play.svg")); + } + + bool enabled = _player->state() != QMediaPlayer::StoppedState; + _pausePlay->setEnabled(enabled); + _next->setEnabled(enabled); + _prev->setEnabled(enabled); +} + +#endif diff --git a/RemoteMediaController.hpp b/RemoteMediaController.hpp index 24f8a33..79bd4f9 100644 --- a/RemoteMediaController.hpp +++ b/RemoteMediaController.hpp @@ -5,6 +5,10 @@ #include #include +#ifdef Q_OS_WIN +#include +#endif + class Mpris2Root : public QDBusAbstractAdaptor { @@ -123,6 +127,28 @@ private slots: QMap _currentTrackMetadata; }; +#ifdef Q_OS_WIN + +class ThumbnailController : public QObject +{ + Q_OBJECT +public: + explicit ThumbnailController(MediaPlayer* player, QObject* parent = nullptr); + ~ThumbnailController(); + +private slots: + void updateToolbar(); + +private: + MediaPlayer* _player; + QWinThumbnailToolBar* _toolbar; + QWinThumbnailToolButton* _next; + QWinThumbnailToolButton* _prev; + QWinThumbnailToolButton* _pausePlay; +}; + +#endif + class RemoteMediaController : public QObject { Q_OBJECT @@ -144,6 +170,9 @@ public slots: Mpris2Root* _mpris2Root; Mpris2Player* _mpris2Player; MediaPlayer* _target; +#ifdef Q_OS_WIN + ThumbnailController* _win = nullptr; +#endif inline static qint64 _serviceDuplicateCount = 1; }; diff --git a/main.cpp b/main.cpp index 5795e64..fec629b 100644 --- a/main.cpp +++ b/main.cpp @@ -2,16 +2,23 @@ #include "file.hpp" #include "settings.hpp" #include "mediaplayer.hpp" +#include "Log.hpp" #include "RemoteMediaController.hpp" #include #include #include -#include +#include int main(int argc, char *argv[]) { Py_Initialize(); + + QTranslator translator; + translator.load("russian"); + QGuiApplication app(argc, argv); + app.installTranslator(&translator); + qmlRegisterType("DMusic", 1, 0, "YClient"); qmlRegisterType("DMusic", 1, 0, "YTrack"); qmlRegisterType("DMusic", 1, 0, "YArtist"); diff --git a/qml.qrc b/qml.qrc index 513cc27..e0e334a 100644 --- a/qml.qrc +++ b/qml.qrc @@ -58,5 +58,6 @@ VolumeSlider.qml FloatingPanel.qml PopupController.qml + russian.ts diff --git a/russian.ts b/russian.ts new file mode 100644 index 0000000..129f8a8 --- /dev/null +++ b/russian.ts @@ -0,0 +1,23 @@ + + + + + ThumbnailController + + Play + Играть + + + Next + Следующий + + + Previous + Предыдущий + + + Pause + Пауза + + +