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>
21 #include <lightdm-gobject-1/lightdm.h>
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::fromLocal8Bit(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::fromLocal8Bit(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);
123 void Greeter::respond(const QString &response)
126 lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
129 void Greeter::cancelAuthentication()
132 lightdm_greeter_cancel_authentication(d->ldmGreeter);
135 bool Greeter::inAuthentication() const
138 return lightdm_greeter_get_in_authentication(d->ldmGreeter);
141 bool Greeter::isAuthenticated() const
144 return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
147 QString Greeter::authenticationUser() const
150 return QString::fromLocal8Bit(lightdm_greeter_get_authentication_user(d->ldmGreeter));
153 void Greeter::setLanguage (const QString &language)
156 lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
159 bool Greeter::startSessionSync(const QString &session)
162 return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
166 QString Greeter::getHint(const QString &name) const
169 return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
172 QString Greeter::defaultSessionHint() const
175 return QString::fromLocal8Bit(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
178 bool Greeter::hideUsersHint() const
181 return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
184 bool Greeter::hasGuestAccountHint() const
187 return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
190 QString Greeter::selectUserHint() const
193 return QString::fromLocal8Bit(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
196 bool Greeter::selectGuestHint() const
199 return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
202 QString Greeter::autologinUserHint() const
205 return QString::fromLocal8Bit(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
208 bool Greeter::autologinGuestHint() const
211 return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
214 int Greeter::autologinTimeoutHint() const
217 return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
220 #include "greeter_moc.cpp"