on xenial help sign in
Fix translations
commitd3d16c8c8adf7aed0a689b948dffd924a165e92f authorJosh Arenson <joshua.arenson@canonical.com> dateFri 4 Mar 2016, 13:18 (11 years ago) parent800f2e4fb8862a
29 files changed+970−41
plugins/LightDM/CMakeLists.txt+1−2 plugins/LightDM/FullLightDM/CMakeLists.txt+4−1 plugins/LightDM/Greeter.cpp+7−2 plugins/LightDM/Greeter.h+3−2 plugins/LightDM/IntegratedLightDM/CMakeLists.txt+3−3 plugins/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt+2 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+86 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h+72 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+41 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+54 plugins/LightDM/SessionsModel.cpp+91 plugins/LightDM/SessionsModel.h+68 plugins/LightDM/plugin.cpp+17−7 tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txt+2 tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cpp+37 tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.h+34 tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModel+17 tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt+2 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cpp+1−1 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp+97 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h+72 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp+66 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h+59 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp+21−21 tests/mocks/LightDM/IntegratedLightDM/plugin.cpp+11 tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+23 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+77 tests/qmltests/tst_OrientedShell.qml+1−1 tests/qmltests/tst_Shell.qml+1−1
plugins/LightDM/CMakeLists.txt+1−2
@@ -7,9 +7,7 @@ include_directories(
77 ${CMAKE_CURRENT_SOURCE_DIR}
88 ${CMAKE_CURRENT_BINARY_DIR}
99 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
1110 ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
12− ${LIBLIGHTDM_INCLUDE_DIRS}
1311 ${libunity8-private_SOURCE_DIR}
1412 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
1513)
@@ -20,6 +18,7 @@ set(QMLPLUGIN_SRC
2018 DBusGreeterList.cpp
2119 Greeter.cpp
2220 plugin.cpp
21+ SessionsModel.cpp
2322 UsersModel.cpp
2423 )
2524
plugins/LightDM/FullLightDM/CMakeLists.txt+4−1
@@ -4,7 +4,10 @@ set(PLUGIN_CLASSNAME "FullLightDM")
44
55add_definitions(-DFULL_LIGHTDM)
66
7−include_directories(../)
7+include_directories(
8+ ../
9+ ${LIBLIGHTDM_INCLUDE_DIRS}
10+ )
811
912foreach(source_file ${QMLPLUGIN_SRC})
1013 list(APPEND RELATIVE_QMLPLUGIN_SRC ../${source_file})
plugins/LightDM/Greeter.cpp+7−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -13,7 +13,6 @@
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
16− * Author: Michael Terry <michael.terry@canonical.com>
1716 */
1817
1918#include "Greeter.h"
@@ -72,6 +71,12 @@ QString Greeter::authenticationUser() const
7271 return d->m_greeter->authenticationUser();
7372}
7473
74+QString Greeter::defaultSessionHint() const
75+{
76+ Q_D(const Greeter);
77+ return d->m_greeter->defaultSessionHint();
78+}
79+
7580bool Greeter::promptless() const
7681{
7782 Q_D(const Greeter);
plugins/LightDM/Greeter.h+3−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
2+ * Copyright (C) 2012,2013,2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -13,7 +13,6 @@
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 *
16− * Authors: Michael Terry <michael.terry@canonical.com>
1716 */
1817
1918/* This class is a really tiny filter around QLightDM::Greeter. There are some
@@ -37,6 +36,7 @@ class Greeter : public QObject
3736 Q_PROPERTY(bool active READ isActive WRITE setIsActive NOTIFY isActiveChanged)
3837 Q_PROPERTY(bool authenticated READ isAuthenticated NOTIFY isAuthenticatedChanged)
3938 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
39+ Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
4040 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
4141
4242public:
@@ -45,6 +45,7 @@ public:
4545 bool isActive() const;
4646 bool isAuthenticated() const;
4747 QString authenticationUser() const;
48+ QString defaultSessionHint() const;
4849 bool promptless() const;
4950
5051public Q_SLOTS:
plugins/LightDM/IntegratedLightDM/CMakeLists.txt+3−3
@@ -7,9 +7,9 @@ foreach(include_directory ${QMLPLUGIN_INCLUDES})
77endforeach()
88
99include_directories(
10− ${QMLPLUGIN_INCLUDES}
11− ${libunity8-private_SOURCE_DIR}
12−)
10+ ../
11+ ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
12+ )
1313
1414foreach(source_file ${QMLPLUGIN_SRC})
1515 list(APPEND RELATIVE_QMLPLUGIN_SRC ../${source_file})
plugins/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt+2
@@ -2,8 +2,10 @@ pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
22
33set(LibLightDM_SOURCES
44 Greeter.cpp
5+ SessionsModel.cpp
56 UsersModel.cpp
67 GreeterPrivate.cpp
8+ SessionsModelPrivate.cpp
79 UsersModelPrivate.cpp
810 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
911 )
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cppnew file+86
@@ -0,0 +1,86 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+
19+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
21+ * COUNTERPART IN tests/mocks/LightDM/IntegratedLightDM/liblightdm
22+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
23+
24+// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
25+// To use the same method of setting role name that it does, we
26+// set our compatibility to Qt4 here too.
27+#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
28+
29+#include "SessionsModel.h"
30+#include "SessionsModelPrivate.h"
31+#include <QtCore/QDir>
32+#include <QtCore/QString>
33+
34+namespace QLightDM
35+{
36+
37+SessionsModel::SessionsModel(QObject* parent) :
38+ QAbstractListModel(parent),
39+ d_ptr(new SessionsModelPrivate(this))
40+{
41+ Q_D(SessionsModel);
42+ m_roleNames = QAbstractListModel::roleNames();
43+ m_roleNames[KeyRole] = "key";
44+ m_roleNames[TypeRole] = "type";
45+}
46+
47+SessionsModel::~SessionsModel()
48+{
49+ delete d_ptr;
50+}
51+
52+QVariant SessionsModel::data(const QModelIndex& index, int role) const
53+{
54+ Q_D(const SessionsModel);
55+
56+ if(!index.isValid()) {
57+ return QVariant();
58+ }
59+
60+ int row = index.row();
61+
62+ switch (role) {
63+ case Qt::DisplayRole:
64+ return d->sessionItems[row].name;
65+ default:
66+ return QVariant();
67+ }
68+}
69+
70+QHash<int, QByteArray> SessionsModel::roleNames() const
71+{
72+ return m_roleNames;
73+}
74+
75+int SessionsModel::rowCount(const QModelIndex& parent) const
76+{
77+ Q_D(const SessionsModel);
78+
79+ if (parent.isValid()) {
80+ return 0;
81+ } else { // parent is root
82+ return d->sessionItems.size();
83+ }
84+}
85+
86+} // namespace QLightDM
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.hnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef UNITY_INTEGRATED_SESSIONSMODEL_H
19+#define UNITY_INTEGRATED_SESSIONSMODEL_H
20+
21+#include <QtCore/QAbstractListModel>
22+#include <QtCore/QString>
23+
24+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25+ * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
26+ * COUNTERPART IN tests/mocks/LightDM/IntegratedLightDM/liblightdm
27+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
28+
29+// This is taken from liblightdm and modified to confirm to our syle conventions
30+namespace QLightDM
31+{
32+class SessionsModelPrivate;
33+
34+class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
35+ {
36+ Q_OBJECT
37+
38+ Q_ENUMS(SessionModelRoles SessionType)
39+
40+ public:
41+
42+ enum SessionModelRoles {
43+ //name is exposed as Qt::DisplayRole
44+ //comment is exposed as Qt::TooltipRole
45+ KeyRole = Qt::UserRole,
46+ IdRole = KeyRole, /** Deprecated */
47+ TypeRole
48+ };
49+
50+ enum SessionType {
51+ LocalSessions,
52+ RemoteSessions
53+ };
54+
55+ explicit SessionsModel(QObject* parent=0); /** Deprecated. Loads local sessions*/
56+ explicit SessionsModel(SessionsModel::SessionType, QObject* parent=0);
57+ virtual ~SessionsModel();
58+
59+ QHash<int, QByteArray> roleNames() const override;
60+ int rowCount(const QModelIndex& parent) const override;
61+ QVariant data(const QModelIndex& index, int role) const override;
62+
63+ protected:
64+ SessionsModelPrivate* const d_ptr;
65+
66+ private:
67+ QHash<int, QByteArray> m_roleNames;
68+ Q_DECLARE_PRIVATE(SessionsModel)
69+ };
70+}
71+
72+#endif // UNITY_INTEGRATED_SESSIONSMODEL_H
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cppnew file+41
@@ -0,0 +1,41 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#include "SessionsModelPrivate.h"
19+
20+#include <QDir>
21+#include <QSettings>
22+#include <QStringList>
23+
24+namespace QLightDM
25+{
26+
27+SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
28+ : q_ptr(parent)
29+{
30+ QSettings settings(QDir::homePath() + "/.unity8-greeter-demo", QSettings::NativeFormat);
31+ const QStringList sessions = settings.value(QStringLiteral("sessions"), QStringList() << qgetenv("DESKTOP_SESSION")).toStringList();
32+
33+ sessionItems.reserve(sessions.count());
34+ Q_FOREACH(const QString& session, sessions)
35+ {
36+ sessionItems.append({"", "", session, ""});
37+ }
38+
39+}
40+
41+} // namespace QLightDM
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.hnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
19+#define UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
20+
21+#include <QtCore/QList>
22+#include <QtCore/QString>
23+
24+namespace QLightDM
25+{
26+class SessionsModel;
27+
28+class SessionItem
29+{
30+public:
31+ QString key; // unused
32+ QString type; // unused
33+ QString name;
34+ QString comment; // unused
35+};
36+
37+class SessionsModelPrivate
38+{
39+public:
40+ explicit SessionsModelPrivate(SessionsModel* parent=0);
41+ virtual ~SessionsModelPrivate() = default;
42+
43+ QList<SessionItem> sessionItems;
44+
45+protected:
46+ SessionsModel* const q_ptr;
47+
48+private:
49+ Q_DECLARE_PUBLIC(SessionsModel)
50+};
51+
52+} // namespace QLightDM
53+
54+#endif // UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
plugins/LightDM/SessionsModel.cppnew file+91
@@ -0,0 +1,91 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#include "SessionsModel.h"
19+#include <QtCore/QFile>
20+#include <QtCore/QSortFilterProxyModel>
21+
22+QHash<int, QByteArray> SessionsModel::roleNames() const
23+{
24+ return m_roleNames;
25+}
26+
27+int SessionsModel::rowCount(const QModelIndex& parent) const
28+{
29+ return m_model->rowCount(parent);
30+}
31+
32+QList<QUrl> SessionsModel::iconSearchDirectories() const
33+{
34+ return m_iconSearchDirectories;
35+}
36+
37+void SessionsModel::setIconSearchDirectories(const QList<QUrl> searchDirectories)
38+{
39+ // QML gives us a url with file:// prepended which breaks QFile::exists()
40+ // so convert the url to a local file
41+ QList<QUrl> localList = {};
42+ Q_FOREACH(const QUrl& searchDirectory, searchDirectories)
43+ {
44+ localList.append(searchDirectory.toLocalFile());
45+ }
46+ m_iconSearchDirectories = localList;
47+ Q_EMIT iconSearchDirectoriesChanged();
48+}
49+
50+QUrl SessionsModel::iconUrl(const QString sessionName) const
51+{
52+ Q_FOREACH(const QUrl& searchDirectory, m_iconSearchDirectories)
53+ {
54+ // This is an established icon naming convention
55+ QString iconUrl = searchDirectory.toString(QUrl::StripTrailingSlash) +
56+ "/" + sessionName.toLower() + "_badge.png";
57+ QFile iconFile(iconUrl);
58+ if (iconFile.exists()) {
59+ return QUrl(iconUrl);
60+ }
61+ }
62+
63+ // FIXME make this smarter
64+ return QUrl("./graphics/session_icons/unknown_badge.png");
65+}
66+
67+QVariant SessionsModel::data(const QModelIndex& index, int role) const
68+{
69+ switch (role) {
70+ case SessionsModel::IconRole:
71+ return iconUrl(m_model->data(index, Qt::DisplayRole).toString());
72+ default:
73+ return m_model->data(index, role);
74+ }
75+}
76+
77+SessionsModel::SessionsModel(QObject* parent)
78+ : UnitySortFilterProxyModelQML(parent)
79+{
80+ // Add a custom IconRole that isn't in either of the lightdm implementations
81+ m_model = new QLightDM::SessionsModel(this);
82+ m_roleNames = m_model->roleNames();
83+ m_roleNames[IconRole] = "icon_url";
84+
85+ setModel(m_model);
86+ setSourceModel(m_model);
87+ setSortCaseSensitivity(Qt::CaseInsensitive);
88+ setSortLocaleAware(true);
89+ setSortRole(Qt::DisplayRole);
90+ sort(0);
91+}
plugins/LightDM/SessionsModel.hnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef UNITY_SESSIONSMODEL_H
19+#define UNITY_SESSIONSMODEL_H
20+
21+#include <unitysortfilterproxymodelqml.h>
22+#include <QLightDM/SessionsModel>
23+#include <QtCore/QHash>
24+#include <QtCore/QObject>
25+#include <QtCore/QUrl>
26+
27+class SessionsModel : public UnitySortFilterProxyModelQML
28+{
29+ Q_OBJECT
30+
31+ Q_ENUMS(SessionModelRoles)
32+
33+ Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
34+ WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
35+Q_SIGNALS:
36+ void iconSearchDirectoriesChanged();
37+
38+public:
39+ enum SessionModelRoles {
40+ /* This is tricky / ugly. Since we are ultimately chaining 3 enums together,
41+ * the _first_ value of this enum MUST be the _last_ value of
42+ * QLightDM::SessionsModel::SessionModelRoles and consquently, this must
43+ * also match the last value in the corresponding enum of the integrated lib
44+ */
45+ TypeRole = QLightDM::SessionsModel::SessionModelRoles::TypeRole,
46+ IconRole
47+ };
48+
49+ explicit SessionsModel(QObject* parent=nullptr);
50+
51+ QHash<int, QByteArray> roleNames() const override;
52+ int rowCount(const QModelIndex& parent) const override;
53+ QVariant data(const QModelIndex& index, int role) const override;
54+ QList<QUrl> iconSearchDirectories() const;
55+ Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
56+
57+ void setIconSearchDirectories(const QList<QUrl> searchDirectories);
58+private:
59+ QLightDM::SessionsModel* m_model;
60+ QHash<int, QByteArray> m_roleNames;
61+ QList<QUrl> m_iconSearchDirectories{
62+ QUrl("/usr/share/unity8/Greeter/graphics/session_icons"),
63+ QUrl("/usr/local/share/unity-greeter"),
64+ QUrl("/usr/share/unity-greeter/")};
65+
66+};
67+
68+#endif // UNITY_SESSIONSMODEL_H
plugins/LightDM/plugin.cpp+17−7
@@ -19,9 +19,11 @@
1919#include "DBusGreeter.h"
2020#include "DBusGreeterList.h"
2121#include "Greeter.h"
22+#include "SessionsModel.h"
2223#include "UsersModel.h"
2324#include <libusermetricsoutput/ColorTheme.h>
2425#include <libusermetricsoutput/UserMetrics.h>
26+#include <QLightDM/SessionsModel>
2527#include <QLightDM/UsersModel>
2628
2729#include <QAbstractItemModel>
@@ -40,6 +42,13 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
4042 return greeter;
4143}
4244
45+static QObject *sessions_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
46+{
47+ Q_UNUSED(engine)
48+ Q_UNUSED(scriptEngine)
49+ return new SessionsModel();
50+}
51+
4352static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
4453{
4554 Q_UNUSED(engine)
@@ -61,21 +70,22 @@ void PLUGIN_CLASSNAME::registerTypes(const char *uri)
6170
6271#if defined INTEGRATED_LIGHTDM
6372 Q_ASSERT(uri == QLatin1String("LightDM.IntegratedLightDM"));
64−#elif defined FULL_LIGHTDM
65− Q_ASSERT(uri == QLatin1String("LightDM.FullLightDM"));
66−#endif
67− qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
68− qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
69−
70−#if defined INTEGRATED_LIGHTDM
7173 qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
7274#elif defined FULL_LIGHTDM
75+ Q_ASSERT(uri == QLatin1String("LightDM.FullLightDM"));
7376 qmlRegisterSingletonType<QLightDM::Greeter>(uri, 0, 1, "Greeter", greeter_provider);
7477#else
7578 #error No library defined in LightDM plugin
7679#endif
7780
81+ qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
82+ qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
83+
84+ qmlRegisterSingletonType<SessionsModel>(uri, 0, 1, "Sessions", sessions_provider);
85+ qmlRegisterUncreatableType<SessionsModel>(uri, 0, 1, "SessionRoles", QStringLiteral("Type is not instantiable"));
86+
7887 qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
7988 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", QStringLiteral("Type is not instantiable"));
89+
8090 qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
8191}
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txt+2
@@ -19,9 +19,11 @@ set(QMLPLUGIN_SRC
1919 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
2020 ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
2121 ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
22+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
2223 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
2324 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
2425 MockGreeter.cpp
26+ MockSessionsModel.cpp
2527 MockUsersModel.cpp
2628 plugin.cpp
2729 )
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cppnew file+37
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#include "MockSessionsModel.h"
19+#include <QLightDM/SessionsModel>
20+
21+QString MockSessionsModel::testScenario() const
22+{
23+ QLightDM::SessionsModel* qSessionsModel =
24+ static_cast<QLightDM::SessionsModel*>(sourceModel());
25+
26+ return qSessionsModel->testScenario();
27+}
28+
29+void MockSessionsModel::setTestScenario(const QString testScenario)
30+{
31+ QLightDM::SessionsModel* qSessionsModel =
32+ static_cast<QLightDM::SessionsModel*>(sourceModel());
33+
34+ if (qSessionsModel->testScenario() != testScenario) {
35+ qSessionsModel->setTestScenario(testScenario);
36+ }
37+}
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.hnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef MOCK_UNITY_SESSIONSMODEL_H
19+#define MOCK_UNITY_SESSIONSMODEL_H
20+
21+#include <SessionsModel.h>
22+
23+class MockSessionsModel : public SessionsModel
24+{
25+ Q_OBJECT
26+
27+ Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario)
28+
29+public:
30+ QString testScenario() const;
31+ void setTestScenario(QString testScenario);
32+};
33+
34+#endif // MOCK_UNITY_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModelnew file+17
@@ -0,0 +1,17 @@
1+/*
2+ * Copyright (C) 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+
17+#include "../liblightdm/SessionsModel.h"
tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt+2
@@ -1,7 +1,9 @@
11set(LibLightDM_SOURCES
22 Greeter.cpp
3+ SessionsModel.cpp
34 UsersModel.cpp
45 GreeterPrivate.cpp
6+ SessionsModelPrivate.cpp
57 UsersModelPrivate.cpp
68 ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
79 )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cpp+1−1
@@ -51,7 +51,7 @@ QString Greeter::getHint(const QString &name) const
5151
5252QString Greeter::defaultSessionHint() const
5353{
54− return "ubuntu";
54+ return QStringLiteral("ubuntu");
5555}
5656
5757bool Greeter::hideUsersHint() const
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cppnew file+97
@@ -0,0 +1,97 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+
19+// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20+// To use the same method of setting role name that it does, we
21+// set our compatibility to Qt4 here too.
22+#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23+
24+#include "SessionsModel.h"
25+#include "SessionsModelPrivate.h"
26+#include <QtCore/QDir>
27+#include <QtCore/QString>
28+
29+namespace QLightDM
30+{
31+
32+SessionsModel::SessionsModel(QObject* parent) :
33+ QAbstractListModel(parent),
34+ d_ptr(new SessionsModelPrivate(this))
35+{
36+ Q_D(SessionsModel);
37+ m_roleNames = QAbstractListModel::roleNames();
38+ m_roleNames[KeyRole] = "key";
39+ m_roleNames[TypeRole] = "type";
40+}
41+
42+SessionsModel::~SessionsModel()
43+{
44+ delete d_ptr;
45+}
46+
47+QVariant SessionsModel::data(const QModelIndex& index, int role) const
48+{
49+ Q_D(const SessionsModel);
50+
51+ if(!index.isValid()) {
52+ return QVariant();
53+ }
54+
55+ int row = index.row();
56+
57+ switch (role) {
58+ case Qt::DisplayRole:
59+ return d->sessionItems[row].name;
60+ default:
61+ return QVariant();
62+ }
63+}
64+
65+QHash<int, QByteArray> SessionsModel::roleNames() const
66+{
67+ return m_roleNames;
68+}
69+
70+int SessionsModel::rowCount(const QModelIndex& parent) const
71+{
72+ Q_D(const SessionsModel);
73+
74+ if (parent.isValid()) {
75+ return 0;
76+ } else { // parent is root
77+ return d->sessionItems.size();
78+ }
79+}
80+
81+QString SessionsModel::testScenario() const
82+{
83+ Q_D(const SessionsModel);
84+ return d->testScenario;
85+}
86+
87+void SessionsModel::setTestScenario(QString testScenario)
88+{
89+ Q_D(SessionsModel);
90+
91+ if (d->testScenario != testScenario) {
92+ d->testScenario = testScenario;
93+ d->resetEntries();
94+ }
95+}
96+
97+} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.hnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef UNITY_MOCK_SESSIONSMODEL_H
19+#define UNITY_MOCK_SESSIONSMODEL_H
20+
21+#include <QtCore/QAbstractListModel>
22+#include <QtCore/QString>
23+
24+namespace QLightDM
25+{
26+class SessionsModelPrivate;
27+
28+class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
29+ {
30+ Q_OBJECT
31+
32+ Q_ENUMS(SessionModelRoles SessionType)
33+
34+ // Mock-only API for testing purposes
35+ Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario)
36+
37+ public:
38+
39+ enum SessionModelRoles {
40+ //name is exposed as Qt::DisplayRole
41+ //comment is exposed as Qt::TooltipRole
42+ KeyRole = Qt::UserRole,
43+ IdRole = KeyRole, /** Deprecated */
44+ TypeRole
45+ };
46+
47+ enum SessionType {
48+ LocalSessions,
49+ RemoteSessions
50+ };
51+
52+ explicit SessionsModel(QObject* parent=nullptr); /** Deprecated. Loads local sessions*/
53+ explicit SessionsModel(SessionsModel::SessionType, QObject* parent=nullptr);
54+ virtual ~SessionsModel();
55+
56+ QHash<int, QByteArray> roleNames() const override;
57+ int rowCount(const QModelIndex& parent) const override;
58+ QVariant data(const QModelIndex& index, int role) const override;
59+
60+ QString testScenario() const;
61+ void setTestScenario(QString testScenario);
62+
63+ protected:
64+ SessionsModelPrivate* const d_ptr;
65+
66+ private:
67+ QHash<int, QByteArray> m_roleNames;
68+ Q_DECLARE_PRIVATE(SessionsModel)
69+ };
70+}
71+
72+#endif // UNITY_MOCK_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cppnew file+66
@@ -0,0 +1,66 @@
1+/*
2+ * Copyright (C) 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+
17+#include "SessionsModel.h"
18+#include "SessionsModelPrivate.h"
19+
20+namespace QLightDM
21+{
22+
23+SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
24+ : testScenario("singleSession")
25+ , q_ptr(parent)
26+{
27+ resetEntries();
28+}
29+
30+void SessionsModelPrivate::resetEntries()
31+{
32+ Q_Q(SessionsModel);
33+
34+ q->beginResetModel();
35+ if (testScenario == "multipleSessions") {
36+ resetEntries_multipleSessions();
37+ } else if (testScenario == "noSessions") {
38+ resetEntries_noSessions();
39+ } else {
40+ resetEntries_singleSession();
41+ }
42+ q->endResetModel();
43+}
44+
45+void SessionsModelPrivate::resetEntries_multipleSessions()
46+{
47+ sessionItems =
48+ {
49+ {"", "", "Ubuntu", ""},
50+ {"", "", "GNOME", ""},
51+ {"", "", "Plasma", ""},
52+ {"", "", "Unknown?", ""}
53+ };
54+}
55+
56+void SessionsModelPrivate::resetEntries_noSessions()
57+{
58+ sessionItems = {};
59+}
60+
61+void SessionsModelPrivate::resetEntries_singleSession()
62+{
63+ sessionItems = {{"", "", "Ubuntu", ""}};
64+}
65+
66+} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.hnew file+59
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright (C) 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+ */
17+
18+#ifndef UNITY_MOCK_SESSIONSMODEL_PRIVATE_H
19+#define UNITY_MOCK_SESSIONSMODEL_PRIVATE_H
20+
21+#include <QtCore/QList>
22+#include <QtCore/QString>
23+
24+namespace QLightDM
25+{
26+class SessionsModel;
27+
28+class SessionItem
29+{
30+public:
31+ QString key; // unused
32+ QString type; // unused
33+ QString name;
34+ QString comment; // unused
35+};
36+
37+class SessionsModelPrivate
38+{
39+public:
40+ explicit SessionsModelPrivate(SessionsModel* parent=0);
41+ virtual ~SessionsModelPrivate() = default;
42+
43+ QList<SessionItem> sessionItems;
44+ QString testScenario;
45+
46+ void resetEntries();
47+protected:
48+ SessionsModel* const q_ptr;
49+
50+private:
51+ void resetEntries_multipleSessions();
52+ void resetEntries_noSessions();
53+ void resetEntries_singleSession();
54+ Q_DECLARE_PUBLIC(SessionsModel)
55+};
56+
57+} // namespace QLightDM
58+
59+#endif // UNITY_MOCK_SESSIONSMODEL_PRIVATE_H
tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp+21−21
@@ -54,7 +54,7 @@ void UsersModelPrivate::resetEntries_single()
5454{
5555 entries =
5656 {
57− { "single", "Single User", 0, 0, false, false, 0, 0 },
57+ { "single", "Single User", 0, 0, false, false, "Ubuntu", 0 },
5858 };
5959}
6060
@@ -62,7 +62,7 @@ void UsersModelPrivate::resetEntries_singlePassphrase()
6262{
6363 entries =
6464 {
65− { "single", "Single User", 0, 0, false, false, 0, 0 },
65+ { "single", "Single User", 0, 0, false, false, "Ubuntu", 0 },
6666 };
6767}
6868
@@ -78,26 +78,26 @@ void UsersModelPrivate::resetEntries_full()
7878{
7979 entries =
8080 {
81− { "has-password", "Has Password", 0, 0, false, false, 0, 0 },
82− { "has-pin", "Has PIN", 0, 0, false, false, 0, 0 },
83− { "different-prompt", "Different Prompt", 0, 0, false, false, 0, 0 },
84− { "no-password", "No Password", 0, 0, false, false, 0, 0 },
85− { "auth-error", "Auth Error", 0, 0, false, false, 0, 0 },
86− { "two-factor", "Two Factor", 0, 0, false, false, 0, 0 },
87− { "info-prompt", "Info Prompt", 0, 0, false, false, 0, 0 },
88− { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, 0, 0 },
89− { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, 0, 0 },
90− { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, 0, 0 },
91− { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, 0, 0 },
92− { "long-name", "Long name (far far too long to fit)", 0, 0, false, false, 0, 0 },
93− { "color-background", "Color Background", "#dd4814", 0, false, false, 0, 0 },
81+ { "has-password", "Has Password", 0, 0, false, false, "Ubuntu", 0 },
82+ { "has-pin", "Has PIN", 0, 0, false, false, "Ubuntu", 0 },
83+ { "different-prompt", "Different Prompt", 0, 0, false, false, "Ubuntu", 0 },
84+ { "no-password", "No Password", 0, 0, false, false, "Ubuntu", 0 },
85+ { "auth-error", "Auth Error", 0, 0, false, false, "Ubuntu", 0 },
86+ { "two-factor", "Two Factor", 0, 0, false, false, "Ubuntu", 0 },
87+ { "info-prompt", "Info Prompt", 0, 0, false, false, "Ubuntu", 0 },
88+ { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "Ubuntu", 0 },
89+ { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "Ubuntu", 0 },
90+ { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "Ubuntu", 0 },
91+ { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "Ububntu", 0 },
92+ { "long-name", "Long name (far far too long to fit)", 0, 0, false, false, "Ubuntu", 0 },
93+ { "color-background", "Color Background", "#dd4814", 0, false, false, "Ubuntu", 0 },
9494 // white and black are a bit redundant, but useful for manually testing if UI is still readable
95− { "white-background", "White Background", "#ffffff", 0, false, false, 0, 0 },
96− { "black-background", "Black Background", "#000000", 0, false, false, 0, 0 },
97− { "no-background", "No Background", "", 0, false, false, 0, 0 },
98− { "unicode", "가나다라마", 0, 0, false, false, 0, 0 },
99− { "no-response", "No Response", 0, 0, false, false, 0, 0 },
100− { "empty-name", "", 0, 0, false, false, 0, 0 },
95+ { "white-background", "White Background", "#ffffff", 0, false, false, "Ubuntu", 0 },
96+ { "black-background", "Black Background", "#000000", 0, false, false, "Ubuntu", 0 },
97+ { "no-background", "No Background", "", 0, false, false, "Ubuntu", 0 },
98+ { "unicode", "가나다라마", 0, 0, false, false, "Ubuntu", 0 },
99+ { "no-response", "No Response", 0, 0, false, false, "Ubuntu", 0 },
100+ { "empty-name", "", 0, 0, false, false, "Ubuntu", 0 },
101101 };
102102}
103103
tests/mocks/LightDM/IntegratedLightDM/plugin.cpp+11
@@ -18,7 +18,9 @@
1818#include <DBusGreeter.h>
1919#include <DBusGreeterList.h>
2020#include "MockGreeter.h"
21+#include "MockSessionsModel.h"
2122#include "MockUsersModel.h"
23+#include <QLightDM/SessionsModel>
2224#include "ColorTheme.h"
2325#include "UserMetrics.h"
2426#include <QLightDM/UsersModel>
@@ -39,6 +41,13 @@ static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3941 return greeter;
4042}
4143
44+static QObject *sessions_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
45+{
46+ Q_UNUSED(engine)
47+ Q_UNUSED(scriptEngine)
48+ return new MockSessionsModel;
49+}
50+
4251static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
4352{
4453 Q_UNUSED(engine)
@@ -62,6 +71,8 @@ void LightDMPlugin::registerTypes(const char *uri)
6271 qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
6372 qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
6473 qmlRegisterSingletonType<MockGreeter>(uri, 0, 1, "Greeter", greeter_provider);
74+ qmlRegisterSingletonType<MockSessionsModel>(uri, 0, 1, "Sessions", sessions_provider);
75+ qmlRegisterUncreatableType<SessionsModel>(uri, 0, 1, "SessionRoles", "Type is not instantiable");
6576 qmlRegisterSingletonType<MockUsersModel>(uri, 0, 1, "Users", users_provider);
6677 qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
6778 qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+23
@@ -43,6 +43,29 @@ target_include_directories(GreeterPamTestExec PUBLIC
4343 )
4444add_qmltest_target(testGreeterPam GreeterPamTestExec COMMAND $<TARGET_FILE:GreeterPamTestExec>)
4545
46+# SessionsModelTest
47+add_executable(GreeterSessionsModelTestExec
48+ sessionsmodel.cpp
49+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
50+ ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
51+ )
52+add_dependencies(GreeterSessionsModelTestExec MockLightDM)
53+qt5_use_modules(GreeterSessionsModelTestExec Core Test)
54+target_link_libraries(GreeterSessionsModelTestExec
55+ MockLightDM
56+ )
57+target_include_directories(GreeterSessionsModelTestExec PUBLIC
58+ ${CMAKE_SOURCE_DIR}/plugins/LightDM
59+ ${CMAKE_SOURCE_DIR}/plugins/Utils
60+ ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
61+ )
62+add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
63+ ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
64+ DEPENDS MockLightDM
65+ LIGHTDM
66+ )
67+
68+# UsersModelTest
4669add_executable(GreeterUsersModelTestExec
4770 usersmodel.cpp
4871 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cppnew file+77
@@ -0,0 +1,77 @@
1+/*
2+ * Copyright (C) 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+
17+#include "SessionsModel.h"
18+
19+#include <QLightDM/SessionsModel>
20+#include <QtCore/QModelIndex>
21+#include <QtTest>
22+#include <QString>
23+
24+class GreeterSessionsModelTest : public QObject
25+{
26+ Q_OBJECT
27+
28+private Q_SLOTS:
29+
30+ void init()
31+ {
32+ model = new SessionsModel();
33+ QVERIFY(model);
34+ sourceModel = new QLightDM::SessionsModel();
35+ QVERIFY(sourceModel);
36+ }
37+
38+ void cleanup()
39+ {
40+ delete model;
41+ delete sourceModel;
42+ }
43+
44+ void testIconDirectoriesAreValid()
45+ {
46+ Q_FOREACH(const QUrl& searchDirectory, model->iconSearchDirectories())
47+ {
48+ QVERIFY(searchDirectory.isValid());
49+ }
50+ }
51+
52+ void testMultipleSessionsCountIsCorrect()
53+ {
54+ sourceModel->setTestScenario("multipleSessions");
55+ QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
56+ }
57+
58+ void testNoSessionsCountIsCorrect()
59+ {
60+ sourceModel->setTestScenario("noSessions");
61+ QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
62+ }
63+
64+ void testSingleSessionCountIsCorrect()
65+ {
66+ sourceModel->setTestScenario("singleSession");
67+ QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
68+ }
69+
70+private:
71+ SessionsModel *model;
72+ QLightDM::SessionsModel *sourceModel;
73+};
74+
75+QTEST_MAIN(GreeterSessionsModelTest)
76+
77+#include "sessionsmodel.moc"
tests/qmltests/tst_OrientedShell.qml+1−1
@@ -21,7 +21,7 @@ import Ubuntu.Components 1.3
2121import Ubuntu.Components.ListItems 1.3 as ListItem
2222import Unity.Application 0.1
2323import Unity.Test 0.1
24−import LightDM.IntegratedLightDM 0.1 as LightDM
24+import IntegratedLightDM 0.1 as LightDM
2525import Powerd 0.1
2626import Unity.InputInfo 0.1
2727
tests/qmltests/tst_Shell.qml+1−1
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
2020import GSettings 1.0
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import IntegratedLightDM 0.1 as LightDM
2222import Ubuntu.Components 1.3
2323import Ubuntu.Components.ListItems 1.3 as ListItem
2424import Ubuntu.Telephony 0.1 as Telephony