2014-06-18 13:22:19 -04:00
|
|
|
#include "picture.h"
|
|
|
|
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);
|
2014-06-18 21:32:10 -04:00
|
|
|
connect(&commandProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(log()));
|
|
|
|
connect(&commandProcess,SIGNAL(readyReadStandardError()),this,SLOT(log()));
|
2014-06-18 13:22:19 -04:00
|
|
|
connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
|
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 21:32:10 -04:00
|
|
|
void Picture::log(){
|
|
|
|
QByteArray cmdoutput = commandProcess.readAllStandardOutput();
|
|
|
|
QString txtoutput = cmdoutput;
|
|
|
|
ui->log->append(txtoutput);
|
|
|
|
cmdoutput = commandProcess.readAllStandardError();
|
|
|
|
txtoutput = cmdoutput;
|
|
|
|
ui->log->append(txtoutput);
|
|
|
|
}
|
|
|
|
|
2014-06-18 13:22:19 -04:00
|
|
|
std::string exec(char* cmd) {
|
2014-06-18 15:23:12 -04:00
|
|
|
FILE* pipe = popen(cmd, "r");
|
|
|
|
if (!pipe) return "ERROR";
|
|
|
|
char buffer[128];
|
|
|
|
std::string result = "";
|
|
|
|
while(!feof(pipe)) {
|
|
|
|
if(fgets(buffer, 128, pipe) != NULL){
|
|
|
|
result += buffer;
|
2014-06-18 13:22:19 -04:00
|
|
|
}
|
2014-06-18 15:23:12 -04:00
|
|
|
}
|
|
|
|
pclose(pipe);
|
|
|
|
return result;
|
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
|
|
|
}
|
|
|
|
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-18 21:32:10 -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-18 15:23:12 -04:00
|
|
|
foreach(const QString &str,directory.entryList()){
|
|
|
|
QString tmp=QString("exiv2 rm ");
|
|
|
|
QImageReader reader(directory.absolutePath()+"/"+str);
|
|
|
|
if(!reader.format().isEmpty()){
|
2014-06-18 16:00:39 -04:00
|
|
|
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());
|
2014-06-18 21:32:10 -04:00
|
|
|
//exec(a);
|
|
|
|
commandProcess.start(a);
|
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(){
|
|
|
|
fillList();
|
2014-06-18 21:32:10 -04:00
|
|
|
ui->log->append("Refreshed directory");
|
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
|
|
|
}
|