Changeset 4874 for extensions/digikam_export/piwigoexport/piwigotalker.cpp
- Timestamp:
- Feb 10, 2010, 10:18:02 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/digikam_export/piwigoexport/piwigotalker.cpp
r4770 r4874 28 28 #include "piwigotalker.moc" 29 29 30 // C++ includes31 32 #include <cstring>33 #include <cstdio>34 35 30 // Qt includes 36 31 … … 72 67 : m_parent(parent), m_job(0), m_loggedIn(false) 73 68 { 74 kDebug() << "BEGIN\n";75 69 } 76 70 … … 143 137 m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); 144 138 m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); 145 /* m_job->addMetaData("cookies", "manual");146 m_job->addMetaData("setcookies", m_cookie);*/147 139 148 140 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), … … 153 145 154 146 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 0163 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 #endif182 }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 0193 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 #endif222 147 } 223 148 … … 269 194 270 195 // Complete name and comment for summary sending 271 m_comment = m_name = KUrl(photoPath).fileName();196 m_comment = m_name = caption; 272 197 m_date = fi.created(); 273 198 … … 301 226 buffer.append(dataParameters.toUtf8()); 302 227 303 //kDebug() << "Request " << m_url << buffer << "\n";304 305 228 m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); 306 229 m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); 307 230 m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); 308 /* m_job->addMetaData("cookies", "manual");309 m_job->addMetaData("setcookies", m_cookie);*/310 231 311 232 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), … … 336 257 m_talker_buffer.resize(oldSize + data.size()); 337 258 memcpy(m_talker_buffer.data() + oldSize, data.data(), data.size()); 338 339 kDebug() << data;340 259 } 341 260 … … 349 268 kDebug() << tempjob->errorString(); 350 269 } 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) { 352 271 emit signalAddPhotoFailed(tempjob->errorString()); 353 272 } else { … … 366 285 case(GE_LISTALBUMS): 367 286 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);374 287 break; 375 288 case(GE_CHECKPHOTOEXIST): … … 391 304 392 305 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 */417 306 listAlbums(); 418 307 } … … 427 316 bool foundResponse = false; 428 317 m_loggedIn = false; 318 319 kDebug() << "parseResponseLogin: " << QString(data); 429 320 430 321 while (!ts.atEnd()) { … … 461 352 GAlbumList::iterator iter = albumList.begin(); 462 353 463 kDebug() << QString(data);354 kDebug() << "parseResponseListAlbums: " << QString(data); 464 355 465 356 while (!ts.atEnd()) { … … 517 408 } 518 409 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 616 410 void PiwigoTalker::parseResponseDoesPhotoExist(const QByteArray& data) 617 411 { … … 622 416 bool success = false; 623 417 624 // typedef QList<GAlbum> GAlbumList; 625 // GAlbumList albumList; 626 // GAlbumList::iterator iter = albumList.begin(); 627 628 kDebug() << QString(data); 418 kDebug() << "parseResponseDoesPhotoExist: " << QString(data); 629 419 630 420 while (!ts.atEnd()) { … … 667 457 imagefile.close(); 668 458 669 //kDebug() << "Request " << m_url << buffer << "\n";670 671 459 m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); 672 460 m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); 673 461 m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); 674 /* m_job->addMetaData("cookies", "manual");675 m_job->addMetaData("setcookies", m_cookie);*/676 462 677 463 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), … … 680 466 connect(m_job, SIGNAL(result(KJob *)), 681 467 this, SLOT(slotResult(KJob *))); 682 683 #if 0684 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 we695 // have to detect things slightly differently696 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 #endif726 468 } 727 469 … … 735 477 bool success = false; 736 478 737 kDebug() << QString(data);479 kDebug() << "parseResponseAddPhoto: " << QString(data); 738 480 739 481 while (!ts.atEnd()) { … … 776 518 imagefile.close(); 777 519 778 //kDebug() << "Request " << m_url << buffer << "\n";779 780 520 m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); 781 521 m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); 782 522 m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); 783 /* m_job->addMetaData("cookies", "manual");784 m_job->addMetaData("setcookies", m_cookie);*/785 523 786 524 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), … … 800 538 bool success = false; 801 539 802 kDebug() << QString(data);540 kDebug() << "parseResponseAddThumbnail: " << QString(data); 803 541 804 542 while (!ts.atEnd()) { … … 826 564 m_state = GE_ADDPHOTOSUMMARY; 827 565 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.add829 830 831 566 QFile imagefile(m_thumbpath); 832 567 imagefile.open(QIODevice::ReadOnly); … … 836 571 qsl.append("original_sum=" + m_md5sum.toHex()); 837 572 qsl.append("name=" + m_name.toUtf8().toPercentEncoding()); 838 qsl.append("author="); // TODO 573 qsl.append("author="); // TODO Retrieve author name from EXIF/IPTC tags 839 574 qsl.append("categories=" + QString::number(m_albumId)); 840 575 qsl.append("file_sum=" + computeMD5Sum(m_path).toHex()); 841 576 qsl.append("thumbnail_sum=" + computeMD5Sum(m_thumbpath).toHex()); 842 qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding()); // 2007%3A06%3A23577 qsl.append("date_creation=" + m_date.toString("yyyy:MM:dd").toUtf8().toPercentEncoding()); 843 578 qsl.append("tag_ids="); 844 579 qsl.append("comment=" + m_comment.toUtf8().toPercentEncoding()); … … 849 584 imagefile.close(); 850 585 851 kDebug() << "Request " << m_url << buffer << "\n";852 853 586 m_job = KIO::http_post(m_url, buffer, KIO::HideProgressInfo); 854 587 m_job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded" ); 855 588 m_job->addMetaData("customHTTPHeader", "Authorization: " + s_authToken ); 856 /* m_job->addMetaData("cookies", "manual");857 m_job->addMetaData("setcookies", m_cookie);*/858 589 859 590 connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), … … 872 603 bool success = false; 873 604 874 kDebug() << QString(data);605 kDebug() << "parseResponseAddPhotoSummary: " << QString(data); 875 606 876 607 while (!ts.atEnd()) { … … 896 627 } 897 628 898 #if 0899 while (!ts.atEnd()) {900 line = ts.readLine();901 902 if (!foundResponse) {903 // Piwigo1 sends resizing debug code sometimes so we904 // have to detect things slightly differently905 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 #endif924 629 if (!foundResponse) { 925 630 emit signalAddPhotoFailed(i18n("Invalid response received from remote Piwigo")); 926 631 return; 927 632 } 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 = ""; 928 641 929 642 if (!success) {
Note: See TracChangeset
for help on using the changeset viewer.