metapicture/picture.cpp

154 lines
4.3 KiB
C++
Raw Normal View History

2014-06-24 00:07:14 -04:00
//Includes{{{
2014-06-18 13:22:19 -04:00
#include "picture.h"
2014-06-24 00:07:14 -04:00
//}}}
//Decleration{{{
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()));
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-24 00:07:14 -04:00
//}}}
//Drag and Drop{{{
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();
ui->fileList->addItem(fileName);
}
}
2014-06-24 00:07:14 -04:00
//}}}
//Fill List{{{
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
foreach(const QString &str,directory.entryList()){
2014-06-18 21:32:10 -04:00
QImageReader reader(directory.absolutePath()+"/"+str);
if(!reader.format().isEmpty()){
QString itemString=directory.path()+"/"+str;
ui->fileList->addItem(itemString);
2014-06-18 21:32:10 -04:00
}
2014-06-18 19:15:35 -04:00
}
2014-06-18 13:22:19 -04:00
}
2014-06-24 00:07:14 -04:00
//}}}
//Change Directory{{{
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
}
2014-06-24 00:07:14 -04:00
void Picture::changeDirectory(){
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
if(path.isNull()==false){
directory.setPath(path);
fillList();
ui->log->append("Changed directory to: "+path+"/");
}else{
ui->log->append("Could not change directory");
}
}
//}}}
//Clear File List{{{
2014-06-18 15:23:12 -04:00
void Picture::on_refresh_clicked(){
ui->fileList->clear();
ui->log->append("Cleared File List");
2014-06-18 13:22:19 -04:00
}
2014-06-24 00:07:14 -04:00
//}}}
//Clear Log{{{
void Picture::on_clearLog_clicked(){
ui->log->setText("");
2014-06-18 21:32:10 -04:00
ui->tabField->setCurrentIndex(0);
}
2014-06-24 00:07:14 -04:00
//}}}
//Process Images{{{
//Switch Tab{{{
void Picture::on_processButton_pressed(){
ui->log->append("Processing images...");
ui->tabField->setCurrentIndex(1);
on_processButton_clicked();
}
2014-06-24 00:07:14 -04:00
//}}}
void Picture::on_processButton_clicked(){
bool ignored=false;
2014-06-24 00:07:14 -04:00
//Populate File List{{{
QStringList myStringList;
2014-06-24 00:07:14 -04:00
for(int i=0;i<ui->fileList->count();++i){
myStringList.append(ui->fileList->item(i)->text());
}
2014-06-24 00:07:14 -04:00
//}}}
foreach(const QString &str,myStringList){
QImageReader reader(str);
if(!reader.format().isEmpty()){
QString fullPath=str;
try{
2014-06-24 00:07:14 -04:00
//Label Images{{{
if(ui->labelImagesRadio->isChecked()){
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert (image.get()!=0);
image->readMetadata();
if(ui->eraseOtherMetadata->isChecked()){
image->clearMetadata();
}
Exiv2::ExifData &exifData=image->exifData();
exifData["Exif.Photo.UserComment"] = "charset=Ascii "+ui->labelText->text().toStdString();
image->writeMetadata();
2014-06-24 00:07:14 -04:00
//}}}
//Erase Metadata{{{
}else{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
2014-06-24 00:07:14 -04:00
assert(image.get()!=0);
image->readMetadata();
image->clearMetadata();
image->writeMetadata();
}
2014-06-24 00:07:14 -04:00
//}}}
//Catch{{{
}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-24 00:07:14 -04:00
//}}}
//List Ignored Files{{{
}else{
if(!ignored){
ignored=true;
ui->log->append("Ignored Files:");
}
ui->log->append(str);
}
2014-06-24 00:07:14 -04:00
//}}}
}
2014-06-24 00:07:14 -04:00
ui->log->append("Done processing metadata");
}
2014-06-24 00:07:14 -04:00
//}}}
void Picture::on_fileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) {
ui->gpsData->clear();
QString tmp=current->text();
std::string tmp2=tmp.toStdString();
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(tmp2);
assert(image.get()!=0);
image->readMetadata();
Exiv2::ExifData &exifData=image->exifData();
std::string arrStr[7]={"GPSLatitudeRef","GPSLatitude","GPSLongitudeRef","GPSLongitude","GPSAltitudeRef","GPSAltitude","GPSTimeStamp"};
for(int i=0;i<7;i++){
Exiv2::Exifdatum gps=exifData["Exif.GPSInfo."+arrStr[i]];
std::string a;
a=gps.toString();
ui->gpsData->append(QString::fromStdString(a));
//qDebug()<<arrStr[i];
}
/* ui->gpsData->append(GPSLatitudeRef.toString()); */
}