2 * Copyright (C) 2010-2011 David Edmundson
3 * Copyright (C) 2010-2011 Robert Ancell
4 * Author: David Edmundson <kde@davidedmundson.co.uk>
6 * This library is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the Free
8 * Software Foundation; either version 3 of the License, or (at your option) any
9 * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
14 #include "QLightDM/greeter.h"
16 #include <QtCore/QDebug>
17 #include <QtCore/QDir>
18 #include <QtCore/QVariant>
19 #include <QtCore/QSettings>
23 using namespace QLightDM;
25 class QLightDM::GreeterPrivate
28 GreeterPrivate(Greeter *parent);
29 LightDMGreeter *ldmGreeter;
33 static void cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data);
34 static void cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data);
35 static void cb_authenticationComplete(LightDMGreeter *greeter, gpointer data);
36 static void cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data);
39 Q_DECLARE_PUBLIC(Greeter)
42 GreeterPrivate::GreeterPrivate(Greeter *parent) :
46 ldmGreeter = lightdm_greeter_new();
48 g_signal_connect (ldmGreeter, "show-prompt", G_CALLBACK (cb_showPrompt), this);
49 g_signal_connect (ldmGreeter, "show-message", G_CALLBACK (cb_showMessage), this);
50 g_signal_connect (ldmGreeter, "authentication-complete", G_CALLBACK (cb_authenticationComplete), this);
51 g_signal_connect (ldmGreeter, "autologin-timer-expired", G_CALLBACK (cb_autoLoginExpired), this);
54 void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
58 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
59 QString message = QString::fromUtf8(text);
63 Q_EMIT that->q_func()->showPrompt(message, Greeter::PromptTypeSecret);
66 void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
70 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
71 QString message = QString::fromUtf8(text);
75 Q_EMIT that->q_func()->showMessage(message, Greeter::MessageTypeInfo);
78 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
81 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
82 Q_EMIT that->q_func()->authenticationComplete();
85 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
88 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
89 Q_EMIT that->q_func()->autologinTimerExpired();
92 Greeter::Greeter(QObject *parent) :
94 d_ptr(new GreeterPrivate(this))
104 bool Greeter::connectSync()
107 return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
110 void Greeter::authenticate(const QString &username)
113 lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
116 void Greeter::authenticateAsGuest()
119 lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
122 void Greeter::authenticateRemote(const QString &session, const QString &username)
125 lightdm_greeter_authenticate_remote(d->ldmGreeter, session.toLocal8Bit().data(), username.toLocal8Bit().data());
128 void Greeter::respond(const QString &response)
131 lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
134 void Greeter::cancelAuthentication()
137 lightdm_greeter_cancel_authentication(d->ldmGreeter);
140 bool Greeter::inAuthentication() const
143 return lightdm_greeter_get_in_authentication(d->ldmGreeter);
146 bool Greeter::isAuthenticated() const
149 return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
152 QString Greeter::authenticationUser() const
155 return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
158 void Greeter::setLanguage (const QString &language)
161 lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
164 bool Greeter::startSessionSync(const QString &session)
167 return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
171 QString Greeter::getHint(const QString &name) const
174 return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
177 QString Greeter::defaultSessionHint() const
180 return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
183 bool Greeter::hideUsersHint() const
186 return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
189 bool Greeter::showManualLoginHint() const
192 return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
195 bool Greeter::lockHint() const
198 return lightdm_greeter_get_lock_hint(d->ldmGreeter);
201 bool Greeter::hasGuestAccountHint() const
204 return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
207 QString Greeter::selectUserHint() const
210 return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
213 bool Greeter::selectGuestHint() const
216 return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
219 QString Greeter::autologinUserHint() const
222 return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
225 bool Greeter::autologinGuestHint() const
228 return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
231 int Greeter::autologinTimeoutHint() const
234 return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
237 QString Greeter::hostname() const
239 return QString::fromUtf8(lightdm_get_hostname());
242 #include "greeter_moc.cpp"