Move SearchType to StreamingService

This commit is contained in:
Jonas Kvinge
2025-03-08 22:41:43 +01:00
parent f85d60f5cd
commit baa82966d8
11 changed files with 52 additions and 57 deletions

View File

@@ -104,7 +104,7 @@ QobuzService::QobuzService(const SharedPtr<TaskManager> 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;
}

View File

@@ -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_;

View File

@@ -111,7 +111,7 @@ SpotifyService::SpotifyService(const SharedPtr<TaskManager> 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:

View File

@@ -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_;

View File

@@ -2,7 +2,7 @@
* Strawberry Music Player
* This code was part of Clementine (GlobalSearch)
* Copyright 2012, David Sansome <me@davidsansome.com>
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -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<StreamingSearchView::SearchType>(s.value("type", static_cast<int>(StreamingSearchView::SearchType::Artists)).toInt());
search_type_ = static_cast<StreamingService::SearchType>(s.value("type", static_cast<int>(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;

View File

@@ -2,7 +2,7 @@
* Strawberry Music Player
* This code was part of Clementine (GlobalSearch)
* Copyright 2012, David Sansome <me@davidsansome.com>
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,10 +24,7 @@
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QWidget>
#include <QSet>
#include <QPair>
#include <QList>
#include <QMap>
@@ -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_;

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
* Strawberry Music Player
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
* Copyright 2018-2025, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,17 +20,13 @@
#ifndef STREAMINGSERVICE_H
#define STREAMINGSERVICE_H
#include <QtGlobal>
#include <QObject>
#include <QMetaType>
#include <QMap>
#include <QString>
#include <QUrl>
#include <QIcon>
#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<CollectionBackend> artists_collection_backend() { return nullptr; }

View File

@@ -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"

View File

@@ -128,7 +128,7 @@ TidalService::TidalService(const SharedPtr<TaskManager> 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:

View File

@@ -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_;