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);
36 static void cb_idle(LightDMGreeter *greeter, gpointer data);
37 static void cb_reset(LightDMGreeter *greeter, gpointer data);
40 Q_DECLARE_PUBLIC(Greeter)
43 GreeterPrivate::GreeterPrivate(Greeter *parent) :
46 #if !defined(GLIB_VERSION_2_36)
49 ldmGreeter = lightdm_greeter_new();
51 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_SHOW_PROMPT, G_CALLBACK (cb_showPrompt), this);
52 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_SHOW_MESSAGE, G_CALLBACK (cb_showMessage), this);
53 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_AUTHENTICATION_COMPLETE, G_CALLBACK (cb_authenticationComplete), this);
54 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_AUTOLOGIN_TIMER_EXPIRED, G_CALLBACK (cb_autoLoginExpired), this);
55 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_IDLE, G_CALLBACK (cb_idle), this);
56 g_signal_connect (ldmGreeter, LIGHTDM_GREETER_SIGNAL_RESET, G_CALLBACK (cb_reset), this);
59 void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
63 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
64 QString message = QString::fromUtf8(text);
66 Q_EMIT that->q_func()->showPrompt(message, type == LIGHTDM_PROMPT_TYPE_QUESTION ?
67 Greeter::PromptTypeQuestion : Greeter::PromptTypeSecret);
70 void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
74 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
75 QString message = QString::fromUtf8(text);
77 Q_EMIT that->q_func()->showMessage(message, type == LIGHTDM_MESSAGE_TYPE_INFO ?
78 Greeter::MessageTypeInfo : Greeter::MessageTypeError);
81 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
84 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
85 Q_EMIT that->q_func()->authenticationComplete();
88 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
91 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
92 Q_EMIT that->q_func()->autologinTimerExpired();
95 void GreeterPrivate::cb_idle(LightDMGreeter *greeter, gpointer data)
98 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
99 Q_EMIT that->q_func()->idle();
102 void GreeterPrivate::cb_reset(LightDMGreeter *greeter, gpointer data)
105 GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
106 Q_EMIT that->q_func()->reset();
109 Greeter::Greeter(QObject *parent) :
111 d_ptr(new GreeterPrivate(this))
121 bool Greeter::connectToDaemonSync()
124 return lightdm_greeter_connect_to_daemon_sync(d->ldmGreeter, NULL);
127 bool Greeter::connectSync()
130 return lightdm_greeter_connect_to_daemon_sync(d->ldmGreeter, NULL);
133 void Greeter::authenticate(const QString &username)
136 lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data(), NULL);
139 void Greeter::authenticateAsGuest()
142 lightdm_greeter_authenticate_as_guest(d->ldmGreeter, NULL);
145 void Greeter::authenticateAutologin()
148 lightdm_greeter_authenticate_autologin(d->ldmGreeter, NULL);
151 void Greeter::authenticateRemote(const QString &session, const QString &username)
154 lightdm_greeter_authenticate_remote(d->ldmGreeter, session.toLocal8Bit().data(), username.toLocal8Bit().data(), NULL);
157 void Greeter::respond(const QString &response)
160 lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data(), NULL);
163 void Greeter::cancelAuthentication()
166 lightdm_greeter_cancel_authentication(d->ldmGreeter, NULL);
169 void Greeter::cancelAutologin()
172 lightdm_greeter_cancel_autologin(d->ldmGreeter);
175 bool Greeter::inAuthentication() const
178 return lightdm_greeter_get_in_authentication(d->ldmGreeter);
181 bool Greeter::isAuthenticated() const
184 return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
187 QString Greeter::authenticationUser() const
190 return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
193 void Greeter::setLanguage (const QString &language)
196 lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData(), NULL);
199 void Greeter::setResettable (bool resettable)
202 lightdm_greeter_set_resettable(d->ldmGreeter, resettable);
205 bool Greeter::startSessionSync(const QString &session)
208 return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
211 QString Greeter::ensureSharedDataDirSync(const QString &username)
214 return QString::fromUtf8(lightdm_greeter_ensure_shared_data_dir_sync(d->ldmGreeter, username.toLocal8Bit().constData(), NULL));
218 QString Greeter::getHint(const QString &name) const
221 return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
224 QString Greeter::defaultSessionHint() const
227 return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
230 bool Greeter::hideUsersHint() const
233 return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
236 bool Greeter::showManualLoginHint() const
239 return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
242 bool Greeter::showRemoteLoginHint() const
245 return lightdm_greeter_get_show_remote_login_hint(d->ldmGreeter);
248 bool Greeter::lockHint() const
251 return lightdm_greeter_get_lock_hint(d->ldmGreeter);
254 bool Greeter::hasGuestAccountHint() const
257 return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
260 QString Greeter::selectUserHint() const
263 return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
266 bool Greeter::selectGuestHint() const
269 return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
272 QString Greeter::autologinUserHint() const
275 return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
278 bool Greeter::autologinGuestHint() const
281 return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
284 int Greeter::autologinTimeoutHint() const
287 return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
290 QString Greeter::hostname() const
292 return QString::fromUtf8(lightdm_get_hostname());
295 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
296 #include "greeter_moc5.cpp"
298 #include "greeter_moc4.cpp"