on 09cb68b help sign in
139 lines 3.5 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
19#include "Greeter.h"
20#include "GreeterPrivate.h"
21#include <libintl.h>
22#include <QDebug>
24GreeterPrivate::GreeterPrivate(Greeter* parent)
25 : m_greeter(new QLightDM::Greeter(parent)),
26 m_active(false),
27 wasPrompted(false),
28 promptless(false),
29 q_ptr(parent)
33Greeter::Greeter(QObject* parent)
34 : QObject(parent),
35 d_ptr(new GreeterPrivate(this))
37 Q_D(Greeter);
39 connect(d->m_greeter, &QLightDM::Greeter::showMessage,
40 this, &Greeter::showMessageFilter);
41 connect(d->m_greeter, &QLightDM::Greeter::showPrompt,
42 this, &Greeter::showPromptFilter);
43 connect(d->m_greeter, &QLightDM::Greeter::authenticationComplete,
44 this, &Greeter::authenticationCompleteFilter);
46 d->m_greeter->connectSync();
49bool Greeter::isActive() const
51 Q_D(const Greeter);
52 return d->m_active;
55void Greeter::setIsActive(bool active)
57 Q_D(Greeter);
58 if (d->m_active != active) {
59 d->m_active = active;
60 Q_EMIT isActiveChanged();
61 }
64bool Greeter::isAuthenticated() const
66 Q_D(const Greeter);
67 return d->m_greeter->isAuthenticated();
70QString Greeter::authenticationUser() const
72 Q_D(const Greeter);
73 return d->m_greeter->authenticationUser();
76bool Greeter::promptless() const
78 Q_D(const Greeter);
79 return d->promptless;
82void Greeter::authenticate(const QString &username)
84 Q_D(Greeter);
85 d->wasPrompted = false;
86 if (d->promptless) {
87 d->promptless = false;
88 Q_EMIT promptlessChanged();
89 }
91 d->m_greeter->authenticate(username);
92 Q_EMIT isAuthenticatedChanged();
93 Q_EMIT authenticationUserChanged(username);
96void Greeter::respond(const QString &response)
98 Q_D(Greeter);
99 d->m_greeter->respond(response);
102bool Greeter::startSessionSync(const QString &session)
104 Q_D(Greeter);
105 return d->m_greeter->startSessionSync(session);
108void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
110 Q_D(Greeter);
111 d->wasPrompted = true;
113 bool isDefaultPrompt = (text == dgettext("Linux-PAM", "Password: "));
115 // Strip prompt of any colons at the end
116 QString trimmedText = text.trimmed();
117 if (trimmedText.endsWith(":") || trimmedText.endsWith(":")) {
118 trimmedText.chop(1);
119 }
121 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret, isDefaultPrompt);
124void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
126 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
129void Greeter::authenticationCompleteFilter()
131 Q_D(Greeter);
132 if (!d->wasPrompted) {
133 d->promptless = true;
134 Q_EMIT promptlessChanged();
135 }
137 Q_EMIT isAuthenticatedChanged();
138 Q_EMIT authenticationComplete();