Compare commits

..

1 Commits

Author SHA1 Message Date
Jonas Kvinge
5c57c923d9 Add Dropbox 2025-12-29 00:48:02 +01:00
53 changed files with 2083 additions and 1075 deletions

View File

@@ -747,7 +747,7 @@ jobs:
df -h
- name: Build FreeBSD
id: build-freebsd
uses: vmactions/freebsd-vm@v1.3.5
uses: vmactions/freebsd-vm@v1.3.2
with:
usesh: true
mem: 8192
@@ -772,7 +772,7 @@ jobs:
submodules: recursive
- name: Build OpenBSD
id: build-openbsd
uses: vmactions/openbsd-vm@v1.3.1
uses: vmactions/openbsd-vm@v1.2.9
with:
usesh: true
mem: 4096
@@ -845,7 +845,7 @@ jobs:
p12-password: ${{ secrets.APPLE_DEVELOPER_ID_CERTIFICATE_PASSWORD }}
- name: Download macOS dependencies
run: curl -f -O -L https://github.com/strawberrymusicplayer/strawberry-macos-dependencies/releases/latest/download/strawberry-macos-${{env.arch}}-${{env.buildtype}}.tar.xz
run: curl -f -O -L https://github.com/strawberrymusicplayer/strawberry-macos-dependencies$(test "${{env.arch}}" = "x86_64" && echo "-intel" || echo "")/releases/latest/download/strawberry-macos-${{env.arch}}-${{env.buildtype}}.tar.xz
- name: Extract macOS dependencies
run: sudo tar -C / -xf strawberry-macos-${{env.arch}}-${{env.buildtype}}.tar.xz
@@ -898,7 +898,7 @@ jobs:
- name: Manually Codesign
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15-intel'
working-directory: build
run: codesign -s 383J84DVB6 -f strawberry.app/Contents/Frameworks/{libpcre2-8.0.dylib,libpcre2-16.0.dylib,libpng16.16.dylib,libfreetype.6.dylib,libzstd.1.dylib,libbrotlicommon.1.dylib,libbrotlienc.1.dylib,libbrotlidec.1.dylib,libsoup-3.0.0.dylib,libnghttp2.14.dylib,libpsl.5.dylib} strawberry.app/Contents/Frameworks/png.framework/png strawberry.app
run: codesign -s 383J84DVB6 -f strawberry.app/Contents/Frameworks/{libpcre2-8.0.dylib,libpcre2-16.0.dylib,libpng16.16.dylib,libfreetype.6.dylib,libzstd.1.dylib,libbrotlicommon.1.dylib,libbrotlienc.1.dylib} strawberry.app/Contents/Frameworks/png.framework/png strawberry.app
- name: Manually Codesign
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15'

View File

@@ -379,6 +379,13 @@ 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)
@@ -776,6 +783,7 @@ 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
@@ -823,8 +831,6 @@ set(SOURCES
src/fileview/fileview.cpp
src/fileview/fileviewlist.cpp
src/fileview/fileviewtree.cpp
src/fileview/fileviewtreemodel.cpp
src/device/devicemanager.cpp
src/device/devicelister.cpp
@@ -1074,6 +1080,7 @@ 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
@@ -1114,8 +1121,6 @@ set(HEADERS
src/fileview/fileview.h
src/fileview/fileviewlist.h
src/fileview/fileviewtree.h
src/fileview/fileviewtreemodel.h
src/device/devicemanager.h
src/device/devicelister.h
@@ -1484,6 +1489,25 @@ optional_source(HAVE_QOBUZ
src/settings/qobuzsettingspage.ui
)
optional_source(HAVE_DROPBOX
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
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
UI
src/settings/dropboxsettingspage.ui
)
qt_wrap_cpp(SOURCES ${HEADERS})
qt_wrap_ui(SOURCES ${UI})
qt_add_resources(SOURCES data/data.qrc data/icons.qrc)

View File

@@ -98,6 +98,7 @@
<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>
@@ -197,6 +198,7 @@
<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>
@@ -300,6 +302,7 @@
<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>
@@ -403,6 +406,7 @@
<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>
@@ -506,5 +510,6 @@
<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.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
data/icons/full/dropbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

82
data/schema/schema-22.sql Normal file
View File

@@ -0,0 +1,82 @@
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;

View File

@@ -1018,6 +1018,87 @@ 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,

View File

@@ -41,9 +41,12 @@ bool CollectionPlaylistItem::InitFromQuery(const SqlRow &query) {
case Song::Source::Collection:
col = 0;
break;
default:
case Song::Source::Dropbox:
col = static_cast<int>(Song::kRowIdColumns.count());
break;
default:
col = static_cast<int>(Song::kRowIdColumns.count() * 2);
break;
}
song_.InitFromQuery(query, true, col);

View File

@@ -383,7 +383,7 @@ void CollectionView::keyPressEvent(QKeyEvent *e) {
case Qt::Key_Enter:
case Qt::Key_Return:
if (currentIndex().isValid()) {
Q_EMIT doubleClicked(currentIndex());
AddToPlaylist();
}
e->accept();
break;

View File

@@ -33,6 +33,8 @@
#cmakedefine HAVE_SPOTIFY
#cmakedefine HAVE_QOBUZ
#cmakedefine HAVE_DISCORD_RPC
#cmakedefine HAVE_DROPBOX
#cmakedefine HAVE_ONEDRIVE
#cmakedefine HAVE_TAGLIB_DSFFILE
#cmakedefine HAVE_TAGLIB_DSDIFFFILE

View File

@@ -0,0 +1,30 @@
/*
* 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

View File

@@ -0,0 +1,46 @@
/*
* 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

View File

@@ -105,6 +105,10 @@
# include "covermanager/qobuzcoverprovider.h"
#endif
#ifdef HAVE_DROPBOX
# include "dropbox/dropboxservice.h"
#endif
#ifdef HAVE_MOODBAR
# include "moodbar/moodbarcontroller.h"
# include "moodbar/moodbarloader.h"
@@ -200,6 +204,9 @@ 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;
}),

View File

@@ -178,6 +178,9 @@
#ifdef HAVE_QOBUZ
# include "constants/qobuzsettings.h"
#endif
#ifdef HAVE_DROPBOX
# include "constants/dropboxsettings.h"
#endif
#include "streaming/streamingservices.h"
#include "streaming/streamingservice.h"
@@ -355,6 +358,9 @@ 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)),
@@ -441,20 +447,15 @@ 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);
ui_->tabs->SetBackgroundPixmap(QPixmap(u":/pictures/sidebar-background.png"_s));
ui_->tabs->LoadSettings(QLatin1String(MainWindowSettings::kSettingsGroup));
// Save tab mode immediately when changed to avoid losing the setting
QObject::connect(ui_->tabs, &FancyTabWidget::ModeChanged, this, [this](FancyTabWidget::Mode mode) {
Settings s;
s.beginGroup(MainWindowSettings::kSettingsGroup);
s.setValue("tab_mode", static_cast<int>(mode));
s.endGroup();
});
track_position_timer_->setInterval(kTrackPositionUpdateTimeMs);
QObject::connect(track_position_timer_, &QTimer::timeout, this, &MainWindow::UpdateTrackPosition);
track_slider_timer_->setInterval(kTrackSliderUpdateTimeMs);
@@ -790,6 +791,12 @@ 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);
@@ -1288,6 +1295,18 @@ 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();
}
@@ -1334,10 +1353,12 @@ 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() {
@@ -2725,6 +2746,9 @@ 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;
}
@@ -3406,6 +3430,11 @@ 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();

View File

@@ -43,6 +43,7 @@
#include <QString>
#include <QUrl>
#include <QImage>
#include <QPixmap>
#include <QTimer>
#include <QtEvents>
@@ -289,6 +290,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void CheckFullRescanRevisions();
// creates the icon by painting the full one depending on the current position
QPixmap CreateOverlayedIcon(const int position, const int scrobble_point);
void GetCoverAutomatically();
void SetToggleScrobblingIcon(const bool value);
@@ -351,6 +355,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
#ifdef HAVE_QOBUZ
StreamingTabsView *qobuz_view_;
#endif
#ifdef HAVE_DROPBOX
StreamingSongsView *dropbox_view_;
#endif
RadioViewContainer *radio_view_;

View File

@@ -1163,6 +1163,8 @@ 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;
@@ -1183,6 +1185,8 @@ 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;
@@ -1202,6 +1206,8 @@ 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;
@@ -1221,6 +1227,8 @@ 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);
@@ -1470,7 +1478,7 @@ Song::FileType Song::FiletypeByExtension(const QString &ext) {
bool Song::IsLinkedCollectionSource(const Source source) {
return source == Source::Collection;
return source == Source::Collection || source == Source::Dropbox;
}
@@ -1489,11 +1497,14 @@ 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;
}
@@ -1668,24 +1679,12 @@ void Song::InitArtManual() {
void Song::InitArtAutomatic() {
if (d->art_automatic_.isEmpty() && d->source_ == Source::LocalFile && d->url_.isLocalFile()) {
const QFileInfo fileinfo(d->url_.toLocalFile());
const QDir dir(fileinfo.path());
const QStringList cover_files = dir.entryList(QStringList() << u"*.jpg"_s << u"*.png"_s << u"*.gif"_s << u"*.jpeg"_s, QDir::Files|QDir::Readable, QDir::Name);
QString best_cover_file;
for (const QString &cover_file : cover_files) {
if (cover_file.contains("back"_L1, Qt::CaseInsensitive)) {
continue;
}
if (cover_file.contains("front"_L1, Qt::CaseInsensitive) || cover_file.startsWith("cover"_L1, Qt::CaseInsensitive)) {
best_cover_file = cover_file;
break;
}
if (best_cover_file.isEmpty()) {
best_cover_file = cover_file;
}
}
if (!best_cover_file.isEmpty()) {
d->art_automatic_ = QUrl::fromLocalFile(fileinfo.path() + QDir::separator() + best_cover_file);
// Pick the first image file in the album directory.
QFileInfo file(d->url_.toLocalFile());
QDir dir(file.path());
QStringList files = dir.entryList(QStringList() << u"*.jpg"_s << u"*.png"_s << u"*.gif"_s << u"*.jpeg"_s, QDir::Files|QDir::Readable, QDir::Name);
if (files.count() > 0) {
d->art_automatic_ = QUrl::fromLocalFile(file.path() + QDir::separator() + files.first());
}
}

View File

@@ -76,7 +76,9 @@ class Song {
Qobuz = 8,
SomaFM = 9,
RadioParadise = 10,
Spotify = 11
Spotify = 11,
Dropbox = 12,
OneDrive = 13,
};
static const int kSourceCount = 16;

View File

@@ -589,6 +589,8 @@ 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()) {

View File

@@ -0,0 +1,132 @@
/*
* 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;
}

View File

@@ -0,0 +1,59 @@
/*
* 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

View File

@@ -0,0 +1,190 @@
/*
* 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);
}

View File

@@ -0,0 +1,93 @@
/*
* 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

View File

@@ -0,0 +1,244 @@
/*
* 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);
}

View File

@@ -0,0 +1,67 @@
/*
* 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

View File

@@ -0,0 +1,129 @@
/*
* 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_);
}

View File

@@ -0,0 +1,71 @@
/*
* 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

View File

@@ -0,0 +1,76 @@
/*
* 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);
}

View File

@@ -0,0 +1,56 @@
/*
* 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

View File

@@ -29,17 +29,13 @@
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QStandardPaths>
#include <QSettings>
#include <QMessageBox>
#include <QScrollBar>
#include <QLineEdit>
#include <QToolButton>
#include <QFileDialog>
#include <QSpacerItem>
#include <QtEvents>
#include "constants/appearancesettings.h"
#include "constants/filefilterconstants.h"
#include "includes/shared_ptr.h"
#include "core/deletefiles.h"
#include "core/filesystemmusicstorage.h"
@@ -49,11 +45,10 @@
#include "dialogs/deleteconfirmationdialog.h"
#include "fileview.h"
#include "fileviewlist.h"
#include "fileviewtree.h"
#include "fileviewtreemodel.h"
#include "fileviewtreeitem.h"
#include "ui_fileview.h"
#include "organize/organizeerrordialog.h"
#include "constants/appearancesettings.h"
#include "constants/filefilterconstants.h"
using std::make_unique;
using namespace Qt::Literals::StringLiterals;
@@ -62,12 +57,9 @@ FileView::FileView(QWidget *parent)
: QWidget(parent),
ui_(new Ui_FileView),
model_(nullptr),
tree_model_(nullptr),
undo_stack_(new QUndoStack(this)),
task_manager_(nullptr),
storage_(new FilesystemMusicStorage(Song::Source::LocalFile, u"/"_s)),
tree_view_active_(false),
view_mode_spacer_(nullptr) {
storage_(new FilesystemMusicStorage(Song::Source::LocalFile, u"/"_s)) {
ui_->setupUi(this);
@@ -76,14 +68,12 @@ FileView::FileView(QWidget *parent)
ui_->forward->setIcon(IconLoader::Load(u"go-next"_s));
ui_->home->setIcon(IconLoader::Load(u"go-home"_s));
ui_->up->setIcon(IconLoader::Load(u"go-up"_s));
ui_->toggle_view->setIcon(IconLoader::Load(u"view-choose"_s));
QObject::connect(ui_->back, &QToolButton::clicked, undo_stack_, &QUndoStack::undo);
QObject::connect(ui_->forward, &QToolButton::clicked, undo_stack_, &QUndoStack::redo);
QObject::connect(ui_->home, &QToolButton::clicked, this, &FileView::FileHome);
QObject::connect(ui_->up, &QToolButton::clicked, this, &FileView::FileUp);
QObject::connect(ui_->path, &QLineEdit::textChanged, this, &FileView::ChangeFilePath);
QObject::connect(ui_->toggle_view, &QToolButton::clicked, this, &FileView::ToggleViewMode);
QObject::connect(undo_stack_, &QUndoStack::canUndoChanged, ui_->back, &FileView::setEnabled);
QObject::connect(undo_stack_, &QUndoStack::canRedoChanged, ui_->forward, &FileView::setEnabled);
@@ -97,22 +87,6 @@ FileView::FileView(QWidget *parent)
QObject::connect(ui_->list, &FileViewList::Delete, this, &FileView::Delete);
QObject::connect(ui_->list, &FileViewList::EditTags, this, &FileView::EditTags);
// Connect tree view signals
QObject::connect(ui_->tree, &FileViewTree::AddToPlaylist, this, &FileView::AddToPlaylist);
QObject::connect(ui_->tree, &FileViewTree::CopyToCollection, this, &FileView::CopyToCollection);
QObject::connect(ui_->tree, &FileViewTree::MoveToCollection, this, &FileView::MoveToCollection);
QObject::connect(ui_->tree, &FileViewTree::CopyToDevice, this, &FileView::CopyToDevice);
QObject::connect(ui_->tree, &FileViewTree::Delete, this, &FileView::Delete);
QObject::connect(ui_->tree, &FileViewTree::EditTags, this, &FileView::EditTags);
QObject::connect(ui_->tree, &FileViewTree::activated, this, &FileView::ItemActivated);
QObject::connect(ui_->tree, &FileViewTree::doubleClicked, this, &FileView::ItemDoubleClick);
// Setup tree root management buttons
ui_->add_tree_root->setIcon(IconLoader::Load(u"folder-new"_s));
ui_->remove_tree_root->setIcon(IconLoader::Load(u"list-remove"_s));
QObject::connect(ui_->add_tree_root, &QToolButton::clicked, this, &FileView::AddRootButtonClicked);
QObject::connect(ui_->remove_tree_root, &QToolButton::clicked, this, &FileView::RemoveRootButtonClicked);
QString filter = QLatin1String(kFileFilter);
filter_list_ << filter.split(u' ');
@@ -135,19 +109,6 @@ void FileView::ReloadSettings() {
ui_->forward->setIconSize(QSize(iconsize, iconsize));
ui_->home->setIconSize(QSize(iconsize, iconsize));
ui_->up->setIconSize(QSize(iconsize, iconsize));
ui_->toggle_view->setIconSize(QSize(iconsize, iconsize));
ui_->add_tree_root->setIconSize(QSize(iconsize, iconsize));
ui_->remove_tree_root->setIconSize(QSize(iconsize, iconsize));
// Load tree root paths setting
Settings file_settings;
file_settings.beginGroup(u"FileView"_s);
tree_root_paths_ = file_settings.value(u"tree_root_paths"_s, QStandardPaths::standardLocations(QStandardPaths::StandardLocation::MusicLocation)).toStringList();
tree_view_active_ = file_settings.value(u"tree_view_active"_s, false).toBool();
file_settings.endGroup();
// Set initial view mode
UpdateViewModeUI();
}
@@ -219,46 +180,24 @@ void FileView::ChangeFilePathWithoutUndo(const QString &new_path) {
}
void FileView::ItemActivated(const QModelIndex &idx) {
// Only handle activation for list view (not tree view)
if (!tree_view_active_ && model_->isDir(idx)) {
if (model_->isDir(idx))
ChangeFilePath(model_->filePath(idx));
}
}
void FileView::ItemDoubleClick(const QModelIndex &idx) {
QString file_path;
bool is_file = false;
// Handle tree view with virtual roots
if (tree_view_active_ && tree_model_) {
QVariant type_var = tree_model_->data(idx, FileViewTreeModel::Role_Type);
if (type_var.isValid()) {
FileViewTreeItem::Type item_type = type_var.value<FileViewTreeItem::Type>();
// Only handle files, ignore directories and virtual roots
if (item_type == FileViewTreeItem::Type::File) {
file_path = tree_model_->data(idx, FileViewTreeModel::Role_FilePath).toString();
is_file = true;
}
}
}
// Handle list view with filesystem model
else if (!tree_view_active_ && model_) {
if (!model_->isDir(idx)) {
file_path = model_->filePath(idx);
is_file = true;
}
if (model_->isDir(idx)) {
return;
}
// Add file to playlist if it's a valid file
if (is_file && !file_path.isEmpty()) {
MimeData *mimedata = new MimeData;
mimedata->from_doubleclick_ = true;
mimedata->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
mimedata->name_for_new_playlist_ = file_path;
QString file_path = model_->filePath(idx);
Q_EMIT AddToPlaylist(mimedata);
}
MimeData *mimedata = new MimeData;
mimedata->from_doubleclick_ = true;
mimedata->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
mimedata->name_for_new_playlist_ = file_path;
Q_EMIT AddToPlaylist(mimedata);
}
@@ -333,156 +272,12 @@ void FileView::showEvent(QShowEvent *e) {
model_->setNameFilterDisables(false);
ui_->list->setModel(model_);
// Create tree model
tree_model_ = new FileViewTreeModel(this);
tree_model_->SetNameFilters(filter_list_);
SetupTreeView();
ChangeFilePathWithoutUndo(QDir::homePath());
if (!lazy_set_path_.isEmpty()) ChangeFilePathWithoutUndo(lazy_set_path_);
}
void FileView::SetupTreeView() {
// Use the new tree model with virtual roots
ui_->tree->setModel(tree_model_);
// Set the root paths in the model
tree_model_->SetRootPaths(tree_root_paths_);
// No need to set root index - the model handles virtual roots
}
void FileView::ToggleViewMode() {
tree_view_active_ = !tree_view_active_;
UpdateViewModeUI();
// Save the preference
Settings s;
s.beginGroup(u"FileView"_s);
s.setValue(u"tree_view_active"_s, tree_view_active_);
s.endGroup();
}
void FileView::UpdateViewModeUI() {
if (tree_view_active_) {
ui_->view_stack->setCurrentWidget(ui_->tree_page);
// Hide navigation controls in tree view mode
ui_->back->setVisible(false);
ui_->forward->setVisible(false);
ui_->up->setVisible(false);
ui_->home->setVisible(false);
ui_->path->setVisible(false);
// Show tree root management buttons
ui_->add_tree_root->setVisible(true);
ui_->remove_tree_root->setVisible(true);
// Insert spacer in tree view if not already present
if (!view_mode_spacer_) {
view_mode_spacer_ = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
ui_->horizontalLayout->insertSpacerItem(ui_->horizontalLayout->indexOf(ui_->toggle_view), view_mode_spacer_);
}
}
else {
ui_->view_stack->setCurrentWidget(ui_->list_page);
// Show navigation controls in list view mode
ui_->back->setVisible(true);
ui_->forward->setVisible(true);
ui_->up->setVisible(true);
ui_->home->setVisible(true);
ui_->path->setVisible(true);
// Hide tree root management buttons in list view
ui_->add_tree_root->setVisible(false);
ui_->remove_tree_root->setVisible(false);
// Remove spacer in list view
if (view_mode_spacer_) {
ui_->horizontalLayout->removeItem(view_mode_spacer_);
delete view_mode_spacer_;
view_mode_spacer_ = nullptr;
}
}
}
void FileView::AddTreeRootPath(const QString &path) {
if (!tree_root_paths_.contains(path)) {
tree_root_paths_.append(path);
SaveTreeRootPaths();
// Refresh the tree view to show the new root
if (tree_model_) {
SetupTreeView();
}
}
}
void FileView::RemoveTreeRootPath(const QString &path) {
tree_root_paths_.removeAll(path);
SaveTreeRootPaths();
// Refresh the tree view
if (tree_model_) {
SetupTreeView();
}
}
void FileView::SaveTreeRootPaths() {
Settings s;
s.beginGroup(u"FileView"_s);
s.setValue(u"tree_root_paths"_s, tree_root_paths_);
s.endGroup();
}
void FileView::AddRootButtonClicked() {
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder to add as tree root"), tree_root_paths_.isEmpty() ? QDir::homePath() : tree_root_paths_.first(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) {
AddTreeRootPath(dir);
}
}
void FileView::RemoveRootButtonClicked() {
// Get currently selected item in tree
QModelIndex current = ui_->tree->currentIndex();
if (!current.isValid()) return;
QString path;
// Get the file path from the appropriate model
if (tree_model_) {
path = tree_model_->data(current, FileViewTreeModel::Role_FilePath).toString();
}
if (path.isEmpty()) return;
const QString clean_path = QDir::cleanPath(path);
// Check if this path or any parent is a configured root
for (const QString &root : std::as_const(tree_root_paths_)) {
const QString clean_root = QDir::cleanPath(root);
if (clean_path == clean_root || clean_path.startsWith(clean_root + QDir::separator())) {
RemoveTreeRootPath(root);
return;
}
}
}
void FileView::keyPressEvent(QKeyEvent *e) {
switch (e->key()) {

View File

@@ -40,12 +40,10 @@ class QFileIconProvider;
class QUndoStack;
class QKeyEvent;
class QShowEvent;
class QSpacerItem;
class MusicStorage;
class TaskManager;
class Ui_FileView;
class FileViewTreeModel;
class FileView : public QWidget {
Q_OBJECT
@@ -78,22 +76,12 @@ class FileView : public QWidget {
void ChangeFilePath(const QString &new_path);
void ItemActivated(const QModelIndex &idx);
void ItemDoubleClick(const QModelIndex &idx);
void ToggleViewMode();
void Delete(const QStringList &filenames);
void DeleteFinished(const SongList &songs_with_errors);
public Q_SLOTS:
void AddTreeRootPath(const QString &path);
void RemoveTreeRootPath(const QString &path);
private:
void ChangeFilePathWithoutUndo(const QString &new_path);
void SetupTreeView();
void SaveTreeRootPaths();
void AddRootButtonClicked();
void RemoveRootButtonClicked();
void UpdateViewModeUI();
private:
class UndoCommand : public QUndoCommand {
@@ -122,21 +110,16 @@ class FileView : public QWidget {
Ui_FileView *ui_;
QFileSystemModel *model_;
FileViewTreeModel *tree_model_;
QUndoStack *undo_stack_;
SharedPtr<TaskManager> task_manager_;
SharedPtr<MusicStorage> storage_;
QString lazy_set_path_;
QStringList tree_root_paths_;
QStringList filter_list_;
ScopedPtr<QFileIconProvider> file_icon_provider_;
bool tree_view_active_;
QSpacerItem *view_mode_spacer_;
};
#endif // FILEVIEW_H

View File

@@ -95,143 +95,28 @@
<item>
<widget class="QLineEdit" name="path"/>
</item>
<item>
<widget class="QToolButton" name="add_tree_root">
<property name="toolTip">
<string>Add root directory</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="remove_tree_root">
<property name="toolTip">
<string>Remove selected root directory</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toggle_view">
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Toggle between list and tree view</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="view_stack">
<property name="currentIndex">
<number>0</number>
<widget class="FileViewList" name="list">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<widget class="QWidget" name="list_page">
<layout class="QVBoxLayout" name="list_layout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="FileViewList" name="list">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tree_page">
<layout class="QVBoxLayout" name="tree_layout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="FileViewTree" name="tree">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@@ -242,11 +127,6 @@
<extends>QListView</extends>
<header>fileview/fileviewlist.h</header>
</customwidget>
<customwidget>
<class>FileViewTree</class>
<extends>QTreeView</extends>
<header>fileview/fileviewtree.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -99,7 +99,7 @@ MimeData *FileViewList::MimeDataFromSelection() const {
const QStringList filenames = FilenamesFromSelection();
// If just one folder selected - use its path as the new playlist's name
// if just one folder selected - use its path as the new playlist's name
if (filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) {
if (filenames.first().length() > 20) {
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
@@ -108,7 +108,7 @@ MimeData *FileViewList::MimeDataFromSelection() const {
mimedata->name_for_new_playlist_ = filenames.first();
}
}
// Otherwise, use the current root path
// otherwise, use the current root path
else {
QString path = qobject_cast<QFileSystemModel*>(model())->rootPath();
if (path.length() > 20) {
@@ -196,11 +196,11 @@ void FileViewList::mousePressEvent(QMouseEvent *e) {
case Qt::XButton2:
Q_EMIT Forward();
break;
// Enqueue to playlist with middleClick
// enqueue to playlist with middleClick
case Qt::MiddleButton:{
QListView::mousePressEvent(e);
// We need to update the menu selection
// we need to update the menu selection
menu_selection_ = selectionModel()->selection();
MimeData *mimedata = new MimeData;

View File

@@ -1,205 +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 <algorithm>
#include <utility>
#include <QWidget>
#include <QAbstractItemModel>
#include <QFileInfo>
#include <QDir>
#include <QMenu>
#include <QUrl>
#include <QCollator>
#include <QtEvents>
#include "core/iconloader.h"
#include "core/mimedata.h"
#include "utilities/filemanagerutils.h"
#include "fileviewtree.h"
#include "fileviewtreemodel.h"
using namespace Qt::Literals::StringLiterals;
FileViewTree::FileViewTree(QWidget *parent)
: QTreeView(parent),
menu_(new QMenu(this)) {
menu_->addAction(IconLoader::Load(u"media-playback-start"_s), tr("Append to current playlist"), this, &FileViewTree::AddToPlaylistSlot);
menu_->addAction(IconLoader::Load(u"media-playback-start"_s), tr("Replace current playlist"), this, &FileViewTree::LoadSlot);
menu_->addAction(IconLoader::Load(u"document-new"_s), tr("Open in new playlist"), this, &FileViewTree::OpenInNewPlaylistSlot);
menu_->addSeparator();
menu_->addAction(IconLoader::Load(u"edit-copy"_s), tr("Copy to collection..."), this, &FileViewTree::CopyToCollectionSlot);
menu_->addAction(IconLoader::Load(u"go-jump"_s), tr("Move to collection..."), this, &FileViewTree::MoveToCollectionSlot);
menu_->addAction(IconLoader::Load(u"device"_s), tr("Copy to device..."), this, &FileViewTree::CopyToDeviceSlot);
menu_->addAction(IconLoader::Load(u"edit-delete"_s), tr("Delete from disk..."), this, &FileViewTree::DeleteSlot);
menu_->addSeparator();
menu_->addAction(IconLoader::Load(u"edit-rename"_s), tr("Edit track information..."), this, &FileViewTree::EditTagsSlot);
menu_->addAction(IconLoader::Load(u"document-open-folder"_s), tr("Show in file browser..."), this, &FileViewTree::ShowInBrowser);
setAttribute(Qt::WA_MacShowFocusRect, false);
setHeaderHidden(true);
setUniformRowHeights(true);
}
void FileViewTree::contextMenuEvent(QContextMenuEvent *e) {
menu_selection_ = selectionModel()->selection();
menu_->popup(e->globalPos());
e->accept();
}
QStringList FileViewTree::FilenamesFromSelection() const {
QStringList filenames;
const QModelIndexList indexes = menu_selection_.indexes();
FileViewTreeModel *tree_model = qobject_cast<FileViewTreeModel*>(model());
if (tree_model) {
for (const QModelIndex &index : indexes) {
if (index.column() == 0) {
QString path = tree_model->data(index, FileViewTreeModel::Role_FilePath).toString();
if (!path.isEmpty()) {
filenames << path;
}
}
}
}
QCollator collator;
collator.setNumericMode(true);
std::sort(filenames.begin(), filenames.end(), collator);
return filenames;
}
QList<QUrl> FileViewTree::UrlListFromSelection() const {
QList<QUrl> urls;
const QStringList filenames = FilenamesFromSelection();
urls.reserve(filenames.count());
for (const QString &filename : std::as_const(filenames)) {
urls << QUrl::fromLocalFile(filename);
}
return urls;
}
MimeData *FileViewTree::MimeDataFromSelection() const {
MimeData *mimedata = new MimeData;
mimedata->setUrls(UrlListFromSelection());
const QStringList filenames = FilenamesFromSelection();
// if just one folder selected - use its path as the new playlist's name
if (filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) {
if (filenames.first().length() > 20) {
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
}
else {
mimedata->name_for_new_playlist_ = filenames.first();
}
}
// otherwise, use "Files" as default
else {
mimedata->name_for_new_playlist_ = tr("Files");
}
return mimedata;
}
void FileViewTree::LoadSlot() {
MimeData *mimedata = MimeDataFromSelection();
mimedata->clear_first_ = true;
Q_EMIT AddToPlaylist(mimedata);
}
void FileViewTree::AddToPlaylistSlot() {
Q_EMIT AddToPlaylist(MimeDataFromSelection());
}
void FileViewTree::OpenInNewPlaylistSlot() {
MimeData *mimedata = MimeDataFromSelection();
mimedata->open_in_new_playlist_ = true;
Q_EMIT AddToPlaylist(mimedata);
}
void FileViewTree::CopyToCollectionSlot() {
Q_EMIT CopyToCollection(UrlListFromSelection());
}
void FileViewTree::MoveToCollectionSlot() {
Q_EMIT MoveToCollection(UrlListFromSelection());
}
void FileViewTree::CopyToDeviceSlot() {
Q_EMIT CopyToDevice(UrlListFromSelection());
}
void FileViewTree::DeleteSlot() {
Q_EMIT Delete(FilenamesFromSelection());
}
void FileViewTree::EditTagsSlot() {
Q_EMIT EditTags(UrlListFromSelection());
}
void FileViewTree::mousePressEvent(QMouseEvent *e) {
switch (e->button()) {
// Enqueue to playlist with middleClick
case Qt::MiddleButton:{
QTreeView::mousePressEvent(e);
// We need to update the menu selection
QItemSelectionModel *selection_model = selectionModel();
if (!selection_model) {
e->ignore();
return;
}
menu_selection_ = selection_model->selection();
MimeData *mimedata = new MimeData;
mimedata->setUrls(UrlListFromSelection());
mimedata->enqueue_now_ = true;
Q_EMIT AddToPlaylist(mimedata);
break;
}
default:
QTreeView::mousePressEvent(e);
break;
}
}
void FileViewTree::ShowInBrowser() {
Utilities::OpenInFileBrowser(UrlListFromSelection());
}

View File

@@ -1,78 +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 FILEVIEWTREE_H
#define FILEVIEWTREE_H
#include <QObject>
#include <QTreeView>
#include <QList>
#include <QUrl>
#include <QString>
#include <QStringList>
class QWidget;
class QMimeData;
class QMenu;
class QMouseEvent;
class QContextMenuEvent;
class MimeData;
class FileViewTree : public QTreeView {
Q_OBJECT
public:
explicit FileViewTree(QWidget *parent = nullptr);
void mousePressEvent(QMouseEvent *e) override;
Q_SIGNALS:
void AddToPlaylist(QMimeData *data);
void CopyToCollection(const QList<QUrl> &urls);
void MoveToCollection(const QList<QUrl> &urls);
void CopyToDevice(const QList<QUrl> &urls);
void Delete(const QStringList &filenames);
void EditTags(const QList<QUrl> &urls);
protected:
void contextMenuEvent(QContextMenuEvent *e) override;
private:
QStringList FilenamesFromSelection() const;
QList<QUrl> UrlListFromSelection() const;
MimeData *MimeDataFromSelection() const;
private Q_SLOTS:
void LoadSlot();
void AddToPlaylistSlot();
void OpenInNewPlaylistSlot();
void CopyToCollectionSlot();
void MoveToCollectionSlot();
void CopyToDeviceSlot();
void DeleteSlot();
void EditTagsSlot();
void ShowInBrowser();
private:
QMenu *menu_;
QItemSelection menu_selection_;
};
#endif // FILEVIEWTREE_H

View File

@@ -1,52 +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 FILEVIEWTREEITEM_H
#define FILEVIEWTREEITEM_H
#include "config.h"
#include <QFileInfo>
#include "core/simpletreeitem.h"
class FileViewTreeItem : public SimpleTreeItem<FileViewTreeItem> {
public:
enum class Type {
Root, // Hidden root
VirtualRoot, // User-configured root paths
Directory, // File system directory
File // File system file
};
explicit FileViewTreeItem(SimpleTreeModel<FileViewTreeItem> *_model) : SimpleTreeItem<FileViewTreeItem>(_model), type(Type::Root), lazy_loaded(false) {}
explicit FileViewTreeItem(const Type _type, FileViewTreeItem *_parent = nullptr) : SimpleTreeItem<FileViewTreeItem>(_parent), type(_type), lazy_loaded(false) {}
Type type;
QString file_path; // Absolute file system path
QFileInfo file_info; // Cached file info
bool lazy_loaded; // Whether children have been loaded
private:
Q_DISABLE_COPY(FileViewTreeItem)
};
Q_DECLARE_METATYPE(FileViewTreeItem::Type)
#endif // FILEVIEWTREEITEM_H

View File

@@ -1,246 +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 <QString>
#include <QStringList>
#include <QList>
#include <QMap>
#include <QDir>
#include <QFileInfo>
#include <QFileIconProvider>
#include <QMimeData>
#include <QUrl>
#include <QIcon>
#include "core/simpletreemodel.h"
#include "core/logging.h"
#include "fileviewtreemodel.h"
#include "fileviewtreeitem.h"
using namespace Qt::Literals::StringLiterals;
FileViewTreeModel::FileViewTreeModel(QObject *parent)
: SimpleTreeModel<FileViewTreeItem>(new FileViewTreeItem(this), parent),
icon_provider_(new QFileIconProvider()) {
}
FileViewTreeModel::~FileViewTreeModel() {
delete root_;
delete icon_provider_;
}
Qt::ItemFlags FileViewTreeModel::flags(const QModelIndex &idx) const {
const FileViewTreeItem *item = IndexToItem(idx);
if (!item) return Qt::NoItemFlags;
switch (item->type) {
case FileViewTreeItem::Type::VirtualRoot:
case FileViewTreeItem::Type::Directory:
case FileViewTreeItem::Type::File:
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
case FileViewTreeItem::Type::Root:
default:
return Qt::ItemIsEnabled;
}
}
QVariant FileViewTreeModel::data(const QModelIndex &idx, const int role) const {
if (!idx.isValid()) return QVariant();
const FileViewTreeItem *item = IndexToItem(idx);
if (!item) return QVariant();
switch (role) {
case Qt::DisplayRole:
if (item->type == FileViewTreeItem::Type::VirtualRoot) {
return item->display_text.isEmpty() ? item->file_path : item->display_text;
}
return item->file_info.fileName();
case Qt::DecorationRole:
return GetIcon(item);
case Role_Type:
return QVariant::fromValue(item->type);
case Role_FilePath:
return item->file_path;
case Role_FileName:
return item->file_info.fileName();
default:
return QVariant();
}
}
bool FileViewTreeModel::hasChildren(const QModelIndex &parent) const {
const FileViewTreeItem *item = IndexToItem(parent);
if (!item) return false;
// Root and VirtualRoot always have children (or can have them)
if (item->type == FileViewTreeItem::Type::Root) return true;
if (item->type == FileViewTreeItem::Type::VirtualRoot) return true;
// Directories can have children
if (item->type == FileViewTreeItem::Type::Directory) {
return true;
}
// Files don't have children
return false;
}
bool FileViewTreeModel::canFetchMore(const QModelIndex &parent) const {
const FileViewTreeItem *item = IndexToItem(parent);
if (!item) return false;
// Can fetch more if not yet lazy loaded
return !item->lazy_loaded && (item->type == FileViewTreeItem::Type::VirtualRoot || item->type == FileViewTreeItem::Type::Directory);
}
void FileViewTreeModel::fetchMore(const QModelIndex &parent) {
FileViewTreeItem *item = IndexToItem(parent);
if (!item || item->lazy_loaded) return;
LazyLoad(item);
}
void FileViewTreeModel::LazyLoad(FileViewTreeItem *item) {
if (item->lazy_loaded) return;
QDir dir(item->file_path);
if (!dir.exists()) {
item->lazy_loaded = true;
return;
}
// Apply name filters
const QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot;
if (!name_filters_.isEmpty()) {
dir.setNameFilters(name_filters_);
}
const QFileInfoList entries = dir.entryInfoList(filters, QDir::Name | QDir::DirsFirst);
if (!entries.isEmpty()) {
BeginInsert(item, 0, static_cast<int>(entries.count()) - 1);
for (const QFileInfo &entry : entries) {
FileViewTreeItem *child = new FileViewTreeItem(
entry.isDir() ? FileViewTreeItem::Type::Directory : FileViewTreeItem::Type::File,
item
);
child->file_path = entry.absoluteFilePath();
child->file_info = entry;
child->lazy_loaded = false;
child->display_text = entry.fileName();
}
EndInsert();
}
item->lazy_loaded = true;
}
QIcon FileViewTreeModel::GetIcon(const FileViewTreeItem *item) const {
if (!item) return QIcon();
switch (item->type) {
case FileViewTreeItem::Type::VirtualRoot:
case FileViewTreeItem::Type::Directory:
return icon_provider_->icon(QFileIconProvider::Folder);
case FileViewTreeItem::Type::File:
return icon_provider_->icon(item->file_info);
default:
return QIcon();
}
}
QStringList FileViewTreeModel::mimeTypes() const {
return QStringList() << u"text/uri-list"_s;
}
QMimeData *FileViewTreeModel::mimeData(const QModelIndexList &indexes) const {
if (indexes.isEmpty()) return nullptr;
QList<QUrl> urls;
for (const QModelIndex &idx : indexes) {
const FileViewTreeItem *item = IndexToItem(idx);
if (item && (item->type == FileViewTreeItem::Type::File || item->type == FileViewTreeItem::Type::Directory || item->type == FileViewTreeItem::Type::VirtualRoot)) {
urls << QUrl::fromLocalFile(item->file_path);
}
}
if (urls.isEmpty()) return nullptr;
QMimeData *data = new QMimeData();
data->setUrls(urls);
return data;
}
void FileViewTreeModel::SetRootPaths(const QStringList &paths) {
Reset();
for (const QString &path : paths) {
QFileInfo info(path);
if (!info.exists() || !info.isDir()) continue;
FileViewTreeItem *virtual_root = new FileViewTreeItem(FileViewTreeItem::Type::VirtualRoot, root_);
virtual_root->file_path = info.absoluteFilePath();
virtual_root->file_info = info;
virtual_root->display_text = info.absoluteFilePath();
virtual_root->lazy_loaded = false;
}
}
void FileViewTreeModel::SetNameFilters(const QStringList &filters) {
name_filters_ = filters;
}
void FileViewTreeModel::Reset() {
beginResetModel();
// Clear children without notifications since we're in a reset
qDeleteAll(root_->children);
root_->children.clear();
endResetModel();
}

View File

@@ -1,72 +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 FILEVIEWTREEMODEL_H
#define FILEVIEWTREEMODEL_H
#include "config.h"
#include <QObject>
#include <QVariant>
#include <QStringList>
#include <QIcon>
#include "core/simpletreemodel.h"
#include "fileviewtreeitem.h"
class QFileIconProvider;
class QMimeData;
class FileViewTreeModel : public SimpleTreeModel<FileViewTreeItem> {
Q_OBJECT
public:
explicit FileViewTreeModel(QObject *parent = nullptr);
~FileViewTreeModel() override;
enum Role {
Role_Type = Qt::UserRole + 1,
Role_FilePath,
Role_FileName,
RoleCount
};
// QAbstractItemModel
Qt::ItemFlags flags(const QModelIndex &idx) const override;
QVariant data(const QModelIndex &idx, const int role) const override;
bool hasChildren(const QModelIndex &parent) const override;
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
QStringList mimeTypes() const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
void SetRootPaths(const QStringList &paths);
void SetNameFilters(const QStringList &filters);
private:
void Reset();
void LazyLoad(FileViewTreeItem *item);
QIcon GetIcon(const FileViewTreeItem *item) const;
private:
QFileIconProvider *icon_provider_;
QStringList name_filters_;
};
#endif // FILEVIEWTREEMODEL_H

View File

@@ -56,7 +56,7 @@ using namespace Qt::Literals::StringLiterals;
using std::make_shared;
namespace {
constexpr int kSongTableJoins = 2;
constexpr int kSongTableJoins = 3;
}
PlaylistBackend::PlaylistBackend(const SharedPtr<Database> database,
@@ -186,10 +186,12 @@ PlaylistBackend::Playlist PlaylistBackend::GetPlaylist(const int id) {
QString PlaylistBackend::PlaylistItemsQuery() {
return QStringLiteral("SELECT %1, %2, p.type FROM playlist_items AS p "
return QStringLiteral("SELECT %1, %2, %3, 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));
}

View File

@@ -47,6 +47,8 @@ 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:
@@ -72,6 +74,8 @@ 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:

View File

@@ -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()));
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count() * 2));
return true;
}

View File

@@ -47,7 +47,7 @@ void StreamPlaylistItem::InitMetadata() {
bool StreamPlaylistItem::InitFromQuery(const SqlRow &query) {
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count()));
song_.InitFromQuery(query, false, static_cast<int>(Song::kRowIdColumns.count() * 2));
InitMetadata();
return true;

View File

@@ -0,0 +1,144 @@
/*
* 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();
}

View File

@@ -0,0 +1,58 @@
/*
* 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

View File

@@ -0,0 +1,125 @@
<?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>

View File

@@ -90,6 +90,10 @@
# include "qobuz/qobuzservice.h"
# include "qobuzsettingspage.h"
#endif
#ifdef HAVE_DROPBOX
# include "dropbox/dropboxservice.h"
# include "dropboxsettingspage.h"
#endif
#include "ui_settingsdialog.h"
@@ -144,7 +148,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)
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_SPOTIFY) || defined(HAVE_QOBUZ) || defined(HAVE_DROPBOX)
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
#endif
@@ -160,6 +164,9 @@ 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);

View File

@@ -93,6 +93,8 @@ class SettingsDialog : public QDialog {
Tidal,
Qobuz,
Spotify,
Dropbox,
OneDrive,
};
enum Role {

View File

@@ -0,0 +1,134 @@
/*
* 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();
}

View File

@@ -0,0 +1,89 @@
/*
* 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

View File

@@ -142,6 +142,8 @@ 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;