]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - liblightdm-qt/greeter.cpp
Qt bindings: properly hand over prompt and message type
[sojka/lightdm.git] / liblightdm-qt / greeter.cpp
1 /*
2  * Copyright (C) 2010-2011 David Edmundson
3  * Copyright (C) 2010-2011 Robert Ancell
4  * Author: David Edmundson <kde@davidedmundson.co.uk>
5  *
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.
10  */
11
12
13 #include "QLightDM/greeter.h"
14
15 #include <QtCore/QDebug>
16 #include <QtCore/QDir>
17 #include <QtCore/QVariant>
18 #include <QtCore/QSettings>
19
20 #include <lightdm.h>
21
22 using namespace QLightDM;
23
24 class QLightDM::GreeterPrivate
25 {
26 public:
27     GreeterPrivate(Greeter *parent);
28     LightDMGreeter *ldmGreeter;
29 protected:
30     Greeter* q_ptr;
31     
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     
37 private:
38     Q_DECLARE_PUBLIC(Greeter)
39 };
40
41 GreeterPrivate::GreeterPrivate(Greeter *parent) :
42     q_ptr(parent)
43 {
44 #if !defined(GLIB_VERSION_2_36)
45     g_type_init();
46 #endif
47     ldmGreeter = lightdm_greeter_new();
48
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);
53 }
54
55 void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data)
56 {
57     Q_UNUSED(greeter);
58     
59     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
60     QString message = QString::fromUtf8(text);
61     
62     Q_EMIT that->q_func()->showPrompt(message, type == LIGHTDM_PROMPT_TYPE_QUESTION ?
63                                                Greeter::PromptTypeQuestion : Greeter::PromptTypeSecret);
64 }
65
66 void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data)
67 {
68     Q_UNUSED(greeter);
69
70     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
71     QString message = QString::fromUtf8(text);
72
73     Q_EMIT that->q_func()->showMessage(message, type == LIGHTDM_MESSAGE_TYPE_INFO ?
74                                                 Greeter::MessageTypeInfo : Greeter::MessageTypeError);
75 }
76
77 void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data)
78 {
79     Q_UNUSED(greeter);
80     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
81     Q_EMIT that->q_func()->authenticationComplete();
82 }
83
84 void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data)
85 {
86     Q_UNUSED(greeter);
87     GreeterPrivate *that = static_cast<GreeterPrivate*>(data);
88     Q_EMIT that->q_func()->autologinTimerExpired();
89 }
90
91 Greeter::Greeter(QObject *parent) :
92     QObject(parent),
93     d_ptr(new GreeterPrivate(this))
94 {
95 }
96
97 Greeter::~Greeter()
98 {
99     delete d_ptr;
100 }
101
102
103 bool Greeter::connectSync()
104 {
105     Q_D(Greeter);
106     return lightdm_greeter_connect_sync(d->ldmGreeter, NULL);
107 }
108
109 void Greeter::authenticate(const QString &username)
110 {
111     Q_D(Greeter);
112     lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data());
113 }
114
115 void Greeter::authenticateAsGuest()
116 {
117     Q_D(Greeter);
118     lightdm_greeter_authenticate_as_guest(d->ldmGreeter);
119 }
120
121 void Greeter::authenticateAutologin()
122 {
123     Q_D(Greeter);
124     lightdm_greeter_authenticate_autologin(d->ldmGreeter);
125 }
126
127 void Greeter::authenticateRemote(const QString &session, const QString &username)
128 {
129     Q_D(Greeter);
130     lightdm_greeter_authenticate_remote(d->ldmGreeter, session.toLocal8Bit().data(), username.toLocal8Bit().data());
131 }
132
133 void Greeter::respond(const QString &response)
134 {
135     Q_D(Greeter);
136     lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data());
137 }
138
139 void Greeter::cancelAuthentication()
140 {
141     Q_D(Greeter);
142     lightdm_greeter_cancel_authentication(d->ldmGreeter);
143 }
144
145 bool Greeter::inAuthentication() const
146 {
147     Q_D(const Greeter);
148     return lightdm_greeter_get_in_authentication(d->ldmGreeter);
149 }
150
151 bool Greeter::isAuthenticated() const
152 {
153     Q_D(const Greeter);
154     return lightdm_greeter_get_is_authenticated(d->ldmGreeter);
155 }
156
157 QString Greeter::authenticationUser() const
158 {
159     Q_D(const Greeter);
160     return QString::fromUtf8(lightdm_greeter_get_authentication_user(d->ldmGreeter));
161 }
162
163 void Greeter::setLanguage (const QString &language)
164 {
165     Q_D(Greeter);
166     lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData());
167 }
168
169 bool Greeter::startSessionSync(const QString &session)
170 {
171     Q_D(Greeter);
172     return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL);
173 }
174
175
176 QString Greeter::getHint(const QString &name) const
177 {
178     Q_D(const Greeter);
179     return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData());
180 }
181
182 QString Greeter::defaultSessionHint() const
183 {
184     Q_D(const Greeter);
185     return QString::fromUtf8(lightdm_greeter_get_default_session_hint(d->ldmGreeter));
186 }
187
188 bool Greeter::hideUsersHint() const
189 {
190     Q_D(const Greeter);
191     return lightdm_greeter_get_hide_users_hint(d->ldmGreeter);
192 }
193
194 bool Greeter::showManualLoginHint() const
195 {
196     Q_D(const Greeter);
197     return lightdm_greeter_get_show_manual_login_hint(d->ldmGreeter);
198 }
199
200 bool Greeter::showRemoteLoginHint() const
201 {
202     Q_D(const Greeter);
203     return lightdm_greeter_get_show_remote_login_hint(d->ldmGreeter);
204 }
205
206 bool Greeter::lockHint() const
207 {
208     Q_D(const Greeter);
209     return lightdm_greeter_get_lock_hint(d->ldmGreeter);
210 }
211
212 bool Greeter::hasGuestAccountHint() const
213 {
214     Q_D(const Greeter);
215     return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter);
216 }
217
218 QString Greeter::selectUserHint() const
219 {
220     Q_D(const Greeter);
221     return QString::fromUtf8(lightdm_greeter_get_select_user_hint(d->ldmGreeter));
222 }
223
224 bool Greeter::selectGuestHint() const
225 {
226     Q_D(const Greeter);
227     return lightdm_greeter_get_select_guest_hint(d->ldmGreeter);
228 }
229
230 QString Greeter::autologinUserHint() const
231 {
232     Q_D(const Greeter);
233     return QString::fromUtf8(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter));
234 }
235
236 bool Greeter::autologinGuestHint() const
237 {
238     Q_D(const Greeter);
239     return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter);
240 }
241
242 int Greeter::autologinTimeoutHint() const
243 {
244     Q_D(const Greeter);
245     return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter);
246 }
247
248 QString Greeter::hostname() const
249 {
250     return QString::fromUtf8(lightdm_get_hostname());
251 }
252
253 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
254 #include "greeter_moc5.cpp"
255 #else
256 #include "greeter_moc4.cpp"
257 #endif