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 HEADERS += picture.h
FORMS += picture.ui \ FORMS += picture.ui
preview.ui
unix: CONFIG += link_pkgconfig unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += exiv2 unix: PKGCONFIG += exiv2

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -54,7 +54,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">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="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.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">

View File

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

View File

@ -1,39 +1,50 @@
//Includes{{{
#include "picture.h" #include "picture.h"
//}}}
//Decleration{{{
Picture::Picture(QWidget *parent) : Picture::Picture(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::Picture){ ui(new Ui::Picture){
ui->setupUi(this); 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())); connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory()));
setAcceptDrops(true);
//changeDirectory(); //changeDirectory();
fillList(); 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(){ Picture::~Picture(){
delete ui; 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(){ void Picture::changeDirectory(){
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path()); QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
if(path.isNull()==false){ if(path.isNull()==false){
@ -44,35 +55,71 @@ void Picture::changeDirectory(){
ui->log->append("Could not change directory"); ui->log->append("Could not change directory");
} }
} }
void Picture::fillList() { //}}}
//Clear File List{{{
void Picture::on_refresh_clicked(){
ui->fileList->clear(); ui->fileList->clear();
//ui->fileList->addItems(directory.entryList()); ui->log->append("Cleared File List");
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>");
}
} }
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; bool ignored=false;
foreach(const QString &str,directory.entryList()){ //Populate File List{{{
QString tmp=QString("exiv2 rm "); QStringList myStringList;
QImageReader reader(directory.absolutePath()+"/"+str); 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()){ if(!reader.format().isEmpty()){
tmp+=directory.absolutePath()+"/"+str+">>/tmp/log"; QString fullPath=str;
std::string tmp2=tmp.toStdString(); try{
char* a=new char[tmp2.size()+1]; //Label Images{{{
a[tmp2.size()]=0; if(ui->labelImagesRadio->isChecked()){
memcpy(a,tmp2.c_str(),tmp2.size()); Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
//exec(a); assert (image.get()!=0);
commandProcess.start(a); 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{ }else{
if(!ignored){ if(!ignored){
ignored=true; ignored=true;
@ -80,19 +127,27 @@ void Picture::on_erase_clicked(){
} }
ui->log->append(str); ui->log->append(str);
} }
//}}}
} }
ui->log->append("Done erasing metadata"); ui->log->append("Done processing metadata");
} }
void Picture::on_refresh_clicked(){ //}}}
fillList(); void Picture::on_fileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) {
ui->log->append("Refreshed directory"); ui->gpsData->clear();
} QString tmp=current->text();
void Picture::on_clearLog_clicked(){ std::string tmp2=tmp.toStdString();
ui->log->setText(""); Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(tmp2);
ui->tabField->setCurrentIndex(0); assert(image.get()!=0);
} image->readMetadata();
void Picture::on_erase_pressed(){ Exiv2::ExifData &exifData=image->exifData();
ui->log->append("Erasing metadata from images..."); std::string arrStr[7]={"GPSLatitudeRef","GPSLatitude","GPSLongitudeRef","GPSLongitude","GPSAltitudeRef","GPSAltitude","GPSTimeStamp"};
ui->tabField->setCurrentIndex(1); for(int i=0;i<7;i++){
on_erase_clicked(); 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 #ifndef PICTURE_H
#define PICTURE_H #define PICTURE_H
#include <QMainWindow> #include <QMainWindow>
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
#include "ui_picture.h" #include "ui_picture.h"
#include "ui_preview.h"
#include <syscall.h> #include <syscall.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
@ -14,31 +12,38 @@
#include <QImageReader> #include <QImageReader>
#include <QDialog> #include <QDialog>
#include <QProcess> #include <QProcess>
#include <exiv2/exiv2.hpp>
#include <cassert>
#include <QDrag>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QRegExp>
#include <QMessageBox>
namespace Ui { namespace Ui {
class Picture; class Picture;
class Preview; class Preview;
} }
class Picture : public QMainWindow {
Q_OBJECT
class Picture : public QMainWindow public:
{
Q_OBJECT
public:
explicit Picture(QWidget *parent = 0); explicit Picture(QWidget *parent = 0);
~Picture(); ~Picture();
private slots: private slots:
void changeDirectory(); void changeDirectory();
void fillList(); void fillList();
void on_cd_clicked(); void on_cd_clicked();
void on_erase_clicked();
void on_refresh_clicked(); void on_refresh_clicked();
void on_clearLog_clicked(); void on_clearLog_clicked();
void on_erase_pressed(); void on_processButton_clicked();
void log(); void on_processButton_pressed();
void on_fileList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
private: private:
Ui::Picture *ui; Ui::Picture *ui;
QDir directory; QDir directory;
QProcess commandProcess; protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
}; };
#endif // PICTURE_H #endif // PICTURE_H

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>656</width> <width>783</width>
<height>350</height> <height>607</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -19,8 +19,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>471</width> <width>651</width>
<height>301</height> <height>411</height>
</rect> </rect>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
@ -30,101 +30,117 @@
<attribute name="title"> <attribute name="title">
<string>Commands</string> <string>Commands</string>
</attribute> </attribute>
<widget class="QWidget" name="layoutWidget"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="geometry"> <item>
<rect> <layout class="QVBoxLayout" name="verticalLayout">
<x>20</x> <item>
<y>20</y> <widget class="QListWidget" name="fileList"/>
<width>258</width> </item>
<height>229</height> <item>
</rect> <layout class="QHBoxLayout" name="horizontalLayout">
</property> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="QPushButton" name="cd">
<item> <property name="text">
<widget class="QListWidget" name="fileList"/> <string>Open Directory</string>
</item> </property>
<item> </widget>
<layout class="QHBoxLayout" name="horizontalLayout"> </item>
<item> <item>
<widget class="QPushButton" name="cd"> <widget class="QPushButton" name="refresh">
<property name="text"> <property name="text">
<string>Change Directory</string> <string>Clear File List</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QPushButton" name="refresh"> </item>
<property name="text"> </layout>
<string>Refresh Directory</string> </item>
</property> <item>
</widget> <layout class="QVBoxLayout" name="verticalLayout_2">
</item> <item>
</layout> <widget class="QTextEdit" name="gpsData"/>
</item> </item>
</layout> <item>
</widget> <layout class="QHBoxLayout" name="horizontalLayout_3">
<widget class="QWidget" name=""> <item>
<property name="geometry"> <widget class="QRadioButton" name="labelImagesRadio">
<rect> <property name="text">
<x>300</x> <string>Label Images</string>
<y>60</y> </property>
<width>107</width> <property name="checked">
<height>62</height> <bool>true</bool>
</rect> </property>
</property> </widget>
<layout class="QVBoxLayout" name="verticalLayout_2"> </item>
<item> <item>
<widget class="QPushButton" name="erase"> <widget class="QRadioButton" name="eraseAllRadio">
<property name="text"> <property name="text">
<string>Erase Metadata</string> <string>Erase All Metadata</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> </layout>
<widget class="QPushButton" name="pushButton"> </item>
<property name="text"> <item>
<string>Label</string> <widget class="QLabel" name="labelLabel">
</property> <property name="text">
</widget> <string>Label</string>
</item> </property>
</layout> </widget>
</widget> </item>
<zorder>fileList</zorder> <item>
<zorder>fileList</zorder> <widget class="QLineEdit" name="labelText"/>
<zorder>layoutWidget</zorder> </item>
<zorder>erase</zorder> <item>
<zorder>pushButton</zorder> <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>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="tab_2">
<attribute name="title"> <attribute name="title">
<string>Log</string> <string>Log</string>
</attribute> </attribute>
<widget class="QTextEdit" name="log"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="geometry"> <item>
<rect> <layout class="QVBoxLayout" name="verticalLayout_3">
<x>10</x> <item>
<y>10</y> <widget class="QTextEdit" name="log">
<width>381</width> <property name="readOnly">
<height>192</height> <bool>true</bool>
</rect> </property>
</property> </widget>
<property name="readOnly"> </item>
<bool>true</bool> <item>
</property> <widget class="QPushButton" name="clearLog">
</widget> <property name="text">
<widget class="QPushButton" name="clearLog"> <string>Clear</string>
<property name="geometry"> </property>
<rect> </widget>
<x>270</x> </item>
<y>220</y> </layout>
<width>51</width> </item>
<height>30</height> </layout>
</rect>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</widget> </widget>
</widget> </widget>
</widget> </widget>
@ -133,7 +149,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>656</width> <width>783</width>
<height>21</height> <height>21</height>
</rect> </rect>
</property> </property>
@ -162,5 +178,70 @@
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <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> </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>