Ignore:
Timestamp:
Feb 10, 2010, 10:18:02 PM (14 years ago)
Author:
fcoiffie
Message:

[digikam_export] Removal of all useless and commented code

  • Temporary files are removed
  • Warnings correction
  • Selected 'thumbnail size' is stored in the configuration file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/digikam_export/piwigoexport/piwigotalker.cpp

    r4770 r4874  
    2828#include "piwigotalker.moc"
    2929
    30 // C++ includes
    31 
    32 #include <cstring>
    33 #include <cstdio>
    34 
    3530// Qt includes
    3631
     
    7267        : m_parent(parent),  m_job(0),  m_loggedIn(false)
    7368{
    74     kDebug() << "BEGIN\n";
    7569}
    7670
     
    143137    m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
    144138    m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
    145     /*    m_job->addMetaData("cookies", "manual");
    146         m_job->addMetaData("setcookies", m_cookie);*/
    147139
    148140    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
     
    153145
    154146    emit signalBusy(true);
    155 }
    156 
    157 void PiwigoTalker::listPhotos(const QString& albumName)
    158 {
    159     m_job   = 0;
    160     m_state = GE_LISTPHOTOS;
    161     m_talker_buffer.resize(0);
    162 #if 0
    163     PiwigoMPForm form;
    164     form.addPair("cmd", "fetch-album-images");
    165     form.addPair("protocol_version", "2.11");
    166     form.addPair("set_albumName", albumName);
    167     form.finish();
    168 
    169     m_job = KIO::http_post(m_url, form.formData(), KIO::HideProgressInfo);
    170     m_job->addMetaData("content-type", form.contentType());
    171     m_job->addMetaData("cookies", "manual");
    172     m_job->addMetaData("setcookies", m_cookie);
    173 
    174     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
    175             this, SLOT(slotTalkerData(KIO::Job*, const QByteArray&)));
    176 
    177     connect(m_job, SIGNAL(result(KJob *)),
    178             this, SLOT(slotResult(KJob *)));
    179 
    180     emit signalBusy(true);
    181 #endif
    182 }
    183 
    184 void PiwigoTalker::createAlbum(const QString& parentAlbumName,
    185                                const QString& albumName,
    186                                const QString& albumTitle,
    187                                const QString& albumCaption)
    188 {
    189     m_job   = 0;
    190     m_state = GE_CREATEALBUM;
    191     m_talker_buffer.resize(0);
    192 #if 0
    193     PiwigoMPForm form;
    194     form.addPair("cmd", "new-album");
    195     form.addPair("protocol_version", "2.11");
    196     form.addPair("set_albumName", parentAlbumName);
    197 
    198     if (!albumName.isEmpty())
    199         form.addPair("newAlbumName", albumName);
    200 
    201     if (!albumTitle.isEmpty())
    202         form.addPair("newAlbumTitle", albumTitle);
    203 
    204     if (!albumCaption.isEmpty())
    205         form.addPair("newAlbumDesc", albumCaption);
    206 
    207     form.finish();
    208 
    209     m_job = KIO::http_post(m_url, form.formData(), KIO::HideProgressInfo);
    210     m_job->addMetaData("content-type", form.contentType());
    211     m_job->addMetaData("cookies", "manual");
    212     m_job->addMetaData("setcookies", m_cookie);
    213 
    214     connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
    215             this, SLOT(slotTalkerData(KIO::Job*, const QByteArray&)));
    216 
    217     connect(m_job, SIGNAL(result(KJob*)),
    218             this, SLOT(slotResult(KJob*)));
    219 
    220     emit signalBusy(true);
    221 #endif
    222147}
    223148
     
    269194
    270195        // Complete name and comment for summary sending
    271         m_comment = m_name = KUrl(photoPath).fileName();
     196        m_comment = m_name = caption;
    272197        m_date = fi.created();
    273198
     
    301226    buffer.append(dataParameters.toUtf8());
    302227
    303     //kDebug() << "Request " << m_url << buffer << "\n";
    304 
    305228    m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
    306229    m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
    307230    m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
    308     /*    m_job->addMetaData("cookies", "manual");
    309         m_job->addMetaData("setcookies", m_cookie);*/
    310231
    311232    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
     
    336257    m_talker_buffer.resize(oldSize + data.size());
    337258    memcpy(m_talker_buffer.data() + oldSize, data.data(), data.size());
    338 
    339     kDebug() << data;
    340259}
    341260
     
    349268            kDebug() << tempjob->errorString();
    350269        } else {
    351             if (m_state == GE_CHECKPHOTOEXIST || m_state == GE_ADDPHOTO) {
     270            if (m_state == GE_CHECKPHOTOEXIST || m_state == GE_ADDPHOTO || m_state == GE_ADDTHUMB || m_state == GE_ADDPHOTOSUMMARY) {
    352271                emit signalAddPhotoFailed(tempjob->errorString());
    353272            } else {
     
    366285    case(GE_LISTALBUMS):
    367286        parseResponseListAlbums(m_talker_buffer);
    368         break;
    369     case(GE_LISTPHOTOS):
    370         parseResponseListPhotos(m_talker_buffer);
    371         break;
    372     case(GE_CREATEALBUM):
    373         parseResponseCreateAlbum(m_talker_buffer);
    374287        break;
    375288    case(GE_CHECKPHOTOEXIST):
     
    391304
    392305    if (m_state == GE_LOGIN && m_loggedIn) {
    393         /*
    394                         const QStringList cookielist = (tempjob->queryMetaData("setcookies")).split('\n');
    395                 m_cookie = "Cookie:";
    396 
    397 
    398                 if(!cookielist.isEmpty())
    399                 {
    400                     QRegExp rx("^PIWIGOSID=.+");
    401                     QString app;
    402                     foreach(const QString &str, cookielist)
    403                     {
    404                         if(str.contains("Set-Cookie: "))
    405                         {
    406                             const QStringList cl = str.split(' ');
    407                             int n = cl.lastIndexOf(rx);
    408                             if(n!= -1)
    409                             {
    410                                 app = cl.at(n);
    411                             }
    412                         }
    413                     }
    414                     m_cookie += app;
    415                 }
    416         */
    417306        listAlbums();
    418307    }
     
    427316    bool foundResponse = false;
    428317    m_loggedIn         = false;
     318
     319    kDebug() << "parseResponseLogin: " << QString(data);
    429320
    430321    while (!ts.atEnd()) {
     
    461352    GAlbumList::iterator iter = albumList.begin();
    462353
    463     kDebug() << QString(data);
     354    kDebug() << "parseResponseListAlbums: " << QString(data);
    464355
    465356    while (!ts.atEnd()) {
     
    517408}
    518409
    519 void PiwigoTalker::parseResponseListPhotos(const QByteArray &data)
    520 {
    521     QString str = QString::fromUtf8(data);
    522     QTextStream ts(&str, QIODevice::ReadOnly);
    523     QString line;
    524     bool foundResponse = false;
    525     bool success       = false;
    526 
    527     typedef QList<GPhoto> GPhotoList;
    528     GPhotoList photoList;
    529     GPhotoList::iterator iter = photoList.begin();
    530 
    531     QString albumURL;
    532 
    533     while (!ts.atEnd()) {
    534         line = ts.readLine();
    535 
    536         if (!foundResponse) {
    537             foundResponse = line.startsWith(QLatin1String(("#__GR2PROTO__")));
    538         } else {
    539             QStringList strlist = line.split('=');
    540             if (strlist.count() == 2) {
    541                 QString key   = strlist[0];
    542                 QString value = strlist[1];
    543 
    544                 if (key == "status") {
    545                     success = (value == "0");
    546                 } else if (key.startsWith(QLatin1String(("image.name")))) {
    547                     GPhoto photo;
    548                     photo.name    = value;
    549                     photo.ref_num = key.section('.', 2, 2).toInt();
    550                     iter = photoList.insert(iter, photo);
    551                 } else if (key.startsWith(QLatin1String(("image.caption")))) {
    552                     (*iter).caption = value;
    553                 } else if (key.startsWith(QLatin1String(("image.thumbName")))) {
    554                     (*iter).thumbName = value;
    555                 } else if (key.startsWith(QLatin1String(("baseurl")))) {
    556                     albumURL = value.replace("\\", "");     // doesn't compile fixing EBN Krazy issue!!
    557                 }
    558             }
    559         }
    560     }
    561 
    562     if (!foundResponse) {
    563         emit signalError(i18n("Invalid response received from remote Piwigo"));
    564         return;
    565     }
    566 
    567     if (!success) {
    568         emit signalError(i18n("Failed to list photos"));
    569         return;
    570     }
    571 
    572     emit signalPhotos(photoList);
    573 }
    574 
    575 void PiwigoTalker::parseResponseCreateAlbum(const QByteArray& data)
    576 {
    577     QString str = QString::fromUtf8(data);
    578     QTextStream ts(&str, QIODevice::ReadOnly);
    579     QString line;
    580     bool foundResponse = false;
    581     bool success       = false;
    582 
    583     while (!ts.atEnd()) {
    584         line = ts.readLine();
    585 
    586         if (!foundResponse) {
    587             foundResponse = line.startsWith(QLatin1String(("#__GR2PROTO__")));
    588         } else {
    589             QStringList strlist = line.split('=');
    590             if (strlist.count() == 2) {
    591                 QString key   = strlist[0];
    592                 QString value = strlist[1];
    593                 if (key == "status") {    // key == "status" NOT FOUND!!!
    594                     success = (value == "0");
    595                     kWarning() << "Create Album. success: " << success ;
    596                 } else if (key.startsWith(QLatin1String(("status_text")))) {
    597                     kDebug() << "STATUS: Create Album: " << value ;
    598                 }
    599             }
    600         }
    601     }
    602 
    603     if (!foundResponse) {
    604         emit signalError(i18n("Invalid response received from remote Piwigo"));
    605         return;
    606     }
    607 
    608     if (!success) {
    609         emit signalError(i18n("Failed to create new album"));
    610         return;
    611     }
    612 
    613     listAlbums();
    614 }
    615 
    616410void PiwigoTalker::parseResponseDoesPhotoExist(const QByteArray& data)
    617411{
     
    622416    bool success       = false;
    623417
    624 //    typedef QList<GAlbum> GAlbumList;
    625 //    GAlbumList albumList;
    626 //    GAlbumList::iterator iter = albumList.begin();
    627 
    628     kDebug() << QString(data);
     418    kDebug() << "parseResponseDoesPhotoExist: " << QString(data);
    629419
    630420    while (!ts.atEnd()) {
     
    667457    imagefile.close();
    668458
    669     //kDebug() << "Request " << m_url << buffer << "\n";
    670 
    671459    m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
    672460    m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
    673461    m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
    674     /*    m_job->addMetaData("cookies", "manual");
    675         m_job->addMetaData("setcookies", m_cookie);*/
    676462
    677463    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
     
    680466    connect(m_job, SIGNAL(result(KJob *)),
    681467            this, SLOT(slotResult(KJob *)));
    682 
    683 #if 0
    684     QString str = QString::fromUtf8(data);
    685     QTextStream ts(&str, QIODevice::ReadOnly);
    686     QString line;
    687     bool foundResponse = false;
    688     bool success       = false;
    689 
    690     while (!ts.atEnd()) {
    691         line = ts.readLine();
    692 
    693         if (!foundResponse) {
    694             // Piwigo1 sends resizing debug code sometimes so we
    695             // have to detect things slightly differently
    696             foundResponse = (line.startsWith(QLatin1String(("#__GR2PROTO__")))
    697                              || (line.startsWith(QLatin1String(("<br>- Resizing")))
    698                                  && line.endsWith(QLatin1String(("#__GR2PROTO__")))));
    699         } else {
    700             QStringList strlist = line.split('=');
    701             if (strlist.count() == 2) {
    702                 QString key   = strlist[0];
    703                 QString value = strlist[1];
    704 
    705                 if (key == "status") {
    706                     success = (value == "0");
    707                     kWarning() << "Add photo. success: " << success ;
    708                 } else if (key.startsWith(QLatin1String(("status_text")))) {
    709                     kDebug() << "STATUS: Add Photo: " << value ;
    710                 }
    711             }
    712         }
    713     }
    714 
    715     if (!foundResponse) {
    716         emit signalAddPhotoFailed(i18n("Invalid response received from remote Piwigo"));
    717         return;
    718     }
    719 
    720     if (!success) {
    721         emit signalAddPhotoFailed(i18n("Failed to upload photo"));
    722     } else {
    723         emit signalAddPhotoSucceeded();
    724     }
    725 #endif
    726468}
    727469
     
    735477    bool success       = false;
    736478
    737     kDebug() << QString(data);
     479    kDebug() << "parseResponseAddPhoto: " << QString(data);
    738480
    739481    while (!ts.atEnd()) {
     
    776518    imagefile.close();
    777519
    778     //kDebug() << "Request " << m_url << buffer << "\n";
    779 
    780520    m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
    781521    m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
    782522    m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
    783     /*    m_job->addMetaData("cookies", "manual");
    784         m_job->addMetaData("setcookies", m_cookie);*/
    785523
    786524    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
     
    800538    bool success       = false;
    801539
    802     kDebug() << QString(data);
     540    kDebug() << "parseResponseAddThumbnail: " << QString(data);
    803541
    804542    while (!ts.atEnd()) {
     
    826564    m_state = GE_ADDPHOTOSUMMARY;
    827565
    828     //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
    829 
    830 
    831566    QFile imagefile(m_thumbpath);
    832567    imagefile.open(QIODevice::ReadOnly);
     
    836571    qsl.append("original_sum=" + m_md5sum.toHex());
    837572    qsl.append("name=" + m_name.toUtf8().toPercentEncoding());
    838     qsl.append("author="); // TODO
     573    qsl.append("author="); // TODO Retrieve author name from EXIF/IPTC tags
    839574    qsl.append("categories=" + QString::number(m_albumId));
    840575    qsl.append("file_sum=" + computeMD5Sum(m_path).toHex());
    841576    qsl.append("thumbnail_sum=" + computeMD5Sum(m_thumbpath).toHex());
    842     qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding()); // 2007%3A06%3A23
     577    qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding());
    843578    qsl.append("tag_ids=");
    844579    qsl.append("comment=" + m_comment.toUtf8().toPercentEncoding());
     
    849584    imagefile.close();
    850585
    851     kDebug() << "Request " << m_url << buffer << "\n";
    852 
    853586    m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo);
    854587    m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" );
    855588    m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken );
    856     /*    m_job->addMetaData("cookies", "manual");
    857         m_job->addMetaData("setcookies", m_cookie);*/
    858589
    859590    connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)),
     
    872603    bool success       = false;
    873604
    874     kDebug() << QString(data);
     605    kDebug() << "parseResponseAddPhotoSummary: " << QString(data);
    875606
    876607    while (!ts.atEnd()) {
     
    896627    }
    897628
    898 #if 0
    899     while (!ts.atEnd()) {
    900         line = ts.readLine();
    901 
    902         if (!foundResponse) {
    903             // Piwigo1 sends resizing debug code sometimes so we
    904             // have to detect things slightly differently
    905             foundResponse = (line.startsWith(QLatin1String(("#__GR2PROTO__")))
    906                              || (line.startsWith(QLatin1String(("<br>- Resizing")))
    907                                  && line.endsWith(QLatin1String(("#__GR2PROTO__")))));
    908         } else {
    909             QStringList strlist = line.split('=');
    910             if (strlist.count() == 2) {
    911                 QString key   = strlist[0];
    912                 QString value = strlist[1];
    913 
    914                 if (key == "status") {
    915                     success = (value == "0");
    916                     kWarning() << "Add photo. success: " << success ;
    917                 } else if (key.startsWith(QLatin1String(("status_text")))) {
    918                     kDebug() << "STATUS: Add Photo: " << value ;
    919                 }
    920             }
    921         }
    922     }
    923 #endif
    924629    if (!foundResponse) {
    925630        emit signalAddPhotoFailed(i18n("Invalid response received from remote Piwigo"));
    926631        return;
    927632    }
     633
     634    if (m_path.size())
     635        QFile(m_path).remove();
     636    if (m_thumbpath.size())
     637        QFile(m_thumbpath).remove();
     638
     639    m_path = "";
     640    m_thumbpath = "";
    928641
    929642    if (!success) {
Note: See TracChangeset for help on using the changeset viewer.