From ed09627fdba3186c0cbe9682e4a838afd1429fea Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Mon, 21 Jun 2021 15:40:25 +0200 Subject: [PATCH] Use std::make_unique --- src/collection/collectionfilterwidget.cpp | 4 +++- src/collection/collectionview.cpp | 11 +++++++---- src/context/contextalbum.cpp | 2 +- src/context/contextalbumsview.cpp | 14 +++++++++----- src/core/mainwindow.cpp | 4 ++-- src/core/player.cpp | 2 +- src/covermanager/currentalbumcoverloader.cpp | 6 ++++-- src/device/deviceview.cpp | 2 +- src/device/mtploader.cpp | 3 ++- src/device/udisks2lister.cpp | 4 +++- src/engine/gstenginepipeline.cpp | 3 ++- src/internet/internetsearchview.cpp | 2 +- src/moodbar/moodbarpipeline.cpp | 3 ++- src/organize/organizedialog.cpp | 2 +- src/osd/osddbus.cpp | 2 +- src/playlist/playlistlistcontainer.cpp | 4 +++- .../smartplaylistquerywizardplugin.cpp | 4 +++- src/subsonic/subsonicservice.cpp | 2 +- src/widgets/playingwidget.cpp | 4 +++- tests/src/collectionbackend_test.cpp | 2 +- tests/src/songplaylistitem_test.cpp | 2 +- 21 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/collection/collectionfilterwidget.cpp b/src/collection/collectionfilterwidget.cpp index 9b802ca0..68bbf461 100644 --- a/src/collection/collectionfilterwidget.cpp +++ b/src/collection/collectionfilterwidget.cpp @@ -20,6 +20,8 @@ #include "config.h" +#include + #include #include #include @@ -281,7 +283,7 @@ void CollectionFilterWidget::SaveGroupBy() { void CollectionFilterWidget::ShowGroupingManager() { if (!groupings_manager_) { - groupings_manager_.reset(new SavedGroupingManager); + groupings_manager_ = std::make_unique(); } groupings_manager_->SetFilter(this); groupings_manager_->UpdateModel(); diff --git a/src/collection/collectionview.cpp b/src/collection/collectionview.cpp index 74ed02a7..2e97c314 100644 --- a/src/collection/collectionview.cpp +++ b/src/collection/collectionview.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -566,7 +568,7 @@ SongList CollectionView::GetSelectedSongs() const { void CollectionView::Organize() { if (!organize_dialog_) { - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), app_->collection_backend(), this)); + organize_dialog_ = std::make_unique(app_->task_manager(), app_->collection_backend(), this); } organize_dialog_->SetDestinationModel(app_->collection_model()->directory_model()); @@ -584,7 +586,7 @@ void CollectionView::Organize() { void CollectionView::EditTracks() { if (!edit_tag_dialog_) { - edit_tag_dialog_.reset(new EditTagDialog(app_, this)); + edit_tag_dialog_ = std::make_unique(app_, this); QObject::connect(edit_tag_dialog_.get(), &EditTagDialog::Error, this, &CollectionView::EditTagError); } const SongList songs = GetSelectedSongs(); @@ -606,8 +608,9 @@ void CollectionView::RescanSongs() { void CollectionView::CopyToDevice() { #ifndef Q_OS_WIN - if (!organize_dialog_) - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this)); + if (!organize_dialog_) { + organize_dialog_ = std::make_unique(app_->task_manager(), nullptr, this); + } organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); organize_dialog_->SetCopy(true); diff --git a/src/context/contextalbum.cpp b/src/context/contextalbum.cpp index 6ef0975d..b5792f13 100644 --- a/src/context/contextalbum.cpp +++ b/src/context/contextalbum.cpp @@ -193,7 +193,7 @@ void ContextAlbum::SearchCoverInProgress() { downloading_covers_ = true; // Show a spinner animation - spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); + spinner_animation_ = std::make_unique(":/pictures/spinner.gif", QByteArray(), this); QObject::connect(spinner_animation_.get(), &QMovie::updated, this, &ContextAlbum::Update); spinner_animation_->start(); update(); diff --git a/src/context/contextalbumsview.cpp b/src/context/contextalbumsview.cpp index e704e1d4..4168c1f6 100644 --- a/src/context/contextalbumsview.cpp +++ b/src/context/contextalbumsview.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include @@ -381,8 +383,9 @@ SongList ContextAlbumsView::GetSelectedSongs() const { void ContextAlbumsView::Organize() { - if (!organize_dialog_) - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), app_->collection_backend(), this)); + if (!organize_dialog_) { + organize_dialog_ = std::make_unique(app_->task_manager(), app_->collection_backend(), this); + } organize_dialog_->SetDestinationModel(app_->collection_model()->directory_model()); organize_dialog_->SetCopy(false); @@ -397,7 +400,7 @@ void ContextAlbumsView::Organize() { void ContextAlbumsView::EditTracks() { if (!edit_tag_dialog_) { - edit_tag_dialog_.reset(new EditTagDialog(app_, this)); + edit_tag_dialog_ = std::make_unique(app_, this); } edit_tag_dialog_->SetSongs(GetSelectedSongs()); edit_tag_dialog_->show(); @@ -406,8 +409,9 @@ void ContextAlbumsView::EditTracks() { void ContextAlbumsView::CopyToDevice() { #ifndef Q_OS_WIN - if (!organize_dialog_) - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this)); + if (!organize_dialog_) { + organize_dialog_ = std::make_unique(app_->task_manager(), nullptr, this); + } organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); organize_dialog_->SetCopy(true); diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index f4560e3f..82747c12 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -2863,8 +2863,8 @@ void MainWindow::AutoCompleteTags() { // Create the tag fetching stuff if it hasn't been already if (!tag_fetcher_) { - tag_fetcher_.reset(new TagFetcher); - track_selection_dialog_.reset(new TrackSelectionDialog); + tag_fetcher_ = std::make_unique(); + track_selection_dialog_ = std::make_unique(); track_selection_dialog_->set_save_on_close(true); QObject::connect(tag_fetcher_.get(), &TagFetcher::ResultAvailable, track_selection_dialog_.get(), &TrackSelectionDialog::FetchTagFinished, Qt::QueuedConnection); diff --git a/src/core/player.cpp b/src/core/player.cpp index 3f9aa39b..18347a80 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -127,7 +127,7 @@ Engine::EngineType Player::CreateEngine(Engine::EngineType enginetype) { #ifdef HAVE_VLC case Engine::VLC: use_enginetype=Engine::VLC; - engine_.reset(new VLCEngine(app_->task_manager())); + engine_ = std::make_unique(app_->task_manager()); break; #endif default: diff --git a/src/covermanager/currentalbumcoverloader.cpp b/src/covermanager/currentalbumcoverloader.cpp index f92df074..f72399ed 100644 --- a/src/covermanager/currentalbumcoverloader.cpp +++ b/src/covermanager/currentalbumcoverloader.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -78,7 +80,7 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverL id_ = 0; if (!result.album_cover.image.isNull()) { - temp_cover_.reset(new QTemporaryFile(temp_file_pattern_)); + temp_cover_ = std::make_unique(temp_file_pattern_); temp_cover_->setAutoRemove(true); if (temp_cover_->open()) { if (result.album_cover.image.save(temp_cover_->fileName(), "JPEG")) { @@ -95,7 +97,7 @@ void CurrentAlbumCoverLoader::TempAlbumCoverLoaded(const quint64 id, AlbumCoverL QUrl thumbnail_url; if (!result.image_thumbnail.isNull()) { - temp_cover_thumbnail_.reset(new QTemporaryFile(temp_file_pattern_)); + temp_cover_thumbnail_ = std::make_unique(temp_file_pattern_); temp_cover_thumbnail_->setAutoRemove(true); if (temp_cover_thumbnail_->open()) { if (result.image_thumbnail.save(temp_cover_thumbnail_->fileName(), "JPEG")) { diff --git a/src/device/deviceview.cpp b/src/device/deviceview.cpp index b09d4dad..48fd389e 100644 --- a/src/device/deviceview.cpp +++ b/src/device/deviceview.cpp @@ -222,7 +222,7 @@ void DeviceView::SetApplication(Application *app) { properties_dialog_->SetDeviceManager(app_->device_manager()); - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this)); + organize_dialog_ = std::make_unique(app_->task_manager(), nullptr, this); organize_dialog_->SetDestinationModel(app_->collection_model()->directory_model()); } diff --git a/src/device/mtploader.cpp b/src/device/mtploader.cpp index 450e2767..1cddc2a4 100644 --- a/src/device/mtploader.cpp +++ b/src/device/mtploader.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "core/taskmanager.h" #include "core/song.h" @@ -61,7 +62,7 @@ void MtpLoader::LoadDatabase() { bool MtpLoader::TryLoad() { - connection_.reset(new MtpConnection(url_)); + connection_ = std::make_unique(url_); if (!connection_ || !connection_->is_valid()) { emit Error(tr("Error connecting MTP device %1").arg(url_.toString())); diff --git a/src/device/udisks2lister.cpp b/src/device/udisks2lister.cpp index d235c993..31e1155a 100644 --- a/src/device/udisks2lister.cpp +++ b/src/device/udisks2lister.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -179,7 +181,7 @@ void Udisks2Lister::UpdateDeviceFreeSpace(const QString &id) { bool Udisks2Lister::Init() { - udisks2_interface_.reset(new OrgFreedesktopDBusObjectManagerInterface(udisks2_service_, "/org/freedesktop/UDisks2", QDBusConnection::systemBus())); + udisks2_interface_ = std::make_unique(udisks2_service_, "/org/freedesktop/UDisks2", QDBusConnection::systemBus()); QDBusPendingReply reply = udisks2_interface_->GetManagedObjects(); reply.waitForFinished(); diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 129be24e..245b17b5 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -21,6 +21,7 @@ #include "config.h" +#include #include #include #include @@ -1216,7 +1217,7 @@ void GstEnginePipeline::StartFader(const qint64 duration_nanosec, const QTimeLin } } - fader_.reset(new QTimeLine(duration_msec, this)); + fader_ = std::make_unique(duration_msec, this); QObject::connect(fader_.get(), &QTimeLine::valueChanged, this, &GstEnginePipeline::SetVolumeModifier); QObject::connect(fader_.get(), &QTimeLine::finished, this, &GstEnginePipeline::FaderTimelineFinished); fader_->setDirection(direction); diff --git a/src/internet/internetsearchview.cpp b/src/internet/internetsearchview.cpp index 9bf99fc4..aab505b4 100644 --- a/src/internet/internetsearchview.cpp +++ b/src/internet/internetsearchview.cpp @@ -676,7 +676,7 @@ void InternetSearchView::GroupByClicked(QAction *action) { if (action->property("group_by").isNull()) { if (!group_by_dialog_) { - group_by_dialog_.reset(new GroupByDialog); + group_by_dialog_ = std::make_unique(); QObject::connect(group_by_dialog_.get(), &GroupByDialog::Accepted, this, &InternetSearchView::SetGroupBy); } diff --git a/src/moodbar/moodbarpipeline.cpp b/src/moodbar/moodbarpipeline.cpp index 31c63610..91eb0683 100644 --- a/src/moodbar/moodbarpipeline.cpp +++ b/src/moodbar/moodbarpipeline.cpp @@ -17,6 +17,7 @@ #include "moodbarpipeline.h" +#include #include #include @@ -111,7 +112,7 @@ void MoodbarPipeline::Start() { return; } - builder_.reset(new MoodbarBuilder); + builder_ = std::make_unique(); // Set properties g_object_set(decodebin, "uri", local_filename_.toEncoded().constData(), nullptr); diff --git a/src/organize/organizedialog.cpp b/src/organize/organizedialog.cpp index b0ff4bef..ecf9facc 100644 --- a/src/organize/organizedialog.cpp +++ b/src/organize/organizedialog.cpp @@ -556,7 +556,7 @@ void OrganizeDialog::OrganizeFinished(const QStringList &files_with_errors, cons if (files_with_errors.isEmpty()) return; - error_dialog_.reset(new OrganizeErrorDialog); + error_dialog_ = std::make_unique(); error_dialog_->Show(OrganizeErrorDialog::Type_Copy, files_with_errors, log); } diff --git a/src/osd/osddbus.cpp b/src/osd/osddbus.cpp index 0a869681..617f4121 100644 --- a/src/osd/osddbus.cpp +++ b/src/osd/osddbus.cpp @@ -117,7 +117,7 @@ OSDDBus::~OSDDBus() = default; void OSDDBus::Init() { - interface_.reset(new OrgFreedesktopNotificationsInterface(OrgFreedesktopNotificationsInterface::staticInterfaceName(), "/org/freedesktop/Notifications", QDBusConnection::sessionBus())); + interface_ = std::make_unique(OrgFreedesktopNotificationsInterface::staticInterfaceName(), "/org/freedesktop/Notifications", QDBusConnection::sessionBus()); if (!interface_->isValid()) { qLog(Warning) << "Error connecting to notifications service."; } diff --git a/src/playlist/playlistlistcontainer.cpp b/src/playlist/playlistlistcontainer.cpp index 7bf137b2..4781e9ab 100644 --- a/src/playlist/playlistlistcontainer.cpp +++ b/src/playlist/playlistlistcontainer.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -369,7 +371,7 @@ void PlaylistListContainer::CopyToDevice() { // Reuse the organize dialog, but set the detail about the playlist name if (!organize_dialog_) { - organize_dialog_.reset(new OrganizeDialog(app_->task_manager(), nullptr, this)); + organize_dialog_ = std::make_unique(app_->task_manager(), nullptr, this); } organize_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); organize_dialog_->SetCopy(true); diff --git a/src/smartplaylists/smartplaylistquerywizardplugin.cpp b/src/smartplaylists/smartplaylistquerywizardplugin.cpp index 00fe915e..a8a6261a 100644 --- a/src/smartplaylists/smartplaylistquerywizardplugin.cpp +++ b/src/smartplaylists/smartplaylistquerywizardplugin.cpp @@ -20,6 +20,8 @@ #include "config.h" +#include + #include #include #include @@ -100,7 +102,7 @@ int SmartPlaylistQueryWizardPlugin::CreatePages(QWizard *wizard, int finish_page search_page_ = new SearchPage(wizard); QWizardPage *sort_page = new SortPage(this, wizard, finish_page_id); - sort_ui_.reset(new Ui_SmartPlaylistQuerySortPage); + sort_ui_ = std::make_unique(); sort_ui_->setupUi(sort_page); sort_ui_->limit_value->setValue(PlaylistGenerator::kDefaultLimit); diff --git a/src/subsonic/subsonicservice.cpp b/src/subsonic/subsonicservice.cpp index abc12478..4252f04d 100644 --- a/src/subsonic/subsonicservice.cpp +++ b/src/subsonic/subsonicservice.cpp @@ -154,7 +154,7 @@ void SubsonicService::SendPing() { void SubsonicService::SendPingWithCredentials(QUrl url, const QString &username, const QString &password, const bool redirect) { if (!redirect) { - network_.reset(new QNetworkAccessManager); + network_ = std::make_unique(); ping_redirects_ = 0; } diff --git a/src/widgets/playingwidget.cpp b/src/widgets/playingwidget.cpp index a56010ac..78b70c3e 100644 --- a/src/widgets/playingwidget.cpp +++ b/src/widgets/playingwidget.cpp @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -535,7 +537,7 @@ void PlayingWidget::SearchCoverInProgress() { downloading_covers_ = true; // Show a spinner animation - spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); + spinner_animation_ = std::make_unique(":/pictures/spinner.gif", QByteArray(), this); QObject::connect(spinner_animation_.get(), &QMovie::updated, this, &PlayingWidget::Update); spinner_animation_->start(); update(); diff --git a/tests/src/collectionbackend_test.cpp b/tests/src/collectionbackend_test.cpp index 4110c2c7..eb76eeb7 100644 --- a/tests/src/collectionbackend_test.cpp +++ b/tests/src/collectionbackend_test.cpp @@ -45,7 +45,7 @@ class CollectionBackendTest : public ::testing::Test { protected: void SetUp() override { database_.reset(new MemoryDatabase(nullptr)); - backend_.reset(new CollectionBackend); + backend_ = std::make_unique(); backend_->Init(database_.get(), Song::Source_Collection, SCollection::kSongsTable, SCollection::kDirsTable, SCollection::kSubdirsTable, SCollection::kFtsTable); } diff --git a/tests/src/songplaylistitem_test.cpp b/tests/src/songplaylistitem_test.cpp index 44363627..766302e9 100644 --- a/tests/src/songplaylistitem_test.cpp +++ b/tests/src/songplaylistitem_test.cpp @@ -49,7 +49,7 @@ class SongPlaylistItemTest : public ::testing::TestWithParam { song_.Init("Title", "Artist", "Album", 123); song_.set_url(QUrl::fromLocalFile(absolute_file_name_)); - item_.reset(new SongPlaylistItem(song_)); + item_ = std::make_unique(song_); if (!absolute_file_name_.startsWith('/')) absolute_file_name_.prepend('/');