#include "picture.h" #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()){ 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){ QString tmp=QString("exiv2 rm "); QImageReader reader(directory.absolutePath()+"/"+str); if(!reader.format().isEmpty()){ tmp+=directory.absolutePath()+"/"+str+">>/tmp/log"; std::string tmp2=tmp.toStdString(); char* a=new char[tmp2.size()+1]; a[tmp2.size()]=0; memcpy(a,tmp2.c_str(),tmp2.size()); //exec(a); //ui->log->append(str); QString fullPath=directory.absolutePath()+"/"+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(); }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(); }