2020-05-06 17:40:00 +00:00
|
|
|
import NimQml
|
2020-05-15 22:02:20 +00:00
|
|
|
import app/chat/core as chat
|
|
|
|
import app/wallet/core as wallet
|
|
|
|
import app/node/core as node
|
2020-05-18 15:07:30 +00:00
|
|
|
import app/signals/core as signals
|
2020-05-08 22:12:32 +00:00
|
|
|
import state
|
2020-05-16 23:46:46 +00:00
|
|
|
import strformat
|
|
|
|
import strutils
|
2020-05-13 15:37:12 +00:00
|
|
|
import status/core as status
|
2020-05-16 23:46:46 +00:00
|
|
|
import status/chat as status_chat
|
2020-05-13 15:37:12 +00:00
|
|
|
import status/test as status_test
|
2020-05-16 23:46:46 +00:00
|
|
|
import status/types as types
|
|
|
|
import status/wallet as status_wallet
|
|
|
|
import status/libstatus
|
|
|
|
import state
|
|
|
|
|
|
|
|
# From QT docs:
|
|
|
|
# For any GUI application using Qt, there is precisely one QApplication object,
|
|
|
|
# no matter whether the application has 0, 1, 2 or more windows at any given time.
|
|
|
|
# For non-QWidget based Qt applications, use QGuiApplication instead, as it does
|
|
|
|
# not depend on the QtWidgets library. Use QCoreApplication for non GUI apps
|
|
|
|
|
2020-05-18 18:48:20 +00:00
|
|
|
var signalsQObjPointer: pointer
|
2020-05-11 17:31:07 +00:00
|
|
|
|
2020-05-06 17:40:00 +00:00
|
|
|
proc mainProc() =
|
2020-05-18 18:48:20 +00:00
|
|
|
var app = newQApplication()
|
|
|
|
|
|
|
|
var signalController = signals.newController(app)
|
|
|
|
|
|
|
|
# We need this global variable in order to be able to access the application
|
|
|
|
# from the non-closure callback passed to `libstatus.setSignalEventCallback`
|
|
|
|
signalsQObjPointer = cast[pointer](signalController.vptr)
|
|
|
|
|
2020-05-11 21:24:08 +00:00
|
|
|
defer: app.delete() # Defer will run this just before mainProc() function ends
|
2020-05-06 17:40:00 +00:00
|
|
|
|
|
|
|
var engine = newQQmlApplicationEngine()
|
|
|
|
defer: engine.delete()
|
|
|
|
|
2020-05-15 21:10:00 +00:00
|
|
|
var appState = state.newAppState()
|
|
|
|
echo appState.title
|
|
|
|
|
2020-05-16 23:46:46 +00:00
|
|
|
# TODO: @RR: commented until I'm able to fix the global variable issue described below
|
|
|
|
#status.init(appState)
|
2020-05-11 17:31:07 +00:00
|
|
|
|
2020-05-13 15:37:12 +00:00
|
|
|
status_test.setupNewAccount()
|
2020-05-11 17:31:07 +00:00
|
|
|
|
2020-05-18 18:20:20 +00:00
|
|
|
status_chat.startMessenger()
|
|
|
|
|
2020-05-15 21:40:05 +00:00
|
|
|
var wallet = wallet.newController()
|
2020-05-15 21:10:00 +00:00
|
|
|
wallet.init()
|
2020-05-15 21:40:05 +00:00
|
|
|
engine.setRootContextProperty("assetsModel", wallet.variant)
|
2020-05-13 19:14:35 +00:00
|
|
|
|
2020-05-15 21:40:05 +00:00
|
|
|
var chat = chat.newController()
|
2020-05-15 21:10:00 +00:00
|
|
|
chat.init()
|
2020-05-15 21:40:05 +00:00
|
|
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
2020-05-11 21:24:08 +00:00
|
|
|
|
2020-05-15 21:40:05 +00:00
|
|
|
var node = node.newController()
|
2020-05-15 21:10:00 +00:00
|
|
|
node.init()
|
2020-05-15 21:40:05 +00:00
|
|
|
engine.setRootContextProperty("nodeModel", node.variant)
|
2020-05-06 17:40:00 +00:00
|
|
|
|
2020-05-18 15:07:30 +00:00
|
|
|
signalController.init()
|
|
|
|
signalController.addSubscriber(SignalType.Wallet, wallet)
|
2020-05-18 18:20:20 +00:00
|
|
|
signalController.addSubscriber(SignalType.Message, chat)
|
|
|
|
|
2020-05-18 15:07:30 +00:00
|
|
|
engine.setRootContextProperty("signals", signalController.variant)
|
|
|
|
|
2020-05-08 22:12:32 +00:00
|
|
|
appState.subscribe(proc () =
|
2020-05-15 21:10:00 +00:00
|
|
|
# chatsModel.names = @[]
|
2020-05-08 22:12:32 +00:00
|
|
|
for channel in appState.channels:
|
|
|
|
echo channel.name
|
2020-05-15 21:10:00 +00:00
|
|
|
# chatsModel.addNameTolist(channel.name)
|
|
|
|
chat.join(channel.name)
|
2020-05-08 22:12:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
appState.addChannel("test")
|
|
|
|
appState.addChannel("test2")
|
2020-05-18 18:48:20 +00:00
|
|
|
|
2020-05-16 23:46:46 +00:00
|
|
|
engine.load("../ui/main.qml")
|
2020-05-18 18:48:20 +00:00
|
|
|
|
|
|
|
# Please note that this must use the `cdecl` calling convention because
|
|
|
|
# it will be passed as a regular C function to libstatus. This means that
|
|
|
|
# we cannot capture any local variables here (we must rely on globals)
|
|
|
|
var callback: SignalCallback = proc(p0: cstring) {.cdecl.} =
|
2020-05-16 23:46:46 +00:00
|
|
|
setupForeignThreadGc()
|
2020-05-18 15:07:30 +00:00
|
|
|
signal_handler(signalsQObjPointer, p0, "receiveSignal")
|
2020-05-16 23:46:46 +00:00
|
|
|
tearDownForeignThreadGc()
|
|
|
|
|
|
|
|
libstatus.setSignalEventCallback(callback)
|
2020-05-15 21:10:00 +00:00
|
|
|
|
2020-05-10 23:24:06 +00:00
|
|
|
# Qt main event loop is entered here
|
|
|
|
# The termination of the loop will be performed when exit() or quit() is called
|
2020-05-06 17:40:00 +00:00
|
|
|
app.exec()
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
mainProc()
|
|
|
|
GC_fullcollect()
|