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 2 or version 3 of the License.
9 * See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
13 #include "QLightDM/greeter.h"
15 #include <QtCore/QDebug>
16 #include <QtCore/QDir>
17 #include <QtCore/QVariant>
18 #include <QtCore/QSettings>
22 using namespace QLightDM;
24 class QLightDM::GreeterPrivate
27 GreeterPrivate(Greeter *parent);
28 LightDMGreeter *ldmGreeter;
32 static void cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data);
33 static void cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data);
34 static void cb_authenticationComplete(LightDMGreeter *greeter, gpointer data);
35 static void cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data);
38 Q_DECLARE_PUBLIC(Greeter)
41 GreeterPrivate::GreeterPrivate(Greeter *parent) :
44 #if !defined(GLIB_VERSION_2_36)
47 ldmGreeter = lightdm_greeter_new();
49 g_signal_connect (ldmGreeter, "show-prompt", G_CALLBACK (cb_showPrompt), this);
50 g_signal_connect (ldmGreeter, "show-message", G_CALLBACK (cb_showMessage), this);
51 g_signal_connect (ldmGreeter, "authentication-complete", G_CALLBACK (cb_authenticationComplete), this);
52 g_signal_connect (ldmGreeter, "autologin-timer-expired", G_CALLBACK (cb_autoLoginExpired), this);
55 void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
59 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
60 QString message = QString::fromUtf8(text);
62 Q_EMIT that->q_func()->showPrompt(message, type == LIGHTDM_PROMPT_TYPE_QUESTION ?
63 Greeter::PromptTypeQuestion : 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);
73 Q_EMIT that->q_func()->showMessage(message, type == LIGHTDM_MESSAGE_TYPE_INFO ?
74 Greeter::MessageTypeInfo : Greeter::MessageTypeError);
77 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
80 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
81 Q_EMIT that->q_func()->authenticationComplete();
84 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
87 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
88 Q_EMIT that->q_func()->autologinTimerExpired();
91 Greeter::Greeter(QObject *parent) :
93 d_ptr(new GreeterPrivate(this))
103 bool Greeter::connectSync()
106 return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
109 void Greeter::authenticate(const QString &username)
112 lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
115 void Greeter::authenticateAsGuest()
118 lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
121 void Greeter::authenticateAutologin()
124 lightdm_greeter_authenticate_autologin(d->ldmGreeter);
127 void Greeter::authenticateRemote(const QString &session, const QString &username)
130 lightdm_greeter_authenticate_remote(d->ldmGreeter, session.toLocal8Bit().data(), username.toLocal8Bit().data());
133 void Greeter::respond(const QString &response)
136 lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
139 void Greeter::cancelAuthentication()
142 lightdm_greeter_cancel_authentication(d->ldmGreeter);
145 bool Greeter::inAuthentication() const
148 return lightdm_greeter_get_in_authentication(d->ldmGreeter);
151 bool Greeter::isAuthenticated() const
154 return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
157 QString Greeter::authenticationUser() const
160 return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
163 void Greeter::setLanguage (const QString &language)
166 lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
169 bool Greeter::startSessionSync(const QString &session)
172 return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
176 QString Greeter::getHint(const QString &name) const
179 return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
182 QString Greeter::defaultSessionHint() const
185 return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
188 bool Greeter::hideUsersHint() const
191 return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
194 bool Greeter::showManualLoginHint() const
197 return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
200 bool Greeter::showRemoteLoginHint() const
203 return lightdm_greeter_get_show_remote_login_hint(d->ldmGreeter);
206 bool Greeter::lockHint() const
209 return lightdm_greeter_get_lock_hint(d->ldmGreeter);
212 bool Greeter::hasGuestAccountHint() const
215 return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
218 QString Greeter::selectUserHint() const
221 return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
224 bool Greeter::selectGuestHint() const
227 return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
230 QString Greeter::autologinUserHint() const
233 return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
236 bool Greeter::autologinGuestHint() const
239 return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
242 int Greeter::autologinTimeoutHint() const
245 return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
248 QString Greeter::hostname() const
250 return QString::fromUtf8(lightdm_get_hostname());
253 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
254 #include "greeter_moc5.cpp"
256 #include "greeter_moc4.cpp"