on 6e7ffdf help sign in
140 lines 3.6 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 <lightdm.h>
22#include <libintl.h>
23#include <QDebug>
25GreeterPrivate::GreeterPrivate(Greeter* parent)
26 : m_greeter(new QLightDM::Greeter(parent)),
27 m_active(false),
28 wasPrompted(false),
29 promptless(false),
30 q_ptr(parent)
34Greeter::Greeter(QObject* parent)
35 : QObject(parent),
36 d_ptr(new GreeterPrivate(this))
38 Q_D(Greeter);
40 connect(d->m_greeter, SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)),
41 this, SLOT(showMessageFilter(QString, QLightDM::Greeter::MessageType)));
42 connect(d->m_greeter, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)),
43 this, SLOT(showPromptFilter(QString, QLightDM::Greeter::PromptType)));
44 connect(d->m_greeter, SIGNAL(authenticationComplete()),
45 this, SLOT(authenticationCompleteFilter()));
47 d->m_greeter->connectSync();
50bool Greeter::isActive() const
52 Q_D(const Greeter);
53 return d->m_active;
56void Greeter::setIsActive(bool active)
58 Q_D(Greeter);
59 if (d->m_active != active) {
60 d->m_active = active;
61 Q_EMIT isActiveChanged();
62 }
65bool Greeter::isAuthenticated() const
67 Q_D(const Greeter);
68 return d->m_greeter->isAuthenticated();
71QString Greeter::authenticationUser() const
73 Q_D(const Greeter);
74 return d->m_greeter->authenticationUser();
77bool Greeter::promptless() const
79 Q_D(const Greeter);
80 return d->promptless;
83void Greeter::authenticate(const QString &username)
85 Q_D(Greeter);
86 d->wasPrompted = false;
87 if (d->promptless) {
88 d->promptless = false;
89 Q_EMIT promptlessChanged();
90 }
92 d->m_greeter->authenticate(username);
93 Q_EMIT isAuthenticatedChanged();
94 Q_EMIT authenticationUserChanged(username);
97void Greeter::respond(const QString &response)
99 Q_D(Greeter);
100 d->m_greeter->respond(response);
103bool Greeter::startSessionSync(const QString &session)
105 Q_D(Greeter);
106 return d->m_greeter->startSessionSync(session);
109void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
111 Q_D(Greeter);
112 d->wasPrompted = true;
114 bool isDefaultPrompt = (text == dgettext("Linux-PAM", "Password: "));
116 // Strip prompt of any colons at the end
117 QString trimmedText = text.trimmed();
118 if (trimmedText.endsWith(":") || trimmedText.endsWith(":")) {
119 trimmedText.chop(1);
120 }
122 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret, isDefaultPrompt);
125void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
127 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
130void Greeter::authenticationCompleteFilter()
132 Q_D(Greeter);
133 if (!d->wasPrompted) {
134 d->promptless = true;
135 Q_EMIT promptlessChanged();
136 }
138 Q_EMIT isAuthenticatedChanged();
139 Q_EMIT authenticationComplete();