commit a535756c9e3768b1621587d5dcee7945e88e6235
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Mon Jun 4 23:36:27 2012 +0200

    gestion complete du drag & drop et reprise de la numerotation pour ajouter des images

diff --git a/original.cpp b/original.cpp
index 97d9303..abd5efb 100644
--- a/original.cpp
+++ b/original.cpp
@@ -54,6 +54,8 @@ original::original(QWidget *parent) :
 
     ui->stackedWidget->setCurrentWidget(ui->page);
 
+    m_currentProjectPictureNumber = 0;
+
     m_baseDir = QDir(QDir::homePath() + "/RyXeo-WebPhotoAlbum");
     m_baseDir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
     QFileInfoList list = m_baseDir  .entryInfoList();
@@ -82,9 +84,9 @@ original::original(QWidget *parent) :
     actions << a_nouveau << a_renommer << a_supprimer;
     m_menu->addActions(actions);
 
-    //============== le menu contextuel du treewidget (gauche)
-ui->lwPictures->setDragEnabled(true);
-ui->lwPictures->setDropIndicatorShown(true);
+    //============== Accepte le drag & drop
+    ui->lwPictures->setDragEnabled(true);
+    ui->lwPictures->setDropIndicatorShown(true);
 }
 
 original::~original()
@@ -224,6 +226,7 @@ void original::on_btnExport_clicked()
 
 void original::on_action_Nouvel_album_triggered()
 {
+    m_currentProjectPictureNumber = 0;
     bool ok;
     QString text = QInputDialog::getText(this, trUtf8("Nom du nouvel album à créer"),
                                          trUtf8("Nom du nouvel album à créer"), QLineEdit::Normal,
@@ -231,13 +234,25 @@ void original::on_action_Nouvel_album_triggered()
     //Si ce nom n'existe pas déjà ...
     QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
     i->setText(0, text);
-    QDir d(m_baseDir.absolutePath() + "/" + text);
-    d.mkpath(d.absolutePath());
+    m_currentProjectDir = m_baseDir.absolutePath() + "/" + text;
+
+    //Creation de la destination
+    QDir rep;
+    rep.mkpath(m_currentProjectDir);
+    rep.mkpath(m_currentProjectDir + "/hq");
+    rep.mkpath(m_currentProjectDir + "/lq");
+    rep.mkpath(m_currentProjectDir + "/mq");
+    rep.mkpath(m_currentProjectDir + "/thumbs");
+    rep.mkpath(m_currentProjectDir + "/zip");
+    rep.mkpath(m_currentProjectDir + "/comments");
+
 }
 
 void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
 {
     ui->lwPictures->clear();
+    m_currentProjectDir = item->data(1,0).toString();
+
     QDir dir(item->data(1,0).toString()+"/thumbs/");
     dir.setFilter(QDir::Files);
     dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
@@ -249,7 +264,10 @@ void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
         newitem->setIcon(icone); // ajout de la petite icone sur l'item
         newitem->setText(list.at(i).fileName());
         ui->lwPictures->insertItem(i,newitem);
+        m_currentProjectPictureNumber = i;
     }
+    m_currentProjectPictureNumber++;
+    qDebug() << "On continue la numerotation a " << m_currentProjectPictureNumber;
 }
 
 void original::on_commandLinkButton_clicked()
@@ -344,19 +362,131 @@ void original::dropEvent(QDropEvent *event)
         for(int i = 0; i < event->mimeData()->urls().count(); i++) {
             //recopier l'image dans le projet
             qDebug() << "Windows d&drop : " << event->mimeData()->urls().at(i).toString();
-/*
+
             //Attention sous windows le drag & drop est un file:/// sous linux file:// et osx ?
 #ifdef Q_OS_WIN32
             addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file:///"));
 #endif
 #ifdef Q_OS_LINUX
-            QString f(event->mimeData()->urls().at(i).toString().remove("file://"));
-            qDebug() << "On importe par d&d le fichier " << f;
-            addPictureToProject(f);
+            addPictureToProject(event->mimeData()->urls().at(i).toString().remove("file://"));
 #endif
-*/
             qDebug() << "Accepte le drop d'une image";
             event->acceptProposedAction();
         }
     }
 }
+
+void original::addPictureToProject(QString fic)
+{
+    ui->statusBar->clearMessage();
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1").arg(fic),3000);
+    qApp->processEvents();
+
+    qDebug() << "Processing : " << fic;
+    QPixmap pixmap(fic);
+    pixmap.save(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
+    qDebug() << "Save to : " << QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber);
+
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq]").arg(fic),3000);
+    QPixmap pixmapThumbs(pixmap.scaled(QSize(120,120), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+    pixmapThumbs.save(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
+
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq]").arg(fic),3000);
+    QPixmap pixmapMQ(pixmap.scaled(QSize(800,600), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+    pixmapMQ.save(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
+
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq]").arg(fic),3000);
+    QPixmap pixmapLQ(pixmap.scaled(QSize(640,480), Qt::KeepAspectRatio, Qt::SmoothTransformation));
+    pixmapLQ.save(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
+
+
+    QFile file(QString("%1/comments/%2.txt").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber));
+    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
+        return;
+
+    QTextStream out(&file);
+    out << "<span>Photo " + QString::number(m_currentProjectPictureNumber) + "</span>\n";
+    file.close();
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta]").arg(fic),3000);
+
+    //================== on copie les metadata
+    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fic.toStdString());
+    Exiv2::Image::AutoPtr imageLQ = Exiv2::ImageFactory::open(QString("%1/lq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
+    Exiv2::Image::AutoPtr imageMQ = Exiv2::ImageFactory::open(QString("%1/mq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
+    Exiv2::Image::AutoPtr imageHQ = Exiv2::ImageFactory::open(QString("%1/hq/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
+    Exiv2::Image::AutoPtr imageThumb = Exiv2::ImageFactory::open(QString("%1/thumbs/img-%2.jpg").arg(m_currentProjectDir).arg(m_currentProjectPictureNumber).toStdString());
+    if (image.get() != 0)
+    {
+        image->readMetadata();
+        Exiv2::ExifData &exifData = image->exifData();
+        if (!exifData.empty())
+        {
+            bool setArtist = false;
+            bool setCopyright = false;
+            bool setSoftware = false;
+            Exiv2::ExifData::const_iterator end = exifData.end();
+            qDebug() << "============================ DEBUT ===============================";
+            for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
+            {
+                qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
+                if (i->key() == "Exif.Image.Artist") {
+                    exifData["Exif.Image.Artist"]    = "Eric S.";
+                    setArtist = true;
+                }
+                if (i->key() == "Exif.Image.Copyright") {
+                    exifData["Exif.Image.Copyright"]    = "Eric S.";
+                    setCopyright = true;
+                }
+                if (i->key() == "Exif.Image.Software") {
+                    exifData["Exif.Image.Software"]  = "RyXeo WebPhotoAlbum - http://www.ryxeo.com/";
+                    setSoftware = true;
+                }
+            }
+            //Si on n'a pas les meta il faut les ajouter
+
+            //Mise à jour de l'auteur
+            if(!setArtist) {
+                Exiv2::ExifKey k("Exif.Image.Artist");
+                Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString);
+                v->read("Eric S.");
+                exifData.add(k,v.get());
+            }
+
+            if(!setCopyright) {
+                Exiv2::ExifKey k2("Exif.Image.Copyright");
+                Exiv2::Value::AutoPtr v2 = Exiv2::Value::create(Exiv2::asciiString);
+                v2->read("Eric S.");
+                exifData.add(k2,v2.get());
+            }
+
+            if(!setSoftware) {
+                Exiv2::ExifKey k3("Exif.Image.Software");
+                Exiv2::Value::AutoPtr v3 = Exiv2::Value::create(Exiv2::asciiString);
+                v3->read("RyXéo WebPhotoAlbum - http://www.ryxeo.com/");
+                exifData.add(k3,v3.get());
+            }
+
+            qDebug() << "============================ APRES ===============================";
+            Exiv2::ExifData::const_iterator end2 = exifData.end();
+            for (Exiv2::ExifData::const_iterator i2 = exifData.begin(); i2 != end2; ++i2)
+            {
+                qDebug() << i2->key().c_str() << " = " << i2->value().toString().c_str();
+            }
+            qDebug() << "============================ FIN ===============================";
+
+            imageLQ->setExifData(exifData);
+            imageLQ->writeMetadata();
+
+            imageMQ->setExifData(exifData);
+            imageMQ->writeMetadata();
+
+            imageHQ->setExifData(exifData);
+            imageHQ->writeMetadata();
+
+            imageThumb->setExifData(exifData);
+            imageThumb->writeMetadata();
+        }
+    }
+    m_currentProjectPictureNumber++;
+    ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(fic),3000);
+}
diff --git a/original.h b/original.h
index 6c453e2..4cd86ad 100644
--- a/original.h
+++ b/original.h
@@ -59,11 +59,14 @@ private slots:
     //Gestion du drop d'image venant de l'extérieur
     void dragEnterEvent(QDragEnterEvent *event);
     void dropEvent(QDropEvent *event);
+    void addPictureToProject(QString fic);
 
 private:
     Ui::original *ui;
     QDir m_baseDir;
     QMenu *m_menu;
+    QString m_currentProjectDir;
+    int m_currentProjectPictureNumber;
 };
 
 #endif // ORIGINAL_H
