on f621663 help sign in
unity8/plugins/LightDM/Greeter.cpp
156 lines 3.9 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 <libintl.h>
21#include <QLightDM/Greeter>
23class GreeterPrivate
25public:
26 explicit GreeterPrivate(Greeter *parent);
28 QLightDM::Greeter *m_greeter;
29 bool m_active;
30 bool wasPrompted;
31 bool promptless;
33protected:
34 Greeter * const q_ptr;
36private:
37 Q_DECLARE_PUBLIC(Greeter)
38};
41GreeterPrivate::GreeterPrivate(Greeter* parent)
42 : m_greeter(new QLightDM::Greeter(parent)),
43 m_active(false),
44 wasPrompted(false),
45 promptless(false),
46 q_ptr(parent)
50Greeter::Greeter(QObject* parent)
51 : QObject(parent),
52 d_ptr(new GreeterPrivate(this))
54 Q_D(Greeter);
56 connect(d->m_greeter, SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)),
57 this, SLOT(showMessageFilter(QString, QLightDM::Greeter::MessageType)));
58 connect(d->m_greeter, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)),
59 this, SLOT(showPromptFilter(QString, QLightDM::Greeter::PromptType)));
60 connect(d->m_greeter, SIGNAL(authenticationComplete()),
61 this, SLOT(authenticationCompleteFilter()));
63 d->m_greeter->connectSync();
66bool Greeter::isActive() const
68 Q_D(const Greeter);
69 return d->m_active;
72void Greeter::setIsActive(bool active)
74 Q_D(Greeter);
75 if (d->m_active != active) {
76 d->m_active = active;
77 Q_EMIT isActiveChanged();
78 }
81bool Greeter::isAuthenticated() const
83 Q_D(const Greeter);
84 return d->m_greeter->isAuthenticated();
87QString Greeter::authenticationUser() const
89 Q_D(const Greeter);
90 return d->m_greeter->authenticationUser();
93bool Greeter::promptless() const
95 Q_D(const Greeter);
96 return d->promptless;
99void Greeter::authenticate(const QString &username)
101 Q_D(Greeter);
102 d->wasPrompted = false;
103 if (d->promptless) {
104 d->promptless = false;
105 Q_EMIT promptlessChanged();
106 }
108 d->m_greeter->authenticate(username);
109 Q_EMIT isAuthenticatedChanged();
110 Q_EMIT authenticationUserChanged(username);
113void Greeter::respond(const QString &response)
115 Q_D(Greeter);
116 d->m_greeter->respond(response);
119bool Greeter::startSessionSync(const QString &session)
121 Q_D(Greeter);
122 return d->m_greeter->startSessionSync(session);
125void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
127 Q_D(Greeter);
128 d->wasPrompted = true;
130 bool isDefaultPrompt = (text == dgettext("Linux-PAM", "Password: "));
132 // Strip prompt of any colons at the end
133 QString trimmedText = text.trimmed();
134 if (trimmedText.endsWith(":") || trimmedText.endsWith(":")) {
135 trimmedText.chop(1);
136 }
138 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret, isDefaultPrompt);
141void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
143 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
146void Greeter::authenticationCompleteFilter()
148 Q_D(Greeter);
149 if (!d->wasPrompted) {
150 d->promptless = true;
151 Q_EMIT promptlessChanged();
152 }
154 Q_EMIT isAuthenticatedChanged();
155 Q_EMIT authenticationComplete();