diff options
author | aavit <eirik.aavitsland@digia.com> | 2013-01-31 12:01:54 +0100 |
---|---|---|
committer | aavit <eirik.aavitsland@digia.com> | 2013-02-07 11:53:52 +0100 |
commit | 71b64b2544f81814078f97f0f52bc31c8ce19296 (patch) | |
tree | ff1a5d57c49671121e14e3e684d4b61adfe162fe |
Initial commit - Long live the B2Qt utils!
-rw-r--r-- | .qmake.conf | 1 | ||||
-rw-r--r-- | b2qt-utils.pro | 1 | ||||
-rw-r--r-- | src/imports/imports.pro | 2 | ||||
-rw-r--r-- | src/imports/utils/plugin.cpp | 30 | ||||
-rw-r--r-- | src/imports/utils/qmldir | 3 | ||||
-rw-r--r-- | src/imports/utils/utils.pro | 14 | ||||
-rw-r--r-- | src/src.pro | 5 | ||||
-rw-r--r-- | src/utils/qdroidutils.cpp | 72 | ||||
-rw-r--r-- | src/utils/qdroidutils.h | 28 | ||||
-rw-r--r-- | src/utils/utils.pro | 20 | ||||
-rw-r--r-- | sync.profile | 14 |
11 files changed, 190 insertions, 0 deletions
diff --git a/.qmake.conf b/.qmake.conf new file mode 100644 index 0000000..42ba8e4 --- /dev/null +++ b/.qmake.conf @@ -0,0 +1 @@ +load(qt_build_config) diff --git a/b2qt-utils.pro b/b2qt-utils.pro new file mode 100644 index 0000000..58c33f2 --- /dev/null +++ b/b2qt-utils.pro @@ -0,0 +1 @@ +load(qt_parts) 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 <QtDroidUtils/qdroidutils.h> +#include <QtQml> + +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<QDroidUtils>(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 <cutils/android_reboot.h> +#include <hardware/lights.h> +#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 <qobject.h> + +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 diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..22d148b --- /dev/null +++ b/sync.profile @@ -0,0 +1,14 @@ +%modules = ( # path to module name map + "QtDroidUtils" => "$basedir/src/utils" +); +%moduleheaders = ( # restrict the module headers to those found in relative path +); +# Module dependencies. +# Every module that is required to build this module should have one entry. +# Each of the module version specifiers can take one of the following values: +# - A specific Git revision. +# - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch) +# +%dependencies = ( + "qtbase" => "refs/heads/dev" +); |