From 081a0b6d47e93840e4dbb6c5be1c9b840a1f6e01 Mon Sep 17 00:00:00 2001 From: Andre Meyering Date: Wed, 13 May 2020 15:20:14 +0200 Subject: [PATCH] [MusicSearch] Remove singleton for dialog --- src/ui/main/MainWindow.cpp | 1 - src/ui/music/MusicSearch.cpp | 18 ++---------------- src/ui/music/MusicSearch.h | 5 ++--- src/ui/music/MusicWidgetAlbum.cpp | 16 ++++++++++------ src/ui/music/MusicWidgetArtist.cpp | 14 +++++++++----- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/ui/main/MainWindow.cpp b/src/ui/main/MainWindow.cpp index 1f8d39a73e..4110963103 100644 --- a/src/ui/main/MainWindow.cpp +++ b/src/ui/main/MainWindow.cpp @@ -214,7 +214,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->movieDuplicatesWidget, &MovieDuplicates::sigJumpToMovie, this, &MainWindow::onJumpToMovie); // clang-format on - MusicSearch::instance(this); TvShowSearch::instance(this); ImageDialog::instance(this); MovieListDialog::instance(this); diff --git a/src/ui/music/MusicSearch.cpp b/src/ui/music/MusicSearch.cpp index a0df4f5a33..3b61ee009d 100644 --- a/src/ui/music/MusicSearch.cpp +++ b/src/ui/music/MusicSearch.cpp @@ -21,16 +21,7 @@ MusicSearch::~MusicSearch() delete ui; } -MusicSearch* MusicSearch::instance(QWidget* parent) -{ - static MusicSearch* m_instance = nullptr; - if (m_instance == nullptr) { - m_instance = new MusicSearch(parent); - } - return m_instance; -} - -int MusicSearch::exec(QString type, QString searchString, QString artistName) +int MusicSearch::execWithSearch(QString type, QString searchString, QString artistName) { QSize newSize; newSize.setHeight(parentWidget()->size().height() - 200); @@ -39,12 +30,7 @@ int MusicSearch::exec(QString type, QString searchString, QString artistName) ui->musicSearchWidget->setType(type); ui->musicSearchWidget->setArtistName(artistName); ui->musicSearchWidget->search(searchString); - return QDialog::exec(); -} - -int MusicSearch::exec() -{ - return 0; + return exec(); } int MusicSearch::scraperNo() diff --git a/src/ui/music/MusicSearch.h b/src/ui/music/MusicSearch.h index 3e9200130e..719805f7f1 100644 --- a/src/ui/music/MusicSearch.h +++ b/src/ui/music/MusicSearch.h @@ -18,9 +18,8 @@ class MusicSearch : public QDialog ~MusicSearch() override; public slots: - int exec() override; - int exec(QString type, QString searchString, QString artistName = QString()); - static MusicSearch* instance(QWidget* parent = nullptr); + int execWithSearch(QString type, QString searchString, QString artistName = QString()); + int scraperNo(); QString scraperId(); QString scraperId2(); diff --git a/src/ui/music/MusicWidgetAlbum.cpp b/src/ui/music/MusicWidgetAlbum.cpp index 774160d170..20199c0d04 100644 --- a/src/ui/music/MusicWidgetAlbum.cpp +++ b/src/ui/music/MusicWidgetAlbum.cpp @@ -218,18 +218,22 @@ void MusicWidgetAlbum::onStartScraperSearch() emit sigSetActionSearchEnabled(false, MainWidgets::Music); emit sigSetActionSaveEnabled(false, MainWidgets::Music); - MusicSearch::instance()->exec("album", + auto* searchWidget = new MusicSearch(this); + searchWidget->execWithSearch("album", m_album->title(), (m_album->artist().isEmpty() && (m_album->artistObj() != nullptr)) ? m_album->artistObj()->name() : m_album->artist()); - if (MusicSearch::instance()->result() == QDialog::Accepted) { + if (searchWidget->result() == QDialog::Accepted) { onSetEnabled(false); - m_album->controller()->loadData(MusicSearch::instance()->scraperId(), - MusicSearch::instance()->scraperId2(), - Manager::instance()->musicScrapers().at(MusicSearch::instance()->scraperNo()), - MusicSearch::instance()->infosToLoad()); + m_album->controller()->loadData(searchWidget->scraperId(), + searchWidget->scraperId2(), + Manager::instance()->musicScrapers().at(searchWidget->scraperNo()), + searchWidget->infosToLoad()); + searchWidget->deleteLater(); + } else { + searchWidget->deleteLater(); emit sigSetActionSearchEnabled(true, MainWidgets::Music); emit sigSetActionSaveEnabled(true, MainWidgets::Music); } diff --git a/src/ui/music/MusicWidgetArtist.cpp b/src/ui/music/MusicWidgetArtist.cpp index 50961e7e32..362e94ddd5 100644 --- a/src/ui/music/MusicWidgetArtist.cpp +++ b/src/ui/music/MusicWidgetArtist.cpp @@ -213,14 +213,18 @@ void MusicWidgetArtist::onStartScraperSearch() emit sigSetActionSearchEnabled(false, MainWidgets::Music); emit sigSetActionSaveEnabled(false, MainWidgets::Music); - MusicSearch::instance()->exec("artist", m_artist->name()); + auto* searchWidget = new MusicSearch(this); + searchWidget->execWithSearch("artist", m_artist->name()); - if (MusicSearch::instance()->result() == QDialog::Accepted) { + if (searchWidget->result() == QDialog::Accepted) { onSetEnabled(false); - m_artist->controller()->loadData(MusicSearch::instance()->scraperId(), - Manager::instance()->musicScrapers().at(MusicSearch::instance()->scraperNo()), - MusicSearch::instance()->infosToLoad()); + m_artist->controller()->loadData(searchWidget->scraperId(), + Manager::instance()->musicScrapers().at(searchWidget->scraperNo()), + searchWidget->infosToLoad()); + searchWidget->deleteLater(); + } else { + searchWidget->deleteLater(); emit sigSetActionSearchEnabled(true, MainWidgets::Music); emit sigSetActionSaveEnabled(true, MainWidgets::Music); }