~lightdm-team/lightdm/1.4

« back to all changes in this revision

Viewing changes to greeters/qt/lightdm-example-qt-greeter.cpp

  • Committer: David Edmundson
  • Date: 2011-05-21 00:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 456.
  • Revision ID: david@davidedmundson.co.uk-20110521005356-stabgjwhvgxzb4lp
Replaced Qt Demo greeter with something more extensive

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "lightdm-example-qt-greeter.h"
2
 
 
3
 
#include <QtGui/QApplication>
4
 
#include <QtGui/QLabel>
5
 
#include <QtGui/QLineEdit>
6
 
#include <QtGui/QPushButton>
7
 
#include <QtGui/QGridLayout>
8
 
#include <QtCore/QDebug>
9
 
 
10
 
#include "ldmgreeter.h"
11
 
 
12
 
LoginDialog::LoginDialog() : 
13
 
  QDialog()
14
 
{
15
 
    label = new QLabel("Username:", this);
16
 
    entry = new QLineEdit(this);
17
 
    connect(entry, SIGNAL(returnPressed()), this, SLOT(onLogin()));  
18
 
 
19
 
    QPushButton *button = new QPushButton("Login", this);
20
 
    connect(button, SIGNAL(clicked()), this, SLOT(onLogin()));
21
 
 
22
 
    QGridLayout *layout = new QGridLayout(this);
23
 
    layout->addWidget(label, 0, 0, 1, 1);
24
 
    layout->addWidget(entry, 1, 0, 2, 1);
25
 
    layout->addWidget(button, 2, 0, 3, 1);
26
 
    setLayout(layout);
27
 
 
28
 
    greeter = new LdmGreeter(this);
29
 
    connect(greeter, SIGNAL(showPrompt(QString)), this, SLOT(showPrompt(QString)));
30
 
    connect(greeter, SIGNAL(showMessage(QString)), this, SLOT(showMessage(QString)));
31
 
    connect(greeter, SIGNAL(showError(QString)), this, SLOT(showError(QString)));
32
 
    connect(greeter, SIGNAL(authenticationComplete()), this, SLOT(authenticationComplete()));
33
 
    connect(greeter, SIGNAL(quit()), this, SLOT(quit()));
34
 
    greeter->connectToServer();
35
 
}
36
 
 
37
 
void LoginDialog::onLogin()
38
 
{
39
 
    if(greeter->inAuthentication()) {
40
 
        if(inPrompt) {
41
 
            greeter->provideSecret(entry->text());
42
 
        }
43
 
        inPrompt = false;
44
 
        entry->setText("");
45
 
        entry->setEchoMode(QLineEdit::Normal);
46
 
    }
47
 
    else {
48
 
        greeter->startAuthentication(entry->text());
49
 
    }
50
 
}
51
 
 
52
 
void LoginDialog::showPrompt(QString text)
53
 
{
54
 
    entry->setText("");
55
 
    entry->setEchoMode(QLineEdit::Password);
56
 
    label->setText(text);
57
 
    inPrompt = true;
58
 
}
59
 
 
60
 
void LoginDialog::showMessage(QString text)
61
 
{    
62
 
    label->setText(text);
63
 
}
64
 
 
65
 
void LoginDialog::showError(QString text)
66
 
{
67
 
     label->setText(text);
68
 
}
69
 
 
70
 
void LoginDialog::authenticationComplete()
71
 
{
72
 
    entry->setText("");
73
 
    if(greeter->isAuthenticated()) {
74
 
        greeter->login(greeter->authenticationUser(), greeter->defaultSession(), greeter->defaultLanguage());
75
 
    }
76
 
    else {
77
 
        label->setText("Failed to authenticate");
78
 
    }
79
 
}
80
 
 
81
 
void LoginDialog::quit()
82
 
{
83
 
    exit(0);
84
 
}
85
 
 
86
 
int main(int argc, char *argv[])
87
 
{
88
 
    QApplication a(argc, argv);
89
 
 
90
 
    LoginDialog d;
91
 
    d.show();
92
 
 
93
 
    return a.exec();
94
 
}