on xenial help sign in
Add all the files that were accidently unversioned
c066d25Josh Arenson
plugins/LightDM/FullLightDM/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module LightDM.FullLightDM
2+plugin FullLightDM-qml
3+typeinfo FullLightDM.qmltypes
plugins/LightDM/FullLightDMqmldirnew file+3
@@ -0,0 +1,3 @@
1+module FullLightDM
2+plugin FullLightDM-qml
3+typeinfo FullLightDM.qmltypes
plugins/LightDM/IntegratedLightDM/CMakeLists.txtnew file+34
@@ -0,0 +1,34 @@
1+set(PLUGIN_CLASSNAME "IntegratedLightDM")
2+
3+# Written to source dir as thats where add_unity8_plugin expects it
4+configure_file(../qmldir.in ${CMAKE_CURRENT_SOURCE_DIR}/qmldir)
5+
6+add_definitions(-DINTEGRATED_LIGHTDM)
7+
8+foreach(include_directory ${QMLPLUGIN_INCLUDES})
9+ list(APPEND RELATIVE_QMLPLUGIN_INCLUDES ../${include_directory})
10+endforeach()
11+
12+include_directories(
13+ ${QMLPLUGIN_INCLUDES}
14+ ${libunity8-private_SOURCE_DIR}
15+)
16+
17+foreach(source_file ${QMLPLUGIN_SRC})
18+ list(APPEND RELATIVE_QMLPLUGIN_SRC ../${source_file})
19+endforeach()
20+
21+add_library(IntegratedLightDM-qml MODULE
22+ ${RELATIVE_QMLPLUGIN_SRC}
23+ )
24+
25+target_link_libraries(IntegratedLightDM-qml
26+ integratedLightDM
27+ unity8-private
28+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
29+ )
30+
31+qt5_use_modules(IntegratedLightDM-qml DBus Gui Qml)
32+add_unity8_plugin(IntegratedLightDM 0.1 LightDM/IntegratedLightDM TARGETS IntegratedLightDM-qml)
33+
34+add_subdirectory(liblightdm)
plugins/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txtnew file+37
@@ -0,0 +1,37 @@
1+pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
2+
3+set(LibLightDM_SOURCES
4+ Greeter.cpp
5+ UsersModel.cpp
6+ GreeterPrivate.cpp
7+ UsersModelPrivate.cpp
8+ ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
9+ )
10+
11+add_library(integratedLightDM STATIC ${LibLightDM_SOURCES})
12+add_library(MockLightDM-demo-shared SHARED ${LibLightDM_SOURCES})
13+
14+include_directories(
15+ ${CMAKE_CURRENT_BINARY_DIR}
16+ ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
17+)
18+
19+target_link_libraries(integratedLightDM
20+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
21+ -lpam
22+)
23+target_link_libraries(MockLightDM-demo-shared
24+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
25+ -lpam
26+)
27+
28+qt5_use_modules(integratedLightDM Concurrent Gui)
29+qt5_use_modules(MockLightDM-demo-shared Concurrent Gui)
30+
31+set_target_properties(integratedLightDM PROPERTIES COMPILE_FLAGS -fPIC)
32+set_target_properties(MockLightDM-demo-shared PROPERTIES
33+ OUTPUT_NAME lightdm-qt5-2)
34+
35+install(TARGETS MockLightDM-demo-shared
36+ DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/demo
37+ )
plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.cppnew file+184
@@ -0,0 +1,184 @@
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+ */
18+
19+
20+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
22+ * COUNTERPART IN tests/mocks/Lightdm/liblightdm
23+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
24+
25+
26+#include "Greeter.h"
27+#include "GreeterPrivate.h"
28+#include <QtCore/QCoreApplication>
29+#include <QTimer>
30+
31+namespace QLightDM
32+{
33+
34+Greeter::Greeter(QObject *parent)
35+ : QObject(parent),
36+ d_ptr(new GreeterPrivate(this))
37+{
38+}
39+
40+Greeter::~Greeter()
41+{
42+}
43+
44+QString Greeter::authenticationUser() const
45+{
46+ Q_D(const Greeter);
47+ return d->authenticationUser;
48+}
49+
50+bool Greeter::hasGuestAccountHint() const
51+{
52+ return true;
53+}
54+
55+QString Greeter::getHint(const QString &name) const
56+{
57+ Q_UNUSED(name)
58+ return "";
59+}
60+
61+QString Greeter::defaultSessionHint() const
62+{
63+ return "ubuntu";
64+}
65+
66+bool Greeter::hideUsersHint() const
67+{
68+ return false;
69+}
70+
71+bool Greeter::showManualLoginHint() const
72+{
73+ return true;
74+}
75+
76+bool Greeter::showRemoteLoginHint() const
77+{
78+ return true;
79+}
80+
81+bool Greeter::lockHint () const
82+{
83+ return false;
84+}
85+
86+QString Greeter::selectUserHint() const
87+{
88+ return "";
89+}
90+
91+bool Greeter::selectGuestHint() const
92+{
93+ return false;
94+}
95+
96+QString Greeter::autologinUserHint() const
97+{
98+ return "";
99+}
100+
101+bool Greeter::autologinGuestHint() const
102+{
103+ return false;
104+}
105+
106+int Greeter::autologinTimeoutHint() const
107+{
108+ return 0;
109+}
110+
111+bool Greeter::inAuthentication() const
112+{
113+ return false;
114+}
115+
116+QString Greeter::hostname() const
117+{
118+ return "hostname1";
119+}
120+
121+bool Greeter::isAuthenticated() const
122+{
123+ Q_D(const Greeter);
124+ return d->authenticated;
125+}
126+
127+bool Greeter::connectSync()
128+{
129+ return true;
130+}
131+
132+void Greeter::authenticate(const QString &username)
133+{
134+ Q_D(Greeter);
135+
136+ d->authenticated = false;
137+ d->authenticationUser = username;
138+ d->handleAuthenticate();
139+}
140+
141+void Greeter::authenticateAsGuest()
142+{}
143+
144+void Greeter::authenticateAutologin()
145+{}
146+
147+void Greeter::authenticateRemote(const QString &session, const QString &username)
148+{
149+ Q_UNUSED(session)
150+ Q_UNUSED(username)
151+}
152+
153+void Greeter::cancelAuthentication()
154+{}
155+
156+void Greeter::setLanguage (const QString &language)
157+{
158+ Q_UNUSED(language)
159+}
160+
161+bool Greeter::startSessionSync(const QString &session)
162+{
163+ Q_UNUSED(session)
164+ return true;
165+}
166+
167+void Greeter::respond(const QString &response)
168+{
169+ Q_D(Greeter);
170+
171+ d->handleRespond(response);
172+}
173+
174+void Greeter::sendAuthenticationComplete()
175+{
176+ if (qgetenv("UNITY_TESTING").isEmpty()) {
177+ // simulate PAM's delay
178+ QTimer::singleShot(1000, this, SIGNAL(authenticationComplete()));
179+ } else {
180+ Q_EMIT authenticationComplete();
181+ }
182+}
183+
184+}
plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.hnew file+110
@@ -0,0 +1,110 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ * Copyright (C) 2010-2011 David Edmundson.
4+ * Copyright (C) 2010-2011 Robert Ancell
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ *
18+ * Author: David Edmundson <kde@davidedmundson.co.uk>
19+ */
20+
21+#ifndef UNITY_MOCK_GREETER_H
22+#define UNITY_MOCK_GREETER_H
23+
24+#include <QtCore/QObject>
25+#include <QtCore/QVariant>
26+
27+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
29+ * COUNTERPART IN tests/mocks/Lightdm/liblightdm
30+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
31+
32+namespace QLightDM
33+{
34+ class GreeterPrivate;
35+
36+class Q_DECL_EXPORT Greeter : public QObject
37+{
38+ Q_OBJECT
39+
40+ Q_PROPERTY(bool authenticated READ isAuthenticated ) //NOTFIY authenticationComplete
41+ Q_PROPERTY(QString authenticationUser READ authenticationUser )
42+ Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
43+ Q_PROPERTY(QString selectUser READ selectUserHint CONSTANT)
44+ Q_PROPERTY(bool selectGuest READ selectGuestHint CONSTANT)
45+
46+ Q_PROPERTY(QString hostname READ hostname CONSTANT)
47+ Q_PROPERTY(bool hasGuestAccount READ hasGuestAccountHint CONSTANT)
48+ Q_PROPERTY(bool locked READ lockHint CONSTANT)
49+
50+ Q_ENUMS(PromptType MessageType)
51+
52+public:
53+ enum PromptType {
54+ PromptTypeQuestion,
55+ PromptTypeSecret
56+ };
57+
58+ enum MessageType {
59+ MessageTypeInfo,
60+ MessageTypeError
61+ };
62+
63+ explicit Greeter(QObject* parent=0);
64+ virtual ~Greeter();
65+
66+ QString getHint(const QString &name) const;
67+ QString defaultSessionHint() const;
68+ bool hideUsersHint() const;
69+ bool showManualLoginHint() const;
70+ bool showRemoteLoginHint() const;
71+ bool lockHint () const;
72+ bool hasGuestAccountHint() const;
73+ QString selectUserHint() const;
74+ bool selectGuestHint() const;
75+ QString autologinUserHint() const;
76+ bool autologinGuestHint() const;
77+ int autologinTimeoutHint() const;
78+
79+ bool inAuthentication() const;
80+ bool isAuthenticated() const;
81+ QString authenticationUser() const;
82+ QString hostname() const;
83+
84+public Q_SLOTS:
85+ bool connectSync();
86+ void authenticate(const QString &username=QString());
87+ void authenticateAsGuest();
88+ void authenticateAutologin();
89+ void authenticateRemote(const QString &session=QString(), const QString &username=QString());
90+ void respond(const QString &response);
91+ void cancelAuthentication();
92+ void setLanguage (const QString &language);
93+ bool startSessionSync(const QString &session=QString());
94+
95+Q_SIGNALS:
96+ void showMessage(QString text, QLightDM::Greeter::MessageType type);
97+ void showPrompt(QString text, QLightDM::Greeter::PromptType type);
98+ void authenticationComplete();
99+ void autologinTimerExpired();
100+
101+protected:
102+ void sendAuthenticationComplete();
103+
104+private:
105+ GreeterPrivate *d_ptr;
106+ Q_DECLARE_PRIVATE(Greeter)
107+};
108+}
109+
110+#endif // UNITY_MOCK_GREETER_H
plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cppnew file+305
@@ -0,0 +1,305 @@
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+ */
18+
19+#include "Greeter.h"
20+#include "GreeterPrivate.h"
21+#include <QFuture>
22+#include <QFutureInterface>
23+#include <QFutureWatcher>
24+#include <QQueue>
25+#include <QtConcurrent>
26+#include <QVector>
27+#include <security/pam_appl.h>
28+
29+namespace QLightDM
30+{
31+
32+class GreeterImpl : public QObject
33+{
34+ Q_OBJECT
35+
36+ struct AppData
37+ {
38+ GreeterImpl *impl;
39+ pam_handle *handle;
40+ };
41+
42+ typedef QFutureInterface<QString> ResponseFuture;
43+
44+public:
45+ explicit GreeterImpl(Greeter *parent, GreeterPrivate *greeterPrivate)
46+ : QObject(parent),
47+ greeter(parent),
48+ greeterPrivate(greeterPrivate),
49+ pamHandle(nullptr)
50+ {
51+ qRegisterMetaType<QLightDM::GreeterImpl::ResponseFuture>("QLightDM::GreeterImpl::ResponseFuture");
52+
53+ connect(&futureWatcher, SIGNAL(finished()),
54+ this, SLOT(finishPam()));
55+ connect(this, SIGNAL(showMessage(pam_handle *, QString, QLightDM::Greeter::MessageType)),
56+ this, SLOT(handleMessage(pam_handle *, QString, QLightDM::Greeter::MessageType)));
57+ // This next connect is how we pass ResponseFutures between threads
58+ connect(this, SIGNAL(showPrompt(pam_handle *, QString, QLightDM::Greeter::PromptType, QLightDM::GreeterImpl::ResponseFuture)),
59+ this, SLOT(handlePrompt(pam_handle *, QString, QLightDM::Greeter::PromptType, QLightDM::GreeterImpl::ResponseFuture)),
60+ Qt::BlockingQueuedConnection);
61+ }
62+
63+ ~GreeterImpl()
64+ {
65+ cancelPam();
66+ }
67+
68+ void start(QString username)
69+ {
70+ // Clear out any existing PAM interactions first
71+ cancelPam();
72+ if (pamHandle != nullptr) {
73+ // While we were cancelling pam above, we processed Qt events.
74+ // Which may have allowed someone to call start() on us again.
75+ // In which case, we'll bail on our current start() call.
76+ // This isn't racy because it's all in the same thread.
77+ return;
78+ }
79+
80+ AppData *appData = new AppData();
81+ appData->impl = this;
82+
83+ // Now actually start a new conversation with PAM
84+ pam_conv conversation;
85+ conversation.conv = converseWithPam;
86+ conversation.appdata_ptr = static_cast<void*>(appData);
87+
88+ if (pam_start("lightdm", username.toUtf8(), &conversation, &pamHandle) == PAM_SUCCESS) {
89+ appData->handle = pamHandle;
90+ futureWatcher.setFuture(QtConcurrent::mapped(QList<pam_handle*>() << pamHandle, authenticateWithPam));
91+ } else {
92+ delete appData;
93+ greeterPrivate->authenticated = false;
94+ Q_EMIT greeter->showMessage("Internal error: could not start PAM authentication", QLightDM::Greeter::MessageTypeError);
95+ Q_EMIT greeter->authenticationComplete();
96+ }
97+ }
98+
99+ static int authenticateWithPam(pam_handle* const& pamHandle)
100+ {
101+ int pamStatus = pam_authenticate(pamHandle, 0);
102+ if (pamStatus == PAM_SUCCESS) {
103+ pamStatus = pam_acct_mgmt(pamHandle, 0);
104+ }
105+ if (pamStatus == PAM_NEW_AUTHTOK_REQD) {
106+ pamStatus = pam_chauthtok(pamHandle, PAM_CHANGE_EXPIRED_AUTHTOK);
107+ }
108+ if (pamStatus == PAM_SUCCESS) {
109+ pam_setcred(pamHandle, PAM_REINITIALIZE_CRED);
110+ }
111+ return pamStatus;
112+ }
113+
114+ static int converseWithPam(int num_msg, const pam_message** msg,
115+ pam_response** resp, void* appdata_ptr)
116+ {
117+ if (num_msg <= 0)
118+ return PAM_CONV_ERR;
119+
120+ auto* tmp_response = static_cast<pam_response*>(calloc(num_msg, sizeof(pam_response)));
121+ if (!tmp_response)
122+ return PAM_CONV_ERR;
123+
124+ AppData *appData = static_cast<AppData*>(appdata_ptr);
125+ GreeterImpl *impl = appData->impl;
126+ pam_handle *handle = appData->handle;
127+
128+ int count;
129+ QVector<ResponseFuture> responses;
130+
131+ for (count = 0; count < num_msg; ++count)
132+ {
133+ switch (msg[count]->msg_style)
134+ {
135+ case PAM_PROMPT_ECHO_ON:
136+ {
137+ QString message(msg[count]->msg);
138+ responses.append(ResponseFuture());
139+ responses.last().reportStarted();
140+ Q_EMIT impl->showPrompt(handle, message, Greeter::PromptTypeQuestion, responses.last());
141+ break;
142+ }
143+ case PAM_PROMPT_ECHO_OFF:
144+ {
145+ QString message(msg[count]->msg);
146+ responses.append(ResponseFuture());
147+ responses.last().reportStarted();
148+ Q_EMIT impl->showPrompt(handle, message, Greeter::PromptTypeSecret, responses.last());
149+ break;
150+ }
151+ case PAM_TEXT_INFO:
152+ {
153+ QString message(msg[count]->msg);
154+ Q_EMIT impl->showMessage(handle, message, Greeter::MessageTypeInfo);
155+ break;
156+ }
157+ default:
158+ {
159+ QString message(msg[count]->msg);
160+ Q_EMIT impl->showMessage(handle, message, Greeter::MessageTypeError);
161+ break;
162+ }
163+ }
164+ }
165+
166+ int i = 0;
167+ bool raise_error = false;
168+
169+ for (auto &response : responses)
170+ {
171+ pam_response* resp_item = &tmp_response[i++];
172+ resp_item->resp_retcode = 0;
173+ resp_item->resp = strdup(response.future().result().toUtf8());
174+
175+ if (!resp_item->resp)
176+ {
177+ raise_error = true;
178+ break;
179+ }
180+ }
181+
182+ delete appData;
183+
184+ if (raise_error)
185+ {
186+ for (int i = 0; i < count; ++i)
187+ free(tmp_response[i].resp);
188+
189+ free(tmp_response);
190+ return PAM_CONV_ERR;
191+ }
192+ else
193+ {
194+ *resp = tmp_response;
195+ return PAM_SUCCESS;
196+ }
197+ }
198+
199+public Q_SLOTS:
200+ bool respond(QString response)
201+ {
202+ if (!futures.isEmpty()) {
203+ futures.dequeue().reportFinished(&response);
204+ return true;
205+ } else {
206+ return false;
207+ }
208+ }
209+
210+Q_SIGNALS:
211+ void showMessage(pam_handle *handle, QString text, QLightDM::Greeter::MessageType type);
212+ void showPrompt(pam_handle *handle, QString text, QLightDM::Greeter::PromptType type, QLightDM::GreeterImpl::ResponseFuture response);
213+
214+private Q_SLOTS:
215+ void finishPam()
216+ {
217+ if (pamHandle == nullptr) {
218+ return;
219+ }
220+
221+ int pamStatus = futureWatcher.result();
222+
223+ pam_end(pamHandle, pamStatus);
224+ pamHandle = nullptr;
225+
226+ greeterPrivate->authenticated = (pamStatus == PAM_SUCCESS);
227+ Q_EMIT greeter->authenticationComplete();
228+ }
229+
230+ void handleMessage(pam_handle *handle, QString text, QLightDM::Greeter::MessageType type)
231+ {
232+ if (handle != pamHandle)
233+ return;
234+
235+ Q_EMIT greeter->showMessage(text, type);
236+ }
237+
238+ void handlePrompt(pam_handle *handle, QString text, QLightDM::Greeter::PromptType type, QLightDM::GreeterImpl::ResponseFuture future)
239+ {
240+ if (handle != pamHandle) {
241+ future.reportResult(QString());
242+ future.reportFinished();
243+ return;
244+ }
245+
246+ futures.enqueue(future);
247+ Q_EMIT greeter->showPrompt(text, type);
248+ }
249+
250+private:
251+ void cancelPam()
252+ {
253+ if (pamHandle != nullptr) {
254+ QFuture<int> pamFuture = futureWatcher.future();
255+ pam_handle *handle = pamHandle;
256+ pamHandle = nullptr; // to disable normal finishPam() handling
257+ pamFuture.cancel();
258+
259+ // Note the empty loop, we just want to clear the futures queue.
260+ // Any further prompts from the pam thread will be immediately
261+ // responded to/dismissed in handlePrompt().
262+ while (respond(QString()));
263+
264+ // Now let signal/slot handling happen so the thread can finish
265+ while (!pamFuture.isFinished()) {
266+ QCoreApplication::processEvents();
267+ }
268+
269+ pam_end(handle, PAM_CONV_ERR);
270+ }
271+ }
272+
273+ Greeter *greeter;
274+ GreeterPrivate *greeterPrivate;
275+ pam_handle* pamHandle;
276+ QFutureWatcher<int> futureWatcher;
277+ QQueue<ResponseFuture> futures;
278+};
279+
280+GreeterPrivate::GreeterPrivate(Greeter* parent)
281+ : authenticated(false),
282+ authenticationUser(),
283+ m_impl(new GreeterImpl(parent, this)),
284+ q_ptr(parent)
285+{
286+}
287+
288+GreeterPrivate::~GreeterPrivate()
289+{
290+ delete m_impl;
291+}
292+
293+void GreeterPrivate::handleAuthenticate()
294+{
295+ m_impl->start(authenticationUser);
296+}
297+
298+void GreeterPrivate::handleRespond(const QString &response)
299+{
300+ m_impl->respond(response);
301+}
302+
303+}
304+
305+#include "GreeterPrivate.moc"
plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.hnew file+51
@@ -0,0 +1,51 @@
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+ */
18+
19+#ifndef UNITY_MOCK_GREETER_PRIVATE_H
20+#define UNITY_MOCK_GREETER_PRIVATE_H
21+
22+#include <QtCore/QObject>
23+
24+namespace QLightDM
25+{
26+class Greeter;
27+class GreeterImpl;
28+
29+class GreeterPrivate
30+{
31+public:
32+ explicit GreeterPrivate(Greeter* parent=0);
33+ virtual ~GreeterPrivate();
34+
35+ // These variables may not be used by all subclasses, that's no problem
36+ bool authenticated;
37+ QString authenticationUser;
38+
39+ void handleAuthenticate();
40+ void handleRespond(const QString &response);
41+
42+protected:
43+ GreeterImpl *m_impl; // if the backend needs more private data
44+ Greeter * const q_ptr;
45+
46+private:
47+ Q_DECLARE_PUBLIC(Greeter)
48+};
49+}
50+
51+#endif // UNITY_MOCK_GREETER_PRIVATE_H
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.cppnew file+123
@@ -0,0 +1,123 @@
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+ */
18+
19+
20+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
22+ * COUNTERPART IN tests/mocks/Lightdm/liblightdm
23+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
24+
25+// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
26+// To use the same method of setting role name that it does, we
27+// set our compatibility to Qt4 here too.
28+#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
29+
30+#include "UsersModel.h"
31+#include "UsersModelPrivate.h"
32+#include <QtCore/QDir>
33+#include <QtCore/QString>
34+#include <QtGui/QIcon>
35+
36+namespace QLightDM
37+{
38+
39+UsersModel::UsersModel(QObject *parent) :
40+ QAbstractListModel(parent),
41+ d_ptr(new UsersModelPrivate(this))
42+{
43+ Q_D(UsersModel);
44+
45+ // Extend roleNames (we want to keep the "display" role)
46+ QHash<int, QByteArray> roles = roleNames();
47+ roles[NameRole] = "name";
48+ roles[RealNameRole] = "realName";
49+ roles[LoggedInRole] = "loggedIn";
50+ roles[BackgroundRole] = "background";
51+ roles[BackgroundPathRole] = "backgroundPath";
52+ roles[SessionRole] = "session";
53+ roles[HasMessagesRole] = "hasMessages";
54+ roles[ImagePathRole] = "imagePath";
55+ setRoleNames(roles);
56+
57+ // Now modify our mock user backgrounds
58+ QDir bgdir = QDir("/usr/share/demo-assets/shell/backgrounds/");
59+ QStringList backgrounds = bgdir.entryList(QDir::Files | QDir::NoDotAndDotDot);
60+
61+ for (int i = 0, j = 0; i < d->entries.size(); i++) {
62+ Entry &entry = d->entries[i];
63+ if (entry.background.isNull() && !backgrounds.isEmpty()) {
64+ entry.background = bgdir.filePath(backgrounds[j++]);
65+ if (j >= backgrounds.length()) {
66+ j = 0;
67+ }
68+ }
69+ }
70+}
71+
72+UsersModel::~UsersModel()
73+{
74+ delete d_ptr;
75+}
76+
77+int UsersModel::rowCount(const QModelIndex &parent) const
78+{
79+ Q_D(const UsersModel);
80+
81+ if (parent.isValid()) {
82+ return 0;
83+ } else { // parent is root
84+ return d->entries.size();
85+ }
86+}
87+
88+QVariant UsersModel::data(const QModelIndex &index, int role) const
89+{
90+ Q_D(const UsersModel);
91+
92+ if (!index.isValid()) {
93+ return QVariant();
94+ }
95+
96+ int row = index.row();
97+ switch (role) {
98+ case Qt::DisplayRole:
99+ return d->entries[row].real_name;
100+ case Qt::DecorationRole:
101+ return QIcon();
102+ case UsersModel::NameRole:
103+ return d->entries[row].username;
104+ case UsersModel::RealNameRole:
105+ return d->entries[row].real_name;
106+ case UsersModel::SessionRole:
107+ return d->entries[row].session;
108+ case UsersModel::LoggedInRole:
109+ return d->entries[row].is_active;
110+ case UsersModel::BackgroundRole:
111+ return QPixmap(d->entries[row].background);
112+ case UsersModel::BackgroundPathRole:
113+ return d->entries[row].background;
114+ case UsersModel::HasMessagesRole:
115+ return d->entries[row].has_messages;
116+ case UsersModel::ImagePathRole:
117+ return "";
118+ default:
119+ return QVariant();
120+ }
121+}
122+
123+}
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.hnew file+66
@@ -0,0 +1,66 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ * Copyright (C) 2010-2011 David Edmundson.
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; version 3.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ * Author: David Edmundson <kde@davidedmundson.co.uk>
18+ */
19+
20+#ifndef UNITY_MOCK_USERSMODEL_H
21+#define UNITY_MOCK_USERSMODEL_H
22+
23+#include <QtCore/QString>
24+#include <QtCore/QSharedDataPointer>
25+#include <QAbstractListModel>
26+
27+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
29+ * COUNTERPART IN tests/mocks/Lightdm/liblightdm
30+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
31+
32+namespace QLightDM
33+{
34+class UsersModelPrivate;
35+
36+class Q_DECL_EXPORT UsersModel : public QAbstractListModel
37+{
38+ Q_OBJECT
39+
40+ Q_ENUMS(UserModelRoles)
41+
42+public:
43+ explicit UsersModel(QObject *parent = 0);
44+ virtual ~UsersModel();
45+
46+ enum UserModelRoles {NameRole = Qt::UserRole,
47+ RealNameRole,
48+ LoggedInRole,
49+ BackgroundRole,
50+ SessionRole,
51+ HasMessagesRole,
52+ ImagePathRole,
53+ BackgroundPathRole
54+ };
55+
56+ int rowCount(const QModelIndex &parent) const override;
57+ QVariant data(const QModelIndex &index, int role) const override;
58+
59+private:
60+ UsersModelPrivate * const d_ptr;
61+ Q_DECLARE_PRIVATE(UsersModel)
62+};
63+
64+}
65+
66+#endif // UNITY_MOCK_USERSMODEL_H
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cppnew file+41
@@ -0,0 +1,41 @@
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+ */
18+
19+#include "UsersModelPrivate.h"
20+
21+#include <QDir>
22+#include <QSettings>
23+#include <QStringList>
24+
25+namespace QLightDM
26+{
27+
28+UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
29+ : q_ptr(parent)
30+{
31+ QSettings settings(QDir::homePath() + "/.unity8-greeter-demo", QSettings::NativeFormat);
32+ QStringList users = settings.value("users", QStringList() << qgetenv("USER")).toStringList();
33+
34+ Q_FOREACH(const QString &user, users)
35+ {
36+ QString name = settings.value(user + "/name", user[0].toUpper() + user.mid(1)).toString();
37+ entries.append({user, name, 0, 0, false, false, 0, 0});
38+ }
39+}
40+
41+}
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.hnew file+59
@@ -0,0 +1,59 @@
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+ */
18+
19+#ifndef UNITY_MOCK_USERSMODEL_PRIVATE_H
20+#define UNITY_MOCK_USERSMODEL_PRIVATE_H
21+
22+#include <QtCore/QList>
23+#include <QtCore/QString>
24+
25+namespace QLightDM
26+{
27+class UsersModel;
28+
29+class Entry
30+{
31+public:
32+ QString username;
33+ QString real_name;
34+ QString background;
35+ QString layouts;
36+ bool is_active;
37+ bool has_messages;
38+ QString session;
39+ QString infographic;
40+};
41+
42+class UsersModelPrivate
43+{
44+public:
45+ explicit UsersModelPrivate(UsersModel *parent = 0);
46+ virtual ~UsersModelPrivate() = default;
47+
48+ QList<Entry> entries;
49+
50+protected:
51+ UsersModel * const q_ptr;
52+
53+private:
54+ Q_DECLARE_PUBLIC(UsersModel)
55+};
56+
57+}
58+
59+#endif // UNITY_MOCK_USERSMODEL_PRIVATE_H
plugins/LightDM/IntegratedLightDM/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module LightDM.IntegratedLightDM
2+plugin IntegratedLightDM-qml
3+typeinfo IntegratedLightDM.qmltypes