Added desktop implementation
This commit is contained in:
parent
8fa789d984
commit
3844e88488
|
@ -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}
|
||||
\"RNI18n\" PARENT_SCOPE)
|
||||
|
||||
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rni18ndesktop.cpp PARENT_SCOPE)
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Copyright (C) 2016, Canonical Ltd.
|
||||
* 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.
|
||||
*
|
||||
* Author: Justin McPherson <justin.mcpherson@canonical.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "bridge.h"
|
||||
#include "rni18ndesktop.h"
|
||||
#include <QCryptographicHash>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QMap>
|
||||
#include <QNetworkDiskCache>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
namespace {
|
||||
struct RegisterQMLMetaType {
|
||||
RegisterQMLMetaType() {
|
||||
qRegisterMetaType<RNI18n*>();
|
||||
}
|
||||
} registerMetaType;
|
||||
} // namespace
|
||||
|
||||
class RNI18nPrivate {
|
||||
|
||||
public:
|
||||
RNI18nPrivate() {}
|
||||
|
||||
Bridge* bridge = nullptr;
|
||||
|
||||
QVariantList languages() {
|
||||
QStringList languages = QLocale().uiLanguages();
|
||||
QVariantList variantLanguages;
|
||||
for (QString l : languages) {
|
||||
variantLanguages.push_back(l);
|
||||
}
|
||||
return variantLanguages;
|
||||
}
|
||||
};
|
||||
|
||||
RNI18n::RNI18n(QObject* parent) : QObject(parent), d_ptr(new RNI18nPrivate) {}
|
||||
|
||||
RNI18n::~RNI18n() {}
|
||||
|
||||
void RNI18n::getLanguages(double successCallback, double errorCallback) {
|
||||
Q_D(RNI18n);
|
||||
QVariantList args;
|
||||
args.push_back(d->languages());
|
||||
|
||||
if (d->bridge) {
|
||||
d->bridge->invokePromiseCallback(successCallback, args);
|
||||
}
|
||||
}
|
||||
|
||||
QString RNI18n::moduleName() {
|
||||
return "RNI18n";
|
||||
}
|
||||
|
||||
QList<ModuleMethod*> RNI18n::methodsToExport() {
|
||||
return QList<ModuleMethod*>{};
|
||||
}
|
||||
|
||||
QVariantMap RNI18n::constantsToExport() {
|
||||
return QVariantMap{{"languages", d_ptr->languages()}};
|
||||
}
|
||||
|
||||
void RNI18n::setBridge(Bridge* bridge) {
|
||||
Q_D(RNI18n);
|
||||
d->bridge = bridge;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
/**
|
||||
* Copyright (C) 2016, Canonical Ltd.
|
||||
* 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.
|
||||
*
|
||||
* Author: Justin McPherson <justin.mcpherson@canonical.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RNI18NDESKTOP_H
|
||||
#define RNI18NDESKTOP_H
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "moduleinterface.h"
|
||||
|
||||
class RNI18nPrivate;
|
||||
class RNI18n : public QObject, public ModuleInterface {
|
||||
Q_OBJECT
|
||||
|
||||
Q_INTERFACES(ModuleInterface)
|
||||
|
||||
Q_DECLARE_PRIVATE(RNI18n)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE RNI18n(QObject* parent = 0);
|
||||
~RNI18n();
|
||||
|
||||
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<RNI18nPrivate> d_ptr;
|
||||
};
|
||||
|
||||
#endif // RNI18NDESKTOP_H
|
Loading…
Reference in New Issue