diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc40fd6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./Picture.pro.user diff --git a/Picture.pro b/Picture.pro index 9e8b806..8de8f4f 100644 --- a/Picture.pro +++ b/Picture.pro @@ -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 diff --git a/Picture.pro.user b/Picture.pro.user index 259c700..f394213 100644 --- a/Picture.pro.user +++ b/Picture.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -54,7 +54,7 @@ Desktop Desktop {78915aca-1f52-4c43-bbd6-02dcf5b6f6cf} - 0 + 1 0 0 diff --git a/main.cpp b/main.cpp index 7aa843b..3947d14 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,8 @@ #include "picture.h" #include - - -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(); } diff --git a/picture.cpp b/picture.cpp index f269c82..9195f63 100644 --- a/picture.cpp +++ b/picture.cpp @@ -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(""); - } + 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;ifileList->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()<gpsData->append(GPSLatitudeRef.toString()); */ + } diff --git a/picture.h b/picture.h index ed733cf..ed14778 100644 --- a/picture.h +++ b/picture.h @@ -1,11 +1,9 @@ #ifndef PICTURE_H #define PICTURE_H - #include #include #include #include "ui_picture.h" -#include "ui_preview.h" #include #include #include @@ -14,31 +12,38 @@ #include #include #include - +#include +#include +#include +#include +#include +#include +#include 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 diff --git a/picture.ui b/picture.ui index 2d8eb55..8792506 100644 --- a/picture.ui +++ b/picture.ui @@ -6,8 +6,8 @@ 0 0 - 656 - 350 + 783 + 607 @@ -19,8 +19,8 @@ 0 0 - 471 - 301 + 651 + 411 @@ -30,101 +30,117 @@ Commands - - - - 20 - 20 - 258 - 229 - - - - - - - - - - - - Change Directory - - - - - - - Refresh Directory - - - - - - - - - - - 300 - 60 - 107 - 62 - - - - - - - Erase Metadata - - - - - - - Label - - - - - - fileList - fileList - layoutWidget - erase - pushButton + + + + + + + + + + + + Open Directory + + + + + + + Clear File List + + + + + + + + + + + + + + + + + + Label Images + + + true + + + + + + + Erase All Metadata + + + + + + + + + Label + + + + + + + + + + Erase Other Metadata + + + + + + + Set GPS Data From Above + + + + + + + Process + + + + + + Log - - - - 10 - 10 - 381 - 192 - - - - true - - - - - - 270 - 220 - 51 - 30 - - - - Clear - - + + + + + + + true + + + + + + + Clear + + + + + + @@ -133,7 +149,7 @@ 0 0 - 656 + 783 21 @@ -162,5 +178,70 @@ - + + + eraseOtherMetadata + toggled(bool) + eraseGpsData + setDisabled(bool) + + + 428 + 367 + + + 432 + 387 + + + + + eraseAllRadio + toggled(bool) + labelText + setDisabled(bool) + + + 527 + 120 + + + 457 + 332 + + + + + eraseAllRadio + toggled(bool) + eraseOtherMetadata + setDisabled(bool) + + + 583 + 120 + + + 381 + 369 + + + + + eraseAllRadio + toggled(bool) + eraseGpsData + setDisabled(bool) + + + 601 + 118 + + + 539 + 386 + + + + diff --git a/preview.ui b/preview.ui deleted file mode 100644 index 92cccb3..0000000 --- a/preview.ui +++ /dev/null @@ -1,66 +0,0 @@ - - - Dialog - - - - 0 - 0 - 432 - 334 - - - - Dialog - - - - - 1 - 1 - 120 - 16 - - - - Process this picture? - - - - - - 1 - 22 - 431 - 311 - - - - - - - - - - No (n) - - - - - - - Yes (y) - - - - - - buttonBox - image - buttonBox - noButton - yesButton - - - -