2014-06-18 13:22:19 -04:00
|
|
|
#include "picture.h"
|
2014-06-19 14:13:48 -04:00
|
|
|
#include <QDrag>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QRegExp>
|
2014-06-20 14:35:39 -04:00
|
|
|
#include <QMessageBox>
|
2014-06-18 13:22:19 -04:00
|
|
|
Picture::Picture(QWidget *parent) :
|
2014-06-18 15:23:12 -04:00
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::Picture){
|
2014-06-18 13:22:19 -04:00
|
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
|
2014-06-19 14:13:48 -04:00
|
|
|
setAcceptDrops(true);
|
2014-06-18 15:23:12 -04:00
|
|
|
//changeDirectory();
|
2014-06-18 13:22:19 -04:00
|
|
|
fillList();
|
2014-06-18 15:23:12 -04:00
|
|
|
}
|
2014-06-18 13:22:19 -04:00
|
|
|
Picture::~Picture(){
|
2014-06-18 15:23:12 -04:00
|
|
|
delete ui;
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
2014-06-19 14:13:48 -04:00
|
|
|
void Picture::dragEnterEvent(QDragEnterEvent *event){
|
2014-06-20 13:39:10 -04:00
|
|
|
if(event->mimeData()->hasUrls()){
|
2014-06-21 17:17:00 -04:00
|
|
|
ui->tabField->setCurrentIndex(0);
|
2014-06-20 13:39:10 -04:00
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
2014-06-19 14:13:48 -04:00
|
|
|
}
|
|
|
|
void Picture::dropEvent(QDropEvent *event){
|
2014-06-20 13:39:10 -04:00
|
|
|
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()<<fileName;
|
|
|
|
//}
|
|
|
|
//qDebug() << "Dropped file:" << fileName;
|
|
|
|
}
|
2014-06-19 14:13:48 -04:00
|
|
|
}
|
2014-06-18 13:22:19 -04:00
|
|
|
void Picture::changeDirectory(){
|
2014-06-18 15:23:12 -04:00
|
|
|
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
|
|
|
|
if(path.isNull()==false){
|
|
|
|
directory.setPath(path);
|
|
|
|
fillList();
|
2014-06-18 16:00:39 -04:00
|
|
|
ui->log->append("Changed directory to: "+path+"/");
|
|
|
|
}else{
|
|
|
|
ui->log->append("Could not change directory");
|
2014-06-18 15:23:12 -04:00
|
|
|
}
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
|
|
|
void Picture::fillList() {
|
2014-06-18 15:23:12 -04:00
|
|
|
ui->fileList->clear();
|
2014-06-18 19:15:35 -04:00
|
|
|
//ui->fileList->addItems(directory.entryList());
|
|
|
|
foreach(const QString &str,directory.entryList()){
|
2014-06-18 21:32:10 -04:00
|
|
|
QImageReader reader(directory.absolutePath()+"/"+str);
|
|
|
|
if(!reader.format().isEmpty()){
|
|
|
|
ui->fileList->addItem(str);
|
|
|
|
}
|
2014-06-18 19:15:35 -04:00
|
|
|
}
|
|
|
|
if(ui->fileList->count()==0){
|
2014-06-19 14:13:48 -04:00
|
|
|
//ui->fileList->addItem("<NO PICTURES>");
|
2014-06-18 19:15:35 -04:00
|
|
|
}
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
|
|
|
void Picture::on_cd_clicked(){
|
2014-06-18 15:23:12 -04:00
|
|
|
changeDirectory();
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
|
|
|
void Picture::on_erase_clicked(){
|
2014-06-18 16:00:39 -04:00
|
|
|
bool ignored=false;
|
2014-06-20 13:39:10 -04:00
|
|
|
QStringList myStringList;
|
|
|
|
for (int i = 0; i < ui->fileList->count(); ++i)
|
|
|
|
myStringList.append(ui->fileList->item(i)->text());
|
|
|
|
qDebug() << myStringList;
|
2014-06-19 14:13:48 -04:00
|
|
|
//foreach(const QString &str,directory.entryList()){
|
|
|
|
foreach(const QString &str,myStringList){
|
2014-06-20 13:39:10 -04:00
|
|
|
QImageReader reader(str);
|
2014-06-18 15:23:12 -04:00
|
|
|
if(!reader.format().isEmpty()){
|
2014-06-20 13:39:10 -04:00
|
|
|
QString fullPath=str;
|
2014-06-20 14:35:39 -04:00
|
|
|
try{
|
|
|
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
|
|
|
|
assert (image.get() != 0);
|
|
|
|
image->readMetadata();
|
2014-06-21 17:17:00 -04:00
|
|
|
image->clearMetadata();
|
2014-06-20 14:35:39 -04:00
|
|
|
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();
|
|
|
|
}
|
2014-06-18 15:23:12 -04:00
|
|
|
}else{
|
2014-06-18 16:00:39 -04:00
|
|
|
if(!ignored){
|
|
|
|
ignored=true;
|
|
|
|
ui->log->append("Ignored Files:");
|
|
|
|
}
|
|
|
|
ui->log->append(str);
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
2014-06-18 15:23:12 -04:00
|
|
|
}
|
2014-06-18 16:00:39 -04:00
|
|
|
ui->log->append("Done erasing metadata");
|
2014-06-18 15:23:12 -04:00
|
|
|
}
|
|
|
|
void Picture::on_refresh_clicked(){
|
2014-06-19 14:13:48 -04:00
|
|
|
//fillList();
|
|
|
|
ui->fileList->clear();
|
|
|
|
ui->log->append("Cleared File List");
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
2014-06-18 16:00:39 -04:00
|
|
|
void Picture::on_clearLog_clicked(){
|
|
|
|
ui->log->setText("");
|
2014-06-18 21:32:10 -04:00
|
|
|
ui->tabField->setCurrentIndex(0);
|
2014-06-18 16:00:39 -04:00
|
|
|
}
|
2014-06-18 19:15:35 -04:00
|
|
|
void Picture::on_erase_pressed(){
|
2014-06-18 16:00:39 -04:00
|
|
|
ui->log->append("Erasing metadata from images...");
|
2014-06-18 21:32:10 -04:00
|
|
|
ui->tabField->setCurrentIndex(1);
|
|
|
|
on_erase_clicked();
|
2014-06-18 16:00:39 -04:00
|
|
|
}
|
2014-06-21 17:17:00 -04:00
|
|
|
void Picture::on_processButton_pressed(){
|
|
|
|
ui->log->append("Processing images...");
|
|
|
|
ui->tabField->setCurrentIndex(1);
|
|
|
|
on_processButton_clicked();
|
|
|
|
}
|
|
|
|
void Picture::on_processButton_clicked(){
|
2014-06-22 19:51:33 -04:00
|
|
|
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,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();
|
|
|
|
if(ui->eraseOtherMetadata->isChecked()){
|
|
|
|
image->clearMetadata();
|
2014-06-21 17:17:00 -04:00
|
|
|
}
|
2014-06-22 19:51:33 -04:00
|
|
|
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();
|
2014-06-21 17:17:00 -04:00
|
|
|
}
|
2014-06-22 19:51:33 -04:00
|
|
|
}else{
|
|
|
|
if(!ignored){
|
|
|
|
ignored=true;
|
|
|
|
ui->log->append("Ignored Files:");
|
|
|
|
}
|
|
|
|
ui->log->append(str);
|
2014-06-21 17:17:00 -04:00
|
|
|
}
|
2014-06-22 19:51:33 -04:00
|
|
|
}
|
|
|
|
ui->log->append("Done erasing metadata");
|
2014-06-21 17:17:00 -04:00
|
|
|
}
|