File indexing completed on 2022-09-27 13:43:09

0001 /* ============================================================
0002  *
0003  * This file is a part of KDE project
0004  *
0005  *
0006  * Date        : 2005-17-06
0007  * Description : a kipi plugin to export images to Flickr 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) 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 "flickrwindow.h"
0026 
0027 // Qt includes
0028 
0029 #include <QPushButton>
0030 #include <QProgressDialog>
0031 #include <QPixmap>
0032 #include <QCheckBox>
0033 #include <QStringList>
0034 #include <QSpinBox>
0035 #include <QPointer>
0036 #include <QApplication>
0037 #include <QMenu>
0038 #include <QMessageBox>
0039 #include <QWindow>
0040 
0041 // KDE includes
0042 
0043 #include <kconfig.h>
0044 #include <kwindowconfig.h>
0045 
0046 // LibKIPI includes
0047 
0048 #include <KIPI/Interface>
0049 
0050 // Local includes
0051 
0052 #include "kpaboutdata.h"
0053 #include "kpimageinfo.h"
0054 #include "kpversion.h"
0055 #include "kpprogresswidget.h"
0056 #include "flickrtalker.h"
0057 #include "flickritem.h"
0058 #include "flickrlist.h"
0059 #include "flickrwidget.h"
0060 #include "selectuserdlg.h"
0061 #include "kipiplugins_debug.h"
0062 #include "newalbum.h"
0063 
0064 namespace KIPIFlickrPlugin
0065 {
0066 
0067 FlickrWindow::FlickrWindow(QWidget* const /*parent*/, const QString& serviceName, SelectUserDlg* const dlg)
0068     : KPToolDialog(nullptr)
0069 {
0070     m_serviceName = serviceName;
0071     setWindowTitle(i18n("Export to %1 Web Service", m_serviceName));
0072     setModal(false);
0073 
0074     if (serviceName == QLatin1String("23"))
0075     {
0076         setWindowIcon(QIcon::fromTheme(QString::fromLatin1("kipi-hq")));
0077     }
0078     else
0079     {
0080         setWindowIcon(QIcon::fromTheme(QString::fromLatin1("kipi-flickr")));
0081     }
0082 
0083     KConfig config(QString::fromLatin1("kipirc"));
0084     KConfigGroup grp = config.group(QString::fromLatin1("%1Export Settings").arg(m_serviceName));
0085 
0086     if (grp.exists())
0087     {
0088         qCDebug(KIPIPLUGINS_LOG) << QString::fromLatin1("%1Export Settings").arg(m_serviceName) << " exists, deleting it";
0089         grp.deleteGroup();
0090     }
0091 
0092     m_select                    = dlg;
0093     m_uploadCount               = 0;
0094     m_uploadTotal               = 0;
0095     m_widget                    = new FlickrWidget(this, iface(), serviceName);
0096     m_albumDlg                  = new NewAlbum(this,QString::fromLatin1("Flickr"));
0097     m_albumsListComboBox        = m_widget->getAlbumsCoB();
0098     m_newAlbumBtn               = m_widget->getNewAlbmBtn();
0099     m_originalCheckBox          = m_widget->getOriginalCheckBox();
0100     m_resizeCheckBox            = m_widget->getResizeCheckBox();
0101     m_publicCheckBox            = m_widget->m_publicCheckBox;
0102     m_familyCheckBox            = m_widget->m_familyCheckBox;
0103     m_friendsCheckBox           = m_widget->m_friendsCheckBox;
0104     m_dimensionSpinBox          = m_widget->getDimensionSpB();
0105     m_imageQualitySpinBox       = m_widget->getImgQualitySpB();
0106     m_extendedTagsButton        = m_widget->m_extendedTagsButton;
0107     m_addExtraTagsCheckBox      = m_widget->m_addExtraTagsCheckBox;
0108     m_extendedPublicationButton = m_widget->m_extendedPublicationButton;
0109     m_safetyLevelComboBox       = m_widget->m_safetyLevelComboBox;
0110     m_contentTypeComboBox       = m_widget->m_contentTypeComboBox;
0111     m_tagsLineEdit              = m_widget->m_tagsLineEdit;
0112     m_exportHostTagsCheckBox    = m_widget->m_exportHostTagsCheckBox;
0113     m_stripSpaceTagsCheckBox    = m_widget->m_stripSpaceTagsCheckBox;
0114     m_changeUserButton          = m_widget->getChangeUserBtn();
0115     m_removeAccount             = m_widget->m_removeAccount;
0116     m_userNameDisplayLabel      = m_widget->getUserNameLabel();
0117     m_imglst                    = m_widget->m_imglst;
0118 
0119     startButton()->setText(i18n("Start Uploading"));
0120     startButton()->setToolTip(QString());
0121 
0122     setMainWidget(m_widget);
0123     m_widget->setMinimumSize(800, 600);
0124 
0125     connect(m_imglst, SIGNAL(signalImageListChanged()),
0126             this, SLOT(slotImageListChanged()));
0127 
0128     // --------------------------------------------------------------------------
0129     // About data and help button.
0130 
0131     KPAboutData* const about = new KPAboutData(ki18n("Flickr/23 Export"),
0132                                                ki18n("A tool to export an image collection to a "
0133                                                      "Flickr / 23 web service."),
0134                                                ki18n("(c) 2005-2008, Vardhman Jain\n"
0135                                                      "(c) 2008-2015, Gilles Caulier\n"
0136                                                      "(c) 2009, Luka Renko\n"
0137                                                      "(c) 2015, Shourya Singh Gupta"));
0138 
0139     about->addAuthor(i18n("Vardhman Jain"), i18n("Author and maintainer"),
0140                      QString::fromLatin1("Vardhman at gmail dot com"));
0141 
0142     about->addAuthor(i18n("Gilles Caulier"), i18n("Developer"),
0143                      QString::fromLatin1("caulier dot gilles at gmail dot com"));
0144 
0145     about->addAuthor(i18n("Shourya Singh Gupta"), i18n("Developer"),
0146                      QString::fromLatin1("shouryasgupta at gmail dot com"));
0147 
0148     about->setHandbookEntry(QString::fromLatin1("tool-flickrexport"));
0149     setAboutData(about);
0150 
0151     // --------------------------------------------------------------------------
0152 
0153     m_talker = new FlickrTalker(this, serviceName);
0154 
0155     connect(m_talker, SIGNAL(signalError(QString)),
0156             m_talker, SLOT(slotError(QString)));
0157 
0158     connect(m_talker, SIGNAL(signalBusy(bool)),
0159             this, SLOT(slotBusy(bool)));
0160 
0161     connect(m_talker, SIGNAL(signalAddPhotoSucceeded()),
0162             this, SLOT(slotAddPhotoSucceeded()));
0163 
0164     connect(m_talker, SIGNAL(signalAddPhotoFailed(QString)),
0165             this, SLOT(slotAddPhotoFailed(QString)));
0166 
0167     connect(m_talker, SIGNAL(signalAddPhotoSetSucceeded()),
0168             this, SLOT(slotAddPhotoSetSucceeded()));
0169 
0170     connect(m_talker, SIGNAL(signalListPhotoSetsSucceeded()),
0171             this, SLOT(slotPopulatePhotoSetComboBox()));
0172 
0173     connect(m_talker, SIGNAL(signalListPhotoSetsFailed(QString)),
0174             this, SLOT(slotListPhotoSetsFailed(QString)));
0175 
0176     connect(m_talker, SIGNAL(signalLinkingSucceeded()),
0177             this, SLOT(slotLinkingSucceeded()));
0178 
0179     connect(m_widget->progressBar(), SIGNAL(signalProgressCanceled()),
0180             this, SLOT(slotAddPhotoCancelAndClose()));
0181 
0182     connect(m_widget->getReloadBtn(), SIGNAL(clicked()),
0183             this, SLOT(slotReloadPhotoSetRequest()));
0184 
0185     // --------------------------------------------------------------------------
0186 
0187     connect(m_changeUserButton, SIGNAL(clicked()),
0188             this, SLOT(slotUserChangeRequest()));
0189 
0190     connect(m_removeAccount, SIGNAL(clicked()),
0191             this, SLOT(slotRemoveAccount()));
0192 
0193     connect(m_newAlbumBtn, SIGNAL(clicked()),
0194             this, SLOT(slotCreateNewPhotoSet()));
0195 
0196     // --------------------------------------------------------------------------
0197 
0198     m_authProgressDlg = new QProgressDialog(this);
0199     m_authProgressDlg->setModal(true);
0200     m_authProgressDlg->setAutoReset(true);
0201     m_authProgressDlg->setAutoClose(true);
0202     m_authProgressDlg->setMaximum(0);
0203     m_authProgressDlg->reset();
0204 
0205     connect(m_authProgressDlg, SIGNAL(canceled()),
0206             this, SLOT(slotAuthCancel()));
0207 
0208     m_talker->m_authProgressDlg = m_authProgressDlg;
0209 
0210     // --------------------------------------------------------------------------
0211 
0212     connect(this, &QDialog::finished,
0213             this, &FlickrWindow::slotFinished);
0214 
0215     connect(this, SIGNAL(cancelClicked()),
0216             this, SLOT(slotCancelClicked()));
0217 
0218     connect(startButton(), &QPushButton::clicked,
0219             this, &FlickrWindow::slotUser1);
0220 }
0221 
0222 FlickrWindow::~FlickrWindow()
0223 {
0224     delete m_authProgressDlg;
0225     delete m_talker;
0226     delete m_widget;
0227 }
0228 
0229 void FlickrWindow::closeEvent(QCloseEvent* e)
0230 {
0231     if (!e)
0232     {
0233         return;
0234     }
0235 
0236     slotFinished();
0237     e->accept();
0238 }
0239 
0240 void FlickrWindow::slotFinished()
0241 {
0242     writeSettings();
0243     m_imglst->listView()->clear();
0244 }
0245 
0246 void FlickrWindow::setUiInProgressState(bool inProgress)
0247 {
0248     setRejectButtonMode(inProgress ? QDialogButtonBox::Cancel : QDialogButtonBox::Close);
0249 
0250     if (inProgress)
0251     {
0252         m_widget->progressBar()->show();
0253     }
0254     else
0255     {
0256         m_widget->progressBar()->hide();
0257         m_widget->progressBar()->progressCompleted();
0258     }
0259 }
0260 
0261 void FlickrWindow::slotCancelClicked()
0262 {
0263     m_talker->cancel();
0264     m_uploadQueue.clear();
0265     setUiInProgressState(false);
0266 }
0267 
0268 void FlickrWindow::slotAddPhotoCancelAndClose()
0269 {
0270     writeSettings();
0271     m_imglst->listView()->clear();
0272     m_uploadQueue.clear();
0273     m_widget->progressBar()->reset();
0274     setUiInProgressState(false);
0275     m_talker->cancel();
0276     reject();
0277 }
0278 
0279 void FlickrWindow::reactivate()
0280 {
0281     m_userNameDisplayLabel->setText(QString());
0282     readSettings(m_select->getUname());
0283     m_talker->link(m_select->getUname());
0284 
0285     m_widget->m_imglst->loadImagesFromCurrentSelection();
0286     show();
0287 }
0288 
0289 void FlickrWindow::readSettings(QString uname)
0290 {
0291     KConfig config(QString::fromLatin1("kipirc"));
0292     qCDebug(KIPIPLUGINS_LOG) << "Group name is : "<<QString::fromLatin1("%1%2Export Settings").arg(m_serviceName, uname);
0293     KConfigGroup grp = config.group(QString::fromLatin1("%1%2Export Settings").arg(m_serviceName, uname));
0294     m_exportHostTagsCheckBox->setChecked(grp.readEntry("Export Host Tags",      false));
0295     m_extendedTagsButton->setChecked(grp.readEntry("Show Extended Tag Options", false));
0296     m_addExtraTagsCheckBox->setChecked(grp.readEntry("Add Extra Tags",          false));
0297     m_stripSpaceTagsCheckBox->setChecked(grp.readEntry("Strip Space From Tags", false));
0298     m_stripSpaceTagsCheckBox->setEnabled(m_exportHostTagsCheckBox->isChecked());
0299 
0300     if (!iface()->hasFeature(KIPI::HostSupportsTags))
0301     {
0302         m_exportHostTagsCheckBox->setEnabled(false);
0303         m_stripSpaceTagsCheckBox->setEnabled(false);
0304     }
0305 
0306     m_publicCheckBox->setChecked(grp.readEntry("Public Sharing",                               false));
0307     m_familyCheckBox->setChecked(grp.readEntry("Family Sharing",                               false));
0308     m_friendsCheckBox->setChecked(grp.readEntry("Friends Sharing",                             false));
0309     m_extendedPublicationButton->setChecked(grp.readEntry("Show Extended Publication Options", false));
0310 
0311     int safetyLevel = m_safetyLevelComboBox->findData(QVariant(grp.readEntry("Safety Level", 0)));
0312 
0313     if (safetyLevel == -1)
0314     {
0315         safetyLevel = 0;
0316     }
0317 
0318     m_safetyLevelComboBox->setCurrentIndex(safetyLevel);
0319 
0320     int contentType = m_contentTypeComboBox->findData(QVariant(grp.readEntry("Content Type", 0)));
0321 
0322     if (contentType == -1)
0323     {
0324         contentType = 0;
0325     }
0326 
0327     m_contentTypeComboBox->setCurrentIndex(contentType);
0328 
0329     m_originalCheckBox->setChecked(grp.readEntry("Upload Original", false));
0330     m_resizeCheckBox->setChecked(grp.readEntry("Resize",            false));
0331     m_dimensionSpinBox->setValue(grp.readEntry("Maximum Width",     1600));
0332     m_imageQualitySpinBox->setValue(grp.readEntry("Image Quality",  85));
0333 
0334     winId();
0335     KConfigGroup dialogGroup = config.group(QString::fromLatin1("%1Export Dialog").arg(m_serviceName));
0336     KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup);
0337     resize(windowHandle()->size());
0338 }
0339 
0340 void FlickrWindow::writeSettings()
0341 {
0342     KConfig config(QString::fromLatin1("kipirc"));
0343     qCDebug(KIPIPLUGINS_LOG) << "Group name is : "<<QString::fromLatin1("%1%2Export Settings").arg(m_serviceName,m_username);
0344 
0345     if (QString::compare(QString::fromLatin1("%1Export Settings").arg(m_serviceName),
0346         QString::fromLatin1("%1%2Export Settings").arg(m_serviceName, m_username), Qt::CaseInsensitive) == 0)
0347     {
0348         qCDebug(KIPIPLUGINS_LOG) << "Not writing entry of group " << QString::fromLatin1("%1%2Export Settings").arg(m_serviceName,m_username);
0349         return;
0350     }
0351 
0352     KConfigGroup grp = config.group(QString::fromLatin1("%1%2Export Settings").arg(m_serviceName, m_username));
0353     grp.writeEntry("username",                          m_username);
0354     grp.writeEntry("Export Host Tags",                  m_exportHostTagsCheckBox->isChecked());
0355     grp.writeEntry("Show Extended Tag Options",         m_extendedTagsButton->isChecked());
0356     grp.writeEntry("Add Extra Tags",                    m_addExtraTagsCheckBox->isChecked());
0357     grp.writeEntry("Strip Space From Tags",             m_stripSpaceTagsCheckBox->isChecked());
0358     grp.writeEntry("Public Sharing",                    m_publicCheckBox->isChecked());
0359     grp.writeEntry("Family Sharing",                    m_familyCheckBox->isChecked());
0360     grp.writeEntry("Friends Sharing",                   m_friendsCheckBox->isChecked());
0361     grp.writeEntry("Show Extended Publication Options", m_extendedPublicationButton->isChecked());
0362     int safetyLevel = m_safetyLevelComboBox->itemData(m_safetyLevelComboBox->currentIndex()).toInt();
0363     grp.writeEntry("Safety Level",                      safetyLevel);
0364     int contentType = m_contentTypeComboBox->itemData(m_contentTypeComboBox->currentIndex()).toInt();
0365     grp.writeEntry("Content Type",                      contentType);
0366     grp.writeEntry("Resize",                            m_resizeCheckBox->isChecked());
0367     grp.writeEntry("Upload Original",                   m_originalCheckBox->isChecked());
0368     grp.writeEntry("Maximum Width",                     m_dimensionSpinBox->value());
0369     grp.writeEntry("Image Quality",                     m_imageQualitySpinBox->value());
0370     KConfigGroup dialogGroup = config.group(QString::fromLatin1("%1Export Dialog").arg(m_serviceName));
0371     KWindowConfig::saveWindowSize(windowHandle(), dialogGroup);
0372     config.sync();
0373 }
0374 
0375 void FlickrWindow::slotLinkingSucceeded()
0376 {
0377     m_username = m_talker->getUserName();
0378     m_userId   = m_talker->getUserId();
0379     qCDebug(KIPIPLUGINS_LOG) << "SlotLinkingSucceeded invoked setting user Display name to " << m_username;
0380     m_userNameDisplayLabel->setText(QString::fromLatin1("<b>%1</b>").arg(m_username));
0381 
0382     KConfig config(QString::fromLatin1("kipirc"));
0383 
0384     foreach(const QString& group, config.groupList())
0385     {
0386         if (!(group.contains(m_serviceName)))
0387             continue;
0388 
0389         KConfigGroup grp = config.group(group);
0390 
0391         if (group.contains(m_username))
0392         {
0393             readSettings(m_username);
0394             break;
0395         }
0396     }
0397 
0398     writeSettings();
0399     m_talker->listPhotoSets();
0400 }
0401 
0402 void FlickrWindow::slotBusy(bool val)
0403 {
0404     if (val)
0405     {
0406         setCursor(Qt::WaitCursor);
0407     }
0408     else
0409     {
0410         setCursor(Qt::ArrowCursor);
0411     }
0412 }
0413 
0414 void FlickrWindow::slotError(const QString& msg)
0415 {
0416     QMessageBox::critical(this, i18n("Error"), msg);
0417 }
0418 
0419 void FlickrWindow::slotUserChangeRequest()
0420 {
0421     writeSettings();
0422     m_userNameDisplayLabel->setText(QString());
0423     qCDebug(KIPIPLUGINS_LOG) << "Slot Change User Request ";
0424     m_select->reactivate();
0425     readSettings(m_select->getUname());
0426 
0427     m_talker->link(m_select->getUname());
0428 }
0429 
0430 void FlickrWindow::slotRemoveAccount()
0431 {
0432     KConfig config(QString::fromLatin1("kipirc"));
0433     KConfigGroup grp = config.group(QString::fromLatin1("%1%2Export Settings").arg(m_serviceName).arg(m_username));
0434 
0435     if (grp.exists())
0436     {
0437         qCDebug(KIPIPLUGINS_LOG) << "Removing Account having group"<<QString::fromLatin1("%1%2Export Settings").arg(m_serviceName);
0438         grp.deleteGroup();
0439     }
0440 
0441     m_talker->unLink();
0442     m_talker->removeUserName(m_serviceName + m_username);
0443 
0444     m_userNameDisplayLabel->setText(QString());
0445     m_username = QString();
0446 }
0447 
0448 /**
0449  * Try to guess a sensible set name from the urls given.
0450  * Currently, it extracs the last path name component, and returns the most
0451  * frequently seen. The function could be expanded to, for example, only
0452  * accept the path if it occurs at least 50% of the time. It could also look
0453  * further up in the path name.
0454  */
0455 QString FlickrWindow::guessSensibleSetName(const QList<QUrl>& urlList)
0456 {
0457     QMap<QString,int> nrFolderOccurences;
0458 
0459     // Extract last component of directory
0460     foreach(const QUrl& url, urlList)
0461     {
0462         QString dir      = url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile();
0463         QStringList list = dir.split(QLatin1Char('/'));
0464 
0465         if (list.isEmpty())
0466             continue;
0467 
0468         nrFolderOccurences[list.last()]++;
0469     }
0470 
0471     int maxCount   = 0;
0472     int totalCount = 0;
0473     QString name;
0474 
0475     for (QMap<QString,int>::const_iterator it=nrFolderOccurences.constBegin();
0476          it != nrFolderOccurences.constEnd() ; ++it)
0477     {
0478         totalCount += it.value();
0479 
0480         if (it.value() > maxCount)
0481         {
0482             maxCount = it.value();
0483             name     = it.key();
0484         }
0485     }
0486 
0487     // If there is only one entry or one name appears at least twice, return the suggestion
0488     if (totalCount == 1 || maxCount > 1)
0489         return name;
0490 
0491     return QString();
0492 }
0493 
0494 /** This method is called when the photo set creation button is pressed. It
0495  * summons a creation dialog for user input. When that is closed, it
0496  * creates a new photo set in the local list. The id gets the form of
0497  * UNDEFINED_ followed by a number, to indicate that it doesn't exist on
0498  * Flickr yet.
0499  */
0500 void FlickrWindow::slotCreateNewPhotoSet()
0501 {
0502     if (m_albumDlg->exec() == QDialog::Accepted)
0503     {
0504         FPhotoSet fps;
0505         m_albumDlg->getFolderProperties(fps);
0506         qCDebug(KIPIPLUGINS_LOG) << "in slotCreateNewPhotoSet() " << fps.title;
0507 
0508         // Lets find an UNDEFINED_ style id that isn't taken yet.s
0509         QString id;
0510         int i                               = 0;
0511         id                                  = QString::fromLatin1("UNDEFINED_") + QString::number(i);
0512         QLinkedList<FPhotoSet>::iterator it = m_talker->m_photoSetsList->begin();
0513 
0514         while (it != m_talker->m_photoSetsList->end())
0515         {
0516             FPhotoSet fps = *it;
0517 
0518             if (fps.id == id)
0519             {
0520                 id = QString::fromLatin1("UNDEFINED_") + QString::number(++i);
0521                 it = m_talker->m_photoSetsList->begin();
0522             }
0523 
0524             ++it;
0525         }
0526 
0527         fps.id = id;
0528 
0529         qCDebug(KIPIPLUGINS_LOG) << "Created new photoset with temporary id " << id;
0530         // Append the new photoset to the list.
0531         m_talker->m_photoSetsList->prepend(fps);
0532         m_talker->m_selectedPhotoSet = fps;
0533 
0534         // Re-populate the photo sets combo box.
0535         slotPopulatePhotoSetComboBox();
0536     }
0537     else
0538     {
0539         qCDebug(KIPIPLUGINS_LOG) << "New Photoset creation aborted ";
0540     }
0541 }
0542 
0543 void FlickrWindow::slotAuthCancel()
0544 {
0545     m_talker->cancel();
0546     m_authProgressDlg->hide();
0547 }
0548 
0549 void FlickrWindow::slotPopulatePhotoSetComboBox()
0550 {
0551     qCDebug(KIPIPLUGINS_LOG) << "slotPopulatePhotoSetComboBox invoked";
0552 
0553     if (m_talker && m_talker->m_photoSetsList)
0554     {
0555         QLinkedList <FPhotoSet>* const list = m_talker->m_photoSetsList;
0556         m_albumsListComboBox->clear();
0557         m_albumsListComboBox->insertItem(0, i18n("Photostream Only"));
0558         m_albumsListComboBox->insertSeparator(1);
0559         QLinkedList<FPhotoSet>::iterator it = list->begin();
0560         int index = 2, curr_index = 0;
0561 
0562         while (it != list->end())
0563         {
0564             FPhotoSet photoSet = *it;
0565             QString name       = photoSet.title;
0566             // Store the id as user data, because the title is not unique.
0567             QVariant id        = QVariant(photoSet.id);
0568 
0569             if (id == m_talker->m_selectedPhotoSet.id)
0570             {
0571                 curr_index = index;
0572             }
0573 
0574             m_albumsListComboBox->insertItem(index++, name, id);
0575             ++it;
0576         }
0577 
0578         m_albumsListComboBox->setCurrentIndex(curr_index);
0579     }
0580 }
0581 
0582 /** This slot is call when 'Start Uploading' button is pressed.
0583 */
0584 void FlickrWindow::slotUser1()
0585 {
0586     qCDebug(KIPIPLUGINS_LOG) << "SlotUploadImages invoked";
0587 
0588     //m_widget->m_tab->setCurrentIndex(FlickrWidget::FILELIST);
0589 
0590     if (m_imglst->imageUrls().isEmpty())
0591     {
0592         return;
0593     }
0594 
0595     typedef QPair<QUrl, FPhotoInfo> Pair;
0596 
0597     m_uploadQueue.clear();
0598 
0599     for (int i = 0; i < m_imglst->listView()->topLevelItemCount(); ++i)
0600     {
0601         FlickrListViewItem* const lvItem = dynamic_cast<FlickrListViewItem*>(m_imglst->listView()->topLevelItem(i));
0602 
0603         if (lvItem)
0604         {
0605             KPImageInfo info(lvItem->url());
0606             qCDebug(KIPIPLUGINS_LOG) << "Adding images"<<lvItem->url()<<" to the list";
0607             FPhotoInfo temp;
0608 
0609             temp.title                 = info.title();
0610             temp.description           = info.description();
0611             temp.size                  = info.fileSize();
0612             temp.is_public             = lvItem->isPublic()  ? 1 : 0;
0613             temp.is_family             = lvItem->isFamily()  ? 1 : 0;
0614             temp.is_friend             = lvItem->isFriends() ? 1 : 0;
0615             temp.safety_level          = lvItem->safetyLevel();
0616             temp.content_type          = lvItem->contentType();
0617             QStringList tagsFromDialog = m_tagsLineEdit->text().split(QLatin1Char(','), Qt::SkipEmptyParts);
0618             QStringList tagsFromList   = lvItem->extraTags();
0619 
0620             QStringList           allTags;
0621             QStringList::Iterator itTags;
0622 
0623             // Tags from the dialog
0624             itTags = tagsFromDialog.begin();
0625 
0626             while (itTags != tagsFromDialog.end())
0627             {
0628                 allTags.append(*itTags);
0629                 ++itTags;
0630             }
0631 
0632             // Tags from the database
0633             if (m_exportHostTagsCheckBox->isChecked())
0634             {
0635                 QStringList tagsFromDatabase;
0636 
0637                 tagsFromDatabase = info.keywords();
0638                 itTags           = tagsFromDatabase.begin();
0639 
0640                 while (itTags != tagsFromDatabase.end())
0641                 {
0642                     allTags.append(*itTags);
0643                     ++itTags;
0644                 }
0645             }
0646 
0647             // Tags from the list view.
0648             itTags = tagsFromList.begin();
0649 
0650             while (itTags != tagsFromList.end())
0651             {
0652                 allTags.append(*itTags);
0653                 ++itTags;
0654             }
0655 
0656             // Remove spaces if the user doesn't like them.
0657             if (m_stripSpaceTagsCheckBox->isChecked())
0658             {
0659                 for (QStringList::iterator it = allTags.begin();
0660                     it != allTags.end();
0661                     ++it)
0662                 {
0663                     *it = (*it).trimmed().remove(QLatin1Char(' '));
0664                 }
0665             }
0666 
0667             // Debug the tag list.
0668             itTags = allTags.begin();
0669 
0670             while (itTags != allTags.end())
0671             {
0672                 qCDebug(KIPIPLUGINS_LOG) << "Tags list: " << (*itTags);
0673                 ++itTags;
0674             }
0675 
0676             temp.tags = allTags;
0677             m_uploadQueue.append(Pair(lvItem->url(), temp));
0678         }
0679     }
0680 
0681     m_uploadTotal = m_uploadQueue.count();
0682     m_uploadCount = 0;
0683     m_widget->progressBar()->reset();
0684     slotAddPhotoNext();
0685     qCDebug(KIPIPLUGINS_LOG) << "SlotUploadImages done";
0686 }
0687 
0688 void FlickrWindow::slotAddPhotoNext()
0689 {
0690     if (m_uploadQueue.isEmpty())
0691     {
0692         m_widget->progressBar()->reset();
0693         setUiInProgressState(false);
0694         return;
0695     }
0696 
0697     typedef QPair<QUrl, FPhotoInfo> Pair;
0698     Pair pathComments = m_uploadQueue.first();
0699     FPhotoInfo info   = pathComments.second;
0700 
0701     QString selectedPhotoSetId = m_albumsListComboBox->itemData(m_albumsListComboBox->currentIndex()).toString();
0702 
0703     if (selectedPhotoSetId.isEmpty())
0704     {
0705         m_talker->m_selectedPhotoSet = FPhotoSet();
0706     }
0707     else
0708     {
0709         QLinkedList<FPhotoSet>::iterator it = m_talker->m_photoSetsList->begin();
0710 
0711         while (it != m_talker->m_photoSetsList->end())
0712         {
0713             if (it->id == selectedPhotoSetId)
0714             {
0715                 m_talker->m_selectedPhotoSet = *it;
0716                 break;
0717             }
0718 
0719             ++it;
0720         }
0721     }
0722 
0723     qCDebug(KIPIPLUGINS_LOG) << "Max allowed file size is : "<<((m_talker->getMaxAllowedFileSize()).toLongLong())<<"File Size is "<<info.size;
0724 
0725     bool res = m_talker->addPhoto(pathComments.first.toLocalFile(), //the file path
0726                                   info,
0727                                   m_originalCheckBox->isChecked(),
0728                                   m_resizeCheckBox->isChecked(),
0729                                   m_dimensionSpinBox->value(),
0730                                   m_imageQualitySpinBox->value());
0731 
0732     if (!res)
0733     {
0734         slotAddPhotoFailed(QString::fromLatin1(""));
0735         return;
0736     }
0737 
0738     if (m_widget->progressBar()->isHidden())
0739     {
0740         setUiInProgressState(true);
0741         m_widget->progressBar()->progressScheduled(i18n("Flickr Export"), true, true);
0742         m_widget->progressBar()->progressThumbnailChanged(QIcon(QLatin1String(":/icons/kipi-icon.svg")).pixmap(22, 22));
0743     }
0744 }
0745 
0746 void FlickrWindow::slotAddPhotoSucceeded()
0747 {
0748     // Remove photo uploaded from the list
0749     m_imglst->removeItemByUrl(m_uploadQueue.first().first);
0750     m_uploadQueue.pop_front();
0751     m_uploadCount++;
0752     m_widget->progressBar()->setMaximum(m_uploadTotal);
0753     m_widget->progressBar()->setValue(m_uploadCount);
0754     slotAddPhotoNext();
0755 }
0756 
0757 void FlickrWindow::slotListPhotoSetsFailed(const QString& msg)
0758 {
0759     QMessageBox::critical(this, QString::fromLatin1("Error"), i18n("Failed to Fetch Photoset information from %1. %2\n", m_serviceName, msg));
0760 }
0761 
0762 void FlickrWindow::slotAddPhotoFailed(const QString& msg)
0763 {
0764     QMessageBox warn(QMessageBox::Warning,
0765                      i18n("Warning"),
0766                      i18n("Failed to upload photo into %1. %2\nDo you want to continue?", m_serviceName, msg),
0767                      QMessageBox::Yes | QMessageBox::No);
0768 
0769     (warn.button(QMessageBox::Yes))->setText(i18n("Continue"));
0770     (warn.button(QMessageBox::No))->setText(i18n("Cancel"));
0771 
0772     if (warn.exec() != QMessageBox::Yes)
0773     {
0774         m_uploadQueue.clear();
0775         m_widget->progressBar()->reset();
0776         setUiInProgressState(false);
0777     }
0778     else
0779     {
0780         m_uploadQueue.pop_front();
0781         m_uploadTotal--;
0782         m_widget->progressBar()->setMaximum(m_uploadTotal);
0783         m_widget->progressBar()->setValue(m_uploadCount);
0784         slotAddPhotoNext();
0785     }
0786 }
0787 
0788 void FlickrWindow::slotAddPhotoSetSucceeded()
0789 {
0790     /* Method called when a photo set has been successfully created on Flickr.
0791      * It functions to restart the normal flow after a photo set has been created
0792      * on Flickr. */
0793     slotPopulatePhotoSetComboBox();
0794     slotAddPhotoSucceeded();
0795 }
0796 
0797 void FlickrWindow::slotImageListChanged()
0798 {
0799     startButton()->setEnabled(!(m_widget->m_imglst->imageUrls().isEmpty()));
0800 }
0801 
0802 void FlickrWindow::slotReloadPhotoSetRequest()
0803 {
0804     m_talker->listPhotoSets();
0805 }
0806 
0807 } // namespace KIPIFlickrPlugin