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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2014-09-30
0007  * Description : a tool to export items to Piwigo web service
0008  *
0009  * SPDX-FileCopyrightText: 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006      by Colin Guthrie <kde at colin dot guthr dot ie>
0011  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  * SPDX-FileCopyrightText: 2008      by Andrea Diamantini <adjam7 at gmail dot com>
0013  * SPDX-FileCopyrightText: 2010-2014 by Frederic Coiffier <frederic dot coiffier at free dot com>
0014  *
0015  * SPDX-License-Identifier: GPL-2.0-or-later
0016  *
0017  * ============================================================ */
0018 
0019 #include "piwigologindlg.h"
0020 
0021 // Qt includes
0022 
0023 #include <QLabel>
0024 #include <QFrame>
0025 #include <QGridLayout>
0026 #include <QPushButton>
0027 #include <QLineEdit>
0028 #include <QDialogButtonBox>
0029 
0030 // KDE includes
0031 
0032 #include <klocalizedstring.h>
0033 
0034 // Local includes
0035 
0036 #include "digikam_version.h"
0037 #include "digikam_debug.h"
0038 
0039 namespace DigikamGenericPiwigoPlugin
0040 {
0041 
0042 class Q_DECL_HIDDEN PiwigoLoginDlg::Private
0043 {
0044 public:
0045 
0046     explicit Private()
0047       : pUrlEdit     (nullptr),
0048         pUsernameEdit(nullptr),
0049         pPasswordEdit(nullptr),
0050         pPiwigo      (nullptr)
0051     {
0052     }
0053 
0054     QLineEdit*     pUrlEdit;
0055     QLineEdit*     pUsernameEdit;
0056     QLineEdit*     pPasswordEdit;
0057 
0058     PiwigoSession* pPiwigo;
0059 };
0060 
0061 PiwigoLoginDlg::PiwigoLoginDlg(QWidget* const pParent,
0062                                PiwigoSession* const pPiwigo,
0063                                const QString& title)
0064     : QDialog(pParent, Qt::Dialog),
0065       d      (new Private)
0066 {
0067     d->pPiwigo = pPiwigo;
0068 
0069     setWindowTitle(title);
0070 
0071     QFrame* const  page             = new QFrame(this);
0072     QGridLayout* const centerLayout = new QGridLayout();
0073     page->setMinimumSize(500, 128);
0074 
0075     d->pUrlEdit      = new QLineEdit(this);
0076     centerLayout->addWidget(d->pUrlEdit, 1, 1);
0077 
0078     d->pUsernameEdit = new QLineEdit(this);
0079     centerLayout->addWidget(d->pUsernameEdit, 2, 1);
0080 
0081     d->pPasswordEdit = new QLineEdit(this);
0082     d->pPasswordEdit->setEchoMode(QLineEdit::Password);
0083     centerLayout->addWidget(d->pPasswordEdit, 3, 1);
0084 
0085     QLabel* const urlLabel = new QLabel(this);
0086     urlLabel->setText(i18nc("piwigo login settings", "URL:"));
0087     centerLayout->addWidget(urlLabel, 1, 0);
0088 
0089     QLabel* const usernameLabel = new QLabel(this);
0090     usernameLabel->setText(i18nc("piwigo login settings", "Username:"));
0091     centerLayout->addWidget(usernameLabel, 2, 0);
0092 
0093     QLabel* const passwdLabel = new QLabel(this);
0094     passwdLabel->setText(i18nc("piwigo login settings", "Password:"));
0095     centerLayout->addWidget(passwdLabel, 3, 0);
0096 
0097     //---------------------------------------------
0098 
0099     page->setLayout(centerLayout);
0100 
0101     resize(QSize(300, 150).expandedTo(minimumSizeHint()));
0102 
0103     // setting initial data
0104 
0105     d->pUrlEdit->setText(pPiwigo->url());
0106     d->pUsernameEdit->setText(pPiwigo->username());
0107     d->pPasswordEdit->setText(pPiwigo->password());
0108 
0109     //---------------------------------------------
0110 
0111     QDialogButtonBox* const buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
0112                                                              QDialogButtonBox::Cancel);
0113     buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
0114 
0115     QVBoxLayout* const dialogLayout   = new QVBoxLayout(this);
0116     dialogLayout->addWidget(page);
0117     dialogLayout->addWidget(buttonBox);
0118 
0119     connect(buttonBox, SIGNAL(accepted()),
0120             this, SLOT(slotOk()));
0121 
0122     connect(buttonBox, SIGNAL(rejected()),
0123             this, SLOT(reject()));
0124 }
0125 
0126 PiwigoLoginDlg::~PiwigoLoginDlg()
0127 {
0128     delete d;
0129 }
0130 
0131 void PiwigoLoginDlg::slotOk()
0132 {
0133     if (d->pUrlEdit->isModified())
0134     {
0135         d->pPiwigo->setUrl(d->pUrlEdit->text());
0136     }
0137 
0138     if (d->pUsernameEdit->isModified())
0139     {
0140         d->pPiwigo->setUsername(d->pUsernameEdit->text());
0141     }
0142 
0143     if (d->pPasswordEdit->isModified())
0144     {
0145         d->pPiwigo->setPassword(d->pPasswordEdit->text());
0146     }
0147 
0148     d->pPiwigo->save();
0149     accept();
0150 }
0151 
0152 } // namespace DigikamGenericPiwigoPlugin
0153 
0154 #include "moc_piwigologindlg.cpp"