Compare commits
4 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0df4afe363 | ||
|
|
350d907e8b | ||
|
|
eaced733bb | ||
|
|
2abe4576a9 |
16
.github/workflows/build.yml
vendored
16
.github/workflows/build.yml
vendored
@@ -739,18 +739,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Free disk space
|
|
||||||
run: |
|
|
||||||
df -h
|
|
||||||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
|
|
||||||
sudo apt-get clean
|
|
||||||
df -h
|
|
||||||
- name: Build FreeBSD
|
- name: Build FreeBSD
|
||||||
id: build-freebsd
|
id: build-freebsd
|
||||||
uses: vmactions/freebsd-vm@v1.3.5
|
uses: vmactions/freebsd-vm@v1.3.0
|
||||||
with:
|
with:
|
||||||
usesh: true
|
usesh: true
|
||||||
mem: 8192
|
mem: 4096
|
||||||
prepare: pkg install -y git cmake pkgconf boost-libs alsa-lib glib qt6-base qt6-tools sqlite gstreamer1 gstreamer1-plugins chromaprint libebur128 taglib libcdio libmtp gdk-pixbuf2 libgpod fftw3 icu kdsingleapplication googletest pulseaudio sparsehash rapidjson
|
prepare: pkg install -y git cmake pkgconf boost-libs alsa-lib glib qt6-base qt6-tools sqlite gstreamer1 gstreamer1-plugins chromaprint libebur128 taglib libcdio libmtp gdk-pixbuf2 libgpod fftw3 icu kdsingleapplication googletest pulseaudio sparsehash rapidjson
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
@@ -772,7 +766,7 @@ jobs:
|
|||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Build OpenBSD
|
- name: Build OpenBSD
|
||||||
id: build-openbsd
|
id: build-openbsd
|
||||||
uses: vmactions/openbsd-vm@v1.3.1
|
uses: vmactions/openbsd-vm@v1.2.5
|
||||||
with:
|
with:
|
||||||
usesh: true
|
usesh: true
|
||||||
mem: 4096
|
mem: 4096
|
||||||
@@ -845,7 +839,7 @@ jobs:
|
|||||||
p12-password: ${{ secrets.APPLE_DEVELOPER_ID_CERTIFICATE_PASSWORD }}
|
p12-password: ${{ secrets.APPLE_DEVELOPER_ID_CERTIFICATE_PASSWORD }}
|
||||||
|
|
||||||
- name: Download macOS dependencies
|
- 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
|
- name: Extract macOS dependencies
|
||||||
run: sudo tar -C / -xf strawberry-macos-${{env.arch}}-${{env.buildtype}}.tar.xz
|
run: sudo tar -C / -xf strawberry-macos-${{env.arch}}-${{env.buildtype}}.tar.xz
|
||||||
@@ -898,7 +892,7 @@ jobs:
|
|||||||
- name: Manually Codesign
|
- name: Manually Codesign
|
||||||
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15-intel'
|
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15-intel'
|
||||||
working-directory: build
|
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
|
- name: Manually Codesign
|
||||||
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15'
|
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-15'
|
||||||
|
|||||||
@@ -823,8 +823,6 @@ set(SOURCES
|
|||||||
|
|
||||||
src/fileview/fileview.cpp
|
src/fileview/fileview.cpp
|
||||||
src/fileview/fileviewlist.cpp
|
src/fileview/fileviewlist.cpp
|
||||||
src/fileview/fileviewtree.cpp
|
|
||||||
src/fileview/fileviewtreemodel.cpp
|
|
||||||
|
|
||||||
src/device/devicemanager.cpp
|
src/device/devicemanager.cpp
|
||||||
src/device/devicelister.cpp
|
src/device/devicelister.cpp
|
||||||
@@ -1114,8 +1112,6 @@ set(HEADERS
|
|||||||
|
|
||||||
src/fileview/fileview.h
|
src/fileview/fileview.h
|
||||||
src/fileview/fileviewlist.h
|
src/fileview/fileviewlist.h
|
||||||
src/fileview/fileviewtree.h
|
|
||||||
src/fileview/fileviewtreemodel.h
|
|
||||||
|
|
||||||
src/device/devicemanager.h
|
src/device/devicemanager.h
|
||||||
src/device/devicelister.h
|
src/device/devicelister.h
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Strawberry Music Player
|
* Strawberry Music Player
|
||||||
* This file was part of Clementine.
|
* This file was part of Clementine.
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||||
*
|
*
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -189,26 +189,6 @@ void CollectionLibrary::ReloadSettings() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionLibrary::CurrentSongChanged(const Song &song) {
|
|
||||||
|
|
||||||
current_song_url_ = song.url();
|
|
||||||
|
|
||||||
if (!pending_song_saves_.isEmpty()) {
|
|
||||||
SavePendingPlaycountsAndRatings();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CollectionLibrary::Stopped() {
|
|
||||||
|
|
||||||
current_song_url_ = QUrl();
|
|
||||||
|
|
||||||
if (!pending_song_saves_.isEmpty()) {
|
|
||||||
SavePendingPlaycountsAndRatings();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CollectionLibrary::SyncPlaycountAndRatingToFilesAsync() {
|
void CollectionLibrary::SyncPlaycountAndRatingToFilesAsync() {
|
||||||
|
|
||||||
(void)QtConcurrent::run(&CollectionLibrary::SyncPlaycountAndRatingToFiles, this);
|
(void)QtConcurrent::run(&CollectionLibrary::SyncPlaycountAndRatingToFiles, this);
|
||||||
@@ -232,85 +212,18 @@ void CollectionLibrary::SyncPlaycountAndRatingToFiles() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionLibrary::SongsPlaycountChanged(const SongList &songs, const bool save_tags) {
|
void CollectionLibrary::SongsPlaycountChanged(const SongList &songs, const bool save_tags) const {
|
||||||
|
|
||||||
if (save_tags || save_playcounts_to_files_) {
|
if (save_tags || save_playcounts_to_files_) {
|
||||||
SongList songs_to_save_now;
|
tagreader_client_->SaveSongsPlaycountAsync(songs);
|
||||||
for (const Song &song : songs) {
|
|
||||||
if (song.url().isLocalFile() && song.url() == current_song_url_ &&
|
|
||||||
(song.filetype() == Song::FileType::OggFlac || song.filetype() == Song::FileType::OggVorbis || song.filetype() == Song::FileType::OggOpus)) {
|
|
||||||
qLog(Debug) << "Deferring playcount save for currently playing file" << song.url().toLocalFile();
|
|
||||||
if (pending_song_saves_.contains(song.url())) {
|
|
||||||
SharedPtr<PendingSongSave> pending_song_save = pending_song_saves_[song.url()];
|
|
||||||
pending_song_save->save_playcount = true;
|
|
||||||
pending_song_save->song.set_playcount(song.playcount());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SharedPtr<PendingSongSave> pending_song_save = make_shared<PendingSongSave>();
|
|
||||||
pending_song_save->save_playcount = true;
|
|
||||||
pending_song_save->song = song;
|
|
||||||
pending_song_saves_.insert(song.url(), pending_song_save);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
songs_to_save_now << song;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!songs_to_save_now.isEmpty()) {
|
|
||||||
tagreader_client_->SaveSongsPlaycountAsync(songs_to_save_now);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionLibrary::SongsRatingChanged(const SongList &songs, const bool save_tags) {
|
void CollectionLibrary::SongsRatingChanged(const SongList &songs, const bool save_tags) const {
|
||||||
|
|
||||||
if (save_tags || save_ratings_to_files_) {
|
if (save_tags || save_ratings_to_files_) {
|
||||||
SongList songs_to_save_now;
|
tagreader_client_->SaveSongsRatingAsync(songs);
|
||||||
for (const Song &song : songs) {
|
|
||||||
if (song.url().isLocalFile() && song.url() == current_song_url_ &&
|
|
||||||
(song.filetype() == Song::FileType::OggFlac || song.filetype() == Song::FileType::OggVorbis || song.filetype() == Song::FileType::OggOpus)) {
|
|
||||||
qLog(Debug) << "Deferring rating save for currently playing file" << song.url().toLocalFile();
|
|
||||||
if (pending_song_saves_.contains(song.url())) {
|
|
||||||
SharedPtr<PendingSongSave> pending_song_save = pending_song_saves_[song.url()];
|
|
||||||
pending_song_save->save_rating = true;
|
|
||||||
pending_song_save->song.set_rating(song.rating());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SharedPtr<PendingSongSave> pending_song_save = make_shared<PendingSongSave>();
|
|
||||||
pending_song_save->save_rating = true;
|
|
||||||
pending_song_save->song = song;
|
|
||||||
pending_song_saves_.insert(song.url(), pending_song_save);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
songs_to_save_now << song;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!songs_to_save_now.isEmpty()) {
|
|
||||||
tagreader_client_->SaveSongsRatingAsync(songs_to_save_now);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CollectionLibrary::SavePendingPlaycountsAndRatings() {
|
|
||||||
|
|
||||||
for (auto it = pending_song_saves_.constBegin(); it != pending_song_saves_.constEnd();) {
|
|
||||||
const QUrl url = it.key();
|
|
||||||
SharedPtr<PendingSongSave> pending_song_save = it.value();
|
|
||||||
if (url == current_song_url_) {
|
|
||||||
++it;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
qLog(Debug) << "Saving deferred playcount/rating for" << url.toLocalFile();
|
|
||||||
if (pending_song_save->save_playcount) {
|
|
||||||
tagreader_client_->SaveSongsPlaycountAsync(SongList() << pending_song_save->song);
|
|
||||||
}
|
|
||||||
if (pending_song_save->save_rating) {
|
|
||||||
tagreader_client_->SaveSongsRatingAsync(SongList() << pending_song_save->song);
|
|
||||||
}
|
|
||||||
it = pending_song_saves_.erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* Strawberry Music Player
|
* Strawberry Music Player
|
||||||
* This file was part of Clementine.
|
* This file was part of Clementine.
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||||
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||||
*
|
*
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMap>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "includes/shared_ptr.h"
|
#include "includes/shared_ptr.h"
|
||||||
@@ -72,7 +71,6 @@ class CollectionLibrary : public QObject {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void SyncPlaycountAndRatingToFiles();
|
void SyncPlaycountAndRatingToFiles();
|
||||||
void SavePendingPlaycountsAndRatings();
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
@@ -86,26 +84,16 @@ class CollectionLibrary : public QObject {
|
|||||||
|
|
||||||
void IncrementalScan();
|
void IncrementalScan();
|
||||||
|
|
||||||
void CurrentSongChanged(const Song &song);
|
|
||||||
void Stopped();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void ExitReceived();
|
void ExitReceived();
|
||||||
void SongsPlaycountChanged(const SongList &songs, const bool save_tags = false);
|
void SongsPlaycountChanged(const SongList &songs, const bool save_tags = false) const;
|
||||||
void SongsRatingChanged(const SongList &songs, const bool save_tags = false);
|
void SongsRatingChanged(const SongList &songs, const bool save_tags = false) const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void Error(const QString &error);
|
void Error(const QString &error);
|
||||||
void ExitFinished();
|
void ExitFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PendingSongSave {
|
|
||||||
public:
|
|
||||||
Song song;
|
|
||||||
bool save_playcount = false;
|
|
||||||
bool save_rating = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const SharedPtr<TaskManager> task_manager_;
|
const SharedPtr<TaskManager> task_manager_;
|
||||||
const SharedPtr<TagReaderClient> tagreader_client_;
|
const SharedPtr<TagReaderClient> tagreader_client_;
|
||||||
|
|
||||||
@@ -123,10 +111,6 @@ class CollectionLibrary : public QObject {
|
|||||||
|
|
||||||
bool save_playcounts_to_files_;
|
bool save_playcounts_to_files_;
|
||||||
bool save_ratings_to_files_;
|
bool save_ratings_to_files_;
|
||||||
|
|
||||||
QUrl current_song_url_;
|
|
||||||
|
|
||||||
QMap<QUrl, SharedPtr<PendingSongSave>> pending_song_saves_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1209,41 +1209,49 @@ QString CollectionModel::ContainerKey(const GroupBy group_by, const Song &song,
|
|||||||
switch (group_by) {
|
switch (group_by) {
|
||||||
case GroupBy::AlbumArtist:
|
case GroupBy::AlbumArtist:
|
||||||
key = TextOrUnknown(song.effective_albumartist());
|
key = TextOrUnknown(song.effective_albumartist());
|
||||||
|
if (!song.effective_albumartistsort().isEmpty() && song.effective_albumartistsort() != song.effective_albumartist()) key.append(QLatin1Char('-') + TextOrUnknown(song.effective_albumartistsort()));
|
||||||
has_unique_album_identifier = true;
|
has_unique_album_identifier = true;
|
||||||
break;
|
break;
|
||||||
case GroupBy::Artist:
|
case GroupBy::Artist:
|
||||||
key = TextOrUnknown(song.artist());
|
key = TextOrUnknown(song.artist());
|
||||||
|
if (!song.artistsort().isEmpty() && song.artistsort() != song.artist()) key.append(QLatin1Char('-') + TextOrUnknown(song.artistsort()));
|
||||||
has_unique_album_identifier = true;
|
has_unique_album_identifier = true;
|
||||||
break;
|
break;
|
||||||
case GroupBy::Album:
|
case GroupBy::Album:
|
||||||
key = TextOrUnknown(song.album());
|
key = TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
break;
|
break;
|
||||||
case GroupBy::AlbumDisc:
|
case GroupBy::AlbumDisc:
|
||||||
key = TextOrUnknown(song.album());
|
key = TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
break;
|
break;
|
||||||
case GroupBy::YearAlbum:
|
case GroupBy::YearAlbum:
|
||||||
key = SortTextForYear(song.year()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
key = SortTextForYear(song.year()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
break;
|
break;
|
||||||
case GroupBy::YearAlbumDisc:
|
case GroupBy::YearAlbumDisc:
|
||||||
key = SortTextForYear(song.year()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
key = SortTextForYear(song.year()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
break;
|
break;
|
||||||
case GroupBy::OriginalYearAlbum:
|
case GroupBy::OriginalYearAlbum:
|
||||||
key = SortTextForYear(song.effective_originalyear()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
key = SortTextForYear(song.effective_originalyear()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
break;
|
break;
|
||||||
case GroupBy::OriginalYearAlbumDisc:
|
case GroupBy::OriginalYearAlbumDisc:
|
||||||
key = SortTextForYear(song.effective_originalyear()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
key = SortTextForYear(song.effective_originalyear()) + QLatin1Char('-') + TextOrUnknown(song.album());
|
||||||
|
if (!song.albumsort().isEmpty() && song.albumsort() != song.album()) key.append(QLatin1Char('-') + TextOrUnknown(song.albumsort()));
|
||||||
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
key.append(QLatin1Char('-') + SortTextForNumber(song.disc()));
|
||||||
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
if (!song.album_id().isEmpty()) key.append(QLatin1Char('-') + song.album_id());
|
||||||
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
if (options_active_.separate_albums_by_grouping && !song.grouping().isEmpty()) key.append(QLatin1Char('-') + song.grouping());
|
||||||
@@ -1262,10 +1270,12 @@ QString CollectionModel::ContainerKey(const GroupBy group_by, const Song &song,
|
|||||||
break;
|
break;
|
||||||
case GroupBy::Composer:
|
case GroupBy::Composer:
|
||||||
key = TextOrUnknown(song.composer());
|
key = TextOrUnknown(song.composer());
|
||||||
|
if (!song.composersort().isEmpty() && song.composersort() != song.composer()) key.append(QLatin1Char('-') + song.composersort());
|
||||||
has_unique_album_identifier = true;
|
has_unique_album_identifier = true;
|
||||||
break;
|
break;
|
||||||
case GroupBy::Performer:
|
case GroupBy::Performer:
|
||||||
key = TextOrUnknown(song.performer());
|
key = TextOrUnknown(song.performer());
|
||||||
|
if (!song.performersort().isEmpty() && song.performersort() != song.performer()) key.append(QLatin1Char('-') + song.performersort());
|
||||||
has_unique_album_identifier = true;
|
has_unique_album_identifier = true;
|
||||||
break;
|
break;
|
||||||
case GroupBy::Grouping:
|
case GroupBy::Grouping:
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ void CollectionView::keyPressEvent(QKeyEvent *e) {
|
|||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
if (currentIndex().isValid()) {
|
if (currentIndex().isValid()) {
|
||||||
Q_EMIT doubleClicked(currentIndex());
|
AddToPlaylist();
|
||||||
}
|
}
|
||||||
e->accept();
|
e->accept();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ constexpr char kFileFilter[] =
|
|||||||
"*.mod *.s3m *.xm *.it "
|
"*.mod *.s3m *.xm *.it "
|
||||||
"*.spc *.vgm";
|
"*.spc *.vgm";
|
||||||
|
|
||||||
constexpr char kLoadImageFileFilter[] = QT_TRANSLATE_NOOP("FileFilter", "Images (*.png *.jpg *.jpeg *.bmp *.gif *.xpm *.pbm *.pgm *.ppm *.xbm *.webp)");
|
constexpr char kLoadImageFileFilter[] = QT_TRANSLATE_NOOP("FileFilter", "Images (*.png *.jpg *.jpeg *.bmp *.gif *.xpm *.pbm *.pgm *.ppm *.xbm)");
|
||||||
constexpr char kSaveImageFileFilter[] = QT_TRANSLATE_NOOP("FileFilter", "Images (*.png *.jpg *.jpeg *.bmp *.xpm *.pbm *.ppm *.xbm *.webp)");
|
constexpr char kSaveImageFileFilter[] = QT_TRANSLATE_NOOP("FileFilter", "Images (*.png *.jpg *.jpeg *.bmp *.xpm *.pbm *.ppm *.xbm)");
|
||||||
|
|
||||||
#endif // FILEFILTERCONSTANTS_H
|
#endif // FILEFILTERCONSTANTS_H
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ constexpr char kShowErrorDialog[] = "show_error_dialog";
|
|||||||
constexpr char kStripRemastered[] = "strip_remastered";
|
constexpr char kStripRemastered[] = "strip_remastered";
|
||||||
constexpr char kSources[] = "sources";
|
constexpr char kSources[] = "sources";
|
||||||
constexpr char kUserToken[] = "user_token";
|
constexpr char kUserToken[] = "user_token";
|
||||||
constexpr char kApiKey[] = "api_key";
|
|
||||||
|
|
||||||
} // namespace ScrobblerSettings
|
} // namespace ScrobblerSettings
|
||||||
|
|
||||||
|
|||||||
@@ -110,32 +110,21 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job, QString &error_te
|
|||||||
|
|
||||||
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) {
|
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) {
|
||||||
|
|
||||||
const QString path = job.metadata_.url().toLocalFile();
|
QString path = job.metadata_.url().toLocalFile();
|
||||||
const QFileInfo fileInfo(path);
|
QFileInfo fileInfo(path);
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
|
||||||
if (job.use_trash_ && QFile::supportsMoveToTrash()) {
|
if (job.use_trash_ && QFile::supportsMoveToTrash()) {
|
||||||
#else
|
#else
|
||||||
if (job.use_trash_) {
|
if (job.use_trash_) {
|
||||||
#endif
|
#endif
|
||||||
if (QFile::moveToTrash(path)) {
|
return QFile::moveToTrash(path);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
qLog(Warning) << "Moving file to trash failed for" << path << ", falling back to direct deletion";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
if (fileInfo.isDir()) {
|
if (fileInfo.isDir()) {
|
||||||
success = Utilities::RemoveRecursive(path);
|
return Utilities::RemoveRecursive(path);
|
||||||
}
|
|
||||||
else {
|
|
||||||
success = QFile::remove(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
return QFile::remove(path);
|
||||||
qLog(Error) << "Failed to delete file" << path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QErrorMessage>
|
#include <QErrorMessage>
|
||||||
|
#include <QSettings>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QItemSelectionModel>
|
#include <QItemSelectionModel>
|
||||||
@@ -696,9 +697,6 @@ MainWindow::MainWindow(Application *app,
|
|||||||
QObject::connect(&*app_->task_manager(), &TaskManager::PauseCollectionWatchers, &*app_->collection(), &CollectionLibrary::PauseWatcher);
|
QObject::connect(&*app_->task_manager(), &TaskManager::PauseCollectionWatchers, &*app_->collection(), &CollectionLibrary::PauseWatcher);
|
||||||
QObject::connect(&*app_->task_manager(), &TaskManager::ResumeCollectionWatchers, &*app_->collection(), &CollectionLibrary::ResumeWatcher);
|
QObject::connect(&*app_->task_manager(), &TaskManager::ResumeCollectionWatchers, &*app_->collection(), &CollectionLibrary::ResumeWatcher);
|
||||||
|
|
||||||
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*app_->collection(), &CollectionLibrary::CurrentSongChanged);
|
|
||||||
QObject::connect(&*app_->player(), &Player::Stopped, &*app_->collection(), &CollectionLibrary::Stopped);
|
|
||||||
|
|
||||||
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::LoadAlbumCover);
|
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::LoadAlbumCover);
|
||||||
QObject::connect(&*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &MainWindow::AlbumCoverLoaded);
|
QObject::connect(&*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &MainWindow::AlbumCoverLoaded);
|
||||||
QObject::connect(album_cover_choice_controller_, &AlbumCoverChoiceController::Error, this, &MainWindow::ShowErrorDialog);
|
QObject::connect(album_cover_choice_controller_, &AlbumCoverChoiceController::Error, this, &MainWindow::ShowErrorDialog);
|
||||||
@@ -979,28 +977,27 @@ MainWindow::MainWindow(Application *app,
|
|||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
qLog(Debug) << "Loading settings";
|
qLog(Debug) << "Loading settings";
|
||||||
Settings settings;
|
settings_.beginGroup(MainWindowSettings::kSettingsGroup);
|
||||||
settings.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
|
|
||||||
// Set last used geometry to position window on the correct monitor
|
// Set last used geometry to position window on the correct monitor
|
||||||
// Set window state only if the window was last maximized
|
// Set window state only if the window was last maximized
|
||||||
if (settings.contains("geometry")) {
|
if (settings_.contains("geometry")) {
|
||||||
restoreGeometry(settings.value("geometry").toByteArray());
|
restoreGeometry(settings_.value("geometry").toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings.contains(MainWindowSettings::kSplitterState) || !ui_->splitter->restoreState(settings.value(MainWindowSettings::kSplitterState).toByteArray())) {
|
if (!settings_.contains(MainWindowSettings::kSplitterState) || !ui_->splitter->restoreState(settings_.value(MainWindowSettings::kSplitterState).toByteArray())) {
|
||||||
ui_->splitter->setSizes(QList<int>() << 20 << (width() - 20));
|
ui_->splitter->setSizes(QList<int>() << 20 << (width() - 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_->tabs->setCurrentIndex(settings.value("current_tab", 1).toInt());
|
ui_->tabs->setCurrentIndex(settings_.value("current_tab", 1).toInt());
|
||||||
FancyTabWidget::Mode default_mode = FancyTabWidget::Mode::LargeSidebar;
|
FancyTabWidget::Mode default_mode = FancyTabWidget::Mode::LargeSidebar;
|
||||||
FancyTabWidget::Mode tab_mode = static_cast<FancyTabWidget::Mode>(settings.value("tab_mode", static_cast<int>(default_mode)).toInt());
|
FancyTabWidget::Mode tab_mode = static_cast<FancyTabWidget::Mode>(settings_.value("tab_mode", static_cast<int>(default_mode)).toInt());
|
||||||
if (tab_mode == FancyTabWidget::Mode::None) tab_mode = default_mode;
|
if (tab_mode == FancyTabWidget::Mode::None) tab_mode = default_mode;
|
||||||
ui_->tabs->SetMode(tab_mode);
|
ui_->tabs->SetMode(tab_mode);
|
||||||
|
|
||||||
TabSwitched();
|
TabSwitched();
|
||||||
|
|
||||||
file_view_->SetPath(settings.value("file_path", QDir::homePath()).toString());
|
file_view_->SetPath(settings_.value("file_path", QDir::homePath()).toString());
|
||||||
|
|
||||||
// Users often collapse one side of the splitter by mistake and don't know how to restore it. This must be set after the state is restored above.
|
// Users often collapse one side of the splitter by mistake and don't know how to restore it. This must be set after the state is restored above.
|
||||||
ui_->splitter->setChildrenCollapsible(false);
|
ui_->splitter->setChildrenCollapsible(false);
|
||||||
@@ -1043,13 +1040,13 @@ MainWindow::MainWindow(Application *app,
|
|||||||
case BehaviourSettings::StartupBehaviour::Remember:
|
case BehaviourSettings::StartupBehaviour::Remember:
|
||||||
default:{
|
default:{
|
||||||
|
|
||||||
was_maximized_ = settings.value(MainWindowSettings::kMaximized, true).toBool();
|
was_maximized_ = settings_.value(MainWindowSettings::kMaximized, true).toBool();
|
||||||
if (was_maximized_) setWindowState(windowState() | Qt::WindowMaximized);
|
if (was_maximized_) setWindowState(windowState() | Qt::WindowMaximized);
|
||||||
|
|
||||||
was_minimized_ = settings.value(MainWindowSettings::kMinimized, false).toBool();
|
was_minimized_ = settings_.value(MainWindowSettings::kMinimized, false).toBool();
|
||||||
if (was_minimized_) setWindowState(windowState() | Qt::WindowMinimized);
|
if (was_minimized_) setWindowState(windowState() | Qt::WindowMinimized);
|
||||||
|
|
||||||
if (!systemtrayicon_->IsSystemTrayAvailable() || !systemtrayicon_->isVisible() || !settings.value(MainWindowSettings::kHidden, false).toBool()) {
|
if (!systemtrayicon_->IsSystemTrayAvailable() || !systemtrayicon_->isVisible() || !settings_.value(MainWindowSettings::kHidden, false).toBool()) {
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1057,7 +1054,7 @@ MainWindow::MainWindow(Application *app,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool show_sidebar = settings.value(MainWindowSettings::kShowSidebar, true).toBool();
|
bool show_sidebar = settings_.value(MainWindowSettings::kShowSidebar, true).toBool();
|
||||||
ui_->sidebar_layout->setVisible(show_sidebar);
|
ui_->sidebar_layout->setVisible(show_sidebar);
|
||||||
ui_->action_toggle_show_sidebar->setChecked(show_sidebar);
|
ui_->action_toggle_show_sidebar->setChecked(show_sidebar);
|
||||||
|
|
||||||
@@ -1228,9 +1225,7 @@ void MainWindow::ReloadSettings() {
|
|||||||
|
|
||||||
osd_->ReloadSettings();
|
osd_->ReloadSettings();
|
||||||
|
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
album_cover_choice_controller_->search_cover_auto_action()->setChecked(settings_.value(MainWindowSettings::kSearchForCoverAuto, true).toBool());
|
||||||
album_cover_choice_controller_->search_cover_auto_action()->setChecked(s.value(MainWindowSettings::kSearchForCoverAuto, true).toBool());
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
#ifdef HAVE_SUBSONIC
|
#ifdef HAVE_SUBSONIC
|
||||||
s.beginGroup(SubsonicSettings::kSettingsGroup);
|
s.beginGroup(SubsonicSettings::kSettingsGroup);
|
||||||
@@ -1347,11 +1342,8 @@ void MainWindow::SaveSettings() {
|
|||||||
ui_->playlist->view()->SaveSettings();
|
ui_->playlist->view()->SaveSettings();
|
||||||
app_->scrobbler()->WriteCache();
|
app_->scrobbler()->WriteCache();
|
||||||
|
|
||||||
Settings s;
|
settings_.setValue(MainWindowSettings::kShowSidebar, ui_->action_toggle_show_sidebar->isChecked());
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
settings_.setValue(MainWindowSettings::kSearchForCoverAuto, album_cover_choice_controller_->search_cover_auto_action()->isChecked());
|
||||||
s.setValue(MainWindowSettings::kShowSidebar, ui_->action_toggle_show_sidebar->isChecked());
|
|
||||||
s.setValue(MainWindowSettings::kSearchForCoverAuto, album_cover_choice_controller_->search_cover_auto_action()->isChecked());
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1592,35 +1584,23 @@ void MainWindow::ToggleSidebar(const bool checked) {
|
|||||||
|
|
||||||
ui_->sidebar_layout->setVisible(checked);
|
ui_->sidebar_layout->setVisible(checked);
|
||||||
TabSwitched();
|
TabSwitched();
|
||||||
|
settings_.setValue(MainWindowSettings::kShowSidebar, checked);
|
||||||
Settings s;
|
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
s.setValue(MainWindowSettings::kShowSidebar, checked);
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ToggleSearchCoverAuto(const bool checked) {
|
void MainWindow::ToggleSearchCoverAuto(const bool checked) {
|
||||||
|
settings_.setValue(MainWindowSettings::kSearchForCoverAuto, checked);
|
||||||
Settings s;
|
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
s.setValue(MainWindowSettings::kSearchForCoverAuto, checked);
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SaveGeometry() {
|
void MainWindow::SaveGeometry() {
|
||||||
|
|
||||||
if (!initialized_) return;
|
if (!initialized_) return;
|
||||||
|
|
||||||
Settings s;
|
settings_.setValue(MainWindowSettings::kMaximized, isMaximized());
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
settings_.setValue(MainWindowSettings::kMinimized, isMinimized());
|
||||||
s.setValue(MainWindowSettings::kMaximized, isMaximized());
|
settings_.setValue(MainWindowSettings::kHidden, isHidden());
|
||||||
s.setValue(MainWindowSettings::kMinimized, isMinimized());
|
settings_.setValue(MainWindowSettings::kGeometry, saveGeometry());
|
||||||
s.setValue(MainWindowSettings::kHidden, isHidden());
|
settings_.setValue(MainWindowSettings::kSplitterState, ui_->splitter->saveState());
|
||||||
s.setValue(MainWindowSettings::kGeometry, saveGeometry());
|
|
||||||
s.setValue(MainWindowSettings::kSplitterState, ui_->splitter->saveState());
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1762,12 +1742,7 @@ void MainWindow::SetHiddenInTray(const bool hidden) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::FilePathChanged(const QString &path) {
|
void MainWindow::FilePathChanged(const QString &path) {
|
||||||
|
settings_.setValue("file_path", path);
|
||||||
Settings s;
|
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
s.setValue("file_path", path);
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::Seeked(const qint64 microseconds) {
|
void MainWindow::Seeked(const qint64 microseconds) {
|
||||||
@@ -2349,9 +2324,7 @@ void MainWindow::EditValue() {
|
|||||||
void MainWindow::AddFile() {
|
void MainWindow::AddFile() {
|
||||||
|
|
||||||
// Last used directory
|
// Last used directory
|
||||||
Settings s;
|
QString directory = settings_.value("add_media_path", QDir::currentPath()).toString();
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
QString directory = s.value("add_media_path", QDir::currentPath()).toString();
|
|
||||||
|
|
||||||
PlaylistParser parser(app_->tagreader_client(), app_->collection_backend());
|
PlaylistParser parser(app_->tagreader_client(), app_->collection_backend());
|
||||||
|
|
||||||
@@ -2361,7 +2334,7 @@ void MainWindow::AddFile() {
|
|||||||
if (filenames.isEmpty()) return;
|
if (filenames.isEmpty()) return;
|
||||||
|
|
||||||
// Save last used directory
|
// Save last used directory
|
||||||
s.setValue("add_media_path", filenames[0]);
|
settings_.setValue("add_media_path", filenames[0]);
|
||||||
|
|
||||||
// Convert to URLs
|
// Convert to URLs
|
||||||
QList<QUrl> urls;
|
QList<QUrl> urls;
|
||||||
@@ -2379,16 +2352,14 @@ void MainWindow::AddFile() {
|
|||||||
void MainWindow::AddFolder() {
|
void MainWindow::AddFolder() {
|
||||||
|
|
||||||
// Last used directory
|
// Last used directory
|
||||||
Settings s;
|
QString directory = settings_.value("add_folder_path", QDir::currentPath()).toString();
|
||||||
s.beginGroup(MainWindowSettings::kSettingsGroup);
|
|
||||||
QString directory = s.value("add_folder_path", QDir::currentPath()).toString();
|
|
||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
directory = QFileDialog::getExistingDirectory(this, tr("Add folder"), directory);
|
directory = QFileDialog::getExistingDirectory(this, tr("Add folder"), directory);
|
||||||
if (directory.isEmpty()) return;
|
if (directory.isEmpty()) return;
|
||||||
|
|
||||||
// Save last used directory
|
// Save last used directory
|
||||||
s.setValue("add_folder_path", directory);
|
settings_.setValue("add_folder_path", directory);
|
||||||
|
|
||||||
// Add media
|
// Add media
|
||||||
MimeData *mimedata = new MimeData;
|
MimeData *mimedata = new MimeData;
|
||||||
|
|||||||
@@ -43,7 +43,9 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QPixmap>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QSettings>
|
||||||
#include <QtEvents>
|
#include <QtEvents>
|
||||||
|
|
||||||
#include "includes/scoped_ptr.h"
|
#include "includes/scoped_ptr.h"
|
||||||
@@ -51,6 +53,7 @@
|
|||||||
#include "includes/lazy.h"
|
#include "includes/lazy.h"
|
||||||
#include "core/platforminterface.h"
|
#include "core/platforminterface.h"
|
||||||
#include "core/song.h"
|
#include "core/song.h"
|
||||||
|
#include "core/settings.h"
|
||||||
#include "core/commandlineoptions.h"
|
#include "core/commandlineoptions.h"
|
||||||
#include "tagreader/tagreaderclient.h"
|
#include "tagreader/tagreaderclient.h"
|
||||||
#include "osd/osdbase.h"
|
#include "osd/osdbase.h"
|
||||||
@@ -289,6 +292,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
|||||||
|
|
||||||
void CheckFullRescanRevisions();
|
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 GetCoverAutomatically();
|
||||||
|
|
||||||
void SetToggleScrobblingIcon(const bool value);
|
void SetToggleScrobblingIcon(const bool value);
|
||||||
@@ -384,6 +390,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
|
|||||||
|
|
||||||
QTimer *track_position_timer_;
|
QTimer *track_position_timer_;
|
||||||
QTimer *track_slider_timer_;
|
QTimer *track_slider_timer_;
|
||||||
|
Settings settings_;
|
||||||
|
|
||||||
bool keep_running_;
|
bool keep_running_;
|
||||||
bool playing_widget_;
|
bool playing_widget_;
|
||||||
|
|||||||
@@ -805,19 +805,19 @@ bool Song::lyrics_supported() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Song::albumartistsort_supported() const {
|
bool Song::albumartistsort_supported() const {
|
||||||
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::OggOpus || d->filetype_ == FileType::MPEG;
|
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::MPEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::albumsort_supported() const {
|
bool Song::albumsort_supported() const {
|
||||||
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::OggOpus || d->filetype_ == FileType::MPEG;
|
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::MPEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::artistsort_supported() const {
|
bool Song::artistsort_supported() const {
|
||||||
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::OggOpus || d->filetype_ == FileType::MPEG;
|
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::MPEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::composersort_supported() const {
|
bool Song::composersort_supported() const {
|
||||||
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::OggOpus || d->filetype_ == FileType::MPEG;
|
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::MPEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::performersort_supported() const {
|
bool Song::performersort_supported() const {
|
||||||
@@ -826,7 +826,7 @@ bool Song::performersort_supported() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Song::titlesort_supported() const {
|
bool Song::titlesort_supported() const {
|
||||||
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::OggOpus || d->filetype_ == FileType::MPEG;
|
return d->filetype_ == FileType::FLAC || d->filetype_ == FileType::OggFlac || d->filetype_ == FileType::OggVorbis || d->filetype_ == FileType::MPEG;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Song::save_embedded_cover_supported(const FileType filetype) {
|
bool Song::save_embedded_cover_supported(const FileType filetype) {
|
||||||
@@ -1668,24 +1668,12 @@ void Song::InitArtManual() {
|
|||||||
void Song::InitArtAutomatic() {
|
void Song::InitArtAutomatic() {
|
||||||
|
|
||||||
if (d->art_automatic_.isEmpty() && d->source_ == Source::LocalFile && d->url_.isLocalFile()) {
|
if (d->art_automatic_.isEmpty() && d->source_ == Source::LocalFile && d->url_.isLocalFile()) {
|
||||||
const QFileInfo fileinfo(d->url_.toLocalFile());
|
// Pick the first image file in the album directory.
|
||||||
const QDir dir(fileinfo.path());
|
QFileInfo file(d->url_.toLocalFile());
|
||||||
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);
|
QDir dir(file.path());
|
||||||
QString best_cover_file;
|
QStringList files = dir.entryList(QStringList() << u"*.jpg"_s << u"*.png"_s << u"*.gif"_s << u"*.jpeg"_s, QDir::Files|QDir::Readable, QDir::Name);
|
||||||
for (const QString &cover_file : cover_files) {
|
if (files.count() > 0) {
|
||||||
if (cover_file.contains("back"_L1, Qt::CaseInsensitive)) {
|
d->art_automatic_ = QUrl::fromLocalFile(file.path() + QDir::separator() + files.first());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,9 +98,6 @@ SongLoader::SongLoader(const SharedPtr<UrlHandlers> url_handlers,
|
|||||||
|
|
||||||
QObject::connect(timeout_timer_, &QTimer::timeout, this, &SongLoader::Timeout);
|
QObject::connect(timeout_timer_, &QTimer::timeout, this, &SongLoader::Timeout);
|
||||||
|
|
||||||
QObject::connect(playlist_parser_, &PlaylistParser::Error, this, &SongLoader::ParserError);
|
|
||||||
QObject::connect(cue_parser_, &CueParser::Error, this, &SongLoader::ParserError);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SongLoader::~SongLoader() {
|
SongLoader::~SongLoader() {
|
||||||
@@ -109,10 +106,6 @@ SongLoader::~SongLoader() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongLoader::ParserError(const QString &error) {
|
|
||||||
errors_ << error;
|
|
||||||
}
|
|
||||||
|
|
||||||
SongLoader::Result SongLoader::Load(const QUrl &url) {
|
SongLoader::Result SongLoader::Load(const QUrl &url) {
|
||||||
|
|
||||||
if (url.isEmpty()) return Result::Error;
|
if (url.isEmpty()) return Result::Error;
|
||||||
@@ -294,7 +287,6 @@ SongLoader::Result SongLoader::LoadLocalAsync(const QString &filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parser) { // It's a playlist!
|
if (parser) { // It's a playlist!
|
||||||
QObject::connect(parser, &ParserBase::Error, this, &SongLoader::ParserError, static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection));
|
|
||||||
qLog(Debug) << "Parsing using" << parser->name();
|
qLog(Debug) << "Parsing using" << parser->name();
|
||||||
LoadPlaylist(parser, filename);
|
LoadPlaylist(parser, filename);
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
@@ -714,10 +706,6 @@ void SongLoader::MagicReady() {
|
|||||||
StopTypefindAsync(true);
|
StopTypefindAsync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser_) {
|
|
||||||
QObject::connect(parser_, &ParserBase::Error, this, &SongLoader::ParserError, static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection));
|
|
||||||
}
|
|
||||||
|
|
||||||
state_ = State::WaitingForData;
|
state_ = State::WaitingForData;
|
||||||
|
|
||||||
if (!IsPipelinePlaying()) {
|
if (!IsPipelinePlaying()) {
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ class SongLoader : public QObject {
|
|||||||
void ScheduleTimeout();
|
void ScheduleTimeout();
|
||||||
void Timeout();
|
void Timeout();
|
||||||
void StopTypefind();
|
void StopTypefind();
|
||||||
void ParserError(const QString &error);
|
|
||||||
|
|
||||||
#ifdef HAVE_AUDIOCD
|
#ifdef HAVE_AUDIOCD
|
||||||
void AudioCDTracksLoadErrorSlot(const QString &error);
|
void AudioCDTracksLoadErrorSlot(const QString &error);
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
|
|||||||
audiobin_(nullptr),
|
audiobin_(nullptr),
|
||||||
audiosink_(nullptr),
|
audiosink_(nullptr),
|
||||||
audioqueue_(nullptr),
|
audioqueue_(nullptr),
|
||||||
|
audioqueueconverter_(nullptr),
|
||||||
volume_(nullptr),
|
volume_(nullptr),
|
||||||
volume_sw_(nullptr),
|
volume_sw_(nullptr),
|
||||||
volume_fading_(nullptr),
|
volume_fading_(nullptr),
|
||||||
@@ -186,7 +187,6 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
|
|||||||
equalizer_(nullptr),
|
equalizer_(nullptr),
|
||||||
equalizer_preamp_(nullptr),
|
equalizer_preamp_(nullptr),
|
||||||
eventprobe_(nullptr),
|
eventprobe_(nullptr),
|
||||||
bufferprobe_(nullptr),
|
|
||||||
logged_unsupported_analyzer_format_(false),
|
logged_unsupported_analyzer_format_(false),
|
||||||
about_to_finish_(false),
|
about_to_finish_(false),
|
||||||
finish_requested_(false),
|
finish_requested_(false),
|
||||||
@@ -436,7 +436,7 @@ void GstEnginePipeline::Disconnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_probe_cb_id_.has_value()) {
|
if (buffer_probe_cb_id_.has_value()) {
|
||||||
GstPad *pad = gst_element_get_static_pad(bufferprobe_, "src");
|
GstPad *pad = gst_element_get_static_pad(audioqueueconverter_, "src");
|
||||||
if (pad) {
|
if (pad) {
|
||||||
gst_pad_remove_probe(pad, buffer_probe_cb_id_.value());
|
gst_pad_remove_probe(pad, buffer_probe_cb_id_.value());
|
||||||
gst_object_unref(pad);
|
gst_object_unref(pad);
|
||||||
@@ -674,13 +674,8 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GstElement *audioqueueconverter = CreateElement(u"audioconvert"_s, u"audioqueueconverter"_s, audiobin_, error);
|
audioqueueconverter_ = CreateElement(u"audioconvert"_s, u"audioqueueconverter"_s, audiobin_, error);
|
||||||
if (!audioqueueconverter) {
|
if (!audioqueueconverter_) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GstElement *audioqueueresampler = CreateElement(u"audioresample"_s, u"audioqueueresampler"_s, audiobin_, error);
|
|
||||||
if (!audioqueueresampler) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,11 +684,6 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GstElement *audiosinkresampler = CreateElement(u"audioresample"_s, u"audiosinkresampler"_s, audiobin_, error);
|
|
||||||
if (!audiosinkresampler) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the volume element if it's enabled.
|
// Create the volume element if it's enabled.
|
||||||
if (volume_enabled_ && !volume_) {
|
if (volume_enabled_ && !volume_) {
|
||||||
volume_sw_ = CreateElement(u"volume"_s, u"volume_sw"_s, audiobin_, error);
|
volume_sw_ = CreateElement(u"volume"_s, u"volume_sw"_s, audiobin_, error);
|
||||||
@@ -771,8 +761,7 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventprobe_ = audioqueueconverter;
|
eventprobe_ = audioqueueconverter_;
|
||||||
bufferprobe_ = audioqueueconverter;
|
|
||||||
|
|
||||||
// Create the replaygain elements if it's enabled.
|
// Create the replaygain elements if it's enabled.
|
||||||
GstElement *rgvolume = nullptr;
|
GstElement *rgvolume = nullptr;
|
||||||
@@ -858,17 +847,12 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
|
|
||||||
// Link all elements
|
// Link all elements
|
||||||
|
|
||||||
if (!gst_element_link(audioqueue_, audioqueueconverter)) {
|
if (!gst_element_link(audioqueue_, audioqueueconverter_)) {
|
||||||
error = u"Failed to link audio queue to audio queue converter."_s;
|
error = u"Failed to link audio queue to audio queue converter."_s;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_element_link(audioqueueconverter, audioqueueresampler)) {
|
GstElement *element_link = audioqueueconverter_; // The next element to link from.
|
||||||
error = u"Failed to link audio queue converter to audio queue resampler."_s;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GstElement *element_link = audioqueueresampler; // The next element to link from.
|
|
||||||
|
|
||||||
// Link replaygain elements if enabled.
|
// Link replaygain elements if enabled.
|
||||||
if (rg_enabled_ && rgvolume && rglimiter && rgconverter) {
|
if (rg_enabled_ && rgvolume && rglimiter && rgconverter) {
|
||||||
@@ -944,11 +928,6 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_element_link(audiosinkconverter, audiosinkresampler)) {
|
|
||||||
error = "Failed to link audio sink converter to audio sink resampler."_L1;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
|
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
|
||||||
if (!caps) {
|
if (!caps) {
|
||||||
@@ -959,16 +938,16 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
|
|||||||
qLog(Debug) << "Setting channels to" << channels_;
|
qLog(Debug) << "Setting channels to" << channels_;
|
||||||
gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels_, nullptr);
|
gst_caps_set_simple(caps, "channels", G_TYPE_INT, channels_, nullptr);
|
||||||
}
|
}
|
||||||
const bool link_filtered_result = gst_element_link_filtered(audiosinkresampler, audiosink_, caps);
|
const bool link_filtered_result = gst_element_link_filtered(audiosinkconverter, audiosink_, caps);
|
||||||
gst_caps_unref(caps);
|
gst_caps_unref(caps);
|
||||||
if (!link_filtered_result) {
|
if (!link_filtered_result) {
|
||||||
error = "Failed to link audio sink resampler to audio sink with filter for "_L1 + output_;
|
error = "Failed to link audio sink converter to audio sink with filter for "_L1 + output_;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Add probes and handlers.
|
{ // Add probes and handlers.
|
||||||
GstPad *pad = gst_element_get_static_pad(bufferprobe_, "src");
|
GstPad *pad = gst_element_get_static_pad(audioqueueconverter_, "src");
|
||||||
if (pad) {
|
if (pad) {
|
||||||
buffer_probe_cb_id_ = gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, BufferProbeCallback, this, nullptr);
|
buffer_probe_cb_id_ = gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, BufferProbeCallback, this, nullptr);
|
||||||
gst_object_unref(pad);
|
gst_object_unref(pad);
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ class GstEnginePipeline : public QObject {
|
|||||||
GstElement *audiobin_;
|
GstElement *audiobin_;
|
||||||
GstElement *audiosink_;
|
GstElement *audiosink_;
|
||||||
GstElement *audioqueue_;
|
GstElement *audioqueue_;
|
||||||
|
GstElement *audioqueueconverter_;
|
||||||
GstElement *volume_;
|
GstElement *volume_;
|
||||||
GstElement *volume_sw_;
|
GstElement *volume_sw_;
|
||||||
GstElement *volume_fading_;
|
GstElement *volume_fading_;
|
||||||
@@ -363,7 +364,6 @@ class GstEnginePipeline : public QObject {
|
|||||||
GstElement *equalizer_;
|
GstElement *equalizer_;
|
||||||
GstElement *equalizer_preamp_;
|
GstElement *equalizer_preamp_;
|
||||||
GstElement *eventprobe_;
|
GstElement *eventprobe_;
|
||||||
GstElement *bufferprobe_;
|
|
||||||
|
|
||||||
std::optional<gulong> upstream_events_probe_cb_id_;
|
std::optional<gulong> upstream_events_probe_cb_id_;
|
||||||
std::optional<gulong> buffer_probe_cb_id_;
|
std::optional<gulong> buffer_probe_cb_id_;
|
||||||
|
|||||||
@@ -29,17 +29,13 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QStandardPaths>
|
#include <QSettings>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QSpacerItem>
|
|
||||||
#include <QtEvents>
|
#include <QtEvents>
|
||||||
|
|
||||||
#include "constants/appearancesettings.h"
|
|
||||||
#include "constants/filefilterconstants.h"
|
|
||||||
#include "includes/shared_ptr.h"
|
#include "includes/shared_ptr.h"
|
||||||
#include "core/deletefiles.h"
|
#include "core/deletefiles.h"
|
||||||
#include "core/filesystemmusicstorage.h"
|
#include "core/filesystemmusicstorage.h"
|
||||||
@@ -49,11 +45,10 @@
|
|||||||
#include "dialogs/deleteconfirmationdialog.h"
|
#include "dialogs/deleteconfirmationdialog.h"
|
||||||
#include "fileview.h"
|
#include "fileview.h"
|
||||||
#include "fileviewlist.h"
|
#include "fileviewlist.h"
|
||||||
#include "fileviewtree.h"
|
|
||||||
#include "fileviewtreemodel.h"
|
|
||||||
#include "fileviewtreeitem.h"
|
|
||||||
#include "ui_fileview.h"
|
#include "ui_fileview.h"
|
||||||
#include "organize/organizeerrordialog.h"
|
#include "organize/organizeerrordialog.h"
|
||||||
|
#include "constants/appearancesettings.h"
|
||||||
|
#include "constants/filefilterconstants.h"
|
||||||
|
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
@@ -62,12 +57,9 @@ FileView::FileView(QWidget *parent)
|
|||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
ui_(new Ui_FileView),
|
ui_(new Ui_FileView),
|
||||||
model_(nullptr),
|
model_(nullptr),
|
||||||
tree_model_(nullptr),
|
|
||||||
undo_stack_(new QUndoStack(this)),
|
undo_stack_(new QUndoStack(this)),
|
||||||
task_manager_(nullptr),
|
task_manager_(nullptr),
|
||||||
storage_(new FilesystemMusicStorage(Song::Source::LocalFile, u"/"_s)),
|
storage_(new FilesystemMusicStorage(Song::Source::LocalFile, u"/"_s)) {
|
||||||
tree_view_active_(false),
|
|
||||||
view_mode_spacer_(nullptr) {
|
|
||||||
|
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
|
|
||||||
@@ -76,14 +68,12 @@ FileView::FileView(QWidget *parent)
|
|||||||
ui_->forward->setIcon(IconLoader::Load(u"go-next"_s));
|
ui_->forward->setIcon(IconLoader::Load(u"go-next"_s));
|
||||||
ui_->home->setIcon(IconLoader::Load(u"go-home"_s));
|
ui_->home->setIcon(IconLoader::Load(u"go-home"_s));
|
||||||
ui_->up->setIcon(IconLoader::Load(u"go-up"_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_->back, &QToolButton::clicked, undo_stack_, &QUndoStack::undo);
|
||||||
QObject::connect(ui_->forward, &QToolButton::clicked, undo_stack_, &QUndoStack::redo);
|
QObject::connect(ui_->forward, &QToolButton::clicked, undo_stack_, &QUndoStack::redo);
|
||||||
QObject::connect(ui_->home, &QToolButton::clicked, this, &FileView::FileHome);
|
QObject::connect(ui_->home, &QToolButton::clicked, this, &FileView::FileHome);
|
||||||
QObject::connect(ui_->up, &QToolButton::clicked, this, &FileView::FileUp);
|
QObject::connect(ui_->up, &QToolButton::clicked, this, &FileView::FileUp);
|
||||||
QObject::connect(ui_->path, &QLineEdit::textChanged, this, &FileView::ChangeFilePath);
|
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::canUndoChanged, ui_->back, &FileView::setEnabled);
|
||||||
QObject::connect(undo_stack_, &QUndoStack::canRedoChanged, ui_->forward, &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::Delete, this, &FileView::Delete);
|
||||||
QObject::connect(ui_->list, &FileViewList::EditTags, this, &FileView::EditTags);
|
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);
|
QString filter = QLatin1String(kFileFilter);
|
||||||
filter_list_ << filter.split(u' ');
|
filter_list_ << filter.split(u' ');
|
||||||
|
|
||||||
@@ -135,19 +109,6 @@ void FileView::ReloadSettings() {
|
|||||||
ui_->forward->setIconSize(QSize(iconsize, iconsize));
|
ui_->forward->setIconSize(QSize(iconsize, iconsize));
|
||||||
ui_->home->setIconSize(QSize(iconsize, iconsize));
|
ui_->home->setIconSize(QSize(iconsize, iconsize));
|
||||||
ui_->up->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) {
|
void FileView::ItemActivated(const QModelIndex &idx) {
|
||||||
// Only handle activation for list view (not tree view)
|
if (model_->isDir(idx))
|
||||||
if (!tree_view_active_ && model_->isDir(idx)) {
|
|
||||||
ChangeFilePath(model_->filePath(idx));
|
ChangeFilePath(model_->filePath(idx));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileView::ItemDoubleClick(const QModelIndex &idx) {
|
void FileView::ItemDoubleClick(const QModelIndex &idx) {
|
||||||
|
|
||||||
QString file_path;
|
if (model_->isDir(idx)) {
|
||||||
bool is_file = false;
|
return;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add file to playlist if it's a valid file
|
QString file_path = model_->filePath(idx);
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
model_->setNameFilterDisables(false);
|
||||||
|
|
||||||
ui_->list->setModel(model_);
|
ui_->list->setModel(model_);
|
||||||
|
|
||||||
// Create tree model
|
|
||||||
tree_model_ = new FileViewTreeModel(this);
|
|
||||||
tree_model_->SetNameFilters(filter_list_);
|
|
||||||
|
|
||||||
SetupTreeView();
|
|
||||||
|
|
||||||
ChangeFilePathWithoutUndo(QDir::homePath());
|
ChangeFilePathWithoutUndo(QDir::homePath());
|
||||||
|
|
||||||
if (!lazy_set_path_.isEmpty()) ChangeFilePathWithoutUndo(lazy_set_path_);
|
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) {
|
void FileView::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|
||||||
switch (e->key()) {
|
switch (e->key()) {
|
||||||
|
|||||||
@@ -40,12 +40,10 @@ class QFileIconProvider;
|
|||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
class QSpacerItem;
|
|
||||||
|
|
||||||
class MusicStorage;
|
class MusicStorage;
|
||||||
class TaskManager;
|
class TaskManager;
|
||||||
class Ui_FileView;
|
class Ui_FileView;
|
||||||
class FileViewTreeModel;
|
|
||||||
|
|
||||||
class FileView : public QWidget {
|
class FileView : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -78,22 +76,12 @@ class FileView : public QWidget {
|
|||||||
void ChangeFilePath(const QString &new_path);
|
void ChangeFilePath(const QString &new_path);
|
||||||
void ItemActivated(const QModelIndex &idx);
|
void ItemActivated(const QModelIndex &idx);
|
||||||
void ItemDoubleClick(const QModelIndex &idx);
|
void ItemDoubleClick(const QModelIndex &idx);
|
||||||
void ToggleViewMode();
|
|
||||||
|
|
||||||
void Delete(const QStringList &filenames);
|
void Delete(const QStringList &filenames);
|
||||||
void DeleteFinished(const SongList &songs_with_errors);
|
void DeleteFinished(const SongList &songs_with_errors);
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void AddTreeRootPath(const QString &path);
|
|
||||||
void RemoveTreeRootPath(const QString &path);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ChangeFilePathWithoutUndo(const QString &new_path);
|
void ChangeFilePathWithoutUndo(const QString &new_path);
|
||||||
void SetupTreeView();
|
|
||||||
void SaveTreeRootPaths();
|
|
||||||
void AddRootButtonClicked();
|
|
||||||
void RemoveRootButtonClicked();
|
|
||||||
void UpdateViewModeUI();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class UndoCommand : public QUndoCommand {
|
class UndoCommand : public QUndoCommand {
|
||||||
@@ -122,21 +110,16 @@ class FileView : public QWidget {
|
|||||||
Ui_FileView *ui_;
|
Ui_FileView *ui_;
|
||||||
|
|
||||||
QFileSystemModel *model_;
|
QFileSystemModel *model_;
|
||||||
FileViewTreeModel *tree_model_;
|
|
||||||
QUndoStack *undo_stack_;
|
QUndoStack *undo_stack_;
|
||||||
|
|
||||||
SharedPtr<TaskManager> task_manager_;
|
SharedPtr<TaskManager> task_manager_;
|
||||||
SharedPtr<MusicStorage> storage_;
|
SharedPtr<MusicStorage> storage_;
|
||||||
|
|
||||||
QString lazy_set_path_;
|
QString lazy_set_path_;
|
||||||
QStringList tree_root_paths_;
|
|
||||||
|
|
||||||
QStringList filter_list_;
|
QStringList filter_list_;
|
||||||
|
|
||||||
ScopedPtr<QFileIconProvider> file_icon_provider_;
|
ScopedPtr<QFileIconProvider> file_icon_provider_;
|
||||||
|
|
||||||
bool tree_view_active_;
|
|
||||||
QSpacerItem *view_mode_spacer_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILEVIEW_H
|
#endif // FILEVIEW_H
|
||||||
|
|||||||
@@ -95,143 +95,28 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="path"/>
|
<widget class="QLineEdit" name="path"/>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QStackedWidget" name="view_stack">
|
<widget class="FileViewList" name="list">
|
||||||
<property name="currentIndex">
|
<property name="dragEnabled">
|
||||||
<number>0</number>
|
<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>
|
</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>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -242,11 +127,6 @@
|
|||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header>fileview/fileviewlist.h</header>
|
<header>fileview/fileviewlist.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>FileViewTree</class>
|
|
||||||
<extends>QTreeView</extends>
|
|
||||||
<header>fileview/fileviewtree.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ MimeData *FileViewList::MimeDataFromSelection() const {
|
|||||||
|
|
||||||
const QStringList filenames = FilenamesFromSelection();
|
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.size() == 1 && QFileInfo(filenames.first()).isDir()) {
|
||||||
if (filenames.first().length() > 20) {
|
if (filenames.first().length() > 20) {
|
||||||
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
|
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
|
||||||
@@ -108,7 +108,7 @@ MimeData *FileViewList::MimeDataFromSelection() const {
|
|||||||
mimedata->name_for_new_playlist_ = filenames.first();
|
mimedata->name_for_new_playlist_ = filenames.first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, use the current root path
|
// otherwise, use the current root path
|
||||||
else {
|
else {
|
||||||
QString path = qobject_cast<QFileSystemModel*>(model())->rootPath();
|
QString path = qobject_cast<QFileSystemModel*>(model())->rootPath();
|
||||||
if (path.length() > 20) {
|
if (path.length() > 20) {
|
||||||
@@ -196,11 +196,11 @@ void FileViewList::mousePressEvent(QMouseEvent *e) {
|
|||||||
case Qt::XButton2:
|
case Qt::XButton2:
|
||||||
Q_EMIT Forward();
|
Q_EMIT Forward();
|
||||||
break;
|
break;
|
||||||
// Enqueue to playlist with middleClick
|
// enqueue to playlist with middleClick
|
||||||
case Qt::MiddleButton:{
|
case Qt::MiddleButton:{
|
||||||
QListView::mousePressEvent(e);
|
QListView::mousePressEvent(e);
|
||||||
|
|
||||||
// We need to update the menu selection
|
// we need to update the menu selection
|
||||||
menu_selection_ = selectionModel()->selection();
|
menu_selection_ = selectionModel()->selection();
|
||||||
|
|
||||||
MimeData *mimedata = new MimeData;
|
MimeData *mimedata = new MimeData;
|
||||||
|
|||||||
@@ -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());
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
@@ -32,7 +32,6 @@
|
|||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/settings.h"
|
|
||||||
|
|
||||||
#include "globalshortcutsmanager.h"
|
#include "globalshortcutsmanager.h"
|
||||||
#include "globalshortcutsbackend.h"
|
#include "globalshortcutsbackend.h"
|
||||||
@@ -59,32 +58,29 @@ using namespace Qt::Literals::StringLiterals;
|
|||||||
|
|
||||||
GlobalShortcutsManager::GlobalShortcutsManager(QWidget *parent) : QWidget(parent) {
|
GlobalShortcutsManager::GlobalShortcutsManager(QWidget *parent) : QWidget(parent) {
|
||||||
|
|
||||||
Settings s;
|
settings_.beginGroup(GlobalShortcutsSettings::kSettingsGroup);
|
||||||
s.beginGroup(GlobalShortcutsSettings::kSettingsGroup);
|
|
||||||
|
|
||||||
// Create actions
|
// Create actions
|
||||||
AddShortcut(s, u"play"_s, tr("Play"), std::bind(&GlobalShortcutsManager::Play, this));
|
AddShortcut(u"play"_s, tr("Play"), std::bind(&GlobalShortcutsManager::Play, this));
|
||||||
AddShortcut(s, u"pause"_s, tr("Pause"), std::bind(&GlobalShortcutsManager::Pause, this));
|
AddShortcut(u"pause"_s, tr("Pause"), std::bind(&GlobalShortcutsManager::Pause, this));
|
||||||
AddShortcut(s, u"play_pause"_s, tr("Play/Pause"), std::bind(&GlobalShortcutsManager::PlayPause, this), QKeySequence(Qt::Key_MediaPlay));
|
AddShortcut(u"play_pause"_s, tr("Play/Pause"), std::bind(&GlobalShortcutsManager::PlayPause, this), QKeySequence(Qt::Key_MediaPlay));
|
||||||
AddShortcut(s, u"stop"_s, tr("Stop"), std::bind(&GlobalShortcutsManager::Stop, this), QKeySequence(Qt::Key_MediaStop));
|
AddShortcut(u"stop"_s, tr("Stop"), std::bind(&GlobalShortcutsManager::Stop, this), QKeySequence(Qt::Key_MediaStop));
|
||||||
AddShortcut(s, u"stop_after"_s, tr("Stop playing after current track"), std::bind(&GlobalShortcutsManager::StopAfter, this));
|
AddShortcut(u"stop_after"_s, tr("Stop playing after current track"), std::bind(&GlobalShortcutsManager::StopAfter, this));
|
||||||
AddShortcut(s, u"next_track"_s, tr("Next track"), std::bind(&GlobalShortcutsManager::Next, this), QKeySequence(Qt::Key_MediaNext));
|
AddShortcut(u"next_track"_s, tr("Next track"), std::bind(&GlobalShortcutsManager::Next, this), QKeySequence(Qt::Key_MediaNext));
|
||||||
AddShortcut(s, u"prev_track"_s, tr("Previous track"), std::bind(&GlobalShortcutsManager::Previous, this), QKeySequence(Qt::Key_MediaPrevious));
|
AddShortcut(u"prev_track"_s, tr("Previous track"), std::bind(&GlobalShortcutsManager::Previous, this), QKeySequence(Qt::Key_MediaPrevious));
|
||||||
AddShortcut(s, u"restart_or_prev_track"_s, tr("Restart or previous track"), std::bind(&GlobalShortcutsManager::RestartOrPrevious, this));
|
AddShortcut(u"restart_or_prev_track"_s, tr("Restart or previous track"), std::bind(&GlobalShortcutsManager::RestartOrPrevious, this));
|
||||||
AddShortcut(s, u"inc_volume"_s, tr("Increase volume"), std::bind(&GlobalShortcutsManager::IncVolume, this));
|
AddShortcut(u"inc_volume"_s, tr("Increase volume"), std::bind(&GlobalShortcutsManager::IncVolume, this));
|
||||||
AddShortcut(s, u"dec_volume"_s, tr("Decrease volume"), std::bind(&GlobalShortcutsManager::DecVolume, this));
|
AddShortcut(u"dec_volume"_s, tr("Decrease volume"), std::bind(&GlobalShortcutsManager::DecVolume, this));
|
||||||
AddShortcut(s, u"mute"_s, tr("Mute"), std::bind(&GlobalShortcutsManager::Mute, this));
|
AddShortcut(u"mute"_s, tr("Mute"), std::bind(&GlobalShortcutsManager::Mute, this));
|
||||||
AddShortcut(s, u"seek_forward"_s, tr("Seek forward"), std::bind(&GlobalShortcutsManager::SeekForward, this));
|
AddShortcut(u"seek_forward"_s, tr("Seek forward"), std::bind(&GlobalShortcutsManager::SeekForward, this));
|
||||||
AddShortcut(s, u"seek_backward"_s, tr("Seek backward"), std::bind(&GlobalShortcutsManager::SeekBackward, this));
|
AddShortcut(u"seek_backward"_s, tr("Seek backward"), std::bind(&GlobalShortcutsManager::SeekBackward, this));
|
||||||
AddShortcut(s, u"show_hide"_s, tr("Show/Hide"), std::bind(&GlobalShortcutsManager::ShowHide, this));
|
AddShortcut(u"show_hide"_s, tr("Show/Hide"), std::bind(&GlobalShortcutsManager::ShowHide, this));
|
||||||
AddShortcut(s, u"show_osd"_s, tr("Show OSD"), std::bind(&GlobalShortcutsManager::ShowOSD, this));
|
AddShortcut(u"show_osd"_s, tr("Show OSD"), std::bind(&GlobalShortcutsManager::ShowOSD, this));
|
||||||
AddShortcut(s, u"toggle_pretty_osd"_s, tr("Toggle Pretty OSD"), std::bind(&GlobalShortcutsManager::TogglePrettyOSD, this)); // Toggling possible only for pretty OSD
|
AddShortcut(u"toggle_pretty_osd"_s, tr("Toggle Pretty OSD"), std::bind(&GlobalShortcutsManager::TogglePrettyOSD, this)); // Toggling possible only for pretty OSD
|
||||||
AddShortcut(s, u"shuffle_mode"_s, tr("Change shuffle mode"), std::bind(&GlobalShortcutsManager::CycleShuffleMode, this));
|
AddShortcut(u"shuffle_mode"_s, tr("Change shuffle mode"), std::bind(&GlobalShortcutsManager::CycleShuffleMode, this));
|
||||||
AddShortcut(s, u"repeat_mode"_s, tr("Change repeat mode"), std::bind(&GlobalShortcutsManager::CycleRepeatMode, this));
|
AddShortcut(u"repeat_mode"_s, tr("Change repeat mode"), std::bind(&GlobalShortcutsManager::CycleRepeatMode, this));
|
||||||
AddShortcut(s, u"toggle_scrobbling"_s, tr("Enable/disable scrobbling"), std::bind(&GlobalShortcutsManager::ToggleScrobbling, this));
|
AddShortcut(u"toggle_scrobbling"_s, tr("Enable/disable scrobbling"), std::bind(&GlobalShortcutsManager::ToggleScrobbling, this));
|
||||||
AddShortcut(s, u"love"_s, tr("Love"), std::bind(&GlobalShortcutsManager::Love, this));
|
AddShortcut(u"love"_s, tr("Love"), std::bind(&GlobalShortcutsManager::Love, this));
|
||||||
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
// Create backends - these do the actual shortcut registration
|
// Create backends - these do the actual shortcut registration
|
||||||
|
|
||||||
@@ -120,39 +116,35 @@ void GlobalShortcutsManager::ReloadSettings() {
|
|||||||
backends_enabled_ << GlobalShortcutsBackend::Type::Win;
|
backends_enabled_ << GlobalShortcutsBackend::Type::Win;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
|
||||||
Settings s;
|
|
||||||
s.beginGroup(GlobalShortcutsSettings::kSettingsGroup);
|
|
||||||
#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS
|
#ifdef HAVE_KGLOBALACCEL_GLOBALSHORTCUTS
|
||||||
if (s.value(GlobalShortcutsSettings::kUseKGlobalAccel, true).toBool()) {
|
if (settings_.value(GlobalShortcutsSettings::kUseKGlobalAccel, true).toBool()) {
|
||||||
backends_enabled_ << GlobalShortcutsBackend::Type::KGlobalAccel;
|
backends_enabled_ << GlobalShortcutsBackend::Type::KGlobalAccel;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
|
||||||
if (s.value(GlobalShortcutsSettings::kUseX11, false).toBool()) {
|
|
||||||
backends_enabled_ << GlobalShortcutsBackend::Type::X11;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
s.endGroup();
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_X11_GLOBALSHORTCUTS
|
||||||
|
if (settings_.value(GlobalShortcutsSettings::kUseX11, false).toBool()) {
|
||||||
|
backends_enabled_ << GlobalShortcutsBackend::Type::X11;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Unregister();
|
Unregister();
|
||||||
Register();
|
Register();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalShortcutsManager::AddShortcut(Settings &s, const QString &id, const QString &name, std::function<void()> signal, const QKeySequence &default_key) { // clazy:exclude=function-args-by-ref
|
void GlobalShortcutsManager::AddShortcut(const QString &id, const QString &name, std::function<void()> signal, const QKeySequence &default_key) { // clazy:exclude=function-args-by-ref
|
||||||
|
|
||||||
Shortcut shortcut = AddShortcut(s, id, name, default_key);
|
Shortcut shortcut = AddShortcut(id, name, default_key);
|
||||||
QObject::connect(shortcut.action, &QAction::triggered, this, signal);
|
QObject::connect(shortcut.action, &QAction::triggered, this, signal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalShortcutsManager::Shortcut GlobalShortcutsManager::AddShortcut(Settings &s, const QString &id, const QString &name, const QKeySequence &default_key) {
|
GlobalShortcutsManager::Shortcut GlobalShortcutsManager::AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key) {
|
||||||
|
|
||||||
Shortcut shortcut;
|
Shortcut shortcut;
|
||||||
shortcut.action = new QAction(name, this);
|
shortcut.action = new QAction(name, this);
|
||||||
QKeySequence key_sequence = QKeySequence::fromString(s.value(id, default_key.toString()).toString());
|
QKeySequence key_sequence = QKeySequence::fromString(settings_.value(id, default_key.toString()).toString());
|
||||||
shortcut.action->setShortcut(key_sequence);
|
shortcut.action->setShortcut(key_sequence);
|
||||||
shortcut.id = id;
|
shortcut.id = id;
|
||||||
shortcut.default_key = default_key;
|
shortcut.default_key = default_key;
|
||||||
|
|||||||
@@ -32,14 +32,15 @@
|
|||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "globalshortcutsbackend.h"
|
#include "globalshortcutsbackend.h"
|
||||||
|
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
class QShortcut;
|
class QShortcut;
|
||||||
class QAction;
|
class QAction;
|
||||||
|
|
||||||
class Settings;
|
|
||||||
|
|
||||||
class GlobalShortcutsManager : public QWidget {
|
class GlobalShortcutsManager : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -98,11 +99,12 @@ class GlobalShortcutsManager : public QWidget {
|
|||||||
void Love();
|
void Love();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddShortcut(Settings &s, const QString &id, const QString &name, std::function<void()> signal, const QKeySequence &default_key = QKeySequence(0));
|
void AddShortcut(const QString &id, const QString &name, std::function<void()> signal, const QKeySequence &default_key = QKeySequence(0));
|
||||||
Shortcut AddShortcut(Settings &s, const QString &id, const QString &name, const QKeySequence &default_key);
|
Shortcut AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<GlobalShortcutsBackend*> backends_;
|
QList<GlobalShortcutsBackend*> backends_;
|
||||||
|
Settings settings_;
|
||||||
QList<GlobalShortcutsBackend::Type> backends_enabled_;
|
QList<GlobalShortcutsBackend::Type> backends_enabled_;
|
||||||
QMap<QString, Shortcut> shortcuts_;
|
QMap<QString, Shortcut> shortcuts_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
|
|||||||
no_matches_font.setBold(true);
|
no_matches_font.setBold(true);
|
||||||
no_matches_label_->setFont(no_matches_font);
|
no_matches_label_->setFont(no_matches_font);
|
||||||
|
|
||||||
|
settings_.beginGroup(kSettingsGroup);
|
||||||
|
|
||||||
// Tab bar
|
// Tab bar
|
||||||
ui_->tab_bar->setExpanding(false);
|
ui_->tab_bar->setExpanding(false);
|
||||||
ui_->tab_bar->setMovable(true);
|
ui_->tab_bar->setMovable(true);
|
||||||
@@ -255,11 +257,7 @@ void PlaylistContainer::ReloadSettings() {
|
|||||||
ui_->redo->setIconSize(QSize(iconsize, iconsize));
|
ui_->redo->setIconSize(QSize(iconsize, iconsize));
|
||||||
ui_->search_field->setIconSize(iconsize);
|
ui_->search_field->setIconSize(iconsize);
|
||||||
|
|
||||||
s.beginGroup(kSettingsGroup);
|
bool playlist_clear = settings_.value("playlist_clear", true).toBool();
|
||||||
const bool playlist_clear = s.value("playlist_clear", true).toBool();
|
|
||||||
const bool show_toolbar = s.value("show_toolbar", true).toBool();
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
if (playlist_clear) {
|
if (playlist_clear) {
|
||||||
ui_->clear->show();
|
ui_->clear->show();
|
||||||
}
|
}
|
||||||
@@ -267,6 +265,7 @@ void PlaylistContainer::ReloadSettings() {
|
|||||||
ui_->clear->hide();
|
ui_->clear->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool show_toolbar = settings_.value("show_toolbar", true).toBool();
|
||||||
ui_->toolbar->setVisible(show_toolbar);
|
ui_->toolbar->setVisible(show_toolbar);
|
||||||
|
|
||||||
if (!show_toolbar) ui_->search_field->clear();
|
if (!show_toolbar) ui_->search_field->clear();
|
||||||
@@ -309,12 +308,7 @@ void PlaylistContainer::PlaylistAdded(const int id, const QString &name, const b
|
|||||||
ui_->tab_bar->InsertTab(id, index, name, favorite);
|
ui_->tab_bar->InsertTab(id, index, name, favorite);
|
||||||
|
|
||||||
// Are we start up, should we select this tab?
|
// Are we start up, should we select this tab?
|
||||||
Settings s;
|
if (starting_up_ && settings_.value("current_playlist", 1).toInt() == id) {
|
||||||
s.beginGroup(kSettingsGroup);
|
|
||||||
const int current_playlist = s.value("current_playlist", 1).toInt();
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
if (starting_up_ && current_playlist == id) {
|
|
||||||
starting_up_ = false;
|
starting_up_ = false;
|
||||||
ui_->tab_bar->set_current_id(id);
|
ui_->tab_bar->set_current_id(id);
|
||||||
}
|
}
|
||||||
@@ -353,14 +347,12 @@ void PlaylistContainer::NewPlaylist() { manager_->New(tr("Playlist")); }
|
|||||||
|
|
||||||
void PlaylistContainer::LoadPlaylist() {
|
void PlaylistContainer::LoadPlaylist() {
|
||||||
|
|
||||||
Settings s;
|
QString filename = settings_.value("last_load_playlist").toString();
|
||||||
s.beginGroup(kSettingsGroup);
|
|
||||||
QString filename = s.value("last_load_playlist").toString();
|
|
||||||
filename = QFileDialog::getOpenFileName(this, tr("Load playlist"), filename, manager_->parser()->filters(PlaylistParser::Type::Load));
|
filename = QFileDialog::getOpenFileName(this, tr("Load playlist"), filename, manager_->parser()->filters(PlaylistParser::Type::Load));
|
||||||
|
|
||||||
if (filename.isNull()) return;
|
if (filename.isNull()) return;
|
||||||
|
|
||||||
s.setValue("last_load_playlist", filename);
|
settings_.setValue("last_load_playlist", filename);
|
||||||
|
|
||||||
manager_->Load(filename);
|
manager_->Load(filename);
|
||||||
|
|
||||||
@@ -399,10 +391,7 @@ void PlaylistContainer::Save() {
|
|||||||
|
|
||||||
if (starting_up_) return;
|
if (starting_up_) return;
|
||||||
|
|
||||||
Settings s;
|
settings_.setValue("current_playlist", ui_->tab_bar->current_id());
|
||||||
s.beginGroup(kSettingsGroup);
|
|
||||||
s.setValue("current_playlist", ui_->tab_bar->current_id());
|
|
||||||
s.endGroup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class QTimeLine;
|
class QTimeLine;
|
||||||
@@ -44,6 +45,7 @@ class PlaylistView;
|
|||||||
class Ui_PlaylistContainer;
|
class Ui_PlaylistContainer;
|
||||||
|
|
||||||
#include "includes/shared_ptr.h"
|
#include "includes/shared_ptr.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
class PlaylistContainer : public QWidget {
|
class PlaylistContainer : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -116,6 +118,7 @@ class PlaylistContainer : public QWidget {
|
|||||||
QAction *redo_;
|
QAction *redo_;
|
||||||
Playlist *playlist_;
|
Playlist *playlist_;
|
||||||
|
|
||||||
|
Settings settings_;
|
||||||
bool starting_up_;
|
bool starting_up_;
|
||||||
|
|
||||||
bool tab_bar_visible_;
|
bool tab_bar_visible_;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
@@ -33,9 +34,12 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
#include <QScreen>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
#include "core/iconloader.h"
|
#include "core/iconloader.h"
|
||||||
#include "core/settingsprovider.h"
|
#include "core/settingsprovider.h"
|
||||||
|
#include "utilities/screenutils.h"
|
||||||
#include "playlistsequence.h"
|
#include "playlistsequence.h"
|
||||||
#include "ui_playlistsequence.h"
|
#include "ui_playlistsequence.h"
|
||||||
|
|
||||||
@@ -43,7 +47,14 @@ using namespace Qt::Literals::StringLiterals;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char kSettingsGroup[] = "PlaylistSequence";
|
constexpr char kSettingsGroup[] = "PlaylistSequence";
|
||||||
}
|
|
||||||
|
// Base icon size for reference resolution (1920x1080 at 1.0 scale)
|
||||||
|
constexpr int kBaseIconSize = 20;
|
||||||
|
constexpr int kReferenceWidth = 1920;
|
||||||
|
constexpr int kReferenceHeight = 1080;
|
||||||
|
constexpr qreal kReferenceDevicePixelRatio = 1.0;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
PlaylistSequence::PlaylistSequence(QWidget *parent, SettingsProvider *settings)
|
PlaylistSequence::PlaylistSequence(QWidget *parent, SettingsProvider *settings)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
@@ -60,9 +71,11 @@ PlaylistSequence::PlaylistSequence(QWidget *parent, SettingsProvider *settings)
|
|||||||
// Icons
|
// Icons
|
||||||
ui_->repeat->setIcon(AddDesaturatedIcon(IconLoader::Load(u"media-playlist-repeat"_s)));
|
ui_->repeat->setIcon(AddDesaturatedIcon(IconLoader::Load(u"media-playlist-repeat"_s)));
|
||||||
ui_->shuffle->setIcon(AddDesaturatedIcon(IconLoader::Load(u"media-playlist-shuffle"_s)));
|
ui_->shuffle->setIcon(AddDesaturatedIcon(IconLoader::Load(u"media-playlist-shuffle"_s)));
|
||||||
const int base_icon_size = static_cast<int>(fontMetrics().height() * 1.2);
|
|
||||||
ui_->repeat->setIconSize(QSize(base_icon_size, base_icon_size));
|
// Calculate icon size dynamically based on screen resolution, aspect ratio, and scaling
|
||||||
ui_->shuffle->setIconSize(QSize(base_icon_size, base_icon_size));
|
const int icon_size = CalculateIconSize();
|
||||||
|
ui_->repeat->setIconSize(QSize(icon_size, icon_size));
|
||||||
|
ui_->shuffle->setIconSize(QSize(icon_size, icon_size));
|
||||||
|
|
||||||
// Remove arrow indicators
|
// Remove arrow indicators
|
||||||
ui_->repeat->setStyleSheet(u"QToolButton::menu-indicator { image: none; }"_s);
|
ui_->repeat->setStyleSheet(u"QToolButton::menu-indicator { image: none; }"_s);
|
||||||
@@ -99,6 +112,48 @@ PlaylistSequence::~PlaylistSequence() {
|
|||||||
delete ui_;
|
delete ui_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PlaylistSequence::CalculateIconSize() {
|
||||||
|
|
||||||
|
// Get screen information for the widget
|
||||||
|
QScreen *screen = Utilities::GetScreen(this);
|
||||||
|
if (!screen) {
|
||||||
|
screen = QGuiApplication::primaryScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!screen) {
|
||||||
|
// Fallback to a reasonable default if no screen is available
|
||||||
|
return kBaseIconSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get screen properties
|
||||||
|
const QSize screen_size = screen->size();
|
||||||
|
const qreal device_pixel_ratio = screen->devicePixelRatio();
|
||||||
|
const int screen_width = screen_size.width();
|
||||||
|
const int screen_height = screen_size.height();
|
||||||
|
|
||||||
|
// Calculate scaling factors based on resolution
|
||||||
|
// Use the smaller dimension to handle both landscape and portrait orientations
|
||||||
|
const int min_dimension = std::min(screen_width, screen_height);
|
||||||
|
const int ref_min_dimension = std::min(kReferenceWidth, kReferenceHeight);
|
||||||
|
const qreal resolution_factor = static_cast<qreal>(min_dimension) / static_cast<qreal>(ref_min_dimension);
|
||||||
|
|
||||||
|
// Apply device pixel ratio (for high-DPI displays)
|
||||||
|
const qreal dpi_factor = device_pixel_ratio / kReferenceDevicePixelRatio;
|
||||||
|
|
||||||
|
// Calculate final icon size with combined scaling
|
||||||
|
// Formula: 50% from resolution scaling + 50% from DPI scaling + 50% base multiplier
|
||||||
|
// The 0.5 base ensures icons scale up appropriately across different displays
|
||||||
|
// Without it, icons would be too small on average displays
|
||||||
|
const qreal combined_factor = (resolution_factor * 0.5) + (dpi_factor * 0.5) + 0.5;
|
||||||
|
int calculated_size = static_cast<int>(kBaseIconSize * combined_factor);
|
||||||
|
|
||||||
|
// Clamp to reasonable bounds (minimum 16px, maximum 48px)
|
||||||
|
calculated_size = std::max(16, std::min(48, calculated_size));
|
||||||
|
|
||||||
|
return calculated_size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void PlaylistSequence::Load() {
|
void PlaylistSequence::Load() {
|
||||||
|
|
||||||
loading_ = true; // Stops these setter functions calling Save()
|
loading_ = true; // Stops these setter functions calling Save()
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class PlaylistSequence : public QWidget {
|
|||||||
private:
|
private:
|
||||||
void Load();
|
void Load();
|
||||||
void Save();
|
void Save();
|
||||||
|
int CalculateIconSize();
|
||||||
static QIcon AddDesaturatedIcon(const QIcon &icon);
|
static QIcon AddDesaturatedIcon(const QIcon &icon);
|
||||||
static QPixmap DesaturatedPixmap(const QPixmap &pixmap);
|
static QPixmap DesaturatedPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
#include <QLinearGradient>
|
#include <QLinearGradient>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QtEvents>
|
#include <QtEvents>
|
||||||
|
#include <QSettings>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
|
|
||||||
#include "includes/qt_blurimage.h"
|
#include "includes/qt_blurimage.h"
|
||||||
|
|||||||
@@ -80,13 +80,12 @@ void SongLoaderInserter::Load(Playlist *destination, const int row, const bool p
|
|||||||
songs_ << loader->songs();
|
songs_ << loader->songs();
|
||||||
playlist_name_ = loader->playlist_name();
|
playlist_name_ = loader->playlist_name();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// Always check for errors, even on success (e.g., playlist parsed but some songs failed to load)
|
const QStringList errors = loader->errors();
|
||||||
const QStringList errors = loader->errors();
|
for (const QString &error : errors) {
|
||||||
for (const QString &error : errors) {
|
Q_EMIT Error(error);
|
||||||
Q_EMIT Error(error);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete loader;
|
delete loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,13 +192,11 @@ void SongLoaderInserter::AsyncLoad() {
|
|||||||
const SongLoader::Result result = loader->LoadFilenamesBlocking();
|
const SongLoader::Result result = loader->LoadFilenamesBlocking();
|
||||||
task_manager_->SetTaskProgress(async_load_id, static_cast<quint64>(++async_progress));
|
task_manager_->SetTaskProgress(async_load_id, static_cast<quint64>(++async_progress));
|
||||||
|
|
||||||
// Always check for errors, even on success (e.g., playlist parsed but some songs failed to load)
|
|
||||||
const QStringList errors = loader->errors();
|
|
||||||
for (const QString &error : errors) {
|
|
||||||
Q_EMIT Error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == SongLoader::Result::Error) {
|
if (result == SongLoader::Result::Error) {
|
||||||
|
const QStringList errors = loader->errors();
|
||||||
|
for (const QString &error : errors) {
|
||||||
|
Q_EMIT Error(error);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,18 +112,10 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the file exists before trying to read it
|
|
||||||
if (!QFile::exists(filename)) {
|
|
||||||
qLog(Error) << "File does not exist:" << filename;
|
|
||||||
Q_EMIT Error(tr("File %1 does not exist").arg(filename));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tagreader_client_) {
|
if (tagreader_client_) {
|
||||||
const TagReaderResult result = tagreader_client_->ReadFileBlocking(filename, song);
|
const TagReaderResult result = tagreader_client_->ReadFileBlocking(filename, song);
|
||||||
if (!result.success()) {
|
if (!result.success()) {
|
||||||
qLog(Error) << "Could not read file" << filename << result.error_string();
|
qLog(Error) << "Could not read file" << filename << result.error_string();
|
||||||
Q_EMIT Error(tr("Could not read file %1: %2").arg(filename, result.error_string()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,22 +42,15 @@
|
|||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/networkaccessmanager.h"
|
#include "core/networkaccessmanager.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "constants/scrobblersettings.h"
|
|
||||||
|
|
||||||
#include "lastfmimport.h"
|
#include "lastfmimport.h"
|
||||||
|
|
||||||
#include "lastfmscrobbler.h"
|
#include "lastfmscrobbler.h"
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
using namespace ScrobblerSettings;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr int kRequestsDelay = 2000;
|
constexpr int kRequestsDelay = 2000;
|
||||||
constexpr int kMaxRetries = 5;
|
|
||||||
constexpr int kInitialBackoffMs = 5000;
|
|
||||||
constexpr int kMaxBackoffShift = 10; // Maximum shift value to prevent overflow
|
|
||||||
constexpr int kRetryHttpStatusCode1 = 500; // Internal Server Error
|
|
||||||
constexpr int kRetryHttpStatusCode2 = 503; // Service Unavailable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LastFMImport::LastFMImport(const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
LastFMImport::LastFMImport(const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||||
@@ -108,17 +101,14 @@ void LastFMImport::ReloadSettings() {
|
|||||||
Settings s;
|
Settings s;
|
||||||
s.beginGroup(LastFMScrobbler::kSettingsGroup);
|
s.beginGroup(LastFMScrobbler::kSettingsGroup);
|
||||||
username_ = s.value("username").toString();
|
username_ = s.value("username").toString();
|
||||||
api_key_ = s.value(ScrobblerSettings::kApiKey).toString();
|
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *LastFMImport::CreateRequest(const ParamList &request_params) {
|
QNetworkReply *LastFMImport::CreateRequest(const ParamList &request_params) {
|
||||||
|
|
||||||
const QString api_key = !api_key_.isEmpty() ? api_key_ : QLatin1String(LastFMScrobbler::kApiKey);
|
|
||||||
|
|
||||||
ParamList params = ParamList()
|
ParamList params = ParamList()
|
||||||
<< Param(u"api_key"_s, api_key)
|
<< Param(u"api_key"_s, QLatin1String(LastFMScrobbler::kApiKey))
|
||||||
<< Param(u"user"_s, username_)
|
<< Param(u"user"_s, username_)
|
||||||
<< Param(u"lang"_s, QLocale().name().left(2).toLower())
|
<< Param(u"lang"_s, QLocale().name().left(2).toLower())
|
||||||
<< Param(u"format"_s, u"json"_s)
|
<< Param(u"format"_s, u"json"_s)
|
||||||
@@ -244,11 +234,11 @@ void LastFMImport::SendGetRecentTracksRequest(GetRecentTracksRequest request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *reply = CreateRequest(params);
|
QNetworkReply *reply = CreateRequest(params);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { GetRecentTracksRequestFinished(reply, request); });
|
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { GetRecentTracksRequestFinished(reply, request.page); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, GetRecentTracksRequest request) {
|
void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, const int page) {
|
||||||
|
|
||||||
if (!replies_.contains(reply)) return;
|
if (!replies_.contains(reply)) return;
|
||||||
replies_.removeAll(reply);
|
replies_.removeAll(reply);
|
||||||
@@ -257,21 +247,10 @@ void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, GetRecen
|
|||||||
|
|
||||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||||
if (!json_object_result.success()) {
|
if (!json_object_result.success()) {
|
||||||
if (ShouldRetryRequest(json_object_result) && request.retry_count < kMaxRetries) {
|
|
||||||
const int delay_ms = CalculateBackoffDelay(request.retry_count);
|
|
||||||
LogRetryAttempt(json_object_result.http_status_code, request.retry_count, delay_ms);
|
|
||||||
QTimer::singleShot(delay_ms, this, [this, request]() {
|
|
||||||
GetRecentTracksRequest retry_request(request.page, request.retry_count + 1);
|
|
||||||
SendGetRecentTracksRequest(retry_request);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Error(json_object_result.error_message);
|
Error(json_object_result.error_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int page = request.page;
|
|
||||||
|
|
||||||
QJsonObject json_object = json_object_result.json_object;
|
QJsonObject json_object = json_object_result.json_object;
|
||||||
if (json_object.isEmpty()) {
|
if (json_object.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@@ -411,11 +390,11 @@ void LastFMImport::SendGetTopTracksRequest(GetTopTracksRequest request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *reply = CreateRequest(params);
|
QNetworkReply *reply = CreateRequest(params);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { GetTopTracksRequestFinished(reply, request); });
|
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, request]() { GetTopTracksRequestFinished(reply, request.page); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, GetTopTracksRequest request) {
|
void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, const int page) {
|
||||||
|
|
||||||
if (!replies_.contains(reply)) return;
|
if (!replies_.contains(reply)) return;
|
||||||
replies_.removeAll(reply);
|
replies_.removeAll(reply);
|
||||||
@@ -424,21 +403,10 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, GetTopTrack
|
|||||||
|
|
||||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
||||||
if (!json_object_result.success()) {
|
if (!json_object_result.success()) {
|
||||||
if (ShouldRetryRequest(json_object_result) && request.retry_count < kMaxRetries) {
|
|
||||||
const int delay_ms = CalculateBackoffDelay(request.retry_count);
|
|
||||||
LogRetryAttempt(json_object_result.http_status_code, request.retry_count, delay_ms);
|
|
||||||
QTimer::singleShot(delay_ms, this, [this, request]() {
|
|
||||||
GetTopTracksRequest retry_request(request.page, request.retry_count + 1);
|
|
||||||
SendGetTopTracksRequest(retry_request);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Error(json_object_result.error_message);
|
Error(json_object_result.error_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int page = request.page;
|
|
||||||
|
|
||||||
QJsonObject json_object = json_object_result.json_object;
|
QJsonObject json_object = json_object_result.json_object;
|
||||||
if (json_object.isEmpty()) {
|
if (json_object.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@@ -548,23 +516,6 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, GetTopTrack
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LastFMImport::ShouldRetryRequest(const JsonObjectResult &result) const {
|
|
||||||
return result.http_status_code == kRetryHttpStatusCode1 ||
|
|
||||||
result.http_status_code == kRetryHttpStatusCode2 ||
|
|
||||||
result.network_error == QNetworkReply::TemporaryNetworkFailureError;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LastFMImport::LogRetryAttempt(const int http_status_code, const int retry_count, const int delay_ms) const {
|
|
||||||
qLog(Warning) << "Last.fm request failed with status" << http_status_code
|
|
||||||
<< ", retrying in" << delay_ms << "ms (attempt"
|
|
||||||
<< (retry_count + 1) << "of" << kMaxRetries << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
int LastFMImport::CalculateBackoffDelay(const int retry_count) const {
|
|
||||||
const int safe_shift = std::min(retry_count, kMaxBackoffShift);
|
|
||||||
return kInitialBackoffMs * (1 << safe_shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LastFMImport::UpdateTotalCheck() {
|
void LastFMImport::UpdateTotalCheck() {
|
||||||
|
|
||||||
Q_EMIT UpdateTotal(lastplayed_total_, playcount_total_);
|
Q_EMIT UpdateTotal(lastplayed_total_, playcount_total_);
|
||||||
|
|||||||
@@ -60,14 +60,12 @@ class LastFMImport : public JsonBaseRequest {
|
|||||||
using ParamList = QList<Param>;
|
using ParamList = QList<Param>;
|
||||||
|
|
||||||
struct GetRecentTracksRequest {
|
struct GetRecentTracksRequest {
|
||||||
explicit GetRecentTracksRequest(const int _page, const int _retry_count = 0) : page(_page), retry_count(_retry_count) {}
|
explicit GetRecentTracksRequest(const int _page) : page(_page) {}
|
||||||
int page;
|
int page;
|
||||||
int retry_count;
|
|
||||||
};
|
};
|
||||||
struct GetTopTracksRequest {
|
struct GetTopTracksRequest {
|
||||||
explicit GetTopTracksRequest(const int _page, const int _retry_count = 0) : page(_page), retry_count(_retry_count) {}
|
explicit GetTopTracksRequest(const int _page) : page(_page) {}
|
||||||
int page;
|
int page;
|
||||||
int retry_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -80,10 +78,6 @@ class LastFMImport : public JsonBaseRequest {
|
|||||||
void SendGetRecentTracksRequest(GetRecentTracksRequest request);
|
void SendGetRecentTracksRequest(GetRecentTracksRequest request);
|
||||||
void SendGetTopTracksRequest(GetTopTracksRequest request);
|
void SendGetTopTracksRequest(GetTopTracksRequest request);
|
||||||
|
|
||||||
bool ShouldRetryRequest(const JsonObjectResult &result) const;
|
|
||||||
int CalculateBackoffDelay(const int retry_count) const;
|
|
||||||
void LogRetryAttempt(const int http_status_code, const int retry_count, const int delay_ms) const;
|
|
||||||
|
|
||||||
void Error(const QString &error, const QVariant &debug = QVariant()) override;
|
void Error(const QString &error, const QVariant &debug = QVariant()) override;
|
||||||
|
|
||||||
void UpdateTotalCheck();
|
void UpdateTotalCheck();
|
||||||
@@ -101,15 +95,14 @@ class LastFMImport : public JsonBaseRequest {
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void FlushRequests();
|
void FlushRequests();
|
||||||
void GetRecentTracksRequestFinished(QNetworkReply *reply, GetRecentTracksRequest request);
|
void GetRecentTracksRequestFinished(QNetworkReply *reply, const int page);
|
||||||
void GetTopTracksRequestFinished(QNetworkReply *reply, GetTopTracksRequest request);
|
void GetTopTracksRequestFinished(QNetworkReply *reply, const int page);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedPtr<NetworkAccessManager> network_;
|
SharedPtr<NetworkAccessManager> network_;
|
||||||
QTimer *timer_flush_requests_;
|
QTimer *timer_flush_requests_;
|
||||||
|
|
||||||
QString username_;
|
QString username_;
|
||||||
QString api_key_;
|
|
||||||
bool lastplayed_;
|
bool lastplayed_;
|
||||||
bool playcount_;
|
bool playcount_;
|
||||||
int playcount_total_;
|
int playcount_total_;
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ void LastFMScrobbler::ReloadSettings() {
|
|||||||
|
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
enabled_ = s.value(ScrobblerSettings::kEnabled, false).toBool();
|
enabled_ = s.value(ScrobblerSettings::kEnabled, false).toBool();
|
||||||
api_key_ = s.value(ScrobblerSettings::kApiKey).toString();
|
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ class LastFMScrobbler : public ScrobblerService {
|
|||||||
bool subscriber() const { return subscriber_; }
|
bool subscriber() const { return subscriber_; }
|
||||||
bool submitted() const override { return submitted_; }
|
bool submitted() const override { return submitted_; }
|
||||||
QString username() const { return username_; }
|
QString username() const { return username_; }
|
||||||
QString api_key() const { return api_key_; }
|
|
||||||
|
|
||||||
void Authenticate();
|
void Authenticate();
|
||||||
void UpdateNowPlaying(const Song &song) override;
|
void UpdateNowPlaying(const Song &song) override;
|
||||||
@@ -140,7 +139,6 @@ class LastFMScrobbler : public ScrobblerService {
|
|||||||
bool subscriber_;
|
bool subscriber_;
|
||||||
QString username_;
|
QString username_;
|
||||||
QString session_key_;
|
QString session_key_;
|
||||||
QString api_key_;
|
|
||||||
|
|
||||||
bool submitted_;
|
bool submitted_;
|
||||||
Song song_playing_;
|
Song song_playing_;
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ void ScrobblerSettingsPage::Load() {
|
|||||||
ui_->checkbox_source_unknown->setChecked(scrobbler_->sources().contains(Song::Source::Unknown));
|
ui_->checkbox_source_unknown->setChecked(scrobbler_->sources().contains(Song::Source::Unknown));
|
||||||
|
|
||||||
ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->enabled());
|
ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->enabled());
|
||||||
ui_->lineedit_lastfm_api_key->setText(lastfmscrobbler_->api_key());
|
|
||||||
LastFM_RefreshControls(lastfmscrobbler_->authenticated());
|
LastFM_RefreshControls(lastfmscrobbler_->authenticated());
|
||||||
|
|
||||||
ui_->checkbox_listenbrainz_enable->setChecked(listenbrainzscrobbler_->enabled());
|
ui_->checkbox_listenbrainz_enable->setChecked(listenbrainzscrobbler_->enabled());
|
||||||
@@ -153,7 +152,6 @@ void ScrobblerSettingsPage::Save() {
|
|||||||
|
|
||||||
s.beginGroup(LastFMScrobbler::kSettingsGroup);
|
s.beginGroup(LastFMScrobbler::kSettingsGroup);
|
||||||
s.setValue(kEnabled, ui_->checkbox_lastfm_enable->isChecked());
|
s.setValue(kEnabled, ui_->checkbox_lastfm_enable->isChecked());
|
||||||
s.setValue(kApiKey, ui_->lineedit_lastfm_api_key->text());
|
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup(ListenBrainzScrobbler::kSettingsGroup);
|
s.beginGroup(ListenBrainzScrobbler::kSettingsGroup);
|
||||||
|
|||||||
@@ -234,43 +234,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="layout_lastfm_api_key">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_lastfm_api_key">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>80</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>API key:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="lineedit_lastfm_api_key">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Optional - your own Last.fm API key</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_lastfm_api_key_info">
|
|
||||||
<property name="text">
|
|
||||||
<string><html><head/><body><p><span style=" font-size:8pt;">Using your own API key can help avoid rate limiting for large libraries. Get one at </span><a href="https://www.last.fm/api/account/create"><span style=" font-size:8pt; text-decoration: underline; color:#0000ff;">https://www.last.fm/api/account/create</span></a></p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="openExternalLinks">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="LoginStateWidget" name="widget_lastfm_login_state" native="true"/>
|
<widget class="LoginStateWidget" name="widget_lastfm_login_state" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
@@ -431,7 +394,6 @@
|
|||||||
<tabstop>checkbox_source_somafm</tabstop>
|
<tabstop>checkbox_source_somafm</tabstop>
|
||||||
<tabstop>checkbox_source_radioparadise</tabstop>
|
<tabstop>checkbox_source_radioparadise</tabstop>
|
||||||
<tabstop>checkbox_lastfm_enable</tabstop>
|
<tabstop>checkbox_lastfm_enable</tabstop>
|
||||||
<tabstop>lineedit_lastfm_api_key</tabstop>
|
|
||||||
<tabstop>button_lastfm_login</tabstop>
|
<tabstop>button_lastfm_login</tabstop>
|
||||||
<tabstop>checkbox_listenbrainz_enable</tabstop>
|
<tabstop>checkbox_listenbrainz_enable</tabstop>
|
||||||
<tabstop>lineedit_listenbrainz_user_token</tabstop>
|
<tabstop>lineedit_listenbrainz_user_token</tabstop>
|
||||||
|
|||||||
@@ -5526,7 +5526,7 @@ Are you sure you want to continue?</source>
|
|||||||
<name>RadioParadiseService</name>
|
<name>RadioParadiseService</name>
|
||||||
<message>
|
<message>
|
||||||
<source>Getting %1 channels</source>
|
<source>Getting %1 channels</source>
|
||||||
<translation>Получение каналов %1</translation>
|
<translation>Получение %1 каналов</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
@@ -6191,7 +6191,7 @@ Are you sure you want to continue?</source>
|
|||||||
<name>SomaFMService</name>
|
<name>SomaFMService</name>
|
||||||
<message>
|
<message>
|
||||||
<source>Getting %1 channels</source>
|
<source>Getting %1 channels</source>
|
||||||
<translation>Получение каналов %1</translation>
|
<translation>Получение %1 каналов</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
|
|||||||
@@ -1187,7 +1187,7 @@ If there are no matches then it will use the largest image in the directory.</tr
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Queue to play next</source>
|
<source>Queue to play next</source>
|
||||||
<translation>Sıradaki yap</translation>
|
<translation>Sıradaki Yap</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Search for this</source>
|
<source>Search for this</source>
|
||||||
@@ -3496,7 +3496,7 @@ If there are no matches then it will use the largest image in the directory.</tr
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Queue to play next</source>
|
<source>Queue to play next</source>
|
||||||
<translation>Sıradaki yap</translation>
|
<translation>Sıradaki Yap</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Unskip track</source>
|
<source>Unskip track</source>
|
||||||
@@ -4431,7 +4431,7 @@ If there are no matches then it will use the largest image in the directory.</tr
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>&Hide %1</source>
|
<source>&Hide %1</source>
|
||||||
<translation>&%1 ögesini sakla</translation>
|
<translation>&%1'i sakla</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
@@ -6407,7 +6407,7 @@ Devam etmek istediğinizden emin misiniz?</translation>
|
|||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Queue to play next</source>
|
<source>Queue to play next</source>
|
||||||
<translation>Sıradaki yap</translation>
|
<translation>Sıradaki Yap</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Remove from favorites</source>
|
<source>Remove from favorites</source>
|
||||||
|
|||||||
Reference in New Issue
Block a user