Unity 8
plugin.cpp
1 /*
2  * Copyright (C) 2014 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: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
17  */
18 
19 #include "plugin.h"
20 #include "Lights.h"
21 #include "HfdLights.h"
22 #include "LegacyLights.h"
23 
24 // libandroid-properties
25 #include <hybris/properties/properties.h>
26 
27 #include <QtQml/qqml.h>
28 
29 static QObject *lights_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
30 {
31  Q_UNUSED(engine)
32  Q_UNUSED(scriptEngine)
33 
34  bool use_hfd = false;
35  char buffer[PROP_VALUE_MAX];
36  auto result = property_get("ro.build.version.sdk", buffer, "0");
37  if (result) {
38  auto sdkVersion = QString(buffer).toInt();
39  if (sdkVersion >= 27 || sdkVersion == 0) {
40  use_hfd = true;
41  }
42  }
43  if (use_hfd) {
44  return new HfdLights();
45  } else {
46  return new LegacyLights();
47  }
48 }
49 
50 void LightsPlugin::registerTypes(const char *uri)
51 {
52  Q_ASSERT(uri == QLatin1String("Lights"));
53  qmlRegisterSingletonType<Lights>(uri, 0, 1, "Lights", lights_provider);
54 }