2022-02-21 17:07:16 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QQmlContext>
|
|
|
|
|
2022-01-06 19:29:19 +00:00
|
|
|
#include "app_controller.h"
|
2022-01-20 14:48:57 +00:00
|
|
|
#include "modules/main/module.h"
|
2022-02-21 18:03:38 +00:00
|
|
|
#include "modules/startup/module.h"
|
2022-02-21 17:07:16 +00:00
|
|
|
#include "singleton.h"
|
2022-01-06 19:29:19 +00:00
|
|
|
|
|
|
|
AppController::AppController()
|
|
|
|
{
|
2022-02-21 17:07:16 +00:00
|
|
|
// To-do remove when transition to c++ is complete
|
|
|
|
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("cppApp", true);
|
2022-02-14 14:38:41 +00:00
|
|
|
// result.statusFoundation = statusFoundation
|
|
|
|
|
|
|
|
// # Global
|
|
|
|
// result.localAppSettingsVariant = newQVariant(singletonInstance.localAppSettings)
|
|
|
|
// result.localAccountSettingsVariant = newQVariant(singletonInstance.localAccountSettings)
|
|
|
|
// result.localAccountSensitiveSettingsVariant = newQVariant(singletonInstance.localAccountSensitiveSettings)
|
|
|
|
// result.userProfileVariant = newQVariant(singletonInstance.userProfile)
|
|
|
|
// result.globalUtilsVariant = newQVariant(singletonInstance.utils)
|
|
|
|
|
|
|
|
// # Services
|
|
|
|
// result.settingsService = settings_service.newService()
|
|
|
|
// result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,
|
|
|
|
// result.settingsService)
|
|
|
|
// result.osNotificationService = os_notification_service.newService(statusFoundation.status.events)
|
|
|
|
// result.keychainService = keychain_service.newService(statusFoundation.status.events)
|
|
|
|
// result.ethService = eth_service.newService()
|
2022-02-22 08:02:34 +00:00
|
|
|
|
|
|
|
// FIXME: it should be done in constructor member initializer list
|
2022-02-14 14:38:41 +00:00
|
|
|
m_accountsService = new Accounts::Service();
|
|
|
|
m_walletServicePtr = std::make_shared<Wallets::Service>();
|
|
|
|
// result.networkService = network_service.newService()
|
|
|
|
// result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
|
|
|
// result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService)
|
|
|
|
// result.communityService = community_service.newService(statusFoundation.status.events)
|
|
|
|
// result.messageService = message_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
|
|
|
// result.activityCenterService = activity_center_service.newService(statusFoundation.status.events,
|
|
|
|
// statusFoundation.threadpool, result.chatService)
|
|
|
|
// result.tokenService = token_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
|
|
|
// result.settingsService)
|
|
|
|
// result.collectibleService = collectible_service.newService(result.settingsService)
|
|
|
|
// result.walletAccountService = wallet_account_service.newService(statusFoundation.status.events, result.settingsService,
|
|
|
|
// result.accountsService, result.tokenService)
|
|
|
|
// result.transactionService = transaction_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
|
|
|
// result.walletAccountService)
|
|
|
|
// result.bookmarkService = bookmark_service.newService()
|
|
|
|
// result.profileService = profile_service.newService()
|
|
|
|
// result.stickersService = stickers_service.newService(
|
|
|
|
// statusFoundation.status.events,
|
|
|
|
// statusFoundation.threadpool,
|
|
|
|
// result.ethService,
|
|
|
|
// result.settingsService,
|
|
|
|
// result.walletAccountService,
|
|
|
|
// result.transactionService,
|
|
|
|
// result.networkService,
|
|
|
|
// result.chatService
|
|
|
|
// )
|
|
|
|
// result.aboutService = about_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
|
|
|
// result.settingsService)
|
|
|
|
// result.dappPermissionsService = dapp_permissions_service.newService()
|
|
|
|
// result.languageService = language_service.newService()
|
|
|
|
// # result.mnemonicService = mnemonic_service.newService()
|
|
|
|
// result.privacyService = privacy_service.newService(statusFoundation.status.events, result.settingsService,
|
|
|
|
// result.accountsService)
|
|
|
|
// result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService)
|
|
|
|
// result.savedAddressService = saved_address_service.newService(statusFoundation.status.events)
|
|
|
|
// result.devicesService = devices_service.newService(statusFoundation.status.events, result.settingsService)
|
|
|
|
// result.mailserversService = mailservers_service.newService(statusFoundation.status.events, statusFoundation.marathon,
|
|
|
|
// result.settingsService, result.nodeConfigurationService, statusFoundation.fleetConfiguration)
|
|
|
|
|
|
|
|
// # Modules
|
2022-02-22 08:02:34 +00:00
|
|
|
|
|
|
|
// FIXME: it should be done in constructor member initializer list
|
2022-02-14 14:38:41 +00:00
|
|
|
m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService);
|
|
|
|
|
2022-02-16 21:51:04 +00:00
|
|
|
m_mainModulePtr = new Modules::Main::Module(m_walletServicePtr, this);
|
2022-02-21 18:03:38 +00:00
|
|
|
// statusFoundation.status.events,
|
|
|
|
// result.keychainService,
|
|
|
|
// result.accountsService,
|
|
|
|
// result.chatService,
|
|
|
|
// result.communityService,
|
|
|
|
// result.messageService,
|
|
|
|
// result.tokenService,
|
|
|
|
// result.transactionService,
|
|
|
|
// result.collectibleService,
|
|
|
|
// result.walletAccountService,
|
|
|
|
// result.bookmarkService,
|
|
|
|
// result.profileService,
|
|
|
|
// result.settingsService,
|
|
|
|
// result.contactsService,
|
|
|
|
// result.aboutService,
|
|
|
|
// result.dappPermissionsService,
|
|
|
|
// result.languageService,
|
|
|
|
// # result.mnemonicService,
|
|
|
|
// result.privacyService,
|
|
|
|
// result.providerService,
|
|
|
|
// result.stickersService,
|
|
|
|
// result.activityCenterService,
|
|
|
|
// result.savedAddressService,
|
|
|
|
// result.nodeConfigurationService,
|
|
|
|
// result.devicesService,
|
|
|
|
// result.mailserversService
|
2022-02-14 14:38:41 +00:00
|
|
|
|
|
|
|
// # Do connections
|
|
|
|
connect();
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppController::~AppController()
|
|
|
|
{
|
2022-02-22 08:02:34 +00:00
|
|
|
// FIXME: `delete` should never be used, use RAII
|
2022-02-14 14:38:41 +00:00
|
|
|
delete m_startupModule;
|
|
|
|
delete m_accountsService;
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::connect()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
// self.statusFoundation.status.events.once("nodeStopped") do(a: Args):
|
|
|
|
// TODO: remove this once accounts are not tracked in the AccountsModel
|
|
|
|
// self.statusFoundation.status.reset()
|
2022-02-22 08:02:34 +00:00
|
|
|
|
|
|
|
// FIXME: use PointerToMember approach
|
2022-02-16 21:51:04 +00:00
|
|
|
QObject::connect(dynamic_cast<QObject*>(m_mainModulePtr), SIGNAL(loaded()), this, SLOT(mainDidLoad()));
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::startupDidLoad()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
// singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant)
|
|
|
|
// singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
|
|
|
// singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-14 14:38:41 +00:00
|
|
|
// We need to init a language service once qml is loaded
|
|
|
|
// self.languageService.init()
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::mainDidLoad()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
//self.statusFoundation.onLoggedIn()
|
|
|
|
m_startupModule->moveToAppState();
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-14 14:38:41 +00:00
|
|
|
//self.mainModule.checkForStoringPassword()
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::start()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
// self.ethService.init()
|
|
|
|
m_accountsService->init();
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-14 14:38:41 +00:00
|
|
|
m_startupModule->load();
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::load()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
qWarning() << "TODO: init services and load main module";
|
|
|
|
m_walletServicePtr->init();
|
|
|
|
// self.settingsService.init()
|
|
|
|
// self.nodeConfigurationService.init()
|
|
|
|
// self.contactsService.init()
|
|
|
|
// self.chatService.init()
|
|
|
|
// self.messageService.init()
|
|
|
|
// self.communityService.init()
|
|
|
|
// self.bookmarkService.init()
|
|
|
|
// self.tokenService.init()
|
|
|
|
// self.dappPermissionsService.init()
|
|
|
|
// self.providerService.init()
|
|
|
|
// self.walletAccountService.init()
|
|
|
|
// self.transactionService.init()
|
|
|
|
// self.stickersService.init()
|
|
|
|
// self.networkService.init()
|
|
|
|
// self.activityCenterService.init()
|
|
|
|
// self.savedAddressService.init()
|
|
|
|
// self.aboutService.init()
|
|
|
|
// self.devicesService.init()
|
|
|
|
// self.mailserversService.init()
|
|
|
|
|
|
|
|
// let pubKey = self.settingsService.getPublicKey()
|
|
|
|
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
|
|
|
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
|
|
|
// singletonInstance.engine.setRootContextProperty("globalUtils", self.globalUtilsVariant)
|
|
|
|
|
|
|
|
// # other global instances
|
|
|
|
// self.buildAndRegisterLocalAccountSensitiveSettings()
|
|
|
|
// self.buildAndRegisterUserProfile()
|
|
|
|
|
|
|
|
// # load main module
|
|
|
|
m_mainModulePtr->load(
|
2022-02-21 18:03:38 +00:00
|
|
|
// self.statusFoundation.status.events,
|
|
|
|
// self.settingsService,
|
|
|
|
// self.contactsService,
|
|
|
|
// self.chatService,
|
|
|
|
// self.communityService,
|
|
|
|
// self.messageService
|
|
|
|
);
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::userLoggedIn()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
//self.statusFoundation.status.startMessenger()
|
|
|
|
AppController::load();
|
|
|
|
|
|
|
|
// Once user is logged in and main module is loaded we need to check if it gets here importing mnemonic or not
|
|
|
|
// and delete mnemonic in the first case.
|
|
|
|
auto importedAccount = m_accountsService->getImportedAccount();
|
|
|
|
if(importedAccount.isValid())
|
|
|
|
{
|
|
|
|
// self.privacyService.removeMnemonic();
|
|
|
|
}
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::buildAndRegisterLocalAccountSensitiveSettings()
|
|
|
|
{
|
|
|
|
|
2022-02-14 14:38:41 +00:00
|
|
|
// var pubKey = self.settingsService.getPublicKey()
|
|
|
|
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
|
|
|
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppController::buildAndRegisterUserProfile()
|
|
|
|
{
|
2022-02-14 14:38:41 +00:00
|
|
|
// let pubKey = self.settingsService.getPublicKey()
|
|
|
|
// let preferredName = self.settingsService.getPreferredName()
|
|
|
|
// let ensUsernames = self.settingsService.getEnsUsernames()
|
|
|
|
// let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
|
|
|
|
// let sendUserStatus = self.settingsService.getSendStatusUpdates()
|
|
|
|
// // This is still not in use. Read a comment in UserProfile.
|
|
|
|
// // let currentUserStatus = self.settingsService.getCurrentUserStatus()
|
|
|
|
|
|
|
|
// let loggedInAccount = self.accountsService.getLoggedInAccount()
|
|
|
|
// var thumbnail, large: string
|
|
|
|
// for img in loggedInAccount.images:
|
|
|
|
// if(img.imgType == "large"):
|
|
|
|
// large = img.uri
|
|
|
|
// elif(img.imgType == "thumbnail"):
|
|
|
|
// thumbnail = img.uri
|
|
|
|
|
|
|
|
// let meAsContact = self.contactsService.getContactById(pubKey)
|
|
|
|
|
|
|
|
// singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, loggedInAccount.identicon,
|
|
|
|
// pubKey)
|
|
|
|
// singletonInstance.userProfile.setPreferredName(preferredName)
|
|
|
|
// singletonInstance.userProfile.setEnsName(meAsContact.name)
|
|
|
|
// singletonInstance.userProfile.setFirstEnsName(firstEnsName)
|
|
|
|
// singletonInstance.userProfile.setThumbnailImage(thumbnail)
|
|
|
|
// singletonInstance.userProfile.setLargeImage(large)
|
|
|
|
// singletonInstance.userProfile.setUserStatus(sendUserStatus)
|
|
|
|
|
|
|
|
// singletonInstance.engine.setRootContextProperty("userProfile", self.userProfileVariant)
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|