2017-01-29 15:54:16 +00:00
|
|
|
#include "application.h"
|
|
|
|
#include <QDebug>
|
2021-12-26 08:45:13 +00:00
|
|
|
|
|
|
|
#if QT_VERSION < 0x060000
|
2017-01-29 15:54:16 +00:00
|
|
|
#include "native.h"
|
2021-12-26 08:45:13 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-29 15:54:16 +00:00
|
|
|
|
|
|
|
#if defined(Q_OS_ANDROID)
|
2021-12-26 08:45:13 +00:00
|
|
|
|
|
|
|
#if QT_VERSION < 0x060100
|
2017-01-29 15:54:16 +00:00
|
|
|
#include <QAndroidJniObject>
|
|
|
|
#include <QtAndroid>
|
2021-12-26 08:45:13 +00:00
|
|
|
#else
|
|
|
|
#include <QJniObject>
|
|
|
|
#endif
|
|
|
|
|
2017-01-29 15:54:16 +00:00
|
|
|
#endif // Q_OS_ANDROID
|
|
|
|
|
|
|
|
Application::Application()
|
|
|
|
{
|
|
|
|
//both signals will be connected to the same function for
|
|
|
|
//simplicity
|
|
|
|
|
|
|
|
connect(this, &Application::onPermissionsGranted,
|
|
|
|
this, &Application::initializeQML);
|
|
|
|
|
|
|
|
connect(this, &Application::onPermissionsDenied,
|
|
|
|
this, &Application::initializeQML);
|
|
|
|
|
2021-12-26 08:45:13 +00:00
|
|
|
#if QT_VERSION < 0x060000
|
|
|
|
NativeHelpers::registerApplicationInstance(this);
|
|
|
|
#endif
|
2017-01-29 15:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::initializeQML()
|
|
|
|
{
|
2021-11-03 09:28:28 +00:00
|
|
|
#if QT_VERSION < 0x060200
|
2017-01-29 15:54:16 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
2021-11-03 09:28:28 +00:00
|
|
|
#else
|
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main_qt6_2.qml")));
|
|
|
|
#endif // QT_VERSION < 0x060200
|
2017-01-29 15:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::checkPermissions()
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_ANDROID)
|
|
|
|
//intentionally called in the C++ thread since it is blocking and will continue after the check
|
|
|
|
qDebug() << "About to request permissions";
|
|
|
|
|
2021-12-26 08:45:13 +00:00
|
|
|
#if QT_VERSION < 0x060000
|
2017-01-29 15:54:16 +00:00
|
|
|
QAndroidJniObject::callStaticMethod<void>("org/ftylitak/qzxing/Utilities",
|
|
|
|
"requestQZXingPermissions",
|
|
|
|
"(Landroid/app/Activity;)V",
|
|
|
|
QtAndroid::androidActivity().object());
|
2021-12-26 08:45:13 +00:00
|
|
|
#else
|
|
|
|
emit onPermissionsGranted();
|
|
|
|
#endif
|
2017-01-29 15:54:16 +00:00
|
|
|
qDebug() << "Permissions granted";
|
|
|
|
#else
|
|
|
|
emit onPermissionsGranted();
|
|
|
|
#endif //Q_OS_ANDROID
|
|
|
|
}
|