Unity 8
 All Classes Functions Properties
plugin.cpp
1 /*
2  * Copyright (C) 2012,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  * Authors: Gerry Boland <gerry.boland@canonical.com>
17  * Michael Terry <michael.terry@canonical.com>
18  */
19 
20 #include "plugin.h"
21 #include "DBusGreeterList.h"
22 #include "Greeter.h"
23 #include "UsersModel.h"
24 #include <libusermetricsoutput/ColorTheme.h>
25 #include <libusermetricsoutput/UserMetrics.h>
26 #include <QLightDM/UsersModel>
27 
28 #include <QAbstractItemModel>
29 #include <QDBusConnection>
30 #include <QtQml/qqml.h>
31 
32 static const char* GREETER_LIST_DBUS_PATH = "/list";
33 static const char* GREETER_DBUS_SERVICE = "com.canonical.UnityGreeter";
34 
35 static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
36 {
37  Q_UNUSED(engine)
38  Q_UNUSED(scriptEngine)
39 
40  Greeter *greeter = new Greeter();
41  QDBusConnection connection = QDBusConnection::sessionBus();
42  DBusGreeterList *list = new DBusGreeterList(greeter, connection, GREETER_LIST_DBUS_PATH);
43  connection.registerObject(GREETER_LIST_DBUS_PATH, list, QDBusConnection::ExportScriptableContents);
44  connection.registerService(GREETER_DBUS_SERVICE);
45 
46  return greeter;
47 }
48 
49 static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
50 {
51  Q_UNUSED(engine)
52  Q_UNUSED(scriptEngine)
53  return new UsersModel();
54 }
55 
56 static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
57 {
58  Q_UNUSED(engine)
59  Q_UNUSED(scriptEngine)
60  return UserMetricsOutput::UserMetrics::getInstance();
61 }
62 
63 void LightDMPlugin::registerTypes(const char *uri)
64 {
65  qmlRegisterType<QAbstractItemModel>();
66  qmlRegisterType<UserMetricsOutput::ColorTheme>();
67 
68  Q_ASSERT(uri == QLatin1String("LightDM"));
69  qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
70  qmlRegisterSingletonType<UsersModel>(uri, 0, 1, "Users", users_provider);
71  qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
72  qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
73 }