commit d4a9c7c88ffd955bc17cd832923ffd55737b10b5
Author: Eric Seigne <eric.seigne@ryxeo.com>
Date:   Sat Jun 9 15:19:54 2012 +0200

    creation d'un widget personnalise + upload gallerie ok

diff --git a/assistant.cpp b/assistant.cpp
index 5033742..56b5d47 100644
--- a/assistant.cpp
+++ b/assistant.cpp
@@ -1,5 +1,5 @@
 /**
-  * Classe 
+  * Classe
   * @see https://redmine.ryxeo.com/projects/
   * @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
   * @see The GNU Public License (GNU/GPL) v3
@@ -41,15 +41,15 @@ void Assistant::on_btnUploadPHP_clicked()
 {
     qDebug() << "Assistant::on_btnUploadPHP_clicked";
 
-    m_ftp = m_tools->ftpConnect(ui->leFTPServeur->text(),
-                                ui->leFTPLogin->text(),
-                                ui->leFTPPass->text());
+    m_tools->ftpConnect(ui->leFTPServeur->text(),
+                        ui->leFTPLogin->text(),
+                        ui->leFTPPass->text());
 
-    m_ftp->mkdir(ui->leFTPDirectory->text());
-    m_ftp->mkdir(ui->leFTPDirectory->text() + "/galleries");
+    m_tools->ftpMkdir(ui->leFTPDirectory->text());
+    m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries");
 
     //On uploade le code php
-    m_ftp->cd(ui->leFTPDirectory->text());
+    //m_ftp->cd(ui->leFTPDirectory->text());
     QDir dir("www");
     m_tools->clear();
     m_tools->parcoursRecursif(dir.absolutePath(),"");
diff --git a/assistant.h b/assistant.h
index e6403bb..f7b1927 100644
--- a/assistant.h
+++ b/assistant.h
@@ -50,7 +50,6 @@ private slots:
 private:
     Ui::Assistant *ui;
     tools *m_tools;
-    QFtp  *m_ftp;
     QString m_currentProjectDir;
     QString m_typeUploadRecursif;
     QStringList m_fileListToUploadIndex;
diff --git a/newalbumdialog.cpp b/newalbumdialog.cpp
new file mode 100644
index 0000000..6b1a4a3
--- /dev/null
+++ b/newalbumdialog.cpp
@@ -0,0 +1,51 @@
+/**
+  * Classe 
+  * @see https://redmine.ryxeo.com/projects/
+  * @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
+  * @see The GNU Public License (GNU/GPL) v3
+  *
+  *
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License as published by
+  * the Free Software Foundation; either version 3 of the License, or
+  * (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+  * for more details.
+  *
+  * You should have received a copy of the GNU General Public License along
+  * with this program. If not, see <http://www.gnu.org/licenses/>.
+  */
+
+
+#include "newalbumdialog.h"
+#include "ui_newalbumdialog.h"
+
+NewAlbumDialog::NewAlbumDialog(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::NewAlbumDialog)
+{
+    ui->setupUi(this);
+    QRegExp expressionReguliere("[a-zA-Z0-9_-]*");
+    ui->leNom->setValidator(new QRegExpValidator(expressionReguliere, this));
+}
+
+NewAlbumDialog::~NewAlbumDialog()
+{
+    delete ui;
+}
+
+QString NewAlbumDialog::getValue(QWidget *parent)
+{
+    NewAlbumDialog dialog(parent);
+    int ret = dialog.exec();
+    return dialog.textValue();
+}
+
+QString NewAlbumDialog::textValue()
+{
+    return ui->leNom->text();
+}
diff --git a/newalbumdialog.h b/newalbumdialog.h
new file mode 100644
index 0000000..0bc339d
--- /dev/null
+++ b/newalbumdialog.h
@@ -0,0 +1,49 @@
+/**
+  * Classe 
+  * @see https://redmine.ryxeo.com/projects/
+  * @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
+  * @see The GNU Public License (GNU/GPL) v3
+  *
+  *
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License as published by
+  * the Free Software Foundation; either version 3 of the License, or
+  * (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful, but
+  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+  * for more details.
+  *
+  * You should have received a copy of the GNU General Public License along
+  * with this program. If not, see <http://www.gnu.org/licenses/>.
+  */
+
+
+#ifndef NEWALBUMDIALOG_H
+#define NEWALBUMDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class NewAlbumDialog;
+}
+
+class NewAlbumDialog : public QDialog
+{
+    Q_OBJECT
+    
+public:
+    explicit NewAlbumDialog(QWidget *parent = 0);
+    ~NewAlbumDialog();
+    static QString getValue(QWidget *parent);
+    QString textValue();
+    
+private slots:
+
+private:
+    Ui::NewAlbumDialog *ui;
+};
+
+#endif // NEWALBUMDIALOG_H
diff --git a/newalbumdialog.ui b/newalbumdialog.ui
new file mode 100644
index 0000000..279bb1b
--- /dev/null
+++ b/newalbumdialog.ui
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NewAlbumDialog</class>
+ <widget class="QDialog" name="NewAlbumDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>83</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="lblNom">
+     <property name="text">
+      <string>Nom de l'album</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QLineEdit" name="leNom">
+     <property name="maxLength">
+      <number>50</number>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>NewAlbumDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>NewAlbumDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/original.cpp b/original.cpp
index f137568..a166770 100644
--- a/original.cpp
+++ b/original.cpp
@@ -67,6 +67,8 @@ original::original(QWidget *parent) :
         item->setText(0, list.at(i).fileName());
         item->setData(1,0,list.at(i).absoluteFilePath());
     }
+
+    ui->dateEdit->setDate(QDate::currentDate());
     m_tools = new tools(m_baseDir, this);
 
     //============== l'étiquette invitant a déposer des images
@@ -110,9 +112,7 @@ 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,
-                                         QDir::home().dirName(), &ok);
+    QString text = NewAlbumDialog::getValue(this);
     //Si ce nom n'existe pas déjà ...
     QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
     i->setText(0, text);
@@ -166,8 +166,10 @@ void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
                 ui->leAuthor->setText(tab.at(1));
             if(tab.at(0) == "description")
                 ui->leDesc->setText(tab.at(1));
-            if(tab.at(0) == "date")
-                ui->dateEdit->setDate(QDate::fromString(tab.at(1)));
+            if(tab.at(0) == "date") {
+                qDebug() << "**************** DATE : " << tab.at(1).trimmed();
+                ui->dateEdit->setDate(QDate::fromString(tab.at(1).trimmed(),"dd.MM.yyyy"));
+            }
             if(tab.at(0) == "restricted_user")
                 ui->leLogin->setText(tab.at(1));
             if(tab.at(0) == "restricted_password")
@@ -176,7 +178,7 @@ void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
         }
 
     }
-m_currentProjectPictureNumber++;
+    m_currentProjectPictureNumber++;
     refreshPictureList();
     qDebug() << "On continue la numerotation a " << m_currentProjectPictureNumber;
     qDebug() << "Espace de stockage du projet " << m_currentProjectDir;
@@ -188,7 +190,7 @@ void original::on_btnSave_clicked()
     data.append(QString("name|%1\n").arg(ui->leTitre->text().trimmed()));
     data.append(QString("author|%1\n").arg(ui->leAuthor->text().trimmed()));
     data.append(QString("description|%1\n").arg(ui->leDesc->text().trimmed()));
-    data.append(QString("date|%1\n").arg(ui->dateEdit->text().trimmed()));
+    data.append(QString("date|%1\n").arg(ui->dateEdit->date().toString("dd.MM.yyyy")));
     if(ui->leLogin->text().trimmed() != "") {
         data.append(QString("restricted_user|%1\n").arg(ui->leLogin->text().trimmed()));
         data.append(QString("restricted_password|%1\n").arg(ui->lePasswd->text().trimmed()));
@@ -298,10 +300,10 @@ void original::addPictureToProject(QString fic)
                 bool setCopyright = false;
                 bool setSoftware = false;
                 Exiv2::ExifData::const_iterator end = exifData.end();
-//                qDebug() << "============================ DEBUT ===============================";
+                //                qDebug() << "============================ DEBUT ===============================";
                 for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
                 {
-//                    qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
+                    //                    qDebug() << i->key().c_str() << " = " << i->value().toString().c_str();
                     if (i->key() == "Exif.Image.Artist") {
                         exifData["Exif.Image.Artist"]    = "Eric S.";
                         setArtist = true;
@@ -339,13 +341,13 @@ void original::addPictureToProject(QString fic)
                     exifData.add(k3,v3.get());
                 }
 
-//                qDebug() << "============================ APRES ===============================";
+                //                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 ===============================";
+                //                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();
@@ -365,7 +367,7 @@ void original::addPictureToProject(QString fic)
         qDebug() << "Erreur EXIV2";
     }
     ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(fic),3000);
-m_currentProjectPictureNumber++;
+    m_currentProjectPictureNumber++;
     refreshPictureList();
 }
 
@@ -401,24 +403,32 @@ void original::refreshPictureList()
     else {
         m_labelDeposez->hide();
     }
+    m_currentProjectPictureNumber = currentProjectPictureNumber+1;
 }
 
 void original::on_btnUpload_clicked()
 {
-    m_ftp = m_tools->ftpConnect(ui->leFTPServeur->text(),
-                                ui->leFTPLogin->text(),
-                                ui->leFTPPass->text());
     qDebug() << "on_btnUpload_clicked : " << ui->treeWidget->currentItem()->data(1,0).toString();
-    QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString());
-    QDir dir(fi.absoluteFilePath());
     m_tools->clear();
-    m_tools->parcoursRecursif(dir.absolutePath(),ui->treeWidget->currentItem()->text(0));
-//    qDebug() << m_fileListToUpload;
 
-    QString ladest = ui->leFTPDirectory->text() + "/galleries/" + ui->treeWidget->currentItem()->text(0);
-    qDebug() << "mkdir : " << ladest;
-    m_ftp->mkdir(ladest);
-//    uploadRecursifGallery();
+    m_tools->ftpConnect(ui->leFTPServeur->text(),
+                        ui->leFTPLogin->text(),
+                        ui->leFTPPass->text());
+
+    m_tools->ftpMkdir(ui->leFTPDirectory->text());
+    m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries");
+    m_tools->ftpMkdir(ui->leFTPDirectory->text() + "/galleries/" + ui->treeWidget->currentItem()->text(0));
+
+    //On uploade la gallerie
+    //m_ftp->cd(ui->leFTPDirectory->text());
+
+    QFileInfo fi(ui->treeWidget->currentItem()->data(1,0).toString());
+    QDir dir(fi.absoluteFilePath());
+    m_tools->parcoursRecursif(dir.absolutePath(),"");
+    //qDebug() << m_fileListToUpload;
+    m_tools->uploadRecursifGallery(ui->leFTPDirectory->text());
+    connect(m_tools, SIGNAL(signalUpload(int,int)), this, SLOT(updateProgressFichier(int,int)));
+    connect(m_tools, SIGNAL(signalUploadData(int,int)), this, SLOT(updateProgressData(int,int)));
 }
 
 void original::on_action_Assistant_d_installation_triggered()
@@ -426,3 +436,15 @@ void original::on_action_Assistant_d_installation_triggered()
     Assistant *a = new Assistant(this);
     a->show();
 }
+
+void original::updateProgressFichier(int total, int current)
+{
+    ui->pbFTPFichier->setMaximum(total);
+    ui->pbFTPFichier->setValue(current);
+}
+
+void original::updateProgressData(int total, int current)
+{
+    ui->pbFTPProgress->setMaximum(total);
+    ui->pbFTPProgress->setValue(current);
+}
diff --git a/original.h b/original.h
index 29bd244..faa633d 100644
--- a/original.h
+++ b/original.h
@@ -39,6 +39,7 @@
 #include <QMessageBox>
 #include "tools.h"
 #include "assistant.h"
+#include "newalbumdialog.h"
 
 namespace Ui {
 class original;
@@ -67,8 +68,9 @@ private slots:
 //    void cancelUpload();
 //    void processItem(QTreeWidgetItem *item, int column);
     void on_btnUpload_clicked();
-
     void on_action_Assistant_d_installation_triggered();
+    void updateProgressFichier(int total, int current);
+    void updateProgressData(int total, int current);
 
 private:
     Ui::original *ui;
@@ -81,9 +83,7 @@ private:
     QMap<QString,QString> m_fileListToUpload;
     int m_currentProjectPictureNumber;
     int m_currentFTPFileUpload;
-    QFtp *m_ftp;
     tools *m_tools;
-
 };
 
 #endif // ORIGINAL_H
diff --git a/original.ui b/original.ui
index f9a1819..9d119bb 100644
--- a/original.ui
+++ b/original.ui
@@ -76,13 +76,13 @@
        <property name="currentIndex">
         <number>0</number>
        </property>
-       <widget class="QWidget" name="tab_2">
+       <widget class="QWidget" name="tabProprietes">
         <attribute name="title">
          <string>1. Propriétés</string>
         </attribute>
         <layout class="QGridLayout" name="gridLayout_4">
          <item row="0" column="0">
-          <widget class="QLabel" name="label_5">
+          <widget class="QLabel" name="lblTitre">
            <property name="text">
             <string>Titre</string>
            </property>
@@ -92,7 +92,7 @@
           <widget class="QLineEdit" name="leTitre"/>
          </item>
          <item row="1" column="0">
-          <widget class="QLabel" name="label_3">
+          <widget class="QLabel" name="lblDesc">
            <property name="text">
             <string>Description</string>
            </property>
@@ -102,7 +102,7 @@
           <widget class="QLineEdit" name="leDesc"/>
          </item>
          <item row="2" column="0">
-          <widget class="QLabel" name="label_6">
+          <widget class="QLabel" name="lblAuthor">
            <property name="text">
             <string>Auteur</string>
            </property>
@@ -112,7 +112,7 @@
           <widget class="QLineEdit" name="leAuthor"/>
          </item>
          <item row="2" column="2">
-          <widget class="QLabel" name="label">
+          <widget class="QLabel" name="lblDate">
            <property name="text">
             <string>Date</string>
            </property>
@@ -132,7 +132,7 @@
            </property>
            <layout class="QFormLayout" name="formLayout">
             <item row="1" column="0">
-             <widget class="QLabel" name="label_4">
+             <widget class="QLabel" name="lblIdentifiant">
               <property name="text">
                <string>Identifiant</string>
               </property>
@@ -142,7 +142,7 @@
              <widget class="QLineEdit" name="leLogin"/>
             </item>
             <item row="2" column="0">
-             <widget class="QLabel" name="label_2">
+             <widget class="QLabel" name="lblPasswd">
               <property name="text">
                <string>Mot de passe</string>
               </property>
@@ -152,7 +152,7 @@
              <widget class="QLineEdit" name="lePasswd"/>
             </item>
             <item row="0" column="0" colspan="2">
-             <widget class="QLabel" name="label_7">
+             <widget class="QLabel" name="lblCompletez">
               <property name="text">
                <string>Complétez les deux champs ci-dessous si vous voulez protéger l'accès (lorsqu'il sera publié sur internet) à cet album photo par un identifiant et un mot de passe.</string>
               </property>
@@ -173,7 +173,7 @@
          </item>
         </layout>
        </widget>
-       <widget class="QWidget" name="tab_3">
+       <widget class="QWidget" name="tabPhotos">
         <attribute name="title">
          <string>2. Photos</string>
         </attribute>
@@ -202,13 +202,13 @@
          </item>
         </layout>
        </widget>
-       <widget class="QWidget" name="tab">
+       <widget class="QWidget" name="tabPublier">
         <attribute name="title">
          <string>3. Publier sur internet</string>
         </attribute>
         <layout class="QGridLayout" name="gridLayout_2">
          <item row="0" column="0">
-          <widget class="QLabel" name="label_8">
+          <widget class="QLabel" name="lblLogin">
            <property name="text">
             <string>Identifiant</string>
            </property>
@@ -222,7 +222,7 @@
           </widget>
          </item>
          <item row="1" column="0">
-          <widget class="QLabel" name="label_9">
+          <widget class="QLabel" name="lblPass">
            <property name="text">
             <string>Mot de passe</string>
            </property>
@@ -239,7 +239,7 @@
           </widget>
          </item>
          <item row="2" column="0">
-          <widget class="QLabel" name="label_10">
+          <widget class="QLabel" name="lblFTP">
            <property name="text">
             <string>Serveur FTP</string>
            </property>
@@ -253,7 +253,7 @@
           </widget>
          </item>
          <item row="3" column="0">
-          <widget class="QLabel" name="label_11">
+          <widget class="QLabel" name="lblDest">
            <property name="text">
             <string>Répertoire d'installation</string>
            </property>
@@ -266,13 +266,44 @@
            </property>
           </widget>
          </item>
-         <item row="4" column="1">
+         <item row="6" column="1">
           <widget class="QPushButton" name="btnUpload">
            <property name="text">
             <string>Upload gallerie en cours</string>
            </property>
           </widget>
          </item>
+         <item row="4" column="1">
+          <widget class="QProgressBar" name="pbFTPFichier">
+           <property name="value">
+            <number>0</number>
+           </property>
+           <property name="format">
+            <string>%v / %m</string>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="1">
+          <widget class="QProgressBar" name="pbFTPProgress">
+           <property name="value">
+            <number>24</number>
+           </property>
+          </widget>
+         </item>
+         <item row="4" column="0">
+          <widget class="QLabel" name="lblFichiers">
+           <property name="text">
+            <string>Fichiers:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="0">
+          <widget class="QLabel" name="lblProgression">
+           <property name="text">
+            <string>Progression</string>
+           </property>
+          </widget>
+         </item>
         </layout>
        </widget>
       </widget>
diff --git a/ryxeo-webphotoalbum.pro b/ryxeo-webphotoalbum.pro
index 5ec512e..fe0353d 100644
--- a/ryxeo-webphotoalbum.pro
+++ b/ryxeo-webphotoalbum.pro
@@ -12,14 +12,17 @@ TEMPLATE = app
 SOURCES += main.cpp\
         original.cpp \
     assistant.cpp \
-    tools.cpp
+    tools.cpp \
+    newalbumdialog.cpp
 
 HEADERS  += original.h \
     assistant.h \
-    tools.h
+    tools.h \
+    newalbumdialog.h
 
 FORMS    += original.ui \
-    assistant.ui
+    assistant.ui \
+    newalbumdialog.ui
 
 unix:LIBS += -lexiv2
 win32:LIBS += -lexiv2
diff --git a/tools.cpp b/tools.cpp
index f96f024..07faf47 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -1,11 +1,9 @@
-/**
-  * Classe 
+/** Classe tools: regroupe ce qui est mutualisable entre assistant et appli
   * @see https://redmine.ryxeo.com/projects/
   * @author 2012 Eric Seigne <eric.seigne@ryxeo.com>
   * @see The GNU Public License (GNU/GPL) v3
   *
   *
-  *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 3 of the License, or
@@ -23,87 +21,118 @@
 
 #include "tools.h"
 
+class AbulEduSleeperThread : public QThread
+{
+public:
+    static void msleep(unsigned long msecs) {QThread::msleep(msecs);}
+};
+
+
 tools::tools(QDir basedir, QObject *parent) :
     QObject(parent)
 {
     m_baseDir = basedir;
 }
 
-QFtp *tools::ftpConnect(QString serveur, QString login, QString passwd)
+void tools::ftpConnect(QString serveur, QString login, QString passwd)
 {
+    qDebug() << "tools::ftpConnect (0)";
     m_currentFTPFileUpload = -1;
 
     m_ftp = new QFtp(this);
     connect(m_ftp, SIGNAL(commandFinished(int,bool)),
             this, SLOT(ftpCommandFinished(int,bool)));
+    connect(m_ftp, SIGNAL(done(bool)),
+            this, SLOT(ftpDone(bool)));
+    connect(m_ftp, SIGNAL(stateChanged(int)),
+            this, SLOT(ftpStateChanged(int)));
     connect(m_ftp, SIGNAL(listInfo(QUrlInfo)),
             this, SLOT(addToList(QUrlInfo)));
     connect(m_ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
             this, SLOT(updateDataTransferProgress(qint64,qint64)));
 
-    qDebug() << "aaaaaaaaaaaaaa";
     m_ftp->connectToHost(serveur, 21);
     m_ftp->setTransferMode(QFtp::Passive);
-
-    qDebug() << "bbbbbbbbbbbbb";
-
     m_ftp->login(login, passwd);
 
-    qDebug() << "Listing FTP: ";
-    //ftp->cd(url.path());
-    //On uploade l'album en cours
-    //m_ftp->put()
-
-    return m_ftp;
+    qDebug() << "tools::ftpConnect (1)";
 }
 
 void tools::ftpCommandFinished(int commandId, bool error)
 {
-//    qDebug() << "ftpCommandFinished";
-    if(error) {
-        qDebug() << "ftpCommandFinished ERROR : " << commandId << " " << m_ftp->errorString();
-
-    }
-    //setCursor(Qt::ArrowCursor);
+    //    if(error) {
+    qDebug() << "======================= BEGIN FTP INFO ======================= ";
+    qDebug() << "  Numero de commande : " << commandId;
+    //    }
 
     if (m_ftp->currentCommand() == QFtp::ConnectToHost) {
-        qDebug() << "Logged onto server error : " << error;
+        qDebug() << "  Command: Connect to host";
     }
 
     if (m_ftp->currentCommand() == QFtp::Login) {
-        qDebug() << "Login ...";
-        m_ftp->list();
+        qDebug() << "  Command: Login";
     }
 
     if (m_ftp->currentCommand() == QFtp::Put) {
-//        qDebug() << "Put ...";
+        QFile *file = static_cast<QFile*>(m_ftp->currentDevice());
+        if(file) {
+            file->deleteLater();
+        }
+        qDebug() << "  Command: Put";
     }
 
     if (m_ftp->currentCommand() == QFtp::Get) {
-        qDebug() << "Get ...";
-        if (error) {
-        } else {
-        }
-    } else if (m_ftp->currentCommand() == QFtp::List) {
-        qDebug() << "List ...";
+        qDebug() << "  Command: Get";
     }
 
-    //on passe au suivant
-    if(m_currentFTPFileUpload >= 0 && m_fileListToUploadIndex.count() > 0) {
-//        qDebug() << "Il en reste encore a envoyer ";
-        if(m_typeUploadRecursif == "PHP")
-            uploadRecursifPHP(m_destDirBase);
-        else
-            uploadRecursifGallery(m_destDirBase);
+    if (m_ftp->currentCommand() == QFtp::List) {
+        qDebug() << "  Command: List";
+    }
+    if(error) {
+        qDebug() << "  Description de l'erreur " << m_ftp->errorString().trimmed();
+        qDebug() << "  Abort command and clear pending commands !";
+        //grosse ruse pour remettre un peu a zero les erreurs de QFTP qui est quand meme
+        //bien capricieux !
+        m_ftp->cd("/");
+        m_ftp->list("/");
+        m_ftp->clearPendingCommands();
+        AbulEduSleeperThread::msleep(2000);
     }
-    else {
-        qDebug() << "Tout a ete expedie ";
+    qDebug() << "======================= END FTP INFO ======================= ";
+
+    //    if(m_currentFTPFileUpload >= 0 && m_fileListToUploadIndex.count() > 0) {
+    //        if(m_typeUploadRecursif == "PHP")
+    //            uploadRecursifPHP(m_destDirBase);
+    //        else
+    //            uploadRecursifGallery(m_destDirBase);
+    //    }
+    //    else {
+    //        qDebug() << "Tout a ete expedie ";
+    //    }
+}
+
+void tools::ftpDone(bool error)
+{
+    qDebug() << "tools::ftpDone : " << error;
+    //if(error)
+    qDebug() << "   " << m_ftp->errorString();
+
+    //on passe a la commande FTP suivante et on nettoie au passage
+    //    m_ftp->clearPendingCommands();
+    ftpNextCommand();
+}
+
+void tools::ftpStateChanged(int state)
+{
+    qDebug() << "tools::ftpStateChanged : code " << state;
+    if(state == QFtp::Closing) {
+        m_ftpCommands.clear();
     }
 }
 
 void tools::updateDataTransferProgress(qint64 readBytes, qint64 totalBytes)
 {
-//    qDebug() << "Transfert: " << readBytes << " sur " << totalBytes;
+    //    qDebug() << "Transfert: " << readBytes << " sur " << totalBytes;
     emit signalUploadData(totalBytes, readBytes);
 }
 
@@ -124,6 +153,40 @@ int tools::nbResteUpload()
     return m_fileListToUploadIndex.count();
 }
 
+void tools::ftpNextCommand()
+{
+    if(!m_ftpCommands.isEmpty()) {
+        QStringList cmd(m_ftpCommands.takeFirst().split(";"));
+        if(cmd.at(0) == "mkdir") {
+            m_ftp->mkdir(cmd.at(1));
+        }
+        if(cmd.at(0) == "put") {
+            QFile *fic = new QFile(cmd.at(1));
+            if(fic->open(QIODevice::ReadOnly)) {
+                qDebug() << "       Upload : " << cmd.at(1) << " -> " << cmd.at(2);
+                m_ftp->put(fic,cmd.at(2));
+            }
+            else {
+                //erreur
+            }
+        }
+        m_currentFTPFileUpload++;
+        emit signalUpload(nbTotalUpload(), m_currentFTPFileUpload);
+    }
+}
+
+void tools::ftpMkdir(QString rep)
+{
+    //Avant de faire un mkdir il faut verifier si le repertoire n'existe pas deja
+    //sinon la pile des commandes FTP est remise a zero !!!
+    m_ftpCommands << "mkdir;" + rep;
+}
+
+void tools::ftpPut(QString source, QString ladest)
+{
+    m_ftpCommands << "put;" + source + ";" + ladest;
+}
+
 void tools::parcoursRecursif(QString rep, QString repertoireServeur)
 {
     qDebug() << "parcoursRecursif : " << rep;
@@ -144,25 +207,22 @@ void tools::parcoursRecursif(QString rep, QString repertoireServeur)
 
 void tools::uploadRecursifGallery(QString destDirBase)
 {
-    qDebug() << "uploadRecursifGallery : ";
-    m_typeUploadRecursif = "Gallery";
+    qDebug() << " ** uploadRecursifGallery : " << m_fileListToUploadIndex.count() ;
     m_destDirBase = destDirBase;
-    if(m_currentFTPFileUpload < m_fileListToUploadIndex.count()) {
-        QFileInfo fi(m_fileListToUploadIndex.at(m_currentFTPFileUpload));
+    m_typeUploadRecursif = "Gallery";
+    while(m_fileListToUploadIndex.count()>0) {
+        QString s(m_fileListToUploadIndex.takeFirst());
+        qDebug() << "     -> " << s;
+        QFileInfo fi(s);
         if(fi.isDir()) {
-            QString ladest = destDirBase + "/galleries/" + fi.absoluteFilePath().remove(m_baseDir.absolutePath()).remove("/www");
-            qDebug() << "mkdir : " << ladest;
-            m_ftp->mkdir(ladest);
+            QString ladest = m_destDirBase + "/galleries" + fi.absoluteFilePath().remove(m_baseDir.absolutePath());
+            qDebug() << "       mkdir : " << ladest;
+            ftpMkdir(ladest);
         }
         else {
-            QFile *fic = new QFile(fi.absoluteFilePath());
-            fic->open(QIODevice::ReadOnly);
             QString ladest = destDirBase + "/galleries/" + m_fileListToUpload.value(fi.absoluteFilePath()) + "/" + fi.fileName();
-            qDebug() << "Upload : " << fi.absoluteFilePath() << " -> " << ladest;
-            m_ftp->put(fic,ladest);
-            fic->close();
+            ftpPut(fi.absoluteFilePath(),ladest);
         }
-        m_currentFTPFileUpload++;
     }
 }
 
@@ -181,15 +241,11 @@ void tools::uploadRecursifPHP(QString destDirBase)
         if(fi.isDir()) {
             QString ladest = m_destDirBase + fi.absoluteFilePath().remove(m_baseDir.absolutePath()).remove("/www");
             qDebug() << "mkdir : " << ladest;
-            m_ftp->mkdir(ladest);
+            ftpMkdir(ladest);
         }
         else {
-            QFile *fic = new QFile(fi.absoluteFilePath());
-            fic->open(QIODevice::ReadOnly);
             QString ladest = m_destDirBase + m_fileListToUpload.value(fi.absoluteFilePath()) + "/" + fi.fileName();
-            qDebug() << "Upload : " << fi.fileName() << " -> " << ladest;
-            m_ftp->put(fic,ladest);
-            fic->close();
+            ftpPut(fi.absoluteFilePath(),ladest);
         }
         m_currentFTPFileUpload++;
     }
@@ -197,6 +253,6 @@ void tools::uploadRecursifPHP(QString destDirBase)
 
 void tools::addToList(const QUrlInfo &urlInfo)
 {
+    qDebug() << "tools::addToList";
     qDebug() << urlInfo.name();
 }
-
diff --git a/tools.h b/tools.h
index 4771128..69457d1 100644
--- a/tools.h
+++ b/tools.h
@@ -31,6 +31,7 @@
 #include <QDebug>
 #include <QApplication>
 #include <QDir>
+#include <QThread>
 
 class tools : public QObject
 {
@@ -43,9 +44,11 @@ signals:
     void signalUploadData(int,int);
 
 public slots:
-    QFtp *ftpConnect(QString serveur, QString login, QString passwd);
+    void ftpConnect(QString serveur, QString login, QString passwd);
     void parcoursRecursif(QString rep, QString repertoireServeur);
     void ftpCommandFinished(int commandId, bool error);
+    void ftpDone(bool error);
+    void ftpStateChanged(int state);
     void uploadRecursifPHP(QString destDirBase);
     void uploadRecursifGallery(QString destDirBase);
     void updateDataTransferProgress(qint64 readBytes,
@@ -54,6 +57,9 @@ public slots:
     void clear();
     int nbTotalUpload();
     int nbResteUpload();
+    void ftpMkdir(QString rep);
+    void ftpPut(QString source, QString ladest);
+    void ftpNextCommand();
 
 private:
     QFtp *m_ftp;
@@ -65,7 +71,7 @@ private:
     QMap<QString,QString> m_fileListToUpload;
     int m_currentProjectPictureNumber;
     int m_currentFTPFileUpload;
-
+    QStringList m_ftpCommands;
 };
 
 #endif // TOOLS_H
