commit cf314c59627e7a9a072a874cfee000927a010b89
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Sat Jun 9 18:51:16 2012 +0200

    upload des fichiers ZIP + extraction cote serveur

diff --git a/original.cpp b/original.cpp
index c771d9a..fe7b5cb 100644
--- a/original.cpp
+++ b/original.cpp
@@ -61,7 +61,7 @@ original::original(QWidget *parent) :
 
     m_baseDir = QDir(QDir::homePath() + "/RyXeo-Applications/WebPhotoAlbum");
     m_baseDir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
-    QFileInfoList list = m_baseDir  .entryInfoList();
+    QFileInfoList list = m_baseDir.entryInfoList();
     for(int i = 0; i < list.count(); i++) {
         QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
         item->setText(0, list.at(i).fileName());
@@ -409,6 +409,19 @@ void original::refreshPictureList()
 void original::on_btnUpload_clicked()
 {
     qDebug() << "on_btnUpload_clicked : " << ui->treeWidget->currentItem()->data(1,0).toString();
+
+    makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/hq",
+            m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/hq.zip");
+
+    makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/mq",
+            m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/mq.zip");
+
+    makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/lq",
+            m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/lq.zip");
+
+    makeZip(m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/thumbs",
+            m_baseDir.absolutePath() + "/" + ui->treeWidget->currentItem()->text(0) + "/zip/thumbs.zip");
+
     m_tools->clear();
 
     m_tools->ftpConnect(ui->leFTPServeur->text(),
@@ -448,3 +461,41 @@ void original::updateProgressData(int total, int current)
     ui->pbFTPProgress->setMaximum(total);
     ui->pbFTPProgress->setValue(current);
 }
+
+void original::makeZip(QString repSource, QString destFileName)
+{
+    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+    ui->statusBar->showMessage(QString::fromUtf8("Création du fichier ZIP %1 en cours").arg(destFileName), 5000);
+    qApp->processEvents();
+    qDebug() << "original::makeZip " << repSource << " :: " << destFileName;
+    //Creation d'une archive ZIP dans tous les cas
+    QuaZip zipDestination(destFileName);
+    if(zipDestination.open(QuaZip::mdCreate)) {
+        //On sauvegarde tout dans ce fichier
+        QuaZipFile fichierDehors(&zipDestination);
+
+        //Les droits par defaut en 644 pour les fichiers contenus dans le .zip
+        QuaZipNewInfo newInfo("");
+        int permission644 = 33188;
+        newInfo.externalAttr = (permission644 << 16L);
+
+        QDir dir(repSource);
+        dir.setFilter(QDir::Files);
+        QFileInfoList fileList = dir.entryInfoList();
+        qDebug() << "avant " << fileList.count();
+        for(int i = 0; i < fileList.count(); i++) {
+            QString fileName = fileList.at(i).fileName();
+            QFile fic(fileList.at(i).absoluteFilePath());
+            qDebug() << "On ajoute le fichier " << fileName;
+            newInfo.name = fileName;
+            if(fic.open(QIODevice::ReadOnly) && fichierDehors.open(QIODevice::WriteOnly,newInfo)) {
+                fichierDehors.write(fic.read(fic.size()));
+                fichierDehors.close();
+                fic.close();
+                qDebug() << " ajout ok";
+            }
+        }
+        zipDestination.close();
+    }
+    QApplication::restoreOverrideCursor();
+}
diff --git a/original.h b/original.h
index faa633d..6cd60ee 100644
--- a/original.h
+++ b/original.h
@@ -40,6 +40,9 @@
 #include "tools.h"
 #include "assistant.h"
 #include "newalbumdialog.h"
+#include "quazip.h"
+#include "quazipfile.h"
+
 
 namespace Ui {
 class original;
@@ -71,6 +74,7 @@ private slots:
     void on_action_Assistant_d_installation_triggered();
     void updateProgressFichier(int total, int current);
     void updateProgressData(int total, int current);
+    void makeZip(QString repSource, QString destFileName);
 
 private:
     Ui::original *ui;
diff --git a/original.ui b/original.ui
index fa6d707..734d7e4 100644
--- a/original.ui
+++ b/original.ui
@@ -74,7 +74,7 @@
       </widget>
       <widget class="QTabWidget" name="tabWidget">
        <property name="currentIndex">
-        <number>0</number>
+        <number>2</number>
        </property>
        <widget class="QWidget" name="tabProprietes">
         <attribute name="title">
@@ -304,6 +304,15 @@
            </property>
           </widget>
          </item>
+         <item row="7" column="0" colspan="2">
+          <widget class="QWebView" name="webView">
+           <property name="url">
+            <url>
+             <string>about:blank</string>
+            </url>
+           </property>
+          </widget>
+         </item>
         </layout>
        </widget>
       </widget>
@@ -374,6 +383,13 @@
   </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+  <customwidget>
+   <class>QWebView</class>
+   <extends>QWidget</extends>
+   <header>QtWebKit/QWebView</header>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>treeWidget</tabstop>
  </tabstops>
diff --git a/ryxeo-webphotoalbum.pro b/ryxeo-webphotoalbum.pro
index d899b9b..5949b47 100644
--- a/ryxeo-webphotoalbum.pro
+++ b/ryxeo-webphotoalbum.pro
@@ -4,7 +4,7 @@
 #
 #-------------------------------------------------
 
-QT       += core gui network
+QT       += core gui network webkit
 
 TARGET = ryxeo-webphotoalbum
 TEMPLATE = app
@@ -33,3 +33,6 @@ win32 {
 }
 
 RESOURCES += resources.qrc
+
+# la lib quazip: les fichiers sont des archives zip
+include(lib/quazip/quazip/quazip.pri)
diff --git a/tools.cpp b/tools.cpp
index 1e2bc5c..4422ccb 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -32,6 +32,9 @@ tools::tools(QDir basedir, QObject *parent) :
     QObject(parent)
 {
     m_baseDir = basedir;
+
+    m_web = new QWebView();
+    connect(m_web,SIGNAL(loadFinished(bool)),this,SLOT(unzipFinished(bool)));
 }
 
 void tools::ftpConnect(QString serveur, QString login, QString passwd)
@@ -94,7 +97,7 @@ void tools::ftpCommandFinished(int commandId, bool error)
         m_ftp->cd("/");
         m_ftp->list("/");
         m_ftp->clearPendingCommands();
-        AbulEduSleeperThread::msleep(2000);
+        AbulEduSleeperThread::msleep(800);
     }
     qDebug() << "======================= END FTP INFO ======================= ";
 
@@ -154,6 +157,13 @@ void tools::ftpNextCommand()
 {
     if(!m_ftpCommands.isEmpty()) {
         QStringList cmd(m_ftpCommands.takeFirst().split(";"));
+        //Commande speciale pour extraire un fichier ZIP sur le serveur
+        //exemple: http://webopenphoto.free.fr/sagc/extract.php?src=galleries/Cala-Montjoi-2012_Christophe/zip/mq.zip
+        if(cmd.at(0) == "unzip") {
+            QUrl u("http://webopenphoto.free.fr/sagc/extract.php?src=" + cmd.at(1));
+            m_web->load(u);
+            qDebug() << "Ouverture de " << u;
+        }
         if(cmd.at(0) == "mkdir") {
             m_ftp->mkdir(cmd.at(1));
         }
@@ -172,6 +182,17 @@ void tools::ftpNextCommand()
     }
 }
 
+void tools::unzipFinished(bool status)
+{
+    ftpNextCommand();
+}
+
+void tools::ftpUnzip(QString zipUrl)
+{
+    qDebug() << "tools::ftpUnzip " << zipUrl;
+    m_ftpCommands << "unzip;" + zipUrl;
+}
+
 void tools::ftpMkdir(QString rep)
 {
     //Avant de faire un mkdir il faut verifier si le repertoire n'existe pas deja
@@ -192,11 +213,17 @@ void tools::parcoursRecursif(QString rep, QString repertoireServeur)
     dir.setFilter(QDir::Hidden | QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
     QFileInfoList list = dir.entryInfoList();
     for(int i = 0; i < list.count(); i++) {
-        qDebug() << "Ajout de " << list.at(i).absoluteFilePath() << " rep serveur : " << repertoireServeur;
+        qDebug() << " Ajout de " << list.at(i).absoluteFilePath() << " rep serveur : " << repertoireServeur;
         m_fileListToUpload.insert(list.at(i).absoluteFilePath(), repertoireServeur);
         m_fileListToUploadIndex << list.at(i).absoluteFilePath();
+
         if(list.at(i).isDir()) {
-            parcoursRecursif(list.at(i).absoluteFilePath(), list.at(i).absoluteFilePath().remove(m_baseDir.absolutePath()).remove("/www"));
+            if(list.at(i).fileName() == "hq" || list.at(i).fileName() == "mq" || list.at(i).fileName() == "lq" || list.at(i).fileName() == "thumbs") {
+                qDebug() << " On ne parcours pas " << list.at(i).absoluteFilePath();
+            }
+            else {
+                parcoursRecursif(list.at(i).absoluteFilePath(), list.at(i).absoluteFilePath().remove(m_baseDir.absolutePath()).remove("/www"));
+            }
         }
     }
 }
@@ -219,6 +246,9 @@ void tools::uploadRecursifGallery(QString destDirBase)
         else {
             QString ladest = m_destDirBase + "/galleries/" + m_fileListToUpload.value(fi.absoluteFilePath()) + "/" + fi.fileName();
             ftpPut(fi.absoluteFilePath(),ladest);
+            if(fi.absoluteFilePath().endsWith(".zip")) {
+                ftpUnzip("galleries/" + m_fileListToUpload.value(fi.absoluteFilePath()) + "/" + fi.fileName());
+            }
         }
     }
 }
diff --git a/tools.h b/tools.h
index 69457d1..2a0025e 100644
--- a/tools.h
+++ b/tools.h
@@ -32,6 +32,7 @@
 #include <QApplication>
 #include <QDir>
 #include <QThread>
+#include <QWebView>
 
 class tools : public QObject
 {
@@ -59,7 +60,9 @@ public slots:
     int nbResteUpload();
     void ftpMkdir(QString rep);
     void ftpPut(QString source, QString ladest);
+    void ftpUnzip(QString zipUrl);
     void ftpNextCommand();
+    void unzipFinished(bool status);
 
 private:
     QFtp *m_ftp;
@@ -72,6 +75,7 @@ private:
     int m_currentProjectPictureNumber;
     int m_currentFTPFileUpload;
     QStringList m_ftpCommands;
+    QWebView *m_web;
 };
 
 #endif // TOOLS_H
diff --git a/www/extract.php b/www/extract.php
index 304acd4..fbc69dc 100644
--- a/www/extract.php
+++ b/www/extract.php
@@ -3,15 +3,21 @@
   //GNU/GPL
 print "<pre>";
 require_once("zip/pclzip.lib.php");
-if($_GET['src'] != "" && $_GET['dst'] != "") {
+if($_GET['src'] != "") {
   $base = getcwd() . "/";
   print "on est ici : " . getcwd() . "\n";
-  print "on essaye de decompresser " . $_GET['src'] . " vers " . $_GET['dst'] . "\n";
+  print "on essaye de decompresser " . $base . $_GET['src'];
   if(file_exists($base . $_GET['src'])) {
     $archive = new PclZip($base . $_GET['src']);
+    //src=galleries/Cala-Montjoi-2012_Christophe/zip/mq.zip
+    //et nous on extrait dans galleries/Cala-Montjoi-2012_Christophe/mq
+    $dstRep = basename($_GET['src'],".zip");
+    $dst = dirname(dirname($base . $_GET['src'])) . "/" . $dstRep;
+    print " vers $dst\n";
+
     //Extrait dans le repertoire courant.
-    if(is_dir($base . $_GET['dst'])) {
-      chdir($base . $_GET['dst']);
+    if(is_dir($dst)) {
+      chdir($dst);
       $list = $archive->extract();
       if($list  == 0) {
 	die("Error : ".$archive->errorInfo(true));
