1 /*
2 * Copyright (C) 2014 by Daniel Molkentin <danimo@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "authenticationdialog.h"
16
17 #include <QLabel>
18 #include <QLineEdit>
19 #include <QVBoxLayout>
20 #include <QFormLayout>
21 #include <QDialogButtonBox>
22
23 namespace OCC {
24
AuthenticationDialog(const QString & realm,const QString & domain,QWidget * parent)25 AuthenticationDialog::AuthenticationDialog(const QString &realm, const QString &domain, QWidget *parent)
26 : QDialog(parent)
27 , _user(new QLineEdit)
28 , _password(new QLineEdit)
29 {
30 setWindowTitle(tr("Authentication Required"));
31 auto *lay = new QVBoxLayout(this);
32 auto *label = new QLabel(tr("Enter username and password for \"%1\" at %2.").arg(realm, domain));
33 label->setTextFormat(Qt::PlainText);
34 lay->addWidget(label);
35
36 auto *form = new QFormLayout;
37 form->addRow(tr("&User:"), _user);
38 form->addRow(tr("&Password:"), _password);
39 lay->addLayout(form);
40 _password->setEchoMode(QLineEdit::Password);
41
42 auto *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
43 connect(box, &QDialogButtonBox::accepted, this, &QDialog::accept);
44 connect(box, &QDialogButtonBox::rejected, this, &QDialog::reject);
45 lay->addWidget(box);
46 }
47
user() const48 QString AuthenticationDialog::user() const
49 {
50 return _user->text();
51 }
52
password() const53 QString AuthenticationDialog::password() const
54 {
55 return _password->text();
56 }
57
58 } // namespace OCC
59