on e225248 help sign in
unity8/plugins/LightDM/Greeter.cpp
143 lines 3.6 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::promptless() const
82 Q_D(const Greeter);
83 return d->promptless;
86void Greeter::authenticate(const QString &username)
88 Q_D(Greeter);
89 d->wasPrompted = false;
90 if (d->promptless) {
91 d->promptless = false;
92 Q_EMIT promptlessChanged();
93 }
95 d->m_greeter->authenticate(username);
96 Q_EMIT isAuthenticatedChanged();
97 Q_EMIT authenticationUserChanged(username);
100void Greeter::respond(const QString &response)
102 Q_D(Greeter);
103 d->m_greeter->respond(response);
106bool Greeter::startSessionSync(const QString &session)
108 Q_D(Greeter);
109 return d->m_greeter->startSessionSync(session);
112void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
114 Q_D(Greeter);
115 d->wasPrompted = true;
117 bool isDefaultPrompt = (text == dgettext("Linux-PAM", "Password: "));
119 // Strip prompt of any colons at the end
120 QString trimmedText = text.trimmed();
121 if (trimmedText.endsWith(':') || trimmedText.endsWith(QStringLiteral(":"))) {
122 trimmedText.chop(1);
123 }
125 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret, isDefaultPrompt);
128void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
130 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
133void Greeter::authenticationCompleteFilter()
135 Q_D(Greeter);
136 if (!d->wasPrompted) {
137 d->promptless = true;
138 Q_EMIT promptlessChanged();
139 }
141 Q_EMIT isAuthenticatedChanged();
142 Q_EMIT authenticationComplete();