File indexing completed on 2025-01-05 03:53:38

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-02-11
0007  * Description : a tool to export images to MediaWiki web service
0008  *
0009  * SPDX-FileCopyrightText: 2011      by Alexandre Mendes <alex dot mendes1988 at gmail dot com>
0010  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2012      by Parthasarathy Gopavarapu <gparthasarathy93 at gmail dot com>
0012  * SPDX-FileCopyrightText: 2012      by Nathan Damie <nathan dot damie at gmail dot com>
0013  * SPDX-FileCopyrightText: 2012      by Iliya Ivanov <ilko2002 at abv dot bg>
0014  * SPDX-FileCopyrightText: 2012-2016 by Peter Potrowl <peter dot potrowl at gmail dot com>
0015  *
0016  * SPDX-License-Identifier: GPL-2.0-or-later
0017  *
0018  * ============================================================ */
0019 
0020 #include "mediawikiwidget.h"
0021 
0022 // Qt includes
0023 
0024 #include <QButtonGroup>
0025 #include <QCheckBox>
0026 #include <QGridLayout>
0027 #include <QHBoxLayout>
0028 #include <QLabel>
0029 #include <QMap>
0030 #include <QProgressBar>
0031 #include <QRadioButton>
0032 #include <QScrollArea>
0033 #include <QSpinBox>
0034 #include <QTabWidget>
0035 #include <QVBoxLayout>
0036 #include <QComboBox>
0037 #include <QApplication>
0038 #include <QPushButton>
0039 #include <QLineEdit>
0040 #include <QGroupBox>
0041 
0042 // KDE includes
0043 
0044 #include <klocalizedstring.h>
0045 #include <ksharedconfig.h>
0046 #include <kconfiggroup.h>
0047 
0048 // Local includes
0049 
0050 #include "wstoolutils.h"
0051 #include "digikam_debug.h"
0052 #include "dlayoutbox.h"
0053 #include "dtextedit.h"
0054 
0055 namespace DigikamGenericMediaWikiPlugin
0056 {
0057 
0058 class Q_DECL_HIDDEN MediaWikiWidget::Private
0059 {
0060 public:
0061 
0062     explicit Private()
0063     {
0064         fileBox            = nullptr;
0065         titleEdit          = nullptr;
0066         descEdit           = nullptr;
0067         dateEdit           = nullptr;
0068         longitudeEdit      = nullptr;
0069         latitudeEdit       = nullptr;
0070         categoryEdit       = nullptr;
0071         loginHeaderLbl     = nullptr;
0072         nameEdit           = nullptr;
0073         passwdEdit         = nullptr;
0074         newWikiSv          = nullptr;
0075         newWikiNameEdit    = nullptr;
0076         newWikiUrlEdit     = nullptr;
0077         wikiSelect         = nullptr;
0078         authorEdit         = nullptr;
0079         sourceEdit         = nullptr;
0080         genCatEdit         = nullptr;
0081         genTxtEdit         = nullptr;
0082         genComEdit         = nullptr;
0083         headerLbl          = nullptr;
0084         wikiNameDisplayLbl = nullptr;
0085         userNameDisplayLbl = nullptr;
0086         changeUserBtn      = nullptr;
0087         resizeChB          = nullptr;
0088         dimensionSpB       = nullptr;
0089         imageQualitySpB    = nullptr;
0090         removeMetaChB      = nullptr;
0091         removeGeoChB       = nullptr;
0092         licenseComboBox    = nullptr;
0093         progressBar        = nullptr;
0094         iface              = nullptr;
0095         imgList            = nullptr;
0096         defaultMessage     = i18nc("@info", "Select an image");
0097         loginGBox          = nullptr;
0098         userGBox           = nullptr;
0099     }
0100 
0101     QWidget*                                 fileBox;
0102     DTextEdit*                               titleEdit;
0103     DTextEdit*                               descEdit;
0104     QLineEdit*                               dateEdit;
0105     QLineEdit*                               longitudeEdit;
0106     QLineEdit*                               latitudeEdit;
0107     DTextEdit*                               categoryEdit;
0108 
0109     QLabel*                                  loginHeaderLbl;
0110     QLineEdit*                               nameEdit;
0111     QLineEdit*                               passwdEdit;
0112     QScrollArea*                             newWikiSv;
0113     QLineEdit*                               newWikiNameEdit;
0114     QLineEdit*                               newWikiUrlEdit;
0115     QComboBox*                               wikiSelect;
0116 
0117     QLineEdit*                               authorEdit;
0118     QLineEdit*                               sourceEdit;
0119 
0120     DTextEdit*                               genCatEdit;
0121     DTextEdit*                               genTxtEdit;
0122     DTextEdit*                               genComEdit;
0123 
0124     QLabel*                                  headerLbl;
0125     QLabel*                                  wikiNameDisplayLbl;
0126     QLabel*                                  userNameDisplayLbl;
0127     QPushButton*                             changeUserBtn;
0128 
0129     QCheckBox*                               resizeChB;
0130     QSpinBox*                                dimensionSpB;
0131     QSpinBox*                                imageQualitySpB;
0132     QCheckBox*                               removeMetaChB;
0133     QCheckBox*                               removeGeoChB;
0134     QComboBox*                               licenseComboBox;
0135 
0136     QGroupBox*                               loginGBox;
0137     QGroupBox*                               userGBox;
0138 
0139     DProgressWdg*                            progressBar;
0140     DInfoInterface*                          iface;
0141     DItemsList*                              imgList;
0142 
0143     QStringList                              WikisHistory;
0144     QStringList                              UrlsHistory;
0145 
0146     QString                                  defaultMessage;
0147 
0148     QMap <QString, QMap <QString, QString> > imagesDescInfo;
0149 };
0150 
0151 MediaWikiWidget::MediaWikiWidget(DInfoInterface* const iface, QWidget* const parent)
0152     : QWidget(parent),
0153       d      (new Private)
0154 {
0155     setObjectName(QLatin1String("MediaWikiWidget"));
0156 
0157     d->iface                      = iface;
0158     const int spacing             = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0159                                          QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0160     QVBoxLayout* const mainLayout = new QVBoxLayout(this);
0161 
0162     // -------------------------------------------------------------------
0163 
0164     d->headerLbl           = new QLabel(this);
0165     d->headerLbl->setWhatsThis(i18nc("@info", "This is a clickable link to open the MediaWiki home page in a web browser."));
0166     d->headerLbl->setOpenExternalLinks(true);
0167     d->headerLbl->setFocusPolicy(Qt::NoFocus);
0168 
0169     d->imgList             = new DItemsList(this);
0170     d->imgList->setObjectName(QLatin1String("WebService ImagesList"));
0171     d->progressBar         = new DProgressWdg(this);
0172 
0173     d->imgList->appendControlButtonsWidget(d->progressBar);
0174     QBoxLayout* const blay = d->imgList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow);
0175     blay->setStretchFactor(d->progressBar, 20);
0176 
0177     d->imgList->setAllowRAW(true);
0178     d->imgList->setIface(d->iface);
0179     d->imgList->loadImagesFromCurrentSelection();
0180     d->imgList->listView()->setWhatsThis(i18nc("@info", "This is the list of images to upload to the wiki."));
0181     d->progressBar->hide();
0182 
0183     // --------------------- Upload tab ----------------------------------
0184 
0185     QScrollArea* const wrapperScroll   = new QScrollArea(this);
0186     DVBox* const wrapperPan            = new DVBox(wrapperScroll->viewport());
0187     wrapperScroll->setWidget(wrapperPan);
0188     wrapperScroll->setWidgetResizable(true);
0189     wrapperScroll->setVisible(false);
0190 
0191     QWidget* const wrapper             = new QWidget(wrapperPan);
0192     QHBoxLayout* const wrapperLayout   = new QHBoxLayout(wrapper);
0193 
0194     QScrollArea* const upload          = new QScrollArea(wrapper);
0195     DVBox* const pan                   = new DVBox(upload->viewport());
0196     pan->setAutoFillBackground(true);
0197 
0198     upload->setWidget(pan);
0199     upload->setWidgetResizable(true);
0200 
0201     DVBox* const uploadBox             = new DVBox(pan);
0202     QWidget* const uploadPanel         = new QWidget(uploadBox);
0203     QVBoxLayout* const uploadBoxLayout = new QVBoxLayout(uploadPanel);
0204 
0205     d->fileBox = new QWidget(uploadBox);
0206     d->fileBox->setWhatsThis(i18nc("@info", "This is the login form to your account on the chosen wiki."));
0207     QGridLayout* const fileBoxLayout = new QGridLayout(d->fileBox);
0208 
0209     loadItemInfoFirstLoad();
0210 
0211     d->titleEdit    = new DTextEdit(d->defaultMessage, d->fileBox);
0212     d->titleEdit->setLinesVisible(1);
0213     d->dateEdit     = new QLineEdit(d->defaultMessage, d->fileBox);
0214 
0215     d->descEdit     = new DTextEdit(0, d->fileBox);
0216     d->descEdit->setPlainText(d->defaultMessage);
0217     d->descEdit->setTabChangesFocus(1);
0218     d->descEdit->setAcceptRichText(false);
0219     d->categoryEdit = new DTextEdit(0, d->fileBox);
0220     d->categoryEdit->setPlainText(d->defaultMessage);
0221     d->categoryEdit->setTabChangesFocus(1);
0222     d->categoryEdit->setAcceptRichText(false);
0223 
0224     d->latitudeEdit  = new QLineEdit(d->defaultMessage, d->fileBox);
0225     d->longitudeEdit = new QLineEdit(d->defaultMessage, d->fileBox);
0226 
0227     QLabel* const titleLabel     = new QLabel(d->fileBox);
0228     titleLabel->setText(i18nc("@label: properties", "Title:"));
0229     QLabel* const dateLabel      = new QLabel(d->fileBox);
0230     dateLabel->setText(i18nc("@label: properties", "Date:"));
0231     QLabel* const descLabel      = new QLabel(d->fileBox);
0232     descLabel->setText(i18nc("@label: properties", "Description:"));
0233     QLabel* const categoryLabel  = new QLabel(d->fileBox);
0234     categoryLabel->setText(i18nc("@label: properties", "Categories:"));
0235     QLabel* const latitudeLabel  = new QLabel(d->fileBox);
0236     latitudeLabel->setText(i18nc("@label: properties", "Latitude:"));
0237     QLabel* const longitudeLabel = new QLabel(d->fileBox);
0238     longitudeLabel->setText(i18nc("@label: properties", "Longitude:"));
0239 
0240     uploadBoxLayout->setSpacing(spacing);
0241     uploadBoxLayout->addWidget(d->fileBox, 0, Qt::AlignTop);
0242 
0243     fileBoxLayout->addWidget(titleLabel,       1, 0, 1, 1);
0244     fileBoxLayout->addWidget(dateLabel,        2, 0, 1, 1);
0245     fileBoxLayout->addWidget(descLabel,        3, 0, 1, 1);
0246     fileBoxLayout->addWidget(categoryLabel,    4, 0, 1, 1);
0247     fileBoxLayout->addWidget(latitudeLabel,    5, 0, 1, 1);
0248     fileBoxLayout->addWidget(longitudeLabel,   6, 0, 1, 1);
0249     fileBoxLayout->addWidget(d->titleEdit,     1, 1, 1, 3);
0250     fileBoxLayout->addWidget(d->dateEdit,      2, 1, 1, 3);
0251     fileBoxLayout->addWidget(d->descEdit,      3, 1, 1, 3);
0252     fileBoxLayout->addWidget(d->categoryEdit,  4, 1, 1, 3);
0253     fileBoxLayout->addWidget(d->latitudeEdit,  5, 1, 1, 3);
0254     fileBoxLayout->addWidget(d->longitudeEdit, 6, 1, 1, 3);
0255 
0256     // --------------------- Config tab ----------------------------------
0257 
0258     QScrollArea* const config = new QScrollArea(wrapper);
0259     DVBox* const panel2       = new DVBox(config->viewport());
0260     config->setWidget(panel2);
0261     config->setWidgetResizable(true);
0262 
0263     // --------------------- Account area ----------------------------------
0264 
0265     d->userGBox = new QGroupBox(panel2);
0266     d->userGBox->setTitle(i18nc("@option", "Account"));
0267     d->userGBox->setWhatsThis(i18nc("@info", "This is the login form to your MediaWiki account."));
0268 
0269     QGridLayout* const loginBoxLayout = new QGridLayout(d->userGBox);
0270     d->userGBox->setLayout(loginBoxLayout);
0271 
0272     d->wikiSelect                 = new QComboBox(d->userGBox);
0273     d->wikiSelect->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
0274     QPushButton* const newWikiBtn = new QPushButton(QIcon::fromTheme(QLatin1String("list-add")),
0275                                                     i18nc("@option: button", "New"), d->userGBox);
0276     newWikiBtn->setToolTip(i18nc("@info", "Add a wiki to this list"));
0277     d->nameEdit                   = new QLineEdit(d->userGBox);
0278     d->passwdEdit                 = new QLineEdit(d->userGBox);
0279     d->passwdEdit->setEchoMode(QLineEdit::Password);
0280 
0281     d->wikiSelect->addItem(i18nc("@item", "Wikimedia Commons"),  QLatin1String("https://commons.wikimedia.org/w/api.php"));
0282     d->wikiSelect->addItem(i18nc("@item", "Wikimedia Meta"),     QLatin1String("https://meta.wikimedia.org/w/api.php"));
0283     d->wikiSelect->addItem(i18nc("@item", "Wikipedia"),          QLatin1String("https://en.wikipedia.org/w/api.php"));
0284     d->wikiSelect->addItem(i18nc("@item", "Wikibooks"),          QLatin1String("https://en.wikibooks.org/w/api.php"));
0285     d->wikiSelect->addItem(i18nc("@item", "Wikinews"),           QLatin1String("https://en.wikinews.org/w/api.php"));
0286     d->wikiSelect->addItem(i18nc("@item", "Wikiquote"),          QLatin1String("https://en.wikiquote.org/w/api.php"));
0287     d->wikiSelect->addItem(i18nc("@item", "Wikisource"),         QLatin1String("https://en.wikinews.org/w/api.php"));
0288     d->wikiSelect->addItem(i18nc("@item", "Wiktionary"),         QLatin1String("https://en.wiktionary.org/w/api.php"));
0289     d->wikiSelect->addItem(i18nc("@item", "MediaWiki"),          QLatin1String("https://www.MediaWiki.org/w/api.php"));
0290     d->wikiSelect->addItem(i18nc("@item", "Wikia Foto"),         QLatin1String("https://foto.wikia.com/api.php"));
0291     d->wikiSelect->addItem(i18nc("@item", "Wikia Uncyclopedia"), QLatin1String("https://uncyclopedia.wikia.com/api.php"));
0292 
0293     d->wikiSelect->setEditable(false);
0294 
0295     QLabel* const wikiLabel = new QLabel(d->userGBox);
0296     wikiLabel->setText(i18nc("@label", "Wiki:"));
0297 
0298     // --------------------- New wiki area ----------------------------------
0299 
0300     d->newWikiSv              = new QScrollArea(this);
0301     DVBox* const newWikiPanel = new DVBox(d->newWikiSv->viewport());
0302     d->newWikiSv->setWidget(newWikiPanel);
0303     d->newWikiSv->setWidgetResizable(true);
0304     d->newWikiSv->setVisible(false);
0305 
0306     QWidget* const newWikiBox        = new QWidget(newWikiPanel);
0307     newWikiBox->setWhatsThis(i18nc("@info", "These are options for adding a Wiki."));
0308 
0309     QGridLayout* const newWikiLayout = new QGridLayout(newWikiBox);
0310 
0311     QLabel* const newWikiNameLabel   = new QLabel(newWikiPanel);
0312     newWikiNameLabel->setText(i18nc("@label: name of wiki area", "Name:"));
0313 
0314     QLabel* const newWikiUrlLabel    = new QLabel(newWikiPanel);
0315     newWikiUrlLabel->setText(i18nc("@label", "API URL:"));
0316 
0317     d->newWikiNameEdit            = new QLineEdit(newWikiPanel);
0318     d->newWikiUrlEdit             = new QLineEdit(newWikiPanel);
0319 
0320     QPushButton* const addWikiBtn = new QPushButton(QIcon::fromTheme(QLatin1String("list-add")),
0321                                                     i18nc("@action: button", "Add"), newWikiPanel);
0322     addWikiBtn->setToolTip(i18nc("@info", "Add a new wiki"));
0323 
0324     newWikiLayout->addWidget(newWikiNameLabel,   0, 0, 1, 1);
0325     newWikiLayout->addWidget(d->newWikiNameEdit, 0, 1, 1, 1);
0326     newWikiLayout->addWidget(newWikiUrlLabel,    1, 0, 1, 1);
0327     newWikiLayout->addWidget(d->newWikiUrlEdit,  1, 1, 1, 1);
0328     newWikiLayout->addWidget(addWikiBtn,         2, 1, 1, 1);
0329 
0330     QLabel* const nameLabel     = new QLabel(d->userGBox);
0331     nameLabel->setText(i18nc("@label", "Login:" ));
0332 
0333     QLabel* const passwdLabel   = new QLabel(d->userGBox);
0334     passwdLabel->setText(i18nc("@label", "Password:"));
0335 
0336     QPushButton* const loginBtn = new QPushButton(d->userGBox);
0337     loginBtn->setAutoDefault(true);
0338     loginBtn->setDefault(true);
0339     loginBtn->setText(i18nc("@action", "&Log in"));
0340 
0341     loginBoxLayout->addWidget(wikiLabel,     0, 0, 1, 1);
0342     loginBoxLayout->addWidget(d->wikiSelect, 0, 1, 1, 1);
0343     loginBoxLayout->addWidget(newWikiBtn,    0, 2, 1, 1);
0344     loginBoxLayout->addWidget(d->newWikiSv,  1, 1, 3, 3);
0345     loginBoxLayout->addWidget(nameLabel,     4, 0, 1, 1);
0346     loginBoxLayout->addWidget(d->nameEdit,   4, 1, 1, 1);
0347     loginBoxLayout->addWidget(passwdLabel,   5, 0, 1, 1);
0348     loginBoxLayout->addWidget(d->passwdEdit, 5, 1, 1, 1);
0349     loginBoxLayout->addWidget(loginBtn,      6, 0, 1, 1);
0350     loginBoxLayout->setObjectName(QLatin1String("loginBoxLayout"));
0351 
0352     // --------------------- Login info area ----------------------------------
0353 
0354     d->loginGBox = new QGroupBox(panel2);
0355     d->loginGBox->setTitle(i18nc("@option", "Login Information"));
0356 
0357     QGridLayout* const linfoBoxLayout = new QGridLayout(d->loginGBox);
0358     d->loginGBox->setLayout(linfoBoxLayout);
0359 
0360     QLabel* const wikiNameLbl = new QLabel(d->loginGBox);
0361     wikiNameLbl->setText(i18nc("@label: name of the wiki the user is currently logged on", "Logged on: "));
0362     d->wikiNameDisplayLbl     = new QLabel(d->loginGBox);
0363 
0364     QLabel* const userNameLbl = new QLabel(d->loginGBox);
0365     userNameLbl->setText(i18nc("@label: username which is used to connect to the wiki", "Logged as: "));
0366     d->userNameDisplayLbl     = new QLabel(d->loginGBox);
0367 
0368     d->changeUserBtn          = new QPushButton(QIcon::fromTheme(QLatin1String("system-switch-user")),
0369                                                 i18nc("@action: button", "Change Account"), d->loginGBox);
0370     d->changeUserBtn->setToolTip(i18nc("@info", "Logout and change the account used for transfer"));
0371 
0372     linfoBoxLayout->addWidget(wikiNameLbl,           0, 0, 1, 1);
0373     linfoBoxLayout->addWidget(d->wikiNameDisplayLbl, 0, 1, 1, 1);
0374     linfoBoxLayout->addWidget(userNameLbl,           1, 0, 1, 1);
0375     linfoBoxLayout->addWidget(d->userNameDisplayLbl, 1, 1, 1, 1);
0376     linfoBoxLayout->addWidget(d->changeUserBtn,      2, 0, 1, 2);
0377     d->loginGBox->hide();
0378 
0379     // --------------------- Info area ----------------------------------
0380 
0381     QGroupBox* const textGBox = new QGroupBox(panel2);
0382     textGBox->setTitle(i18nc("@option", "Information"));
0383     textGBox->setWhatsThis(i18nc("@info", "This is the login form to your account on the chosen wiki."));
0384 
0385     QGridLayout* const textBoxLayout = new QGridLayout(textGBox);
0386     textGBox->setLayout(textBoxLayout);
0387 
0388     QLabel* const authorLbl  = new QLabel(i18nc("@label", "Author:"), textGBox);
0389     d->authorEdit            = new QLineEdit(textGBox);
0390 
0391     QLabel* const sourceLbl  = new QLabel(i18nc("@label: source file", "Source:"), textGBox);
0392     d->sourceEdit            = new QLineEdit(textGBox);
0393 
0394     QLabel* const licenseLbl = new QLabel(i18nc("@label", "License:"), textGBox);
0395     d->licenseComboBox       = new QComboBox(textGBox);
0396     d->licenseComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
0397 
0398     d->licenseComboBox->addItem(i18nc("@item", "Own work, Creative Commons Attribution-Share Alike 4.0"),
0399                                        QLatin1String("{{self|cc-by-sa-4.0}}"));
0400     d->licenseComboBox->addItem(i18nc("@item", "Own work, multi-license with CC-BY-SA-3.0 and GFDL"),
0401                                        QLatin1String("{{self|cc-by-sa-3.0|GFDL|migration=redundant}}"));
0402     d->licenseComboBox->addItem(i18nc("@item", "Own work, multi-license with CC-BY-SA-3.0 and older"),
0403                                        QLatin1String("{{self|cc-by-sa-3.0,2.5,2.0,1.0}}"));
0404     d->licenseComboBox->addItem(i18nc("@item", "Own work, Creative Commons Attribution-Share Alike 3.0"),
0405                                        QLatin1String("{{self|cc-by-sa-3.0}}"));
0406     d->licenseComboBox->addItem(i18nc("@item", "Own work, Creative Commons Attribution 3.0"),
0407                                        QLatin1String("{{self|cc-by-3.0}}"));
0408     d->licenseComboBox->addItem(i18nc("@item", "Own work, release into public domain under the CC-Zero license"),
0409                                        QLatin1String("{{self|cc-zero}}"));
0410     d->licenseComboBox->addItem(i18nc("@item", "Author died more than 100 years ago"),
0411                                        QLatin1String("{{PD-old}}"));
0412     d->licenseComboBox->addItem(i18nc("@item", "Photo of a two-dimensional work whose author died more than 100 years ago"),
0413                                        QLatin1String("{{PD-art}}"));
0414     d->licenseComboBox->addItem(i18nc("@item", "First published in the United States before 1923"),
0415                                        QLatin1String("{{PD-US}}"));
0416     d->licenseComboBox->addItem(i18nc("@item", "Work of a U.S. government agency"),
0417                                        QLatin1String("{{PD-USGov}}"));
0418     d->licenseComboBox->addItem(i18nc("@item", "Simple typefaces, individual words or geometric shapes"),
0419                                        QLatin1String("{{PD-text}}"));
0420     d->licenseComboBox->addItem(i18nc("@item", "Logos with only simple typefaces, individual words or geometric shapes"),
0421                                        QLatin1String("{{PD-textlogo}}"));
0422     d->licenseComboBox->addItem(i18nc("@item", "No license specified (not recommended for public wiki sites)"),
0423                                        QLatin1String(""));
0424 
0425     QLabel* const genCatLbl = new QLabel(i18nc("@label", "Generic categories:"), textGBox);
0426     d->genCatEdit           = new DTextEdit(0, textGBox);
0427     d->genCatEdit->setTabChangesFocus(1);
0428     d->genCatEdit->setWhatsThis(i18nc("@info", "This is a place to enter categories that will be added to all the files."));
0429     d->genCatEdit->setAcceptRichText(false);
0430 
0431     QLabel* const genTxtLbl = new QLabel(i18nc("@label", "Generic text:"), textGBox);
0432     d->genTxtEdit           = new DTextEdit(0, textGBox);
0433     d->genTxtEdit->setTabChangesFocus(1);
0434     d->genTxtEdit->setWhatsThis(i18nc("@info", "This is a place to enter text that will be added to all the files, "
0435                                       "below the Information template."));
0436     d->genTxtEdit->setAcceptRichText(false);
0437 
0438     QLabel* const genComLbl = new QLabel(i18nc("@label", "Upload comments:"), textGBox);
0439     d->genComEdit           = new DTextEdit(0, textGBox);
0440     d->genComEdit->setTabChangesFocus(1);
0441     d->genComEdit->setWhatsThis(i18nc("@info", "This is a place to enter text that will be used as upload comments. "
0442                                       "The default of 'Uploaded via digiKam uploader' will be used if empty."));
0443     d->genComEdit->setAcceptRichText(false);
0444 
0445     textBoxLayout->addWidget(authorLbl,          1, 0, 1, 1);
0446     textBoxLayout->addWidget(sourceLbl,          2, 0, 1, 1);
0447     textBoxLayout->addWidget(licenseLbl,         3, 0, 1, 1);
0448     textBoxLayout->addWidget(genCatLbl,          4, 0, 1, 1);
0449     textBoxLayout->addWidget(genTxtLbl,          5, 0, 1, 1);
0450     textBoxLayout->addWidget(genComLbl,          6, 0, 1, 1);
0451 
0452     textBoxLayout->addWidget(d->authorEdit,      1, 2, 1, 2);
0453     textBoxLayout->addWidget(d->sourceEdit,      2, 2, 1, 2);
0454     textBoxLayout->addWidget(d->licenseComboBox, 3, 2, 1, 2);
0455     textBoxLayout->addWidget(d->genCatEdit,      4, 2, 1, 2);
0456     textBoxLayout->addWidget(d->genTxtEdit,      5, 2, 1, 2);
0457     textBoxLayout->addWidget(d->genComEdit,      6, 2, 1, 2);
0458     textBoxLayout->setObjectName(QLatin1String("textBoxLayout"));
0459 
0460     // --------------------- Options area ----------------------------------
0461 
0462     QGroupBox* const optGBox = new QGroupBox(panel2);
0463     optGBox->setTitle(i18nc("@option", "Options"));
0464     optGBox->setWhatsThis(i18nc("@info", "These are options that will be applied to photos before upload."));
0465 
0466     QGridLayout* const optionsBoxLayout = new QGridLayout(optGBox);
0467     optGBox->setLayout(optionsBoxLayout);
0468 
0469     d->resizeChB = new QCheckBox(optGBox);
0470     d->resizeChB->setText(i18nc("@option", "Resize photos before uploading"));
0471     d->resizeChB->setChecked(false);
0472 
0473     d->dimensionSpB            = new QSpinBox(optGBox);
0474     d->dimensionSpB->setMinimum(0);
0475     d->dimensionSpB->setMaximum(10000);
0476     d->dimensionSpB->setSingleStep(10);
0477     d->dimensionSpB->setValue(1600);
0478     d->dimensionSpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
0479     d->dimensionSpB->setEnabled(false);
0480     QLabel* const dimensionLbl = new QLabel(i18nc("@label", "Maximum size:"), optGBox);
0481 
0482     d->imageQualitySpB         = new QSpinBox(optGBox);
0483     d->imageQualitySpB->setMinimum(0);
0484     d->imageQualitySpB->setMaximum(100);
0485     d->imageQualitySpB->setSingleStep(1);
0486     d->imageQualitySpB->setValue(85);
0487     d->imageQualitySpB->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
0488     QLabel* const imageQualityLbl = new QLabel(i18nc("@label", "JPEG quality:"), optGBox);
0489 
0490     d->removeMetaChB = new QCheckBox(optGBox);
0491     d->removeMetaChB->setText(i18nc("@option", "Remove metadata from file"));
0492     d->removeMetaChB->setChecked(false);
0493 
0494     d->removeGeoChB = new QCheckBox(optGBox);
0495     d->removeGeoChB->setText(i18nc("@option", "Remove coordinates from file"));
0496     d->removeGeoChB->setChecked(false);
0497 
0498     optionsBoxLayout->addWidget(d->resizeChB,       0, 0, 1, 2);
0499     optionsBoxLayout->addWidget(dimensionLbl,       1, 0, 1, 1);
0500     optionsBoxLayout->addWidget(imageQualityLbl,    2, 0, 1, 1);
0501     optionsBoxLayout->addWidget(d->dimensionSpB,    1, 1, 1, 1);
0502     optionsBoxLayout->addWidget(d->imageQualitySpB, 2, 1, 1, 1);
0503     optionsBoxLayout->addWidget(d->removeMetaChB,   3, 0, 1, 2);
0504     optionsBoxLayout->addWidget(d->removeGeoChB,    4, 0, 1, 2);
0505     optionsBoxLayout->setRowStretch(3, 10);
0506     optionsBoxLayout->setSpacing(spacing);
0507     optionsBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0508 
0509     // ------------------------------------------------------------------------
0510 
0511     QTabWidget* const tabWidget = new QTabWidget;
0512     tabWidget->addTab(upload, i18nc("@item", "Items Properties"));
0513     tabWidget->addTab(config, i18nc("@item", "Upload Settings"));
0514     tabWidget->setMinimumWidth(350);
0515 
0516     // ------------------------------------------------------------------------
0517 
0518     wrapperLayout->addWidget(d->imgList);
0519     wrapperLayout->addWidget(tabWidget);
0520     wrapperLayout->setStretch(0, 10);
0521     wrapperLayout->setStretch(1, 5);
0522 
0523     mainLayout->addWidget(d->headerLbl);
0524     mainLayout->addWidget(wrapper);
0525     mainLayout->setSpacing(spacing);
0526     mainLayout->setContentsMargins(QMargins());
0527 
0528     updateLabels();  // use empty labels until login
0529 
0530     // --------------------- Slots definition ----------------------------------
0531 
0532     connect(d->resizeChB, SIGNAL(clicked()),
0533             this, SLOT(slotResizeChecked()));
0534 
0535     connect(d->removeMetaChB, SIGNAL(clicked()),
0536             this, SLOT(slotRemoveMetaChecked()));
0537 
0538     connect(d->changeUserBtn, SIGNAL(clicked()),
0539             this, SLOT(slotChangeUserClicked()));
0540 
0541     connect(loginBtn, SIGNAL(clicked()),
0542             this, SLOT(slotLoginClicked()));
0543 
0544     connect(newWikiBtn, SIGNAL(clicked()),
0545             this, SLOT(slotNewWikiClicked()));
0546 
0547     connect(addWikiBtn, SIGNAL(clicked()),
0548             this, SLOT(slotAddWikiClicked()));
0549 
0550     connect(d->titleEdit, SIGNAL(editingFinished()),
0551             this, SLOT(slotRestoreExtension()));
0552 
0553     connect(d->titleEdit, SIGNAL(textChanged()),
0554             this, SLOT(slotApplyTitle()));
0555 
0556     connect(d->dateEdit, SIGNAL(textEdited(QString)),
0557             this, SLOT(slotApplyDate()));
0558 
0559     // Problem: textChanged() is also called when the text is changed by setText()
0560     // textEdited() would be better, but QTextEdit does not have this.
0561     // Solution for the moment: we do not setText() when the selection changes
0562 
0563     connect(d->categoryEdit, SIGNAL(textChanged()),
0564             this, SLOT(slotApplyCategories()));
0565 
0566     // Problem: textChanged() is also called when the text is changed by setText()
0567     // textEdited() would be better, but QTextEdit does not have this.
0568     // Solution for the moment: we do not setText() when the selection changes
0569 
0570     connect(d->descEdit, SIGNAL(textChanged()),
0571             this, SLOT(slotApplyDescription()));
0572 
0573     connect(d->latitudeEdit, SIGNAL(textEdited(QString)),
0574             this, SLOT(slotApplyLatitude()));
0575 
0576     connect(d->longitudeEdit, SIGNAL(textEdited(QString)),
0577             this, SLOT(slotApplyLongitude()));
0578 
0579     connect(d->imgList, SIGNAL(signalItemClicked(QTreeWidgetItem*)),
0580             this, SLOT(slotLoadImagesDesc(QTreeWidgetItem*)));
0581 
0582     connect(d->imgList, SIGNAL(signalImageListChanged()),
0583             this, SLOT(slotRemoveImagesDesc()));
0584 }
0585 
0586 MediaWikiWidget::~MediaWikiWidget()
0587 {
0588     delete d;
0589 }
0590 
0591 void MediaWikiWidget::readSettings(KConfigGroup& group)
0592 {
0593     qCDebug(DIGIKAM_WEBSERVICES_LOG) <<  "Read settings from" << group.name();
0594 
0595     d->authorEdit->setText(group.readEntry("Author",           ""));
0596     d->sourceEdit->setText(group.readEntry("Source",           "{{own}}"));
0597 
0598     d->genCatEdit->setText(group.readEntry("genCategories",    "Uploaded with digiKam uploader"));
0599     d->genTxtEdit->setText(group.readEntry("genText",          ""));
0600 
0601     d->genComEdit->setText(group.readEntry("Comments",         "Uploaded with digiKam uploader"));
0602     d->resizeChB->setChecked(group.readEntry("Resize",         false));
0603     d->dimensionSpB->setValue(group.readEntry("Dimension",     1600));
0604     d->imageQualitySpB->setValue(group.readEntry("Quality",    85));
0605     d->removeMetaChB->setChecked(group.readEntry("RemoveMeta", false));
0606     d->removeGeoChB->setChecked(group.readEntry("RemoveGeo",   false));
0607     slotResizeChecked();
0608     slotRemoveMetaChecked();
0609 
0610     d->WikisHistory = group.readEntry("Wikis history",         QStringList());
0611     d->UrlsHistory  = group.readEntry("Urls history",          QStringList());
0612 
0613     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "UrlHistory.size: " << d->UrlsHistory.size() << "; WikisHistory.size:" << d->WikisHistory.size();
0614 
0615     for (int i = 0 ; i < d->UrlsHistory.size() && i < d->WikisHistory.size() ; ++i)
0616     {
0617         d->wikiSelect->addItem(d->WikisHistory.at(i), d->UrlsHistory.at(i));
0618     }
0619 }
0620 
0621 void MediaWikiWidget::saveSettings(KConfigGroup& group)
0622 {
0623     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Save settings to" << group.name();
0624 
0625     group.writeEntry("Author",        d->authorEdit->text());
0626     group.writeEntry("Source",        d->sourceEdit->text());
0627 
0628     group.writeEntry("genCategories", d->genCatEdit->toPlainText());
0629     group.writeEntry("genText",       d->genTxtEdit->toPlainText());
0630     group.writeEntry("Comments",      d->genComEdit->toPlainText());
0631 
0632     group.writeEntry("Resize",        d->resizeChB->isChecked());
0633     group.writeEntry("Dimension",     d->dimensionSpB->value());
0634     group.writeEntry("Quality",       d->imageQualitySpB->value());
0635 
0636     group.writeEntry("RemoveMeta",    d->removeMetaChB->isChecked());
0637     group.writeEntry("RemoveGeo",     d->removeGeoChB->isChecked());
0638 }
0639 
0640 DItemsList* MediaWikiWidget::imagesList() const
0641 {
0642     return d->imgList;
0643 }
0644 
0645 DProgressWdg* MediaWikiWidget::progressBar() const
0646 {
0647     return d->progressBar;
0648 }
0649 
0650 void MediaWikiWidget::updateLabels(const QString& userName, const QString& wikiName, const QString& url)
0651 {
0652     QString web = QLatin1String("https://www.MediaWiki.org");
0653 
0654     if (url.isEmpty())
0655     {
0656         d->wikiNameDisplayLbl->clear();
0657     }
0658     else
0659     {
0660         web = url;
0661         d->wikiNameDisplayLbl->setText(QString::fromLatin1("<b>%1</b>").arg(wikiName));
0662     }
0663 
0664     d->headerLbl->setText(QString::fromUtf8("<h2><b><a href='%1'><font color=\"#3B5998\">%2</font></a></b></h2>").arg(web).arg(wikiName));
0665 
0666     if (userName.isEmpty())
0667     {
0668         d->userNameDisplayLbl->clear();
0669     }
0670     else
0671     {
0672         d->userNameDisplayLbl->setText(QString::fromLatin1("<b>%1</b>").arg(userName));
0673     }
0674 }
0675 
0676 void MediaWikiWidget::invertAccountLoginBox()
0677 {
0678     if (d->loginGBox->isHidden())
0679     {
0680         d->userGBox->hide();
0681         d->loginGBox->show();
0682     }
0683     else
0684     {
0685         d->userGBox->show();
0686         d->loginGBox->hide();
0687     }
0688 }
0689 
0690 void MediaWikiWidget::slotResizeChecked()
0691 {
0692     d->dimensionSpB->setEnabled(d->resizeChB->isChecked());
0693     d->imageQualitySpB->setEnabled(d->resizeChB->isChecked());
0694 }
0695 
0696 void MediaWikiWidget::slotRemoveMetaChecked()
0697 {
0698     d->removeGeoChB->setEnabled(!d->removeMetaChB->isChecked());
0699     d->removeGeoChB->setChecked(d->removeMetaChB->isChecked());
0700 }
0701 
0702 void MediaWikiWidget::slotChangeUserClicked()
0703 {
0704     Q_EMIT signalChangeUserRequest();
0705 }
0706 
0707 void MediaWikiWidget::slotLoginClicked()
0708 {
0709     Q_EMIT signalLoginRequest(d->nameEdit->text(), d->passwdEdit->text(),
0710                               d->wikiSelect->itemText(d->wikiSelect->currentIndex()),
0711                               d->wikiSelect->itemData(d->wikiSelect->currentIndex()).toUrl());
0712 }
0713 
0714 void MediaWikiWidget::slotNewWikiClicked()
0715 {
0716     if (d->newWikiSv->isVisible())
0717     {
0718         d->newWikiSv->setVisible(false);
0719     }
0720     else
0721     {
0722         d->newWikiSv->setVisible(true);
0723     }
0724 }
0725 
0726 void MediaWikiWidget::slotAddWikiClicked()
0727 {
0728     KSharedConfigPtr config = KSharedConfig::openConfig();
0729     KConfigGroup group      = config->group(QLatin1String("MediaWiki export settings"));
0730 
0731     d->UrlsHistory << d->newWikiUrlEdit->text();
0732     group.writeEntry(QLatin1String("Urls history"), d->UrlsHistory);
0733 
0734     d->WikisHistory << d->newWikiNameEdit->text();
0735     group.writeEntry(QLatin1String("Wikis history"), d->WikisHistory);
0736 
0737     d->wikiSelect->addItem(d->newWikiNameEdit->text(), d->newWikiUrlEdit->text());
0738     d->wikiSelect->setCurrentIndex(d->wikiSelect->count()-1);
0739 
0740     slotNewWikiClicked();
0741 }
0742 
0743 void MediaWikiWidget::loadItemInfoFirstLoad()
0744 {
0745     QList<QUrl> urls = d->imgList->imageUrls(false);
0746 
0747     d->imagesDescInfo.clear();
0748 
0749     for (int j = 0 ; j < urls.size() ; ++j)
0750     {
0751         loadItemInfo(urls.at(j));
0752     }
0753 }
0754 
0755 void MediaWikiWidget::loadItemInfo(const QUrl& url)
0756 {
0757     DItemInfo info(d->iface->itemInfo(url));
0758     QStringList keywar        = info.keywords();
0759     QString date              = info.dateTime().toString(Qt::ISODate).replace(QLatin1Char('T'), QLatin1Char(' '), Qt::CaseSensitive);
0760     QString title             = info.name();
0761     QString description       = info.title();
0762     QString currentCategories;
0763     QString latitude;
0764     QString longitude;
0765 
0766     for (int i = 0 ; i < keywar.size() ; ++i)
0767     {
0768         if (i == keywar.size() - 1)
0769         {
0770             currentCategories.append(keywar.at(i));
0771         }
0772         else
0773         {
0774             currentCategories.append(keywar.at(i)).append(QLatin1Char('\n'));
0775         }
0776     }
0777 
0778     if (info.hasGeolocationInfo())
0779     {
0780         latitude  = QString::number(info.latitude(),  'f', 9);
0781         longitude = QString::number(info.longitude(), 'f', 9);
0782     }
0783 
0784     QMap<QString, QString> imageMetaData;
0785     imageMetaData[QLatin1String("title")]       = title;
0786     imageMetaData[QLatin1String("date")]        = date;
0787     imageMetaData[QLatin1String("categories")]  = currentCategories;
0788     imageMetaData[QLatin1String("description")] = description;
0789     imageMetaData[QLatin1String("latitude")]    = latitude;
0790     imageMetaData[QLatin1String("longitude")]   = longitude;
0791     d->imagesDescInfo.insert(url.toLocalFile(), imageMetaData);
0792 }
0793 
0794 void MediaWikiWidget::clearEditFields()
0795 {
0796     d->titleEdit->setText(d->defaultMessage);
0797     d->dateEdit->setText(d->defaultMessage);
0798     d->descEdit->setText(d->defaultMessage);
0799     d->categoryEdit->setText(d->defaultMessage);
0800     d->latitudeEdit->setText(d->defaultMessage);
0801     d->longitudeEdit->setText(d->defaultMessage);
0802 }
0803 
0804 void MediaWikiWidget::slotLoadImagesDesc(QTreeWidgetItem* item)
0805 {
0806     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0807     DItemsListViewItem* const l_item     = dynamic_cast<DItemsListViewItem*>(item);
0808 
0809     if (!l_item)
0810         return;
0811 
0812     QMap<QString, QString> imageMetaData;
0813 
0814     if (!d->imagesDescInfo.contains(l_item->url().toLocalFile()))
0815     {
0816         loadItemInfo(l_item->url());
0817     }
0818 
0819     imageMetaData = d->imagesDescInfo[l_item->url().toLocalFile()];
0820 
0821     d->titleEdit->setText(imageMetaData[QLatin1String("title")]);
0822     d->dateEdit->setText(imageMetaData[QLatin1String("date")].replace(QLatin1Char('T'), QLatin1Char(' '), Qt::CaseSensitive));
0823     d->latitudeEdit->setText(imageMetaData[QLatin1String("latitude")]);
0824     d->longitudeEdit->setText(imageMetaData[QLatin1String("longitude")]);
0825 
0826     if (selectedItems.size() == 1)
0827     {
0828         d->categoryEdit->setText(imageMetaData[QLatin1String("categories")]);
0829         d->descEdit->setText(imageMetaData[QLatin1String("description")]);
0830     }
0831 }
0832 
0833 void MediaWikiWidget::slotRemoveImagesDesc()
0834 {
0835     QList<QUrl> items = d->imgList->imageUrls();
0836     QStringList toRemove;
0837 
0838     for (QMap <QString, QMap <QString, QString> >::const_iterator it = d->imagesDescInfo.constBegin() ;
0839          it != d->imagesDescInfo.constEnd() ; ++it)
0840     {
0841         QString path = it.key();
0842 
0843         if (!items.contains(QUrl::fromLocalFile(path)))
0844         {
0845             toRemove << path;
0846         }
0847     }
0848 
0849     Q_FOREACH (const QString& path, toRemove)
0850     {
0851         d->imagesDescInfo.remove(path);
0852         qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Remove" << path << "; new length:" << d->imagesDescInfo.size();
0853     }
0854 }
0855 
0856 void MediaWikiWidget::slotRestoreExtension()
0857 {
0858     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "RestoreExtension";
0859 
0860     QString imageTitle;
0861     QString originalExtension;
0862     QString currentExtension;
0863     QList<QUrl> urls;
0864     QMap<QString, QString> imageMetaData;
0865     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0866 
0867     // Build the list of items to rename
0868 
0869     for (int i = 0 ; i < selectedItems.size() ; ++i)
0870     {
0871         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
0872 
0873         if (l_item)
0874             urls.append(l_item->url());
0875     }
0876 
0877     for (int i = 0 ; i < urls.size() ; ++i)
0878     {
0879         imageMetaData = d->imagesDescInfo[urls.at(i).toLocalFile()];
0880         imageTitle    = imageMetaData[QLatin1String("title")];
0881 
0882         // Add original extension if removed
0883 
0884         currentExtension  = imageTitle.split(QLatin1Char('.')).last();
0885         originalExtension = urls.at(i).toLocalFile().split(QLatin1Char('.')).last();
0886 
0887         if (QString::compare(currentExtension, originalExtension, Qt::CaseInsensitive) != 0)
0888         {
0889             imageTitle.append(QLatin1Char('.')).append(originalExtension);
0890             d->titleEdit->setText(imageTitle);
0891         }
0892 
0893         qCDebug(DIGIKAM_WEBSERVICES_LOG) << urls.at(i).toLocalFile() << "renamed to" << imageTitle;
0894         imageMetaData[QLatin1String("title")]       = imageTitle;
0895         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
0896     }
0897 }
0898 
0899 void MediaWikiWidget::slotApplyTitle()
0900 {
0901     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "ApplyTitle";
0902 
0903     QString givenTitle = title();
0904     QString imageTitle;
0905     QString number;
0906     QList<QUrl> urls;
0907     QMap<QString, QString> imageMetaData;
0908     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0909     QStringList parts;
0910 
0911     const int minLength = givenTitle.count(QLatin1Char('#'));
0912 
0913     // Build the list of items to rename
0914 
0915     for (int i = 0 ; i < selectedItems.size() ; ++i)
0916     {
0917         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
0918 
0919         if (l_item)
0920             urls.append(l_item->url());
0921     }
0922 
0923     for (int i = 0 ; i < urls.size() ; ++i)
0924     {
0925         imageMetaData = d->imagesDescInfo[urls.at(i).toLocalFile()];
0926         imageTitle    = givenTitle;
0927 
0928         // If there is at least one #, replace it the correct number
0929 
0930         if (minLength > 0)
0931         {
0932             parts      = imageTitle.split(QLatin1Char('#'), QT_KEEP_EMPTY_PARTS);
0933             imageTitle = parts.first().append(QLatin1Char('#')).append(parts.last());
0934             number     = QString::number(i + 1);
0935 
0936             while (number.length() < minLength)
0937             {
0938                 number.prepend(QLatin1Char('0'));
0939             }
0940 
0941             imageTitle.replace(imageTitle.indexOf(QLatin1Char('#')), 1, number);
0942         }
0943 
0944         qCDebug(DIGIKAM_WEBSERVICES_LOG) << urls.at(i).toLocalFile() << "renamed to" << imageTitle;
0945         imageMetaData[QLatin1String("title")]       = imageTitle;
0946         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
0947     }
0948 }
0949 
0950 void MediaWikiWidget::slotApplyDate()
0951 {
0952     QList<QUrl> urls;
0953     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0954 
0955     for (int i = 0 ; i < selectedItems.size() ; ++i)
0956     {
0957         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
0958 
0959         if (l_item)
0960             urls.append(l_item->url());
0961     }
0962 
0963     for (int i = 0 ; i < urls.size() ; ++i)
0964     {
0965         QMap<QString, QString> imageMetaData;
0966         imageMetaData                               = d->imagesDescInfo[urls.at(i).toLocalFile()];
0967         imageMetaData[QLatin1String("date")]        = date();
0968         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
0969     }
0970 }
0971 
0972 void MediaWikiWidget::slotApplyCategories()
0973 {
0974     QList<QUrl> urls;
0975     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0976 
0977     for (int i = 0 ; i < selectedItems.size() ; ++i)
0978     {
0979         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
0980 
0981         if (l_item)
0982             urls.append(l_item->url());
0983     }
0984 
0985     for (int i = 0 ; i < urls.size() ; ++i)
0986     {
0987         QMap<QString, QString> imageMetaData;
0988         imageMetaData                               = d->imagesDescInfo[urls.at(i).toLocalFile()];
0989         imageMetaData[QLatin1String("categories")]  = categories();
0990         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
0991     }
0992 }
0993 
0994 void MediaWikiWidget::slotApplyDescription()
0995 {
0996     QList<QUrl> urls;
0997     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
0998 
0999     for (int i = 0 ; i < selectedItems.size() ; ++i)
1000     {
1001         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
1002 
1003         if (l_item)
1004             urls.append(l_item->url());
1005     }
1006 
1007     for (int i = 0 ; i < urls.size() ; ++i)
1008     {
1009         QMap<QString, QString> imageMetaData;
1010         imageMetaData                               = d->imagesDescInfo[urls.at(i).toLocalFile()];
1011         imageMetaData[QLatin1String("description")] = description();
1012         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
1013     }
1014 }
1015 
1016 void MediaWikiWidget::slotApplyLatitude()
1017 {
1018 
1019     QList<QUrl> urls;
1020     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
1021 
1022     for (int i = 0 ; i < selectedItems.size() ; ++i)
1023     {
1024         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
1025 
1026         if (l_item)
1027             urls.append(l_item->url());
1028     }
1029 
1030     for (int i = 0 ; i < urls.size() ; ++i)
1031     {
1032         QMap<QString, QString> imageMetaData;
1033         imageMetaData                               = d->imagesDescInfo[urls.at(i).toLocalFile()];
1034         imageMetaData[QLatin1String("latitude")]    = latitude();
1035         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
1036     }
1037 }
1038 
1039 void MediaWikiWidget::slotApplyLongitude()
1040 {
1041     QList<QUrl> urls;
1042     QList<QTreeWidgetItem*> selectedItems = d->imgList->listView()->selectedItems();
1043 
1044     for (int i = 0 ; i < selectedItems.size() ; ++i)
1045     {
1046         DItemsListViewItem* const l_item = dynamic_cast<DItemsListViewItem*>(selectedItems.at(i));
1047 
1048         if (l_item)
1049             urls.append(l_item->url());
1050     }
1051 
1052     for (int i = 0 ; i < urls.size() ; ++i)
1053     {
1054         QMap<QString, QString> imageMetaData;
1055         imageMetaData                               = d->imagesDescInfo[urls.at(i).toLocalFile()];
1056         imageMetaData[QLatin1String("longitude")]   = longitude();
1057         d->imagesDescInfo[urls.at(i).toLocalFile()] = imageMetaData;
1058     }
1059 }
1060 
1061 QMap <QString,QMap <QString,QString> > MediaWikiWidget::allImagesDesc()
1062 {
1063     QList<QUrl> urls = d->imgList->imageUrls(false);
1064 
1065     for (int i = 0 ; i < urls.size() ; ++i)
1066     {
1067         QMap<QString, QString> imageMetaData          = d->imagesDescInfo[urls.at(i).toLocalFile()];
1068         imageMetaData[QLatin1String("author")]        = author();
1069         imageMetaData[QLatin1String("source")]        = source();
1070         imageMetaData[QLatin1String("license")]       = license();
1071         imageMetaData[QLatin1String("genCategories")] = genCategories();
1072         imageMetaData[QLatin1String("genText")]       = genText();
1073         imageMetaData[QLatin1String("comments")]      = genComments();
1074         d->imagesDescInfo[urls.at(i).toLocalFile()]   = imageMetaData;
1075     }
1076 
1077     return d->imagesDescInfo;
1078 }
1079 
1080 QString MediaWikiWidget::author() const
1081 {
1082     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::author()";
1083     return d->authorEdit->text();
1084 }
1085 
1086 QString MediaWikiWidget::source() const
1087 {
1088     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::source()";
1089     return d->sourceEdit->text();
1090 }
1091 
1092 QString MediaWikiWidget::genCategories() const
1093 {
1094     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::genCategories()";
1095     return d->genCatEdit->toPlainText();
1096 }
1097 
1098 QString MediaWikiWidget::genText() const
1099 {
1100     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::genText()";
1101     return d->genTxtEdit->toPlainText();
1102 }
1103 
1104 QString MediaWikiWidget::genComments() const
1105 {
1106     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::genComments()";
1107     return d->genComEdit->toPlainText();
1108 }
1109 
1110 int MediaWikiWidget::quality() const
1111 {
1112     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::quality()";
1113     return d->imageQualitySpB->value();
1114 }
1115 
1116 int MediaWikiWidget::dimension() const
1117 {
1118     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::dimension()";
1119     return d->dimensionSpB->value();
1120 }
1121 
1122 bool MediaWikiWidget::resize() const
1123 {
1124     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::resize()";
1125     return d->resizeChB->isChecked();
1126 }
1127 
1128 bool MediaWikiWidget::removeMeta() const
1129 {
1130     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::removeMeta()";
1131     return d->removeMetaChB->isChecked();
1132 }
1133 
1134 bool MediaWikiWidget::removeGeo() const
1135 {
1136     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::removeGeo()";
1137     return d->removeGeoChB->isChecked();
1138 }
1139 
1140 QString MediaWikiWidget::license() const
1141 {
1142     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::license()";
1143     return d->licenseComboBox->itemData(d->licenseComboBox->currentIndex()).toString();
1144 }
1145 
1146 QString MediaWikiWidget::title() const
1147 {
1148     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::title()";
1149     return d->titleEdit->text();
1150 }
1151 
1152 QString MediaWikiWidget::categories() const
1153 {
1154     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::categories()";
1155     return d->categoryEdit->toPlainText();
1156 }
1157 
1158 QString MediaWikiWidget::description() const
1159 {
1160     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::description()";
1161     return d->descEdit->toPlainText();
1162 }
1163 
1164 QString MediaWikiWidget::date() const
1165 {
1166     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::date()";
1167     return d->dateEdit->text();
1168 }
1169 
1170 QString MediaWikiWidget::latitude() const
1171 {
1172     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::latitude()";
1173     return d->latitudeEdit->text();
1174 }
1175 
1176 QString MediaWikiWidget::longitude() const
1177 {
1178     qCDebug(DIGIKAM_WEBSERVICES_LOG) << "MediaWikiWidget::longitude()";
1179     return d->longitudeEdit->text();
1180 }
1181 
1182 } // namespace DigikamGenericMediaWikiPlugin
1183 
1184 #include "moc_mediawikiwidget.cpp"