Merge branch 'lib' into 'master'

Merge lib with master
This commit is contained in:
Austen Adler 2014-06-25 20:01:57 -04:00
commit 6344a2653b
8 changed files with 323 additions and 251 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
./Picture.pro.user

View File

@ -17,8 +17,7 @@ SOURCES += main.cpp\
HEADERS += picture.h
FORMS += picture.ui \
preview.ui
FORMS += picture.ui
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += exiv2

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-06-18T20:10:29. -->
<!-- Written by QtCreator 3.0.1, 2014-06-25T16:15:57. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -54,7 +54,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{78915aca-1f52-4c43-bbd6-02dcf5b6f6cf}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">

View File

@ -1,11 +1,8 @@
#include "picture.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Picture w;
w.show();
return a.exec();
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Picture w;
w.show();
return a.exec();
}

View File

@ -1,39 +1,50 @@
//Includes{{{
#include "picture.h"
//}}}
//Decleration{{{
Picture::Picture(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Picture){
ui->setupUi(this);
connect(&commandProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(log()));
connect(&commandProcess,SIGNAL(readyReadStandardError()),this,SLOT(log()));
connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
setAcceptDrops(true);
//changeDirectory();
fillList();
}
void Picture::log(){
QByteArray cmdoutput = commandProcess.readAllStandardOutput();
QString txtoutput = cmdoutput;
ui->log->append(txtoutput);
cmdoutput = commandProcess.readAllStandardError();
txtoutput = cmdoutput;
ui->log->append(txtoutput);
}
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;
}
//}}}
//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);
}
}
//}}}
//Fill List{{{
void Picture::fillList() {
ui->fileList->clear();
foreach(const QString &str,directory.entryList()){
QImageReader reader(directory.absolutePath()+"/"+str);
if(!reader.format().isEmpty()){
QString itemString=directory.path()+"/"+str;
ui->fileList->addItem(itemString);
}
}
}
//}}}
//Change Directory{{{
void Picture::on_cd_clicked(){
changeDirectory();
}
void Picture::changeDirectory(){
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
if(path.isNull()==false){
@ -44,35 +55,71 @@ void Picture::changeDirectory(){
ui->log->append("Could not change directory");
}
}
void Picture::fillList() {
//}}}
//Clear File List{{{
void Picture::on_refresh_clicked(){
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("<NO PICTURES>");
}
ui->log->append("Cleared File List");
}
void Picture::on_cd_clicked(){
changeDirectory();
//}}}
//Clear Log{{{
void Picture::on_clearLog_clicked(){
ui->log->setText("");
ui->tabField->setCurrentIndex(0);
}
void Picture::on_erase_clicked(){
//}}}
//Process Images{{{
//Switch Tab{{{
void Picture::on_processButton_pressed(){
ui->log->append("Processing images...");
ui->tabField->setCurrentIndex(1);
on_processButton_clicked();
}
//}}}
void Picture::on_processButton_clicked(){
bool ignored=false;
foreach(const QString &str,directory.entryList()){
QString tmp=QString("exiv2 rm ");
QImageReader reader(directory.absolutePath()+"/"+str);
//Populate File List{{{
QStringList myStringList;
for(int i=0;i<ui->fileList->count();++i){
myStringList.append(ui->fileList->item(i)->text());
}
//}}}
foreach(const QString &str,myStringList){
QImageReader reader(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);
commandProcess.start(a);
QString fullPath=str;
try{
//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();
//}}}
//Erase Metadata{{{
}else{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert(image.get()!=0);
image->readMetadata();
image->clearMetadata();
image->writeMetadata();
}
//}}}
//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();
}
//}}}
//List Ignored Files{{{
}else{
if(!ignored){
ignored=true;
@ -80,19 +127,27 @@ void Picture::on_erase_clicked(){
}
ui->log->append(str);
}
//}}}
}
ui->log->append("Done erasing metadata");
ui->log->append("Done processing metadata");
}
void Picture::on_refresh_clicked(){
fillList();
ui->log->append("Refreshed directory");
}
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();
//}}}
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()); */
}

View File

@ -1,11 +1,9 @@
#ifndef PICTURE_H
#define PICTURE_H
#include <QMainWindow>
#include <QDir>
#include <QFileDialog>
#include "ui_picture.h"
#include "ui_preview.h"
#include <syscall.h>
#include <string>
#include <iostream>
@ -14,31 +12,38 @@
#include <QImageReader>
#include <QDialog>
#include <QProcess>
#include <exiv2/exiv2.hpp>
#include <cassert>
#include <QDrag>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QRegExp>
#include <QMessageBox>
namespace Ui {
class Picture;
class Preview;
class Picture;
class Preview;
}
class Picture : public QMainWindow {
Q_OBJECT
class Picture : public QMainWindow
{
Q_OBJECT
public:
public:
explicit Picture(QWidget *parent = 0);
~Picture();
private slots:
void changeDirectory();
private slots:
void changeDirectory();
void fillList();
void on_cd_clicked();
void on_erase_clicked();
void on_refresh_clicked();
void on_clearLog_clicked();
void on_erase_pressed();
void log();
void on_processButton_clicked();
void on_processButton_pressed();
void on_fileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
private:
Ui::Picture *ui;
QDir directory;
QProcess commandProcess;
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
};
#endif // PICTURE_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>656</width>
<height>350</height>
<width>783</width>
<height>607</height>
</rect>
</property>
<property name="windowTitle">
@ -19,8 +19,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>301</height>
<width>651</width>
<height>411</height>
</rect>
</property>
<property name="currentIndex">
@ -30,101 +30,117 @@
<attribute name="title">
<string>Commands</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>258</width>
<height>229</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="fileList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cd">
<property name="text">
<string>Change Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Refresh Directory</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>300</x>
<y>60</y>
<width>107</width>
<height>62</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="erase">
<property name="text">
<string>Erase Metadata</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
</layout>
</widget>
<zorder>fileList</zorder>
<zorder>fileList</zorder>
<zorder>layoutWidget</zorder>
<zorder>erase</zorder>
<zorder>pushButton</zorder>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="fileList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cd">
<property name="text">
<string>Open Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Clear File List</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="gpsData"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="labelImagesRadio">
<property name="text">
<string>Label Images</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="eraseAllRadio">
<property name="text">
<string>Erase All Metadata</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelLabel">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="labelText"/>
</item>
<item>
<widget class="QCheckBox" name="eraseOtherMetadata">
<property name="text">
<string>Erase Other Metadata</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="eraseGpsData">
<property name="text">
<string>Set GPS Data From Above</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="processButton">
<property name="text">
<string>Process</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Log</string>
</attribute>
<widget class="QTextEdit" name="log">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>192</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="clearLog">
<property name="geometry">
<rect>
<x>270</x>
<y>220</y>
<width>51</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTextEdit" name="log">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearLog">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
@ -133,7 +149,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>656</width>
<width>783</width>
<height>21</height>
</rect>
</property>
@ -162,5 +178,70 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
<connections>
<connection>
<sender>eraseOtherMetadata</sender>
<signal>toggled(bool)</signal>
<receiver>eraseGpsData</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>428</x>
<y>367</y>
</hint>
<hint type="destinationlabel">
<x>432</x>
<y>387</y>
</hint>
</hints>
</connection>
<connection>
<sender>eraseAllRadio</sender>
<signal>toggled(bool)</signal>
<receiver>labelText</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>527</x>
<y>120</y>
</hint>
<hint type="destinationlabel">
<x>457</x>
<y>332</y>
</hint>
</hints>
</connection>
<connection>
<sender>eraseAllRadio</sender>
<signal>toggled(bool)</signal>
<receiver>eraseOtherMetadata</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>583</x>
<y>120</y>
</hint>
<hint type="destinationlabel">
<x>381</x>
<y>369</y>
</hint>
</hints>
</connection>
<connection>
<sender>eraseAllRadio</sender>
<signal>toggled(bool)</signal>
<receiver>eraseGpsData</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>601</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>539</x>
<y>386</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,66 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>334</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>1</x>
<y>1</y>
<width>120</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Process this picture?</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>1</x>
<y>22</y>
<width>431</width>
<height>311</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QGraphicsView" name="image"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="noButton">
<property name="text">
<string>No (n)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="yesButton">
<property name="text">
<string>Yes (y)</string>
</property>
</widget>
</item>
</layout>
</widget>
<zorder>buttonBox</zorder>
<zorder>image</zorder>
<zorder>buttonBox</zorder>
<zorder>noButton</zorder>
<zorder>yesButton</zorder>
</widget>
<resources/>
<connections/>
</ui>