Exiv2 error handling implemented. Now it doesn't crash when there's a gif

This commit is contained in:
Austen Adler 2014-06-20 14:35:39 -04:00
parent 5e400c5d51
commit fdfdffc9b0
2 changed files with 16 additions and 8 deletions

View File

@ -3,6 +3,7 @@
#include <QDragEnterEvent>
#include <QMimeData>
#include <QRegExp>
#include <QMessageBox>
Picture::Picture(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Picture){
@ -31,7 +32,6 @@ void Picture::dropEvent(QDropEvent *event){
//qDebug() << "Dropped file:" << fileName;
}
}
void Picture::changeDirectory(){
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
if(path.isNull()==false){
@ -69,12 +69,20 @@ void Picture::on_erase_clicked(){
QImageReader reader(str);
if(!reader.format().isEmpty()){
QString fullPath=str;
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert (image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
exifData["Exif.Photo.UserComment"] = "charset=Ascii An ASCII Exif comment added with Exiv2";
image->writeMetadata();
try{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert (image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
exifData["Exif.Photo.UserComment"] = "charset=Ascii An ASCII Exif comment added with Exiv2";
image->writeMetadata();
}catch(Exiv2::AnyError& e){
QMessageBox msgBox;
msgBox.setInformativeText("The program could not process the file: "+fullPath);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret=msgBox.exec();
}
}else{
if(!ignored){
ignored=true;

View File

@ -41,7 +41,7 @@
<item>
<widget class="QPushButton" name="cd">
<property name="text">
<string>Change Directory</string>
<string>Open Directory</string>
</property>
</widget>
</item>