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

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