File indexing completed on 2024-05-05 16:08:29

0001 /* This file is part of the KDE libraries
0002    Copyright (C) 2000 David Faure <faure@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License version 2 as published by the Free Software Foundation.
0007 
0008    This library is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    Library General Public License for more details.
0012 
0013    You should have received a copy of the GNU Library General Public License
0014    along with this library; see the file COPYING.LIB.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017 */
0018 #include "passworddialog.h"
0019 
0020 #include <QCheckBox>
0021 #include <QLabel>
0022 #include <QLayout>
0023 #include <QTextDocument>
0024 #include <QTextLayout>
0025 
0026 #include <kconfig.h>
0027 #include <klocalizedstring.h>
0028 
0029 using namespace KIO;
0030 
0031 PasswordDialog::PasswordDialog(const QString &prompt, const QString &user,
0032                                bool enableKeep, bool modal, QWidget *parent)
0033     : KPasswordDialog(parent, enableKeep ? (ShowUsernameLine | ShowKeepPassword) : ShowUsernameLine)
0034 {
0035     setModal(modal);
0036     setPrompt(prompt);
0037     setUsername(user);
0038 }
0039 
0040 PasswordDialog::~PasswordDialog()
0041 {
0042 }
0043 
0044 int PasswordDialog::getNameAndPassword(QString &user, QString &pass, bool *keep,
0045                                        const QString &prompt, bool readOnly,
0046                                        const QString &caption,
0047                                        const QString &comment,
0048                                        const QString &label)
0049 {
0050     PasswordDialog *dlg;
0051     dlg = new PasswordDialog(prompt, user, keep);
0052 
0053     if (!caption.isEmpty()) {
0054         dlg->setWindowTitle(caption);
0055     } else {
0056         dlg->setWindowTitle(i18n("Authorization Dialog"));
0057     }
0058 
0059     if (!comment.isEmpty()) {
0060         dlg->addCommentLine(label, comment);
0061     }
0062 
0063     if (readOnly) {
0064         dlg->setUsernameReadOnly(readOnly);
0065     }
0066 
0067     if (keep) {
0068         dlg->setKeepPassword(*keep);
0069     }
0070 
0071     int ret = dlg->exec();
0072     if (ret == Accepted) {
0073         user = dlg->username();
0074         pass = dlg->password();
0075         if (keep) {
0076             (*keep) = dlg->keepPassword();
0077         }
0078     }
0079     delete dlg;
0080     return ret;
0081 }
0082 
0083 #include "moc_passworddialog.cpp"