Changed two buttons to two radiobuttons of "Label Images" and "Erase All Metadata"

This commit is contained in:
Austen Adler 2014-06-23 23:51:36 -04:00
parent 88ab8a2500
commit b346ed838b
5 changed files with 91 additions and 67 deletions

2
.gitignore vendored
View File

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

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-22T20:11:46. --> <!-- Written by QtCreator 3.0.1, 2014-06-23T22:55:24. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -20,12 +20,7 @@ void Picture::dragEnterEvent(QDragEnterEvent *event){
void Picture::dropEvent(QDropEvent *event){ void Picture::dropEvent(QDropEvent *event){
foreach (const QUrl &url, event->mimeData()->urls()) { foreach (const QUrl &url, event->mimeData()->urls()) {
const QString &fileName = url.toLocalFile(); const QString &fileName = url.toLocalFile();
//if(fileName.contains(QRegExp("\.(?i)(jpe?g|png|gif)$"))){
ui->fileList->addItem(fileName); ui->fileList->addItem(fileName);
//}else{
// qDebug()<<fileName;
//}
//qDebug() << "Dropped file:" << fileName;
} }
} }
void Picture::changeDirectory(){ void Picture::changeDirectory(){
@ -44,7 +39,8 @@ void Picture::fillList() {
foreach(const QString &str,directory.entryList()){ foreach(const QString &str,directory.entryList()){
QImageReader reader(directory.absolutePath()+"/"+str); QImageReader reader(directory.absolutePath()+"/"+str);
if(!reader.format().isEmpty()){ if(!reader.format().isEmpty()){
ui->fileList->addItem(str); QString itemString=directory.path()+"/"+str;
ui->fileList->addItem(itemString);
} }
} }
if(ui->fileList->count()==0){ if(ui->fileList->count()==0){
@ -54,40 +50,6 @@ void Picture::fillList() {
void Picture::on_cd_clicked(){ void Picture::on_cd_clicked(){
changeDirectory(); changeDirectory();
} }
void Picture::on_erase_clicked(){
bool ignored=false;
QStringList myStringList;
for (int i = 0; i < ui->fileList->count(); ++i)
myStringList.append(ui->fileList->item(i)->text());
qDebug() << myStringList;
//foreach(const QString &str,directory.entryList()){
foreach(const QString &str,myStringList){
QImageReader reader(str);
if(!reader.format().isEmpty()){
QString fullPath=str;
try{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert (image.get() != 0);
image->readMetadata();
image->clearMetadata();
image->writeMetadata();
}catch(Exiv2::AnyError& e){
QMessageBox msgBox;
msgBox.setInformativeText("The program could not process the file: "+fullPath);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret=msgBox.exec();
}
}else{
if(!ignored){
ignored=true;
ui->log->append("Ignored Files:");
}
ui->log->append(str);
}
}
ui->log->append("Done erasing metadata");
}
void Picture::on_refresh_clicked(){ void Picture::on_refresh_clicked(){
//fillList(); //fillList();
ui->fileList->clear(); ui->fileList->clear();
@ -97,11 +59,6 @@ void Picture::on_clearLog_clicked(){
ui->log->setText(""); ui->log->setText("");
ui->tabField->setCurrentIndex(0); 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_processButton_pressed(){ void Picture::on_processButton_pressed(){
ui->log->append("Processing images..."); ui->log->append("Processing images...");
ui->tabField->setCurrentIndex(1); ui->tabField->setCurrentIndex(1);
@ -113,21 +70,28 @@ void Picture::on_processButton_clicked(){
for (int i=0;i<ui->fileList->count();++i){ for (int i=0;i<ui->fileList->count();++i){
myStringList.append(ui->fileList->item(i)->text()); myStringList.append(ui->fileList->item(i)->text());
} }
qDebug()<<myStringList;
foreach(const QString &str,myStringList){ foreach(const QString &str,myStringList){
QImageReader reader(str); QImageReader reader(str);
if(!reader.format().isEmpty()){ if(!reader.format().isEmpty()){
QString fullPath=str; QString fullPath=str;
try{ try{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString()); if(ui->labelImagesRadio->isChecked()){
assert (image.get() != 0); Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
image->readMetadata(); assert (image.get() != 0);
if(ui->eraseOtherMetadata->isChecked()){ 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();
}else{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString());
assert (image.get() != 0);
image->readMetadata();
image->clearMetadata(); image->clearMetadata();
image->writeMetadata();
} }
Exiv2::ExifData &exifData=image->exifData();
exifData["Exif.Photo.UserComment"] = "charset=Ascii "+ui->labelText->text().toStdString();
image->writeMetadata();
}catch(Exiv2::AnyError& e){ }catch(Exiv2::AnyError& e){
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setInformativeText("The program could not process the file: "+fullPath); msgBox.setInformativeText("The program could not process the file: "+fullPath);

View File

@ -33,10 +33,8 @@ class Picture : public QMainWindow {
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 on_processButton_clicked();
void on_processButton_pressed(); void on_processButton_pressed();
private: private:

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>463</height> <height>607</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -58,13 +58,6 @@
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="erase">
<property name="text">
<string>Erase All Metadata</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
@ -78,6 +71,27 @@
</property> </property>
</spacer> </spacer>
</item> </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> <item>
<widget class="QLabel" name="labelLabel"> <widget class="QLabel" name="labelLabel">
<property name="text"> <property name="text">
@ -145,7 +159,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>
@ -191,5 +205,53 @@
</hint> </hint>
</hints> </hints>
</connection> </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> </connections>
</ui> </ui>