2021-04-02 12:22:37 +00:00
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2021, The Monero Project.
# include <iostream>
# include <QResource>
# include <QApplication>
# include <QCoreApplication>
# include <QQmlComponent>
# include <QtCore>
# include <QtGui>
# include <QQmlApplicationEngine>
# include <QtQml>
2021-04-06 00:20:42 +00:00
# include <QFileInfo>
2021-04-02 12:22:37 +00:00
# include <QQuickView>
# include <QQuickItem>
# include "openvr.h"
# include "vr/openvr_init.h"
# include "vr/main.h"
# include "libwalletqt/TransactionInfo.h"
# include "libwalletqt/TransactionHistory.h"
# include "model/TransactionHistoryModel.h"
# include "model/TransactionHistoryProxyModel.h"
# include "libwalletqt/WalletManager.h"
# include "utils/keysfiles.h"
namespace wowletvr {
void check_error ( int line , vr : : EVRInitError error ) { if ( error ! = 0 ) printf ( " %d: error %s \n " , line , VR_GetVRInitErrorAsSymbol ( error ) ) ; }
WowletVR : : WowletVR ( AppContext * ctx , QCommandLineParser * parser , QObject * parent ) :
QObject ( parent ) , ctx ( ctx ) , m_parser ( parser ) {
2021-04-06 00:20:42 +00:00
AppContext : : isQML = true ;
2021-04-08 01:40:44 +00:00
m_pClipboard = QGuiApplication : : clipboard ( ) ;
desktopMode = m_parser - > isSet ( " openvr-debug " ) ;
// Init QML themes
this - > readThemes ( ) ;
// turn on auto tx commits
ctx - > autoCommitTx = true ;
2021-04-06 00:20:42 +00:00
// write icon to disk so openvr overlay can refer to it
auto icon = " :/assets/images/wowlet.png " ;
if ( Utils : : fileExists ( icon ) ) {
QFile f ( icon ) ;
QFileInfo fileInfo ( f ) ;
auto icon_path = QDir ( ctx - > configDirectory ) . filePath ( fileInfo . fileName ( ) ) ;
f . copy ( icon_path ) ;
f . close ( ) ;
}
2021-04-02 12:22:37 +00:00
# ifdef Q_OS_WIN
if ( desktopMode )
2021-04-08 01:40:44 +00:00
qputenv ( " QMLSCENE_DEVICE " , " softwarecontext " ) ; // virtualbox
2021-04-02 12:22:37 +00:00
# endif
qDebug ( ) < < " QMLSCENE_DEVICE: " < < qgetenv ( " QMLSCENE_DEVICE " ) ;
2021-04-06 00:20:42 +00:00
qInfo ( ) < < " OPENSSL VERSION: " < < QSslSocket : : sslLibraryBuildVersionString ( ) ;
2021-04-02 12:22:37 +00:00
m_engine . rootContext ( ) - > setContextProperty ( " homePath " , QDir : : homePath ( ) ) ;
m_engine . rootContext ( ) - > setContextProperty ( " applicationDirectory " , QApplication : : applicationDirPath ( ) ) ;
m_engine . rootContext ( ) - > setContextProperty ( " idealThreadCount " , QThread : : idealThreadCount ( ) ) ;
m_engine . rootContext ( ) - > setContextProperty ( " qtRuntimeVersion " , qVersion ( ) ) ;
m_engine . rootContext ( ) - > setContextProperty ( " ctx " , ctx ) ;
// qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
2021-04-08 01:40:44 +00:00
m_engine . rootContext ( ) - > setContextProperty ( " WowletVR " , this ) ;
2021-04-02 12:22:37 +00:00
qRegisterMetaType < NetworkType : : Type > ( ) ;
qmlRegisterType < NetworkType > ( " wowlet.NetworkType " , 1 , 0 , " NetworkType " ) ;
2021-04-08 01:40:44 +00:00
qmlRegisterUncreatableType < WalletKeysFiles > ( " wowlet.WalletKeysFiles " , 1 , 0 , " WalletKeysFiles " , " WalletKeysFiles can't be instantiated directly " ) ;
2021-04-02 12:22:37 +00:00
qmlRegisterUncreatableType < Wallet > ( " wowlet.Wallet " , 1 , 0 , " Wallet " , " Wallet can't be instantiated directly " ) ;
qmlRegisterType < WalletManager > ( " wowlet.WalletManager " , 1 , 0 , " WalletManager " ) ;
qmlRegisterUncreatableType < TransactionHistoryProxyModel > ( " wowlet.TransactionHistoryProxyModel " , 1 , 0 , " TransactionHistoryProxyModel " , " TransactionHistoryProxyModel can't be instantiated directly " ) ;
qmlRegisterUncreatableType < TransactionHistoryModel > ( " wowlet.TransactionHistoryModel " , 1 , 0 , " TransactionHistoryModel " , " TransactionHistoryModel can't be instantiated directly " ) ;
qmlRegisterUncreatableType < TransactionInfo > ( " wowlet.TransactionInfo " , 1 , 0 , " TransactionInfo " , " TransactionHistory can't be instantiated directly " ) ;
qmlRegisterUncreatableType < TransactionHistory > ( " wowlet.TransactionHistory " , 1 , 0 , " TransactionHistory " , " TransactionHistory can't be instantiated directly " ) ;
qRegisterMetaType < PendingTransaction : : Priority > ( ) ;
qRegisterMetaType < TransactionInfo : : Direction > ( ) ;
qRegisterMetaType < TransactionHistoryModel : : TransactionInfoRole > ( ) ;
2021-04-06 00:20:42 +00:00
if ( ! desktopMode ) {
if ( ! openvr_init : : initializeOpenVR ( openvr_init : : OpenVrInitializationType : : Overlay ) )
throw std : : runtime_error ( " Error: initializeOpenVR() " ) ;
}
2021-04-08 01:40:44 +00:00
m_controller = new wowletvr : : OverlayController ( desktopMode , m_engine ) ;
m_engine . rootContext ( ) - > setContextProperty ( " OverlayController " , m_controller ) ;
2021-04-02 12:22:37 +00:00
auto widgetUrl = QUrl ( QStringLiteral ( " qrc:///main " ) ) ;
m_component = new QQmlComponent ( & m_engine , widgetUrl ) ;
this - > errors = m_component - > errors ( ) ;
for ( auto & e : this - > errors )
qCritical ( ) < < " QML Error: " < < e . toString ( ) . toStdString ( ) . c_str ( ) ;
}
void WowletVR : : render ( ) {
auto quickObj = m_component - > create ( ) ;
QQuickItem * quickObjItem = qobject_cast < QQuickItem * > ( quickObj ) ;
auto displayName = application_strings : : applicationDisplayName ;
auto appKey = application_strings : : applicationKey ;
if ( desktopMode ) {
auto m_pWindow = new QQuickWindow ( ) ;
qobject_cast < QQuickItem * > ( quickObj ) - > setParentItem ( m_pWindow - > contentItem ( ) ) ;
m_pWindow - > setGeometry ( 0 , 0 ,
static_cast < int > ( qobject_cast < QQuickItem * > ( quickObj ) - > width ( ) ) ,
static_cast < int > ( qobject_cast < QQuickItem * > ( quickObj ) - > height ( ) ) ) ;
m_pWindow - > show ( ) ;
return ;
}
2021-04-06 00:20:42 +00:00
auto iconPath = ctx - > configDirectory + " /wowlet.png " ;
m_controller - > SetWidget ( quickObjItem , displayName , appKey , iconPath . toStdString ( ) ) ;
2021-04-02 12:22:37 +00:00
}
2021-04-08 01:40:44 +00:00
void WowletVR : : readThemes ( ) {
theme_names = QVariantList ( ) ;
themes = QVariantMap ( ) ;
auto lol = Utils : : fileOpen ( " :/qml_themes.json " ) ;
auto doc = QJsonDocument : : fromJson ( lol ) ;
QJsonObject obj = doc . object ( ) ;
foreach ( const QString & themeName , obj . keys ( ) ) {
theme_names < < themeName ;
QJsonValue value = obj . value ( themeName ) ;
QJsonObject theme = value . toObject ( ) ;
QVariantMap map ;
foreach ( const QString & key , theme . keys ( ) ) {
map [ key ] = theme . value ( key ) . toString ( ) ;
}
themes [ themeName ] = map ;
}
2021-04-02 12:22:37 +00:00
} ;
2021-04-08 01:40:44 +00:00
WowletVR : : ~ WowletVR ( ) {
// bla
}
2021-04-02 12:22:37 +00:00
}