Add PrivacyPolicyHelper
This commit is contained in:
parent
156af36954
commit
6df42a1fe3
@ -52,6 +52,7 @@
|
|||||||
#include "mouseobserver.h"
|
#include "mouseobserver.h"
|
||||||
#include "configuredhostsmodel.h"
|
#include "configuredhostsmodel.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#include "utils/privacypolicyhelper.h"
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
@ -185,6 +186,8 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterUncreatableType<DashboardSceneItem>("Nymea", 1, 0, "DashboardSceneItem", "");
|
qmlRegisterUncreatableType<DashboardSceneItem>("Nymea", 1, 0, "DashboardSceneItem", "");
|
||||||
qmlRegisterUncreatableType<DashboardWebViewItem>("Nymea", 1, 0, "DashboardWebViewItem", "");
|
qmlRegisterUncreatableType<DashboardWebViewItem>("Nymea", 1, 0, "DashboardWebViewItem", "");
|
||||||
|
|
||||||
|
qmlRegisterSingletonType<PrivacyPolicyHelper>("NymeaApp.Utils", 1, 0, "PrivacyPolicyHelper", PrivacyPolicyHelper::qmlProvider);
|
||||||
|
|
||||||
qmlRegisterType<MouseObserver>("Nymea", 1, 0, "MouseObserver");
|
qmlRegisterType<MouseObserver>("Nymea", 1, 0, "MouseObserver");
|
||||||
|
|
||||||
qmlRegisterType<ConfiguredHostsModel>("Nymea", 1, 0, "ConfiguredHostsModel");
|
qmlRegisterType<ConfiguredHostsModel>("Nymea", 1, 0, "ConfiguredHostsModel");
|
||||||
|
|||||||
@ -41,7 +41,8 @@ HEADERS += \
|
|||||||
stylecontroller.h \
|
stylecontroller.h \
|
||||||
pushnotifications.h \
|
pushnotifications.h \
|
||||||
platformhelper.h \
|
platformhelper.h \
|
||||||
ruletemplates/messages.h
|
ruletemplates/messages.h \
|
||||||
|
utils/privacypolicyhelper.h
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
configuredhostsmodel.cpp \
|
configuredhostsmodel.cpp \
|
||||||
@ -54,7 +55,8 @@ SOURCES += main.cpp \
|
|||||||
stylecontroller.cpp \
|
stylecontroller.cpp \
|
||||||
pushnotifications.cpp \
|
pushnotifications.cpp \
|
||||||
platformhelper.cpp \
|
platformhelper.cpp \
|
||||||
platformintegration/generic/screenhelper.cpp
|
platformintegration/generic/screenhelper.cpp \
|
||||||
|
utils/privacypolicyhelper.cpp
|
||||||
|
|
||||||
RESOURCES += resources.qrc \
|
RESOURCES += resources.qrc \
|
||||||
ruletemplates.qrc \
|
ruletemplates.qrc \
|
||||||
|
|||||||
74
nymea-app/utils/privacypolicyhelper.cpp
Normal file
74
nymea-app/utils/privacypolicyhelper.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include "privacypolicyhelper.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QtDebug>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
#include "platformhelper.h"
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcApplication)
|
||||||
|
|
||||||
|
PrivacyPolicyHelper::PrivacyPolicyHelper(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
QDir dir(QString(":/privacypolicy/"));
|
||||||
|
foreach (const QString &versionString, dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) {
|
||||||
|
bool ok;
|
||||||
|
int version = versionString.toInt(&ok);
|
||||||
|
if (ok && version > m_version) {
|
||||||
|
m_version = version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_version < 0) {
|
||||||
|
qCWarning(dcApplication()) << "Privacy policy directory not found. :/privacypolicy/<version>/ expected.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(dcApplication()) << "Using privacy policy version" << m_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject* PrivacyPolicyHelper::qmlProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(engine)
|
||||||
|
Q_UNUSED(scriptEngine)
|
||||||
|
static PrivacyPolicyHelper* qmlInstance = nullptr;
|
||||||
|
if (!qmlInstance) {
|
||||||
|
qmlInstance = new PrivacyPolicyHelper();
|
||||||
|
}
|
||||||
|
return qmlInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PrivacyPolicyHelper::version() const
|
||||||
|
{
|
||||||
|
return m_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PrivacyPolicyHelper::text() const
|
||||||
|
{
|
||||||
|
QFile f(findFile());
|
||||||
|
if (!f.open(QFile::ReadOnly)) {
|
||||||
|
qWarning() << "Cannot open privacy policy file for reading:" << f.fileName();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return f.readAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PrivacyPolicyHelper::findFile() const
|
||||||
|
{
|
||||||
|
QString privacyPolicyFile = QString(":/privacypolicy/%1/privacypolicy-%2.md")
|
||||||
|
.arg(m_version);
|
||||||
|
QStringList languages = {
|
||||||
|
QLocale().name(),
|
||||||
|
QLocale().name().split('_').at(0),
|
||||||
|
"en_US"
|
||||||
|
};
|
||||||
|
foreach (const QString &lang, languages) {
|
||||||
|
qCDebug(dcApplication) << "Trying Privacy policy at" << privacyPolicyFile.arg(lang);
|
||||||
|
if (QFile::exists(privacyPolicyFile.arg(lang))) {
|
||||||
|
return privacyPolicyFile.arg(lang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
26
nymea-app/utils/privacypolicyhelper.h
Normal file
26
nymea-app/utils/privacypolicyhelper.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef PRIVACYPOLICYHELPER_H
|
||||||
|
#define PRIVACYPOLICYHELPER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <qqml.h>
|
||||||
|
|
||||||
|
class PrivacyPolicyHelper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int version READ version CONSTANT)
|
||||||
|
Q_PROPERTY(QString text READ text CONSTANT)
|
||||||
|
public:
|
||||||
|
explicit PrivacyPolicyHelper(QObject *parent = nullptr);
|
||||||
|
static QObject *qmlProvider(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||||
|
|
||||||
|
|
||||||
|
int version() const;
|
||||||
|
QString text() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString findFile() const;
|
||||||
|
|
||||||
|
int m_version = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PRIVACYPOLICYHELPER_H
|
||||||
Reference in New Issue
Block a user