mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
add 'ensure-permissions' for android; revisions
This commit is contained in:
parent
8929b6f60f
commit
60d4a08a8c
12 changed files with 121 additions and 37 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -8,6 +8,8 @@ _*
|
|||
*.o
|
||||
*.obj
|
||||
*.so*
|
||||
*.dylib
|
||||
*.dll
|
||||
*.qm
|
||||
*.stash
|
||||
*.ts
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "lib.h"
|
||||
#include "../../src/cpp/ecl_fun_plugin.h"
|
||||
#include "../../src/cpp/ecl_fun_plugin.h" // for ecl_fun(); independent from LQML
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QtDebug>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@
|
|||
(my-qt-function *c++* x y) ; call from Lisp
|
||||
|
||||
|
||||
<b>ensure-permissions (permission/permissions)</b>
|
||||
|
||||
Android only; requests the passed permission, or a list of them.
|
||||
Returns the permission if it was granted, or a list of the granted
|
||||
permissions.
|
||||
|
||||
(ensure-permissions "android.permission.ACCESS_FINE_LOCATION")
|
||||
|
||||
|
||||
<b>find-quick-item (object-name)</b>
|
||||
|
||||
Finds the first QQuickItem matching OBJECT-NAME. Locally set *ROOT-ITEM* if
|
||||
|
|
|
|||
|
|
@ -74,4 +74,3 @@
|
|||
:info #.(read-file "txt/neptune.txt"))))
|
||||
|
||||
(populate-item-model)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@
|
|||
#include <QQmlExpression>
|
||||
#include <QQmlProperty>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QtAndroid>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
void iniCLFunctions() {
|
||||
|
|
@ -21,6 +25,7 @@ void iniCLFunctions() {
|
|||
cl_make_package(1, qml);
|
||||
}
|
||||
si_select_package(qml);
|
||||
DEFUN ("%ensure-permissions", ensure_permissions2, 1)
|
||||
DEFUN ("%js", js2, 2)
|
||||
DEFUN ("pixel-ratio", pixel_ratio, 0)
|
||||
DEFUN ("%qapropos", qapropos2, 3)
|
||||
|
|
@ -547,6 +552,46 @@ cl_object reload2() {
|
|||
ecl_return1(ecl_process_env(), l_ret);
|
||||
}
|
||||
|
||||
cl_object ensure_permissions2(cl_object l_permissions) {
|
||||
/// args: (permission/permissions)
|
||||
/// Android only; requests the passed permission, or a list of them.
|
||||
/// Returns the permission if it was granted, or a list of the granted
|
||||
/// permissions.
|
||||
/// (ensure-permissions "android.permission.ACCESS_FINE_LOCATION")
|
||||
cl_object l_ret = ECL_T;
|
||||
#if (defined Q_OS_ANDROID) && (QT_VERSION > 0x050A00) // 5.10
|
||||
QStringList permissions(toQStringList(l_permissions));
|
||||
QStringList denied;
|
||||
QStringList granted;
|
||||
Q_FOREACH (QString p, permissions) {
|
||||
if (QtAndroid::checkPermission(p) == QtAndroid::PermissionResult::Granted) {
|
||||
granted << p;
|
||||
} else {
|
||||
denied << p;
|
||||
}
|
||||
}
|
||||
if (!denied.isEmpty()) {
|
||||
QEventLoop loop; // custom sync because requestPermissionsSync() may hang
|
||||
QtAndroid::requestPermissions(denied, [&](const QtAndroid::PermissionResultMap& res) {
|
||||
Q_FOREACH (QString p, denied) {
|
||||
if (res[p] == QtAndroid::PermissionResult::Granted) {
|
||||
granted << p;
|
||||
}
|
||||
}
|
||||
loop.exit();
|
||||
});
|
||||
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
if (granted.length() == 1) {
|
||||
l_ret = from_qstring(granted.first());
|
||||
}
|
||||
else {
|
||||
l_ret = from_qstringlist(granted);
|
||||
}
|
||||
#endif
|
||||
ecl_return1(ecl_process_env(), l_ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// *** meta info ***
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
|
|||
#define LIST10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
|
||||
CONS(a1, LIST9(a2, a3, a4, a5, a6, a7, a8, a9, a10))
|
||||
|
||||
cl_object ensure_permissions2 (cl_object);
|
||||
cl_object js2 (cl_object, cl_object);
|
||||
cl_object pixel_ratio ();
|
||||
cl_object qapropos2 (cl_object, cl_object, cl_object);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// all-in-on-header to include in Qt plugin source files which want to call
|
||||
// all-in-one header to include in Qt plugin source files which want to call
|
||||
// ECL functions through 'ecl_fun()'
|
||||
//
|
||||
// does not depend on LQML
|
||||
|
|
|
|||
|
|
@ -124,6 +124,18 @@ QString toQString(cl_object l_str) {
|
|||
return s;
|
||||
}
|
||||
|
||||
QStringList toQStringList(cl_object l_list) {
|
||||
QStringList l;
|
||||
if (ECL_LISTP(l_list)) {
|
||||
cl_object l_el = l_list;
|
||||
while (l_el != ECL_NIL) {
|
||||
l << toQString(cl_car(l_el));
|
||||
l_el = cl_cdr(l_el);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
TO_QT_FLOAT_2 (QPointF)
|
||||
TO_QT_FLOAT_2 (QSizeF)
|
||||
TO_QT_FLOAT_4 (QRectF)
|
||||
|
|
@ -246,6 +258,15 @@ cl_object from_qstring(const QString& s) {
|
|||
return l_s;
|
||||
}
|
||||
|
||||
cl_object from_qstringlist(const QStringList& l) {
|
||||
cl_object l_list = ECL_NIL;
|
||||
Q_FOREACH (QString s, l) {
|
||||
l_list = CONS(from_qstring(s), l_list);
|
||||
}
|
||||
l_list = cl_nreverse(l_list);
|
||||
return l_list;
|
||||
}
|
||||
|
||||
TO_CL_FLOAT_2 (QPointF, qpointf, x, y)
|
||||
TO_CL_FLOAT_2 (QSizeF, qsizef, width, height)
|
||||
TO_CL_FLOAT_4 (QRectF, qrectf, x, y, width, height)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ qreal toReal(cl_object);
|
|||
QByteArray toCString(cl_object);
|
||||
QByteArray toQByteArray(cl_object);
|
||||
QString toQString(cl_object);
|
||||
QStringList toQStringList(cl_object);
|
||||
QVariant toQVariant(cl_object, int = -1);
|
||||
QVariantList toQVariantList(cl_object);
|
||||
QVariant toQVariantMap(cl_object);
|
||||
|
|
@ -91,6 +92,7 @@ QObject* toQObjectPointer(cl_object);
|
|||
cl_object from_cstring(const QByteArray&);
|
||||
cl_object from_qbytearray(const QByteArray&);
|
||||
cl_object from_qstring(const QString&);
|
||||
cl_object from_qstringlist(const QStringList&);
|
||||
cl_object from_qvariant(const QVariant&);
|
||||
cl_object from_qobject_pointer(QObject*);
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,10 @@
|
|||
(assert (typep exit-status 'fixnum))
|
||||
(%qquit exit-status))
|
||||
|
||||
;;; for android logging
|
||||
;;; android
|
||||
|
||||
(defun ensure-permissions (permissions)
|
||||
(qrun* (%ensure-permissions (x:ensure-list permissions))))
|
||||
|
||||
(defun qlog (arg1 &rest args)
|
||||
"args: (arg1 &rest args)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#:*root-item*
|
||||
#:*caller*
|
||||
#:define-qt-wrappers
|
||||
#:ensure-permissions
|
||||
#:find-quick-item
|
||||
#:pixel-ratio
|
||||
#:qapropos
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ macx {
|
|||
}
|
||||
|
||||
android {
|
||||
QT += androidextras
|
||||
INCLUDEPATH = $$(ECL_ANDROID)/include
|
||||
LIBS = -L$$(ECL_ANDROID)/lib -lecl
|
||||
DESTDIR = ../../platforms/android/lib
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue