#include "picture.h" #include #include #include #include #include Picture::Picture(QWidget *parent) : QMainWindow(parent), ui(new Ui::Picture){ ui->setupUi(this); connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory())); setAcceptDrops(true); //changeDirectory(); fillList(); } Picture::~Picture(){ delete ui; } void Picture::dragEnterEvent(QDragEnterEvent *event){ if(event->mimeData()->hasUrls()){ ui->tabField->setCurrentIndex(0); event->acceptProposedAction(); } } void Picture::dropEvent(QDropEvent *event){ foreach (const QUrl &url, event->mimeData()->urls()) { const QString &fileName = url.toLocalFile(); //if(fileName.contains(QRegExp("\.(?i)(jpe?g|png|gif)$"))){ ui->fileList->addItem(fileName); //}else{ // qDebug()<log->append("Changed directory to: "+path+"/"); }else{ ui->log->append("Could not change directory"); } } void Picture::fillList() { ui->fileList->clear(); //ui->fileList->addItems(directory.entryList()); foreach(const QString &str,directory.entryList()){ QImageReader reader(directory.absolutePath()+"/"+str); if(!reader.format().isEmpty()){ ui->fileList->addItem(str); } } if(ui->fileList->count()==0){ //ui->fileList->addItem(""); } } void Picture::on_cd_clicked(){ changeDirectory(); } void Picture::on_erase_clicked(){ bool ignored=false; QStringList myStringList; for (int i = 0; i < ui->fileList->count(); ++i) myStringList.append(ui->fileList->item(i)->text()); qDebug() << myStringList; //foreach(const QString &str,directory.entryList()){ foreach(const QString &str,myStringList){ QImageReader reader(str); if(!reader.format().isEmpty()){ QString fullPath=str; try{ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString()); assert (image.get() != 0); image->readMetadata(); image->clearMetadata(); 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; ui->log->append("Ignored Files:"); } ui->log->append(str); } } ui->log->append("Done erasing metadata"); } void Picture::on_refresh_clicked(){ //fillList(); ui->fileList->clear(); ui->log->append("Cleared File List"); } void Picture::on_clearLog_clicked(){ ui->log->setText(""); ui->tabField->setCurrentIndex(0); } void Picture::on_erase_pressed(){ ui->log->append("Erasing metadata from images..."); ui->tabField->setCurrentIndex(1); on_erase_clicked(); } void Picture::on_processButton_pressed(){ ui->log->append("Processing images..."); ui->tabField->setCurrentIndex(1); on_processButton_clicked(); } void Picture::on_processButton_clicked(){ bool ignored=false; QStringList myStringList; for (int i=0;ifileList->count();++i){ myStringList.append(ui->fileList->item(i)->text()); } qDebug()<readMetadata(); if(ui->eraseOtherMetadata->isChecked()){ image->clearMetadata(); } Exiv2::ExifData &exifData=image->exifData(); exifData["Exif.Photo.UserComment"] = "charset=Ascii "+ui->labelText->text().toStdString(); 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); msgBox.exec(); } }else{ if(!ignored){ ignored=true; ui->log->append("Ignored Files:"); } ui->log->append(str); } } ui->log->append("Done erasing metadata"); }