summaryrefslogtreecommitdiff
path: root/liblightdm-qt/greeter.cpp
blob: cf47ec59e558af27e642306c141624905119c447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * Copyright (C) 2010-2011 David Edmundson
 * Copyright (C) 2010-2011 Robert Ancell
 * Author: David Edmundson <kde@davidedmundson.co.uk>
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
 * license.
 */


#include "QLightDM/greeter.h"

#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QVariant>
#include <QtCore/QSettings>

#include <lightdm-gobject-1/lightdm.h>

using namespace QLightDM;

class QLightDM::GreeterPrivate
{
public:
    GreeterPrivate(Greeter *parent);
    LightDMGreeter *ldmGreeter;
protected:
    Greeter* q_ptr;
    
    static void cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data);
    static void cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data);
    static void cb_authenticationComplete(LightDMGreeter *greeter, gpointer data);
    static void cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data);
    
private:
    Q_DECLARE_PUBLIC(Greeter)
};

GreeterPrivate::GreeterPrivate(Greeter *parent) :
    q_ptr(parent)
{
    g_type_init();
    ldmGreeter = lightdm_greeter_new();
    
    g_signal_connect (ldmGreeter, "show-prompt", G_CALLBACK (cb_showPrompt), this);
    g_signal_connect (ldmGreeter, "show-message", G_CALLBACK (cb_showMessage), this);
    g_signal_connect (ldmGreeter, "authentication-complete", G_CALLBACK (cb_authenticationComplete), this);
    g_signal_connect (ldmGreeter, "autologin-timer-expired", G_CALLBACK (cb_autoLoginExpired), this);
}

void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
{
    Q_UNUSED(greeter);
    
    GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
    QString message = QString::fromLocal8Bit(text);
    
    //FIXME prompt type

    Q_EMIT that->q_func()->showPrompt(message, Greeter::PromptTypeSecret);
}

void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
{
    Q_UNUSED(greeter);

    GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
    QString message = QString::fromLocal8Bit(text);

    //FIXME prompt type

    Q_EMIT that->q_func()->showMessage(message, Greeter::MessageTypeInfo);
}

void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
{
    Q_UNUSED(greeter);
    GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
    Q_EMIT that->q_func()->authenticationComplete();
}

void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
{
    Q_UNUSED(greeter);
    GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
    Q_EMIT that->q_func()->autologinTimerExpired();
}

Greeter::Greeter(QObject *parent) :
    QObject(parent),
    d_ptr(new GreeterPrivate(this))
{
}

Greeter::~Greeter()
{
    delete d_ptr;
}


bool Greeter::connectSync()
{
    Q_D(Greeter);
    return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
}

void Greeter::authenticate(const QString &username)
{
    Q_D(Greeter);
    lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
}

void Greeter::authenticateAsGuest()
{
    Q_D(Greeter);
    lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
    
}

void Greeter::respond(const QString &response)
{
    Q_D(Greeter);
    lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
}

void Greeter::cancelAuthentication()
{
    Q_D(Greeter);
    lightdm_greeter_cancel_authentication(d->ldmGreeter);
}

bool Greeter::inAuthentication() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_in_authentication(d->ldmGreeter);
}

bool Greeter::isAuthenticated() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
}

QString Greeter::authenticationUser() const
{
    Q_D(const Greeter);
    return QString::fromLocal8Bit(lightdm_greeter_get_authentication_user(d->ldmGreeter));
}

void Greeter::setLanguage (const QString &language)
{
    Q_D(Greeter);
    lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
}

bool Greeter::startSessionSync(const QString &session)
{
    Q_D(Greeter);
    return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
}


QString Greeter::getHint(const QString &name) const
{
    Q_D(Greeter());
    return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
}

QString Greeter::defaultSessionHint() const
{
    Q_D(const Greeter);
    return QString::fromLocal8Bit(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
}

bool Greeter::hideUsersHint() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
}

bool Greeter::hasGuestAccountHint() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
}

QString Greeter::selectUserHint() const
{
    Q_D(const Greeter);
    return QString::fromLocal8Bit(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
}

bool Greeter::selectGuestHint() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
}

QString Greeter::autologinUserHint() const
{
    Q_D(const Greeter);
    return QString::fromLocal8Bit(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
}

bool Greeter::autologinGuestHint() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
}

int Greeter::autologinTimeoutHint() const
{
    Q_D(const Greeter);
    return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
}

#include "greeter_moc.cpp"