1 #include "lightdm-example-qt-greeter.h"
3 #include <QtGui/QApplication>
4 #include <QtGui/QLabel>
5 #include <QtGui/QLineEdit>
6 #include <QtGui/QPushButton>
7 #include <QtGui/QGridLayout>
9 #include "ldmgreeter.h"
11 LoginDialog::LoginDialog() : QDialog()
13 label = new QLabel("Username:", this);
14 entry = new QLineEdit(this);
15 connect(entry, SIGNAL(returnPressed()), this, SLOT(onLogin()));
17 QPushButton *button = new QPushButton("Login", this);
18 connect(button, SIGNAL(clicked()), this, SLOT(onLogin()));
20 QGridLayout *layout = new QGridLayout(this);
21 layout->addWidget(label, 0, 0, 1, 1);
22 layout->addWidget(entry, 1, 0, 2, 1);
23 layout->addWidget(button, 2, 0, 3, 1);
26 greeter = new LdmGreeter; //FIXME this LEAKS! Either finish the QWidget subclass plan, or add parent arg to LdmGreeter.
27 connect(greeter, SIGNAL(showPrompt(QString)), this, SLOT(showPrompt(QString)));
28 connect(greeter, SIGNAL(showMessage(QString)), this, SLOT(showMessage(QString)));
29 connect(greeter, SIGNAL(showError(QString)), this, SLOT(showError(QString)));
30 connect(greeter, SIGNAL(authenticationComplete()), this, SLOT(authenticationComplete()));
31 connect(greeter, SIGNAL(quit()), this, SLOT(quit()));
32 greeter->connectToServer();
35 void LoginDialog::onLogin()
37 if(greeter->inAuthentication()) {
39 greeter->provideSecret(entry->text());
43 entry->setEchoMode(QLineEdit::Normal);
46 greeter->startAuthentication(entry->text());
50 void LoginDialog::showPrompt(QString text)
53 entry->setEchoMode(QLineEdit::Password);
58 void LoginDialog::showMessage(QString text)
63 void LoginDialog::showError(QString text)
68 void LoginDialog::authenticationComplete()
71 if(greeter->isAuthenticated()) {
72 greeter->login(greeter->authenticationUser(), greeter->defaultSession(), greeter->defaultLanguage());
75 label->setText("Failed to authenticate");
79 void LoginDialog::quit()
84 int main(int argc, char *argv[])
86 QApplication a(argc, argv);