Compare commits

..

1 Commits

Author SHA1 Message Date
Jonas Kvinge
c87b56adcb Buffer entire songs 2024-08-10 18:28:07 +02:00
641 changed files with 68501 additions and 35246 deletions

View File

@@ -16,9 +16,13 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
opensuse_version: [ 'tumbleweed', 'leap:15.6' ] opensuse_version: [ 'tumbleweed', 'leap:15.6' ]
qt_version: [ '5', '6' ]
container: container:
image: opensuse/${{matrix.opensuse_version}} image: opensuse/${{matrix.opensuse_version}}
steps: steps:
- name: Add tagparser repo
if: matrix.opensuse_version == 'tumbleweed'
run: zypper -n ar -c -f -n 'repo-tagparser' https://download.opensuse.org/repositories/home:/mkittler/openSUSE_Tumbleweed/ repo-tagparser
- name: Refresh repositories - name: Refresh repositories
run: zypper -n --gpg-auto-import-keys ref run: zypper -n --gpg-auto-import-keys ref
- name: Upgrade packages - name: Upgrade packages
@@ -70,6 +74,26 @@ jobs:
update-desktop-files update-desktop-files
appstream-glib appstream-glib
hicolor-icon-theme hicolor-icon-theme
- name: Install Qt 5
if: matrix.qt_version == '5'
run: >
zypper -n --gpg-auto-import-keys in
libQt5Core-devel
libQt5Gui-devel
libQt5Widgets-devel
libQt5Concurrent-devel
libQt5Network-devel
libQt5Sql-devel
libQt5DBus-devel
libQt5Test-devel
libqt5-qtbase-common-devel
libQt5Sql5-sqlite
libqt5-linguist-devel
libqt5-qtx11extras-devel
- name: Install Qt 6
if: matrix.qt_version == '6'
run: >
zypper -n --gpg-auto-import-keys in
qt6-core-devel qt6-core-devel
qt6-gui-devel qt6-gui-devel
qt6-widgets-devel qt6-widgets-devel
@@ -81,8 +105,14 @@ jobs:
qt6-base-common-devel qt6-base-common-devel
qt6-sql-sqlite qt6-sql-sqlite
qt6-linguist-devel qt6-linguist-devel
- name: Install kdsingleapplication-qt6-devel - name: Install tagparser
if: matrix.opensuse_version == 'tumbleweed' if: matrix.opensuse_version == 'tumbleweed'
run: zypper -n --gpg-auto-import-keys in tagparser-devel
- name: Install kdsingleapplication-devel
if: matrix.opensuse_version == 'tumbleweed' && matrix.qt_version == '5'
run: zypper -n --gpg-auto-import-keys in kdsingleapplication-devel
- name: Install kdsingleapplication-qt6-devel
if: matrix.opensuse_version == 'tumbleweed' && matrix.qt_version == '6'
run: zypper -n --gpg-auto-import-keys in kdsingleapplication-qt6-devel run: zypper -n --gpg-auto-import-keys in kdsingleapplication-qt6-devel
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -94,7 +124,7 @@ jobs:
- name: Create Build Environment - name: Create Build Environment
run: cmake -E make_directory build run: cmake -E make_directory build
- name: Configure CMake - name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_WERROR=ON -DUSE_TAGLIB=ON run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_WERROR=ON -DUSE_TAGLIB=ON -DQT_VERSION_MAJOR=${{matrix.qt_version}}
- name: Create source tarball - name: Create source tarball
working-directory: build working-directory: build
run: ../dist/scripts/maketarball.sh run: ../dist/scripts/maketarball.sh
@@ -118,14 +148,14 @@ jobs:
id: set-subdir id: set-subdir
run: echo "subdir=$(echo ${{matrix.opensuse_version}} | sed 's/leap:/lp/g' | sed 's/\.//g')" > $GITHUB_OUTPUT run: echo "subdir=$(echo ${{matrix.opensuse_version}} | sed 's/leap:/lp/g' | sed 's/\.//g')" > $GITHUB_OUTPUT
- name: Upload source - name: Upload source
if: matrix.opensuse_version == 'tumbleweed' if: matrix.opensuse_version == 'tumbleweed' && matrix.qt_version == '6'
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: source name: source
path: | path: |
/usr/src/packages/SOURCES/*.xz /usr/src/packages/SOURCES/*.xz
- name: Upload rpm - name: Upload rpm
if: matrix.opensuse_version != 'tumbleweed' if: matrix.opensuse_version != 'tumbleweed' && matrix.qt_version == '6'
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: opensuse-${{steps.set-subdir.outputs.subdir}} name: opensuse-${{steps.set-subdir.outputs.subdir}}
@@ -430,7 +460,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
debian_version: [ 'bookworm', 'trixie' ] debian_version: [ 'bullseye', 'bookworm', 'trixie' ]
container: container:
image: debian:${{matrix.debian_version}} image: debian:${{matrix.debian_version}}
steps: steps:
@@ -475,11 +505,16 @@ jobs:
libcdio-dev libcdio-dev
libmtp-dev libmtp-dev
libgpod-dev libgpod-dev
qt6-base-dev - name: Install Qt 5
qt6-base-dev-tools if: matrix.debian_version == 'bullseye'
qt6-tools-dev env:
qt6-tools-dev-tools DEBIAN_FRONTEND: noninteractive
qt6-l10n-tools run: apt install -y qtbase5-dev qtbase5-dev-tools qttools5-dev qttools5-dev-tools libqt5x11extras5-dev
- name: Install Qt 6
if: matrix.debian_version != 'bullseye'
env:
DEBIAN_FRONTEND: noninteractive
run: apt install -y qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -509,7 +544,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
ubuntu_version: [ 'noble', 'oracular' ] ubuntu_version: [ 'focal', 'jammy', 'noble', 'oracular' ]
container: container:
image: ubuntu:${{matrix.ubuntu_version}} image: ubuntu:${{matrix.ubuntu_version}}
steps: steps:
@@ -557,11 +592,16 @@ jobs:
libcdio-dev libcdio-dev
libmtp-dev libmtp-dev
libgpod-dev libgpod-dev
qt6-base-dev - name: Install Qt 5
qt6-base-dev-tools if: matrix.ubuntu_version == 'focal'
qt6-tools-dev env:
qt6-tools-dev-tools DEBIAN_FRONTEND: noninteractive
qt6-l10n-tools run: apt install -y qtbase5-dev qtbase5-dev-tools qttools5-dev qttools5-dev-tools libqt5x11extras5-dev
- name: Install Qt 6
if: matrix.ubuntu_version != 'focal'
env:
DEBIAN_FRONTEND: noninteractive
run: apt install -y qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -588,12 +628,12 @@ jobs:
upload-ubuntu-ppa: upload-ubuntu-ppa:
name: Upload Ubuntu PPA name: Upload Ubuntu PPA
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && (github.event_name == 'release' || (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci' || github.ref == 'refs/heads/1.1'))) if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && (github.event_name == 'release' || (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci')))
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
ubuntu_version: [ 'noble', 'oracular' ] ubuntu_version: [ 'focal', 'jammy', 'noble', 'oracular' ]
container: container:
image: ubuntu:${{matrix.ubuntu_version}} image: ubuntu:${{matrix.ubuntu_version}}
steps: steps:
@@ -638,11 +678,6 @@ jobs:
libcdio-dev libcdio-dev
libmtp-dev libmtp-dev
libgpod-dev libgpod-dev
qt6-base-dev
qt6-base-dev-tools
qt6-tools-dev
qt6-tools-dev-tools
qt6-l10n-tools
gstreamer1.0-alsa gstreamer1.0-alsa
gstreamer1.0-pulseaudio gstreamer1.0-pulseaudio
protobuf-compiler protobuf-compiler
@@ -651,6 +686,16 @@ jobs:
env: env:
DEBIAN_FRONTEND: noninteractive DEBIAN_FRONTEND: noninteractive
run: apt install -y keyboxd run: apt install -y keyboxd
- name: Install Qt 5
if: matrix.ubuntu_version == 'focal'
env:
DEBIAN_FRONTEND: noninteractive
run: apt install -y qtbase5-dev qtbase5-dev-tools qttools5-dev qttools5-dev-tools libqt5x11extras5-dev
- name: Install Qt 6
if: matrix.ubuntu_version != 'focal'
env:
DEBIAN_FRONTEND: noninteractive
run: apt install -y qt6-base-dev qt6-base-dev-tools qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -762,6 +807,7 @@ jobs:
-B build -B build
-DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}" -DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}"
-DCMAKE_PREFIX_PATH="${{env.prefix_path}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.prefix_path}}/lib/cmake"
-DBUILD_WITH_QT6=ON
-DBUILD_WERROR=OFF -DBUILD_WERROR=OFF
-DUSE_BUNDLE=ON -DUSE_BUNDLE=ON
-DENABLE_DBUS=OFF -DENABLE_DBUS=OFF
@@ -787,14 +833,9 @@ jobs:
run: make deploy run: make deploy
- name: Manually Codesign - name: Manually Codesign
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-13' if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false
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,libutf8_validity.dylib} strawberry.app/Contents/Frameworks/png.framework/png strawberry.app run: codesign -s 383J84DVB6 -f strawberry.app/Contents/Frameworks/{libsoup-3.0.0.dylib,libnghttp2.14.dylib,libpsl.5.dylib,libpcre2-8.0.dylib,libpcre2-16.0.dylib,libpng16.16.dylib,libzstd.1.dylib,libfreetype.6.dylib} strawberry.app/Contents/Frameworks/png.framework/png strawberry.app
- name: Manually Codesign
if: github.repository == 'strawberrymusicplayer/strawberry' && github.event.pull_request.head.repo.fork == false && matrix.runner == 'macos-14'
working-directory: build
run: codesign -s 383J84DVB6 -f strawberry.app/Contents/Frameworks/png.framework/png strawberry.app
- name: Deploy check - name: Deploy check
working-directory: build working-directory: build
@@ -902,6 +943,7 @@ jobs:
-B build -B build
-DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}" -DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}"
-DCMAKE_PREFIX_PATH="${{env.prefix_path}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.prefix_path}}/lib/cmake"
-DBUILD_WITH_QT6=ON
-DBUILD_WERROR=OFF -DBUILD_WERROR=OFF
-DUSE_BUNDLE=ON -DUSE_BUNDLE=ON
-DENABLE_DBUS=OFF -DENABLE_DBUS=OFF
@@ -951,11 +993,11 @@ jobs:
echo "upload_path=${{secrets.DOWNLOADS_PATH}}/development_releases/macos" >> $GITHUB_OUTPUT echo "upload_path=${{secrets.DOWNLOADS_PATH}}/development_releases/macos" >> $GITHUB_OUTPUT
fi fi
#- name: Create server path - name: Create server path
#run: ssh -p ${{secrets.SSH_PORT}} -o StrictHostKeyChecking=no ${{secrets.SSH_USER}}@${{secrets.SSH_HOST}} mkdir -p ${{steps.set-upload-path.outputs.upload_path}} run: ssh -p ${{secrets.SSH_PORT}} -o StrictHostKeyChecking=no ${{secrets.SSH_USER}}@${{secrets.SSH_HOST}} mkdir -p ${{steps.set-upload-path.outputs.upload_path}}
#- name: rsync - name: rsync
#run: rsync -e "ssh -p ${{secrets.SSH_PORT}} -o StrictHostKeyChecking=no" -var build/*.dmg ${{secrets.SSH_USER}}@${{secrets.SSH_HOST}}:${{steps.set-upload-path.outputs.upload_path}}/ run: rsync -e "ssh -p ${{secrets.SSH_PORT}} -o StrictHostKeyChecking=no" -var build/*.dmg ${{secrets.SSH_USER}}@${{secrets.SSH_HOST}}:${{steps.set-upload-path.outputs.upload_path}}/
build-windows-mingw: build-windows-mingw:
@@ -1000,6 +1042,7 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-${{matrix.arch}}-w64-mingw32-shared.cmake" -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-${{matrix.arch}}-w64-mingw32-shared.cmake"
-DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}" -DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}"
-DCMAKE_PREFIX_PATH="/strawberry-mxe/usr/${{matrix.arch}}-w64-mingw32.shared/qt6" -DCMAKE_PREFIX_PATH="/strawberry-mxe/usr/${{matrix.arch}}-w64-mingw32.shared/qt6"
-DBUILD_WITH_QT6=ON
-DBUILD_WERROR=OFF -DBUILD_WERROR=OFF
-DARCH="${{matrix.arch}}" -DARCH="${{matrix.arch}}"
-DENABLE_WIN32_CONSOLE=$(test "${{matrix.buildtype}}" = "debug" && echo "ON" || echo "OFF") -DENABLE_WIN32_CONSOLE=$(test "${{matrix.buildtype}}" = "debug" && echo "ON" || echo "OFF")
@@ -1288,6 +1331,7 @@ jobs:
-G "Ninja" -G "Ninja"
-DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}" -DCMAKE_BUILD_TYPE="${{env.cmake_buildtype}}"
-DCMAKE_PREFIX_PATH="${{env.prefix_path_forwardslash}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.prefix_path_forwardslash}}/lib/cmake"
-DBUILD_WITH_QT6=ON
-DARCH="${{matrix.arch}}" -DARCH="${{matrix.arch}}"
-DENABLE_WIN32_CONSOLE=${{env.win32_console}} -DENABLE_WIN32_CONSOLE=${{env.win32_console}}
-DUSE_TAGLIB=ON -DUSE_TAGLIB=ON
@@ -1499,7 +1543,7 @@ jobs:
upload_path="${{secrets.RELEASES_PATH}}/" upload_path="${{secrets.RELEASES_PATH}}/"
else else
distro=$(echo "$i" | cut -d '/' -f 2) distro=$(echo "$i" | cut -d '/' -f 2)
if [ -z "$(echo "${distro}" | grep '-' || true)" ]; then if [ "$(echo "$i" | grep '-' || true)" = "" ]; then
upload_path="${{secrets.BUILDS_PATH}}/${distro}/" upload_path="${{secrets.BUILDS_PATH}}/${distro}/"
else else
distro_name=$(echo "${distro}" | cut -d '-' -f 1) distro_name=$(echo "${distro}" | cut -d '-' -f 1)

2
.gitignore vendored
View File

@@ -13,5 +13,5 @@
/dist/scripts/maketarball.sh /dist/scripts/maketarball.sh
/dist/unix/strawberry.spec /dist/unix/strawberry.spec
/dist/windows/strawberry.nsi /dist/windows/strawberry.nsi
/debian/control
/debian/changelog /debian/changelog
/dist/macos/Info.plist

22
3rdparty/README.md vendored
View File

@@ -2,28 +2,20 @@
============================================ ============================================
KDSingleApplication KDSingleApplication
------------------- -----------------
A small library used by Strawberry to prevent it from starting twice per user session. This is a small static library used by Strawberry to prevent it from starting twice per user session.
If the user tries to start strawberry twice, the main window will maximize instead of starting another instance. If the user tries to start strawberry twice, the main window will maximize instead of starting another instance.
It is also used to pass command-line options through to the first instance. It is also used to pass command-line options through to the first instance.
This 3rdparty copy is used only if KDSingleApplication 1.1 or higher is not found on the system.
URL: https://github.com/KDAB/KDSingleApplication/ URL: https://github.com/KDAB/KDSingleApplication/
SPMediaKeyTap SPMediaKeyTap
------------- -------------
A library used on macOS to exclusively grab global media shortcuts. Used on macOS to exclusively enable strawberry to grab global media shortcuts.
Can safely be deleted on other platforms.
The library is no longer maintained by the original author.
The directory can safely be deleted on other platforms.
gstfastspectrum getopt
--------------- ------
A GStreamer spectrum plugin using FFTW3. getopt included only when compiling on Windows.
It is needed for moodbar support, and is currently not available
in GStreamer.
The plan is to submit it to GStreamer, or move it to
a seperate repository outside of Strawberry.

3
3rdparty/getopt/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,3 @@
add_library(getopt STATIC getopt.cpp)
target_compile_definitions(getopt PRIVATE -DSTATIC_GETOPT -D_UNICODE)
target_include_directories(getopt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

753
3rdparty/getopt/getopt.cpp vendored Normal file
View File

@@ -0,0 +1,753 @@
/* Getopt for Microsoft C
This code is a modification of the Free Software Foundation, Inc.
Getopt library for parsing command line argument the purpose was
to provide a Microsoft Visual C friendly derivative. This code
provides functionality for both Unicode and Multibyte builds.
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
Version: 1.1
Comment: Supports getopt, getopt_long, and getopt_long_only
and POSIXLY_CORRECT environment flag
License: LGPL
Revisions:
02/03/2011 - Ludvik Jerabek - Initial Release
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
09/24/2022 - Ludvik Jerabek - Updated to match most recent getopt release
09/25/2022 - Ludvik Jerabek - Fixed memory allocation (malloc call) issue for wchar_t*
**DISCLAIMER**
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include "getopt.h"
#ifdef __cplusplus
# define _GETOPT_THROW throw()
#else
# define _GETOPT_THROW
#endif
int optind = 1;
int opterr = 1;
int optopt = '?';
enum ENUM_ORDERING {
REQUIRE_ORDER,
PERMUTE,
RETURN_IN_ORDER
};
//
//
// Ansi structures and functions follow
//
//
static struct _getopt_data_a {
int optind;
int opterr;
int optopt;
char *optarg;
int __initialized;
char *__nextchar;
enum ENUM_ORDERING __ordering;
int __first_nonopt;
int __last_nonopt;
} getopt_data_a;
char *optarg_a;
static void exchange_a(char **argv, struct _getopt_data_a *d) {
int bottom = d->__first_nonopt;
int middle = d->__last_nonopt;
int top = d->optind;
char *tem;
while (top > middle && middle > bottom) {
if (top - middle > middle - bottom) {
int len = middle - bottom;
int i;
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
top -= len;
}
else {
int len = top - middle;
int i;
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
bottom += len;
}
}
d->__first_nonopt += (d->optind - d->__last_nonopt);
d->__last_nonopt = d->optind;
}
static int process_long_option_a(int argc, char **argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int print_errors, const char *prefix);
static int process_long_option_a(int argc, char **argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int print_errors, const char *prefix) {
assert(longopts != NULL);
char *nameend;
size_t namelen;
const struct option_a *p;
const struct option_a *pfound = NULL;
int n_options;
int option_index = 0;
for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
;
namelen = nameend - d->__nextchar;
for (p = longopts, n_options = 0; p->name; p++, n_options++)
if (!strncmp(p->name, d->__nextchar, namelen) && namelen == strlen(p->name)) {
pfound = p;
option_index = n_options;
break;
}
if (pfound == NULL) {
unsigned char *ambig_set = NULL;
int ambig_fallback = 0;
int indfound = -1;
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp(p->name, d->__nextchar, namelen)) {
if (pfound == NULL) {
pfound = p;
indfound = option_index;
}
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val) {
if (!ambig_fallback) {
if (!print_errors)
ambig_fallback = 1;
else if (!ambig_set) {
if ((ambig_set = reinterpret_cast<unsigned char *>(malloc(n_options * sizeof(char)))) == NULL)
ambig_fallback = 1;
if (ambig_set) {
memset(ambig_set, 0, n_options * sizeof(char));
ambig_set[indfound] = 1;
}
}
if (ambig_set)
ambig_set[option_index] = 1;
}
}
}
if (ambig_set || ambig_fallback) {
if (print_errors) {
if (ambig_fallback)
fprintf(stderr, "%s: option '%s%s' is ambiguous\n", argv[0], prefix, d->__nextchar);
else {
_lock_file(stderr);
fprintf(stderr, "%s: option '%s%s' is ambiguous; possibilities:", argv[0], prefix, d->__nextchar);
for (option_index = 0; option_index < n_options; option_index++)
if (ambig_set[option_index])
fprintf(stderr, " '%s%s'", prefix, longopts[option_index].name);
fprintf(stderr, "\n");
_unlock_file(stderr);
}
}
free(ambig_set);
d->__nextchar += strlen(d->__nextchar);
d->optind++;
d->optopt = 0;
return '?';
}
option_index = indfound;
}
if (pfound == NULL) {
if (!long_only || argv[d->optind][1] == '-' || strchr(optstring, *d->__nextchar) == NULL) {
if (print_errors)
fprintf(stderr, "%s: unrecognized option '%s%s'\n", argv[0], prefix, d->__nextchar);
d->__nextchar = NULL;
d->optind++;
d->optopt = 0;
return '?';
}
return -1;
}
d->optind++;
d->__nextchar = NULL;
if (*nameend) {
if (pfound->has_arg)
d->optarg = nameend + 1;
else {
if (print_errors)
fprintf(stderr, "%s: option '%s%s' doesn't allow an argument\n", argv[0], prefix, pfound->name);
d->optopt = pfound->val;
return '?';
}
}
else if (pfound->has_arg == 1) {
if (d->optind < argc)
d->optarg = argv[d->optind++];
else {
if (print_errors)
fprintf(stderr, "%s: option '%s%s' requires an argument\n", argv[0], prefix, pfound->name);
d->optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
if (longind != NULL)
*longind = option_index;
if (pfound->flag) {
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
static const char *_getopt_initialize_a(const char *optstring, struct _getopt_data_a *d, int posixly_correct) {
if (d->optind == 0)
d->optind = 1;
d->__first_nonopt = d->__last_nonopt = d->optind;
d->__nextchar = NULL;
if (optstring[0] == '-') {
d->__ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+') {
d->__ordering = REQUIRE_ORDER;
++optstring;
}
else if (posixly_correct | !!getenv("POSIXLY_CORRECT"))
d->__ordering = REQUIRE_ORDER;
else
d->__ordering = PERMUTE;
d->__initialized = 1;
return optstring;
}
int _getopt_internal_r_a(int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int posixly_correct);
int _getopt_internal_r_a(int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, struct _getopt_data_a *d, int posixly_correct) {
int print_errors = d->opterr;
if (argc < 1)
return -1;
d->optarg = NULL;
if (d->optind == 0 || !d->__initialized)
optstring = _getopt_initialize_a(optstring, d, posixly_correct);
else if (optstring[0] == '-' || optstring[0] == '+')
optstring++;
if (optstring[0] == ':')
print_errors = 0;
if (d->__nextchar == NULL || *d->__nextchar == '\0') {
if (d->__last_nonopt > d->optind)
d->__last_nonopt = d->optind;
if (d->__first_nonopt > d->optind)
d->__first_nonopt = d->optind;
if (d->__ordering == PERMUTE) {
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
exchange_a(const_cast<char **>(argv), d);
else if (d->__last_nonopt != d->optind)
d->__first_nonopt = d->optind;
while (d->optind < argc && (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0'))
d->optind++;
d->__last_nonopt = d->optind;
}
if (d->optind != argc && !strcmp(argv[d->optind], "--")) {
d->optind++;
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
exchange_a(const_cast<char **>(argv), d);
else if (d->__first_nonopt == d->__last_nonopt)
d->__first_nonopt = d->optind;
d->__last_nonopt = argc;
d->optind = argc;
}
if (d->optind == argc) {
if (d->__first_nonopt != d->__last_nonopt)
d->optind = d->__first_nonopt;
return -1;
}
if (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0') {
if (d->__ordering == REQUIRE_ORDER)
return -1;
d->optarg = argv[d->optind++];
return 1;
}
if (longopts) {
if (argv[d->optind][1] == '-') {
d->__nextchar = argv[d->optind] + 2;
return process_long_option_a(argc, const_cast<char **>(argv), optstring, longopts, longind, long_only, d, print_errors, "--");
}
if (long_only && (argv[d->optind][2] || !strchr(optstring, argv[d->optind][1]))) {
int code;
d->__nextchar = argv[d->optind] + 1;
code = process_long_option_a(argc, const_cast<char **>(argv), optstring, longopts,
longind, long_only, d,
print_errors, "-");
if (code != -1)
return code;
}
}
d->__nextchar = argv[d->optind] + 1;
}
{
char c = *d->__nextchar++;
const char *temp = strchr(optstring, c);
if (*d->__nextchar == '\0')
++d->optind;
if (temp == NULL || c == ':' || c == ';') {
if (print_errors)
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], c);
d->optopt = c;
return '?';
}
if (temp[0] == 'W' && temp[1] == ';' && longopts != NULL) {
if (*d->__nextchar != '\0')
d->optarg = d->__nextchar;
else if (d->optind == argc) {
if (print_errors)
fprintf(stderr, "%s: option requires an argument -- '%c'\n", argv[0], c);
d->optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
return c;
}
else
d->optarg = argv[d->optind];
d->__nextchar = d->optarg;
d->optarg = NULL;
return process_long_option_a(argc, const_cast<char **>(argv), optstring, longopts, longind, 0, d, print_errors, "-W ");
}
if (temp[1] == ':') {
if (temp[2] == ':') {
if (*d->__nextchar != '\0') {
d->optarg = d->__nextchar;
d->optind++;
}
else
d->optarg = NULL;
d->__nextchar = NULL;
}
else {
if (*d->__nextchar != '\0') {
d->optarg = d->__nextchar;
d->optind++;
}
else if (d->optind == argc) {
if (print_errors)
fprintf(stderr, "%s: option requires an argument -- '%c'\n", argv[0], c);
d->optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
d->optarg = argv[d->optind++];
d->__nextchar = NULL;
}
}
return c;
}
}
int _getopt_internal_a(int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, int posixly_correct);
int _getopt_internal_a(int argc, char *const *argv, const char *optstring, const struct option_a *longopts, int *longind, int long_only, int posixly_correct) {
int result;
getopt_data_a.optind = optind;
getopt_data_a.opterr = opterr;
result = _getopt_internal_r_a(argc, argv, optstring, longopts, longind, long_only, &getopt_data_a, posixly_correct);
optind = getopt_data_a.optind;
optarg_a = getopt_data_a.optarg;
optopt = getopt_data_a.optopt;
return result;
}
int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW {
return _getopt_internal_a(argc, argv, optstring, static_cast<const struct option_a *>(0), static_cast<int *>(0), 0, 0);
}
int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW {
return _getopt_internal_a(argc, argv, options, long_options, opt_index, 0, 0);
}
int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW {
return _getopt_internal_a(argc, argv, options, long_options, opt_index, 1, 0);
}
int _getopt_long_r_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d);
int _getopt_long_r_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d) {
return _getopt_internal_r_a(argc, argv, options, long_options, opt_index, 0, d, 0);
}
int _getopt_long_only_r_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d);
int _getopt_long_only_r_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index, struct _getopt_data_a *d) {
return _getopt_internal_r_a(argc, argv, options, long_options, opt_index, 1, d, 0);
}
//
//
// Unicode Structures and Functions
//
//
static struct _getopt_data_w {
int optind;
int opterr;
int optopt;
wchar_t *optarg;
int __initialized;
wchar_t *__nextchar;
enum ENUM_ORDERING __ordering;
int __first_nonopt;
int __last_nonopt;
} getopt_data_w;
wchar_t *optarg_w;
static void exchange_w(wchar_t **argv, struct _getopt_data_w *d) {
int bottom = d->__first_nonopt;
int middle = d->__last_nonopt;
int top = d->optind;
wchar_t *tem;
while (top > middle && middle > bottom) {
if (top - middle > middle - bottom) {
int len = middle - bottom;
int i;
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
top -= len;
}
else {
int len = top - middle;
int i;
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
bottom += len;
}
}
d->__first_nonopt += (d->optind - d->__last_nonopt);
d->__last_nonopt = d->optind;
}
static int process_long_option_w(int argc, wchar_t **argv, const wchar_t *optstring, const struct option_w *longopts, int *longind, int long_only, struct _getopt_data_w *d, int print_errors, const wchar_t *prefix) {
assert(longopts != NULL);
wchar_t *nameend;
size_t namelen;
const struct option_w *p;
const struct option_w *pfound = NULL;
int n_options;
int option_index = 0;
for (nameend = d->__nextchar; *nameend && *nameend != L'='; nameend++)
;
namelen = nameend - d->__nextchar;
for (p = longopts, n_options = 0; p->name; p++, n_options++)
if (!wcsncmp(p->name, d->__nextchar, namelen) && namelen == wcslen(p->name)) {
pfound = p;
option_index = n_options;
break;
}
if (pfound == NULL) {
wchar_t *ambig_set = NULL;
int ambig_fallback = 0;
int indfound = -1;
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!wcsncmp(p->name, d->__nextchar, namelen)) {
if (pfound == NULL) {
pfound = p;
indfound = option_index;
}
else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val) {
if (!ambig_fallback) {
if (!print_errors)
ambig_fallback = 1;
else if (!ambig_set) {
if ((ambig_set = reinterpret_cast<wchar_t *>(malloc(n_options * sizeof(wchar_t)))) == NULL)
ambig_fallback = 1;
if (ambig_set) {
memset(ambig_set, 0, n_options * sizeof(wchar_t));
ambig_set[indfound] = 1;
}
}
if (ambig_set)
ambig_set[option_index] = 1;
}
}
}
if (ambig_set || ambig_fallback) {
if (print_errors) {
if (ambig_fallback)
fwprintf(stderr, L"%s: option '%s%s' is ambiguous\n", argv[0], prefix, d->__nextchar);
else {
_lock_file(stderr);
fwprintf(stderr, L"%s: option '%s%s' is ambiguous; possibilities:", argv[0], prefix, d->__nextchar);
for (option_index = 0; option_index < n_options; option_index++)
if (ambig_set[option_index])
fwprintf(stderr, L" '%s%s'", prefix, longopts[option_index].name);
fwprintf(stderr, L"\n");
_unlock_file(stderr);
}
}
free(ambig_set);
d->__nextchar += wcslen(d->__nextchar);
d->optind++;
d->optopt = 0;
return L'?';
}
option_index = indfound;
}
if (pfound == NULL) {
if (!long_only || argv[d->optind][1] == L'-' || wcschr(optstring, *d->__nextchar) == NULL) {
if (print_errors)
fwprintf(stderr, L"%s: unrecognized option '%s%s'\n", argv[0], prefix, d->__nextchar);
d->__nextchar = NULL;
d->optind++;
d->optopt = 0;
return L'?';
}
return -1;
}
d->optind++;
d->__nextchar = NULL;
if (*nameend) {
if (pfound->has_arg)
d->optarg = nameend + 1;
else {
if (print_errors)
fwprintf(stderr, L"%s: option '%s%s' doesn't allow an argument\n", argv[0], prefix, pfound->name);
d->optopt = pfound->val;
return L'?';
}
}
else if (pfound->has_arg == 1) {
if (d->optind < argc)
d->optarg = argv[d->optind++];
else {
if (print_errors)
fwprintf(stderr, L"%s: option '%s%s' requires an argument\n", argv[0], prefix, pfound->name);
d->optopt = pfound->val;
return optstring[0] == L':' ? L':' : L'?';
}
}
if (longind != NULL)
*longind = option_index;
if (pfound->flag) {
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
static const wchar_t *_getopt_initialize_w(const wchar_t *optstring, struct _getopt_data_w *d, int posixly_correct) {
if (d->optind == 0)
d->optind = 1;
d->__first_nonopt = d->__last_nonopt = d->optind;
d->__nextchar = NULL;
if (optstring[0] == L'-') {
d->__ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == L'+') {
d->__ordering = REQUIRE_ORDER;
++optstring;
}
else if (posixly_correct | !!_wgetenv(L"POSIXLY_CORRECT"))
d->__ordering = REQUIRE_ORDER;
else
d->__ordering = PERMUTE;
d->__initialized = 1;
return optstring;
}
int _getopt_internal_r_w(int argc, wchar_t *const *argv, const wchar_t *optstring, const struct option_w *longopts, int *longind, int long_only, struct _getopt_data_w *d, int posixly_correct);
int _getopt_internal_r_w(int argc, wchar_t *const *argv, const wchar_t *optstring, const struct option_w *longopts, int *longind, int long_only, struct _getopt_data_w *d, int posixly_correct) {
int print_errors = d->opterr;
if (argc < 1)
return -1;
d->optarg = NULL;
if (d->optind == 0 || !d->__initialized)
optstring = _getopt_initialize_w(optstring, d, posixly_correct);
else if (optstring[0] == L'-' || optstring[0] == L'+')
optstring++;
if (optstring[0] == L':')
print_errors = 0;
#define NONOPTION_P (argv[d->optind][0] != L'-' || argv[d->optind][1] == L'\0')
if (d->__nextchar == NULL || *d->__nextchar == L'\0') {
if (d->__last_nonopt > d->optind)
d->__last_nonopt = d->optind;
if (d->__first_nonopt > d->optind)
d->__first_nonopt = d->optind;
if (d->__ordering == PERMUTE) {
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
exchange_w(const_cast<wchar_t **>(argv), d);
else if (d->__last_nonopt != d->optind)
d->__first_nonopt = d->optind;
while (d->optind < argc && NONOPTION_P)
d->optind++;
d->__last_nonopt = d->optind;
}
if (d->optind != argc && !wcscmp(argv[d->optind], L"--")) {
d->optind++;
if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
exchange_w(const_cast<wchar_t **>(argv), d);
else if (d->__first_nonopt == d->__last_nonopt)
d->__first_nonopt = d->optind;
d->__last_nonopt = argc;
d->optind = argc;
}
if (d->optind == argc) {
if (d->__first_nonopt != d->__last_nonopt)
d->optind = d->__first_nonopt;
return -1;
}
if (NONOPTION_P) {
if (d->__ordering == REQUIRE_ORDER)
return -1;
d->optarg = argv[d->optind++];
return 1;
}
if (longopts) {
if (argv[d->optind][1] == L'-') {
d->__nextchar = argv[d->optind] + 2;
return process_long_option_w(argc, const_cast<wchar_t **>(argv), optstring, longopts, longind, long_only, d, print_errors, L"--");
}
if (long_only && (argv[d->optind][2] || !wcschr(optstring, argv[d->optind][1]))) {
int code;
d->__nextchar = argv[d->optind] + 1;
code = process_long_option_w(argc, const_cast<wchar_t **>(argv), optstring, longopts, longind, long_only, d, print_errors, L"-");
if (code != -1)
return code;
}
}
d->__nextchar = argv[d->optind] + 1;
}
{
wchar_t c = *d->__nextchar++;
const wchar_t *temp = wcschr(optstring, c);
if (*d->__nextchar == L'\0')
++d->optind;
if (temp == NULL || c == L':' || c == L';') {
if (print_errors)
fwprintf(stderr, L"%s: invalid option -- '%c'\n", argv[0], c);
d->optopt = c;
return L'?';
}
if (temp[0] == L'W' && temp[1] == L';' && longopts != NULL) {
if (*d->__nextchar != L'\0')
d->optarg = d->__nextchar;
else if (d->optind == argc) {
if (print_errors)
fwprintf(stderr, L"%s: option requires an argument -- '%c'\n", argv[0], c);
d->optopt = c;
if (optstring[0] == L':')
c = L':';
else
c = L'?';
return c;
}
else
d->optarg = argv[d->optind];
d->__nextchar = d->optarg;
d->optarg = NULL;
return process_long_option_w(argc, const_cast<wchar_t **>(argv), optstring, longopts, longind,
0, d, print_errors, L"-W ");
}
if (temp[1] == L':') {
if (temp[2] == L':') {
if (*d->__nextchar != L'\0') {
d->optarg = d->__nextchar;
d->optind++;
}
else
d->optarg = NULL;
d->__nextchar = NULL;
}
else {
if (*d->__nextchar != L'\0') {
d->optarg = d->__nextchar;
d->optind++;
}
else if (d->optind == argc) {
if (print_errors)
fwprintf(stderr, L"%s: option requires an argument -- '%c'\n", argv[0], c);
d->optopt = c;
if (optstring[0] == L':')
c = L':';
else
c = L'?';
}
else
d->optarg = argv[d->optind++];
d->__nextchar = NULL;
}
}
return c;
}
}
int _getopt_internal_w(int argc, wchar_t *const *argv, const wchar_t *optstring, const struct option_w *longopts, int *longind, int long_only, int posixly_correct);
int _getopt_internal_w(int argc, wchar_t *const *argv, const wchar_t *optstring, const struct option_w *longopts, int *longind, int long_only, int posixly_correct) {
int result;
getopt_data_w.optind = optind;
getopt_data_w.opterr = opterr;
result = _getopt_internal_r_w(argc, argv, optstring, longopts, longind, long_only, &getopt_data_w, posixly_correct);
optind = getopt_data_w.optind;
optarg_w = getopt_data_w.optarg;
optopt = getopt_data_w.optopt;
return result;
}
int getopt_w(int argc, wchar_t *const *argv, const wchar_t *optstring) _GETOPT_THROW {
return _getopt_internal_w(argc, argv, optstring, static_cast<const struct option_w *>(0), static_cast<int *>(0), 0, 0);
}
int getopt_long_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW {
return _getopt_internal_w(argc, argv, options, long_options, opt_index, 0, 0);
}
int getopt_long_only_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW {
return _getopt_internal_w(argc, argv, options, long_options, opt_index, 1, 0);
}
int _getopt_long_r_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index, struct _getopt_data_w *d);
int _getopt_long_r_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index, struct _getopt_data_w *d) {
return _getopt_internal_r_w(argc, argv, options, long_options, opt_index, 0, d, 0);
}
int _getopt_long_only_r_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index, struct _getopt_data_w *d);
int _getopt_long_only_r_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index, struct _getopt_data_w *d) {
return _getopt_internal_r_w(argc, argv, options, long_options, opt_index, 1, d, 0);
}

135
3rdparty/getopt/getopt.h vendored Normal file
View File

@@ -0,0 +1,135 @@
/* Getopt for Microsoft C
This code is a modification of the Free Software Foundation, Inc.
Getopt library for parsing command line argument the purpose was
to provide a Microsoft Visual C friendly derivative. This code
provides functionality for both Unicode and Multibyte builds.
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
Version: 1.1
Comment: Supports getopt, getopt_long, and getopt_long_only
and POSIXLY_CORRECT environment flag
License: LGPL
Revisions:
02/03/2011 - Ludvik Jerabek - Initial Release
02/20/2011 - Ludvik Jerabek - Fixed compiler warnings at Level 4
07/05/2011 - Ludvik Jerabek - Added no_argument, required_argument, optional_argument defs
08/03/2011 - Ludvik Jerabek - Fixed non-argument runtime bug which caused runtime exception
08/09/2011 - Ludvik Jerabek - Added code to export functions for DLL and LIB
02/15/2012 - Ludvik Jerabek - Fixed _GETOPT_THROW definition missing in implementation file
08/01/2012 - Ludvik Jerabek - Created separate functions for char and wchar_t characters so single dll can do both unicode and ansi
10/15/2012 - Ludvik Jerabek - Modified to match latest GNU features
06/19/2015 - Ludvik Jerabek - Fixed maximum option limitation caused by option_a (255) and option_w (65535) structure val variable
09/24/2022 - Ludvik Jerabek - Updated to match most recent getopt release
09/25/2022 - Ludvik Jerabek - Fixed memory allocation (malloc call) issue for wchar_t*
**DISCLAIMER**
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING, BUT Not LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY NOT
APPLY TO YOU. IN NO EVENT WILL I BE LIABLE TO ANY PARTY FOR ANY
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY
USE OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST
PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON
YOUR INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN If WE ARE
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef __GETOPT_H_
#define __GETOPT_H_
#ifdef _GETOPT_API
# undef _GETOPT_API
#endif
#if defined(EXPORTS_GETOPT) && defined(STATIC_GETOPT)
# error "The preprocessor definitions of EXPORTS_GETOPT and STATIC_GETOPT can only be used individually"
#elif defined(STATIC_GETOPT)
# define _GETOPT_API
#elif defined(EXPORTS_GETOPT)
# pragma message("Exporting getopt library")
# define _GETOPT_API __declspec(dllexport)
#else
# pragma message("Importing getopt library")
# define _GETOPT_API __declspec(dllimport)
#endif
// Change behavior for C\C++
#ifdef __cplusplus
# define _BEGIN_EXTERN_C extern "C" {
# define _END_EXTERN_C }
# define _GETOPT_THROW throw()
#else
# define _BEGIN_EXTERN_C
# define _END_EXTERN_C
# define _GETOPT_THROW
#endif
// Standard GNU options
#define null_argument 0 /*Argument Null*/
#define no_argument 0 /*Argument Switch Only*/
#define required_argument 1 /*Argument Required*/
#define optional_argument 2 /*Argument Optional*/
// Shorter Options
#define ARG_NULL 0 /*Argument Null*/
#define ARG_NONE 0 /*Argument Switch Only*/
#define ARG_REQ 1 /*Argument Required*/
#define ARG_OPT 2 /*Argument Optional*/
#include <string.h>
#include <wchar.h>
_BEGIN_EXTERN_C
extern _GETOPT_API int optind;
extern _GETOPT_API int opterr;
extern _GETOPT_API int optopt;
// Ansi
struct option_a {
const char *name;
int has_arg;
int *flag;
int val;
};
extern _GETOPT_API char *optarg_a;
extern _GETOPT_API int getopt_a(int argc, char *const *argv, const char *optstring) _GETOPT_THROW;
extern _GETOPT_API int getopt_long_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
extern _GETOPT_API int getopt_long_only_a(int argc, char *const *argv, const char *options, const struct option_a *long_options, int *opt_index) _GETOPT_THROW;
// Unicode
struct option_w {
const wchar_t *name;
int has_arg;
int *flag;
int val;
};
extern _GETOPT_API wchar_t *optarg_w;
extern _GETOPT_API int getopt_w(int argc, wchar_t *const *argv, const wchar_t *optstring) _GETOPT_THROW;
extern _GETOPT_API int getopt_long_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
extern _GETOPT_API int getopt_long_only_w(int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index) _GETOPT_THROW;
_END_EXTERN_C
#undef _BEGIN_EXTERN_C
#undef _END_EXTERN_C
#undef _GETOPT_THROW
#undef _GETOPT_API
#ifdef _UNICODE
# define getopt getopt_w
# define getopt_long getopt_long_w
# define getopt_long_only getopt_long_only_w
# define option option_w
# define optarg optarg_w
#else
# define getopt getopt_a
# define getopt_long getopt_long_a
# define getopt_long_only getopt_long_only_a
# define option option_a
# define optarg optarg_a
#endif
#endif // __GETOPT_H_

View File

@@ -1,520 +0,0 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* <2006,2011> Stefan Kost <ensonic@users.sf.net>
* <2007-2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* <2018-2024> Jonas Kvinge <jonas@jkvinge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <cstring>
#include <cmath>
#include <glib.h>
#include <gst/gst.h>
#include <gst/audio/gstaudiofilter.h>
#include <fftw3.h>
#include "gstfastspectrum.h"
GST_DEBUG_CATEGORY_STATIC(gst_strawberry_fastspectrum_debug);
namespace {
// Spectrum properties
constexpr auto DEFAULT_INTERVAL = (GST_SECOND / 10);
constexpr auto DEFAULT_BANDS = 128;
enum {
PROP_0,
PROP_INTERVAL,
PROP_BANDS
};
} // namespace
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
G_DEFINE_TYPE(GstStrawberryFastSpectrum, gst_strawberry_fastspectrum, GST_TYPE_AUDIO_FILTER)
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static void gst_strawberry_fastspectrum_finalize(GObject *object);
static void gst_strawberry_fastspectrum_set_property(GObject *object, const guint prop_id, const GValue *value, GParamSpec *pspec);
static void gst_strawberry_fastspectrum_get_property(GObject *object, const guint prop_id, GValue *value, GParamSpec *pspec);
static gboolean gst_strawberry_fastspectrum_start(GstBaseTransform *transform);
static gboolean gst_strawberry_fastspectrum_stop(GstBaseTransform *transform);
static GstFlowReturn gst_strawberry_fastspectrum_transform_ip(GstBaseTransform *transform, GstBuffer *buffer);
static gboolean gst_strawberry_fastspectrum_setup(GstAudioFilter *audio_filter, const GstAudioInfo *audio_info);
static void gst_strawberry_fastspectrum_class_init(GstStrawberryFastSpectrumClass *klass) {
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
GstBaseTransformClass *transform_class = GST_BASE_TRANSFORM_CLASS(klass);
GstAudioFilterClass *filter_class = GST_AUDIO_FILTER_CLASS(klass);
gobject_class->set_property = gst_strawberry_fastspectrum_set_property;
gobject_class->get_property = gst_strawberry_fastspectrum_get_property;
gobject_class->finalize = gst_strawberry_fastspectrum_finalize;
transform_class->start = GST_DEBUG_FUNCPTR(gst_strawberry_fastspectrum_start);
transform_class->stop = GST_DEBUG_FUNCPTR(gst_strawberry_fastspectrum_stop);
transform_class->transform_ip = GST_DEBUG_FUNCPTR(gst_strawberry_fastspectrum_transform_ip);
transform_class->passthrough_on_same_caps = TRUE;
filter_class->setup = GST_DEBUG_FUNCPTR(gst_strawberry_fastspectrum_setup);
g_object_class_install_property(gobject_class, PROP_INTERVAL, g_param_spec_uint64("interval", "Interval", "Interval of time between message posts (in nanoseconds)", 1, G_MAXUINT64, DEFAULT_INTERVAL, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property(gobject_class, PROP_BANDS, g_param_spec_uint("bands", "Bands", "Number of frequency bands", 0, G_MAXUINT, DEFAULT_BANDS, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
GST_DEBUG_CATEGORY_INIT(gst_strawberry_fastspectrum_debug, "spectrum", 0, "audio spectrum analyser element");
gst_element_class_set_static_metadata(element_class,
"Fast spectrum analyzer using FFTW",
"Filter/Analyzer/Audio",
"Run an FFT on the audio signal, output spectrum data",
"Erik Walthinsen <omega@cse.ogi.edu>, "
"Stefan Kost <ensonic@users.sf.net>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>, "
"Jonas Kvinge <jonas@jkvinge.net>");
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
GstCaps *caps = gst_caps_from_string(GST_AUDIO_CAPS_MAKE("{ S16LE, S24LE, S32LE, F32LE, F64LE }") ", layout = (string) interleaved, channels = 1");
#else
GstCaps *caps = gst_caps_from_string(GST_AUDIO_CAPS_MAKE("{ S16BE, S24BE, S32BE, F32BE, F64BE }") ", layout = (string) interleaved, channels = 1");
#endif
gst_audio_filter_class_add_pad_templates(filter_class, caps);
gst_caps_unref(caps);
g_mutex_init(&klass->fftw_lock);
}
static void gst_strawberry_fastspectrum_init(GstStrawberryFastSpectrum *fastspectrum) {
fastspectrum->interval = DEFAULT_INTERVAL;
fastspectrum->bands = DEFAULT_BANDS;
fastspectrum->channel_data_initialized = false;
g_mutex_init(&fastspectrum->lock);
}
static void gst_strawberry_fastspectrum_alloc_channel_data(GstStrawberryFastSpectrum *fastspectrum) {
const guint bands = fastspectrum->bands;
const guint nfft = 2 * bands - 2;
fastspectrum->input_ring_buffer = new double[nfft];
fastspectrum->fft_input = reinterpret_cast<double*>(fftw_malloc(sizeof(double) * nfft));
fastspectrum->fft_output = reinterpret_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * (nfft / 2 + 1)));
fastspectrum->spect_magnitude = new double[bands] {};
GstStrawberryFastSpectrumClass *klass = reinterpret_cast<GstStrawberryFastSpectrumClass*>(G_OBJECT_GET_CLASS(fastspectrum));
{
g_mutex_lock(&klass->fftw_lock);
fastspectrum->plan = fftw_plan_dft_r2c_1d(static_cast<int>(nfft), fastspectrum->fft_input, fastspectrum->fft_output, FFTW_ESTIMATE);
g_mutex_unlock(&klass->fftw_lock);
}
fastspectrum->channel_data_initialized = true;
}
static void gst_strawberry_fastspectrum_free_channel_data(GstStrawberryFastSpectrum *fastspectrum) {
GstStrawberryFastSpectrumClass *klass = reinterpret_cast<GstStrawberryFastSpectrumClass*>(G_OBJECT_GET_CLASS(fastspectrum));
if (fastspectrum->channel_data_initialized) {
{
g_mutex_lock(&klass->fftw_lock);
fftw_destroy_plan(fastspectrum->plan);
g_mutex_unlock(&klass->fftw_lock);
}
fftw_free(fastspectrum->fft_input);
fftw_free(fastspectrum->fft_output);
delete[] fastspectrum->input_ring_buffer;
delete[] fastspectrum->spect_magnitude;
fastspectrum->channel_data_initialized = false;
}
}
static void gst_strawberry_fastspectrum_flush(GstStrawberryFastSpectrum *fastspectrum) {
fastspectrum->num_frames = 0;
fastspectrum->num_fft = 0;
fastspectrum->accumulated_error = 0;
}
static void gst_strawberry_fastspectrum_reset_state(GstStrawberryFastSpectrum *fastspectrum) {
GST_DEBUG_OBJECT(fastspectrum, "resetting state");
gst_strawberry_fastspectrum_free_channel_data(fastspectrum);
gst_strawberry_fastspectrum_flush(fastspectrum);
}
static void gst_strawberry_fastspectrum_finalize(GObject *object) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(object);
gst_strawberry_fastspectrum_reset_state(fastspectrum);
g_mutex_clear(&fastspectrum->lock);
G_OBJECT_CLASS(gst_strawberry_fastspectrum_parent_class)->finalize(object);
}
static void gst_strawberry_fastspectrum_set_property(GObject *object, const guint prop_id, const GValue *value, GParamSpec *pspec) {
GstStrawberryFastSpectrum *filter = reinterpret_cast<GstStrawberryFastSpectrum*>(object);
switch (prop_id) {
case PROP_INTERVAL: {
const guint64 interval = g_value_get_uint64(value);
g_mutex_lock(&filter->lock);
if (filter->interval != interval) {
filter->interval = interval;
gst_strawberry_fastspectrum_reset_state(filter);
}
g_mutex_unlock(&filter->lock);
break;
}
case PROP_BANDS: {
const guint bands = g_value_get_uint(value);
g_mutex_lock(&filter->lock);
if (filter->bands != bands) {
filter->bands = bands;
gst_strawberry_fastspectrum_reset_state(filter);
}
g_mutex_unlock(&filter->lock);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void gst_strawberry_fastspectrum_get_property(GObject *object, const guint prop_id, GValue *value, GParamSpec *pspec) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(object);
switch (prop_id) {
case PROP_INTERVAL:
g_value_set_uint64(value, fastspectrum->interval);
break;
case PROP_BANDS:
g_value_set_uint(value, fastspectrum->bands);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static gboolean gst_strawberry_fastspectrum_start(GstBaseTransform *transform) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(transform);
gst_strawberry_fastspectrum_reset_state(fastspectrum);
return TRUE;
}
static gboolean gst_strawberry_fastspectrum_stop(GstBaseTransform *transform) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(transform);
gst_strawberry_fastspectrum_reset_state(fastspectrum);
return TRUE;
}
// Mixing data readers
static void gst_strawberry_fastspectrum_input_data_mixed_float(const guint8 *_in, double *out, const guint64 len, const double max_value, guint op, const guint nfft) {
(void) max_value;
const gfloat *in = reinterpret_cast<const gfloat*>(_in);
guint ip = 0;
for (guint64 j = 0; j < len; j++) {
out[op] = in[ip++];
op = (op + 1) % nfft;
}
}
static void gst_strawberry_fastspectrum_input_data_mixed_double(const guint8 *_in, double *out, const guint64 len, const double max_value, guint op, const guint nfft) {
(void) max_value;
const gdouble *in = reinterpret_cast<const gdouble*>(_in);
guint ip = 0;
for (guint64 j = 0; j < len; j++) {
out[op] = in[ip++];
op = (op + 1) % nfft;
}
}
static void gst_strawberry_fastspectrum_input_data_mixed_int32_max(const guint8 *_in, double *out, const guint64 len, const double max_value, guint op, const guint nfft) {
const gint32 *in = reinterpret_cast<const gint32*>(_in);
guint ip = 0;
for (guint64 j = 0; j < len; j++) {
out[op] = in[ip++] / max_value;
op = (op + 1) % nfft;
}
}
static void gst_strawberry_fastspectrum_input_data_mixed_int24_max(const guint8 *_in, double *out, const guint64 len, const double max_value, guint op, const guint nfft) {
for (guint64 j = 0; j < len; j++) {
#if G_BYTE_ORDER == G_BIG_ENDIAN
guint32 value = GST_READ_UINT24_BE(_in);
#else
guint32 value = GST_READ_UINT24_LE(_in);
#endif
if (value & 0x00800000) {
value |= 0xff000000;
}
out[op] = value / max_value;
op = (op + 1) % nfft;
_in += 3;
}
}
static void gst_strawberry_fastspectrum_input_data_mixed_int16_max(const guint8 *_in, double *out, const guint64 len, const double max_value, guint op, const guint nfft) {
const gint16 *in = reinterpret_cast<const gint16*>(_in);
guint ip = 0;
for (guint64 j = 0; j < len; j++) {
out[op] = in[ip++] / max_value;
op = (op + 1) % nfft;
}
}
static gboolean gst_strawberry_fastspectrum_setup(GstAudioFilter *audio_filter, const GstAudioInfo *audio_info) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(audio_filter);
GstStrawberryFastSpectrumInputData input_data = nullptr;
g_mutex_lock(&fastspectrum->lock);
switch (GST_AUDIO_INFO_FORMAT(audio_info)) {
case GST_AUDIO_FORMAT_S16:
input_data = gst_strawberry_fastspectrum_input_data_mixed_int16_max;
break;
case GST_AUDIO_FORMAT_S24:
input_data = gst_strawberry_fastspectrum_input_data_mixed_int24_max;
break;
case GST_AUDIO_FORMAT_S32:
input_data = gst_strawberry_fastspectrum_input_data_mixed_int32_max;
break;
case GST_AUDIO_FORMAT_F32:
input_data = gst_strawberry_fastspectrum_input_data_mixed_float;
break;
case GST_AUDIO_FORMAT_F64:
input_data = gst_strawberry_fastspectrum_input_data_mixed_double;
break;
default:
g_assert_not_reached();
break;
}
fastspectrum->input_data = input_data;
gst_strawberry_fastspectrum_reset_state(fastspectrum);
g_mutex_unlock(&fastspectrum->lock);
return TRUE;
}
static void gst_strawberry_fastspectrum_run_fft(GstStrawberryFastSpectrum *fastspectrum, const guint input_pos) {
const guint bands = fastspectrum->bands;
const guint nfft = 2 * bands - 2;
for (guint i = 0; i < nfft; i++) {
fastspectrum->fft_input[i] = fastspectrum->input_ring_buffer[(input_pos + i) % nfft];
}
// Should be safe to execute the same plan multiple times in parallel.
fftw_execute(fastspectrum->plan);
// Calculate magnitude in db
for (guint i = 0; i < bands; i++) {
gdouble value = fastspectrum->fft_output[i][0] * fastspectrum->fft_output[i][0];
value += fastspectrum->fft_output[i][1] * fastspectrum->fft_output[i][1];
value /= nfft * nfft;
fastspectrum->spect_magnitude[i] += value;
}
}
static GstFlowReturn gst_strawberry_fastspectrum_transform_ip(GstBaseTransform *transform, GstBuffer *buffer) {
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(transform);
const guint rate = GST_AUDIO_FILTER_RATE(fastspectrum);
const guint bps = GST_AUDIO_FILTER_BPS(fastspectrum);
const guint64 bpf = GST_AUDIO_FILTER_BPF(fastspectrum);
const double max_value = static_cast<double>((1UL << ((bps << 3) - 1)) - 1);
const guint bands = fastspectrum->bands;
const guint nfft = 2 * bands - 2;
g_mutex_lock(&fastspectrum->lock);
GstMapInfo map;
gst_buffer_map(buffer, &map, GST_MAP_READ);
const guint8 *data = map.data;
gsize size = map.size;
GST_LOG_OBJECT(fastspectrum, "input size: %" G_GSIZE_FORMAT " bytes", size);
if (GST_BUFFER_IS_DISCONT(buffer)) {
GST_DEBUG_OBJECT(fastspectrum, "Discontinuity detected -- flushing");
gst_strawberry_fastspectrum_flush(fastspectrum);
}
// If we don't have a FFT context yet (or it was reset due to parameter changes) get one and allocate memory for everything
if (!fastspectrum->channel_data_initialized) {
GST_DEBUG_OBJECT(fastspectrum, "allocating for bands %u", bands);
gst_strawberry_fastspectrum_alloc_channel_data(fastspectrum);
// Number of sample frames we process before posting a message interval is in ns
fastspectrum->frames_per_interval = gst_util_uint64_scale(fastspectrum->interval, rate, GST_SECOND);
fastspectrum->frames_todo = fastspectrum->frames_per_interval;
// Rounding error for frames_per_interval in ns, aggregated it in accumulated_error
fastspectrum->error_per_interval = (fastspectrum->interval * rate) % GST_SECOND;
if (fastspectrum->frames_per_interval == 0) {
fastspectrum->frames_per_interval = 1;
}
GST_INFO_OBJECT(fastspectrum, "interval %" GST_TIME_FORMAT ", fpi %" G_GUINT64_FORMAT ", error %" GST_TIME_FORMAT, GST_TIME_ARGS(fastspectrum->interval), fastspectrum->frames_per_interval, GST_TIME_ARGS(fastspectrum->error_per_interval));
fastspectrum->input_pos = 0;
gst_strawberry_fastspectrum_flush(fastspectrum);
}
if (fastspectrum->num_frames == 0) {
fastspectrum->message_ts = GST_BUFFER_TIMESTAMP(buffer);
}
guint input_pos = fastspectrum->input_pos;
GstStrawberryFastSpectrumInputData input_data = fastspectrum->input_data;
while (size >= bpf) {
// Run input_data for a chunk of data
guint64 fft_todo = nfft - (fastspectrum->num_frames % nfft);
guint64 msg_todo = fastspectrum->frames_todo - fastspectrum->num_frames;
GST_LOG_OBJECT(fastspectrum, "message frames todo: %lu, fft frames todo: %lu, input frames %" G_GSIZE_FORMAT, msg_todo, fft_todo, (size / bpf));
guint64 block_size = msg_todo;
if (block_size > (size / bpf)) {
block_size = (size / bpf);
}
if (block_size > fft_todo) {
block_size = fft_todo;
}
// Move the current frames into our ringbuffers
input_data(data, fastspectrum->input_ring_buffer, block_size, max_value, input_pos, nfft);
data += block_size * bpf;
size -= block_size * bpf;
input_pos = (input_pos + block_size) % nfft;
fastspectrum->num_frames += block_size;
gboolean have_full_interval = (fastspectrum->num_frames == fastspectrum->frames_todo);
GST_LOG_OBJECT(fastspectrum, "size: %" G_GSIZE_FORMAT ", do-fft = %d, do-message = %d", size, (fastspectrum->num_frames % nfft == 0), have_full_interval);
// If we have enough frames for an FFT or we have all frames required for the interval and we haven't run a FFT, then run an FFT
if ((fastspectrum->num_frames % nfft == 0) || (have_full_interval && !fastspectrum->num_fft)) {
gst_strawberry_fastspectrum_run_fft(fastspectrum, input_pos);
fastspectrum->num_fft++;
}
// Do we have the FFTs for one interval?
if (have_full_interval) {
GST_DEBUG_OBJECT(fastspectrum, "nfft: %u frames: %" G_GUINT64_FORMAT " fpi: %" G_GUINT64_FORMAT " error: %" GST_TIME_FORMAT, nfft, fastspectrum->num_frames, fastspectrum->frames_per_interval, GST_TIME_ARGS(fastspectrum->accumulated_error));
fastspectrum->frames_todo = fastspectrum->frames_per_interval;
if (fastspectrum->accumulated_error >= GST_SECOND) {
fastspectrum->accumulated_error -= GST_SECOND;
fastspectrum->frames_todo++;
}
fastspectrum->accumulated_error += fastspectrum->error_per_interval;
if (fastspectrum->output_callback) {
// Calculate average
for (guint i = 0; i < fastspectrum->bands; i++) {
fastspectrum->spect_magnitude[i] /= static_cast<double>(fastspectrum->num_fft);
}
fastspectrum->output_callback(fastspectrum->spect_magnitude, static_cast<int>(fastspectrum->bands));
// Reset spectrum accumulators
memset(fastspectrum->spect_magnitude, 0, fastspectrum->bands * sizeof(double));
}
if (GST_CLOCK_TIME_IS_VALID(fastspectrum->message_ts)) {
fastspectrum->message_ts += gst_util_uint64_scale(fastspectrum->num_frames, GST_SECOND, rate);
}
fastspectrum->num_frames = 0;
fastspectrum->num_fft = 0;
}
}
fastspectrum->input_pos = input_pos;
gst_buffer_unmap(buffer, &map);
g_mutex_unlock(&fastspectrum->lock);
g_assert(size == 0);
return GST_FLOW_OK;
}

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
set(SOURCES KDSingleApplication/src/kdsingleapplication.cpp KDSingleApplication/src/kdsingleapplication_localsocket.cpp) set(SOURCES KDSingleApplication/src/kdsingleapplication.cpp KDSingleApplication/src/kdsingleapplication_localsocket.cpp)
set(HEADERS KDSingleApplication/src/kdsingleapplication.h KDSingleApplication/src/kdsingleapplication_localsocket_p.h) set(HEADERS KDSingleApplication/src/kdsingleapplication.h KDSingleApplication/src/kdsingleapplication_localsocket_p.h)
qt_wrap_cpp(MOC ${HEADERS}) qt_wrap_cpp(MOC ${HEADERS})

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
project(strawberry) project(strawberry)
@@ -84,13 +84,6 @@ add_compile_options(${COMPILE_OPTIONS})
if(CMAKE_BUILD_TYPE MATCHES "Release") if(CMAKE_BUILD_TYPE MATCHES "Release")
add_definitions(-DNDEBUG) add_definitions(-DNDEBUG)
set(ENABLE_DEBUG_OUTPUT_DEFAULT OFF)
else()
set(ENABLE_DEBUG_OUTPUT_DEFAULT ON)
endif()
option(ENABLE_DEBUG_OUTPUT "Enable debug output" ${ENABLE_DEBUG_OUTPUT_DEFAULT})
if(NOT ENABLE_DEBUG_OUTPUT)
add_definitions(-DQT_NO_DEBUG_OUTPUT) add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif() endif()
@@ -99,8 +92,6 @@ if(USE_RPATH)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif() endif()
set(QT_NO_SHOW_OLD_QT_WRAP_CPP_WARNING ON)
find_program(CCACHE_EXECUTABLE NAMES ccache) find_program(CCACHE_EXECUTABLE NAMES ccache)
if(CCACHE_EXECUTABLE) if(CCACHE_EXECUTABLE)
message(STATUS "ccache found: will be used for compilation and linkage") message(STATUS "ccache found: will be used for compilation and linkage")
@@ -165,14 +156,38 @@ find_package(FFTW3)
find_package(GTest) find_package(GTest)
find_library(GMOCK_LIBRARY gmock) find_library(GMOCK_LIBRARY gmock)
set(QT_VERSION_MAJOR 6) option(BUILD_WITH_QT5 "Build with Qt 5" OFF)
set(QT_MIN_VERSION 6.4.0) option(BUILD_WITH_QT6 "Build with Qt 6" OFF)
if(BUILD_WITH_QT6)
set(QT_VERSION_MAJOR 6)
elseif(BUILD_WITH_QT5)
set(QT_VERSION_MAJOR 5)
endif()
if(NOT QT_VERSION_MAJOR)
message(STATUS "QT_VERSION_MAJOR, BUILD_WITH_QT5 or BUILD_WITH_QT6 not set, detecting Qt version...")
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
endif()
if(QT_VERSION_MAJOR EQUAL 6)
set(QT_MIN_VERSION 6.0)
elseif(QT_VERSION_MAJOR EQUAL 5)
set(QT_MIN_VERSION 5.12)
else()
message(FATAL_ERROR "Invalid QT_VERSION_MAJOR.")
endif()
set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR}) set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR})
set(QT_COMPONENTS Core Concurrent Gui Widgets Network Sql) set(QT_COMPONENTS Core Concurrent Gui Widgets Network Sql)
set(QT_OPTIONAL_COMPONENTS LinguistTools Test) set(QT_OPTIONAL_COMPONENTS LinguistTools Test)
if(DBUS_FOUND AND NOT WIN32) if(DBUS_FOUND AND NOT WIN32)
list(APPEND QT_COMPONENTS DBus) list(APPEND QT_COMPONENTS DBus)
endif() endif()
if(X11_FOUND AND QT_VERSION_MAJOR EQUAL 5)
list(APPEND QT_COMPONENTS X11Extras)
endif()
find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} COMPONENTS ${QT_COMPONENTS} REQUIRED OPTIONAL_COMPONENTS ${QT_OPTIONAL_COMPONENTS}) find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} COMPONENTS ${QT_COMPONENTS} REQUIRED OPTIONAL_COMPONENTS ${QT_OPTIONAL_COMPONENTS})
@@ -182,6 +197,27 @@ endif()
if(Qt${QT_VERSION_MAJOR}LinguistTools_FOUND) if(Qt${QT_VERSION_MAJOR}LinguistTools_FOUND)
get_target_property(QT_LCONVERT_EXECUTABLE Qt${QT_VERSION_MAJOR}::lconvert LOCATION) get_target_property(QT_LCONVERT_EXECUTABLE Qt${QT_VERSION_MAJOR}::lconvert LOCATION)
endif() endif()
if(Qt${QT_VERSION_MAJOR}X11Extras_FOUND)
set(HAVE_X11EXTRAS ON)
endif()
if(QT_VERSION_MAJOR EQUAL 5 AND Qt5Core_VERSION VERSION_LESS 5.15.0)
macro(qt_add_resources)
qt5_add_resources(${ARGN})
endmacro()
macro(qt_wrap_cpp)
qt5_wrap_cpp(${ARGN})
endmacro()
macro(qt_wrap_ui)
qt5_wrap_ui(${ARGN})
endmacro()
macro(qt_add_dbus_adaptor)
qt5_add_dbus_adaptor(${ARGN})
endmacro()
macro(qt_add_dbus_interface)
qt5_add_dbus_interface(${ARGN})
endmacro()
endif()
if(X11_FOUND) if(X11_FOUND)
find_path(KEYSYMDEF_H NAMES "keysymdef.h" PATHS "${X11_INCLUDE_DIR}" PATH_SUFFIXES "X11") find_path(KEYSYMDEF_H NAMES "keysymdef.h" PATHS "${X11_INCLUDE_DIR}" PATH_SUFFIXES "X11")
@@ -206,19 +242,21 @@ if(X11_FOUND)
endif() endif()
# Check for QX11Application (Qt 6 compiled with XCB). # Check for QX11Application (Qt 6 compiled with XCB).
set(CMAKE_REQUIRED_FLAGS "-std=c++17") if(QT_VERSION_MAJOR EQUAL 6 AND Qt6Gui_VERSION VERSION_GREATER_EQUAL 6.2.0)
set(CMAKE_REQUIRED_LIBRARIES Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui) set(CMAKE_REQUIRED_FLAGS "-std=c++17")
check_cxx_source_compiles(" set(CMAKE_REQUIRED_LIBRARIES Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui)
check_cxx_source_compiles("
#include <QGuiApplication> #include <QGuiApplication>
int main() { int main() {
(void)qApp->nativeInterface<QNativeInterface::QX11Application>(); (void)qApp->nativeInterface<QNativeInterface::QX11Application>();
return 0; return 0;
} }
" "
HAVE_QX11APPLICATION HAVE_QX11APPLICATION
) )
unset(CMAKE_REQUIRED_FLAGS) unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES) unset(CMAKE_REQUIRED_LIBRARIES)
endif()
endif(X11_FOUND) endif(X11_FOUND)
@@ -234,7 +272,7 @@ if(USE_TAGLIB)
set(HAVE_TAGLIB_DSFFILE ON) set(HAVE_TAGLIB_DSFFILE ON)
set(HAVE_TAGLIB_DSDIFFFILE ON) set(HAVE_TAGLIB_DSDIFFFILE ON)
else() else()
pkg_check_modules(TAGLIB REQUIRED taglib>=1.12) pkg_check_modules(TAGLIB REQUIRED taglib>=1.11.1)
endif() endif()
set(HAVE_TAGLIB ON) set(HAVE_TAGLIB ON)
else() else()
@@ -256,10 +294,18 @@ if(NOT HAVE_TAGLIB AND NOT HAVE_TAGPARSER)
endif() endif()
# SingleApplication # SingleApplication
set(KDSINGLEAPPLICATION_NAME "KDSingleApplication-qt${QT_VERSION_MAJOR}") if(QT_VERSION_MAJOR EQUAL 5)
set(KDSINGLEAPPLICATION_NAME "KDSingleApplication")
else()
set(KDSINGLEAPPLICATION_NAME "KDSingleApplication-qt${QT_VERSION_MAJOR}")
endif()
find_package(${KDSINGLEAPPLICATION_NAME} 1.1.0) find_package(${KDSINGLEAPPLICATION_NAME} 1.1.0)
if(TARGET KDAB::kdsingleapplication) if(TARGET KDAB::kdsingleapplication)
set(KDSINGLEAPPLICATION_VERSION "${KDSingleApplication-qt6_VERSION}") if(QT_VERSION_MAJOR EQUAL 5)
set(KDSINGLEAPPLICATION_VERSION "${KDSingleApplication_VERSION}")
elseif(QT_VERSION_MAJOR EQUAL 6)
set(KDSINGLEAPPLICATION_VERSION "${KDSingleApplication-qt6_VERSION}")
endif()
message(STATUS "Using system KDSingleApplication (Version ${KDSINGLEAPPLICATION_VERSION})") message(STATUS "Using system KDSingleApplication (Version ${KDSINGLEAPPLICATION_VERSION})")
set(SINGLEAPPLICATION_LIBRARIES KDAB::kdsingleapplication) set(SINGLEAPPLICATION_LIBRARIES KDAB::kdsingleapplication)
else() else()
@@ -275,16 +321,23 @@ if(APPLE)
add_subdirectory(3rdparty/SPMediaKeyTap) add_subdirectory(3rdparty/SPMediaKeyTap)
set(SPMEDIAKEYTAP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/SPMediaKeyTap) set(SPMEDIAKEYTAP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/SPMediaKeyTap)
set(SPMEDIAKEYTAP_LIBRARIES SPMediaKeyTap) set(SPMEDIAKEYTAP_LIBRARIES SPMediaKeyTap)
add_subdirectory(ext/macdeploycheck)
endif() endif()
if(WIN32) if(WIN32)
find_package(getopt-win REQUIRED)
pkg_check_modules(QTSPARKLE qtsparkle-qt${QT_VERSION_MAJOR}) pkg_check_modules(QTSPARKLE qtsparkle-qt${QT_VERSION_MAJOR})
if(QTSPARKLE_FOUND) if(QTSPARKLE_FOUND)
set(HAVE_QTSPARKLE ON) set(HAVE_QTSPARKLE ON)
endif() endif()
endif() endif()
if(WIN32)
add_subdirectory(3rdparty/getopt)
set(GETOPT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/getopt)
set(GETOPT_LIBRARIES getopt)
add_definitions(-DSTATIC_GETOPT -D_UNICODE)
endif()
if(WIN32 AND NOT MSVC) if(WIN32 AND NOT MSVC)
# RC compiler # RC compiler
string(REPLACE "gcc" "windres" CMAKE_RC_COMPILER_INIT ${CMAKE_C_COMPILER}) string(REPLACE "gcc" "windres" CMAKE_RC_COMPILER_INIT ${CMAKE_C_COMPILER})
@@ -340,9 +393,12 @@ optional_component(GLOBALSHORTCUTS ON "Global shortcuts"
DEPENDS "D-Bus, X11, Windows or macOS" HAVE_GLOBALSHORTCUTS_SUPPORT DEPENDS "D-Bus, X11, Windows or macOS" HAVE_GLOBALSHORTCUTS_SUPPORT
) )
if(HAVE_QX11APPLICATION OR HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
set(X11_GLOBALSHORTCUTS_REQUIREMENT_FOUND ON)
endif()
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts"
DEPENDS "X11" X11_FOUND DEPENDS "X11" X11_FOUND
DEPENDS "QX11Application" HAVE_QX11APPLICATION DEPENDS "QX11Application, X11Extras or qpa/qplatformnativeinterface.h header" X11_GLOBALSHORTCUTS_REQUIREMENT_FOUND
) )
optional_component(AUDIOCD ON "Devices: Audio CD support" optional_component(AUDIOCD ON "Devices: Audio CD support"
@@ -438,8 +494,6 @@ add_definitions(
-DQT_NO_FOREACH -DQT_NO_FOREACH
-DQT_ASCII_CAST_WARNINGS -DQT_ASCII_CAST_WARNINGS
-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_ASCII
-DQT_NO_KEYWORDS
-DQT_NO_SIGNALS_SLOTS_KEYWORDS
) )
if(WIN32) if(WIN32)
@@ -456,7 +510,7 @@ add_subdirectory(ext/libstrawberry-common)
add_subdirectory(ext/libstrawberry-tagreader) add_subdirectory(ext/libstrawberry-tagreader)
add_subdirectory(ext/strawberry-tagreader) add_subdirectory(ext/strawberry-tagreader)
if(HAVE_MOODBAR) if(HAVE_MOODBAR)
add_subdirectory(3rdparty/gstfastspectrum) add_subdirectory(ext/gstmoodbar)
endif() endif()
if(GTest_FOUND AND GMOCK_LIBRARY AND Qt${QT_VERSION_MAJOR}Test_FOUND) if(GTest_FOUND AND GMOCK_LIBRARY AND Qt${QT_VERSION_MAJOR}Test_FOUND)
@@ -480,8 +534,16 @@ elseif(NOT HAVE_GSTREAMER)
message(WARNING "GStreamer is the only engine that is fully implemented. Using other engines is possible but not recommended.") message(WARNING "GStreamer is the only engine that is fully implemented. Using other engines is possible but not recommended.")
endif() endif()
if(QT_VERSION_MAJOR EQUAL 5)
message(WARNING "It is detected that Strawberry is being built with Qt 5. There are no bugfix releases for the latest minor LTS version of Qt 5 available to open-source users, only commercial users. Therefore Strawberry should be built with Qt 6 when possible. Building with Qt 6 will also take advantage of improvements and new features not available in Qt 5. To build with Qt 6 specify -DBUILD_WITH_QT6=ON to automatically detect Qt 6, or for example -DCMAKE_PREFIX_PATH=/usr/local/lib64/cmake to manually specify the Qt 6 directory.")
endif()
if(NOT CMAKE_CROSSCOMPILING) if(NOT CMAKE_CROSSCOMPILING)
if(NOT QT_SQLITE_TEST) if(NOT QT_SQLITE_TEST)
message(WARNING "The Qt sqlite driver test failed.") message(WARNING "The Qt sqlite driver test failed.")
endif() endif()
endif() endif()
if(HAVE_TAGLIB AND TAGLIB_FOUND AND NOT TAGLIB_VERSION VERSION_GREATER_EQUAL 1.12)
message(WARNING "There is a critical bug in TagLib (1.11.1) that can result in corrupt Ogg files, see: https://github.com/taglib/taglib/issues/864, please consider updating TagLib to the newest version.")
endif()

View File

@@ -2,44 +2,17 @@ Strawberry Music Player
======================= =======================
ChangeLog ChangeLog
Version 1.1.3 (2024.09.21): Unreleased:
Bugfixes:
* Fixed gstreamer registry lookup leak in Spotify settings.
* Fixed all songs in a CUE sheet starting playback at the zero position (#1549).
* Fixed playback going to pause and back to play on song change.
* Fixed Genius Lyrics login not working (#1554).
* Fixed slow collection filter search.
Version 1.1.2 (2024.09.12):
Bugfixes: Bugfixes:
* Fixed Tidal Open API cover provider to only login when needed instead of on startup. * Fixed Tidal Open API cover provider to only login when needed instead of on startup.
* Fixed KDE added keyboard accelerator characters (ampersands) appearing in sidebar (#1400, #1389, #1476). * Fixed KDE added keyboard accelerator characters (ampersands) appearing in sidebar (#1400, #1389, #1476).
* Fixed KDE added keyboard accelerator characters (ampersands) appearing when editing playlist name (#1499). * Fixed KDE added keyboard accelerator characters (ampersands) appearing when editing playlist name (#1499).
* Fixed collection "Search for this" adding prefix without value (#1510). * Fixed collection "Search for this" adding prefix without value (#1510).
* Fixed play (-p) command line option not working on startup (#1465). * (macOS) Fixed missing Spotify.
* Fixed scan transaction being started when "Update the collection when Strawberry starts" option is unchecked (#1469)
* Fixed Spotify bitrate being limited 128kbit/s.
* Fixed Spotify returning too many artists and albums.
* Fixed manually switching Spotify songs blocking UI.
* Fixed analyzer not being set.
* Fixed context top text being updated causing selected text to be unselected.
* Fixed filter search to use filename for songs with empty title.
* Fixed missing developer in Appstream appdata file.
* Fixed MPRIS2 DesktopEntry to return desktop file entry without ".desktop" (#1516)
* Fixed WavPack .wvc accepted as valid audio files (#1525).
* Fixed dynamic playlist controls not following system colors (#1483).
* Fixed freeze on playlist right click (#1478).
* Fixed copying songs to a iPod device keeping too many files open (#1527).
* Fixed MBIDs from MP4 being parsed incorrectly causing ListenBrainz errors (#1531).
* Fixed playlist sorting after filename (#1538).
Enhancements: Enhancements:
* Improved volume adjustment and track seeking using touchpad (#1498). * Improved volume adjustment and track seeking using touchpad (#1498).
* Use own thread for lyrics parsing.
* Added url and filename columns to collection and playlist filter search.
* (macOS) Added Spotify.
Version 1.1.1 (2024.07.22): Version 1.1.1 (2024.07.22):

View File

@@ -14,6 +14,7 @@ Resources:
* Wiki: https://wiki.strawberrymusicplayer.org/ * Wiki: https://wiki.strawberrymusicplayer.org/
* Forum: https://forum.strawberrymusicplayer.org/ * Forum: https://forum.strawberrymusicplayer.org/
* Github: https://github.com/strawberrymusicplayer/strawberry * Github: https://github.com/strawberrymusicplayer/strawberry
* Buildbot: https://buildbot.strawberrymusicplayer.org/
* Latest builds: https://builds.strawberrymusicplayer.org/ * Latest builds: https://builds.strawberrymusicplayer.org/
* openSUSE buildservice: https://build.opensuse.org/package/show/home:jonaski:audio/strawberry * openSUSE buildservice: https://build.opensuse.org/package/show/home:jonaski:audio/strawberry
* Ubuntu PPA: https://launchpad.net/~jonaski/+archive/ubuntu/strawberry * Ubuntu PPA: https://launchpad.net/~jonaski/+archive/ubuntu/strawberry
@@ -75,7 +76,7 @@ To build Strawberry from source you need the following installed on your system
* [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) or [pkgconf](https://github.com/pkgconf/pkgconf) * [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) or [pkgconf](https://github.com/pkgconf/pkgconf)
* [Boost](https://www.boost.org/) * [Boost](https://www.boost.org/)
* [GLib](https://developer.gnome.org/glib/) * [GLib](https://developer.gnome.org/glib/)
* [Qt 6.4.0 or higher with components Core, Gui, Widgets, Concurrent, Network and Sql](https://www.qt.io/) * [Qt 6 or Qt 5.12 or higher with components Core, Gui, Widgets, Concurrent, Network and Sql](https://www.qt.io/)
* [SQLite 3.9 or newer](https://www.sqlite.org) * [SQLite 3.9 or newer](https://www.sqlite.org)
* [Protobuf](https://developers.google.com/protocol-buffers/) * [Protobuf](https://developers.google.com/protocol-buffers/)
* [ALSA (Required on Linux)](https://www.alsa-project.org/) * [ALSA (Required on Linux)](https://www.alsa-project.org/)
@@ -107,10 +108,14 @@ You should also install the gstreamer plugins base and good, and optionally bad,
cd strawberry cd strawberry
mkdir build mkdir build
cd build cd build
cmake .. cmake .. -DBUILD_WITH_QT6=ON
make -j $(nproc) make -j $(nproc)
sudo make install sudo make install
Strawberry is backwards compatible with Qt 5, to compile with Qt 5 use:
cmake .. -DBUILD_WITH_QT5=ON
To compile on Windows with Visual Studio 2019 or 2022, see https://github.com/strawberrymusicplayer/strawberry-msvc To compile on Windows with Visual Studio 2019 or 2022, see https://github.com/strawberrymusicplayer/strawberry-msvc
### :penguin: Packaging status ### :penguin: Packaging status

View File

@@ -1,17 +1,10 @@
find_program(MACDEPLOYQT_EXECUTABLE NAMES macdeployqt PATHS /usr/bin /usr/local/bin /opt/local/bin /usr/local/opt/qt6/bin REQUIRED) find_program(MACDEPLOYQT_EXECUTABLE NAMES macdeployqt PATHS /usr/bin /usr/local/bin /opt/local/bin /usr/local/opt/qt6/bin /usr/local/opt/qt5/bin REQUIRED)
if(MACDEPLOYQT_EXECUTABLE) if(MACDEPLOYQT_EXECUTABLE)
message(STATUS "Found macdeployqt: ${MACDEPLOYQT_EXECUTABLE}") message(STATUS "Found macdeployqt: ${MACDEPLOYQT_EXECUTABLE}")
else() else()
message(WARNING "Missing macdeployqt executable.") message(WARNING "Missing macdeployqt executable.")
endif() endif()
find_program(MACDEPLOYCHECK_EXECUTABLE NAMES macdeploycheck PATHS /usr/bin /usr/local/bin /opt/local/bin /usr/local/opt/qt6/bin REQUIRED)
if(MACDEPLOYCHECK_EXECUTABLE)
message(STATUS "Found macdeploycheck: ${MACDEPLOYCHECK_EXECUTABLE}")
else()
message(WARNING "Missing macdeploycheck executable.")
endif()
find_program(CREATEDMG_EXECUTABLE NAMES create-dmg REQUIRED) find_program(CREATEDMG_EXECUTABLE NAMES create-dmg REQUIRED)
if(CREATEDMG_EXECUTABLE) if(CREATEDMG_EXECUTABLE)
message(STATUS "Found create-dmg: ${CREATEDMG_EXECUTABLE}") message(STATUS "Found create-dmg: ${CREATEDMG_EXECUTABLE}")
@@ -38,11 +31,10 @@ if(MACDEPLOYQT_EXECUTABLE)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS strawberry strawberry-tagreader DEPENDS strawberry strawberry-tagreader
) )
if(MACDEPLOYCHECK_EXECUTABLE) add_custom_target(deploycheck
add_custom_target(deploycheck COMMAND ${CMAKE_BINARY_DIR}/ext/macdeploycheck/macdeploycheck strawberry.app
COMMAND ${MACDEPLOYCHECK_EXECUTABLE} strawberry.app DEPENDS macdeploycheck
) )
endif()
if(CREATEDMG_EXECUTABLE) if(CREATEDMG_EXECUTABLE)
add_custom_target(dmg add_custom_target(dmg
COMMAND ${CREATEDMG_EXECUTABLE} --volname strawberry --background "${CMAKE_SOURCE_DIR}/dist/macos/dmg_background.png" --app-drop-link 450 218 --icon strawberry.app 150 218 --window-size 600 450 ${CREATEDMG_CODESIGN} ${CREATEDMG_SKIP_JENKINS_ARG} strawberry-${STRAWBERRY_VERSION_PACKAGE}-${CMAKE_HOST_SYSTEM_PROCESSOR}.dmg strawberry.app COMMAND ${CREATEDMG_EXECUTABLE} --volname strawberry --background "${CMAKE_SOURCE_DIR}/dist/macos/dmg_background.png" --app-drop-link 450 218 --icon strawberry.app 150 218 --window-size 600 450 ${CREATEDMG_CODESIGN} ${CREATEDMG_SKIP_JENKINS_ARG} strawberry-${STRAWBERRY_VERSION_PACKAGE}-${CMAKE_HOST_SYSTEM_PROCESSOR}.dmg strawberry.app

View File

@@ -44,7 +44,7 @@ macro(add_pot outfiles header pot)
add_custom_command( add_custom_command(
OUTPUT ${pot} OUTPUT ${pot}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} ${XGETTEXT_OPTIONS} -C --omit-header --no-location --output="${CMAKE_CURRENT_BINARY_DIR}/pot.temp" ${add_pot_sources} COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} ${XGETTEXT_OPTIONS} -s -C --omit-header --output="${CMAKE_CURRENT_BINARY_DIR}/pot.temp" ${add_pot_sources}
COMMAND cat ${header} ${CMAKE_CURRENT_BINARY_DIR}/pot.temp > ${pot} COMMAND cat ${header} ${CMAKE_CURRENT_BINARY_DIR}/pot.temp > ${pot}
DEPENDS ${add_pot_sources} ${header} DEPENDS ${add_pot_sources} ${header}
) )

View File

@@ -1,6 +1,6 @@
set(STRAWBERRY_VERSION_MAJOR 1) set(STRAWBERRY_VERSION_MAJOR 1)
set(STRAWBERRY_VERSION_MINOR 2) set(STRAWBERRY_VERSION_MINOR 1)
set(STRAWBERRY_VERSION_PATCH 0) set(STRAWBERRY_VERSION_PATCH 1)
#set(STRAWBERRY_VERSION_PRERELEASE rc1) #set(STRAWBERRY_VERSION_PRERELEASE rc1)
set(INCLUDE_GIT_REVISION ON) set(INCLUDE_GIT_REVISION ON)

View File

@@ -45,6 +45,5 @@
<file>mood/sample.mood</file> <file>mood/sample.mood</file>
<file>text/ghosts.txt</file> <file>text/ghosts.txt</file>
<file>pictures/sidebar-background.png</file> <file>pictures/sidebar-background.png</file>
<file>style/dynamicplaylistcontrols.css</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@@ -1,13 +0,0 @@
#container {
background: %background;
border-radius: 10px;
border: 1px solid rgba(200, 200, 200, 75%);
}
#label1 {
font-weight: bold;
}
#label2 {
font-size: 7.5pt;
}

12
debian/CMakeLists.txt vendored
View File

@@ -4,7 +4,19 @@ if(LSB_RELEASE_EXEC AND DPKG_BUILDPACKAGE)
execute_process(COMMAND /bin/sh "-c" "${LSB_RELEASE_EXEC} -cs" OUTPUT_VARIABLE DEB_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND /bin/sh "-c" "${LSB_RELEASE_EXEC} -cs" OUTPUT_VARIABLE DEB_CODENAME OUTPUT_STRIP_TRAILING_WHITESPACE)
if(DEB_CODENAME AND DEB_DATE) if(DEB_CODENAME AND DEB_DATE)
if(QT_VERSION_MAJOR EQUAL 5)
set(DEBIAN_BUILD_DEPENDS_QT_PACKAGES qtbase5-dev,qtbase5-dev-tools,qttools5-dev,qttools5-dev-tools,libqt5x11extras5-dev)
set(DEBIAN_DEPENDS_QT_PACKAGES libqt5sql5-sqlite)
endif()
if(QT_VERSION_MAJOR EQUAL 6)
set(DEBIAN_BUILD_DEPENDS_QT_PACKAGES qt6-base-dev,qt6-base-dev-tools,qt6-tools-dev,qt6-tools-dev-tools,qt6-l10n-tools)
set(DEBIAN_DEPENDS_QT_PACKAGES libqt6sql6-sqlite,qt6-qpa-plugins)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.in ${CMAKE_CURRENT_SOURCE_DIR}/control @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/changelog.in ${CMAKE_CURRENT_SOURCE_DIR}/changelog) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/changelog.in ${CMAKE_CURRENT_SOURCE_DIR}/changelog)
endif() endif()
endif() endif()

View File

@@ -18,11 +18,7 @@ Build-Depends: debhelper (>= 11),
libpulse-dev, libpulse-dev,
libtag1-dev, libtag1-dev,
libicu-dev, libicu-dev,
qt6-base-dev, @DEBIAN_BUILD_DEPENDS_QT_PACKAGES@,
qt6-base-dev-tools,
qt6-tools-dev,
qt6-tools-dev-tools,
qt6-l10n-tools,
libgstreamer1.0-dev, libgstreamer1.0-dev,
libgstreamer-plugins-base1.0-dev, libgstreamer-plugins-base1.0-dev,
libcdio-dev, libcdio-dev,
@@ -37,8 +33,7 @@ Package: strawberry
Architecture: any Architecture: any
Depends: ${shlibs:Depends}, Depends: ${shlibs:Depends},
${misc:Depends}, ${misc:Depends},
libqt6sql6-sqlite, @DEBIAN_DEPENDS_QT_PACKAGES@,
qt6-qpa-plugins,
gstreamer1.0-plugins-base, gstreamer1.0-plugins-base,
gstreamer1.0-plugins-good, gstreamer1.0-plugins-good,
gstreamer1.0-alsa, gstreamer1.0-alsa,

1
debian/copyright vendored
View File

@@ -95,6 +95,7 @@ Files: src/core/main.h
src/transcoder/transcoderoptionswavpack.h src/transcoder/transcoderoptionswavpack.h
ext/libstrawberry-tagreader/tagreadertagparser.cpp ext/libstrawberry-tagreader/tagreadertagparser.cpp
ext/libstrawberry-tagreader/tagreadertagparser.h ext/libstrawberry-tagreader/tagreadertagparser.h
ext/macdeploycheck/*
src/widgets/resizabletextedit.cpp src/widgets/resizabletextedit.cpp
src/widgets/resizabletextedit.h src/widgets/resizabletextedit.h
Copyright: 2012-2014, 2017-2023, Jonas Kvinge <jonas@jkvinge.net> Copyright: 2012-2014, 2017-2023, Jonas Kvinge <jonas@jkvinge.net>

View File

@@ -12,14 +12,11 @@
<summary>A music player and collection organizer</summary> <summary>A music player and collection organizer</summary>
<url type="homepage">https://www.strawberrymusicplayer.org/</url> <url type="homepage">https://www.strawberrymusicplayer.org/</url>
<url type="bugtracker">https://github.com/strawberrymusicplayer/strawberry/</url> <url type="bugtracker">https://github.com/strawberrymusicplayer/strawberry/</url>
<developer id="net.jkvinge.jonas"> <translation type="qt">strawberry</translation>
<name>Jonas Kvinge</name>
</developer>
<translation type="gettext">strawberry</translation>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<description> <description>
<p> <p>
Strawberry is a music player and music collection organizer. It is aimed at music collectors and audiophiles. Strawberry is free software released under GPL. It's written in C++ using the Qt framework and GStreamer. Strawberry is a music player and music collection organizer. It is aimed at music collectors and audiophiles. With Strawberry you can play and manage your digital music collection, or stream your favorite radios. It also has unofficial streaming support for Tidal and Qobuz. Strawberry is free software released under GPL. The source code is available on GitHub. It's written in C++ using the Qt toolkit and GStreamer. Strawberry is compatible with both Qt version 5 and 6.
</p> </p>
<p>Features:</p> <p>Features:</p>
<ul> <ul>
@@ -33,11 +30,12 @@
<li>Automatically retrieve tags from MusicBrainz</li> <li>Automatically retrieve tags from MusicBrainz</li>
<li>Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify</li> <li>Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify</li>
<li>Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net</li> <li>Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net</li>
<li>Support for multiple backends</li>
<li>Audio analyzer and equalizer</li> <li>Audio analyzer and equalizer</li>
<li>Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic</li> <li>Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic</li>
<li>Scrobbler with support for Last.fm, Libre.fm and ListenBrainz</li> <li>Scrobbler with support for Last.fm, Libre.fm and ListenBrainz</li>
<li>Streaming support for Subsonic-compatible servers</li> <li>Streaming support for Subsonic-compatible servers</li>
<li>Unofficial streaming support for Tidal, Spotify and Qobuz</li> <li>Unofficial streaming support for Tidal and Qobuz</li>
</ul> </ul>
</description> </description>
<screenshots> <screenshots>
@@ -52,8 +50,6 @@
</screenshots> </screenshots>
<update_contact>eclipseo@fedoraproject.org</update_contact> <update_contact>eclipseo@fedoraproject.org</update_contact>
<releases> <releases>
<release version="1.1.3" date="2024-09-21"/>
<release version="1.1.2" date="2024-09-12"/>
<release version="1.1.1" date="2024-07-22"/> <release version="1.1.1" date="2024-07-22"/>
<release version="1.1.0" date="2024-07-14"/> <release version="1.1.0" date="2024-07-14"/>
<release version="1.0.23" date="2024-01-11"/> <release version="1.0.23" date="2024-01-11"/>

View File

@@ -55,6 +55,9 @@ BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Gui)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Widgets) BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Widgets)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Test) BuildRequires: cmake(Qt@QT_VERSION_MAJOR@Test)
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@LinguistTools) BuildRequires: cmake(Qt@QT_VERSION_MAJOR@LinguistTools)
%if "@QT_VERSION_MAJOR@" == "5"
BuildRequires: cmake(Qt@QT_VERSION_MAJOR@X11Extras)
%endif
BuildRequires: pkgconfig(gstreamer-1.0) BuildRequires: pkgconfig(gstreamer-1.0)
BuildRequires: pkgconfig(gstreamer-app-1.0) BuildRequires: pkgconfig(gstreamer-app-1.0)
BuildRequires: pkgconfig(gstreamer-audio-1.0) BuildRequires: pkgconfig(gstreamer-audio-1.0)
@@ -71,8 +74,13 @@ BuildRequires: pkgconfig(libvlc)
%endif %endif
%if 0%{?suse_version} %if 0%{?suse_version}
%if "@QT_VERSION_MAJOR@" == "6"
Requires: qt6-sql-sqlite Requires: qt6-sql-sqlite
Requires: qt6-network-tls Requires: qt6-network-tls
%endif
%if "@QT_VERSION_MAJOR@" == "5"
Requires: libQt5Sql5-sqlite
%endif
%endif %endif
%description %description

View File

@@ -261,7 +261,6 @@ Section "Strawberry" Strawberry
File "libFLAC-12.dll" File "libFLAC-12.dll"
File "libbrotlicommon.dll" File "libbrotlicommon.dll"
File "libbrotlidec.dll" File "libbrotlidec.dll"
File "libbrotlienc.dll"
File "libbs2b-0.dll" File "libbs2b-0.dll"
File "libbz2.dll" File "libbz2.dll"
File "libchromaprint.dll" File "libchromaprint.dll"
@@ -273,7 +272,6 @@ Section "Strawberry" Strawberry
File "libffi-8.dll" File "libffi-8.dll"
File "libfreetype-6.dll" File "libfreetype-6.dll"
File "libgcrypt-20.dll" File "libgcrypt-20.dll"
File "libgetopt.dll"
File "libgio-2.0-0.dll" File "libgio-2.0-0.dll"
File "libglib-2.0-0.dll" File "libglib-2.0-0.dll"
File "libgme.dll" File "libgme.dll"
@@ -330,7 +328,6 @@ Section "Strawberry" Strawberry
File "libtasn1-6.dll" File "libtasn1-6.dll"
File "libtwolame-0.dll" File "libtwolame-0.dll"
File "libunistring-5.dll" File "libunistring-5.dll"
File "libutf8_validity.dll"
File "libvorbis-0.dll" File "libvorbis-0.dll"
File "libvorbisenc-2.dll" File "libvorbisenc-2.dll"
File "libvorbisfile-3.dll" File "libvorbisfile-3.dll"
@@ -412,7 +409,6 @@ Section "Strawberry" Strawberry
!endif !endif
File "FLAC.dll" File "FLAC.dll"
File "abseil_dll.dll"
File "brotlicommon.dll" File "brotlicommon.dll"
File "brotlidec.dll" File "brotlidec.dll"
File "chromaprint.dll" File "chromaprint.dll"
@@ -420,7 +416,6 @@ Section "Strawberry" Strawberry
File "faad-2.dll" File "faad-2.dll"
File "fdk-aac.dll" File "fdk-aac.dll"
File "ffi-7.dll" File "ffi-7.dll"
File "getopt.dll"
File "gio-2.0-0.dll" File "gio-2.0-0.dll"
File "glib-2.0-0.dll" File "glib-2.0-0.dll"
File "gme.dll" File "gme.dll"
@@ -466,10 +461,10 @@ Section "Strawberry" Strawberry
File "soup-3.0-0.dll" File "soup-3.0-0.dll"
File "sqlite3.dll" File "sqlite3.dll"
File "tag.dll" File "tag.dll"
File "utf8_validity.dll"
File "vorbis.dll" File "vorbis.dll"
File "vorbisfile.dll" File "vorbisfile.dll"
File "wavpackdll.dll" File "wavpackdll.dll"
File "abseil_dll.dll"
!ifdef release !ifdef release
File "freetype.dll" File "freetype.dll"
@@ -531,13 +526,13 @@ Section "Strawberry" Strawberry
File "Qt6Widgets.dll" File "Qt6Widgets.dll"
!endif !endif
File "avcodec-61.dll" File "avcodec-60.dll"
File "avfilter-10.dll" File "avfilter-9.dll"
File "avformat-61.dll" File "avformat-60.dll"
File "avutil-59.dll" File "avutil-58.dll"
File "postproc-58.dll" File "postproc-57.dll"
File "swresample-5.dll" File "swresample-4.dll"
File "swscale-8.dll" File "swscale-7.dll"
; Register Strawberry with Default Programs ; Register Strawberry with Default Programs
Var /GLOBAL AppIcon Var /GLOBAL AppIcon
@@ -836,7 +831,6 @@ Section "Uninstall"
Delete "$INSTDIR\libFLAC-12.dll" Delete "$INSTDIR\libFLAC-12.dll"
Delete "$INSTDIR\libbrotlicommon.dll" Delete "$INSTDIR\libbrotlicommon.dll"
Delete "$INSTDIR\libbrotlidec.dll" Delete "$INSTDIR\libbrotlidec.dll"
Delete "$INSTDIR\libbrotlienc.dll"
Delete "$INSTDIR\libbs2b-0.dll" Delete "$INSTDIR\libbs2b-0.dll"
Delete "$INSTDIR\libbz2.dll" Delete "$INSTDIR\libbz2.dll"
Delete "$INSTDIR\libchromaprint.dll" Delete "$INSTDIR\libchromaprint.dll"
@@ -848,7 +842,6 @@ Section "Uninstall"
Delete "$INSTDIR\libffi-8.dll" Delete "$INSTDIR\libffi-8.dll"
Delete "$INSTDIR\libfreetype-6.dll" Delete "$INSTDIR\libfreetype-6.dll"
Delete "$INSTDIR\libgcrypt-20.dll" Delete "$INSTDIR\libgcrypt-20.dll"
Delete "$INSTDIR\libgetopt.dll"
Delete "$INSTDIR\libgio-2.0-0.dll" Delete "$INSTDIR\libgio-2.0-0.dll"
Delete "$INSTDIR\libglib-2.0-0.dll" Delete "$INSTDIR\libglib-2.0-0.dll"
Delete "$INSTDIR\libgme.dll" Delete "$INSTDIR\libgme.dll"
@@ -905,7 +898,6 @@ Section "Uninstall"
Delete "$INSTDIR\libtasn1-6.dll" Delete "$INSTDIR\libtasn1-6.dll"
Delete "$INSTDIR\libtwolame-0.dll" Delete "$INSTDIR\libtwolame-0.dll"
Delete "$INSTDIR\libunistring-5.dll" Delete "$INSTDIR\libunistring-5.dll"
Delete "$INSTDIR\libutf8_validity.dll"
Delete "$INSTDIR\libvorbis-0.dll" Delete "$INSTDIR\libvorbis-0.dll"
Delete "$INSTDIR\libvorbisenc-2.dll" Delete "$INSTDIR\libvorbisenc-2.dll"
Delete "$INSTDIR\libvorbisfile-3.dll" Delete "$INSTDIR\libvorbisfile-3.dll"
@@ -987,7 +979,6 @@ Section "Uninstall"
!endif !endif
Delete "$INSTDIR\FLAC.dll" Delete "$INSTDIR\FLAC.dll"
Delete "$INSTDIR\abseil_dll.dll"
Delete "$INSTDIR\brotlicommon.dll" Delete "$INSTDIR\brotlicommon.dll"
Delete "$INSTDIR\brotlidec.dll" Delete "$INSTDIR\brotlidec.dll"
Delete "$INSTDIR\chromaprint.dll" Delete "$INSTDIR\chromaprint.dll"
@@ -995,7 +986,6 @@ Section "Uninstall"
Delete "$INSTDIR\faad-2.dll" Delete "$INSTDIR\faad-2.dll"
Delete "$INSTDIR\fdk-aac.dll" Delete "$INSTDIR\fdk-aac.dll"
Delete "$INSTDIR\ffi-7.dll" Delete "$INSTDIR\ffi-7.dll"
Delete "$INSTDIR\getopt.dll"
Delete "$INSTDIR\gio-2.0-0.dll" Delete "$INSTDIR\gio-2.0-0.dll"
Delete "$INSTDIR\glib-2.0-0.dll" Delete "$INSTDIR\glib-2.0-0.dll"
Delete "$INSTDIR\gme.dll" Delete "$INSTDIR\gme.dll"
@@ -1041,10 +1031,10 @@ Section "Uninstall"
Delete "$INSTDIR\soup-3.0-0.dll" Delete "$INSTDIR\soup-3.0-0.dll"
Delete "$INSTDIR\sqlite3.dll" Delete "$INSTDIR\sqlite3.dll"
Delete "$INSTDIR\tag.dll" Delete "$INSTDIR\tag.dll"
Delete "$INSTDIR\utf8_validity.dll"
Delete "$INSTDIR\vorbis.dll" Delete "$INSTDIR\vorbis.dll"
Delete "$INSTDIR\vorbisfile.dll" Delete "$INSTDIR\vorbisfile.dll"
Delete "$INSTDIR\wavpackdll.dll" Delete "$INSTDIR\wavpackdll.dll"
Delete "$INSTDIR\abseil_dll.dll"
!ifdef release !ifdef release
Delete "$INSTDIR\freetype.dll" Delete "$INSTDIR\freetype.dll"
@@ -1105,13 +1095,13 @@ Section "Uninstall"
Delete "$INSTDIR\Qt6Widgets.dll" Delete "$INSTDIR\Qt6Widgets.dll"
!endif !endif
Delete "$INSTDIR\avcodec-61.dll" Delete "$INSTDIR\avcodec-60.dll"
Delete "$INSTDIR\avfilter-10.dll" Delete "$INSTDIR\avfilter-9.dll"
Delete "$INSTDIR\avformat-61.dll" Delete "$INSTDIR\avformat-60.dll"
Delete "$INSTDIR\avutil-59.dll" Delete "$INSTDIR\avutil-58.dll"
Delete "$INSTDIR\postproc-58.dll" Delete "$INSTDIR\postproc-57.dll"
Delete "$INSTDIR\swresample-5.dll" Delete "$INSTDIR\swresample-4.dll"
Delete "$INSTDIR\swscale-8.dll" Delete "$INSTDIR\swscale-7.dll"
!ifdef mingw !ifdef mingw
Delete "$INSTDIR\gio-modules\libgiognutls.dll" Delete "$INSTDIR\gio-modules\libgiognutls.dll"

View File

@@ -1,21 +1,8 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
set(SOURCES gstfastspectrum.cpp) set(SOURCES gstfastspectrum.cpp gstmoodbarplugin.cpp)
add_library(gstfastspectrum STATIC ${SOURCES}) link_directories(
target_include_directories(gstfastspectrum SYSTEM PRIVATE
${GLIB_INCLUDE_DIRS}
${GOBJECT_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS}
${GSTREAMER_BASE_INCLUDE_DIRS}
${GSTREAMER_AUDIO_INCLUDE_DIRS}
${FFTW3_INCLUDE_DIR}
)
target_include_directories(gstfastspectrum PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_directories(gstfastspectrum PRIVATE
${GLIB_LIBRARY_DIRS} ${GLIB_LIBRARY_DIRS}
${GOBJECT_LIBRARY_DIRS} ${GOBJECT_LIBRARY_DIRS}
${GSTREAMER_LIBRARY_DIRS} ${GSTREAMER_LIBRARY_DIRS}
@@ -24,11 +11,25 @@ target_link_directories(gstfastspectrum PRIVATE
${FFTW3_LIBRARY_DIRS} ${FFTW3_LIBRARY_DIRS}
) )
target_link_libraries(gstfastspectrum PRIVATE add_library(gstmoodbar STATIC ${SOURCES})
target_include_directories(gstmoodbar SYSTEM PRIVATE
${GLIB_INCLUDE_DIRS}
${GOBJECT_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS}
${GSTREAMER_BASE_INCLUDE_DIRS}
${GSTREAMER_AUDIO_INCLUDE_DIRS}
${FFTW3_INCLUDE_DIR}
)
target_include_directories(gstmoodbar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(gstmoodbar PRIVATE
${GLIB_LIBRARIES} ${GLIB_LIBRARIES}
${GOBJECT_LIBRARIES} ${GOBJECT_LIBRARIES}
${GSTREAMER_LIBRARIES} ${GSTREAMER_LIBRARIES}
${GSTREAMER_BASE_LIBRARIES} ${GSTREAMER_BASE_LIBRARIES}
${GSTREAMER_AUDIO_LIBRARIES} ${GSTREAMER_AUDIO_LIBRARIES}
${FFTW3_FFTW_LIBRARY} ${FFTW3_FFTW_LIBRARY}
Qt${QT_VERSION_MAJOR}::Core
) )

View File

@@ -0,0 +1,520 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* <2006,2011> Stefan Kost <ensonic@users.sf.net>
* <2007-2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QtGlobal>
#include <cstring>
#include <cmath>
#include <glib.h>
#include <gst/gst.h>
#include <gst/audio/gstaudiofilter.h>
#include <QMutex>
#include "gstfastspectrum.h"
GST_DEBUG_CATEGORY_STATIC(gst_fastspectrum_debug);
namespace {
// Spectrum properties
constexpr auto DEFAULT_INTERVAL = (GST_SECOND / 10);
constexpr auto DEFAULT_BANDS = 128;
enum {
PROP_0,
PROP_INTERVAL,
PROP_BANDS
};
} // namespace
#define gst_fastspectrum_parent_class parent_class
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
G_DEFINE_TYPE(GstFastSpectrum, gst_fastspectrum, GST_TYPE_AUDIO_FILTER)
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static void gst_fastspectrum_finalize(GObject *object);
static void gst_fastspectrum_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void gst_fastspectrum_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static gboolean gst_fastspectrum_start(GstBaseTransform *trans);
static gboolean gst_fastspectrum_stop(GstBaseTransform *trans);
static GstFlowReturn gst_fastspectrum_transform_ip(GstBaseTransform *trans, GstBuffer *buffer);
static gboolean gst_fastspectrum_setup(GstAudioFilter *base, const GstAudioInfo *info);
static void gst_fastspectrum_class_init(GstFastSpectrumClass *klass) {
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS(klass);
GstAudioFilterClass *filter_class = GST_AUDIO_FILTER_CLASS(klass);
GstCaps *caps = nullptr;
gobject_class->set_property = gst_fastspectrum_set_property;
gobject_class->get_property = gst_fastspectrum_get_property;
gobject_class->finalize = gst_fastspectrum_finalize;
trans_class->start = GST_DEBUG_FUNCPTR(gst_fastspectrum_start);
trans_class->stop = GST_DEBUG_FUNCPTR(gst_fastspectrum_stop);
trans_class->transform_ip = GST_DEBUG_FUNCPTR(gst_fastspectrum_transform_ip);
trans_class->passthrough_on_same_caps = TRUE;
filter_class->setup = GST_DEBUG_FUNCPTR(gst_fastspectrum_setup);
g_object_class_install_property(gobject_class, PROP_INTERVAL, g_param_spec_uint64("interval", "Interval", "Interval of time between message posts (in nanoseconds)", 1, G_MAXUINT64, DEFAULT_INTERVAL, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property(gobject_class, PROP_BANDS, g_param_spec_uint("bands", "Bands", "Number of frequency bands", 0, G_MAXUINT, DEFAULT_BANDS, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
GST_DEBUG_CATEGORY_INIT(gst_fastspectrum_debug, "spectrum", 0, "audio spectrum analyser element");
gst_element_class_set_static_metadata(element_class, "Spectrum analyzer",
"Filter/Analyzer/Audio",
"Run an FFT on the audio signal, output spectrum data",
"Erik Walthinsen <omega@cse.ogi.edu>, "
"Stefan Kost <ensonic@users.sf.net>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
caps = gst_caps_from_string(GST_AUDIO_CAPS_MAKE("{ S16LE, S24LE, S32LE, F32LE, F64LE }") ", layout = (string) interleaved, channels = 1");
#else
caps = gst_caps_from_string(GST_AUDIO_CAPS_MAKE("{ S16BE, S24BE, S32BE, F32BE, F64BE }") ", layout = (string) interleaved, channels = 1");
#endif
gst_audio_filter_class_add_pad_templates(filter_class, caps);
gst_caps_unref(caps);
klass->fftw_lock = new QMutex;
}
static void gst_fastspectrum_init(GstFastSpectrum *spectrum) {
spectrum->interval = DEFAULT_INTERVAL;
spectrum->bands = DEFAULT_BANDS;
spectrum->channel_data_initialized = false;
g_mutex_init(&spectrum->lock);
}
static void gst_fastspectrum_alloc_channel_data(GstFastSpectrum *spectrum) {
guint bands = spectrum->bands;
guint nfft = 2 * bands - 2;
spectrum->input_ring_buffer = new double[nfft];
spectrum->fft_input = reinterpret_cast<double*>(fftw_malloc(sizeof(double) * nfft));
spectrum->fft_output = reinterpret_cast<fftw_complex*>(fftw_malloc(sizeof(fftw_complex) * (nfft / 2 + 1)));
spectrum->spect_magnitude = new double[bands] {};
GstFastSpectrumClass *klass = reinterpret_cast<GstFastSpectrumClass*>(G_OBJECT_GET_CLASS(spectrum));
{
QMutexLocker l(klass->fftw_lock);
spectrum->plan = fftw_plan_dft_r2c_1d(static_cast<int>(nfft), spectrum->fft_input, spectrum->fft_output, FFTW_ESTIMATE);
}
spectrum->channel_data_initialized = true;
}
static void gst_fastspectrum_free_channel_data(GstFastSpectrum *spectrum) {
GstFastSpectrumClass *klass = reinterpret_cast<GstFastSpectrumClass*>(G_OBJECT_GET_CLASS(spectrum));
if (spectrum->channel_data_initialized) {
{
QMutexLocker l(klass->fftw_lock);
fftw_destroy_plan(spectrum->plan);
}
fftw_free(spectrum->fft_input);
fftw_free(spectrum->fft_output);
delete[] spectrum->input_ring_buffer;
delete[] spectrum->spect_magnitude;
spectrum->channel_data_initialized = false;
}
}
static void gst_fastspectrum_flush(GstFastSpectrum *spectrum) {
spectrum->num_frames = 0;
spectrum->num_fft = 0;
spectrum->accumulated_error = 0;
}
static void gst_fastspectrum_reset_state(GstFastSpectrum *spectrum) {
GST_DEBUG_OBJECT(spectrum, "resetting state");
gst_fastspectrum_free_channel_data(spectrum);
gst_fastspectrum_flush(spectrum);
}
static void gst_fastspectrum_finalize(GObject *object) {
GstFastSpectrum *spectrum = reinterpret_cast<GstFastSpectrum*>(object);
gst_fastspectrum_reset_state(spectrum);
g_mutex_clear(&spectrum->lock);
G_OBJECT_CLASS(parent_class)->finalize(object);
}
static void gst_fastspectrum_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) {
GstFastSpectrum *filter = reinterpret_cast<GstFastSpectrum*>(object);
switch (prop_id) {
case PROP_INTERVAL: {
guint64 interval = g_value_get_uint64(value);
g_mutex_lock(&filter->lock);
if (filter->interval != interval) {
filter->interval = interval;
gst_fastspectrum_reset_state(filter);
}
g_mutex_unlock(&filter->lock);
break;
}
case PROP_BANDS: {
guint bands = g_value_get_uint(value);
g_mutex_lock(&filter->lock);
if (filter->bands != bands) {
filter->bands = bands;
gst_fastspectrum_reset_state(filter);
}
g_mutex_unlock(&filter->lock);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void gst_fastspectrum_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
GstFastSpectrum *filter = reinterpret_cast<GstFastSpectrum*>(object);
switch (prop_id) {
case PROP_INTERVAL:
g_value_set_uint64(value, filter->interval);
break;
case PROP_BANDS:
g_value_set_uint(value, filter->bands);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static gboolean gst_fastspectrum_start(GstBaseTransform *trans) {
GstFastSpectrum *spectrum = reinterpret_cast<GstFastSpectrum*>(trans);
gst_fastspectrum_reset_state(spectrum);
return TRUE;
}
static gboolean gst_fastspectrum_stop(GstBaseTransform *trans) {
GstFastSpectrum *spectrum = reinterpret_cast<GstFastSpectrum*>(trans);
gst_fastspectrum_reset_state(spectrum);
return TRUE;
}
// Mixing data readers
static void input_data_mixed_float(const guint8 *_in, double *out, guint len, double max_value, guint op, guint nfft) {
Q_UNUSED(max_value);
const gfloat *in = reinterpret_cast<const gfloat*>(_in);
guint ip = 0;
for (guint j = 0; j < len; j++) {
out[op] = in[ip++];
op = (op + 1) % nfft;
}
}
static void input_data_mixed_double(const guint8 *_in, double *out, guint len, double max_value, guint op, guint nfft) {
Q_UNUSED(max_value);
const gdouble *in = reinterpret_cast<const gdouble*>(_in);
guint ip = 0;
for (guint j = 0; j < len; j++) {
out[op] = in[ip++];
op = (op + 1) % nfft;
}
}
static void input_data_mixed_int32_max(const guint8 *_in, double *out, guint len, double max_value, guint op, guint nfft) {
const gint32 *in = reinterpret_cast<const gint32*>(_in);
guint ip = 0;
for (guint j = 0; j < len; j++) {
out[op] = in[ip++] / max_value;
op = (op + 1) % nfft;
}
}
static void input_data_mixed_int24_max(const guint8 *_in, double *out, guint len, double max_value, guint op, guint nfft) {
for (guint j = 0; j < len; j++) {
#if G_BYTE_ORDER == G_BIG_ENDIAN
guint32 value = GST_READ_UINT24_BE(_in);
#else
guint32 value = GST_READ_UINT24_LE(_in);
#endif
if (value & 0x00800000) {
value |= 0xff000000;
}
out[op] = value / max_value;
op = (op + 1) % nfft;
_in += 3;
}
}
static void input_data_mixed_int16_max(const guint8 *_in, double *out, guint len, double max_value, guint op, guint nfft) {
const gint16 *in = reinterpret_cast<const gint16*>(_in);
guint ip = 0;
for (guint j = 0; j < len; j++) {
out[op] = in[ip++] / max_value;
op = (op + 1) % nfft;
}
}
static gboolean gst_fastspectrum_setup(GstAudioFilter *base, const GstAudioInfo *info) {
GstFastSpectrum *spectrum = reinterpret_cast<GstFastSpectrum*>(base);
GstFastSpectrumInputData input_data = nullptr;
g_mutex_lock(&spectrum->lock);
switch (GST_AUDIO_INFO_FORMAT(info)) {
case GST_AUDIO_FORMAT_S16:
input_data = input_data_mixed_int16_max;
break;
case GST_AUDIO_FORMAT_S24:
input_data = input_data_mixed_int24_max;
break;
case GST_AUDIO_FORMAT_S32:
input_data = input_data_mixed_int32_max;
break;
case GST_AUDIO_FORMAT_F32:
input_data = input_data_mixed_float;
break;
case GST_AUDIO_FORMAT_F64:
input_data = input_data_mixed_double;
break;
default:
g_assert_not_reached();
break;
}
spectrum->input_data = input_data;
gst_fastspectrum_reset_state(spectrum);
g_mutex_unlock(&spectrum->lock);
return TRUE;
}
static void gst_fastspectrum_run_fft(GstFastSpectrum *spectrum, guint input_pos) {
guint bands = spectrum->bands;
guint nfft = 2 * bands - 2;
for (guint i = 0; i < nfft; i++) {
spectrum->fft_input[i] = spectrum->input_ring_buffer[(input_pos + i) % nfft];
}
// Should be safe to execute the same plan multiple times in parallel.
fftw_execute(spectrum->plan);
// Calculate magnitude in db
for (guint i = 0; i < bands; i++) {
gdouble val = spectrum->fft_output[i][0] * spectrum->fft_output[i][0];
val += spectrum->fft_output[i][1] * spectrum->fft_output[i][1];
val /= nfft * nfft;
spectrum->spect_magnitude[i] += val;
}
}
static GstFlowReturn gst_fastspectrum_transform_ip(GstBaseTransform *trans, GstBuffer *buffer) {
GstFastSpectrum *spectrum = reinterpret_cast<GstFastSpectrum*>(trans);
guint rate = GST_AUDIO_FILTER_RATE(spectrum);
guint bps = GST_AUDIO_FILTER_BPS(spectrum);
guint bpf = GST_AUDIO_FILTER_BPF(spectrum);
double max_value = static_cast<double>((1UL << ((bps << 3) - 1)) - 1);
guint bands = spectrum->bands;
guint nfft = 2 * bands - 2;
guint input_pos = 0;
GstMapInfo map;
const guint8 *data = nullptr;
gsize size = 0;
GstFastSpectrumInputData input_data = nullptr;
g_mutex_lock(&spectrum->lock);
gst_buffer_map(buffer, &map, GST_MAP_READ);
data = map.data;
size = map.size;
GST_LOG_OBJECT(spectrum, "input size: %" G_GSIZE_FORMAT " bytes", size);
if (GST_BUFFER_IS_DISCONT(buffer)) {
GST_DEBUG_OBJECT(spectrum, "Discontinuity detected -- flushing");
gst_fastspectrum_flush(spectrum);
}
// If we don't have a FFT context yet (or it was reset due to parameter changes) get one and allocate memory for everything
if (!spectrum->channel_data_initialized) {
GST_DEBUG_OBJECT(spectrum, "allocating for bands %u", bands);
gst_fastspectrum_alloc_channel_data(spectrum);
// Number of sample frames we process before posting a message interval is in ns
spectrum->frames_per_interval = gst_util_uint64_scale(spectrum->interval, rate, GST_SECOND);
spectrum->frames_todo = spectrum->frames_per_interval;
// Rounding error for frames_per_interval in ns, aggregated it in accumulated_error
spectrum->error_per_interval = (spectrum->interval * rate) % GST_SECOND;
if (spectrum->frames_per_interval == 0) {
spectrum->frames_per_interval = 1;
}
GST_INFO_OBJECT(spectrum, "interval %" GST_TIME_FORMAT ", fpi %" G_GUINT64_FORMAT ", error %" GST_TIME_FORMAT, GST_TIME_ARGS(spectrum->interval), spectrum->frames_per_interval, GST_TIME_ARGS(spectrum->error_per_interval));
spectrum->input_pos = 0;
gst_fastspectrum_flush(spectrum);
}
if (spectrum->num_frames == 0) {
spectrum->message_ts = GST_BUFFER_TIMESTAMP(buffer);
}
input_pos = spectrum->input_pos;
input_data = spectrum->input_data;
while (size >= bpf) {
// Run input_data for a chunk of data
guint fft_todo = nfft - (spectrum->num_frames % nfft);
guint msg_todo = spectrum->frames_todo - spectrum->num_frames;
GST_LOG_OBJECT(spectrum, "message frames todo: %u, fft frames todo: %u, input frames %" G_GSIZE_FORMAT, msg_todo, fft_todo, (size / bpf));
guint block_size = msg_todo;
if (block_size > (size / bpf)) {
block_size = (size / bpf);
}
if (block_size > fft_todo) {
block_size = fft_todo;
}
// Move the current frames into our ringbuffers
input_data(data, spectrum->input_ring_buffer, block_size, max_value, input_pos, nfft);
data += block_size * bpf;
size -= block_size * bpf;
input_pos = (input_pos + block_size) % nfft;
spectrum->num_frames += block_size;
gboolean have_full_interval = (spectrum->num_frames == spectrum->frames_todo);
GST_LOG_OBJECT(spectrum, "size: %" G_GSIZE_FORMAT ", do-fft = %d, do-message = %d", size, (spectrum->num_frames % nfft == 0), have_full_interval);
// If we have enough frames for an FFT or we have all frames required for the interval and we haven't run a FFT, then run an FFT
if ((spectrum->num_frames % nfft == 0) || (have_full_interval && !spectrum->num_fft)) {
gst_fastspectrum_run_fft(spectrum, input_pos);
spectrum->num_fft++;
}
// Do we have the FFTs for one interval?
if (have_full_interval) {
GST_DEBUG_OBJECT(spectrum, "nfft: %u frames: %" G_GUINT64_FORMAT " fpi: %" G_GUINT64_FORMAT " error: %" GST_TIME_FORMAT, nfft, spectrum->num_frames, spectrum->frames_per_interval, GST_TIME_ARGS(spectrum->accumulated_error));
spectrum->frames_todo = spectrum->frames_per_interval;
if (spectrum->accumulated_error >= GST_SECOND) {
spectrum->accumulated_error -= GST_SECOND;
spectrum->frames_todo++;
}
spectrum->accumulated_error += spectrum->error_per_interval;
if (spectrum->output_callback) {
// Calculate average
for (guint i = 0; i < spectrum->bands; i++) {
spectrum->spect_magnitude[i] /= static_cast<double>(spectrum->num_fft);
}
spectrum->output_callback(spectrum->spect_magnitude, static_cast<int>(spectrum->bands));
// Reset spectrum accumulators
memset(spectrum->spect_magnitude, 0, spectrum->bands * sizeof(double));
}
if (GST_CLOCK_TIME_IS_VALID(spectrum->message_ts)) {
spectrum->message_ts += gst_util_uint64_scale(spectrum->num_frames, GST_SECOND, rate);
}
spectrum->num_frames = 0;
spectrum->num_fft = 0;
}
}
spectrum->input_pos = input_pos;
gst_buffer_unmap(buffer, &map);
g_mutex_unlock(&spectrum->lock);
g_assert(size == 0);
return GST_FLOW_OK;
}

View File

@@ -1,7 +1,6 @@
/* GStreamer /* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk> * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) <2018-2024> Jonas Kvinge <jonas@jkvinge.net>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@@ -26,8 +25,9 @@
// - Send output via a callback instead of GST messages (less overhead). // - Send output via a callback instead of GST messages (less overhead).
// - Removed all properties except interval and band. // - Removed all properties except interval and band.
#ifndef GST_STRAWBERRY_FASTSPECTRUM_H
#define GST_STRAWBERRY_FASTSPECTRUM_H #ifndef GST_MOODBAR_FASTSPECTRUM_H
#define GST_MOODBAR_FASTSPECTRUM_H
#include <functional> #include <functional>
@@ -37,17 +37,19 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_STRAWBERRY_FASTSPECTRUM (gst_strawberry_fastspectrum_get_type()) #define GST_TYPE_FASTSPECTRUM (gst_fastspectrum_get_type())
#define GST_STRAWBERRY_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_FASTSPECTRUM, GstStrawberryFastSpectrum)) #define GST_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_FASTSPECTRUM, GstFastSpectrum))
#define GST_IS_STRAWBERRY_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_FASTSPECTRUM)) #define GST_IS_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_FASTSPECTRUM))
#define GST_STRAWBERRY_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_FASTSPECTRUM, GstStrawberryFastSpectrumClass)) #define GST_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_FASTSPECTRUM, GstFastSpectrumClass))
#define GST_IS_STRAWBERRY_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_FASTSPECTRUM)) #define GST_IS_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_FASTSPECTRUM))
typedef void (*GstStrawberryFastSpectrumInputData)(const guint8 *in, double *out, guint64 len, double max_value, guint op, guint nfft); class QMutex;
using GstStrawberryFastSpectrumOutputCallback = std::function<void(double *magnitudes, int size)>; typedef void (*GstFastSpectrumInputData)(const guint8 *in, double *out, guint len, double max_value, guint op, guint nfft);
struct GstStrawberryFastSpectrum { using OutputCallback = std::function<void(double *magnitudes, int size)>;
struct GstFastSpectrum {
GstAudioFilter parent; GstAudioFilter parent;
// Properties // Properties
@@ -75,17 +77,20 @@ struct GstStrawberryFastSpectrum {
GMutex lock; GMutex lock;
GstStrawberryFastSpectrumInputData input_data; GstFastSpectrumInputData input_data;
GstStrawberryFastSpectrumOutputCallback output_callback;
OutputCallback output_callback;
}; };
struct GstStrawberryFastSpectrumClass { struct GstFastSpectrumClass {
GstAudioFilterClass parent_class; GstAudioFilterClass parent_class;
GMutex fftw_lock;
// Static lock for creating & destroying FFTW plans.
QMutex *fftw_lock;
}; };
GType gst_strawberry_fastspectrum_get_type(void); GType gst_fastspectrum_get_type(void);
G_END_DECLS G_END_DECLS
#endif // GST_STRAWBERRY_FASTSPECTRUM_H #endif // GST_MOODBAR_FASTSPECTRUM_H

View File

@@ -0,0 +1,46 @@
/* This file was part of Clementine.
Copyright 2014, David Sansome <me@davidsansome.com>
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 <glib.h>
#include <gst/gst.h>
#include "gstfastspectrum.h"
#include "gstmoodbarplugin.h"
static gboolean gst_moodbar_plugin_init(GstPlugin *plugin) {
if (!gst_element_register(plugin, "fastspectrum", GST_RANK_NONE, GST_TYPE_FASTSPECTRUM)) {
return FALSE;
}
return TRUE;
}
int gstfastspectrum_register_static() {
return gst_plugin_register_static(
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"fastspectrum",
"Fast spectrum analyzer for generating Moodbars",
gst_moodbar_plugin_init,
"0.1",
"GPL",
"FastSpectrum",
"FastSpectrum",
"https://www.strawberrymusicplayer.org");
}

View File

@@ -0,0 +1,25 @@
/* This file was part of Clementine.
Copyright 2014, David Sansome <me@davidsansome.com>
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 GST_MOODBAR_PLUGIN_H
#define GST_MOODBAR_PLUGIN_H
extern "C" {
int gstfastspectrum_register_static();
}
#endif // GST_MOODBAR_PLUGIN_H

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
set(SOURCES set(SOURCES
core/logging.cpp core/logging.cpp
@@ -16,6 +16,8 @@ set(HEADERS
qt_wrap_cpp(MOC ${HEADERS}) qt_wrap_cpp(MOC ${HEADERS})
link_directories(${GLIB_LIBRARY_DIRS})
add_library(libstrawberry-common STATIC ${SOURCES} ${MOC}) add_library(libstrawberry-common STATIC ${SOURCES} ${MOC})
target_include_directories(libstrawberry-common SYSTEM PRIVATE ${GLIB_INCLUDE_DIRS}) target_include_directories(libstrawberry-common SYSTEM PRIVATE ${GLIB_INCLUDE_DIRS})
@@ -29,8 +31,6 @@ if(Backtrace_FOUND)
target_include_directories(libstrawberry-common SYSTEM PRIVATE ${Backtrace_INCLUDE_DIRS}) target_include_directories(libstrawberry-common SYSTEM PRIVATE ${Backtrace_INCLUDE_DIRS})
endif() endif()
target_link_directories(libstrawberry-common PRIVATE ${GLIB_LIBRARY_DIRS})
target_link_libraries(libstrawberry-common PRIVATE target_link_libraries(libstrawberry-common PRIVATE
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${GLIB_LIBRARIES} ${GLIB_LIBRARIES}

View File

@@ -24,9 +24,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <utility>
#include <memory> #include <memory>
#include <chrono>
#ifndef _MSC_VER #ifndef _MSC_VER
# include <cxxabi.h> # include <cxxabi.h>
@@ -61,8 +59,6 @@
#include "logging.h" #include "logging.h"
using namespace Qt::StringLiterals;
namespace logging { namespace logging {
static Level sDefaultLevel = Level_Debug; static Level sDefaultLevel = Level_Debug;
@@ -161,13 +157,12 @@ static void MessageHandler(QtMsgType type, const QMessageLogContext&, const QStr
break; break;
} }
const QStringList lines = message.split(u'\n'); for (const QString &line : message.split(QLatin1Char('\n'))) {
for (const QString &line : lines) {
BufferedDebug d = CreateLogger<BufferedDebug>(level, QStringLiteral("unknown"), -1, nullptr); BufferedDebug d = CreateLogger<BufferedDebug>(level, QStringLiteral("unknown"), -1, nullptr);
d << line.toLocal8Bit().constData(); d << line.toLocal8Bit().constData();
if (d.buf_) { if (d.buf_) {
d.buf_->close(); d.buf_->close();
fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", d.buf_->buffer().constData()); fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", d.buf_->buffer().data());
fflush(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout); fflush(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout);
} }
} }
@@ -198,9 +193,8 @@ void SetLevels(const QString &levels) {
if (!sClassLevels) return; if (!sClassLevels) return;
const QStringList items = levels.split(u','); for (const QString &item : levels.split(QLatin1Char(','))) {
for (const QString &item : items) { const QStringList class_level = item.split(QLatin1Char(':'));
const QStringList class_level = item.split(u':');
QString class_name; QString class_name;
bool ok = false; bool ok = false;
@@ -218,7 +212,7 @@ void SetLevels(const QString &levels) {
continue; continue;
} }
if (class_name.isEmpty() || class_name == u'*') { if (class_name.isEmpty() || class_name == QLatin1Char('*')) {
sDefaultLevel = static_cast<Level>(level); sDefaultLevel = static_cast<Level>(level);
} }
else { else {
@@ -232,9 +226,9 @@ static QString ParsePrettyFunction(const char *pretty_function) {
// Get the class name out of the function name. // Get the class name out of the function name.
QString class_name = QLatin1String(pretty_function); QString class_name = QLatin1String(pretty_function);
const qint64 paren = class_name.indexOf(u'('); const qint64 paren = class_name.indexOf(QLatin1Char('('));
if (paren != -1) { if (paren != -1) {
const qint64 colons = class_name.lastIndexOf("::"_L1, paren); const qint64 colons = class_name.lastIndexOf(QLatin1String("::"), paren);
if (colons != -1) { if (colons != -1) {
class_name = class_name.left(colons); class_name = class_name.left(colons);
} }
@@ -243,7 +237,7 @@ static QString ParsePrettyFunction(const char *pretty_function) {
} }
} }
const qint64 space = class_name.lastIndexOf(u' '); const qint64 space = class_name.lastIndexOf(QLatin1Char(' '));
if (space != -1) { if (space != -1) {
class_name = class_name.mid(space + 1); class_name = class_name.mid(space + 1);
} }
@@ -316,8 +310,8 @@ QString CXXDemangle(const QString &mangled_function) {
QString LinuxDemangle(const QString &symbol); QString LinuxDemangle(const QString &symbol);
QString LinuxDemangle(const QString &symbol) { QString LinuxDemangle(const QString &symbol) {
static const QRegularExpression regex_symbol(QStringLiteral("\\(([^+]+)")); QRegularExpression regex(QStringLiteral("\\(([^+]+)"));
QRegularExpressionMatch match = regex_symbol.match(symbol); QRegularExpressionMatch match = regex.match(symbol);
if (!match.hasMatch()) { if (!match.hasMatch()) {
return symbol; return symbol;
} }
@@ -331,7 +325,11 @@ QString LinuxDemangle(const QString &symbol) {
QString DarwinDemangle(const QString &symbol); QString DarwinDemangle(const QString &symbol);
QString DarwinDemangle(const QString &symbol) { QString DarwinDemangle(const QString &symbol) {
const QStringList split = symbol.split(QLatin1Char(' '), Qt::SkipEmptyParts); # if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QStringList split = symbol.split(QLatin1Char(' '), Qt::SkipEmptyParts);
# else
QStringList split = symbol.split(QLatin1Char(' '), QString::SkipEmptyParts);
# endif
QString mangled_function = split[3]; QString mangled_function = split[3];
return CXXDemangle(mangled_function); return CXXDemangle(mangled_function);
@@ -372,49 +370,20 @@ void DumpStackTrace() {
// It's okay that the LoggedDebug instance is copied to a QDebug in these. It doesn't override any behavior that should be needed after return. // It's okay that the LoggedDebug instance is copied to a QDebug in these. It doesn't override any behavior that should be needed after return.
#define qCreateLogger(line, pretty_function, category, level) logging::CreateLogger<LoggedDebug>(logging::Level_##level, logging::ParsePrettyFunction(pretty_function), line, category) #define qCreateLogger(line, pretty_function, category, level) logging::CreateLogger<LoggedDebug>(logging::Level_##level, logging::ParsePrettyFunction(pretty_function), line, category)
QDebug CreateLoggerFatal(const int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Fatal); } QDebug CreateLoggerInfo(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Info); }
QDebug CreateLoggerError(const int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Error); } QDebug CreateLoggerFatal(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Fatal); }
QDebug CreateLoggerError(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Error); }
#ifdef QT_NO_INFO_OUTPUT
QNoDebug CreateLoggerInfo(const int line, const char *pretty_function, const char *category) {
Q_UNUSED(line)
Q_UNUSED(pretty_function)
Q_UNUSED(category)
return QNoDebug();
}
#else
QDebug CreateLoggerInfo(const int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Info); }
#endif // QT_NO_INFO_OUTPUT
#ifdef QT_NO_WARNING_OUTPUT #ifdef QT_NO_WARNING_OUTPUT
QNoDebug CreateLoggerWarning(const int line, const char *pretty_function, const char *category) { QNoDebug CreateLoggerWarning(int, const char*, const char*) { return QNoDebug(); }
Q_UNUSED(line)
Q_UNUSED(pretty_function)
Q_UNUSED(category)
return QNoDebug();
}
#else #else
QDebug CreateLoggerWarning(const int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Warning); } QDebug CreateLoggerWarning(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Warning); }
#endif // QT_NO_WARNING_OUTPUT #endif // QT_NO_WARNING_OUTPUT
#ifdef QT_NO_DEBUG_OUTPUT #ifdef QT_NO_DEBUG_OUTPUT
QNoDebug CreateLoggerDebug(const int line, const char *pretty_function, const char *category) { QNoDebug CreateLoggerDebug(int, const char*, const char*) { return QNoDebug(); }
Q_UNUSED(line)
Q_UNUSED(pretty_function)
Q_UNUSED(category)
return QNoDebug();
}
#else #else
QDebug CreateLoggerDebug(const int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Debug); } QDebug CreateLoggerDebug(int line, const char *pretty_function, const char *category) { return qCreateLogger(line, pretty_function, category, Debug); }
#endif // QT_NO_DEBUG_OUTPUT #endif // QT_NO_DEBUG_OUTPUT
} // namespace logging } // namespace logging

View File

@@ -72,25 +72,20 @@ enum Level {
void DumpStackTrace(); void DumpStackTrace();
QDebug CreateLoggerFatal(const int line, const char *pretty_function, const char *category); QDebug CreateLoggerInfo(int line, const char *pretty_function, const char *category);
QDebug CreateLoggerError(const int line, const char *pretty_function, const char *category); QDebug CreateLoggerFatal(int line, const char *pretty_function, const char *category);
QDebug CreateLoggerError(int line, const char *pretty_function, const char *category);
#ifdef QT_NO_INFO_OUTPUT
QNoDebug CreateLoggerInfo(const int line, const char *pretty_function, const char *category);
#else
QDebug CreateLoggerInfo(const int line, const char *pretty_function, const char *category);
#endif // QT_NO_INFO_OUTPUT
#ifdef QT_NO_WARNING_OUTPUT #ifdef QT_NO_WARNING_OUTPUT
QNoDebug CreateLoggerWarning(const int line, const char *pretty_function, const char *category); QNoDebug CreateLoggerWarning(int, const char*, const char*);
#else #else
QDebug CreateLoggerWarning(const int line, const char *pretty_function, const char *category); QDebug CreateLoggerWarning(int line, const char *pretty_function, const char *category);
#endif // QT_NO_WARNING_OUTPUT #endif // QT_NO_WARNING_OUTPUT
#ifdef QT_NO_DEBUG_OUTPUT #ifdef QT_NO_DEBUG_OUTPUT
QNoDebug CreateLoggerDebug(const int line, const char *pretty_function, const char *category); QNoDebug CreateLoggerDebug(int, const char*, const char*);
#else #else
QDebug CreateLoggerDebug(const int line, const char *pretty_function, const char *category); QDebug CreateLoggerDebug(int line, const char *pretty_function, const char *category);
#endif // QT_NO_DEBUG_OUTPUT #endif // QT_NO_DEBUG_OUTPUT
void GLog(const char *domain, int level, const char *message, void *user_data); void GLog(const char *domain, int level, const char *message, void *user_data);

View File

@@ -50,7 +50,7 @@ class _MessageHandlerBase : public QObject {
// After this is true, messages cannot be sent to the handler any more. // After this is true, messages cannot be sent to the handler any more.
bool is_device_closed() const { return is_device_closed_; } bool is_device_closed() const { return is_device_closed_; }
protected Q_SLOTS: protected slots:
void WriteMessage(const QByteArray &data); void WriteMessage(const QByteArray &data);
void DeviceReadyRead(); void DeviceReadyRead();
virtual void DeviceClosed(); virtual void DeviceClosed();

View File

@@ -41,7 +41,7 @@ void _MessageReplyBase::Abort() {
finished_ = true; finished_ = true;
success_ = false; success_ = false;
Q_EMIT Finished(); emit Finished();
qLog(Debug) << "Releasing ID" << id() << "(aborted)"; qLog(Debug) << "Releasing ID" << id() << "(aborted)";
semaphore_.release(); semaphore_.release();

View File

@@ -45,7 +45,7 @@ class _MessageReplyBase : public QObject {
void Abort(); void Abort();
Q_SIGNALS: signals:
void Finished(); void Finished();
protected: protected:

View File

@@ -52,11 +52,11 @@ class _WorkerPoolBase : public QObject {
public: public:
explicit _WorkerPoolBase(QObject *parent = nullptr); explicit _WorkerPoolBase(QObject *parent = nullptr);
Q_SIGNALS: signals:
// Emitted when a worker failed to start. This usually happens when the worker wasn't found, or couldn't be executed. // Emitted when a worker failed to start. This usually happens when the worker wasn't found, or couldn't be executed.
void WorkerFailedToStart(); void WorkerFailedToStart();
protected Q_SLOTS: protected slots:
virtual void DoStart() {} virtual void DoStart() {}
virtual void NewConnection() {} virtual void NewConnection() {}
virtual void ProcessReadyReadStandardOutput() {} virtual void ProcessReadyReadStandardOutput() {}
@@ -293,7 +293,7 @@ void WorkerPool<HandlerType>::StartOneWorker(Worker *worker) {
QObject::connect(worker->process_, &QProcess::readyReadStandardError, this, &WorkerPool::ProcessReadyReadStandardError); QObject::connect(worker->process_, &QProcess::readyReadStandardError, this, &WorkerPool::ProcessReadyReadStandardError);
// Create a server, find an unused name and start listening // Create a server, find an unused name and start listening
Q_FOREVER { forever {
const quint32 unique_number = QRandomGenerator::global()->bounded(static_cast<quint32>(quint64(this) & 0xFFFFFFFF)); const quint32 unique_number = QRandomGenerator::global()->bounded(static_cast<quint32>(quint64(this) & 0xFFFFFFFF));
const QString name = QStringLiteral("%1_%2").arg(local_server_name_).arg(unique_number); const QString name = QStringLiteral("%1_%2").arg(local_server_name_).arg(unique_number);
@@ -357,7 +357,7 @@ void WorkerPool<HandlerType>::ProcessError(QProcess::ProcessError error) {
// Failed to start errors are bad - it usually means the worker isn't installed. // Failed to start errors are bad - it usually means the worker isn't installed.
// Don't restart the process, but tell our owner, who will probably want to do something fatal. // Don't restart the process, but tell our owner, who will probably want to do something fatal.
qLog(Error) << "Worker failed to start"; qLog(Error) << "Worker failed to start";
Q_EMIT WorkerFailedToStart(); emit WorkerFailedToStart();
break; break;
default: default:

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
# Workaround a bug in protobuf-generate.cmake (https://github.com/protocolbuffers/protobuf/issues/12450) # Workaround a bug in protobuf-generate.cmake (https://github.com/protocolbuffers/protobuf/issues/12450)
if(NOT protobuf_PROTOC_EXE) if(NOT protobuf_PROTOC_EXE)
@@ -19,6 +19,19 @@ if(HAVE_TAGPARSER)
list(APPEND SOURCES tagreadertagparser.cpp) list(APPEND SOURCES tagreadertagparser.cpp)
endif() endif()
link_directories(
${GLIB_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
)
if(HAVE_TAGLIB)
link_directories(${TAGLIB_LIBRARY_DIRS})
endif()
if(HAVE_TAGPARSER)
link_directories(${TAGPARSER_LIBRARY_DIRS})
endif()
add_library(libstrawberry-tagreader STATIC ${PROTO_SOURCES} ${SOURCES}) add_library(libstrawberry-tagreader STATIC ${PROTO_SOURCES} ${SOURCES})
target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE
@@ -34,11 +47,6 @@ target_include_directories(libstrawberry-tagreader PRIVATE
${CMAKE_BINARY_DIR}/src ${CMAKE_BINARY_DIR}/src
) )
target_link_directories(libstrawberry-tagreader PRIVATE
${GLIB_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
)
target_link_libraries(libstrawberry-tagreader PRIVATE target_link_libraries(libstrawberry-tagreader PRIVATE
${GLIB_LIBRARIES} ${GLIB_LIBRARIES}
${Protobuf_LIBRARIES} ${Protobuf_LIBRARIES}
@@ -50,13 +58,11 @@ target_link_libraries(libstrawberry-tagreader PRIVATE
if(HAVE_TAGLIB) if(HAVE_TAGLIB)
target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS}) target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS})
target_link_directories(libstrawberry-tagreader PRIVATE ${TAGLIB_LIBRARY_DIRS})
target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES}) target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES})
endif() endif()
if(HAVE_TAGPARSER) if(HAVE_TAGPARSER)
target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS}) target_include_directories(libstrawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS})
target_link_directories(libstrawberry-tagreader PRIVATE ${TAGPARSER_LIBRARY_DIRS})
target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES}) target_link_libraries(libstrawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES})
endif() endif()

View File

@@ -31,8 +31,6 @@
#include "core/logging.h" #include "core/logging.h"
#include "tagreaderbase.h" #include "tagreaderbase.h"
using namespace Qt::StringLiterals;
TagReaderBase::TagReaderBase() = default; TagReaderBase::TagReaderBase() = default;
TagReaderBase::~TagReaderBase() = default; TagReaderBase::~TagReaderBase() = default;
@@ -144,11 +142,11 @@ TagReaderBase::Cover TagReaderBase::LoadCoverFromRequest(const QString &song_fil
if (cover_mime_type.isEmpty()) { if (cover_mime_type.isEmpty()) {
cover_mime_type = QMimeDatabase().mimeTypeForData(cover_data).name(); cover_mime_type = QMimeDatabase().mimeTypeForData(cover_data).name();
} }
if (cover_mime_type == "image/jpeg"_L1) { if (cover_mime_type == QLatin1String("image/jpeg")) {
qLog(Debug) << "Using cover from JPEG data for" << song_filename; qLog(Debug) << "Using cover from JPEG data for" << song_filename;
return Cover(cover_data, cover_mime_type); return Cover(cover_data, cover_mime_type);
} }
if (cover_mime_type == "image/png"_L1) { if (cover_mime_type == QLatin1String("image/png")) {
qLog(Debug) << "Using cover from PNG data for" << song_filename; qLog(Debug) << "Using cover from PNG data for" << song_filename;
return Cover(cover_data, cover_mime_type); return Cover(cover_data, cover_mime_type);
} }

View File

@@ -34,21 +34,19 @@
#include "tagreaderbase.h" #include "tagreaderbase.h"
#include "tagreadertaglib.h" #include "tagreadertaglib.h"
using namespace Qt::StringLiterals;
#undef TStringToQString #undef TStringToQString
#undef QStringToTString #undef QStringToTString
bool GME::IsSupportedFormat(const QFileInfo &fileinfo) { bool GME::IsSupportedFormat(const QFileInfo &fileinfo) {
return fileinfo.exists() && (fileinfo.completeSuffix().endsWith("spc"_L1, Qt::CaseInsensitive) || fileinfo.completeSuffix().endsWith("vgm"_L1), Qt::CaseInsensitive); return fileinfo.exists() && (fileinfo.completeSuffix().endsWith(QLatin1String("spc"), Qt::CaseInsensitive) || fileinfo.completeSuffix().endsWith(QLatin1String("vgm")), Qt::CaseInsensitive);
} }
TagReaderBase::Result GME::ReadFile(const QFileInfo &fileinfo, spb::tagreader::SongMetadata *song) { TagReaderBase::Result GME::ReadFile(const QFileInfo &fileinfo, spb::tagreader::SongMetadata *song) {
if (fileinfo.completeSuffix().endsWith("spc"_L1), Qt::CaseInsensitive) { if (fileinfo.completeSuffix().endsWith(QLatin1String("spc")), Qt::CaseInsensitive) {
return SPC::Read(fileinfo, song); return SPC::Read(fileinfo, song);
} }
if (fileinfo.completeSuffix().endsWith("vgm"_L1, Qt::CaseInsensitive)) { if (fileinfo.completeSuffix().endsWith(QLatin1String("vgm"), Qt::CaseInsensitive)) {
return VGM::Read(fileinfo, song); return VGM::Read(fileinfo, song);
} }
@@ -231,7 +229,6 @@ TagReaderBase::Result GME::VGM::Read(const QFileInfo &fileinfo, spb::tagreader::
file.seek(static_cast<qint64>(GD3_TAG_PTR + pt)); file.seek(static_cast<qint64>(GD3_TAG_PTR + pt));
QByteArray gd3_version = file.read(4); QByteArray gd3_version = file.read(4);
Q_UNUSED(gd3_version)
file.seek(file.pos() + 4); file.seek(file.pos() + 4);
QByteArray gd3_length_bytes = file.read(4); QByteArray gd3_length_bytes = file.read(4);
@@ -240,8 +237,12 @@ TagReaderBase::Result GME::VGM::Read(const QFileInfo &fileinfo, spb::tagreader::
QByteArray gd3Data = file.read(gd3_length); QByteArray gd3Data = file.read(gd3_length);
QTextStream fileTagStream(gd3Data, QIODevice::ReadOnly); QTextStream fileTagStream(gd3Data, QIODevice::ReadOnly);
// Stored as 16 bit UTF string, two bytes per letter. // Stored as 16 bit UTF string, two bytes per letter.
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
fileTagStream.setEncoding(QStringConverter::Utf16); fileTagStream.setEncoding(QStringConverter::Utf16);
QStringList strings = fileTagStream.readLine(0).split(u'\0'); #else
fileTagStream.setCodec("UTF-16");
#endif
QStringList strings = fileTagStream.readLine(0).split(QLatin1Char('\0'));
if (strings.count() < 10) { if (strings.count() < 10) {
return TagReaderBase::Result::ErrorCode::FileParseError; return TagReaderBase::Result::ErrorCode::FileParseError;
} }

View File

@@ -97,8 +97,6 @@
#include "core/messagehandler.h" #include "core/messagehandler.h"
#include "utilities/timeconstants.h" #include "utilities/timeconstants.h"
using namespace Qt::StringLiterals;
#undef TStringToQString #undef TStringToQString
#undef QStringToTString #undef QStringToTString
@@ -445,7 +443,7 @@ TagReaderBase::Result TagReaderTagLib::ReadFile(const QString &filename, spb::ta
} }
if (!disc.isEmpty()) { if (!disc.isEmpty()) {
const qint64 i = disc.indexOf(u'/'); const qint64 i = disc.indexOf(QLatin1Char('/'));
if (i != -1) { if (i != -1) {
// disc.right( i ).toInt() is total number of discs, we don't use this at the moment // disc.right( i ).toInt() is total number of discs, we don't use this at the moment
song->set_disc(disc.left(i).toInt()); song->set_disc(disc.left(i).toInt());
@@ -459,7 +457,7 @@ TagReaderBase::Result TagReaderTagLib::ReadFile(const QString &filename, spb::ta
// well, it wasn't set, but if the artist is VA assume it's a compilation // well, it wasn't set, but if the artist is VA assume it's a compilation
const QString albumartist = QString::fromStdString(song->albumartist()); const QString albumartist = QString::fromStdString(song->albumartist());
const QString artist = QString::fromStdString(song->artist()); const QString artist = QString::fromStdString(song->artist());
if (artist.compare("various artists"_L1) == 0 || albumartist.compare("various artists"_L1) == 0) { if (artist.compare(QLatin1String("various artists")) == 0 || albumartist.compare(QLatin1String("various artists")) == 0) {
song->set_compilation(true); song->set_compilation(true);
} }
} }
@@ -531,7 +529,7 @@ void TagReaderTagLib::ParseID3v2Tags(TagLib::ID3v2::Tag *tag, QString *disc, QSt
for (uint i = 0; i < map[kID3v2_CommercialFrame].size(); ++i) { for (uint i = 0; i < map[kID3v2_CommercialFrame].size(); ++i) {
const TagLib::ID3v2::CommentsFrame *frame = dynamic_cast<const TagLib::ID3v2::CommentsFrame*>(map[kID3v2_CommercialFrame][i]); const TagLib::ID3v2::CommentsFrame *frame = dynamic_cast<const TagLib::ID3v2::CommentsFrame*>(map[kID3v2_CommercialFrame][i]);
if (frame && TagLibStringToQString(frame->description()) != "iTunNORM"_L1) { if (frame && TagLibStringToQString(frame->description()) != QLatin1String("iTunNORM")) {
AssignTagLibStringToStdString(frame->text(), song->mutable_comment()); AssignTagLibStringToStdString(frame->text(), song->mutable_comment());
break; break;
} }
@@ -800,13 +798,13 @@ void TagReaderTagLib::ParseMP4Tags(TagLib::MP4::Tag *tag, QString *disc, QString
} }
if (tag->contains(kMP4_MusicBrainz_AlbumArtistId)) { if (tag->contains(kMP4_MusicBrainz_AlbumArtistId)) {
AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_AlbumArtistId).toStringList()), song->mutable_musicbrainz_album_artist_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_AlbumArtistId).toStringList().toString(), song->mutable_musicbrainz_album_artist_id());
} }
if (tag->contains(kMP4_MusicBrainz_ArtistId)) { if (tag->contains(kMP4_MusicBrainz_ArtistId)) {
AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_ArtistId).toStringList()), song->mutable_musicbrainz_artist_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_ArtistId).toStringList().toString(), song->mutable_musicbrainz_artist_id());
} }
if (tag->contains(kMP4_MusicBrainz_OriginalArtistId)) { if (tag->contains(kMP4_MusicBrainz_OriginalArtistId)) {
AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_OriginalArtistId).toStringList()), song->mutable_musicbrainz_original_artist_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_OriginalArtistId).toStringList().toString(), song->mutable_musicbrainz_original_artist_id());
} }
if (tag->contains(kMP4_MusicBrainz_AlbumId)) { if (tag->contains(kMP4_MusicBrainz_AlbumId)) {
AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_AlbumId).toStringList().toString(), song->mutable_musicbrainz_album_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_AlbumId).toStringList().toString(), song->mutable_musicbrainz_album_id());
@@ -827,7 +825,7 @@ void TagReaderTagLib::ParseMP4Tags(TagLib::MP4::Tag *tag, QString *disc, QString
AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_ReleaseGroupId).toStringList().toString(), song->mutable_musicbrainz_release_group_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_ReleaseGroupId).toStringList().toString(), song->mutable_musicbrainz_release_group_id());
} }
if (tag->contains(kMP4_MusicBrainz_WorkId)) { if (tag->contains(kMP4_MusicBrainz_WorkId)) {
AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_WorkId).toStringList()), song->mutable_musicbrainz_work_id()); AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_WorkId).toStringList().toString(), song->mutable_musicbrainz_work_id());
} }
} }
@@ -939,7 +937,7 @@ TagReaderBase::Result TagReaderTagLib::WriteFile(const QString &filename, const
save_tags_options << QStringLiteral("embedded cover"); save_tags_options << QStringLiteral("embedded cover");
} }
qLog(Debug) << "Saving" << save_tags_options.join(", "_L1) << "to" << filename; qLog(Debug) << "Saving" << save_tags_options.join(QLatin1String(", ")) << "to" << filename;
const Cover cover = LoadCoverFromRequest(filename, request); const Cover cover = LoadCoverFromRequest(filename, request);
@@ -1213,7 +1211,7 @@ void TagReaderTagLib::SetUnsyncLyricsFrame(const std::string &value, TagLib::ID3
// If no frames stored create empty frame // If no frames stored create empty frame
if (frames_buffer.isEmpty()) { if (frames_buffer.isEmpty()) {
TagLib::ID3v2::UnsynchronizedLyricsFrame frame(TagLib::String::UTF8); TagLib::ID3v2::UnsynchronizedLyricsFrame frame(TagLib::String::UTF8);
frame.setDescription("Strawberry editor"); frame.setDescription("Clementine editor");
frames_buffer.push_back(frame.render()); frames_buffer.push_back(frame.render());
} }
@@ -1503,10 +1501,10 @@ void TagReaderTagLib::SetEmbeddedArt(TagLib::MP4::File *aac_file, TagLib::MP4::T
} }
else { else {
TagLib::MP4::CoverArt::Format cover_format = TagLib::MP4::CoverArt::Format::JPEG; TagLib::MP4::CoverArt::Format cover_format = TagLib::MP4::CoverArt::Format::JPEG;
if (mime_type == "image/jpeg"_L1) { if (mime_type == QLatin1String("image/jpeg")) {
cover_format = TagLib::MP4::CoverArt::Format::JPEG; cover_format = TagLib::MP4::CoverArt::Format::JPEG;
} }
else if (mime_type == "image/png"_L1) { else if (mime_type == QLatin1String("image/png")) {
cover_format = TagLib::MP4::CoverArt::Format::PNG; cover_format = TagLib::MP4::CoverArt::Format::PNG;
} }
else { else {
@@ -1872,17 +1870,3 @@ TagReaderBase::Result TagReaderTagLib::SaveSongRatingToFile(const QString &filen
return success ? Result::ErrorCode::Success : Result::ErrorCode::FileSaveError; return success ? Result::ErrorCode::Success : Result::ErrorCode::FileSaveError;
} }
TagLib::String TagReaderTagLib::TagLibStringListToSlashSeparatedString(const TagLib::StringList &taglib_string_list) {
TagLib::String result_string;
for (const TagLib::String &taglib_string : taglib_string_list) {
if (!result_string.isEmpty()) {
result_string += '/';
}
result_string += taglib_string;
}
return result_string;
}

View File

@@ -136,8 +136,6 @@ class TagReaderTagLib : public TagReaderBase {
void SetEmbeddedArt(TagLib::ID3v2::Tag *tag, const QByteArray &data, const QString &mime_type) const; void SetEmbeddedArt(TagLib::ID3v2::Tag *tag, const QByteArray &data, const QString &mime_type) const;
void SetEmbeddedArt(TagLib::MP4::File *aac_file, TagLib::MP4::Tag *tag, const QByteArray &data, const QString &mime_type) const; void SetEmbeddedArt(TagLib::MP4::File *aac_file, TagLib::MP4::Tag *tag, const QByteArray &data, const QString &mime_type) const;
static TagLib::String TagLibStringListToSlashSeparatedString(const TagLib::StringList &taglib_string_list);
private: private:
FileRefFactory *factory_; FileRefFactory *factory_;

View File

@@ -0,0 +1,15 @@
qt_wrap_cpp(MACDEPLOYCHECK_MOC ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common/core/logging.h)
link_directories(${GLIB_LIBRARY_DIRS})
add_executable(macdeploycheck macdeploycheck.cpp ${CMAKE_SOURCE_DIR}/ext/libstrawberry-common/core/logging.cpp ${MACDEPLOYCHECK_MOC})
target_include_directories(macdeploycheck PUBLIC SYSTEM
${GLIB_INCLUDE_DIRS}
)
target_include_directories(macdeploycheck PUBLIC
${CMAKE_SOURCE_DIR}/ext/libstrawberry-common
${CMAKE_BINARY_DIR}/src
)
target_link_libraries(macdeploycheck PUBLIC
"-framework AppKit"
${GLIB_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core
)

View File

@@ -0,0 +1,147 @@
/* This file is part of Strawberry.
Copyright 2021, 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 <QCoreApplication>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
#include <QProcess>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include "core/logging.h"
int main(int argc, char **argv);
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
logging::Init();
qLog(Info) << "Running macdeploycheck";
if (argc < 1) {
qLog(Error) << "Usage: macdeploycheck <bundledir>";
return 1;
}
QString bundle_path = QString::fromLocal8Bit(argv[1]);
bool success = true;
QDirIterator iter(bundle_path, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
while (iter.hasNext()) {
iter.next();
QString filepath = iter.fileInfo().filePath();
// Ignore these files.
if (filepath.endsWith(".plist") ||
filepath.endsWith(".icns") ||
filepath.endsWith(".prl") ||
filepath.endsWith(".conf") ||
filepath.endsWith(".h") ||
filepath.endsWith(".nib") ||
filepath.endsWith(".strings") ||
filepath.endsWith(".css") ||
filepath.endsWith("CodeResources") ||
filepath.endsWith("PkgInfo") ||
filepath.endsWith(".modulemap")) {
continue;
}
QProcess otool;
otool.start("otool", QStringList() << "-L" << filepath);
otool.waitForFinished();
if (otool.exitStatus() != QProcess::NormalExit || otool.exitCode() != 0) {
qLog(Error) << "otool failed for" << filepath << ":" << otool.readAllStandardError();
success = false;
continue;
}
QString output = otool.readAllStandardOutput();
QStringList output_lines = output.split("\n", Qt::SkipEmptyParts);
if (output_lines.size() < 2) {
qLog(Error) << "Could not parse otool output:" << output;
success = false;
continue;
}
QString first_line = output_lines.first();
if (first_line.endsWith(':')) first_line.chop(1);
if (first_line == filepath) {
output_lines.removeFirst();
}
else {
qLog(Error) << "First line" << first_line << "does not match" << filepath;
success = false;
}
QRegularExpression regexp(QStringLiteral("^\\t(.+) \\(compatibility version (\\d+\\.\\d+\\.\\d+), current version (\\d+\\.\\d+\\.\\d+)(, weak|, reexport)?\\)$"));
for (const QString &output_line : output_lines) {
//qDebug() << "Final check on" << filepath << output_line;
QRegularExpressionMatch match = regexp.match(output_line);
if (match.hasMatch()) {
QString library = match.captured(1);
if (QFileInfo(library).fileName() == QFileInfo(filepath).fileName()) { // It's this.
continue;
}
else if (library.startsWith("@executable_path")) {
QString real_path = library;
real_path = real_path.replace("@executable_path", bundle_path + "/Contents/MacOS");
if (!QFile::exists(real_path)) {
qLog(Error) << real_path << "does not exist for" << filepath;
success = false;
}
}
else if (library.startsWith("@rpath")) {
QString real_path = library;
real_path = real_path.replace("@rpath", bundle_path + "/Contents/Frameworks");
if (!QFile::exists(real_path) && !real_path.endsWith("QtSvg")) { // FIXME: Ignore broken svg image plugin.
qLog(Error) << real_path << "does not exist for" << filepath;
success = false;
}
}
else if (library.startsWith("@loader_path")) {
QString loader_path = QFileInfo(filepath).path();
QString real_path = library;
real_path = real_path.replace("@loader_path", loader_path);
if (!QFile::exists(real_path)) {
qLog(Error) << real_path << "does not exist for" << filepath;
success = false;
}
}
else if (library.startsWith("/System/Library/") || library.startsWith("/usr/lib/")) { // System library
continue;
}
else {
qLog(Error) << "File" << filepath << "points to" << library;
success = false;
}
}
else {
qLog(Error) << "Could not parse otool output line:" << output_line;
success = false;
}
}
}
return success ? 0 : 1;
}

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
@@ -7,6 +7,16 @@ set(HEADERS tagreaderworker.h)
qt_wrap_cpp(MOC ${HEADERS}) qt_wrap_cpp(MOC ${HEADERS})
link_directories(${GLIB_LIBRARY_DIRS})
if(HAVE_TAGLIB)
link_directories(${TAGLIB_LIBRARY_DIRS})
endif()
if(HAVE_TAGPARSER)
link_directories(${TAGPARSER_LIBRARY_DIRS})
endif()
add_executable(strawberry-tagreader ${SOURCES} ${MOC} ${QRC}) add_executable(strawberry-tagreader ${SOURCES} ${MOC} ${QRC})
target_include_directories(strawberry-tagreader SYSTEM PRIVATE target_include_directories(strawberry-tagreader SYSTEM PRIVATE
@@ -21,8 +31,6 @@ target_include_directories(strawberry-tagreader PRIVATE
${CMAKE_BINARY_DIR}/src ${CMAKE_BINARY_DIR}/src
) )
target_link_directories(strawberry-tagreader PRIVATE ${GLIB_LIBRARY_DIRS})
target_link_libraries(strawberry-tagreader PRIVATE target_link_libraries(strawberry-tagreader PRIVATE
${GLIB_LIBRARIES} ${GLIB_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Core
@@ -33,13 +41,11 @@ target_link_libraries(strawberry-tagreader PRIVATE
if(HAVE_TAGLIB) if(HAVE_TAGLIB)
target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS}) target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGLIB_INCLUDE_DIRS})
target_link_directories(strawberry-tagreader PRIVATE ${TAGLIB_LIBRARY_DIRS})
target_link_libraries(strawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES}) target_link_libraries(strawberry-tagreader PRIVATE ${TAGLIB_LIBRARIES})
endif() endif()
if(HAVE_TAGPARSER) if(HAVE_TAGPARSER)
target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS}) target_include_directories(strawberry-tagreader SYSTEM PRIVATE ${TAGPARSER_INCLUDE_DIRS})
target_link_directories(strawberry-tagreader PRIVATE ${TAGPARSER_LIBRARY_DIRS})
target_link_libraries(strawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES}) target_link_libraries(strawberry-tagreader PRIVATE ${TAGPARSER_LIBRARIES})
endif() endif()

View File

@@ -18,7 +18,6 @@
#include "config.h" #include "config.h"
#include <utility>
#include <memory> #include <memory>
#include <string> #include <string>
@@ -74,7 +73,7 @@ void TagReaderWorker::DeviceClosed() {
void TagReaderWorker::HandleMessage(const spb::tagreader::Message &message, spb::tagreader::Message &reply) { void TagReaderWorker::HandleMessage(const spb::tagreader::Message &message, spb::tagreader::Message &reply) {
for (shared_ptr<TagReaderBase> reader : std::as_const(tagreaders_)) { for (shared_ptr<TagReaderBase> reader : tagreaders_) {
if (message.has_is_media_file_request()) { if (message.has_is_media_file_request()) {
const QString filename = QString::fromStdString(message.is_media_file_request().filename()); const QString filename = QString::fromStdString(message.is_media_file_request().filename());

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.7)
if(HAVE_TRANSLATIONS) if(HAVE_TRANSLATIONS)
include(../cmake/Translations.cmake) include(../cmake/Translations.cmake)
@@ -41,9 +41,6 @@ set(SOURCES
core/translations.cpp core/translations.cpp
core/systemtrayicon.cpp core/systemtrayicon.cpp
core/localredirectserver.cpp core/localredirectserver.cpp
core/mimedata.cpp
core/potranslator.cpp
core/temporaryfile.cpp
utilities/strutils.cpp utilities/strutils.cpp
utilities/envutils.cpp utilities/envutils.cpp
utilities/colorutils.cpp utilities/colorutils.cpp
@@ -113,10 +110,8 @@ set(SOURCES
playlist/playlistfilter.cpp playlist/playlistfilter.cpp
playlist/playlistheader.cpp playlist/playlistheader.cpp
playlist/playlistitem.cpp playlist/playlistitem.cpp
playlist/playlistitemmimedata.cpp
playlist/playlistlistcontainer.cpp playlist/playlistlistcontainer.cpp
playlist/playlistlistmodel.cpp playlist/playlistlistmodel.cpp
playlist/playlistlistsortfiltermodel.cpp
playlist/playlistlistview.cpp playlist/playlistlistview.cpp
playlist/playlistmanager.cpp playlist/playlistmanager.cpp
playlist/playlistsaveoptionsdialog.cpp playlist/playlistsaveoptionsdialog.cpp
@@ -125,7 +120,6 @@ set(SOURCES
playlist/playlistundocommands.cpp playlist/playlistundocommands.cpp
playlist/playlistview.cpp playlist/playlistview.cpp
playlist/playlistproxystyle.cpp playlist/playlistproxystyle.cpp
playlist/songmimedata.cpp
playlist/songloaderinserter.cpp playlist/songloaderinserter.cpp
playlist/songplaylistitem.cpp playlist/songplaylistitem.cpp
playlist/dynamicplaylistcontrols.cpp playlist/dynamicplaylistcontrols.cpp
@@ -146,23 +140,17 @@ set(SOURCES
smartplaylists/playlistgenerator.cpp smartplaylists/playlistgenerator.cpp
smartplaylists/playlistgeneratorinserter.cpp smartplaylists/playlistgeneratorinserter.cpp
smartplaylists/playlistgeneratormimedata.cpp
smartplaylists/playlistquerygenerator.cpp smartplaylists/playlistquerygenerator.cpp
smartplaylists/smartplaylistquerywizardplugin.cpp smartplaylists/smartplaylistquerywizardplugin.cpp
smartplaylists/smartplaylistquerywizardpluginsortpage.cpp
smartplaylists/smartplaylistquerywizardpluginsearchpage.cpp
smartplaylists/smartplaylistsearch.cpp smartplaylists/smartplaylistsearch.cpp
smartplaylists/smartplaylistsearchpreview.cpp smartplaylists/smartplaylistsearchpreview.cpp
smartplaylists/smartplaylistsearchterm.cpp smartplaylists/smartplaylistsearchterm.cpp
smartplaylists/smartplaylistsearchtermwidget.cpp smartplaylists/smartplaylistsearchtermwidget.cpp
smartplaylists/smartplaylistsearchtermwidgetoverlay.cpp
smartplaylists/smartplaylistsmodel.cpp smartplaylists/smartplaylistsmodel.cpp
smartplaylists/smartplaylistsviewcontainer.cpp smartplaylists/smartplaylistsviewcontainer.cpp
smartplaylists/smartplaylistsview.cpp smartplaylists/smartplaylistsview.cpp
smartplaylists/smartplaylistwizard.cpp smartplaylists/smartplaylistwizard.cpp
smartplaylists/smartplaylistwizardplugin.cpp smartplaylists/smartplaylistwizardplugin.cpp
smartplaylists/smartplaylistwizardtypepage.cpp
smartplaylists/smartplaylistwizardfinishpage.cpp
covermanager/albumcovermanager.cpp covermanager/albumcovermanager.cpp
covermanager/albumcovermanagerlist.cpp covermanager/albumcovermanagerlist.cpp
@@ -207,7 +195,6 @@ set(SOURCES
lyrics/azlyricscomlyricsprovider.cpp lyrics/azlyricscomlyricsprovider.cpp
lyrics/elyricsnetlyricsprovider.cpp lyrics/elyricsnetlyricsprovider.cpp
lyrics/letraslyricsprovider.cpp lyrics/letraslyricsprovider.cpp
lyrics/lyricfindlyricsprovider.cpp
providers/musixmatchprovider.cpp providers/musixmatchprovider.cpp
@@ -283,7 +270,6 @@ set(SOURCES
streaming/streamingcollectionview.cpp streaming/streamingcollectionview.cpp
streaming/streamingcollectionviewcontainer.cpp streaming/streamingcollectionviewcontainer.cpp
streaming/streamingsearchview.cpp streaming/streamingsearchview.cpp
streaming/streamsongmimedata.cpp
radios/radioservices.cpp radios/radioservices.cpp
radios/radiobackend.cpp radios/radiobackend.cpp
@@ -295,7 +281,6 @@ set(SOURCES
radios/radiochannel.cpp radios/radiochannel.cpp
radios/somafmservice.cpp radios/somafmservice.cpp
radios/radioparadiseservice.cpp radios/radioparadiseservice.cpp
radios/radiomimedata.cpp
scrobbler/audioscrobbler.cpp scrobbler/audioscrobbler.cpp
scrobbler/scrobblersettings.cpp scrobbler/scrobblersettings.cpp
@@ -311,8 +296,6 @@ set(SOURCES
organize/organize.cpp organize/organize.cpp
organize/organizeformat.cpp organize/organizeformat.cpp
organize/organizeformatvalidator.cpp
organize/organizesyntaxhighlighter.cpp
organize/organizedialog.cpp organize/organizedialog.cpp
organize/organizeerrordialog.cpp organize/organizeerrordialog.cpp
@@ -415,18 +398,13 @@ set(HEADERS
smartplaylists/playlistquerygenerator.h smartplaylists/playlistquerygenerator.h
smartplaylists/playlistgeneratormimedata.h smartplaylists/playlistgeneratormimedata.h
smartplaylists/smartplaylistquerywizardplugin.h smartplaylists/smartplaylistquerywizardplugin.h
smartplaylists/smartplaylistquerywizardpluginsortpage.h
smartplaylists/smartplaylistquerywizardpluginsearchpage.h
smartplaylists/smartplaylistsearchpreview.h smartplaylists/smartplaylistsearchpreview.h
smartplaylists/smartplaylistsearchtermwidget.h smartplaylists/smartplaylistsearchtermwidget.h
smartplaylists/smartplaylistsearchtermwidgetoverlay.h
smartplaylists/smartplaylistsmodel.h smartplaylists/smartplaylistsmodel.h
smartplaylists/smartplaylistsviewcontainer.h smartplaylists/smartplaylistsviewcontainer.h
smartplaylists/smartplaylistsview.h smartplaylists/smartplaylistsview.h
smartplaylists/smartplaylistwizard.h smartplaylists/smartplaylistwizard.h
smartplaylists/smartplaylistwizardplugin.h smartplaylists/smartplaylistwizardplugin.h
smartplaylists/smartplaylistwizardtypepage.h
smartplaylists/smartplaylistwizardfinishpage.h
covermanager/albumcovermanager.h covermanager/albumcovermanager.h
covermanager/albumcovermanagerlist.h covermanager/albumcovermanagerlist.h
@@ -467,7 +445,6 @@ set(HEADERS
lyrics/azlyricscomlyricsprovider.h lyrics/azlyricscomlyricsprovider.h
lyrics/elyricsnetlyricsprovider.h lyrics/elyricsnetlyricsprovider.h
lyrics/letraslyricsprovider.h lyrics/letraslyricsprovider.h
lyrics/lyricfindlyricsprovider.h
settings/settingsdialog.h settings/settingsdialog.h
settings/settingspage.h settings/settingspage.h
@@ -522,7 +499,7 @@ set(HEADERS
widgets/tracksliderpopup.h widgets/tracksliderpopup.h
widgets/tracksliderslider.h widgets/tracksliderslider.h
widgets/loginstatewidget.h widgets/loginstatewidget.h
widgets/searchfield.h widgets/qsearchfield.h
widgets/ratingwidget.h widgets/ratingwidget.h
widgets/forcescrollperpixel.h widgets/forcescrollperpixel.h
widgets/resizabletextedit.h widgets/resizabletextedit.h
@@ -563,8 +540,6 @@ set(HEADERS
scrobbler/lastfmimport.h scrobbler/lastfmimport.h
organize/organize.h organize/organize.h
organize/organizeformatvalidator.h
organize/organizesyntaxhighlighter.h
organize/organizedialog.h organize/organizedialog.h
organize/organizeerrordialog.h organize/organizeerrordialog.h
@@ -650,7 +625,7 @@ option(USE_INSTALL_PREFIX "Look for data in CMAKE_INSTALL_PREFIX" ON)
if(NOT APPLE) if(NOT APPLE)
set(NOT_APPLE ON) set(NOT_APPLE ON)
optional_source(NOT_APPLE SOURCES widgets/searchfield_qt.cpp widgets/searchfield_qt_private.cpp core/qtsystemtrayicon.cpp HEADERS core/qtsystemtrayicon.h widgets/searchfield_qt_private.h) optional_source(NOT_APPLE SOURCES widgets/qsearchfield_qt.cpp core/qtsystemtrayicon.cpp HEADERS core/qtsystemtrayicon.h)
endif() endif()
if(HAVE_GLOBALSHORTCUTS) if(HAVE_GLOBALSHORTCUTS)
@@ -789,7 +764,6 @@ optional_source(HAVE_LIBPULSE SOURCES engine/pulsedevicefinder.cpp)
optional_source(HAVE_GSTREAMER optional_source(HAVE_GSTREAMER
SOURCES SOURCES
transcoder/transcoder.cpp transcoder/transcoder.cpp
transcoder/transcoderoptionsinterface.cpp
transcoder/transcodedialog.cpp transcoder/transcodedialog.cpp
transcoder/transcoderoptionsdialog.cpp transcoder/transcoderoptionsdialog.cpp
transcoder/transcoderoptionsflac.cpp transcoder/transcoderoptionsflac.cpp
@@ -868,7 +842,7 @@ optional_source(APPLE
core/macsystemtrayicon.mm core/macsystemtrayicon.mm
core/macfslistener.mm core/macfslistener.mm
osd/osdmac.mm osd/osdmac.mm
widgets/searchfield_mac.mm widgets/qsearchfield_mac.mm
engine/macosdevicefinder.cpp engine/macosdevicefinder.cpp
globalshortcuts/globalshortcutsbackend-macos.mm globalshortcuts/globalshortcutsbackend-macos.mm
globalshortcuts/globalshortcutgrabber.mm globalshortcuts/globalshortcutgrabber.mm
@@ -988,7 +962,6 @@ optional_source(HAVE_MOODBAR
moodbar/moodbarpipeline.cpp moodbar/moodbarpipeline.cpp
moodbar/moodbarproxystyle.cpp moodbar/moodbarproxystyle.cpp
moodbar/moodbarrenderer.cpp moodbar/moodbarrenderer.cpp
moodbar/gstfastspectrumplugin.cpp
settings/moodbarsettingspage.cpp settings/moodbarsettingspage.cpp
HEADERS HEADERS
moodbar/moodbarcontroller.h moodbar/moodbarcontroller.h
@@ -1031,20 +1004,95 @@ if(HAVE_TRANSLATIONS)
endif(NOT LINGUAS OR LINGUAS STREQUAL "None") endif(NOT LINGUAS OR LINGUAS STREQUAL "None")
endif(LINGUAS STREQUAL "All") endif(LINGUAS STREQUAL "All")
if(NOT MSVC) add_pot(POT
add_pot(POT ${CMAKE_CURRENT_SOURCE_DIR}/translations/header
${CMAKE_CURRENT_SOURCE_DIR}/translations/header ${CMAKE_CURRENT_BINARY_DIR}/translations/translations.pot
${CMAKE_CURRENT_SOURCE_DIR}/translations/translations.pot ${SOURCES}
${SOURCES} ${MOC}
${MOC} ${UIC}
${UIC} ${CMAKE_SOURCE_DIR}/data/html/oauthsuccess.html
${CMAKE_SOURCE_DIR}/data/html/oauthsuccess.html )
)
endif()
add_po(PO strawberry_ LANGUAGES ${LANGUAGES} DIRECTORY translations) add_po(PO strawberry_ LANGUAGES ${LANGUAGES} DIRECTORY translations)
endif(HAVE_TRANSLATIONS) endif(HAVE_TRANSLATIONS)
link_directories(
${Boost_LIBRARY_DIRS}
${GLIB_LIBRARY_DIRS}
${GOBJECT_LIBRARY_DIRS}
${SQLITE_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
${SINGLEAPPLICATION_LIBRARY_DIRS}
${ICU_LIBRARY_DIRS}
)
if(HAVE_ALSA)
link_directories(${ALSA_LIBRARY_DIRS})
endif()
if(HAVE_LIBPULSE)
link_directories(${LIBPULSE_LIBRARY_DIRS})
endif()
if(HAVE_GSTREAMER)
link_directories(
${GSTREAMER_LIBRARY_DIRS}
${GSTREAMER_BASE_LIBRARY_DIRS}
${GSTREAMER_APP_LIBRARY_DIRS}
${GSTREAMER_AUDIO_LIBRARY_DIRS}
${GSTREAMER_TAG_LIBRARY_DIRS}
${GSTREAMER_PBUTILS_LIBRARY_DIRS}
)
endif()
if(HAVE_VLC)
link_directories(${LIBVLC_LIBRARY_DIRS})
endif()
if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ)
link_directories(${CHROMAPRINT_LIBRARY_DIRS})
endif()
if(X11_FOUND)
link_directories(${X11_LIBRARY_DIRS})
endif()
if(XCB_FOUND)
link_directories(${XCB_LIBRARY_DIRS})
endif()
if(HAVE_GIO)
link_directories(${GIO_LIBRARY_DIRS})
endif()
if(HAVE_GIO_UNIX)
link_directories(${GIO_UNIX_LIBRARY_DIRS})
endif()
if(HAVE_AUDIOCD)
link_directories(${LIBCDIO_LIBRARY_DIRS})
endif()
if(HAVE_LIBGPOD)
link_directories(${LIBGPOD_LIBRARY_DIRS} ${GDK_PIXBUF_LIBRARY_DIRS})
endif()
if(HAVE_LIBMTP)
link_directories(${LIBMTP_LIBRARY_DIRS})
endif()
if(HAVE_TAGLIB)
link_directories(${TAGLIB_LIBRARY_DIRS})
endif()
if(HAVE_TAGPARSER)
link_directories(${TAGPARSER_LIBRARY_DIRS})
endif()
if(HAVE_QTSPARKLE)
link_directories(${QTSPARKLE_LIBRARY_DIRS})
endif()
add_library(strawberry_lib STATIC add_library(strawberry_lib STATIC
${SOURCES} ${SOURCES}
${MOC} ${MOC}
@@ -1079,16 +1127,6 @@ target_include_directories(strawberry_lib PUBLIC
${SINGLEAPPLICATION_INCLUDE_DIRS} ${SINGLEAPPLICATION_INCLUDE_DIRS}
) )
target_link_directories(strawberry_lib PUBLIC
${Boost_LIBRARY_DIRS}
${GLIB_LIBRARY_DIRS}
${GOBJECT_LIBRARY_DIRS}
${SQLITE_LIBRARY_DIRS}
${PROTOBUF_LIBRARY_DIRS}
${SINGLEAPPLICATION_LIBRARY_DIRS}
${ICU_LIBRARY_DIRS}
)
target_link_libraries(strawberry_lib PUBLIC target_link_libraries(strawberry_lib PUBLIC
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${GLIB_LIBRARIES} ${GLIB_LIBRARIES}
@@ -1111,15 +1149,17 @@ if(HAVE_DBUS)
target_link_libraries(strawberry_lib PUBLIC Qt${QT_VERSION_MAJOR}::DBus) target_link_libraries(strawberry_lib PUBLIC Qt${QT_VERSION_MAJOR}::DBus)
endif() endif()
if(HAVE_X11_GLOBALSHORTCUTS AND HAVE_X11EXTRAS)
target_link_libraries(strawberry_lib PUBLIC Qt${QT_VERSION_MAJOR}::X11Extras)
endif()
if(HAVE_ALSA) if(HAVE_ALSA)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${ALSA_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${ALSA_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${ALSA_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${ALSA_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${ALSA_LIBRARIES})
endif() endif()
if(HAVE_LIBPULSE) if(HAVE_LIBPULSE)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBPULSE_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBPULSE_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${LIBPULSE_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${LIBPULSE_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${LIBPULSE_LIBRARIES})
endif() endif()
@@ -1132,14 +1172,6 @@ if(HAVE_GSTREAMER)
${GSTREAMER_TAG_INCLUDE_DIRS} ${GSTREAMER_TAG_INCLUDE_DIRS}
${GSTREAMER_PBUTILS_INCLUDE_DIRS} ${GSTREAMER_PBUTILS_INCLUDE_DIRS}
) )
target_link_directories(strawberry_lib PRIVATE
${GSTREAMER_LIBRARY_DIRS}
${GSTREAMER_BASE_LIBRARY_DIRS}
${GSTREAMER_APP_LIBRARY_DIRS}
${GSTREAMER_AUDIO_LIBRARY_DIRS}
${GSTREAMER_TAG_LIBRARY_DIRS}
${GSTREAMER_PBUTILS_LIBRARY_DIRS}
)
target_link_libraries(strawberry_lib PRIVATE target_link_libraries(strawberry_lib PRIVATE
${GSTREAMER_LIBRARIES} ${GSTREAMER_LIBRARIES}
${GSTREAMER_BASE_LIBRARIES} ${GSTREAMER_BASE_LIBRARIES}
@@ -1151,19 +1183,16 @@ if(HAVE_GSTREAMER)
endif() endif()
if(HAVE_MOODBAR) if(HAVE_MOODBAR)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/gstfastspectrum) target_link_libraries(strawberry_lib PRIVATE gstmoodbar)
target_link_libraries(strawberry_lib PRIVATE gstfastspectrum)
endif() endif()
if(HAVE_VLC) if(HAVE_VLC)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBVLC_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBVLC_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${LIBVLC_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${LIBVLC_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${LIBVLC_LIBRARIES})
endif() endif()
if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ) if(HAVE_SONGFINGERPRINTING OR HAVE_MUSICBRAINZ)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${CHROMAPRINT_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${CHROMAPRINT_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${CHROMAPRINT_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${CHROMAPRINT_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${CHROMAPRINT_LIBRARIES})
endif() endif()
@@ -1173,43 +1202,36 @@ endif()
if(X11_FOUND) if(X11_FOUND)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${X11_INCLUDE_DIR}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${X11_INCLUDE_DIR})
target_link_directories(strawberry_lib PRIVATE ${X11_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${X11_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${X11_LIBRARIES})
endif() endif()
if(XCB_FOUND) if(XCB_FOUND)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${XCB_INCLUDE_DIR}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${XCB_INCLUDE_DIR})
target_link_directories(strawberry_lib PRIVATE ${XCB_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${XCB_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${XCB_LIBRARIES})
endif() endif()
if(HAVE_GIO) if(HAVE_GIO)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${GIO_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${GIO_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${GIO_LIBRARIES})
endif() endif()
if(HAVE_GIO_UNIX) if(HAVE_GIO_UNIX)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_UNIX_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${GIO_UNIX_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${GIO_UNIX_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${GIO_UNIX_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${GIO_UNIX_LIBRARIES})
endif() endif()
if(HAVE_AUDIOCD) if(HAVE_AUDIOCD)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBCDIO_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBCDIO_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${LIBCDIO_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${LIBCDIO_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${LIBCDIO_LIBRARIES})
endif() endif()
if(HAVE_LIBGPOD) if(HAVE_LIBGPOD)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBGPOD_INCLUDE_DIRS} ${GDK_PIXBUF_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBGPOD_INCLUDE_DIRS} ${GDK_PIXBUF_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${LIBGPOD_LIBRARY_DIRS} ${GDK_PIXBUF_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${LIBGPOD_LIBRARIES} ${GDK_PIXBUF_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${LIBGPOD_LIBRARIES} ${GDK_PIXBUF_LIBRARIES})
endif() endif()
if(HAVE_LIBMTP) if(HAVE_LIBMTP)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBMTP_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${LIBMTP_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${LIBMTP_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${LIBMTP_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${LIBMTP_LIBRARIES})
endif() endif()
@@ -1231,12 +1253,16 @@ if(WIN32)
if(MSVC) if(MSVC)
target_link_libraries(strawberry_lib PRIVATE WindowsApp) target_link_libraries(strawberry_lib PRIVATE WindowsApp)
endif() endif()
target_link_libraries(strawberry_lib PRIVATE getopt-win::getopt) if(GETOPT_INCLUDE_DIRS)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${GETOPT_INCLUDE_DIRS})
endif()
if(GETOPT_LIBRARIES)
target_link_libraries(strawberry_lib PRIVATE ${GETOPT_LIBRARIES})
endif()
endif() endif()
if(HAVE_QTSPARKLE) if(HAVE_QTSPARKLE)
target_include_directories(strawberry_lib SYSTEM PRIVATE ${QTSPARKLE_INCLUDE_DIRS}) target_include_directories(strawberry_lib SYSTEM PRIVATE ${QTSPARKLE_INCLUDE_DIRS})
target_link_directories(strawberry_lib PRIVATE ${QTSPARKLE_LIBRARY_DIRS})
target_link_libraries(strawberry_lib PRIVATE ${QTSPARKLE_LIBRARIES}) target_link_libraries(strawberry_lib PRIVATE ${QTSPARKLE_LIBRARIES})
endif() endif()

View File

@@ -116,7 +116,11 @@ void AnalyzerContainer::mouseReleaseEvent(QMouseEvent *e) {
} }
if (e->button() == Qt::RightButton) { if (e->button() == Qt::RightButton) {
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
context_menu_->popup(e->globalPosition().toPoint()); context_menu_->popup(e->globalPosition().toPoint());
#else
context_menu_->popup(e->globalPos());
#endif
} }
} }
@@ -126,7 +130,7 @@ void AnalyzerContainer::ShowPopupMenu() {
} }
void AnalyzerContainer::wheelEvent(QWheelEvent *e) { void AnalyzerContainer::wheelEvent(QWheelEvent *e) {
Q_EMIT WheelEvent(e->angleDelta().y()); emit WheelEvent(e->angleDelta().y());
} }
void AnalyzerContainer::SetEngine(SharedPtr<EngineBase> engine) { void AnalyzerContainer::SetEngine(SharedPtr<EngineBase> engine) {
@@ -145,7 +149,7 @@ void AnalyzerContainer::DisableAnalyzer() {
void AnalyzerContainer::ChangeAnalyzer(const int id) { void AnalyzerContainer::ChangeAnalyzer(const int id) {
QObject *instance = analyzer_types_.at(id)->newInstance(Q_ARG(QWidget*, this)); QObject *instance = analyzer_types_[id]->newInstance(Q_ARG(QWidget*, this));
if (!instance) { if (!instance) {
qLog(Warning) << "Couldn't initialize a new" << analyzer_types_[id]->className(); qLog(Warning) << "Couldn't initialize a new" << analyzer_types_[id]->className();
@@ -196,25 +200,22 @@ void AnalyzerContainer::Load() {
for (int i = 0; i < analyzer_types_.count(); ++i) { for (int i = 0; i < analyzer_types_.count(); ++i) {
if (type == QString::fromLatin1(analyzer_types_[i]->className())) { if (type == QString::fromLatin1(analyzer_types_[i]->className())) {
ChangeAnalyzer(i); ChangeAnalyzer(i);
QAction *action = actions_.value(i); actions_[i]->setChecked(true);
action->setChecked(true);
break; break;
} }
} }
if (!current_analyzer_) { if (!current_analyzer_) {
ChangeAnalyzer(0); ChangeAnalyzer(0);
QAction *action = actions_.value(0); actions_[0]->setChecked(true);
action->setChecked(true);
} }
} }
// Framerate // Framerate
const QList<QAction*> actions = group_framerate_->actions(); QList<QAction*> actions = group_framerate_->actions();
for (int i = 0; i < framerate_list_.count(); ++i) { for (int i = 0; i < framerate_list_.count(); ++i) {
if (current_framerate_ == framerate_list_.value(i)) { if (current_framerate_ == framerate_list_[i]) {
ChangeFramerate(current_framerate_); ChangeFramerate(current_framerate_);
QAction *action = actions[i]; actions[i]->setChecked(true);
action->setChecked(true);
break; break;
} }
} }

View File

@@ -50,14 +50,14 @@ class AnalyzerContainer : public QWidget {
static const char *kSettingsGroup; static const char *kSettingsGroup;
static const char *kSettingsFramerate; static const char *kSettingsFramerate;
Q_SIGNALS: signals:
void WheelEvent(const int delta); void WheelEvent(const int delta);
protected: protected:
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override; void wheelEvent(QWheelEvent *e) override;
private Q_SLOTS: private slots:
void ChangeAnalyzer(const int id); void ChangeAnalyzer(const int id);
void ChangeFramerate(int new_framerate); void ChangeFramerate(int new_framerate);
void DisableAnalyzer(); void DisableAnalyzer();

View File

@@ -167,12 +167,11 @@ void BlockAnalyzer::analyze(QPainter &p, const Scope &s, const bool new_frame) {
for (int x = 0, y = 0; x < static_cast<int>(scope_.size()); ++x) { for (int x = 0, y = 0; x < static_cast<int>(scope_.size()); ++x) {
// determine y // determine y
for (y = 0; scope_[x] < yscale_.at(y); ++y); for (y = 0; scope_[x] < yscale_[y]; ++y);
// This is opposite to what you'd think, higher than y means the bar is lower than y (physically) // This is opposite to what you'd think, higher than y means the bar is lower than y (physically)
if (static_cast<double>(y) > store_.at(x)) { if (static_cast<double>(y) > store_[x]) {
store_[x] += step_; y = static_cast<int>(store_[x] += step_);
y = static_cast<int>(store_.value(x));
} }
else { else {
store_[x] = y; store_[x] = y;
@@ -180,19 +179,18 @@ void BlockAnalyzer::analyze(QPainter &p, const Scope &s, const bool new_frame) {
// If y is lower than fade_pos_, then the bar has exceeded the height of the fadeout // If y is lower than fade_pos_, then the bar has exceeded the height of the fadeout
// if the fadeout is quite faded now, then display the new one // if the fadeout is quite faded now, then display the new one
if (y <= fade_pos_.at(x) /*|| fade_intensity_[x] < kFadeSize / 3*/) { if (y <= fade_pos_[x] /*|| fade_intensity_[x] < kFadeSize / 3*/) {
fade_pos_[x] = y; fade_pos_[x] = y;
fade_intensity_[x] = kFadeSize; fade_intensity_[x] = kFadeSize;
} }
if (fade_intensity_.at(x) > 0) { if (fade_intensity_[x] > 0) {
--fade_intensity_[x]; const int offset = --fade_intensity_[x];
const int offset = fade_intensity_.value(x); const int y2 = y_ + (fade_pos_[x] * (kHeight + 1));
const int y2 = y_ + (fade_pos_.value(x) * (kHeight + 1));
canvas_painter.drawPixmap(x * (kWidth + 1), y2, fade_bars_[offset], 0, 0, kWidth, height() - y2); canvas_painter.drawPixmap(x * (kWidth + 1), y2, fade_bars_[offset], 0, 0, kWidth, height() - y2);
} }
if (fade_intensity_.at(x) == 0) fade_pos_[x] = rows_; if (fade_intensity_[x] == 0) fade_pos_[x] = rows_;
// REMEMBER: y is a number from 0 to rows_, 0 means all blocks are glowing, rows_ means none are // REMEMBER: y is a number from 0 to rows_, 0 means all blocks are glowing, rows_ means none are
canvas_painter.drawPixmap(x * (kWidth + 1), y * (kHeight + 1) + y_, *bar(), 0, y * (kHeight + 1), bar()->width(), bar()->height()); canvas_painter.drawPixmap(x * (kWidth + 1), y * (kHeight + 1) + y_, *bar(), 0, y * (kHeight + 1), bar()->width(), bar()->height());

View File

@@ -47,7 +47,7 @@ class BoomAnalyzer : public AnalyzerBase {
void transform(Scope &s) override; void transform(Scope &s) override;
void analyze(QPainter &p, const Scope &scope, const bool new_frame) override; void analyze(QPainter &p, const Scope &scope, const bool new_frame) override;
public Q_SLOTS: public slots:
void changeK_barHeight(int); void changeK_barHeight(int);
void changeF_peakSpeed(int); void changeF_peakSpeed(int);

View File

@@ -63,8 +63,6 @@ SCollection::SCollection(Application *app, QObject *parent)
save_playcounts_to_files_(false), save_playcounts_to_files_(false),
save_ratings_to_files_(false) { save_ratings_to_files_(false) {
setObjectName(QLatin1String(metaObject()->className()));
original_thread_ = thread(); original_thread_ = thread();
backend_ = make_shared<CollectionBackend>(); backend_ = make_shared<CollectionBackend>();
@@ -82,7 +80,7 @@ SCollection::SCollection(Application *app, QObject *parent)
SCollection::~SCollection() { SCollection::~SCollection() {
if (watcher_) { if (watcher_) {
watcher_->Abort(); watcher_->Stop();
watcher_->deleteLater(); watcher_->deleteLater();
} }
if (watcher_thread_) { if (watcher_thread_) {
@@ -96,7 +94,6 @@ void SCollection::Init() {
watcher_ = new CollectionWatcher(Song::Source::Collection); watcher_ = new CollectionWatcher(Song::Source::Collection);
watcher_thread_ = new Thread(this); watcher_thread_ = new Thread(this);
watcher_thread_->setObjectName(watcher_->objectName());
watcher_thread_->SetIoPriority(Utilities::IoPriority::IOPRIO_CLASS_IDLE); watcher_thread_->SetIoPriority(Utilities::IoPriority::IOPRIO_CLASS_IDLE);
@@ -154,7 +151,7 @@ void SCollection::ExitReceived() {
QObject::disconnect(obj, nullptr, this, nullptr); QObject::disconnect(obj, nullptr, this, nullptr);
qLog(Debug) << obj << "successfully exited."; qLog(Debug) << obj << "successfully exited.";
wait_for_exit_.removeAll(obj); wait_for_exit_.removeAll(obj);
if (wait_for_exit_.isEmpty()) Q_EMIT ExitFinished(); if (wait_for_exit_.isEmpty()) emit ExitFinished();
} }
@@ -162,7 +159,7 @@ void SCollection::IncrementalScan() { watcher_->IncrementalScanAsync(); }
void SCollection::FullScan() { watcher_->FullScanAsync(); } void SCollection::FullScan() { watcher_->FullScanAsync(); }
void SCollection::StopScan() { watcher_->Stop(); } void SCollection::AbortScan() { watcher_->Stop(); }
void SCollection::Rescan(const SongList &songs) { void SCollection::Rescan(const SongList &songs) {
@@ -192,7 +189,11 @@ void SCollection::ReloadSettings() {
void SCollection::SyncPlaycountAndRatingToFilesAsync() { void SCollection::SyncPlaycountAndRatingToFilesAsync() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
(void)QtConcurrent::run(&SCollection::SyncPlaycountAndRatingToFiles, this); (void)QtConcurrent::run(&SCollection::SyncPlaycountAndRatingToFiles, this);
#else
(void)QtConcurrent::run(this, &SCollection::SyncPlaycountAndRatingToFiles);
#endif
} }

View File

@@ -64,24 +64,24 @@ class SCollection : public QObject {
private: private:
void SyncPlaycountAndRatingToFiles(); void SyncPlaycountAndRatingToFiles();
public Q_SLOTS: public slots:
void ReloadSettings(); void ReloadSettings();
void PauseWatcher(); void PauseWatcher();
void ResumeWatcher(); void ResumeWatcher();
void FullScan(); void FullScan();
void StopScan(); void AbortScan();
void Rescan(const SongList &songs); void Rescan(const SongList &songs);
void IncrementalScan(); void IncrementalScan();
private Q_SLOTS: private 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);
void SongsRatingChanged(const SongList &songs, const bool save_tags = false); void SongsRatingChanged(const SongList &songs, const bool save_tags = false);
Q_SIGNALS: signals:
void Error(const QString &error); void Error(const QString &error);
void ExitFinished(); void ExitFinished();

View File

@@ -59,8 +59,6 @@
#include "collectionquery.h" #include "collectionquery.h"
#include "collectiontask.h" #include "collectiontask.h"
using namespace Qt::StringLiterals;
CollectionBackend::CollectionBackend(QObject *parent) CollectionBackend::CollectionBackend(QObject *parent)
: CollectionBackendInterface(parent), : CollectionBackendInterface(parent),
db_(nullptr), db_(nullptr),
@@ -74,21 +72,17 @@ CollectionBackend::CollectionBackend(QObject *parent)
CollectionBackend::~CollectionBackend() { CollectionBackend::~CollectionBackend() {
qLog(Debug) << "Collection backend" << this << "deleted"; qLog(Debug) << "Collection backend" << this << "for" << Song::TextForSource(source_) << "deleted";
} }
void CollectionBackend::Init(SharedPtr<Database> db, SharedPtr<TaskManager> task_manager, const Song::Source source, const QString &songs_table, const QString &dirs_table, const QString &subdirs_table) { void CollectionBackend::Init(SharedPtr<Database> db, SharedPtr<TaskManager> task_manager, const Song::Source source, const QString &songs_table, const QString &dirs_table, const QString &subdirs_table) {
setObjectName(source == Song::Source::Collection ? QLatin1String(metaObject()->className()) : QStringLiteral("%1%2").arg(Song::DescriptionForSource(source), QLatin1String(metaObject()->className())));
db_ = db; db_ = db;
task_manager_ = task_manager; task_manager_ = task_manager;
source_ = source; source_ = source;
songs_table_ = songs_table; songs_table_ = songs_table;
dirs_table_ = dirs_table; dirs_table_ = dirs_table;
subdirs_table_ = subdirs_table; subdirs_table_ = subdirs_table;
} }
void CollectionBackend::Close() { void CollectionBackend::Close() {
@@ -109,7 +103,7 @@ void CollectionBackend::Exit() {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
moveToThread(original_thread_); moveToThread(original_thread_);
Q_EMIT ExitFinished(); emit ExitFinished();
} }
@@ -120,8 +114,8 @@ void CollectionBackend::ReportErrors(const CollectionQuery &query) {
qLog(Error) << "Unable to execute collection SQL query:" << sql_error; qLog(Error) << "Unable to execute collection SQL query:" << sql_error;
qLog(Error) << "Failed SQL query:" << query.lastQuery(); qLog(Error) << "Failed SQL query:" << query.lastQuery();
qLog(Error) << "Bound SQL values:" << query.boundValues(); qLog(Error) << "Bound SQL values:" << query.boundValues();
Q_EMIT Error(tr("Unable to execute collection SQL query: %1").arg(sql_error.text())); emit Error(tr("Unable to execute collection SQL query: %1").arg(sql_error.text()));
Q_EMIT Error(tr("Failed SQL query: %1").arg(query.lastQuery())); emit Error(tr("Failed SQL query: %1").arg(query.lastQuery()));
} }
} }
@@ -140,7 +134,7 @@ void CollectionBackend::GetAllSongs(const int id) {
q.prepare(QStringLiteral("SELECT %1 FROM %2").arg(Song::kRowIdColumnSpec, songs_table_)); q.prepare(QStringLiteral("SELECT %1 FROM %2").arg(Song::kRowIdColumnSpec, songs_table_));
if (!q.exec()) { if (!q.exec()) {
db_->ReportErrors(q); db_->ReportErrors(q);
Q_EMIT GotSongs(SongList(), id); emit GotSongs(SongList(), id);
return; return;
} }
@@ -151,7 +145,7 @@ void CollectionBackend::GetAllSongs(const int id) {
songs << song; songs << song;
} }
Q_EMIT GotSongs(songs, id); emit GotSongs(songs, id);
} }
@@ -195,7 +189,7 @@ void CollectionBackend::LoadDirectories() {
QSqlDatabase db(db_->Connect()); QSqlDatabase db(db_->Connect());
for (const CollectionDirectory &dir : dirs) { for (const CollectionDirectory &dir : dirs) {
Q_EMIT DirectoryAdded(dir, SubdirsInDirectory(dir.id, db)); emit DirectoryAdded(dir, SubdirsInDirectory(dir.id, db));
} }
} }
@@ -323,7 +317,7 @@ void CollectionBackend::UpdateTotalSongCount() {
return; return;
} }
Q_EMIT TotalSongCountUpdated(q.value(0).toInt()); emit TotalSongCountUpdated(q.value(0).toInt());
} }
@@ -343,7 +337,7 @@ void CollectionBackend::UpdateTotalArtistCount() {
return; return;
} }
Q_EMIT TotalArtistCountUpdated(q.value(0).toInt()); emit TotalArtistCountUpdated(q.value(0).toInt());
} }
@@ -363,7 +357,7 @@ void CollectionBackend::UpdateTotalAlbumCount() {
return; return;
} }
Q_EMIT TotalAlbumCountUpdated(q.value(0).toInt()); emit TotalAlbumCountUpdated(q.value(0).toInt());
} }
@@ -401,7 +395,7 @@ void CollectionBackend::AddDirectory(const QString &path) {
dir.path = path; dir.path = path;
dir.id = q.lastInsertId().toInt(); dir.id = q.lastInsertId().toInt();
Q_EMIT DirectoryAdded(dir, CollectionSubdirectoryList()); emit DirectoryAdded(dir, CollectionSubdirectoryList());
} }
@@ -443,7 +437,7 @@ void CollectionBackend::RemoveDirectory(const CollectionDirectory &dir) {
transaction.Commit(); transaction.Commit();
Q_EMIT DirectoryDeleted(dir); emit DirectoryDeleted(dir);
} }
@@ -723,8 +717,8 @@ void CollectionBackend::AddOrUpdateSongs(const SongList &songs) {
transaction.Commit(); transaction.Commit();
if (!added_songs.isEmpty()) Q_EMIT SongsAdded(added_songs); if (!added_songs.isEmpty()) emit SongsAdded(added_songs);
if (!changed_songs.isEmpty()) Q_EMIT SongsChanged(changed_songs); if (!changed_songs.isEmpty()) emit SongsChanged(changed_songs);
UpdateTotalSongCountAsync(); UpdateTotalSongCountAsync();
UpdateTotalArtistCountAsync(); UpdateTotalArtistCountAsync();
@@ -825,9 +819,9 @@ void CollectionBackend::UpdateSongsBySongID(const SongMap &new_songs) {
transaction.Commit(); transaction.Commit();
if (!deleted_songs.isEmpty()) Q_EMIT SongsDeleted(deleted_songs); if (!deleted_songs.isEmpty()) emit SongsDeleted(deleted_songs);
if (!added_songs.isEmpty()) Q_EMIT SongsAdded(added_songs); if (!added_songs.isEmpty()) emit SongsAdded(added_songs);
if (!changed_songs.isEmpty()) Q_EMIT SongsChanged(changed_songs); if (!changed_songs.isEmpty()) emit SongsChanged(changed_songs);
UpdateTotalSongCountAsync(); UpdateTotalSongCountAsync();
UpdateTotalArtistCountAsync(); UpdateTotalArtistCountAsync();
@@ -873,7 +867,7 @@ void CollectionBackend::DeleteSongs(const SongList &songs) {
transaction.Commit(); transaction.Commit();
Q_EMIT SongsDeleted(songs); emit SongsDeleted(songs);
UpdateTotalSongCountAsync(); UpdateTotalSongCountAsync();
UpdateTotalArtistCountAsync(); UpdateTotalArtistCountAsync();
@@ -900,10 +894,10 @@ void CollectionBackend::MarkSongsUnavailable(const SongList &songs, const bool u
transaction.Commit(); transaction.Commit();
if (unavailable) { if (unavailable) {
Q_EMIT SongsDeleted(songs); emit SongsDeleted(songs);
} }
else { else {
Q_EMIT SongsAdded(songs); emit SongsAdded(songs);
} }
UpdateTotalSongCountAsync(); UpdateTotalSongCountAsync();
@@ -948,14 +942,14 @@ QStringList CollectionBackend::GetAllArtistsWithAlbums(const CollectionFilterOpt
CollectionQuery query(db, songs_table_, opt); CollectionQuery query(db, songs_table_, opt);
query.SetColumnSpec(QStringLiteral("DISTINCT albumartist")); query.SetColumnSpec(QStringLiteral("DISTINCT albumartist"));
query.AddCompilationRequirement(false); query.AddCompilationRequirement(false);
query.AddWhere(QStringLiteral("album"), ""_L1, QStringLiteral("!=")); query.AddWhere(QStringLiteral("album"), QLatin1String(""), QStringLiteral("!="));
// Albums with no 'albumartist' (extract 'artist'): // Albums with no 'albumartist' (extract 'artist'):
CollectionQuery query2(db, songs_table_, opt); CollectionQuery query2(db, songs_table_, opt);
query2.SetColumnSpec(QStringLiteral("DISTINCT artist")); query2.SetColumnSpec(QStringLiteral("DISTINCT artist"));
query2.AddCompilationRequirement(false); query2.AddCompilationRequirement(false);
query2.AddWhere(QStringLiteral("album"), ""_L1, QStringLiteral("!=")); query2.AddWhere(QStringLiteral("album"), QLatin1String(""), QStringLiteral("!="));
query2.AddWhere(QStringLiteral("albumartist"), ""_L1, QStringLiteral("=")); query2.AddWhere(QStringLiteral("albumartist"), QLatin1String(""), QStringLiteral("="));
if (!query.Exec()) { if (!query.Exec()) {
ReportErrors(query); ReportErrors(query);
@@ -1109,7 +1103,7 @@ SongList CollectionBackend::GetSongsByForeignId(const QStringList &ids, const QS
QMutexLocker l(db_->Mutex()); QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect()); QSqlDatabase db(db_->Connect());
QString in = ids.join(u','); QString in = ids.join(QLatin1Char(','));
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("SELECT %3.ROWID, %2, %3.%4 FROM %3, %1 WHERE %3.%4 IN (in) AND %1.ROWID = %3.ROWID AND unavailable = 0").arg(songs_table_, Song::kColumnSpec, table, column, in)); q.prepare(QStringLiteral("SELECT %3.ROWID, %2, %3.%4 FROM %3, %1 WHERE %3.%4 IN (in) AND %1.ROWID = %3.ROWID AND unavailable = 0").arg(songs_table_, Song::kColumnSpec, table, column, in));
@@ -1140,7 +1134,7 @@ Song CollectionBackend::GetSongById(const int id, QSqlDatabase &db) {
SongList CollectionBackend::GetSongsById(const QStringList &ids, QSqlDatabase &db) { SongList CollectionBackend::GetSongsById(const QStringList &ids, QSqlDatabase &db) {
QString in = ids.join(u','); QString in = ids.join(QLatin1Char(','));
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("SELECT %1 FROM %2 WHERE ROWID IN (%3)").arg(Song::kRowIdColumnSpec, songs_table_, in)); q.prepare(QStringLiteral("SELECT %1 FROM %2 WHERE ROWID IN (%3)").arg(Song::kRowIdColumnSpec, songs_table_, in));
@@ -1278,7 +1272,7 @@ SongList CollectionBackend::GetSongsBySongId(const QStringList &song_ids, QSqlDa
for (const QString &song_id : song_ids) { for (const QString &song_id : song_ids) {
song_ids2 << QLatin1Char('\'') + song_id + QLatin1Char('\''); song_ids2 << QLatin1Char('\'') + song_id + QLatin1Char('\'');
} }
QString in = song_ids2.join(u','); QString in = song_ids2.join(QLatin1Char(','));
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("SELECT %1 FROM %2 WHERE SONG_ID IN (%3)").arg(Song::kRowIdColumnSpec, songs_table_, in)); q.prepare(QStringLiteral("SELECT %1 FROM %2 WHERE SONG_ID IN (%3)").arg(Song::kRowIdColumnSpec, songs_table_, in));
@@ -1416,7 +1410,7 @@ void CollectionBackend::CompilationsNeedUpdating() {
transaction.Commit(); transaction.Commit();
if (!changed_songs.isEmpty()) { if (!changed_songs.isEmpty()) {
Q_EMIT SongsChanged(changed_songs); emit SongsChanged(changed_songs);
} }
} }
@@ -1503,8 +1497,7 @@ CollectionBackend::AlbumList CollectionBackend::GetAlbums(const QString &artist,
album_info.art_embedded = query.Value(6).toBool(); album_info.art_embedded = query.Value(6).toBool();
const QString art_automatic = query.Value(7).toString(); const QString art_automatic = query.Value(7).toString();
static const QRegularExpression regex_url_schema(QStringLiteral("..+:.*")); if (art_automatic.contains(QRegularExpression(QStringLiteral("..+:.*")))) {
if (art_automatic.contains(regex_url_schema)) {
album_info.art_automatic = QUrl::fromEncoded(art_automatic.toUtf8()); album_info.art_automatic = QUrl::fromEncoded(art_automatic.toUtf8());
} }
else { else {
@@ -1512,7 +1505,7 @@ CollectionBackend::AlbumList CollectionBackend::GetAlbums(const QString &artist,
} }
const QString art_manual = query.Value(8).toString(); const QString art_manual = query.Value(8).toString();
if (art_manual.contains(regex_url_schema)) { if (art_manual.contains(QRegularExpression(QStringLiteral("..+:.*")))) {
album_info.art_manual = QUrl::fromEncoded(art_manual.toUtf8()); album_info.art_manual = QUrl::fromEncoded(art_manual.toUtf8());
} }
else { else {
@@ -1526,7 +1519,7 @@ CollectionBackend::AlbumList CollectionBackend::GetAlbums(const QString &artist,
key.append(album_info.album_artist); key.append(album_info.album_artist);
} }
if (!album_info.album.isEmpty()) { if (!album_info.album.isEmpty()) {
if (!key.isEmpty()) key.append(u'-'); if (!key.isEmpty()) key.append(QLatin1Char('-'));
key.append(album_info.album); key.append(album_info.album);
} }
if (!filetype.isEmpty()) { if (!filetype.isEmpty()) {
@@ -1623,7 +1616,7 @@ void CollectionBackend::UpdateEmbeddedAlbumArt(const QString &effective_albumart
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsChanged(songs); emit SongsChanged(songs);
} }
} }
@@ -1642,7 +1635,7 @@ void CollectionBackend::UpdateManualAlbumArt(const QString &effective_albumartis
{ {
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("UPDATE %1 SET art_manual = :art_manual, art_unset = 0 WHERE effective_albumartist = :effective_albumartist AND album = :album AND unavailable = 0").arg(songs_table_)); q.prepare(QStringLiteral("UPDATE %1 SET art_manual = :art_manual, art_unset = 0 WHERE effective_albumartist = :effective_albumartist AND album = :album AND unavailable = 0").arg(songs_table_));
q.BindValue(QStringLiteral(":art_manual"), art_manual.isValid() ? art_manual.toString(QUrl::FullyEncoded) : ""_L1); q.BindValue(QStringLiteral(":art_manual"), art_manual.isValid() ? art_manual.toString(QUrl::FullyEncoded) : QLatin1String(""));
q.BindValue(QStringLiteral(":effective_albumartist"), effective_albumartist); q.BindValue(QStringLiteral(":effective_albumartist"), effective_albumartist);
q.BindValue(QStringLiteral(":album"), album); q.BindValue(QStringLiteral(":album"), album);
if (!q.Exec()) { if (!q.Exec()) {
@@ -1669,7 +1662,7 @@ void CollectionBackend::UpdateManualAlbumArt(const QString &effective_albumartis
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsChanged(songs); emit SongsChanged(songs);
} }
} }
@@ -1714,7 +1707,7 @@ void CollectionBackend::UnsetAlbumArt(const QString &effective_albumartist, cons
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsChanged(songs); emit SongsChanged(songs);
} }
} }
@@ -1760,7 +1753,7 @@ void CollectionBackend::ClearAlbumArt(const QString &effective_albumartist, cons
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsChanged(songs); emit SongsChanged(songs);
} }
} }
@@ -1775,7 +1768,7 @@ void CollectionBackend::ForceCompilation(const QString &album, const QStringList
// Update the songs // Update the songs
QString sql(QStringLiteral("UPDATE %1 SET compilation_on = :compilation_on, compilation_off = :compilation_off, compilation_effective = ((compilation OR compilation_detected OR :compilation_on) AND NOT :compilation_off) + 0 WHERE album = :album AND unavailable = 0").arg(songs_table_)); QString sql(QStringLiteral("UPDATE %1 SET compilation_on = :compilation_on, compilation_off = :compilation_off, compilation_effective = ((compilation OR compilation_detected OR :compilation_on) AND NOT :compilation_off) + 0 WHERE album = :album AND unavailable = 0").arg(songs_table_));
if (!artist.isEmpty()) sql += " AND artist = :artist"_L1; if (!artist.isEmpty()) sql += QLatin1String(" AND artist = :artist");
SqlQuery q(db); SqlQuery q(db);
q.prepare(sql); q.prepare(sql);
@@ -1809,7 +1802,7 @@ void CollectionBackend::ForceCompilation(const QString &album, const QStringList
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsChanged(songs); emit SongsChanged(songs);
} }
} }
@@ -1831,7 +1824,7 @@ void CollectionBackend::IncrementPlayCount(const int id) {
} }
Song new_song = GetSongById(id, db); Song new_song = GetSongById(id, db);
Q_EMIT SongsStatisticsChanged(SongList() << new_song); emit SongsStatisticsChanged(SongList() << new_song);
} }
@@ -1853,7 +1846,7 @@ void CollectionBackend::IncrementSkipCount(const int id, const float progress) {
} }
Song new_song = GetSongById(id, db); Song new_song = GetSongById(id, db);
Q_EMIT SongsStatisticsChanged(SongList() << new_song); emit SongsStatisticsChanged(SongList() << new_song);
} }
@@ -1878,7 +1871,7 @@ void CollectionBackend::ResetPlayStatistics(const QList<int> &id_list, const boo
const bool success = ResetPlayStatistics(id_str_list); const bool success = ResetPlayStatistics(id_str_list);
if (success) { if (success) {
const SongList songs = GetSongsById(id_list); const SongList songs = GetSongsById(id_list);
Q_EMIT SongsStatisticsChanged(songs, save_tags); emit SongsStatisticsChanged(songs, save_tags);
} }
} }
@@ -1892,7 +1885,7 @@ bool CollectionBackend::ResetPlayStatistics(const QStringList &id_str_list) {
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("UPDATE %1 SET playcount = 0, skipcount = 0, lastplayed = -1 WHERE ROWID IN (:ids)").arg(songs_table_)); q.prepare(QStringLiteral("UPDATE %1 SET playcount = 0, skipcount = 0, lastplayed = -1 WHERE ROWID IN (:ids)").arg(songs_table_));
q.BindValue(QStringLiteral(":ids"), id_str_list.join(u',')); q.BindValue(QStringLiteral(":ids"), id_str_list.join(QLatin1Char(',')));
if (!q.Exec()) { if (!q.Exec()) {
db_->ReportErrors(q); db_->ReportErrors(q);
return false; return false;
@@ -1927,7 +1920,7 @@ void CollectionBackend::DeleteAll() {
t.Commit(); t.Commit();
} }
Q_EMIT DatabaseReset(); emit DatabaseReset();
} }
@@ -2020,7 +2013,7 @@ void CollectionBackend::UpdateLastPlayed(const QString &artist, const QString &a
} }
} }
Q_EMIT SongsStatisticsChanged(SongList() << songs); emit SongsStatisticsChanged(SongList() << songs);
} }
@@ -2046,7 +2039,7 @@ void CollectionBackend::UpdatePlayCount(const QString &artist, const QString &ti
} }
} }
Q_EMIT SongsStatisticsChanged(SongList() << songs, save_tags); emit SongsStatisticsChanged(SongList() << songs, save_tags);
} }
@@ -2070,7 +2063,7 @@ void CollectionBackend::UpdateSongsRating(const QList<int> &id_list, const float
for (int i : id_list) { for (int i : id_list) {
id_str_list << QString::number(i); id_str_list << QString::number(i);
} }
QString ids = id_str_list.join(u','); QString ids = id_str_list.join(QLatin1Char(','));
SqlQuery q(db); SqlQuery q(db);
q.prepare(QStringLiteral("UPDATE %1 SET rating = :rating WHERE ROWID IN (%2)").arg(songs_table_, ids)); q.prepare(QStringLiteral("UPDATE %1 SET rating = :rating WHERE ROWID IN (%2)").arg(songs_table_, ids));
q.BindValue(QStringLiteral(":rating"), rating); q.BindValue(QStringLiteral(":rating"), rating);
@@ -2081,7 +2074,7 @@ void CollectionBackend::UpdateSongsRating(const QList<int> &id_list, const float
SongList new_song_list = GetSongsById(id_str_list, db); SongList new_song_list = GetSongsById(id_str_list, db);
Q_EMIT SongsRatingChanged(new_song_list, save_tags); emit SongsRatingChanged(new_song_list, save_tags);
} }

View File

@@ -236,7 +236,7 @@ class CollectionBackend : public CollectionBackendInterface {
void UpdateSongRatingAsync(const int id, const float rating, const bool save_tags = false); void UpdateSongRatingAsync(const int id, const float rating, const bool save_tags = false);
void UpdateSongsRatingAsync(const QList<int> &ids, const float rating, const bool save_tags = false); void UpdateSongsRatingAsync(const QList<int> &ids, const float rating, const bool save_tags = false);
public Q_SLOTS: public slots:
void Exit(); void Exit();
void GetAllSongs(const int id); void GetAllSongs(const int id);
void LoadDirectories(); void LoadDirectories();
@@ -275,7 +275,7 @@ class CollectionBackend : public CollectionBackendInterface {
void UpdateLastSeen(const int directory_id, const int expire_unavailable_songs_days); void UpdateLastSeen(const int directory_id, const int expire_unavailable_songs_days);
void ExpireSongs(const int directory_id, const int expire_unavailable_songs_days); void ExpireSongs(const int directory_id, const int expire_unavailable_songs_days);
Q_SIGNALS: signals:
void DirectoryAdded(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdir); void DirectoryAdded(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdir);
void DirectoryDeleted(const CollectionDirectory &dir); void DirectoryDeleted(const CollectionDirectory &dir);

View File

@@ -54,7 +54,7 @@ class CollectionDirectoryModel : public QStandardItemModel {
QMap<int, CollectionDirectory> directories() const { return directories_; } QMap<int, CollectionDirectory> directories() const { return directories_; }
QStringList paths() const { return paths_; } QStringList paths() const { return paths_; }
private Q_SLOTS: private slots:
void AddDirectory(const CollectionDirectory &directory); void AddDirectory(const CollectionDirectory &directory);
void RemoveDirectory(const CollectionDirectory &directory); void RemoveDirectory(const CollectionDirectory &directory);

View File

@@ -60,7 +60,11 @@ bool CollectionFilter::filterAcceptsRow(const int source_row, const QModelIndex
return item->type == CollectionItem::Type::LoadingIndicator; return item->type == CollectionItem::Type::LoadingIndicator;
} }
size_t hash = qHash(filter_string_); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const size_t hash = qHash(filter_string_);
#else
const uint hash = qHash(filter_string_);
#endif
if (hash != query_hash_) { if (hash != query_hash_) {
FilterParser p(filter_string_); FilterParser p(filter_string_);
filter_tree_.reset(p.parse()); filter_tree_.reset(p.parse());

View File

@@ -51,7 +51,11 @@ class CollectionFilter : public QSortFilterProxyModel {
private: private:
mutable QScopedPointer<FilterTree> filter_tree_; mutable QScopedPointer<FilterTree> filter_tree_;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
mutable size_t query_hash_; mutable size_t query_hash_;
#else
mutable uint query_hash_;
#endif
QString filter_string_; QString filter_string_;
}; };

View File

@@ -57,12 +57,10 @@
#include "collectionfilterwidget.h" #include "collectionfilterwidget.h"
#include "groupbydialog.h" #include "groupbydialog.h"
#include "ui_collectionfilterwidget.h" #include "ui_collectionfilterwidget.h"
#include "widgets/searchfield.h" #include "widgets/qsearchfield.h"
#include "settings/collectionsettingspage.h" #include "settings/collectionsettingspage.h"
#include "settings/appearancesettingspage.h" #include "settings/appearancesettingspage.h"
using namespace Qt::StringLiterals;
namespace { namespace {
constexpr int kFilterDelay = 500; // msec constexpr int kFilterDelay = 500; // msec
} }
@@ -86,7 +84,7 @@ CollectionFilterWidget::CollectionFilterWidget(QWidget *parent)
ui_->search_field->setToolTip(FilterParser::ToolTip()); ui_->search_field->setToolTip(FilterParser::ToolTip());
QObject::connect(ui_->search_field, &SearchField::returnPressed, this, &CollectionFilterWidget::ReturnPressed); QObject::connect(ui_->search_field, &QSearchField::returnPressed, this, &CollectionFilterWidget::ReturnPressed);
QObject::connect(timer_filter_delay_, &QTimer::timeout, this, &CollectionFilterWidget::FilterDelayTimeout); QObject::connect(timer_filter_delay_, &QTimer::timeout, this, &CollectionFilterWidget::FilterDelayTimeout);
timer_filter_delay_->setInterval(kFilterDelay); timer_filter_delay_->setInterval(kFilterDelay);
@@ -129,7 +127,7 @@ CollectionFilterWidget::CollectionFilterWidget(QWidget *parent)
collection_menu_->addSeparator(); collection_menu_->addSeparator();
ui_->options->setMenu(collection_menu_); ui_->options->setMenu(collection_menu_);
QObject::connect(ui_->search_field, &SearchField::textChanged, this, &CollectionFilterWidget::FilterTextChanged); QObject::connect(ui_->search_field, &QSearchField::textChanged, this, &CollectionFilterWidget::FilterTextChanged);
QObject::connect(ui_->options, &QToolButton::clicked, ui_->options, &QToolButton::showMenu); QObject::connect(ui_->options, &QToolButton::clicked, ui_->options, &QToolButton::showMenu);
ReloadSettings(); ReloadSettings();
@@ -160,7 +158,7 @@ void CollectionFilterWidget::Init(CollectionModel *model, CollectionFilter *filt
const QList<QAction*> actions = filter_max_ages_.keys(); const QList<QAction*> actions = filter_max_ages_.keys();
for (QAction *action : actions) { for (QAction *action : actions) {
const int filter_max_age = filter_max_ages_.value(action); int filter_max_age = filter_max_ages_[action];
QObject::connect(action, &QAction::triggered, this, [this, filter_max_age]() { model_->SetFilterMaxAge(filter_max_age); } ); QObject::connect(action, &QAction::triggered, this, [this, filter_max_age]() { model_->SetFilterMaxAge(filter_max_age); } );
} }
@@ -298,7 +296,7 @@ QActionGroup *CollectionFilterWidget::CreateGroupByActions(const QString &saved_
if (version == 1) { if (version == 1) {
QStringList saved = s.childKeys(); QStringList saved = s.childKeys();
for (int i = 0; i < saved.size(); ++i) { for (int i = 0; i < saved.size(); ++i) {
if (saved.at(i) == "version"_L1) continue; if (saved.at(i) == QLatin1String("version")) continue;
QByteArray bytes = s.value(saved.at(i)).toByteArray(); QByteArray bytes = s.value(saved.at(i)).toByteArray();
QDataStream ds(&bytes, QIODevice::ReadOnly); QDataStream ds(&bytes, QIODevice::ReadOnly);
CollectionModel::Grouping g; CollectionModel::Grouping g;
@@ -309,7 +307,7 @@ QActionGroup *CollectionFilterWidget::CreateGroupByActions(const QString &saved_
else { else {
QStringList saved = s.childKeys(); QStringList saved = s.childKeys();
for (int i = 0; i < saved.size(); ++i) { for (int i = 0; i < saved.size(); ++i) {
if (saved.at(i) == "version"_L1) continue; if (saved.at(i) == QLatin1String("version")) continue;
s.remove(saved.at(i)); s.remove(saved.at(i));
} }
} }
@@ -481,12 +479,12 @@ void CollectionFilterWidget::keyReleaseEvent(QKeyEvent *e) {
switch (e->key()) { switch (e->key()) {
case Qt::Key_Up: case Qt::Key_Up:
Q_EMIT UpPressed(); emit UpPressed();
e->accept(); e->accept();
break; break;
case Qt::Key_Down: case Qt::Key_Down:
Q_EMIT DownPressed(); emit DownPressed();
e->accept(); e->accept();
break; break;

View File

@@ -86,12 +86,12 @@ class CollectionFilterWidget : public QWidget {
bool SearchFieldHasFocus() const; bool SearchFieldHasFocus() const;
void FocusSearchField(); void FocusSearchField();
public Q_SLOTS: public slots:
void UpdateGroupByActions(); void UpdateGroupByActions();
void SetFilterMode(CollectionFilterOptions::FilterMode filter_mode); void SetFilterMode(CollectionFilterOptions::FilterMode filter_mode);
void FocusOnFilter(QKeyEvent *e); void FocusOnFilter(QKeyEvent *e);
Q_SIGNALS: signals:
void UpPressed(); void UpPressed();
void DownPressed(); void DownPressed();
void ReturnPressed(); void ReturnPressed();
@@ -99,7 +99,7 @@ class CollectionFilterWidget : public QWidget {
protected: protected:
void keyReleaseEvent(QKeyEvent *e) override; void keyReleaseEvent(QKeyEvent *e) override;
private Q_SLOTS: private slots:
void GroupingChanged(const CollectionModel::Grouping g, const bool separate_albums_by_grouping); void GroupingChanged(const CollectionModel::Grouping g, const bool separate_albums_by_grouping);
void GroupByClicked(QAction *action); void GroupByClicked(QAction *action);
void SaveGroupBy(); void SaveGroupBy();

View File

@@ -30,7 +30,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="SearchField" name="search_field" native="true"> <widget class="QSearchField" name="search_field" native="true">
<property name="placeholderText" stdset="0"> <property name="placeholderText" stdset="0">
<string>Enter search terms here</string> <string>Enter search terms here</string>
</property> </property>
@@ -123,9 +123,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>SearchField</class> <class>QSearchField</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>widgets/searchfield.h</header> <header>widgets/qsearchfield.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>

View File

@@ -40,7 +40,7 @@ class CollectionItemDelegate : public QStyledItemDelegate {
explicit CollectionItemDelegate(QObject *parent); explicit CollectionItemDelegate(QObject *parent);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
public Q_SLOTS: public slots:
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &idx) override; bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &idx) override;
}; };

View File

@@ -24,11 +24,10 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <optional> #include <optional>
#include <chrono>
#include <QObject> #include <QObject>
#include <QtGlobal> #include <QtGlobal>
#include <QtConcurrentRun> #include <QtConcurrent>
#include <QThread> #include <QThread>
#include <QMutex> #include <QMutex>
#include <QFuture> #include <QFuture>
@@ -76,9 +75,6 @@
#include "covermanager/albumcoverloader.h" #include "covermanager/albumcoverloader.h"
#include "settings/collectionsettingspage.h" #include "settings/collectionsettingspage.h"
using namespace std::chrono_literals;
using namespace Qt::StringLiterals;
const int CollectionModel::kPrettyCoverSize = 32; const int CollectionModel::kPrettyCoverSize = 32;
namespace { namespace {
constexpr char kPixmapDiskCacheDir[] = "pixmapcache"; constexpr char kPixmapDiskCacheDir[] = "pixmapcache";
@@ -102,8 +98,6 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
total_album_count_(0), total_album_count_(0),
loading_(false) { loading_(false) {
setObjectName(backend_->source() == Song::Source::Collection ? QLatin1String(metaObject()->className()) : QStringLiteral("%1%2").arg(Song::DescriptionForSource(backend_->source()), QLatin1String(metaObject()->className())));
filter_->setSourceModel(this); filter_->setSourceModel(this);
filter_->setSortRole(Role_SortText); filter_->setSortRole(Role_SortText);
filter_->sort(0); filter_->sort(0);
@@ -120,7 +114,7 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
if (app_ && !sIconCache) { if (app_ && !sIconCache) {
sIconCache = new QNetworkDiskCache(this); sIconCache = new QNetworkDiskCache(this);
sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u'/' + QLatin1String(kPixmapDiskCacheDir)); sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + QLatin1String(kPixmapDiskCacheDir));
QObject::connect(app_, &Application::ClearPixmapDiskCache, this, &CollectionModel::ClearDiskCache); QObject::connect(app_, &Application::ClearPixmapDiskCache, this, &CollectionModel::ClearDiskCache);
} }
@@ -139,11 +133,11 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
backend_->UpdateTotalAlbumCountAsync(); backend_->UpdateTotalAlbumCountAsync();
timer_reload_->setSingleShot(true); timer_reload_->setSingleShot(true);
timer_reload_->setInterval(300ms); timer_reload_->setInterval(300);
QObject::connect(timer_reload_, &QTimer::timeout, this, &CollectionModel::Reload); QObject::connect(timer_reload_, &QTimer::timeout, this, &CollectionModel::Reload);
timer_update_->setSingleShot(false); timer_update_->setSingleShot(false);
timer_update_->setInterval(20ms); timer_update_->setInterval(20);
QObject::connect(timer_update_, &QTimer::timeout, this, &CollectionModel::ProcessUpdate); QObject::connect(timer_update_, &QTimer::timeout, this, &CollectionModel::ProcessUpdate);
ReloadSettings(); ReloadSettings();
@@ -152,7 +146,7 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
CollectionModel::~CollectionModel() { CollectionModel::~CollectionModel() {
qLog(Debug) << "Collection model" << this << "deleted"; qLog(Debug) << "Collection model" << this << "for" << Song::TextForSource(backend_->source()) << "deleted";
beginResetModel(); beginResetModel();
Clear(); Clear();
@@ -272,7 +266,7 @@ void CollectionModel::SetGroupBy(const Grouping g, const std::optional<bool> sep
ScheduleReset(); ScheduleReset();
Q_EMIT GroupingChanged(g, options_current_.separate_albums_by_grouping); emit GroupingChanged(g, options_current_.separate_albums_by_grouping);
} }
@@ -520,7 +514,7 @@ void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) {
songs_added << new_song; songs_added << new_song;
continue; continue;
} }
const Song old_song = song_nodes_.value(new_song.id())->metadata; const Song &old_song = song_nodes_[new_song.id()]->metadata;
bool container_key_changed = false; bool container_key_changed = false;
bool has_unique_album_identifier_1 = false; bool has_unique_album_identifier_1 = false;
bool has_unique_album_identifier_2 = false; bool has_unique_album_identifier_2 = false;
@@ -586,7 +580,7 @@ void CollectionModel::AddSongsInternal(const SongList &songs) {
container_key = container->container_key; container_key = container->container_key;
} }
else { else {
if (!container_key.isEmpty()) container_key.append(u'-'); if (!container_key.isEmpty()) container_key.append(QLatin1Char('-'));
container_key.append(ContainerKey(group_by, song, has_unique_album_identifier)); container_key.append(ContainerKey(group_by, song, has_unique_album_identifier));
if (container_nodes_[i].contains(container_key)) { if (container_nodes_[i].contains(container_key)) {
container = container_nodes_[i][container_key]; container = container_nodes_[i][container_key];
@@ -612,7 +606,7 @@ void CollectionModel::UpdateSongsInternal(const SongList &songs) {
qLog(Error) << "Song does not exist in model" << new_song.id() << new_song.PrettyTitleWithArtist(); qLog(Error) << "Song does not exist in model" << new_song.id() << new_song.PrettyTitleWithArtist();
continue; continue;
} }
CollectionItem *item = song_nodes_.value(new_song.id()); CollectionItem *item = song_nodes_[new_song.id()];
const Song &old_song = item->metadata; const Song &old_song = item->metadata;
const bool song_title_data_changed = IsSongTitleDataChanged(old_song, new_song); const bool song_title_data_changed = IsSongTitleDataChanged(old_song, new_song);
const bool art_changed = !old_song.IsArtEqual(new_song); const bool art_changed = !old_song.IsArtEqual(new_song);
@@ -628,18 +622,18 @@ void CollectionModel::UpdateSongsInternal(const SongList &songs) {
qLog(Debug) << "Song metadata and title for" << new_song.id() << new_song.PrettyTitleWithArtist() << "changed, informing model"; qLog(Debug) << "Song metadata and title for" << new_song.id() << new_song.PrettyTitleWithArtist() << "changed, informing model";
const QModelIndex idx = ItemToIndex(item); const QModelIndex idx = ItemToIndex(item);
if (!idx.isValid()) continue; if (!idx.isValid()) continue;
Q_EMIT dataChanged(idx, idx); emit dataChanged(idx, idx);
} }
else { else {
qLog(Debug) << "Song metadata for" << new_song.id() << new_song.PrettyTitleWithArtist() << "changed"; qLog(Debug) << "Song metadata for" << new_song.id() << new_song.PrettyTitleWithArtist() << "changed";
} }
} }
for (CollectionItem *item : std::as_const(album_parents)) { for (CollectionItem *item : album_parents) {
ClearItemPixmapCache(item); ClearItemPixmapCache(item);
const QModelIndex idx = ItemToIndex(item); const QModelIndex idx = ItemToIndex(item);
if (idx.isValid()) { if (idx.isValid()) {
Q_EMIT dataChanged(idx, idx); emit dataChanged(idx, idx);
} }
} }
@@ -654,7 +648,7 @@ void CollectionModel::RemoveSongsInternal(const SongList &songs) {
for (const Song &song : songs) { for (const Song &song : songs) {
if (song_nodes_.contains(song.id())) { if (song_nodes_.contains(song.id())) {
CollectionItem *node = song_nodes_.value(song.id()); CollectionItem *node = song_nodes_[song.id()];
if (node->parent != root_) parents << node->parent; if (node->parent != root_) parents << node->parent;
@@ -712,7 +706,7 @@ void CollectionModel::RemoveSongsInternal(const SongList &songs) {
} }
// Remove the divider // Remove the divider
const int row = divider_nodes_.value(divider_key)->row; int row = divider_nodes_[divider_key]->row;
beginRemoveRows(ItemToIndex(root_), row, row); beginRemoveRows(ItemToIndex(root_), row, row);
root_->Delete(row); root_->Delete(row);
endRemoveRows(); endRemoveRows();
@@ -759,7 +753,7 @@ void CollectionModel::CreateDividerItem(const QString &divider_key, const QStrin
CollectionItem *divider = new CollectionItem(CollectionItem::Type::Divider, root_); CollectionItem *divider = new CollectionItem(CollectionItem::Type::Divider, root_);
divider->container_key = divider_key; divider->container_key = divider_key;
divider->display_text = display_text; divider->display_text = display_text;
divider->sort_text = divider_key + " "_L1; divider->sort_text = divider_key + QLatin1String(" ");
divider_nodes_[divider_key] = divider; divider_nodes_[divider_key] = divider;
endInsertRows(); endInsertRows();
@@ -803,7 +797,7 @@ CollectionItem *CollectionModel::CreateCompilationArtistNode(CollectionItem *par
if (parent != root_ && !parent->container_key.isEmpty()) parent->compilation_artist_node_->container_key.append(parent->container_key); if (parent != root_ && !parent->container_key.isEmpty()) parent->compilation_artist_node_->container_key.append(parent->container_key);
parent->compilation_artist_node_->container_key.append(QLatin1String(kVariousArtists)); parent->compilation_artist_node_->container_key.append(QLatin1String(kVariousArtists));
parent->compilation_artist_node_->display_text = QLatin1String(kVariousArtists); parent->compilation_artist_node_->display_text = QLatin1String(kVariousArtists);
parent->compilation_artist_node_->sort_text = " various"_L1; parent->compilation_artist_node_->sort_text = QLatin1String(" various");
parent->compilation_artist_node_->container_level = parent->container_level + 1; parent->compilation_artist_node_->container_level = parent->container_level + 1;
endInsertRows(); endInsertRows();
@@ -814,7 +808,11 @@ CollectionItem *CollectionModel::CreateCompilationArtistNode(CollectionItem *par
void CollectionModel::LoadSongsFromSqlAsync() { void CollectionModel::LoadSongsFromSqlAsync() {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QFuture<SongList> future = QtConcurrent::run(&CollectionModel::LoadSongsFromSql, this, options_active_.filter_options); QFuture<SongList> future = QtConcurrent::run(&CollectionModel::LoadSongsFromSql, this, options_active_.filter_options);
#else
QFuture<SongList> future = QtConcurrent::run(this, &CollectionModel::LoadSongsFromSql, options_active_.filter_options);
#endif
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>(); QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
QObject::connect(watcher, &QFutureWatcher<void>::finished, this, &CollectionModel::LoadSongsFromSqlAsyncFinished); QObject::connect(watcher, &QFutureWatcher<void>::finished, this, &CollectionModel::LoadSongsFromSqlAsyncFinished);
watcher->setFuture(future); watcher->setFuture(future);
@@ -991,7 +989,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderR
const QModelIndex idx = ItemToIndex(item); const QModelIndex idx = ItemToIndex(item);
if (!idx.isValid()) return; if (!idx.isValid()) return;
Q_EMIT dataChanged(idx, idx); emit dataChanged(idx, idx);
} }
@@ -1057,14 +1055,14 @@ QString CollectionModel::TextOrUnknown(const QString &text) {
QString CollectionModel::PrettyYearAlbum(const int year, const QString &album) { QString CollectionModel::PrettyYearAlbum(const int year, const QString &album) {
if (year <= 0) return TextOrUnknown(album); if (year <= 0) return TextOrUnknown(album);
return QString::number(year) + " - "_L1 + TextOrUnknown(album); return QString::number(year) + QLatin1String(" - ") + TextOrUnknown(album);
} }
QString CollectionModel::PrettyAlbumDisc(const QString &album, const int disc) { QString CollectionModel::PrettyAlbumDisc(const QString &album, const int disc) {
if (disc <= 0 || Song::AlbumContainsDisc(album)) return TextOrUnknown(album); if (disc <= 0 || Song::AlbumContainsDisc(album)) return TextOrUnknown(album);
return TextOrUnknown(album) + " - (Disc "_L1 + QString::number(disc) + ")"_L1; return TextOrUnknown(album) + QLatin1String(" - (Disc ") + QString::number(disc) + QLatin1String(")");
} }
@@ -1073,9 +1071,9 @@ QString CollectionModel::PrettyYearAlbumDisc(const int year, const QString &albu
QString str; QString str;
if (year <= 0) str = TextOrUnknown(album); if (year <= 0) str = TextOrUnknown(album);
else str = QString::number(year) + " - "_L1 + TextOrUnknown(album); else str = QString::number(year) + QLatin1String(" - ") + TextOrUnknown(album);
if (!Song::AlbumContainsDisc(album) && disc > 0) str += " - (Disc "_L1 + QString::number(disc) + ")"_L1; if (!Song::AlbumContainsDisc(album) && disc > 0) str += QLatin1String(" - (Disc ") + QString::number(disc) + QLatin1String(")");
return str; return str;
@@ -1083,7 +1081,7 @@ QString CollectionModel::PrettyYearAlbumDisc(const int year, const QString &albu
QString CollectionModel::PrettyDisc(const int disc) { QString CollectionModel::PrettyDisc(const int disc) {
return "Disc "_L1 + QString::number(std::max(1, disc)); return QLatin1String("Disc ") + QString::number(std::max(1, disc));
} }
@@ -1160,13 +1158,12 @@ QString CollectionModel::SortText(const GroupBy group_by, const int container_le
QString CollectionModel::SortText(QString text) { QString CollectionModel::SortText(QString text) {
if (text.isEmpty()) { if (text.isEmpty()) {
text = " unknown"_L1; text = QLatin1String(" unknown");
} }
else { else {
text = text.toLower(); text = text.toLower();
} }
static const QRegularExpression regex_not_words(QStringLiteral("[^\\w ]"), QRegularExpression::UseUnicodePropertiesOption); text = text.remove(QRegularExpression(QStringLiteral("[^\\w ]"), QRegularExpression::UseUnicodePropertiesOption));
text = text.remove(regex_not_words);
return text; return text;
@@ -1180,7 +1177,7 @@ QString CollectionModel::SortTextForArtist(QString artist, const bool skip_artic
for (const auto &i : Song::kArticles) { for (const auto &i : Song::kArticles) {
if (artist.startsWith(i)) { if (artist.startsWith(i)) {
qint64 ilen = i.length(); qint64 ilen = i.length();
artist = artist.right(artist.length() - ilen) + ", "_L1 + i.left(ilen - 1); artist = artist.right(artist.length() - ilen) + QLatin1String(", ") + i.left(ilen - 1);
break; break;
} }
} }
@@ -1191,6 +1188,7 @@ QString CollectionModel::SortTextForArtist(QString artist, const bool skip_artic
} }
QString CollectionModel::SortTextForNumber(const int number) { QString CollectionModel::SortTextForNumber(const int number) {
return QStringLiteral("%1").arg(number, 4, 10, QLatin1Char('0')); return QStringLiteral("%1").arg(number, 4, 10, QLatin1Char('0'));
} }
@@ -1318,7 +1316,7 @@ QString CollectionModel::ContainerKey(const GroupBy group_by, const Song &song,
// Make sure we distinguish albums by different artists if the parent group by is not including artist. // Make sure we distinguish albums by different artists if the parent group by is not including artist.
if (IsAlbumGroupBy(group_by) && !has_unique_album_identifier && !song.is_compilation() && !song.effective_albumartist().isEmpty()) { if (IsAlbumGroupBy(group_by) && !has_unique_album_identifier && !song.is_compilation() && !song.effective_albumartist().isEmpty()) {
key.prepend(u'-'); key.prepend(QLatin1Char('-'));
key.prepend(TextOrUnknown(song.effective_albumartist())); key.prepend(TextOrUnknown(song.effective_albumartist()));
has_unique_album_identifier = true; has_unique_album_identifier = true;
} }
@@ -1348,7 +1346,7 @@ QString CollectionModel::DividerKey(const GroupBy group_by, const Song &song, co
case GroupBy::FileType: { case GroupBy::FileType: {
QChar c = sort_text[0]; QChar c = sort_text[0];
if (c.isDigit()) return QStringLiteral("0"); if (c.isDigit()) return QStringLiteral("0");
if (c == u' ') return QString(); if (c == QLatin1Char(' ')) return QString();
if (c.decompositionTag() != QChar::NoDecomposition) { if (c.decompositionTag() != QChar::NoDecomposition) {
QString decomposition = c.decomposition(); QString decomposition = c.decomposition();
return QChar(decomposition[0]); return QChar(decomposition[0]);
@@ -1397,25 +1395,25 @@ QString CollectionModel::DividerDisplayText(const GroupBy group_by, const QStrin
case GroupBy::Genre: case GroupBy::Genre:
case GroupBy::FileType: case GroupBy::FileType:
case GroupBy::Format: case GroupBy::Format:
if (key == "0"_L1) return QStringLiteral("0-9"); if (key == QLatin1String("0")) return QStringLiteral("0-9");
return key.toUpper(); return key.toUpper();
case GroupBy::YearAlbum: case GroupBy::YearAlbum:
case GroupBy::YearAlbumDisc: case GroupBy::YearAlbumDisc:
case GroupBy::OriginalYearAlbum: case GroupBy::OriginalYearAlbum:
case GroupBy::OriginalYearAlbumDisc: case GroupBy::OriginalYearAlbumDisc:
if (key == "0000"_L1) return tr("Unknown"); if (key == QLatin1String("0000")) return tr("Unknown");
return key.toUpper(); return key.toUpper();
case GroupBy::Year: case GroupBy::Year:
case GroupBy::OriginalYear: case GroupBy::OriginalYear:
if (key == "0000"_L1) return tr("Unknown"); if (key == QLatin1String("0000")) return tr("Unknown");
return QString::number(key.toInt()); // To remove leading 0s return QString::number(key.toInt()); // To remove leading 0s
case GroupBy::Samplerate: case GroupBy::Samplerate:
case GroupBy::Bitdepth: case GroupBy::Bitdepth:
case GroupBy::Bitrate: case GroupBy::Bitrate:
if (key == "000"_L1) return tr("Unknown"); if (key == QLatin1String("000")) return tr("Unknown");
return QString::number(key.toInt()); // To remove leading 0s return QString::number(key.toInt()); // To remove leading 0s
case GroupBy::None: case GroupBy::None:
@@ -1431,15 +1429,17 @@ QString CollectionModel::DividerDisplayText(const GroupBy group_by, const QStrin
bool CollectionModel::CompareItems(const CollectionItem *a, const CollectionItem *b) const { bool CollectionModel::CompareItems(const CollectionItem *a, const CollectionItem *b) const {
QVariant left = data(a, CollectionModel::Role_SortText); QVariant left(data(a, CollectionModel::Role_SortText));
QVariant right = data(b, CollectionModel::Role_SortText); QVariant right(data(b, CollectionModel::Role_SortText));
if (left.metaType().id() == QMetaType::Int) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (left.metaType().id() == QMetaType::Int)
#else
if (left.type() == QVariant::Int)
#endif
return left.toInt() < right.toInt(); return left.toInt() < right.toInt();
} else
else {
return left.toString() < right.toString(); return left.toString() < right.toString();
}
} }
@@ -1531,21 +1531,21 @@ CollectionModel::GroupBy &CollectionModel::Grouping::operator[](const int i) {
void CollectionModel::TotalSongCountUpdatedSlot(const int count) { void CollectionModel::TotalSongCountUpdatedSlot(const int count) {
total_song_count_ = count; total_song_count_ = count;
Q_EMIT TotalSongCountUpdated(count); emit TotalSongCountUpdated(count);
} }
void CollectionModel::TotalArtistCountUpdatedSlot(const int count) { void CollectionModel::TotalArtistCountUpdatedSlot(const int count) {
total_artist_count_ = count; total_artist_count_ = count;
Q_EMIT TotalArtistCountUpdated(count); emit TotalArtistCountUpdated(count);
} }
void CollectionModel::TotalAlbumCountUpdatedSlot(const int count) { void CollectionModel::TotalAlbumCountUpdatedSlot(const int count) {
total_album_count_ = count; total_album_count_ = count;
Q_EMIT TotalAlbumCountUpdated(count); emit TotalAlbumCountUpdated(count);
} }
@@ -1565,7 +1565,7 @@ void CollectionModel::RowsInserted(const QModelIndex &parent, const int first, c
} }
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
Q_EMIT SongsAdded(songs); emit SongsAdded(songs);
} }
} }
@@ -1581,7 +1581,7 @@ void CollectionModel::RowsRemoved(const QModelIndex &parent, const int first, co
songs << item->metadata; songs << item->metadata;
} }
Q_EMIT SongsRemoved(songs); emit SongsRemoved(songs);
} }

View File

@@ -201,7 +201,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
bool CompareItems(const CollectionItem *a, const CollectionItem *b) const; bool CompareItems(const CollectionItem *a, const CollectionItem *b) const;
Q_SIGNALS: signals:
void TotalSongCountUpdated(const int count); void TotalSongCountUpdated(const int count);
void TotalArtistCountUpdated(const int count); void TotalArtistCountUpdated(const int count);
void TotalAlbumCountUpdated(const int count); void TotalAlbumCountUpdated(const int count);
@@ -209,7 +209,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
void SongsAdded(const SongList &songs); void SongsAdded(const SongList &songs);
void SongsRemoved(const SongList &songs); void SongsRemoved(const SongList &songs);
public Q_SLOTS: public slots:
void SetFilterMode(const CollectionFilterOptions::FilterMode filter_mode); void SetFilterMode(const CollectionFilterOptions::FilterMode filter_mode);
void SetFilterMaxAge(const int filter_max_age); void SetFilterMaxAge(const int filter_max_age);
@@ -253,7 +253,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
void ClearItemPixmapCache(CollectionItem *item); void ClearItemPixmapCache(CollectionItem *item);
static qint64 MaximumCacheSize(Settings *s, const char *size_id, const char *size_unit_id, const qint64 cache_size_default); static qint64 MaximumCacheSize(Settings *s, const char *size_id, const char *size_unit_id, const qint64 cache_size_default);
private Q_SLOTS: private slots:
void Reload(); void Reload();
void ScheduleReset(); void ScheduleReset();
void ProcessUpdate(); void ProcessUpdate();

View File

@@ -19,5 +19,5 @@
#include "collectionmodelupdate.h" #include "collectionmodelupdate.h"
CollectionModelUpdate::CollectionModelUpdate(const Type _type, const SongList &_songs) CollectionModelUpdate::CollectionModelUpdate(const Type &_type, const SongList &_songs)
: type(_type), songs(_songs) {} : type(_type), songs(_songs) {}

View File

@@ -30,7 +30,7 @@ class CollectionModelUpdate {
Update, Update,
Remove, Remove,
}; };
explicit CollectionModelUpdate(const Type _type, const SongList &_songs); explicit CollectionModelUpdate(const Type &_type, const SongList &_songs);
Type type; Type type;
SongList songs; SongList songs;
}; };

View File

@@ -21,8 +21,6 @@
#include "config.h" #include "config.h"
#include <utility>
#include <QtGlobal> #include <QtGlobal>
#include <QMetaType> #include <QMetaType>
#include <QDateTime> #include <QDateTime>
@@ -38,8 +36,6 @@
#include "collectionquery.h" #include "collectionquery.h"
#include "collectionfilteroptions.h" #include "collectionfilteroptions.h"
using namespace Qt::StringLiterals;
CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_table, const CollectionFilterOptions &filter_options) CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_table, const CollectionFilterOptions &filter_options)
: SqlQuery(db), : SqlQuery(db),
songs_table_(songs_table), songs_table_(songs_table),
@@ -48,7 +44,7 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
limit_(-1) { limit_(-1) {
if (filter_options.max_age() != -1) { if (filter_options.max_age() != -1) {
qint64 cutoff = QDateTime::currentSecsSinceEpoch() - filter_options.max_age(); qint64 cutoff = QDateTime::currentDateTime().toSecsSinceEpoch() - filter_options.max_age();
where_clauses_ << QStringLiteral("ctime > ?"); where_clauses_ << QStringLiteral("ctime > ?");
bound_values_ << cutoff; bound_values_ << cutoff;
@@ -65,8 +61,8 @@ CollectionQuery::CollectionQuery(const QSqlDatabase &db, const QString &songs_ta
void CollectionQuery::AddWhere(const QString &column, const QVariant &value, const QString &op) { void CollectionQuery::AddWhere(const QString &column, const QVariant &value, const QString &op) {
// Ignore 'literal' for IN // Ignore 'literal' for IN
if (op.compare("IN"_L1, Qt::CaseInsensitive) == 0) { if (op.compare(QLatin1String("IN"), Qt::CaseInsensitive) == 0) {
const QStringList values = value.toStringList(); QStringList values = value.toStringList();
QStringList final_values; QStringList final_values;
final_values.reserve(values.count()); final_values.reserve(values.count());
for (const QString &single_value : values) { for (const QString &single_value : values) {
@@ -74,16 +70,26 @@ void CollectionQuery::AddWhere(const QString &column, const QVariant &value, con
bound_values_ << single_value; bound_values_ << single_value;
} }
where_clauses_ << QStringLiteral("%1 IN (%2)").arg(column, final_values.join(u',')); where_clauses_ << QStringLiteral("%1 IN (%2)").arg(column, final_values.join(QLatin1Char(',')));
} }
else { else {
// Do integers inline - sqlite seems to get confused when you pass integers to bound parameters // Do integers inline - sqlite seems to get confused when you pass integers to bound parameters
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (value.metaType().id() == QMetaType::Int) { if (value.metaType().id() == QMetaType::Int) {
#else
if (value.type() == QVariant::Int) {
#endif
where_clauses_ << QStringLiteral("%1 %2 %3").arg(column, op, value.toString()); where_clauses_ << QStringLiteral("%1 %2 %3").arg(column, op, value.toString());
} }
else if (value.metaType().id() == QMetaType::QString && value.toString().isNull()) { else if (
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
value.metaType().id() == QMetaType::QString
#else
value.type() == QVariant::String
#endif
&& value.toString().isNull()) {
where_clauses_ << QStringLiteral("%1 %2 ?").arg(column, op); where_clauses_ << QStringLiteral("%1 %2 ?").arg(column, op);
bound_values_ << ""_L1; bound_values_ << QLatin1String("");
} }
else { else {
where_clauses_ << QStringLiteral("%1 %2 ?").arg(column, op); where_clauses_ << QStringLiteral("%1 %2 ?").arg(column, op);
@@ -117,18 +123,18 @@ bool CollectionQuery::Exec() {
where_clauses << QStringLiteral("unavailable = 0"); where_clauses << QStringLiteral("unavailable = 0");
} }
if (!where_clauses.isEmpty()) sql += " WHERE "_L1 + where_clauses.join(" AND "_L1); if (!where_clauses.isEmpty()) sql += QLatin1String(" WHERE ") + where_clauses.join(QLatin1String(" AND "));
if (!order_by_.isEmpty()) sql += " ORDER BY "_L1 + order_by_; if (!order_by_.isEmpty()) sql += QLatin1String(" ORDER BY ") + order_by_;
if (limit_ != -1) sql += " LIMIT "_L1 + QString::number(limit_); if (limit_ != -1) sql += QLatin1String(" LIMIT ") + QString::number(limit_);
sql.replace("%songs_table"_L1, songs_table_); sql.replace(QLatin1String("%songs_table"), songs_table_);
if (!QSqlQuery::prepare(sql)) return false; if (!QSqlQuery::prepare(sql)) return false;
// Bind values // Bind values
for (const QVariant &value : std::as_const(bound_values_)) { for (const QVariant &value : bound_values_) {
QSqlQuery::addBindValue(value); QSqlQuery::addBindValue(value);
} }

View File

@@ -104,8 +104,6 @@ CollectionView::CollectionView(QWidget *parent)
is_in_keyboard_search_(false), is_in_keyboard_search_(false),
delete_files_(false) { delete_files_(false) {
setObjectName(QLatin1String(metaObject()->className()));
setItemDelegate(new CollectionItemDelegate(this)); setItemDelegate(new CollectionItemDelegate(this));
setAttribute(Qt::WA_MacShowFocusRect, false); setAttribute(Qt::WA_MacShowFocusRect, false);
setHeaderHidden(true); setHeaderHidden(true);
@@ -275,7 +273,7 @@ void CollectionView::TotalSongCountUpdated(const int count) {
unsetCursor(); unsetCursor();
} }
Q_EMIT TotalSongCountUpdated_(); emit TotalSongCountUpdated_();
} }
@@ -292,7 +290,7 @@ void CollectionView::TotalArtistCountUpdated(const int count) {
unsetCursor(); unsetCursor();
} }
Q_EMIT TotalArtistCountUpdated_(); emit TotalArtistCountUpdated_();
} }
@@ -309,7 +307,7 @@ void CollectionView::TotalAlbumCountUpdated(const int count) {
unsetCursor(); unsetCursor();
} }
Q_EMIT TotalAlbumCountUpdated_(); emit TotalAlbumCountUpdated_();
} }
@@ -350,7 +348,7 @@ void CollectionView::mouseReleaseEvent(QMouseEvent *e) {
QTreeView::mouseReleaseEvent(e); QTreeView::mouseReleaseEvent(e);
if (total_song_count_ == 0) { if (total_song_count_ == 0) {
Q_EMIT ShowConfigDialog(); emit ShowConfigDialog();
} }
} }
@@ -459,7 +457,11 @@ void CollectionView::contextMenuEvent(QContextMenuEvent *e) {
action_copy_to_device_->setVisible(regular_elements == regular_editable); action_copy_to_device_->setVisible(regular_elements == regular_editable);
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
action_delete_files_->setVisible(delete_files_); action_delete_files_->setVisible(delete_files_);
#else
action_delete_files_->setVisible(false);
#endif
action_show_in_various_->setVisible(songs_selected > 0); action_show_in_various_->setVisible(songs_selected > 0);
action_no_show_in_various_->setVisible(songs_selected > 0); action_no_show_in_various_->setVisible(songs_selected > 0);
@@ -470,7 +472,11 @@ void CollectionView::contextMenuEvent(QContextMenuEvent *e) {
action_copy_to_device_->setEnabled(regular_elements == regular_editable); action_copy_to_device_->setEnabled(regular_elements == regular_editable);
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
action_delete_files_->setEnabled(delete_files_); action_delete_files_->setEnabled(delete_files_);
#else
action_delete_files_->setEnabled(false);
#endif
context_menu_->popup(e->globalPos()); context_menu_->popup(e->globalPos());
@@ -515,7 +521,11 @@ void CollectionView::SetShowInVarious(const bool on) {
} }
} }
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QSet<QString> albums_set = QSet<QString>(albums.keyBegin(), albums.keyEnd()); const QSet<QString> albums_set = QSet<QString>(albums.keyBegin(), albums.keyEnd());
#else
const QSet<QString> albums_set = QSet<QString>::fromList(albums.keys());
#endif
for (const QString &album : albums_set) { for (const QString &album : albums_set) {
app_->collection_backend()->ForceCompilation(album, albums.values(album), on); app_->collection_backend()->ForceCompilation(album, albums.values(album), on);
} }
@@ -528,13 +538,13 @@ void CollectionView::Load() {
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) { if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->clear_first_ = true; mimedata->clear_first_ = true;
} }
Q_EMIT AddToPlaylistSignal(q_mimedata); emit AddToPlaylistSignal(q_mimedata);
} }
void CollectionView::AddToPlaylist() { void CollectionView::AddToPlaylist() {
Q_EMIT AddToPlaylistSignal(model()->mimeData(selectedIndexes())); emit AddToPlaylistSignal(model()->mimeData(selectedIndexes()));
} }
@@ -544,7 +554,7 @@ void CollectionView::AddToPlaylistEnqueue() {
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) { if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->enqueue_now_ = true; mimedata->enqueue_now_ = true;
} }
Q_EMIT AddToPlaylistSignal(q_mimedata); emit AddToPlaylistSignal(q_mimedata);
} }
@@ -554,7 +564,7 @@ void CollectionView::AddToPlaylistEnqueueNext() {
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) { if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->enqueue_next_now_ = true; mimedata->enqueue_next_now_ = true;
} }
Q_EMIT AddToPlaylistSignal(q_mimedata); emit AddToPlaylistSignal(q_mimedata);
} }
@@ -564,7 +574,7 @@ void CollectionView::OpenInNewPlaylist() {
if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) { if (MimeData *mimedata = qobject_cast<MimeData*>(q_mimedata)) {
mimedata->open_in_new_playlist_ = true; mimedata->open_in_new_playlist_ = true;
} }
Q_EMIT AddToPlaylistSignal(q_mimedata); emit AddToPlaylistSignal(q_mimedata);
} }
@@ -601,7 +611,7 @@ void CollectionView::SearchForThis() {
CollectionItem *item = app_->collection_model()->IndexToItem(index); CollectionItem *item = app_->collection_model()->IndexToItem(index);
const CollectionModel::GroupBy group_by = app_->collection_model()->GetGroupBy()[item->container_level]; const CollectionModel::GroupBy group_by = app_->collection_model()->GetGroupBy()[item->container_level];
while (!item->children.isEmpty()) { while (!item->children.isEmpty()) {
item = item->children.constFirst(); item = item->children.first();
} }
switch (group_by) { switch (group_by) {
@@ -721,7 +731,7 @@ void CollectionView::EditTracks() {
} }
void CollectionView::EditTagError(const QString &message) { void CollectionView::EditTagError(const QString &message) {
Q_EMIT Error(message); emit Error(message);
} }
void CollectionView::RescanSongs() { void CollectionView::RescanSongs() {
@@ -763,7 +773,7 @@ void CollectionView::FilterReturnPressed() {
if (!currentIndex().isValid()) return; if (!currentIndex().isValid()) return;
Q_EMIT doubleClicked(currentIndex()); emit doubleClicked(currentIndex());
} }
void CollectionView::ShowInBrowser() const { void CollectionView::ShowInBrowser() const {

View File

@@ -69,7 +69,7 @@ class CollectionView : public AutoExpandingTreeView {
int TotalArtists() const; int TotalArtists() const;
int TotalAlbums() const; int TotalAlbums() const;
public Q_SLOTS: public slots:
void TotalSongCountUpdated(const int count); void TotalSongCountUpdated(const int count);
void TotalArtistCountUpdated(const int count); void TotalArtistCountUpdated(const int count);
void TotalAlbumCountUpdated(const int count); void TotalAlbumCountUpdated(const int count);
@@ -82,7 +82,7 @@ class CollectionView : public AutoExpandingTreeView {
void EditTagError(const QString &message); void EditTagError(const QString &message);
Q_SIGNALS: signals:
void ShowConfigDialog(); void ShowConfigDialog();
void TotalSongCountUpdated_(); void TotalSongCountUpdated_();
@@ -97,7 +97,7 @@ class CollectionView : public AutoExpandingTreeView {
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override; void contextMenuEvent(QContextMenuEvent *e) override;
private Q_SLOTS: private slots:
void Load(); void Load();
void AddToPlaylist(); void AddToPlaylist();
void AddToPlaylistEnqueue(); void AddToPlaylistEnqueue();

View File

@@ -42,7 +42,6 @@
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <QImage> #include <QImage>
#include <QMutexLocker>
#include <QSettings> #include <QSettings>
#include "core/filesystemwatcherinterface.h" #include "core/filesystemwatcherinterface.h"
@@ -71,9 +70,9 @@
#endif #endif
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace Qt::StringLiterals;
QStringList CollectionWatcher::sValidImages = QStringList() << QStringLiteral("jpg") << QStringLiteral("png") << QStringLiteral("gif") << QStringLiteral("jpeg"); QStringList CollectionWatcher::sValidImages = QStringList() << QStringLiteral("jpg") << QStringLiteral("png") << QStringLiteral("gif") << QStringLiteral("jpeg");
const QStringList CollectionWatcher::kIgnoredExtensions = QStringList() << QStringLiteral("tmp") << QStringLiteral("tar") << QStringLiteral("gz") << QStringLiteral("bz2") << QStringLiteral("xz") << QStringLiteral("tbz") << QStringLiteral("tgz") << QStringLiteral("z") << QStringLiteral("zip") << QStringLiteral("rar");
CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent) CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent)
: QObject(parent), : QObject(parent),
@@ -99,8 +98,6 @@ CollectionWatcher::CollectionWatcher(Song::Source source, QObject *parent)
cue_parser_(new CueParser(backend_, this)), cue_parser_(new CueParser(backend_, this)),
last_scan_time_(0) { last_scan_time_(0) {
setObjectName(source_ == Song::Source::Collection ? QLatin1String(metaObject()->className()) : QStringLiteral("%1%2").arg(Song::DescriptionForSource(source_), QLatin1String(metaObject()->className())));
original_thread_ = thread(); original_thread_ = thread();
rescan_timer_->setInterval(2s); rescan_timer_->setInterval(2s);
@@ -138,51 +135,10 @@ void CollectionWatcher::Exit() {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
Abort(); Stop();
if (backend_) backend_->Close(); if (backend_) backend_->Close();
moveToThread(original_thread_); moveToThread(original_thread_);
Q_EMIT ExitFinished(); emit ExitFinished();
}
void CollectionWatcher::Stop() {
QMutexLocker l(&mutex_stop_);
stop_requested_ = true;
}
void CollectionWatcher::CancelStop() {
QMutexLocker l(&mutex_stop_);
stop_requested_ = false;
}
bool CollectionWatcher::stop_requested() const {
QMutexLocker l(&mutex_stop_);
return stop_requested_;
}
void CollectionWatcher::Abort() {
QMutexLocker l(&mutex_abort_);
abort_requested_ = true;
}
bool CollectionWatcher::abort_requested() const {
QMutexLocker l(&mutex_abort_);
return abort_requested_;
}
bool CollectionWatcher::stop_or_abort_requested() const {
return stop_requested() || abort_requested();
} }
@@ -267,14 +223,14 @@ CollectionWatcher::ScanTransaction::ScanTransaction(CollectionWatcher *watcher,
} }
task_id_ = watcher_->task_manager_->StartTask(description); task_id_ = watcher_->task_manager_->StartTask(description);
Q_EMIT watcher_->ScanStarted(task_id_); emit watcher_->ScanStarted(task_id_);
} }
CollectionWatcher::ScanTransaction::~ScanTransaction() { CollectionWatcher::ScanTransaction::~ScanTransaction() {
// If we're stopping then don't commit the transaction // If we're stopping then don't commit the transaction
if (!watcher_->stop_or_abort_requested()) { if (!watcher_->stop_requested_ && !watcher_->abort_requested_) {
CommitNewOrUpdatedSongs(); CommitNewOrUpdatedSongs();
} }
@@ -300,35 +256,35 @@ void CollectionWatcher::ScanTransaction::CommitNewOrUpdatedSongs() {
if (!deleted_songs.isEmpty()) { if (!deleted_songs.isEmpty()) {
if (mark_songs_unavailable_ && watcher_->source() == Song::Source::Collection) { if (mark_songs_unavailable_ && watcher_->source() == Song::Source::Collection) {
Q_EMIT watcher_->SongsUnavailable(deleted_songs); emit watcher_->SongsUnavailable(deleted_songs);
} }
else { else {
Q_EMIT watcher_->SongsDeleted(deleted_songs); emit watcher_->SongsDeleted(deleted_songs);
} }
deleted_songs.clear(); deleted_songs.clear();
} }
if (!new_songs.isEmpty()) { if (!new_songs.isEmpty()) {
Q_EMIT watcher_->NewOrUpdatedSongs(new_songs); emit watcher_->NewOrUpdatedSongs(new_songs);
new_songs.clear(); new_songs.clear();
} }
if (!touched_songs.isEmpty()) { if (!touched_songs.isEmpty()) {
Q_EMIT watcher_->SongsMTimeUpdated(touched_songs); emit watcher_->SongsMTimeUpdated(touched_songs);
touched_songs.clear(); touched_songs.clear();
} }
if (!readded_songs.isEmpty()) { if (!readded_songs.isEmpty()) {
Q_EMIT watcher_->SongsReadded(readded_songs); emit watcher_->SongsReadded(readded_songs);
readded_songs.clear(); readded_songs.clear();
} }
if (!new_subdirs.isEmpty()) { if (!new_subdirs.isEmpty()) {
Q_EMIT watcher_->SubdirsDiscovered(new_subdirs); emit watcher_->SubdirsDiscovered(new_subdirs);
} }
if (!touched_subdirs.isEmpty()) { if (!touched_subdirs.isEmpty()) {
Q_EMIT watcher_->SubdirsMTimeUpdated(touched_subdirs); emit watcher_->SubdirsMTimeUpdated(touched_subdirs);
touched_subdirs.clear(); touched_subdirs.clear();
} }
@@ -350,7 +306,7 @@ void CollectionWatcher::ScanTransaction::CommitNewOrUpdatedSongs() {
new_subdirs.clear(); new_subdirs.clear();
if (incremental_ || ignores_mtime_) { if (incremental_ || ignores_mtime_) {
Q_EMIT watcher_->UpdateLastSeen(dir_, expire_unavailable_songs_days_); emit watcher_->UpdateLastSeen(dir_, expire_unavailable_songs_days_);
} }
} }
@@ -361,7 +317,7 @@ SongList CollectionWatcher::ScanTransaction::FindSongsInSubdirectory(const QStri
if (cached_songs_dirty_) { if (cached_songs_dirty_) {
const SongList songs = watcher_->backend_->FindSongsInDirectory(dir_); const SongList songs = watcher_->backend_->FindSongsInDirectory(dir_);
for (const Song &song : songs) { for (const Song &song : songs) {
const QString p = song.url().toLocalFile().section(u'/', 0, -2); const QString p = song.url().toLocalFile().section(QLatin1Char('/'), 0, -2);
cached_songs_.insert(p, song); cached_songs_.insert(p, song);
} }
cached_songs_dirty_ = false; cached_songs_dirty_ = false;
@@ -380,7 +336,7 @@ bool CollectionWatcher::ScanTransaction::HasSongsWithMissingFingerprint(const QS
if (cached_songs_missing_fingerprint_dirty_) { if (cached_songs_missing_fingerprint_dirty_) {
const SongList songs = watcher_->backend_->SongsWithMissingFingerprint(dir_); const SongList songs = watcher_->backend_->SongsWithMissingFingerprint(dir_);
for (const Song &song : songs) { for (const Song &song : songs) {
const QString p = song.url().toLocalFile().section(u'/', 0, -2); const QString p = song.url().toLocalFile().section(QLatin1Char('/'), 0, -2);
cached_songs_missing_fingerprint_.insert(p, song); cached_songs_missing_fingerprint_.insert(p, song);
} }
cached_songs_missing_fingerprint_dirty_ = false; cached_songs_missing_fingerprint_dirty_ = false;
@@ -395,7 +351,7 @@ bool CollectionWatcher::ScanTransaction::HasSongsWithMissingLoudnessCharacterist
if (cached_songs_missing_loudness_characteristics_dirty_) { if (cached_songs_missing_loudness_characteristics_dirty_) {
const SongList songs = watcher_->backend_->SongsWithMissingLoudnessCharacteristics(dir_); const SongList songs = watcher_->backend_->SongsWithMissingLoudnessCharacteristics(dir_);
for (const Song &song : songs) { for (const Song &song : songs) {
const QString p = song.url().toLocalFile().section(u'/', 0, -2); const QString p = song.url().toLocalFile().section(QLatin1Char('/'), 0, -2);
cached_songs_missing_loudness_characteristics_.insert(p, song); cached_songs_missing_loudness_characteristics_.insert(p, song);
} }
cached_songs_missing_loudness_characteristics_dirty_ = false; cached_songs_missing_loudness_characteristics_dirty_ = false;
@@ -451,7 +407,7 @@ CollectionSubdirectoryList CollectionWatcher::ScanTransaction::GetAllSubdirs() {
void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdirs) { void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdirs) {
CancelStop(); stop_requested_ = false;
watched_dirs_[dir.id] = dir; watched_dirs_[dir.id] = dir;
@@ -478,16 +434,16 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle
transaction.SetKnownSubdirs(subdirs); transaction.SetKnownSubdirs(subdirs);
transaction.AddToProgressMax(files_count); transaction.AddToProgressMax(files_count);
for (const CollectionSubdirectory &subdir : subdirs) { for (const CollectionSubdirectory &subdir : subdirs) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction); ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction);
} }
if (!stop_or_abort_requested()) { if (!stop_requested_ && !abort_requested_) {
last_scan_time_ = QDateTime::currentSecsSinceEpoch(); last_scan_time_ = QDateTime::currentSecsSinceEpoch();
} }
} }
} }
Q_EMIT CompilationsNeedUpdating(); emit CompilationsNeedUpdating();
} }
@@ -541,7 +497,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
QDirIterator it(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); QDirIterator it(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
while (it.hasNext()) { while (it.hasNext()) {
if (stop_or_abort_requested()) return; if (stop_requested_ || abort_requested_) return;
QString child(it.next()); QString child(it.next());
QFileInfo child_info(child); QFileInfo child_info(child);
@@ -560,7 +516,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
else { else {
QString ext_part(ExtensionPart(child)); QString ext_part(ExtensionPart(child));
QString dir_part(DirectoryPart(child)); QString dir_part(DirectoryPart(child));
if (Song::kRejectedExtensions.contains(child_info.suffix(), Qt::CaseInsensitive) || child_info.baseName() == "qt_temp"_L1) { if (kIgnoredExtensions.contains(child_info.suffix(), Qt::CaseInsensitive) || child_info.baseName() == QLatin1String("qt_temp")) {
t->AddToProgress(1); t->AddToProgress(1);
} }
else if (sValidImages.contains(ext_part)) { else if (sValidImages.contains(ext_part)) {
@@ -576,7 +532,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
} }
} }
if (stop_or_abort_requested()) return; if (stop_requested_ || abort_requested_) return;
// Ask the database for a list of files in this directory // Ask the database for a list of files in this directory
SongList songs_in_db = t->FindSongsInSubdirectory(path); SongList songs_in_db = t->FindSongsInSubdirectory(path);
@@ -587,7 +543,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
QStringList files_on_disk_copy = files_on_disk; QStringList files_on_disk_copy = files_on_disk;
for (const QString &file : files_on_disk_copy) { for (const QString &file : files_on_disk_copy) {
if (stop_or_abort_requested()) return; if (stop_requested_ || abort_requested_) return;
// Associated CUE // Associated CUE
QString new_cue = CueParser::FindCueFilename(file); QString new_cue = CueParser::FindCueFilename(file);
@@ -662,7 +618,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
Chromaprinter chromaprinter(file); Chromaprinter chromaprinter(file);
fingerprint = chromaprinter.CreateFingerprint(); fingerprint = chromaprinter.CreateFingerprint();
if (fingerprint.isEmpty()) { if (fingerprint.isEmpty()) {
fingerprint = "NONE"_L1; fingerprint = QLatin1String("NONE");
} }
} }
#endif #endif
@@ -689,11 +645,11 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
Chromaprinter chromaprinter(file); Chromaprinter chromaprinter(file);
fingerprint = chromaprinter.CreateFingerprint(); fingerprint = chromaprinter.CreateFingerprint();
if (fingerprint.isEmpty()) { if (fingerprint.isEmpty()) {
fingerprint = "NONE"_L1; fingerprint = QLatin1String("NONE");
} }
} }
#endif #endif
if (song_tracking_ && !fingerprint.isEmpty() && fingerprint != "NONE"_L1 && FindSongsByFingerprint(file, fingerprint, &matching_songs)) { if (song_tracking_ && !fingerprint.isEmpty() && fingerprint != QLatin1String("NONE") && FindSongsByFingerprint(file, fingerprint, &matching_songs)) {
// The song is in the database and still on disk. // The song is in the database and still on disk.
// Check the mtime to see if it's been changed since it was added. // Check the mtime to see if it's been changed since it was added.
@@ -789,7 +745,7 @@ void CollectionWatcher::ScanSubdirectory(const QString &path, const CollectionSu
// Recurse into the new subdirs that we found // Recurse into the new subdirs that we found
for (const CollectionSubdirectory &my_new_subdir : std::as_const(my_new_subdirs)) { for (const CollectionSubdirectory &my_new_subdir : std::as_const(my_new_subdirs)) {
if (stop_or_abort_requested()) return; if (stop_requested_ || abort_requested_) return;
ScanSubdirectory(my_new_subdir.path, my_new_subdir, 0, t, true); ScanSubdirectory(my_new_subdir.path, my_new_subdir, 0, t, true);
} }
@@ -986,7 +942,7 @@ void CollectionWatcher::AddChangedSong(const QString &file, const Song &matching
qLog(Debug) << "Song" << file << "unchanged."; qLog(Debug) << "Song" << file << "unchanged.";
} }
else { else {
qLog(Debug) << "Song" << file << changes.join(", "_L1) << "changed."; qLog(Debug) << "Song" << file << changes.join(QLatin1String(", ")) << "changed.";
} }
} }
@@ -1130,10 +1086,10 @@ void CollectionWatcher::RescanPathsNow() {
const QList<int> dirs = rescan_queue_.keys(); const QList<int> dirs = rescan_queue_.keys();
for (const int dir : dirs) { for (const int dir : dirs) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
ScanTransaction transaction(this, dir, false, false, mark_songs_unavailable_); ScanTransaction transaction(this, dir, false, false, mark_songs_unavailable_);
const QStringList paths = rescan_queue_.value(dir); const QStringList paths = rescan_queue_[dir];
QMap<QString, quint64> subdir_files_count; QMap<QString, quint64> subdir_files_count;
for (const QString &path : paths) { for (const QString &path : paths) {
@@ -1143,7 +1099,7 @@ void CollectionWatcher::RescanPathsNow() {
} }
for (const QString &path : paths) { for (const QString &path : paths) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
CollectionSubdirectory subdir; CollectionSubdirectory subdir;
subdir.directory_id = dir; subdir.directory_id = dir;
subdir.mtime = 0; subdir.mtime = 0;
@@ -1154,7 +1110,7 @@ void CollectionWatcher::RescanPathsNow() {
rescan_queue_.clear(); rescan_queue_.clear();
Q_EMIT CompilationsNeedUpdating(); emit CompilationsNeedUpdating();
} }
@@ -1188,7 +1144,7 @@ QString CollectionWatcher::PickBestArt(const QStringList &art_automatic_list) {
QString biggest_path; QString biggest_path;
for (const QString &path : std::as_const(filtered)) { for (const QString &path : std::as_const(filtered)) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
QImage image(path); QImage image(path);
if (image.isNull()) continue; if (image.isNull()) continue;
@@ -1264,11 +1220,11 @@ void CollectionWatcher::FullScanNow() { PerformScan(false, true); }
void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mtimes) { void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mtimes) {
CancelStop(); stop_requested_ = false;
for (const CollectionDirectory &dir : std::as_const(watched_dirs_)) { for (const CollectionDirectory &dir : std::as_const(watched_dirs_)) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
ScanTransaction transaction(this, dir.id, incremental, ignore_mtimes, mark_songs_unavailable_); ScanTransaction transaction(this, dir.id, incremental, ignore_mtimes, mark_songs_unavailable_);
CollectionSubdirectoryList subdirs = transaction.GetAllSubdirs(); CollectionSubdirectoryList subdirs = transaction.GetAllSubdirs();
@@ -1286,7 +1242,7 @@ void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mt
transaction.AddToProgressMax(files_count); transaction.AddToProgressMax(files_count);
for (const CollectionSubdirectory &subdir : std::as_const(subdirs)) { for (const CollectionSubdirectory &subdir : std::as_const(subdirs)) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction); ScanSubdirectory(subdir.path, subdir, subdir_files_count[subdir.path], &transaction);
} }
@@ -1294,7 +1250,7 @@ void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mt
last_scan_time_ = QDateTime::currentSecsSinceEpoch(); last_scan_time_ = QDateTime::currentSecsSinceEpoch();
Q_EMIT CompilationsNeedUpdating(); emit CompilationsNeedUpdating();
} }
@@ -1304,7 +1260,7 @@ quint64 CollectionWatcher::FilesCountForPath(ScanTransaction *t, const QString &
QDirIterator it(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); QDirIterator it(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
while (it.hasNext()) { while (it.hasNext()) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
QString child = it.next(); QString child = it.next();
QFileInfo path_info(child); QFileInfo path_info(child);
@@ -1338,7 +1294,7 @@ quint64 CollectionWatcher::FilesCountForSubdirs(ScanTransaction *t, const Collec
quint64 i = 0; quint64 i = 0;
for (const CollectionSubdirectory &subdir : subdirs) { for (const CollectionSubdirectory &subdir : subdirs) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
const quint64 files_count = FilesCountForPath(t, subdir.path); const quint64 files_count = FilesCountForPath(t, subdir.path);
subdir_files_count[subdir.path] = files_count; subdir_files_count[subdir.path] = files_count;
i += files_count; i += files_count;
@@ -1356,17 +1312,17 @@ void CollectionWatcher::RescanSongsAsync(const SongList &songs) {
void CollectionWatcher::RescanSongs(const SongList &songs) { void CollectionWatcher::RescanSongs(const SongList &songs) {
CancelStop(); stop_requested_ = false;
QStringList scanned_paths; QStringList scanned_paths;
for (const Song &song : songs) { for (const Song &song : songs) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
const QString song_path = song.url().toLocalFile().section(u'/', 0, -2); const QString song_path = song.url().toLocalFile().section(QLatin1Char('/'), 0, -2);
if (scanned_paths.contains(song_path)) continue; if (scanned_paths.contains(song_path)) continue;
ScanTransaction transaction(this, song.directory_id(), false, true, mark_songs_unavailable_); ScanTransaction transaction(this, song.directory_id(), false, true, mark_songs_unavailable_);
const CollectionSubdirectoryList subdirs = transaction.GetAllSubdirs(); const CollectionSubdirectoryList subdirs = transaction.GetAllSubdirs();
for (const CollectionSubdirectory &subdir : subdirs) { for (const CollectionSubdirectory &subdir : subdirs) {
if (stop_or_abort_requested()) break; if (stop_requested_ || abort_requested_) break;
if (subdir.path != song_path) continue; if (subdir.path != song_path) continue;
qLog(Debug) << "Rescan for directory ID" << song.directory_id() << "directory" << subdir.path; qLog(Debug) << "Rescan for directory ID" << song.directory_id() << "directory" << subdir.path;
quint64 files_count = FilesCountForPath(&transaction, subdir.path); quint64 files_count = FilesCountForPath(&transaction, subdir.path);
@@ -1375,6 +1331,6 @@ void CollectionWatcher::RescanSongs(const SongList &songs) {
} }
} }
Q_EMIT CompilationsNeedUpdating(); emit CompilationsNeedUpdating();
} }

View File

@@ -33,7 +33,6 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <QMutex>
#include "collectiondirectory.h" #include "collectiondirectory.h"
#include "core/shared_ptr.h" #include "core/shared_ptr.h"
@@ -47,8 +46,6 @@ class FileSystemWatcherInterface;
class TaskManager; class TaskManager;
class CueParser; class CueParser;
using namespace Qt::Literals::StringLiterals;
class CollectionWatcher : public QObject { class CollectionWatcher : public QObject {
Q_OBJECT Q_OBJECT
@@ -67,15 +64,14 @@ class CollectionWatcher : public QObject {
void SetRescanPausedAsync(const bool pause); void SetRescanPausedAsync(const bool pause);
void ReloadSettingsAsync(); void ReloadSettingsAsync();
void Stop(); void Stop() { stop_requested_ = true; }
void CancelStop(); void Abort() { abort_requested_ = true; }
void Abort();
void ExitAsync(); void ExitAsync();
void RescanSongsAsync(const SongList &songs); void RescanSongsAsync(const SongList &songs);
Q_SIGNALS: signals:
void NewOrUpdatedSongs(const SongList &songs); void NewOrUpdatedSongs(const SongList &songs);
void SongsMTimeUpdated(const SongList &songs); void SongsMTimeUpdated(const SongList &songs);
void SongsDeleted(const SongList &songs); void SongsDeleted(const SongList &songs);
@@ -89,7 +85,7 @@ class CollectionWatcher : public QObject {
void ScanStarted(const int task_id); void ScanStarted(const int task_id);
public Q_SLOTS: public slots:
void AddDirectory(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdirs); void AddDirectory(const CollectionDirectory &dir, const CollectionSubdirectoryList &subdirs);
void RemoveDirectory(const CollectionDirectory &dir); void RemoveDirectory(const CollectionDirectory &dir);
void SetRescanPaused(bool pause); void SetRescanPaused(bool pause);
@@ -170,7 +166,7 @@ class CollectionWatcher : public QObject {
bool known_subdirs_dirty_; bool known_subdirs_dirty_;
}; };
private Q_SLOTS: private slots:
void ReloadSettings(); void ReloadSettings();
void Exit(); void Exit();
void DirectoryChanged(const QString &subdir); void DirectoryChanged(const QString &subdir);
@@ -182,9 +178,6 @@ class CollectionWatcher : public QObject {
void RescanSongs(const SongList &songs); void RescanSongs(const SongList &songs);
private: private:
bool stop_requested() const;
bool abort_requested() const;
bool stop_or_abort_requested() const;
static bool FindSongsByPath(const SongList &songs, const QString &path, SongList *out); static bool FindSongsByPath(const SongList &songs, const QString &path, SongList *out);
bool FindSongsByFingerprint(const QString &file, const QString &fingerprint, SongList *out); bool FindSongsByFingerprint(const QString &file, const QString &fingerprint, SongList *out);
static bool FindSongsByFingerprint(const QString &file, const SongList &songs, const QString &fingerprint, SongList *out); static bool FindSongsByFingerprint(const QString &file, const SongList &songs, const QString &fingerprint, SongList *out);
@@ -238,10 +231,7 @@ class CollectionWatcher : public QObject {
bool overwrite_playcount_; bool overwrite_playcount_;
bool overwrite_rating_; bool overwrite_rating_;
mutable QMutex mutex_stop_;
bool stop_requested_; bool stop_requested_;
mutable QMutex mutex_abort_;
bool abort_requested_; bool abort_requested_;
QMap<int, CollectionDirectory> watched_dirs_; QMap<int, CollectionDirectory> watched_dirs_;
@@ -255,20 +245,21 @@ class CollectionWatcher : public QObject {
CueParser *cue_parser_; CueParser *cue_parser_;
static QStringList sValidImages; static QStringList sValidImages;
static const QStringList kIgnoredExtensions;
qint64 last_scan_time_; qint64 last_scan_time_;
}; };
inline QString CollectionWatcher::NoExtensionPart(const QString &fileName) { inline QString CollectionWatcher::NoExtensionPart(const QString &fileName) {
return fileName.contains(u'.') ? fileName.section(u'.', 0, -2) : ""_L1; return fileName.contains(QLatin1Char('.')) ? fileName.section(QLatin1Char('.'), 0, -2) : QLatin1String("");
} }
// Thanks Amarok // Thanks Amarok
inline QString CollectionWatcher::ExtensionPart(const QString &fileName) { inline QString CollectionWatcher::ExtensionPart(const QString &fileName) {
return fileName.contains(u'.') ? fileName.mid(fileName.lastIndexOf(u'.') + 1).toLower() : ""_L1; return fileName.contains(QLatin1Char('.')) ? fileName.mid(fileName.lastIndexOf(QLatin1Char('.')) + 1).toLower() : QLatin1String("");
} }
inline QString CollectionWatcher::DirectoryPart(const QString &fileName) { inline QString CollectionWatcher::DirectoryPart(const QString &fileName) {
return fileName.section(u'/', 0, -2); return fileName.section(QLatin1Char('/'), 0, -2);
} }
#endif // COLLECTIONWATCHER_H #endif // COLLECTIONWATCHER_H

View File

@@ -116,7 +116,7 @@ void GroupByDialog::Reset() {
void GroupByDialog::accept() { void GroupByDialog::accept() {
Q_EMIT Accepted(CollectionModel::Grouping( emit Accepted(CollectionModel::Grouping(
p_->mapping_.get<tag_index>().find(ui_->combobox_first->currentIndex())->group_by, p_->mapping_.get<tag_index>().find(ui_->combobox_first->currentIndex())->group_by,
p_->mapping_.get<tag_index>().find(ui_->combobox_second->currentIndex())->group_by, p_->mapping_.get<tag_index>().find(ui_->combobox_second->currentIndex())->group_by,
p_->mapping_.get<tag_index>().find(ui_->combobox_third->currentIndex())->group_by), p_->mapping_.get<tag_index>().find(ui_->combobox_third->currentIndex())->group_by),

View File

@@ -43,14 +43,14 @@ class GroupByDialog : public QDialog {
explicit GroupByDialog(QWidget *parent = nullptr); explicit GroupByDialog(QWidget *parent = nullptr);
~GroupByDialog() override; ~GroupByDialog() override;
public Q_SLOTS: public slots:
void CollectionGroupingChanged(const CollectionModel::Grouping g, const bool separate_albums_by_grouping); void CollectionGroupingChanged(const CollectionModel::Grouping g, const bool separate_albums_by_grouping);
void accept() override; void accept() override;
Q_SIGNALS: signals:
void Accepted(const CollectionModel::Grouping g, const bool separate_albums_by_grouping); void Accepted(const CollectionModel::Grouping g, const bool separate_albums_by_grouping);
private Q_SLOTS: private slots:
void Reset(); void Reset();
private: private:

View File

@@ -44,8 +44,6 @@
#include "savedgroupingmanager.h" #include "savedgroupingmanager.h"
#include "ui_savedgroupingmanager.h" #include "ui_savedgroupingmanager.h"
using namespace Qt::StringLiterals;
const char *SavedGroupingManager::kSavedGroupingsSettingsGroup = "SavedGroupings"; const char *SavedGroupingManager::kSavedGroupingsSettingsGroup = "SavedGroupings";
SavedGroupingManager::SavedGroupingManager(const QString &saved_groupings_settings_group, QWidget *parent) SavedGroupingManager::SavedGroupingManager(const QString &saved_groupings_settings_group, QWidget *parent)
@@ -167,7 +165,7 @@ void SavedGroupingManager::UpdateModel() {
if (version == 1) { if (version == 1) {
QStringList saved = s.childKeys(); QStringList saved = s.childKeys();
for (int i = 0; i < saved.size(); ++i) { for (int i = 0; i < saved.size(); ++i) {
if (saved.at(i) == "version"_L1) continue; if (saved.at(i) == QLatin1String("version")) continue;
QByteArray bytes = s.value(saved.at(i)).toByteArray(); QByteArray bytes = s.value(saved.at(i)).toByteArray();
QDataStream ds(&bytes, QIODevice::ReadOnly); QDataStream ds(&bytes, QIODevice::ReadOnly);
CollectionModel::Grouping g; CollectionModel::Grouping g;
@@ -185,7 +183,7 @@ void SavedGroupingManager::UpdateModel() {
else { else {
QStringList saved = s.childKeys(); QStringList saved = s.childKeys();
for (int i = 0; i < saved.size(); ++i) { for (int i = 0; i < saved.size(); ++i) {
if (saved.at(i) == "version"_L1) continue; if (saved.at(i) == QLatin1String("version")) continue;
s.remove(saved.at(i)); s.remove(saved.at(i));
} }
} }
@@ -209,7 +207,7 @@ void SavedGroupingManager::Remove() {
} }
UpdateModel(); UpdateModel();
Q_EMIT UpdateGroupByActions(); emit UpdateGroupByActions();
} }

View File

@@ -51,10 +51,10 @@ class SavedGroupingManager : public QDialog {
static QString GroupByToString(const CollectionModel::GroupBy g); static QString GroupByToString(const CollectionModel::GroupBy g);
Q_SIGNALS: signals:
void UpdateGroupByActions(); void UpdateGroupByActions();
private Q_SLOTS: private slots:
void UpdateButtonState(); void UpdateButtonState();
void Remove(); void Remove();

View File

@@ -48,11 +48,13 @@
#cmakedefine INSTALL_TRANSLATIONS #cmakedefine INSTALL_TRANSLATIONS
#define TRANSLATIONS_DIR "${CMAKE_INSTALL_PREFIX}/share/strawberry/translations" #define TRANSLATIONS_DIR "${CMAKE_INSTALL_PREFIX}/share/strawberry/translations"
#cmakedefine HAVE_QX11APPLICATION
#cmakedefine HAVE_QPA_QPLATFORMNATIVEINTERFACE_H #cmakedefine HAVE_QPA_QPLATFORMNATIVEINTERFACE_H
#cmakedefine HAVE_X11EXTRAS
#cmakedefine ENABLE_WIN32_CONSOLE #cmakedefine ENABLE_WIN32_CONSOLE
#cmakedefine HAVE_QX11APPLICATION
#cmakedefine HAVE_EBUR128 #cmakedefine HAVE_EBUR128
#endif // CONFIG_H_IN #endif // CONFIG_H_IN

View File

@@ -19,7 +19,6 @@
#include "config.h" #include "config.h"
#include <utility>
#include <memory> #include <memory>
#include <QtGlobal> #include <QtGlobal>
@@ -203,7 +202,7 @@ void ContextAlbum::DrawSpinner(QPainter *p) {
void ContextAlbum::DrawPreviousCovers(QPainter *p) { void ContextAlbum::DrawPreviousCovers(QPainter *p) {
for (SharedPtr<PreviousCover> previous_cover : std::as_const(previous_covers_)) { for (SharedPtr<PreviousCover> previous_cover : previous_covers_) {
DrawImage(p, previous_cover->pixmap, previous_cover->opacity); DrawImage(p, previous_cover->pixmap, previous_cover->opacity);
} }
@@ -221,7 +220,7 @@ void ContextAlbum::FadeCurrentCover(const qreal value) {
void ContextAlbum::FadeCurrentCoverFinished() { void ContextAlbum::FadeCurrentCoverFinished() {
if (image_original_ == image_strawberry_) { if (image_original_ == image_strawberry_) {
Q_EMIT FadeStopFinished(); emit FadeStopFinished();
} }
} }
@@ -255,7 +254,7 @@ void ContextAlbum::ScaleCover() {
void ContextAlbum::ScalePreviousCovers() { void ContextAlbum::ScalePreviousCovers() {
for (SharedPtr<PreviousCover> previous_cover : std::as_const(previous_covers_)) { for (SharedPtr<PreviousCover> previous_cover : previous_covers_) {
QImage image = ImageUtils::ScaleImage(previous_cover->image, QSize(desired_height_, desired_height_), devicePixelRatioF(), true); QImage image = ImageUtils::ScaleImage(previous_cover->image, QSize(desired_height_, desired_height_), devicePixelRatioF(), true);
if (image.isNull()) { if (image.isNull()) {
previous_cover->pixmap = QPixmap(); previous_cover->pixmap = QPixmap();

View File

@@ -78,18 +78,18 @@ class ContextAlbum : public QWidget {
void ScaleCover(); void ScaleCover();
void ScalePreviousCovers(); void ScalePreviousCovers();
Q_SIGNALS: signals:
void FadeStopFinished(); void FadeStopFinished();
private Q_SLOTS: private slots:
void Update() { update(); } void Update() { update(); }
void AutomaticCoverSearchDone(); void AutomaticCoverSearchDone();
void FadeCurrentCover(const qreal value); void FadeCurrentCover(const qreal value);
void FadeCurrentCoverFinished(); void FadeCurrentCoverFinished();
void FadePreviousCover(SharedPtr<ContextAlbum::PreviousCover> previous_cover); void FadePreviousCover(SharedPtr<PreviousCover> previous_cover);
void FadePreviousCoverFinished(SharedPtr<ContextAlbum::PreviousCover> previous_cover); void FadePreviousCoverFinished(SharedPtr<PreviousCover> previous_cover);
public Q_SLOTS: public slots:
void SearchCoverInProgress(); void SearchCoverInProgress();
private: private:

View File

@@ -19,8 +19,6 @@
#include "config.h" #include "config.h"
#include <utility>
#include <QtGlobal> #include <QtGlobal>
#include <QObject> #include <QObject>
#include <QWidget> #include <QWidget>
@@ -67,8 +65,6 @@
#include "contextview.h" #include "contextview.h"
#include "contextalbum.h" #include "contextalbum.h"
using namespace Qt::StringLiterals;
namespace { namespace {
constexpr int kWidgetSpacing = 50; constexpr int kWidgetSpacing = 50;
} }
@@ -297,7 +293,11 @@ void ContextView::AddActions() {
void ContextView::ReloadSettings() { void ContextView::ReloadSettings() {
QString default_font; QString default_font;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (QFontDatabase::families().contains(QLatin1String(ContextSettingsPage::kDefaultFontFamily))) { if (QFontDatabase::families().contains(QLatin1String(ContextSettingsPage::kDefaultFontFamily))) {
#else
if (QFontDatabase().families().contains(QLatin1String(ContextSettingsPage::kDefaultFontFamily))) {
#endif
default_font = QLatin1String(ContextSettingsPage::kDefaultFontFamily); default_font = QLatin1String(ContextSettingsPage::kDefaultFontFamily);
} }
else { else {
@@ -412,15 +412,15 @@ void ContextView::NoSong() {
QString html; QString html;
if (collectionview_->TotalSongs() == 1) html += tr("%1 song").arg(collectionview_->TotalSongs()); if (collectionview_->TotalSongs() == 1) html += tr("%1 song").arg(collectionview_->TotalSongs());
else html += tr("%1 songs").arg(collectionview_->TotalSongs()); else html += tr("%1 songs").arg(collectionview_->TotalSongs());
html += "<br />"_L1; html += QLatin1String("<br />");
if (collectionview_->TotalArtists() == 1) html += tr("%1 artist").arg(collectionview_->TotalArtists()); if (collectionview_->TotalArtists() == 1) html += tr("%1 artist").arg(collectionview_->TotalArtists());
else html += tr("%1 artists").arg(collectionview_->TotalArtists()); else html += tr("%1 artists").arg(collectionview_->TotalArtists());
html += "<br />"_L1; html += QLatin1String("<br />");
if (collectionview_->TotalAlbums() == 1) html += tr("%1 album").arg(collectionview_->TotalAlbums()); if (collectionview_->TotalAlbums() == 1) html += tr("%1 album").arg(collectionview_->TotalAlbums());
else html += tr("%1 albums").arg(collectionview_->TotalAlbums()); else html += tr("%1 albums").arg(collectionview_->TotalAlbums());
html += "<br />"_L1; html += QLatin1String("<br />");
label_stop_summary_->setFont(font_normal_); label_stop_summary_->setFont(font_normal_);
label_stop_summary_->setText(html); label_stop_summary_->setText(html);
@@ -429,10 +429,10 @@ void ContextView::NoSong() {
void ContextView::UpdateFonts() { void ContextView::UpdateFonts() {
for (QLabel *l : std::as_const(labels_play_all_)) { for (QLabel *l : labels_play_all_) {
l->setFont(font_normal_); l->setFont(font_normal_);
} }
for (QTextEdit *e : std::as_const(textedit_play_)) { for (QTextEdit *e : textedit_play_) {
e->setFont(font_normal_); e->setFont(font_normal_);
} }
@@ -454,7 +454,7 @@ void ContextView::SetSong() {
widget_album_->hide(); widget_album_->hide();
widget_album_changed = true; widget_album_changed = true;
} }
if (widget_album_changed) Q_EMIT AlbumEnabledChanged(); if (widget_album_changed) emit AlbumEnabledChanged();
if (action_show_data_->isChecked()) { if (action_show_data_->isChecked()) {
widget_play_data_->show(); widget_play_data_->show();
@@ -620,11 +620,11 @@ void ContextView::UpdateSong(const Song &song) {
void ContextView::ResetSong() { void ContextView::ResetSong() {
for (QLabel *l : std::as_const(labels_play_data_)) { for (QLabel *l : labels_play_data_) {
l->clear(); l->clear();
} }
for (QTextEdit *l : std::as_const(textedit_play_)) { for (QTextEdit *l : textedit_play_) {
l->clear(); l->clear();
} }
@@ -638,10 +638,10 @@ void ContextView::UpdateLyrics(const quint64 id, const QString &provider, const
if (static_cast<qint64>(id) != lyrics_id_) return; if (static_cast<qint64>(id) != lyrics_id_) return;
if (lyrics.isEmpty()) { if (lyrics.isEmpty()) {
lyrics_ = "No lyrics found.\n"_L1; lyrics_ = QLatin1String("No lyrics found.\n");
} }
else { else {
lyrics_ = lyrics + "\n\n(Lyrics from "_L1 + provider + ")\n"_L1; lyrics_ = lyrics + QLatin1String("\n\n(Lyrics from ") + provider + QLatin1String(")\n");
} }
lyrics_id_ = -1; lyrics_id_ = -1;

View File

@@ -80,10 +80,10 @@ class ContextView : public QWidget {
void SearchLyrics(); void SearchLyrics();
void UpdateFonts(); void UpdateFonts();
Q_SIGNALS: signals:
void AlbumEnabledChanged(); void AlbumEnabledChanged();
private Q_SLOTS: private slots:
void ActionShowAlbum(); void ActionShowAlbum();
void ActionShowData(); void ActionShowData();
void ActionShowLyrics(); void ActionShowLyrics();
@@ -92,7 +92,7 @@ class ContextView : public QWidget {
void FadeStopFinished(); void FadeStopFinished();
void UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics); void UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics);
public Q_SLOTS: public slots:
void ReloadSettings(); void ReloadSettings();
void Playing(); void Playing();
void Stopped(); void Stopped();

View File

@@ -24,7 +24,6 @@
#include "application.h" #include "application.h"
#include <utility>
#include <functional> #include <functional>
#include <chrono> #include <chrono>
@@ -69,7 +68,6 @@
#include "lyrics/azlyricscomlyricsprovider.h" #include "lyrics/azlyricscomlyricsprovider.h"
#include "lyrics/elyricsnetlyricsprovider.h" #include "lyrics/elyricsnetlyricsprovider.h"
#include "lyrics/letraslyricsprovider.h" #include "lyrics/letraslyricsprovider.h"
#include "lyrics/lyricfindlyricsprovider.h"
#include "scrobbler/audioscrobbler.h" #include "scrobbler/audioscrobbler.h"
#include "scrobbler/lastfmscrobbler.h" #include "scrobbler/lastfmscrobbler.h"
@@ -171,16 +169,15 @@ class ApplicationImpl {
lyrics_providers_([app]() { lyrics_providers_([app]() {
LyricsProviders *lyrics_providers = new LyricsProviders(app); LyricsProviders *lyrics_providers = new LyricsProviders(app);
// Initialize the repository of lyrics providers. // Initialize the repository of lyrics providers.
lyrics_providers->AddProvider(new GeniusLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new GeniusLyricsProvider(app->network()));
lyrics_providers->AddProvider(new OVHLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new OVHLyricsProvider(app->network()));
lyrics_providers->AddProvider(new LoloLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new LoloLyricsProvider(app->network()));
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new MusixmatchLyricsProvider(app->network()));
lyrics_providers->AddProvider(new ChartLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new ChartLyricsProvider(app->network()));
lyrics_providers->AddProvider(new SongLyricsComLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new SongLyricsComLyricsProvider(app->network()));
lyrics_providers->AddProvider(new AzLyricsComLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new AzLyricsComLyricsProvider(app->network()));
lyrics_providers->AddProvider(new ElyricsNetLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new ElyricsNetLyricsProvider(app->network()));
lyrics_providers->AddProvider(new LetrasLyricsProvider(lyrics_providers->network())); lyrics_providers->AddProvider(new LetrasLyricsProvider(app->network()));
lyrics_providers->AddProvider(new LyricFindLyricsProvider(lyrics_providers->network()));
lyrics_providers->ReloadSettings(); lyrics_providers->ReloadSettings();
return lyrics_providers; return lyrics_providers;
}), }),
@@ -248,8 +245,6 @@ class ApplicationImpl {
Application::Application(QObject *parent) Application::Application(QObject *parent)
: QObject(parent), p_(new ApplicationImpl(this)) { : QObject(parent), p_(new ApplicationImpl(this)) {
setObjectName(QLatin1String(metaObject()->className()));
device_finders()->Init(); device_finders()->Init();
collection()->Init(); collection()->Init();
tag_reader_client(); tag_reader_client();
@@ -262,11 +257,11 @@ Application::~Application() {
qLog(Debug) << "Terminating application"; qLog(Debug) << "Terminating application";
for (QThread *thread : std::as_const(threads_)) { for (QThread *thread : threads_) {
thread->quit(); thread->quit();
} }
for (QThread *thread : std::as_const(threads_)) { for (QThread *thread : threads_) {
thread->wait(); thread->wait();
thread->deleteLater(); thread->deleteLater();
} }
@@ -277,8 +272,6 @@ QThread *Application::MoveToNewThread(QObject *object) {
QThread *thread = new QThread(this); QThread *thread = new QThread(this);
thread->setObjectName(object->objectName());
MoveToThread(object, thread); MoveToThread(object, thread);
thread->start(); thread->start();
@@ -347,9 +340,9 @@ void Application::ExitReceived() {
} }
void Application::AddError(const QString &message) { Q_EMIT ErrorAdded(message); } void Application::AddError(const QString &message) { emit ErrorAdded(message); }
void Application::ReloadSettings() { Q_EMIT SettingsChanged(); } void Application::ReloadSettings() { emit SettingsChanged(); }
void Application::OpenSettingsDialogAtPage(SettingsDialog::Page page) { Q_EMIT SettingsDialogRequested(page); } void Application::OpenSettingsDialogAtPage(SettingsDialog::Page page) { emit SettingsDialogRequested(page); }
SharedPtr<TagReaderClient> Application::tag_reader_client() const { return p_->tag_reader_client_.ptr(); } SharedPtr<TagReaderClient> Application::tag_reader_client() const { return p_->tag_reader_client_.ptr(); }
SharedPtr<Database> Application::database() const { return p_->database_.ptr(); } SharedPtr<Database> Application::database() const { return p_->database_.ptr(); }

View File

@@ -112,15 +112,15 @@ class Application : public QObject {
QThread *MoveToNewThread(QObject *object); QThread *MoveToNewThread(QObject *object);
static void MoveToThread(QObject *object, QThread *thread); static void MoveToThread(QObject *object, QThread *thread);
private Q_SLOTS: private slots:
void ExitReceived(); void ExitReceived();
public Q_SLOTS: public slots:
void AddError(const QString &message); void AddError(const QString &message);
void ReloadSettings(); void ReloadSettings();
void OpenSettingsDialogAtPage(SettingsDialog::Page page); void OpenSettingsDialogAtPage(SettingsDialog::Page page);
Q_SIGNALS: signals:
void ErrorAdded(const QString &message); void ErrorAdded(const QString &message);
void SettingsChanged(); void SettingsChanged();
void SettingsDialogRequested(const SettingsDialog::Page page); void SettingsDialogRequested(const SettingsDialog::Page page);

View File

@@ -206,7 +206,7 @@ bool CommandlineOptions::Parse() {
// Parse the arguments // Parse the arguments
bool ok = false; bool ok = false;
Q_FOREVER { forever {
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
int c = getopt_long(argc_, argv_, L"hptusqrfv:c:alk:i:oyg:w:", kOptions, nullptr); int c = getopt_long(argc_, argv_, L"hptusqrfv:c:alk:i:oyg:w:", kOptions, nullptr);
#else #else

View File

@@ -49,8 +49,6 @@
#include "sqlquery.h" #include "sqlquery.h"
#include "scopedtransaction.h" #include "scopedtransaction.h"
using namespace Qt::StringLiterals;
const int Database::kSchemaVersion = 20; const int Database::kSchemaVersion = 20;
namespace { namespace {
@@ -65,13 +63,14 @@ QMutex Database::sNextConnectionIdMutex;
Database::Database(Application *app, QObject *parent, const QString &database_name) : Database::Database(Application *app, QObject *parent, const QString &database_name) :
QObject(parent), QObject(parent),
app_(app), app_(app),
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mutex_(QMutex::Recursive),
#endif
injected_database_name_(database_name), injected_database_name_(database_name),
query_hash_(0), query_hash_(0),
startup_schema_version_(-1), startup_schema_version_(-1),
original_thread_(nullptr) { original_thread_(nullptr) {
setObjectName(QLatin1String(metaObject()->className()));
original_thread_ = thread(); original_thread_ = thread();
{ {
@@ -106,7 +105,7 @@ void Database::Exit() {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());
Close(); Close();
moveToThread(original_thread_); moveToThread(original_thread_);
Q_EMIT ExitFinished(); emit ExitFinished();
} }
@@ -138,7 +137,7 @@ QSqlDatabase Database::Connect() {
//qLog(Debug) << "Opened database with connection id" << connection_id; //qLog(Debug) << "Opened database with connection id" << connection_id;
if (injected_database_name_.isNull()) { if (injected_database_name_.isNull()) {
db.setDatabaseName(directory_ + u'/' + QLatin1String(kDatabaseFilename)); db.setDatabaseName(directory_ + QLatin1Char('/') + QLatin1String(kDatabaseFilename));
} }
else { else {
db.setDatabaseName(injected_database_name_); db.setDatabaseName(injected_database_name_);
@@ -162,7 +161,7 @@ QSqlDatabase Database::Connect() {
// Attach external databases // Attach external databases
QStringList keys = attached_databases_.keys(); QStringList keys = attached_databases_.keys();
for (const QString &key : std::as_const(keys)) { for (const QString &key : std::as_const(keys)) {
QString filename = attached_databases_.value(key).filename_; QString filename = attached_databases_[key].filename_;
if (!injected_database_name_.isNull()) filename = injected_database_name_; if (!injected_database_name_.isNull()) filename = injected_database_name_;
@@ -183,7 +182,7 @@ QSqlDatabase Database::Connect() {
// We might have to initialize the schema in some attached databases now, if they were deleted and don't match up with the main schema version. // We might have to initialize the schema in some attached databases now, if they were deleted and don't match up with the main schema version.
keys = attached_databases_.keys(); keys = attached_databases_.keys();
for (const QString &key : std::as_const(keys)) { for (const QString &key : std::as_const(keys)) {
if (attached_databases_.value(key).is_temporary_ && attached_databases_.value(key).schema_.isEmpty()) { if (attached_databases_[key].is_temporary_ && attached_databases_[key].schema_.isEmpty()) {
continue; continue;
} }
// Find out if there are any tables in this database // Find out if there are any tables in this database
@@ -259,7 +258,7 @@ void Database::RecreateAttachedDb(const QString &database_name) {
return; return;
} }
const QString filename = attached_databases_.value(database_name).filename_; const QString filename = attached_databases_[database_name].filename_;
QMutexLocker l(&mutex_); QMutexLocker l(&mutex_);
{ {
@@ -354,7 +353,7 @@ void Database::UrlEncodeFilenameColumn(const QString &table, QSqlDatabase &db) {
const int rowid = select.value(0).toInt(); const int rowid = select.value(0).toInt();
const QString filename = select.value(1).toString(); const QString filename = select.value(1).toString();
if (filename.isEmpty() || filename.contains("://"_L1)) { if (filename.isEmpty() || filename.contains(QLatin1String("://"))) {
continue; continue;
} }
@@ -378,8 +377,8 @@ void Database::ExecSchemaCommandsFromFile(QSqlDatabase &db, const QString &filen
} }
QByteArray data = schema_file.readAll(); QByteArray data = schema_file.readAll();
QString schema = QString::fromUtf8(data); QString schema = QString::fromUtf8(data);
if (schema.contains("\r\n"_L1)) { if (schema.contains(QLatin1String("\r\n"))) {
schema = schema.replace("\r\n"_L1, "\n"_L1); schema = schema.replace(QLatin1String("\r\n"), QLatin1String("\n"));
} }
schema_file.close(); schema_file.close();
ExecSchemaCommands(db, schema, schema_version, in_transaction); ExecSchemaCommands(db, schema, schema_version, in_transaction);
@@ -389,8 +388,7 @@ void Database::ExecSchemaCommandsFromFile(QSqlDatabase &db, const QString &filen
void Database::ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction) { void Database::ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction) {
// Run each command // Run each command
static const QRegularExpression regex_split_commands(QStringLiteral("; *\n\n")); QStringList commands = schema.split(QRegularExpression(QStringLiteral("; *\n\n")));
QStringList commands = schema.split(regex_split_commands);
// We don't want this list to reflect possible DB schema changes, so we initialize it before executing any statements. // We don't want this list to reflect possible DB schema changes, so we initialize it before executing any statements.
// If no outer transaction is provided the song tables need to be queried before beginning an inner transaction! // If no outer transaction is provided the song tables need to be queried before beginning an inner transaction!
@@ -416,7 +414,7 @@ void Database::ExecSongTablesCommands(QSqlDatabase &db, const QStringList &song_
if (command.contains(QLatin1String(kMagicAllSongsTables))) { if (command.contains(QLatin1String(kMagicAllSongsTables))) {
for (const QString &table : song_tables) { for (const QString &table : song_tables) {
// Another horrible hack: device songs tables don't have matching _fts tables, so if this command tries to touch one, ignore it. // Another horrible hack: device songs tables don't have matching _fts tables, so if this command tries to touch one, ignore it.
if (table.startsWith("device_"_L1) && command.contains(QLatin1String(kMagicAllSongsTables) + "_fts"_L1)) { if (table.startsWith(QLatin1String("device_")) && command.contains(QLatin1String(kMagicAllSongsTables) + QLatin1String("_fts"))) {
continue; continue;
} }
@@ -452,7 +450,7 @@ QStringList Database::SongsTables(QSqlDatabase &db, const int schema_version) {
// look for the tables in the main db // look for the tables in the main db
const QStringList &tables = db.tables(); const QStringList &tables = db.tables();
for (const QString &table : tables) { for (const QString &table : tables) {
if (table == "songs"_L1 || table.endsWith("_songs"_L1)) ret << table; if (table == QLatin1String("songs") || table.endsWith(QLatin1String("_songs"))) ret << table;
} }
// look for the tables in attached dbs // look for the tables in attached dbs
@@ -483,8 +481,8 @@ void Database::ReportErrors(const SqlQuery &query) {
if (sql_error.isValid()) { if (sql_error.isValid()) {
qLog(Error) << "Unable to execute SQL query:" << sql_error; qLog(Error) << "Unable to execute SQL query:" << sql_error;
qLog(Error) << "Failed SQL query:" << query.LastQuery(); qLog(Error) << "Failed SQL query:" << query.LastQuery();
Q_EMIT Error(tr("Unable to execute SQL query: %1").arg(sql_error.text())); emit Error(tr("Unable to execute SQL query: %1").arg(sql_error.text()));
Q_EMIT Error(tr("Failed SQL query: %1").arg(query.LastQuery())); emit Error(tr("Failed SQL query: %1").arg(query.LastQuery()));
} }
} }
@@ -504,7 +502,7 @@ bool Database::IntegrityCheck(const QSqlDatabase &db) {
QString message = q.value(0).toString(); QString message = q.value(0).toString();
// If no errors are found, a single row with the value "ok" is returned // If no errors are found, a single row with the value "ok" is returned
if (message == "ok"_L1) { if (message == QLatin1String("ok")) {
ok = true; ok = true;
break; break;
} }

View File

@@ -34,7 +34,9 @@
#include <QSqlQuery> #include <QSqlQuery>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QRecursiveMutex> #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
# include <QRecursiveMutex>
#endif
#include "sqlquery.h" #include "sqlquery.h"
@@ -65,7 +67,11 @@ class Database : public QObject {
void Close(); void Close();
void ReportErrors(const SqlQuery &query); void ReportErrors(const SqlQuery &query);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex *Mutex() { return &mutex_; } QRecursiveMutex *Mutex() { return &mutex_; }
#else
QMutex *Mutex() { return &mutex_; }
#endif
void RecreateAttachedDb(const QString &database_name); void RecreateAttachedDb(const QString &database_name);
void ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction = false); void ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction = false);
@@ -77,15 +83,15 @@ class Database : public QObject {
void AttachDatabaseOnDbConnection(const QString &database_name, const AttachedDatabase &database, QSqlDatabase &db); void AttachDatabaseOnDbConnection(const QString &database_name, const AttachedDatabase &database, QSqlDatabase &db);
void DetachDatabase(const QString &database_name); void DetachDatabase(const QString &database_name);
Q_SIGNALS: signals:
void ExitFinished(); void ExitFinished();
void Error(const QString &error); void Error(const QString &error);
void Errors(const QStringList &errors); void Errors(const QStringList &errors);
private Q_SLOTS: private slots:
void Exit(); void Exit();
public Q_SLOTS: public slots:
void DoBackup(); void DoBackup();
private: private:
@@ -109,7 +115,11 @@ class Database : public QObject {
QString directory_; QString directory_;
QMutex connect_mutex_; QMutex connect_mutex_;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex mutex_; QRecursiveMutex mutex_;
#else
QMutex mutex_;
#endif
// This ID makes the QSqlDatabase name unique to the object as well as the thread // This ID makes the QSqlDatabase name unique to the object as well as the thread
int connection_id_; int connection_id_;

View File

@@ -99,7 +99,7 @@ void DeleteFiles::ProcessSomeFiles() {
task_manager_->SetTaskFinished(task_id_); task_manager_->SetTaskFinished(task_id_);
Q_EMIT Finished(songs_with_errors_); emit Finished(songs_with_errors_);
// Move back to the original thread so deleteLater() can get called in the main thread's event loop // Move back to the original thread so deleteLater() can get called in the main thread's event loop
moveToThread(original_thread_); moveToThread(original_thread_);
@@ -116,7 +116,7 @@ void DeleteFiles::ProcessSomeFiles() {
for (; progress_ < n; ++progress_) { for (; progress_ < n; ++progress_) {
task_manager_->SetTaskProgress(task_id_, progress_, songs_.count()); task_manager_->SetTaskProgress(task_id_, progress_, songs_.count());
const Song song = songs_.value(progress_); const Song &song = songs_[progress_];
MusicStorage::DeleteJob job; MusicStorage::DeleteJob job;
job.metadata_ = song; job.metadata_ = song;

View File

@@ -44,10 +44,10 @@ class DeleteFiles : public QObject {
void Start(const SongList &songs); void Start(const SongList &songs);
void Start(const QStringList &filenames); void Start(const QStringList &filenames);
Q_SIGNALS: signals:
void Finished(const SongList &songs_with_errors); void Finished(const SongList &songs_with_errors);
private Q_SLOTS: private slots:
void ProcessSomeFiles(); void ProcessSomeFiles();
private: private:

View File

@@ -114,7 +114,11 @@ bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) {
QFileInfo fileInfo(path); QFileInfo fileInfo(path);
if (job.use_trash_) { if (job.use_trash_) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
return QFile::moveToTrash(path); return QFile::moveToTrash(path);
#else
return false;
#endif
} }
if (fileInfo.isDir()) { if (fileInfo.isDir()) {

View File

@@ -39,7 +39,7 @@ class FileSystemWatcherInterface : public QObject {
static FileSystemWatcherInterface *Create(QObject *parent = nullptr); static FileSystemWatcherInterface *Create(QObject *parent = nullptr);
Q_SIGNALS: signals:
void PathChanged(const QString &path); void PathChanged(const QString &path);
}; };

View File

@@ -27,8 +27,6 @@
namespace IconMapper { namespace IconMapper {
using namespace Qt::Literals::StringLiterals;
struct IconProperties { struct IconProperties {
explicit IconProperties() : min_size(0), max_size(0), allow_system_icon(true) {} explicit IconProperties() : min_size(0), max_size(0), allow_system_icon(true) {}
IconProperties(const QStringList &_names, const int _min_size = 16, const int _max_size = 512, const bool _allow_system_icon = true) : names(_names), min_size(_min_size), max_size(_max_size), allow_system_icon(_allow_system_icon) {} IconProperties(const QStringList &_names, const int _min_size = 16, const int _max_size = 512, const bool _allow_system_icon = true) : names(_names), min_size(_min_size), max_size(_max_size), allow_system_icon(_allow_system_icon) {}
@@ -40,103 +38,104 @@ struct IconProperties {
static const QMap<QString, IconProperties> iconmapper_ = { // clazy:exclude=non-pod-global-static static const QMap<QString, IconProperties> iconmapper_ = { // clazy:exclude=non-pod-global-static
{ u"albums"_s, { {u"media-optical"_s}} }, { QStringLiteral("albums"), { {QStringLiteral("media-optical")}} },
{ u"alsa"_s, { {}} }, { QStringLiteral("alsa"), { {}} },
{ u"application-exit"_s, { {}} }, { QStringLiteral("application-exit"), { {}} },
{ u"applications-internet"_s, { {}} }, { QStringLiteral("applications-internet"), { {}} },
{ u"bluetooth"_s, { {u"preferences-system-bluetooth"_s, u"bluetooth-active"_s}} }, { QStringLiteral("bluetooth"), { {QStringLiteral("preferences-system-bluetooth"), QStringLiteral("bluetooth-active")}} },
{ u"cdcase"_s, { {u"cdcover"_s, u"media-optical"_s}} }, { QStringLiteral("cdcase"), { {QStringLiteral("cdcover"), QStringLiteral("media-optical")}} },
{ u"media-optical"_s, { {u"cd"_s}} }, { QStringLiteral("media-optical"), { {QStringLiteral("cd")}} },
{ u"configure"_s, { {}} }, { QStringLiteral("configure"), { {}} },
{ u"device-ipod-nano"_s, { {}} }, { QStringLiteral("device-ipod-nano"), { {}} },
{ u"device-ipod"_s, { {}} }, { QStringLiteral("device-ipod"), { {}} },
{ u"device-phone"_s, { {}} }, { QStringLiteral("device-phone"), { {}} },
{ u"device"_s, { {u"drive-removable-media-usb-pendrive"_s}} }, { QStringLiteral("device"), { {QStringLiteral("drive-removable-media-usb-pendrive")}} },
{ u"device-usb-drive"_s, { {}} }, { QStringLiteral("device-usb-drive"), { {}} },
{ u"device-usb-flash"_s, { {}} }, { QStringLiteral("device-usb-flash"), { {}} },
{ u"dialog-error"_s, { {}} }, { QStringLiteral("dialog-error"), { {}} },
{ u"dialog-information"_s, { {}} }, { QStringLiteral("dialog-information"), { {}} },
{ u"dialog-ok-apply"_s, { {}} }, { QStringLiteral("dialog-ok-apply"), { {}} },
{ u"dialog-password"_s, { {}} }, { QStringLiteral("dialog-password"), { {}} },
{ u"dialog-warning"_s, { {}} }, { QStringLiteral("dialog-warning"), { {}} },
{ u"document-download"_s, { {u"download"_s}} }, { QStringLiteral("document-download"), { {QStringLiteral("download")}} },
{ u"document-new"_s, { {}} }, { QStringLiteral("document-new"), { {}} },
{ u"document-open-folder"_s, { {}} }, { QStringLiteral("document-open-folder"), { {}} },
{ u"document-open"_s, { {}} }, { QStringLiteral("document-open"), { {}} },
{ u"document-save"_s, { {}} }, { QStringLiteral("document-save"), { {}} },
{ u"document-search"_s, { {}} }, { QStringLiteral("document-search"), { {}} },
{ u"document-open-remote"_s, { {}} }, { QStringLiteral("document-open-remote"), { {}} },
{ u"download"_s, { {u"applications-internet"_s, u"network-workgroup"_s}} }, { QStringLiteral("download"), { {QStringLiteral("applications-internet"), QStringLiteral("network-workgroup")}} },
{ u"edit-clear-list"_s, { {u"edit-clear-list"_s, u"edit-clear-all"_s}} }, { QStringLiteral("edit-clear-list"), { {QStringLiteral("edit-clear-list"), QStringLiteral("edit-clear-all")}} },
{ u"edit-clear-locationbar-ltr"_s, { {u"edit-clear-locationbar-ltr"_s}} }, { QStringLiteral("edit-clear-locationbar-ltr"), { {QStringLiteral("edit-clear-locationbar-ltr")}} },
{ u"edit-copy"_s, { {}} }, { QStringLiteral("edit-copy"), { {}} },
{ u"edit-delete"_s, { {}} }, { QStringLiteral("edit-delete"), { {}} },
{ u"edit-find"_s, { {}} }, { QStringLiteral("edit-find"), { {}} },
{ u"edit-redo"_s, { {}} }, { QStringLiteral("edit-redo"), { {}} },
{ u"edit-rename"_s, { {}} }, { QStringLiteral("edit-rename"), { {}} },
{ u"edit-undo"_s, { {}} }, { QStringLiteral("edit-undo"), { {}} },
{ u"electrocompaniet"_s, { {}} }, { QStringLiteral("electrocompaniet"), { {}} },
{ u"equalizer"_s, { {u"view-media-equalizer"_s}} }, { QStringLiteral("equalizer"), { {QStringLiteral("view-media-equalizer")}} },
{ u"folder-new"_s, { {}} }, { QStringLiteral("folder-new"), { {}} },
{ u"folder"_s, { {}} }, { QStringLiteral("folder"), { {}} },
{ u"folder-sound"_s, { {u"folder-music"_s}} }, { QStringLiteral("folder-sound"), { {QStringLiteral("folder-music")}} },
{ u"footsteps"_s, { {u"go-jump"_s}} }, { QStringLiteral("footsteps"), { {QStringLiteral("go-jump")}} },
{ u"go-down"_s, { {}} }, { QStringLiteral("go-down"), { {}} },
{ u"go-home"_s, { {}} }, { QStringLiteral("go-home"), { {}} },
{ u"go-jump"_s, { {}} }, { QStringLiteral("go-jump"), { {}} },
{ u"go-next"_s, { {}} }, { QStringLiteral("go-next"), { {}} },
{ u"go-previous"_s, { {}} }, { QStringLiteral("go-previous"), { {}} },
{ u"go-up"_s, { {}} }, { QStringLiteral("go-up"), { {}} },
{ u"gstreamer"_s, { {u"phonon-gstreamer"_s}} }, { QStringLiteral("gstreamer"), { {QStringLiteral("phonon-gstreamer")}} },
{ u"headset"_s, { {u"audio-headset"_s}} }, { QStringLiteral("headset"), { {QStringLiteral("audio-headset")}} },
{ u"help-hint"_s, { {}} }, { QStringLiteral("help-hint"), { {}} },
{ u"intel"_s, { {}} }, { QStringLiteral("intel"), { {}} },
{ u"jack"_s, { {u"audio-input-line"_s}} }, { QStringLiteral("jack"), { {QStringLiteral("audio-input-line")}} },
{ u"keyboard"_s, { {u"input-keyboard"_s}} }, { QStringLiteral("keyboard"), { {QStringLiteral("input-keyboard")}} },
{ u"list-add"_s, { {}} }, { QStringLiteral("list-add"), { {}} },
{ u"list-remove"_s, { {}} }, { QStringLiteral("list-remove"), { {}} },
{ u"love"_s, { {u"heart"_s, u"emblem-favorite"_s}} }, { QStringLiteral("love"), { {QStringLiteral("heart"), QStringLiteral("emblem-favorite")}} },
{ u"mcintosh-player"_s, { {}} }, { QStringLiteral("mcintosh-player"), { {}} },
{ u"mcintosh"_s, { {}} }, { QStringLiteral("mcintosh"), { {}} },
{ u"mcintosh-text"_s, { {}} }, { QStringLiteral("mcintosh-text"), { {}} },
{ u"media-eject"_s, { {}} }, { QStringLiteral("media-eject"), { {}} },
{ u"media-playback-pause"_s, { {u"media-pause"_s}} }, { QStringLiteral("media-playback-pause"), { {QStringLiteral("media-pause")}} },
{ u"media-playlist-repeat"_s, { {}} }, { QStringLiteral("media-playlist-repeat"), { {}} },
{ u"media-playlist-shuffle"_s, { {""_L1}} }, { QStringLiteral("media-playlist-shuffle"), { {QLatin1String("")}} },
{ u"media-playback-start"_s, { {u"media-play"_s, u"media-playback-playing"_s}} }, { QStringLiteral("media-playback-start"), { {QStringLiteral("media-play"), QStringLiteral("media-playback-playing")}} },
{ u"media-seek-backward"_s, { {}} }, { QStringLiteral("media-seek-backward"), { {}} },
{ u"media-seek-forward"_s, { {}} }, { QStringLiteral("media-seek-forward"), { {}} },
{ u"media-skip-backward"_s, { {}} }, { QStringLiteral("media-skip-backward"), { {}} },
{ u"media-skip-forward"_s, { {}} }, { QStringLiteral("media-skip-forward"), { {}} },
{ u"media-playback-stop"_s, { {u"media-stop"_s}} }, { QStringLiteral("media-playback-stop"), { {QStringLiteral("media-stop")}} },
{ u"moodbar"_s, { {u"preferences-desktop-icons"_s}} }, { QStringLiteral("moodbar"), { {QStringLiteral("preferences-desktop-icons")}} },
{ u"nvidia"_s, { {}} }, { QStringLiteral("nvidia"), { {}} },
{ u"pulseaudio"_s, { {}} }, { QStringLiteral("pulseaudio"), { {}} },
{ u"realtek"_s, { {}} }, { QStringLiteral("realtek"), { {}} },
{ u"scrobble-disabled"_s, { {}} }, { QStringLiteral("scrobble-disabled"), { {}} },
{ u"scrobble"_s, { {u"love"_s}} }, { QStringLiteral("scrobble"), { {QStringLiteral("love")}} },
{ u"search"_s, { {}} }, { QStringLiteral("search"), { {}} },
{ u"soundcard"_s, { {u"audiocard"_s, u"audio-card"_s}} }, { QStringLiteral("soundcard"), { {QStringLiteral("audiocard"), QStringLiteral("audio-card")}} },
{ u"speaker"_s, { {}} }, { QStringLiteral("speaker"), { {}} },
{ u"star-grey"_s, { {}} }, { QStringLiteral("star-grey"), { {}} },
{ u"star"_s, { {}} }, { QStringLiteral("star"), { {}} },
{ u"strawberry"_s, { {}} }, { QStringLiteral("strawberry"), { {}} },
{ u"subsonic"_s, { {}} }, { QStringLiteral("subsonic"), { {}} },
{ u"tidal"_s, { {}} }, { QStringLiteral("tidal"), { {}} },
{ u"tools-wizard"_s, { {}} }, { QStringLiteral("tools-wizard"), { {}} },
{ u"view-choose"_s, { {}} }, { QStringLiteral("view-choose"), { {}} },
{ u"view-fullscreen"_s, { {}} }, { QStringLiteral("view-fullscreen"), { {}} },
{ u"view-media-lyrics"_s, { {}} }, { QStringLiteral("view-media-lyrics"), { {}} },
{ u"view-media-playlist"_s, { {}} }, { QStringLiteral("view-media-playlist"), { {}} },
{ u"view-media-visualization"_s, { {u"preferences-desktop-theme"_s}} }, { QStringLiteral("view-media-visualization"), { {QStringLiteral("preferences-desktop-theme")}} },
{ u"view-refresh"_s, { {}} }, { QStringLiteral("view-refresh"), { {}} },
{ u"library-music"_s, { {u"vinyl"_s}} }, { QStringLiteral("library-music"), { {QStringLiteral("vinyl")}} },
{ u"vlc"_s, { {}} }, { QStringLiteral("vlc"), { {}} },
{ u"zoom-in"_s, { {}} }, { QStringLiteral("zoom-in"), { {}} },
{ u"zoom-out"_s, { {}, 0, 0 } } { QStringLiteral("zoom-out"), { {}, 0, 0 } }
}; };
} // namespace IconMapper } // namespace IconMapper
#endif // ICONMAPPER_H #endif // ICONMAPPER_H

View File

@@ -39,8 +39,6 @@
#include <QDateTime> #include <QDateTime>
#include <QRandomGenerator> #include <QRandomGenerator>
using namespace Qt::StringLiterals;
LocalRedirectServer::LocalRedirectServer(QObject *parent) LocalRedirectServer::LocalRedirectServer(QObject *parent)
: QTcpServer(parent), : QTcpServer(parent),
port_(0), port_(0),
@@ -88,8 +86,8 @@ void LocalRedirectServer::incomingConnection(qintptr socket_descriptor) {
if (!tcp_socket->setSocketDescriptor(socket_descriptor)) { if (!tcp_socket->setSocketDescriptor(socket_descriptor)) {
delete tcp_socket; delete tcp_socket;
close(); close();
error_ = "Unable to set socket descriptor"_L1; error_ = QLatin1String("Unable to set socket descriptor");
Q_EMIT Finished(); emit Finished();
return; return;
} }
socket_ = tcp_socket; socket_ = tcp_socket;
@@ -116,7 +114,7 @@ void LocalRedirectServer::ReadyRead() {
socket_ = nullptr; socket_ = nullptr;
request_url_ = ParseUrlFromRequest(buffer_); request_url_ = ParseUrlFromRequest(buffer_);
close(); close();
Q_EMIT Finished(); emit Finished();
} }
else { else {
QObject::connect(socket_, &QAbstractSocket::readyRead, this, &LocalRedirectServer::ReadyRead); QObject::connect(socket_, &QAbstractSocket::readyRead, this, &LocalRedirectServer::ReadyRead);
@@ -131,9 +129,9 @@ void LocalRedirectServer::WriteTemplate() const {
QString page_data = QString::fromUtf8(page_file.readAll()); QString page_data = QString::fromUtf8(page_file.readAll());
page_file.close(); page_file.close();
static const QRegularExpression tr_regexp(QStringLiteral("tr\\(\"([^\"]+)\"\\)")); QRegularExpression tr_regexp(QStringLiteral("tr\\(\"([^\"]+)\"\\)"));
qint64 offset = 0; qint64 offset = 0;
Q_FOREVER { forever {
QRegularExpressionMatch re_match = tr_regexp.match(page_data, offset); QRegularExpressionMatch re_match = tr_regexp.match(page_data, offset);
if (!re_match.hasMatch()) break; if (!re_match.hasMatch()) break;
offset = re_match.capturedStart(); offset = re_match.capturedStart();
@@ -153,7 +151,7 @@ void LocalRedirectServer::WriteTemplate() const {
.pixmap(16) .pixmap(16)
.toImage() .toImage()
.save(&image_buffer, "PNG"); .save(&image_buffer, "PNG");
page_data.replace("@IMAGE_DATA@"_L1, QString::fromUtf8(image_buffer.data().toBase64())); page_data.replace(QLatin1String("@IMAGE_DATA@"), QString::fromUtf8(image_buffer.data().toBase64()));
image_buffer.close(); image_buffer.close();
} }

View File

@@ -45,10 +45,10 @@ class LocalRedirectServer : public QTcpServer {
const QUrl &request_url() const { return request_url_; } const QUrl &request_url() const { return request_url_; }
const QString &error() const { return error_; } const QString &error() const { return error_; }
Q_SIGNALS: signals:
void Finished(); void Finished();
public Q_SLOTS: public slots:
void NewConnection(); void NewConnection();
void incomingConnection(qintptr socket_descriptor) override; void incomingConnection(qintptr socket_descriptor) override;
void Encrypted(); void Encrypted();

View File

@@ -44,10 +44,10 @@ class MacFSListener : public FileSystemWatcherInterface {
void RemovePath(const QString &path); void RemovePath(const QString &path);
void Clear(); void Clear();
Q_SIGNALS: signals:
void PathChanged(const QString &path); void PathChanged(const QString &path);
private Q_SLOTS: private slots:
void UpdateStream(); void UpdateStream();
private: private:

View File

@@ -32,13 +32,11 @@
#include "core/logging.h" #include "core/logging.h"
#include "scoped_nsobject.h" #include "scoped_nsobject.h"
using namespace Qt::Literals::StringLiterals;
MacFSListener::MacFSListener(QObject *parent) MacFSListener::MacFSListener(QObject *parent)
: FileSystemWatcherInterface(parent), : FileSystemWatcherInterface(parent),
run_loop_(nullptr), run_loop_(nullptr),
stream_(nullptr), stream_(nullptr),
update_timer_(new QTimer(this)) { update_timer_(new QTimer(this)) {
update_timer_->setSingleShot(true); update_timer_->setSingleShot(true);
update_timer_->setInterval(2000); update_timer_->setInterval(2000);
@@ -59,10 +57,10 @@ void MacFSListener::EventStreamCallback(ConstFSEventStreamRef stream, void *user
for (size_t i = 0; i < num_events; ++i) { for (size_t i = 0; i < num_events; ++i) {
QString path = QString::fromUtf8(paths[i]); QString path = QString::fromUtf8(paths[i]);
qLog(Debug) << "Something changed at:" << path; qLog(Debug) << "Something changed at:" << path;
while (path.endsWith(u'/')) { while (path.endsWith(QLatin1Char('/'))) {
path.chop(1); path.chop(1);
} }
Q_EMIT me->PathChanged(path); emit me->PathChanged(path);
} }
} }

View File

@@ -71,10 +71,10 @@ class SystemTrayIcon : public QObject {
QPixmap CreateIcon(const QPixmap &icon, const QPixmap &grey_icon); QPixmap CreateIcon(const QPixmap &icon, const QPixmap &grey_icon);
void UpdateIcon(); void UpdateIcon();
private Q_SLOTS: private slots:
void ActionChanged(); void ActionChanged();
Q_SIGNALS: signals:
void ChangeVolume(const int delta); void ChangeVolume(const int delta);
void SeekForward(); void SeekForward();
void SeekBackward(); void SeekBackward();

View File

@@ -23,9 +23,8 @@
#include "version.h" #include "version.h"
#include <cmath> #include <cmath>
#include <algorithm>
#include <utility>
#include <functional> #include <functional>
#include <algorithm>
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@@ -217,13 +216,16 @@
#endif #endif
#ifdef HAVE_QTSPARKLE #ifdef HAVE_QTSPARKLE
# include <qtsparkle-qt6/Updater> # if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
# include <qtsparkle-qt6/Updater>
# else
# include <qtsparkle-qt5/Updater>
# endif
#endif // HAVE_QTSPARKLE #endif // HAVE_QTSPARKLE
using std::make_unique; using std::make_unique;
using std::make_shared; using std::make_shared;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace Qt::StringLiterals;
const char *MainWindow::kSettingsGroup = "MainWindow"; const char *MainWindow::kSettingsGroup = "MainWindow";
const char *MainWindow::kAllFilesFilterSpec = QT_TR_NOOP("All Files (*)"); const char *MainWindow::kAllFilesFilterSpec = QT_TR_NOOP("All Files (*)");
@@ -397,7 +399,7 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
ui_->tabs->AddTab(tidal_view_, QStringLiteral("tidal"), IconLoader::Load(QStringLiteral("tidal"), true, 0, 32), tr("Tidal")); ui_->tabs->AddTab(tidal_view_, QStringLiteral("tidal"), IconLoader::Load(QStringLiteral("tidal"), true, 0, 32), tr("Tidal"));
#endif #endif
#ifdef HAVE_SPOTIFY #ifdef HAVE_SPOTIFY
ui_->tabs->AddTab(spotify_view_, QStringLiteral("spotify"), IconLoader::Load(QStringLiteral("spotify"), true, 0, 32), tr("Spotify")); ui_->tabs->AddTab(spotify_view_, QLatin1String("spotify"), IconLoader::Load(QStringLiteral("spotify"), true, 0, 32), tr("Spotify"));
#endif #endif
#ifdef HAVE_QOBUZ #ifdef HAVE_QOBUZ
ui_->tabs->AddTab(qobuz_view_, QStringLiteral("qobuz"), IconLoader::Load(QStringLiteral("qobuz"), true, 0, 32), tr("Qobuz")); ui_->tabs->AddTab(qobuz_view_, QStringLiteral("qobuz"), IconLoader::Load(QStringLiteral("qobuz"), true, 0, 32), tr("Qobuz"));
@@ -487,7 +489,7 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
ui_->action_transcoder->setIcon(IconLoader::Load(QStringLiteral("tools-wizard"))); ui_->action_transcoder->setIcon(IconLoader::Load(QStringLiteral("tools-wizard")));
ui_->action_update_collection->setIcon(IconLoader::Load(QStringLiteral("view-refresh"))); ui_->action_update_collection->setIcon(IconLoader::Load(QStringLiteral("view-refresh")));
ui_->action_full_collection_scan->setIcon(IconLoader::Load(QStringLiteral("view-refresh"))); ui_->action_full_collection_scan->setIcon(IconLoader::Load(QStringLiteral("view-refresh")));
ui_->action_stop_collection_scan->setIcon(IconLoader::Load(QStringLiteral("dialog-error"))); ui_->action_abort_collection_scan->setIcon(IconLoader::Load(QStringLiteral("dialog-error")));
ui_->action_settings->setIcon(IconLoader::Load(QStringLiteral("configure"))); ui_->action_settings->setIcon(IconLoader::Load(QStringLiteral("configure")));
ui_->action_import_data_from_last_fm->setIcon(IconLoader::Load(QStringLiteral("scrobble"))); ui_->action_import_data_from_last_fm->setIcon(IconLoader::Load(QStringLiteral("scrobble")));
ui_->action_console->setIcon(IconLoader::Load(QStringLiteral("keyboard"))); ui_->action_console->setIcon(IconLoader::Load(QStringLiteral("keyboard")));
@@ -553,7 +555,7 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
QObject::connect(ui_->action_jump, &QAction::triggered, ui_->playlist->view(), &PlaylistView::JumpToCurrentlyPlayingTrack); QObject::connect(ui_->action_jump, &QAction::triggered, ui_->playlist->view(), &PlaylistView::JumpToCurrentlyPlayingTrack);
QObject::connect(ui_->action_update_collection, &QAction::triggered, &*app_->collection(), &SCollection::IncrementalScan); QObject::connect(ui_->action_update_collection, &QAction::triggered, &*app_->collection(), &SCollection::IncrementalScan);
QObject::connect(ui_->action_full_collection_scan, &QAction::triggered, &*app_->collection(), &SCollection::FullScan); QObject::connect(ui_->action_full_collection_scan, &QAction::triggered, &*app_->collection(), &SCollection::FullScan);
QObject::connect(ui_->action_stop_collection_scan, &QAction::triggered, &*app_->collection(), &SCollection::StopScan); QObject::connect(ui_->action_abort_collection_scan, &QAction::triggered, &*app_->collection(), &SCollection::AbortScan);
#if defined(HAVE_GSTREAMER) #if defined(HAVE_GSTREAMER)
QObject::connect(ui_->action_add_files_to_transcoder, &QAction::triggered, this, &MainWindow::AddFilesToTranscoder); QObject::connect(ui_->action_add_files_to_transcoder, &QAction::triggered, this, &MainWindow::AddFilesToTranscoder);
ui_->action_add_files_to_transcoder->setIcon(IconLoader::Load(QStringLiteral("tools-wizard"))); ui_->action_add_files_to_transcoder->setIcon(IconLoader::Load(QStringLiteral("tools-wizard")));
@@ -619,7 +621,6 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
QObject::connect(&*app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValue); QObject::connect(&*app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValue);
QObject::connect(&*app_->player(), &Player::ForceShowOSD, this, &MainWindow::ForceShowOSD); QObject::connect(&*app_->player(), &Player::ForceShowOSD, this, &MainWindow::ForceShowOSD);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::AllPlaylistsLoaded, &*app->player(), &Player::PlaylistsLoaded);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &MainWindow::SongChanged); QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &MainWindow::SongChanged);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*app_->player(), &Player::CurrentMetadataChanged); QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, &*app_->player(), &Player::CurrentMetadataChanged);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::EditingFinished, this, &MainWindow::PlaylistEditFinished); QObject::connect(&*app_->playlist_manager(), &PlaylistManager::EditingFinished, this, &MainWindow::PlaylistEditFinished);
@@ -830,7 +831,6 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::StopAfter, ui_->action_stop_after_this_track, &QAction::trigger); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::StopAfter, ui_->action_stop_after_this_track, &QAction::trigger);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Next, ui_->action_next_track, &QAction::trigger); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Next, ui_->action_next_track, &QAction::trigger);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Previous, ui_->action_previous_track, &QAction::trigger); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Previous, ui_->action_previous_track, &QAction::trigger);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::RestartOrPrevious, &*app_->player(), &Player::RestartOrPrevious);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::IncVolume, &*app_->player(), &Player::VolumeUp); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::IncVolume, &*app_->player(), &Player::VolumeUp);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::DecVolume, &*app_->player(), &Player::VolumeDown); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::DecVolume, &*app_->player(), &Player::VolumeDown);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Mute, &*app_->player(), &Player::Mute); QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Mute, &*app_->player(), &Player::Mute);
@@ -1023,6 +1023,9 @@ MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OS
CommandlineOptionsReceived(options); CommandlineOptionsReceived(options);
if (!options.contains_play_options()) {
LoadPlaybackStatus();
}
if (app_->scrobbler()->enabled() && !app_->scrobbler()->offline()) { if (app_->scrobbler()->enabled() && !app_->scrobbler()->offline()) {
app_->scrobbler()->Submit(); app_->scrobbler()->Submit();
} }
@@ -1270,15 +1273,15 @@ void MainWindow::ReloadAllSettings() {
void MainWindow::RefreshStyleSheet() { void MainWindow::RefreshStyleSheet() {
QString contents(styleSheet()); QString contents(styleSheet());
setStyleSheet(""_L1); setStyleSheet(QLatin1String(""));
setStyleSheet(contents); setStyleSheet(contents);
} }
void MainWindow::SaveSettings() { void MainWindow::SaveSettings() {
SaveGeometry(); SaveGeometry();
SavePlaybackStatus();
app_->player()->SaveVolume(); app_->player()->SaveVolume();
app_->player()->SavePlaybackStatus();
ui_->tabs->SaveSettings(QLatin1String(kSettingsGroup)); ui_->tabs->SaveSettings(QLatin1String(kSettingsGroup));
ui_->playlist->view()->SaveSettings(); ui_->playlist->view()->SaveSettings();
app_->scrobbler()->WriteCache(); app_->scrobbler()->WriteCache();
@@ -1304,7 +1307,7 @@ void MainWindow::Exit() {
else { else {
if (app_->player()->engine()->is_fadeout_enabled()) { if (app_->player()->engine()->is_fadeout_enabled()) {
// To shut down the application when fadeout will be finished // To shut down the application when fadeout will be finished
QObject::connect(&*app_->player()->engine(), &EngineBase::Finished, this, &MainWindow::DoExit); QObject::connect(&*app_->player()->engine(), &EngineBase::FadeoutFinishedSignal, this, &MainWindow::DoExit);
if (app_->player()->GetState() == EngineBase::State::Playing) { if (app_->player()->GetState() == EngineBase::State::Playing) {
app_->player()->Stop(); app_->player()->Stop();
ignore_close_ = true; ignore_close_ = true;
@@ -1368,12 +1371,8 @@ void MainWindow::MediaStopped() {
ui_->button_love->setEnabled(false); ui_->button_love->setEnabled(false);
tray_icon_->LoveStateChanged(false); tray_icon_->LoveStateChanged(false);
if (track_position_timer_->isActive()) { track_position_timer_->stop();
track_position_timer_->stop(); track_slider_timer_->stop();
}
if (track_slider_timer_->isActive()) {
track_slider_timer_->stop();
}
ui_->track_slider->SetStopped(); ui_->track_slider->SetStopped();
tray_icon_->SetProgress(0); tray_icon_->SetProgress(0);
tray_icon_->SetStopped(); tray_icon_->SetStopped();
@@ -1401,12 +1400,8 @@ void MainWindow::MediaPaused() {
ui_->action_play_pause->setEnabled(true); ui_->action_play_pause->setEnabled(true);
if (!track_position_timer_->isActive()) { track_position_timer_->stop();
track_position_timer_->start(); track_slider_timer_->stop();
}
if (!track_slider_timer_->isActive()) {
track_slider_timer_->start();
}
tray_icon_->SetPaused(); tray_icon_->SetPaused();
@@ -1431,13 +1426,8 @@ void MainWindow::MediaPlaying() {
ui_->track_slider->SetCanSeek(can_seek); ui_->track_slider->SetCanSeek(can_seek);
tray_icon_->SetPlaying(enable_play_pause); tray_icon_->SetPlaying(enable_play_pause);
if (!track_position_timer_->isActive()) { track_position_timer_->start();
track_position_timer_->start(); track_slider_timer_->start();
}
if (!track_slider_timer_->isActive()) {
track_slider_timer_->start();
}
UpdateTrackPosition(); UpdateTrackPosition();
} }
@@ -1545,6 +1535,80 @@ void MainWindow::SaveGeometry() {
} }
void MainWindow::SavePlaybackStatus() {
Settings s;
s.beginGroup(Player::kSettingsGroup);
s.setValue("playback_state", static_cast<int>(app_->player()->GetState()));
if (app_->player()->GetState() == EngineBase::State::Playing || app_->player()->GetState() == EngineBase::State::Paused) {
s.setValue("playback_playlist", app_->playlist_manager()->active()->id());
s.setValue("playback_position", app_->player()->engine()->position_nanosec() / kNsecPerSec);
}
else {
s.setValue("playback_playlist", -1);
s.setValue("playback_position", 0);
}
s.endGroup();
}
void MainWindow::LoadPlaybackStatus() {
Settings s;
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
const bool resume_playback = s.value("resumeplayback", false).toBool();
s.endGroup();
s.beginGroup(Player::kSettingsGroup);
const EngineBase::State playback_state = static_cast<EngineBase::State>(s.value("playback_state", static_cast<int>(EngineBase::State::Empty)).toInt());
s.endGroup();
if (resume_playback && playback_state != EngineBase::State::Empty && playback_state != EngineBase::State::Idle) {
SharedPtr<QMetaObject::Connection> connection = make_shared<QMetaObject::Connection>();
*connection = QObject::connect(&*app_->playlist_manager(), &PlaylistManager::AllPlaylistsLoaded, this, [this, connection]() {
QObject::disconnect(*connection);
QTimer::singleShot(400ms, this, &MainWindow::ResumePlayback);
});
}
}
void MainWindow::ResumePlayback() {
qLog(Debug) << "Resuming playback";
Settings s;
s.beginGroup(Player::kSettingsGroup);
const EngineBase::State playback_state = static_cast<EngineBase::State>(s.value("playback_state", static_cast<int>(EngineBase::State::Empty)).toInt());
int playback_playlist = s.value("playback_playlist", -1).toInt();
int playback_position = s.value("playback_position", 0).toInt();
s.endGroup();
if (playback_playlist == app_->playlist_manager()->current()->id()) {
// Set active to current to resume playback on correct playlist.
app_->playlist_manager()->SetActiveToCurrent();
if (playback_state == EngineBase::State::Paused) {
SharedPtr<QMetaObject::Connection> connection = make_shared<QMetaObject::Connection>();
*connection = QObject::connect(&*app_->player(), &Player::Playing, &*app_->player(), [this, connection]() {
QObject::disconnect(*connection);
QTimer::singleShot(300, &*app_->player(), &Player::PlayPauseHelper);
});
}
app_->player()->Play(playback_position * kNsecPerSec);
}
// Reset saved playback status so we don't resume again from the same position.
s.beginGroup(Player::kSettingsGroup);
s.setValue("playback_state", static_cast<int>(EngineBase::State::Empty));
s.setValue("playback_playlist", -1);
s.setValue("playback_position", 0);
s.endGroup();
}
void MainWindow::PlayIndex(const QModelIndex &idx, Playlist::AutoScroll autoscroll) { void MainWindow::PlayIndex(const QModelIndex &idx, Playlist::AutoScroll autoscroll) {
if (!idx.isValid()) return; if (!idx.isValid()) return;
@@ -1556,7 +1620,7 @@ void MainWindow::PlayIndex(const QModelIndex &idx, Playlist::AutoScroll autoscro
} }
app_->playlist_manager()->SetActiveToCurrent(); app_->playlist_manager()->SetActiveToCurrent();
app_->player()->PlayAt(row, false, 0, EngineBase::TrackChangeType::Manual, autoscroll, true); app_->player()->PlayAt(row, 0, EngineBase::TrackChangeType::Manual, autoscroll, true);
} }
@@ -1573,14 +1637,14 @@ void MainWindow::PlaylistDoubleClick(const QModelIndex &idx) {
switch (doubleclick_playlist_addmode_) { switch (doubleclick_playlist_addmode_) {
case BehaviourSettingsPage::PlaylistAddBehaviour::Play: case BehaviourSettingsPage::PlaylistAddBehaviour::Play:
app_->playlist_manager()->SetActiveToCurrent(); app_->playlist_manager()->SetActiveToCurrent();
app_->player()->PlayAt(source_idx.row(), false, 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Never, true, true); app_->player()->PlayAt(source_idx.row(), 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Never, true, true);
break; break;
case BehaviourSettingsPage::PlaylistAddBehaviour::Enqueue: case BehaviourSettingsPage::PlaylistAddBehaviour::Enqueue:
app_->playlist_manager()->current()->queue()->ToggleTracks(QModelIndexList() << source_idx); app_->playlist_manager()->current()->queue()->ToggleTracks(QModelIndexList() << source_idx);
if (app_->player()->GetState() != EngineBase::State::Playing) { if (app_->player()->GetState() != EngineBase::State::Playing) {
app_->playlist_manager()->SetActiveToCurrent(); app_->playlist_manager()->SetActiveToCurrent();
app_->player()->PlayAt(app_->playlist_manager()->current()->queue()->TakeNext(), false, 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Never, true); app_->player()->PlayAt(app_->playlist_manager()->current()->queue()->TakeNext(), 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Never, true);
} }
break; break;
} }
@@ -1622,7 +1686,7 @@ void MainWindow::ToggleHide() {
void MainWindow::StopAfterCurrent() { void MainWindow::StopAfterCurrent() {
app_->playlist_manager()->current()->StopAfter(app_->playlist_manager()->current()->current_row()); app_->playlist_manager()->current()->StopAfter(app_->playlist_manager()->current()->current_row());
Q_EMIT StopAfterToggled(app_->playlist_manager()->active()->stop_after_current()); emit StopAfterToggled(app_->playlist_manager()->active()->stop_after_current());
} }
void MainWindow::showEvent(QShowEvent *e) { void MainWindow::showEvent(QShowEvent *e) {
@@ -1832,8 +1896,7 @@ void MainWindow::AddToPlaylistFromAction(QAction *action) {
SongList songs; SongList songs;
// Get the selected playlist items // Get the selected playlist items
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -1900,7 +1963,7 @@ void MainWindow::PlaylistRightClick(const QPoint global_pos, const QModelIndex &
playlist_stop_after_->setEnabled(source_index.isValid()); playlist_stop_after_->setEnabled(source_index.isValid());
// Are any of the selected songs editable or queued? // Are any of the selected songs editable or queued?
const QModelIndexList selection = ui_->playlist->view()->selectionModel()->selectedRows(); QModelIndexList selection = ui_->playlist->view()->selectionModel()->selectedRows();
bool cue_selected = false; bool cue_selected = false;
qint64 selected = ui_->playlist->view()->selectionModel()->selectedRows().count(); qint64 selected = ui_->playlist->view()->selectionModel()->selectedRows().count();
int editable = 0; int editable = 0;
@@ -2042,10 +2105,12 @@ void MainWindow::PlaylistRightClick(const QPoint global_pos, const QModelIndex &
playlist_copy_to_device_->setVisible(local_songs > 0); playlist_copy_to_device_->setVisible(local_songs > 0);
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
playlist_delete_->setVisible(delete_files_ && local_songs > 0); playlist_delete_->setVisible(delete_files_ && local_songs > 0);
#endif
// Remove old item actions, if any. // Remove old item actions, if any.
for (QAction *action : std::as_const(playlistitem_actions_)) { for (QAction *action : playlistitem_actions_) {
playlist_menu_->removeAction(action); playlist_menu_->removeAction(action);
} }
@@ -2055,7 +2120,7 @@ void MainWindow::PlaylistRightClick(const QPoint global_pos, const QModelIndex &
playlist_menu_->insertActions(playlistitem_actions_separator_, playlistitem_actions_); playlist_menu_->insertActions(playlistitem_actions_separator_, playlistitem_actions_);
} }
// If it isn't the first time we right click, we need to remove the menu previously created //if it isn't the first time we right click, we need to remove the menu previously created
if (playlist_add_to_another_ != nullptr) { if (playlist_add_to_another_ != nullptr) {
playlist_menu_->removeAction(playlist_add_to_another_); playlist_menu_->removeAction(playlist_add_to_another_);
delete playlist_add_to_another_; delete playlist_add_to_another_;
@@ -2067,19 +2132,18 @@ void MainWindow::PlaylistRightClick(const QPoint global_pos, const QModelIndex &
QMenu *add_to_another_menu = new QMenu(tr("Add to another playlist"), this); QMenu *add_to_another_menu = new QMenu(tr("Add to another playlist"), this);
add_to_another_menu->setIcon(IconLoader::Load(QStringLiteral("list-add"))); add_to_another_menu->setIcon(IconLoader::Load(QStringLiteral("list-add")));
const QList<int> playlist_ids = app_->playlist_manager()->playlist_ids(); for (const PlaylistBackend::Playlist &playlist : app_->playlist_backend()->GetAllOpenPlaylists()) {
for (const int playlist_id : playlist_ids) { // don't add the current playlist
// Don't add the current playlist if (playlist.id != app_->playlist_manager()->current()->id()) {
if (playlist_id != app_->playlist_manager()->current()->id()) {
QAction *existing_playlist = new QAction(this); QAction *existing_playlist = new QAction(this);
existing_playlist->setText(app_->playlist_manager()->playlist_name(playlist_id)); existing_playlist->setText(playlist.name);
existing_playlist->setData(playlist_id); existing_playlist->setData(playlist.id);
add_to_another_menu->addAction(existing_playlist); add_to_another_menu->addAction(existing_playlist);
} }
} }
add_to_another_menu->addSeparator(); add_to_another_menu->addSeparator();
// Add to a new playlist // add to a new playlist
QAction *new_playlist = new QAction(this); QAction *new_playlist = new QAction(this);
new_playlist->setText(tr("New playlist")); new_playlist->setText(tr("New playlist"));
new_playlist->setData(-1); // fake id new_playlist->setData(-1); // fake id
@@ -2113,8 +2177,7 @@ void MainWindow::RescanSongs() {
SongList songs; SongList songs;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row())); PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row()));
@@ -2139,8 +2202,7 @@ void MainWindow::EditTracks() {
SongList songs; SongList songs;
PlaylistItemPtrList items; PlaylistItemPtrList items;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row())); PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row()));
@@ -2162,8 +2224,7 @@ void MainWindow::EditTracks() {
void MainWindow::EditTagDialogAccepted() { void MainWindow::EditTagDialogAccepted() {
const PlaylistItemPtrList items = edit_tag_dialog_->playlist_items(); for (PlaylistItemPtr item : edit_tag_dialog_->playlist_items()) {
for (PlaylistItemPtr item : items) {
item->Reload(); item->Reload();
} }
@@ -2182,13 +2243,13 @@ void MainWindow::RenumberTracks() {
// Get the index list in order // Get the index list in order
std::stable_sort(indexes.begin(), indexes.end()); std::stable_sort(indexes.begin(), indexes.end());
// If first selected song has a track number set, start from that offset // if first selected song has a track number set, start from that offset
if (!indexes.isEmpty()) { if (!indexes.isEmpty()) {
const Song first_song = app_->playlist_manager()->current()->item_at(indexes[0].row())->OriginalMetadata(); const Song first_song = app_->playlist_manager()->current()->item_at(indexes[0].row())->OriginalMetadata();
if (first_song.track() > 0) track = first_song.track(); if (first_song.track() > 0) track = first_song.track();
} }
for (const QModelIndex &proxy_index : std::as_const(indexes)) { for (const QModelIndex &proxy_index : indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2219,8 +2280,7 @@ void MainWindow::SelectionSetValue() {
Playlist::Column column = static_cast<Playlist::Column>(playlist_menu_index_.column()); Playlist::Column column = static_cast<Playlist::Column>(playlist_menu_index_.column());
QVariant column_value = app_->playlist_manager()->current()->data(playlist_menu_index_); QVariant column_value = app_->playlist_manager()->current()->data(playlist_menu_index_);
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2267,7 +2327,7 @@ void MainWindow::AddFile() {
PlaylistParser parser(app_->collection_backend()); PlaylistParser parser(app_->collection_backend());
// Show dialog // Show dialog
const QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Add file"), directory, QStringLiteral("%1 (%2);;%3;;%4").arg(tr("Music"), QLatin1String(FileView::kFileFilter), parser.filters(PlaylistParser::Type::Load), tr(kAllFilesFilterSpec))); QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Add file"), directory, QStringLiteral("%1 (%2);;%3;;%4").arg(tr("Music"), QLatin1String(FileView::kFileFilter), parser.filters(PlaylistParser::Type::Load), tr(kAllFilesFilterSpec)));
if (filenames.isEmpty()) return; if (filenames.isEmpty()) return;
@@ -2334,8 +2394,7 @@ void MainWindow::ShowInCollection() {
// Show the first valid selected track artist/album in CollectionView // Show the first valid selected track artist/album in CollectionView
SongList songs; SongList songs;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2346,7 +2405,7 @@ void MainWindow::ShowInCollection() {
} }
QString search; QString search;
if (!songs.isEmpty()) { if (!songs.isEmpty()) {
search = "artist:"_L1 + songs.first().artist() + " album:"_L1 + songs.first().album(); search = QLatin1String("artist:") + songs.first().artist() + QLatin1String(" album:") + songs.first().album();
} }
collection_view_->filter_widget()->ShowInCollection(search); collection_view_->filter_widget()->ShowInCollection(search);
@@ -2439,9 +2498,9 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
break; break;
case CommandlineOptions::PlayerAction::ResizeWindow:{ case CommandlineOptions::PlayerAction::ResizeWindow:{
if (options.window_size().contains(u'x') && options.window_size().length() >= 4) { if (options.window_size().contains(QLatin1Char('x')) && options.window_size().length() >= 4) {
QString str_w = options.window_size().left(options.window_size().indexOf(u'x')); QString str_w = options.window_size().left(options.window_size().indexOf(QLatin1Char('x')));
QString str_h = options.window_size().right(options.window_size().length() - options.window_size().indexOf(u'x') - 1); QString str_h = options.window_size().right(options.window_size().length() - options.window_size().indexOf(QLatin1Char('x')) - 1);
bool w_ok = false; bool w_ok = false;
bool h_ok = false; bool h_ok = false;
int w = str_w.toInt(&w_ok); int w = str_w.toInt(&w_ok);
@@ -2479,10 +2538,9 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
if (!options.urls().empty()) { if (!options.urls().empty()) {
#ifdef HAVE_TIDAL #ifdef HAVE_TIDAL
const QList<QUrl> urls = options.urls(); for (const QUrl &url : options.urls()) {
for (const QUrl &url : urls) { if (url.scheme() == QLatin1String("tidal") && url.host() == QLatin1String("login")) {
if (url.scheme() == "tidal"_L1 && url.host() == "login"_L1) { emit AuthorizationUrlReceived(url);
Q_EMIT AuthorizationUrlReceived(url);
return; return;
} }
} }
@@ -2527,7 +2585,7 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions &options) {
app_->player()->SeekTo(app_->player()->engine()->position_nanosec() / kNsecPerSec + options.seek_by()); app_->player()->SeekTo(app_->player()->engine()->position_nanosec() / kNsecPerSec + options.seek_by());
} }
if (options.play_track_at() != -1) app_->player()->PlayAt(options.play_track_at(), false, 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Maybe, true); if (options.play_track_at() != -1) app_->player()->PlayAt(options.play_track_at(), 0, EngineBase::TrackChangeType::Manual, Playlist::AutoScroll::Maybe, true);
if (options.show_osd()) app_->player()->ShowOSD(); if (options.show_osd()) app_->player()->ShowOSD();
@@ -2559,8 +2617,8 @@ bool MainWindow::LoadUrl(const QString &url) {
return true; return true;
} }
#ifdef HAVE_TIDAL #ifdef HAVE_TIDAL
if (url.startsWith("tidal://login"_L1)) { if (url.startsWith(QLatin1String("tidal://login"))) {
Q_EMIT AuthorizationUrlReceived(QUrl(url)); emit AuthorizationUrlReceived(QUrl(url));
return true; return true;
} }
#endif #endif
@@ -2583,8 +2641,7 @@ void MainWindow::AddFilesToTranscoder() {
QStringList filenames; QStringList filenames;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row())); PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row()));
@@ -2696,8 +2753,7 @@ void MainWindow::PlaylistMoveToCollection() {
void MainWindow::PlaylistOrganizeSelected(const bool copy) { void MainWindow::PlaylistOrganizeSelected(const bool copy) {
SongList songs; SongList songs;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2719,8 +2775,7 @@ void MainWindow::PlaylistOrganizeSelected(const bool copy) {
void MainWindow::PlaylistOpenInBrowser() { void MainWindow::PlaylistOpenInBrowser() {
QList<QUrl> urls; QList<QUrl> urls;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
urls << QUrl(source_index.sibling(source_index.row(), static_cast<int>(Playlist::Column::Filename)).data().toString()); urls << QUrl(source_index.sibling(source_index.row(), static_cast<int>(Playlist::Column::Filename)).data().toString());
@@ -2733,8 +2788,7 @@ void MainWindow::PlaylistOpenInBrowser() {
void MainWindow::PlaylistCopyUrl() { void MainWindow::PlaylistCopyUrl() {
QList<QUrl> urls; QList<QUrl> urls;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2765,7 +2819,7 @@ void MainWindow::PlaylistQueue() {
void MainWindow::PlaylistQueuePlayNext() { void MainWindow::PlaylistQueuePlayNext() {
const QModelIndexList selected_rows = ui_->playlist->view()->selectionModel()->selectedRows(); QModelIndexList selected_rows = ui_->playlist->view()->selectionModel()->selectedRows();
QModelIndexList indexes; QModelIndexList indexes;
indexes.reserve(selected_rows.count()); indexes.reserve(selected_rows.count());
for (const QModelIndex &proxy_index : selected_rows) { for (const QModelIndex &proxy_index : selected_rows) {
@@ -2795,8 +2849,7 @@ void MainWindow::PlaylistCopyToDevice() {
SongList songs; SongList songs;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_index.row());
@@ -2911,7 +2964,7 @@ void MainWindow::CheckFullRescanRevisions() {
int from = app_->database()->startup_schema_version(); int from = app_->database()->startup_schema_version();
int to = app_->database()->current_schema_version(); int to = app_->database()->current_schema_version();
// If we're restoring DB from scratch or nothing has changed, do nothing // if we're restoring DB from scratch or nothing has changed, do nothing
if (from == 0 || from == to) { if (from == 0 || from == to) {
return; return;
} }
@@ -2925,13 +2978,13 @@ void MainWindow::CheckFullRescanRevisions() {
} }
} }
// If we have any... // if we have any...
if (!reasons.isEmpty()) { if (!reasons.isEmpty()) {
QString message = tr("The version of Strawberry you've just updated to requires a full collection rescan because of the new features listed below:") + QStringLiteral("<ul>"); QString message = tr("The version of Strawberry you've just updated to requires a full collection rescan because of the new features listed below:") + QStringLiteral("<ul>");
for (const QString &reason : reasons) { for (const QString &reason : reasons) {
message += "<li>"_L1 + reason + "</li>"_L1; message += QLatin1String("<li>") + reason + QLatin1String("</li>");
} }
message += "</ul>"_L1 + tr("Would you like to run a full rescan right now?"); message += QLatin1String("</ul>") + tr("Would you like to run a full rescan right now?");
if (QMessageBox::question(this, tr("Collection rescan notice"), message, QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { if (QMessageBox::question(this, tr("Collection rescan notice"), message, QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
app_->collection()->FullScan(); app_->collection()->FullScan();
} }
@@ -2962,7 +3015,11 @@ void MainWindow::Raise() {
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) { bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) {
# else
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) {
# endif
if (exit_count_ == 0 && message) { if (exit_count_ == 0 && message) {
MSG *msg = static_cast<MSG*>(message); MSG *msg = static_cast<MSG*>(message);
@@ -2993,8 +3050,7 @@ void MainWindow::AutoCompleteTags() {
// Get the selected songs and start fetching tags for them // Get the selected songs and start fetching tags for them
SongList songs; SongList songs;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_index : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_index : proxy_indexes) {
const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index); const QModelIndex source_index = app_->playlist_manager()->current()->filter()->mapToSource(proxy_index);
if (!source_index.isValid()) continue; if (!source_index.isValid()) continue;
PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row())); PlaylistItemPtr item(app_->playlist_manager()->current()->item_at(source_index.row()));
@@ -3019,7 +3075,7 @@ void MainWindow::AutoCompleteTags() {
void MainWindow::AutoCompleteTagsAccepted() { void MainWindow::AutoCompleteTagsAccepted() {
for (PlaylistItemPtr item : std::as_const(autocomplete_tag_items_)) { for (PlaylistItemPtr item : autocomplete_tag_items_) {
item->Reload(); item->Reload();
} }
autocomplete_tag_items_.clear(); autocomplete_tag_items_.clear();
@@ -3124,7 +3180,7 @@ void MainWindow::AlbumCoverLoaded(const Song &song, const AlbumCoverLoaderResult
song_ = song; song_ = song;
album_cover_ = result.album_cover; album_cover_ = result.album_cover;
Q_EMIT AlbumCoverReady(song, result.album_cover.image); emit AlbumCoverReady(song, result.album_cover.image);
const bool enable_change_art = song.is_collection_song() && !song.effective_albumartist().isEmpty() && !song.album().isEmpty(); const bool enable_change_art = song.is_collection_song() && !song.effective_albumartist().isEmpty() && !song.album().isEmpty();
album_cover_choice_controller_->show_cover_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::Unset); album_cover_choice_controller_->show_cover_action()->setEnabled(result.success && result.type != AlbumCoverLoaderResult::Type::Unset);
@@ -3152,7 +3208,7 @@ void MainWindow::GetCoverAutomatically() {
!song_.effective_album().isEmpty(); !song_.effective_album().isEmpty();
if (search) { if (search) {
Q_EMIT SearchCoverInProgress(); emit SearchCoverInProgress();
album_cover_choice_controller_->SearchCoverAutomatically(song_); album_cover_choice_controller_->SearchCoverAutomatically(song_);
} }
@@ -3211,8 +3267,7 @@ void MainWindow::PlaylistDelete() {
SongList selected_songs; SongList selected_songs;
QStringList files; QStringList files;
bool is_current_item = false; bool is_current_item = false;
const QModelIndexList proxy_indexes = ui_->playlist->view()->selectionModel()->selectedRows(); for (const QModelIndex &proxy_idx : ui_->playlist->view()->selectionModel()->selectedRows()) {
for (const QModelIndex &proxy_idx : proxy_indexes) {
QModelIndex source_idx = app_->playlist_manager()->current()->filter()->mapToSource(proxy_idx); QModelIndex source_idx = app_->playlist_manager()->current()->filter()->mapToSource(proxy_idx);
PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_idx.row()); PlaylistItemPtr item = app_->playlist_manager()->current()->item_at(source_idx.row());
if (!item || !item->Metadata().url().isLocalFile()) continue; if (!item || !item->Metadata().url().isLocalFile()) continue;

View File

@@ -120,14 +120,18 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void closeEvent(QCloseEvent *e) override; void closeEvent(QCloseEvent *e) override;
void keyPressEvent(QKeyEvent *e) override; void keyPressEvent(QKeyEvent *e) override;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
# else
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
# endif
#endif #endif
// PlatformInterface // PlatformInterface
void Activate() override; void Activate() override;
bool LoadUrl(const QString &url) override; bool LoadUrl(const QString &url) override;
Q_SIGNALS: signals:
void AlbumCoverReady(const Song &song, const QImage &image); void AlbumCoverReady(const Song &song, const QImage &image);
void SearchCoverInProgress(); void SearchCoverInProgress();
// Signals that stop playing after track was toggled. // Signals that stop playing after track was toggled.
@@ -135,7 +139,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void AuthorizationUrlReceived(const QUrl &url); void AuthorizationUrlReceived(const QUrl &url);
private Q_SLOTS: private slots:
void FilePathChanged(const QString &path); void FilePathChanged(const QString &path);
void EngineChanged(const EngineBase::Type enginetype); void EngineChanged(const EngineBase::Type enginetype);
@@ -234,6 +238,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void ToggleSidebar(const bool checked); void ToggleSidebar(const bool checked);
void ToggleSearchCoverAuto(const bool checked); void ToggleSearchCoverAuto(const bool checked);
void SaveGeometry(); void SaveGeometry();
void SavePlaybackStatus();
void LoadPlaybackStatus();
void ResumePlayback();
void Exit(); void Exit();
void DoExit(); void DoExit();
@@ -267,7 +274,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void DeleteFilesFinished(const SongList &songs_with_errors); void DeleteFilesFinished(const SongList &songs_with_errors);
public Q_SLOTS: public slots:
void CommandlineOptionsReceived(const QByteArray &string_options); void CommandlineOptionsReceived(const QByteArray &string_options);
void Raise(); void Raise();

View File

@@ -37,7 +37,7 @@
<item> <item>
<widget class="QSplitter" name="splitter"> <widget class="QSplitter" name="splitter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QWidget" name="sidebar_layout"> <widget class="QWidget" name="sidebar_layout">
<layout class="QVBoxLayout" name="layout_left"> <layout class="QVBoxLayout" name="layout_left">
@@ -77,7 +77,7 @@
<item> <item>
<widget class="Line" name="line_6"> <widget class="Line" name="line_6">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -102,7 +102,7 @@
<item> <item>
<widget class="QFrame" name="player_controls"> <widget class="QFrame" name="player_controls">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<layout class="QHBoxLayout" name="layout_player_controls"> <layout class="QHBoxLayout" name="layout_player_controls">
<property name="spacing"> <property name="spacing">
@@ -167,7 +167,7 @@
</size> </size>
</property> </property>
<property name="popupMode"> <property name="popupMode">
<enum>QToolButton::ToolButtonPopupMode::MenuButtonPopup</enum> <enum>QToolButton::MenuButtonPopup</enum>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
<bool>true</bool> <bool>true</bool>
@@ -211,7 +211,7 @@
<item> <item>
<widget class="Line" name="line_love"> <widget class="Line" name="line_love">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -237,7 +237,7 @@
<item> <item>
<widget class="Line" name="line_buttons"> <widget class="Line" name="line_buttons">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -260,10 +260,10 @@
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Policy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
@@ -276,7 +276,7 @@
<item> <item>
<widget class="Line" name="line_volume"> <widget class="Line" name="line_volume">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -292,7 +292,7 @@
<number>100</number> <number>100</number>
</property> </property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -326,7 +326,7 @@
<item> <item>
<widget class="Line" name="status_bar_line"> <widget class="Line" name="status_bar_line">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -380,7 +380,7 @@
<item> <item>
<widget class="QLabel" name="playlist_summary"> <widget class="QLabel" name="playlist_summary">
<property name="alignment"> <property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@@ -391,7 +391,7 @@
<item> <item>
<widget class="Line" name="line_5"> <widget class="Line" name="line_5">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -401,7 +401,7 @@
<item> <item>
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Orientation::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>
@@ -524,7 +524,7 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_update_collection"/> <addaction name="action_update_collection"/>
<addaction name="action_full_collection_scan"/> <addaction name="action_full_collection_scan"/>
<addaction name="action_stop_collection_scan"/> <addaction name="action_abort_collection_scan"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_settings"/> <addaction name="action_settings"/>
<addaction name="action_import_data_from_last_fm"/> <addaction name="action_import_data_from_last_fm"/>
@@ -580,7 +580,7 @@
<string>Ctrl+Q</string> <string>Ctrl+Q</string>
</property> </property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::MenuRole::QuitRole</enum> <enum>QAction::QuitRole</enum>
</property> </property>
</action> </action>
<action name="action_stop_after_this_track"> <action name="action_stop_after_this_track">
@@ -644,7 +644,7 @@
<string>Ctrl+P</string> <string>Ctrl+P</string>
</property> </property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::MenuRole::PreferencesRole</enum> <enum>QAction::PreferencesRole</enum>
</property> </property>
</action> </action>
<action name="action_about_strawberry"> <action name="action_about_strawberry">
@@ -659,7 +659,7 @@
<string>F1</string> <string>F1</string>
</property> </property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::MenuRole::AboutRole</enum> <enum>QAction::AboutRole</enum>
</property> </property>
</action> </action>
<action name="action_shuffle"> <action name="action_shuffle">
@@ -785,7 +785,7 @@
<string>About &amp;Qt</string> <string>About &amp;Qt</string>
</property> </property>
<property name="menuRole"> <property name="menuRole">
<enum>QAction::MenuRole::AboutQtRole</enum> <enum>QAction::AboutQtRole</enum>
</property> </property>
</action> </action>
<action name="action_mute"> <action name="action_mute">
@@ -804,12 +804,9 @@
<string>&amp;Do a full collection rescan</string> <string>&amp;Do a full collection rescan</string>
</property> </property>
</action> </action>
<action name="action_stop_collection_scan"> <action name="action_abort_collection_scan">
<property name="text"> <property name="text">
<string>Stop collection scan</string> <string>Abort collection scan</string>
</property>
<property name="toolTip">
<string>Stop collection scan</string>
</property> </property>
</action> </action>
<action name="action_auto_complete_tags"> <action name="action_auto_complete_tags">

View File

@@ -232,7 +232,7 @@ void MergedProxyModel::SubModelResetSlot() {
endInsertRows(); endInsertRows();
} }
Q_EMIT SubModelReset(proxy_parent, submodel); emit SubModelReset(proxy_parent, submodel);
} }
@@ -516,7 +516,7 @@ QAbstractItemModel *MergedProxyModel::GetModel(const QModelIndex &source_index)
} }
void MergedProxyModel::DataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right) { void MergedProxyModel::DataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right) {
Q_EMIT dataChanged(mapFromSource(top_left), mapFromSource(bottom_right)); emit dataChanged(mapFromSource(top_left), mapFromSource(bottom_right));
} }
void MergedProxyModel::LayoutAboutToBeChanged() { void MergedProxyModel::LayoutAboutToBeChanged() {
@@ -535,8 +535,8 @@ void MergedProxyModel::LayoutChanged() {
for (QAbstractItemModel *model : models) { for (QAbstractItemModel *model : models) {
if (!old_merge_points_.contains(model)) continue; if (!old_merge_points_.contains(model)) continue;
const int old_row = old_merge_points_.value(model).row(); const int old_row = old_merge_points_[model].row();
const int new_row = merge_points_.value(model).row(); const int new_row = merge_points_[model].row();
if (old_row != new_row) { if (old_row != new_row) {
beginResetModel(); beginResetModel();

View File

@@ -85,10 +85,10 @@ class MergedProxyModel : public QAbstractProxyModel {
QModelIndexList mapFromSource(const QModelIndexList &source_indexes) const; QModelIndexList mapFromSource(const QModelIndexList &source_indexes) const;
QModelIndexList mapToSource(const QModelIndexList &proxy_indexes) const; QModelIndexList mapToSource(const QModelIndexList &proxy_indexes) const;
Q_SIGNALS: signals:
void SubModelReset(const QModelIndex root, QAbstractItemModel *model); void SubModelReset(const QModelIndex root, QAbstractItemModel *model);
private Q_SLOTS: private slots:
void SourceModelReset(); void SourceModelReset();
void SubModelAboutToBeReset(); void SubModelAboutToBeReset();
void SubModelResetSlot(); void SubModelResetSlot();

View File

@@ -81,8 +81,6 @@
#include "smartplaylists/smartplaylistsearchterm.h" #include "smartplaylists/smartplaylistsearchterm.h"
#include "smartplaylists/smartplaylistsitem.h" #include "smartplaylists/smartplaylistsitem.h"
#include "lyrics/lyricssearchresult.h"
void RegisterMetaTypes() { void RegisterMetaTypes() {
qRegisterMetaType<const char*>("const char*"); qRegisterMetaType<const char*>("const char*");
@@ -96,6 +94,10 @@ void RegisterMetaTypes() {
qRegisterMetaType<QItemSelection>("QItemSelection"); qRegisterMetaType<QItemSelection>("QItemSelection");
qRegisterMetaType<QMap<int, Qt::Alignment>>("ColumnAlignmentMap"); qRegisterMetaType<QMap<int, Qt::Alignment>>("ColumnAlignmentMap");
qRegisterMetaType<QMap<int, int>>("ColumnAlignmentIntMap"); qRegisterMetaType<QMap<int, int>>("ColumnAlignmentIntMap");
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<QMap<int, Qt::Alignment>>("ColumnAlignmentMap");
qRegisterMetaTypeStreamOperators<QMap<int, int>>("ColumnAlignmentIntMap");
#endif
qRegisterMetaType<Song>("Song"); qRegisterMetaType<Song>("Song");
qRegisterMetaType<SongList>("SongList"); qRegisterMetaType<SongList>("SongList");
qRegisterMetaType<SongMap>("SongMap"); qRegisterMetaType<SongMap>("SongMap");
@@ -129,6 +131,10 @@ void RegisterMetaTypes() {
qRegisterMetaType<Equalizer::Params>("Equalizer::Params"); qRegisterMetaType<Equalizer::Params>("Equalizer::Params");
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<Equalizer::Params>("Equalizer::Params");
#endif
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
qDBusRegisterMetaType<QByteArrayList>(); qDBusRegisterMetaType<QByteArrayList>();
qDBusRegisterMetaType<QImage>(); qDBusRegisterMetaType<QImage>();
@@ -161,6 +167,4 @@ void RegisterMetaTypes() {
qRegisterMetaType<SmartPlaylistSearchTerm::DateType>("SmartPlaylistSearchTerm::DateType"); qRegisterMetaType<SmartPlaylistSearchTerm::DateType>("SmartPlaylistSearchTerm::DateType");
qRegisterMetaType<SmartPlaylistsItem::Type>("SmartPlaylistsItem::Type"); qRegisterMetaType<SmartPlaylistsItem::Type>("SmartPlaylistsItem::Type");
qRegisterMetaType<LyricsSearchResults>("LyricsSearchResults");
} }

View File

@@ -1,44 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2024, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QString>
#include "mimedata.h"
MimeData::MimeData(const bool clear, const bool play_now, const bool enqueue, const bool enqueue_next_now, const bool open_in_new_playlist, QObject *parent)
: override_user_settings_(false),
clear_first_(clear),
play_now_(play_now),
enqueue_now_(enqueue),
enqueue_next_now_(enqueue_next_now),
open_in_new_playlist_(open_in_new_playlist),
name_for_new_playlist_(QString()),
from_doubleclick_(false) {
Q_UNUSED(parent);
}
QString MimeData::get_name_for_new_playlist() const {
return name_for_new_playlist_.isEmpty() ? tr("Playlist") : name_for_new_playlist_;
}

View File

@@ -2,7 +2,6 @@
* 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-2024, 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
@@ -22,6 +21,9 @@
#ifndef MIMEDATA_H #ifndef MIMEDATA_H
#define MIMEDATA_H #define MIMEDATA_H
#include "config.h"
#include <QObject>
#include <QMimeData> #include <QMimeData>
#include <QString> #include <QString>
@@ -29,7 +31,15 @@ class MimeData : public QMimeData {
Q_OBJECT Q_OBJECT
public: public:
explicit MimeData(const bool clear = false, const bool play_now = false, const bool enqueue = false, const bool enqueue_next_now = false, const bool open_in_new_playlist = false, QObject *parent = nullptr); explicit MimeData(const bool clear = false, const bool play_now = false, const bool enqueue = false, const bool enqueue_next_now = false, const bool open_in_new_playlist = false, QObject* = nullptr)
: override_user_settings_(false),
clear_first_(clear),
play_now_(play_now),
enqueue_now_(enqueue),
enqueue_next_now_(enqueue_next_now),
open_in_new_playlist_(open_in_new_playlist),
name_for_new_playlist_(QString()),
from_doubleclick_(false) {}
// If this is set then MainWindow will not touch any of the other flags. // If this is set then MainWindow will not touch any of the other flags.
bool override_user_settings_; bool override_user_settings_;
@@ -59,7 +69,9 @@ class MimeData : public QMimeData {
// Returns a pretty name for a playlist containing songs described by this MimeData object. // Returns a pretty name for a playlist containing songs described by this MimeData object.
// By pretty name we mean the value of 'name_for_new_playlist_' or generic "Playlist" string if the 'name_for_new_playlist_' attribute is empty. // By pretty name we mean the value of 'name_for_new_playlist_' or generic "Playlist" string if the 'name_for_new_playlist_' attribute is empty.
QString get_name_for_new_playlist() const; QString get_name_for_new_playlist() {
return name_for_new_playlist_.isEmpty() ? tr("Playlist") : name_for_new_playlist_;
}
}; };
#endif // MIMEDATA_H #endif // MIMEDATA_H

Some files were not shown because too many files have changed in this diff Show More