File indexing completed on 2025-01-05 03:53:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-09-30 0007 * Description : a tool to export items to Piwigo web service 0008 * 0009 * SPDX-FileCopyrightText: 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006 by Colin Guthrie <kde at colin dot guthr dot ie> 0011 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 * SPDX-FileCopyrightText: 2008 by Andrea Diamantini <adjam7 at gmail dot com> 0013 * SPDX-FileCopyrightText: 2010-2014 by Frederic Coiffier <frederic dot coiffier at free dot com> 0014 * 0015 * SPDX-License-Identifier: GPL-2.0-or-later 0016 * 0017 * ============================================================ */ 0018 0019 #include "piwigowindow.h" 0020 0021 // Qt includes 0022 0023 #include <QCheckBox> 0024 #include <QDialog> 0025 #include <QFileInfo> 0026 #include <QBuffer> 0027 #include <QImage> 0028 #include <QGroupBox> 0029 #include <QPushButton> 0030 #include <QSpinBox> 0031 #include <QTreeWidgetItem> 0032 #include <QPointer> 0033 #include <QHBoxLayout> 0034 #include <QVBoxLayout> 0035 #include <QTextStream> 0036 #include <QFile> 0037 #include <QApplication> 0038 #include <QIcon> 0039 #include <QMenu> 0040 #include <QMessageBox> 0041 #include <QLabel> 0042 0043 // KDE includes 0044 0045 #include <klocalizedstring.h> 0046 #include <ksharedconfig.h> 0047 #include <kconfiggroup.h> 0048 0049 // Local includes 0050 0051 #include "digikam_debug.h" 0052 #include "piwigosession.h" 0053 #include "piwigologindlg.h" 0054 #include "piwigotalker.h" 0055 #include "imagedialog.h" 0056 #include "ditemslist.h" 0057 #include "dprogresswdg.h" 0058 0059 namespace DigikamGenericPiwigoPlugin 0060 { 0061 0062 class Q_DECL_HIDDEN PiwigoWindow::Private 0063 { 0064 public: 0065 0066 explicit Private(PiwigoWindow* const parent, 0067 DInfoInterface* const interface); 0068 0069 QWidget* widget; 0070 0071 QTreeWidget* albumView; 0072 0073 QPushButton* confButton; 0074 QPushButton* reloadButton; 0075 0076 QCheckBox* resizeCheckBox; 0077 QSpinBox* widthSpinBox; 0078 QSpinBox* heightSpinBox; 0079 QSpinBox* qualitySpinBox; 0080 0081 QHash<QString, PiwigoAlbum> albumDict; 0082 0083 PiwigoTalker* talker; 0084 PiwigoSession* pPiwigo; 0085 DInfoInterface* iface; 0086 DItemsList* imageList; 0087 DProgressWdg* progressBar; 0088 0089 unsigned int uploadCount; 0090 unsigned int uploadTotal; 0091 QStringList pUploadList; 0092 QString currPhotoPath; 0093 0094 QLabel* userNameLbl; 0095 QLabel* userName; 0096 QLabel* urlLbl; 0097 QLabel* url; 0098 }; 0099 0100 PiwigoWindow::Private::Private(PiwigoWindow* const parent, 0101 DInfoInterface* const interface) 0102 : widget (new QWidget(parent)), 0103 albumView (nullptr), 0104 confButton (nullptr), 0105 reloadButton (nullptr), 0106 resizeCheckBox(nullptr), 0107 widthSpinBox (nullptr), 0108 heightSpinBox (nullptr), 0109 qualitySpinBox(nullptr), 0110 talker (nullptr), 0111 pPiwigo (nullptr), 0112 iface (interface), 0113 imageList (nullptr), 0114 progressBar (nullptr), 0115 uploadCount (0), 0116 uploadTotal (0), 0117 userNameLbl (nullptr), 0118 userName (nullptr), 0119 urlLbl (nullptr), 0120 url (nullptr) 0121 { 0122 parent->setMainWidget(widget); 0123 parent->setModal(false); 0124 0125 QHBoxLayout* const hlay = new QHBoxLayout(widget); 0126 0127 // --------------------------------------------------------------------------- 0128 0129 QLabel* const logo = new QLabel(); 0130 logo->setContentsMargins(QMargins()); 0131 logo->setScaledContents(false); 0132 logo->setOpenExternalLinks(true); 0133 logo->setTextFormat(Qt::RichText); 0134 logo->setFocusPolicy(Qt::NoFocus); 0135 logo->setTextInteractionFlags(Qt::LinksAccessibleByMouse); 0136 logo->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); 0137 logo->setToolTip(i18n("Visit Piwigo website")); 0138 logo->setAlignment(Qt::AlignLeft); 0139 QImage img = QImage(QStandardPaths::locate(QStandardPaths::GenericDataLocation, 0140 QLatin1String("digikam/data/logo-piwigo.png"))); 0141 0142 QByteArray byteArray; 0143 QBuffer buffer(&byteArray); 0144 img.save(&buffer, "PNG"); 0145 logo->setText(QString::fromLatin1("<a href=\"%1\">%2</a>") 0146 .arg(QLatin1String("https://piwigo.org")) 0147 .arg(QString::fromLatin1("<img src=\"data:image/png;base64,%1\">") 0148 .arg(QLatin1String(byteArray.toBase64().data())))); 0149 0150 // --------------------------------------------------------------------------- 0151 0152 imageList = new DItemsList(nullptr); 0153 imageList->setObjectName(QLatin1String("Piwigo ImagesList")); 0154 imageList->setIface(iface); 0155 imageList->listView()->clear(); 0156 imageList->loadImagesFromCurrentSelection(); 0157 0158 progressBar = new DProgressWdg(imageList); 0159 progressBar->setMaximum(0); 0160 progressBar->reset(); 0161 imageList->appendControlButtonsWidget(progressBar); 0162 QBoxLayout* const blay = imageList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow); 0163 blay->setStretchFactor(progressBar, 20); 0164 progressBar->hide(); 0165 0166 // --------------------------------------------------------------------------- 0167 0168 albumView = new QTreeWidget; 0169 QStringList labels; 0170 labels << i18n("Remote Albums"); 0171 albumView->setHeaderLabels(labels); 0172 albumView->setSortingEnabled(true); 0173 albumView->sortByColumn(0, Qt::AscendingOrder); 0174 0175 reloadButton = new QPushButton(); 0176 reloadButton->setText(i18nc("reload album list", "Reload")); 0177 reloadButton->setIcon(QIcon::fromTheme(QLatin1String("view-refresh"))); 0178 reloadButton->setToolTip(i18n("Reload album list")); 0179 reloadButton->setEnabled(false); 0180 0181 // --------------------------------------------------------------------------- 0182 0183 QFrame* const optionFrame = new QFrame; 0184 QVBoxLayout* const vlay = new QVBoxLayout(); 0185 0186 userNameLbl = new QLabel(i18nc("piwigo account settings", "Name:"), optionFrame); 0187 userName = new QLabel(optionFrame); 0188 urlLbl = new QLabel(i18nc("piwigo url settings", "Url:"), optionFrame); 0189 url = new QLabel(optionFrame); 0190 url->setOpenExternalLinks(true); 0191 url->setFocusPolicy(Qt::NoFocus); 0192 0193 confButton = new QPushButton; 0194 confButton->setText(i18n("Change Account")); 0195 confButton->setIcon(QIcon::fromTheme(QLatin1String("system-switch-user"))); 0196 confButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0197 0198 QGroupBox* const optionsBox = new QGroupBox(i18n("Options")); 0199 QVBoxLayout* const vlay2 = new QVBoxLayout(); 0200 0201 resizeCheckBox = new QCheckBox(optionsBox); 0202 resizeCheckBox->setText(i18n("Resize photos before uploading")); 0203 0204 QGridLayout* const glay = new QGridLayout; 0205 QLabel* const widthLabel = new QLabel(i18n("Maximum width:")); 0206 0207 widthSpinBox = new QSpinBox; 0208 widthSpinBox->setRange(1,8000); 0209 widthSpinBox->setValue(1600); 0210 0211 QLabel* const heightLabel = new QLabel(i18n("Maximum height:")); 0212 0213 heightSpinBox = new QSpinBox; 0214 heightSpinBox->setRange(1,8000); 0215 heightSpinBox->setValue(1600); 0216 0217 QLabel* const qualityLabel = new QLabel(i18n("Resized JPEG quality:")); 0218 0219 qualitySpinBox = new QSpinBox; 0220 qualitySpinBox->setRange(1,100); 0221 qualitySpinBox->setValue(95); 0222 0223 resizeCheckBox->setChecked(false); 0224 widthSpinBox->setEnabled(false); 0225 heightSpinBox->setEnabled(false); 0226 qualitySpinBox->setEnabled(false); 0227 0228 // --------------------------------------------------------------------------- 0229 0230 glay->addWidget(widthLabel, 0, 0); 0231 glay->addWidget(widthSpinBox, 0, 1); 0232 glay->addWidget(heightLabel, 1, 0); 0233 glay->addWidget(heightSpinBox, 1, 1); 0234 glay->addWidget(qualityLabel, 2, 0); 0235 glay->addWidget(qualitySpinBox, 2, 1); 0236 0237 // --------------------------------------------------------------------------- 0238 0239 vlay2->addWidget(resizeCheckBox); 0240 vlay2->addLayout(glay); 0241 vlay2->addStretch(0); 0242 0243 optionsBox->setLayout(vlay2); 0244 0245 // --------------------------------------------------------------------------- 0246 0247 vlay->addWidget(logo); 0248 vlay->addWidget(userNameLbl); 0249 vlay->addWidget(userName); 0250 vlay->addWidget(urlLbl); 0251 vlay->addWidget(url); 0252 vlay->addWidget(confButton); 0253 vlay->addWidget(albumView); 0254 vlay->addWidget(reloadButton); 0255 vlay->addWidget(optionsBox); 0256 0257 optionFrame->setLayout(vlay); 0258 0259 // --------------------------------------------------------------------------- 0260 0261 hlay->addWidget(imageList); 0262 hlay->addWidget(optionFrame); 0263 0264 widget->setLayout(hlay); 0265 } 0266 0267 // --------------------------------------------------------------------------- 0268 0269 PiwigoWindow::PiwigoWindow(DInfoInterface* const iface, 0270 QWidget* const /*parent*/) 0271 : WSToolDialog(nullptr, QLatin1String("PiwigoSync Dialog")), 0272 d (new Private(this, iface)) 0273 { 0274 d->pPiwigo = new PiwigoSession(); 0275 0276 setWindowTitle(i18nc("@title:window", "Piwigo Export")); 0277 setModal(false); 0278 0279 // "Start Upload" button 0280 0281 startButton()->setText(i18nc("@action:button", "Start Upload")); 0282 startButton()->setEnabled(false); 0283 0284 connect(startButton(), SIGNAL(clicked()), 0285 this, SLOT(slotAddPhoto())); 0286 0287 // we need to let d->talker work.. 0288 0289 d->talker = new PiwigoTalker(iface, d->widget); 0290 0291 // connect functions 0292 0293 connectSignals(); 0294 0295 KSharedConfigPtr config = KSharedConfig::openConfig(); 0296 0297 if (!config->hasGroup(QLatin1String("Piwigo Settings"))) 0298 { 0299 QPointer<PiwigoLoginDlg> dlg = new PiwigoLoginDlg(QApplication::activeWindow(), 0300 d->pPiwigo, i18n("Edit Piwigo Data")); 0301 dlg->exec(); 0302 delete dlg; 0303 } 0304 0305 readSettings(); 0306 slotDoLogin(); 0307 } 0308 0309 PiwigoWindow::~PiwigoWindow() 0310 { 0311 // write config 0312 0313 KSharedConfigPtr config = KSharedConfig::openConfig(); 0314 KConfigGroup group = config->group(QLatin1String("PiwigoSync Galleries")); 0315 0316 group.writeEntry("Resize", d->resizeCheckBox->isChecked()); 0317 group.writeEntry("Maximum Width", d->widthSpinBox->value()); 0318 group.writeEntry("Maximum Height", d->heightSpinBox->value()); 0319 group.writeEntry("Quality", d->qualitySpinBox->value()); 0320 0321 delete d->talker; 0322 delete d->pPiwigo; 0323 delete d; 0324 } 0325 0326 void PiwigoWindow::connectSignals() 0327 { 0328 connect(d->albumView, SIGNAL(itemSelectionChanged()), 0329 this, SLOT(slotAlbumSelected())); 0330 0331 connect(d->confButton, SIGNAL(clicked()), 0332 this, SLOT(slotSettings())); 0333 0334 connect(d->reloadButton, SIGNAL(clicked()), 0335 this, SLOT(slotReloadAlbums())); 0336 0337 connect(d->resizeCheckBox, SIGNAL(stateChanged(int)), 0338 this, SLOT(slotEnableSpinBox(int))); 0339 0340 connect(d->progressBar, SIGNAL(signalProgressCanceled()), 0341 this, SLOT(slotAddPhotoCancel())); 0342 0343 connect(d->talker, SIGNAL(signalProgressInfo(QString)), 0344 this, SLOT(slotProgressInfo(QString))); 0345 0346 connect(d->talker, SIGNAL(signalError(QString)), 0347 this, SLOT(slotError(QString))); 0348 0349 connect(d->talker, SIGNAL(signalBusy(bool)), 0350 this, SLOT(slotBusy(bool))); 0351 0352 connect(d->talker, SIGNAL(signalLoginFailed(QString)), 0353 this, SLOT(slotLoginFailed(QString))); 0354 0355 connect(d->talker, SIGNAL(signalAlbums(QList<PiwigoAlbum>)), 0356 this, SLOT(slotAlbums(QList<PiwigoAlbum>))); 0357 0358 connect(d->talker, SIGNAL(signalAddPhotoSucceeded()), 0359 this, SLOT(slotAddPhotoSucceeded())); 0360 0361 connect(d->talker, SIGNAL(signalAddPhotoFailed(QString)), 0362 this, SLOT(slotAddPhotoFailed(QString))); 0363 } 0364 0365 void PiwigoWindow::readSettings() 0366 { 0367 KSharedConfigPtr config = KSharedConfig::openConfig(); 0368 KConfigGroup group = config->group(QLatin1String("PiwigoSync Galleries")); 0369 0370 if (group.readEntry("Resize", false)) 0371 { 0372 d->resizeCheckBox->setChecked(true); 0373 d->widthSpinBox->setEnabled(true); 0374 d->heightSpinBox->setEnabled(true); 0375 } 0376 else 0377 { 0378 d->resizeCheckBox->setChecked(false); 0379 d->heightSpinBox->setEnabled(false); 0380 d->widthSpinBox->setEnabled(false); 0381 } 0382 0383 d->widthSpinBox->setValue(group.readEntry("Maximum Width", 1600)); 0384 d->heightSpinBox->setValue(group.readEntry("Maximum Height", 1600)); 0385 d->qualitySpinBox->setValue(group.readEntry("Quality", 95)); 0386 } 0387 0388 void PiwigoWindow::slotReloadAlbums() 0389 { 0390 d->talker->listAlbums(); 0391 } 0392 0393 void PiwigoWindow::slotDoLogin() 0394 { 0395 QUrl url(d->pPiwigo->url()); 0396 0397 if (url.scheme().isEmpty()) 0398 { 0399 url.setScheme(QLatin1String("http")); 0400 url.setHost(d->pPiwigo->url()); 0401 } 0402 0403 // If we've done something clever, save it back to the piwigo. 0404 0405 if (!url.url().isEmpty() && (d->pPiwigo->url() != url.url())) 0406 { 0407 d->pPiwigo->setUrl(url.url()); 0408 d->pPiwigo->save(); 0409 } 0410 0411 d->talker->login(url, d->pPiwigo->username(), d->pPiwigo->password()); 0412 0413 d->userName->setText(QString::fromLatin1("<b>%1</b>").arg(d->pPiwigo->username())); 0414 d->url->setText(QString::fromLatin1( 0415 "<b><a href='%1'>" 0416 "<font color=\"#9ACD32\">%2</font>" 0417 "</a></b>") 0418 .arg(url.url()) 0419 .arg(url.toDisplayString()) 0420 ); 0421 } 0422 0423 void PiwigoWindow::slotLoginFailed(const QString& msg) 0424 { 0425 if (QMessageBox::question(this, i18nc("@title:window", "Login Failed"), 0426 i18n("Failed to login into remote piwigo. ") + msg + 0427 i18n("\nDo you want to check your settings and try again?")) 0428 != QMessageBox::Yes) 0429 { 0430 close(); 0431 return; 0432 } 0433 0434 QPointer<PiwigoLoginDlg> dlg = new PiwigoLoginDlg(QApplication::activeWindow(), 0435 d->pPiwigo, i18n("Edit Piwigo Data")); 0436 0437 int result = dlg->exec(); 0438 delete dlg; 0439 0440 if (result != QDialog::Accepted) 0441 { 0442 return; 0443 } 0444 0445 slotDoLogin(); 0446 } 0447 0448 void PiwigoWindow::slotBusy(bool val) 0449 { 0450 if (val) 0451 { 0452 setCursor(Qt::WaitCursor); 0453 startButton()->setEnabled(false); 0454 d->reloadButton->setEnabled(false); 0455 } 0456 else 0457 { 0458 setCursor(Qt::ArrowCursor); 0459 bool loggedIn = d->talker->loggedIn(); 0460 d->reloadButton->setEnabled(loggedIn); 0461 0462 bool b = (loggedIn && d->albumView->currentItem()); 0463 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "busy : " << b; 0464 startButton()->setEnabled(b); 0465 } 0466 } 0467 0468 void PiwigoWindow::slotProgressInfo(const QString& msg) 0469 { 0470 d->progressBar->progressStatusChanged(msg); 0471 } 0472 0473 void PiwigoWindow::slotError(const QString& msg) 0474 { 0475 setUiInProgressState(false); 0476 QMessageBox::critical(this, QString(), msg); 0477 } 0478 0479 void PiwigoWindow::slotAlbums(const QList<PiwigoAlbum>& albumList) 0480 { 0481 d->albumDict.clear(); 0482 d->albumView->clear(); 0483 0484 // album work list 0485 0486 QList<PiwigoAlbum> workList(albumList); 0487 QList<QTreeWidgetItem*> parentItemList; 0488 0489 // fill QTreeWidget 0490 0491 while (!workList.isEmpty()) 0492 { 0493 // the album to work on 0494 0495 PiwigoAlbum album = workList.takeFirst(); 0496 int parentRefNum = album.m_parentRefNum; 0497 0498 if (parentRefNum == -1) 0499 { 0500 QTreeWidgetItem* const item = new QTreeWidgetItem(); 0501 item->setText(0, cleanName(album.m_name)); 0502 item->setIcon(0, QIcon::fromTheme(QLatin1String("inode-directory"))); 0503 item->setData(1, Qt::UserRole, QVariant(album.m_refNum)); 0504 item->setText(2, i18n("Album")); 0505 0506 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Top : " << album.m_name << " " << album.m_refNum << "\n"; 0507 0508 d->albumView->addTopLevelItem(item); 0509 d->albumDict.insert(album.m_name, album); 0510 parentItemList << item; 0511 } 0512 else 0513 { 0514 QTreeWidgetItem* parentItem = nullptr; 0515 bool found = false; 0516 int i = 0; 0517 0518 while (!found && (i < parentItemList.size())) 0519 { 0520 parentItem = parentItemList.at(i); 0521 0522 if (parentItem && (parentItem->data(1, Qt::UserRole).toInt() == parentRefNum)) 0523 { 0524 QTreeWidgetItem* const item = new QTreeWidgetItem(parentItem); 0525 item->setText(0, cleanName(album.m_name)); 0526 item->setIcon(0, QIcon::fromTheme(QLatin1String("inode-directory"))); 0527 item->setData(1, Qt::UserRole, album.m_refNum); 0528 item->setText(2, i18n("Album")); 0529 0530 parentItem->addChild(item); 0531 d->albumDict.insert(album.m_name, album); 0532 parentItemList << item; 0533 found = true; 0534 } 0535 0536 i++; 0537 } 0538 } 0539 } 0540 } 0541 0542 void PiwigoWindow::slotAlbumSelected() 0543 { 0544 QTreeWidgetItem* const item = d->albumView->currentItem(); 0545 0546 // stop loading if user clicked an image 0547 0548 if (item && (item->text(2) == i18n("Image"))) 0549 { 0550 return; 0551 } 0552 0553 if (!item) 0554 { 0555 startButton()->setEnabled(false); 0556 } 0557 else 0558 { 0559 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Album selected\n"; 0560 0561 int albumId = item->data(1, Qt::UserRole).toInt(); 0562 qCDebug(DIGIKAM_WEBSERVICES_LOG) << albumId << "\n"; 0563 0564 if (d->talker->loggedIn() && albumId) 0565 { 0566 startButton()->setEnabled(true); 0567 } 0568 else 0569 { 0570 startButton()->setEnabled(false); 0571 } 0572 } 0573 } 0574 0575 void PiwigoWindow::slotAddPhoto() 0576 { 0577 const QList<QUrl> urls(d->imageList->imageUrls()); 0578 0579 if (urls.isEmpty()) 0580 { 0581 QMessageBox::critical(this, QString(), 0582 i18n("Nothing to upload - please select photos to upload.")); 0583 return; 0584 } 0585 0586 for (QList<QUrl>::const_iterator it = urls.constBegin() ; 0587 it != urls.constEnd() ; ++it) 0588 { 0589 d->pUploadList.append((*it).toLocalFile()); 0590 } 0591 0592 d->uploadTotal = d->pUploadList.count(); 0593 d->progressBar->reset(); 0594 d->progressBar->setMaximum(d->uploadTotal); 0595 d->uploadCount = 0; 0596 startButton()->setEnabled(false); 0597 slotAddPhotoNext(); 0598 } 0599 0600 void PiwigoWindow::slotAddPhotoNext() 0601 { 0602 if (d->pUploadList.isEmpty()) 0603 { 0604 d->progressBar->reset(); 0605 setUiInProgressState(false); 0606 startButton()->setEnabled(true); 0607 0608 return; 0609 } 0610 0611 QTreeWidgetItem* const item = d->albumView->currentItem(); 0612 int column = d->albumView->currentColumn(); 0613 QString albumTitle = item->text(column); 0614 const PiwigoAlbum& album = d->albumDict.value(albumTitle); 0615 d->currPhotoPath = d->pUploadList.takeFirst(); 0616 bool res = d->talker->addPhoto(album.m_refNum, 0617 d->currPhotoPath, 0618 d->resizeCheckBox->isChecked(), 0619 d->widthSpinBox->value(), 0620 d->heightSpinBox->value(), 0621 d->qualitySpinBox->value()); 0622 0623 if (!res) 0624 { 0625 slotAddPhotoFailed(i18n("The file %1 is not a supported image or video format", 0626 QUrl(d->currPhotoPath).fileName())); 0627 return; 0628 } 0629 0630 d->progressBar->progressStatusChanged(i18n("Uploading file %1", QUrl(d->currPhotoPath).fileName())); 0631 d->imageList->processing(QUrl::fromLocalFile(d->currPhotoPath)); 0632 0633 if (d->progressBar->isHidden()) 0634 { 0635 setUiInProgressState(true); 0636 } 0637 } 0638 0639 void PiwigoWindow::slotAddPhotoSucceeded() 0640 { 0641 d->uploadCount++; 0642 d->progressBar->setValue(d->uploadCount); 0643 d->imageList->processed(QUrl::fromLocalFile(d->currPhotoPath), true); 0644 slotAddPhotoNext(); 0645 } 0646 0647 void PiwigoWindow::slotAddPhotoFailed(const QString& msg) 0648 { 0649 d->imageList->processed(QUrl::fromLocalFile(d->currPhotoPath), false); 0650 d->progressBar->reset(); 0651 setUiInProgressState(false); 0652 0653 if (QMessageBox::question(this, i18nc("@title:window", "Uploading Failed"), 0654 i18n("Failed to upload media into remote Piwigo. ") + msg + 0655 i18n("\nDo you want to continue?")) 0656 != QMessageBox::Yes) 0657 { 0658 return; 0659 } 0660 else 0661 { 0662 slotAddPhotoNext(); 0663 } 0664 } 0665 0666 void PiwigoWindow::slotAddPhotoCancel() 0667 { 0668 d->imageList->processed(QUrl::fromLocalFile(d->currPhotoPath), false); 0669 d->progressBar->reset(); 0670 setUiInProgressState(false); 0671 d->talker->cancel(); 0672 } 0673 0674 void PiwigoWindow::slotEnableSpinBox(int n) 0675 { 0676 bool b; 0677 0678 switch (n) 0679 { 0680 case 0: 0681 { 0682 b = false; 0683 break; 0684 } 0685 0686 case 1: 0687 case 2: 0688 { 0689 b = true; 0690 break; 0691 } 0692 0693 default: 0694 { 0695 b = false; 0696 break; 0697 } 0698 } 0699 0700 d->widthSpinBox->setEnabled(b); 0701 d->heightSpinBox->setEnabled(b); 0702 d->qualitySpinBox->setEnabled(b); 0703 } 0704 0705 void PiwigoWindow::slotSettings() 0706 { 0707 // TODO: reload albumlist if OK slot used. 0708 0709 QPointer<PiwigoLoginDlg> dlg = new PiwigoLoginDlg(QApplication::activeWindow(), 0710 d->pPiwigo, i18n("Edit Piwigo Data")); 0711 0712 if (dlg->exec() == QDialog::Accepted) 0713 { 0714 slotDoLogin(); 0715 } 0716 0717 delete dlg; 0718 } 0719 0720 QString PiwigoWindow::cleanName(const QString& str) const 0721 { 0722 QString plain = str; 0723 plain.replace(QLatin1String("<"), QLatin1String("<")); 0724 plain.replace(QLatin1String(">"), QLatin1String(">")); 0725 plain.replace(QLatin1String("""), QLatin1String("\"")); 0726 plain.replace(QLatin1String("&"), QLatin1String("&")); 0727 0728 return plain; 0729 } 0730 0731 void PiwigoWindow::setUiInProgressState(bool inProgress) 0732 { 0733 setRejectButtonMode(inProgress ? QDialogButtonBox::Cancel : QDialogButtonBox::Close); 0734 0735 if (inProgress) 0736 { 0737 d->progressBar->show(); 0738 } 0739 else 0740 { 0741 d->progressBar->hide(); 0742 d->progressBar->progressCompleted(); 0743 } 0744 } 0745 0746 } // namespace DigikamGenericPiwigoPlugin 0747 0748 #include "moc_piwigowindow.cpp"