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 "UsersModel.h"
23 #include <libusermetricsoutput/ColorTheme.h>
24 #include <libusermetricsoutput/UserMetrics.h>
25 #include <QLightDM/UsersModel>
26 
27 #include <QAbstractItemModel>
28 #include <QDBusConnection>
29 #include <QtQml/qqml.h>
30 
31 static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
32 {
33  Q_UNUSED(engine)
34  Q_UNUSED(scriptEngine)
35 
36  Greeter *greeter = new Greeter();
37  new DBusGreeter(greeter, QStringLiteral("/"));
38  new DBusGreeterList(greeter, QStringLiteral("/list"));
39 
40  return greeter;
41 }
42 
43 static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
44 {
45  Q_UNUSED(engine)
46  Q_UNUSED(scriptEngine)
47  return new UsersModel();
48 }
49 
50 static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
51 {
52  Q_UNUSED(engine)
53  Q_UNUSED(scriptEngine)
54  return UserMetricsOutput::UserMetrics::getInstance();
55 }
56 
57 void IntegratedLightDMPlugin::registerTypes(const char *uri)
58 {
59  qmlRegisterType<QAbstractItemModel>();
60  qmlRegisterType<UserMetricsOutput::ColorTheme>();
61 
62  Q_ASSERT(uri == QLatin1String("IntegratedLightDM"));
63  qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
64  qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
65  qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
66  qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
67  qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", QStringLiteral("Type is not instantiable"));
68  qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
69 }