diff --git a/core/dplugins/generic/webservices/flickr/flickrlist.h b/core/dplugins/generic/webservices/flickr/flickrlist.h index ef06ff9206..1f8f3413d9 100644 --- a/core/dplugins/generic/webservices/flickr/flickrlist.h +++ b/core/dplugins/generic/webservices/flickr/flickrlist.h @@ -1,168 +1,173 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-05-22 * Description : Flickr file list view and items. * * Copyright (C) 2009 by Pieter Edelman * Copyright (C) 2008-2020 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_FLICKR_LIST_H #define DIGIKAM_FLICKR_LIST_H // Qt includes #include #include #include // Local includes #include "ditemslist.h" using namespace Digikam; namespace DigikamGenericFlickrPlugin { class FlickrList : public DItemsList { Q_OBJECT public: - /** The different columns in a Flickr list. + /** + * The different columns in a Flickr list. */ enum FieldType { SAFETYLEVEL = DItemsListView::User1, CONTENTTYPE = DItemsListView::User2, TAGS = DItemsListView::User3, PUBLIC = DItemsListView::User4, FAMILY = DItemsListView::User5, FRIENDS = DItemsListView::User6 }; - /** The different possible safety levels recognized by Flickr. + /** + * The different possible safety levels recognized by Flickr. */ enum SafetyLevel { SAFE = 1, MODERATE = 2, RESTRICTED = 3, MIXEDLEVELS = -1 }; - /** The different possible content types recognized by Flickr. + /** + * The different possible content types recognized by Flickr. */ enum ContentType { PHOTO = 1, SCREENSHOT = 2, OTHER = 3, MIXEDTYPES = -1 }; public: explicit FlickrList(QWidget* const parent = nullptr); ~FlickrList(); void setPublic(Qt::CheckState); void setFamily(Qt::CheckState); void setFriends(Qt::CheckState); void setSafetyLevels(SafetyLevel); void setContentTypes(ContentType); Q_SIGNALS: - // Signal for notifying when the states of one of the permission columns has - // changed. The first argument specifies which permission has changed, the - // second the state. + /** + * Signal for notifying when the states of one of the permission columns has + * changed. The first argument specifies which permission has changed, the + * second the state. + */ void signalPermissionChanged(FlickrList::FieldType, Qt::CheckState); void signalSafetyLevelChanged(FlickrList::SafetyLevel); void signalContentTypeChanged(FlickrList::ContentType); public Q_SLOTS: void slotAddImages(const QList& list) override; private: void setPermissionState(FieldType, Qt::CheckState); void singlePermissionChanged(QTreeWidgetItem*, int); void singleComboBoxChanged(QTreeWidgetItem*, int); private Q_SLOTS: void slotItemChanged(QTreeWidgetItem*, int); void slotItemClicked(QTreeWidgetItem*, int); private: class Private; Private* const d; }; // ------------------------------------------------------------------------- class FlickrListViewItem : public DItemsListViewItem { public: explicit FlickrListViewItem(DItemsListView* const view, const QUrl& url, bool, bool, bool, FlickrList::SafetyLevel, FlickrList::ContentType); ~FlickrListViewItem(); void setPublic(bool); void setFamily(bool); void setFriends(bool); void setSafetyLevel(FlickrList::SafetyLevel); void setContentType(FlickrList::ContentType); - bool isPublic() const; - bool isFamily() const; - bool isFriends() const; + bool isPublic() const; + bool isFamily() const; + bool isFriends() const; FlickrList::SafetyLevel safetyLevel() const; FlickrList::ContentType contentType() const; /** * Returns the list of extra tags that the user specified for this image. */ QStringList extraTags() const; /** * This method should be called when one of the checkboxes is clicked. */ void toggled(); void updateItemWidgets() override; private: class Private; Private* const d; }; } // namespace DigikamGenericFlickrPlugin #endif // DIGIKAM_FLICKR_LIST_H diff --git a/core/dplugins/generic/webservices/flickr/flickrnewalbumdlg.cpp b/core/dplugins/generic/webservices/flickr/flickrnewalbumdlg.cpp index c48b31085a..ce466fb5a2 100644 --- a/core/dplugins/generic/webservices/flickr/flickrnewalbumdlg.cpp +++ b/core/dplugins/generic/webservices/flickr/flickrnewalbumdlg.cpp @@ -1,61 +1,62 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2015-08-07 * Description : a dialog to create a new remote album for export tools * * Copyright (C) 2013 by Pankaj Kumar * Copyright (C) 2015 by Shourya Singh Gupta * Copyright (C) 2013-2020 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. * * ============================================================ */ #include "flickrnewalbumdlg.h" // Qt includes #include #include #include // Local includes #include "digikam_debug.h" #include "flickritem.h" namespace DigikamGenericFlickrPlugin { FlickrNewAlbumDlg::FlickrNewAlbumDlg(QWidget* const parent, const QString& toolName) : WSNewAlbumDialog(parent, toolName) { hideDateTime(); hideLocation(); getMainWidget()->setMinimumSize(350,0); } FlickrNewAlbumDlg::~FlickrNewAlbumDlg() { } void FlickrNewAlbumDlg::getFolderProperties(FPhotoSet& folder) { folder.title = getTitleEdit()->text(); folder.description = getDescEdit()->toPlainText(); - qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Folder Title " << folder.title<<" Folder Description "< * Copyright (C) 2009-2020 by Gilles Caulier * Copyright (C) 2017-2019 by Maik Qualmann * * 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 "flickrtalker.h" // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include #include // KDE includes #include // Local includes #include "dmetadata.h" #include "wstoolutils.h" #include "flickrmpform.h" #include "flickrwindow.h" #include "webbrowserdlg.h" #include "digikam_debug.h" #include "digikam_config.h" #include "digikam_version.h" #include "previewloadthread.h" // OAuth2 library includes #if defined(Q_CC_CLANG) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wextra-semi" #endif #include "o1.h" #include "o0globals.h" #include "o1requestor.h" #include "o0settingsstore.h" #if defined(Q_CC_CLANG) # pragma clang diagnostic pop #endif namespace DigikamGenericFlickrPlugin { class Q_DECL_HIDDEN FlickrTalker::Private { public: explicit Private() : parent(nullptr), netMngr(nullptr), reply(nullptr), settings(nullptr), state(FE_LOGOUT), iface(nullptr), o1(nullptr), store(nullptr), requestor(nullptr), browser(nullptr) { apiUrl = QLatin1String("https://www.flickr.com/services/rest/"); authUrl = QLatin1String("https://www.flickr.com/services/oauth/authorize?perms=write"); tokenUrl = QLatin1String("https://www.flickr.com/services/oauth/request_token"); accessUrl = QLatin1String("https://www.flickr.com/services/oauth/access_token"); uploadUrl = QLatin1String("https://up.flickr.com/services/upload/"); callbackUrl = QLatin1String("https://www.flickr.com"); apikey = QLatin1String("74f882bf4dabe22baaaace1f6d33c66b"); secret = QLatin1String("537d58e3ead2d6d5"); } QWidget* parent; QString serviceName; QString apiUrl; QString authUrl; QString tokenUrl; QString accessUrl; QString uploadUrl; QString callbackUrl; QString apikey; QString secret; QString maxSize; QString username; QString userId; QString lastTmpFile; QNetworkAccessManager* netMngr; QNetworkReply* reply; QSettings* settings; State state; DInfoInterface* iface; O1* o1; O0SettingsStore* store; O1Requestor* requestor; WebBrowserDlg* browser; }; FlickrTalker::FlickrTalker(QWidget* const parent, const QString& serviceName, DInfoInterface* const iface) : d(new Private) { - d->parent = parent; - d->serviceName = serviceName; - d->iface = iface; - m_photoSetsList = nullptr; - m_authProgressDlg = nullptr; + d->parent = parent; + d->serviceName = serviceName; + d->iface = iface; + m_photoSetsList = nullptr; + m_authProgressDlg = nullptr; - d->netMngr = new QNetworkAccessManager(this); + d->netMngr = new QNetworkAccessManager(this); connect(d->netMngr, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinished(QNetworkReply*))); /* Initialize selected photo set as empty. */ m_selectedPhotoSet = FPhotoSet(); /* Initialize photo sets list. */ m_photoSetsList = new QLinkedList(); - d->o1 = new O1(this); + d->o1 = new O1(this); d->o1->setLocalPort(80); d->o1->setClientId(d->apikey); d->o1->setClientSecret(d->secret); d->o1->setCallbackUrl(d->callbackUrl); d->o1->setAuthorizeUrl(QUrl(d->authUrl)); d->o1->setAccessTokenUrl(QUrl(d->accessUrl)); d->o1->setRequestTokenUrl(QUrl(d->tokenUrl)); d->o1->setUseExternalWebInterceptor(true); d->settings = WSToolUtils::getOauthSettings(this); d->store = new O0SettingsStore(d->settings, QLatin1String(O2_ENCRYPTION_KEY), this); d->store->setGroupKey(d->serviceName); d->o1->setStore(d->store); connect(d->o1, SIGNAL(linkingFailed()), this, SLOT(slotLinkingFailed())); connect(d->o1, SIGNAL(linkingSucceeded()), this, SLOT(slotLinkingSucceeded())); connect(d->o1, SIGNAL(openBrowser(QUrl)), this, SLOT(slotOpenBrowser(QUrl))); d->requestor = new O1Requestor(d->netMngr, d->o1, this); } FlickrTalker::~FlickrTalker() { if (d->reply) { d->reply->abort(); } WSToolUtils::removeTemporaryDir(d->serviceName.toLatin1().constData()); delete m_photoSetsList; delete d; } void FlickrTalker::link(const QString& userName) { emit signalBusy(true); if (userName.isEmpty()) { d->store->setGroupKey(d->serviceName); } else { d->store->setGroupKey(d->serviceName + userName); } d->o1->link(); } void FlickrTalker::unLink() { d->o1->unlink(); } void FlickrTalker::removeUserName(const QString& userName) { if (userName.startsWith(d->serviceName)) { d->settings->beginGroup(userName); d->settings->remove(QString()); d->settings->endGroup(); } } void FlickrTalker::slotCatchUrl(const QUrl& url) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Received URL from webview:" << url; QString str = url.toString(); QUrlQuery query(str.section(QLatin1Char('?'), -1, -1)); if (query.hasQueryItem(QLatin1String("oauth_token"))) { QMultiMap queryParams; queryParams.insert(QLatin1String("oauth_token"), query.queryItemValue(QLatin1String("oauth_token"))); queryParams.insert(QLatin1String("oauth_verifier"), query.queryItemValue(QLatin1String("oauth_verifier"))); d->o1->onVerificationReceived(queryParams); } } void FlickrTalker::slotLinkingFailed() { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Flickr fail"; d->username = QString(); emit signalBusy(false); } void FlickrTalker::slotLinkingSucceeded() { if (!d->o1->linked()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "UNLINK to Flickr ok"; d->username = QString(); return; } if (d->browser) { d->browser->close(); } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Flickr ok"; d->username = d->o1->extraTokens()[QLatin1String("username")].toString(); d->userId = d->o1->extraTokens()[QLatin1String("user_nsid")].toString(); if (d->store->groupKey() == d->serviceName) { d->settings->beginGroup(d->serviceName); QStringList keys = d->settings->allKeys(); d->settings->endGroup(); foreach (const QString& key, keys) { d->settings->beginGroup(d->serviceName); QVariant value = d->settings->value(key); d->settings->endGroup(); d->settings->beginGroup(d->serviceName + d->username); d->settings->setValue(key, value); d->settings->endGroup(); } d->store->setGroupKey(d->serviceName + d->username); removeUserName(d->serviceName); } emit signalLinkingSucceeded(); } void FlickrTalker::slotOpenBrowser(const QUrl& url) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Open Browser... (" << url << ")"; delete d->browser; d->browser = new WebBrowserDlg(url, d->parent, true); d->browser->setModal(true); connect(d->browser, SIGNAL(urlChanged(QUrl)), this, SLOT(slotCatchUrl(QUrl))); connect(d->browser, SIGNAL(closeView(bool)), this, SIGNAL(signalBusy(bool))); d->browser->show(); } QString FlickrTalker::getMaxAllowedFileSize() { return d->maxSize; } void FlickrTalker::maxAllowedFileSize() { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } QUrl url(d->apiUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); reqParams << O0RequestParameter("method", "flickr.people.getLimits"); QByteArray postData = O1::createQueryParameters(reqParams); d->reply = d->requestor->post(netRequest, reqParams, postData); d->state = FE_GETMAXSIZE; m_authProgressDlg->setLabelText(i18n("Getting the maximum allowed file size.")); m_authProgressDlg->setMaximum(4); m_authProgressDlg->setValue(1); emit signalBusy(true); } void FlickrTalker::listPhotoSets() { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "List photoset invoked"; QUrl url(d->apiUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); reqParams << O0RequestParameter("method", "flickr.photosets.getList"); QByteArray postData = O1::createQueryParameters(reqParams); d->reply = d->requestor->post(netRequest, reqParams, postData); d->state = FE_LISTPHOTOSETS; emit signalBusy(true); } void FlickrTalker::getPhotoProperty(const QString& method, const QStringList& argList) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } QUrl url(d->apiUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); reqParams << O0RequestParameter("method", method.toLatin1()); for (QStringList::const_iterator it = argList.constBegin(); it != argList.constEnd(); ++it) { QStringList str = (*it).split(QLatin1Char('='), QString::SkipEmptyParts); reqParams << O0RequestParameter(str[0].toLatin1(), str[1].toLatin1()); } QByteArray postData = O1::createQueryParameters(reqParams); d->reply = d->requestor->post(netRequest, reqParams, postData); d->state = FE_GETPHOTOPROPERTY; emit signalBusy(true); } void FlickrTalker::listPhotos(const QString& /*albumName*/) { // TODO } void FlickrTalker::createPhotoSet(const QString& /*albumName*/, const QString& albumTitle, const QString& albumDescription, const QString& primaryPhotoId) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Create photoset invoked"; QUrl url(d->apiUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); reqParams << O0RequestParameter("method", "flickr.photosets.create"); reqParams << O0RequestParameter("title", albumTitle.toLatin1()); reqParams << O0RequestParameter("description", albumDescription.toLatin1()); reqParams << O0RequestParameter("primary_photo_id", primaryPhotoId.toLatin1()); QByteArray postData = O1::createQueryParameters(reqParams); d->reply = d->requestor->post(netRequest, reqParams, postData); d->state = FE_CREATEPHOTOSET; emit signalBusy(true); } void FlickrTalker::addPhotoToPhotoSet(const QString& photoId, const QString& photoSetId) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "AddPhotoToPhotoSet invoked"; /* * If the photoset id starts with the special string "UNDEFINED_", it means * it doesn't exist yet on Flickr and needs to be created. Note that it's * not necessary to subsequently add the photo to the photo set, as this * is done in the set creation call to Flickr. */ if (photoSetId.startsWith(QLatin1String("UNDEFINED_"))) { createPhotoSet(QLatin1String(""), m_selectedPhotoSet.title, m_selectedPhotoSet.description, photoId); } else { QUrl url(d->apiUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); reqParams << O0RequestParameter("method", "flickr.photosets.addPhoto"); reqParams << O0RequestParameter("photoset_id", photoSetId.toLatin1()); reqParams << O0RequestParameter("photo_id", photoId.toLatin1()); QByteArray postData = O1::createQueryParameters(reqParams); d->reply = d->requestor->post(netRequest, reqParams, postData); d->state = FE_ADDPHOTOTOPHOTOSET; emit signalBusy(true); } } bool FlickrTalker::addPhoto(const QString& photoPath, const FPhotoInfo& info, bool original, bool rescale, int maxDim, int imageQuality) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return false; } emit signalBusy(true); QUrl url(d->uploadUrl); QNetworkRequest netRequest(url); QList reqParams = QList(); QString path = photoPath; FlickrMPForm form; QString ispublic = (info.is_public == 1) ? QLatin1String("1") : QLatin1String("0"); form.addPair(QLatin1String("is_public"), ispublic, QLatin1String("text/plain")); reqParams << O0RequestParameter("is_public", ispublic.toLatin1()); QString isfamily = (info.is_family == 1) ? QLatin1String("1") : QLatin1String("0"); form.addPair(QLatin1String("is_family"), isfamily, QLatin1String("text/plain")); reqParams << O0RequestParameter("is_family", isfamily.toLatin1()); QString isfriend = (info.is_friend == 1) ? QLatin1String("1") : QLatin1String("0"); form.addPair(QLatin1String("is_friend"), isfriend, QLatin1String("text/plain")); reqParams << O0RequestParameter("is_friend", isfriend.toLatin1()); QString safetyLevel = QString::number(static_cast(info.safety_level)); form.addPair(QLatin1String("safety_level"), safetyLevel, QLatin1String("text/plain")); reqParams << O0RequestParameter("safety_level", safetyLevel.toLatin1()); QString contentType = QString::number(static_cast(info.content_type)); form.addPair(QLatin1String("content_type"), contentType, QLatin1String("text/plain")); reqParams << O0RequestParameter("content_type", contentType.toLatin1()); QString tags = QLatin1Char('"') + info.tags.join(QLatin1String("\" \"")) + QLatin1Char('"'); if (tags.length() > 0) { form.addPair(QLatin1String("tags"), tags, QLatin1String("text/plain")); reqParams << O0RequestParameter("tags", tags.toUtf8()); } if (!info.title.isEmpty()) { form.addPair(QLatin1String("title"), info.title, QLatin1String("text/plain")); reqParams << O0RequestParameter("title", info.title.toUtf8()); } if (!info.description.isEmpty()) { form.addPair(QLatin1String("description"), info.description, QLatin1String("text/plain")); reqParams << O0RequestParameter("description", info.description.toUtf8()); } if (!original) { QImage image = PreviewLoadThread::loadHighQualitySynchronously(photoPath).copyQImage(); if (image.isNull()) { image.load(photoPath); } if (!image.isNull()) { if (!d->lastTmpFile.isEmpty()) { QFile::remove(d->lastTmpFile); } path = WSToolUtils::makeTemporaryDir(d->serviceName.toLatin1().constData()).filePath(QFileInfo(photoPath) .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); d->lastTmpFile = path; // Restore all metadata. DMetadata meta; if (meta.load(photoPath)) { meta.setItemDimensions(image.size()); meta.setItemOrientation(MetaEngine::ORIENTATION_NORMAL); // NOTE: see bug #153207: Flickr use IPTC keywords to create Tags in web interface // As IPTC do not support UTF-8, we need to remove it. // This function call remove all Application2 Tags. meta.removeIptcTags(QStringList() << QLatin1String("Application2")); // NOTE: see bug # 384260: Flickr use Xmp.dc.subject to create Tags // in web interface, we need to remove it. // This function call remove all Dublin Core Tags. meta.removeXmpTags(QStringList() << QLatin1String("dc")); meta.setMetadataWritingMode((int)DMetadata::WRITE_TO_FILE_ONLY); meta.save(path, true); } else { qCWarning(DIGIKAM_WEBSERVICES_LOG) << "Flickr::Image do not have metadata"; } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Resizing and saving to temp file: " << path; } } QFileInfo tempFileInfo(path); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "QUrl path is " << QUrl::fromLocalFile(path) << "Image size (in bytes) is "<< tempFileInfo.size(); if (tempFileInfo.size() > (getMaxAllowedFileSize().toLongLong())) { emit signalAddPhotoFailed(i18n("File Size exceeds maximum allowed file size.")); emit signalBusy(false); return false; } if (!form.addFile(QLatin1String("photo"), path)) { emit signalBusy(false); return false; } form.finish(); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, form.contentType()); d->reply = d->requestor->post(netRequest, reqParams, form.formData()); d->state = FE_ADDPHOTO; return true; } void FlickrTalker::setGeoLocation(const QString& photoId, const QString& lat, const QString& lon) { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (!d->o1->linked()) { return; } QUrl url(d->apiUrl); QNetworkRequest netRequest(url); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String(O2_MIME_TYPE_XFORM)); QList reqParams = QList(); reqParams << O0RequestParameter("method", "flickr.photos.geo.setLocation"); reqParams << O0RequestParameter("photo_id", photoId.toLatin1()); reqParams << O0RequestParameter("lat", lat.toLatin1()); reqParams << O0RequestParameter("lon", lon.toLatin1()); QByteArray postData = O1::createQueryParameters(reqParams); + d->reply = d->requestor->post(netRequest, reqParams, postData); + d->state = FE_SETGEO; - d->reply = d->requestor->post(netRequest, reqParams, postData); - - d->state = FE_SETGEO; emit signalBusy(true); } QString FlickrTalker::getUserName() const { return d->username; } QString FlickrTalker::getUserId() const { return d->userId; } void FlickrTalker::cancel() { if (d->reply) { d->reply->abort(); d->reply = nullptr; } if (m_authProgressDlg && !m_authProgressDlg->isHidden()) { m_authProgressDlg->hide(); } } void FlickrTalker::slotError(const QString& error) { QString transError; int errorNo = error.toInt(); switch (errorNo) { case 2: transError = i18n("No photo specified"); break; case 3: transError = i18n("General upload failure"); break; case 4: transError = i18n("Filesize was zero"); break; case 5: transError = i18n("Filetype was not recognized"); break; case 6: transError = i18n("User exceeded upload limit"); break; case 96: transError = i18n("Invalid signature"); break; case 97: transError = i18n("Missing signature"); break; case 98: transError = i18n("Login Failed / Invalid auth token"); break; case 100: transError = i18n("Invalid API Key"); break; case 105: transError = i18n("Service currently unavailable"); break; case 108: transError = i18n("Invalid Frob"); break; case 111: transError = i18n("Format \"xxx\" not found"); break; case 112: transError = i18n("Method \"xxx\" not found"); break; case 114: transError = i18n("Invalid SOAP envelope"); break; case 115: transError = i18n("Invalid XML-RPC Method Call"); break; case 116: transError = i18n("The POST method is now required for all setters"); break; default: transError = i18n("Unknown error"); break; }; QMessageBox::critical(QApplication::activeWindow(), i18n("Error"), i18n("Error Occurred: %1\nCannot proceed any further.", transError)); } void FlickrTalker::slotFinished(QNetworkReply* reply) { emit signalBusy(false); if (reply != d->reply) { return; } d->reply = nullptr; if (reply->error() != QNetworkReply::NoError) { if (d->state == FE_ADDPHOTO) { emit signalAddPhotoFailed(reply->errorString()); } else { QMessageBox::critical(QApplication::activeWindow(), i18n("Error"), reply->errorString()); } reply->deleteLater(); + return; } QByteArray buffer = reply->readAll(); switch (d->state) { case (FE_LOGIN): - //parseResponseLogin(buffer); +/* + parseResponseLogin(buffer); +*/ break; case (FE_LISTPHOTOSETS): parseResponseListPhotoSets(buffer); break; case (FE_LISTPHOTOS): parseResponseListPhotos(buffer); break; case (FE_GETPHOTOPROPERTY): parseResponsePhotoProperty(buffer); break; case (FE_ADDPHOTO): parseResponseAddPhoto(buffer); break; case (FE_ADDPHOTOTOPHOTOSET): parseResponseAddPhotoToPhotoSet(buffer); break; case (FE_CREATEPHOTOSET): parseResponseCreatePhotoSet(buffer); break; case (FE_GETMAXSIZE): parseResponseMaxSize(buffer); break; case (FE_SETGEO): parseResponseSetGeoLocation(buffer); break; default: // FR_LOGOUT break; } reply->deleteLater(); } void FlickrTalker::parseResponseMaxSize(const QByteArray& data) { QString errorString; QDomDocument doc(QLatin1String("mydocument")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); QDomElement e; while (!node.isNull()) { - if (node.isElement() && node.nodeName() == QLatin1String("person")) + if (node.isElement() && (node.nodeName() == QLatin1String("person"))) { e = node.toElement(); QDomNode details = e.firstChild(); while (!details.isNull()) { if (details.isElement()) { e = details.toElement(); if (details.nodeName() == QLatin1String("videos")) { QDomAttr a = e.attributeNode(QLatin1String("maxupload")); d->maxSize = a.value(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Max upload size is"<maxSize; } } details = details.nextSibling(); } } - if (node.isElement() && node.nodeName() == QLatin1String("err")) + if (node.isElement() && (node.nodeName() == QLatin1String("err"))) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Checking Error in response"; errorString = node.toElement().attribute(QLatin1String("code")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error code=" << errorString; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Msg=" << node.toElement().attribute(QLatin1String("msg")); } node = node.nextSibling(); } m_authProgressDlg->hide(); } void FlickrTalker::parseResponseCreatePhotoSet(const QByteArray& data) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Parse response create photoset received " << data; //bool success = false; QDomDocument doc(QLatin1String("getListPhotoSets")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); QDomElement e; while (!node.isNull()) { - if (node.isElement() && node.nodeName() == QLatin1String("photoset")) + if (node.isElement() && (node.nodeName() == QLatin1String("photoset"))) { // Parse the id from the response. QString new_id = node.toElement().attribute(QLatin1String("id")); // Set the new id in the photo sets list. QLinkedList::iterator it = m_photoSetsList->begin(); while (it != m_photoSetsList->end()) { if (it->id == m_selectedPhotoSet.id) { it->id = new_id; break; } ++it; } // Set the new id in the selected photo set. m_selectedPhotoSet.id = new_id; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "PhotoSet created successfully with id" << new_id; emit signalAddPhotoSetSucceeded(); } - if (node.isElement() && node.nodeName() == QLatin1String("err")) + if (node.isElement() && (node.nodeName() == QLatin1String("err"))) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Checking Error in response"; QString code = node.toElement().attribute(QLatin1String("code")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error code=" << code; - QString msg = node.toElement().attribute(QLatin1String("msg")); + QString msg = node.toElement().attribute(QLatin1String("msg")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Msg=" << msg; QMessageBox::critical(QApplication::activeWindow(), i18n("Error"), i18n("PhotoSet creation failed: ") + msg); } node = node.nextSibling(); } } void FlickrTalker::parseResponseListPhotoSets(const QByteArray& data) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "parseResponseListPhotosets" << data; bool success = false; QDomDocument doc(QLatin1String("getListPhotoSets")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); QDomElement e; QString photoSet_id, photoSet_title, photoSet_description; m_photoSetsList->clear(); while (!node.isNull()) { - if (node.isElement() && node.nodeName() == QLatin1String("photosets")) + if (node.isElement() && (node.nodeName() == QLatin1String("photosets"))) { e = node.toElement(); QDomNode details = e.firstChild(); FPhotoSet fps; QDomNode detailsNode = details; while (!detailsNode.isNull()) { if (detailsNode.isElement()) { e = detailsNode.toElement(); if (detailsNode.nodeName() == QLatin1String("photoset")) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "id=" << e.attribute(QLatin1String("id")); photoSet_id = e.attribute(QLatin1String("id")); // this is what is obtained from data. fps.id = photoSet_id; QDomNode photoSetDetails = detailsNode.firstChild(); QDomElement e_detail; while (!photoSetDetails.isNull()) { e_detail = photoSetDetails.toElement(); if (photoSetDetails.nodeName() == QLatin1String("title")) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Title=" << e_detail.text(); photoSet_title = e_detail.text(); fps.title = photoSet_title; } else if (photoSetDetails.nodeName() == QLatin1String("description")) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Description =" << e_detail.text(); photoSet_description = e_detail.text(); fps.description = photoSet_description; } photoSetDetails = photoSetDetails.nextSibling(); } m_photoSetsList->append(fps); } } detailsNode = detailsNode.nextSibling(); } details = details.nextSibling(); success = true; } - if (node.isElement() && node.nodeName() == QLatin1String("err")) + if (node.isElement() && (node.nodeName() == QLatin1String("err"))) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Checking Error in response"; QString code = node.toElement().attribute(QLatin1String("code")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error code=" << code; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Msg=" << node.toElement().attribute(QLatin1String("msg")); emit signalError(code); } node = node.nextSibling(); } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "GetPhotoList finished"; if (!success) { emit signalListPhotoSetsFailed(i18n("Failed to fetch list of photo sets.")); } else { emit signalListPhotoSetsSucceeded(); maxAllowedFileSize(); } } void FlickrTalker::parseResponseListPhotos(const QByteArray& data) { QDomDocument doc(QLatin1String("getPhotosList")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); + //QDomElement e; //TODO } void FlickrTalker::parseResponseCreateAlbum(const QByteArray& data) { QDomDocument doc(QLatin1String("getCreateAlbum")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); //TODO } void FlickrTalker::parseResponseAddPhoto(const QByteArray& data) { bool success = false; QString line; QDomDocument doc(QLatin1String("AddPhoto Response")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); QDomElement e; QString photoId; while (!node.isNull()) { - if (node.isElement() && node.nodeName() == QLatin1String("photoid")) + if (node.isElement() && (node.nodeName() == QLatin1String("photoid"))) { e = node.toElement(); // try to convert the node to an element. QDomNode details = e.firstChild(); photoId = e.text(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Photoid= " << photoId; success = true; } - if (node.isElement() && node.nodeName() == QLatin1String("err")) + if (node.isElement() && (node.nodeName() == QLatin1String("err"))) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Checking Error in response"; QString code = node.toElement().attribute(QLatin1String("code")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error code=" << code; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Msg=" << node.toElement().attribute(QLatin1String("msg")); emit signalError(code); } node = node.nextSibling(); } if (!success) { emit signalAddPhotoFailed(i18n("Failed to upload photo")); } else { QString photoSetId = m_selectedPhotoSet.id; if (photoSetId == QLatin1String("-1")) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "PhotoSet Id not set, not adding the photo to any photoset"; emit signalAddPhotoSucceeded(photoId); } else { addPhotoToPhotoSet(photoId, photoSetId); } } } void FlickrTalker::parseResponsePhotoProperty(const QByteArray& data) { bool success = false; QString line; QDomDocument doc(QLatin1String("Photos Properties")); if (!doc.setContent(data)) { return; } QDomElement docElem = doc.documentElement(); QDomNode node = docElem.firstChild(); QDomElement e; while (!node.isNull()) { - if (node.isElement() && node.nodeName() == QLatin1String("photoid")) + if (node.isElement() && (node.nodeName() == QLatin1String("photoid"))) { e = node.toElement(); // try to convert the node to an element. QDomNode details = e.firstChild(); success = true; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Photoid=" << e.text(); } - if (node.isElement() && node.nodeName() == QLatin1String("err")) + if (node.isElement() && (node.nodeName() == QLatin1String("err"))) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Checking Error in response"; QString code = node.toElement().attribute(QLatin1String("code")); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error code=" << code; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Msg=" << node.toElement().attribute(QLatin1String("msg")); emit signalError(code); } node = node.nextSibling(); } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "GetToken finished"; if (!success) { emit signalAddPhotoFailed(i18n("Failed to query photo information")); } else { emit signalAddPhotoSucceeded(QLatin1String("")); } } void FlickrTalker::parseResponseAddPhotoToPhotoSet(const QByteArray& data) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "parseResponseListPhotosets" << data; emit signalAddPhotoSucceeded(QLatin1String("")); } void FlickrTalker::parseResponseSetGeoLocation(const QByteArray& data) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "parseResponseSetGeoLocation" << data; emit signalAddPhotoSucceeded(QLatin1String("")); } } // namespace DigikamGenericFlickrPlugin diff --git a/core/dplugins/generic/webservices/flickr/flickrtalker.h b/core/dplugins/generic/webservices/flickr/flickrtalker.h index 1a647f7453..58db65ac55 100644 --- a/core/dplugins/generic/webservices/flickr/flickrtalker.h +++ b/core/dplugins/generic/webservices/flickr/flickrtalker.h @@ -1,150 +1,151 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-07-07 * Description : a tool to export images to Flickr web service * * Copyright (C) 2005-2009 by Vardhman Jain * Copyright (C) 2009-2020 by Gilles Caulier * Copyright (C) 2017-2019 by Maik Qualmann * * 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_FLICKR_TALKER_H #define DIGIKAM_FLICKR_TALKER_H // Qt includes #include #include #include #include #include #include // Local includes #include "dinfointerface.h" #include "flickritem.h" class QProgressDialog; using namespace Digikam; namespace DigikamGenericFlickrPlugin { class FPhotoInfo; class FPhotoSet; class FlickrTalker : public QObject { Q_OBJECT public: enum State { FE_LOGOUT = -1, FE_LOGIN = 0, FE_LISTPHOTOSETS, FE_LISTPHOTOS, FE_GETPHOTOPROPERTY, FE_ADDPHOTO, FE_CREATEPHOTOSET, FE_ADDPHOTOTOPHOTOSET, FE_GETMAXSIZE, FE_SETGEO }; public: explicit FlickrTalker(QWidget* const parent, const QString& serviceName, DInfoInterface* const iface); ~FlickrTalker(); void link(const QString& userName); void unLink(); void removeUserName(const QString& userName); QString getUserName() const; QString getUserId() const; void maxAllowedFileSize(); QString getMaxAllowedFileSize(); void getPhotoProperty(const QString& method, const QStringList& argList); void cancel(); void listPhotoSets(); void listPhotos(const QString& albumName); void createPhotoSet(const QString& name, const QString& title, const QString& desc, const QString& primaryPhotoId); void addPhotoToPhotoSet(const QString& photoId, const QString& photoSetId); bool addPhoto(const QString& photoPath, const FPhotoInfo& info, bool original = false, bool rescale = false, int maxDim = 600, int imageQuality = 85); void setGeoLocation(const QString& photoId, const QString& lat, const QString& lon); public: QProgressDialog* m_authProgressDlg; QLinkedList * m_photoSetsList; FPhotoSet m_selectedPhotoSet; Q_SIGNALS: void signalError(const QString& msg); void signalBusy(bool val); void signalAddPhotoSucceeded(const QString&); void signalAddPhotoSetSucceeded(); void signalListPhotoSetsSucceeded(); void signalListPhotoSetsFailed(QString& msg); void signalAddPhotoFailed(const QString& msg); void signalListPhotoSetsFailed(const QString& msg); void signalLinkingSucceeded(); private: + /* void parseResponseLogin(const QByteArray& data); */ void parseResponseMaxSize(const QByteArray& data); void parseResponseListPhotoSets(const QByteArray& data); void parseResponseListPhotos(const QByteArray& data); void parseResponseCreateAlbum(const QByteArray& data); void parseResponseAddPhoto(const QByteArray& data); void parseResponsePhotoProperty(const QByteArray& data); void parseResponseCreatePhotoSet(const QByteArray& data); void parseResponseAddPhotoToPhotoSet(const QByteArray& data); void parseResponseSetGeoLocation(const QByteArray& data); private Q_SLOTS: void slotLinkingFailed(); void slotLinkingSucceeded(); void slotCatchUrl(const QUrl& url); void slotOpenBrowser(const QUrl& url); void slotError(const QString& msg); void slotFinished(QNetworkReply* reply); private: class Private; Private* const d; }; } // namespace DigikamGenericFlickrPlugin #endif // DIGIKAM_FLICKR_TALKER_H diff --git a/core/dplugins/generic/webservices/flickr/flickrwidget.cpp b/core/dplugins/generic/webservices/flickr/flickrwidget.cpp index 20cb4e7b9e..731e38e9b7 100644 --- a/core/dplugins/generic/webservices/flickr/flickrwidget.cpp +++ b/core/dplugins/generic/webservices/flickr/flickrwidget.cpp @@ -1,523 +1,523 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-07-07 * Description : a tool to export images to Flickr web service * * Copyright (C) 2005-2008 by Vardhman Jain * Copyright (C) 2008-2020 by Gilles Caulier * Copyright (C) 2009 by Luka Renko * * 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 "flickrwidget_p.h" namespace DigikamGenericFlickrPlugin { FlickrWidget::FlickrWidget(QWidget* const parent, DInfoInterface* const iface, const QString& serviceName) : WSSettingsWidget(parent, iface, serviceName), d(new Private) { d->serviceName = serviceName; // Adding Remove Account button d->removeAccount = new QPushButton(getAccountBox()); d->removeAccount->setText(i18n("Remove Account")); getAccountBoxLayout()->addWidget(d->removeAccount, 2, 0, 1, 4); // -- The image list -------------------------------------------------- d->imglst = new FlickrList(this); // For figuring out the width of the permission columns. QHeaderView* const hdr = d->imglst->listView()->header(); QFontMetrics hdrFont = QFontMetrics(hdr->font()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) int permColWidth = hdrFont.horizontalAdvance(i18nc("photo permissions", "Public")); #else int permColWidth = hdrFont.width(i18nc("photo permissions", "Public")); #endif d->imglst->setAllowRAW(true); d->imglst->setIface(iface); d->imglst->loadImagesFromCurrentSelection(); d->imglst->listView()->setWhatsThis(i18n("This is the list of images to upload to your Flickr account.")); d->imglst->listView()->setColumn(static_cast(FlickrList::PUBLIC), i18nc("photo permissions", "Public"), true); // Handle extra tags per image. d->imglst->listView()->setColumn(static_cast(FlickrList::TAGS), i18n("Extra tags"), true); int tmpWidth; #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) if ((tmpWidth = hdrFont.horizontalAdvance(i18nc("photo permissions", "Family"))) > permColWidth) #else if ((tmpWidth = hdrFont.width(i18nc("photo permissions", "Family"))) > permColWidth) #endif { permColWidth = tmpWidth; } #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) if ((tmpWidth = hdrFont.horizontalAdvance(i18nc("photo permissions", "Friends"))) > permColWidth) #else if ((tmpWidth = hdrFont.width(i18nc("photo permissions", "Friends"))) > permColWidth) #endif { permColWidth = tmpWidth; } d->imglst->listView()->setColumn(static_cast(FlickrList::FAMILY), i18nc("photo permissions", "Family"), true); d->imglst->listView()->setColumn(static_cast(FlickrList::FRIENDS), i18nc("photo permissions", "Friends"), true); hdr->setSectionResizeMode(FlickrList::FAMILY, QHeaderView::Interactive); hdr->setSectionResizeMode(FlickrList::FRIENDS, QHeaderView::Interactive); hdr->resizeSection(FlickrList::FAMILY, permColWidth); hdr->resizeSection(FlickrList::FRIENDS, permColWidth); d->imglst->listView()->setColumn(static_cast(FlickrList::SAFETYLEVEL), i18n("Safety level"), true); d->imglst->listView()->setColumn(static_cast(FlickrList::CONTENTTYPE), i18n("Content type"), true); QMap safetyLevelItems; QMap contentTypeItems; safetyLevelItems[FlickrList::SAFE] = i18nc("photo safety level", "Safe"); safetyLevelItems[FlickrList::MODERATE] = i18nc("photo safety level", "Moderate"); safetyLevelItems[FlickrList::RESTRICTED] = i18nc("photo safety level", "Restricted"); contentTypeItems[FlickrList::PHOTO] = i18nc("photo content type", "Photo"); contentTypeItems[FlickrList::SCREENSHOT] = i18nc("photo content type", "Screenshot"); contentTypeItems[FlickrList::OTHER] = i18nc("photo content type", "Other"); ComboBoxDelegate* const safetyLevelDelegate = new ComboBoxDelegate(d->imglst, safetyLevelItems); ComboBoxDelegate* const contentTypeDelegate = new ComboBoxDelegate(d->imglst, contentTypeItems); d->imglst->listView()->setItemDelegateForColumn(static_cast(FlickrList::SAFETYLEVEL), safetyLevelDelegate); d->imglst->listView()->setItemDelegateForColumn(static_cast(FlickrList::CONTENTTYPE), contentTypeDelegate); hdr->setSectionResizeMode(FlickrList::PUBLIC, QHeaderView::Interactive); hdr->resizeSection(FlickrList::PUBLIC, permColWidth); // -- Show upload original image CheckBox---------------------------------- getOriginalCheckBox()->show(); // -- Layout for the tags ------------------------------------------------- QGroupBox* const tagsBox = new QGroupBox(i18n("Tag options"), getSettingsBox()); QGridLayout* const tagsBoxLayout = new QGridLayout(tagsBox); d->exportHostTagsCheckBox = new QCheckBox(tagsBox); d->exportHostTagsCheckBox->setText(i18n("Use Host Application Tags")); d->extendedTagsButton = new QPushButton(i18n("More tag options")); d->extendedTagsButton->setCheckable(true); // Initialize this button to checked, so extended options are shown. // FlickrWindow::readSettings can change this, but if checked is false it // cannot uncheck and subsequently hide the extended options (the toggled // signal won't be emitted). d->extendedTagsButton->setChecked(true); d->extendedTagsButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); d->extendedTagsBox = new QGroupBox(QLatin1String(""), getSettingsBox()); d->extendedTagsBox->setFlat(true); QGridLayout* extendedTagsLayout = new QGridLayout(d->extendedTagsBox); QLabel* const tagsLabel = new QLabel(i18n("Added Tags: "), d->extendedTagsBox); d->tagsLineEdit = new QLineEdit(d->extendedTagsBox); d->tagsLineEdit->setToolTip(i18n("Enter new tags here, separated by commas.")); d->addExtraTagsCheckBox = new QCheckBox(d->extendedTagsBox); d->addExtraTagsCheckBox->setText(i18n("Add tags per image")); d->addExtraTagsCheckBox->setToolTip(i18n("If checked, you can set extra tags for " "each image in the File List tab")); d->addExtraTagsCheckBox->setChecked(true); d->stripSpaceTagsCheckBox = new QCheckBox(d->extendedTagsBox); d->stripSpaceTagsCheckBox->setText(i18n("Strip Spaces From Tags")); extendedTagsLayout->addWidget(tagsLabel, 0, 0); extendedTagsLayout->addWidget(d->tagsLineEdit, 0, 1); extendedTagsLayout->addWidget(d->stripSpaceTagsCheckBox, 1, 0, 1, 2); extendedTagsLayout->addWidget(d->addExtraTagsCheckBox, 2, 0, 1, 2); tagsBoxLayout->addWidget(d->exportHostTagsCheckBox, 0, 0); tagsBoxLayout->addWidget(d->extendedTagsButton, 0, 1); tagsBoxLayout->addWidget(d->extendedTagsBox, 1, 0, 1, 2); // -- Layout for the publication options ---------------------------------- QGroupBox* const publicationBox = new QGroupBox(i18n("Publication Options"), getSettingsBox()); QGridLayout* const publicationBoxLayout = new QGridLayout; publicationBox->setLayout(publicationBoxLayout); d->publicCheckBox = new QCheckBox(publicationBox); d->publicCheckBox->setText(i18nc("As in accessible for people", "Public (anyone can see them)")); d->familyCheckBox = new QCheckBox(publicationBox); d->familyCheckBox->setText(i18n("Visible to Family")); d->friendsCheckBox = new QCheckBox(publicationBox); d->friendsCheckBox->setText(i18n("Visible to Friends")); // Extended publication settings d->extendedPublicationButton = new QPushButton(i18n("More publication options")); d->extendedPublicationButton->setCheckable(true); // Initialize this button to checked, so extended options are shown. // FlickrWindow::readSettings can change this, but if checked is false it // cannot uncheck and subsequently hide the extended options (the toggled // signal won't be emitted). d->extendedPublicationButton->setChecked(true); d->extendedPublicationButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); d->extendedPublicationBox = new QGroupBox(QLatin1String(""), publicationBox); d->extendedPublicationBox->setFlat(true); QGridLayout* const extendedSettingsLayout = new QGridLayout(d->extendedPublicationBox); QLabel* const imageSafetyLabel = new QLabel(i18n("Safety level:")); d->safetyLevelComboBox = new WSComboBoxIntermediate(); d->safetyLevelComboBox->addItem(i18n("Safe"), QVariant(FlickrList::SAFE)); d->safetyLevelComboBox->addItem(i18n("Moderate"), QVariant(FlickrList::MODERATE)); d->safetyLevelComboBox->addItem(i18n("Restricted"), QVariant(FlickrList::RESTRICTED)); QLabel* const imageTypeLabel = new QLabel(i18n("Content type:")); d->contentTypeComboBox = new WSComboBoxIntermediate(); d->contentTypeComboBox->addItem(i18nc("photo content type", "Photo"), QVariant(FlickrList::PHOTO)); d->contentTypeComboBox->addItem(i18nc("photo content type", "Screenshot"), QVariant(FlickrList::SCREENSHOT)); d->contentTypeComboBox->addItem(i18nc("photo content type", "Other"), QVariant(FlickrList::OTHER)); extendedSettingsLayout->addWidget(imageSafetyLabel, 1, 0, Qt::AlignLeft); extendedSettingsLayout->addWidget(d->safetyLevelComboBox, 1, 1, Qt::AlignLeft); extendedSettingsLayout->addWidget(imageTypeLabel, 0, 0, Qt::AlignLeft); extendedSettingsLayout->addWidget(d->contentTypeComboBox, 0, 1, Qt::AlignLeft); extendedSettingsLayout->setColumnStretch(0, 0); extendedSettingsLayout->setColumnStretch(1, 1); publicationBoxLayout->addWidget(d->publicCheckBox, 0, 0); publicationBoxLayout->addWidget(d->familyCheckBox, 1, 0); publicationBoxLayout->addWidget(d->friendsCheckBox, 2, 0); publicationBoxLayout->addWidget(d->extendedPublicationButton, 2, 1); publicationBoxLayout->addWidget(d->extendedPublicationBox, 3, 0, 1, 2); // -- Add these extra widgets to settings box ------------------------------------------------- addWidgetToSettingsBox(publicationBox); addWidgetToSettingsBox(tagsBox); // hiding widgets not required. getUploadBox()->hide(); getSizeBox()->hide(); // Removing DItemsList inherited from WSSettingsWidget and replacing it with more specific FlickrList replaceImageList(d->imglst); updateLabels(); connect(d->imglst, SIGNAL(signalPermissionChanged(FlickrList::FieldType,Qt::CheckState)), this, SLOT(slotPermissionChanged(FlickrList::FieldType,Qt::CheckState))); connect(d->publicCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotMainPublicToggled(int))); connect(d->extendedTagsButton, SIGNAL(toggled(bool)), this, SLOT(slotExtendedTagsToggled(bool))); connect(d->addExtraTagsCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotAddExtraTagsToggled(bool))); connect(d->familyCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotMainFamilyToggled(int))); connect(d->friendsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotMainFriendsToggled(int))); connect(d->safetyLevelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotMainSafetyLevelChanged(int))); connect(d->contentTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotMainContentTypeChanged(int))); connect(d->extendedPublicationButton, SIGNAL(toggled(bool)), this, SLOT(slotExtendedPublicationToggled(bool))); connect(d->imglst, SIGNAL(signalSafetyLevelChanged(FlickrList::SafetyLevel)), this, SLOT(slotSafetyLevelChanged(FlickrList::SafetyLevel))); connect(d->imglst, SIGNAL(signalContentTypeChanged(FlickrList::ContentType)), this, SLOT(slotContentTypeChanged(FlickrList::ContentType))); } FlickrWidget::~FlickrWidget() { delete d; } void FlickrWidget::updateLabels(const QString& /*name*/, const QString& /*url*/) { getHeaderLbl()->setText(i18n("

" "flick" "r" " Export" "

")); } void FlickrWidget::slotPermissionChanged(FlickrList::FieldType checkbox, Qt::CheckState state) { /* * Slot for handling the signal from the FlickrList that the general * permissions have changed, considering the clicks in the checkboxes next * to each image. In response, the main permission checkboxes should be set * to the proper state. * The checkbox variable determines which of the checkboxes should be * changed. */ // Select the proper checkbox. QCheckBox* currBox = nullptr; if (checkbox == FlickrList::PUBLIC) { currBox = d->publicCheckBox; } else if (checkbox == FlickrList::FAMILY) { currBox = d->familyCheckBox; } else { currBox = d->friendsCheckBox; } // If the checkbox should be set in the intermediate state, the tristate // property of the checkbox should be manually set to true, otherwise, it // has to be set to false so that the user cannot select it. currBox->setCheckState(state); if ((state == Qt::Checked) || (state == Qt::Unchecked)) { currBox->setTristate(false); } else { currBox->setTristate(true); } } void FlickrWidget::slotSafetyLevelChanged(FlickrList::SafetyLevel safetyLevel) { /* * Called when the general safety level of the FlickrList has changed, * considering the individual comboboxes next to the photos. Used to set the * main safety level combobox appropriately. */ if (safetyLevel == FlickrList::MIXEDLEVELS) { d->safetyLevelComboBox->setIntermediate(true); } else { int index = d->safetyLevelComboBox->findData(QVariant(static_cast(safetyLevel))); d->safetyLevelComboBox->setCurrentIndex(index); } } void FlickrWidget::slotContentTypeChanged(FlickrList::ContentType contentType) { /* * Called when the general content type of the FlickrList has changed, * considering the individual comboboxes next to the photos. Used to set the * main content type combobox appropriately. */ if (contentType == FlickrList::MIXEDTYPES) { d->contentTypeComboBox->setIntermediate(true); } else { int index = d->contentTypeComboBox->findData(QVariant(static_cast(contentType))); d->contentTypeComboBox->setCurrentIndex(index); } } void FlickrWidget::slotMainPublicToggled(int state) { mainPermissionToggled(FlickrList::PUBLIC, static_cast(state)); } void FlickrWidget::slotMainFamilyToggled(int state) { mainPermissionToggled(FlickrList::FAMILY, static_cast(state)); } void FlickrWidget::slotMainFriendsToggled(int state) { mainPermissionToggled(FlickrList::FRIENDS, static_cast(state)); } void FlickrWidget::mainPermissionToggled(FlickrList::FieldType checkbox, Qt::CheckState state) { /* * Callback for when one of the main permission checkboxes is toggled. * checkbox specifies which of the checkboxes is toggled. */ if (state != Qt::PartiallyChecked) { // Set the states for the image list. if (checkbox == FlickrList::PUBLIC) { d->imglst->setPublic(state); } else if (checkbox == FlickrList::FAMILY) { d->imglst->setFamily(state); } else if (checkbox == FlickrList::FRIENDS) { d->imglst->setFriends(state); } // Dis- or enable the family and friends checkboxes if the public // checkbox is clicked. if (checkbox == 0) { if (state == Qt::Checked) { d->familyCheckBox->setEnabled(false); d->friendsCheckBox->setEnabled(false); } else if (state == Qt::Unchecked) { d->familyCheckBox->setEnabled(true); d->friendsCheckBox->setEnabled(true); } } // Set the main checkbox tristate state to false, so that the user // cannot select the intermediate state. if (checkbox == FlickrList::PUBLIC) { d->publicCheckBox->setTristate(false); } else if (checkbox == FlickrList::FAMILY) { d->familyCheckBox->setTristate(false); } else if (checkbox == FlickrList::FRIENDS) { d->friendsCheckBox->setTristate(false); } } } void FlickrWidget::slotMainSafetyLevelChanged(int index) { int currValue = (d->safetyLevelComboBox->itemData(index)).value(); - -// int currValue = qVariantValue(d->safetyLevelComboBox->itemData(index)); - +/* + int currValue = qVariantValue(d->safetyLevelComboBox->itemData(index)); +*/ d->imglst->setSafetyLevels(static_cast(currValue)); } void FlickrWidget::slotMainContentTypeChanged(int index) { int currValue = (d->contentTypeComboBox->itemData(index)).value(); - -// int currValue = qVariantValue(d->contentTypeComboBox->itemData(index)); - +/* + int currValue = qVariantValue(d->contentTypeComboBox->itemData(index)); +*/ d->imglst->setContentTypes(static_cast(currValue)); } void FlickrWidget::slotExtendedPublicationToggled(bool status) { // Show or hide the extended settings when the extended settings button // is toggled. d->extendedPublicationBox->setVisible(status); d->imglst->listView()->setColumnHidden(FlickrList::SAFETYLEVEL, !status); d->imglst->listView()->setColumnHidden(FlickrList::CONTENTTYPE, !status); if (status) { d->extendedPublicationButton->setText(i18n("Fewer publication options")); } else { d->extendedPublicationButton->setText(i18n("More publication options")); } } void FlickrWidget::slotExtendedTagsToggled(bool status) { // Show or hide the extended tag settings when the extended tag option // button is toggled. d->extendedTagsBox->setVisible(status); if (!status) { d->imglst->listView()->setColumnHidden(FlickrList::TAGS, true); d->extendedTagsButton->setText(i18n("More tag options")); } else { d->imglst->listView()->setColumnHidden(FlickrList::TAGS, !d->addExtraTagsCheckBox->isChecked()); d->extendedTagsButton->setText(i18n("Fewer tag options")); } } void FlickrWidget::slotAddExtraTagsToggled(bool status) { if (d->extendedTagsButton->isChecked()) { d->imglst->listView()->setColumnHidden(FlickrList::TAGS, !status); } } } // namespace DigikamGenericFlickrPlugin diff --git a/core/dplugins/generic/webservices/flickr/flickrwindow.cpp b/core/dplugins/generic/webservices/flickr/flickrwindow.cpp index a4d278c02e..91f7167f71 100644 --- a/core/dplugins/generic/webservices/flickr/flickrwindow.cpp +++ b/core/dplugins/generic/webservices/flickr/flickrwindow.cpp @@ -1,911 +1,911 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-17-06 * Description : a tool to export images to Flickr web service * * Copyright (C) 2005-2008 by Vardhman Jain * Copyright (C) 2008-2020 by Gilles Caulier * Copyright (C) 2009 by Luka Renko * * 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 "flickrwindow.h" // Qt includes #include #include #include #include #include #include #include #include #include #include #include // KDE includes #include #include // Local includes #include "dprogresswdg.h" #include "flickrtalker.h" #include "flickritem.h" #include "flickrlist.h" #include "wsselectuserdlg.h" #include "digikam_debug.h" #include "flickrnewalbumdlg.h" #include "previewloadthread.h" #include "flickrwidget_p.h" namespace DigikamGenericFlickrPlugin { class Q_DECL_HIDDEN FlickrWindow::Private { public: explicit Private() : uploadCount(0), uploadTotal(0), newAlbumBtn(nullptr), changeUserButton(nullptr), removeAccount(nullptr), albumsListComboBox(nullptr), publicCheckBox(nullptr), familyCheckBox(nullptr), friendsCheckBox(nullptr), exportHostTagsCheckBox(nullptr), stripSpaceTagsCheckBox(nullptr), addExtraTagsCheckBox(nullptr), originalCheckBox(nullptr), resizeCheckBox(nullptr), dimensionSpinBox(nullptr), imageQualitySpinBox(nullptr), extendedPublicationButton(nullptr), extendedTagsButton(nullptr), contentTypeComboBox(nullptr), safetyLevelComboBox(nullptr), userNameDisplayLabel(nullptr), authProgressDlg(nullptr), tagsLineEdit(nullptr), widget(nullptr), talker(nullptr), imglst(nullptr), select(nullptr), albumDlg(nullptr), iface(nullptr) { } unsigned int uploadCount; unsigned int uploadTotal; QString serviceName; QPushButton* newAlbumBtn; QPushButton* changeUserButton; QPushButton* removeAccount; QComboBox* albumsListComboBox; QCheckBox* publicCheckBox; QCheckBox* familyCheckBox; QCheckBox* friendsCheckBox; QCheckBox* exportHostTagsCheckBox; QCheckBox* stripSpaceTagsCheckBox; QCheckBox* addExtraTagsCheckBox; QCheckBox* originalCheckBox; QCheckBox* resizeCheckBox; QSpinBox* dimensionSpinBox; QSpinBox* imageQualitySpinBox; QPushButton* extendedPublicationButton; QPushButton* extendedTagsButton; WSComboBoxIntermediate* contentTypeComboBox; WSComboBoxIntermediate* safetyLevelComboBox; QString username; QString userId; QString lastSelectedAlbum; QLabel* userNameDisplayLabel; QProgressDialog* authProgressDlg; QList< QPair > uploadQueue; QLineEdit* tagsLineEdit; FlickrWidget* widget; FlickrTalker* talker; FlickrList* imglst; WSSelectUserDlg* select; FlickrNewAlbumDlg* albumDlg; DInfoInterface* iface; }; FlickrWindow::FlickrWindow(DInfoInterface* const iface, QWidget* const /*parent*/, const QString& serviceName) : WSToolDialog(nullptr, QString::fromLatin1("%1Export Dialog").arg(serviceName)), d(new Private) { d->iface = iface; d->serviceName = serviceName; setWindowTitle(i18n("Export to %1 Web Service", d->serviceName)); setModal(false); KConfig config; KConfigGroup grp = config.group(QString::fromLatin1("%1Export Settings").arg(d->serviceName)); if (grp.exists()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << QString::fromLatin1("%1Export Settings").arg(d->serviceName) << " exists, deleting it"; grp.deleteGroup(); } d->select = new WSSelectUserDlg(nullptr, serviceName); d->uploadCount = 0; d->uploadTotal = 0; d->widget = new FlickrWidget(this, iface, serviceName); d->albumDlg = new FlickrNewAlbumDlg(this, QLatin1String("Flickr")); d->albumsListComboBox = d->widget->getAlbumsCoB(); d->newAlbumBtn = d->widget->getNewAlbmBtn(); d->originalCheckBox = d->widget->getOriginalCheckBox(); d->resizeCheckBox = d->widget->getResizeCheckBox(); d->publicCheckBox = d->widget->d->publicCheckBox; d->familyCheckBox = d->widget->d->familyCheckBox; d->friendsCheckBox = d->widget->d->friendsCheckBox; d->dimensionSpinBox = d->widget->getDimensionSpB(); d->imageQualitySpinBox = d->widget->getImgQualitySpB(); d->extendedTagsButton = d->widget->d->extendedTagsButton; d->addExtraTagsCheckBox = d->widget->d->addExtraTagsCheckBox; d->extendedPublicationButton = d->widget->d->extendedPublicationButton; d->safetyLevelComboBox = d->widget->d->safetyLevelComboBox; d->contentTypeComboBox = d->widget->d->contentTypeComboBox; d->tagsLineEdit = d->widget->d->tagsLineEdit; d->exportHostTagsCheckBox = d->widget->d->exportHostTagsCheckBox; d->stripSpaceTagsCheckBox = d->widget->d->stripSpaceTagsCheckBox; d->changeUserButton = d->widget->getChangeUserBtn(); d->removeAccount = d->widget->d->removeAccount; d->userNameDisplayLabel = d->widget->getUserNameLabel(); d->imglst = d->widget->d->imglst; startButton()->setText(i18n("Start Uploading")); startButton()->setToolTip(QString()); setMainWidget(d->widget); d->widget->setMinimumSize(800, 600); connect(d->imglst, SIGNAL(signalImageListChanged()), this, SLOT(slotImageListChanged())); // -------------------------------------------------------------------------- d->talker = new FlickrTalker(this, serviceName, d->iface); connect(d->talker, SIGNAL(signalError(QString)), d->talker, SLOT(slotError(QString))); connect(d->talker, SIGNAL(signalBusy(bool)), this, SLOT(slotBusy(bool))); connect(d->talker, SIGNAL(signalAddPhotoSucceeded(QString)), this, SLOT(slotAddPhotoSucceeded(QString))); connect(d->talker, SIGNAL(signalAddPhotoFailed(QString)), this, SLOT(slotAddPhotoFailed(QString))); connect(d->talker, SIGNAL(signalAddPhotoSetSucceeded()), this, SLOT(slotAddPhotoSetSucceeded())); connect(d->talker, SIGNAL(signalListPhotoSetsSucceeded()), this, SLOT(slotPopulatePhotoSetComboBox())); connect(d->talker, SIGNAL(signalListPhotoSetsFailed(QString)), this, SLOT(slotListPhotoSetsFailed(QString))); connect(d->talker, SIGNAL(signalLinkingSucceeded()), this, SLOT(slotLinkingSucceeded())); connect(d->widget->progressBar(), SIGNAL(signalProgressCanceled()), this, SLOT(slotAddPhotoCancelAndClose())); connect(d->widget->getReloadBtn(), SIGNAL(clicked()), this, SLOT(slotReloadPhotoSetRequest())); // -------------------------------------------------------------------------- connect(d->changeUserButton, SIGNAL(clicked()), this, SLOT(slotUserChangeRequest())); connect(d->removeAccount, SIGNAL(clicked()), this, SLOT(slotRemoveAccount())); connect(d->newAlbumBtn, SIGNAL(clicked()), this, SLOT(slotCreateNewPhotoSet())); // -------------------------------------------------------------------------- d->authProgressDlg = new QProgressDialog(this); d->authProgressDlg->setModal(true); d->authProgressDlg->setAutoReset(true); d->authProgressDlg->setAutoClose(true); d->authProgressDlg->setMaximum(0); d->authProgressDlg->reset(); connect(d->authProgressDlg, SIGNAL(canceled()), this, SLOT(slotAuthCancel())); d->talker->m_authProgressDlg = d->authProgressDlg; // -------------------------------------------------------------------------- connect(this, &QDialog::finished, this, &FlickrWindow::slotFinished); connect(this, SIGNAL(cancelClicked()), this, SLOT(slotCancelClicked())); connect(startButton(), &QPushButton::clicked, this, &FlickrWindow::slotUser1); d->select->reactivate(); readSettings(d->select->getUserName()); d->talker->link(d->select->getUserName()); } FlickrWindow::~FlickrWindow() { delete d->select; delete d->authProgressDlg; delete d->talker; delete d->widget; delete d; } void FlickrWindow::setItemsList(const QList& urls) { d->widget->imagesList()->slotAddImages(urls); } void FlickrWindow::closeEvent(QCloseEvent* e) { if (!e) { return; } slotFinished(); e->accept(); } void FlickrWindow::slotFinished() { writeSettings(); d->imglst->listView()->clear(); } void FlickrWindow::setUiInProgressState(bool inProgress) { setRejectButtonMode(inProgress ? QDialogButtonBox::Cancel : QDialogButtonBox::Close); if (inProgress) { d->widget->progressBar()->show(); } else { d->widget->progressBar()->hide(); d->widget->progressBar()->progressCompleted(); } } void FlickrWindow::slotCancelClicked() { d->talker->cancel(); d->uploadQueue.clear(); setUiInProgressState(false); } void FlickrWindow::slotAddPhotoCancelAndClose() { writeSettings(); d->imglst->listView()->clear(); d->uploadQueue.clear(); d->widget->progressBar()->reset(); setUiInProgressState(false); d->talker->cancel(); reject(); } void FlickrWindow::reactivate() { d->userNameDisplayLabel->setText(QString()); readSettings(d->select->getUserName()); d->talker->link(d->select->getUserName()); d->widget->d->imglst->loadImagesFromCurrentSelection(); show(); } void FlickrWindow::readSettings(QString uname) { KConfig config; QString groupName = QString::fromLatin1("%1%2Export Settings").arg(d->serviceName, uname); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Group name is:" << groupName; KConfigGroup grp = config.group(groupName); d->exportHostTagsCheckBox->setChecked(grp.readEntry("Export Host Tags", false)); d->extendedTagsButton->setChecked(grp.readEntry("Show Extended Tag Options", false)); d->addExtraTagsCheckBox->setChecked(grp.readEntry("Add Extra Tags", false)); d->stripSpaceTagsCheckBox->setChecked(grp.readEntry("Strip Space From Tags", false)); d->publicCheckBox->setChecked(grp.readEntry("Public Sharing", false)); d->familyCheckBox->setChecked(grp.readEntry("Family Sharing", false)); d->friendsCheckBox->setChecked(grp.readEntry("Friends Sharing", false)); d->extendedPublicationButton->setChecked(grp.readEntry("Show Extended Publication Options", false)); int safetyLevel = d->safetyLevelComboBox->findData(QVariant(grp.readEntry("Safety Level", 0))); if (safetyLevel == -1) { safetyLevel = 0; } d->safetyLevelComboBox->setCurrentIndex(safetyLevel); int contentType = d->contentTypeComboBox->findData(QVariant(grp.readEntry("Content Type", 0))); if (contentType == -1) { contentType = 0; } d->contentTypeComboBox->setCurrentIndex(contentType); d->originalCheckBox->setChecked(grp.readEntry("Upload Original", false)); d->resizeCheckBox->setChecked(grp.readEntry("Resize", false)); d->dimensionSpinBox->setValue(grp.readEntry("Maximum Width", 1600)); d->imageQualitySpinBox->setValue(grp.readEntry("Image Quality", 85)); winId(); KConfigGroup dialogGroup = config.group(QString::fromLatin1("%1Export Dialog").arg(d->serviceName)); KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup); resize(windowHandle()->size()); } void FlickrWindow::writeSettings() { KConfig config; QString groupName = QString::fromLatin1("%1%2Export Settings").arg(d->serviceName, d->username); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Group name is:" << groupName; if (QString::compare(QString::fromLatin1("%1Export Settings").arg(d->serviceName), groupName) == 0) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Not writing entry of group" << groupName; return; } KConfigGroup grp = config.group(groupName); grp.writeEntry("username", d->username); grp.writeEntry("Export Host Tags", d->exportHostTagsCheckBox->isChecked()); grp.writeEntry("Show Extended Tag Options", d->extendedTagsButton->isChecked()); grp.writeEntry("Add Extra Tags", d->addExtraTagsCheckBox->isChecked()); grp.writeEntry("Strip Space From Tags", d->stripSpaceTagsCheckBox->isChecked()); grp.writeEntry("Public Sharing", d->publicCheckBox->isChecked()); grp.writeEntry("Family Sharing", d->familyCheckBox->isChecked()); grp.writeEntry("Friends Sharing", d->friendsCheckBox->isChecked()); grp.writeEntry("Show Extended Publication Options", d->extendedPublicationButton->isChecked()); int safetyLevel = d->safetyLevelComboBox->itemData(d->safetyLevelComboBox->currentIndex()).toInt(); grp.writeEntry("Safety Level", safetyLevel); int contentType = d->contentTypeComboBox->itemData(d->contentTypeComboBox->currentIndex()).toInt(); grp.writeEntry("Content Type", contentType); grp.writeEntry("Resize", d->resizeCheckBox->isChecked()); grp.writeEntry("Upload Original", d->originalCheckBox->isChecked()); grp.writeEntry("Maximum Width", d->dimensionSpinBox->value()); grp.writeEntry("Image Quality", d->imageQualitySpinBox->value()); KConfigGroup dialogGroup = config.group(QString::fromLatin1("%1Export Dialog").arg(d->serviceName)); KWindowConfig::saveWindowSize(windowHandle(), dialogGroup); config.sync(); } void FlickrWindow::slotLinkingSucceeded() { d->username = d->talker->getUserName(); d->userId = d->talker->getUserId(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "SlotLinkingSucceeded invoked setting user Display name to" << d->username; d->userNameDisplayLabel->setText(QString::fromLatin1("%1").arg(d->username)); KConfig config; foreach (const QString& group, config.groupList()) { if (!(group.contains(d->serviceName))) { continue; } KConfigGroup grp = config.group(group); if (group.contains(d->username)) { readSettings(d->username); break; } } writeSettings(); d->talker->listPhotoSets(); } void FlickrWindow::slotBusy(bool val) { if (val) { setCursor(Qt::WaitCursor); } else { setCursor(Qt::ArrowCursor); } } void FlickrWindow::slotError(const QString& msg) { QMessageBox::critical(this, i18n("Error"), msg); } void FlickrWindow::slotUserChangeRequest() { writeSettings(); d->userNameDisplayLabel->setText(QString()); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Slot Change User Request"; d->select->reactivate(); readSettings(d->select->getUserName()); d->talker->link(d->select->getUserName()); } void FlickrWindow::slotRemoveAccount() { KConfig config; QString groupName = QString::fromLatin1("%1%2Export Settings").arg(d->serviceName, d->username); KConfigGroup grp = config.group(groupName); if (grp.exists()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Removing Account having group" << groupName; grp.deleteGroup(); } d->talker->unLink(); d->talker->removeUserName(d->serviceName + d->username); d->userNameDisplayLabel->setText(QString()); d->username = QString(); } /** * Try to guess a sensible set name from the urls given. * Currently, it extracs the last path name component, and returns the most * frequently seen. The function could be expanded to, for example, only * accept the path if it occurs at least 50% of the time. It could also look * further up in the path name. */ QString FlickrWindow::guessSensibleSetName(const QList& urlList) const { QMap nrFolderOccurences; // Extract last component of directory foreach (const QUrl& url, urlList) { QString dir = url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile(); QStringList list = dir.split(QLatin1Char('/')); if (list.isEmpty()) { continue; } nrFolderOccurences[list.last()]++; } int maxCount = 0; int totalCount = 0; QString name; for (QMap::const_iterator it = nrFolderOccurences.constBegin() ; it != nrFolderOccurences.constEnd() ; ++it) { totalCount += it.value(); if (it.value() > maxCount) { maxCount = it.value(); name = it.key(); } } // If there is only one entry or one name appears at least twice, return the suggestion if ((totalCount == 1) || (maxCount > 1)) { return name; } return QString(); } /** * This method is called when the photo set creation button is pressed. It * summons a creation dialog for user input. When that is closed, it * creates a new photo set in the local list. The id gets the form of * UNDEFINED_ followed by a number, to indicate that it doesn't exist on * Flickr yet. */ void FlickrWindow::slotCreateNewPhotoSet() { if (d->albumDlg->exec() == QDialog::Accepted) { - FPhotoSet fps; - d->albumDlg->getFolderProperties(fps); - qCDebug(DIGIKAM_WEBSERVICES_LOG) << "in slotCreateNewPhotoSet()" << fps.title; + FPhotoSet fps1; + d->albumDlg->getFolderProperties(fps1); + qCDebug(DIGIKAM_WEBSERVICES_LOG) << "in slotCreateNewPhotoSet()" << fps1.title; // Lets find an UNDEFINED_ style id that isn't taken yet.s QString id; int i = 0; id = QLatin1String("UNDEFINED_") + QString::number(i); QLinkedList::iterator it = d->talker->m_photoSetsList->begin(); while (it != d->talker->m_photoSetsList->end()) { - FPhotoSet fps = *it; + FPhotoSet fps2 = *it; - if (fps.id == id) + if (fps2.id == id) { id = QLatin1String("UNDEFINED_") + QString::number(++i); it = d->talker->m_photoSetsList->begin(); } ++it; } - fps.id = id; + fps1.id = id; qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Created new photoset with temporary id" << id; // Append the new photoset to the list. - d->talker->m_photoSetsList->prepend(fps); - d->talker->m_selectedPhotoSet = fps; + d->talker->m_photoSetsList->prepend(fps1); + d->talker->m_selectedPhotoSet = fps1; // Re-populate the photo sets combo box. slotPopulatePhotoSetComboBox(); } else { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "New Photoset creation aborted"; } } void FlickrWindow::slotAuthCancel() { d->talker->cancel(); d->authProgressDlg->hide(); } void FlickrWindow::slotPopulatePhotoSetComboBox() { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "slotPopulatePhotoSetComboBox invoked"; if (d->talker && d->talker->m_photoSetsList) { QLinkedList * const list = d->talker->m_photoSetsList; d->albumsListComboBox->clear(); d->albumsListComboBox->insertItem(0, i18n("Photostream Only")); d->albumsListComboBox->insertSeparator(1); QLinkedList::iterator it = list->begin(); int index = 2; int curr_index = 0; while (it != list->end()) { FPhotoSet photoSet = *it; QString name = photoSet.title; // Store the id as user data, because the title is not unique. QVariant id = QVariant(photoSet.id); if (id == d->talker->m_selectedPhotoSet.id) { curr_index = index; } d->albumsListComboBox->insertItem(index++, name, id); ++it; } d->albumsListComboBox->setCurrentIndex(curr_index); } } /** * This slot is call when 'Start Uploading' button is pressed. */ void FlickrWindow::slotUser1() { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "SlotUploadImages invoked"; /* d->widget->d->tab->setCurrentIndex(FlickrWidget::FILELIST); */ if (d->imglst->imageUrls().isEmpty()) { return; } typedef QPair Pair; d->uploadQueue.clear(); for (int i = 0 ; i < d->imglst->listView()->topLevelItemCount() ; ++i) { FlickrListViewItem* const lvItem = dynamic_cast(d->imglst->listView()->topLevelItem(i)); if (lvItem) { DItemInfo info(d->iface->itemInfo(lvItem->url())); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Adding images" << lvItem->url() << " to the list"; FPhotoInfo temp; temp.title = info.title(); temp.description = info.comment(); temp.size = info.fileSize(); temp.is_public = lvItem->isPublic() ? 1 : 0; temp.is_family = lvItem->isFamily() ? 1 : 0; temp.is_friend = lvItem->isFriends() ? 1 : 0; temp.safety_level = lvItem->safetyLevel(); temp.content_type = lvItem->contentType(); QStringList tagsFromDialog = d->tagsLineEdit->text().split(QLatin1Char(','), QString::SkipEmptyParts); QStringList tagsFromList = lvItem->extraTags(); QStringList allTags; QStringList::Iterator itTags; // Tags from the dialog itTags = tagsFromDialog.begin(); while (itTags != tagsFromDialog.end()) { allTags.append(*itTags); ++itTags; } // Tags from the database if (d->exportHostTagsCheckBox->isChecked()) { QStringList tagsFromDatabase; tagsFromDatabase = info.keywords(); itTags = tagsFromDatabase.begin(); while (itTags != tagsFromDatabase.end()) { allTags.append(*itTags); ++itTags; } } // Tags from the list view. itTags = tagsFromList.begin(); while (itTags != tagsFromList.end()) { allTags.append(*itTags); ++itTags; } // Remove spaces if the user doesn't like them. if (d->stripSpaceTagsCheckBox->isChecked()) { for (QStringList::iterator it = allTags.begin() ; it != allTags.end() ; ++it) { *it = (*it).trimmed().remove(QLatin1Char(' ')); } } // Debug the tag list. itTags = allTags.begin(); while (itTags != allTags.end()) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Tags list:" << (*itTags); ++itTags; } temp.tags = allTags; d->uploadQueue.append(Pair(lvItem->url(), temp)); } } d->uploadTotal = d->uploadQueue.count(); d->uploadCount = 0; d->widget->progressBar()->reset(); slotAddPhotoNext(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "SlotUploadImages done"; } void FlickrWindow::slotAddPhotoNext() { if (d->uploadQueue.isEmpty()) { d->widget->progressBar()->reset(); setUiInProgressState(false); return; } typedef QPair Pair; Pair pathComments = d->uploadQueue.first(); FPhotoInfo info = pathComments.second; QString selectedPhotoSetId = d->albumsListComboBox->itemData(d->albumsListComboBox->currentIndex()).toString(); if (selectedPhotoSetId.isEmpty()) { d->talker->m_selectedPhotoSet = FPhotoSet(); } else { QLinkedList::iterator it = d->talker->m_photoSetsList->begin(); while (it != d->talker->m_photoSetsList->end()) { if (it->id == selectedPhotoSetId) { d->talker->m_selectedPhotoSet = *it; break; } ++it; } } qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Max allowed file size is:" << d->talker->getMaxAllowedFileSize().toLongLong() << "File Size is" << info.size; bool res = d->talker->addPhoto(pathComments.first.toLocalFile(), //the file path info, d->originalCheckBox->isChecked(), d->resizeCheckBox->isChecked(), d->dimensionSpinBox->value(), d->imageQualitySpinBox->value()); if (!res) { slotAddPhotoFailed(QLatin1String("")); return; } if (d->widget->progressBar()->isHidden()) { setUiInProgressState(true); d->widget->progressBar()->progressScheduled(i18n("Flickr Export"), true, true); d->widget->progressBar()->progressThumbnailChanged( QIcon::fromTheme(QLatin1String("dk-flickr")).pixmap(22, 22)); } } void FlickrWindow::slotAddPhotoSucceeded(const QString& photoId) { QUrl photoUrl = d->uploadQueue.first().first; // Set location for uploaded photo DItemInfo info(d->iface->itemInfo(photoUrl)); if (info.hasGeolocationInfo() && !photoId.isEmpty()) { d->talker->setGeoLocation(photoId, QString::number(info.latitude()), QString::number(info.longitude())); return; } // Remove photo uploaded from the list d->imglst->removeItemByUrl(photoUrl); d->uploadQueue.removeFirst(); d->uploadCount++; d->widget->progressBar()->setMaximum(d->uploadTotal); d->widget->progressBar()->setValue(d->uploadCount); slotAddPhotoNext(); } void FlickrWindow::slotListPhotoSetsFailed(const QString& msg) { QMessageBox::critical(this, QLatin1String("Error"), i18n("Failed to Fetch Photoset information from %1. %2\n", d->serviceName, msg)); } void FlickrWindow::slotAddPhotoFailed(const QString& msg) { QPointer warn = new QMessageBox(QMessageBox::Warning, i18n("Warning"), i18n("Failed to upload photo into %1. %2\nDo you want to continue?", d->serviceName, msg), QMessageBox::Yes | QMessageBox::No); (warn->button(QMessageBox::Yes))->setText(i18n("Continue")); (warn->button(QMessageBox::No))->setText(i18n("Cancel")); if (warn->exec() != QMessageBox::Yes) { d->uploadQueue.clear(); d->widget->progressBar()->reset(); setUiInProgressState(false); } else { d->uploadQueue.removeFirst(); d->uploadTotal--; d->widget->progressBar()->setMaximum(d->uploadTotal); d->widget->progressBar()->setValue(d->uploadCount); slotAddPhotoNext(); } delete warn; } /** * Method called when a photo set has been successfully created on Flickr. * It functions to restart the normal flow after a photo set has been created * on Flickr. */ void FlickrWindow::slotAddPhotoSetSucceeded() { slotPopulatePhotoSetComboBox(); slotAddPhotoSucceeded(QLatin1String("")); } void FlickrWindow::slotImageListChanged() { startButton()->setEnabled(!(d->widget->d->imglst->imageUrls().isEmpty())); } void FlickrWindow::slotReloadPhotoSetRequest() { d->talker->listPhotoSets(); } } // namespace DigikamGenericFlickrPlugin