on ebc6a48 help sign in
unity8/plugins/LightDM/Greeter.cpp
146 lines 3.7 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 <QCoreApplication>
21#include <QLightDM/Greeter>
23#include <QDebug>
25class GreeterPrivate
27public:
28 explicit GreeterPrivate(Greeter *parent);
30 QLightDM::Greeter *m_greeter;
31 bool wasPrompted;
32 bool promptless;
34protected:
35 Greeter * const q_ptr;
37private:
38 Q_DECLARE_PUBLIC(Greeter)
39};
42GreeterPrivate::GreeterPrivate(Greeter* parent)
43 : m_greeter(new QLightDM::Greeter(parent)),
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 // Listen for "state resets"
64 connect(QCoreApplication::instance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)),
65 this, SLOT(handleAppStateChange(Qt::ApplicationState)));
67 d->m_greeter->connectSync();
70void Greeter::handleAppStateChange(Qt::ApplicationState state)
72 qDebug() << "MIKE state change " << state;
75bool Greeter::isAuthenticated() const
77 Q_D(const Greeter);
78 return d->m_greeter->isAuthenticated();
81QString Greeter::authenticationUser() const
83 Q_D(const Greeter);
84 return d->m_greeter->authenticationUser();
87bool Greeter::promptless() const
89 Q_D(const Greeter);
90 return d->promptless;
93void Greeter::authenticate(const QString &username)
95 Q_D(Greeter);
96 d->wasPrompted = false;
97 if (d->promptless) {
98 d->promptless = false;
99 Q_EMIT promptlessChanged();
100 }
102 d->m_greeter->authenticate(username);
103 Q_EMIT authenticationUserChanged(username);
106void Greeter::respond(const QString &response)
108 Q_D(Greeter);
109 d->m_greeter->respond(response);
112bool Greeter::startSessionSync(const QString &session)
114 Q_D(Greeter);
115 return d->m_greeter->startSessionSync(session);
118void Greeter::showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type)
120 Q_D(Greeter);
121 d->wasPrompted = true;
123 // Strip prompt of any colons at the end
124 QString trimmedText = text.trimmed();
125 if (trimmedText.endsWith(":") || trimmedText.endsWith(":")) {
126 trimmedText.chop(1);
127 }
129 Q_EMIT showPrompt(trimmedText, type == QLightDM::Greeter::PromptTypeSecret);
132void Greeter::showMessageFilter(const QString &text, QLightDM::Greeter::MessageType type)
134 Q_EMIT showMessage(text, type == QLightDM::Greeter::MessageTypeError);
137void Greeter::authenticationCompleteFilter()
139 Q_D(Greeter);
140 if (!d->wasPrompted) {
141 d->promptless = true;
142 Q_EMIT promptlessChanged();
143 }
145 Q_EMIT authenticationComplete();