diff --git a/core/dplugins/generic/webservices/box/boxplugin.h b/core/dplugins/generic/webservices/box/boxplugin.h index af1af593b4..cb53528fb3 100644 --- a/core/dplugins/generic/webservices/box/boxplugin.h +++ b/core/dplugins/generic/webservices/box/boxplugin.h @@ -1,71 +1,71 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-07-30 * Description : a plugin to export to Box web-service. * * Copyright (C) 2018-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_BOX_PLUGIN_H #define DIGIKAM_BOX_PLUGIN_H // Local includes #include "dplugingeneric.h" #define DPLUGIN_IID "org.kde.digikam.plugin.generic.Box" using namespace Digikam; namespace DigikamGenericBoxPlugin { class BOXWindow; class BoxPlugin : public DPluginGeneric { Q_OBJECT Q_PLUGIN_METADATA(IID DPLUGIN_IID) Q_INTERFACES(Digikam::DPluginGeneric) public: explicit BoxPlugin(QObject* const parent = nullptr); ~BoxPlugin(); QString name() const override; QString iid() const override; QIcon icon() const override; QString details() const override; QString description() const override; QList authors() const override; - void setup(QObject* const) override; - void cleanUp() override; + void setup(QObject* const) override; + void cleanUp() override; private Q_SLOTS: void slotBox(); private: QPointer m_toolDlg; }; } // namespace DigikamGenericBoxPlugin #endif // DIGIKAM_BOX_PLUGIN_H diff --git a/core/dplugins/generic/webservices/box/boxtalker.cpp b/core/dplugins/generic/webservices/box/boxtalker.cpp index 19b001e76a..2143a702a5 100644 --- a/core/dplugins/generic/webservices/box/boxtalker.cpp +++ b/core/dplugins/generic/webservices/box/boxtalker.cpp @@ -1,504 +1,518 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-05-20 * Description : a tool to export images to Box web service * * Copyright (C) 2018 by Tarek Talaat * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "boxtalker.h" // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // KDE includes #include // Local includes #include "digikam_debug.h" #include "digikam_version.h" #include "wstoolutils.h" #include "boxwindow.h" #include "boxitem.h" #include "previewloadthread.h" #include "o0settingsstore.h" namespace DigikamGenericBoxPlugin { class Q_DECL_HIDDEN BOXTalker::Private { public: enum State { BOX_USERNAME = 0, BOX_LISTFOLDERS, BOX_CREATEFOLDER, BOX_ADDPHOTO }; public: explicit Private() { clientId = QLatin1String("yvd43v8av9zgg9phig80m2dc3r7mks4t"); clientSecret = QLatin1String("KJkuMjvzOKDMyp3oxweQBEYixg678Fh5"); authUrl = QLatin1String("https://account.box.com/api/oauth2/authorize"); tokenUrl = QLatin1String("https://api.box.com/oauth2/token"); redirectUrl = QLatin1String("https://app.box.com"); state = BOX_USERNAME; parent = nullptr; netMngr = nullptr; reply = nullptr; settings = nullptr; o2 = nullptr; } public: QString clientId; QString clientSecret; QString authUrl; QString tokenUrl; QString redirectUrl; State state; QWidget* parent; QNetworkAccessManager* netMngr; QNetworkReply* reply; QSettings* settings; O2* o2; QList > foldersList; }; BOXTalker::BOXTalker(QWidget* const parent) : d(new Private) { d->parent = parent; d->netMngr = new QNetworkAccessManager(this); connect(this, SIGNAL(boxLinkingFailed()), this, SLOT(slotLinkingFailed())); connect(this, SIGNAL(boxLinkingSucceeded()), this, SLOT(slotLinkingSucceeded())); connect(d->netMngr, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinished(QNetworkReply*))); d->o2 = new O2(this); d->o2->setClientId(d->clientId); d->o2->setClientSecret(d->clientSecret); d->o2->setRefreshTokenUrl(d->tokenUrl); d->o2->setRequestUrl(d->authUrl); d->o2->setTokenUrl(d->tokenUrl); d->o2->setLocalPort(8000); d->settings = WSToolUtils::getOauthSettings(this); O0SettingsStore* const store = new O0SettingsStore(d->settings, QLatin1String(O2_ENCRYPTION_KEY), this); store->setGroupKey(QLatin1String("Box")); d->o2->setStore(store); connect(d->o2, SIGNAL(linkingFailed()), this, SLOT(slotLinkingFailed())); connect(d->o2, SIGNAL(linkingSucceeded()), this, SLOT(slotLinkingSucceeded())); connect(d->o2, SIGNAL(openBrowser(QUrl)), this, SLOT(slotOpenBrowser(QUrl))); } BOXTalker::~BOXTalker() { if (d->reply) { d->reply->abort(); } WSToolUtils::removeTemporaryDir("box"); delete d; } void BOXTalker::link() { emit signalBusy(true); d->o2->link(); } void BOXTalker::unLink() { d->o2->unlink(); d->settings->beginGroup(QLatin1String("Box")); d->settings->remove(QString()); d->settings->endGroup(); } void BOXTalker::slotLinkingFailed() { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Box fail"; emit signalBusy(false); } void BOXTalker::slotLinkingSucceeded() { if (!d->o2->linked()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "UNLINK to Box ok"; emit signalBusy(false); return; } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Box ok"; emit signalLinkingSucceeded(); } bool BOXTalker::authenticated() { return d->o2->linked(); } void BOXTalker::cancel() { if (d->reply) { d->reply->abort(); d->reply = nullptr; } emit signalBusy(false); } void BOXTalker::slotOpenBrowser(const QUrl& url) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Open Browser..."; QDesktopServices::openUrl(url); } void BOXTalker::createFolder(QString& path) { QString name = path.section(QLatin1Char('/'), -1); QString folderPath = path.section(QLatin1Char('/'), -2, -2); QString id; for (int i = 0 ; i < d->foldersList.size() ; ++i) { if (d->foldersList.value(i).second == folderPath) { id = d->foldersList.value(i).first; } } QUrl url(QLatin1String("https://api.box.com/2.0/folders")); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); netRequest.setRawHeader("Authorization", QString::fromLatin1("Bearer %1").arg(d->o2->token()).toUtf8()); QByteArray postData = QString::fromUtf8("{\"name\": \"%1\",\"parent\": {\"id\": \"%2\"}}").arg(name).arg(id).toUtf8(); d->reply = d->netMngr->post(netRequest, postData); d->state = Private::BOX_CREATEFOLDER; + emit signalBusy(true); } void BOXTalker::getUserName() { QUrl url(QLatin1String("https://api.box.com/2.0/users/me")); QNetworkRequest netRequest(url); netRequest.setRawHeader("Authorization", QString::fromLatin1("Bearer %1").arg(d->o2->token()).toUtf8()); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); d->reply = d->netMngr->get(netRequest); d->state = Private::BOX_USERNAME; + emit signalBusy(true); } void BOXTalker::listFolders(const QString& /*path*/) { QUrl url(QLatin1String("https://api.box.com/2.0/folders/0/items"));; QNetworkRequest netRequest(url); netRequest.setRawHeader("Authorization", QString::fromLatin1("Bearer %1").arg(d->o2->token()).toUtf8()); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); d->reply = d->netMngr->get(netRequest); - d->state = Private::BOX_LISTFOLDERS; + emit signalBusy(true); } bool BOXTalker::addPhoto(const QString& imgPath, const QString& uploadFolder, bool rescale, int maxDim, int imageQuality) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } emit signalBusy(true); QMimeDatabase mimeDB; QString path = imgPath; QString mimeType = mimeDB.mimeTypeForFile(path).name(); if (mimeType.startsWith(QLatin1String("image/"))) { QImage image = PreviewLoadThread::loadHighQualitySynchronously(imgPath).copyQImage(); if (image.isNull()) { emit signalBusy(false); return false; } path = WSToolUtils::makeTemporaryDir("box").filePath(QFileInfo(imgPath) .baseName().trimmed() + QLatin1String(".jpg")); if (rescale && (image.width() > maxDim || image.height() > maxDim)) { image = image.scaled(maxDim, maxDim, Qt::KeepAspectRatio, Qt::SmoothTransformation); } image.save(path, "JPEG", imageQuality); DMetadata meta; if (meta.load(imgPath)) { meta.setItemDimensions(image.size()); meta.setItemOrientation(DMetadata::ORIENTATION_NORMAL); meta.setMetadataWritingMode((int)DMetadata::WRITE_TO_FILE_ONLY); meta.save(path, true); } } QString id; for (int i = 0 ; i < d->foldersList.size() ; ++i) { if (d->foldersList.value(i).second == uploadFolder) { id = d->foldersList.value(i).first; } } QHttpMultiPart* const multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart attributes; QString attributesHeader = QLatin1String("form-data; name=\"attributes\""); attributes.setHeader(QNetworkRequest::ContentDispositionHeader, attributesHeader); QString postData = QLatin1String("{\"name\":\"") + QFileInfo(imgPath).fileName() + QLatin1Char('"') + QLatin1String(", \"parent\":{\"id\":\"") + id + QLatin1String("\"}}"); attributes.setBody(postData.toUtf8()); multiPart->append(attributes); QFile* const file = new QFile(path); - file->open(QIODevice::ReadOnly); + + if (!file) + { + return false; + } + + if (!file->open(QIODevice::ReadOnly)) + { + return false; + } QHttpPart imagePart; QString imagePartHeader = QLatin1String("form-data; name=\"file\"; filename=\"") + QFileInfo(imgPath).fileName() + QLatin1Char('"'); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, imagePartHeader); imagePart.setHeader(QNetworkRequest::ContentTypeHeader, mimeType); imagePart.setBodyDevice(file); multiPart->append(imagePart); QUrl url(QString::fromLatin1("https://upload.box.com/api/2.0/files/content?access_token=%1").arg(d->o2->token())); QNetworkRequest netRequest(url); QString content = QLatin1String("multipart/form-data;boundary=") + QString::fromUtf8(multiPart->boundary()); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, content); d->reply = d->netMngr->post(netRequest, multiPart); + // delete the multiPart and file with the reply + multiPart->setParent(d->reply); d->state = Private::BOX_ADDPHOTO; + return true; } void BOXTalker::slotFinished(QNetworkReply* reply) { if (reply != d->reply) { return; } d->reply = nullptr; if (reply->error() != QNetworkReply::NoError) { if (d->state != Private::BOX_CREATEFOLDER) { emit signalBusy(false); QMessageBox::critical(QApplication::activeWindow(), i18n("Error"), reply->errorString()); reply->deleteLater(); return; } } QByteArray buffer = reply->readAll(); switch (d->state) { case Private::BOX_LISTFOLDERS: qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In BOX_LISTFOLDERS"; parseResponseListFolders(buffer); break; case Private::BOX_CREATEFOLDER: qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In BOX_CREATEFOLDER"; parseResponseCreateFolder(buffer); break; case Private::BOX_ADDPHOTO: qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In BOX_ADDPHOTO"; parseResponseAddPhoto(buffer); break; case Private::BOX_USERNAME: qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In BOX_USERNAME"; parseResponseUserName(buffer); break; default: break; } reply->deleteLater(); } void BOXTalker::parseResponseAddPhoto(const QByteArray& data) { QJsonDocument doc = QJsonDocument::fromJson(data); QJsonObject jsonObject = doc.object(); bool success = jsonObject.contains(QLatin1String("total_count")); emit signalBusy(false); if (!success) { emit signalAddPhotoFailed(i18n("Failed to upload photo")); } else { emit signalAddPhotoSucceeded(); } } void BOXTalker::parseResponseUserName(const QByteArray& data) { QJsonDocument doc = QJsonDocument::fromJson(data); QString name = doc.object()[QLatin1String("name")].toString(); emit signalBusy(false); emit signalSetUserName(name); } void BOXTalker::parseResponseListFolders(const QByteArray& data) { QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(data, &err); if (err.error != QJsonParseError::NoError) { emit signalBusy(false); emit signalListAlbumsFailed(i18n("Failed to list folders")); return; } QJsonObject jsonObject = doc.object(); QJsonArray jsonArray = jsonObject[QLatin1String("entries")].toArray(); d->foldersList.clear(); d->foldersList.append(qMakePair(QLatin1String("0"), QLatin1String("root"))); foreach (const QJsonValue& value, jsonArray) { QString folderName; QString type; QString id; QJsonObject obj = value.toObject(); type = obj[QLatin1String("type")].toString(); if (type == QLatin1String("folder")) { folderName = obj[QLatin1String("name")].toString(); id = obj[QLatin1String("id")].toString(); d->foldersList.append(qMakePair(id, folderName)); } } emit signalBusy(false); emit signalListAlbumsDone(d->foldersList); } void BOXTalker::parseResponseCreateFolder(const QByteArray& data) { QJsonDocument doc = QJsonDocument::fromJson(data); QJsonObject jsonObject = doc.object(); bool fail = jsonObject.contains(QLatin1String("error")); emit signalBusy(false); if (fail) { QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(data, &err); emit signalCreateFolderFailed(jsonObject[QLatin1String("error_summary")].toString()); } else { emit signalCreateFolderSucceeded(); } } } // namespace DigikamGenericBoxPlugin diff --git a/core/dplugins/generic/webservices/box/boxwidget.cpp b/core/dplugins/generic/webservices/box/boxwidget.cpp index 2f96ae77ee..854930b1ac 100644 --- a/core/dplugins/generic/webservices/box/boxwidget.cpp +++ b/core/dplugins/generic/webservices/box/boxwidget.cpp @@ -1,72 +1,72 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-05-20 * Description : a tool to export images to Box web service * * Copyright (C) 2018 by Tarek Talaat * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "boxwidget.h" // Qt includes #include #include // Local includes namespace DigikamGenericBoxPlugin { BOXWidget::BOXWidget(QWidget* const parent, DInfoInterface* const iface, const QString& toolName) : WSSettingsWidget(parent, iface, toolName) { getUploadBox()->hide(); getSizeBox()->hide(); } BOXWidget::~BOXWidget() { } void BOXWidget::updateLabels(const QString& name, const QString& url) { QString web(QLatin1String("https://www.box.com/")); if (!url.isEmpty()) { web = url; } getHeaderLbl()->setText(QString::fromLatin1( - "

" - "Box" - "

").arg(web)); + "

" + "Box" + "

").arg(web)); if (name.isEmpty()) { getUserNameLabel()->clear(); } else { getUserNameLabel()->setText(QString::fromLatin1("%1").arg(name)); } } } // namespace DigikamGenericBoxPlugin diff --git a/core/dplugins/generic/webservices/box/boxwindow.cpp b/core/dplugins/generic/webservices/box/boxwindow.cpp index dece7e9599..38c5bda05c 100644 --- a/core/dplugins/generic/webservices/box/boxwindow.cpp +++ b/core/dplugins/generic/webservices/box/boxwindow.cpp @@ -1,470 +1,471 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-05-20 * Description : a tool to export images to Box web service * * Copyright (C) 2018 by Tarek Talaat * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "boxwindow.h" // Qt includes #include #include #include #include #include #include // KDE includes #include #include #include // Local includes #include "digikam_debug.h" #include "ditemslist.h" #include "digikam_version.h" #include "boxtalker.h" #include "boxitem.h" #include "boxnewalbumdlg.h" #include "boxwidget.h" namespace DigikamGenericBoxPlugin { class Q_DECL_HIDDEN BOXWindow::Private { public: explicit Private() { imagesCount = 0; imagesTotal = 0; widget = nullptr; albumDlg = nullptr; talker = nullptr; } unsigned int imagesCount; unsigned int imagesTotal; BOXWidget* widget; BOXNewAlbumDlg* albumDlg; BOXTalker* talker; QString currentAlbumName; QList transferQueue; }; BOXWindow::BOXWindow(DInfoInterface* const iface, QWidget* const /*parent*/) : WSToolDialog(nullptr, QLatin1String("Box Export Dialog")), d(new Private) { d->widget = new BOXWidget(this, iface, QLatin1String("Box")); d->widget->imagesList()->setIface(iface); setMainWidget(d->widget); setModal(false); setWindowTitle(i18n("Export to Box")); startButton()->setText(i18n("Start Upload")); startButton()->setToolTip(i18n("Start upload to Box")); d->widget->setMinimumSize(700, 500); connect(d->widget->imagesList(), SIGNAL(signalImageListChanged()), this, SLOT(slotImageListChanged())); connect(d->widget->getChangeUserBtn(), SIGNAL(clicked()), this, SLOT(slotUserChangeRequest())); connect(d->widget->getNewAlbmBtn(), SIGNAL(clicked()), this, SLOT(slotNewAlbumRequest())); connect(d->widget->getReloadBtn(), SIGNAL(clicked()), this, SLOT(slotReloadAlbumsRequest())); connect(startButton(), SIGNAL(clicked()), this, SLOT(slotStartTransfer())); d->albumDlg = new BOXNewAlbumDlg(this, QLatin1String("Box")); d->talker = new BOXTalker(this); connect(d->talker,SIGNAL(signalBusy(bool)), this, SLOT(slotBusy(bool))); connect(d->talker, SIGNAL(signalLinkingFailed()), this, SLOT(slotSignalLinkingFailed())); connect(d->talker, SIGNAL(signalLinkingSucceeded()), this, SLOT(slotSignalLinkingSucceeded())); connect(d->talker, SIGNAL(signalSetUserName(QString)), this, SLOT(slotSetUserName(QString))); connect(d->talker, SIGNAL(signalListAlbumsFailed(QString)), this, SLOT(slotListAlbumsFailed(QString))); connect(d->talker, SIGNAL(signalListAlbumsDone(QList >)), // krazy:exclude=normalize this, SLOT(slotListAlbumsDone(QList >))); // krazy:exclude=normalize connect(d->talker, SIGNAL(signalCreateFolderFailed(QString)), this, SLOT(slotCreateFolderFailed(QString))); connect(d->talker, SIGNAL(signalCreateFolderSucceeded()), this, SLOT(slotCreateFolderSucceeded())); connect(d->talker, SIGNAL(signalAddPhotoFailed(QString)), this, SLOT(slotAddPhotoFailed(QString))); connect(d->talker, SIGNAL(signalAddPhotoSucceeded()), this, SLOT(slotAddPhotoSucceeded())); connect(this, SIGNAL(finished(int)), this, SLOT(slotFinished())); readSettings(); buttonStateChange(false); d->talker->link(); } BOXWindow::~BOXWindow() { delete d->widget; delete d->albumDlg; delete d->talker; delete d; } void BOXWindow::readSettings() { KConfig config; KConfigGroup grp = config.group("Box Settings"); d->currentAlbumName = grp.readEntry("Current Album", QString()); if (grp.readEntry("Resize", false)) { d->widget->getResizeCheckBox()->setChecked(true); d->widget->getDimensionSpB()->setEnabled(true); } else { d->widget->getResizeCheckBox()->setChecked(false); d->widget->getDimensionSpB()->setEnabled(false); } d->widget->getDimensionSpB()->setValue(grp.readEntry("Maximum Width", 1600)); d->widget->getImgQualitySpB()->setValue(grp.readEntry("Image Quality", 90)); KConfigGroup dialogGroup = config.group("Box Export Dialog"); winId(); KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup); resize(windowHandle()->size()); } void BOXWindow::writeSettings() { KConfig config; KConfigGroup grp = config.group("Box Settings"); grp.writeEntry("Current Album", d->currentAlbumName); grp.writeEntry("Resize", d->widget->getResizeCheckBox()->isChecked()); grp.writeEntry("Maximum Width", d->widget->getDimensionSpB()->value()); grp.writeEntry("Image Quality", d->widget->getImgQualitySpB()->value()); KConfigGroup dialogGroup = config.group("Box Export Dialog"); KWindowConfig::saveWindowSize(windowHandle(), dialogGroup); config.sync(); } void BOXWindow::reactivate() { d->widget->imagesList()->loadImagesFromCurrentSelection(); d->widget->progressBar()->hide(); show(); } void BOXWindow::setItemsList(const QList& urls) { d->widget->imagesList()->slotAddImages(urls); } void BOXWindow::slotBusy(bool val) { if (val) { setCursor(Qt::WaitCursor); d->widget->getChangeUserBtn()->setEnabled(false); buttonStateChange(false); } else { setCursor(Qt::ArrowCursor); d->widget->getChangeUserBtn()->setEnabled(true); buttonStateChange(true); } } void BOXWindow::slotSetUserName(const QString& msg) { d->widget->updateLabels(msg, QLatin1String("")); } void BOXWindow::slotListAlbumsDone(const QList >& list) { d->widget->getAlbumsCoB()->clear(); for (int i = 0 ; i < list.size() ; ++i) { d->widget->getAlbumsCoB()->addItem( QIcon::fromTheme(QLatin1String("system-users")), list.value(i).second, list.value(i).second); if (d->currentAlbumName == QString(list.value(i).second)) { d->widget->getAlbumsCoB()->setCurrentIndex(i); } } buttonStateChange(true); d->talker->getUserName(); } void BOXWindow::slotStartTransfer() { d->widget->imagesList()->clearProcessedStatus(); if (d->widget->imagesList()->imageUrls().isEmpty()) { QMessageBox::critical(this, i18nc("@title:window", "Error"), i18n("No image selected. Please select which images should be uploaded.")); return; } if (!(d->talker->authenticated())) { QPointer warn = new QMessageBox(QMessageBox::Warning, i18n("Warning"), i18n("Authentication failed. Click \"Continue\" to authenticate."), QMessageBox::Yes | QMessageBox::No); (warn->button(QMessageBox::Yes))->setText(i18n("Continue")); (warn->button(QMessageBox::No))->setText(i18n("Cancel")); if (warn->exec() == QMessageBox::Yes) { d->talker->link(); delete warn; return; } else { delete warn; return; } } d->transferQueue = d->widget->imagesList()->imageUrls(); if (d->transferQueue.isEmpty()) { return; } d->currentAlbumName = d->widget->getAlbumsCoB()->itemData(d->widget->getAlbumsCoB()->currentIndex()).toString(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "StartTransfer:" << d->currentAlbumName << "INDEX: " << d->widget->getAlbumsCoB()->currentIndex(); d->imagesTotal = d->transferQueue.count(); d->imagesCount = 0; d->widget->progressBar()->setFormat(i18n("%v / %m")); d->widget->progressBar()->setMaximum(d->imagesTotal); d->widget->progressBar()->setValue(0); d->widget->progressBar()->show(); d->widget->progressBar()->progressScheduled(i18n("Box export"), true, true); d->widget->progressBar()->progressThumbnailChanged( QIcon::fromTheme(QLatin1String("dk-box")).pixmap(22, 22)); uploadNextPhoto(); } void BOXWindow::uploadNextPhoto() { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "uploadNextPhoto:" << d->transferQueue.count(); if (d->transferQueue.isEmpty()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "empty"; d->widget->progressBar()->progressCompleted(); return; } QString imgPath = d->transferQueue.first().toLocalFile(); QString temp = d->currentAlbumName; bool result = d->talker->addPhoto(imgPath, temp, d->widget->getResizeCheckBox()->isChecked(), d->widget->getDimensionSpB()->value(), d->widget->getImgQualitySpB()->value()); if (!result) { slotAddPhotoFailed(QLatin1String("")); return; } } void BOXWindow::slotAddPhotoFailed(const QString& msg) { if (QMessageBox::question(this, i18n("Uploading Failed"), i18n("Failed to upload photo to Box." "\n%1\n" "Do you want to continue?", msg)) != QMessageBox::Yes) { d->transferQueue.clear(); d->widget->progressBar()->hide(); } else { d->transferQueue.pop_front(); d->imagesTotal--; d->widget->progressBar()->setMaximum(d->imagesTotal); d->widget->progressBar()->setValue(d->imagesCount); uploadNextPhoto(); } } void BOXWindow::slotAddPhotoSucceeded() { // Remove photo uploaded from the list + d->widget->imagesList()->removeItemByUrl(d->transferQueue.first()); d->transferQueue.pop_front(); d->imagesCount++; d->widget->progressBar()->setMaximum(d->imagesTotal); d->widget->progressBar()->setValue(d->imagesCount); uploadNextPhoto(); } void BOXWindow::slotImageListChanged() { startButton()->setEnabled(!(d->widget->imagesList()->imageUrls().isEmpty())); } void BOXWindow::slotNewAlbumRequest() { if (d->albumDlg->exec() == QDialog::Accepted) { BOXFolder newFolder; d->albumDlg->getFolderTitle(newFolder); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "slotNewAlbumRequest:" << newFolder.title; d->currentAlbumName = d->widget->getAlbumsCoB()->itemData(d->widget->getAlbumsCoB()->currentIndex()).toString(); d->currentAlbumName = d->currentAlbumName + newFolder.title; d->talker->createFolder(d->currentAlbumName); } } void BOXWindow::slotReloadAlbumsRequest() { d->talker->listFolders(); } void BOXWindow::slotSignalLinkingFailed() { slotSetUserName(QLatin1String("")); d->widget->getAlbumsCoB()->clear(); if (QMessageBox::question(this, i18n("Login Failed"), i18n("Authentication failed. Do you want to try again?")) == QMessageBox::Yes) { d->talker->link(); } } void BOXWindow::slotSignalLinkingSucceeded() { slotBusy(false); d->talker->listFolders(); } void BOXWindow::slotListAlbumsFailed(const QString& msg) { QMessageBox::critical(this, QString(), i18n("Box call failed:\n%1", msg)); } void BOXWindow::slotCreateFolderFailed(const QString& msg) { QMessageBox::critical(this, QString(), i18n("Box call failed:\n%1", msg)); } void BOXWindow::slotCreateFolderSucceeded() { d->talker->listFolders(); } void BOXWindow::slotTransferCancel() { d->transferQueue.clear(); d->widget->progressBar()->hide(); d->talker->cancel(); } void BOXWindow::slotUserChangeRequest() { slotSetUserName(QLatin1String("")); d->widget->getAlbumsCoB()->clear(); d->talker->unLink(); d->talker->link(); } void BOXWindow::buttonStateChange(bool state) { d->widget->getNewAlbmBtn()->setEnabled(state); d->widget->getReloadBtn()->setEnabled(state); startButton()->setEnabled(state); } void BOXWindow::slotFinished() { writeSettings(); d->widget->imagesList()->listView()->clear(); } void BOXWindow::closeEvent(QCloseEvent* e) { if (!e) { return; } slotFinished(); e->accept(); } } // namespace DigikamGenericBoxPlugin