Index: extensions/digikam_export/piwigoexport/piwigotalker.cpp
===================================================================
--- extensions/digikam_export/piwigoexport/piwigotalker.cpp	(revision 4770)
+++ extensions/digikam_export/piwigoexport/piwigotalker.cpp	(revision 4874)
@@ -28,9 +28,4 @@
 #include "piwigotalker.moc"
 
-// C++ includes
-
-#include <cstring>
-#include <cstdio>
-
 // Qt includes
 
@@ -72,5 +67,4 @@
         : m_parent(parent),  m_job(0),  m_loggedIn(false)
 {
-    kDebug() << "BEGIN\n";
 }
 
@@ -143,6 +137,4 @@
     m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
     m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
-    /*    m_job->addMetaData("cookies", "manual");
-        m_job->addMetaData("setcookies", m_cookie);*/
 
     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
@@ -153,71 +145,4 @@
 
     emit signalBusy(true);
-}
-
-void PiwigoTalker::listPhotos(const QString& albumName)
-{
-    m_job   = 0;
-    m_state = GE_LISTPHOTOS;
-    m_talker_buffer.resize(0);
-#if 0
-    PiwigoMPForm form;
-    form.addPair("cmd", "fetch-album-images");
-    form.addPair("protocol_version", "2.11");
-    form.addPair("set_albumName", albumName);
-    form.finish();
-
-    m_job = KIO::http_post(m_url, form.formData(), KIO::HideProgressInfo);
-    m_job->addMetaData("content-type", form.contentType());
-    m_job->addMetaData("cookies", "manual");
-    m_job->addMetaData("setcookies", m_cookie);
-
-    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
-            this, SLOT(slotTalkerData(KIO::Job*, const QByteArray&)));
-
-    connect(m_job, SIGNAL(result(KJob *)),
-            this, SLOT(slotResult(KJob *)));
-
-    emit signalBusy(true);
-#endif
-}
-
-void PiwigoTalker::createAlbum(const QString& parentAlbumName,
-                               const QString& albumName,
-                               const QString& albumTitle,
-                               const QString& albumCaption)
-{
-    m_job   = 0;
-    m_state = GE_CREATEALBUM;
-    m_talker_buffer.resize(0);
-#if 0
-    PiwigoMPForm form;
-    form.addPair("cmd", "new-album");
-    form.addPair("protocol_version", "2.11");
-    form.addPair("set_albumName", parentAlbumName);
-
-    if (!albumName.isEmpty())
-        form.addPair("newAlbumName", albumName);
-
-    if (!albumTitle.isEmpty())
-        form.addPair("newAlbumTitle", albumTitle);
-
-    if (!albumCaption.isEmpty())
-        form.addPair("newAlbumDesc", albumCaption);
-
-    form.finish();
-
-    m_job = KIO::http_post(m_url, form.formData(), KIO::HideProgressInfo);
-    m_job->addMetaData("content-type", form.contentType());
-    m_job->addMetaData("cookies", "manual");
-    m_job->addMetaData("setcookies", m_cookie);
-
-    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
-            this, SLOT(slotTalkerData(KIO::Job*, const QByteArray&)));
-
-    connect(m_job, SIGNAL(result(KJob*)),
-            this, SLOT(slotResult(KJob*)));
-
-    emit signalBusy(true);
-#endif
 }
 
@@ -269,5 +194,5 @@
 
         // Complete name and comment for summary sending
-        m_comment = m_name = KUrl(photoPath).fileName();
+        m_comment = m_name = caption;
         m_date = fi.created();
 
@@ -301,11 +226,7 @@
     buffer.append(dataParameters.toUtf8());
 
-    //kDebug() << "Request " << m_url << buffer << "\n";
-
     m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
     m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
     m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
-    /*    m_job->addMetaData("cookies", "manual");
-        m_job->addMetaData("setcookies", m_cookie);*/
 
     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
@@ -336,6 +257,4 @@
     m_talker_buffer.resize(oldSize + data.size());
     memcpy(m_talker_buffer.data() + oldSize, data.data(), data.size());
-
-    kDebug() << data;
 }
 
@@ -349,5 +268,5 @@
             kDebug() << tempjob->errorString();
         } else {
-            if (m_state == GE_CHECKPHOTOEXIST || m_state == GE_ADDPHOTO) {
+            if (m_state == GE_CHECKPHOTOEXIST || m_state == GE_ADDPHOTO || m_state == GE_ADDTHUMB || m_state == GE_ADDPHOTOSUMMARY) {
                 emit signalAddPhotoFailed(tempjob->errorString());
             } else {
@@ -366,10 +285,4 @@
     case(GE_LISTALBUMS):
         parseResponseListAlbums(m_talker_buffer);
-        break;
-    case(GE_LISTPHOTOS):
-        parseResponseListPhotos(m_talker_buffer);
-        break;
-    case(GE_CREATEALBUM):
-        parseResponseCreateAlbum(m_talker_buffer);
         break;
     case(GE_CHECKPHOTOEXIST):
@@ -391,28 +304,4 @@
 
     if (m_state == GE_LOGIN && m_loggedIn) {
-        /*
-        		const QStringList cookielist = (tempjob->queryMetaData("setcookies")).split('\n');
-                m_cookie = "Cookie:";
-
-
-                if(!cookielist.isEmpty())
-                {
-                    QRegExp rx("^PIWIGOSID=.+");
-                    QString app;
-                    foreach(const QString &str, cookielist)
-                    {
-                        if(str.contains("Set-Cookie: "))
-                        {
-                            const QStringList cl = str.split(' ');
-                            int n = cl.lastIndexOf(rx);
-                            if(n!= -1)
-                            {
-                                app = cl.at(n);
-                            }
-                        }
-                    }
-                    m_cookie += app;
-                }
-        */
         listAlbums();
     }
@@ -427,4 +316,6 @@
     bool foundResponse = false;
     m_loggedIn         = false;
+
+    kDebug() << "parseResponseLogin: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -461,5 +352,5 @@
     GAlbumList::iterator iter = albumList.begin();
 
-    kDebug() << QString(data);
+    kDebug() << "parseResponseListAlbums: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -517,101 +408,4 @@
 }
 
-void PiwigoTalker::parseResponseListPhotos(const QByteArray &data)
-{
-    QString str = QString::fromUtf8(data);
-    QTextStream ts(&str, QIODevice::ReadOnly);
-    QString line;
-    bool foundResponse = false;
-    bool success       = false;
-
-    typedef QList<GPhoto> GPhotoList;
-    GPhotoList photoList;
-    GPhotoList::iterator iter = photoList.begin();
-
-    QString albumURL;
-
-    while (!ts.atEnd()) {
-        line = ts.readLine();
-
-        if (!foundResponse) {
-            foundResponse = line.startsWith(QLatin1String(("#__GR2PROTO__")));
-        } else {
-            QStringList strlist = line.split('=');
-            if (strlist.count() == 2) {
-                QString key   = strlist[0];
-                QString value = strlist[1];
-
-                if (key == "status") {
-                    success = (value == "0");
-                } else if (key.startsWith(QLatin1String(("image.name")))) {
-                    GPhoto photo;
-                    photo.name    = value;
-                    photo.ref_num = key.section('.', 2, 2).toInt();
-                    iter = photoList.insert(iter, photo);
-                } else if (key.startsWith(QLatin1String(("image.caption")))) {
-                    (*iter).caption = value;
-                } else if (key.startsWith(QLatin1String(("image.thumbName")))) {
-                    (*iter).thumbName = value;
-                } else if (key.startsWith(QLatin1String(("baseurl")))) {
-                    albumURL = value.replace("\\", "");     // doesn't compile fixing EBN Krazy issue!!
-                }
-            }
-        }
-    }
-
-    if (!foundResponse) {
-        emit signalError(i18n("Invalid response received from remote Piwigo"));
-        return;
-    }
-
-    if (!success) {
-        emit signalError(i18n("Failed to list photos"));
-        return;
-    }
-
-    emit signalPhotos(photoList);
-}
-
-void PiwigoTalker::parseResponseCreateAlbum(const QByteArray& data)
-{
-    QString str = QString::fromUtf8(data);
-    QTextStream ts(&str, QIODevice::ReadOnly);
-    QString line;
-    bool foundResponse = false;
-    bool success       = false;
-
-    while (!ts.atEnd()) {
-        line = ts.readLine();
-
-        if (!foundResponse) {
-            foundResponse = line.startsWith(QLatin1String(("#__GR2PROTO__")));
-        } else {
-            QStringList strlist = line.split('=');
-            if (strlist.count() == 2) {
-                QString key   = strlist[0];
-                QString value = strlist[1];
-                if (key == "status") {    // key == "status" NOT FOUND!!!
-                    success = (value == "0");
-                    kWarning() << "Create Album. success: " << success ;
-                } else if (key.startsWith(QLatin1String(("status_text")))) {
-                    kDebug() << "STATUS: Create Album: " << value ;
-                }
-            }
-        }
-    }
-
-    if (!foundResponse) {
-        emit signalError(i18n("Invalid response received from remote Piwigo"));
-        return;
-    }
-
-    if (!success) {
-        emit signalError(i18n("Failed to create new album"));
-        return;
-    }
-
-    listAlbums();
-}
-
 void PiwigoTalker::parseResponseDoesPhotoExist(const QByteArray& data)
 {
@@ -622,9 +416,5 @@
     bool success       = false;
 
-//    typedef QList<GAlbum> GAlbumList;
-//    GAlbumList albumList;
-//    GAlbumList::iterator iter = albumList.begin();
-
-    kDebug() << QString(data);
+    kDebug() << "parseResponseDoesPhotoExist: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -667,11 +457,7 @@
     imagefile.close();
 
-    //kDebug() << "Request " << m_url << buffer << "\n";
-
     m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
     m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
     m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
-    /*    m_job->addMetaData("cookies", "manual");
-        m_job->addMetaData("setcookies", m_cookie);*/
 
     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
@@ -680,48 +466,4 @@
     connect(m_job, SIGNAL(result(KJob *)),
             this, SLOT(slotResult(KJob *)));
-
-#if 0
-    QString str = QString::fromUtf8(data);
-    QTextStream ts(&str, QIODevice::ReadOnly);
-    QString line;
-    bool foundResponse = false;
-    bool success       = false;
-
-    while (!ts.atEnd()) {
-        line = ts.readLine();
-
-        if (!foundResponse) {
-            // Piwigo1 sends resizing debug code sometimes so we
-            // have to detect things slightly differently
-            foundResponse = (line.startsWith(QLatin1String(("#__GR2PROTO__")))
-                             || (line.startsWith(QLatin1String(("<br>- Resizing")))
-                                 && line.endsWith(QLatin1String(("#__GR2PROTO__")))));
-        } else {
-            QStringList strlist = line.split('=');
-            if (strlist.count() == 2) {
-                QString key   = strlist[0];
-                QString value = strlist[1];
-
-                if (key == "status") {
-                    success = (value == "0");
-                    kWarning() << "Add photo. success: " << success ;
-                } else if (key.startsWith(QLatin1String(("status_text")))) {
-                    kDebug() << "STATUS: Add Photo: " << value ;
-                }
-            }
-        }
-    }
-
-    if (!foundResponse) {
-        emit signalAddPhotoFailed(i18n("Invalid response received from remote Piwigo"));
-        return;
-    }
-
-    if (!success) {
-        emit signalAddPhotoFailed(i18n("Failed to upload photo"));
-    } else {
-        emit signalAddPhotoSucceeded();
-    }
-#endif
 }
 
@@ -735,5 +477,5 @@
     bool success       = false;
 
-    kDebug() << QString(data);
+    kDebug() << "parseResponseAddPhoto: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -776,11 +518,7 @@
     imagefile.close();
 
-    //kDebug() << "Request " << m_url << buffer << "\n";
-
     m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
     m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
     m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
-    /*    m_job->addMetaData("cookies", "manual");
-        m_job->addMetaData("setcookies", m_cookie);*/
 
     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
@@ -800,5 +538,5 @@
     bool success       = false;
 
-    kDebug() << QString(data);
+    kDebug() << "parseResponseAddThumbnail: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -826,7 +564,4 @@
     m_state = GE_ADDPHOTOSUMMARY;
 
-    //name=img_9738&author=Fr%E9d%E9ric+COIFFIER&categories=12&file_sum=8aa81afb8f15a5dbcf463e210e0cc6f2&thumbnail_sum=8d30dd047bd8d44ea099c461bd87ff7c&original_sum=278d66d52b278fbf531a4c7a74a0dd21&date_creation=2009%3A06%3A16&tag_ids=&comment=&mthod=pwg.images.add
-
-
     QFile imagefile(m_thumbpath);
     imagefile.open(QIODevice::ReadOnly);
@@ -836,9 +571,9 @@
     qsl.append("original_sum=" + m_md5sum.toHex());
     qsl.append("name=" + m_name.toUtf8().toPercentEncoding());
-    qsl.append("author="); // TODO
+    qsl.append("author="); // TODO Retrieve author name from EXIF/IPTC tags
     qsl.append("categories=" + QString::number(m_albumId));
     qsl.append("file_sum=" + computeMD5Sum(m_path).toHex());
     qsl.append("thumbnail_sum=" + computeMD5Sum(m_thumbpath).toHex());
-    qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding()); // 2007%3A06%3A23
+    qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding());
     qsl.append("tag_ids=");
     qsl.append("comment=" + m_comment.toUtf8().toPercentEncoding());
@@ -849,11 +584,7 @@
     imagefile.close();
 
-    kDebug() << "Request " << m_url << buffer << "\n";
-
     m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
     m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
     m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
-    /*    m_job->addMetaData("cookies", "manual");
-        m_job->addMetaData("setcookies", m_cookie);*/
 
     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
@@ -872,5 +603,5 @@
     bool success       = false;
 
-    kDebug() << QString(data);
+    kDebug() << "parseResponseAddPhotoSummary: " << QString(data);
 
     while (!ts.atEnd()) {
@@ -896,34 +627,16 @@
     }
 
-#if 0
-    while (!ts.atEnd()) {
-        line = ts.readLine();
-
-        if (!foundResponse) {
-            // Piwigo1 sends resizing debug code sometimes so we
-            // have to detect things slightly differently
-            foundResponse = (line.startsWith(QLatin1String(("#__GR2PROTO__")))
-                             || (line.startsWith(QLatin1String(("<br>- Resizing")))
-                                 && line.endsWith(QLatin1String(("#__GR2PROTO__")))));
-        } else {
-            QStringList strlist = line.split('=');
-            if (strlist.count() == 2) {
-                QString key   = strlist[0];
-                QString value = strlist[1];
-
-                if (key == "status") {
-                    success = (value == "0");
-                    kWarning() << "Add photo. success: " << success ;
-                } else if (key.startsWith(QLatin1String(("status_text")))) {
-                    kDebug() << "STATUS: Add Photo: " << value ;
-                }
-            }
-        }
-    }
-#endif
     if (!foundResponse) {
         emit signalAddPhotoFailed(i18n("Invalid response received from remote Piwigo"));
         return;
     }
+
+    if (m_path.size())
+        QFile(m_path).remove();
+    if (m_thumbpath.size())
+        QFile(m_thumbpath).remove();
+
+    m_path = "";
+    m_thumbpath = "";
 
     if (!success) {
