wmwidget.cpp 13.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
/* ============================================================
 *
 * This file is a part of kipi-plugins project
 * http://www.kipi-plugins.org
 *
 * Date        : 2011-02-11
 * Description : a kipi plugin to export images to wikimedia commons
 *
 * Copyright (C) 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com>
10
 * Copyright (C) 2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 *
 * 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 "wmwidget.moc"

// Qt includes

#include <QLabel>
#include <QSpinBox>
#include <QCheckBox>
#include <QGroupBox>
#include <QRadioButton>
#include <QButtonGroup>
#include <QProgressBar>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTabWidget>
#include <QComboBox>
#include <QLineEdit>
41
#include <QScrollArea>
42
43
44
45

// KDE includes

#include <kdebug.h>
46
#include <kvbox.h>
47
48
49
50
51
52
53
54
55
56
57
#include <KLocale>
#include <KDialog>
#include <KComboBox>
#include <KPushButton>
#include <KLineEdit>

// LibKIPI includes

#include <libkipi/interface.h>
#include <libkipi/uploadwidget.h>

58
59
60
// libKdcraw includes

#include <libkdcraw/rexpanderbox.h>
61
#include <libkdcraw/version.h>
62

63
64
65
66
// Local includes

#include "imageslist.h"

67
68
using namespace KDcrawIface;

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
namespace KIPIWikiMediaPlugin
{

WmWidget::WmWidget(QWidget* parent, KIPI::Interface* iface)
    : QWidget(parent)
{
    setObjectName("WmWidget");

    QHBoxLayout* mainLayout = new QHBoxLayout(this);

    // -------------------------------------------------------------------

    m_imgList = new KIPIPlugins::ImagesList(iface, this);
    m_imgList->setControlButtonsPlacement(KIPIPlugins::ImagesList::ControlButtonsBelow);
    m_imgList->setAllowRAW(true);
    m_imgList->loadImagesFromCurrentSelection();
    m_imgList->listView()->setWhatsThis(i18n("This is the list of images to upload to your Wikimedia account."));

87
88
89
90
91
92
93
94
95
    // ------------------------------------------------------------------------

    QScrollArea* sv = new QScrollArea(this);
    KVBox* panel    = new KVBox(sv->viewport());
    panel->setAutoFillBackground(false);
    sv->setWidget(panel);
    sv->setWidgetResizable(true);
    sv->setAutoFillBackground(false);
    sv->viewport()->setAutoFillBackground(false);
96

97
    m_headerLbl = new QLabel(panel);
98
99
100
101
    m_headerLbl->setWhatsThis(i18n("This is a clickable link to open the Wikimedia home page in a web browser."));
    m_headerLbl->setOpenExternalLinks(true);
    m_headerLbl->setFocusPolicy(Qt::NoFocus);

102
103
104
    m_settingsExpander = new RExpanderBox(panel);
    m_settingsExpander->setObjectName("MediaWiki Settings Expander");

105
106
    // ------------------------------------------------------------------------

107
108
    m_userBox    = new KVBox(panel);
    m_loginBox   = new QWidget(m_userBox);
109
110
111
112
113
114
115
116
117
118
119
120
    m_loginBox->setWhatsThis(i18n("This is the login form to your Wikimedia account."));
    QGridLayout* loginBoxLayout = new QGridLayout(m_loginBox);

    m_nameEdit   = new KLineEdit(m_loginBox);
    m_passwdEdit = new KLineEdit(m_loginBox);
    m_wikiSelect = new QComboBox(m_loginBox);
    m_passwdEdit->setEchoMode(KLineEdit::Password);

    m_wikiSelect->addItem(QString("test wikipedia"), QUrl("http://test.wikipedia.org/w/api.php"));
    m_wikiSelect->addItem(QString("en wikipedia"),   QUrl("http://en.wikipedia.org/w/api.php"));
    m_wikiSelect->addItem(QString("fr wikipedia"),   QUrl("http://fr.wikipedia.org/w/api.php"));

Gilles Caulier's avatar
polish    
Gilles Caulier committed
121
    QLabel* nameLabel     = new QLabel(m_loginBox);
Gilles Caulier's avatar
Gilles Caulier committed
122
    nameLabel->setText(i18n( "Login:" ));
123

Gilles Caulier's avatar
polish    
Gilles Caulier committed
124
    QLabel* passwdLabel   = new QLabel(m_loginBox);
125
126
    passwdLabel->setText(i18n("Password:"));

Gilles Caulier's avatar
polish    
Gilles Caulier committed
127
    QLabel* wikiLabel     = new QLabel(m_loginBox);
128
129
    wikiLabel->setText(i18n("Wiki:"));

130
    QPushButton* loginBtn = new QPushButton(m_loginBox);
131
132
    loginBtn->setAutoDefault(true);
    loginBtn->setDefault(true);
Gilles Caulier's avatar
Gilles Caulier committed
133
    loginBtn->setText(i18n("&Log in"));
134
135
136
137
138
139
140
141

    loginBoxLayout->addWidget(nameLabel,    0, 0, 1, 1);
    loginBoxLayout->addWidget(m_nameEdit,   0, 1, 1, 1);
    loginBoxLayout->addWidget(m_passwdEdit, 1, 1, 1, 1);
    loginBoxLayout->addWidget(m_wikiSelect, 2, 1, 1, 1);
    loginBoxLayout->addWidget(passwdLabel,  1, 0, 1, 1);
    loginBoxLayout->addWidget(wikiLabel,    2, 0, 1, 1);
    loginBoxLayout->addWidget(loginBtn,     3, 0, 1, 1);
142
143
    loginBoxLayout->setObjectName("m_loginBoxLayout");

144
    m_accountBox         = new KHBox(m_userBox);
145
146
    m_accountBox->setWhatsThis(i18n("This is the Wikimedia account that is currently logged in."));

147
148
    QLabel* userNameLbl  = new QLabel(m_accountBox);
    userNameLbl->setText(i18nc("Wikimedia account settings", "Logged as: "));
149
    m_userNameDisplayLbl = new QLabel(m_accountBox);
150
    QLabel* space        = new QLabel(m_accountBox);
151
152
153
    m_changeUserBtn      = new KPushButton(KGuiItem(i18n("Change Account"), "system-switch-user",
                               i18n("Logout and change Wikimedia Account used for transfer")),
                               m_accountBox);
154
155
    m_accountBox->setStretchFactor(space, 10);
    m_accountBox->hide();
156

157
158
    m_settingsExpander->addItem(m_userBox, i18n("Account"), QString("account"), true);
    m_settingsExpander->setItemIcon(0, SmallIcon("user-properties"));
159
160
161

    // ------------------------------------------------------------------------

162
    m_textBox                  = new QWidget(panel);
163
164
165
    m_textBox->setWhatsThis(i18n("This is the login form to your Wikimedia account."));
    QGridLayout* textBoxLayout = new QGridLayout(m_textBox);

166
    QLabel* desc      = new QLabel(i18n("Description:"), m_textBox);
167
168
    m_descriptionEdit = new QTextEdit(m_textBox);

169
    QLabel* aut  = new QLabel(i18n("Author:"), m_textBox);
170
171
    m_authorEdit = new KLineEdit(m_textBox);

172
173
    QLabel* licenceLabel = new QLabel(i18n("License:"), m_textBox);
    m_licenceComboBox    = new QComboBox(m_textBox);
174

Laurent Montel's avatar
Laurent Montel committed
175
176
177
178
179
180
181
182
183
184
185
    m_licenceComboBox->addItem(i18n("Own work, multi-license with CC-BY-SA-3.0 and GFDL"), QString("{{self|cc-by-sa-3.0|GFDL|migration=redundant}}"));
    m_licenceComboBox->addItem(i18n("Own work, multi-license with CC-BY-SA-3.0 and older"), QString("{{self|cc-by-sa-3.0,2.5,2.0,1.0}}"));
    m_licenceComboBox->addItem(i18n("Creative Commons Attribution-Share Alike 3.0"), QString("{{self|cc-by-sa-3.0}}"));
    m_licenceComboBox->addItem(i18n("Own work, Creative Commons Attribution 3.0"), QString("{{self|cc-by-3.0}}"));
    m_licenceComboBox->addItem(i18n("Own work, release into public domain under the CC-Zero license"), QString("{{self|cc-zero}}"));
    m_licenceComboBox->addItem(i18n("Author died more than 100 years ago"), QString("{{PD-old}}"));
    m_licenceComboBox->addItem(i18n("Photo of a two-dimensional work whose author died more than 100 years ago"), QString("{{PD-art}}"));
    m_licenceComboBox->addItem(i18n("First published in the United States before 1923"), QString("{{PD-US}}"));
    m_licenceComboBox->addItem(i18n("Work of a U.S. government agency"), QString("{{PD-USGov}}"));
    m_licenceComboBox->addItem(i18n("Simple typefaces, individual words or geometric shapes"), QString("{{PD-text}}"));
    m_licenceComboBox->addItem(i18n("Logos with only simple typefaces, individual words or geometric shapes"), QString("{{PD-textlogo}}"));
186

187
188
189
190
191
192
    textBoxLayout->addWidget(desc,              0, 0, 1, 1);
    textBoxLayout->addWidget(m_descriptionEdit, 0, 2, 1, 2);
    textBoxLayout->addWidget(aut,               1, 0, 1, 1);
    textBoxLayout->addWidget(m_authorEdit,      1, 2, 1, 2);
    textBoxLayout->addWidget(licenceLabel,      3, 0, 1, 1);
    textBoxLayout->addWidget(m_licenceComboBox, 3, 2, 1, 2);
193
    textBoxLayout->setObjectName("m_textBoxLayout");
194
195
196

    m_settingsExpander->addItem(m_textBox, i18n("Information"), QString("information"), true);
    m_settingsExpander->setItemIcon(1, SmallIcon("document-properties"));
197
198
199

    //------------------------------------------------------------------------------------

200
201
202
    m_optionsBox                  = new QWidget(panel);
    m_optionsBox->setWhatsThis(i18n("These are options that will be applied to photos before upload."));
    QGridLayout* optionsBoxLayout = new QGridLayout(m_optionsBox);
203

204
    m_resizeChB = new QCheckBox(m_optionsBox);
205
206
207
    m_resizeChB->setText(i18n("Resize photos before uploading"));
    m_resizeChB->setChecked(false);

208
    m_dimensionSpB = new QSpinBox(m_optionsBox);
209
210
211
212
213
214
    m_dimensionSpB->setMinimum(0);
    m_dimensionSpB->setMaximum(5000);
    m_dimensionSpB->setSingleStep(10);
    m_dimensionSpB->setValue(600);
    m_dimensionSpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    m_dimensionSpB->setEnabled(false);
215
    QLabel* dimensionLbl = new QLabel(i18n("Maximum size:"), m_optionsBox);
216

217
    m_imageQualitySpB = new QSpinBox(m_optionsBox);
218
219
220
221
222
    m_imageQualitySpB->setMinimum(0);
    m_imageQualitySpB->setMaximum(100);
    m_imageQualitySpB->setSingleStep(1);
    m_imageQualitySpB->setValue(85);
    m_imageQualitySpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
223
    QLabel* imageQualityLbl = new QLabel(i18n("JPEG quality:"), m_optionsBox);
224

Gilles Caulier's avatar
polish    
Gilles Caulier committed
225
    optionsBoxLayout->addWidget(m_resizeChB,       0, 0, 1, 2);
226
227
228
229
    optionsBoxLayout->addWidget(imageQualityLbl,   1, 0, 1, 1);
    optionsBoxLayout->addWidget(m_imageQualitySpB, 1, 1, 1, 1);
    optionsBoxLayout->addWidget(dimensionLbl,      2, 0, 1, 1);
    optionsBoxLayout->addWidget(m_dimensionSpB,    2, 1, 1, 1);
230
231
232
233
    optionsBoxLayout->setRowStretch(3, 10);
    optionsBoxLayout->setSpacing(KDialog::spacingHint());
    optionsBoxLayout->setMargin(KDialog::spacingHint());

234
235
    m_settingsExpander->addItem(m_optionsBox, i18n("Options"), QString("options"), true);
    m_settingsExpander->setItemIcon(2, SmallIcon("system-run"));
236
237
238

    // ------------------------------------------------------------------------

239
240
241
    m_progressBar = new QProgressBar(panel);
    m_progressBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    m_progressBar->hide();
242
243
244
245

    // ------------------------------------------------------------------------

    mainLayout->addWidget(m_imgList);
246
    mainLayout->addWidget(sv);
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
    mainLayout->setSpacing(KDialog::spacingHint());
    mainLayout->setMargin(0);

    updateLabels();  // use empty labels until login

    // ------------------------------------------------------------------------

    connect(m_resizeChB, SIGNAL( clicked() ),
            this, SLOT( slotResizeChecked() ));

    connect(m_changeUserBtn, SIGNAL(clicked()),
            this, SLOT(slotChangeUserClicked()));

    connect(loginBtn, SIGNAL(clicked()),
            this, SLOT(slotLoginClicked()));
}

WmWidget::~WmWidget()
{
}

268
269
void WmWidget::readSettings(KConfigGroup& group)
{
270
271
272
#if KDCRAW_VERSION >= 0x020000
    m_settingsExpander->readSettings(group);
#else
273
    m_settingsExpander->readSettings();
274
275
#endif

276
277
278
279
280
281
282
283
    m_resizeChB->setChecked(group.readEntry("Resize", false));
    m_dimensionSpB->setValue(group.readEntry("Dimension", 600));
    m_imageQualitySpB->setValue(group.readEntry("Quality", 85));
    slotResizeChecked();
}

void WmWidget::saveSettings(KConfigGroup& group)
{
284
285
286
#if KDCRAW_VERSION >= 0x020000
    m_settingsExpander->writeSettings(group);
#else
287
    m_settingsExpander->writeSettings();
288
289
#endif

290
291
292
293
294
    group.writeEntry("Resize", m_resizeChB->isChecked());
    group.readEntry("Dimension", m_dimensionSpB->value());
    group.readEntry("Quality", m_imageQualitySpB->value());
}

295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
KIPIPlugins::ImagesList* WmWidget::imagesList() const
{
    return m_imgList;
}

QProgressBar* WmWidget::progressBar() const
{
    return m_progressBar;
}

void WmWidget::updateLabels(const QString& name, const QString& url)
{
    QString web("http://commons.wikimedia.org");
    if (!url.isEmpty())
        web = url;

    m_headerLbl->setText(QString("<b><h2><a href='%1'>"
Laurent Montel's avatar
Laurent Montel committed
312
313
                                 "<font color=\"#3B5998\">%2</font>"
                                 "</a></h2></b>").arg(web).arg(i18n("Wikimedia commons")));
314
315
316
317
318
319
    if (name.isEmpty())
    {
        m_userNameDisplayLbl->clear();
    }
    else
    {
Laurent Montel's avatar
Laurent Montel committed
320
        m_userNameDisplayLbl->setText(QString::fromLatin1("<b>%1</b>").arg(name));
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
    }
}

void WmWidget::invertAccountLoginBox()
{
    if(m_accountBox->isHidden())
    {
        m_loginBox->hide();
        m_accountBox->show();
    }
    else
    {
        m_loginBox->show();
        m_accountBox->hide();
    }
}

void WmWidget::slotResizeChecked()
{
    m_dimensionSpB->setEnabled(m_resizeChB->isChecked());
    m_imageQualitySpB->setEnabled(m_resizeChB->isChecked());
}

void WmWidget::slotChangeUserClicked()
{
    emit signalChangeUserRequest();
}

void WmWidget::slotLoginClicked()
{
    emit signalLoginRequest(m_nameEdit->text(), m_passwdEdit->text(),
                            m_wikiSelect->itemData(m_wikiSelect->currentIndex()).toUrl());
}

QString WmWidget::author()
{
    kDebug() << "WmWidget::author()";
    return this->m_authorEdit->text();
}

QString WmWidget::description()
{
    kDebug() << "WmWidget::description()";
    return this->m_descriptionEdit->toPlainText();
}
366

367
368
369
370
371
372
373
QString WmWidget::licence()
{
    kDebug() << "WmWidget::licence()";
    return m_licenceComboBox->itemData(m_licenceComboBox->currentIndex()).toString();
}

} // namespace KIPIWikimediaPlugin