1 /* ============================================================
2 *
3 * This file is a part of KDE project
4 *
5 *
6 * Date : 2008-12-01
7 * Description : a kipi plugin to import/export images to/from
8 SmugMug web service
9 *
10 * Copyright (C) 2008-2009 by Luka Renko <lure at kubuntu dot org>
11 *
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software Foundation;
15 * either version 2, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "smugwidget.h"
25
26 // Qt includes
27
28 #include <QLabel>
29 #include <QSpinBox>
30 #include <QCheckBox>
31 #include <QGroupBox>
32 #include <QRadioButton>
33 #include <QGridLayout>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QComboBox>
37 #include <QApplication>
38 #include <QPushButton>
39 #include <QLineEdit>
40
41 // KDE includes
42
43 #include <klocalizedstring.h>
44
45 // Libkipi includes
46
47 #include <KIPI/Interface>
48 #include <KIPI/UploadWidget>
49 #include <KIPI/ImageCollection>
50
51 // Local includes
52
53 #include "kpimageslist.h"
54 #include "kpprogresswidget.h"
55
56 namespace KIPISmugPlugin
57 {
58
SmugWidget(QWidget * const parent,KIPI::Interface * const iface,bool import)59 SmugWidget::SmugWidget(QWidget* const parent, KIPI::Interface* const iface, bool import)
60 : QWidget(parent)
61 {
62 setObjectName(QString::fromLatin1("SmugWidget"));
63
64 const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
65
66 QHBoxLayout* const mainLayout = new QHBoxLayout(this);
67
68 // -------------------------------------------------------------------
69
70 m_imgList = new KIPIPlugins::KPImagesList(this);
71 m_imgList->setControlButtonsPlacement(KIPIPlugins::KPImagesList::ControlButtonsBelow);
72 m_imgList->setAllowRAW(true);
73 m_imgList->listView()->setWhatsThis(i18n("This is the list of images to upload to your SmugMug account."));
74
75 QWidget* const settingsBox = new QWidget(this);
76 QVBoxLayout* const settingsBoxLayout = new QVBoxLayout(settingsBox);
77
78 m_headerLbl = new QLabel(settingsBox);
79 m_headerLbl->setWhatsThis(i18n("This is a clickable link to open the SmugMug home page in a web browser."));
80 m_headerLbl->setOpenExternalLinks(true);
81 m_headerLbl->setFocusPolicy(Qt::NoFocus);
82
83 // ------------------------------------------------------------------------
84
85 QGroupBox* const accountBox = new QGroupBox(i18n("Account"), settingsBox);
86 accountBox->setWhatsThis(i18n("This is the SmugMug account that will be used to authenticate."));
87 QGridLayout* const accountBoxLayout = new QGridLayout(accountBox);
88
89 m_anonymousRBtn = new QRadioButton(i18nc("smug account login", "Anonymous"), accountBox);
90 m_anonymousRBtn->setWhatsThis(i18n("Login as anonymous to SmugMug web service."));
91
92 m_accountRBtn = new QRadioButton(i18n("SmugMug Account"), accountBox);
93 m_accountRBtn->setWhatsThis(i18n("Login to SmugMug web service using email and password."));
94
95 m_userNameLbl = new QLabel(i18nc("smug account settings", "Name:"), accountBox);
96 m_userName = new QLabel(accountBox);
97 m_emailLbl = new QLabel(i18nc("smug account settings", "Email:"), accountBox);
98 m_email = new QLabel(accountBox);
99 m_changeUserBtn = new QPushButton(accountBox);
100
101 m_changeUserBtn->setText(i18n("Change Account"));
102 m_changeUserBtn->setIcon(QIcon::fromTheme(QString::fromLatin1("system-switch-user")));
103 m_changeUserBtn->setToolTip(i18n("Change SmugMug Account used to authenticate"));
104
105 accountBoxLayout->addWidget(m_anonymousRBtn, 0, 0, 1, 2);
106 accountBoxLayout->addWidget(m_accountRBtn, 1, 0, 1, 2);
107 accountBoxLayout->addWidget(m_userNameLbl, 2, 0, 1, 1);
108 accountBoxLayout->addWidget(m_userName, 2, 1, 1, 1);
109 accountBoxLayout->addWidget(m_emailLbl, 3, 0, 1, 1);
110 accountBoxLayout->addWidget(m_email, 3, 1, 1, 1);
111 accountBoxLayout->addWidget(m_changeUserBtn, 4, 1, 1, 1);
112 accountBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing);
113 accountBoxLayout->setSpacing(spacing);
114
115 // ------------------------------------------------------------------------
116
117 QGroupBox* const albumsBox = new QGroupBox(i18n("Album"), settingsBox);
118 albumsBox->setWhatsThis(i18n("This is the SmugMug album that will be used for transfer."));
119 QGridLayout* const albumsBoxLayout = new QGridLayout(albumsBox);
120
121 m_albumsCoB = new QComboBox(albumsBox);
122 m_albumsCoB->setEditable(false);
123 m_nickNameLbl = new QLabel(i18n("Nickname:"), albumsBox);
124 m_nickNameEdt = new QLineEdit(albumsBox);
125 m_nickNameEdt->setWhatsThis(i18n("Nickname of SmugMug user to list albums."));
126 m_sitePasswordLbl = new QLabel(i18n("Site Password:"), albumsBox);
127 m_sitePasswordEdt = new QLineEdit(albumsBox);
128 m_sitePasswordEdt->setWhatsThis(i18n("Site-wide password for specified SmugMug nick/user."));
129 m_albumPasswordLbl = new QLabel(i18n("Album Password:"), albumsBox);
130 m_albumPasswordEdt = new QLineEdit(albumsBox);
131 m_albumPasswordEdt->setWhatsThis(i18n("Password for SmugMug album."));
132
133 m_newAlbumBtn = new QPushButton(accountBox);
134 m_newAlbumBtn->setText(i18n("New Album"));
135 m_newAlbumBtn->setIcon(QIcon::fromTheme(QString::fromLatin1("list-add")));
136 m_newAlbumBtn->setToolTip(i18n("Create new SmugMug album"));
137
138 m_reloadAlbumsBtn = new QPushButton(accountBox);
139 m_reloadAlbumsBtn->setText(i18nc("reload album list", "Reload"));
140 m_reloadAlbumsBtn->setIcon(QIcon::fromTheme(QString::fromLatin1("view-refresh")));
141 m_reloadAlbumsBtn->setToolTip(i18n("Reload album list"));
142
143 albumsBoxLayout->addWidget(m_albumsCoB, 0, 0, 1, 5);
144 albumsBoxLayout->addWidget(m_nickNameLbl, 1, 0, 1, 1);
145 albumsBoxLayout->addWidget(m_nickNameEdt, 1, 1, 1, 3);
146 albumsBoxLayout->addWidget(m_newAlbumBtn, 1, 3, 1, 1);
147 albumsBoxLayout->addWidget(m_reloadAlbumsBtn, 1, 4, 1, 1);
148 albumsBoxLayout->addWidget(m_sitePasswordLbl, 2, 0, 1, 1);
149 albumsBoxLayout->addWidget(m_sitePasswordEdt, 2, 1, 1, 4);
150 albumsBoxLayout->addWidget(m_albumPasswordLbl, 3, 0, 1, 1);
151 albumsBoxLayout->addWidget(m_albumPasswordEdt, 3, 1, 1, 4);
152
153 // ------------------------------------------------------------------------
154
155 QGroupBox* const uploadBox = new QGroupBox(i18n("Destination"), settingsBox);
156 uploadBox->setWhatsThis(i18n("This is the location where SmugMug images will be downloaded."));
157 QVBoxLayout* const uploadBoxLayout = new QVBoxLayout(uploadBox);
158 m_uploadWidget = iface->uploadWidget(uploadBox);
159 uploadBoxLayout->addWidget(m_uploadWidget);
160
161 // ------------------------------------------------------------------------
162
163 QGroupBox* const optionsBox = new QGroupBox(i18n("Options"), settingsBox);
164 optionsBox->setWhatsThis(i18n("These are options that will be applied to images before upload."));
165 QGridLayout* const optionsBoxLayout = new QGridLayout(optionsBox);
166
167 m_resizeChB = new QCheckBox(optionsBox);
168 m_resizeChB->setText(i18n("Resize photos before uploading"));
169 m_resizeChB->setChecked(false);
170
171 m_dimensionSpB = new QSpinBox(optionsBox);
172 m_dimensionSpB->setMinimum(0);
173 m_dimensionSpB->setMaximum(15000);
174 m_dimensionSpB->setSingleStep(10);
175 m_dimensionSpB->setValue(600);
176 m_dimensionSpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
177 m_dimensionSpB->setEnabled(false);
178 QLabel* const dimensionLbl = new QLabel(i18n("Maximum dimension:"), optionsBox);
179
180 m_imageQualitySpB = new QSpinBox(optionsBox);
181 m_imageQualitySpB->setMinimum(0);
182 m_imageQualitySpB->setMaximum(100);
183 m_imageQualitySpB->setSingleStep(1);
184 m_imageQualitySpB->setValue(85);
185 m_imageQualitySpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
186 QLabel* const imageQualityLbl = new QLabel(i18n("JPEG quality:"), optionsBox);
187
188 optionsBoxLayout->addWidget(m_resizeChB, 0, 0, 1, 5);
189 optionsBoxLayout->addWidget(imageQualityLbl, 1, 1, 1, 1);
190 optionsBoxLayout->addWidget(m_imageQualitySpB, 1, 2, 1, 1);
191 optionsBoxLayout->addWidget(dimensionLbl, 2, 1, 1, 1);
192 optionsBoxLayout->addWidget(m_dimensionSpB, 2, 2, 1, 1);
193 optionsBoxLayout->setRowStretch(3, 10);
194 optionsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing);
195 optionsBoxLayout->setSpacing(spacing);
196
197 m_progressBar = new KIPIPlugins::KPProgressWidget(settingsBox);
198 m_progressBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
199 m_progressBar->hide();
200
201 // ------------------------------------------------------------------------
202
203 settingsBoxLayout->addWidget(m_headerLbl);
204 settingsBoxLayout->addWidget(accountBox);
205 settingsBoxLayout->addWidget(albumsBox);
206 settingsBoxLayout->addWidget(uploadBox);
207 settingsBoxLayout->addWidget(optionsBox);
208 settingsBoxLayout->addWidget(m_progressBar);
209 settingsBoxLayout->setSpacing(spacing);
210 settingsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing);
211
212 // ------------------------------------------------------------------------
213
214 mainLayout->addWidget(m_imgList);
215 mainLayout->addWidget(settingsBox);
216 mainLayout->setSpacing(spacing);
217 mainLayout->setContentsMargins(QMargins());
218
219 updateLabels(); // use empty labels until login
220
221 // ------------------------------------------------------------------------
222
223 connect(m_changeUserBtn, SIGNAL(clicked()),
224 this, SLOT(slotChangeUserClicked()));
225
226 connect(m_resizeChB, SIGNAL(clicked()),
227 this, SLOT(slotResizeChecked()));
228
229 connect(m_anonymousRBtn, SIGNAL(toggled(bool)),
230 this, SLOT(slotAnonymousToggled(bool)));
231
232 // ------------------------------------------------------------------------
233
234 if (import)
235 {
236 m_imgList->hide();
237 m_newAlbumBtn->hide();
238 optionsBox->hide();
239 }
240 else
241 {
242 m_anonymousRBtn->hide();
243 m_accountRBtn->hide();
244
245 m_nickNameLbl->hide();
246 m_nickNameEdt->hide();
247 m_sitePasswordLbl->hide();
248 m_sitePasswordEdt->hide();
249 m_albumPasswordLbl->hide();
250 m_albumPasswordEdt->hide();
251
252 uploadBox->hide();
253 }
254 }
255
~SmugWidget()256 SmugWidget::~SmugWidget()
257 {
258 }
259
imagesList() const260 KIPIPlugins::KPImagesList* SmugWidget::imagesList() const
261 {
262 return m_imgList;
263 }
264
progressBar() const265 KIPIPlugins::KPProgressWidget* SmugWidget::progressBar() const
266 {
267 return m_progressBar;
268 }
269
isAnonymous() const270 bool SmugWidget::isAnonymous() const
271 {
272 return m_anonymousRBtn->isChecked();
273 }
274
setAnonymous(bool checked)275 void SmugWidget::setAnonymous(bool checked)
276 {
277 m_anonymousRBtn->setChecked(checked);
278 m_accountRBtn->setChecked(!checked);
279 }
280
getNickName() const281 QString SmugWidget::getNickName() const
282 {
283 return m_nickNameEdt->text();
284 }
285
getSitePassword() const286 QString SmugWidget::getSitePassword() const
287 {
288 return m_sitePasswordEdt->text();
289 }
290
getAlbumPassword() const291 QString SmugWidget::getAlbumPassword() const
292 {
293 return m_albumPasswordEdt->text();
294 }
295
getDestinationPath() const296 QString SmugWidget::getDestinationPath() const
297 {
298 return m_uploadWidget->selectedImageCollection().uploadUrl().toLocalFile();
299 }
300
setNickName(const QString & nick)301 void SmugWidget::setNickName(const QString& nick)
302 {
303 m_nickNameEdt->setText(nick);
304 m_headerLbl->setText(QString::fromLatin1("<b><h2><a href='http://%1.smugmug.com'>"
305 "<font color=\"#9ACD32\">SmugMug</font>"
306 "</a></h2></b>").arg(nick));
307 }
308
updateLabels(const QString & email,const QString & name,const QString & nick)309 void SmugWidget::updateLabels(const QString& email, const QString& name, const QString& nick)
310 {
311 m_email->setText(email);
312 m_userName->setText(QString::fromLatin1("<b>%1</b>").arg(name));
313 QString web(QString::fromLatin1("www"));
314
315 if (!nick.isEmpty())
316 web = nick;
317
318 m_headerLbl->setText(QString::fromLatin1("<b><h2><a href='http://%1.smugmug.com'>"
319 "<font color=\"#9ACD32\">SmugMug</font>"
320 "</a></h2></b>").arg(web));
321 }
322
slotAnonymousToggled(bool checked)323 void SmugWidget::slotAnonymousToggled(bool checked)
324 {
325 m_emailLbl->setEnabled(!checked);
326 m_email->setEnabled(!checked);
327 m_userNameLbl->setEnabled(!checked);
328 m_userName->setEnabled(!checked);
329 m_changeUserBtn->setEnabled(!checked);
330
331 emit signalUserChangeRequest(checked);
332 }
333
slotChangeUserClicked()334 void SmugWidget::slotChangeUserClicked()
335 {
336 emit signalUserChangeRequest(false);
337 }
338
slotResizeChecked()339 void SmugWidget::slotResizeChecked()
340 {
341 m_dimensionSpB->setEnabled(m_resizeChB->isChecked());
342 m_imageQualitySpB->setEnabled(m_resizeChB->isChecked());
343 }
344
345 } // namespace KIPISmugPlugin
346