diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index 04272060..fa5004e9 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -1247,6 +1247,14 @@ MetaInfoDialog + + Load Artwork From File + + + + Clear Artwork + + Meta Information @@ -1255,6 +1263,18 @@ The following meta information have been extracted from the original file. + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/LameXP_DE.ts b/etc/Translation/LameXP_DE.ts index 5e09838d..bf86578d 100644 --- a/etc/Translation/LameXP_DE.ts +++ b/etc/Translation/LameXP_DE.ts @@ -1256,6 +1256,26 @@ The following meta information have been extracted from the original file. Die folgenden Meta-Informationen wurden aus der Originaldatei extrahiert. + + Load Artwork From File + Artwork aus Datei laden + + + Clear Artwork + Artwork löschen + + + Load Artwork + Artwork laden + + + Artwork Error + Artwork Fehler + + + Sorry, failed to load artwork from selected file! + Artwork konnte nicht aus der Ausgewählten Datei geladen werden! + MetaInfoModel diff --git a/etc/Translation/LameXP_ES.ts b/etc/Translation/LameXP_ES.ts index 75348768..8eb73366 100644 --- a/etc/Translation/LameXP_ES.ts +++ b/etc/Translation/LameXP_ES.ts @@ -1255,6 +1255,26 @@ The following meta information have been extracted from the original file. Los siguientes metadatos han sido extraídos del archivo original. + + Load Artwork From File + + + + Clear Artwork + + + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/LameXP_FR.ts b/etc/Translation/LameXP_FR.ts index a505d8ce..b228e53a 100644 --- a/etc/Translation/LameXP_FR.ts +++ b/etc/Translation/LameXP_FR.ts @@ -1264,6 +1264,26 @@ Sélection automatique (par défaut) The following meta information have been extracted from the original file. Les informations méta suivantes ont été extraites du fichier d'origine. + + Load Artwork From File + + + + Clear Artwork + + + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/LameXP_IT.ts b/etc/Translation/LameXP_IT.ts index 995db8d9..1082c57e 100644 --- a/etc/Translation/LameXP_IT.ts +++ b/etc/Translation/LameXP_IT.ts @@ -1256,6 +1256,26 @@ The following meta information have been extracted from the original file. Le seguenti meta informazioni sono state estratte dal file originale. + + Load Artwork From File + + + + Clear Artwork + + + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/LameXP_RU.ts b/etc/Translation/LameXP_RU.ts index eeba5434..830f433d 100644 --- a/etc/Translation/LameXP_RU.ts +++ b/etc/Translation/LameXP_RU.ts @@ -1258,6 +1258,26 @@ The following meta information have been extracted from the original file. Эта метаинформация была получена из исходного файла. + + Load Artwork From File + + + + Clear Artwork + + + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/LameXP_UK.ts b/etc/Translation/LameXP_UK.ts index e39beac8..be483e0a 100644 --- a/etc/Translation/LameXP_UK.ts +++ b/etc/Translation/LameXP_UK.ts @@ -1255,6 +1255,26 @@ The following meta information have been extracted from the original file. Дана метаінформація була витягнута з оригінального файла. + + Load Artwork From File + + + + Clear Artwork + + + + Load Artwork + + + + Artwork Error + + + + Sorry, failed to load artwork from selected file! + + MetaInfoModel diff --git a/etc/Translation/update.lst b/etc/Translation/update.lst index a1c8d4da..723b0fa5 100644 --- a/etc/Translation/update.lst +++ b/etc/Translation/update.lst @@ -46,6 +46,7 @@ ..\..\src\Global.cpp ..\..\src\LockedFile.cpp ..\..\src\Main.cpp +..\..\src\Model_Artwork.cpp ..\..\src\Model_AudioFile.cpp ..\..\src\Model_FileList.cpp ..\..\src\Model_FileSystem.cpp @@ -102,6 +103,7 @@ ..\..\src\Genres.h ..\..\src\Global.h ..\..\src\LockedFile.h +..\..\src\Model_Artwork.h ..\..\src\Model_AudioFile.h ..\..\src\Model_FileList.h ..\..\src\Model_FileSystem.h diff --git a/gui/MetaInfo.ui b/gui/MetaInfo.ui index 3b4db62c..a1bbb130 100644 --- a/gui/MetaInfo.ui +++ b/gui/MetaInfo.ui @@ -191,6 +191,9 @@ + + Qt::CustomContextMenu + QFrame::Box @@ -257,6 +260,9 @@ + + Qt::CustomContextMenu + (ARTWORK) @@ -488,6 +494,9 @@ + + + @@ -538,22 +547,6 @@ - - buttonArtwork - clicked(bool) - editButton - setDisabled(bool) - - - 55 - 396 - - - 468 - 396 - - - buttonArtwork clicked(bool) diff --git a/res/Images.qrc b/res/Images.qrc index 20622070..6b88d80a 100644 --- a/res/Images.qrc +++ b/res/Images.qrc @@ -2,6 +2,7 @@ images/Busy.gif + images/CD.png images/DropBox.png images/HeaderIcon_LogFile.png images/HeaderIcon_MetaInfo.png diff --git a/res/images/CD.png b/res/images/CD.png new file mode 100644 index 00000000..36e8a29f Binary files /dev/null and b/res/images/CD.png differ diff --git a/res/localization/LameXP_DE.qm b/res/localization/LameXP_DE.qm index 148fb3e3..30f925e5 100644 Binary files a/res/localization/LameXP_DE.qm and b/res/localization/LameXP_DE.qm differ diff --git a/src/Config.h b/src/Config.h index 0a3c7f27..73e8380a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 1 -#define VER_LAMEXP_BUILD 394 +#define VER_LAMEXP_BUILD 398 #define VER_LAMEXP_SUFFIX Beta-11 /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index d718d486..04c112af 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -2136,7 +2136,7 @@ void MainWindow::restoreCursor(void) void MainWindow::sourceFilesContextMenu(const QPoint &pos) { QAbstractScrollArea *scrollArea = dynamic_cast(QObject::sender()); - QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast(QObject::sender()); + QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast(QObject::sender()); if(sender) { diff --git a/src/Dialog_MetaInfo.cpp b/src/Dialog_MetaInfo.cpp index 2f835c14..45af622a 100644 --- a/src/Dialog_MetaInfo.cpp +++ b/src/Dialog_MetaInfo.cpp @@ -27,9 +27,18 @@ #include #include #include +#include +#include + +#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } + +//////////////////////////////////////////////////////////// +// Constructor & Destructor +//////////////////////////////////////////////////////////// MetaInfoDialog::MetaInfoDialog(QWidget *parent) - : QDialog(parent) +: + QDialog(parent) { //Init the dialog, from the .ui file setupUi(this); @@ -52,14 +61,29 @@ MetaInfoDialog::MetaInfoDialog(QWidget *parent) connect(downButton, SIGNAL(clicked()), this, SLOT(downButtonClicked())); connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked())); + //Create context menu + m_contextMenu = new QMenu(); + QAction *loadArtworkAction = m_contextMenu->addAction(QIcon(":/icons/folder_image.png"), tr("Load Artwork From File")); + QAction *clearArtworkAction = m_contextMenu->addAction(QIcon(":/icons/bin.png"), tr("Clear Artwork")); + SET_FONT_BOLD(loadArtworkAction, true); + connect(labelArtwork, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); + connect(frameArtwork, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); + connect(loadArtworkAction, SIGNAL(triggered(bool)), this, SLOT(editButtonClicked())); + connect(clearArtworkAction, SIGNAL(triggered(bool)), this, SLOT(clearArtworkActionTriggered())); + //Translate labelHeaderText->setText(QString("%1
%2").arg(tr("Meta Information"), tr("The following meta information have been extracted from the original file."))); } MetaInfoDialog::~MetaInfoDialog(void) { + LAMEXP_DELETE(m_contextMenu); } +//////////////////////////////////////////////////////////// +// Slots +//////////////////////////////////////////////////////////// + int MetaInfoDialog::exec(AudioFileModel &audioFile, bool allowUp, bool allowDown) { MetaInfoModel *model = new MetaInfoModel(&audioFile); @@ -71,25 +95,28 @@ int MetaInfoDialog::exec(AudioFileModel &audioFile, bool allowUp, bool allowDown upButton->setEnabled(allowUp); downButton->setEnabled(allowDown); buttonArtwork->setChecked(false); - buttonArtwork->setEnabled(false); if(!audioFile.fileCover().isEmpty()) { QImage artwork; if(artwork.load(audioFile.fileCover())) { - if((artwork.width() > 320) || (artwork.height() > 240)) + if((artwork.width() > 256) || (artwork.height() > 256)) { - artwork = artwork.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation); + artwork = artwork.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation); } labelArtwork->setPixmap(QPixmap::fromImage(artwork)); - buttonArtwork->setEnabled(true); } else { qWarning("Error: Failed to load cover art!"); + labelArtwork->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png"))); } } + else + { + labelArtwork->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png"))); + } int iResult = QDialog::exec(); @@ -111,5 +138,50 @@ void MetaInfoDialog::downButtonClicked(void) void MetaInfoDialog::editButtonClicked(void) { - dynamic_cast(tableView->model())->editItem(tableView->currentIndex(), this); + if(!buttonArtwork->isChecked()) + { + dynamic_cast(tableView->model())->editItem(tableView->currentIndex(), this); + return; + } + + QString fileName = QFileDialog::getOpenFileName(this, tr("Load Artwork"), QString(), QString::fromLatin1("JPEG (*.jpg);;PNG (*.png);;GIF (*.gif)")); + if(!fileName.isEmpty()) + { + QImage artwork; + if(artwork.load(fileName)) + { + if((artwork.width() > 256) || (artwork.height() > 256)) + { + artwork = artwork.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + dynamic_cast(tableView->model())->editArtwork(fileName); + labelArtwork->setPixmap(QPixmap::fromImage(artwork)); + } + else + { + qWarning("Error: Failed to load cover art!"); + QMessageBox::warning(this, tr("Artwork Error"), QString("%1

%2").arg(tr("Sorry, failed to load artwork from selected file!"), QDir::toNativeSeparators(fileName))); + } + } +} + + +void MetaInfoDialog::contextMenuRequested(const QPoint &pos) +{ + QAbstractScrollArea *scrollArea = dynamic_cast(QObject::sender()); + QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast(QObject::sender()); + + if(sender) + { + if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0) + { + m_contextMenu->popup(sender->mapToGlobal(pos)); + } + } +} + +void MetaInfoDialog::clearArtworkActionTriggered(void) +{ + labelArtwork->setPixmap(QPixmap::fromImage(QImage(":/images/CD.png"))); + dynamic_cast(tableView->model())->editArtwork(QString()); } diff --git a/src/Dialog_MetaInfo.h b/src/Dialog_MetaInfo.h index ced62a63..fcca527e 100644 --- a/src/Dialog_MetaInfo.h +++ b/src/Dialog_MetaInfo.h @@ -40,5 +40,9 @@ private slots: void upButtonClicked(void); void downButtonClicked(void); void editButtonClicked(void); + void contextMenuRequested(const QPoint &pos); + void clearArtworkActionTriggered(void); +private: + QMenu *m_contextMenu; }; diff --git a/src/Model_Artwork.cpp b/src/Model_Artwork.cpp index 00540005..8046f950 100644 --- a/src/Model_Artwork.cpp +++ b/src/Model_Artwork.cpp @@ -38,21 +38,24 @@ QMap ArtworkModel::m_fileHandle; ArtworkModel::ArtworkModel(void) { + m_isOwner = false; } -ArtworkModel::ArtworkModel(const QString &fileName) +ArtworkModel::ArtworkModel(const QString &fileName, bool isOwner) { - setFilePath(fileName); + m_isOwner = false; + setFilePath(fileName, isOwner); } ArtworkModel::ArtworkModel(const ArtworkModel &model) { - setFilePath(model.m_filePath); + m_isOwner = false; + setFilePath(model.m_filePath, model.m_isOwner); } ArtworkModel &ArtworkModel::operator=(const ArtworkModel &model) { - setFilePath(model.m_filePath); + setFilePath(model.m_filePath, model.m_isOwner); return (*this); } @@ -71,7 +74,12 @@ const QString &ArtworkModel::filePath(void) const return m_filePath; } -void ArtworkModel::setFilePath(const QString &newPath) +bool ArtworkModel::isOwner(void) const +{ + return m_isOwner; +} + +void ArtworkModel::setFilePath(const QString &newPath, bool isOwner) { if(newPath.isEmpty() || m_filePath.isEmpty() || QString::compare(m_filePath, newPath,Qt::CaseInsensitive)) { @@ -92,6 +100,7 @@ void ArtworkModel::setFilePath(const QString &newPath) } m_filePath = newPath; + m_isOwner = isOwner; } } @@ -111,15 +120,25 @@ void ArtworkModel:: clear(void) { if(QFile *fileHandle = m_fileHandle.take(m_filePath)) { - fileHandle->remove(); + if(m_isOwner) + { + fileHandle->remove(); + } + else + { + fileHandle->close(); + } LAMEXP_DELETE(fileHandle); } } - QFile::remove(m_filePath); + if(m_isOwner) + { + QFile::remove(m_filePath); + } } } - + m_filePath.clear(); } } diff --git a/src/Model_Artwork.h b/src/Model_Artwork.h index 2ad0ee9e..e3cc676a 100644 --- a/src/Model_Artwork.h +++ b/src/Model_Artwork.h @@ -31,17 +31,19 @@ class ArtworkModel { public: ArtworkModel(void); - ArtworkModel(const QString &fileName); + ArtworkModel(const QString &fileName, bool isOwner = true); ArtworkModel(const ArtworkModel &model); ArtworkModel &operator=(const ArtworkModel &model); ~ArtworkModel(void); const QString &filePath(void) const; - void setFilePath(const QString &newPath); + bool isOwner(void) const; + void setFilePath(const QString &newPath, bool isOwner = true); void clear(void); private: QString m_filePath; + bool m_isOwner; static QMutex m_mutex; static QMap m_refCount; diff --git a/src/Model_AudioFile.cpp b/src/Model_AudioFile.cpp index da220470..a6a2f2d9 100644 --- a/src/Model_AudioFile.cpp +++ b/src/Model_AudioFile.cpp @@ -60,7 +60,7 @@ AudioFileModel::AudioFileModel(const AudioFileModel &model, bool copyMetaInfo) setFileAlbum(model.m_fileAlbum); setFileGenre(model.m_fileGenre); setFileComment(model.m_fileComment); - setFileCover(model.m_fileCover.filePath()); + setFileCover(model.m_fileCover); setFileYear(model.m_fileYear); setFilePosition(model.m_filePosition); } @@ -74,7 +74,7 @@ AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model) setFileAlbum(model.m_fileAlbum); setFileGenre(model.m_fileGenre); setFileComment(model.m_fileComment); - setFileCover(model.m_fileCover.filePath()); + setFileCover(model.m_fileCover); setFileYear(model.m_fileYear); setFilePosition(model.m_filePosition); setFileDuration(model.m_fileDuration); @@ -337,9 +337,14 @@ void AudioFileModel::setFileComment(const QString &comment) m_fileComment = comment; } -void AudioFileModel::setFileCover(const QString &coverFile) +void AudioFileModel::setFileCover(const QString &coverFile, bool owner) { - m_fileCover = ArtworkModel(coverFile); + m_fileCover.setFilePath(coverFile, owner); +} + +void AudioFileModel::setFileCover(const ArtworkModel &model) +{ + m_fileCover = model; } void AudioFileModel::setFileYear(unsigned int year) diff --git a/src/Model_AudioFile.h b/src/Model_AudioFile.h index 74e99ab9..25031b4b 100644 --- a/src/Model_AudioFile.h +++ b/src/Model_AudioFile.h @@ -77,7 +77,8 @@ public: void setFileAlbum(const QString &album); void setFileGenre(const QString &genre); void setFileComment(const QString &comment); - void setFileCover(const QString &coverFile); + void setFileCover(const QString &coverFile, bool owner); + void setFileCover(const ArtworkModel &model); void setFileYear(unsigned int year); void setFilePosition(unsigned int position); void setFileDuration(unsigned int duration); diff --git a/src/Model_MetaInfo.cpp b/src/Model_MetaInfo.cpp index 104bd216..df0ca9d5 100644 --- a/src/Model_MetaInfo.cpp +++ b/src/Model_MetaInfo.cpp @@ -430,6 +430,11 @@ void MetaInfoModel::editItem(const QModelIndex &index, QWidget *parent) } } +void MetaInfoModel::editArtwork(const QString &imagePath) +{ + m_audioFile->setFileCover(imagePath, false); +} + void MetaInfoModel::clearData(void) { beginResetModel(); @@ -443,6 +448,7 @@ void MetaInfoModel::clearData(void) m_audioFile->setFileAlbum(QString()); m_audioFile->setFileGenre(QString()); m_audioFile->setFileComment(tr("Encoded with LameXP")); + m_audioFile->setFileCover(QString(), false); m_audioFile->setFileYear(0); m_audioFile->setFilePosition(UINT_MAX); m_audioFile->setFileDuration(0); diff --git a/src/Model_MetaInfo.h b/src/Model_MetaInfo.h index 74711092..855fa463 100644 --- a/src/Model_MetaInfo.h +++ b/src/Model_MetaInfo.h @@ -42,6 +42,7 @@ public: bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); Qt::ItemFlags flags(const QModelIndex &index) const; void editItem(const QModelIndex &index, QWidget *parent); + void editArtwork(const QString &imagePath); void clearData(void); private: diff --git a/src/Thread_FileAnalyzer.cpp b/src/Thread_FileAnalyzer.cpp index 20372298..3d8a087b 100644 --- a/src/Thread_FileAnalyzer.cpp +++ b/src/Thread_FileAnalyzer.cpp @@ -473,7 +473,7 @@ void FileAnalyzer::retrieveCover(AudioFileModel &audioFile, const QString &fileP { coverFile.write(coverData); coverFile.close(); - audioFile.setFileCover(coverFile.fileName()); + audioFile.setFileCover(coverFile.fileName(), true); } break; }