Add desktop implementation
This commit is contained in:
parent
828ee9875d
commit
d633b1ac6c
|
@ -0,0 +1,7 @@
|
|||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES}
|
||||
\"RNLanguages\" PARENT_SCOPE)
|
||||
|
||||
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rnlanguagesdesktop.cpp PARENT_SCOPE)
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Status Research and Development GmbH.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "bridge.h"
|
||||
#include "rnlanguagesdesktop.h"
|
||||
#include <QCryptographicHash>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QMap>
|
||||
#include <QNetworkDiskCache>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
namespace {
|
||||
struct RegisterQMLMetaType {
|
||||
RegisterQMLMetaType() {
|
||||
qRegisterMetaType<RNLanguages*>();
|
||||
}
|
||||
} registerMetaType;
|
||||
} // namespace
|
||||
|
||||
class RNLanguagesPrivate {
|
||||
|
||||
public:
|
||||
RNLanguagesPrivate() {}
|
||||
|
||||
Bridge* bridge = nullptr;
|
||||
|
||||
QVariantList languages() {
|
||||
QStringList languages = QLocale().uiLanguages();
|
||||
QVariantList variantLanguages;
|
||||
for (QString l : languages) {
|
||||
variantLanguages.push_back(l);
|
||||
}
|
||||
return variantLanguages;
|
||||
}
|
||||
};
|
||||
|
||||
RNLanguages::RNLanguages(QObject* parent) : QObject(parent), d_ptr(new RNLanguagesPrivate) {}
|
||||
|
||||
RNLanguages::~RNLanguages() {}
|
||||
|
||||
void RNLanguages::getLanguages(double successCallback, double errorCallback) {
|
||||
Q_D(RNLanguages);
|
||||
QVariantList args;
|
||||
args.push_back(d->languages());
|
||||
|
||||
if (d->bridge) {
|
||||
d->bridge->invokePromiseCallback(successCallback, args);
|
||||
}
|
||||
}
|
||||
|
||||
QString RNLanguages::moduleName() {
|
||||
return "RNLanguages";
|
||||
}
|
||||
|
||||
QList<ModuleMethod*> RNLanguages::methodsToExport() {
|
||||
return QList<ModuleMethod*>{};
|
||||
}
|
||||
|
||||
QVariantMap RNLanguages::constantsToExport() {
|
||||
return QVariantMap{{"languages", d_ptr->languages()}};
|
||||
}
|
||||
|
||||
void RNLanguages::setBridge(Bridge* bridge) {
|
||||
Q_D(RNLanguages);
|
||||
d->bridge = bridge;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Status Research and Development GmbH.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RNLANGUAGESDESKTOP_H
|
||||
#define RNLANGUAGESDESKTOP_H
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "moduleinterface.h"
|
||||
|
||||
class RNLanguagesPrivate;
|
||||
class RNLanguages : public QObject, public ModuleInterface {
|
||||
Q_OBJECT
|
||||
|
||||
Q_INTERFACES(ModuleInterface)
|
||||
|
||||
Q_DECLARE_PRIVATE(RNLanguages)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE RNLanguages(QObject* parent = 0);
|
||||
~RNLanguages();
|
||||
|
||||
Q_INVOKABLE REACT_PROMISE void getLanguages(double successCallback, double errorCallback);
|
||||
virtual QString moduleName() override;
|
||||
virtual QList<ModuleMethod*> methodsToExport() override;
|
||||
virtual QVariantMap constantsToExport() override;
|
||||
virtual void setBridge(Bridge* bridge) override;
|
||||
|
||||
private:
|
||||
QScopedPointer<RNLanguagesPrivate> d_ptr;
|
||||
};
|
||||
|
||||
#endif // RNLANGUAGESDESKTOP_H
|
||||
|
Loading…
Reference in New Issue