Back to index

lightdm  1.3.2
greeter.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 David Edmundson
00003  * Copyright (C) 2010-2011 Robert Ancell
00004  * Author: David Edmundson <kde@davidedmundson.co.uk>
00005  *
00006  * This library is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free
00008  * Software Foundation; either version 3 of the License, or (at your option) any
00009  * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
00010  * license.
00011  */
00012 
00013 
00014 #include "QLightDM/greeter.h"
00015 
00016 #include <QtCore/QDebug>
00017 #include <QtCore/QDir>
00018 #include <QtCore/QVariant>
00019 #include <QtCore/QSettings>
00020 
00021 #include <lightdm.h>
00022 
00023 using namespace QLightDM;
00024 
00025 class QLightDM::GreeterPrivate
00026 {
00027 public:
00028     GreeterPrivate(Greeter *parent);
00029     LightDMGreeter *ldmGreeter;
00030 protected:
00031     Greeter* q_ptr;
00032     
00033     static void cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data);
00034     static void cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data);
00035     static void cb_authenticationComplete(LightDMGreeter *greeter, gpointer data);
00036     static void cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data);
00037     
00038 private:
00039     Q_DECLARE_PUBLIC(Greeter)
00040 };
00041 
00042 GreeterPrivate::GreeterPrivate(Greeter *parent) :
00043     q_ptr(parent)
00044 {
00045     g_type_init();
00046     ldmGreeter = lightdm_greeter_new();
00047 
00048     g_signal_connect (ldmGreeter, "show-prompt", G_CALLBACK (cb_showPrompt), this);
00049     g_signal_connect (ldmGreeter, "show-message", G_CALLBACK (cb_showMessage), this);
00050     g_signal_connect (ldmGreeter, "authentication-complete", G_CALLBACK (cb_authenticationComplete), this);
00051     g_signal_connect (ldmGreeter, "autologin-timer-expired", G_CALLBACK (cb_autoLoginExpired), this);
00052 }
00053 
00054 void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
00055 {
00056     Q_UNUSED(greeter);
00057     
00058     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
00059     QString message = QString::fromUtf8(text);
00060     
00061     //FIXME prompt type
00062 
00063     Q_EMIT that->q_func()->showPrompt(message, Greeter::PromptTypeSecret);
00064 }
00065 
00066 void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
00067 {
00068     Q_UNUSED(greeter);
00069 
00070     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
00071     QString message = QString::fromUtf8(text);
00072 
00073     //FIXME prompt type
00074 
00075     Q_EMIT that->q_func()->showMessage(message, Greeter::MessageTypeInfo);
00076 }
00077 
00078 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
00079 {
00080     Q_UNUSED(greeter);
00081     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
00082     Q_EMIT that->q_func()->authenticationComplete();
00083 }
00084 
00085 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
00086 {
00087     Q_UNUSED(greeter);
00088     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
00089     Q_EMIT that->q_func()->autologinTimerExpired();
00090 }
00091 
00092 Greeter::Greeter(QObject *parent) :
00093     QObject(parent),
00094     d_ptr(new GreeterPrivate(this))
00095 {
00096 }
00097 
00098 Greeter::~Greeter()
00099 {
00100     delete d_ptr;
00101 }
00102 
00103 
00104 bool Greeter::connectSync()
00105 {
00106     Q_D(Greeter);
00107     return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
00108 }
00109 
00110 void Greeter::authenticate(const QString &username)
00111 {
00112     Q_D(Greeter);
00113     lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
00114 }
00115 
00116 void Greeter::authenticateAsGuest()
00117 {
00118     Q_D(Greeter);
00119     lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
00120     
00121 }
00122 
00123 void Greeter::respond(const QString &response)
00124 {
00125     Q_D(Greeter);
00126     lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
00127 }
00128 
00129 void Greeter::cancelAuthentication()
00130 {
00131     Q_D(Greeter);
00132     lightdm_greeter_cancel_authentication(d->ldmGreeter);
00133 }
00134 
00135 bool Greeter::inAuthentication() const
00136 {
00137     Q_D(const Greeter);
00138     return lightdm_greeter_get_in_authentication(d->ldmGreeter);
00139 }
00140 
00141 bool Greeter::isAuthenticated() const
00142 {
00143     Q_D(const Greeter);
00144     return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
00145 }
00146 
00147 QString Greeter::authenticationUser() const
00148 {
00149     Q_D(const Greeter);
00150     return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
00151 }
00152 
00153 void Greeter::setLanguage (const QString &language)
00154 {
00155     Q_D(Greeter);
00156     lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
00157 }
00158 
00159 bool Greeter::startSessionSync(const QString &session)
00160 {
00161     Q_D(Greeter);
00162     return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
00163 }
00164 
00165 
00166 QString Greeter::getHint(const QString &name) const
00167 {
00168     Q_D(const Greeter);
00169     return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
00170 }
00171 
00172 QString Greeter::defaultSessionHint() const
00173 {
00174     Q_D(const Greeter);
00175     return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
00176 }
00177 
00178 bool Greeter::hideUsersHint() const
00179 {
00180     Q_D(const Greeter);
00181     return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
00182 }
00183 
00184 bool Greeter::showManualLoginHint() const
00185 {
00186     Q_D(const Greeter);
00187     return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
00188 }
00189 
00190 bool Greeter::lockHint() const
00191 {
00192     Q_D(const Greeter);
00193     return lightdm_greeter_get_lock_hint(d->ldmGreeter);
00194 }
00195 
00196 bool Greeter::hasGuestAccountHint() const
00197 {
00198     Q_D(const Greeter);
00199     return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
00200 }
00201 
00202 QString Greeter::selectUserHint() const
00203 {
00204     Q_D(const Greeter);
00205     return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
00206 }
00207 
00208 bool Greeter::selectGuestHint() const
00209 {
00210     Q_D(const Greeter);
00211     return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
00212 }
00213 
00214 QString Greeter::autologinUserHint() const
00215 {
00216     Q_D(const Greeter);
00217     return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
00218 }
00219 
00220 bool Greeter::autologinGuestHint() const
00221 {
00222     Q_D(const Greeter);
00223     return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
00224 }
00225 
00226 int Greeter::autologinTimeoutHint() const
00227 {
00228     Q_D(const Greeter);
00229     return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
00230 }
00231 
00232 QString Greeter::hostname() const
00233 {
00234     return QString::fromUtf8(lightdm_get_hostname());
00235 }
00236 
00237 #include "greeter_moc.cpp"