File indexing completed on 2025-01-19 03:55:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-11-12 0007 * Description : a common login dialog for Web Service tools 0008 * 0009 * SPDX-FileCopyrightText: 2007-2008 by Vardhman Jain <vardhman at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Roman Tsisyk <roman at tsisyk dot com> 0011 * SPDX-FileCopyrightText: 2015 by Shourya Singh Gupta <shouryasgupta at gmail dot com> 0012 * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #include "wslogindialog.h" 0019 0020 // Qt includes 0021 0022 #include <QGridLayout> 0023 #include <QHBoxLayout> 0024 #include <QVBoxLayout> 0025 #include <QFrame> 0026 #include <QLabel> 0027 #include <QPushButton> 0028 #include <QLineEdit> 0029 #include <QMessageBox> 0030 0031 // KDE includes 0032 0033 #include <klocalizedstring.h> 0034 0035 // Local includes 0036 0037 #include "digikam_debug.h" 0038 0039 namespace Digikam 0040 { 0041 0042 class Q_DECL_HIDDEN WSLoginDialog::Private 0043 { 0044 public: 0045 0046 explicit Private() 0047 : headerLabel (nullptr), 0048 loginEdit (nullptr), 0049 passwordEdit (nullptr) 0050 { 0051 } 0052 0053 QLabel* headerLabel; 0054 QLineEdit* loginEdit; 0055 QLineEdit* passwordEdit; 0056 }; 0057 0058 WSLoginDialog::WSLoginDialog(QWidget* const parent, 0059 const QString& prompt, 0060 const QString& login, 0061 const QString& password) 0062 : QDialog(parent), 0063 d (new Private) 0064 { 0065 setSizeGripEnabled(false); 0066 0067 QVBoxLayout* const vbox = new QVBoxLayout(this); 0068 d->headerLabel = new QLabel(this); 0069 d->headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); 0070 d->headerLabel->setTextFormat(Qt::RichText); 0071 d->headerLabel->setText(prompt); 0072 0073 QFrame* const hline = new QFrame(this); 0074 hline->setObjectName(QLatin1String("hline")); 0075 hline->setFrameShape( QFrame::HLine ); 0076 hline->setFrameShadow( QFrame::Sunken ); 0077 hline->setFrameShape( QFrame::HLine ); 0078 0079 QGridLayout* const centerLayout = new QGridLayout(); 0080 0081 d->loginEdit = new QLineEdit(this); 0082 d->passwordEdit = new QLineEdit(this); 0083 d->passwordEdit->setEchoMode(QLineEdit::Password); 0084 0085 QLabel* const loginLabel = new QLabel(this); 0086 loginLabel->setText(i18n( "Login:" )); 0087 0088 QLabel* const passwordLabel = new QLabel(this); 0089 passwordLabel->setText(i18n("Password:")); 0090 0091 centerLayout->addWidget(d->loginEdit, 0, 1); 0092 centerLayout->addWidget(d->passwordEdit, 1, 1); 0093 centerLayout->addWidget(loginLabel, 0, 0); 0094 centerLayout->addWidget(passwordLabel, 1, 0); 0095 0096 QHBoxLayout* const btnLayout = new QHBoxLayout(); 0097 QPushButton* const okBtn = new QPushButton(this); 0098 okBtn->setAutoDefault(true); 0099 okBtn->setDefault(true); 0100 okBtn->setText(i18n("&Login")); 0101 0102 QPushButton* const cancelBtn = new QPushButton(this); 0103 cancelBtn->setText(i18n("&Skip")); 0104 0105 btnLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); 0106 btnLayout->addWidget(okBtn); 0107 btnLayout->addWidget(cancelBtn); 0108 btnLayout->setContentsMargins(QMargins()); 0109 btnLayout->setSpacing(5); 0110 0111 vbox->setContentsMargins(5, 5, 5, 5); 0112 vbox->setSpacing(5); 0113 vbox->setObjectName(QLatin1String("vbox")); 0114 vbox->addWidget(d->headerLabel); 0115 vbox->addWidget(hline); 0116 vbox->addLayout(centerLayout); 0117 vbox->addLayout(btnLayout); 0118 0119 resize(QSize(300, 150).expandedTo(minimumSizeHint())); 0120 0121 setLogin(login); 0122 setPassword(password); 0123 0124 connect(okBtn, SIGNAL(clicked()), 0125 this, SLOT(slotAccept())); 0126 0127 connect(cancelBtn, SIGNAL(clicked()), 0128 this, SLOT(reject())); 0129 } 0130 0131 WSLoginDialog::~WSLoginDialog() 0132 { 0133 delete d; 0134 } 0135 0136 QString WSLoginDialog::login() const 0137 { 0138 return d->loginEdit->text(); 0139 } 0140 0141 QString WSLoginDialog::password() const 0142 { 0143 return d->passwordEdit->text(); 0144 } 0145 0146 void WSLoginDialog::setLogin(const QString& login) 0147 { 0148 d->loginEdit->setText(login); 0149 } 0150 0151 void WSLoginDialog::setPassword(const QString& password) 0152 { 0153 d->passwordEdit->setText(password); 0154 } 0155 0156 void WSLoginDialog::slotAccept() 0157 { 0158 if (!d->passwordEdit->text().isEmpty()) 0159 { 0160 accept(); 0161 } 0162 else 0163 { 0164 QMessageBox::critical(this, i18nc("@title:window", "Error"), 0165 i18n("Password cannot be empty.")); 0166 } 0167 } 0168 0169 } // namespace Digikam 0170 0171 #include "moc_wslogindialog.cpp"