on c641e76 help sign in
unity8/plugins/LightDM/Greeter.cpp
155 lines 3.8 kB history raw
1/*
2 * Copyright (C) 2013, 2015 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 */
18#include "Greeter.h"
19#include "GreeterPrivate.h"
20#include <libintl.h>
22GreeterPrivate::GreeterPrivate(Greeter* parent)
23 : m_greeter(new QLightDM::Greeter(parent)),
24 m_active(false),
25 wasPrompted(false),
26 promptless(false),
27 q_ptr(parent)
31Greeter::Greeter(QObject* parent)
32 : QObject(parent),
33 d_ptr(new GreeterPrivate(this))
35 Q_D(Greeter);
37 connect(d->m_greeter, &QLightDM::Greeter::showMessage,
38 this, &Greeter::showMessageFilter);
39 connect(d->m_greeter, &QLightDM::Greeter::showPrompt,
40 this, &Greeter::showPromptFilter);
41 connect(d->m_greeter, &QLightDM::Greeter::authenticationComplete,
42 this, &Greeter::authenticationCompleteFilter);
44 d->m_greeter->connectSync();
47bool Greeter::isActive() const
49 Q_D(const Greeter);
50 return d->m_active;
53void Greeter::setIsActive(bool active)
55 Q_D(Greeter);
56 if (d->m_active != active) {
57 d->m_active = active;
58 Q_EMIT isActiveChanged();
59 }
62bool Greeter::isAuthenticated() const
64 Q_D(const Greeter);
65 return d->m_greeter->isAuthenticated();
68QString Greeter::authenticationUser() const
70 Q_D(const Greeter);
71 return d->m_greeter->authenticationUser();
74QString Greeter::defaultSessionHint() const
76 Q_D(const Greeter);
77 return d->m_greeter->defaultSessionHint();
80bool Greeter::lockHint() const
82 Q_D(const Greeter);
83 return d->m_greeter->lockHint();
86bool Greeter::promptless() const
88 Q_D(const Greeter);
89 return d->promptless;
92QString Greeter::selectUser() const
94 Q_D(const Greeter);
95 return d->m_greeter->selectUserHint();
98void Greeter::authenticate(const QString &username)
100 Q_D(Greeter);
101 d->wasPrompted = false;
102 if (d->promptless) {
103 d->promptless = false;
104 Q_EMIT promptlessChanged();
105 }
107 d->m_greeter->authenticate(username);
108 Q_EMIT isAuthenticatedChanged();
109 Q_EMIT authenticationUserChanged(username);
112void Greeter::respond(const QString &response)
114 Q_D(Greeter);
115 d->m_greeter->respond(response);
118bool Greeter::startSessionSync(const QString &session)
120 Q_D(Greeter);
121 return d->m_greeter->startSessionSync(session);
124void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
126 Q_D(Greeter);
127 d->wasPrompted = true;
129 bool isDefaultPrompt = (text == dgettext("Linux-PAM", "Password: "));
131 // Strip prompt of any colons at the end
132 QString trimmedText = text.trimmed();
133 if (trimmedText.endsWith(':') || trimmedText.endsWith(QStringLiteral(":"))) {
134 trimmedText.chop(1);
135 }
137 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret, isDefaultPrompt);
140void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
142 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
145void Greeter::authenticationCompleteFilter()
147 Q_D(Greeter);
148 if (!d->wasPrompted) {
149 d->promptless = true;
150 Q_EMIT promptlessChanged();
151 }
153 Q_EMIT isAuthenticatedChanged();
154 Q_EMIT authenticationComplete();