From baa82966d8a1187b09d18ce94ec2ea3e8aaf600e Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 8 Mar 2025 22:41:43 +0100 Subject: [PATCH] Move SearchType to StreamingService --- src/qobuz/qobuzservice.cpp | 10 +++++----- src/qobuz/qobuzservice.h | 4 ++-- src/spotify/spotifyservice.cpp | 10 +++++----- src/spotify/spotifyservice.h | 4 ++-- src/streaming/streamingsearchview.cpp | 24 ++++++++++++------------ src/streaming/streamingsearchview.h | 22 +++++++--------------- src/streaming/streamingservice.cpp | 2 +- src/streaming/streamingservice.h | 18 ++++++++++-------- src/subsonic/subsonicservice.h | 1 + src/tidal/tidalservice.cpp | 10 +++++----- src/tidal/tidalservice.h | 4 ++-- 11 files changed, 52 insertions(+), 57 deletions(-) diff --git a/src/qobuz/qobuzservice.cpp b/src/qobuz/qobuzservice.cpp index 653729c75..786b8e210 100644 --- a/src/qobuz/qobuzservice.cpp +++ b/src/qobuz/qobuzservice.cpp @@ -104,7 +104,7 @@ QobuzService::QobuzService(const SharedPtr task_manager, credential_id_(-1), pending_search_id_(0), next_pending_search_id_(1), - pending_search_type_(StreamingSearchView::SearchType::Artists), + pending_search_type_(SearchType::Artists), search_id_(0), login_sent_(false), login_attempts_(0), @@ -645,7 +645,7 @@ void QobuzService::SongsUpdateProgressReceived(const int id, const int progress) Q_EMIT SongsUpdateProgress(progress); } -int QobuzService::Search(const QString &text, StreamingSearchView::SearchType type) { +int QobuzService::Search(const QString &text, const SearchType type) { pending_search_id_ = next_pending_search_id_; pending_search_text_ = text; @@ -686,13 +686,13 @@ void QobuzService::SendSearch() { QobuzBaseRequest::Type query_type = QobuzBaseRequest::Type::None; switch (pending_search_type_) { - case StreamingSearchView::SearchType::Artists: + case SearchType::Artists: query_type = QobuzBaseRequest::Type::SearchArtists; break; - case StreamingSearchView::SearchType::Albums: + case SearchType::Albums: query_type = QobuzBaseRequest::Type::SearchAlbums; break; - case StreamingSearchView::SearchType::Songs: + case SearchType::Songs: query_type = QobuzBaseRequest::Type::SearchSongs; break; } diff --git a/src/qobuz/qobuzservice.h b/src/qobuz/qobuzservice.h index 8447c28e0..638517008 100644 --- a/src/qobuz/qobuzservice.h +++ b/src/qobuz/qobuzservice.h @@ -78,7 +78,7 @@ class QobuzService : public StreamingService { void ReloadSettings() override; void Logout(); - int Search(const QString &text, StreamingSearchView::SearchType type) override; + int Search(const QString &text, const SearchType type) override; void CancelSearch() override; int max_login_attempts() const { return kLoginAttempts; } @@ -194,7 +194,7 @@ class QobuzService : public StreamingService { int pending_search_id_; int next_pending_search_id_; QString pending_search_text_; - StreamingSearchView::SearchType pending_search_type_; + SearchType pending_search_type_; int search_id_; QString search_text_; diff --git a/src/spotify/spotifyservice.cpp b/src/spotify/spotifyservice.cpp index b9cf5c7c6..142801077 100644 --- a/src/spotify/spotifyservice.cpp +++ b/src/spotify/spotifyservice.cpp @@ -111,7 +111,7 @@ SpotifyService::SpotifyService(const SharedPtr task_manager, login_time_(0), pending_search_id_(0), next_pending_search_id_(1), - pending_search_type_(StreamingSearchView::SearchType::Artists), + pending_search_type_(SearchType::Artists), search_id_(0), server_(nullptr) { @@ -656,7 +656,7 @@ void SpotifyService::SongsUpdateProgressReceived(const int id, const int progres Q_EMIT SongsUpdateProgress(progress); } -int SpotifyService::Search(const QString &text, StreamingSearchView::SearchType type) { +int SpotifyService::Search(const QString &text, const SearchType type) { pending_search_id_ = next_pending_search_id_; pending_search_text_ = text; @@ -697,13 +697,13 @@ void SpotifyService::SendSearch() { SpotifyBaseRequest::Type type = SpotifyBaseRequest::Type::None; switch (pending_search_type_) { - case StreamingSearchView::SearchType::Artists: + case SearchType::Artists: type = SpotifyBaseRequest::Type::SearchArtists; break; - case StreamingSearchView::SearchType::Albums: + case SearchType::Albums: type = SpotifyBaseRequest::Type::SearchAlbums; break; - case StreamingSearchView::SearchType::Songs: + case SearchType::Songs: type = SpotifyBaseRequest::Type::SearchSongs; break; default: diff --git a/src/spotify/spotifyservice.h b/src/spotify/spotifyservice.h index ed5213cd7..7bacac986 100644 --- a/src/spotify/spotifyservice.h +++ b/src/spotify/spotifyservice.h @@ -74,7 +74,7 @@ class SpotifyService : public StreamingService { void Exit() override; void ReloadSettings() override; - int Search(const QString &text, StreamingSearchView::SearchType type) override; + int Search(const QString &text, const SearchType type) override; void CancelSearch() override; int artistssearchlimit() const { return artistssearchlimit_; } @@ -173,7 +173,7 @@ class SpotifyService : public StreamingService { int pending_search_id_; int next_pending_search_id_; QString pending_search_text_; - StreamingSearchView::SearchType pending_search_type_; + SearchType pending_search_type_; int search_id_; QString search_text_; diff --git a/src/streaming/streamingsearchview.cpp b/src/streaming/streamingsearchview.cpp index 0ab18375a..e02b7a3aa 100644 --- a/src/streaming/streamingsearchview.cpp +++ b/src/streaming/streamingsearchview.cpp @@ -2,7 +2,7 @@ * Strawberry Music Player * This code was part of Clementine (GlobalSearch) * Copyright 2012, David Sansome - * Copyright 2018-2021, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -106,7 +106,7 @@ StreamingSearchView::StreamingSearchView(QWidget *parent) current_proxy_(front_proxy_), swap_models_timer_(new QTimer(this)), use_pretty_covers_(true), - search_type_(StreamingSearchView::SearchType::Artists), + search_type_(StreamingService::SearchType::Artists), search_error_(false), last_search_id_(0), searches_next_id_(1) { @@ -221,15 +221,15 @@ void StreamingSearchView::ReloadSettings() { // Streaming search settings - search_type_ = static_cast(s.value("type", static_cast(StreamingSearchView::SearchType::Artists)).toInt()); + search_type_ = static_cast(s.value("type", static_cast(StreamingService::SearchType::Artists)).toInt()); switch (search_type_) { - case StreamingSearchView::SearchType::Artists: + case StreamingService::SearchType::Artists: ui_->radiobutton_search_artists->setChecked(true); break; - case StreamingSearchView::SearchType::Albums: + case StreamingService::SearchType::Albums: ui_->radiobutton_search_albums->setChecked(true); break; - case StreamingSearchView::SearchType::Songs: + case StreamingService::SearchType::Songs: ui_->radiobutton_search_songs->setChecked(true); break; } @@ -464,7 +464,7 @@ bool StreamingSearchView::Matches(const QStringList &tokens, const QString &stri } -int StreamingSearchView::SearchAsync(const QString &query, const SearchType type) { +int StreamingSearchView::SearchAsync(const QString &query, const StreamingService::SearchType type) { const int id = searches_next_id_++; @@ -477,7 +477,7 @@ int StreamingSearchView::SearchAsync(const QString &query, const SearchType type } -void StreamingSearchView::SearchAsync(const int id, const QString &query, const SearchType type) { +void StreamingSearchView::SearchAsync(const int id, const QString &query, const StreamingService::SearchType type) { const int service_id = service_->Search(query, type); pending_searches_[service_id] = PendingState(id, TokenizeQuery(query)); @@ -732,20 +732,20 @@ void StreamingSearchView::SetGroupBy(const CollectionModel::Grouping g) { void StreamingSearchView::SearchArtistsClicked(const bool checked) { Q_UNUSED(checked) - SetSearchType(StreamingSearchView::SearchType::Artists); + SetSearchType(StreamingService::SearchType::Artists); } void StreamingSearchView::SearchAlbumsClicked(const bool checked) { Q_UNUSED(checked) - SetSearchType(StreamingSearchView::SearchType::Albums); + SetSearchType(StreamingService::SearchType::Albums); } void StreamingSearchView::SearchSongsClicked(const bool checked) { Q_UNUSED(checked) - SetSearchType(StreamingSearchView::SearchType::Songs); + SetSearchType(StreamingService::SearchType::Songs); } -void StreamingSearchView::SetSearchType(const StreamingSearchView::SearchType type) { +void StreamingSearchView::SetSearchType(const StreamingService::SearchType type) { search_type_ = type; diff --git a/src/streaming/streamingsearchview.h b/src/streaming/streamingsearchview.h index 74df0d37f..13ffeb2b4 100644 --- a/src/streaming/streamingsearchview.h +++ b/src/streaming/streamingsearchview.h @@ -2,7 +2,7 @@ * Strawberry Music Player * This code was part of Clementine (GlobalSearch) * Copyright 2012, David Sansome - * Copyright 2018-2021, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,10 +24,7 @@ #include "config.h" -#include -#include #include -#include #include #include #include @@ -43,6 +40,7 @@ #include "core/song.h" #include "collection/collectionmodel.h" #include "covermanager/albumcoverloaderresult.h" +#include "streamingservice.h" class QSortFilterProxyModel; class QMimeData; @@ -59,7 +57,6 @@ class QTimerEvent; class MimeData; class AlbumCoverLoader; class GroupByDialog; -class StreamingService; class StreamingSearchModel; class Ui_StreamingSearchView; @@ -70,11 +67,6 @@ class StreamingSearchView : public QWidget { explicit StreamingSearchView(QWidget *parent = nullptr); ~StreamingSearchView() override; - enum class SearchType { - Artists = 1, - Albums = 2, - Songs = 3 - }; struct Result { Song metadata_; QString pixmap_cache_key_; @@ -117,7 +109,7 @@ class StreamingSearchView : public QWidget { struct DelayedSearch { int id_; QString query_; - SearchType type_; + StreamingService::SearchType type_; }; bool SearchKeyEvent(QKeyEvent *e); @@ -125,10 +117,10 @@ class StreamingSearchView : public QWidget { MimeData *SelectedMimeData(); - void SetSearchType(const SearchType type); + void SetSearchType(const StreamingService::SearchType type); - int SearchAsync(const QString &query, SearchType type); - void SearchAsync(const int id, const QString &query, const SearchType type); + int SearchAsync(const QString &query, const StreamingService::SearchType type); + void SearchAsync(const int id, const QString &query, const StreamingService::SearchType type); void SearchError(const int id, const QString &error); void CancelSearch(const int id); @@ -202,7 +194,7 @@ class StreamingSearchView : public QWidget { QTimer *swap_models_timer_; bool use_pretty_covers_; - SearchType search_type_; + StreamingService::SearchType search_type_; bool search_error_; int last_search_id_; int searches_next_id_; diff --git a/src/streaming/streamingservice.cpp b/src/streaming/streamingservice.cpp index d47b20799..a262f2788 100644 --- a/src/streaming/streamingservice.cpp +++ b/src/streaming/streamingservice.cpp @@ -1,6 +1,6 @@ /* * Strawberry Music Player - * Copyright 2018-2021, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/streaming/streamingservice.h b/src/streaming/streamingservice.h index dff89095e..06c4ebdb1 100644 --- a/src/streaming/streamingservice.h +++ b/src/streaming/streamingservice.h @@ -1,6 +1,6 @@ /* * Strawberry Music Player - * Copyright 2018-2021, Jonas Kvinge + * Copyright 2018-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,17 +20,13 @@ #ifndef STREAMINGSERVICE_H #define STREAMINGSERVICE_H -#include #include -#include -#include #include #include #include #include "includes/shared_ptr.h" #include "core/song.h" -#include "streamingsearchview.h" class CollectionBackend; class CollectionModel; @@ -41,9 +37,15 @@ class StreamingService : public QObject { public: explicit StreamingService(const Song::Source source, const QString &name, const QString &url_scheme, const QString &settings_group, QObject *parent = nullptr); - ~StreamingService() override {} - virtual void Exit() {} + + enum class SearchType { + Artists = 1, + Albums = 2, + Songs = 3 + }; + + virtual void Exit() = 0; virtual Song::Source source() const { return source_; } virtual QString name() const { return name_; } @@ -55,7 +57,7 @@ class StreamingService : public QObject { virtual QIcon Icon() const { return Song::IconForSource(source_); } virtual bool oauth() const { return false; } virtual bool authenticated() const { return false; } - virtual int Search(const QString &query, StreamingSearchView::SearchType type) { Q_UNUSED(query); Q_UNUSED(type); return 0; } + virtual int Search(const QString &query, const SearchType type) { Q_UNUSED(query); Q_UNUSED(type); return 0; } virtual void CancelSearch() {} virtual SharedPtr artists_collection_backend() { return nullptr; } diff --git a/src/subsonic/subsonicservice.h b/src/subsonic/subsonicservice.h index 725e5eaae..4da05dfee 100644 --- a/src/subsonic/subsonicservice.h +++ b/src/subsonic/subsonicservice.h @@ -39,6 +39,7 @@ #include "includes/scoped_ptr.h" #include "includes/shared_ptr.h" #include "core/song.h" +#include "collection/collectionmodel.h" #include "streaming/streamingservice.h" #include "constants/subsonicsettings.h" diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index f3336efd9..cc6a1b7f6 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -128,7 +128,7 @@ TidalService::TidalService(const SharedPtr task_manager, login_time_(0), pending_search_id_(0), next_pending_search_id_(1), - pending_search_type_(StreamingSearchView::SearchType::Artists), + pending_search_type_(SearchType::Artists), search_id_(0), next_stream_url_request_id_(0) { @@ -667,7 +667,7 @@ void TidalService::SongsUpdateProgressReceived(const int id, const int progress) Q_EMIT SongsUpdateProgress(progress); } -int TidalService::Search(const QString &text, StreamingSearchView::SearchType type) { +int TidalService::Search(const QString &text, const SearchType type) { pending_search_id_ = next_pending_search_id_; pending_search_text_ = text; @@ -707,13 +707,13 @@ void TidalService::SendSearch() { TidalBaseRequest::Type query_type = TidalBaseRequest::Type::None; switch (pending_search_type_) { - case StreamingSearchView::SearchType::Artists: + case SearchType::Artists: query_type = TidalBaseRequest::Type::SearchArtists; break; - case StreamingSearchView::SearchType::Albums: + case SearchType::Albums: query_type = TidalBaseRequest::Type::SearchAlbums; break; - case StreamingSearchView::SearchType::Songs: + case SearchType::Songs: query_type = TidalBaseRequest::Type::SearchSongs; break; default: diff --git a/src/tidal/tidalservice.h b/src/tidal/tidalservice.h index dd86855cd..a1dadf85d 100644 --- a/src/tidal/tidalservice.h +++ b/src/tidal/tidalservice.h @@ -79,7 +79,7 @@ class TidalService : public StreamingService { void ReloadSettings() override; void Logout(); - int Search(const QString &text, StreamingSearchView::SearchType type) override; + int Search(const QString &text, const SearchType type) override; void CancelSearch() override; QString client_id() const { return client_id_; } @@ -195,7 +195,7 @@ class TidalService : public StreamingService { int pending_search_id_; int next_pending_search_id_; QString pending_search_text_; - StreamingSearchView::SearchType pending_search_type_; + SearchType pending_search_type_; int search_id_; QString search_text_;