File indexing completed on 2025-01-19 03:55:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-07-28 0007 * Description : Common widgets shared by Web Service tools 0008 * 0009 * SPDX-FileCopyrightText: 2013 by Pankaj Kumar <me at panks dot me> 0010 * SPDX-FileCopyrightText: 2015 by Shourya Singh Gupta <shouryasgupta at gmail dot com> 0011 * SPDX-FileCopyrightText: 2016-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "wssettingswidget.h" 0018 0019 // Qt includes 0020 0021 #include <QLabel> 0022 #include <QSpinBox> 0023 #include <QCheckBox> 0024 #include <QGroupBox> 0025 #include <QRadioButton> 0026 #include <QButtonGroup> 0027 #include <QGridLayout> 0028 #include <QHBoxLayout> 0029 #include <QVBoxLayout> 0030 #include <QPushButton> 0031 #include <QApplication> 0032 #include <QComboBox> 0033 #include <QScrollArea> 0034 0035 // KDE includes 0036 0037 #include <klocalizedstring.h> 0038 0039 namespace Digikam 0040 { 0041 0042 class Q_DECL_HIDDEN WSSettingsWidget::Private 0043 { 0044 public: 0045 0046 explicit Private(DInfoInterface* const interface, const QString& name) 0047 : imgList (nullptr), 0048 uploadWidget (nullptr), 0049 toolName (name), 0050 headerLbl (nullptr), 0051 userNameDisplayLbl(nullptr), 0052 changeUserBtn (nullptr), 0053 dlDimensionCoB (nullptr), 0054 settingsScrollArea(nullptr), 0055 albumsCoB (nullptr), 0056 newAlbumBtn (nullptr), 0057 reloadAlbumsBtn (nullptr), 0058 originalChB (nullptr), 0059 resizeChB (nullptr), 0060 photoIdChB (nullptr), 0061 dimensionSpB (nullptr), 0062 imageQualitySpB (nullptr), 0063 mainLayout (nullptr), 0064 settingsBox (nullptr), 0065 settingsBoxLayout (nullptr), 0066 albBox (nullptr), 0067 albumsBoxLayout (nullptr), 0068 optionsBox (nullptr), 0069 optionsBoxLayout (nullptr), 0070 uploadBox (nullptr), 0071 uploadBoxLayout (nullptr), 0072 sizeBox (nullptr), 0073 sizeBoxLayout (nullptr), 0074 accountBox (nullptr), 0075 accountBoxLayout (nullptr), 0076 iface (interface), 0077 progressBar (nullptr) 0078 { 0079 } 0080 0081 DItemsList* imgList; 0082 QWidget* uploadWidget; 0083 QString toolName; 0084 QString albumTitle; 0085 0086 QLabel* headerLbl; 0087 QLabel* userNameDisplayLbl; 0088 QPushButton* changeUserBtn; 0089 QComboBox* dlDimensionCoB; 0090 QScrollArea* settingsScrollArea; 0091 0092 QComboBox* albumsCoB; 0093 QPushButton* newAlbumBtn; 0094 QPushButton* reloadAlbumsBtn; 0095 0096 QCheckBox* originalChB; 0097 QCheckBox* resizeChB; 0098 QCheckBox* photoIdChB; 0099 QSpinBox* dimensionSpB; 0100 QSpinBox* imageQualitySpB; 0101 0102 QHBoxLayout* mainLayout; 0103 0104 QWidget* settingsBox; 0105 QVBoxLayout* settingsBoxLayout; 0106 0107 QGroupBox* albBox; 0108 QGridLayout* albumsBoxLayout; 0109 0110 QGroupBox* optionsBox; 0111 QGridLayout* optionsBoxLayout; 0112 0113 QGroupBox* uploadBox; 0114 QVBoxLayout* uploadBoxLayout; 0115 0116 QGroupBox* sizeBox; 0117 QVBoxLayout* sizeBoxLayout; 0118 0119 QGroupBox* accountBox; 0120 QGridLayout* accountBoxLayout; 0121 0122 DInfoInterface* iface; 0123 DProgressWdg* progressBar; 0124 }; 0125 0126 WSSettingsWidget::WSSettingsWidget(QWidget* const parent, 0127 DInfoInterface* const iface, 0128 const QString& toolName) 0129 : QWidget(parent), 0130 d (new Private(iface, toolName)) 0131 { 0132 setObjectName(d->toolName + QLatin1String(" Widget")); 0133 0134 d->mainLayout = new QHBoxLayout(this); 0135 d->imgList = new DItemsList(this); 0136 d->settingsScrollArea = new QScrollArea(this); 0137 d->settingsBox = new QWidget(d->settingsScrollArea); 0138 d->settingsBoxLayout = new QVBoxLayout(d->settingsBox); 0139 d->headerLbl = new QLabel(this); 0140 d->accountBox = new QGroupBox(i18n("Account"), d->settingsBox); 0141 d->accountBoxLayout = new QGridLayout(d->accountBox); 0142 d->userNameDisplayLbl = new QLabel(d->accountBox); 0143 d->changeUserBtn = new QPushButton(d->accountBox); 0144 d->albBox = new QGroupBox(i18n("Album"), d->settingsBox); 0145 d->albumsBoxLayout = new QGridLayout(d->albBox); 0146 d->albumsCoB = new QComboBox(d->albBox); 0147 d->newAlbumBtn = new QPushButton(d->accountBox); 0148 d->reloadAlbumsBtn = new QPushButton(d->accountBox); 0149 d->sizeBox = new QGroupBox(i18n("Max Dimension"), d->settingsBox); 0150 d->sizeBoxLayout = new QVBoxLayout(d->sizeBox); 0151 d->dlDimensionCoB = new QComboBox(d->sizeBox); 0152 d->uploadBox = new QGroupBox(i18n("Destination"), d->settingsBox); 0153 d->uploadWidget = iface->uploadWidget(d->uploadBox); 0154 d->uploadBoxLayout = new QVBoxLayout(d->uploadBox); 0155 d->optionsBox = new QGroupBox(i18n("Options"), d->settingsBox); 0156 d->optionsBoxLayout = new QGridLayout(d->optionsBox); 0157 d->originalChB = new QCheckBox(d->optionsBox); 0158 d->resizeChB = new QCheckBox(d->optionsBox); 0159 d->photoIdChB = new QCheckBox(d->optionsBox); 0160 d->dimensionSpB = new QSpinBox(d->optionsBox); 0161 d->imageQualitySpB = new QSpinBox(d->optionsBox); 0162 d->progressBar = new DProgressWdg(this); 0163 0164 //---------------------------------------------------------- 0165 0166 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0167 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0168 0169 d->imgList->setObjectName(QLatin1String("WebService ImagesList")); 0170 0171 d->imgList->appendControlButtonsWidget(d->progressBar); 0172 QBoxLayout* const blay = d->imgList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow); 0173 blay->setStretchFactor(d->progressBar, 20); 0174 0175 d->imgList->setAllowRAW(true); 0176 d->imgList->listView()->setWhatsThis(i18n("This is the list of images " 0177 "to upload to your %1 account.", d->toolName)); 0178 d->imgList->setIface(d->iface); 0179 0180 if (d->iface->forceAlbumSelection) 0181 { 0182 d->iface->forceAlbumSelection = false; 0183 d->imgList->loadImagesFromCurrentAlbum(); 0184 0185 const QList<QUrl>& urls = d->imgList->imageUrls(); 0186 0187 if (d->iface->supportAlbums() && !urls.isEmpty()) 0188 { 0189 DItemInfo info(d->iface->itemInfo(urls.constFirst())); 0190 d->albumTitle = DAlbumInfo(d->iface->albumInfo(info.albumId())).title(); 0191 } 0192 } 0193 else 0194 { 0195 d->imgList->loadImagesFromCurrentSelection(); 0196 } 0197 0198 d->settingsScrollArea->setMinimumSize(400, 500); 0199 d->settingsScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 0200 d->settingsScrollArea->setWidget(d->settingsBox); 0201 d->settingsScrollArea->setWidgetResizable(true); 0202 d->settingsScrollArea->setFrameShadow(QFrame::Plain); 0203 0204 d->headerLbl->setWhatsThis(i18n("This is a clickable link to open %1 in a browser.", d->toolName)); 0205 d->headerLbl->setOpenExternalLinks(true); 0206 d->headerLbl->setFocusPolicy(Qt::NoFocus); 0207 0208 //------------------------------------------------------------ 0209 0210 d->accountBox->setWhatsThis(i18n("This is the %1 account that is currently logged in.", d->toolName)); 0211 0212 QLabel* const userNameLbl = new QLabel(i18nc("account settings","Name:"), d->accountBox); 0213 d->changeUserBtn->setText(i18n("Change Account")); 0214 d->changeUserBtn->setIcon(QIcon::fromTheme(QLatin1String("system-switch-user")).pixmap(16)); 0215 d->changeUserBtn->setToolTip(i18n("Change %1 account for transfer", d->toolName)); 0216 0217 d->accountBoxLayout->addWidget(userNameLbl, 0, 0, 1, 2); 0218 d->accountBoxLayout->addWidget(d->userNameDisplayLbl, 0, 2, 1, 2); 0219 d->accountBoxLayout->addWidget(d->changeUserBtn, 1, 0, 1, 4); 0220 d->accountBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0221 d->accountBoxLayout->setSpacing(spacing); 0222 0223 //------------------------------------------------------------- 0224 0225 d->albBox->setWhatsThis(i18n("This is the %1 folder to/from which selected " 0226 "photos will be uploaded/downloaded.", d->toolName)); 0227 0228 QLabel* const albLbl = new QLabel(i18n("Album:"), d->albBox); 0229 0230 d->albumsCoB->setEditable(false); 0231 0232 d->newAlbumBtn->setText(i18n("New Album")); 0233 d->newAlbumBtn->setIcon(QIcon::fromTheme(QLatin1String("list-add")).pixmap(16)); 0234 d->newAlbumBtn->setToolTip(i18n("Create new %1 folder", d->toolName)); 0235 0236 d->reloadAlbumsBtn->setText(i18nc("album list","Reload")); 0237 d->reloadAlbumsBtn->setIcon(QIcon::fromTheme(QLatin1String("view-refresh")).pixmap(16)); 0238 d->reloadAlbumsBtn->setToolTip(i18n("Reload album list")); 0239 0240 d->albumsBoxLayout->addWidget(albLbl, 0, 0, 1, 1); 0241 d->albumsBoxLayout->addWidget(d->albumsCoB, 0, 1, 1, 4); 0242 d->albumsBoxLayout->addWidget(d->newAlbumBtn, 1, 3, 1, 1); 0243 d->albumsBoxLayout->addWidget(d->reloadAlbumsBtn, 1, 4, 1, 1); 0244 0245 //---------------------------------------------------------- 0246 0247 d->sizeBox->setWhatsThis(i18n("This is the maximum dimension of the images. " 0248 "Images larger than this will be scaled down.")); 0249 d->dlDimensionCoB->addItem(i18n("Original Size"), QLatin1String("d")); 0250 d->dlDimensionCoB->addItem(i18n("1600 px"), QLatin1String("1600")); 0251 d->dlDimensionCoB->addItem(i18n("1440 px"), QLatin1String("1440")); 0252 d->dlDimensionCoB->addItem(i18n("1280 px"), QLatin1String("1280")); 0253 d->dlDimensionCoB->addItem(i18n("1152 px"), QLatin1String("1152")); 0254 d->dlDimensionCoB->addItem(i18n("1024 px"), QLatin1String("1024")); 0255 d->dlDimensionCoB->setCurrentIndex(0); 0256 d->sizeBoxLayout->addWidget(d->dlDimensionCoB); 0257 0258 // ------------------------------------------------------------------------ 0259 0260 d->uploadBox->setWhatsThis(i18n("This is the location where %1 " 0261 "images will be downloaded.", d->toolName)); 0262 d->uploadBoxLayout->addWidget(d->uploadWidget); 0263 0264 //----------------------------------------------------------- 0265 0266 d->optionsBox->setWhatsThis(i18n("These are the options that would " 0267 "be applied to photos before upload.")); 0268 0269 d->originalChB->setText(i18n("Upload original image file")); 0270 d->originalChB->setChecked(false); 0271 d->originalChB->hide(); 0272 0273 d->resizeChB->setText(i18n("Resize photos before uploading")); 0274 d->resizeChB->setChecked(false); 0275 0276 d->photoIdChB->setText(i18n("Write the photo ID to the source image")); 0277 d->photoIdChB->setWhatsThis(i18n("Write the photo ID as metadata in " 0278 "the source image after uploading.")); 0279 d->photoIdChB->setChecked(false); 0280 d->photoIdChB->hide(); 0281 0282 d->dimensionSpB->setMinimum(0); 0283 d->dimensionSpB->setMaximum(5000); 0284 d->dimensionSpB->setSingleStep(10); 0285 d->dimensionSpB->setValue(1600); 0286 d->dimensionSpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0287 d->dimensionSpB->setEnabled(false); 0288 0289 QLabel* const dimensionLbl = new QLabel(i18n("Maximum Dimension:"), d->optionsBox); 0290 0291 d->imageQualitySpB->setMinimum(0); 0292 d->imageQualitySpB->setMaximum(100); 0293 d->imageQualitySpB->setSingleStep(1); 0294 d->imageQualitySpB->setValue(90); 0295 d->imageQualitySpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0296 0297 QLabel* const imageQualityLbl = new QLabel(i18n("JPEG Quality:"), d->optionsBox); 0298 0299 d->optionsBoxLayout->addWidget(d->originalChB, 0, 0, 1, 5); 0300 d->optionsBoxLayout->addWidget(d->resizeChB, 1, 0, 1, 5); 0301 d->optionsBoxLayout->addWidget(imageQualityLbl, 2, 1, 1, 1); 0302 d->optionsBoxLayout->addWidget(d->imageQualitySpB, 2, 2, 1, 1); 0303 d->optionsBoxLayout->addWidget(dimensionLbl, 3, 1, 1, 1); 0304 d->optionsBoxLayout->addWidget(d->dimensionSpB, 3, 2, 1, 1); 0305 d->optionsBoxLayout->addWidget(d->photoIdChB, 4, 0, 1, 5); 0306 d->optionsBoxLayout->setRowStretch(5, 10); 0307 d->optionsBoxLayout->setSpacing(spacing); 0308 d->optionsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0309 0310 d->progressBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 0311 d->progressBar->hide(); 0312 0313 //------------------------------------------------------ 0314 0315 d->settingsBoxLayout->addWidget(d->headerLbl); 0316 d->settingsBoxLayout->addWidget(d->accountBox); 0317 d->settingsBoxLayout->addWidget(d->albBox); 0318 d->settingsBoxLayout->addWidget(d->sizeBox); 0319 d->settingsBoxLayout->addWidget(d->uploadBox); 0320 d->settingsBoxLayout->addWidget(d->optionsBox); 0321 d->settingsBoxLayout->setSpacing(spacing); 0322 d->settingsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0323 0324 //-------------------------------------------------------- 0325 0326 d->mainLayout->addWidget(d->imgList); 0327 d->mainLayout->addWidget(d->settingsScrollArea); 0328 d->mainLayout->setContentsMargins(QMargins()); 0329 d->mainLayout->setSpacing(spacing); 0330 0331 //------------------------------------------------------- 0332 0333 connect(d->originalChB, SIGNAL(toggled(bool)), 0334 this, SLOT(slotResizeChecked())); 0335 0336 connect(d->resizeChB, SIGNAL(toggled(bool)), 0337 this, SLOT(slotResizeChecked())); 0338 } 0339 0340 WSSettingsWidget::~WSSettingsWidget() 0341 { 0342 delete d; 0343 } 0344 0345 QString WSSettingsWidget::getDestinationPath() const 0346 { 0347 QUrl url = d->iface->uploadUrl(); 0348 return url.toLocalFile(); 0349 } 0350 0351 QString WSSettingsWidget::getAlbumTitle() const 0352 { 0353 return d->albumTitle; 0354 } 0355 0356 DItemsList* WSSettingsWidget::imagesList() const 0357 { 0358 return d->imgList; 0359 } 0360 0361 void WSSettingsWidget::slotResizeChecked() 0362 { 0363 d->resizeChB->setEnabled(!d->originalChB->isChecked()); 0364 d->imageQualitySpB->setEnabled(!d->originalChB->isChecked()); 0365 d->dimensionSpB->setEnabled(d->resizeChB->isChecked() && !d->originalChB->isChecked()); 0366 } 0367 0368 DProgressWdg* WSSettingsWidget::progressBar() const 0369 { 0370 return d->progressBar; 0371 } 0372 0373 void WSSettingsWidget::addWidgetToSettingsBox(QWidget* const widget) 0374 { 0375 d->settingsBoxLayout->addWidget(widget); 0376 0377 // NOTE: This is important because progress bar always has to be at the end of settings box layout. 0378 // So we remove it and then add it back. 0379 0380 d->settingsBoxLayout->removeWidget(d->progressBar); 0381 0382 d->settingsBoxLayout->addWidget(d->progressBar); 0383 } 0384 0385 void WSSettingsWidget::replaceImageList(QWidget* const imgList) 0386 { 0387 d->imgList->hide(); 0388 d->mainLayout->removeWidget(d->imgList); 0389 d->mainLayout->insertWidget(0, imgList); 0390 } 0391 0392 QWidget* WSSettingsWidget::getSettingsBox() const 0393 { 0394 return d->settingsBox; 0395 } 0396 0397 QVBoxLayout* WSSettingsWidget::getSettingsBoxLayout() const 0398 { 0399 return d->settingsBoxLayout; 0400 } 0401 0402 QGroupBox* WSSettingsWidget::getAlbumBox() const 0403 { 0404 return d->albBox; 0405 } 0406 0407 QGridLayout* WSSettingsWidget::getAlbumBoxLayout() const 0408 { 0409 return d->albumsBoxLayout; 0410 } 0411 0412 QGroupBox* WSSettingsWidget::getOptionsBox() const 0413 { 0414 return d->optionsBox; 0415 } 0416 0417 QGridLayout* WSSettingsWidget::getOptionsBoxLayout() const 0418 { 0419 return d->optionsBoxLayout; 0420 } 0421 0422 QGroupBox* WSSettingsWidget::getUploadBox() const 0423 { 0424 return d->uploadBox; 0425 } 0426 0427 QVBoxLayout* WSSettingsWidget::getUploadBoxLayout() const 0428 { 0429 return d->uploadBoxLayout; 0430 } 0431 0432 QGroupBox* WSSettingsWidget::getSizeBox() const 0433 { 0434 return d->sizeBox; 0435 } 0436 0437 QVBoxLayout* WSSettingsWidget::getSizeBoxLayout() const 0438 { 0439 return d->sizeBoxLayout; 0440 } 0441 0442 QGroupBox* WSSettingsWidget::getAccountBox() const 0443 { 0444 return d->accountBox; 0445 } 0446 0447 QGridLayout* WSSettingsWidget::getAccountBoxLayout() const 0448 { 0449 return d->accountBoxLayout; 0450 } 0451 0452 QLabel* WSSettingsWidget::getHeaderLbl() const 0453 { 0454 return d->headerLbl; 0455 } 0456 0457 QLabel* WSSettingsWidget::getUserNameLabel() const 0458 { 0459 return d->userNameDisplayLbl; 0460 } 0461 0462 QPushButton* WSSettingsWidget::getChangeUserBtn() const 0463 { 0464 return d->changeUserBtn; 0465 } 0466 0467 QComboBox* WSSettingsWidget::getDimensionCoB() const 0468 { 0469 return d->dlDimensionCoB; 0470 } 0471 0472 QPushButton* WSSettingsWidget::getNewAlbmBtn() const 0473 { 0474 return d->newAlbumBtn; 0475 } 0476 0477 QPushButton* WSSettingsWidget::getReloadBtn() const 0478 { 0479 return d->reloadAlbumsBtn; 0480 } 0481 0482 QCheckBox* WSSettingsWidget::getOriginalCheckBox() const 0483 { 0484 return d->originalChB; 0485 } 0486 0487 QCheckBox* WSSettingsWidget::getResizeCheckBox() const 0488 { 0489 return d->resizeChB; 0490 } 0491 0492 QCheckBox* WSSettingsWidget::getPhotoIdCheckBox() const 0493 { 0494 return d->photoIdChB; 0495 } 0496 0497 QSpinBox* WSSettingsWidget::getDimensionSpB() const 0498 { 0499 return d->dimensionSpB; 0500 } 0501 0502 QSpinBox* WSSettingsWidget::getImgQualitySpB() const 0503 { 0504 return d->imageQualitySpB; 0505 } 0506 0507 QComboBox* WSSettingsWidget::getAlbumsCoB() const 0508 { 0509 return d->albumsCoB; 0510 } 0511 0512 } // namespace Digikam 0513 0514 #include "moc_wssettingswidget.cpp"