Refactoring

This commit is contained in:
Jonas Kvinge
2024-10-22 18:12:33 +02:00
parent dfcf715291
commit 8da2b9cd94
623 changed files with 9071 additions and 5126 deletions

View File

@@ -29,7 +29,7 @@
#include <QByteArray>
#include <QString>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "playlist/playlistitem.h"
class CollectionBackend;

View File

@@ -23,7 +23,7 @@
#include "config.h"
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
class PlaylistGenerator;

View File

@@ -26,7 +26,7 @@
#include <QFuture>
#include <QFutureWatcher>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/taskmanager.h"
#include "playlist/playlist.h"

View File

@@ -26,7 +26,7 @@
#include <QObject>
#include <QString>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "playlist/playlist.h"
#include "playlist/playlistitem.h"

View File

@@ -88,7 +88,7 @@ PlaylistItemPtrList PlaylistQueryGenerator::GenerateMore(const int count) {
current_pos_ += search_copy.limit_;
}
const SongList songs = collection_backend_->SmartPlaylistsFindSongs(search_copy);
const SongList songs = collection_backend_->ExecuteQuery(search_copy.ToSql(collection_backend_->songs_table()));
PlaylistItemPtrList items;
items.reserve(songs.count());
for (const Song &song : songs) {

View File

@@ -30,8 +30,8 @@
#include <QVBoxLayout>
#include <QScrollBar>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "includes/scoped_ptr.h"
#include "includes/shared_ptr.h"
#include "playlistquerygenerator.h"
#include "smartplaylistquerywizardplugin.h"
#include "smartplaylistquerywizardpluginsearchpage.h"
@@ -43,8 +43,22 @@
using std::make_unique;
using std::make_shared;
SmartPlaylistQueryWizardPlugin::SmartPlaylistQueryWizardPlugin(Application *app, SharedPtr<CollectionBackend> collection_backend, QObject *parent)
: SmartPlaylistWizardPlugin(app, collection_backend, parent),
SmartPlaylistQueryWizardPlugin::SmartPlaylistQueryWizardPlugin(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QObject *parent)
: SmartPlaylistWizardPlugin(collection_backend, parent),
player_(player),
playlist_manager_(playlist_manager),
collection_backend_(collection_backend),
#ifdef HAVE_MOODBAR
moodbar_loader_(moodbar_loader),
#endif
current_albumcover_loader_(current_albumcover_loader),
search_page_(nullptr),
previous_scrollarea_max_(0) {}
@@ -86,8 +100,13 @@ int SmartPlaylistQueryWizardPlugin::CreatePages(QWizard *wizard, int finish_page
QVBoxLayout *terms_page_layout = static_cast<QVBoxLayout*>(search_page_->layout());
terms_page_layout->addStretch();
search_page_->preview_ = new SmartPlaylistSearchPreview(search_page_);
search_page_->preview_->set_application(app_);
search_page_->preview_->set_collection(collection_backend_);
search_page_->preview_->Init(player_,
playlist_manager_,
collection_backend_,
#ifdef HAVE_MOODBAR
moodbar_loader_,
#endif
current_albumcover_loader_);
terms_page_layout->addWidget(search_page_->preview_);
// Add sort field texts
@@ -105,8 +124,14 @@ int SmartPlaylistQueryWizardPlugin::CreatePages(QWizard *wizard, int finish_page
sort_ui_->limit_none->setChecked(true);
// Set up the preview widget that's already at the bottom of the sort page
sort_ui_->preview->set_application(app_);
sort_ui_->preview->set_collection(collection_backend_);
sort_ui_->preview->Init(player_,
playlist_manager_,
collection_backend_,
#ifdef HAVE_MOODBAR
moodbar_loader_,
#endif
current_albumcover_loader_);
QObject::connect(sort_ui_->field, &QRadioButton::toggled, this, &SmartPlaylistQueryWizardPlugin::UpdateSortPreview);
QObject::connect(sort_ui_->field_value, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &SmartPlaylistQueryWizardPlugin::UpdateSortPreview);
QObject::connect(sort_ui_->limit_limit, &QRadioButton::toggled, this, &SmartPlaylistQueryWizardPlugin::UpdateSortPreview);

View File

@@ -25,23 +25,38 @@
#include <QString>
#include "core/scoped_ptr.h"
#include "core/shared_ptr.h"
#include "includes/scoped_ptr.h"
#include "includes/shared_ptr.h"
#include "smartplaylistwizardplugin.h"
#include "smartplaylistsearch.h"
class QWizard;
class Player;
class PlaylistManager;
class CollectionBackend;
class CurrentAlbumCoverLoader;
class SmartPlaylistSearch;
class SmartPlaylistQueryWizardPluginSearchPage;
class Ui_SmartPlaylistQuerySortPage;
#ifdef HAVE_MOODBAR
class MoodbarLoader;
#endif
class SmartPlaylistQueryWizardPlugin : public SmartPlaylistWizardPlugin {
Q_OBJECT
public:
explicit SmartPlaylistQueryWizardPlugin(Application *app, SharedPtr<CollectionBackend> collection_backend, QObject *parent);
explicit SmartPlaylistQueryWizardPlugin(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QObject *parent);
~SmartPlaylistQueryWizardPlugin() override;
PlaylistGenerator::Type type() const override { return PlaylistGenerator::Type::Query; }
@@ -68,6 +83,14 @@ class SmartPlaylistQueryWizardPlugin : public SmartPlaylistWizardPlugin {
void MoveTermListToBottom(const int min, const int max);
private:
const SharedPtr<Player> player_;
const SharedPtr<PlaylistManager> playlist_manager_;
const SharedPtr<CollectionBackend> collection_backend_;
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader_;
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader_;
SmartPlaylistSearch MakeSearch() const;
ScopedPtr<Ui_SmartPlaylistQuerySortPage> sort_ui_;

View File

@@ -23,7 +23,7 @@
#include <QWizardPage>
#include "core/scoped_ptr.h"
#include "includes/scoped_ptr.h"
#include "ui_smartplaylistquerysearchpage.h"

View File

@@ -29,7 +29,7 @@
#include <QFuture>
#include <QFutureWatcher>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "smartplaylistsearchpreview.h"
#include "ui_smartplaylistsearchpreview.h"
@@ -62,21 +62,29 @@ SmartPlaylistSearchPreview::~SmartPlaylistSearchPreview() {
delete ui_;
}
void SmartPlaylistSearchPreview::set_application(Application *app) {
ui_->tree->Init(app);
}
void SmartPlaylistSearchPreview::set_collection(SharedPtr<CollectionBackend> collection_backend) {
void SmartPlaylistSearchPreview::Init(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader) {
collection_backend_ = collection_backend;
model_ = new Playlist(nullptr, nullptr, collection_backend_, -1, QString(), false, this);
model_ = new Playlist(nullptr, nullptr, nullptr, collection_backend_, nullptr, -1, QString(), false, this);
ui_->tree->setModel(model_);
ui_->tree->SetPlaylist(model_);
ui_->tree->SetItemDelegates();
ui_->tree->Init(player,
playlist_manager,
collection_backend,
#ifdef HAVE_MOODBAR
moodbar_loader,
#endif
current_albumcover_loader);
}
void SmartPlaylistSearchPreview::Update(const SmartPlaylistSearch &search) {

View File

@@ -26,18 +26,24 @@
#include <QWidget>
#include <QList>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "smartplaylistsearch.h"
#include "playlistgenerator_fwd.h"
class QShowEvent;
class Application;
class Player;
class PlaylistManager;
class CollectionBackend;
class CurrentAlbumCoverLoader;
class Playlist;
class Ui_SmartPlaylistSearchPreview;
#ifdef HAVE_MOODBAR
class MoodbarLoader;
#endif
class SmartPlaylistSearchPreview : public QWidget {
Q_OBJECT
@@ -45,8 +51,13 @@ class SmartPlaylistSearchPreview : public QWidget {
explicit SmartPlaylistSearchPreview(QWidget *parent = nullptr);
~SmartPlaylistSearchPreview() override;
void set_application(Application *app);
void set_collection(SharedPtr<CollectionBackend> backend);
void Init(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader);
void Update(const SmartPlaylistSearch &search);

View File

@@ -31,7 +31,7 @@
#include <QShowEvent>
#include <QResizeEvent>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/iconloader.h"
#include "utilities/colorutils.h"
#include "playlist/playlist.h"

View File

@@ -26,7 +26,7 @@
#include <QWidget>
#include <QPushButton>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "smartplaylistsearchterm.h"
class QPropertyAnimation;

View File

@@ -29,9 +29,8 @@
#include <QMimeData>
#include <QSettings>
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "core/simpletreemodel.h"
#include "core/settings.h"

View File

@@ -31,13 +31,12 @@
#include <QSettings>
#include <QIcon>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "core/simpletreemodel.h"
#include "core/settings.h"
#include "smartplaylistsitem.h"
#include "playlistgenerator_fwd.h"
class Application;
class CollectionBackend;
class QModelIndex;

View File

@@ -24,11 +24,10 @@
#include <QSettings>
#include <QShowEvent>
#include "core/application.h"
#include "core/iconloader.h"
#include "core/mimedata.h"
#include "core/settings.h"
#include "settings/appearancesettingspage.h"
#include "constants/appearancesettings.h"
#include "smartplaylistsviewcontainer.h"
#include "smartplaylistsmodel.h"
@@ -39,10 +38,23 @@
using namespace Qt::Literals::StringLiterals;
SmartPlaylistsViewContainer::SmartPlaylistsViewContainer(Application *app, QWidget *parent)
SmartPlaylistsViewContainer::SmartPlaylistsViewContainer(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QWidget *parent)
: QWidget(parent),
ui_(new Ui_SmartPlaylistsViewContainer),
app_(app),
player_(player),
playlist_manager_(playlist_manager),
collection_backend_(collection_backend),
#ifdef HAVE_MOODBAR
moodbar_loader_(moodbar_loader),
#endif
current_albumcover_loader_(current_albumcover_loader),
context_menu_(new QMenu(this)),
context_menu_selected_(new QMenu(this)),
action_new_smart_playlist_(nullptr),
@@ -56,7 +68,7 @@ SmartPlaylistsViewContainer::SmartPlaylistsViewContainer(Application *app, QWidg
ui_->setupUi(this);
model_ = new SmartPlaylistsModel(app_->collection_backend(), this);
model_ = new SmartPlaylistsModel(collection_backend, this);
ui_->view->setModel(model_);
model_->Init();
@@ -111,8 +123,8 @@ void SmartPlaylistsViewContainer::showEvent(QShowEvent *e) {
void SmartPlaylistsViewContainer::ReloadSettings() {
Settings s;
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
int iconsize = s.value(AppearanceSettingsPage::kIconSizeLeftPanelButtons, 22).toInt();
s.beginGroup(AppearanceSettings::kSettingsGroup);
int iconsize = s.value(AppearanceSettings::kIconSizeLeftPanelButtons, 22).toInt();
s.endGroup();
ui_->new_->setIconSize(QSize(iconsize, iconsize));
@@ -188,7 +200,14 @@ void SmartPlaylistsViewContainer::AddToPlaylistEnqueueNext() {
void SmartPlaylistsViewContainer::NewSmartPlaylist() {
SmartPlaylistWizard *wizard = new SmartPlaylistWizard(app_, app_->collection_backend(), this);
SmartPlaylistWizard *wizard = new SmartPlaylistWizard(player_,
playlist_manager_,
collection_backend_,
#ifdef HAVE_MOODBAR
moodbar_loader_,
#endif
current_albumcover_loader_,
this);
wizard->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(wizard, &SmartPlaylistWizard::accepted, this, &SmartPlaylistsViewContainer::NewSmartPlaylistFinished);
@@ -200,7 +219,14 @@ void SmartPlaylistsViewContainer::EditSmartPlaylist(const QModelIndex &idx) {
if (!idx.isValid()) return;
SmartPlaylistWizard *wizard = new SmartPlaylistWizard(app_, app_->collection_backend(), this);
SmartPlaylistWizard *wizard = new SmartPlaylistWizard(player_,
playlist_manager_,
collection_backend_,
#ifdef HAVE_MOODBAR
moodbar_loader_,
#endif
current_albumcover_loader_,
this);
wizard->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(wizard, &SmartPlaylistWizard::accepted, this, &SmartPlaylistsViewContainer::EditSmartPlaylistFinished);

View File

@@ -25,21 +25,38 @@
#include <QWidget>
#include <QModelIndex>
#include "includes/shared_ptr.h"
class QMimeData;
class QMenu;
class QAction;
class QShowEvent;
class Application;
class Player;
class PlaylistManager;
class CollectionBackend;
class CurrentAlbumCoverLoader;
class SmartPlaylistsModel;
class SmartPlaylistsView;
class Ui_SmartPlaylistsViewContainer;
#ifdef HAVE_MOODBAR
class MoodbarLoader;
#endif
class SmartPlaylistsViewContainer : public QWidget {
Q_OBJECT
public:
explicit SmartPlaylistsViewContainer(Application *app, QWidget *parent = nullptr);
explicit SmartPlaylistsViewContainer(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QWidget *parent = nullptr);
~SmartPlaylistsViewContainer() override;
SmartPlaylistsView *view() const;
@@ -80,7 +97,15 @@ class SmartPlaylistsViewContainer : public QWidget {
private:
Ui_SmartPlaylistsViewContainer *ui_;
Application *app_;
const SharedPtr<Player> player_;
const SharedPtr<PlaylistManager> playlist_manager_;
const SharedPtr<CollectionBackend> collection_backend_;
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader_;
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader_;
SmartPlaylistsModel *model_;
QMenu *context_menu_;

View File

@@ -27,8 +27,8 @@
#include <QVBoxLayout>
#include <QStyle>
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/shared_ptr.h"
#include "core/iconloader.h"
#include "smartplaylistquerywizardplugin.h"
@@ -40,9 +40,15 @@
using namespace Qt::Literals::StringLiterals;
SmartPlaylistWizard::SmartPlaylistWizard(Application *app, SharedPtr<CollectionBackend> collection_backend, QWidget *parent)
SmartPlaylistWizard::SmartPlaylistWizard(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QWidget *parent)
: QWizard(parent),
app_(app),
collection_backend_(collection_backend),
type_page_(new SmartPlaylistWizardTypePage(this)),
finish_page_(new SmartPlaylistWizardFinishPage(this)),
@@ -75,7 +81,14 @@ SmartPlaylistWizard::SmartPlaylistWizard(Application *app, SharedPtr<CollectionB
finish_id_ = addPage(finish_page_);
new QVBoxLayout(type_page_);
AddPlugin(new SmartPlaylistQueryWizardPlugin(app_, collection_backend, this));
AddPlugin(new SmartPlaylistQueryWizardPlugin(player,
playlist_manager,
collection_backend,
#ifdef HAVE_MOODBAR
moodbar_loader,
#endif
current_albumcover_loader,
this));
// Skip the type page - remove this when we have more than one type
setStartId(2);

View File

@@ -25,21 +25,35 @@
#include <QWizard>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "playlistgenerator_fwd.h"
class Application;
class Player;
class PlaylistManager;
class CollectionBackend;
class CurrentAlbumCoverLoader;
class SmartPlaylistWizardPlugin;
class SmartPlaylistWizardTypePage;
class SmartPlaylistWizardFinishPage;
#ifdef HAVE_MOODBAR
class MoodbarLoader;
#endif
class SmartPlaylistWizard : public QWizard {
Q_OBJECT
public:
explicit SmartPlaylistWizard(Application *app, SharedPtr<CollectionBackend> collection_backend, QWidget *parent);
explicit SmartPlaylistWizard(const SharedPtr<Player> player,
const SharedPtr<PlaylistManager> playlist_manager,
const SharedPtr<CollectionBackend> collection_backend,
#ifdef HAVE_MOODBAR
const SharedPtr<MoodbarLoader> moodbar_loader,
#endif
const SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader,
QWidget *parent);
~SmartPlaylistWizard() override;
void SetGenerator(PlaylistGeneratorPtr gen);
@@ -55,8 +69,7 @@ class SmartPlaylistWizard : public QWizard {
void TypeChanged(const int index);
private:
Application *app_;
SharedPtr<CollectionBackend> collection_backend_;
const SharedPtr<CollectionBackend> collection_backend_;
SmartPlaylistWizardTypePage *type_page_;
SmartPlaylistWizardFinishPage *finish_page_;
int finish_id_;

View File

@@ -23,12 +23,11 @@
#include <QObject>
#include <QWizard>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "smartplaylistwizardplugin.h"
SmartPlaylistWizardPlugin::SmartPlaylistWizardPlugin(Application *app, SharedPtr<CollectionBackend> collection_backend, QObject *parent)
SmartPlaylistWizardPlugin::SmartPlaylistWizardPlugin(const SharedPtr<CollectionBackend> collection_backend, QObject *parent)
: QObject(parent),
app_(app),
collection_backend_(collection_backend),
start_page_(-1) {}

View File

@@ -23,19 +23,18 @@
#include <QObject>
#include "core/shared_ptr.h"
#include "includes/shared_ptr.h"
#include "playlistgenerator.h"
class QWizard;
class Application;
class CollectionBackend;
class SmartPlaylistWizardPlugin : public QObject {
Q_OBJECT
public:
explicit SmartPlaylistWizardPlugin(Application *app, SharedPtr<CollectionBackend> collection_backend, QObject *parent);
explicit SmartPlaylistWizardPlugin(const SharedPtr<CollectionBackend> collection_backend, QObject *parent);
virtual PlaylistGenerator::Type type() const = 0;
virtual QString name() const = 0;
@@ -51,8 +50,7 @@ class SmartPlaylistWizardPlugin : public QObject {
protected:
virtual int CreatePages(QWizard *wizard, const int finish_page_id) = 0;
Application *app_;
SharedPtr<CollectionBackend> collection_backend_;
const SharedPtr<CollectionBackend> collection_backend_;
private:
int start_page_;