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