Show error when reading or saving album covers
This commit is contained in:
@@ -253,6 +253,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
|||||||
cover_manager->Init();
|
cover_manager->Init();
|
||||||
|
|
||||||
// Cover manager connections
|
// Cover manager connections
|
||||||
|
QObject::connect(cover_manager, &AlbumCoverManager::Error, this, &MainWindow::ShowErrorDialog);
|
||||||
QObject::connect(cover_manager, &AlbumCoverManager::AddToPlaylist, this, &MainWindow::AddToPlaylist);
|
QObject::connect(cover_manager, &AlbumCoverManager::AddToPlaylist, this, &MainWindow::AddToPlaylist);
|
||||||
return cover_manager;
|
return cover_manager;
|
||||||
}),
|
}),
|
||||||
@@ -621,6 +622,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
|||||||
QObject::connect(app_->task_manager(), &TaskManager::ResumeCollectionWatchers, app_->collection(), &SCollection::ResumeWatcher);
|
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_from_file_action(), &QAction::triggered, this, &MainWindow::LoadCoverFromFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &MainWindow::SaveCoverToFile);
|
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &MainWindow::SaveCoverToFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &MainWindow::LoadCoverFromURL);
|
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &MainWindow::LoadCoverFromURL);
|
||||||
|
|||||||
@@ -182,7 +182,11 @@ AlbumCoverImageResult AlbumCoverChoiceController::LoadImageFromFile(Song *song)
|
|||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
result.image_data = file.readAll();
|
result.image_data = file.readAll();
|
||||||
file.close();
|
file.close();
|
||||||
if (!result.image_data.isEmpty()) {
|
if (result.image_data.isEmpty()) {
|
||||||
|
qLog(Error) << "Cover file" << cover_file << "is empty.";
|
||||||
|
emit Error(tr("Cover file %1 is empty.").arg(cover_file));
|
||||||
|
}
|
||||||
|
else {
|
||||||
result.mime_type = Utilities::MimeTypeFromData(result.image_data);
|
result.mime_type = Utilities::MimeTypeFromData(result.image_data);
|
||||||
result.image.loadFromData(result.image_data);
|
result.image.loadFromData(result.image_data);
|
||||||
result.cover_url = QUrl::fromLocalFile(cover_file);
|
result.cover_url = QUrl::fromLocalFile(cover_file);
|
||||||
@@ -190,6 +194,7 @@ AlbumCoverImageResult AlbumCoverChoiceController::LoadImageFromFile(Song *song)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to open cover file" << cover_file << "for reading:" << file.errorString();
|
qLog(Error) << "Failed to open cover file" << cover_file << "for reading:" << file.errorString();
|
||||||
|
emit Error(tr("Failed to open cover file %1 for reading: %2").arg(cover_file, file.errorString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -257,15 +262,20 @@ void AlbumCoverChoiceController::SaveCoverToFileManual(const Song &song, const A
|
|||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
if (file.write(result.image_data) <= 0) {
|
if (file.write(result.image_data) <= 0) {
|
||||||
qLog(Error) << "Failed writing cover to file" << save_filename << file.errorString();
|
qLog(Error) << "Failed writing cover to file" << save_filename << file.errorString();
|
||||||
|
emit Error(tr("Failed writing cover to file %1: %2").arg(save_filename, file.errorString()));
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to open cover file" << save_filename << "for writing:" << file.errorString();
|
qLog(Error) << "Failed to open cover file" << save_filename << "for writing:" << file.errorString();
|
||||||
|
emit Error(tr("Failed to open cover file %1 for writing: %2").arg(save_filename, file.errorString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.image.save(save_filename);
|
if (!result.image.save(save_filename)) {
|
||||||
|
qLog(Error) << "Failed writing cover to file" << save_filename;
|
||||||
|
emit Error(tr("Failed writing cover to file %1.").arg(save_filename));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -383,24 +393,34 @@ bool AlbumCoverChoiceController::DeleteCover(Song *song, const bool manually_uns
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
if (!art_automatic.isEmpty()) {
|
if (!art_automatic.isEmpty()) {
|
||||||
if (QFile::exists(art_automatic)) {
|
QFile file(art_automatic);
|
||||||
if (QFile::remove(art_automatic)) {
|
if (file.exists()) {
|
||||||
|
if (file.remove()) {
|
||||||
song->clear_art_automatic();
|
song->clear_art_automatic();
|
||||||
if (art_automatic == art_manual) song->clear_art_manual();
|
if (art_automatic == art_manual) song->clear_art_manual();
|
||||||
}
|
}
|
||||||
else success = false;
|
else {
|
||||||
|
success = false;
|
||||||
|
qLog(Error) << "Failed to delete cover file" << art_automatic << file.errorString();
|
||||||
|
emit Error(tr("Failed to delete cover file %1: %2").arg(art_automatic, file.errorString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else song->clear_art_automatic();
|
else song->clear_art_automatic();
|
||||||
}
|
}
|
||||||
else song->clear_art_automatic();
|
else song->clear_art_automatic();
|
||||||
|
|
||||||
if (!art_manual.isEmpty()) {
|
if (!art_manual.isEmpty()) {
|
||||||
if (QFile::exists(art_manual)) {
|
QFile file(art_manual);
|
||||||
if (QFile::remove(art_manual)) {
|
if (file.exists()) {
|
||||||
|
if (file.remove()) {
|
||||||
song->clear_art_manual();
|
song->clear_art_manual();
|
||||||
if (art_automatic == art_manual) song->clear_art_automatic();
|
if (art_automatic == art_manual) song->clear_art_automatic();
|
||||||
}
|
}
|
||||||
else success = false;
|
else {
|
||||||
|
success = false;
|
||||||
|
qLog(Error) << "Failed to delete cover file" << art_manual << file.errorString();
|
||||||
|
emit Error(tr("Failed to delete cover file %1: %2").arg(art_manual, file.errorString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else song->clear_art_manual();
|
else song->clear_art_manual();
|
||||||
}
|
}
|
||||||
@@ -609,11 +629,13 @@ QUrl AlbumCoverChoiceController::SaveCoverToFileAutomatic(const Song::Source sou
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to write cover to file" << file.fileName() << file.errorString();
|
qLog(Error) << "Failed to write cover to file" << file.fileName() << file.errorString();
|
||||||
|
emit Error(tr("Failed to write cover to file %1: %2").arg(file.fileName(), file.errorString()));
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Error) << "Failed to open cover file" << file.fileName() << "for writing:" << file.errorString();
|
qLog(Error) << "Failed to open cover file" << file.fileName() << "for writing:" << file.errorString();
|
||||||
|
emit Error(tr("Failed to open cover file %1 for writing: %2").arg(file.fileName(), file.errorString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ class AlbumCoverChoiceController : public QWidget {
|
|||||||
void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared);
|
void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void Error(QString);
|
||||||
void AutomaticCoverSearchDone();
|
void AutomaticCoverSearchDone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ void AlbumCoverManager::Init() {
|
|||||||
|
|
||||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||||
|
|
||||||
|
QObject::connect(album_cover_choice_controller_, &AlbumCoverChoiceController::Error, this, &AlbumCoverManager::Error);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_from_file_action(), &QAction::triggered, this, &AlbumCoverManager::LoadCoverFromFile);
|
QObject::connect(album_cover_choice_controller_->cover_from_file_action(), &QAction::triggered, this, &AlbumCoverManager::LoadCoverFromFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &AlbumCoverManager::SaveCoverToFile);
|
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &AlbumCoverManager::SaveCoverToFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &AlbumCoverManager::LoadCoverFromURL);
|
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &AlbumCoverManager::LoadCoverFromURL);
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ class AlbumCoverManager : public QMainWindow {
|
|||||||
bool ItemHasCover(const AlbumItem &item) const;
|
bool ItemHasCover(const AlbumItem &item) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void Error(QString);
|
||||||
void AddToPlaylist(QMimeData *data);
|
void AddToPlaylist(QMimeData *data);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ EditTagDialog::EditTagDialog(Application *app, QWidget *parent)
|
|||||||
|
|
||||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||||
|
|
||||||
|
QObject::connect(album_cover_choice_controller_, &AlbumCoverChoiceController::Error, this, &EditTagDialog::Error);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_from_file_action(), &QAction::triggered, this, &EditTagDialog::LoadCoverFromFile);
|
QObject::connect(album_cover_choice_controller_->cover_from_file_action(), &QAction::triggered, this, &EditTagDialog::LoadCoverFromFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &EditTagDialog::SaveCoverToFile);
|
QObject::connect(album_cover_choice_controller_->cover_to_file_action(), &QAction::triggered, this, &EditTagDialog::SaveCoverToFile);
|
||||||
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &EditTagDialog::LoadCoverFromURL);
|
QObject::connect(album_cover_choice_controller_->cover_from_url_action(), &QAction::triggered, this, &EditTagDialog::LoadCoverFromURL);
|
||||||
|
|||||||
Reference in New Issue
Block a user