File indexing completed on 2023-10-03 07:22:43

0001 /* ============================================================
0002  *
0003  * This file is a part of KDE project
0004  *
0005  *
0006  * Date        : 2005-17-26
0007  * Description : a kipi plugin to export images to Facebook web service
0008  *
0009  * Copyright (C) 2005-2008 by Vardhman Jain <vardhman at gmail dot com>
0010  * Copyright (C) 2008-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * Copyright (C) 2008-2009 by Luka Renko <lure at kubuntu dot org>
0012  *
0013  * This program is free software; you can redistribute it
0014  * and/or modify it under the terms of the GNU General
0015  * Public License as published by the Free Software Foundation;
0016  * either version 2, or (at your option) any later version.
0017  *
0018  * This program is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0021  * GNU General Public License for more details.
0022  *
0023  * ============================================================ */
0024 
0025 #include "fbwindow.h"
0026 
0027 // Qt includes
0028 
0029 #include <QWindow>
0030 #include <QComboBox>
0031 #include <QMenu>
0032 #include <QFileInfo>
0033 #include <QCheckBox>
0034 #include <QCloseEvent>
0035 #include <QSpinBox>
0036 #include <QMessageBox>
0037 #include <QPointer>
0038 
0039 // KDE includes
0040 
0041 #include <kconfig.h>
0042 #include <klocalizedstring.h>
0043 #include <kwindowconfig.h>
0044 
0045 // Libkipi includes
0046 
0047 #include <KIPI/Interface>
0048 
0049 // Local includes
0050 
0051 #include "kipiplugins_debug.h"
0052 #include "kpimageslist.h"
0053 #include "kpaboutdata.h"
0054 #include "kpimageinfo.h"
0055 #include "kpversion.h"
0056 #include "kpprogresswidget.h"
0057 #include "fbitem.h"
0058 #include "fbtalker.h"
0059 #include "fbwidget.h"
0060 #include "fbalbum.h"
0061 
0062 namespace KIPIFacebookPlugin
0063 {
0064 
0065 class FbWindow::Private
0066 {
0067 public:
0068 
0069     Private(QWidget* const widget, KIPI::Interface* const iface)
0070     {
0071         m_widget          = new FbWidget(widget, iface, QString::fromLatin1("Facebook"));
0072         m_imgList         = m_widget->imagesList();
0073         m_progressBar     = m_widget->progressBar();
0074         m_changeUserBtn   = m_widget->getChangeUserBtn();
0075         m_albumsCoB       = m_widget->getAlbumsCoB();
0076         m_newAlbumBtn     = m_widget->getNewAlbmBtn();
0077         m_reloadAlbumsBtn = m_widget->getReloadBtn();
0078         m_resizeChB       = m_widget->getResizeCheckBox();
0079         m_dimensionSpB    = m_widget->getDimensionSpB();
0080         m_imageQualitySpB = m_widget->getImgQualitySpB();
0081     }
0082 
0083     FbWidget*                      m_widget;
0084     KPImagesList*                  m_imgList;
0085     QPushButton*                   m_changeUserBtn;
0086     QComboBox*                     m_albumsCoB;
0087     QPushButton*                   m_newAlbumBtn;
0088     QPushButton*                   m_reloadAlbumsBtn;
0089     QCheckBox*                     m_resizeChB;
0090     QSpinBox*                      m_dimensionSpB;
0091     QSpinBox*                      m_imageQualitySpB;
0092     KPProgressWidget*              m_progressBar;
0093 };
0094 
0095 
0096 FbWindow::FbWindow(const QString& tmpFolder, QWidget* const /*parent*/)
0097     : KPToolDialog(nullptr),
0098       d(new Private(this, iface()))
0099 {
0100     m_tmpPath.clear();
0101     m_tmpDir      = tmpFolder;
0102     m_imagesCount = 0;
0103     m_imagesTotal = 0;
0104 
0105     setMainWidget(d->m_widget);
0106     setWindowIcon(QIcon::fromTheme(QString::fromLatin1("kipi-facebook")));
0107     setModal(false);
0108 
0109     setWindowTitle(i18n("Export to Facebook Web Service"));
0110 
0111     startButton()->setText(i18n("Start Upload"));
0112     startButton()->setToolTip(i18n("Start upload to Facebook web service"));
0113 
0114     d->m_widget->setMinimumSize(700, 500);
0115     // ------------------------------------------------------------------------
0116 
0117     connect(d->m_imgList, SIGNAL(signalImageListChanged()),
0118             this, SLOT(slotImageListChanged()));
0119 
0120     connect(d->m_changeUserBtn, SIGNAL(clicked()),
0121             this, SLOT(slotUserChangeRequest()));
0122 
0123     connect(d->m_newAlbumBtn, SIGNAL(clicked()),
0124             this, SLOT(slotNewAlbumRequest()));
0125 
0126     connect(d->m_widget, SIGNAL(reloadAlbums(long long)),
0127             this, SLOT(slotReloadAlbumsRequest(long long)));
0128 
0129     connect(startButton(), SIGNAL(clicked()),
0130             this, SLOT(slotStartTransfer()));
0131 
0132     connect(this, SIGNAL(finished(int)),
0133             this, SLOT(slotFinished()));
0134 
0135     connect(this, SIGNAL(cancelClicked()),
0136             this, SLOT(slotCancelClicked()));
0137 
0138     // ------------------------------------------------------------------------
0139 
0140     KPAboutData* about = new KPAboutData(ki18n("Facebook Export"),
0141                                          ki18n("A tool to export image collection "
0142                                                "to/from Facebook web service."),
0143                                          ki18n("(c) 2005-2008, Vardhman Jain\n"
0144                                                "(c) 2008-2012, Gilles Caulier\n"
0145                                                "(c) 2008-2009, Luka Renko"));
0146 
0147     about->addAuthor(ki18n("Luka Renko").toString(),
0148                      ki18n("Author and maintainer").toString(),
0149                      QString::fromLatin1("lure at kubuntu dot org"));
0150 
0151     about->setHandbookEntry(QString::fromLatin1("tool-facebookexport"));
0152     setAboutData(about);
0153 
0154     // ------------------------------------------------------------------------
0155 
0156     m_albumDlg = new FbNewAlbum(this, QString::fromLatin1("Facebook"));
0157 
0158     // ------------------------------------------------------------------------
0159 
0160     m_talker = new FbTalker(this);
0161 
0162     connect(m_talker, SIGNAL(signalBusy(bool)),
0163             this, SLOT(slotBusy(bool)));
0164 
0165     connect(m_talker, SIGNAL(signalLoginProgress(int,int,QString)),
0166             this, SLOT(slotLoginProgress(int,int,QString)));
0167 
0168     connect(m_talker, SIGNAL(signalLoginDone(int,QString)),
0169             this, SLOT(slotLoginDone(int,QString)));
0170 
0171     connect(m_talker, SIGNAL(signalAddPhotoDone(int,QString)),
0172             this, SLOT(slotAddPhotoDone(int,QString)));
0173 
0174     connect(m_talker, SIGNAL(signalCreateAlbumDone(int,QString,QString)),
0175             this, SLOT(slotCreateAlbumDone(int,QString,QString)));
0176 
0177     connect(m_talker, SIGNAL(signalListAlbumsDone(int,QString,QList<FbAlbum>)),
0178             this, SLOT(slotListAlbumsDone(int,QString,QList<FbAlbum>)));
0179 
0180     connect(d->m_progressBar, SIGNAL(signalProgressCanceled()),
0181             this, SLOT(slotStopAndCloseProgressBar()));
0182 
0183     // ------------------------------------------------------------------------
0184 
0185     readSettings();
0186 
0187     qCDebug(KIPIPLUGINS_LOG) << "Calling Login method";
0188     buttonStateChange(m_talker->loggedIn());
0189     authenticate();
0190 }
0191 
0192 FbWindow::~FbWindow()
0193 {
0194     delete m_albumDlg;
0195     delete m_talker;
0196     delete d;
0197 }
0198 
0199 void FbWindow::slotStopAndCloseProgressBar()
0200 {
0201     // Cancel the operation
0202     slotCancelClicked();
0203 
0204     // Write settings and tidy up
0205     slotFinished();
0206 
0207     // Close the dialog
0208     reject();
0209 }
0210 
0211 void FbWindow::slotFinished()
0212 {
0213     writeSettings();
0214     d->m_imgList->listView()->clear();
0215     d->m_progressBar->progressCompleted();
0216 }
0217 
0218 void FbWindow::slotCancelClicked()
0219 {
0220     setRejectButtonMode(QDialogButtonBox::Close);
0221     m_talker->cancel();
0222     m_transferQueue.clear();
0223     d->m_imgList->cancelProcess();
0224     d->m_progressBar->hide();
0225     d->m_progressBar->progressCompleted();
0226 }
0227 
0228 void FbWindow::reactivate()
0229 {
0230     d->m_imgList->loadImagesFromCurrentSelection();
0231     show();
0232 }
0233 
0234 void FbWindow::closeEvent(QCloseEvent* e)
0235 {
0236     if (!e)
0237     {
0238         return;
0239     }
0240 
0241     slotFinished();
0242     e->accept();
0243 }
0244 
0245 void FbWindow::readSettings()
0246 {
0247     KConfig config(QString::fromLatin1("kipirc"));
0248     KConfigGroup grp = config.group("Facebook Settings");
0249     m_accessToken    = grp.readEntry("Access Token");
0250     m_sessionExpires = grp.readEntry("Session Expires", 0);
0251 
0252     if (m_accessToken.isEmpty())
0253     {
0254         m_sessionKey     = grp.readEntry("Session Key");
0255         m_sessionSecret  = grp.readEntry("Session Secret");
0256     }
0257 
0258     m_currentAlbumID = grp.readEntry("Current Album", QString());
0259 
0260     if (grp.readEntry("Resize", false))
0261     {
0262         d->m_resizeChB->setChecked(true);
0263         d->m_dimensionSpB->setEnabled(true);
0264         d->m_imageQualitySpB->setEnabled(true);
0265     }
0266     else
0267     {
0268         d->m_resizeChB->setChecked(false);
0269         d->m_dimensionSpB->setEnabled(false);
0270         d->m_imageQualitySpB->setEnabled(false);
0271     }
0272 
0273     d->m_dimensionSpB->setValue(grp.readEntry("Maximum Width", 604));
0274     d->m_imageQualitySpB->setValue(grp.readEntry("Image Quality", 85));
0275 
0276     winId();
0277     KConfigGroup dialogGroup = config.group("Facebook Export Dialog");
0278     KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup);
0279     resize(windowHandle()->size());
0280 }
0281 
0282 void FbWindow::writeSettings()
0283 {
0284     KConfig config(QString::fromLatin1("kipirc"));
0285     KConfigGroup grp = config.group("Facebook Settings");
0286     grp.writeEntry("Access Token",    m_accessToken);
0287 
0288     /* If we have both access token and session key, then we have just converted one into the other. */
0289     if (! m_accessToken.isEmpty())
0290     {
0291         if (! m_sessionKey.isEmpty())
0292         {
0293             grp.deleteEntry("Session Key");
0294         }
0295 
0296         if (! m_sessionSecret.isEmpty())
0297         {
0298             grp.deleteEntry("Session Secret");
0299         }
0300     }
0301 
0302     grp.writeEntry("Session Expires", m_sessionExpires);
0303     grp.writeEntry("Current Album",   m_currentAlbumID);
0304     grp.writeEntry("Resize",          d->m_resizeChB->isChecked());
0305     grp.writeEntry("Maximum Width",   d->m_dimensionSpB->value());
0306     grp.writeEntry("Image Quality",   d->m_imageQualitySpB->value());
0307 
0308     KConfigGroup dialogGroup = config.group("Facebook Export Dialog");
0309     KWindowConfig::saveWindowSize(windowHandle(), dialogGroup);
0310 
0311     config.sync();
0312 }
0313 
0314 void FbWindow::authenticate()
0315 {
0316     setRejectButtonMode(QDialogButtonBox::Cancel);
0317     d->m_progressBar->show();
0318     d->m_progressBar->setFormat(QString::fromLatin1(""));
0319 
0320     // Converting old world session keys into OAuth2 tokens
0321     if (! m_sessionKey.isEmpty() && m_accessToken.isEmpty())
0322     {
0323         qCDebug(KIPIPLUGINS_LOG) << "Exchanging session tokens to OAuth";
0324         m_talker->exchangeSession(m_sessionKey);
0325     }
0326     else
0327     {
0328         qCDebug(KIPIPLUGINS_LOG) << "Calling Login method";
0329         m_talker->authenticate(m_accessToken, m_sessionExpires);
0330     }
0331 }
0332 
0333 void FbWindow::slotLoginProgress(int step, int maxStep, const QString& label)
0334 {
0335     KIPIPlugins::KPProgressWidget* const progressBar = d->m_progressBar;
0336 
0337     if (!label.isEmpty())
0338     {
0339         progressBar->setFormat(label);
0340     }
0341 
0342     if (maxStep > 0)
0343     {
0344         progressBar->setMaximum(maxStep);
0345     }
0346 
0347     progressBar->setValue(step);
0348 }
0349 
0350 void FbWindow::slotLoginDone(int errCode, const QString& errMsg)
0351 {
0352     setRejectButtonMode(QDialogButtonBox::Close);
0353     d->m_progressBar->hide();
0354 
0355     buttonStateChange(m_talker->loggedIn());
0356     FbUser user = m_talker->getUser();
0357     setProfileAID(user.id);
0358     d->m_widget->updateLabels(user.name, user.profileURL);
0359     d->m_albumsCoB->clear();
0360 
0361     d->m_albumsCoB->addItem(i18n("<auto create>"), QString());
0362 
0363     m_accessToken    = m_talker->getAccessToken();
0364     m_sessionExpires = m_talker->getSessionExpires();
0365 
0366     if (errCode == 0 && m_talker->loggedIn())
0367     {
0368         m_talker->listAlbums();    // get albums to fill combo box
0369     }
0370     else
0371     {
0372         QMessageBox::critical(this, QString(), i18n("Facebook Call Failed: %1\n", errMsg));
0373     }
0374 }
0375 
0376 void FbWindow::slotListAlbumsDone(int errCode, const QString& errMsg, const QList<FbAlbum>& albumsList)
0377 {
0378 
0379     QString albumDebug = QString::fromLatin1("");
0380     foreach(const FbAlbum &album, albumsList)
0381     {
0382         albumDebug.append(QString::fromLatin1("%1: %2\n").arg(album.id).arg(album.title));
0383     }
0384 
0385     qCDebug(KIPIPLUGINS_LOG) << "Received albums (errCode = " << errCode << ", errMsg = "
0386              << errMsg << "): " << albumDebug;
0387 
0388     if (errCode != 0)
0389     {
0390         QMessageBox::critical(this, QString(), i18n("Facebook Call Failed: %1\n", errMsg));
0391         return;
0392     }
0393 
0394     d->m_albumsCoB->clear();
0395     d->m_albumsCoB->addItem(i18n("<auto create>"), QString());
0396 
0397     for (int i = 0; i < albumsList.size(); ++i)
0398     {
0399         QString albumIcon;
0400 
0401         switch (albumsList.at(i).privacy)
0402         {
0403             case FB_ME:
0404                 albumIcon = QString::fromLatin1("secure-card");
0405                 break;
0406 
0407             case FB_FRIENDS:
0408                 albumIcon = QString::fromLatin1("user-identity");
0409                 break;
0410 
0411             case FB_FRIENDS_OF_FRIENDS:
0412                 albumIcon = QString::fromLatin1("system-users");
0413                 break;
0414 
0415             case FB_NETWORKS:
0416                 albumIcon = QString::fromLatin1("network-workgroup");
0417                 break;
0418 
0419             case FB_EVERYONE:
0420                 albumIcon = QString::fromLatin1("folder-html");
0421                 break;
0422 
0423             case FB_CUSTOM:
0424                 albumIcon = QString::fromLatin1("configure");
0425                 break;
0426         }
0427 
0428         d->m_albumsCoB->addItem(
0429             QIcon::fromTheme(albumIcon),
0430             albumsList.at(i).title,
0431             albumsList.at(i).id);
0432 
0433         if (m_currentAlbumID == albumsList.at(i).id)
0434         {
0435             d->m_albumsCoB->setCurrentIndex(i + 1);
0436         }
0437     }
0438 }
0439 
0440 void FbWindow::buttonStateChange(bool state)
0441 {
0442     d->m_newAlbumBtn->setEnabled(state);
0443     d->m_reloadAlbumsBtn->setEnabled(state);
0444     startButton()->setEnabled(state);
0445 }
0446 
0447 void FbWindow::slotBusy(bool val)
0448 {
0449     if (val)
0450     {
0451         setCursor(Qt::WaitCursor);
0452         d->m_changeUserBtn->setEnabled(false);
0453         buttonStateChange(false);
0454     }
0455     else
0456     {
0457         setCursor(Qt::ArrowCursor);
0458         d->m_changeUserBtn->setEnabled(true);
0459         buttonStateChange(m_talker->loggedIn());
0460     }
0461 }
0462 
0463 void FbWindow::slotUserChangeRequest()
0464 {
0465     qCDebug(KIPIPLUGINS_LOG) << "Slot Change User Request";
0466 
0467     if (m_talker->loggedIn())
0468     {
0469         m_talker->logout();
0470         QMessageBox warn(QMessageBox::Warning,
0471                      i18n("Warning"),
0472                      i18n("After you have been logged out in the browser, "
0473                           "click \"Continue\" to authenticate for another account"),
0474                      QMessageBox::Yes | QMessageBox::No);
0475 
0476         (warn.button(QMessageBox::Yes))->setText(i18n("Continue"));
0477         (warn.button(QMessageBox::No))->setText(i18n("Cancel"));
0478 
0479         if (warn.exec() == QMessageBox::Yes)
0480         {
0481             m_accessToken.clear();
0482             m_sessionExpires = 0;
0483         }
0484         else
0485             return;
0486     }
0487 
0488     authenticate();
0489 }
0490 
0491 void FbWindow::slotReloadAlbumsRequest(long long userID)
0492 {
0493     qCDebug(KIPIPLUGINS_LOG) << "Reload Albums Request for UID:" << userID;
0494 
0495     if (userID == 0)
0496     {
0497         FbUser user = m_talker->getUser();
0498         setProfileAID(user.id);
0499         m_talker->listAlbums(); // re-get albums from current user
0500     }
0501     else
0502     {
0503         setProfileAID(userID);
0504         m_talker->listAlbums(userID); // re-get albums for friend
0505     }
0506 }
0507 
0508 void FbWindow::slotNewAlbumRequest()
0509 {
0510     qCDebug(KIPIPLUGINS_LOG) << "Slot New Album Request";
0511 
0512     if (m_albumDlg->exec() == QDialog::Accepted)
0513     {
0514         qCDebug(KIPIPLUGINS_LOG) << "Calling New Album method";
0515         FbAlbum newAlbum;
0516         m_albumDlg->getAlbumProperties(newAlbum);
0517         m_talker->createAlbum(newAlbum);
0518     }
0519 }
0520 
0521 void FbWindow::slotStartTransfer()
0522 {
0523     qCDebug(KIPIPLUGINS_LOG) << "slotStartTransfer invoked";
0524 
0525     d->m_imgList->clearProcessedStatus();
0526     m_transferQueue  = d->m_imgList->imageUrls();
0527 
0528     if (m_transferQueue.isEmpty())
0529     {
0530         return;
0531     }
0532 
0533     m_currentAlbumID = d->m_albumsCoB->itemData(d->m_albumsCoB->currentIndex()).toString();
0534     qCDebug(KIPIPLUGINS_LOG) << "upload request got album id from widget: " << m_currentAlbumID;
0535     m_imagesTotal    = m_transferQueue.count();
0536     m_imagesCount    = 0;
0537 
0538     setRejectButtonMode(QDialogButtonBox::Cancel);
0539     d->m_progressBar->setFormat(i18n("%v / %m"));
0540     d->m_progressBar->setMaximum(m_imagesTotal);
0541     d->m_progressBar->setValue(0);
0542     d->m_progressBar->show();
0543     d->m_progressBar->progressScheduled(i18n("Facebook export"), true, true);
0544     d->m_progressBar->progressThumbnailChanged(QIcon(QLatin1String(":/icons/kipi-icon.svg")).pixmap(22, 22));
0545 
0546     uploadNextPhoto();
0547 }
0548 
0549 void FbWindow::setProfileAID(long long userID)
0550 {
0551     // store AID of Profile Photos album
0552     // http://wiki.developers.facebook.com/index.php/Profile_archive_album
0553     m_profileAID = QString::number((userID << 32)
0554                                    + (-3 & 0xFFFFFFFF));
0555 }
0556 
0557 QString FbWindow::getImageCaption(const QString& fileName)
0558 {
0559     KPImageInfo info(QUrl::fromLocalFile(fileName));
0560     // Facebook doesn't support image titles. Include it in descriptions if needed.
0561     QStringList descriptions = QStringList() << info.title() << info.description();
0562     descriptions.removeAll(QString::fromLatin1(""));
0563     return descriptions.join(QString::fromLatin1("\n\n"));
0564 }
0565 
0566 bool FbWindow::prepareImageForUpload(const QString& imgPath, QString& caption)
0567 {
0568     QImage image;
0569 
0570     if (iface())
0571     {
0572         image = iface()->preview(QUrl::fromLocalFile(imgPath));
0573     }
0574 
0575     if (image.isNull())
0576     {
0577         image.load(imgPath);
0578     }
0579 
0580     if (image.isNull())
0581     {
0582         return false;
0583     }
0584 
0585     // get temporary file name
0586     m_tmpPath = m_tmpDir + QFileInfo(imgPath).baseName().trimmed() + QString::fromLatin1(".jpg");
0587 
0588     // rescale image if requested
0589     int maxDim = d->m_dimensionSpB->value();
0590 
0591     if (d->m_resizeChB->isChecked()
0592         && (image.width() > maxDim || image.height() > maxDim))
0593     {
0594         qCDebug(KIPIPLUGINS_LOG) << "Resizing to " << maxDim;
0595         image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio,
0596                              Qt::SmoothTransformation);
0597     }
0598 
0599     qCDebug(KIPIPLUGINS_LOG) << "Saving to temp file: " << m_tmpPath;
0600     image.save(m_tmpPath, "JPEG", d->m_imageQualitySpB->value());
0601 
0602     // copy meta data to temporary image
0603 
0604     if (iface())
0605     {
0606         QPointer<MetadataProcessor> meta = iface()->createMetadataProcessor();
0607 
0608         if (meta && meta->load(QUrl::fromLocalFile(imgPath)))
0609         {
0610             caption = getImageCaption(imgPath);
0611             meta->setImageDimensions(image.size());
0612             meta->setImageOrientation(MetadataProcessor::NORMAL);
0613             meta->setImageProgramId(QString::fromLatin1("Kipi-plugins"), kipipluginsVersion());
0614             meta->save(QUrl::fromLocalFile(m_tmpPath), true);
0615         }
0616         else
0617         {
0618             caption.clear();
0619         }
0620     }
0621 
0622     return true;
0623 }
0624 
0625 void FbWindow::uploadNextPhoto()
0626 {
0627     if (m_transferQueue.isEmpty())
0628     {
0629         setRejectButtonMode(QDialogButtonBox::Close);
0630         d->m_progressBar->hide();
0631         d->m_progressBar->progressCompleted();
0632         return;
0633     }
0634 
0635     d->m_imgList->processing(m_transferQueue.first());
0636     QString imgPath = m_transferQueue.first().toLocalFile();
0637 
0638     d->m_progressBar->setMaximum(m_imagesTotal);
0639     d->m_progressBar->setValue(m_imagesCount);
0640 
0641     QString caption;
0642     bool    res;
0643 
0644     if (d->m_resizeChB->isChecked())
0645     {
0646         if (!prepareImageForUpload(imgPath, caption))
0647         {
0648             slotAddPhotoDone(666, i18n("Cannot open file"));
0649             return;
0650         }
0651 
0652         res = m_talker->addPhoto(m_tmpPath, m_currentAlbumID, caption);
0653     }
0654     else
0655     {
0656         caption = getImageCaption(imgPath);
0657         m_tmpPath.clear();
0658         res     = m_talker->addPhoto(imgPath, m_currentAlbumID, caption);
0659     }
0660 
0661     if (!res)
0662     {
0663         slotAddPhotoDone(666, i18n("Cannot open file"));
0664         return;
0665     }
0666 }
0667 
0668 void FbWindow::slotAddPhotoDone(int errCode, const QString& errMsg)
0669 {
0670     // Remove temporary file if it was used
0671     if (!m_tmpPath.isEmpty())
0672     {
0673         QFile::remove(m_tmpPath);
0674         m_tmpPath.clear();
0675     }
0676 
0677     d->m_imgList->processed(m_transferQueue.first(), (errCode == 0));
0678 
0679     if (errCode == 0)
0680     {
0681         m_transferQueue.pop_front();
0682         m_imagesCount++;
0683     }
0684     else
0685     {
0686         if (QMessageBox::question(this, i18n("Uploading Failed"),
0687                                   i18n("Failed to upload photo into Facebook: %1\n"
0688                                        "Do you want to continue?", errMsg))
0689             != QMessageBox::Yes)
0690         {
0691             setRejectButtonMode(QDialogButtonBox::Close);
0692             d->m_progressBar->hide();
0693             d->m_progressBar->progressCompleted();
0694             m_transferQueue.clear();
0695             return;
0696         }
0697     }
0698 
0699     uploadNextPhoto();
0700 }
0701 
0702 void FbWindow::slotCreateAlbumDone(int errCode, const QString& errMsg, const QString& newAlbumID)
0703 {
0704     if (errCode != 0)
0705     {
0706         QMessageBox::critical(this, QString(), i18n("Facebook Call Failed: %1", errMsg));
0707         return;
0708     }
0709 
0710     // reload album list and automatically select new album
0711     m_currentAlbumID = newAlbumID;
0712     m_talker->listAlbums();
0713 }
0714 
0715 void FbWindow::slotImageListChanged()
0716 {
0717     startButton()->setEnabled(!(d->m_imgList->imageUrls().isEmpty()));
0718 }
0719 
0720 } // namespace KIPIFacebookPlugin
0721 
0722 #include "moc_fbwindow.cpp"