Skip to content

Commit

Permalink
[MusicSearch] Remove singleton for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwelle committed May 13, 2020
1 parent 22ce6b3 commit 081a0b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/ui/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 2 additions & 16 deletions src/ui/music/MusicSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/ui/music/MusicSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 10 additions & 6 deletions src/ui/music/MusicWidgetAlbum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 9 additions & 5 deletions src/ui/music/MusicWidgetArtist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 081a0b6

Please sign in to comment.