77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#include "picture.h"
|
|
#include "ui_picture.h"
|
|
#include <syscall.h>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <stdio.h>
|
|
#include <QDebug>
|
|
#include <QImageReader>
|
|
|
|
Picture::Picture(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::Picture){
|
|
ui->setupUi(this);
|
|
connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
|
|
//changeDirectory();
|
|
fillList();
|
|
}
|
|
std::string exec(char* cmd) {
|
|
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;
|
|
}
|
|
}
|
|
pclose(pipe);
|
|
return result;
|
|
}
|
|
Picture::~Picture(){
|
|
delete ui;
|
|
}
|
|
void Picture::changeDirectory(){
|
|
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
|
|
if(path.isNull()==false){
|
|
directory.setPath(path);
|
|
fillList();
|
|
}
|
|
//exec("which exiv2>>/tmp/log");
|
|
}
|
|
|
|
void Picture::fillList() {
|
|
ui->fileList->clear();
|
|
ui->fileList->addItems(directory.entryList());
|
|
}
|
|
|
|
void Picture::on_cd_clicked(){
|
|
changeDirectory();
|
|
}
|
|
|
|
void Picture::on_erase_clicked(){
|
|
foreach(const QString &str,directory.entryList()){
|
|
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);
|
|
}else{
|
|
tmp="echo "+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);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Picture::on_refresh_clicked(){
|
|
fillList();
|
|
}
|