Skip to content

Commit

Permalink
[ImageDialog] 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 c7ccd57 commit 0990ba0
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 136 deletions.
12 changes: 0 additions & 12 deletions src/globals/ImageDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,6 @@ void ImageDialog::reject()
QDialog::reject();
}

/**
* @brief Returns an instance of ImageDialog
* @param parent Parent widget (used the first time for constructing)
* @return Instance of ImageDialog
*/
ImageDialog* ImageDialog::instance(QWidget* parent)
{
static ImageDialog* s_instance = new ImageDialog(parent);
return s_instance;
}

/**
* @brief Clears the dialogs contents and cancels outstanding downloads
*/
Expand Down Expand Up @@ -271,7 +260,6 @@ void ImageDialog::clearSearch()
*/
QUrl ImageDialog::imageUrl()
{
qDebug() << "Entered, returning" << m_imageUrl;
return m_imageUrl;
}

Expand Down
2 changes: 1 addition & 1 deletion src/globals/ImageDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImageDialog : public QDialog
public:
explicit ImageDialog(QWidget* parent = nullptr);
~ImageDialog() override;
static ImageDialog* instance(QWidget* parent = nullptr);

void setDownloads(QVector<Poster> downloads, bool initial = true);
QUrl imageUrl();
QVector<QUrl> imageUrls();
Expand Down
46 changes: 28 additions & 18 deletions src/ui/concerts/ConcertWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,22 @@ void ConcertWidget::onAddExtraFanart()
return;
}

ImageDialog::instance()->setImageType(ImageType::ConcertExtraFanart);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMultiSelection(true);
ImageDialog::instance()->setConcert(m_concert);
ImageDialog::instance()->setDownloads(m_concert->backdrops());
ImageDialog::instance()->exec(ImageType::ConcertBackdrop);

if (ImageDialog::instance()->result() == QDialog::Accepted && !ImageDialog::instance()->imageUrls().isEmpty()) {
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::ConcertExtraFanart);
imageDialog->clear();
imageDialog->setMultiSelection(true);
imageDialog->setConcert(m_concert);
imageDialog->setDownloads(m_concert->backdrops());

imageDialog->exec(ImageType::ConcertBackdrop);
const int exitCode = imageDialog->result();
const QVector<QUrl> imageUrls = imageDialog->imageUrls();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted && !imageUrls.isEmpty()) {
ui->fanarts->setLoading(true);
emit setActionSaveEnabled(false, MainWidgets::Concerts);
m_concert->controller()->loadImages(ImageType::ConcertExtraFanart, ImageDialog::instance()->imageUrls());
m_concert->controller()->loadImages(ImageType::ConcertExtraFanart, imageUrls);
onInfoChanged();
}
}
Expand All @@ -628,21 +633,26 @@ void ConcertWidget::onChooseImage()
return;
}

ImageDialog::instance()->setImageType(image->imageType());
ImageDialog::instance()->clear();
ImageDialog::instance()->setConcert(m_concert);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(image->imageType());
imageDialog->clear();
imageDialog->setConcert(m_concert);
if (image->imageType() == ImageType::ConcertPoster) {
ImageDialog::instance()->setDownloads(m_concert->posters());
imageDialog->setDownloads(m_concert->posters());
} else if (image->imageType() == ImageType::ConcertBackdrop) {
ImageDialog::instance()->setDownloads(m_concert->backdrops());
imageDialog->setDownloads(m_concert->backdrops());
} else {
ImageDialog::instance()->setDownloads(QVector<Poster>());
imageDialog->setDownloads(QVector<Poster>());
}
ImageDialog::instance()->exec(image->imageType());

if (ImageDialog::instance()->result() == QDialog::Accepted) {
imageDialog->exec(image->imageType());
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted) {
emit setActionSaveEnabled(false, MainWidgets::Concerts);
m_concert->controller()->loadImage(image->imageType(), ImageDialog::instance()->imageUrl());
m_concert->controller()->loadImage(image->imageType(), imageUrl);
onInfoChanged();
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/ui/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi

NotificationBox::instance(this)->reposition(this->size());
Manager::instance();
TvShowSearch::instance(this);
Notificator::instance(nullptr, ui->centralWidget);

if (!m_settings->mainSplitterState().isNull()) {
ui->movieSplitter->restoreState(m_settings->mainSplitterState());
Expand Down Expand Up @@ -214,10 +216,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(ui->movieDuplicatesWidget, &MovieDuplicates::sigJumpToMovie, this, &MainWindow::onJumpToMovie);
// clang-format on

TvShowSearch::instance(this);
ImageDialog::instance(this);
Notificator::instance(nullptr, ui->centralWidget);

#ifdef Q_OS_WIN
setStyleSheet(styleSheet() + " #centralWidget { border-bottom: 1px solid rgba(0, 0, 0, 100); } ");

Expand Down
38 changes: 25 additions & 13 deletions src/ui/movie_sets/SetsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void SetsWidget::onRemoveMovie()
void SetsWidget::chooseSetPoster()
{
if (ui->sets->currentRow() < 0 || ui->sets->currentRow() >= ui->sets->rowCount()) {
qDebug() << "Invalid current row in sets";
qDebug() << "[SetsWidget] Invalid current row in sets";
return;
}

Expand All @@ -374,15 +374,21 @@ void SetsWidget::chooseSetPoster()
QString setName = ui->sets->item(ui->sets->currentRow(), 0)->data(Qt::UserRole).toString();
Movie* movie = new Movie(QStringList());
movie->setName(setName);
ImageDialog::instance()->setImageType(ImageType::MovieSetPoster);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMovie(movie);
ImageDialog::instance()->exec(ImageType::MoviePoster);
if (ImageDialog::instance()->result() == QDialog::Accepted) {

auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::MovieSetPoster);
imageDialog->clear();
imageDialog->setMovie(movie);
imageDialog->exec(ImageType::MoviePoster);
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted) {
DownloadManagerElement d;
d.movie = movie;
d.imageType = ImageType::MovieSetPoster;
d.url = ImageDialog::instance()->imageUrl();
d.url = imageUrl;
m_downloadManager->addDownload(d);
ui->poster->setPixmap(QPixmap());
ui->poster->setMovie(m_loadingMovie);
Expand All @@ -407,15 +413,21 @@ void SetsWidget::chooseSetBackdrop()
QString setName = ui->sets->item(ui->sets->currentRow(), 0)->data(Qt::UserRole).toString();
Movie* movie = new Movie(QStringList());
movie->setName(setName);
ImageDialog::instance()->setImageType(ImageType::MovieSetBackdrop);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMovie(movie);
ImageDialog::instance()->exec(ImageType::MovieBackdrop);
if (ImageDialog::instance()->result() == QDialog::Accepted) {

auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::MovieSetBackdrop);
imageDialog->clear();
imageDialog->setMovie(movie);
imageDialog->exec(ImageType::MovieBackdrop);
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted) {
DownloadManagerElement d;
d.movie = movie;
d.imageType = ImageType::MovieSetBackdrop;
d.url = ImageDialog::instance()->imageUrl();
d.url = imageUrl;
m_downloadManager->addDownload(d);
ui->backdrop->setPixmap(QPixmap());
ui->backdrop->setMovie(m_loadingMovie);
Expand Down
48 changes: 29 additions & 19 deletions src/ui/movies/MovieWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,17 +1545,22 @@ void MovieWidget::onAddExtraFanart()
return;
}

ImageDialog::instance()->setImageType(ImageType::MovieExtraFanart);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMultiSelection(true);
ImageDialog::instance()->setMovie(m_movie);
ImageDialog::instance()->setDownloads(m_movie->images().backdrops());
ImageDialog::instance()->exec(ImageType::MovieBackdrop);

if (ImageDialog::instance()->result() == QDialog::Accepted && !ImageDialog::instance()->imageUrls().isEmpty()) {
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::MovieExtraFanart);
imageDialog->clear();
imageDialog->setMultiSelection(true);
imageDialog->setMovie(m_movie);
imageDialog->setDownloads(m_movie->images().backdrops());

imageDialog->exec(ImageType::MovieBackdrop);
const int exitCode = imageDialog->result();
const QVector<QUrl> imageUrls = imageDialog->imageUrls();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted && !imageUrls.isEmpty()) {
ui->fanarts->setLoading(true);
emit setActionSaveEnabled(false, MainWidgets::Movies);
m_movie->controller()->loadImages(ImageType::MovieExtraFanart, ImageDialog::instance()->imageUrls());
m_movie->controller()->loadImages(ImageType::MovieExtraFanart, imageUrls);
ui->buttonRevert->setVisible(true);
}
}
Expand Down Expand Up @@ -1592,23 +1597,28 @@ void MovieWidget::onChooseImage()
return;
}

ImageDialog::instance()->setImageType(image->imageType());
ImageDialog::instance()->clear();
ImageDialog::instance()->setMovie(m_movie);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(image->imageType());
imageDialog->clear();
imageDialog->setMovie(m_movie);
if (image->imageType() == ImageType::MoviePoster) {
ImageDialog::instance()->setDownloads(m_movie->images().posters());
imageDialog->setDownloads(m_movie->images().posters());
} else if (image->imageType() == ImageType::MovieBackdrop) {
ImageDialog::instance()->setDownloads(m_movie->images().backdrops());
imageDialog->setDownloads(m_movie->images().backdrops());
} else if (image->imageType() == ImageType::MovieCdArt && !m_movie->images().discArts().isEmpty()) {
ImageDialog::instance()->setDownloads(m_movie->images().discArts());
imageDialog->setDownloads(m_movie->images().discArts());
} else {
ImageDialog::instance()->setDownloads(QVector<Poster>());
imageDialog->setDownloads(QVector<Poster>());
}
ImageDialog::instance()->exec(image->imageType());

if (ImageDialog::instance()->result() == QDialog::Accepted) {
imageDialog->exec(image->imageType());
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted) {
emit setActionSaveEnabled(false, MainWidgets::Movies);
m_movie->controller()->loadImage(image->imageType(), ImageDialog::instance()->imageUrl());
m_movie->controller()->loadImage(image->imageType(), imageUrl);
ui->buttonRevert->setVisible(true);
}
}
Expand Down
41 changes: 25 additions & 16 deletions src/ui/music/MusicWidgetAlbum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,21 +426,25 @@ void MusicWidgetAlbum::onChooseImage()
return;
}

ImageDialog::instance()->setImageType(image->imageType());
ImageDialog::instance()->clear();
ImageDialog::instance()->setAlbum(m_album);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(image->imageType());
imageDialog->clear();
imageDialog->setAlbum(m_album);

if (!m_album->images(image->imageType()).isEmpty()) {
ImageDialog::instance()->setDownloads(m_album->images(image->imageType()));
imageDialog->setDownloads(m_album->images(image->imageType()));
} else {
ImageDialog::instance()->setDownloads(QVector<Poster>());
imageDialog->setDownloads(QVector<Poster>());
}

ImageDialog::instance()->exec(image->imageType());
imageDialog->exec(image->imageType());
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (ImageDialog::instance()->result() == QDialog::Accepted) {
if (exitCode == QDialog::Accepted) {
emit sigSetActionSaveEnabled(false, MainWidgets::Music);
m_album->controller()->loadImage(image->imageType(), ImageDialog::instance()->imageUrl());
m_album->controller()->loadImage(image->imageType(), imageUrl);
ui->buttonRevert->setVisible(true);
}
}
Expand Down Expand Up @@ -562,19 +566,24 @@ void MusicWidgetAlbum::onAddBooklet()
return;
}

ImageDialog::instance()->setImageType(ImageType::AlbumBooklet);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMultiSelection(true);
ImageDialog::instance()->setAlbum(m_album);
ImageDialog::instance()->setDownloads(QVector<Poster>());
ImageDialog::instance()->exec(ImageType::AlbumBooklet);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::AlbumBooklet);
imageDialog->clear();
imageDialog->setMultiSelection(true);
imageDialog->setAlbum(m_album);
imageDialog->setDownloads(QVector<Poster>());

if (ImageDialog::instance()->result() == QDialog::Accepted && !ImageDialog::instance()->imageUrls().isEmpty()) {
imageDialog->exec(ImageType::AlbumBooklet);
const int exitCode = imageDialog->result();
const QVector<QUrl> imageUrls = imageDialog->imageUrls();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted && !imageUrls.isEmpty()) {
if (m_bookletWidget != nullptr) {
m_bookletWidget->setLoading(true);
}
emit sigSetActionSaveEnabled(false, MainWidgets::Music);
m_album->controller()->loadImages(ImageType::AlbumBooklet, ImageDialog::instance()->imageUrls());
m_album->controller()->loadImages(ImageType::AlbumBooklet, imageUrls);
ui->buttonRevert->setVisible(true);
}
}
Expand Down
41 changes: 25 additions & 16 deletions src/ui/music/MusicWidgetArtist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,25 @@ void MusicWidgetArtist::onChooseImage()
return;
}

ImageDialog::instance()->setImageType(image->imageType());
ImageDialog::instance()->clear();
ImageDialog::instance()->setArtist(m_artist);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(image->imageType());
imageDialog->clear();
imageDialog->setArtist(m_artist);

if (!m_artist->images(image->imageType()).isEmpty()) {
ImageDialog::instance()->setDownloads(m_artist->images(image->imageType()));
imageDialog->setDownloads(m_artist->images(image->imageType()));
} else {
ImageDialog::instance()->setDownloads(QVector<Poster>());
imageDialog->setDownloads(QVector<Poster>());
}

ImageDialog::instance()->exec(image->imageType());
imageDialog->exec(image->imageType());
const int exitCode = imageDialog->result();
const QUrl imageUrl = imageDialog->imageUrl();
imageDialog->deleteLater();

if (ImageDialog::instance()->result() == QDialog::Accepted) {
if (exitCode == QDialog::Accepted) {
emit sigSetActionSaveEnabled(false, MainWidgets::Music);
m_artist->controller()->loadImage(image->imageType(), ImageDialog::instance()->imageUrl());
m_artist->controller()->loadImage(image->imageType(), imageUrl);
ui->buttonRevert->setVisible(true);
}
}
Expand Down Expand Up @@ -540,17 +544,22 @@ void MusicWidgetArtist::onAddExtraFanart()
return;
}

ImageDialog::instance()->setImageType(ImageType::ArtistExtraFanart);
ImageDialog::instance()->clear();
ImageDialog::instance()->setMultiSelection(true);
ImageDialog::instance()->setArtist(m_artist);
ImageDialog::instance()->setDownloads(m_artist->images(ImageType::ArtistFanart));
ImageDialog::instance()->exec(ImageType::ArtistFanart);
auto* imageDialog = new ImageDialog(this);
imageDialog->setImageType(ImageType::ArtistExtraFanart);
imageDialog->clear();
imageDialog->setMultiSelection(true);
imageDialog->setArtist(m_artist);
imageDialog->setDownloads(m_artist->images(ImageType::ArtistFanart));

if (ImageDialog::instance()->result() == QDialog::Accepted && !ImageDialog::instance()->imageUrls().isEmpty()) {
imageDialog->exec(ImageType::ArtistFanart);
const int exitCode = imageDialog->result();
const QVector<QUrl> imageUrls = imageDialog->imageUrls();
imageDialog->deleteLater();

if (exitCode == QDialog::Accepted && !imageUrls.isEmpty()) {
ui->fanarts->setLoading(true);
emit sigSetActionSaveEnabled(false, MainWidgets::Music);
m_artist->controller()->loadImages(ImageType::ArtistExtraFanart, ImageDialog::instance()->imageUrls());
m_artist->controller()->loadImages(ImageType::ArtistExtraFanart, imageUrls);
ui->buttonRevert->setVisible(true);
}
}
Expand Down
Loading

0 comments on commit 0990ba0

Please sign in to comment.