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);
64 Q_EMIT that->q_func()->showPrompt(message, Greeter::PromptTypeSecret);
67 void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
71 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
72 QString message = QString::fromUtf8(text);
76 Q_EMIT that->q_func()->showMessage(message, Greeter::MessageTypeInfo);
79 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
82 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
83 Q_EMIT that->q_func()->authenticationComplete();
86 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
89 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
90 Q_EMIT that->q_func()->autologinTimerExpired();
93 Greeter::Greeter(QObject *parent) :
95 d_ptr(new GreeterPrivate(this))
105 bool Greeter::connectSync()
108 return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
111 void Greeter::authenticate(const QString &username)
114 lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
117 void Greeter::authenticateAsGuest()
120 lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
123 void Greeter::authenticateAutologin()
126 lightdm_greeter_authenticate_autologin(d->ldmGreeter);
129 void Greeter::authenticateRemote(const QString &session, const QString &username)
132 lightdm_greeter_authenticate_remote(d->ldmGreeter, session.toLocal8Bit().data(), username.toLocal8Bit().data());
135 void Greeter::respond(const QString &response)
138 lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
141 void Greeter::cancelAuthentication()
144 lightdm_greeter_cancel_authentication(d->ldmGreeter);
147 bool Greeter::inAuthentication() const
150 return lightdm_greeter_get_in_authentication(d->ldmGreeter);
153 bool Greeter::isAuthenticated() const
156 return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
159 QString Greeter::authenticationUser() const
162 return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
165 void Greeter::setLanguage (const QString &language)
168 lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
171 bool Greeter::startSessionSync(const QString &session)
174 return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
178 QString Greeter::getHint(const QString &name) const
181 return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
184 QString Greeter::defaultSessionHint() const
187 return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
190 bool Greeter::hideUsersHint() const
193 return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
196 bool Greeter::showManualLoginHint() const
199 return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
202 bool Greeter::showRemoteLoginHint() const
205 return lightdm_greeter_get_show_remote_login_hint(d->ldmGreeter);
208 bool Greeter::lockHint() const
211 return lightdm_greeter_get_lock_hint(d->ldmGreeter);
214 bool Greeter::hasGuestAccountHint() const
217 return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
220 QString Greeter::selectUserHint() const
223 return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
226 bool Greeter::selectGuestHint() const
229 return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
232 QString Greeter::autologinUserHint() const
235 return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
238 bool Greeter::autologinGuestHint() const
241 return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
244 int Greeter::autologinTimeoutHint() const
247 return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
250 QString Greeter::hostname() const
252 return QString::fromUtf8(lightdm_get_hostname());
255 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
256 #include "greeter_moc5.cpp"
258 #include "greeter_moc4.cpp"