Application: Use shared pointers

Fixes #1239
This commit is contained in:
Jonas Kvinge
2023-07-21 05:55:24 +02:00
parent d6b53f78ab
commit 2e61235403
316 changed files with 2170 additions and 1643 deletions

View File

@@ -31,10 +31,11 @@
#include <QThread>
#include <QString>
#include "core/lazy.h"
#include "core/tagreaderclient.h"
#include "core/logging.h"
#include "shared_ptr.h"
#include "lazy.h"
#include "tagreaderclient.h"
#include "database.h"
#include "taskmanager.h"
#include "player.h"
@@ -98,99 +99,103 @@
#include "radios/radioservices.h"
#include "radios/radiobackend.h"
using std::make_shared;
using namespace std::chrono_literals;
class ApplicationImpl {
public:
explicit ApplicationImpl(Application *app) :
tag_reader_client_([app]() {
TagReaderClient *client = new TagReaderClient(app);
tag_reader_client_([app](){
TagReaderClient *client = new TagReaderClient();
app->MoveToNewThread(client);
client->Start();
return client;
}),
database_([app]() {
Database *db = new Database(app, app);
Database *db = new Database(app);
app->MoveToNewThread(db);
QTimer::singleShot(30s, db, &Database::DoBackup);
return db;
}),
task_manager_([app]() { return new TaskManager(app); }),
player_([app]() { return new Player(app, app); }),
network_([app]() { return new NetworkAccessManager(app); }),
device_finders_([app]() { return new DeviceFinders(app); }),
task_manager_([]() { return new TaskManager(); }),
player_([app]() { return new Player(app); }),
network_([]() { return new NetworkAccessManager(); }),
device_finders_([]() { return new DeviceFinders(); }),
#ifndef Q_OS_WIN
device_manager_([app]() { return new DeviceManager(app, app); }),
device_manager_([app]() { return new DeviceManager(app); }),
#endif
collection_([app]() { return new SCollection(app, app); }),
collection_([app]() { return new SCollection(app); }),
playlist_backend_([this, app]() {
PlaylistBackend *backend = new PlaylistBackend(app, app);
PlaylistBackend *backend = new PlaylistBackend(app);
app->MoveToThread(backend, database_->thread());
return backend;
}),
playlist_manager_([app]() { return new PlaylistManager(app); }),
cover_providers_([app]() {
CoverProviders *cover_providers = new CoverProviders(app);
CoverProviders *cover_providers = new CoverProviders();
// Initialize the repository of cover providers.
cover_providers->AddProvider(new LastFmCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new MusicbrainzCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new DiscogsCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new DeezerCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new MusixmatchCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new SpotifyCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new LastFmCoverProvider(app, app->network()));
cover_providers->AddProvider(new MusicbrainzCoverProvider(app, app->network()));
cover_providers->AddProvider(new DiscogsCoverProvider(app, app->network()));
cover_providers->AddProvider(new DeezerCoverProvider(app, app->network()));
cover_providers->AddProvider(new MusixmatchCoverProvider(app, app->network()));
cover_providers->AddProvider(new SpotifyCoverProvider(app, app->network()));
#ifdef HAVE_TIDAL
cover_providers->AddProvider(new TidalCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new TidalCoverProvider(app, app->network()));
#endif
#ifdef HAVE_QOBUZ
cover_providers->AddProvider(new QobuzCoverProvider(app, app->network(), app));
cover_providers->AddProvider(new QobuzCoverProvider(app, app->network()));
#endif
cover_providers->ReloadSettings();
return cover_providers;
}),
album_cover_loader_([app]() {
AlbumCoverLoader *loader = new AlbumCoverLoader(app);
AlbumCoverLoader *loader = new AlbumCoverLoader();
app->MoveToNewThread(loader);
return loader;
}),
current_albumcover_loader_([app]() { return new CurrentAlbumCoverLoader(app, app); }),
current_albumcover_loader_([app]() { return new CurrentAlbumCoverLoader(app); }),
lyrics_providers_([app]() {
LyricsProviders *lyrics_providers = new LyricsProviders(app);
// Initialize the repository of lyrics providers.
lyrics_providers->AddProvider(new GeniusLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new OVHLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new LoloLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new ChartLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new LyricsComLyricsProvider(app->network(), app));
lyrics_providers->AddProvider(new GeniusLyricsProvider(app->network()));
lyrics_providers->AddProvider(new OVHLyricsProvider(app->network()));
lyrics_providers->AddProvider(new LoloLyricsProvider(app->network()));
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(app->network()));
lyrics_providers->AddProvider(new ChartLyricsProvider(app->network()));
lyrics_providers->AddProvider(new LyricsComLyricsProvider(app->network()));
lyrics_providers->ReloadSettings();
return lyrics_providers;
}),
internet_services_([app]() {
InternetServices *internet_services = new InternetServices(app);
InternetServices *internet_services = new InternetServices();
#ifdef HAVE_SUBSONIC
internet_services->AddService(new SubsonicService(app, internet_services));
internet_services->AddService(make_shared<SubsonicService>(app));
#endif
#ifdef HAVE_TIDAL
internet_services->AddService(new TidalService(app, internet_services));
internet_services->AddService(make_shared<TidalService>(app));
#endif
#ifdef HAVE_QOBUZ
internet_services->AddService(new QobuzService(app, internet_services));
internet_services->AddService(make_shared<QobuzService>(app));
#endif
return internet_services;
}),
radio_services_([app]() { return new RadioServices(app, app); }),
radio_services_([app]() { return new RadioServices(app); }),
scrobbler_([app]() {
AudioScrobbler *scrobbler = new AudioScrobbler(app);
scrobbler->AddService(new LastFMScrobbler(scrobbler, app->network(), app));
scrobbler->AddService(new LibreFMScrobbler(scrobbler, app->network(), app));
scrobbler->AddService(new ListenBrainzScrobbler(scrobbler, app->network(), app));
scrobbler->AddService(make_shared<LastFMScrobbler>(scrobbler->settings(), app->network()));
scrobbler->AddService(make_shared<LibreFMScrobbler>(scrobbler->settings(), app->network()));
scrobbler->AddService(make_shared<ListenBrainzScrobbler>(scrobbler->settings(), app->network()));
#ifdef HAVE_SUBSONIC
scrobbler->AddService(make_shared<SubsonicScrobbler>(scrobbler->settings(), app));
#endif
return scrobbler;
}),
#ifdef HAVE_MOODBAR
moodbar_loader_([app]() { return new MoodbarLoader(app, app); }),
moodbar_controller_([app]() { return new MoodbarController(app, app); }),
moodbar_loader_([app]() { return new MoodbarLoader(app); }),
moodbar_controller_([app]() { return new MoodbarController(app); }),
#endif
lastfm_import_([app]() { return new LastFMImport(app->network(), app); })
lastfm_import_([app]() { return new LastFMImport(app->network()); })
{}
Lazy<TagReaderClient> tag_reader_client_;
@@ -227,17 +232,13 @@ Application::Application(QObject *parent)
collection()->Init();
tag_reader_client();
QObject::connect(database(), &Database::Error, this, &Application::ErrorAdded);
QObject::connect(&*database(), &Database::Error, this, &Application::ErrorAdded);
}
Application::~Application() {
// It's important that the device manager is deleted before the database.
// Deleting the database deletes all objects that have been created in its thread, including some device collection backends.
#ifndef Q_OS_WIN
p_->device_manager_.reset();
#endif
qLog(Debug) << "Terminating application";
for (QThread *thread : threads_) {
thread->quit();
@@ -271,37 +272,37 @@ void Application::MoveToThread(QObject *object, QThread *thread) {
void Application::Exit() {
wait_for_exit_ << tag_reader_client()
<< collection()
<< playlist_backend()
<< album_cover_loader()
wait_for_exit_ << &*tag_reader_client()
<< &*collection()
<< &*playlist_backend()
<< &*album_cover_loader()
#ifndef Q_OS_WIN
<< device_manager()
<< &*device_manager()
#endif
<< internet_services()
<< radio_services()->radio_backend();
<< &*internet_services()
<< &*radio_services()->radio_backend();
QObject::connect(tag_reader_client(), &TagReaderClient::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*tag_reader_client(), &TagReaderClient::ExitFinished, this, &Application::ExitReceived);
tag_reader_client()->ExitAsync();
QObject::connect(collection(), &SCollection::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*collection(), &SCollection::ExitFinished, this, &Application::ExitReceived);
collection()->Exit();
QObject::connect(playlist_backend(), &PlaylistBackend::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*playlist_backend(), &PlaylistBackend::ExitFinished, this, &Application::ExitReceived);
playlist_backend()->ExitAsync();
QObject::connect(album_cover_loader(), &AlbumCoverLoader::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*album_cover_loader(), &AlbumCoverLoader::ExitFinished, this, &Application::ExitReceived);
album_cover_loader()->ExitAsync();
#ifndef Q_OS_WIN
QObject::connect(device_manager(), &DeviceManager::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*device_manager(), &DeviceManager::ExitFinished, this, &Application::ExitReceived);
device_manager()->Exit();
#endif
QObject::connect(internet_services(), &InternetServices::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*internet_services(), &InternetServices::ExitFinished, this, &Application::ExitReceived);
internet_services()->Exit();
QObject::connect(radio_services()->radio_backend(), &RadioBackend::ExitFinished, this, &Application::ExitReceived);
QObject::connect(&*radio_services()->radio_backend(), &RadioBackend::ExitFinished, this, &Application::ExitReceived);
radio_services()->radio_backend()->ExitAsync();
}
@@ -316,7 +317,7 @@ void Application::ExitReceived() {
wait_for_exit_.removeAll(obj);
if (wait_for_exit_.isEmpty()) {
database()->Close();
QObject::connect(database(), &Database::ExitFinished, this, &Application::ExitFinished);
QObject::connect(&*database(), &Database::ExitFinished, this, &Application::ExitFinished);
database()->ExitAsync();
}
@@ -326,29 +327,29 @@ void Application::AddError(const QString &message) { emit ErrorAdded(message); }
void Application::ReloadSettings() { emit SettingsChanged(); }
void Application::OpenSettingsDialogAtPage(SettingsDialog::Page page) { emit SettingsDialogRequested(page); }
TagReaderClient *Application::tag_reader_client() const { return p_->tag_reader_client_.get(); }
Database *Application::database() const { return p_->database_.get(); }
TaskManager *Application::task_manager() const { return p_->task_manager_.get(); }
Player *Application::player() const { return p_->player_.get(); }
NetworkAccessManager *Application::network() const { return p_->network_.get(); }
DeviceFinders *Application::device_finders() const { return p_->device_finders_.get(); }
SharedPtr<TagReaderClient> Application::tag_reader_client() const { return p_->tag_reader_client_.ptr(); }
SharedPtr<Database> Application::database() const { return p_->database_.ptr(); }
SharedPtr<TaskManager> Application::task_manager() const { return p_->task_manager_.ptr(); }
SharedPtr<Player> Application::player() const { return p_->player_.ptr(); }
SharedPtr<NetworkAccessManager> Application::network() const { return p_->network_.ptr(); }
SharedPtr<DeviceFinders> Application::device_finders() const { return p_->device_finders_.ptr(); }
#ifndef Q_OS_WIN
DeviceManager *Application::device_manager() const { return p_->device_manager_.get(); }
SharedPtr<DeviceManager> Application::device_manager() const { return p_->device_manager_.ptr(); }
#endif
SCollection *Application::collection() const { return p_->collection_.get(); }
CollectionBackend *Application::collection_backend() const { return collection()->backend(); }
SharedPtr<SCollection> Application::collection() const { return p_->collection_.ptr(); }
SharedPtr<CollectionBackend> Application::collection_backend() const { return collection()->backend(); }
CollectionModel *Application::collection_model() const { return collection()->model(); }
AlbumCoverLoader *Application::album_cover_loader() const { return p_->album_cover_loader_.get(); }
CoverProviders *Application::cover_providers() const { return p_->cover_providers_.get(); }
CurrentAlbumCoverLoader *Application::current_albumcover_loader() const { return p_->current_albumcover_loader_.get(); }
LyricsProviders *Application::lyrics_providers() const { return p_->lyrics_providers_.get(); }
PlaylistBackend *Application::playlist_backend() const { return p_->playlist_backend_.get(); }
PlaylistManager *Application::playlist_manager() const { return p_->playlist_manager_.get(); }
InternetServices *Application::internet_services() const { return p_->internet_services_.get(); }
RadioServices *Application::radio_services() const { return p_->radio_services_.get(); }
AudioScrobbler *Application::scrobbler() const { return p_->scrobbler_.get(); }
LastFMImport *Application::lastfm_import() const { return p_->lastfm_import_.get(); }
SharedPtr<AlbumCoverLoader> Application::album_cover_loader() const { return p_->album_cover_loader_.ptr(); }
SharedPtr<CoverProviders> Application::cover_providers() const { return p_->cover_providers_.ptr(); }
SharedPtr<CurrentAlbumCoverLoader> Application::current_albumcover_loader() const { return p_->current_albumcover_loader_.ptr(); }
SharedPtr<LyricsProviders> Application::lyrics_providers() const { return p_->lyrics_providers_.ptr(); }
SharedPtr<PlaylistBackend> Application::playlist_backend() const { return p_->playlist_backend_.ptr(); }
SharedPtr<PlaylistManager> Application::playlist_manager() const { return p_->playlist_manager_.ptr(); }
SharedPtr<InternetServices> Application::internet_services() const { return p_->internet_services_.ptr(); }
SharedPtr<RadioServices> Application::radio_services() const { return p_->radio_services_.ptr(); }
SharedPtr<AudioScrobbler> Application::scrobbler() const { return p_->scrobbler_.ptr(); }
SharedPtr<LastFMImport> Application::lastfm_import() const { return p_->lastfm_import_.ptr(); }
#ifdef HAVE_MOODBAR
MoodbarController *Application::moodbar_controller() const { return p_->moodbar_controller_.get(); }
MoodbarLoader *Application::moodbar_loader() const { return p_->moodbar_loader_.get(); }
SharedPtr<MoodbarController> Application::moodbar_controller() const { return p_->moodbar_controller_.ptr(); }
SharedPtr<MoodbarLoader> Application::moodbar_loader() const { return p_->moodbar_loader_.ptr(); }
#endif

View File

@@ -25,12 +25,13 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QList>
#include <QString>
#include "scoped_ptr.h"
#include "shared_ptr.h"
#include "settings/settingsdialog.h"
class QThread;
@@ -71,40 +72,40 @@ class Application : public QObject {
explicit Application(QObject *parent = nullptr);
~Application() override;
TagReaderClient *tag_reader_client() const;
Database *database() const;
TaskManager *task_manager() const;
Player *player() const;
NetworkAccessManager *network() const;
DeviceFinders *device_finders() const;
SharedPtr<TagReaderClient> tag_reader_client() const;
SharedPtr<Database> database() const;
SharedPtr<TaskManager> task_manager() const;
SharedPtr<Player> player() const;
SharedPtr<NetworkAccessManager> network() const;
SharedPtr<DeviceFinders> device_finders() const;
#ifndef Q_OS_WIN
DeviceManager *device_manager() const;
SharedPtr<DeviceManager> device_manager() const;
#endif
SCollection *collection() const;
CollectionBackend *collection_backend() const;
SharedPtr<SCollection> collection() const;
SharedPtr<CollectionBackend> collection_backend() const;
CollectionModel *collection_model() const;
PlaylistBackend *playlist_backend() const;
PlaylistManager *playlist_manager() const;
SharedPtr<PlaylistBackend> playlist_backend() const;
SharedPtr<PlaylistManager> playlist_manager() const;
CoverProviders *cover_providers() const;
AlbumCoverLoader *album_cover_loader() const;
CurrentAlbumCoverLoader *current_albumcover_loader() const;
SharedPtr<CoverProviders> cover_providers() const;
SharedPtr<AlbumCoverLoader> album_cover_loader() const;
SharedPtr<CurrentAlbumCoverLoader> current_albumcover_loader() const;
LyricsProviders *lyrics_providers() const;
SharedPtr<LyricsProviders> lyrics_providers() const;
AudioScrobbler *scrobbler() const;
SharedPtr<AudioScrobbler> scrobbler() const;
InternetServices *internet_services() const;
RadioServices *radio_services() const;
SharedPtr<InternetServices> internet_services() const;
SharedPtr<RadioServices> radio_services() const;
#ifdef HAVE_MOODBAR
MoodbarController *moodbar_controller() const;
MoodbarLoader *moodbar_loader() const;
SharedPtr<MoodbarController> moodbar_controller() const;
SharedPtr<MoodbarLoader> moodbar_loader() const;
#endif
LastFMImport *lastfm_import() const;
SharedPtr<LastFMImport> lastfm_import() const;
void Exit();
@@ -127,7 +128,7 @@ class Application : public QObject {
void ClearPixmapDiskCache();
private:
std::unique_ptr<ApplicationImpl> p_;
ScopedPtr<ApplicationImpl> p_;
QList<QThread*> threads_;
QList<QObject*> wait_for_exit_;

View File

@@ -28,6 +28,7 @@
#include <QUrl>
#include <QMetaObject>
#include "shared_ptr.h"
#include "taskmanager.h"
#include "song.h"
#include "deletefiles.h"
@@ -35,7 +36,7 @@
const int DeleteFiles::kBatchSize = 50;
DeleteFiles::DeleteFiles(TaskManager *task_manager, std::shared_ptr<MusicStorage> storage, const bool use_trash, QObject *parent)
DeleteFiles::DeleteFiles(SharedPtr<TaskManager> task_manager, SharedPtr<MusicStorage> storage, const bool use_trash, QObject *parent)
: QObject(parent),
thread_(nullptr),
task_manager_(task_manager),

View File

@@ -24,11 +24,10 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QStringList>
#include "shared_ptr.h"
#include "song.h"
class QThread;
@@ -39,7 +38,7 @@ class DeleteFiles : public QObject {
Q_OBJECT
public:
explicit DeleteFiles(TaskManager *task_manager, std::shared_ptr<MusicStorage> storage, const bool use_trash, QObject *parent = nullptr);
explicit DeleteFiles(SharedPtr<TaskManager> task_manager, SharedPtr<MusicStorage> storage, const bool use_trash, QObject *parent = nullptr);
~DeleteFiles() override;
static const int kBatchSize;
@@ -56,8 +55,8 @@ class DeleteFiles : public QObject {
private:
QThread *thread_;
QThread *original_thread_;
TaskManager *task_manager_;
std::shared_ptr<MusicStorage> storage_;
SharedPtr<TaskManager> task_manager_;
SharedPtr<MusicStorage> storage_;
SongList songs_;
bool use_trash_;

View File

@@ -19,7 +19,11 @@
#define LAZY_H
#include <functional>
#include <memory>
#include <type_traits>
#include "core/logging.h"
#include "shared_ptr.h"
// Helper for lazy initialization of objects.
// Usage:
@@ -38,6 +42,11 @@ class Lazy {
return ptr_.get();
}
SharedPtr<T> ptr() const {
CheckInitialized();
return ptr_;
}
typename std::add_lvalue_reference<T>::type operator*() const {
CheckInitialized();
return *ptr_;
@@ -54,12 +63,13 @@ class Lazy {
private:
void CheckInitialized() const {
if (!ptr_) {
ptr_.reset(init_(), [](T*obj) { obj->deleteLater(); });
ptr_ = SharedPtr<T>(init_(), [](T*obj) { qLog(Debug) << obj << "deleted"; delete obj; });
qLog(Debug) << &*ptr_ << "created";
}
}
const std::function<T*()> init_;
mutable std::shared_ptr<T> ptr_;
mutable SharedPtr<T> ptr_;
};
#endif // LAZY_H

View File

@@ -24,13 +24,12 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QUrl>
#include <QPixmap>
#include <QAction>
#include "scoped_ptr.h"
#include "song.h"
class MacSystemTrayIconPrivate;
@@ -85,7 +84,7 @@ class SystemTrayIcon : public QObject {
void PlayPause();
private:
std::unique_ptr<MacSystemTrayIconPrivate> p_;
ScopedPtr<MacSystemTrayIconPrivate> p_;
QPixmap normal_icon_;
QPixmap grey_icon_;

View File

@@ -22,11 +22,11 @@
#include "config.h"
#include "version.h"
#include <memory>
#include <cmath>
#include <functional>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <memory>
#include <QMainWindow>
#include <QApplication>
@@ -79,6 +79,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "shared_ptr.h"
#include "commandlineoptions.h"
#include "mimedata.h"
#include "iconloader.h"
@@ -166,7 +167,6 @@
#include "settings/playlistsettingspage.h"
#ifdef HAVE_SUBSONIC
# include "settings/subsonicsettingspage.h"
# include "scrobbler/subsonicscrobbler.h"
#endif
#ifdef HAVE_TIDAL
# include "tidal/tidalservice.h"
@@ -212,6 +212,8 @@
# endif
#endif // HAVE_QTSPARKLE
using std::make_unique;
using std::make_shared;
using namespace std::chrono_literals;
const char *MainWindow::kSettingsGroup = "MainWindow";
@@ -238,7 +240,7 @@ constexpr char QTSPARKLE_URL[] = "https://www.strawberrymusicplayer.org/sparkle-
# endif
#endif
MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent)
MainWindow::MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent)
: QMainWindow(parent),
ui_(new Ui_MainWindow),
#ifdef Q_OS_WIN
@@ -397,7 +399,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
// Start initializing the player
qLog(Debug) << "Initializing player";
app_->player()->SetAnalyzer(ui_->analyzer);
app_->player()->SetEqualizer(equalizer_.get());
app_->player()->SetEqualizer(equalizer_);
app_->player()->Init();
EngineChanged(app_->player()->engine()->type());
const uint volume = app_->player()->GetVolume();
@@ -504,17 +506,17 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
file_view_->SetTaskManager(app_->task_manager());
// Action connections
QObject::connect(ui_->action_next_track, &QAction::triggered, app_->player(), &Player::Next);
QObject::connect(ui_->action_previous_track, &QAction::triggered, app_->player(), &Player::Previous);
QObject::connect(ui_->action_play_pause, &QAction::triggered, app_->player(), &Player::PlayPauseHelper);
QObject::connect(ui_->action_stop, &QAction::triggered, app_->player(), &Player::Stop);
QObject::connect(ui_->action_next_track, &QAction::triggered, &*app_->player(), &Player::Next);
QObject::connect(ui_->action_previous_track, &QAction::triggered, &*app_->player(), &Player::Previous);
QObject::connect(ui_->action_play_pause, &QAction::triggered, &*app_->player(), &Player::PlayPauseHelper);
QObject::connect(ui_->action_stop, &QAction::triggered, &*app_->player(), &Player::Stop);
QObject::connect(ui_->action_quit, &QAction::triggered, this, &MainWindow::Exit);
QObject::connect(ui_->action_stop_after_this_track, &QAction::triggered, this, &MainWindow::StopAfterCurrent);
QObject::connect(ui_->action_mute, &QAction::triggered, app_->player(), &Player::Mute);
QObject::connect(ui_->action_mute, &QAction::triggered, &*app_->player(), &Player::Mute);
QObject::connect(ui_->action_clear_playlist, &QAction::triggered, this, &MainWindow::PlaylistClearCurrent);
QObject::connect(ui_->action_remove_duplicates, &QAction::triggered, app_->playlist_manager(), &PlaylistManager::RemoveDuplicatesCurrent);
QObject::connect(ui_->action_remove_unavailable, &QAction::triggered, app_->playlist_manager(), &PlaylistManager::RemoveUnavailableCurrent);
QObject::connect(ui_->action_remove_duplicates, &QAction::triggered, &*app_->playlist_manager(), &PlaylistManager::RemoveDuplicatesCurrent);
QObject::connect(ui_->action_remove_unavailable, &QAction::triggered, &*app_->playlist_manager(), &PlaylistManager::RemoveUnavailableCurrent);
QObject::connect(ui_->action_remove_from_playlist, &QAction::triggered, this, &MainWindow::PlaylistRemoveCurrent);
QObject::connect(ui_->action_edit_track, &QAction::triggered, this, &MainWindow::EditTracks);
QObject::connect(ui_->action_renumber_tracks, &QAction::triggered, this, &MainWindow::RenumberTracks);
@@ -528,7 +530,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
QObject::connect(ui_->action_toggle_show_sidebar, &QAction::toggled, this, &MainWindow::ToggleSidebar);
QObject::connect(ui_->action_about_strawberry, &QAction::triggered, this, &MainWindow::ShowAboutDialog);
QObject::connect(ui_->action_about_qt, &QAction::triggered, qApp, &QApplication::aboutQt);
QObject::connect(ui_->action_shuffle, &QAction::triggered, app_->playlist_manager(), &PlaylistManager::ShuffleCurrent);
QObject::connect(ui_->action_shuffle, &QAction::triggered, &*app_->playlist_manager(), &PlaylistManager::ShuffleCurrent);
QObject::connect(ui_->action_open_file, &QAction::triggered, this, &MainWindow::AddFile);
QObject::connect(ui_->action_open_cd, &QAction::triggered, this, &MainWindow::AddCDTracks);
QObject::connect(ui_->action_add_file, &QAction::triggered, this, &MainWindow::AddFile);
@@ -542,9 +544,9 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
ui_->action_transcoder->setDisabled(true);
#endif
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_full_collection_scan, &QAction::triggered, app_->collection(), &SCollection::FullScan);
QObject::connect(ui_->action_abort_collection_scan, &QAction::triggered, app_->collection(), &SCollection::AbortScan);
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_abort_collection_scan, &QAction::triggered, &*app_->collection(), &SCollection::AbortScan);
#if defined(HAVE_GSTREAMER)
QObject::connect(ui_->action_add_files_to_transcoder, &QAction::triggered, this, &MainWindow::AddFilesToTranscoder);
ui_->action_add_files_to_transcoder->setIcon(IconLoader::Load("tools-wizard"));
@@ -552,9 +554,9 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
ui_->action_add_files_to_transcoder->setDisabled(true);
#endif
QObject::connect(ui_->action_toggle_scrobbling, &QAction::triggered, app_->scrobbler(), &AudioScrobbler::ToggleScrobbling);
QObject::connect(ui_->action_toggle_scrobbling, &QAction::triggered, &*app_->scrobbler(), &AudioScrobbler::ToggleScrobbling);
QObject::connect(ui_->action_love, &QAction::triggered, this, &MainWindow::Love);
QObject::connect(app_->scrobbler(), &AudioScrobbler::ErrorMessage, this, &MainWindow::ShowErrorDialog);
QObject::connect(&*app_->scrobbler(), &AudioScrobbler::ErrorMessage, this, &MainWindow::ShowErrorDialog);
// Playlist view actions
ui_->action_next_playlist->setShortcuts(QList<QKeySequence>() << QKeySequence::fromString("Ctrl+Tab") << QKeySequence::fromString("Ctrl+PgDown"));
@@ -584,55 +586,55 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
ui_->stop_button->setMenu(stop_menu);
// Player connections
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, app_->player(), &Player::SetVolumeFromSlider);
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, &*app_->player(), &Player::SetVolumeFromSlider);
QObject::connect(app_->player(), &Player::EngineChanged, this, &MainWindow::EngineChanged);
QObject::connect(app_->player(), &Player::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(app_->player(), &Player::SongChangeRequestProcessed, app_->playlist_manager(), &PlaylistManager::SongChangeRequestProcessed);
QObject::connect(&*app_->player(), &Player::EngineChanged, this, &MainWindow::EngineChanged);
QObject::connect(&*app_->player(), &Player::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(&*app_->player(), &Player::SongChangeRequestProcessed, &*app_->playlist_manager(), &PlaylistManager::SongChangeRequestProcessed);
QObject::connect(app_->player(), &Player::Paused, this, &MainWindow::MediaPaused);
QObject::connect(app_->player(), &Player::Playing, this, &MainWindow::MediaPlaying);
QObject::connect(app_->player(), &Player::Stopped, this, &MainWindow::MediaStopped);
QObject::connect(app_->player(), &Player::Seeked, this, &MainWindow::Seeked);
QObject::connect(app_->player(), &Player::TrackSkipped, this, &MainWindow::TrackSkipped);
QObject::connect(app_->player(), &Player::VolumeChanged, this, &MainWindow::VolumeChanged);
QObject::connect(&*app_->player(), &Player::Paused, this, &MainWindow::MediaPaused);
QObject::connect(&*app_->player(), &Player::Playing, this, &MainWindow::MediaPlaying);
QObject::connect(&*app_->player(), &Player::Stopped, this, &MainWindow::MediaStopped);
QObject::connect(&*app_->player(), &Player::Seeked, this, &MainWindow::Seeked);
QObject::connect(&*app_->player(), &Player::TrackSkipped, this, &MainWindow::TrackSkipped);
QObject::connect(&*app_->player(), &Player::VolumeChanged, this, &MainWindow::VolumeChanged);
QObject::connect(app_->player(), &Player::Paused, ui_->playlist, &PlaylistContainer::ActivePaused);
QObject::connect(app_->player(), &Player::Playing, ui_->playlist, &PlaylistContainer::ActivePlaying);
QObject::connect(app_->player(), &Player::Stopped, ui_->playlist, &PlaylistContainer::ActiveStopped);
QObject::connect(&*app_->player(), &Player::Paused, ui_->playlist, &PlaylistContainer::ActivePaused);
QObject::connect(&*app_->player(), &Player::Playing, ui_->playlist, &PlaylistContainer::ActivePlaying);
QObject::connect(&*app_->player(), &Player::Stopped, ui_->playlist, &PlaylistContainer::ActiveStopped);
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, osd_, &OSDBase::SongChanged);
QObject::connect(app_->player(), &Player::Paused, osd_, &OSDBase::Paused);
QObject::connect(app_->player(), &Player::Resumed, osd_, &OSDBase::Resumed);
QObject::connect(app_->player(), &Player::Stopped, osd_, &OSDBase::Stopped);
QObject::connect(app_->player(), &Player::PlaylistFinished, osd_, &OSDBase::PlaylistFinished);
QObject::connect(app_->player(), &Player::VolumeChanged, osd_, &OSDBase::VolumeChanged);
QObject::connect(app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValue);
QObject::connect(app_->player(), &Player::ForceShowOSD, this, &MainWindow::ForceShowOSD);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, osd_, &OSDBase::SongChanged);
QObject::connect(&*app_->player(), &Player::Paused, osd_, &OSDBase::Paused);
QObject::connect(&*app_->player(), &Player::Resumed, osd_, &OSDBase::Resumed);
QObject::connect(&*app_->player(), &Player::Stopped, osd_, &OSDBase::Stopped);
QObject::connect(&*app_->player(), &Player::PlaylistFinished, osd_, &OSDBase::PlaylistFinished);
QObject::connect(&*app_->player(), &Player::VolumeChanged, osd_, &OSDBase::VolumeChanged);
QObject::connect(&*app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValue);
QObject::connect(&*app_->player(), &Player::ForceShowOSD, this, &MainWindow::ForceShowOSD);
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::EditingFinished, this, &MainWindow::PlaylistEditFinished);
QObject::connect(app_->playlist_manager(), &PlaylistManager::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(app_->playlist_manager(), &PlaylistManager::SummaryTextChanged, ui_->playlist_summary, &QLabel::setText);
QObject::connect(app_->playlist_manager(), &PlaylistManager::PlayRequested, this, &MainWindow::PlayIndex);
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::EditingFinished, this, &MainWindow::PlaylistEditFinished);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::SummaryTextChanged, ui_->playlist_summary, &QLabel::setText);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::PlayRequested, this, &MainWindow::PlayIndex);
QObject::connect(ui_->playlist->view(), &PlaylistView::doubleClicked, this, &MainWindow::PlaylistDoubleClick);
QObject::connect(ui_->playlist->view(), &PlaylistView::PlayItem, this, &MainWindow::PlayIndex);
QObject::connect(ui_->playlist->view(), &PlaylistView::PlayPause, app_->player(), &Player::PlayPause);
QObject::connect(ui_->playlist->view(), &PlaylistView::PlayPause, &*app_->player(), &Player::PlayPause);
QObject::connect(ui_->playlist->view(), &PlaylistView::RightClicked, this, &MainWindow::PlaylistRightClick);
QObject::connect(ui_->playlist->view(), &PlaylistView::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(ui_->playlist->view(), &PlaylistView::SeekBackward, app_->player(), &Player::SeekBackward);
QObject::connect(ui_->playlist->view(), &PlaylistView::SeekForward, &*app_->player(), &Player::SeekForward);
QObject::connect(ui_->playlist->view(), &PlaylistView::SeekBackward, &*app_->player(), &Player::SeekBackward);
QObject::connect(ui_->playlist->view(), &PlaylistView::BackgroundPropertyChanged, this, &MainWindow::RefreshStyleSheet);
QObject::connect(ui_->track_slider, &TrackSlider::ValueChangedSeconds, app_->player(), &Player::SeekTo);
QObject::connect(ui_->track_slider, &TrackSlider::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(ui_->track_slider, &TrackSlider::SeekBackward, app_->player(), &Player::SeekBackward);
QObject::connect(ui_->track_slider, &TrackSlider::Previous, app_->player(), &Player::Previous);
QObject::connect(ui_->track_slider, &TrackSlider::Next, app_->player(), &Player::Next);
QObject::connect(ui_->track_slider, &TrackSlider::ValueChangedSeconds, &*app_->player(), &Player::SeekTo);
QObject::connect(ui_->track_slider, &TrackSlider::SeekForward, &*app_->player(), &Player::SeekForward);
QObject::connect(ui_->track_slider, &TrackSlider::SeekBackward, &*app_->player(), &Player::SeekBackward);
QObject::connect(ui_->track_slider, &TrackSlider::Previous, &*app_->player(), &Player::Previous);
QObject::connect(ui_->track_slider, &TrackSlider::Next, &*app_->player(), &Player::Next);
// Collection connections
QObject::connect(app_->collection(), &SCollection::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(&*app_->collection(), &SCollection::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(collection_view_->view(), &CollectionView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
QObject::connect(collection_view_->view(), &CollectionView::ShowConfigDialog, this, &MainWindow::ShowCollectionConfig);
QObject::connect(collection_view_->view(), &CollectionView::Error, this, &MainWindow::ShowErrorDialog);
@@ -642,10 +644,10 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
QObject::connect(app_->collection_model(), &CollectionModel::modelAboutToBeReset, collection_view_->view(), &CollectionView::SaveFocus);
QObject::connect(app_->collection_model(), &CollectionModel::modelReset, collection_view_->view(), &CollectionView::RestoreFocus);
QObject::connect(app_->task_manager(), &TaskManager::PauseCollectionWatchers, app_->collection(), &SCollection::PauseWatcher);
QObject::connect(app_->task_manager(), &TaskManager::ResumeCollectionWatchers, app_->collection(), &SCollection::ResumeWatcher);
QObject::connect(&*app_->task_manager(), &TaskManager::PauseCollectionWatchers, &*app_->collection(), &SCollection::PauseWatcher);
QObject::connect(&*app_->task_manager(), &TaskManager::ResumeCollectionWatchers, &*app_->collection(), &SCollection::ResumeWatcher);
QObject::connect(app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &MainWindow::AlbumCoverLoaded);
QObject::connect(&*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &MainWindow::AlbumCoverLoaded);
QObject::connect(album_cover_choice_controller_, &AlbumCoverChoiceController::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(album_cover_choice_controller_->cover_from_file_action(), &QAction::triggered, this, &MainWindow::LoadCoverFromFile);
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &MainWindow::SaveCoverToFile);
@@ -700,8 +702,8 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
QObject::connect(tidal_view_->albums_collection_view(), &InternetCollectionView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
QObject::connect(tidal_view_->songs_collection_view(), &InternetCollectionView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
QObject::connect(tidal_view_->search_view(), &InternetSearchView::AddToPlaylist, this, &MainWindow::AddToPlaylist);
if (TidalService *tidalservice = qobject_cast<TidalService*>(app_->internet_services()->ServiceBySource(Song::Source::Tidal))) {
QObject::connect(this, &MainWindow::AuthorizationUrlReceived, tidalservice, &TidalService::AuthorizationUrlReceived);
if (TidalServicePtr tidalservice = app_->internet_services()->Service<TidalService>()) {
QObject::connect(this, &MainWindow::AuthorizationUrlReceived, &*tidalservice, &TidalService::AuthorizationUrlReceived);
}
#endif
@@ -712,8 +714,8 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
QObject::connect(qobuz_view_->search_view(), &InternetSearchView::AddToPlaylist, this, &MainWindow::AddToPlaylist);
#endif
QObject::connect(radio_view_, &RadioViewContainer::Refresh, app_->radio_services(), &RadioServices::RefreshChannels);
QObject::connect(radio_view_->view(), &RadioView::GetChannels, app_->radio_services(), &RadioServices::GetChannels);
QObject::connect(radio_view_, &RadioViewContainer::Refresh, &*app_->radio_services(), &RadioServices::RefreshChannels);
QObject::connect(radio_view_->view(), &RadioView::GetChannels, &*app_->radio_services(), &RadioServices::GetChannels);
QObject::connect(radio_view_->view(), &RadioView::AddToPlaylistSignal, this, &MainWindow::AddToPlaylist);
// Playlist menu
@@ -777,22 +779,22 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
QObject::connect(app_->device_manager()->connected_devices_model(), &DeviceStateFilterModel::IsEmptyChanged, playlist_copy_to_device_, &QAction::setDisabled);
#endif
QObject::connect(app_->scrobbler(), &AudioScrobbler::ScrobblingEnabledChanged, this, &MainWindow::ScrobblingEnabledChanged);
QObject::connect(app_->scrobbler(), &AudioScrobbler::ScrobbleButtonVisibilityChanged, this, &MainWindow::ScrobbleButtonVisibilityChanged);
QObject::connect(app_->scrobbler(), &AudioScrobbler::LoveButtonVisibilityChanged, this, &MainWindow::LoveButtonVisibilityChanged);
QObject::connect(&*app_->scrobbler()->settings(), &ScrobblerSettings::ScrobblingEnabledChanged, this, &MainWindow::ScrobblingEnabledChanged);
QObject::connect(&*app_->scrobbler()->settings(), &ScrobblerSettings::ScrobbleButtonVisibilityChanged, this, &MainWindow::ScrobbleButtonVisibilityChanged);
QObject::connect(&*app_->scrobbler()->settings(), &ScrobblerSettings::LoveButtonVisibilityChanged, this, &MainWindow::LoveButtonVisibilityChanged);
#ifdef Q_OS_MACOS
mac::SetApplicationHandler(this);
#endif
// Tray icon
tray_icon_->SetupMenu(ui_->action_previous_track, ui_->action_play_pause, ui_->action_stop, ui_->action_stop_after_this_track, ui_->action_next_track, ui_->action_mute, ui_->action_love, ui_->action_quit);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::PlayPause, app_->player(), &Player::PlayPauseHelper);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::SeekBackward, app_->player(), &Player::SeekBackward);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::NextTrack, app_->player(), &Player::Next);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::PreviousTrack, app_->player(), &Player::Previous);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::ShowHide, this, &MainWindow::ToggleShowHide);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::ChangeVolume, this, &MainWindow::VolumeWheelEvent);
QObject::connect(&*tray_icon_, &SystemTrayIcon::PlayPause, &*app_->player(), &Player::PlayPauseHelper);
QObject::connect(&*tray_icon_, &SystemTrayIcon::SeekForward, &*app_->player(), &Player::SeekForward);
QObject::connect(&*tray_icon_, &SystemTrayIcon::SeekBackward, &*app_->player(), &Player::SeekBackward);
QObject::connect(&*tray_icon_, &SystemTrayIcon::NextTrack, &*app_->player(), &Player::Next);
QObject::connect(&*tray_icon_, &SystemTrayIcon::PreviousTrack, &*app_->player(), &Player::Previous);
QObject::connect(&*tray_icon_, &SystemTrayIcon::ShowHide, this, &MainWindow::ToggleShowHide);
QObject::connect(&*tray_icon_, &SystemTrayIcon::ChangeVolume, this, &MainWindow::VolumeWheelEvent);
// Windows 7 thumbbar buttons
#ifdef Q_OS_WIN
@@ -806,35 +808,35 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
#ifdef HAVE_GLOBALSHORTCUTS
// Global shortcuts
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Play, app_->player(), &Player::PlayHelper);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Pause, app_->player(), &Player::Pause);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Play, &*app_->player(), &Player::PlayHelper);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Pause, &*app_->player(), &Player::Pause);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::PlayPause, ui_->action_play_pause, &QAction::trigger);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Stop, ui_->action_stop, &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::Previous, ui_->action_previous_track, &QAction::trigger);
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::Mute, app_->player(), &Player::Mute);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::SeekBackward, app_->player(), &Player::SeekBackward);
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::Mute, &*app_->player(), &Player::Mute);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::SeekForward, &*app_->player(), &Player::SeekForward);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::SeekBackward, &*app_->player(), &Player::SeekBackward);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::ShowHide, this, &MainWindow::ToggleShowHide);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::ShowOSD, app_->player(), &Player::ShowOSD);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::TogglePrettyOSD, app_->player(), &Player::TogglePrettyOSD);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::ToggleScrobbling, app_->scrobbler(), &AudioScrobbler::ToggleScrobbling);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Love, app_->scrobbler(), &AudioScrobbler::Love);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::ShowOSD, &*app_->player(), &Player::ShowOSD);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::TogglePrettyOSD, &*app_->player(), &Player::TogglePrettyOSD);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::ToggleScrobbling, &*app_->scrobbler(), &AudioScrobbler::ToggleScrobbling);
QObject::connect(globalshortcuts_manager_, &GlobalShortcutsManager::Love, &*app_->scrobbler(), &AudioScrobbler::Love);
#endif
// Fancy tabs
QObject::connect(ui_->tabs, &FancyTabWidget::CurrentChanged, this, &MainWindow::TabSwitched);
// Context
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, context_view_, &ContextView::SongChanged);
QObject::connect(app_->playlist_manager(), &PlaylistManager::SongMetadataChanged, context_view_, &ContextView::SongChanged);
QObject::connect(app_->player(), &Player::PlaylistFinished, context_view_, &ContextView::Stopped);
QObject::connect(app_->player(), &Player::Playing, context_view_, &ContextView::Playing);
QObject::connect(app_->player(), &Player::Stopped, context_view_, &ContextView::Stopped);
QObject::connect(app_->player(), &Player::Error, context_view_, &ContextView::Error);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, context_view_, &ContextView::SongChanged);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::SongMetadataChanged, context_view_, &ContextView::SongChanged);
QObject::connect(&*app_->player(), &Player::PlaylistFinished, context_view_, &ContextView::Stopped);
QObject::connect(&*app_->player(), &Player::Playing, context_view_, &ContextView::Playing);
QObject::connect(&*app_->player(), &Player::Stopped, context_view_, &ContextView::Stopped);
QObject::connect(&*app_->player(), &Player::Error, context_view_, &ContextView::Error);
QObject::connect(this, &MainWindow::AlbumCoverReady, context_view_, &ContextView::AlbumCoverLoaded);
QObject::connect(this, &MainWindow::SearchCoverInProgress, context_view_->album_widget(), &ContextAlbum::SearchCoverInProgress);
QObject::connect(context_view_, &ContextView::AlbumEnabledChanged, this, &MainWindow::TabSwitched);
@@ -851,17 +853,17 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
#ifdef HAVE_MOODBAR
// Moodbar connections
QObject::connect(app_->moodbar_controller(), &MoodbarController::CurrentMoodbarDataChanged, ui_->track_slider->moodbar_style(), &MoodbarProxyStyle::SetMoodbarData);
QObject::connect(&*app_->moodbar_controller(), &MoodbarController::CurrentMoodbarDataChanged, ui_->track_slider->moodbar_style(), &MoodbarProxyStyle::SetMoodbarData);
#endif
// Playing widget
qLog(Debug) << "Creating playing widget";
ui_->widget_playing->set_ideal_height(ui_->status_bar->sizeHint().height() + ui_->player_controls->sizeHint().height());
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, ui_->widget_playing, &PlayingWidget::SongChanged);
QObject::connect(app_->player(), &Player::PlaylistFinished, ui_->widget_playing, &PlayingWidget::Stopped);
QObject::connect(app_->player(), &Player::Playing, ui_->widget_playing, &PlayingWidget::Playing);
QObject::connect(app_->player(), &Player::Stopped, ui_->widget_playing, &PlayingWidget::Stopped);
QObject::connect(app_->player(), &Player::Error, ui_->widget_playing, &PlayingWidget::Error);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, ui_->widget_playing, &PlayingWidget::SongChanged);
QObject::connect(&*app_->player(), &Player::PlaylistFinished, ui_->widget_playing, &PlayingWidget::Stopped);
QObject::connect(&*app_->player(), &Player::Playing, ui_->widget_playing, &PlayingWidget::Playing);
QObject::connect(&*app_->player(), &Player::Stopped, ui_->widget_playing, &PlayingWidget::Stopped);
QObject::connect(&*app_->player(), &Player::Error, ui_->widget_playing, &PlayingWidget::Error);
QObject::connect(ui_->widget_playing, &PlayingWidget::ShowAboveStatusBarChanged, this, &MainWindow::PlayingWidgetPositionChanged);
QObject::connect(this, &MainWindow::AlbumCoverReady, ui_->widget_playing, &PlayingWidget::AlbumCoverLoaded);
QObject::connect(this, &MainWindow::SearchCoverInProgress, ui_->widget_playing, &PlayingWidget::SearchCoverInProgress);
@@ -891,15 +893,15 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
// Smart playlists
QObject::connect(smartplaylists_view_, &SmartPlaylistsViewContainer::AddToPlaylist, this, &MainWindow::AddToPlaylist);
ScrobbleButtonVisibilityChanged(app_->scrobbler()->ScrobbleButton());
LoveButtonVisibilityChanged(app_->scrobbler()->LoveButton());
ScrobblingEnabledChanged(app_->scrobbler()->IsEnabled());
ScrobbleButtonVisibilityChanged(app_->scrobbler()->scrobble_button());
LoveButtonVisibilityChanged(app_->scrobbler()->love_button());
ScrobblingEnabledChanged(app_->scrobbler()->enabled());
// Last.fm ImportData
QObject::connect(app_->lastfm_import(), &LastFMImport::Finished, lastfm_import_dialog_, &LastFMImportDialog::Finished);
QObject::connect(app_->lastfm_import(), &LastFMImport::FinishedWithError, lastfm_import_dialog_, &LastFMImportDialog::FinishedWithError);
QObject::connect(app_->lastfm_import(), &LastFMImport::UpdateTotal, lastfm_import_dialog_, &LastFMImportDialog::UpdateTotal);
QObject::connect(app_->lastfm_import(), &LastFMImport::UpdateProgress, lastfm_import_dialog_, &LastFMImportDialog::UpdateProgress);
QObject::connect(&*app_->lastfm_import(), &LastFMImport::Finished, lastfm_import_dialog_, &LastFMImportDialog::Finished);
QObject::connect(&*app_->lastfm_import(), &LastFMImport::FinishedWithError, lastfm_import_dialog_, &LastFMImportDialog::FinishedWithError);
QObject::connect(&*app_->lastfm_import(), &LastFMImport::UpdateTotal, lastfm_import_dialog_, &LastFMImportDialog::UpdateTotal);
QObject::connect(&*app_->lastfm_import(), &LastFMImport::UpdateProgress, lastfm_import_dialog_, &LastFMImportDialog::UpdateProgress);
// Load settings
qLog(Debug) << "Loading settings";
@@ -1008,7 +1010,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
if (!options.contains_play_options()) {
LoadPlaybackStatus();
}
if (app_->scrobbler()->IsEnabled() && !app_->scrobbler()->IsOffline()) {
if (app_->scrobbler()->enabled() && !app_->scrobbler()->offline()) {
app_->scrobbler()->Submit();
}
@@ -1134,7 +1136,6 @@ void MainWindow::ReloadSettings() {
else {
ui_->tabs->DisableTab(subsonic_view_);
}
app_->scrobbler()->Service<SubsonicScrobbler>()->ReloadSettings();
#endif
#ifdef HAVE_TIDAL
@@ -1239,7 +1240,7 @@ void MainWindow::Exit() {
else {
if (app_->player()->engine()->is_fadeout_enabled()) {
// To shut down the application when fadeout will be finished
QObject::connect(app_->player()->engine(), &EngineBase::FadeoutFinishedSignal, this, &MainWindow::DoExit);
QObject::connect(&*app_->player()->engine(), &EngineBase::FadeoutFinishedSignal, this, &MainWindow::DoExit);
if (app_->player()->GetState() == EngineBase::State::Playing) {
app_->player()->Stop();
ignore_close_ = true;
@@ -1355,7 +1356,7 @@ void MainWindow::SendNowPlaying() {
// Send now playing to scrobble services
Playlist *playlist = app_->playlist_manager()->active();
if (app_->scrobbler()->IsEnabled() && playlist && playlist->current_item() && playlist->current_item()->Metadata().is_metadata_good()) {
if (app_->scrobbler()->enabled() && playlist && playlist->current_item() && playlist->current_item()->Metadata().is_metadata_good()) {
app_->scrobbler()->UpdateNowPlaying(playlist->current_item()->Metadata());
ui_->action_love->setEnabled(true);
ui_->button_love->setEnabled(true);
@@ -1480,8 +1481,8 @@ void MainWindow::LoadPlaybackStatus() {
s.endGroup();
if (resume_playback && playback_state != EngineBase::State::Empty && playback_state != EngineBase::State::Idle) {
std::shared_ptr<QMetaObject::Connection> connection = std::make_shared<QMetaObject::Connection>();
*connection = QObject::connect(app_->playlist_manager(), &PlaylistManager::AllPlaylistsLoaded, this, [this, connection]() {
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);
});
@@ -1504,10 +1505,10 @@ void MainWindow::ResumePlayback() {
// Set active to current to resume playback on correct playlist.
app_->playlist_manager()->SetActiveToCurrent();
if (playback_state == EngineBase::State::Paused) {
std::shared_ptr<QMetaObject::Connection> connection = std::make_shared<QMetaObject::Connection>();
*connection = QObject::connect(app_->player(), &Player::Playing, app_->player(), [this, connection]() {
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);
QTimer::singleShot(300, &*app_->player(), &Player::PlayPauseHelper);
});
}
app_->player()->Play(playback_position * kNsecPerSec);
@@ -1682,7 +1683,7 @@ void MainWindow::UpdateTrackPosition() {
if (position % 10 == 0) tray_icon_->SetProgress(static_cast<int>(static_cast<double>(position) / static_cast<double>(length) * 100.0));
// Send Scrobble
if (app_->scrobbler()->IsEnabled() && item->Metadata().is_metadata_good()) {
if (app_->scrobbler()->enabled() && item->Metadata().is_metadata_good()) {
Playlist *playlist = app_->playlist_manager()->active();
if (playlist && !playlist->scrobbled()) {
const qint64 scrobble_point = (playlist->scrobble_point_nanosec() / kNsecPerSec);
@@ -2926,15 +2927,15 @@ void MainWindow::AutoCompleteTags() {
// Create the tag fetching stuff if it hasn't been already
if (!tag_fetcher_) {
tag_fetcher_ = std::make_unique<TagFetcher>(app_->network());
track_selection_dialog_ = std::make_unique<TrackSelectionDialog>();
tag_fetcher_ = make_unique<TagFetcher>(app_->network());
track_selection_dialog_ = make_unique<TrackSelectionDialog>();
track_selection_dialog_->set_save_on_close(true);
QObject::connect(tag_fetcher_.get(), &TagFetcher::ResultAvailable, track_selection_dialog_.get(), &TrackSelectionDialog::FetchTagFinished, Qt::QueuedConnection);
QObject::connect(tag_fetcher_.get(), &TagFetcher::Progress, track_selection_dialog_.get(), &TrackSelectionDialog::FetchTagProgress);
QObject::connect(track_selection_dialog_.get(), &TrackSelectionDialog::accepted, this, &MainWindow::AutoCompleteTagsAccepted);
QObject::connect(track_selection_dialog_.get(), &TrackSelectionDialog::finished, tag_fetcher_.get(), &TagFetcher::Cancel);
QObject::connect(track_selection_dialog_.get(), &TrackSelectionDialog::Error, this, &MainWindow::ShowErrorDialog);
QObject::connect(&*tag_fetcher_, &TagFetcher::ResultAvailable, &*track_selection_dialog_, &TrackSelectionDialog::FetchTagFinished, Qt::QueuedConnection);
QObject::connect(&*tag_fetcher_, &TagFetcher::Progress, &*track_selection_dialog_, &TrackSelectionDialog::FetchTagProgress);
QObject::connect(&*track_selection_dialog_, &TrackSelectionDialog::accepted, this, &MainWindow::AutoCompleteTagsAccepted);
QObject::connect(&*track_selection_dialog_, &TrackSelectionDialog::finished, &*tag_fetcher_, &TagFetcher::Cancel);
QObject::connect(&*track_selection_dialog_, &TrackSelectionDialog::Error, this, &MainWindow::ShowErrorDialog);
}
// Get the selected songs and start fetching tags for them
@@ -3104,14 +3105,14 @@ void MainWindow::GetCoverAutomatically() {
}
void MainWindow::ScrobblingEnabledChanged(const bool value) {
if (app_->scrobbler()->ScrobbleButton()) SetToggleScrobblingIcon(value);
if (app_->scrobbler()->scrobble_button()) SetToggleScrobblingIcon(value);
}
void MainWindow::ScrobbleButtonVisibilityChanged(const bool value) {
ui_->button_scrobble->setVisible(value);
ui_->action_toggle_scrobbling->setVisible(value);
if (value) SetToggleScrobblingIcon(app_->scrobbler()->IsEnabled());
if (value) SetToggleScrobblingIcon(app_->scrobbler()->enabled());
}
@@ -3180,7 +3181,7 @@ void MainWindow::PlaylistDelete() {
app_->player()->Next();
}
std::shared_ptr<MusicStorage> storage = std::make_shared<FilesystemMusicStorage>(Song::Source::LocalFile, "/");
SharedPtr<MusicStorage> storage = make_shared<FilesystemMusicStorage>(Song::Source::LocalFile, "/");
DeleteFiles *delete_files = new DeleteFiles(app_->task_manager(), storage, true);
//QObject::connect(delete_files, &DeleteFiles::Finished, this, &MainWindow::DeleteFinished);
delete_files->Start(selected_songs);

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QObject>
#include <QWidget>
@@ -48,6 +46,8 @@
#include <QSettings>
#include <QtEvents>
#include "scoped_ptr.h"
#include "shared_ptr.h"
#include "lazy.h"
#include "platforminterface.h"
#include "song.h"
@@ -104,7 +104,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Q_OBJECT
public:
explicit MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent = nullptr);
explicit MainWindow(Application *app, SharedPtr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent = nullptr);
~MainWindow() override;
static const char *kSettingsGroup;
@@ -297,7 +297,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
#endif
Application *app_;
std::shared_ptr<SystemTrayIcon> tray_icon_;
SharedPtr<SystemTrayIcon> tray_icon_;
OSDBase *osd_;
Lazy<About> about_dialog_;
Lazy<Console> console_;
@@ -318,7 +318,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Lazy<ErrorDialog> error_dialog_;
Lazy<SettingsDialog> settings_dialog_;
Lazy<AlbumCoverManager> cover_manager_;
std::unique_ptr<Equalizer> equalizer_;
SharedPtr<Equalizer> equalizer_;
Lazy<OrganizeDialog> organize_dialog_;
#ifdef HAVE_GSTREAMER
Lazy<TranscodeDialog> transcode_dialog_;
@@ -326,9 +326,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Lazy<AddStreamDialog> add_stream_dialog_;
#ifdef HAVE_MUSICBRAINZ
std::unique_ptr<TagFetcher> tag_fetcher_;
ScopedPtr<TagFetcher> tag_fetcher_;
#endif
std::unique_ptr<TrackSelectionDialog> track_selection_dialog_;
ScopedPtr<TrackSelectionDialog> track_selection_dialog_;
PlaylistItemPtrList autocomplete_tag_items_;
SmartPlaylistsViewContainer *smartplaylists_view_;

View File

@@ -24,7 +24,6 @@
#include "config.h"
#include <memory>
#include <cstddef>
#include <QObject>
@@ -36,6 +35,8 @@
#include <QString>
#include <QStringList>
#include "core/scoped_ptr.h"
class QMimeData;
std::size_t hash_value(const QModelIndex &idx);
@@ -112,7 +113,7 @@ class MergedProxyModel : public QAbstractProxyModel {
QHash<QAbstractItemModel*, QModelIndex> old_merge_points_;
std::unique_ptr<MergedProxyModelPrivate> p_;
ScopedPtr<MergedProxyModelPrivate> p_;
};
#endif // MERGEDPROXYMODEL_H

View File

@@ -118,16 +118,16 @@ Mpris2::Mpris2(Application *app, QObject *parent)
return;
}
QObject::connect(app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &Mpris2::AlbumCoverLoaded);
QObject::connect(&*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::AlbumCoverLoaded, this, &Mpris2::AlbumCoverLoaded);
QObject::connect(app_->player()->engine(), &EngineBase::StateChanged, this, &Mpris2::EngineStateChanged);
QObject::connect(app_->player(), &Player::VolumeChanged, this, &Mpris2::VolumeChanged);
QObject::connect(app_->player(), &Player::Seeked, this, &Mpris2::Seeked);
QObject::connect(&*app_->player()->engine(), &EngineBase::StateChanged, this, &Mpris2::EngineStateChanged);
QObject::connect(&*app_->player(), &Player::VolumeChanged, this, &Mpris2::VolumeChanged);
QObject::connect(&*app_->player(), &Player::Seeked, this, &Mpris2::Seeked);
QObject::connect(app_->playlist_manager(), &PlaylistManager::PlaylistManagerInitialized, this, &Mpris2::PlaylistManagerInitialized);
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &Mpris2::CurrentSongChanged);
QObject::connect(app_->playlist_manager(), &PlaylistManager::PlaylistChanged, this, &Mpris2::PlaylistChangedSlot);
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentChanged, this, &Mpris2::PlaylistCollectionChanged);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::PlaylistManagerInitialized, this, &Mpris2::PlaylistManagerInitialized);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &Mpris2::CurrentSongChanged);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::PlaylistChanged, this, &Mpris2::PlaylistChangedSlot);
QObject::connect(&*app_->playlist_manager(), &PlaylistManager::CurrentChanged, this, &Mpris2::PlaylistCollectionChanged);
app_name_[0] = app_name_[0].toUpper();

View File

@@ -35,6 +35,7 @@
#include <QList>
#include <QImage>
#include "shared_ptr.h"
#include "song.h"
class MusicStorage {
@@ -102,6 +103,6 @@ class MusicStorage {
};
Q_DECLARE_METATYPE(MusicStorage*)
Q_DECLARE_METATYPE(std::shared_ptr<MusicStorage>)
Q_DECLARE_METATYPE(SharedPtr<MusicStorage>)
#endif // MUSICSTORAGE_H

View File

@@ -38,6 +38,8 @@
#include "core/logging.h"
#include "utilities/timeconstants.h"
#include "scoped_ptr.h"
#include "shared_ptr.h"
#include "song.h"
#include "urlhandler.h"
#include "application.h"
@@ -65,6 +67,8 @@
#include "settings/behavioursettingspage.h"
#include "settings/playlistsettingspage.h"
using std::make_shared;
const char *Player::kSettingsGroup = "Player";
Player::Player(Application *app, QObject *parent)
@@ -108,7 +112,7 @@ EngineBase::Type Player::CreateEngine(EngineBase::Type enginetype) {
#ifdef HAVE_GSTREAMER
case EngineBase::Type::GStreamer:{
use_enginetype=EngineBase::Type::GStreamer;
std::unique_ptr<GstEngine> gst_engine(new GstEngine(app_->task_manager()));
ScopedPtr<GstEngine> gst_engine(new GstEngine(app_->task_manager()));
gst_engine->SetStartup(gst_startup_);
engine_.reset(gst_engine.release());
break;
@@ -117,7 +121,7 @@ EngineBase::Type Player::CreateEngine(EngineBase::Type enginetype) {
#ifdef HAVE_VLC
case EngineBase::Type::VLC:
use_enginetype = EngineBase::Type::VLC;
engine_ = std::make_shared<VLCEngine>(app_->task_manager());
engine_ = make_shared<VLCEngine>(app_->task_manager());
break;
#endif
default:
@@ -163,23 +167,23 @@ void Player::Init() {
qFatal("Error initializing audio engine");
}
analyzer_->SetEngine(engine_.get());
analyzer_->SetEngine(engine_);
QObject::connect(engine_.get(), &EngineBase::Error, this, &Player::Error);
QObject::connect(engine_.get(), &EngineBase::FatalError, this, &Player::FatalError);
QObject::connect(engine_.get(), &EngineBase::ValidSongRequested, this, &Player::ValidSongRequested);
QObject::connect(engine_.get(), &EngineBase::InvalidSongRequested, this, &Player::InvalidSongRequested);
QObject::connect(engine_.get(), &EngineBase::StateChanged, this, &Player::EngineStateChanged);
QObject::connect(engine_.get(), &EngineBase::TrackAboutToEnd, this, &Player::TrackAboutToEnd);
QObject::connect(engine_.get(), &EngineBase::TrackEnded, this, &Player::TrackEnded);
QObject::connect(engine_.get(), &EngineBase::MetaData, this, &Player::EngineMetadataReceived);
QObject::connect(engine_.get(), &EngineBase::VolumeChanged, this, &Player::SetVolumeFromEngine);
QObject::connect(&*engine_, &EngineBase::Error, this, &Player::Error);
QObject::connect(&*engine_, &EngineBase::FatalError, this, &Player::FatalError);
QObject::connect(&*engine_, &EngineBase::ValidSongRequested, this, &Player::ValidSongRequested);
QObject::connect(&*engine_, &EngineBase::InvalidSongRequested, this, &Player::InvalidSongRequested);
QObject::connect(&*engine_, &EngineBase::StateChanged, this, &Player::EngineStateChanged);
QObject::connect(&*engine_, &EngineBase::TrackAboutToEnd, this, &Player::TrackAboutToEnd);
QObject::connect(&*engine_, &EngineBase::TrackEnded, this, &Player::TrackEnded);
QObject::connect(&*engine_, &EngineBase::MetaData, this, &Player::EngineMetadataReceived);
QObject::connect(&*engine_, &EngineBase::VolumeChanged, this, &Player::SetVolumeFromEngine);
// Equalizer
QObject::connect(equalizer_, &Equalizer::StereoBalancerEnabledChanged, app_->player()->engine(), &EngineBase::SetStereoBalancerEnabled);
QObject::connect(equalizer_, &Equalizer::StereoBalanceChanged, app_->player()->engine(), &EngineBase::SetStereoBalance);
QObject::connect(equalizer_, &Equalizer::EqualizerEnabledChanged, app_->player()->engine(), &EngineBase::SetEqualizerEnabled);
QObject::connect(equalizer_, &Equalizer::EqualizerParametersChanged, app_->player()->engine(), &EngineBase::SetEqualizerParameters);
QObject::connect(&*equalizer_, &Equalizer::StereoBalancerEnabledChanged, &*app_->player()->engine(), &EngineBase::SetStereoBalancerEnabled);
QObject::connect(&*equalizer_, &Equalizer::StereoBalanceChanged, &*app_->player()->engine(), &EngineBase::SetStereoBalance);
QObject::connect(&*equalizer_, &Equalizer::EqualizerEnabledChanged, &*app_->player()->engine(), &EngineBase::SetEqualizerEnabled);
QObject::connect(&*equalizer_, &Equalizer::EqualizerParametersChanged, &*app_->player()->engine(), &EngineBase::SetEqualizerParameters);
engine_->SetStereoBalancerEnabled(equalizer_->is_stereo_balancer_enabled());
engine_->SetStereoBalance(equalizer_->stereo_balance());

View File

@@ -24,8 +24,6 @@
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QObject>
#include <QMap>
@@ -33,6 +31,7 @@
#include <QString>
#include <QUrl>
#include "shared_ptr.h"
#include "urlhandler.h"
#include "engine/enginebase.h"
#include "engine/enginemetadata.h"
@@ -54,7 +53,7 @@ class PlayerInterface : public QObject {
public:
explicit PlayerInterface(QObject *parent = nullptr) : QObject(parent) {}
virtual EngineBase *engine() const = 0;
virtual SharedPtr<EngineBase> engine() const = 0;
virtual EngineBase::State GetState() const = 0;
virtual uint GetVolume() const = 0;
@@ -130,14 +129,14 @@ class Player : public PlayerInterface {
Q_OBJECT
public:
explicit Player(Application *app, QObject *parent);
explicit Player(Application *app, QObject *parent = nullptr);
static const char *kSettingsGroup;
EngineBase::Type CreateEngine(EngineBase::Type Type);
void Init();
EngineBase *engine() const override { return engine_.get(); }
SharedPtr<EngineBase> engine() const override { return engine_; }
EngineBase::State GetState() const override { return last_state_; }
uint GetVolume() const override;
@@ -152,7 +151,7 @@ class Player : public PlayerInterface {
bool PreviousWouldRestartTrack() const;
void SetAnalyzer(AnalyzerContainer *analyzer) { analyzer_ = analyzer; }
void SetEqualizer(Equalizer *equalizer) { equalizer_ = equalizer; }
void SetEqualizer(SharedPtr<Equalizer> equalizer) { equalizer_ = equalizer; }
public slots:
void ReloadSettings() override;
@@ -218,12 +217,12 @@ class Player : public PlayerInterface {
private:
Application *app_;
std::shared_ptr<EngineBase> engine_;
SharedPtr<EngineBase> engine_;
#ifdef HAVE_GSTREAMER
GstStartup *gst_startup_;
#endif
AnalyzerContainer *analyzer_;
Equalizer *equalizer_;
SharedPtr<Equalizer> equalizer_;
PlaylistItemPtr current_item_;

28
src/core/scoped_ptr.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Strawberry Music Player
* Copyright 2023, 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/>.
*
*/
#ifndef SCOPED_PTR_H
#define SCOPED_PTR_H
#include <memory>
template <typename T, typename D = std::default_delete<T>>
using ScopedPtr = std::unique_ptr<T, D>;
#endif // SCOPED_PTR_H

View File

@@ -21,11 +21,11 @@
#ifndef SCOPEDWCHARARRAY_H
#define SCOPEDWCHARARRAY_H
#include <memory>
#include <QObject>
#include <QString>
#include "scoped_ptr.h"
class ScopedWCharArray {
public:
explicit ScopedWCharArray(const QString &str);
@@ -42,7 +42,7 @@ class ScopedWCharArray {
Q_DISABLE_COPY(ScopedWCharArray)
qint64 chars_;
std::unique_ptr<wchar_t[]> data_;
ScopedPtr<wchar_t[]> data_;
};
#endif // SCOPEDWCHARARRAY_H

28
src/core/shared_ptr.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Strawberry Music Player
* Copyright 2023, 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/>.
*
*/
#ifndef SHARED_PTR_H
#define SHARED_PTR_H
#include <memory>
template<typename T>
using SharedPtr = std::shared_ptr<T>;
#endif // SHARED_PTR_H

View File

@@ -21,7 +21,6 @@
#include "config.h"
#include <memory>
#include <algorithm>
#ifdef HAVE_GSTREAMER
@@ -44,6 +43,7 @@
#include "core/logging.h"
#include "shared_ptr.h"
#include "signalchecker.h"
#include "player.h"
#include "song.h"
@@ -65,13 +65,13 @@
QSet<QString> SongLoader::sRawUriSchemes;
const int SongLoader::kDefaultTimeout = 5000;
SongLoader::SongLoader(CollectionBackendInterface *collection, const Player *player, QObject *parent)
SongLoader::SongLoader(SharedPtr<CollectionBackendInterface> collection_backend, const SharedPtr<Player> player, QObject *parent)
: QObject(parent),
player_(player),
collection_(collection),
collection_backend_(collection_backend),
timeout_timer_(new QTimer(this)),
playlist_parser_(new PlaylistParser(collection, this)),
cue_parser_(new CueParser(collection, this)),
playlist_parser_(new PlaylistParser(collection_backend, this)),
cue_parser_(new CueParser(collection_backend, this)),
parser_(nullptr),
state_(State::WaitingForType),
timeout_(kDefaultTimeout),
@@ -233,10 +233,10 @@ SongLoader::Result SongLoader::LoadLocal(const QString &filename) {
// Search in the database.
QUrl url = QUrl::fromLocalFile(filename);
QMutexLocker l(collection_->db()->Mutex());
QSqlDatabase db(collection_->db()->Connect());
QMutexLocker l(collection_backend_->db()->Mutex());
QSqlDatabase db(collection_backend_->db()->Connect());
CollectionQuery query(db, collection_->songs_table(), collection_->fts_table());
CollectionQuery query(db, collection_backend_->songs_table(), collection_backend_->fts_table());
query.SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
query.AddWhere("url", url.toEncoded());
@@ -348,7 +348,7 @@ void SongLoader::EffectiveSongLoad(Song *song) {
}
// First, try to get the song from the collection
Song collection_song = collection_->GetSongByUrl(song->url());
Song collection_song = collection_backend_->GetSongByUrl(song->url());
if (collection_song.is_valid()) {
*song = collection_song;
}
@@ -429,7 +429,7 @@ void SongLoader::StopTypefind() {
#ifdef HAVE_GSTREAMER
// Destroy the pipeline
if (pipeline_) {
gst_element_set_state(pipeline_.get(), GST_STATE_NULL);
gst_element_set_state(&*pipeline_, GST_STATE_NULL);
CleanupPipeline();
}
#endif
@@ -471,7 +471,7 @@ SongLoader::Result SongLoader::LoadRemote() {
ScheduleTimeoutAsync();
// Create the pipeline - it gets unreffed if it goes out of scope
std::shared_ptr<GstElement> pipeline(gst_pipeline_new(nullptr), std::bind(&gst_object_unref, std::placeholders::_1));
SharedPtr<GstElement> pipeline(gst_pipeline_new(nullptr), std::bind(&gst_object_unref, std::placeholders::_1));
// Create the source element automatically based on the URL
GstElement *source = gst_element_make_from_uri(GST_URI_SRC, url_.toEncoded().constData(), nullptr, nullptr);
@@ -479,7 +479,7 @@ SongLoader::Result SongLoader::LoadRemote() {
errors_ << tr("Couldn't create GStreamer source element for %1").arg(url_.toString());
return Result::Error;
}
gst_bin_add(GST_BIN(pipeline.get()), source);
gst_bin_add(GST_BIN(&*pipeline), source);
g_object_set(source, "ssl-strict", FALSE, nullptr);
@@ -489,14 +489,14 @@ SongLoader::Result SongLoader::LoadRemote() {
errors_ << tr("Couldn't create GStreamer typefind element for %1").arg(url_.toString());
return Result::Error;
}
gst_bin_add(GST_BIN(pipeline.get()), typefind);
gst_bin_add(GST_BIN(&*pipeline), typefind);
fakesink_ = gst_element_factory_make("fakesink", nullptr);
if (!fakesink_) {
errors_ << tr("Couldn't create GStreamer fakesink element for %1").arg(url_.toString());
return Result::Error;
}
gst_bin_add(GST_BIN(pipeline.get()), fakesink_);
gst_bin_add(GST_BIN(&*pipeline), fakesink_);
if (!gst_element_link_many(source, typefind, fakesink_, nullptr)) {
errors_ << tr("Couldn't link GStreamer source, typefind and fakesink elements for %1").arg(url_.toString());
@@ -505,7 +505,7 @@ SongLoader::Result SongLoader::LoadRemote() {
// Connect callbacks
CHECKED_GCONNECT(typefind, "have-type", &TypeFound, this);
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline.get()));
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(&*pipeline));
if (bus) {
gst_bus_set_sync_handler(bus, BusCallbackSync, this, nullptr);
gst_bus_add_watch(bus, BusWatchCallback, this);
@@ -524,7 +524,7 @@ SongLoader::Result SongLoader::LoadRemote() {
// Start "playing"
pipeline_ = pipeline;
gst_element_set_state(pipeline.get(), GST_STATE_PLAYING);
gst_element_set_state(&*pipeline, GST_STATE_PLAYING);
// Wait until loading is finished
loop.exec();
@@ -718,7 +718,7 @@ bool SongLoader::IsPipelinePlaying() {
GstState state = GST_STATE_NULL;
GstState pending_state = GST_STATE_NULL;
GstStateChangeReturn ret = gst_element_get_state(pipeline_.get(), &state, &pending_state, GST_SECOND);
GstStateChangeReturn ret = gst_element_get_state(&*pipeline_, &state, &pending_state, GST_SECOND);
if (ret == GST_STATE_CHANGE_ASYNC && pending_state == GST_STATE_PLAYING) {
// We're still on the way to playing
@@ -763,7 +763,7 @@ void SongLoader::CleanupPipeline() {
if (pipeline_) {
gst_element_set_state(pipeline_.get(), GST_STATE_NULL);
gst_element_set_state(&*pipeline_, GST_STATE_NULL);
if (fakesink_ && buffer_probe_cb_id_ != 0) {
GstPad *pad = gst_element_get_static_pad(fakesink_, "src");
@@ -774,7 +774,7 @@ void SongLoader::CleanupPipeline() {
}
{
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_.get()));
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(&*pipeline_));
if (bus) {
gst_bus_remove_watch(bus);
gst_bus_set_sync_handler(bus, nullptr, nullptr, nullptr);

View File

@@ -41,6 +41,7 @@
#include <QStringList>
#include <QUrl>
#include "shared_ptr.h"
#include "song.h"
class QTimer;
@@ -58,7 +59,7 @@ class SongLoader : public QObject {
Q_OBJECT
public:
explicit SongLoader(CollectionBackendInterface *collection, const Player *player, QObject *parent = nullptr);
explicit SongLoader(SharedPtr<CollectionBackendInterface> collection_backend, const SharedPtr<Player> player, QObject *parent = nullptr);
~SongLoader() override;
enum class Result {
@@ -143,8 +144,8 @@ class SongLoader : public QObject {
QUrl url_;
SongList songs_;
const Player *player_;
CollectionBackendInterface *collection_;
const SharedPtr<Player> player_;
SharedPtr<CollectionBackendInterface> collection_backend_;
QTimer *timeout_timer_;
PlaylistParser *playlist_parser_;
CueParser *cue_parser_;
@@ -158,7 +159,7 @@ class SongLoader : public QObject {
int timeout_;
#ifdef HAVE_GSTREAMER
std::shared_ptr<GstElement> pipeline_;
SharedPtr<GstElement> pipeline_;
GstElement *fakesink_;
gulong buffer_probe_cb_id_;
#endif

View File

@@ -35,9 +35,12 @@
#include <QPalette>
#include <QEvent>
#include "shared_ptr.h"
#include "core/logging.h"
#include "stylesheetloader.h"
using std::make_shared;
StyleSheetLoader::StyleSheetLoader(QObject *parent) : QObject(parent) {}
void StyleSheetLoader::SetStyleSheet(QWidget *widget, const QString &filename) {
@@ -57,7 +60,7 @@ void StyleSheetLoader::SetStyleSheet(QWidget *widget, const QString &filename) {
}
file.close();
std::shared_ptr<StyleSheetData> styledata = std::make_shared<StyleSheetData>();
SharedPtr<StyleSheetData> styledata = make_shared<StyleSheetData>();
styledata->filename_ = filename;
styledata->stylesheet_template_ = stylesheet;
styledata->stylesheet_current_ = widget->styleSheet();
@@ -68,7 +71,7 @@ void StyleSheetLoader::SetStyleSheet(QWidget *widget, const QString &filename) {
}
void StyleSheetLoader::UpdateStyleSheet(QWidget *widget, std::shared_ptr<StyleSheetData> styledata) {
void StyleSheetLoader::UpdateStyleSheet(QWidget *widget, SharedPtr<StyleSheetData> styledata) {
QString stylesheet = styledata->stylesheet_template_;

View File

@@ -24,14 +24,14 @@
#include "config.h"
#include <memory>
#include <QObject>
#include <QPair>
#include <QHash>
#include <QPalette>
#include <QString>
#include "shared_ptr.h"
class QWidget;
class QEvent;
@@ -58,11 +58,11 @@ class StyleSheetLoader : public QObject {
};
private:
void UpdateStyleSheet(QWidget *widget, std::shared_ptr<StyleSheetData> styledata);
void UpdateStyleSheet(QWidget *widget, SharedPtr<StyleSheetData> styledata);
static void ReplaceColor(QString *css, const QString &name, const QPalette &palette, const QPalette::ColorRole role);
private:
QHash<QWidget*, std::shared_ptr<StyleSheetData>> styledata_;
QHash<QWidget*, SharedPtr<StyleSheetData>> styledata_;
};
#endif // STYLESHEETLOADER_H