diff --git a/utilities/assistants/webservices/common/wssettingswidget.h b/utilities/assistants/webservices/common/wssettingswidget.h index 592d2fb7f0..f133dd5203 100644 --- a/utilities/assistants/webservices/common/wssettingswidget.h +++ b/utilities/assistants/webservices/common/wssettingswidget.h @@ -1,119 +1,120 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2015-07-28 * Description : Common widgets shared by Web Service tools * * Copyright (C) 2013 by Pankaj Kumar * Copyright (C) 2015 by Shourya Singh Gupta * Copyright (C) 2016-2018 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 WS_SETTINGS_WIDGET_H #define WS_SETTINGS_WIDGET_H //Qt includes #include // Local includes #include "digikam_export.h" #include "dimageslist.h" #include "dinfointerface.h" #include "dprogresswdg.h" class QLabel; class QSpinBox; class QCheckBox; class QButtonGroup; class QComboBox; class QPushButton; class QGroupBox; class QGridLayout; class QVBoxLayout; class QHBoxLayout; namespace Digikam { class DIGIKAM_EXPORT WSSettingsWidget : public QWidget { Q_OBJECT public: explicit WSSettingsWidget(QWidget* const parent, DInfoInterface* const iface, const QString& toolName); ~WSSettingsWidget(); +public: void replaceImageList(QWidget* const widget); void addWidgetToSettingsBox(QWidget* const widget); QString getDestinationPath() const; DImagesList* imagesList() const; DProgressWdg* progressBar() const; QWidget* getSettingsBox() const; QVBoxLayout* getSettingsBoxLayout() const; QGroupBox* getAlbumBox() const; QGridLayout* getAlbumBoxLayout() const; QGroupBox* getOptionsBox() const; QGridLayout* getOptionsBoxLayout() const; QGroupBox* getUploadBox() const; QVBoxLayout* getUploadBoxLayout() const; QGroupBox* getSizeBox() const; QVBoxLayout* getSizeBoxLayout() const; QGroupBox* getAccountBox() const; QGridLayout* getAccountBoxLayout() const; QLabel* getHeaderLbl() const; QLabel* getUserNameLabel() const; QPushButton* getChangeUserBtn() const; QComboBox* getDimensionCoB() const; QPushButton* getNewAlbmBtn() const; QPushButton* getReloadBtn() const; QCheckBox* getOriginalCheckBox() const; QCheckBox* getResizeCheckBox() const; QSpinBox* getDimensionSpB() const; QSpinBox* getImgQualitySpB() const; QComboBox* getAlbumsCoB() const; public: virtual void updateLabels(const QString& name = QString(), const QString& url = QString()) = 0; protected Q_SLOTS: void slotResizeChecked(); private: class Private; Private* const d; }; } // namespace Digikam #endif // WS_SETTINGS_WIDGET_H diff --git a/utilities/assistants/webservices/rajce/rajcewidget.cpp b/utilities/assistants/webservices/rajce/rajcewidget.cpp index 587ab7467b..b5699777f7 100644 --- a/utilities/assistants/webservices/rajce/rajcewidget.cpp +++ b/utilities/assistants/webservices/rajce/rajcewidget.cpp @@ -1,539 +1,539 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2011-04-12 * Description : A tool to export items to Rajce web service * * Copyright (C) 2011 by Lukas Krejci * Copyright (C) 2011-2018 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 "rajcewidget.h" // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include #include // KDE includes #include #include #include // Local includes #include "rajcetalker.h" #include "rajcesession.h" #include "rajcenewalbumdlg.h" #include "rajcesession.h" #include "dimageslist.h" #include "wslogindialog.h" #include "dinfointerface.h" #include "dprogresswdg.h" namespace Digikam { class RajceWidget::Private { public: explicit Private() { headerLbl = 0; userNameLbl = 0; userName = 0; dimensionSpB = 0; imageQualitySpB = 0; albumsCoB = 0; newAlbumBtn = 0; reloadAlbumsBtn = 0; changeUserBtn = 0; iface = 0; imgList = 0; progressBar = 0; talker = 0; uploadingPhotos = false; lastLoggedInState = false; } QLabel* headerLbl; QLabel* userNameLbl; QLabel* userName; QSpinBox* dimensionSpB; QSpinBox* imageQualitySpB; QComboBox* albumsCoB; QPushButton* newAlbumBtn; QPushButton* reloadAlbumsBtn; QPushButton* changeUserBtn; DInfoInterface* iface; DImagesList* imgList; DProgressWdg* progressBar; RajceTalker* talker; QList uploadQueue; QList::Iterator currentUploadImage; bool uploadingPhotos; bool lastLoggedInState; QString currentAlbumName; }; RajceWidget::RajceWidget(DInfoInterface* const iface, QWidget* const parent) : WSSettingsWidget(parent, iface, QString::fromLatin1("Rajce.net")), d(new Private) { d->iface = iface; d->talker = new RajceTalker(this); d->albumsCoB = getAlbumsCoB(); d->dimensionSpB = getDimensionSpB(); d->imageQualitySpB = getImgQualitySpB(); d->newAlbumBtn = getNewAlbmBtn(); d->reloadAlbumsBtn = getReloadBtn(); d->progressBar = progressBar(); d->imgList = imagesList(); d->changeUserBtn = getChangeUserBtn(); getUploadBox()->hide(); getSizeBox()->hide(); updateLabels(); // ------------------------------------------------------------------------ connect(d->talker, SIGNAL(signalBusyStarted(uint)), this, SLOT(slotProgressStarted(uint))); connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotProgressFinished(uint))); connect(d->talker, SIGNAL(signalBusyProgress(uint,uint)), this, SLOT(slotProgressChanged(uint,uint))); connect(d->changeUserBtn, SIGNAL(clicked()), this, SLOT(slotChangeUserClicked())); connect(d->newAlbumBtn, SIGNAL(clicked()), this, SLOT(slotCreateAlbum())); connect(d->reloadAlbumsBtn, SIGNAL(clicked()), this, SLOT(slotLoadAlbums())); connect(d->albumsCoB, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotSelectedAlbumChanged(QString))); } RajceWidget::~RajceWidget() { delete d; } void RajceWidget::updateLabels(const QString&, const QString&) { bool loggedIn = !d->talker->session().sessionToken().isEmpty(); if (loggedIn != d->lastLoggedInState) { d->lastLoggedInState = loggedIn; emit signalLoginStatusChanged(loggedIn); } QString username = loggedIn ? d->talker->session().username() : QString::fromLatin1(""); QString nickname = loggedIn ? d->talker->session().nickname() : i18n("Not logged in"); getUserNameLabel()->setText(QString::fromLatin1("%2 %1").arg(username, nickname)); QString link = loggedIn ? QString::fromLatin1("

" "Rajce.net" "

") : QString::fromLatin1("

" "Rajce.net" "

"); getHeaderLbl()->setText(link); disconnect(d->albumsCoB, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotSelectedAlbumChanged(QString))); d->albumsCoB->clear(); RajceAlbum album; int selIdx = 0; int i = 0; foreach (album, d->talker->session().albums()) { d->albumsCoB->addItem(album.name, QVariant::fromValue(album)); if (d->currentAlbumName == album.name) { selIdx = i; } ++i; } if (!d->currentAlbumName.isEmpty()) { d->albumsCoB->setCurrentIndex(selIdx); } connect(d->albumsCoB, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotSelectedAlbumChanged(QString))); unsigned max = d->talker->session().maxHeight(); max = max > d->talker->session().maxWidth() ? max : d->talker->session().maxWidth(); d->dimensionSpB->setMaximum(max); if (d->dimensionSpB->value() == 0) { d->dimensionSpB->setValue(max); } d->newAlbumBtn->setEnabled(loggedIn); d->albumsCoB->setEnabled(loggedIn); d->reloadAlbumsBtn->setEnabled(loggedIn); d->dimensionSpB->setEnabled(loggedIn); d->imageQualitySpB->setEnabled(loggedIn); if (d->talker->session().lastErrorCode() != 0) { d->progressBar->setVisible(true); switch (d->talker->session().lastErrorCode()) { case UnknownError: d->progressBar->setFormat(i18n("Unknown error")); break; case InvalidCommand: d->progressBar->setFormat(i18n("Invalid command")); break; case InvalidCredentials: d->progressBar->setFormat(i18n("Invalid login name or password")); break; case InvalidSessionToken: d->progressBar->setFormat(i18n("Session expired")); break; case InvalidOrRepeatedColumnName: break; case InvalidAlbumId: d->progressBar->setFormat(i18n("Unknown album")); break; case AlbumDoesntExistOrNoPrivileges: d->progressBar->setFormat(i18n("Unknown album")); break; case InvalidAlbumToken: d->progressBar->setFormat(i18n("Failed to open album")); break; case AlbumNameEmpty: d->progressBar->setFormat(i18n("The album name cannot be empty")); break; case FailedToCreateAlbum: d->progressBar->setFormat(i18n("Failed to create album")); break; case AlbumDoesntExist: d->progressBar->setFormat(i18n("Album does not exist")); break; case UnknownApplication: break; case InvalidApplicationKey: break; case FileNotAttached: d->progressBar->setFormat(i18n("File upload failed")); break; case NewerVersionExists: break; case SavingFileFailed: d->progressBar->setFormat(i18n("File upload failed")); break; case UnsupportedFileExtension: d->progressBar->setFormat(i18n("Unsupported file extension")); break; case UnknownClientVersion: break; case NonexistentTarget: break; default: break; } QPalette palette = d->progressBar->palette(); palette.setColor(QPalette::Active, QPalette::Background, Qt::darkRed); d->progressBar->setPalette(palette); } } void RajceWidget::reactivate() { d->imgList->listView()->clear(); d->imgList->loadImagesFromCurrentSelection(); d->talker->clearLastError(); updateLabels(); } void RajceWidget::slotProgressChanged(unsigned /*commandType*/, unsigned int percent) { if (d->uploadingPhotos) { unsigned idx = d->currentUploadImage - d->uploadQueue.begin() - 1; float perc = (float)idx / d->uploadQueue.size(); perc += (float)percent / 100 / d->uploadQueue.size(); percent = perc * 100; } d->progressBar->setValue(percent); } void RajceWidget::slotProgressFinished(unsigned) { if (d->uploadingPhotos) { unsigned idx = d->currentUploadImage - d->uploadQueue.begin(); float perc = (float)idx / d->uploadQueue.size(); d->progressBar->setValue(perc * 100); } else { d->progressBar->setVisible(false); setEnabledWidgets(true); updateLabels(); } } void RajceWidget::slotProgressStarted(unsigned commandType) { QString text; switch(commandType) { case Login: text = i18n("Logging in %v%"); break; case Logout: text = i18n("Logging out %v%"); break; case ListAlbums: text = i18n("Loading albums %v%"); break; case CreateAlbum: text = i18n("Creating album %v%"); break; case OpenAlbum: text = i18n("Opening album %v%"); break; case CloseAlbum: text = i18n("Closing album %v%"); break; case AddPhoto: text = i18n("Adding photos %v%"); break; } if (!d->uploadingPhotos) { d->progressBar->setValue(0); } d->progressBar->setFormat(text); d->progressBar->setVisible(true); setEnabledWidgets(false); } void RajceWidget::slotChangeUserClicked() { WSLoginDialog* const dlg = new WSLoginDialog(this, QString::fromLatin1("Rajce.net")); if (dlg->exec() == QDialog::Accepted) { d->talker->clearLastError(); connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotLoadAlbums())); d->talker->login(dlg->login(), dlg->password()); } delete dlg; } void RajceWidget::slotLoadAlbums() { disconnect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotLoadAlbums())); d->talker->loadAlbums(); } void RajceWidget::slotCreateAlbum() { RajceNewAlbumDlg* const dlg = new RajceNewAlbumDlg(this); if (dlg->exec() == QDialog::Accepted) { d->talker->clearLastError(); connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotLoadAlbums())); d->talker->createAlbum(dlg->albumName(), dlg->albumDescription(), dlg->albumVisible()); } delete dlg; } -void RajceWidget::startUpload() +void RajceWidget::slotStartUpload() { d->talker->clearLastError(); setEnabledWidgets(false); d->uploadQueue.clear(); foreach (const QUrl& image, d->imgList->imageUrls(true)) { QString imagePath = image.toLocalFile(); d->uploadQueue.append(imagePath); } if (d->uploadQueue.isEmpty()) { setEnabledWidgets(true); return; } connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotStartUploadAfterAlbumOpened())); QString albumName = d->albumsCoB->currentText(); RajceAlbum album; foreach (RajceAlbum a, d->talker->session().albums()) { if (a.name == albumName) { album = a; break; } } if (album.name == albumName) { d->talker->openAlbum(album); } } void RajceWidget::slotStartUploadAfterAlbumOpened() { disconnect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotStartUploadAfterAlbumOpened())); connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotUploadNext())); d->uploadingPhotos = true; d->progressBar->setValue(0); slotProgressStarted(AddPhoto); d->currentUploadImage = d->uploadQueue.begin(); slotUploadNext(); } void RajceWidget::slotCloseAlbum() { setEnabledWidgets(true); disconnect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotCloseAlbum())); d->uploadQueue.clear(); d->progressBar->setVisible(false); d->uploadingPhotos = false; } void RajceWidget::slotUploadNext() { QList::Iterator tmp = d->currentUploadImage; if (d->currentUploadImage == d->uploadQueue.end()) { d->imgList->processed(QUrl::fromLocalFile(*(--tmp)), (d->talker->session().lastErrorCode() == 0)); cancelUpload(); return; } if (d->currentUploadImage != d->uploadQueue.begin()) { d->imgList->processed(QUrl::fromLocalFile(*(--tmp)), (d->talker->session().lastErrorCode() == 0)); } d->imgList->processing(QUrl::fromLocalFile(*d->currentUploadImage)); QString currentPhoto = *d->currentUploadImage; ++d->currentUploadImage; unsigned dimension = d->dimensionSpB->value(); int jpgQuality = d->imageQualitySpB->value(); d->talker->uploadPhoto(currentPhoto, dimension, jpgQuality); } void RajceWidget::cancelUpload() { if (d->uploadingPhotos && d->currentUploadImage != d->uploadQueue.begin() && d->currentUploadImage != d->uploadQueue.end()) { d->imgList->processed(QUrl::fromLocalFile(*d->currentUploadImage), false); } disconnect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotUploadNext())); connect(d->talker, SIGNAL(signalBusyFinished(uint)), this, SLOT(slotCloseAlbum())); d->talker->cancelCurrentCommand(); d->talker->closeAlbum(); d->uploadQueue.clear(); } void RajceWidget::slotSelectedAlbumChanged(const QString& newName) { d->currentAlbumName = newName; } void RajceWidget::setEnabledWidgets(bool enabled) { d->changeUserBtn->setEnabled(enabled); d->newAlbumBtn->setEnabled(enabled); d->albumsCoB->setEnabled(enabled); d->reloadAlbumsBtn->setEnabled(enabled); d->dimensionSpB->setEnabled(enabled); d->imageQualitySpB->setEnabled(enabled); emit signalLoginStatusChanged(enabled); } void RajceWidget::readSettings() { KConfig config; KConfigGroup grp = config.group("RajceExport Settings"); RajceSession session; session.sessionToken() = grp.readEntry("token"); session.username() = grp.readEntry("username"); session.nickname() = grp.readEntry("nickname"); d->currentAlbumName = grp.readEntry("album"); session.maxHeight() = grp.readEntry("maxHeight", 1200); session.maxWidth() = grp.readEntry("maxWidth", 1200); session.imageQuality() = grp.readEntry("imageQuality", 85); d->talker->init(session); if (!d->talker->session().sessionToken().isEmpty()) { d->talker->loadAlbums(); } } void RajceWidget::writeSettings() { KConfig config; KConfigGroup grp = config.group("RajceExport Settings"); const RajceSession& session = d->talker->session(); grp.writeEntry("token", session.sessionToken()); grp.writeEntry("username", session.username()); grp.writeEntry("nickname", session.nickname()); grp.writeEntry("album", d->currentAlbumName); grp.writeEntry("maxWidth", session.maxWidth()); grp.writeEntry("maxHeight", session.maxHeight()); grp.writeEntry("imageQuality", session.imageQuality()); } } // namespace Digikam diff --git a/utilities/assistants/webservices/rajce/rajcewidget.h b/utilities/assistants/webservices/rajce/rajcewidget.h index c178978f24..5d53e494a9 100644 --- a/utilities/assistants/webservices/rajce/rajcewidget.h +++ b/utilities/assistants/webservices/rajce/rajcewidget.h @@ -1,95 +1,98 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2011-04-12 * Description : A tool to export items to Rajce web service * * Copyright (C) 2011 by Lukas Krejci * Copyright (C) 2011-2018 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 RAJCE_WIDGET_H #define RAJCE_WIDGET_H // Qt includes #include #include // Local includes #include "wssettingswidget.h" namespace Digikam { class DInfoInterface; class RajceWidget : public WSSettingsWidget { Q_OBJECT public: explicit RajceWidget(DInfoInterface* const iface, QWidget* const parent); ~RajceWidget(); Q_SIGNALS: void signalLoginStatusChanged(bool loggedIn); public Q_SLOTS: - void updateLabels(const QString& name = QString(), - const QString& url = QString()) Q_DECL_OVERRIDE; - void reactivate(); + void slotStartUpload(); + +public: - void startUpload(); + void reactivate(); void cancelUpload(); - + void writeSettings(); void readSettings(); private Q_SLOTS: void slotChangeUserClicked(); void slotProgressStarted(unsigned); void slotProgressFinished(unsigned); void slotProgressChanged(unsigned, unsigned percent); void slotLoadAlbums(); void slotCreateAlbum(); void slotCloseAlbum(); void slotUploadNext(); void slotStartUploadAfterAlbumOpened(); void slotSelectedAlbumChanged(const QString&); private: + void updateLabels(const QString& name = QString(), + const QString& url = QString()) Q_DECL_OVERRIDE; + void setEnabledWidgets(bool); private: class Private; Private* const d; }; } // namespace Digikam #endif // RAJCE_WIDGET_H diff --git a/utilities/assistants/webservices/rajce/rajcewindow.cpp b/utilities/assistants/webservices/rajce/rajcewindow.cpp index 091a8dec50..2c7e09f8cd 100644 --- a/utilities/assistants/webservices/rajce/rajcewindow.cpp +++ b/utilities/assistants/webservices/rajce/rajcewindow.cpp @@ -1,102 +1,102 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2011-04-12 * Description : A tool to export items to Rajce web service * * Copyright (C) 2011 by Lukas Krejci * Copyright (C) 2011-2018 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 "rajcewindow.h" // Qt includes #include #include #include // KDE includes #include // Local includes #include "rajcewidget.h" namespace Digikam { RajceWindow::RajceWindow(DInfoInterface* const iface, QWidget* const /*parent*/) : WSToolDialog(0) { m_widget = new RajceWidget(iface, this); m_widget->readSettings(); setMainWidget(m_widget); setModal(false); setWindowTitle(i18n("Export to Rajce.net")); startButton()->setText(i18n("Start Upload")); startButton()->setToolTip(i18n("Start upload to Rajce.net")); m_widget->setMinimumSize(700, 500); connect(startButton(), SIGNAL(clicked()), - m_widget, SLOT(startUpload())); + m_widget, SLOT(slotStartUpload())); connect(this, SIGNAL(finished(int)), this, SLOT(slotFinished())); connect(m_widget, SIGNAL(signalLoginStatusChanged(bool)), this, SLOT(slotSetUploadButtonEnabled(bool))); startButton()->setEnabled(false); } RajceWindow::~RajceWindow() { } void RajceWindow::reactivate() { m_widget->reactivate(); show(); } void RajceWindow::slotSetUploadButtonEnabled(bool enabled) { startButton()->setEnabled(enabled); } void RajceWindow::slotFinished() { m_widget->cancelUpload(); m_widget->writeSettings(); } void RajceWindow::closeEvent(QCloseEvent* e) { if (!e) { return; } slotFinished(); e->accept(); } } // namespace Digikam