Compare commits
1 Commits
cloud_stor
...
visualisat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c435464972 |
9
.github/workflows/build.yml
vendored
9
.github/workflows/build.yml
vendored
@@ -62,6 +62,7 @@ jobs:
|
||||
libchromaprint-devel
|
||||
fftw3-devel
|
||||
libebur128-devel
|
||||
projectM-devel
|
||||
desktop-file-utils
|
||||
update-desktop-files
|
||||
appstream-glib
|
||||
@@ -78,6 +79,7 @@ jobs:
|
||||
qt6-base-common-devel
|
||||
qt6-sql-sqlite
|
||||
qt6-linguist-devel
|
||||
qt6-openglwidgets-devel
|
||||
gtest
|
||||
gmock
|
||||
sparsehash-devel
|
||||
@@ -200,6 +202,7 @@ jobs:
|
||||
libchromaprint-devel
|
||||
libebur128-devel
|
||||
fftw-devel
|
||||
libprojectM-devel
|
||||
desktop-file-utils
|
||||
libappstream-glib
|
||||
hicolor-icon-theme
|
||||
@@ -290,6 +293,7 @@ jobs:
|
||||
lib64Qt6DBus-devel
|
||||
lib64Qt6Gui-devel
|
||||
lib64Qt6Widgets-devel
|
||||
lib64Qt6OpenGLWidgets-devel
|
||||
lib64Qt6Test-devel
|
||||
lib64kdsingleapplication-devel
|
||||
lib64xkbcommon-devel
|
||||
@@ -384,6 +388,7 @@ jobs:
|
||||
lib64fftw-devel
|
||||
lib64dbus-devel
|
||||
lib64appstream-devel
|
||||
lib64projectm-devel
|
||||
lib64qt6core-devel
|
||||
lib64qt6gui-devel
|
||||
lib64qt6widgets-devel
|
||||
@@ -393,6 +398,7 @@ jobs:
|
||||
lib64qt6dbus-devel
|
||||
lib64qt6help-devel
|
||||
lib64qt6test-devel
|
||||
lib64qt6openglwidgets-devel
|
||||
lib64sparsehash-devel
|
||||
lib64kdsingleapplication-devel
|
||||
desktop-file-utils
|
||||
@@ -499,6 +505,7 @@ jobs:
|
||||
qt6-tools-dev-tools
|
||||
qt6-l10n-tools
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install KDSingleApplication
|
||||
if: matrix.debian_version != 'bookworm'
|
||||
run: apt install -y libkdsingleapplication-qt6-dev
|
||||
@@ -595,6 +602,7 @@ jobs:
|
||||
qt6-tools-dev-tools
|
||||
qt6-l10n-tools
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install KDSingleApplication
|
||||
if: matrix.ubuntu_version != 'noble' && matrix.ubuntu_version != 'plucky'
|
||||
run: apt install -y libkdsingleapplication-qt6-dev
|
||||
@@ -693,6 +701,7 @@ jobs:
|
||||
gstreamer1.0-pulseaudio
|
||||
libkdsingleapplication-qt6-dev
|
||||
rapidjson-dev
|
||||
libprojectm-dev
|
||||
- name: Install keyboxd
|
||||
if: matrix.ubuntu_version == 'noble'
|
||||
env:
|
||||
|
||||
@@ -208,6 +208,15 @@ else()
|
||||
pkg_check_modules(TAGLIB REQUIRED IMPORTED_TARGET taglib>=1.12)
|
||||
endif()
|
||||
|
||||
find_package(projectM4 COMPONENTS Playlist)
|
||||
if(projectM4_FOUND)
|
||||
set(LIBPROJECTM_FOUND ON)
|
||||
set(HAVE_PROJECTM4 ON)
|
||||
set(LIBPROJECTM_LIBRARIES libprojectM::projectM libprojectM::playlist)
|
||||
else()
|
||||
pkg_check_modules(LIBPROJECTM libprojectM)
|
||||
endif()
|
||||
|
||||
find_package(GTest)
|
||||
|
||||
pkg_check_modules(LIBSPARSEHASH IMPORTED_TARGET libsparsehash)
|
||||
@@ -218,7 +227,7 @@ set(QT_VERSION_MAJOR 6)
|
||||
set(QT_MIN_VERSION 6.4.0)
|
||||
set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR})
|
||||
set(QT_COMPONENTS Core Concurrent Gui Widgets Network Sql)
|
||||
set(QT_OPTIONAL_COMPONENTS GuiPrivate LinguistTools Test)
|
||||
set(QT_OPTIONAL_COMPONENTS GuiPrivate OpenGLWidgets LinguistTools Test)
|
||||
if(UNIX AND NOT APPLE)
|
||||
list(APPEND QT_OPTIONAL_COMPONENTS DBus)
|
||||
endif()
|
||||
@@ -379,13 +388,6 @@ optional_component(STREAMTAGREADER ON "Stream tagreader"
|
||||
|
||||
optional_component(DISCORD_RPC ON "Discord Rich Presence"
|
||||
DEPENDS "RapidJSON" RapidJSON_FOUND
|
||||
|
||||
optional_component(DROPBOX ON "Streaming: Dropbox"
|
||||
DEPENDS "Stream tagreader" HAVE_STREAMTAGREADER
|
||||
)
|
||||
|
||||
optional_component(ONEDRIVE ON "Streaming: OneDrive"
|
||||
DEPENDS "Stream tagreader" HAVE_STREAMTAGREADER
|
||||
)
|
||||
|
||||
if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ)
|
||||
@@ -396,6 +398,11 @@ if(HAVE_X11_GLOBALSHORTCUTS OR HAVE_KGLOBALACCEL_GLOBALSHORTCUTS OR APPLE OR WIN
|
||||
set(HAVE_GLOBALSHORTCUTS ON)
|
||||
endif()
|
||||
|
||||
optional_component(VISUALIZATIONS ON "Visualizations"
|
||||
DEPENDS "libprojectm" LIBPROJECTM_FOUND
|
||||
DEPENDS "QtOpenGLWidgets" Qt${QT_VERSION_MAJOR}OpenGLWidgets_FOUND
|
||||
)
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
# Check that we have Qt with sqlite driver
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++17")
|
||||
@@ -783,7 +790,6 @@ set(SOURCES
|
||||
src/streaming/streamingcollectionviewcontainer.cpp
|
||||
src/streaming/streamingsearchview.cpp
|
||||
src/streaming/streamsongmimedata.cpp
|
||||
src/streaming/cloudstoragestreamingservice.cpp
|
||||
|
||||
src/radios/radioservices.cpp
|
||||
src/radios/radiobackend.cpp
|
||||
@@ -1080,7 +1086,6 @@ set(HEADERS
|
||||
src/streaming/streamingtabsview.h
|
||||
src/streaming/streamingcollectionview.h
|
||||
src/streaming/streamingcollectionviewcontainer.h
|
||||
src/streaming/cloudstoragestreamingservice.h
|
||||
|
||||
src/radios/radioservices.h
|
||||
src/radios/radiobackend.h
|
||||
@@ -1489,23 +1494,24 @@ optional_source(HAVE_QOBUZ
|
||||
src/settings/qobuzsettingspage.ui
|
||||
)
|
||||
|
||||
optional_source(HAVE_DROPBOX
|
||||
optional_source(HAVE_VISUALIZATIONS
|
||||
SOURCES
|
||||
src/dropbox/dropboxservice.cpp
|
||||
src/dropbox/dropboxurlhandler.cpp
|
||||
src/dropbox/dropboxbaserequest.cpp
|
||||
src/dropbox/dropboxsongsrequest.cpp
|
||||
src/dropbox/dropboxstreamurlrequest.cpp
|
||||
src/settings/dropboxsettingspage.cpp
|
||||
src/visualizations/projectmpresetmodel.cpp
|
||||
src/visualizations/projectmvisualization.cpp
|
||||
src/visualizations/visualizationcontainer.cpp
|
||||
src/visualizations/visualizationoverlay.cpp
|
||||
src/visualizations/visualizationselector.cpp
|
||||
src/visualizations/visualizationopenglwidget.cpp
|
||||
HEADERS
|
||||
src/dropbox/dropboxservice.h
|
||||
src/dropbox/dropboxurlhandler.h
|
||||
src/dropbox/dropboxbaserequest.h
|
||||
src/dropbox/dropboxsongsrequest.h
|
||||
src/dropbox/dropboxstreamurlrequest.h
|
||||
src/settings/dropboxsettingspage.h
|
||||
src/visualizations/projectmpresetmodel.h
|
||||
src/visualizations/projectmvisualization.h
|
||||
src/visualizations/visualizationcontainer.h
|
||||
src/visualizations/visualizationoverlay.h
|
||||
src/visualizations/visualizationselector.h
|
||||
src/visualizations/visualizationopenglwidget.h
|
||||
UI
|
||||
src/settings/dropboxsettingspage.ui
|
||||
src/visualizations/visualizationoverlay.ui
|
||||
src/visualizations/visualizationselector.ui
|
||||
)
|
||||
|
||||
qt_wrap_cpp(SOURCES ${HEADERS})
|
||||
@@ -1578,6 +1584,7 @@ target_link_libraries(strawberry_lib PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
$<$<BOOL:${HAVE_DBUS}>:Qt${QT_VERSION_MAJOR}::DBus>
|
||||
$<$<BOOL:${HAVE_QPA_QPLATFORMNATIVEINTERFACE}>:Qt${QT_VERSION_MAJOR}::GuiPrivate>
|
||||
$<$<BOOL:${HAVE_VISUALIZATIONS}>:Qt${QT_VERSION_MAJOR}::OpenGLWidgets>
|
||||
ICU::uc
|
||||
ICU::i18n
|
||||
$<$<BOOL:${HAVE_STREAMTAGREADER}>:PkgConfig::LIBSPARSEHASH>
|
||||
@@ -1593,6 +1600,7 @@ target_link_libraries(strawberry_lib PUBLIC
|
||||
$<$<BOOL:${HAVE_MTP}>:PkgConfig::LIBMTP>
|
||||
$<$<BOOL:${HAVE_GPOD}>:PkgConfig::LIBGPOD PkgConfig::GDK_PIXBUF>
|
||||
$<$<BOOL:${HAVE_QTSPARKLE}>:qtsparkle-qt${QT_VERSION_MAJOR}::qtsparkle>
|
||||
$<$<BOOL:${HAVE_VISUALIZATIONS}>:${LIBPROJECTM_LIBRARIES}>
|
||||
$<$<BOOL:${WIN32}>:dsound dwmapi ${GETOPT_LIBRARIES}>
|
||||
$<$<BOOL:${MSVC}>:WindowsApp>
|
||||
KDAB::kdsingleapplication
|
||||
|
||||
@@ -98,7 +98,6 @@
|
||||
<file>icons/128x128/somafm.png</file>
|
||||
<file>icons/128x128/radioparadise.png</file>
|
||||
<file>icons/128x128/musicbrainz.png</file>
|
||||
<file>icons/128x128/dropbox.png</file>
|
||||
<file>icons/64x64/albums.png</file>
|
||||
<file>icons/64x64/alsa.png</file>
|
||||
<file>icons/64x64/application-exit.png</file>
|
||||
@@ -198,7 +197,6 @@
|
||||
<file>icons/64x64/somafm.png</file>
|
||||
<file>icons/64x64/radioparadise.png</file>
|
||||
<file>icons/64x64/musicbrainz.png</file>
|
||||
<file>icons/64x64/dropbox.png</file>
|
||||
<file>icons/48x48/albums.png</file>
|
||||
<file>icons/48x48/alsa.png</file>
|
||||
<file>icons/48x48/application-exit.png</file>
|
||||
@@ -302,7 +300,6 @@
|
||||
<file>icons/48x48/somafm.png</file>
|
||||
<file>icons/48x48/radioparadise.png</file>
|
||||
<file>icons/48x48/musicbrainz.png</file>
|
||||
<file>icons/48x48/dropbox.png</file>
|
||||
<file>icons/32x32/albums.png</file>
|
||||
<file>icons/32x32/alsa.png</file>
|
||||
<file>icons/32x32/application-exit.png</file>
|
||||
@@ -406,7 +403,6 @@
|
||||
<file>icons/32x32/somafm.png</file>
|
||||
<file>icons/32x32/radioparadise.png</file>
|
||||
<file>icons/32x32/musicbrainz.png</file>
|
||||
<file>icons/32x32/dropbox.png</file>
|
||||
<file>icons/22x22/albums.png</file>
|
||||
<file>icons/22x22/alsa.png</file>
|
||||
<file>icons/22x22/application-exit.png</file>
|
||||
@@ -510,6 +506,5 @@
|
||||
<file>icons/22x22/somafm.png</file>
|
||||
<file>icons/22x22/radioparadise.png</file>
|
||||
<file>icons/22x22/musicbrainz.png</file>
|
||||
<file>icons/22x22/dropbox.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 638 B |
Binary file not shown.
|
Before Width: | Height: | Size: 746 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1011 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
@@ -1,82 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS dropbox_songs (
|
||||
|
||||
title TEXT,
|
||||
album TEXT,
|
||||
artist TEXT,
|
||||
albumartist TEXT,
|
||||
track INTEGER NOT NULL DEFAULT -1,
|
||||
disc INTEGER NOT NULL DEFAULT -1,
|
||||
year INTEGER NOT NULL DEFAULT -1,
|
||||
originalyear INTEGER NOT NULL DEFAULT -1,
|
||||
genre TEXT,
|
||||
compilation INTEGER NOT NULL DEFAULT 0,
|
||||
composer TEXT,
|
||||
performer TEXT,
|
||||
grouping TEXT,
|
||||
comment TEXT,
|
||||
lyrics TEXT,
|
||||
|
||||
artist_id TEXT,
|
||||
album_id TEXT,
|
||||
song_id TEXT,
|
||||
|
||||
beginning INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
bitrate INTEGER NOT NULL DEFAULT -1,
|
||||
samplerate INTEGER NOT NULL DEFAULT -1,
|
||||
bitdepth INTEGER NOT NULL DEFAULT -1,
|
||||
|
||||
source INTEGER NOT NULL DEFAULT 0,
|
||||
directory_id INTEGER NOT NULL DEFAULT -1,
|
||||
url TEXT NOT NULL,
|
||||
filetype INTEGER NOT NULL DEFAULT 0,
|
||||
filesize INTEGER NOT NULL DEFAULT -1,
|
||||
mtime INTEGER NOT NULL DEFAULT -1,
|
||||
ctime INTEGER NOT NULL DEFAULT -1,
|
||||
unavailable INTEGER DEFAULT 0,
|
||||
|
||||
fingerprint TEXT,
|
||||
|
||||
playcount INTEGER NOT NULL DEFAULT 0,
|
||||
skipcount INTEGER NOT NULL DEFAULT 0,
|
||||
lastplayed INTEGER NOT NULL DEFAULT -1,
|
||||
lastseen INTEGER NOT NULL DEFAULT -1,
|
||||
|
||||
compilation_detected INTEGER DEFAULT 0,
|
||||
compilation_on INTEGER NOT NULL DEFAULT 0,
|
||||
compilation_off INTEGER NOT NULL DEFAULT 0,
|
||||
compilation_effective INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
art_embedded INTEGER DEFAULT 0,
|
||||
art_automatic TEXT,
|
||||
art_manual TEXT,
|
||||
art_unset INTEGER DEFAULT 0,
|
||||
|
||||
effective_albumartist TEXT,
|
||||
effective_originalyear INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
cue_path TEXT,
|
||||
|
||||
rating INTEGER DEFAULT -1,
|
||||
|
||||
acoustid_id TEXT,
|
||||
acoustid_fingerprint TEXT,
|
||||
|
||||
musicbrainz_album_artist_id TEXT,
|
||||
musicbrainz_artist_id TEXT,
|
||||
musicbrainz_original_artist_id TEXT,
|
||||
musicbrainz_album_id TEXT,
|
||||
musicbrainz_original_album_id TEXT,
|
||||
musicbrainz_recording_id TEXT,
|
||||
musicbrainz_track_id TEXT,
|
||||
musicbrainz_disc_id TEXT,
|
||||
musicbrainz_release_group_id TEXT,
|
||||
musicbrainz_work_id TEXT,
|
||||
|
||||
ebur128_integrated_loudness_lufs REAL,
|
||||
ebur128_loudness_range_lu REAL
|
||||
|
||||
);
|
||||
|
||||
UPDATE schema_version SET version=22;
|
||||
@@ -1018,87 +1018,6 @@ CREATE TABLE IF NOT EXISTS qobuz_songs (
|
||||
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dropbox_songs (
|
||||
|
||||
title TEXT,
|
||||
album TEXT,
|
||||
artist TEXT,
|
||||
albumartist TEXT,
|
||||
track INTEGER NOT NULL DEFAULT -1,
|
||||
disc INTEGER NOT NULL DEFAULT -1,
|
||||
year INTEGER NOT NULL DEFAULT -1,
|
||||
originalyear INTEGER NOT NULL DEFAULT -1,
|
||||
genre TEXT,
|
||||
compilation INTEGER NOT NULL DEFAULT 0,
|
||||
composer TEXT,
|
||||
performer TEXT,
|
||||
grouping TEXT,
|
||||
comment TEXT,
|
||||
lyrics TEXT,
|
||||
|
||||
artist_id TEXT,
|
||||
album_id TEXT,
|
||||
song_id TEXT,
|
||||
|
||||
beginning INTEGER NOT NULL DEFAULT 0,
|
||||
length INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
bitrate INTEGER NOT NULL DEFAULT -1,
|
||||
samplerate INTEGER NOT NULL DEFAULT -1,
|
||||
bitdepth INTEGER NOT NULL DEFAULT -1,
|
||||
|
||||
source INTEGER NOT NULL DEFAULT 0,
|
||||
directory_id INTEGER NOT NULL DEFAULT -1,
|
||||
url TEXT NOT NULL,
|
||||
filetype INTEGER NOT NULL DEFAULT 0,
|
||||
filesize INTEGER NOT NULL DEFAULT -1,
|
||||
mtime INTEGER NOT NULL DEFAULT -1,
|
||||
ctime INTEGER NOT NULL DEFAULT -1,
|
||||
unavailable INTEGER DEFAULT 0,
|
||||
|
||||
fingerprint TEXT,
|
||||
|
||||
playcount INTEGER NOT NULL DEFAULT 0,
|
||||
skipcount INTEGER NOT NULL DEFAULT 0,
|
||||
lastplayed INTEGER NOT NULL DEFAULT -1,
|
||||
lastseen INTEGER NOT NULL DEFAULT -1,
|
||||
|
||||
compilation_detected INTEGER DEFAULT 0,
|
||||
compilation_on INTEGER NOT NULL DEFAULT 0,
|
||||
compilation_off INTEGER NOT NULL DEFAULT 0,
|
||||
compilation_effective INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
art_embedded INTEGER DEFAULT 0,
|
||||
art_automatic TEXT,
|
||||
art_manual TEXT,
|
||||
art_unset INTEGER DEFAULT 0,
|
||||
|
||||
effective_albumartist TEXT,
|
||||
effective_originalyear INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
cue_path TEXT,
|
||||
|
||||
rating INTEGER DEFAULT -1,
|
||||
|
||||
acoustid_id TEXT,
|
||||
acoustid_fingerprint TEXT,
|
||||
|
||||
musicbrainz_album_artist_id TEXT,
|
||||
musicbrainz_artist_id TEXT,
|
||||
musicbrainz_original_artist_id TEXT,
|
||||
musicbrainz_album_id TEXT,
|
||||
musicbrainz_original_album_id TEXT,
|
||||
musicbrainz_recording_id TEXT,
|
||||
musicbrainz_track_id TEXT,
|
||||
musicbrainz_disc_id TEXT,
|
||||
musicbrainz_release_group_id TEXT,
|
||||
musicbrainz_work_id TEXT,
|
||||
|
||||
ebur128_integrated_loudness_lufs REAL,
|
||||
ebur128_loudness_range_lu REAL
|
||||
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS playlists (
|
||||
|
||||
name TEXT NOT NULL,
|
||||
|
||||
3
debian/control
vendored
3
debian/control
vendored
@@ -32,7 +32,8 @@ Build-Depends: debhelper-compat (= 12),
|
||||
libfftw3-dev,
|
||||
libebur128-dev,
|
||||
libsparsehash-dev,
|
||||
rapidjson-dev
|
||||
rapidjson-dev,
|
||||
libprojectm-dev
|
||||
Standards-Version: 4.7.0
|
||||
|
||||
Package: strawberry
|
||||
|
||||
1
dist/unix/strawberry.spec.in
vendored
1
dist/unix/strawberry.spec.in
vendored
@@ -43,6 +43,7 @@ BuildRequires: pkgconfig(taglib)
|
||||
BuildRequires: pkgconfig(fftw3)
|
||||
BuildRequires: pkgconfig(icu-uc)
|
||||
BuildRequires: pkgconfig(icu-i18n)
|
||||
BuildRequires: pkgconfig(libprojectM)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Core)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Concurrent)
|
||||
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Network)
|
||||
|
||||
@@ -73,7 +73,8 @@ AnalyzerContainer::AnalyzerContainer(QWidget *parent)
|
||||
double_click_timer_(new QTimer(this)),
|
||||
ignore_next_click_(false),
|
||||
current_analyzer_(nullptr),
|
||||
engine_(nullptr) {
|
||||
engine_(nullptr),
|
||||
action_visualization_(nullptr) {
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
@@ -118,6 +119,17 @@ void AnalyzerContainer::mouseReleaseEvent(QMouseEvent *e) {
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::mouseDoubleClickEvent(QMouseEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
double_click_timer_->stop();
|
||||
ignore_next_click_ = true;
|
||||
|
||||
if (action_visualization_) action_visualization_->trigger();
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::ShowPopupMenu() {
|
||||
context_menu_->popup(last_click_pos_);
|
||||
}
|
||||
@@ -249,3 +261,10 @@ void AnalyzerContainer::AddFramerate(const QString &name, const int framerate) {
|
||||
QObject::connect(action, &QAction::triggered, this, [this, framerate]() { ChangeFramerate(framerate); } );
|
||||
|
||||
}
|
||||
|
||||
void AnalyzerContainer::SetVisualizationsAction(QAction *visualization) {
|
||||
|
||||
action_visualization_ = visualization;
|
||||
context_menu_->addAction(action_visualization_);
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ class AnalyzerContainer : public QWidget {
|
||||
explicit AnalyzerContainer(QWidget *parent);
|
||||
|
||||
void SetEngine(SharedPtr<EngineBase> engine);
|
||||
void SetVisualizationsAction(QAction *visualization);
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
static const char *kSettingsFramerate;
|
||||
@@ -55,6 +56,7 @@ class AnalyzerContainer : public QWidget {
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
@@ -89,6 +91,8 @@ class AnalyzerContainer : public QWidget {
|
||||
|
||||
AnalyzerBase *current_analyzer_;
|
||||
SharedPtr<EngineBase> engine_;
|
||||
|
||||
QAction *action_visualization_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -41,11 +41,8 @@ bool CollectionPlaylistItem::InitFromQuery(const SqlRow &query) {
|
||||
case Song::Source::Collection:
|
||||
col = 0;
|
||||
break;
|
||||
case Song::Source::Dropbox:
|
||||
col = static_cast<int>(Song::kRowIdColumns.count());
|
||||
break;
|
||||
default:
|
||||
col = static_cast<int>(Song::kRowIdColumns.count() * 2);
|
||||
col = static_cast<int>(Song::kRowIdColumns.count());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#cmakedefine HAVE_SPOTIFY
|
||||
#cmakedefine HAVE_QOBUZ
|
||||
#cmakedefine HAVE_DISCORD_RPC
|
||||
#cmakedefine HAVE_DROPBOX
|
||||
#cmakedefine HAVE_ONEDRIVE
|
||||
|
||||
#cmakedefine HAVE_TAGLIB_DSFFILE
|
||||
#cmakedefine HAVE_TAGLIB_DSDIFFFILE
|
||||
@@ -50,4 +48,7 @@
|
||||
|
||||
#cmakedefine ENABLE_WIN32_CONSOLE
|
||||
|
||||
#cmakedefine HAVE_VISUALIZATIONS
|
||||
#cmakedefine HAVE_PROJECTM4
|
||||
|
||||
#endif // CONFIG_H_IN
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXCONSTANTS_H
|
||||
#define DROPBOXCONSTANTS_H
|
||||
|
||||
namespace DropboxConstants {
|
||||
|
||||
constexpr char kApiUrl[] = "https://api.dropboxapi.com";
|
||||
constexpr char kNotifyApiUrl[] = "https://notify.dropboxapi.com";
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // DROPBOXCONSTANTS_H
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXSETTINGS_H
|
||||
#define DROPBOXSETTINGS_H
|
||||
|
||||
namespace DropboxSettings {
|
||||
|
||||
constexpr char kSettingsGroup[] = "Dropbox";
|
||||
|
||||
constexpr char kEnabled[] = "enabled";
|
||||
constexpr char kSearchDelay[] = "searchdelay";
|
||||
constexpr char kArtistsSearchLimit[] = "artistssearchlimit";
|
||||
constexpr char kAlbumsSearchLimit[] = "albumssearchlimit";
|
||||
constexpr char kSongsSearchLimit[] = "songssearchlimit";
|
||||
constexpr char kFetchAlbums[] = "fetchalbums";
|
||||
constexpr char kDownloadAlbumCovers[] = "downloadalbumcovers";
|
||||
|
||||
constexpr char kTokenType[] = "token_type";
|
||||
constexpr char kAccessToken[] = "access_token";
|
||||
constexpr char kRefreshToken[] = "refresh_token";
|
||||
constexpr char kExpiresIn[] = "expires_in";
|
||||
constexpr char kLoginTime[] = "login_time";
|
||||
|
||||
constexpr char kApiUrl[] = "https://api.dropboxapi.com";
|
||||
constexpr char kNotifyApiUrl[] = "https://notify.dropboxapi.com";
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // DROPBOXSETTINGS_H
|
||||
@@ -105,10 +105,6 @@
|
||||
# include "covermanager/qobuzcoverprovider.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DROPBOX
|
||||
# include "dropbox/dropboxservice.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
# include "moodbar/moodbarcontroller.h"
|
||||
# include "moodbar/moodbarloader.h"
|
||||
@@ -204,9 +200,6 @@ class ApplicationImpl {
|
||||
#endif
|
||||
#ifdef HAVE_QOBUZ
|
||||
streaming_services->AddService(make_shared<QobuzService>(app->task_manager(), app->database(), app->network(), app->url_handlers(), app->albumcover_loader()));
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
streaming_services->AddService(make_shared<DropboxService>(app->task_manager(), app->database(), app->network(), app->url_handlers(), app->tagreader_client(), app->albumcover_loader()));
|
||||
#endif
|
||||
return streaming_services;
|
||||
}),
|
||||
|
||||
@@ -178,9 +178,6 @@
|
||||
#ifdef HAVE_QOBUZ
|
||||
# include "constants/qobuzsettings.h"
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
# include "constants/dropboxsettings.h"
|
||||
#endif
|
||||
|
||||
#include "streaming/streamingservices.h"
|
||||
#include "streaming/streamingservice.h"
|
||||
@@ -209,6 +206,11 @@
|
||||
|
||||
#include "organize/organizeerrordialog.h"
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
# include "visualizations/visualizationcontainer.h"
|
||||
# include "engine/gstengine.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
# include "core/windows7thumbbar.h"
|
||||
#endif
|
||||
@@ -358,9 +360,6 @@ MainWindow::MainWindow(Application *app,
|
||||
#endif
|
||||
#ifdef HAVE_QOBUZ
|
||||
qobuz_view_(new StreamingTabsView(app->streaming_services()->ServiceBySource(Song::Source::Qobuz), app->albumcover_loader(), QLatin1String(QobuzSettings::kSettingsGroup), this)),
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
dropbox_view_(new StreamingSongsView(app->streaming_services()->ServiceBySource(Song::Source::Dropbox), QLatin1String(DropboxSettings::kSettingsGroup), this)),
|
||||
#endif
|
||||
radio_view_(new RadioViewContainer(this)),
|
||||
lastfm_import_dialog_(new LastFMImportDialog(app_->lastfm_import(), this)),
|
||||
@@ -447,9 +446,6 @@ MainWindow::MainWindow(Application *app,
|
||||
#ifdef HAVE_QOBUZ
|
||||
ui_->tabs->AddTab(qobuz_view_, u"qobuz"_s, IconLoader::Load(u"qobuz"_s, true, 0, 32), tr("Qobuz"));
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
ui_->tabs->AddTab(dropbox_view_, u"dropbox"_s, IconLoader::Load(u"dropbox"_s, true, 0, 32), tr("Dropbox"));
|
||||
#endif
|
||||
|
||||
// Add the playing widget to the fancy tab widget
|
||||
ui_->tabs->AddBottomWidget(ui_->widget_playing);
|
||||
@@ -632,6 +628,12 @@ MainWindow::MainWindow(Application *app,
|
||||
stop_menu->addAction(ui_->action_stop_after_this_track);
|
||||
ui_->stop_button->setMenu(stop_menu);
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
QObject::connect(ui_->action_visualizations, &QAction::triggered, this, &MainWindow::ShowVisualizations);
|
||||
#else
|
||||
ui_->action_visualizations->setEnabled(false);
|
||||
#endif
|
||||
|
||||
// Player connections
|
||||
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, &*app_->player(), &Player::SetVolumeFromSlider);
|
||||
|
||||
@@ -791,12 +793,6 @@ MainWindow::MainWindow(Application *app,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DROPBOX
|
||||
QObject::connect(dropbox_view_, &StreamingSongsView::ShowErrorDialog, this, &MainWindow::ShowErrorDialog);
|
||||
QObject::connect(dropbox_view_, &StreamingSongsView::OpenSettingsDialog, this, &MainWindow::OpenServiceSettingsDialog);
|
||||
QObject::connect(dropbox_view_->view(), &StreamingCollectionView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
|
||||
#endif
|
||||
|
||||
QObject::connect(radio_view_, &RadioViewContainer::Refresh, &*app_->radio_services(), &RadioServices::RefreshChannels);
|
||||
QObject::connect(radio_view_->view(), &RadioView::GetChannels, &*app_->radio_services(), &RadioServices::GetChannels);
|
||||
QObject::connect(radio_view_->view(), &RadioView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
|
||||
@@ -922,6 +918,7 @@ MainWindow::MainWindow(Application *app,
|
||||
|
||||
// Analyzer
|
||||
QObject::connect(ui_->analyzer, &AnalyzerContainer::WheelEvent, this, &MainWindow::VolumeWheelEvent);
|
||||
ui_->analyzer->SetVisualizationsAction(ui_->action_visualizations);
|
||||
|
||||
// Statusbar widgets
|
||||
ui_->playlist_summary->setMinimumWidth(QFontMetrics(font()).horizontalAdvance(u"WW selected of WW tracks - [ WW:WW ]"_s));
|
||||
@@ -1295,18 +1292,6 @@ void MainWindow::ReloadSettings() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DROPBOX
|
||||
s.beginGroup(DropboxSettings::kSettingsGroup);
|
||||
const bool enable_dropbox = s.value(DropboxSettings::kEnabled, false).toBool();
|
||||
s.endGroup();
|
||||
if (enable_dropbox) {
|
||||
ui_->tabs->EnableTab(dropbox_view_);
|
||||
}
|
||||
else {
|
||||
ui_->tabs->DisableTab(dropbox_view_);
|
||||
}
|
||||
#endif
|
||||
|
||||
ui_->tabs->ReloadSettings();
|
||||
|
||||
}
|
||||
@@ -1353,12 +1338,10 @@ void MainWindow::ReloadAllSettings() {
|
||||
qobuz_view_->ReloadSettings();
|
||||
qobuz_view_->search_view()->ReloadSettings();
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
dropbox_view_->ReloadSettings();
|
||||
#endif
|
||||
#ifdef HAVE_DISCORD_RPC
|
||||
discord_rich_presence_->ReloadSettings();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::RefreshStyleSheet() {
|
||||
@@ -2746,9 +2729,6 @@ void MainWindow::OpenServiceSettingsDialog(const Song::Source source) {
|
||||
case Song::Source::Spotify:
|
||||
settings_dialog_->OpenAtPage(SettingsDialog::Page::Spotify);
|
||||
break;
|
||||
case Song::Source::Dropbox:
|
||||
settings_dialog_->OpenAtPage(SettingsDialog::Page::Dropbox);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -3430,14 +3410,30 @@ void MainWindow::FocusSearchField() {
|
||||
else if (ui_->tabs->currentIndex() == ui_->tabs->IndexOfTab(qobuz_view_) && !qobuz_view_->SearchFieldHasFocus()) {
|
||||
qobuz_view_->FocusSearchField();
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
else if (ui_->tabs->currentIndex() == ui_->tabs->IndexOfTab(dropbox_view_) && !dropbox_view_->SearchFieldHasFocus()) {
|
||||
dropbox_view_->FocusSearchField();
|
||||
}
|
||||
#endif
|
||||
else if (!ui_->playlist->SearchFieldHasFocus()) {
|
||||
ui_->playlist->FocusSearchField();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::ShowVisualizations() {
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
|
||||
if (!visualization_) {
|
||||
visualization_.reset(new VisualizationContainer);
|
||||
|
||||
visualization_->SetActions(ui_->action_previous_track, ui_->action_play_pause, ui_->action_stop, ui_->action_next_track);
|
||||
connect(&*app_->player(), &Player::Stopped, &*visualization_, &VisualizationContainer::Stopped);
|
||||
connect(&*app_->player(), &Player::ForceShowOSD, &*visualization_, &VisualizationContainer::SongMetadataChanged);
|
||||
connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*visualization_, &VisualizationContainer::SongMetadataChanged);
|
||||
|
||||
visualization_->SetEngine(qobject_cast<GstEngine*>(&*app_->player()->engine()));
|
||||
}
|
||||
|
||||
visualization_->show();
|
||||
|
||||
#endif // HAVE_VISUALIZATIONS
|
||||
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ class Windows7ThumbBar;
|
||||
class AddStreamDialog;
|
||||
class LastFMImportDialog;
|
||||
class RadioViewContainer;
|
||||
class VisualizationContainer;
|
||||
|
||||
#ifdef HAVE_DISCORD_RPC
|
||||
namespace discord {
|
||||
@@ -281,6 +282,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
public Q_SLOTS:
|
||||
void CommandlineOptionsReceived(const QByteArray &string_options);
|
||||
void Raise();
|
||||
void ShowVisualizations();
|
||||
|
||||
private:
|
||||
void SaveSettings();
|
||||
@@ -355,14 +357,15 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
||||
#ifdef HAVE_QOBUZ
|
||||
StreamingTabsView *qobuz_view_;
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
StreamingSongsView *dropbox_view_;
|
||||
#endif
|
||||
|
||||
RadioViewContainer *radio_view_;
|
||||
|
||||
LastFMImportDialog *lastfm_import_dialog_;
|
||||
|
||||
#ifdef HAVE_VISUALIZATIONS
|
||||
ScopedPtr<VisualizationContainer> visualization_;
|
||||
#endif
|
||||
|
||||
QAction *collection_show_all_;
|
||||
QAction *collection_show_duplicates_;
|
||||
QAction *collection_show_untagged_;
|
||||
|
||||
@@ -517,6 +517,7 @@
|
||||
<addaction name="action_cover_manager"/>
|
||||
<addaction name="action_equalizer"/>
|
||||
<addaction name="action_transcoder"/>
|
||||
<addaction name="action_visualizations"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="action_update_collection"/>
|
||||
<addaction name="action_full_collection_scan"/>
|
||||
@@ -863,6 +864,11 @@
|
||||
<string>Import data from last.fm...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_visualizations">
|
||||
<property name="text">
|
||||
<string>Visualizations</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
||||
@@ -1163,8 +1163,6 @@ QString Song::TextForSource(const Source source) {
|
||||
case Source::Qobuz: return u"qobuz"_s;
|
||||
case Source::SomaFM: return u"somafm"_s;
|
||||
case Source::RadioParadise: return u"radioparadise"_s;
|
||||
case Source::Dropbox: return u"dropbox"_s;
|
||||
case Source::OneDrive: return u"onedrive"_s;
|
||||
case Source::Unknown: return u"unknown"_s;
|
||||
}
|
||||
return u"unknown"_s;
|
||||
@@ -1185,8 +1183,6 @@ QString Song::DescriptionForSource(const Source source) {
|
||||
case Source::Qobuz: return u"Qobuz"_s;
|
||||
case Source::SomaFM: return u"SomaFM"_s;
|
||||
case Source::RadioParadise: return u"Radio Paradise"_s;
|
||||
case Source::Dropbox: return u"Dropbox"_s;
|
||||
case Source::OneDrive: return u"OneDrive"_s;
|
||||
case Source::Unknown: return u"Unknown"_s;
|
||||
}
|
||||
return u"unknown"_s;
|
||||
@@ -1206,8 +1202,6 @@ Song::Source Song::SourceFromText(const QString &source) {
|
||||
if (source.compare("qobuz"_L1, Qt::CaseInsensitive) == 0) return Source::Qobuz;
|
||||
if (source.compare("somafm"_L1, Qt::CaseInsensitive) == 0) return Source::SomaFM;
|
||||
if (source.compare("radioparadise"_L1, Qt::CaseInsensitive) == 0) return Source::RadioParadise;
|
||||
if (source.compare("dropbox"_L1, Qt::CaseInsensitive) == 0) return Source::Dropbox;
|
||||
if (source.compare("onedrive"_L1, Qt::CaseInsensitive) == 0) return Source::OneDrive;
|
||||
|
||||
return Source::Unknown;
|
||||
|
||||
@@ -1227,8 +1221,6 @@ QIcon Song::IconForSource(const Source source) {
|
||||
case Source::Qobuz: return IconLoader::Load(u"qobuz"_s);
|
||||
case Source::SomaFM: return IconLoader::Load(u"somafm"_s);
|
||||
case Source::RadioParadise: return IconLoader::Load(u"radioparadise"_s);
|
||||
case Source::Dropbox: return IconLoader::Load(u"dropbox"_s);
|
||||
case Source::OneDrive: return IconLoader::Load(u"onedrive"_s);
|
||||
case Source::Unknown: return IconLoader::Load(u"edit-delete"_s);
|
||||
}
|
||||
return IconLoader::Load(u"edit-delete"_s);
|
||||
@@ -1478,7 +1470,7 @@ Song::FileType Song::FiletypeByExtension(const QString &ext) {
|
||||
|
||||
bool Song::IsLinkedCollectionSource(const Source source) {
|
||||
|
||||
return source == Source::Collection || source == Source::Dropbox;
|
||||
return source == Source::Collection;
|
||||
|
||||
}
|
||||
|
||||
@@ -1497,14 +1489,11 @@ QString Song::ImageCacheDir(const Source source) {
|
||||
return StandardPaths::WritableLocation(StandardPaths::StandardLocation::AppLocalDataLocation) + u"/qobuzalbumcovers"_s;
|
||||
case Source::Device:
|
||||
return StandardPaths::WritableLocation(StandardPaths::StandardLocation::AppLocalDataLocation) + u"/devicealbumcovers"_s;
|
||||
case Source::Dropbox:
|
||||
return StandardPaths::WritableLocation(StandardPaths::StandardLocation::AppLocalDataLocation) + u"/dropboxalbumcovers"_s;
|
||||
case Source::LocalFile:
|
||||
case Source::CDDA:
|
||||
case Source::Stream:
|
||||
case Source::SomaFM:
|
||||
case Source::RadioParadise:
|
||||
case Source::OneDrive:
|
||||
case Source::Unknown:
|
||||
return StandardPaths::WritableLocation(StandardPaths::StandardLocation::AppLocalDataLocation) + u"/albumcovers"_s;
|
||||
}
|
||||
|
||||
@@ -76,9 +76,7 @@ class Song {
|
||||
Qobuz = 8,
|
||||
SomaFM = 9,
|
||||
RadioParadise = 10,
|
||||
Spotify = 11,
|
||||
Dropbox = 12,
|
||||
OneDrive = 13,
|
||||
Spotify = 11
|
||||
};
|
||||
static const int kSourceCount = 16;
|
||||
|
||||
|
||||
@@ -589,8 +589,6 @@ void AlbumCoverChoiceController::SaveArtManualToSong(Song *song, const QUrl &art
|
||||
case Song::Source::Tidal:
|
||||
case Song::Source::Spotify:
|
||||
case Song::Source::Qobuz:
|
||||
case Song::Source::Dropbox:
|
||||
case Song::Source::OneDrive:
|
||||
StreamingServicePtr service = streaming_services_->ServiceBySource(song->source());
|
||||
if (!service) break;
|
||||
if (service->artists_collection_backend()) {
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "constants/dropboxconstants.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "dropboxservice.h"
|
||||
#include "dropboxbaserequest.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using namespace DropboxConstants;
|
||||
|
||||
DropboxBaseRequest::DropboxBaseRequest(const SharedPtr<NetworkAccessManager> network, DropboxService *service, QObject *parent)
|
||||
: JsonBaseRequest(network, parent),
|
||||
service_(service) {}
|
||||
|
||||
QString DropboxBaseRequest::service_name() const {
|
||||
|
||||
return service_->name();
|
||||
|
||||
}
|
||||
|
||||
bool DropboxBaseRequest::authentication_required() const {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool DropboxBaseRequest::authenticated() const {
|
||||
|
||||
return service_->authenticated();
|
||||
|
||||
}
|
||||
|
||||
bool DropboxBaseRequest::use_authorization_header() const {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
QByteArray DropboxBaseRequest::authorization_header() const {
|
||||
|
||||
return service_->authorization_header();
|
||||
|
||||
}
|
||||
|
||||
QNetworkReply *DropboxBaseRequest::GetTemporaryLink(const QUrl &url) {
|
||||
|
||||
QJsonObject json_object;
|
||||
json_object.insert("path"_L1, url.path());
|
||||
return CreatePostRequest(QUrl(QLatin1String(kApiUrl) + "/2/files/get_temporary_link"_L1), json_object);
|
||||
|
||||
}
|
||||
|
||||
JsonBaseRequest::JsonObjectResult DropboxBaseRequest::ParseJsonObject(QNetworkReply *reply) {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
||||
return ReplyDataResult(ErrorCode::NetworkError, QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
}
|
||||
|
||||
JsonObjectResult result(ErrorCode::Success);
|
||||
result.network_error = reply->error();
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid()) {
|
||||
result.http_status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
}
|
||||
|
||||
const QByteArray data = reply->readAll();
|
||||
if (!data.isEmpty()) {
|
||||
QJsonParseError json_parse_error;
|
||||
const QJsonDocument json_document = QJsonDocument::fromJson(data, &json_parse_error);
|
||||
if (json_parse_error.error == QJsonParseError::NoError) {
|
||||
const QJsonObject json_object = json_document.object();
|
||||
if (json_object.contains("error"_L1) && json_object["error"_L1].isObject()) {
|
||||
const QJsonObject object_error = json_object["error"_L1].toObject();
|
||||
if (object_error.contains("status"_L1) && object_error.contains("message"_L1)) {
|
||||
const int status = object_error["status"_L1].toInt();
|
||||
const QString message = object_error["message"_L1].toString();
|
||||
result.error_code = ErrorCode::APIError;
|
||||
result.error_message = QStringLiteral("%1 (%2)").arg(message).arg(status);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.json_object = json_document.object();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.error_code = ErrorCode::ParseError;
|
||||
result.error_message = json_parse_error.errorString();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.error_code != ErrorCode::APIError) {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
result.error_code = ErrorCode::NetworkError;
|
||||
result.error_message = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
else if (result.http_status_code != 200) {
|
||||
result.error_code = ErrorCode::HttpError;
|
||||
result.error_message = QStringLiteral("Received HTTP code %1").arg(result.http_status_code);
|
||||
}
|
||||
}
|
||||
|
||||
if (reply->error() == QNetworkReply::AuthenticationRequiredError) {
|
||||
service_->ClearSession();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXBASEREQUEST_H
|
||||
#define DROPBOXBASEREQUEST_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/jsonbaserequest.h"
|
||||
|
||||
class QNetworkReply;
|
||||
class NetworkAccessManager;
|
||||
class DropboxService;
|
||||
|
||||
class DropboxBaseRequest : public JsonBaseRequest {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxBaseRequest(const SharedPtr<NetworkAccessManager> network, DropboxService *service, QObject *parent = nullptr);
|
||||
|
||||
QString service_name() const override;
|
||||
bool authentication_required() const override;
|
||||
bool authenticated() const override;
|
||||
bool use_authorization_header() const override;
|
||||
QByteArray authorization_header() const override;
|
||||
|
||||
protected:
|
||||
QNetworkReply *GetTemporaryLink(const QUrl &url);
|
||||
JsonObjectResult ParseJsonObject(QNetworkReply *reply);
|
||||
|
||||
Q_SIGNALS:
|
||||
void ShowErrorDialog(const QString &error);
|
||||
|
||||
private:
|
||||
DropboxService *service_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXBASEREQUEST_H
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QTimer>
|
||||
|
||||
#include "constants/dropboxsettings.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/database.h"
|
||||
#include "core/urlhandlers.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/oauthenticator.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "collection/collectionmodel.h"
|
||||
#include "streaming/cloudstoragestreamingservice.h"
|
||||
#include "dropboxservice.h"
|
||||
#include "dropboxurlhandler.h"
|
||||
#include "dropboxsongsrequest.h"
|
||||
#include "dropboxstreamurlrequest.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using namespace DropboxSettings;
|
||||
|
||||
const Song::Source DropboxService::kSource = Song::Source::Dropbox;
|
||||
|
||||
namespace {
|
||||
constexpr char kClientIDB64[] = "Zmx0b2EyYzRwaGo2eHlw";
|
||||
constexpr char kClientSecretB64[] = "emo3em5jNnNpM3Ftd2s3";
|
||||
constexpr char kOAuthRedirectUrl[] = "http://localhost/";
|
||||
constexpr char kOAuthAuthorizeUrl[] = "https://www.dropbox.com/1/oauth2/authorize";
|
||||
constexpr char kOAuthAccessTokenUrl[] = "https://api.dropboxapi.com/1/oauth2/token";
|
||||
} // namespace
|
||||
|
||||
DropboxService::DropboxService(const SharedPtr<TaskManager> task_manager,
|
||||
const SharedPtr<Database> database,
|
||||
const SharedPtr<NetworkAccessManager> network,
|
||||
const SharedPtr<UrlHandlers> url_handlers,
|
||||
const SharedPtr<TagReaderClient> tagreader_client,
|
||||
const SharedPtr<AlbumCoverLoader> albumcover_loader,
|
||||
QObject *parent)
|
||||
: CloudStorageStreamingService(task_manager, database, tagreader_client, albumcover_loader, Song::Source::Dropbox, u"Dropbox"_s, u"dropbox"_s, QLatin1String(kSettingsGroup), parent),
|
||||
network_(network),
|
||||
oauth_(new OAuthenticator(network, this)),
|
||||
songs_request_(new DropboxSongsRequest(network, collection_backend_, this, this)),
|
||||
enabled_(false),
|
||||
next_stream_url_request_id_(0) {
|
||||
|
||||
url_handlers->Register(new DropboxUrlHandler(task_manager, this, this));
|
||||
|
||||
oauth_->set_settings_group(QLatin1String(kSettingsGroup));
|
||||
oauth_->set_type(OAuthenticator::Type::Authorization_Code);
|
||||
oauth_->set_authorize_url(QUrl(QLatin1String(kOAuthAuthorizeUrl)));
|
||||
oauth_->set_redirect_url(QUrl(QLatin1String(kOAuthRedirectUrl)));
|
||||
oauth_->set_access_token_url(QUrl(QLatin1String(kOAuthAccessTokenUrl)));
|
||||
oauth_->set_client_id(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)));
|
||||
oauth_->set_client_secret(QString::fromLatin1(QByteArray::fromBase64(kClientSecretB64)));
|
||||
oauth_->set_use_local_redirect_server(true);
|
||||
oauth_->set_random_port(true);
|
||||
|
||||
QObject::connect(oauth_, &OAuthenticator::AuthenticationFinished, this, &DropboxService::OAuthFinished);
|
||||
|
||||
DropboxService::ReloadSettings();
|
||||
oauth_->LoadSession();
|
||||
|
||||
}
|
||||
|
||||
bool DropboxService::authenticated() const {
|
||||
|
||||
return oauth_->authenticated();
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::Exit() {
|
||||
|
||||
wait_for_exit_ << &*collection_backend_;
|
||||
QObject::connect(&*collection_backend_, &CollectionBackend::ExitFinished, this, &DropboxService::ExitReceived);
|
||||
collection_backend_->ExitAsync();
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::ExitReceived() {
|
||||
|
||||
QObject *obj = sender();
|
||||
QObject::disconnect(obj, nullptr, this, nullptr);
|
||||
qLog(Debug) << obj << "successfully exited.";
|
||||
wait_for_exit_.removeAll(obj);
|
||||
if (wait_for_exit_.isEmpty()) Q_EMIT ExitFinished();
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
enabled_ = s.value(kEnabled, false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::Authenticate() {
|
||||
|
||||
oauth_->Authenticate();
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::ClearSession() {
|
||||
|
||||
oauth_->ClearSession();
|
||||
}
|
||||
|
||||
void DropboxService::OAuthFinished(const bool success, const QString &error) {
|
||||
|
||||
if (success) {
|
||||
Q_EMIT LoginFinished(true);
|
||||
Q_EMIT LoginSuccess();
|
||||
}
|
||||
else {
|
||||
Q_EMIT LoginFailure(error);
|
||||
Q_EMIT LoginFinished(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QByteArray DropboxService::authorization_header() const {
|
||||
return oauth_->authorization_header();
|
||||
}
|
||||
|
||||
void DropboxService::Start() {
|
||||
songs_request_->GetFolderList();
|
||||
}
|
||||
|
||||
void DropboxService::Reset() {
|
||||
|
||||
collection_backend_->DeleteAll();
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.remove("cursor");
|
||||
s.endGroup();
|
||||
|
||||
if (authenticated()) {
|
||||
Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint DropboxService::GetStreamURL(const QUrl &url, QString &error) {
|
||||
|
||||
if (!authenticated()) {
|
||||
error = tr("Not authenticated with Dropbox.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint id = 0;
|
||||
while (id == 0) id = ++next_stream_url_request_id_;
|
||||
DropboxStreamURLRequestPtr stream_url_request = DropboxStreamURLRequestPtr(new DropboxStreamURLRequest(network_, this, id, url));
|
||||
stream_url_requests_.insert(id, stream_url_request);
|
||||
QObject::connect(&*stream_url_request, &DropboxStreamURLRequest::StreamURLRequestFinished, this, &DropboxService::StreamURLRequestFinishedSlot);
|
||||
stream_url_request->Process();
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
void DropboxService::StreamURLRequestFinishedSlot(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error) {
|
||||
|
||||
if (!stream_url_requests_.contains(id)) return;
|
||||
DropboxStreamURLRequestPtr stream_url_request = stream_url_requests_.take(id);
|
||||
|
||||
Q_EMIT StreamURLRequestFinished(id, media_url, success, stream_url, error);
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXSERVICE_H
|
||||
#define DROPBOXSERVICE_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "streaming/cloudstoragestreamingservice.h"
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class TaskManager;
|
||||
class Database;
|
||||
class NetworkAccessManager;
|
||||
class UrlHandlers;
|
||||
class TagReaderClient;
|
||||
class AlbumCoverLoader;
|
||||
class OAuthenticator;
|
||||
class DropboxSongsRequest;
|
||||
class DropboxStreamURLRequest;
|
||||
|
||||
class DropboxService : public CloudStorageStreamingService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxService(const SharedPtr<TaskManager> task_manager,
|
||||
const SharedPtr<Database> database,
|
||||
const SharedPtr<NetworkAccessManager> network,
|
||||
const SharedPtr<UrlHandlers> url_handlers,
|
||||
const SharedPtr<TagReaderClient> tagreader_client,
|
||||
const SharedPtr<AlbumCoverLoader> albumcover_loader,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
static const Song::Source kSource;
|
||||
|
||||
bool oauth() const override { return true; }
|
||||
bool authenticated() const override;
|
||||
bool show_progress() const override { return false; }
|
||||
bool enable_refresh_button() const override { return false; }
|
||||
|
||||
void Exit() override;
|
||||
void ReloadSettings() override;
|
||||
|
||||
void Authenticate();
|
||||
void ClearSession();
|
||||
|
||||
void Start();
|
||||
void Reset();
|
||||
uint GetStreamURL(const QUrl &url, QString &error);
|
||||
|
||||
QByteArray authorization_header() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void StreamURLRequestFinished(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error = QString());
|
||||
|
||||
private Q_SLOTS:
|
||||
void ExitReceived();
|
||||
void OAuthFinished(const bool success, const QString &error = QString());
|
||||
void StreamURLRequestFinishedSlot(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error = QString());
|
||||
|
||||
private:
|
||||
const SharedPtr<NetworkAccessManager> network_;
|
||||
OAuthenticator *oauth_;
|
||||
DropboxSongsRequest *songs_request_;
|
||||
bool enabled_;
|
||||
QList<QObject*> wait_for_exit_;
|
||||
bool finished_;
|
||||
uint next_stream_url_request_id_;
|
||||
QMap<uint, QSharedPointer<DropboxStreamURLRequest>> stream_url_requests_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXSERVICE_H
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "constants/dropboxsettings.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "dropboxservice.h"
|
||||
#include "dropboxbaserequest.h"
|
||||
#include "dropboxsongsrequest.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using namespace DropboxSettings;
|
||||
|
||||
DropboxSongsRequest::DropboxSongsRequest(const SharedPtr<NetworkAccessManager> network, const SharedPtr<CollectionBackend> collection_backend, DropboxService *service, QObject *parent)
|
||||
: DropboxBaseRequest(network, service, parent),
|
||||
network_(network),
|
||||
collection_backend_(collection_backend),
|
||||
service_(service) {}
|
||||
|
||||
void DropboxSongsRequest::GetFolderList() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
QString cursor = s.value("cursor").toString();
|
||||
s.endGroup();
|
||||
|
||||
QUrl url(QLatin1String(kApiUrl) + "/2/files/list_folder"_L1);
|
||||
QJsonObject json_object;
|
||||
|
||||
if (cursor.isEmpty()) {
|
||||
json_object.insert("path"_L1, ""_L1);
|
||||
json_object.insert("recursive"_L1, true);
|
||||
json_object.insert("include_deleted"_L1, true);
|
||||
}
|
||||
else {
|
||||
url.setUrl(QLatin1String(kApiUrl) + "/2/files/list_folder/continue"_L1);
|
||||
json_object.insert("cursor"_L1, cursor);
|
||||
}
|
||||
|
||||
QNetworkReply *reply = CreatePostRequest(url, json_object);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply] { GetFolderListFinished(reply); });
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::GetFolderListFinished(QNetworkReply *reply) {
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||
if (json_object_result.success()) {
|
||||
Error(json_object_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject &json_object = json_object_result.json_object;
|
||||
if (json_object.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_object.contains("reset"_L1) && json_object["reset"_L1].toBool()) {
|
||||
qLog(Debug) << "Resetting Dropbox database";
|
||||
collection_backend_->DeleteAll();
|
||||
}
|
||||
|
||||
{
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("cursor", json_object["cursor"_L1].toString());
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
const QJsonArray entires = json_object["entries"_L1].toArray();
|
||||
qLog(Debug) << "File list found:" << entires.size();
|
||||
|
||||
QList<QUrl> urls_deleted;
|
||||
for (const QJsonValue &value_entry : entires) {
|
||||
if (!value_entry.isObject()) {
|
||||
continue;
|
||||
}
|
||||
const QJsonObject object_entry = value_entry.toObject();
|
||||
const QString tag = object_entry[".tag"_L1].toString();
|
||||
const QString path = object_entry["path_lower"_L1].toString();
|
||||
const qint64 size = object_entry["size"_L1].toInt();
|
||||
const QString server_modified = object_entry["server_modified"_L1].toString();
|
||||
|
||||
QUrl url;
|
||||
url.setScheme(service_->url_scheme());
|
||||
url.setPath(path);
|
||||
|
||||
if (tag == "deleted"_L1) {
|
||||
qLog(Debug) << "Deleting song with URL" << url;
|
||||
urls_deleted << url;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag == "folder"_L1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (DropboxService::IsSupportedFiletype(path)) {
|
||||
GetStreamURL(url, path, size, QDateTime::fromString(server_modified, Qt::ISODate).toSecsSinceEpoch());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!urls_deleted.isEmpty()) {
|
||||
collection_backend_->DeleteSongsByUrlsAsync(urls_deleted);
|
||||
}
|
||||
|
||||
if (json_object.contains("has_more"_L1) && json_object["has_more"_L1].isBool() && json_object["has_more"_L1].toBool()) {
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("cursor", json_object["cursor"_L1].toVariant());
|
||||
s.endGroup();
|
||||
GetFolderList();
|
||||
}
|
||||
else {
|
||||
// Long-poll wait for changes.
|
||||
LongPollDelta();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::LongPollDelta() {
|
||||
|
||||
if (!service_->authenticated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
const QString cursor = s.value("cursor").toString();
|
||||
s.endGroup();
|
||||
|
||||
QJsonObject json_object;
|
||||
json_object.insert("cursor"_L1, cursor);
|
||||
json_object.insert("timeout"_L1, 30);
|
||||
|
||||
QNetworkReply *reply = CreatePostRequest(QUrl(QLatin1String(kNotifyApiUrl) + "/2/files/list_folder/longpoll"_L1), json_object);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply] { LongPollDeltaFinished(reply); });
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::LongPollDeltaFinished(QNetworkReply *reply) {
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||
if (json_object_result.success()) {
|
||||
Error(json_object_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject &json_object = json_object_result.json_object;
|
||||
if (json_object["changes"_L1].toBool()) {
|
||||
qLog(Debug) << "Dropbox: Received changes...";
|
||||
GetFolderList();
|
||||
}
|
||||
else {
|
||||
bool ok = false;
|
||||
int backoff = json_object["backoff"_L1].toString().toInt(&ok);
|
||||
if (!ok) {
|
||||
backoff = 10;
|
||||
}
|
||||
QTimer::singleShot(backoff * 1000, this, &DropboxSongsRequest::LongPollDelta);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::GetStreamURL(const QUrl &url, const QString &path, const qint64 size, const qint64 mtime) {
|
||||
|
||||
QNetworkReply *reply = GetTemporaryLink(url);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, path, size, mtime]() {
|
||||
GetStreamUrlFinished(reply, path, size, mtime);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::GetStreamUrlFinished(QNetworkReply *reply, const QString &filename, const qint64 size, const qint64 mtime) {
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||
if (!json_object_result.success()) {
|
||||
Error(json_object_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject &json_object = json_object_result.json_object;
|
||||
if (json_object.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_object.contains("link"_L1)) {
|
||||
Error(u"Missing link"_s);
|
||||
return;
|
||||
}
|
||||
|
||||
const QUrl url = QUrl::fromEncoded(json_object["link"_L1].toVariant().toByteArray());
|
||||
|
||||
service_->MaybeAddFileToDatabase(url, filename, size, mtime);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSongsRequest::Error(const QString &error_message, const QVariant &debug_output) {
|
||||
|
||||
qLog(Error) << service_name() << error_message;
|
||||
if (debug_output.isValid()) {
|
||||
qLog(Debug) << debug_output;
|
||||
}
|
||||
|
||||
Q_EMIT ShowErrorDialog(error_message);
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXSONGSREQUEST_H
|
||||
#define DROPBOXSONGSREQUEST_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "dropboxbaserequest.h"
|
||||
|
||||
class NetworkAccessManager;
|
||||
class CollectionBackend;
|
||||
class QNetworkReply;
|
||||
class DropboxService;
|
||||
|
||||
class DropboxSongsRequest : public DropboxBaseRequest {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxSongsRequest(const SharedPtr<NetworkAccessManager> network, const SharedPtr<CollectionBackend> collection_backend, DropboxService *service, QObject *parent = nullptr);
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
void GetFolderList();
|
||||
|
||||
Q_SIGNALS:
|
||||
void ShowErrorDialog(const QString &error);
|
||||
|
||||
private:
|
||||
void LongPollDelta();
|
||||
void GetStreamURL(const QUrl &url, const QString &path, const qint64 size, const qint64 mtime);
|
||||
|
||||
protected:
|
||||
void Error(const QString &error_message, const QVariant &debug_output = QVariant()) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void GetFolderListFinished(QNetworkReply *reply);
|
||||
void LongPollDeltaFinished(QNetworkReply *reply);
|
||||
void GetStreamUrlFinished(QNetworkReply *reply, const QString &filename, const qint64 size, const qint64 mtime);
|
||||
|
||||
private:
|
||||
const SharedPtr<NetworkAccessManager> network_;
|
||||
const SharedPtr<CollectionBackend> collection_backend_;
|
||||
DropboxService *service_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXSONGSREQUEST_H
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "dropboxservice.h"
|
||||
#include "dropboxbaserequest.h"
|
||||
#include "dropboxstreamurlrequest.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
DropboxStreamURLRequest::DropboxStreamURLRequest(const SharedPtr<NetworkAccessManager> network, DropboxService *service, const uint id, const QUrl &media_url, QObject *parent)
|
||||
: DropboxBaseRequest(network, service, parent),
|
||||
network_(network),
|
||||
service_(service),
|
||||
id_(id),
|
||||
media_url_(media_url),
|
||||
reply_(nullptr) {}
|
||||
|
||||
DropboxStreamURLRequest::~DropboxStreamURLRequest() {
|
||||
|
||||
if (reply_) {
|
||||
QObject::disconnect(reply_, nullptr, this, nullptr);
|
||||
if (reply_->isRunning()) reply_->abort();
|
||||
reply_->deleteLater();
|
||||
reply_ = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::Cancel() {
|
||||
|
||||
if (reply_ && reply_->isRunning()) {
|
||||
reply_->abort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::Process() {
|
||||
|
||||
GetStreamURL();
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::GetStreamURL() {
|
||||
|
||||
if (reply_) {
|
||||
QObject::disconnect(reply_, nullptr, this, nullptr);
|
||||
if (reply_->isRunning()) reply_->abort();
|
||||
reply_->deleteLater();
|
||||
}
|
||||
|
||||
reply_ = GetTemporaryLink(media_url_);
|
||||
QObject::connect(reply_, &QNetworkReply::finished, this, &DropboxStreamURLRequest::StreamURLReceived);
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::StreamURLReceived() {
|
||||
|
||||
const QScopeGuard finish = qScopeGuard([this]() { Finish(); });
|
||||
|
||||
if (!reply_) return;
|
||||
|
||||
Q_ASSERT(replies_.contains(reply_));
|
||||
replies_.removeAll(reply_);
|
||||
|
||||
const JsonObjectResult json_object_result = ParseJsonObject(reply_).json_object;
|
||||
|
||||
QObject::disconnect(reply_, nullptr, this, nullptr);
|
||||
reply_->deleteLater();
|
||||
reply_ = nullptr;
|
||||
|
||||
if (!json_object_result.success()) {
|
||||
Error(json_object_result.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject &json_object = json_object_result.json_object;
|
||||
if (json_object.isEmpty() || !json_object.contains("link"_L1)) {
|
||||
Error(u"Could not parse stream URL"_s);
|
||||
return;
|
||||
}
|
||||
|
||||
stream_url_ = QUrl::fromEncoded(json_object["link"_L1].toVariant().toByteArray());
|
||||
success_ = stream_url_.isValid();
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::Error(const QString &error_message, const QVariant &debug_output) {
|
||||
|
||||
qLog(Error) << service_name() << error_message;
|
||||
if (debug_output.isValid()) {
|
||||
qLog(Debug) << debug_output;
|
||||
}
|
||||
|
||||
error_ = error_message;
|
||||
|
||||
}
|
||||
|
||||
void DropboxStreamURLRequest::Finish() {
|
||||
|
||||
Q_EMIT StreamURLRequestFinished(id_, media_url_, success_, stream_url_, error_);
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXSTREAMURLREQUEST_H
|
||||
#define DROPBOXSTREAMURLREQUEST_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "dropboxservice.h"
|
||||
#include "dropboxbaserequest.h"
|
||||
|
||||
class QNetworkReply;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class DropboxStreamURLRequest : public DropboxBaseRequest {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxStreamURLRequest(const SharedPtr<NetworkAccessManager> network, DropboxService *service, const uint id, const QUrl &media_url, QObject *parent = nullptr);
|
||||
~DropboxStreamURLRequest() override;
|
||||
|
||||
void Process();
|
||||
void Cancel();
|
||||
|
||||
Q_SIGNALS:
|
||||
void StreamURLRequestFinished(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error = QString());
|
||||
|
||||
private Q_SLOTS:
|
||||
void StreamURLReceived();
|
||||
|
||||
private:
|
||||
void GetStreamURL();
|
||||
void Error(const QString &error_message, const QVariant &debug_output = QVariant()) override;
|
||||
void Finish();
|
||||
|
||||
private:
|
||||
const SharedPtr<NetworkAccessManager> network_;
|
||||
DropboxService *service_;
|
||||
uint id_;
|
||||
QUrl media_url_;
|
||||
QUrl stream_url_;
|
||||
QNetworkReply *reply_;
|
||||
bool success_;
|
||||
QString error_;
|
||||
};
|
||||
|
||||
using DropboxStreamURLRequestPtr = QSharedPointer<DropboxStreamURLRequest>;
|
||||
|
||||
#endif // DROPBOXSTREAMURLREQUEST_H
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "dropboxurlhandler.h"
|
||||
#include "dropboxservice.h"
|
||||
|
||||
DropboxUrlHandler::DropboxUrlHandler(const SharedPtr<TaskManager> task_manager, DropboxService *service, QObject *parent)
|
||||
: UrlHandler(parent),
|
||||
task_manager_(task_manager),
|
||||
service_(service) {
|
||||
|
||||
QObject::connect(service, &DropboxService::StreamURLRequestFinished, this, &DropboxUrlHandler::StreamURLRequestFinished);
|
||||
|
||||
}
|
||||
|
||||
QString DropboxUrlHandler::scheme() const { return service_->url_scheme(); }
|
||||
|
||||
UrlHandler::LoadResult DropboxUrlHandler::StartLoading(const QUrl &url) {
|
||||
|
||||
Request request;
|
||||
request.task_id = task_manager_->StartTask(QStringLiteral("Loading %1 stream...").arg(url.scheme()));
|
||||
QString error;
|
||||
request.id = service_->GetStreamURL(url, error);
|
||||
if (request.id == 0) {
|
||||
CancelTask(request.task_id);
|
||||
return LoadResult(url, LoadResult::Type::Error, error);
|
||||
}
|
||||
|
||||
requests_.insert(request.id, request);
|
||||
|
||||
LoadResult load_result(url);
|
||||
load_result.type_ = LoadResult::Type::WillLoadAsynchronously;
|
||||
|
||||
return load_result;
|
||||
|
||||
}
|
||||
|
||||
void DropboxUrlHandler::StreamURLRequestFinished(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error) {
|
||||
|
||||
if (!requests_.contains(id)) return;
|
||||
const Request request = requests_.take(id);
|
||||
CancelTask(request.task_id);
|
||||
|
||||
if (success) {
|
||||
Q_EMIT AsyncLoadComplete(LoadResult(media_url, LoadResult::Type::TrackAvailable, stream_url));
|
||||
}
|
||||
else {
|
||||
Q_EMIT AsyncLoadComplete(LoadResult(media_url, LoadResult::Type::Error, error));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DropboxUrlHandler::CancelTask(const int task_id) {
|
||||
task_manager_->SetTaskFinished(task_id);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXURLHANDLER_H
|
||||
#define DROPBOXURLHANDLER_H
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/urlhandler.h"
|
||||
|
||||
class TaskManager;
|
||||
class DropboxService;
|
||||
|
||||
class DropboxUrlHandler : public UrlHandler {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxUrlHandler(const SharedPtr<TaskManager> task_manager, DropboxService *service, QObject *parent = nullptr);
|
||||
|
||||
QString scheme() const override;
|
||||
LoadResult StartLoading(const QUrl &url) override;
|
||||
|
||||
private:
|
||||
void CancelTask(const int task_id);
|
||||
|
||||
private Q_SLOTS:
|
||||
void StreamURLRequestFinished(const uint id, const QUrl &media_url, const bool success, const QUrl &stream_url, const QString &error = QString());
|
||||
|
||||
private:
|
||||
class Request {
|
||||
public:
|
||||
explicit Request() : id(0), task_id(-1) {}
|
||||
uint id;
|
||||
int task_id;
|
||||
};
|
||||
const SharedPtr<TaskManager> task_manager_;
|
||||
DropboxService *service_;
|
||||
QMap<uint, Request> requests_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXURLHANDLER_H
|
||||
@@ -36,7 +36,7 @@ class GstBufferConsumer {
|
||||
|
||||
// This is called in some unspecified GStreamer thread.
|
||||
// Ownership of the buffer is transferred to the BufferConsumer, and it should gst_buffer_unref it.
|
||||
virtual void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) = 0;
|
||||
virtual void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) = 0;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(GstBufferConsumer)
|
||||
|
||||
@@ -543,7 +543,9 @@ void GstEngine::ReloadSettings() {
|
||||
|
||||
}
|
||||
|
||||
void GstEngine::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) {
|
||||
void GstEngine::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) {
|
||||
|
||||
Q_UNUSED(channels);
|
||||
|
||||
// Schedule this to run in the GUI thread. The buffer gets added to the queue and unreffed by UpdateScope.
|
||||
if (!QMetaObject::invokeMethod(this, "AddBufferToScope", Q_ARG(GstBuffer*, buffer), Q_ARG(int, pipeline_id), Q_ARG(QString, format))) {
|
||||
|
||||
@@ -84,7 +84,7 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
bool ALSADeviceSupport(const QString &output) const override;
|
||||
bool ExclusiveModeSupport(const QString &output) const override;
|
||||
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format) override;
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void ReloadSettings() override;
|
||||
|
||||
@@ -1385,7 +1385,7 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
|
||||
|
||||
for (GstBufferConsumer *consumer : std::as_const(consumers)) {
|
||||
gst_buffer_ref(buf);
|
||||
consumer->ConsumeBuffer(buf, instance->id(), format);
|
||||
consumer->ConsumeBuffer(buf, instance->id(), format, channels);
|
||||
}
|
||||
|
||||
if (buf16) {
|
||||
|
||||
@@ -56,7 +56,7 @@ using namespace Qt::Literals::StringLiterals;
|
||||
using std::make_shared;
|
||||
|
||||
namespace {
|
||||
constexpr int kSongTableJoins = 3;
|
||||
constexpr int kSongTableJoins = 2;
|
||||
}
|
||||
|
||||
PlaylistBackend::PlaylistBackend(const SharedPtr<Database> database,
|
||||
@@ -186,12 +186,10 @@ PlaylistBackend::Playlist PlaylistBackend::GetPlaylist(const int id) {
|
||||
|
||||
QString PlaylistBackend::PlaylistItemsQuery() {
|
||||
|
||||
return QStringLiteral("SELECT %1, %2, %3, p.type FROM playlist_items AS p "
|
||||
return QStringLiteral("SELECT %1, %2, p.type FROM playlist_items AS p "
|
||||
"LEFT JOIN songs ON p.type = songs.source AND p.collection_id = songs.ROWID "
|
||||
"LEFT JOIN dropbox_songs ON p.type = dropbox_songs.source AND p.collection_id = dropbox_songs.ROWID "
|
||||
"WHERE p.playlist = :playlist"
|
||||
).arg(Song::JoinSpec(u"songs"_s),
|
||||
Song::JoinSpec(u"dropbox_songs"_s),
|
||||
Song::JoinSpec(u"p"_s));
|
||||
|
||||
}
|
||||
|
||||
@@ -47,8 +47,6 @@ PlaylistItemPtr PlaylistItem::NewFromSource(const Song::Source source) {
|
||||
|
||||
switch (source) {
|
||||
case Song::Source::Collection:
|
||||
case Song::Source::Dropbox:
|
||||
case Song::Source::OneDrive:
|
||||
return make_shared<CollectionPlaylistItem>(source);
|
||||
case Song::Source::Subsonic:
|
||||
case Song::Source::Tidal:
|
||||
@@ -74,8 +72,6 @@ PlaylistItemPtr PlaylistItem::NewFromSong(const Song &song) {
|
||||
|
||||
switch (song.source()) {
|
||||
case Song::Source::Collection:
|
||||
case Song::Source::Dropbox:
|
||||
case Song::Source::OneDrive:
|
||||
return make_shared<CollectionPlaylistItem>(song);
|
||||
case Song::Source::Subsonic:
|
||||
case Song::Source::Tidal:
|
||||
|
||||
@@ -34,7 +34,7 @@ SongPlaylistItem::SongPlaylistItem(const Song::Source source) : PlaylistItem(sou
|
||||
SongPlaylistItem::SongPlaylistItem(const Song &song) : PlaylistItem(song.source()), song_(song) {}
|
||||
|
||||
bool SongPlaylistItem::InitFromQuery(const SqlRow &query) {
|
||||
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count() * 2));
|
||||
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void StreamPlaylistItem::InitMetadata() {
|
||||
|
||||
bool StreamPlaylistItem::InitFromQuery(const SqlRow &query) {
|
||||
|
||||
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count() * 2));
|
||||
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count()));
|
||||
InitMetadata();
|
||||
return true;
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QMessageBox>
|
||||
#include <QEvent>
|
||||
|
||||
#include "constants/dropboxsettings.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "widgets/loginstatewidget.h"
|
||||
#include "dropbox/dropboxservice.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "dropboxsettingspage.h"
|
||||
#include "ui_dropboxsettingspage.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using namespace DropboxSettings;
|
||||
|
||||
DropboxSettingsPage::DropboxSettingsPage(SettingsDialog *dialog, const SharedPtr<DropboxService> service, QWidget *parent)
|
||||
: SettingsPage(dialog, parent),
|
||||
ui_(new Ui_DropboxSettingsPage),
|
||||
service_(service) {
|
||||
|
||||
Q_ASSERT(service);
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setWindowIcon(IconLoader::Load(u"dropbox"_s));
|
||||
|
||||
ui_->login_state->AddCredentialGroup(ui_->widget_authorization);
|
||||
|
||||
QObject::connect(ui_->button_login, &QPushButton::clicked, this, &DropboxSettingsPage::LoginClicked);
|
||||
QObject::connect(ui_->button_reset, &QPushButton::clicked, this, &DropboxSettingsPage::ResetClicked);
|
||||
QObject::connect(ui_->login_state, &LoginStateWidget::LogoutClicked, this, &DropboxSettingsPage::LogoutClicked);
|
||||
|
||||
QObject::connect(this, &DropboxSettingsPage::Authorize, &*service_, &DropboxService::Authenticate);
|
||||
QObject::connect(&*service_, &StreamingService::LoginFailure, this, &DropboxSettingsPage::LoginFailure);
|
||||
QObject::connect(&*service_, &StreamingService::LoginSuccess, this, &DropboxSettingsPage::LoginSuccess);
|
||||
|
||||
dialog->installEventFilter(this);
|
||||
|
||||
}
|
||||
|
||||
DropboxSettingsPage::~DropboxSettingsPage() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::Load() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
ui_->enable->setChecked(s.value(kEnabled, false).toBool());
|
||||
s.endGroup();
|
||||
|
||||
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedIn);
|
||||
|
||||
Init(ui_->layout_dropboxsettingspage->parentWidget());
|
||||
|
||||
if (!Settings().childGroups().contains(QLatin1String(kSettingsGroup))) set_changed();
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::Save() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue(kEnabled, ui_->enable->isChecked());
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginClicked() {
|
||||
|
||||
Q_EMIT Authorize();
|
||||
|
||||
ui_->button_login->setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
bool DropboxSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
||||
|
||||
if (object == dialog() && event->type() == QEvent::Enter) {
|
||||
ui_->button_login->setEnabled(true);
|
||||
}
|
||||
|
||||
return SettingsPage::eventFilter(object, event);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LogoutClicked() {
|
||||
|
||||
service_->ClearSession();
|
||||
ui_->button_login->setEnabled(true);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginSuccess() {
|
||||
|
||||
if (!isVisible()) return;
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedIn);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginFailure(const QString &failure_reason) {
|
||||
|
||||
if (!isVisible()) return;
|
||||
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::ResetClicked() {
|
||||
|
||||
service_->Reset();
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DROPBOXSETTINGSPAGE_H
|
||||
#define DROPBOXSETTINGSPAGE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "settingspage.h"
|
||||
|
||||
class DropboxService;
|
||||
class Ui_DropboxSettingsPage;
|
||||
|
||||
class DropboxSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxSettingsPage(SettingsDialog *dialog, const SharedPtr<DropboxService> service, QWidget *parent);
|
||||
~DropboxSettingsPage();
|
||||
|
||||
void Load() override;
|
||||
void Save() override;
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void Authorize();
|
||||
|
||||
private Q_SLOTS:
|
||||
void LoginClicked();
|
||||
void LogoutClicked();
|
||||
void LoginSuccess();
|
||||
void LoginFailure(const QString &failure_reason);
|
||||
void ResetClicked();
|
||||
|
||||
private:
|
||||
Ui_DropboxSettingsPage *ui_;
|
||||
const SharedPtr<DropboxService> service_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXSETTINGSPAGE_H
|
||||
@@ -1,125 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DropboxSettingsPage</class>
|
||||
<widget class="QWidget" name="DropboxSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>569</width>
|
||||
<height>491</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dropbox</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_dropboxsettingspage">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_info">
|
||||
<property name="text">
|
||||
<string>Strawberry can play music that you have uploaded to Dropbox</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enable">
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LoginStateWidget" name="login_state" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_authorization" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>28</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_login">
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_login">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_buttons">
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_reset">
|
||||
<property name="text">
|
||||
<string>Reset cursor and songs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_buttons">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_bottom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>357</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LoginStateWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgets/loginstatewidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -90,10 +90,6 @@
|
||||
# include "qobuz/qobuzservice.h"
|
||||
# include "qobuzsettingspage.h"
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
# include "dropbox/dropboxservice.h"
|
||||
# include "dropboxsettingspage.h"
|
||||
#endif
|
||||
|
||||
#include "ui_settingsdialog.h"
|
||||
|
||||
@@ -148,7 +144,7 @@ SettingsDialog::SettingsDialog(const SharedPtr<Player> player,
|
||||
AddPage(Page::Moodbar, new MoodbarSettingsPage(this, this), iface);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_SPOTIFY) || defined(HAVE_QOBUZ) || defined(HAVE_DROPBOX)
|
||||
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_SPOTIFY) || defined(HAVE_QOBUZ)
|
||||
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
|
||||
#endif
|
||||
|
||||
@@ -164,9 +160,6 @@ SettingsDialog::SettingsDialog(const SharedPtr<Player> player,
|
||||
#ifdef HAVE_QOBUZ
|
||||
AddPage(Page::Qobuz, new QobuzSettingsPage(this, streaming_services->Service<QobuzService>(), this), streaming);
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
AddPage(Page::Dropbox, new DropboxSettingsPage(this, streaming_services->Service<DropboxService>(), this), streaming);
|
||||
#endif
|
||||
|
||||
// List box
|
||||
QObject::connect(ui_->list, &QTreeWidget::currentItemChanged, this, &SettingsDialog::CurrentItemChanged);
|
||||
|
||||
@@ -93,8 +93,6 @@ class SettingsDialog : public QDialog {
|
||||
Tidal,
|
||||
Qobuz,
|
||||
Spotify,
|
||||
Dropbox,
|
||||
OneDrive,
|
||||
};
|
||||
|
||||
enum Role {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/database.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/song.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "collection/collectionmodel.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "cloudstoragestreamingservice.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using std::make_shared;
|
||||
|
||||
CloudStorageStreamingService::CloudStorageStreamingService(const SharedPtr<TaskManager> task_manager,
|
||||
const SharedPtr<Database> database,
|
||||
const SharedPtr<TagReaderClient> tagreader_client,
|
||||
const SharedPtr<AlbumCoverLoader> albumcover_loader,
|
||||
const Song::Source source,
|
||||
const QString &name,
|
||||
const QString &url_scheme,
|
||||
const QString &settings_group,
|
||||
QObject *parent)
|
||||
: StreamingService(source, name, url_scheme, settings_group, parent),
|
||||
task_manager_(task_manager),
|
||||
tagreader_client_(tagreader_client),
|
||||
source_(source),
|
||||
indexing_task_id_(-1),
|
||||
indexing_task_progress_(0),
|
||||
indexing_task_max_(0) {
|
||||
|
||||
collection_backend_ = make_shared<CollectionBackend>();
|
||||
collection_backend_->moveToThread(database->thread());
|
||||
collection_backend_->Init(database, task_manager, source, name + "_songs"_L1);
|
||||
collection_model_ = new CollectionModel(collection_backend_, albumcover_loader, this);
|
||||
|
||||
}
|
||||
|
||||
void CloudStorageStreamingService::MaybeAddFileToDatabase(const QUrl &url, const QString &filename, const size_t size, const quint64 mtime, const QString &token_type, const QString &access_token) {
|
||||
|
||||
if (!IsSupportedFiletype(filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexing_task_id_ == -1) {
|
||||
indexing_task_id_ = task_manager_->StartTask(tr("Indexing %1").arg(name()));
|
||||
indexing_task_progress_ = 0;
|
||||
indexing_task_max_ = 0;
|
||||
}
|
||||
indexing_task_max_++;
|
||||
task_manager_->SetTaskProgress(indexing_task_id_, indexing_task_progress_, indexing_task_max_);
|
||||
|
||||
TagReaderReadStreamReplyPtr reply = tagreader_client_->ReadStreamAsync(url, filename, size, mtime, token_type, access_token);
|
||||
pending_tagreader_replies_.append(reply);
|
||||
|
||||
SharedPtr<QMetaObject::Connection> connection = make_shared<QMetaObject::Connection>();
|
||||
*connection = QObject::connect(&*reply, &TagReaderReadStreamReply::Finished, this, [this, reply, url, filename, connection]() {
|
||||
ReadStreamFinished(reply, url, filename);
|
||||
QObject::disconnect(*connection);
|
||||
}, Qt::QueuedConnection);
|
||||
|
||||
}
|
||||
|
||||
void CloudStorageStreamingService::ReadStreamFinished(TagReaderReadStreamReplyPtr reply, const QUrl url, const QString filename) {
|
||||
|
||||
++indexing_task_progress_;
|
||||
if (indexing_task_progress_ >= indexing_task_max_) {
|
||||
task_manager_->SetTaskFinished(indexing_task_id_);
|
||||
indexing_task_id_ = -1;
|
||||
Q_EMIT AllIndexingTasksFinished();
|
||||
}
|
||||
else {
|
||||
task_manager_->SetTaskProgress(indexing_task_id_, indexing_task_progress_, indexing_task_max_);
|
||||
}
|
||||
|
||||
if (!reply->result().success()) {
|
||||
qLog(Error) << "Failed to read tags from stream, URL" << url << reply->result().error_string();
|
||||
return;
|
||||
}
|
||||
|
||||
Song song = reply->song();
|
||||
song.set_source(source_);
|
||||
song.set_directory_id(0);
|
||||
QUrl song_url;
|
||||
song_url.setScheme(url_scheme());
|
||||
song_url.setPath(filename);
|
||||
song.set_url(song_url);
|
||||
|
||||
collection_backend_->AddOrUpdateSongs(SongList() << song);
|
||||
|
||||
}
|
||||
|
||||
bool CloudStorageStreamingService::IsSupportedFiletype(const QString &filename) {
|
||||
|
||||
const QFileInfo fileinfo(filename);
|
||||
return Song::kAcceptedExtensions.contains(fileinfo.suffix(), Qt::CaseInsensitive) && !Song::kRejectedExtensions.contains(fileinfo.suffix(), Qt::CaseInsensitive);
|
||||
|
||||
}
|
||||
|
||||
void CloudStorageStreamingService::AbortReadTagsReplies() {
|
||||
|
||||
qLog(Debug) << "Aborting the read tags replies";
|
||||
|
||||
pending_tagreader_replies_.clear();
|
||||
|
||||
task_manager_->SetTaskFinished(indexing_task_id_);
|
||||
indexing_task_id_ = -1;
|
||||
|
||||
Q_EMIT AllIndexingTasksFinished();
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CLOUDSTORAGESTREAMINGSERVICE_H
|
||||
#define CLOUDSTORAGESTREAMINGSERVICE_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "tagreader/tagreaderclient.h"
|
||||
#include "streamingservice.h"
|
||||
#include "covermanager/albumcovermanager.h"
|
||||
#include "collection/collectionmodel.h"
|
||||
|
||||
class TaskManager;
|
||||
class Database;
|
||||
class TagReaderClient;
|
||||
class AlbumCoverLoader;
|
||||
class CollectionBackend;
|
||||
class CollectionModel;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class CloudStorageStreamingService : public StreamingService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CloudStorageStreamingService(const SharedPtr<TaskManager> task_manager,
|
||||
const SharedPtr<Database> database,
|
||||
const SharedPtr<TagReaderClient> tagreader_client,
|
||||
const SharedPtr<AlbumCoverLoader> albumcover_loader,
|
||||
const Song::Source source,
|
||||
const QString &name,
|
||||
const QString &url_scheme,
|
||||
const QString &settings_group,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
bool is_indexing() const { return indexing_task_id_ != -1; }
|
||||
|
||||
SharedPtr<CollectionBackend> collection_backend() const { return collection_backend_; }
|
||||
CollectionModel *collection_model() const { return collection_model_; }
|
||||
CollectionFilter *collection_filter_model() const { return collection_model_->filter(); }
|
||||
|
||||
SharedPtr<CollectionBackend> songs_collection_backend() override { return collection_backend_; }
|
||||
CollectionModel *songs_collection_model() override { return collection_model_; }
|
||||
CollectionFilter *songs_collection_filter_model() override { return collection_model_->filter(); }
|
||||
|
||||
virtual void MaybeAddFileToDatabase(const QUrl &url, const QString &filename, const size_t size, const quint64 mtime, const QString &token_type = QString(), const QString &access_token = QString());
|
||||
static bool IsSupportedFiletype(const QString &filename);
|
||||
|
||||
Q_SIGNALS:
|
||||
void AllIndexingTasksFinished();
|
||||
|
||||
protected:
|
||||
void AbortReadTagsReplies();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void ReadStreamFinished(TagReaderReadStreamReplyPtr reply, const QUrl url, const QString filename);
|
||||
|
||||
protected:
|
||||
const SharedPtr<TaskManager> task_manager_;
|
||||
const SharedPtr<TagReaderClient> tagreader_client_;
|
||||
SharedPtr<CollectionBackend> collection_backend_;
|
||||
CollectionModel *collection_model_;
|
||||
QList<TagReaderReplyPtr> pending_tagreader_replies_;
|
||||
|
||||
private:
|
||||
Song::Source source_;
|
||||
int indexing_task_id_;
|
||||
int indexing_task_progress_;
|
||||
int indexing_task_max_;
|
||||
};
|
||||
|
||||
#endif // CLOUDSTORAGESTREAMINGSERVICE_H
|
||||
@@ -142,8 +142,6 @@ QString CoverUtils::CoverFilenameFromSource(const Song::Source source, const QUr
|
||||
case Song::Source::Stream:
|
||||
case Song::Source::SomaFM:
|
||||
case Song::Source::RadioParadise:
|
||||
case Song::Source::Dropbox:
|
||||
case Song::Source::OneDrive:
|
||||
case Song::Source::Unknown:
|
||||
filename = QString::fromLatin1(Sha1CoverHash(artist, album).toHex());
|
||||
break;
|
||||
|
||||
159
src/visualizations/projectmpresetmodel.cpp
Normal file
159
src/visualizations/projectmpresetmodel.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include "core/logging.h"
|
||||
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
ProjectMPresetModel::ProjectMPresetModel(ProjectMVisualization *projectm_visualization, QObject *parent)
|
||||
: QAbstractItemModel(parent),
|
||||
projectm_visualization_(projectm_visualization) {
|
||||
|
||||
// Find presets
|
||||
if (QFileInfo::exists(projectm_visualization_->preset_path())) {
|
||||
QDirIterator it(projectm_visualization_->preset_path(), QStringList() << QStringLiteral("*.milk") << QStringLiteral("*.prjm"), QDir::Files | QDir::NoDotAndDotDot | QDir::Readable, QDirIterator::Subdirectories);
|
||||
QStringList files;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
files << it.filePath();
|
||||
}
|
||||
std::stable_sort(files.begin(), files.end());
|
||||
for (const QString &filepath : std::as_const(files)) {
|
||||
const QFileInfo fileinfo(filepath);
|
||||
all_presets_ << Preset(fileinfo.filePath(), fileinfo.fileName(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qLog(Error) << "ProjectM preset path" << projectm_visualization_->preset_path() << "does not exist";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ProjectMPresetModel::rowCount(const QModelIndex &idx) const {
|
||||
|
||||
Q_UNUSED(idx);
|
||||
|
||||
if (!projectm_visualization_) return 0;
|
||||
|
||||
return static_cast<int>(all_presets_.count());
|
||||
|
||||
}
|
||||
|
||||
int ProjectMPresetModel::columnCount(const QModelIndex &idx) const {
|
||||
Q_UNUSED(idx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QModelIndex ProjectMPresetModel::index(const int row, const int column, const QModelIndex &idx) const {
|
||||
Q_UNUSED(idx);
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QModelIndex ProjectMPresetModel::parent(const QModelIndex &child) const {
|
||||
Q_UNUSED(child);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QVariant ProjectMPresetModel::data(const QModelIndex &index, const int role) const {
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return all_presets_[index.row()].name_;
|
||||
case Qt::CheckStateRole:{
|
||||
bool selected = all_presets_[index.row()].selected_;
|
||||
return selected ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
case Role::Role_Path:
|
||||
return all_presets_[index.row()].path_;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectMPresetModel::flags(const QModelIndex &idx) const {
|
||||
|
||||
if (!idx.isValid()) return QAbstractItemModel::flags(idx);
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
|
||||
|
||||
}
|
||||
|
||||
bool ProjectMPresetModel::setData(const QModelIndex &idx, const QVariant &value, int role) {
|
||||
|
||||
if (role == Qt::CheckStateRole) {
|
||||
all_presets_[idx.row()].selected_ = value.toBool();
|
||||
projectm_visualization_->SetSelected(QStringList() << all_presets_[idx.row()].path_, value.toBool());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SetImmediatePreset(const QModelIndex &idx) {
|
||||
projectm_visualization_->SetImmediatePreset(all_presets_[idx.row()].path_);
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SelectAll() {
|
||||
|
||||
QStringList paths;
|
||||
paths.reserve(all_presets_.count());
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
paths << all_presets_[i].path_;
|
||||
all_presets_[i].selected_ = true;
|
||||
}
|
||||
projectm_visualization_->SetSelected(paths, true);
|
||||
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::SelectNone() {
|
||||
|
||||
projectm_visualization_->ClearSelected();
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
all_presets_[i].selected_ = false;
|
||||
}
|
||||
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||
|
||||
}
|
||||
|
||||
void ProjectMPresetModel::MarkSelected(const QString &path, const bool selected) {
|
||||
|
||||
for (int i = 0; i < all_presets_.count(); ++i) {
|
||||
if (path == all_presets_[i].path_) {
|
||||
all_presets_[i].selected_ = selected;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
77
src/visualizations/projectmpresetmodel.h
Normal file
77
src/visualizations/projectmpresetmodel.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECTMPRESETMODEL_H
|
||||
#define PROJECTMPRESETMODEL_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class ProjectMVisualization;
|
||||
|
||||
class ProjectMPresetModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
friend class ProjectMVisualization;
|
||||
|
||||
public:
|
||||
explicit ProjectMPresetModel(ProjectMVisualization *projectm_visualization, QObject *parent = nullptr);
|
||||
|
||||
enum Role {
|
||||
Role_Path = Qt::UserRole,
|
||||
};
|
||||
|
||||
void MarkSelected(const QString &path, bool selected);
|
||||
|
||||
// QAbstractItemModel
|
||||
QModelIndex index(const int row, const int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, const int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, const int role = Qt::EditRole) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetImmediatePreset(const QModelIndex &index);
|
||||
void SelectAll();
|
||||
void SelectNone();
|
||||
|
||||
private:
|
||||
struct Preset {
|
||||
explicit Preset(const QString &path, const QString &name, const bool selected)
|
||||
: path_(path),
|
||||
name_(name),
|
||||
selected_(selected) {}
|
||||
|
||||
QString path_;
|
||||
QString name_;
|
||||
bool selected_;
|
||||
};
|
||||
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
QList<Preset> all_presets_;
|
||||
};
|
||||
|
||||
#endif // PROJECTMPRESETMODEL_H
|
||||
469
src/visualizations/projectmvisualization.cpp
Normal file
469
src/visualizations/projectmvisualization.cpp
Normal file
@@ -0,0 +1,469 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
# include <projectM-4/types.h>
|
||||
# include <projectM-4/core.h>
|
||||
# include <projectM-4/parameters.h>
|
||||
# include <projectM-4/memory.h>
|
||||
# include <projectM-4/audio.h>
|
||||
# include <projectM-4/render_opengl.h>
|
||||
# include <projectM-4/playlist_types.h>
|
||||
# include <projectM-4/playlist_core.h>
|
||||
# include <projectM-4/playlist_memory.h>
|
||||
# include <projectM-4/playlist_items.h>
|
||||
# include <projectM-4/playlist_playback.h>
|
||||
#else
|
||||
# include <libprojectM/projectM.hpp>
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QScopeGuard>
|
||||
#include <QPainter>
|
||||
#include <QRandomGenerator>
|
||||
#include <QMessageBox>
|
||||
#include <QTimerEvent>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "projectmvisualization.h"
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "visualizationcontainer.h"
|
||||
|
||||
ProjectMVisualization::ProjectMVisualization(VisualizationContainer *container)
|
||||
: QGraphicsScene(container),
|
||||
container_(container),
|
||||
preset_model_(nullptr),
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_instance_(nullptr),
|
||||
projectm_playlist_instance_(nullptr),
|
||||
#endif
|
||||
mode_(Mode::Random),
|
||||
duration_(15),
|
||||
texture_size_(512) {
|
||||
|
||||
QObject::connect(this, &QGraphicsScene::sceneRectChanged, this, &ProjectMVisualization::SceneRectChanged);
|
||||
|
||||
#ifndef HAVE_PROJECTM4
|
||||
for (int i = 0; i < TOTAL_RATING_TYPES; ++i) {
|
||||
default_rating_list_.push_back(3);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
ProjectMVisualization::~ProjectMVisualization() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_playlist_instance_) {
|
||||
projectm_playlist_destroy(projectm_playlist_instance_);
|
||||
}
|
||||
if (projectm_instance_) {
|
||||
projectm_destroy(projectm_instance_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Init() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
return;
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
// Find the projectM presets
|
||||
|
||||
QStringList data_paths = QStringList() << QStringLiteral("/usr/share")
|
||||
<< QStringLiteral("/usr/local/share")
|
||||
<< QLatin1String(CMAKE_INSTALL_PREFIX) + QLatin1String("/share");
|
||||
|
||||
const QStringList xdg_data_dirs = QString::fromUtf8(qgetenv("XDG_DATA_DIRS")).split(QLatin1Char(':'));
|
||||
for (const QString &xdg_data_dir : xdg_data_dirs) {
|
||||
if (!data_paths.contains(xdg_data_dir)) {
|
||||
data_paths.append(xdg_data_dir);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
data_paths.prepend(QCoreApplication::applicationDirPath());
|
||||
#endif
|
||||
|
||||
const QStringList projectm_paths = QStringList() << QStringLiteral("projectM/presets")
|
||||
<< QStringLiteral("projectm-presets");
|
||||
|
||||
QStringList preset_paths;
|
||||
for (const QString &data_path : std::as_const(data_paths)) {
|
||||
for (const QString &projectm_path : projectm_paths) {
|
||||
const QString path = data_path + QLatin1Char('/') + projectm_path;
|
||||
if (!QFileInfo::exists(path) || QDir(path).entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot).isEmpty()) {
|
||||
preset_paths << path;
|
||||
continue;
|
||||
}
|
||||
preset_path_ = path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Create projectM settings
|
||||
#ifdef HAVE_PROJECTM4
|
||||
Q_ASSERT(projectm_instance_ == nullptr);
|
||||
Q_ASSERT(projectm_playlist_instance_ == nullptr);
|
||||
projectm_instance_ = projectm_create();
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
projectm_set_mesh_size(projectm_instance_, 32, 24);
|
||||
projectm_set_fps(projectm_instance_, 35);
|
||||
projectm_set_window_size(projectm_instance_, 512, 512);
|
||||
projectm_playlist_instance_ = projectm_playlist_create(projectm_instance_);
|
||||
#else
|
||||
projectM::Settings s;
|
||||
s.presetURL = preset_path_.toStdString();
|
||||
s.meshX = 32;
|
||||
s.meshY = 24;
|
||||
s.textureSize = texture_size_;
|
||||
s.fps = 35;
|
||||
s.windowWidth = 512;
|
||||
s.windowHeight = 512;
|
||||
s.smoothPresetDuration = 5;
|
||||
s.presetDuration = duration_;
|
||||
s.shuffleEnabled = true;
|
||||
s.softCutRatingsEnabled = false;
|
||||
s.easterEgg = 0;
|
||||
projectm_ = std::make_unique<projectM>(s);
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
Q_ASSERT(preset_model_ == nullptr);
|
||||
preset_model_ = new ProjectMPresetModel(this, this);
|
||||
|
||||
Load();
|
||||
|
||||
// Start at a random preset.
|
||||
#ifdef HAVE_PROJECTM4
|
||||
const uint count = projectm_playlist_size(projectm_playlist_instance_);
|
||||
if (count > 0) {
|
||||
const uint position = QRandomGenerator::global()->bounded(count);
|
||||
projectm_playlist_set_position(projectm_playlist_instance_, position, true);
|
||||
}
|
||||
#else
|
||||
const uint count = projectm_->getPlaylistSize();
|
||||
if (count > 0) {
|
||||
const uint selection = QRandomGenerator::global()->bounded(count);
|
||||
projectm_->selectPreset(selection, true);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
if (preset_path_.isEmpty()) {
|
||||
qWarning("ProjectM presets could not be found, search path was:\n %s", preset_paths.join(QLatin1String("\n ")).toLocal8Bit().constData());
|
||||
QMessageBox::warning(nullptr, tr("Missing projectM presets"), tr("Strawberry could not load any projectM visualizations. Check that you have installed Strawberry properly."));
|
||||
}
|
||||
|
||||
Resize(sceneRect().width(), sceneRect().height(), container_->devicePixelRatio());
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::drawBackground(QPainter *p, const QRectF &rect) {
|
||||
|
||||
Q_UNUSED(rect);
|
||||
|
||||
p->beginNativePainting();
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_opengl_render_frame(projectm_instance_);
|
||||
#else
|
||||
projectm_->renderFrame();
|
||||
#endif
|
||||
|
||||
p->endNativePainting();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SceneRectChanged(const QRectF &rect) {
|
||||
|
||||
Resize(rect.width(), rect.height(), container_->devicePixelRatio());
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Resize(const qreal width, const qreal height, const qreal pixel_ratio) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_window_size(projectm_instance_, static_cast<size_t>(width * pixel_ratio), static_cast<size_t>(height * pixel_ratio));
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->projectM_resetGL(static_cast<int>(width * pixel_ratio), static_cast<int>(height * pixel_ratio));
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetTextureSize(const int size) {
|
||||
|
||||
texture_size_ = size;
|
||||
|
||||
#ifndef HAVE_PROJECTM4
|
||||
if (projectm_) {
|
||||
projectm_->changeTextureSize(texture_size_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetDuration(const int seconds) {
|
||||
|
||||
duration_ = seconds;
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->changePresetDuration(duration_);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) {
|
||||
|
||||
Q_UNUSED(pipeline_id);
|
||||
Q_UNUSED(format);
|
||||
|
||||
GstMapInfo map;
|
||||
gst_buffer_map(buffer, &map, GST_MAP_READ);
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
const unsigned int samples_per_channel = (map.size / sizeof(int16_t)) / channels;
|
||||
const int16_t *data = reinterpret_cast<int16_t*>(map.data);
|
||||
projectm_pcm_add_int16(projectm_instance_, data, samples_per_channel, static_cast<projectm_channels>(channels));
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
const int16_t samples_per_channel = static_cast<int16_t>((map.size / sizeof(int16_t)) / channels);
|
||||
const int16_t *data = reinterpret_cast<int16_t*>(map.data);
|
||||
projectm_->pcm()->addPCM16Data(data, samples_per_channel);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
gst_buffer_unmap(buffer, &map);
|
||||
gst_buffer_unref(buffer);
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetSelected(const QStringList &paths, const bool selected) {
|
||||
|
||||
for (const QString &path : paths) {
|
||||
const int index = IndexOfPreset(path);
|
||||
if (selected && index == -1) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, path.toUtf8().constData(), true);
|
||||
#else
|
||||
projectm_->addPresetURL(path.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
}
|
||||
else if (!selected && index != -1) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_remove_preset(projectm_playlist_instance_, index);
|
||||
#else
|
||||
projectm_->removePreset(index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::ClearSelected() {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_clear(projectm_playlist_instance_);
|
||||
#else
|
||||
projectm_->clearPlaylist();
|
||||
#endif
|
||||
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
int ProjectMVisualization::IndexOfPreset(const QString &preset_path) const {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
const uint count = projectm_playlist_size(projectm_playlist_instance_);
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
char *projectm_preset_path = projectm_playlist_item(projectm_playlist_instance_, i);
|
||||
if (projectm_preset_path) {
|
||||
const QScopeGuard projectm_preset_path_deleter = qScopeGuard([projectm_preset_path](){ projectm_playlist_free_string(projectm_preset_path); });
|
||||
if (QLatin1String(projectm_preset_path) == preset_path) {
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
const uint count = projectm_->getPlaylistSize();
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
if (QString::fromStdString(projectm_->getPresetURL(i)) == preset_path) return static_cast<int>(i);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Load() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(QLatin1String(VisualizationContainer::kSettingsGroup));
|
||||
mode_ = Mode(s.value("mode", 0).toInt());
|
||||
duration_ = s.value("duration", duration_).toInt();
|
||||
s.endGroup();
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_set_preset_duration(projectm_instance_, duration_);
|
||||
projectm_playlist_clear(projectm_playlist_instance_);
|
||||
#else
|
||||
projectm_->changePresetDuration(duration_);
|
||||
projectm_->clearPlaylist();
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
switch (mode_) {
|
||||
case Mode::Random:{
|
||||
for (int i = 0; i < preset_model_->all_presets_.count(); ++i) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, preset_model_->all_presets_[i].path_.toUtf8().constData(), false);
|
||||
#else
|
||||
projectm_->addPresetURL(preset_model_->all_presets_[i].path_.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
preset_model_->all_presets_[i].selected_ = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mode::FromList:{
|
||||
s.beginGroup(QLatin1String(VisualizationContainer::kSettingsGroup));
|
||||
const QStringList paths = s.value("preset_paths").toStringList();
|
||||
s.endGroup();
|
||||
for (const QString &path : paths) {
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_playlist_add_preset(projectm_playlist_instance_, path.toUtf8().constData(), true);
|
||||
#else
|
||||
projectm_->addPresetURL(path.toStdString(), std::string(), default_rating_list_);
|
||||
#endif
|
||||
preset_model_->MarkSelected(path, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Save() {
|
||||
|
||||
QStringList paths;
|
||||
|
||||
for (const ProjectMPresetModel::Preset &preset : std::as_const(preset_model_->all_presets_)) {
|
||||
if (preset.selected_) paths << preset.path_;
|
||||
}
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(VisualizationContainer::kSettingsGroup);
|
||||
s.setValue("preset_paths", paths);
|
||||
s.setValue("mode", static_cast<int>(mode_));
|
||||
s.setValue("duration", duration_);
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetMode(const Mode mode) {
|
||||
|
||||
mode_ = mode;
|
||||
Save();
|
||||
|
||||
}
|
||||
|
||||
QString ProjectMVisualization::preset_path() const {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
return preset_path_;
|
||||
#else
|
||||
if (projectm_) {
|
||||
return QString::fromStdString(projectm_->settings().presetURL);
|
||||
}
|
||||
return QString();
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetImmediatePreset(const int index) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_playlist_instance_) {
|
||||
projectm_playlist_set_position(projectm_playlist_instance_, index, true);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->selectPreset(index, true);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::SetImmediatePreset(const QString &path) {
|
||||
|
||||
const int index = IndexOfPreset(path);
|
||||
if (index != -1) {
|
||||
SetImmediatePreset(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ProjectMVisualization::Lock(const bool lock) {
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
if (projectm_instance_) {
|
||||
projectm_set_preset_locked(projectm_instance_, lock);
|
||||
}
|
||||
#else
|
||||
if (projectm_) {
|
||||
projectm_->setPresetLock(lock);
|
||||
}
|
||||
#endif // HAVE_PROJECTM4
|
||||
|
||||
if (!lock) Load();
|
||||
|
||||
}
|
||||
114
src/visualizations/projectmvisualization.h
Normal file
114
src/visualizations/projectmvisualization.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECTMVISUALIZATION_H
|
||||
#define PROJECTMVISUALIZATION_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#ifdef HAVE_PROJECTM4
|
||||
# include <projectM-4/types.h>
|
||||
# include <projectM-4/playlist_types.h>
|
||||
#else
|
||||
# include <libprojectM/projectM.hpp>
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include "engine/gstbufferconsumer.h"
|
||||
|
||||
class projectM;
|
||||
class QPainter;
|
||||
class ProjectMPresetModel;
|
||||
class VisualizationContainer;
|
||||
|
||||
class ProjectMVisualization : public QGraphicsScene, public GstBufferConsumer {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectMVisualization(VisualizationContainer *container);
|
||||
~ProjectMVisualization();
|
||||
|
||||
enum class Mode {
|
||||
Random = 0,
|
||||
FromList = 1,
|
||||
};
|
||||
|
||||
QString preset_path() const;
|
||||
ProjectMPresetModel *preset_model() const { return preset_model_; }
|
||||
|
||||
Mode mode() const { return mode_; }
|
||||
int duration() const { return duration_; }
|
||||
|
||||
void Init();
|
||||
|
||||
// BufferConsumer
|
||||
void ConsumeBuffer(GstBuffer *buffer, const int pipeline_id, const QString &format, const int channels) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetTextureSize(const int size);
|
||||
void SetDuration(const int seconds);
|
||||
|
||||
void SetSelected(const QStringList &paths, const bool selected);
|
||||
void ClearSelected();
|
||||
void SetImmediatePreset(const int index);
|
||||
void SetImmediatePreset(const QString &path);
|
||||
void SetMode(const Mode mode);
|
||||
|
||||
void Lock(const bool lock);
|
||||
|
||||
protected:
|
||||
// QGraphicsScene
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void SceneRectChanged(const QRectF &rect);
|
||||
|
||||
private:
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
int IndexOfPreset(const QString &preset_path) const;
|
||||
|
||||
void Resize(const qreal width, const qreal height, const qreal pixel_ratio);
|
||||
|
||||
private:
|
||||
VisualizationContainer *container_;
|
||||
ProjectMPresetModel *preset_model_;
|
||||
#ifdef HAVE_PROJECTM4
|
||||
projectm_handle projectm_instance_;
|
||||
projectm_playlist_handle projectm_playlist_instance_;
|
||||
#else
|
||||
std::unique_ptr<projectM> projectm_;
|
||||
#endif
|
||||
Mode mode_;
|
||||
int duration_;
|
||||
std::vector<int> default_rating_list_;
|
||||
int texture_size_;
|
||||
QString preset_path_;
|
||||
};
|
||||
|
||||
#endif // PROJECTMVISUALIZATION_H
|
||||
328
src/visualizations/visualizationcontainer.cpp
Normal file
328
src/visualizations/visualizationcontainer.cpp
Normal file
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
#include <QActionGroup>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/settings.h"
|
||||
#include "engine/gstengine.h"
|
||||
#include "visualizationcontainer.h"
|
||||
#include "visualizationopenglwidget.h"
|
||||
#include "visualizationoverlay.h"
|
||||
#include "visualizationselector.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
const char *VisualizationContainer::kSettingsGroup = "Visualizations";
|
||||
|
||||
namespace {
|
||||
constexpr int kLowFramerate = 15;
|
||||
constexpr int kMediumFramerate = 25;
|
||||
constexpr int kHighFramerate = 35;
|
||||
constexpr int kSuperHighFramerate = 60;
|
||||
|
||||
constexpr int kDefaultWidth = 828;
|
||||
constexpr int kDefaultHeight = 512;
|
||||
constexpr int kDefaultFps = kHighFramerate;
|
||||
constexpr int kDefaultTextureSize = 512;
|
||||
} // namespace
|
||||
|
||||
VisualizationContainer::VisualizationContainer(QWidget *parent)
|
||||
: QGraphicsView(parent),
|
||||
projectm_visualization_(new ProjectMVisualization(this)),
|
||||
overlay_(new VisualizationOverlay),
|
||||
selector_(new VisualizationSelector(this)),
|
||||
overlay_proxy_(nullptr),
|
||||
engine_(nullptr),
|
||||
menu_(new QMenu(this)),
|
||||
fps_(kDefaultFps),
|
||||
size_(kDefaultTextureSize) {
|
||||
|
||||
setWindowTitle(tr("Visualizations"));
|
||||
setWindowIcon(IconLoader::Load(QStringLiteral("strawberry")));
|
||||
setMinimumSize(64, 64);
|
||||
|
||||
{
|
||||
Settings s;
|
||||
s.beginGroup(QLatin1String(kSettingsGroup));
|
||||
if (!restoreGeometry(s.value("geometry").toByteArray())) {
|
||||
resize(kDefaultWidth, kDefaultHeight);
|
||||
}
|
||||
fps_ = s.value("fps", kDefaultFps).toInt();
|
||||
size_ = s.value("size", kDefaultTextureSize).toInt();
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
QShortcut *close = new QShortcut(QKeySequence::Close, this);
|
||||
QObject::connect(close, &QShortcut::activated, this, &VisualizationContainer::close);
|
||||
|
||||
// Set up the graphics view
|
||||
setScene(projectm_visualization_);
|
||||
setViewport(new VisualizationOpenGLWidget(projectm_visualization_));
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
// Add the overlay
|
||||
overlay_proxy_ = scene()->addWidget(overlay_);
|
||||
QObject::connect(overlay_, &VisualizationOverlay::OpacityChanged, this, &VisualizationContainer::ChangeOverlayOpacity);
|
||||
QObject::connect(overlay_, &VisualizationOverlay::ShowPopupMenu, this, &VisualizationContainer::ShowPopupMenu);
|
||||
ChangeOverlayOpacity(0.0);
|
||||
|
||||
projectm_visualization_->SetTextureSize(size_);
|
||||
SizeChanged();
|
||||
|
||||
// Selector
|
||||
selector_->SetVisualization(projectm_visualization_);
|
||||
|
||||
// Settings menu
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("view-fullscreen")), tr("Toggle fullscreen"), this, &VisualizationContainer::ToggleFullscreen);
|
||||
|
||||
QMenu *fps_menu = menu_->addMenu(tr("Framerate"));
|
||||
QActionGroup *fps_group = new QActionGroup(this);
|
||||
AddFramerateMenuItem(tr("Low (%1 fps)").arg(kLowFramerate), kLowFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("Medium (%1 fps)").arg(kMediumFramerate), kMediumFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("High (%1 fps)").arg(kHighFramerate), kHighFramerate, fps_, fps_group);
|
||||
AddFramerateMenuItem(tr("Super high (%1 fps)").arg(kSuperHighFramerate), kSuperHighFramerate, fps_, fps_group);
|
||||
fps_menu->addActions(fps_group->actions());
|
||||
|
||||
QMenu *quality_menu = menu_->addMenu(tr("Quality", "Visualization quality"));
|
||||
QActionGroup *quality_group = new QActionGroup(this);
|
||||
AddQualityMenuItem(tr("Low (256x256)"), 256, size_, quality_group);
|
||||
AddQualityMenuItem(tr("Medium (512x512)"), 512, size_, quality_group);
|
||||
AddQualityMenuItem(tr("High (1024x1024)"), 1024, size_, quality_group);
|
||||
AddQualityMenuItem(tr("Super high (2048x2048)"), 2048, size_, quality_group);
|
||||
quality_menu->addActions(quality_group->actions());
|
||||
|
||||
menu_->addAction(tr("Select visualizations..."), selector_, &VisualizationContainer::show);
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(IconLoader::Load(QStringLiteral("application-exit")), tr("Close visualization"), this, &VisualizationContainer::hide);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::AddFramerateMenuItem(const QString &name, const int value, const int def, QActionGroup *group) {
|
||||
|
||||
QAction *action = group->addAction(name);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(value == def);
|
||||
QObject::connect(action, &QAction::triggered, this, [this, value]() { SetFps(value); });
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::AddQualityMenuItem(const QString &name, const int value, const int def, QActionGroup *group) {
|
||||
|
||||
QAction *action = group->addAction(name);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(value == def);
|
||||
QObject::connect(action, &QAction::triggered, this, [this, value]() { SetQuality(value); });
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetEngine(GstEngine *engine) {
|
||||
|
||||
engine_ = engine;
|
||||
|
||||
if (isVisible()) engine_->AddBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::showEvent(QShowEvent *e) {
|
||||
|
||||
qLog(Debug) << "Showing visualization";
|
||||
|
||||
QGraphicsView::showEvent(e);
|
||||
|
||||
update_timer_.start(1000 / fps_, this);
|
||||
|
||||
if (engine_) engine_->AddBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::hideEvent(QHideEvent *e) {
|
||||
|
||||
qLog(Debug) << "Hiding visualization";
|
||||
|
||||
QGraphicsView::hideEvent(e);
|
||||
|
||||
update_timer_.stop();
|
||||
|
||||
if (engine_) engine_->RemoveBufferConsumer(projectm_visualization_);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::closeEvent(QCloseEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
// Don't close the window. Just hide it.
|
||||
e->ignore();
|
||||
hide();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::resizeEvent(QResizeEvent *e) {
|
||||
QGraphicsView::resizeEvent(e);
|
||||
SizeChanged();
|
||||
}
|
||||
|
||||
void VisualizationContainer::SizeChanged() {
|
||||
|
||||
// Save the geometry
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("geometry", saveGeometry());
|
||||
|
||||
// Resize the scene
|
||||
if (scene()) scene()->setSceneRect(QRect(QPoint(0, 0), size()));
|
||||
|
||||
// Resize the overlay
|
||||
if (overlay_) overlay_->resize(size());
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::timerEvent(QTimerEvent *e) {
|
||||
|
||||
QGraphicsView::timerEvent(e);
|
||||
if (e->timerId() == update_timer_.timerId()) scene()->update();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next) {
|
||||
overlay_->SetActions(previous, play_pause, stop, next);
|
||||
}
|
||||
|
||||
void VisualizationContainer::SongMetadataChanged(const Song &metadata) {
|
||||
overlay_->SetSongTitle(QStringLiteral("%1 - %2").arg(metadata.artist(), metadata.title()));
|
||||
}
|
||||
|
||||
void VisualizationContainer::Stopped() {
|
||||
overlay_->SetSongTitle(tr("strawberry"));
|
||||
}
|
||||
|
||||
void VisualizationContainer::ChangeOverlayOpacity(const qreal value) {
|
||||
|
||||
overlay_proxy_->setOpacity(value);
|
||||
|
||||
// Hide the cursor if the overlay is hidden
|
||||
if (value < 0.5) {
|
||||
viewport()->setCursor(Qt::BlankCursor);
|
||||
}
|
||||
else {
|
||||
viewport()->unsetCursor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::enterEvent(QEnterEvent *e) {
|
||||
|
||||
QGraphicsView::enterEvent(e);
|
||||
|
||||
overlay_->SetVisible(true);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::leaveEvent(QEvent *e) {
|
||||
QGraphicsView::leaveEvent(e);
|
||||
overlay_->SetVisible(false);
|
||||
}
|
||||
|
||||
void VisualizationContainer::mouseMoveEvent(QMouseEvent *e) {
|
||||
QGraphicsView::mouseMoveEvent(e);
|
||||
overlay_->SetVisible(true);
|
||||
}
|
||||
|
||||
void VisualizationContainer::mouseDoubleClickEvent(QMouseEvent *e) {
|
||||
QGraphicsView::mouseDoubleClickEvent(e);
|
||||
ToggleFullscreen();
|
||||
}
|
||||
|
||||
void VisualizationContainer::contextMenuEvent(QContextMenuEvent *event) {
|
||||
QGraphicsView::contextMenuEvent(event);
|
||||
ShowPopupMenu(event->pos());
|
||||
}
|
||||
|
||||
void VisualizationContainer::keyReleaseEvent(QKeyEvent *event) {
|
||||
|
||||
if (event->matches(QKeySequence::Close) || event->key() == Qt::Key_Escape) {
|
||||
if (isFullScreen()) {
|
||||
ToggleFullscreen();
|
||||
}
|
||||
else {
|
||||
hide();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::keyReleaseEvent(event);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::ToggleFullscreen() {
|
||||
|
||||
setWindowState(windowState() ^ Qt::WindowFullScreen);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetFps(const int fps) {
|
||||
|
||||
fps_ = fps;
|
||||
|
||||
// Save settings
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("fps", fps_);
|
||||
|
||||
update_timer_.stop();
|
||||
update_timer_.start(1000 / fps_, this);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationContainer::ShowPopupMenu(const QPoint &pos) {
|
||||
menu_->popup(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void VisualizationContainer::SetQuality(const int size) {
|
||||
|
||||
size_ = size;
|
||||
|
||||
// Save settings
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("size", size_);
|
||||
|
||||
projectm_visualization_->SetTextureSize(size_);
|
||||
|
||||
}
|
||||
103
src/visualizations/visualizationcontainer.h
Normal file
103
src/visualizations/visualizationcontainer.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONCONTAINER_H
|
||||
#define VISUALIZATIONCONTAINER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QBasicTimer>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class GstEngine;
|
||||
class ProjectMVisualization;
|
||||
class VisualizationOverlay;
|
||||
class VisualizationSelector;
|
||||
|
||||
class QMenu;
|
||||
class QActionGroup;
|
||||
class QEvent;
|
||||
class QShowEvent;
|
||||
class QHideEvent;
|
||||
class QCloseEvent;
|
||||
class QResizeEvent;
|
||||
class QTimerEvent;
|
||||
class QMouseEvent;
|
||||
class QContextMenuEvent;
|
||||
class QKeyEvent;
|
||||
class QEnterEvent;
|
||||
|
||||
class VisualizationContainer : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationContainer(QWidget *parent = nullptr);
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
void SetEngine(GstEngine *engine);
|
||||
void SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SongMetadataChanged(const Song &metadata);
|
||||
void Stopped();
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
void closeEvent(QCloseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void timerEvent(QTimerEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void enterEvent(QEnterEvent *e) override;
|
||||
void leaveEvent(QEvent *e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
void keyReleaseEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
void SizeChanged();
|
||||
void AddFramerateMenuItem(const QString &name, int value, int def, QActionGroup *group);
|
||||
void AddQualityMenuItem(const QString &name, int value, int def, QActionGroup *group);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ChangeOverlayOpacity(qreal value);
|
||||
void ShowPopupMenu(const QPoint &pos);
|
||||
void ToggleFullscreen();
|
||||
void SetFps(const int fps);
|
||||
void SetQuality(const int size);
|
||||
|
||||
private:
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
VisualizationOverlay *overlay_;
|
||||
VisualizationSelector *selector_;
|
||||
QGraphicsProxyWidget *overlay_proxy_;
|
||||
GstEngine *engine_;
|
||||
QMenu *menu_;
|
||||
QBasicTimer update_timer_;
|
||||
int fps_;
|
||||
int size_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONCONTAINER_H
|
||||
39
src/visualizations/visualizationopenglwidget.cpp
Normal file
39
src/visualizations/visualizationopenglwidget.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "visualizationopenglwidget.h"
|
||||
#include "projectmvisualization.h"
|
||||
|
||||
VisualizationOpenGLWidget::VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWidget *parent, Qt::WindowFlags f)
|
||||
: QOpenGLWidget(parent, f),
|
||||
projectm_visualization_(projectm_visualization) {}
|
||||
|
||||
void VisualizationOpenGLWidget::initializeGL() {
|
||||
|
||||
projectm_visualization_->Init();
|
||||
|
||||
QOpenGLWidget::initializeGL();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
}
|
||||
42
src/visualizations/visualizationopenglwidget.h
Normal file
42
src/visualizations/visualizationopenglwidget.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONOPENGLWIDGET_H
|
||||
#define VISUALIZATIONOPENGLWIDGET_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
class ProjectMVisualization;
|
||||
|
||||
class VisualizationOpenGLWidget : public QOpenGLWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationOpenGLWidget(ProjectMVisualization *projectm_visualization, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
|
||||
protected:
|
||||
void initializeGL() override;
|
||||
|
||||
private:
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONOPENGLWIDGET_H
|
||||
116
src/visualizations/visualizationoverlay.cpp
Normal file
116
src/visualizations/visualizationoverlay.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QBasicTimer>
|
||||
#include <QTimeLine>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QTimerEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "core/iconloader.h"
|
||||
#include "visualizationoverlay.h"
|
||||
#include "ui_visualizationoverlay.h"
|
||||
|
||||
namespace {
|
||||
constexpr int kFadeDuration = 500;
|
||||
constexpr int kFadeTimeout = 5000;
|
||||
}
|
||||
|
||||
VisualizationOverlay::VisualizationOverlay(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui_(new Ui_VisualizationOverlay),
|
||||
fade_timeline_(new QTimeLine(kFadeDuration, this)),
|
||||
visible_(false) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setMouseTracking(true);
|
||||
|
||||
ui_->settings->setIcon(IconLoader::Load(QStringLiteral("configure")));
|
||||
|
||||
QObject::connect(ui_->settings, &QToolButton::clicked, this, &VisualizationOverlay::ShowSettingsMenu);
|
||||
QObject::connect(fade_timeline_, &QTimeLine::valueChanged, this, &VisualizationOverlay::OpacityChanged);
|
||||
|
||||
}
|
||||
|
||||
VisualizationOverlay::~VisualizationOverlay() { delete ui_; }
|
||||
|
||||
QGraphicsProxyWidget *VisualizationOverlay::title(QGraphicsProxyWidget *proxy) const {
|
||||
return proxy->createProxyForChildWidget(ui_->song_title);
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next) {
|
||||
|
||||
ui_->previous->setDefaultAction(previous);
|
||||
ui_->play_pause->setDefaultAction(play_pause);
|
||||
ui_->stop->setDefaultAction(stop);
|
||||
ui_->next->setDefaultAction(next);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::ShowSettingsMenu() {
|
||||
|
||||
Q_EMIT ShowPopupMenu(ui_->settings->mapToGlobal(ui_->settings->rect().bottomLeft()));
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::timerEvent(QTimerEvent *e) {
|
||||
|
||||
QWidget::timerEvent(e);
|
||||
|
||||
if (e->timerId() == fade_out_timeout_.timerId()) {
|
||||
SetVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetVisible(const bool visible) {
|
||||
|
||||
// If we're showing the overlay, then fade out again in a little while
|
||||
fade_out_timeout_.stop();
|
||||
if (visible) fade_out_timeout_.start(kFadeTimeout, this);
|
||||
|
||||
// Don't change to the state we're in already
|
||||
if (visible == visible_) return;
|
||||
visible_ = visible;
|
||||
|
||||
// If there's already another fader running then start from the same time that one was already at.
|
||||
int start_time = visible ? 0 : fade_timeline_->duration();
|
||||
if (fade_timeline_->state() == QTimeLine::Running)
|
||||
start_time = fade_timeline_->currentTime();
|
||||
|
||||
fade_timeline_->stop();
|
||||
fade_timeline_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
|
||||
fade_timeline_->setCurrentTime(start_time);
|
||||
fade_timeline_->resume();
|
||||
|
||||
}
|
||||
|
||||
void VisualizationOverlay::SetSongTitle(const QString &title) {
|
||||
|
||||
ui_->song_title->setText(title);
|
||||
SetVisible(true);
|
||||
|
||||
}
|
||||
71
src/visualizations/visualizationoverlay.h
Normal file
71
src/visualizations/visualizationoverlay.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONOVERLAY_H
|
||||
#define VISUALIZATIONOVERLAY_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QBasicTimer>
|
||||
|
||||
class Ui_VisualizationOverlay;
|
||||
|
||||
class QGraphicsProxyWidget;
|
||||
class QTimeLine;
|
||||
class QAction;
|
||||
|
||||
class VisualizationOverlay : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationOverlay(QWidget *parent = nullptr);
|
||||
~VisualizationOverlay();
|
||||
|
||||
QGraphicsProxyWidget *title(QGraphicsProxyWidget *proxy) const;
|
||||
|
||||
void SetActions(QAction *previous, QAction *play_pause, QAction *stop, QAction *next);
|
||||
void SetSongTitle(const QString &title);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetVisible(const bool visible);
|
||||
|
||||
Q_SIGNALS:
|
||||
void OpacityChanged(const qreal value);
|
||||
void ShowPopupMenu(const QPoint &pos);
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
void timerEvent(QTimerEvent *e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void ShowSettingsMenu();
|
||||
|
||||
private:
|
||||
Ui_VisualizationOverlay *ui_;
|
||||
|
||||
QTimeLine *fade_timeline_;
|
||||
QBasicTimer fade_out_timeout_;
|
||||
bool visible_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONOVERLAY_H
|
||||
234
src/visualizations/visualizationoverlay.ui
Normal file
234
src/visualizations/visualizationoverlay.ui
Normal file
@@ -0,0 +1,234 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VisualizationOverlay</class>
|
||||
<widget class="QWidget" name="VisualizationOverlay">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>523</width>
|
||||
<height>302</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">VisualizationOverlay {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#frame {
|
||||
background-color: rgba(96, 59, 25, 70%);
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
border-color: rgba(145, 89, 38, 100%);
|
||||
border-width: 4px 4px 0px 4px;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
#song_title {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
color: #feae65;
|
||||
}
|
||||
|
||||
QToolButton {
|
||||
background: transparent;
|
||||
border: none;
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>210</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="song_title">
|
||||
<property name="text">
|
||||
<string>Strawberry</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="previous">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="play_pause">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="stop">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="next">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>13</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="settings">
|
||||
<property name="toolTip">
|
||||
<string>Visualizations Settings</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
88
src/visualizations/visualizationselector.cpp
Normal file
88
src/visualizations/visualizationselector.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "visualizationselector.h"
|
||||
#include "projectmpresetmodel.h"
|
||||
#include "projectmvisualization.h"
|
||||
#include "ui_visualizationselector.h"
|
||||
|
||||
VisualizationSelector::VisualizationSelector(QWidget *parent)
|
||||
: QDialog(parent),
|
||||
ui_(new Ui_VisualizationSelector),
|
||||
projectm_visualization_(nullptr),
|
||||
select_all_(nullptr),
|
||||
select_none_(nullptr) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
select_all_ = ui_->buttonBox->addButton(tr("Select All"), QDialogButtonBox::ActionRole);
|
||||
select_none_ = ui_->buttonBox->addButton(tr("Select None"), QDialogButtonBox::ActionRole);
|
||||
QObject::connect(select_all_, &QPushButton::clicked, this, &VisualizationSelector::SelectAll);
|
||||
QObject::connect(select_none_, &QPushButton::clicked, this, &VisualizationSelector::SelectNone);
|
||||
select_all_->setEnabled(false);
|
||||
select_none_->setEnabled(false);
|
||||
|
||||
QObject::connect(ui_->mode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &VisualizationSelector::ModeChanged);
|
||||
|
||||
}
|
||||
|
||||
VisualizationSelector::~VisualizationSelector() { delete ui_; }
|
||||
|
||||
void VisualizationSelector::showEvent(QShowEvent *e) {
|
||||
|
||||
Q_UNUSED(e);
|
||||
|
||||
if (!ui_->list->model()) {
|
||||
ui_->delay->setValue(projectm_visualization_->duration());
|
||||
ui_->list->setModel(projectm_visualization_->preset_model());
|
||||
QObject::connect(ui_->list->selectionModel(), &QItemSelectionModel::currentChanged, projectm_visualization_->preset_model(), &ProjectMPresetModel::SetImmediatePreset);
|
||||
QObject::connect(ui_->delay, QOverload<int>::of(&QSpinBox::valueChanged), projectm_visualization_, &ProjectMVisualization::SetDuration);
|
||||
|
||||
ui_->mode->setCurrentIndex(static_cast<int>(projectm_visualization_->mode()));
|
||||
}
|
||||
|
||||
projectm_visualization_->Lock(true);
|
||||
|
||||
}
|
||||
|
||||
void VisualizationSelector::hideEvent(QHideEvent *e) {
|
||||
Q_UNUSED(e);
|
||||
projectm_visualization_->Lock(false);
|
||||
}
|
||||
|
||||
void VisualizationSelector::ModeChanged(const int mode) {
|
||||
|
||||
const bool enabled = mode == 1;
|
||||
ui_->list->setEnabled(enabled);
|
||||
select_all_->setEnabled(enabled);
|
||||
select_none_->setEnabled(enabled);
|
||||
|
||||
projectm_visualization_->SetMode(static_cast<ProjectMVisualization::Mode>(mode));
|
||||
|
||||
}
|
||||
|
||||
void VisualizationSelector::SelectAll() { projectm_visualization_->preset_model()->SelectAll(); }
|
||||
|
||||
void VisualizationSelector::SelectNone() { projectm_visualization_->preset_model()->SelectNone(); }
|
||||
61
src/visualizations/visualizationselector.h
Normal file
61
src/visualizations/visualizationselector.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2024, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Strawberry is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VISUALIZATIONSELECTOR_H
|
||||
#define VISUALIZATIONSELECTOR_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QPushButton;
|
||||
class QShowEvent;
|
||||
class QHideEvent;
|
||||
|
||||
class ProjectMVisualization;
|
||||
class Ui_VisualizationSelector;
|
||||
|
||||
class VisualizationSelector : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit VisualizationSelector(QWidget *parent = nullptr);
|
||||
~VisualizationSelector();
|
||||
|
||||
void SetVisualization(ProjectMVisualization *projectm_visualization) { projectm_visualization_ = projectm_visualization; }
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *e) override;
|
||||
void hideEvent(QHideEvent *e) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void ModeChanged(const int mode);
|
||||
void SelectAll();
|
||||
void SelectNone();
|
||||
|
||||
private:
|
||||
Ui_VisualizationSelector *ui_;
|
||||
ProjectMVisualization *projectm_visualization_;
|
||||
QPushButton *select_all_;
|
||||
QPushButton *select_none_;
|
||||
};
|
||||
|
||||
#endif // VISUALIZATIONSELECTOR_H
|
||||
140
src/visualizations/visualizationselector.ui
Normal file
140
src/visualizations/visualizationselector.ui
Normal file
@@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>VisualizationSelector</class>
|
||||
<widget class="QDialog" name="VisualizationSelector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>595</width>
|
||||
<height>475</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select visualizations</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../data/data.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Visualization mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mode">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Random visualization</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Choose from the list</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Delay between visualizations</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="delay">
|
||||
<property name="suffix">
|
||||
<string> seconds</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>120</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>15</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="list">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>mode</tabstop>
|
||||
<tabstop>delay</tabstop>
|
||||
<tabstop>list</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>VisualizationSelector</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>VisualizationSelector</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user