File indexing completed on 2025-01-05 03:53:43
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-12-01 0007 * Description : a tool to export images to Smugmug web service 0008 * 0009 * SPDX-FileCopyrightText: 2008-2009 by Luka Renko <lure at kubuntu dot org> 0010 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "smugwidget.h" 0017 0018 // Qt includes 0019 0020 #include <QLabel> 0021 #include <QSpinBox> 0022 #include <QCheckBox> 0023 #include <QGroupBox> 0024 #include <QRadioButton> 0025 #include <QGridLayout> 0026 #include <QHBoxLayout> 0027 #include <QVBoxLayout> 0028 #include <QComboBox> 0029 #include <QApplication> 0030 #include <QPushButton> 0031 #include <QLineEdit> 0032 0033 // KDE includes 0034 0035 #include <klocalizedstring.h> 0036 0037 // Local includes 0038 0039 0040 namespace DigikamGenericSmugPlugin 0041 { 0042 0043 SmugWidget::SmugWidget(QWidget* const parent, DInfoInterface* const iface, bool import) 0044 : QWidget(parent), 0045 m_iface(iface) 0046 { 0047 setObjectName(QLatin1String("SmugWidget")); 0048 0049 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0050 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0051 QHBoxLayout* const mainLayout = new QHBoxLayout(this); 0052 0053 // ------------------------------------------------------------------- 0054 0055 m_imgList = new DItemsList(this); 0056 m_imgList->setObjectName(QLatin1String("WebService ImagesList")); 0057 m_progressBar = new DProgressWdg(this); 0058 0059 m_imgList->appendControlButtonsWidget(m_progressBar); 0060 QBoxLayout* const blay = m_imgList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow); 0061 blay->setStretchFactor(m_progressBar, 20); 0062 0063 m_imgList->setAllowRAW(true); 0064 m_imgList->setIface(m_iface); 0065 m_imgList->loadImagesFromCurrentSelection(); 0066 m_imgList->listView()->setWhatsThis(i18n("This is the list of images to upload to your SmugMug account.")); 0067 0068 m_progressBar->hide(); 0069 0070 QWidget* const settingsBox = new QWidget(this); 0071 QVBoxLayout* const settingsBoxLayout = new QVBoxLayout(settingsBox); 0072 0073 m_headerLbl = new QLabel(settingsBox); 0074 m_headerLbl->setWhatsThis(i18n("This is a clickable link to open the SmugMug home page in a web browser.")); 0075 m_headerLbl->setOpenExternalLinks(true); 0076 m_headerLbl->setFocusPolicy(Qt::NoFocus); 0077 0078 // ------------------------------------------------------------------------ 0079 0080 QGroupBox* const accountBox = new QGroupBox(i18n("Account"), settingsBox); 0081 accountBox->setWhatsThis(i18n("This is the SmugMug account that will be used to authenticate.")); 0082 QGridLayout* const accountBoxLayout = new QGridLayout(accountBox); 0083 0084 m_anonymousRBtn = new QRadioButton(i18nc("smug account login", "Anonymous"), accountBox); 0085 m_anonymousRBtn->setWhatsThis(i18n("Login as anonymous to SmugMug web service.")); 0086 0087 m_accountRBtn = new QRadioButton(i18n("SmugMug Account"), accountBox); 0088 m_accountRBtn->setWhatsThis(i18n("Login to SmugMug web service using email and password.")); 0089 0090 m_userNameLbl = new QLabel(i18nc("smug account settings", "Name:"), accountBox); 0091 m_userName = new QLabel(accountBox); 0092 m_emailLbl = new QLabel(i18nc("smug account settings", "Email:"), accountBox); 0093 m_email = new QLabel(accountBox); 0094 m_changeUserBtn = new QPushButton(accountBox); 0095 0096 m_changeUserBtn->setText(i18n("Change Account")); 0097 m_changeUserBtn->setIcon(QIcon::fromTheme(QLatin1String("system-switch-user"))); 0098 m_changeUserBtn->setToolTip(i18n("Change SmugMug Account used to authenticate")); 0099 0100 accountBoxLayout->addWidget(m_anonymousRBtn, 0, 0, 1, 2); 0101 accountBoxLayout->addWidget(m_accountRBtn, 1, 0, 1, 2); 0102 accountBoxLayout->addWidget(m_userNameLbl, 2, 0, 1, 1); 0103 accountBoxLayout->addWidget(m_userName, 2, 1, 1, 1); 0104 accountBoxLayout->addWidget(m_emailLbl, 3, 0, 1, 1); 0105 accountBoxLayout->addWidget(m_email, 3, 1, 1, 1); 0106 accountBoxLayout->addWidget(m_changeUserBtn, 4, 1, 1, 1); 0107 accountBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0108 accountBoxLayout->setSpacing(spacing); 0109 0110 // ------------------------------------------------------------------------ 0111 0112 QGroupBox* const albumsBox = new QGroupBox(i18n("Album"), settingsBox); 0113 albumsBox->setWhatsThis(i18n("This is the SmugMug album that will be used for transfer.")); 0114 QGridLayout* const albumsBoxLayout = new QGridLayout(albumsBox); 0115 0116 m_albumsCoB = new QComboBox(albumsBox); 0117 m_albumsCoB->setEditable(false); 0118 m_nickNameLbl = new QLabel(i18n("Nickname:"), albumsBox); 0119 m_nickNameEdt = new QLineEdit(albumsBox); 0120 m_nickNameEdt->setWhatsThis(i18n("Nickname of SmugMug user to list albums.")); 0121 m_sitePasswordLbl = new QLabel(i18n("Site Password:"), albumsBox); 0122 m_sitePasswordEdt = new QLineEdit(albumsBox); 0123 m_sitePasswordEdt->setWhatsThis(i18n("Site-wide password for specified SmugMug nick/user.")); 0124 m_albumPasswordLbl = new QLabel(i18n("Album Password:"), albumsBox); 0125 m_albumPasswordEdt = new QLineEdit(albumsBox); 0126 m_albumPasswordEdt->setWhatsThis(i18n("Password for SmugMug album.")); 0127 0128 m_newAlbumBtn = new QPushButton(accountBox); 0129 m_newAlbumBtn->setText(i18n("New Album")); 0130 m_newAlbumBtn->setIcon(QIcon::fromTheme(QLatin1String("list-add"))); 0131 m_newAlbumBtn->setToolTip(i18n("Create new SmugMug album")); 0132 0133 m_reloadAlbumsBtn = new QPushButton(accountBox); 0134 m_reloadAlbumsBtn->setText(i18nc("reload album list", "Reload")); 0135 m_reloadAlbumsBtn->setIcon(QIcon::fromTheme(QLatin1String("view-refresh"))); 0136 m_reloadAlbumsBtn->setToolTip(i18n("Reload album list")); 0137 0138 albumsBoxLayout->addWidget(m_albumsCoB, 0, 0, 1, 5); 0139 albumsBoxLayout->addWidget(m_nickNameLbl, 1, 0, 1, 1); 0140 albumsBoxLayout->addWidget(m_nickNameEdt, 1, 1, 1, 3); 0141 albumsBoxLayout->addWidget(m_newAlbumBtn, 1, 3, 1, 1); 0142 albumsBoxLayout->addWidget(m_reloadAlbumsBtn, 1, 4, 1, 1); 0143 albumsBoxLayout->addWidget(m_sitePasswordLbl, 2, 0, 1, 1); 0144 albumsBoxLayout->addWidget(m_sitePasswordEdt, 2, 1, 1, 4); 0145 albumsBoxLayout->addWidget(m_albumPasswordLbl, 3, 0, 1, 1); 0146 albumsBoxLayout->addWidget(m_albumPasswordEdt, 3, 1, 1, 4); 0147 0148 // ------------------------------------------------------------------------ 0149 0150 QGroupBox* const uploadBox = new QGroupBox(i18n("Destination"), settingsBox); 0151 uploadBox->setWhatsThis(i18n("This is the location where SmugMug images will be downloaded.")); 0152 QVBoxLayout* const uploadBoxLayout = new QVBoxLayout(uploadBox); 0153 m_uploadWidget = m_iface->uploadWidget(uploadBox); 0154 uploadBoxLayout->addWidget(m_uploadWidget); 0155 0156 // ------------------------------------------------------------------------ 0157 0158 QGroupBox* const optionsBox = new QGroupBox(i18n("Options"), settingsBox); 0159 optionsBox->setWhatsThis(i18n("These are options that will be applied to images before upload.")); 0160 QGridLayout* const optionsBoxLayout = new QGridLayout(optionsBox); 0161 0162 m_resizeChB = new QCheckBox(optionsBox); 0163 m_resizeChB->setText(i18n("Resize photos before uploading")); 0164 m_resizeChB->setChecked(false); 0165 0166 m_dimensionSpB = new QSpinBox(optionsBox); 0167 m_dimensionSpB->setMinimum(0); 0168 m_dimensionSpB->setMaximum(15000); 0169 m_dimensionSpB->setSingleStep(10); 0170 m_dimensionSpB->setValue(600); 0171 m_dimensionSpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0172 m_dimensionSpB->setEnabled(false); 0173 QLabel* const dimensionLbl = new QLabel(i18n("Maximum dimension:"), optionsBox); 0174 0175 m_imageQualitySpB = new QSpinBox(optionsBox); 0176 m_imageQualitySpB->setMinimum(0); 0177 m_imageQualitySpB->setMaximum(100); 0178 m_imageQualitySpB->setSingleStep(1); 0179 m_imageQualitySpB->setValue(85); 0180 m_imageQualitySpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0181 QLabel* const imageQualityLbl = new QLabel(i18n("JPEG quality:"), optionsBox); 0182 0183 optionsBoxLayout->addWidget(m_resizeChB, 0, 0, 1, 5); 0184 optionsBoxLayout->addWidget(imageQualityLbl, 1, 1, 1, 1); 0185 optionsBoxLayout->addWidget(m_imageQualitySpB, 1, 2, 1, 1); 0186 optionsBoxLayout->addWidget(dimensionLbl, 2, 1, 1, 1); 0187 optionsBoxLayout->addWidget(m_dimensionSpB, 2, 2, 1, 1); 0188 optionsBoxLayout->setRowStretch(3, 10); 0189 optionsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0190 optionsBoxLayout->setSpacing(spacing); 0191 0192 // ------------------------------------------------------------------------ 0193 0194 settingsBoxLayout->addWidget(m_headerLbl); 0195 settingsBoxLayout->addWidget(accountBox); 0196 settingsBoxLayout->addWidget(albumsBox); 0197 settingsBoxLayout->addWidget(uploadBox); 0198 settingsBoxLayout->addWidget(optionsBox); 0199 settingsBoxLayout->setSpacing(spacing); 0200 settingsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing); 0201 0202 // ------------------------------------------------------------------------ 0203 0204 mainLayout->addWidget(m_imgList); 0205 mainLayout->addWidget(settingsBox); 0206 mainLayout->setSpacing(spacing); 0207 mainLayout->setContentsMargins(QMargins()); 0208 0209 updateLabels(); // use empty labels until login 0210 0211 // ------------------------------------------------------------------------ 0212 0213 connect(m_changeUserBtn, SIGNAL(clicked()), 0214 this, SLOT(slotChangeUserClicked())); 0215 0216 connect(m_resizeChB, SIGNAL(clicked()), 0217 this, SLOT(slotResizeChecked())); 0218 0219 connect(m_anonymousRBtn, SIGNAL(toggled(bool)), 0220 this, SLOT(slotAnonymousToggled(bool))); 0221 0222 // ------------------------------------------------------------------------ 0223 0224 if (import) 0225 { 0226 m_imgList->hide(); 0227 m_newAlbumBtn->hide(); 0228 optionsBox->hide(); 0229 0230 /** 0231 * Deactivate anonymous login functionality 0232 */ 0233 0234 m_anonymousRBtn->hide(); 0235 m_accountRBtn->hide(); 0236 m_nickNameLbl->hide(); 0237 m_nickNameEdt->hide(); 0238 m_sitePasswordLbl->hide(); 0239 m_sitePasswordEdt->hide(); 0240 m_albumPasswordLbl->hide(); 0241 m_albumPasswordEdt->hide(); 0242 } 0243 else 0244 { 0245 m_anonymousRBtn->hide(); 0246 m_accountRBtn->hide(); 0247 0248 m_nickNameLbl->hide(); 0249 m_nickNameEdt->hide(); 0250 m_sitePasswordLbl->hide(); 0251 m_sitePasswordEdt->hide(); 0252 m_albumPasswordLbl->hide(); 0253 m_albumPasswordEdt->hide(); 0254 0255 uploadBox->hide(); 0256 } 0257 } 0258 0259 SmugWidget::~SmugWidget() 0260 { 0261 } 0262 0263 DItemsList* SmugWidget::imagesList() const 0264 { 0265 return m_imgList; 0266 } 0267 0268 DProgressWdg* SmugWidget::progressBar() const 0269 { 0270 return m_progressBar; 0271 } 0272 0273 bool SmugWidget::isAnonymous() const 0274 { 0275 return m_anonymousRBtn->isChecked(); 0276 } 0277 0278 void SmugWidget::setAnonymous(bool checked) 0279 { 0280 m_anonymousRBtn->setChecked(checked); 0281 m_accountRBtn->setChecked(!checked); 0282 } 0283 0284 QString SmugWidget::getNickName() const 0285 { 0286 return m_nickNameEdt->text(); 0287 } 0288 0289 QString SmugWidget::getSitePassword() const 0290 { 0291 return m_sitePasswordEdt->text(); 0292 } 0293 0294 QString SmugWidget::getAlbumPassword() const 0295 { 0296 return m_albumPasswordEdt->text(); 0297 } 0298 0299 QString SmugWidget::getDestinationPath() const 0300 { 0301 QUrl url = m_iface->uploadUrl(); 0302 return url.toLocalFile(); 0303 } 0304 0305 void SmugWidget::setNickName(const QString& nick) 0306 { 0307 m_nickNameEdt->setText(nick); 0308 m_headerLbl->setText(QString::fromLatin1("<b><h2><a href='https://%1.smugmug.com'>" 0309 "<font color=\"#9ACD32\">SmugMug</font>" 0310 "</a></h2></b>").arg(nick)); 0311 } 0312 0313 void SmugWidget::updateLabels(const QString& email, const QString& name, const QString& nick) 0314 { 0315 m_email->setText(email); 0316 m_userName->setText(QString::fromLatin1("<b>%1</b>").arg(name)); 0317 QString web(QLatin1String("www")); 0318 0319 if (!nick.isEmpty()) 0320 { 0321 web = nick; 0322 } 0323 0324 m_headerLbl->setText(QString::fromLatin1("<b><h2><a href='https://%1.smugmug.com'>" 0325 "<font color=\"#9ACD32\">SmugMug</font>" 0326 "</a></h2></b>").arg(web)); 0327 } 0328 0329 void SmugWidget::slotAnonymousToggled(bool checked) 0330 { 0331 m_emailLbl->setEnabled(!checked); 0332 m_email->setEnabled(!checked); 0333 m_userNameLbl->setEnabled(!checked); 0334 m_userName->setEnabled(!checked); 0335 m_changeUserBtn->setEnabled(!checked); 0336 0337 Q_EMIT signalUserChangeRequest(checked); 0338 } 0339 0340 void SmugWidget::slotChangeUserClicked() 0341 { 0342 Q_EMIT signalUserChangeRequest(false); 0343 } 0344 0345 void SmugWidget::slotResizeChecked() 0346 { 0347 m_dimensionSpB->setEnabled(m_resizeChB->isChecked()); 0348 m_imageQualitySpB->setEnabled(m_resizeChB->isChecked()); 0349 } 0350 0351 } // namespace DigikamGenericSmugPlugin 0352 0353 #include "moc_smugwidget.cpp"