qtnetworkauth.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2022 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // @snippet qabstractoauth-lookuphost-functor
  4. struct QAbstractOAuthModifyFunctor : public Shiboken::PyObjectHolder
  5. {
  6. public:
  7. using Shiboken::PyObjectHolder::PyObjectHolder;
  8. void operator()(QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant>* dictPointer);
  9. };
  10. void QAbstractOAuthModifyFunctor::operator()(QAbstractOAuth::Stage stage,
  11. QMultiMap<QString, QVariant>* dictPointer)
  12. {
  13. auto *callable = object();
  14. if (!PyCallable_Check(callable)) {
  15. qWarning("Argument 1 of setModifyParametersFunction() must be a callable.");
  16. return;
  17. }
  18. Shiboken::GilState state;
  19. QMultiMap<QString, QVariant> dict = *dictPointer;
  20. Shiboken::AutoDecRef arglist(PyTuple_New(2));
  21. PyTuple_SetItem(arglist, 0, %CONVERTTOPYTHON[QAbstractOAuth::Stage](stage));
  22. PyTuple_SetItem(arglist, 1, %CONVERTTOPYTHON[QMultiMap<QString, QVariant>](dict));
  23. Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist));
  24. if (!ret.isNull() && PyDict_Check(ret.object()) != 0) {
  25. PyObject *key{};
  26. PyObject *value{};
  27. Py_ssize_t pos = 0;
  28. while (PyDict_Next(ret.object(), &pos, &key, &value)) {
  29. QString cppKey = %CONVERTTOCPP[QString](key);
  30. QVariant cppValue = %CONVERTTOCPP[QVariant](value);
  31. dictPointer->replace(cppKey, cppValue);
  32. }
  33. }
  34. }
  35. // @snippet qabstractoauth-lookuphost-functor
  36. // @snippet qabstractoauth-setmodifyparametersfunction
  37. %CPPSELF.%FUNCTION_NAME(QAbstractOAuthModifyFunctor(%PYARG_1));
  38. // @snippet qabstractoauth-setmodifyparametersfunction