aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-07-06 09:40:41 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-09-08 19:17:25 +0200
commitf56329c995d4a708d4169ef52f819b38de1810b0 (patch)
tree6288a93258626b312899a5fa4d868b27fa0c0564
parent7f4245a4cf3cdad151f0f6677fe92cbef3bb9be5 (diff)
PySide: Add requestPermission()
- Only relevant for platforms like Android, where QT_FEATURE_permissions is turned ON. - Used a callback from the wrapper code to establish a call back to the passed Python functor. - The passed functor can either have no parameters, or have a QPermission object as parameter. In the latter case, the QPermission object will store the result of requestPermission(). This is similar to the Qt API. Pick-to: 6.5 Task-number: PYSIDE-1612 Change-Id: I0de8d1c67e69590d2a63ee51c61dfb3a8b76a43f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml24
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp63
2 files changed, 87 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index c943fffd6..82f4f286b 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -2631,6 +2631,30 @@
<declare-function signature="checkPermission(const QContactsPermission &amp; @permission@)" return-type="Qt::PermissionStatus" since="6.5" />
<declare-function signature="checkPermission(const QLocationPermission &amp; @permission@)" return-type="Qt::PermissionStatus" since="6.5" />
<declare-function signature="checkPermission(const QMicrophonePermission &amp; @permission@)" return-type="Qt::PermissionStatus" since="6.5" />
+ <add-function signature="requestPermission(const QBluetoothPermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
+ <add-function signature="requestPermission(const QCalendarPermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
+ <add-function signature="requestPermission(const QCameraPermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
+ <add-function signature="requestPermission(const QContactsPermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
+ <add-function signature="requestPermission(const QLocationPermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
+ <add-function signature="requestPermission(const QMicrophonePermission &amp; @permission@, const QObject* @context@, PyCallable* @functor@)" since="6.5">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qcoreapplication-requestpermission"/>
+ </add-function>
<?endif?>
</object-type>
<object-type name="QSettings">
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 93d1330ef..c955ead15 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1883,3 +1883,66 @@ Py_INCREF(callable);
#endif
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);
// @snippet qlocale_system
+
+// @snippet qcoreapplication-requestpermission
+auto permission = %1;
+auto callable = %PYARG_3;
+
+// check if callable
+if (!PyCallable_Check(callable)) {
+ qWarning("Functor of %FUNCTION_NAME is not a callable");
+ return {};
+}
+
+// find the number of arguments of callable. It should either be empy or accept a QPermission
+// object
+int count = 0;
+PyObject* fc = nullptr;
+bool classMethod = false;
+Shiboken::AutoDecRef func_ob(PyObject_GetAttr(callable, Shiboken::PyMagicName::func()));
+
+if (func_ob.isNull() && PyObject_HasAttr(callable, Shiboken::PyMagicName::code())) {
+ // variable `callable` is a function
+ fc = PyObject_GetAttr(callable, Shiboken::PyMagicName::code());
+} else {
+ // variable `callable` is a class method
+ fc = PyObject_GetAttr(func_ob, Shiboken::PyMagicName::code());
+ classMethod = true;
+}
+
+if (fc) {
+ PyObject* ac = PyObject_GetAttrString(fc, "co_argcount");
+ if (ac) {
+ count = PyLong_AsLong(ac);
+ Py_DECREF(ac);
+ }
+ Py_DECREF(fc);
+}
+
+if ((classMethod && (count > 2)) || (!classMethod && (count > 1))) {
+ qWarning("Functor of %FUNCTION_NAME must either have QPermission object as argument or none."
+ "The QPermission object store the result of requestPermission()");
+ return {};
+}
+
+bool arg_qpermission = (classMethod && (count == 2)) || (!classMethod && (count == 1));
+
+auto callback = [callable, count, arg_qpermission](const QPermission &permission) -> void
+{
+ Shiboken::GilState state;
+ if (arg_qpermission) {
+ Shiboken::AutoDecRef arglist(PyTuple_New(1));
+ PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QPermission](permission));
+ PyObject_CallObject(callable, arglist);
+ } else {
+ PyObject_CallObject(callable, nullptr);
+ }
+ Py_DECREF(callable);
+};
+Py_INCREF(callable);
+
+Py_BEGIN_ALLOW_THREADS
+%CPPSELF.%FUNCTION_NAME(permission, %2, callback);
+Py_END_ALLOW_THREADS
+// @snippet qcoreapplication-requestpermission
+