From 71b64b2544f81814078f97f0f52bc31c8ce19296 Mon Sep 17 00:00:00 2001 From: aavit Date: Thu, 31 Jan 2013 12:01:54 +0100 Subject: Initial commit - Long live the B2Qt utils! --- src/imports/imports.pro | 2 ++ src/imports/utils/plugin.cpp | 30 ++++++++++++++++++ src/imports/utils/qmldir | 3 ++ src/imports/utils/utils.pro | 14 +++++++++ src/src.pro | 5 +++ src/utils/qdroidutils.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++ src/utils/qdroidutils.h | 28 +++++++++++++++++ src/utils/utils.pro | 20 ++++++++++++ 8 files changed, 174 insertions(+) create mode 100644 src/imports/imports.pro create mode 100644 src/imports/utils/plugin.cpp create mode 100644 src/imports/utils/qmldir create mode 100644 src/imports/utils/utils.pro create mode 100644 src/src.pro create mode 100644 src/utils/qdroidutils.cpp create mode 100644 src/utils/qdroidutils.h create mode 100644 src/utils/utils.pro (limited to 'src') diff --git a/src/imports/imports.pro b/src/imports/imports.pro new file mode 100644 index 0000000..92eddcd --- /dev/null +++ b/src/imports/imports.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = utils diff --git a/src/imports/utils/plugin.cpp b/src/imports/utils/plugin.cpp new file mode 100644 index 0000000..4b3f6e1 --- /dev/null +++ b/src/imports/utils/plugin.cpp @@ -0,0 +1,30 @@ +#include +#include + +static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + QDroidUtils *api = new QDroidUtils(); + + return api; +} + +class QDroidUtilsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + QDroidUtilsPlugin() + { + } + + void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == "QtDroid.Utils"); + qmlRegisterSingletonType(uri, 1, 0, "DroidUtils", module_api_factory); + } +}; + +#include "plugin.moc" diff --git a/src/imports/utils/qmldir b/src/imports/utils/qmldir new file mode 100644 index 0000000..6db1b0f --- /dev/null +++ b/src/imports/utils/qmldir @@ -0,0 +1,3 @@ +module QtDroid.Utils +plugin qtdroidutilsplugin +typeinfo plugins.qmltypes diff --git a/src/imports/utils/utils.pro b/src/imports/utils/utils.pro new file mode 100644 index 0000000..a589b46 --- /dev/null +++ b/src/imports/utils/utils.pro @@ -0,0 +1,14 @@ +CXX_MODULE = qml +TARGET = qtdroidutilsplugin +TARGETPATH = QtDroid/Utils +IMPORT_VERSION = 1.0 + +QT += qml + +SOURCES += plugin.cpp + +### kludge +INCLUDEPATH += $$PWD/../../../include +LIBS += -L$$PWD/../../../lib -lQt5DroidUtils + +load(qml_plugin) diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..c9231e6 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +CONFIG += ordered +SUBDIRS += \ + utils \ + imports diff --git a/src/utils/qdroidutils.cpp b/src/utils/qdroidutils.cpp new file mode 100644 index 0000000..4004352 --- /dev/null +++ b/src/utils/qdroidutils.cpp @@ -0,0 +1,72 @@ +#include "qdroidutils.h" + +#ifdef Q_OS_LINUX_ANDROID +#include +#include +#endif + +/*! + * Reboots the system. Does not return. + * + * \sa powerOffSystem() + */ +void QDroidUtils::rebootSystem() +{ +#ifdef Q_OS_LINUX_ANDROID + (void)android_reboot(ANDROID_RB_RESTART, 0, 0); + qFatal("android_reboot returned"); +#else + qDebug("QDroidUtils::rebootSystem()"); +#endif +} + +/*! + * Shuts down the system. Does not return. + * + * \sa rebootSystem() + */ +void QDroidUtils::powerOffSystem() +{ +#ifdef Q_OS_LINUX_ANDROID + (void)android_reboot(ANDROID_RB_POWEROFF, 0, 0); + qFatal("android_reboot returned"); +#else + qDebug("QDroidUtils::powerOffSystem()"); +#endif +} + +/*! + * Sets the display brightness (i.e. the intensity of the backlight) + * to \a value. A value of 255 requests maximum brightness, while 0 requests + * minimum (typically, the backlight turned off). + * + * Returns true on success. + */ +//### TBD: add the user/sensor setting as parameter! +bool QDroidUtils::setDisplayBrightness(quint8 value) +{ +#ifdef Q_OS_LINUX_ANDROID + const struct hw_module_t* module = 0; + if (hw_get_module(LIGHTS_HARDWARE_MODULE_ID, &module)) + return false; + if (!module || !module->methods || !module->methods->open) + return false; + + struct light_device_t* device = 0; + if (module->methods->open(module, LIGHT_ID_BACKLIGHT, (struct hw_device_t**)&device)) + return false; + if (!device || !device->set_light || !device->common.close) + return false; + + struct light_state_t state; + memset(&state, 0, sizeof(light_state_t)); + state.color = 0xff000000 | (value << 16) | (value << 8) | value; + if (!device->set_light(device, &state)) + return false; + + device->common.close(&device->common); +#else + qDebug("QDroidUtils::setDisplayBrightness(%i)", value); +#endif + return true; +} diff --git a/src/utils/qdroidutils.h b/src/utils/qdroidutils.h new file mode 100644 index 0000000..5994ede --- /dev/null +++ b/src/utils/qdroidutils.h @@ -0,0 +1,28 @@ +#ifndef QDROIDUTILS_H +#define QDROIDUTILS_H + +#include + +class Q_DECL_EXPORT QDroidUtils : public QObject +{ + Q_OBJECT +public: + QDroidUtils(QObject* parent = 0) : QObject(parent) + { + } + ~QDroidUtils() + { + } + + //### TBD: make an instance() method, for singleton use from C++ ? + //e.g. connect(myobj, mysig, QDroidUtils::instance(), slot(rebootSystem()); + +public Q_SLOTS: + void rebootSystem(); + void powerOffSystem(); + + bool setDisplayBrightness(quint8 value); + +}; + +#endif // QDROIDUTILS_H diff --git a/src/utils/utils.pro b/src/utils/utils.pro new file mode 100644 index 0000000..c0216b7 --- /dev/null +++ b/src/utils/utils.pro @@ -0,0 +1,20 @@ +TARGET = QtDroidUtils +#VERSION = 1.0.0 +CONFIG += dll warn_on + +QT = core +#QT = core-private gui-private qml-private quick-private +#QT_PRIVATE = v8-private + +#DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES + +MODULE = droidutils +load(qt_module) + +LIBS += -lhardware -lcutils + +HEADERS += \ + $$PWD/qdroidutils.h + +SOURCES += \ + $$PWD/qdroidutils.cpp -- cgit v1.2.3