Unity 8
plugin.cpp
1 /*
2  * Copyright (C) 2012,2013,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 "plugin.h"
19 #include "DBusGreeter.h"
20 #include "DBusGreeterList.h"
21 #include "Greeter.h"
22 #include "SessionsModel.h"
23 #include "UsersModel.h"
24 #include <libusermetricsoutput/ColorTheme.h>
25 #include <libusermetricsoutput/UserMetrics.h>
26 #include <QLightDM/SessionsModel>
27 #include <QLightDM/UsersModel>
28 
29 #include <QAbstractItemModel>
30 #include <QDBusConnection>
31 #include <QtQml/qqml.h>
32 
33 static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
34 {
35  Q_UNUSED(engine)
36  Q_UNUSED(scriptEngine)
37 
38  Greeter *greeter = new Greeter();
39  new DBusGreeter(greeter, QStringLiteral("/"));
40  new DBusGreeterList(greeter, QStringLiteral("/list"));
41 
42  return greeter;
43 }
44 
45 static QObject *sessions_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
46 {
47  Q_UNUSED(engine)
48  Q_UNUSED(scriptEngine)
49  return new SessionsModel();
50 }
51 
52 static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
53 {
54  Q_UNUSED(engine)
55  Q_UNUSED(scriptEngine)
56  return new UsersModel();
57 }
58 
59 static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
60 {
61  Q_UNUSED(engine)
62  Q_UNUSED(scriptEngine)
63  return UserMetricsOutput::UserMetrics::getInstance();
64 }
65 
66 void PLUGIN_CLASSNAME::registerTypes(const char *uri)
67 {
68  qmlRegisterType<QAbstractItemModel>();
69  qmlRegisterType<UserMetricsOutput::ColorTheme>();
70 
71 #if defined INTEGRATED_LIGHTDM
72  Q_ASSERT(uri == QLatin1String("LightDM.IntegratedLightDM"));
73  qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
74 #elif defined FULL_LIGHTDM
75  Q_ASSERT(uri == QLatin1String("LightDM.FullLightDM"));
76  qmlRegisterSingletonType<QLightDM::Greeter>(uri, 0, 1, "Greeter", greeter_provider);
77 #else
78  #error No library defined in LightDM plugin
79 #endif
80 
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 
87  qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
88  qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", QStringLiteral("Type is not instantiable"));
89 
90  qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
91 }